Skip to content

Commit

Permalink
test: ccip steward can disable rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Oct 30, 2024
1 parent b1da849 commit bf4f3e5
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {IProxyPool} from 'src/interfaces/ccip/IProxyPool.sol';
import {IRateLimiter} from 'src/interfaces/ccip/IRateLimiter.sol';
import {ITokenAdminRegistry} from 'src/interfaces/ccip/ITokenAdminRegistry.sol';
import {IGhoToken} from 'src/interfaces/IGhoToken.sol';
import {IGhoCcipSteward} from 'src/interfaces/IGhoCcipSteward.sol';
import {CCIPUtils} from './utils/CCIPUtils.sol';

import {AaveV3Arbitrum_GHOCCIP150Upgrade_20241021} from './AaveV3Arbitrum_GHOCCIP150Upgrade_20241021.sol';
Expand Down Expand Up @@ -50,6 +51,9 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
address internal constant OFF_RAMP_1_2 = 0x542ba1902044069330e8c5b36A84EC503863722f;
address internal constant OFF_RAMP_1_5 = 0x91e46cc5590A4B9182e47f40006140A7077Dec31;

IGhoCcipSteward internal constant GHO_CCIP_STEWARD =
IGhoCcipSteward(0xb329CEFF2c362F315900d245eC88afd24C4949D5);

event Burned(address indexed sender, uint256 amount);
event Minted(address indexed sender, address indexed recipient, uint256 amount);
event CCIPSendRequested(IInternal.EVM2EVMMessage message);
Expand Down Expand Up @@ -314,6 +318,29 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
assertEq(_getFacilitatorLevel(address(ghoTokenPool)), facilitatorLevelBefore + amount);
}

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

vm.prank(ghoTokenPool.owner());
ghoTokenPool.setRateLimitAdmin(address(GHO_CCIP_STEWARD));

vm.prank(_readRiskAdmin());
GHO_CCIP_STEWARD.updateRateLimit(ETH_CHAIN_SELECTOR, false, 0, 0, false, 0, 0);

assertEq(
abi.encode(
_tokenBucketToConfig(ghoTokenPool.getCurrentInboundRateLimiterState(ETH_CHAIN_SELECTOR))
),
abi.encode(_getDisabledConfig())
);
assertEq(
abi.encode(
_tokenBucketToConfig(ghoTokenPool.getCurrentOutboundRateLimiterState(ETH_CHAIN_SELECTOR))
),
abi.encode(_getDisabledConfig())
);
}

function _mockCCIPMigration() private {
IRouter router = IRouter(ghoTokenPool.getRouter());
// token registry not set for 1.5 migration
Expand Down Expand Up @@ -393,6 +420,15 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
return uint8(uint256(vm.load(proxy, bytes32(0))));
}

function _readRiskAdmin() private view returns (address riskAdmin) {
// private immutable at offset 144
address steward = address(GHO_CCIP_STEWARD);
assembly {
extcodecopy(steward, 0, 144, 20) // use scratch space
riskAdmin := shr(96, mload(0)) // correct padding
}
}

function _getFacilitatorLevel(address f) internal view returns (uint256) {
(, uint256 level) = IGhoToken(ARB_GHO_TOKEN).getFacilitatorBucket(f);
return level;
Expand Down Expand Up @@ -424,6 +460,9 @@ contract AaveV3Arbitrum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
assertEq(ITypeAndVersion(ON_RAMP_1_5).typeAndVersion(), 'EVM2EVMOnRamp 1.5.0');
assertEq(ITypeAndVersion(OFF_RAMP_1_2).typeAndVersion(), 'EVM2EVMOffRamp 1.2.0');
assertEq(ITypeAndVersion(OFF_RAMP_1_5).typeAndVersion(), 'EVM2EVMOffRamp 1.5.0');

assertEq(GHO_CCIP_STEWARD.GHO_TOKEN(), ARB_GHO_TOKEN);
assertEq(GHO_CCIP_STEWARD.GHO_TOKEN_POOL(), address(ghoTokenPool));
}

function _getOutboundRefillTime(uint256 amount) private view returns (uint256) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ITypeAndVersion} from 'src/interfaces/ccip/ITypeAndVersion.sol';
import {IProxyPool} from 'src/interfaces/ccip/IProxyPool.sol';
import {IRateLimiter} from 'src/interfaces/ccip/IRateLimiter.sol';
import {ITokenAdminRegistry} from 'src/interfaces/ccip/ITokenAdminRegistry.sol';
import {IGhoCcipSteward} from 'src/interfaces/IGhoCcipSteward.sol';
import {CCIPUtils} from './utils/CCIPUtils.sol';
import {AaveV3Ethereum_GHOCCIP150Upgrade_20241021} from './AaveV3Ethereum_GHOCCIP150Upgrade_20241021.sol';

Expand All @@ -41,11 +42,15 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
address internal constant ARB_PROXY_POOL = 0x26329558f08cbb40d6a4CCA0E0C67b29D64A8c50;
ITokenAdminRegistry internal constant TOKEN_ADMIN_REGISTRY =
ITokenAdminRegistry(0xb22764f98dD05c789929716D677382Df22C05Cb6);

