Skip to content

Commit

Permalink
feat: set in bound rate limit as well
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Oct 30, 2024
1 parent f64be60 commit af02c9e
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021 is IProposalGenericExecutor {
}

/// @notice Returns the rate limiter configuration for the inbound rate limiter
/// The offramp capacity for ETH => ARB will be disabled, as the outbound rate limit
/// will be set on ETH token pool
/// The offRamp rate limit for ETH => ARB will be as follows:
/// Capacity: 350_000 GHO
/// Rate: 100 GHO per second (=> 360_000 GHO per hour)
/// @return The rate limiter configuration
function getInBoundRateLimiterConfig() public pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: false, capacity: 0, rate: 0});
return RateLimiter.Config({isEnabled: true, capacity: 350_000e18, rate: 100e18});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,66 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
assertEq(_readInitialized(_getImplementation(address(ghoTokenPool))), 255);
}

// function test_fuzzOutBoundRateLimit(uint256 amount) public {
// // executePayload(vm, address(proposal));

// (uint256 bucketCapacity, ) = IGhoToken(ARB_GHO_TOKEN).getFacilitatorBucket(
// address(ghoTokenPool)
// );
// amount = bound(amount, 0, bucketCapacity);
// deal(ARB_GHO_TOKEN, alice, amount);

// IRouter router = IRouter(ghoTokenPool.getRouter());
// vm.prank(alice);
// IERC20(ARB_GHO_TOKEN).approve(address(router), amount);
// uint256 capacity = proposal.getOutBoundRateLimiterConfig().capacity;

// (
// IClient.EVM2AnyMessage memory message,
// IInternal.EVM2EVMMessage memory eventArg
// ) = _getTokenMessage(CCIPSendParams({router: router, amount: amount, migrated: false}));

// if (amount > capacity) {
// vm.expectRevert(
// abi.encodeWithSelector(
// RateLimiter.AggregateValueMaxCapacityExceeded.selector,
// capacity,
// amount
// )
// );
// } else {
// vm.expectRevert(
// abi.encodeWithSelector(
// RateLimiter.TokenRateLimitReached.selector,
// 1 /* minWaitInSeconds */,
// 0 /* available */,
// ARB_GHO_TOKEN
// ) // since the upgrade has just happened this block
// );
// }
// vm.prank(alice);
// router.ccipSend{value: eventArg.feeTokenAmount}(ETH_CHAIN_SELECTOR, message);

// skip(_getOutboundRefillTime(amount));

// if (amount > capacity) {
// vm.expectRevert(
// abi.encodeWithSelector(
// RateLimiter.AggregateValueMaxCapacityExceeded.selector,
// capacity,
// amount
// )
// );
// } else {
// vm.expectEmit(address(ghoTokenPool));
// emit Burned(ON_RAMP_1_2, amount);
// vm.expectEmit(ON_RAMP_1_2);
// emit CCIPSendRequested(eventArg);
// }
// vm.prank(alice);
// router.ccipSend{value: eventArg.feeTokenAmount}(ETH_CHAIN_SELECTOR, message);
// }

function test_sendMessagePreCCIPMigration() public {
executePayload(vm, address(proposal));

Expand Down Expand Up @@ -214,7 +274,7 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
uint256 facilitatorLevelBefore = _getFacilitatorLevel(address(ghoTokenPool));

// wait for the rate limiter to refill
skip(_getOutboundRefillTime(amount));
skip(_getInboundRefillTime(amount));

vm.expectEmit(address(ghoTokenPool));
emit Minted(OFF_RAMP_1_2, alice, amount);
Expand All @@ -234,7 +294,7 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
uint256 facilitatorLevelBefore = _getFacilitatorLevel(address(ghoTokenPool));

// wait for the rate limiter to refill
skip(_getOutboundRefillTime(amount));
skip(_getInboundRefillTime(amount));

vm.expectEmit(address(ghoTokenPool));
emit Minted(OFF_RAMP_1_5, alice, amount);
Expand Down Expand Up @@ -279,6 +339,9 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
executePayload(vm, address(proposal));
uint256 facilitatorLevelBefore = _getFacilitatorLevel(address(ghoTokenPool));

// wait for the rate limiter to refill
skip(_getInboundRefillTime(amount));

vm.expectEmit(address(ghoTokenPool));
emit Minted(address(proxyPool), alice, amount);
vm.prank(address(proxyPool));
Expand All @@ -288,6 +351,10 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
assertEq(_getFacilitatorLevel(address(ghoTokenPool)), facilitatorLevelBefore + amount);
}

function test_sendRevertOnInvalidMessageFormat() public {
// invalid message format: 1.2 after migration, 1.5 before migration
}

