Skip to content

Commit

Permalink
Merge pull request #29 from bgd-labs/fix/self-transfer
Browse files Browse the repository at this point in the history
Self transfer balance fix
  • Loading branch information
sendra authored Jun 26, 2023
2 parents 53f60da + 4f22c5e commit 4983bee
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/BaseAaveToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,19 @@ abstract contract BaseAaveToken is Context, IERC20Metadata {
require(from != address(0), 'ERC20: transfer from the zero address');
require(to != address(0), 'ERC20: transfer to the zero address');

uint104 fromBalanceBefore = _balances[from].balance;
uint104 toBalanceBefore = _balances[to].balance;
if (from != to) {
uint104 fromBalanceBefore = _balances[from].balance;
uint104 toBalanceBefore = _balances[to].balance;

require(fromBalanceBefore >= amount, 'ERC20: transfer amount exceeds balance');
unchecked {
_balances[from].balance = fromBalanceBefore - uint104(amount);
}
require(fromBalanceBefore >= amount, 'ERC20: transfer amount exceeds balance');
unchecked {
_balances[from].balance = fromBalanceBefore - uint104(amount);
}

_balances[to].balance = toBalanceBefore + uint104(amount);
_balances[to].balance += toBalanceBefore + uint104(amount);

_afterTokenTransfer(from, to, fromBalanceBefore, toBalanceBefore, amount);
_afterTokenTransfer(from, to, fromBalanceBefore, toBalanceBefore, amount);
}
emit Transfer(from, to, amount);
}

Expand Down

0 comments on commit 4983bee

Please sign in to comment.