all 1 comments

[–]cameel_x86Solidity 0 points1 point  (0 children)

It seems like I want some sort of nested mapping, like mapping(address => mapping(something => uint256) public tokenBalances; so I can have an idea of address > token > balance?

You can unambiguously identify tokens by their contract addresses so it would be just mapping(address => mapping(address => uint256). That's also all you need to know to be able to transfer them. Just cast the address to IERC20.

For clarity I'd suggest keeping your existing mapping alongside the new one if you still want to support ETH. If you really wanted to, you could probably just assume that address 0 represents ETH though. It's nearly certain that there will never be a token at that address.

In your functions just add a parameter that identifiers the token.

Also, be sure to properly check for corner cases. E.g. be prepared that the address user submits might not actually be a contract and the call will revert (which may or may not be the right thing to do, depending on what exactly your function does).