function _mockCCIPMigration() private {
IRouter router = IRouter(ghoTokenPool.getRouter());
// token registry not set for 1.5 migration
Expand Down Expand Up @@ -406,6 +473,12 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
return amount / uint256(rate) + 1; // account for rounding
}

function _getInboundRefillTime(uint256 amount) private view returns (uint256) {
uint128 rate = proposal.getInBoundRateLimiterConfig().rate;
assertNotEq(rate, 0);
return amount / uint256(rate) + 1; // account for rounding
}

function _tokenBucketToConfig(
RateLimiter.TokenBucket memory bucket
) private pure returns (RateLimiter.Config memory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PreCCIPMigration is
vm.prank(alice);
l1.c.token.approve(address(l1.c.router), amount);

uint128 rate = l1.proposal.getOutBoundRateLimiterConfig().rate;
uint128 outBoundRate = l1.proposal.getOutBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(rate) + 1); // rate is non zero
skip(amount / uint256(outBoundRate) + 1); // rate is non zero

uint256 tokenPoolBalance = l1.c.token.balanceOf(address(l1.tokenPool));
uint256 bridgedAmount = l1.tokenPool.getCurrentBridgedAmount();
Expand Down Expand Up @@ -325,6 +325,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PreCCIPMigration is

uint256 aliceBalanceBefore = l2.c.token.balanceOf(alice);

uint128 inBoundRate = l2.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

vm.expectEmit(address(l2.tokenPool));
emit Minted(address(l2.c.EVM2EVMOffRamp1_2), alice, amount);
vm.prank(address(l2.c.EVM2EVMOffRamp1_2));
Expand All @@ -342,9 +346,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PreCCIPMigration is

vm.prank(alice);
l2.c.token.approve(address(l2.c.router), amount);
uint128 rate = l2.proposal.getOutBoundRateLimiterConfig().rate;
uint128 outBoundRate = l2.proposal.getOutBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(rate) + 1); // rate is non zero
skip(amount / uint256(outBoundRate) + 1); // rate is non zero

(
IClient.EVM2AnyMessage memory message,
Expand Down Expand Up @@ -375,6 +379,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PreCCIPMigration is

uint256 tokenPoolBalanceBefore = l1.c.token.balanceOf(address(l1.tokenPool));

uint128 inBoundRate = l1.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

vm.expectEmit(address(l1.tokenPool));
emit Released(address(l1.c.EVM2EVMOffRamp1_2), alice, amount);
vm.prank(address(l1.c.EVM2EVMOffRamp1_2));
Expand Down Expand Up @@ -416,9 +424,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is
vm.prank(alice);
l1.c.token.approve(address(l1.c.router), amount);

uint128 rate = l1.proposal.getOutBoundRateLimiterConfig().rate;
uint128 outBoundRate = l1.proposal.getOutBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(rate) + 1); // rate is non zero
skip(amount / uint256(outBoundRate) + 1); // rate is non zero

uint256 tokenPoolBalance = l1.c.token.balanceOf(address(l1.tokenPool));
uint256 bridgedAmount = l1.tokenPool.getCurrentBridgedAmount();
Expand Down Expand Up @@ -456,6 +464,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is
// ARB executeMessage
vm.selectFork(l2.c.forkId);

uint128 inBoundRate = l2.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

vm.expectEmit(address(l2.tokenPool));
emit Minted(address(l2.c.EVM2EVMOffRamp1_2), alice, amount);
vm.prank(address(l2.c.EVM2EVMOffRamp1_2));
Expand All @@ -464,6 +476,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is
new bytes[](message.tokenAmounts.length)
);

// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

vm.expectEmit(address(l2.c.proxyPool)); // emitter is proxyPool for 1.5 on ramp
emit Minted(address(l2.c.EVM2EVMOffRamp1_5), alice, amount);
vm.prank(address(l2.c.EVM2EVMOffRamp1_5));
Expand All @@ -480,9 +495,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is

vm.prank(alice);
l2.c.token.approve(address(l2.c.router), amount);
uint128 rate = l2.proposal.getOutBoundRateLimiterConfig().rate;
uint128 outBoundRate = l2.proposal.getOutBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(rate) + 1); // rate is non zero
skip(amount / uint256(outBoundRate) + 1); // rate is non zero

