Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add infinite withdraw test coverage for AAVE (SC-862) #68

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions test/base-fork/Aave.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ contract AaveV3BaseMarketWithdrawFailureTests is AaveV3BaseMarketTestBase {
contract AaveV3BaseMarketWithdrawSuccessTests is AaveV3BaseMarketTestBase {

function test_withdrawAave_usdc() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
foreignController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDC
);

// NOTE: Using lower amount to not hit rate limit
deal(Base.USDC, address(almProxy), 500_000e6);
vm.prank(relayer);
Expand All @@ -185,6 +190,8 @@ contract AaveV3BaseMarketWithdrawSuccessTests is AaveV3BaseMarketTestBase {
assertEq(usdcBase.balanceOf(address(almProxy)), 0);
assertEq(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance + 500_000e6);

assertEq(rateLimits.getCurrentRateLimit(key), 1_000_000e6);

// Partial withdraw
vm.prank(relayer);
assertEq(foreignController.withdrawAave(ATOKEN_USDC, 400_000e6), 400_000e6);
Expand All @@ -193,6 +200,8 @@ contract AaveV3BaseMarketWithdrawSuccessTests is AaveV3BaseMarketTestBase {
assertEq(usdcBase.balanceOf(address(almProxy)), 400_000e6);
assertEq(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance + 100_000e6); // 500k - 400k

assertEq(rateLimits.getCurrentRateLimit(key), 600_000e6);

// Withdraw all
vm.prank(relayer);
assertEq(foreignController.withdrawAave(ATOKEN_USDC, type(uint256).max), fullBalance - 400_000e6);
Expand All @@ -201,8 +210,45 @@ contract AaveV3BaseMarketWithdrawSuccessTests is AaveV3BaseMarketTestBase {
assertEq(usdcBase.balanceOf(address(almProxy)), fullBalance);
assertEq(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance + 500_000e6 - fullBalance);

assertEq(rateLimits.getCurrentRateLimit(key), 1_000_000e6 - fullBalance);

// Interest accrued was withdrawn, reducing cash balance
assertLe(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance);
}

function test_withdrawAave_usdc_unlimitedRateLimit() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
foreignController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDC
);
vm.prank(Base.SPARK_EXECUTOR);
rateLimits.setUnlimitedRateLimitData((key));
hexonaut marked this conversation as resolved.
Show resolved Hide resolved

deal(Base.USDC, address(almProxy), 1_000_000e6);
vm.prank(relayer);
foreignController.depositAave(ATOKEN_USDC, 1_000_000e6);

skip(1 days);

uint256 fullBalance = ausdc.balanceOf(address(almProxy));

assertGe(fullBalance, 1_000_000e6);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max);

assertEq(ausdc.balanceOf(address(almProxy)), fullBalance);
assertEq(usdcBase.balanceOf(address(almProxy)), 0);
assertEq(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6);

// Partial withdraw
vm.prank(relayer);
assertEq(foreignController.withdrawAave(ATOKEN_USDC, type(uint256).max), fullBalance);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max); // No change

assertEq(ausdc.balanceOf(address(almProxy)), 0);
assertEq(usdcBase.balanceOf(address(almProxy)), fullBalance);
assertEq(usdcBase.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6 - fullBalance);
}

}
91 changes: 91 additions & 0 deletions test/mainnet-fork/Aave.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ contract AaveV3MainMarketWithdrawFailureTests is AaveV3MainMarketBaseTest {
contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {

function test_withdrawAave_usds() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
mainnetController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDS
);

deal(Ethereum.USDS, address(almProxy), 1_000_000e18);
vm.prank(relayer);
mainnetController.depositAave(ATOKEN_USDS, 1_000_000e18);
Expand All @@ -243,6 +248,8 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertEq(usds.balanceOf(address(almProxy)), 0);
assertEq(usds.balanceOf(address(ausds)), startingAUSDSBalance + 1_000_000e18);

assertEq(rateLimits.getCurrentRateLimit(key), 10_000_000e18);

// Partial withdraw
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDS, 400_000e18), 400_000e18);
Expand All @@ -251,10 +258,14 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertEq(usds.balanceOf(address(almProxy)), 400_000e18);
assertEq(usds.balanceOf(address(ausds)), startingAUSDSBalance + 600_000e18); // 1m - 400k

assertEq(rateLimits.getCurrentRateLimit(key), 9_600_000e18);

// Withdraw all
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDS, type(uint256).max), fullBalance - 400_000e18);

assertEq(rateLimits.getCurrentRateLimit(key), 10_000_000e18 - fullBalance);

