smart-contracts
smart-contracts copied to clipboard
Unable to set token wallet to reserve contract
Once token wallet is set, there is no way to set it to the reserve contract anymore. This is because token approval only happens in approveWithdrawAddress
, and has the condition that the token wallet address is null, but setTokenWallet
checks that the input address is not null. As such, there is no way to reset the token wallet.
Code reference:
function approveWithdrawAddress(ERC20 token, address addr, bool approve) public onlyAdmin {
approvedWithdrawAddresses[keccak256(token, addr)] = approve;
WithdrawAddressApproved(token, addr, approve);
setDecimals(token);
if ((tokenWallet[token] == address(0x0)) && (token != ETH_TOKEN_ADDRESS)) {
tokenWallet[token] = this; // by default
require(token.approve(this, 2 ** 255));
}
}
function setTokenWallet(ERC20 token, address wallet) public onlyAdmin {
require(wallet != address(0x0));
tokenWallet[token] = wallet;
NewTokenWallet(token, wallet);
}
Recommendation is to have a conditional check for token approval in setTokenWallet
:
function setTokenWallet(ERC20 token, address wallet) public onlyAdmin {
require(wallet != address(0x0));
tokenWallet[token] = wallet;
if(wallet == address(this)) {
require(token.approve(this, 2 ** 255));
}
NewTokenWallet(token, wallet);
}
Should probably reset old wallet allowance in this case. And also reset allowance to reserve in case it was non zero before. More generally if u want to change it, then probably should support proper change of token wallet. And not only for wallet as reserve.
Oh right....
In that case, I suppose a separate function to change token wallet would be best?
function changeTokenWallet(ERC20 token, address wallet) public onlyAdmin {
require(wallet != address(0x0));
if (wallet == address(this)) {
require(token.approve(this, 0)); //reset allowance first
require(token.approve(this, 2 ** 255));
} else {
//check that old wallet allowance has been reset
require(token.allowance(tokenWallet[token], this) == 0);
}
tokenWallet[token] = wallet;
NewTokenWallet(token, wallet);
}