Skip to content

Commit

Permalink
fix: Avoid emitting events when balanceIncrease is zero (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf authored Dec 6, 2022
1 parent f8825f8 commit 43f34c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ abstract contract ScaledBalanceTokenBase is MintableIncentivizedERC20, IScaledBa

super._transfer(sender, recipient, amount.rayDiv(index).toUint128());

emit Transfer(address(0), sender, senderBalanceIncrease);
emit Mint(_msgSender(), sender, senderBalanceIncrease, senderBalanceIncrease, index);
if (senderBalanceIncrease > 0) {
emit Transfer(address(0), sender, senderBalanceIncrease);
emit Mint(_msgSender(), sender, senderBalanceIncrease, senderBalanceIncrease, index);
}

if (recipientBalanceIncrease > 0) {
emit Transfer(address(0), recipient, recipientBalanceIncrease);
Expand Down
48 changes: 28 additions & 20 deletions test-suites/helpers/utils/tokenization-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,20 @@ export const transfer = async (
addedScaledBalance,
indexAfter,
]);
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [
ZERO_ADDRESS,
user.address,
fromBalanceIncrease,
]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
user.address,
user.address,
fromBalanceIncrease,
fromBalanceIncrease,
indexAfter,
]);
if (fromBalanceIncrease.gt(0)) {
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [
ZERO_ADDRESS,
user.address,
fromBalanceIncrease,
]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
user.address,
user.address,
fromBalanceIncrease,
fromBalanceIncrease,
indexAfter,
]);
}
if (toBalanceIncrease.gt(0)) {
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [ZERO_ADDRESS, to, toBalanceIncrease]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
Expand Down Expand Up @@ -277,14 +279,20 @@ export const transferFrom = async (
addedScaledBalance,
indexAfter,
]);
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [ZERO_ADDRESS, origin, fromBalanceIncrease]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
user.address,
origin,
fromBalanceIncrease,
fromBalanceIncrease,
indexAfter,
]);
if (fromBalanceIncrease.gt(0)) {
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [
ZERO_ADDRESS,
origin,
fromBalanceIncrease,
]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
user.address,
origin,
fromBalanceIncrease,
fromBalanceIncrease,
indexAfter,
]);
}
if (toBalanceIncrease.gt(0)) {
matchEvent(rcpt, 'Transfer', aToken, aToken.address, [ZERO_ADDRESS, to, toBalanceIncrease]);
matchEvent(rcpt, 'Mint', aToken, aToken.address, [
Expand Down

0 comments on commit 43f34c9

Please sign in to comment.