I have the following _transfer
method implementation in my ERC20 token.
function _transfer(address from, address to, uint256 amount) internal override {
require(transfersEnabled || essentialAddress[from] || essentialAddress[to], "Transfers not allowed");
if (amount == 0) {
super._transfer(from, to, 0);
return;
}
uint256 currentBalanceFrom = balanceOf(from);
uint256 currentBalanceTo = balanceOf(to);
// Deduct the fee if necessary
uint256 fees = calculateFee(amount, from, to);
if (fees > 0) {
super._transfer(from, address(this), fees);
}
super._transfer(from, to, amount - fees);
handleBalanceUpdate(from, to, currentBalanceFrom, currentBalanceTo); <-- Something strange is happening here
_distributeFee();
}
The method calls handleBalanceUpdate
:
When calling
function handleBalanceUpdate( address from, address to, uint256 oldBalanceFrom, uint256 oldBlanceTo) internal {
if (address(rewardsManager) != address(0)) {
try rewardsManager.notifyBalanceUpdate(from, oldBalanceFrom) {} catch { console.log("Fail"); }
try rewardsManager.notifyBalanceUpdate(to, oldBlanceTo) {} catch { console.log("Fail"); }
}
}
Problem is that when rewardsManager.notifyBalanceUpdate
reverts, the whole transfer gets reverted silently, no exception is thrown. I am expecting the transfer to happen normally regardless if rewardsManager.notifyBalanceUpdate
fails or not.
Did you guys face anything similar?
This only happens when the transfer is initiated via the transferFrom
method. Simple transfer
works as expected