Hi, i am working on a side game contract. This contract receives tokens from another contract, when the contracts balance has reached an minimum amount of tokens, the first caller to call the function, will burn the balance of tokens and receives 1% of the balance as reward for doing so.
In order to approve the caller to spend the contract's token balance, i used this:
function approve() public {
approveBurn(msg.sender);
}
function approveBurn(address spender) internal {
// Add some (alot) extra allowance in case more comes in
uint256 extraAllowance = erc20Token.balanceOf(address(this)) * 100**18;
uint256 amount = erc20Token.balanceOf(address(this)) + extraAllowance;
erc20Token.approve(spender, amount);
emit Approval (address(this), spender, amount);
}
When i go to the erc20 token contract, and check the callers allowance, it shows the correct amount (so the games balance * 100). So according to the erc20 token contract, caller have enough allowance to spend the games balance.
However, when the caller calls the function to burn the balance and receive the reward, done with this:
IBurnableToken(erc20Token).burn(address(this), toBeBurned);
erc20Token.transferFrom(address(this), caller, callerReward);
It reverts with "Unsufficient allowance", but when i check allowance on the token contract, the allowance for caller to spend the balance, is there, even multiplied by 100 times.
I am a bit lost here, anyone have a direction where to search?