I have this function, which is receiving a wallet address and an array of tokens, and returns the balances of every token for this wallet.
function getBalances(address wallet, IERC20[] tokens) external view returns (uint256[] memory balances) {
uint size = tokens.length;
uint256[] memory balances = new uint256[](size)
for (uint i=0; i < size; i++) {
TokenContract tokenContract = TokenContract(tokens[i]);
balances[i] = tokenContract.balanceOf(wallet);
}
return balances;
}
But I am concerned about the order of the input tokens. If the order is the same like the user sent them.
For example: user sends [t1, t2, t3, t4], for-loop is iterating in the same order, and the return is like [b1, b2, b3, b4].
Or the order is not 100% guaranteed? In this case, can you give me an idea about how to return the balances for the user to be able to know which token represents?