I'm trying to start a stacking smart contract. Each user can stake different ERC20 Token.
I'm using follwing struct :
struct Token {
address tokenAddress;
uint256 stakedAmount;
uint lastTransactionDate;
bool isUsed;
}
I define a relation User-Token with :
mapping(address => Token) stakingUserBalance;
On my stake function I need to store an ERC20 token for user :
function stakeToken(address tokenAddress, uint256 amount) public {
require(amount > 0, "You cannot stake 0 token");
//Transfer amount to smartcontract
IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount);
//Update user balance
Token storage userToken = stakingUserBalance[msg.sender];
userToken.lastTransactionDate = block.timestamp;
userToken.stakedAmount += amount;
//fire event
emit TokenStaked(tokenAddress, amount);
}
So my question is : how get a specific token address in stakingUserBalance
to update the value of stakedAmount
for right token ?
thanks for your help