assertEq(ausds.balanceOf(address(almProxy)), 0);
assertEq(usds.balanceOf(address(almProxy)), fullBalance);
assertEq(usds.balanceOf(address(ausds)), startingAUSDSBalance + 1_000_000e18 - fullBalance);
Expand All @@ -263,7 +274,46 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertLe(usds.balanceOf(address(ausds)), startingAUSDSBalance);
}

function test_withdrawAave_usds_unlimitedRateLimit() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
mainnetController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDS
);
vm.prank(Ethereum.SPARK_PROXY);
rateLimits.setUnlimitedRateLimitData((key));
hexonaut marked this conversation as resolved.
Show resolved Hide resolved

deal(Ethereum.USDS, address(almProxy), 1_000_000e18);
vm.prank(relayer);
mainnetController.depositAave(ATOKEN_USDS, 1_000_000e18);

skip(1 days);

uint256 fullBalance = ausds.balanceOf(address(almProxy));

assertGe(fullBalance, 1_000_000e18);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max);

assertEq(ausds.balanceOf(address(almProxy)), fullBalance);
assertEq(usds.balanceOf(address(almProxy)), 0);
assertEq(usds.balanceOf(address(ausds)), startingAUSDSBalance + 1_000_000e18);

// Partial withdraw
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDS, type(uint256).max), fullBalance);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max); // No change

assertEq(ausds.balanceOf(address(almProxy)), 0);
assertEq(usds.balanceOf(address(almProxy)), fullBalance);
assertEq(usds.balanceOf(address(ausds)), startingAUSDSBalance + 1_000_000e18 - fullBalance);
}

function test_withdrawAave_usdc() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
mainnetController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDC
);
deal(Ethereum.USDC, address(almProxy), 1_000_000e6);
vm.prank(relayer);
mainnetController.depositAave(ATOKEN_USDC, 1_000_000e6);
Expand All @@ -278,6 +328,8 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertEq(usdc.balanceOf(address(almProxy)), 0);
assertEq(usdc.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6);

assertEq(rateLimits.getCurrentRateLimit(key), 10_000_000e6);

// Partial withdraw
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDC, 400_000e6), 400_000e6);
Expand All @@ -286,6 +338,8 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertEq(usdc.balanceOf(address(almProxy)), 400_000e6);
assertEq(usdc.balanceOf(address(ausdc)), startingAUSDCBalance + 600_000e6); // 1m - 400k

assertEq(rateLimits.getCurrentRateLimit(key), 9_600_000e6);

// Withdraw all
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDC, type(uint256).max), fullBalance - 400_000e6);
Expand All @@ -294,8 +348,45 @@ contract AaveV3MainMarketWithdrawSuccessTests is AaveV3MainMarketBaseTest {
assertEq(usdc.balanceOf(address(almProxy)), fullBalance);
assertEq(usdc.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6 - fullBalance);

assertEq(rateLimits.getCurrentRateLimit(key), 10_000_000e6 - fullBalance);

// Interest accrued was withdrawn, reducing cash balance
assertLe(usdc.balanceOf(address(ausdc)), startingAUSDCBalance);
}

function test_withdrawAave_usdc_unlimitedRateLimit() public {
bytes32 key = RateLimitHelpers.makeAssetKey(
mainnetController.LIMIT_AAVE_WITHDRAW(),
ATOKEN_USDC
);
vm.prank(Ethereum.SPARK_PROXY);
rateLimits.setUnlimitedRateLimitData((key));
hexonaut marked this conversation as resolved.
Show resolved Hide resolved

deal(Ethereum.USDC, address(almProxy), 1_000_000e6);
vm.prank(relayer);
mainnetController.depositAave(ATOKEN_USDC, 1_000_000e6);

skip(1 days);

uint256 fullBalance = ausdc.balanceOf(address(almProxy));

assertGe(fullBalance, 1_000_000e6);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max);

assertEq(ausdc.balanceOf(address(almProxy)), fullBalance);
assertEq(usdc.balanceOf(address(almProxy)), 0);
assertEq(usdc.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6);

// Partial withdraw
vm.prank(relayer);
assertEq(mainnetController.withdrawAave(ATOKEN_USDC, type(uint256).max), fullBalance);

assertEq(rateLimits.getCurrentRateLimit(key), type(uint256).max); // No change

assertEq(ausdc.balanceOf(address(almProxy)), 0);
assertEq(usdc.balanceOf(address(almProxy)), fullBalance);
assertEq(usdc.balanceOf(address(ausdc)), startingAUSDCBalance + 1_000_000e6 - fullBalance);
}

}
Loading