(
IClient.EVM2AnyMessage memory message,
Expand Down Expand Up @@ -516,6 +531,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is

uint256 tokenPoolBalanceBefore = l1.c.token.balanceOf(address(l1.tokenPool));

uint128 inBoundRate = l1.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

vm.expectEmit(address(l1.c.proxyPool)); // emitter is proxyPool for 1.5 off ramp
emit Released(address(l1.c.EVM2EVMOffRamp1_5), alice, amount);
vm.prank(address(l1.c.EVM2EVMOffRamp1_5));
Expand Down Expand Up @@ -608,6 +627,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is
vm.prank(alice);
l1.c.token.approve(address(l1.c.router), amount);

uint128 inBoundRate = l1.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

(
IClient.EVM2AnyMessage memory message,
IInternal.EVM2EVMMessage memory eventArg
Expand Down Expand Up @@ -643,6 +666,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_PostCCIPMigration is
vm.prank(alice);
l2.c.token.approve(address(l2.c.router), amount);

uint128 inBoundRate = l2.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

(
IClient.EVM2AnyMessage memory message,
IInternal.EVM2EVMMessage memory eventArg
Expand Down Expand Up @@ -728,6 +755,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_InBetweenCCIPMigration is
// CCIP Migration on L2
_mockCCIPMigration(l2.c, l1.c);

uint128 inBoundRate = l2.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

// reverts with 1.5 off ramp
vm.expectRevert();
vm.prank(address(l2.c.EVM2EVMOffRamp1_5));
Expand Down Expand Up @@ -756,9 +787,9 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_InBetweenCCIPMigration is
deal(address(l2.c.token), alice, amount, true);
vm.prank(alice);
l2.c.token.approve(address(l2.c.router), amount);
uint128 rate = l2.proposal.getOutBoundRateLimiterConfig().rate;
uint128 outBoundRate = l2.proposal.getOutBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(rate) + 1); // rate is non zero
skip(amount / uint256(outBoundRate) + 1); // rate is non zero

(
IClient.EVM2AnyMessage memory message,
Expand Down Expand Up @@ -788,6 +819,10 @@ contract AaveV3E2E_GHOCCIP150Upgrade_20241021_InBetweenCCIPMigration is
// CCIP Migration on L2
_mockCCIPMigration(l1.c, l1.c);

uint128 inBoundRate = l1.proposal.getInBoundRateLimiterConfig().rate;
// wait for the rate limiter to refill
skip(amount / uint256(inBoundRate) + 1); // rate is non zero

// reverts with 1.5 off ramp
vm.expectRevert();
vm.prank(address(l1.c.EVM2EVMOffRamp1_5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021 is IProposalGenericExecutor {
}

/// @notice Returns the rate limiter configuration for the inbound rate limiter
/// The offramp capacity for ARB => ETH will be disabled, as the outbound rate limit
/// will be set on ARB token pool
/// The offRamp rate limit for ARB=>ETH will be as follows:
/// Capacity: 350_000 GHO
/// Rate: 100 GHO per second (=> 360_000 GHO per hour)
/// @return The rate limiter configuration
function getInBoundRateLimiterConfig() public pure returns (RateLimiter.Config memory) {
return RateLimiter.Config({isEnabled: false, capacity: 0, rate: 0});
return RateLimiter.Config({isEnabled: true, capacity: 350_000e18, rate: 100e18});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
uint256 amount = 350_000e18;

// wait for the rate limiter to refill
skip(_getOutboundRefillTime(amount));
skip(_getInboundRefillTime(amount));
// mock previously locked gho
deal(address(gho), address(ghoTokenPool), amount);

Expand All @@ -225,7 +225,7 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
IERC20 gho = IERC20(address(ghoTokenPool.getToken()));
uint256 amount = 350_000e18;
// wait for the rate limiter to refill
skip(_getOutboundRefillTime(amount));
skip(_getInboundRefillTime(amount));
// mock previously locked gho
deal(address(gho), address(ghoTokenPool), amount);

Expand Down Expand Up @@ -269,6 +269,8 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
executePayload(vm, address(proposal));
// mock previously locked gho
deal(MiscEthereum.GHO_TOKEN, address(ghoTokenPool), amount);
// wait for the rate limiter to refill
skip(_getInboundRefillTime(amount));

vm.expectEmit(address(ghoTokenPool));
emit Released(address(proxyPool), alice, amount);
Expand Down Expand Up @@ -399,6 +401,12 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
return amount / uint256(rate) + 1; // account for rounding
}

function _getInboundRefillTime(uint256 amount) private view returns (uint256) {
uint128 rate = proposal.getInBoundRateLimiterConfig().rate;
assertNotEq(rate, 0);
return amount / uint256(rate) + 1; // account for rounding
}

function _tokenBucketToConfig(
RateLimiter.TokenBucket memory bucket
) private pure returns (RateLimiter.Config memory) {
Expand Down

0 comments on commit af02c9e

Please sign in to comment.