forked from aave-dao/aave-v3-origin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
243 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.10; | ||
|
||
import {IRescuable} from 'solidity-utils/contracts/utils/Rescuable.sol'; | ||
import {ERC20PermitUpgradeable} from 'openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20PermitUpgradeable.sol'; | ||
import {Initializable} from 'openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol'; | ||
import {AToken} from '../../../src/core/contracts/protocol/tokenization/AToken.sol'; | ||
import {DataTypes} from '../../../src/core/contracts/protocol/libraries/configuration/ReserveConfiguration.sol'; | ||
import {IERC20, IERC20Metadata} from '../../../src/periphery/contracts/static-a-token/StaticATokenLM.sol'; | ||
import {RayMathExplicitRounding} from '../../../src/periphery/contracts/libraries/RayMathExplicitRounding.sol'; | ||
import {IStaticATokenLM} from '../../../src/periphery/contracts/static-a-token/interfaces/IStaticATokenLM.sol'; | ||
import {SigUtils} from '../../utils/SigUtils.sol'; | ||
import {BaseTest, TestnetERC20} from './TestBase.sol'; | ||
import {IPool} from '../../../src/core/contracts/interfaces/IPool.sol'; | ||
|
||
contract StataRewardsTest is BaseTest { | ||
using RayMathExplicitRounding for uint256; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
|
||
_configureLM(); | ||
|
||
vm.startPrank(user); | ||
} | ||
|
||
// test rewards | ||
function test_collectAndUpdateRewards() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
_skipBlocks(60); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(address(staticATokenLM)), 0); | ||
uint256 claimable = staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN); | ||
staticATokenLM.collectAndUpdateRewards(REWARD_TOKEN); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(address(staticATokenLM)), claimable); | ||
} | ||
|
||
function test_claimableRewards() external { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
_depositAToken(amountToDeposit, user); | ||
|
||
vm.warp(block.timestamp + 200); | ||
uint256 claimable = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
assertEq(claimable, 200 * 0.00385 ether); | ||
} | ||
|
||
function test_claimRewardsToSelf() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
_skipBlocks(60); | ||
|
||
uint256 claimable = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimable); | ||
assertEq(staticATokenLM.getClaimableRewards(user, REWARD_TOKEN), 0); | ||
} | ||
|
||
function test_claimRewards() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
_skipBlocks(60); | ||
|
||
uint256 claimable = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
staticATokenLM.claimRewards(user, rewardTokens); | ||
assertEq(claimable, IERC20(REWARD_TOKEN).balanceOf(user)); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(address(staticATokenLM)), 0); | ||
assertEq(staticATokenLM.getClaimableRewards(user, REWARD_TOKEN), 0); | ||
} | ||
|
||
// should fail as user1 is not a valid claimer | ||
function testFail_claimRewardsOnBehalfOf() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
_skipBlocks(60); | ||
|
||
vm.stopPrank(); | ||
vm.startPrank(user1); | ||
|
||
staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
staticATokenLM.claimRewardsOnBehalf(user, user1, rewardTokens); | ||
} | ||
|
||
function test_depositATokenClaimWithdrawClaim() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
// deposit aweth | ||
_depositAToken(amountToDeposit, user); | ||
|
||
// forward time | ||
_skipBlocks(60); | ||
|
||
// claim | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), 0); | ||
uint256 claimable0 = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), claimable0); | ||
assertGt(claimable0, 0); | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimable0); | ||
|
||
// forward time | ||
_skipBlocks(60); | ||
|
||
// redeem | ||
staticATokenLM.redeem(staticATokenLM.maxRedeem(user), user, user); | ||
uint256 claimable1 = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), claimable1); | ||
assertGt(claimable1, 0); | ||
|
||
// claim on behalf of other user | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimable1 + claimable0); | ||
assertEq(staticATokenLM.balanceOf(user), 0); | ||
assertEq(staticATokenLM.getClaimableRewards(user, REWARD_TOKEN), 0); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), 0); | ||
assertGe(AToken(UNDERLYING).balanceOf(user), 5 ether); | ||
} | ||
|
||
function test_depositWETHClaimWithdrawClaim() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
// forward time | ||
_skipBlocks(60); | ||
|
||
// claim | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), 0); | ||
uint256 claimable0 = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), claimable0); | ||
assertGt(claimable0, 0); | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimable0); | ||
|
||
// forward time | ||
_skipBlocks(60); | ||
|
||
// redeem | ||
staticATokenLM.redeem(staticATokenLM.maxRedeem(user), user, user); | ||
uint256 claimable1 = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), claimable1); | ||
assertGe(claimable1, 0); | ||
|
||
// claim on behalf of other user | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimable1 + claimable0); | ||
assertEq(staticATokenLM.balanceOf(user), 0); | ||
assertEq(staticATokenLM.getClaimableRewards(user, REWARD_TOKEN), 0); | ||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), 0); | ||
assertGe(AToken(UNDERLYING).balanceOf(user), 5 ether); | ||
} | ||
|
||
function test_transfer() public { | ||
uint128 amountToDeposit = 10 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
_depositAToken(amountToDeposit, user); | ||
|
||
// transfer to 2nd user | ||
staticATokenLM.transfer(user1, amountToDeposit / 2); | ||
assertEq(staticATokenLM.getClaimableRewards(user1, REWARD_TOKEN), 0); | ||
|
||
// forward time | ||
_skipBlocks(60); | ||
|
||
// redeem for both | ||
uint256 claimableUser = staticATokenLM.getClaimableRewards(user, REWARD_TOKEN); | ||
staticATokenLM.redeem(staticATokenLM.maxRedeem(user), user, user); | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user), claimableUser); | ||
vm.stopPrank(); | ||
vm.startPrank(user1); | ||
uint256 claimableUser1 = staticATokenLM.getClaimableRewards(user1, REWARD_TOKEN); | ||
staticATokenLM.redeem(staticATokenLM.maxRedeem(user1), user1, user1); | ||
staticATokenLM.claimRewardsToSelf(rewardTokens); | ||
assertEq(IERC20(REWARD_TOKEN).balanceOf(user1), claimableUser1); | ||
assertGt(claimableUser1, 0); | ||
|
||
assertEq(staticATokenLM.getTotalClaimableRewards(REWARD_TOKEN), 0); | ||
assertEq(staticATokenLM.getClaimableRewards(user, REWARD_TOKEN), 0); | ||
assertEq(staticATokenLM.getClaimableRewards(user1, REWARD_TOKEN), 0); | ||
} | ||
|
||
// getUnclaimedRewards | ||
function test_getUnclaimedRewards() public { | ||
uint128 amountToDeposit = 5 ether; | ||
_fundUser(amountToDeposit, user); | ||
|
||
uint256 shares = _depositAToken(amountToDeposit, user); | ||
assertEq(staticATokenLM.getUnclaimedRewards(user, REWARD_TOKEN), 0); | ||
_skipBlocks(1000); | ||
staticATokenLM.redeem(shares, user, user); | ||
assertGt(staticATokenLM.getUnclaimedRewards(user, REWARD_TOKEN), 0); | ||
} | ||
} |
Oops, something went wrong.