fix: Add claimRewardsToSelf() to force receiver = msg.sender

This commit is contained in:
Lasse Herskind 2021-06-23 15:09:24 +02:00
parent 4373b61d76
commit d12318591c
2 changed files with 16 additions and 30 deletions

View File

@ -493,7 +493,7 @@ contract StaticATokenLM is ERC20 {
* @param receiver The address of the receiver of rewards * @param receiver The address of the receiver of rewards
* @param forceUpdate Flag to retrieve latest rewards from `INCENTIVES_CONTROLLER` * @param forceUpdate Flag to retrieve latest rewards from `INCENTIVES_CONTROLLER`
*/ */
function claimRewards(address receiver, bool forceUpdate) external { function claimRewards(address receiver, bool forceUpdate) public {
if (forceUpdate) { if (forceUpdate) {
collectAndUpdateRewards(); collectAndUpdateRewards();
} }
@ -512,6 +512,10 @@ contract StaticATokenLM is ERC20 {
} }
} }
function claimRewardsToSelf(bool forceUpdate) external {
claimRewards(msg.sender, forceUpdate);
}
/** /**
* @dev Update the rewardDebt for a user with balance as his balance * @dev Update the rewardDebt for a user with balance as his balance
* @param user The user to update * @param user The user to update

View File

@ -157,9 +157,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
const claimedRewards4 = await stkAave.balanceOf(userSigner._address); const claimedRewards4 = await stkAave.balanceOf(userSigner._address);
const stkAaveStatic4 = await stkAave.balanceOf(staticAToken.address); const stkAaveStatic4 = await stkAave.balanceOf(staticAToken.address);
await waitForTx( await waitForTx(await staticAToken.connect(userSigner).claimRewardsToSelf(false));
await staticAToken.connect(userSigner).claimRewards(userSigner._address, false)
);
const pendingRewards5 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards5 = await staticAToken.getClaimableRewards(userSigner._address);
const totPendingRewards5 = await staticAToken.getTotalClaimableRewards(); const totPendingRewards5 = await staticAToken.getTotalClaimableRewards();
@ -315,9 +313,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address);
const claimedRewards3 = await stkAave.balanceOf(userSigner._address); const claimedRewards3 = await stkAave.balanceOf(userSigner._address);
await waitForTx( await waitForTx(await staticAToken.connect(userSigner).claimRewardsToSelf(true));
await staticAToken.connect(userSigner).claimRewards(userSigner._address, true)
);
const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address);
const claimedRewards4 = await stkAave.balanceOf(userSigner._address); const claimedRewards4 = await stkAave.balanceOf(userSigner._address);
@ -394,9 +390,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
// How will my pending look now // How will my pending look now
const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address);
await waitForTx( await waitForTx(await staticAToken.connect(userSigner).claimRewardsToSelf(true));
await staticAToken.connect(userSigner).claimRewards(userSigner._address, true)
);
const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address);
const userBalance4 = await stkAave.balanceOf(userSigner._address); const userBalance4 = await stkAave.balanceOf(userSigner._address);
@ -485,9 +479,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address);
await waitForTx( await waitForTx(await staticAToken.connect(userSigner).claimRewardsToSelf(true));
await staticAToken.connect(userSigner).claimRewards(userSigner._address, true)
);
const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address);
const userBalance4 = await stkAave.balanceOf(userSigner._address); const userBalance4 = await stkAave.balanceOf(userSigner._address);
@ -530,9 +522,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards3 = await staticAToken.getClaimableRewards(userSigner._address);
const unclaimedRewards3 = await staticAToken.getUnclaimedRewards(userSigner._address); const unclaimedRewards3 = await staticAToken.getUnclaimedRewards(userSigner._address);
await waitForTx( await waitForTx(await staticAToken.connect(userSigner).claimRewardsToSelf(false));
await staticAToken.connect(userSigner).claimRewards(userSigner._address, false)
);
const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address); const pendingRewards4 = await staticAToken.getClaimableRewards(userSigner._address);
const userBalance4 = await stkAave.balanceOf(userSigner._address); const userBalance4 = await stkAave.balanceOf(userSigner._address);
@ -606,9 +596,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
// This will claim the first half of the collected tokens (those collected at `collectAndUpdateRewards`) // This will claim the first half of the collected tokens (those collected at `collectAndUpdateRewards`)
await waitForTx( await waitForTx(await staticAToken.connect(users[i]).claimRewardsToSelf(false));
await staticAToken.connect(users[i]).claimRewards(await users[i].getAddress(), false)
);
} }
let staticATokenTotClaimableAfterTransferAndClaim = await staticAToken.getTotalClaimableRewards(); let staticATokenTotClaimableAfterTransferAndClaim = await staticAToken.getTotalClaimableRewards();
@ -748,9 +736,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
// This will not do anything, hence there is no rewards in the current contract. // This will not do anything, hence there is no rewards in the current contract.
await waitForTx( await waitForTx(await staticAToken.connect(users[i]).claimRewardsToSelf(false));
await staticAToken.connect(users[i]).claimRewards(await users[i].getAddress(), false)
);
} }
let staticATokenTotClaimableAfterTransfer = await staticAToken.getTotalClaimableRewards(); let staticATokenTotClaimableAfterTransfer = await staticAToken.getTotalClaimableRewards();
@ -859,9 +845,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
pendingRewards.push(pendingReward); pendingRewards.push(pendingReward);
} }
for (let i = 0; i < users.length; i++) { for (let i = 0; i < users.length; i++) {
await waitForTx( await waitForTx(await staticAToken.connect(users[i]).claimRewardsToSelf(false));
await staticAToken.connect(users[i]).claimRewards(await users[i].getAddress(), false)
);
expect(await stkAave.balanceOf(await users[i].getAddress())).to.be.eq(pendingRewards[i]); expect(await stkAave.balanceOf(await users[i].getAddress())).to.be.eq(pendingRewards[i]);
} }
expect(await stkAave.balanceOf(staticAToken.address)).to.be.lt(DUST); expect(await stkAave.balanceOf(staticAToken.address)).to.be.lt(DUST);
@ -943,9 +927,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
); );
const pendingReward = await staticAToken.getClaimableRewards(await users[i].getAddress()); const pendingReward = await staticAToken.getClaimableRewards(await users[i].getAddress());
await waitForTx( await waitForTx(await staticAToken.connect(users[i]).claimRewardsToSelf(true));
await staticAToken.connect(users[i]).claimRewards(await users[i].getAddress(), true)
);
expect(await stkAave.balanceOf(await users[i].getAddress())).to.be.eq(pendingReward); expect(await stkAave.balanceOf(await users[i].getAddress())).to.be.eq(pendingReward);
} }
}); });
@ -976,7 +958,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
await waitForTx(await staticAToken.connect(user).withdraw(user.address, MAX_UINT_AMOUNT, true)); await waitForTx(await staticAToken.connect(user).withdraw(user.address, MAX_UINT_AMOUNT, true));
await staticAToken.collectAndUpdateRewards(); await staticAToken.collectAndUpdateRewards();
await staticAToken.connect(user).claimRewards(user.address, false); await staticAToken.connect(user).claimRewardsToSelf(false);
expect(await staticAToken.getLifetimeRewardsClaimed()).to.be.gt(0); expect(await staticAToken.getLifetimeRewardsClaimed()).to.be.gt(0);
expect(await staticAToken.getClaimableRewards(user.address)).to.be.eq(0); expect(await staticAToken.getClaimableRewards(user.address)).to.be.eq(0);
@ -1011,7 +993,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
await staticAToken.connect(user).withdraw(user.address, MAX_UINT_AMOUNT, true); await staticAToken.connect(user).withdraw(user.address, MAX_UINT_AMOUNT, true);
await staticAToken.collectAndUpdateRewards(); await staticAToken.collectAndUpdateRewards();
await staticAToken.connect(user).claimRewards(user.address, false); await staticAToken.connect(user).claimRewardsToSelf(false);
await DRE.network.provider.send('evm_mine', []); await DRE.network.provider.send('evm_mine', []);
await DRE.network.provider.send('evm_setAutomine', [true]); await DRE.network.provider.send('evm_setAutomine', [true]);