address internal constant ON_RAMP_1_2 = 0x925228D7B82d883Dde340A55Fe8e6dA56244A22C;
address internal constant ON_RAMP_1_5 = 0x69eCC4E2D8ea56E2d0a05bF57f4Fd6aEE7f2c284;
address internal constant OFF_RAMP_1_2 = 0xeFC4a18af59398FF23bfe7325F2401aD44286F4d;
address internal constant OFF_RAMP_1_5 = 0xdf615eF8D4C64d0ED8Fd7824BBEd2f6a10245aC9;

IGhoCcipSteward internal constant GHO_CCIP_STEWARD =
IGhoCcipSteward(0x101Efb7b9Beb073B1219Cd5473a7C8A2f2EB84f4);

event Locked(address indexed sender, uint256 amount);
event Released(address indexed sender, address indexed recipient, uint256 amount);
event CCIPSendRequested(IInternal.EVM2EVMMessage message);
Expand Down Expand Up @@ -301,6 +306,29 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
ghoTokenPool.releaseOrMint(abi.encode(alice), alice, amount, ARB_CHAIN_SELECTOR, new bytes(0));
}

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

vm.prank(ghoTokenPool.owner());
ghoTokenPool.setRateLimitAdmin(address(GHO_CCIP_STEWARD));

vm.prank(_readRiskAdmin());
GHO_CCIP_STEWARD.updateRateLimit(ARB_CHAIN_SELECTOR, false, 0, 0, false, 0, 0);

assertEq(
abi.encode(
_tokenBucketToConfig(ghoTokenPool.getCurrentInboundRateLimiterState(ARB_CHAIN_SELECTOR))
),
abi.encode(_getDisabledConfig())
);
assertEq(
abi.encode(
_tokenBucketToConfig(ghoTokenPool.getCurrentOutboundRateLimiterState(ARB_CHAIN_SELECTOR))
),
abi.encode(_getDisabledConfig())
);
}

function _mockCCIPMigration() private {
IRouter router = IRouter(ghoTokenPool.getRouter());
// token registry not set for 1.5 migration
Expand Down Expand Up @@ -383,6 +411,15 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
return uint8(uint256(vm.load(proxy, bytes32(0))));
}

function _readRiskAdmin() private view returns (address riskAdmin) {
// private immutable at offset 144
address steward = address(GHO_CCIP_STEWARD);
assembly {
extcodecopy(steward, 0, 144, 20) // use scratch space
riskAdmin := shr(96, mload(0)) // correct padding
}
}

function _getStaticParams() private view returns (bytes memory) {
return
abi.encode(
Expand Down Expand Up @@ -416,6 +453,9 @@ contract AaveV3Ethereum_GHOCCIP150Upgrade_20241021_Test is ProtocolV3TestBase {
assertEq(ITypeAndVersion(ON_RAMP_1_5).typeAndVersion(), 'EVM2EVMOnRamp 1.5.0');
assertEq(ITypeAndVersion(OFF_RAMP_1_2).typeAndVersion(), 'EVM2EVMOffRamp 1.2.0');
assertEq(ITypeAndVersion(OFF_RAMP_1_5).typeAndVersion(), 'EVM2EVMOffRamp 1.5.0');

assertEq(GHO_CCIP_STEWARD.GHO_TOKEN(), MiscEthereum.GHO_TOKEN);
assertEq(GHO_CCIP_STEWARD.GHO_TOKEN_POOL(), address(ghoTokenPool));
}

function _getOutboundRefillTime(uint256 amount) private view returns (uint256) {
Expand Down
51 changes: 51 additions & 0 deletions src/interfaces/IGhoCcipSteward.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IGhoCcipSteward {
/**
* @notice Updates the CCIP bridge limit
* @dev Only callable by Risk Council
* @param newBridgeLimit The new desired bridge limit
*/
function updateBridgeLimit(uint256 newBridgeLimit) external;

/**
* @notice Updates the CCIP rate limit config
* @dev Only callable by Risk Council
* @dev Rate limit update must be consistent with other pools' rate limit
* @param remoteChainSelector The remote chain selector for which the rate limits apply.
* @param outboundEnabled True if the outbound rate limiter is enabled.
* @param outboundCapacity The outbound rate limiter capacity.
* @param outboundRate The outbound rate limiter rate.
* @param inboundEnabled True if the inbound rate limiter is enabled.
* @param inboundCapacity The inbound rate limiter capacity.
* @param inboundRate The inbound rate limiter rate.
*/
function updateRateLimit(
uint64 remoteChainSelector,
bool outboundEnabled,
uint128 outboundCapacity,
uint128 outboundRate,
bool inboundEnabled,
uint128 inboundCapacity,
uint128 inboundRate
) external;

/**
* @notice Returns the minimum delay that must be respected between parameters update.
* @return The minimum delay between parameter updates (in seconds)
*/
function MINIMUM_DELAY() external view returns (uint256);

/**
* @notice Returns the address of the Gho Token
* @return The address of the GhoToken
*/
function GHO_TOKEN() external view returns (address);

/**
* @notice Returns the address of the Gho CCIP Token Pool
* @return The address of the Gho CCIP Token Pool
*/
function GHO_TOKEN_POOL() external view returns (address);
}

0 comments on commit bf4f3e5

Please sign in to comment.