Skip to content

Commit

Permalink
test: separate v1 and v2
Browse files Browse the repository at this point in the history
  • Loading branch information
CheyenneAtapour committed Jul 18, 2024
1 parent 59a6cb5 commit 95faba9
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 272 deletions.
61 changes: 2 additions & 59 deletions contracts/src/v0.8/ccip/pools/GHO/UpgradeableBurnMintTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {IBurnMintERC20} from "../../../shared/token/ERC20/IBurnMintERC20.sol";

import {UpgradeableTokenPool} from "./UpgradeableTokenPool.sol";
import {UpgradeableBurnMintTokenPoolAbstract} from "./UpgradeableBurnMintTokenPoolAbstract.sol";
import {RateLimiter} from "../../libraries/RateLimiter.sol";

import {IRouter} from "../../interfaces/IRouter.sol";

Expand All @@ -19,45 +18,17 @@ import {IRouter} from "../../interfaces/IRouter.sol";
/// - Implementation of Initializable to allow upgrades
/// - Move of allowlist and router definition to initialization stage
contract UpgradeableBurnMintTokenPool is Initializable, UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion {
error Unauthorized(address caller);

string public constant override typeAndVersion = "BurnMintTokenPool 1.4.0";

/// @dev The unique burn mint pool flag to signal through EIP 165.
bytes4 private constant BURN_MINT_INTERFACE_ID = bytes4(keccak256("BurnMintTokenPool"));

/// @dev Whether or not the pool accepts liquidity.
/// External liquidity is not required when there is one canonical token deployed to a chain,
/// and CCIP is facilitating mint/burn on all the other chains, in which case the invariant
/// balanceOf(pool) on home chain == sum(totalSupply(mint/burn "wrapped" token) on all remote chains) should always hold
bool internal immutable i_acceptLiquidity;
/// @notice The address of the rebalancer.
address internal s_rebalancer;
/// @notice The address of the rate limiter admin.
/// @dev Can be address(0) if none is configured.
address internal s_rateLimitAdmin;

/// @notice Maximum amount of tokens that can be bridged to other chains
uint256 private s_bridgeLimit;
/// @notice Amount of tokens bridged (transferred out)
/// @dev Must always be equal to or below the bridge limit
uint256 private s_currentBridged;
/// @notice The address of the bridge limit admin.
/// @dev Can be address(0) if none is configured.
address internal s_bridgeLimitAdmin;

/// @dev Constructor
/// @param token The bridgeable token that is managed by this pool.
/// @param armProxy The address of the arm proxy
/// @param allowlistEnabled True if pool is set to access-controlled mode, false otherwise
constructor(
address token,
address armProxy,
bool allowlistEnabled,
bool acceptLiquidity
) UpgradeableTokenPool(IBurnMintERC20(token), armProxy, allowlistEnabled) {
i_acceptLiquidity = acceptLiquidity;
}
bool allowlistEnabled
) UpgradeableTokenPool(IBurnMintERC20(token), armProxy, allowlistEnabled) {}

/// @dev Initializer
/// @dev The address passed as `owner` must accept ownership after initialization.
Expand All @@ -78,34 +49,6 @@ contract UpgradeableBurnMintTokenPool is Initializable, UpgradeableBurnMintToken
}
}

/// @notice Sets the rate limiter admin address.
/// @dev Only callable by the owner.
/// @param rateLimitAdmin The new rate limiter admin address.
function setRateLimitAdmin(address rateLimitAdmin) external onlyOwner {
s_rateLimitAdmin = rateLimitAdmin;
}

/// @notice Gets the rate limiter admin address.
function getRateLimitAdmin() external view returns (address) {
return s_rateLimitAdmin;
}

/// @notice Sets the rate limiter admin address.
/// @dev Only callable by the owner or the rate limiter admin. NOTE: overwrites the normal
/// onlyAdmin check in the base implementation to also allow the rate limiter admin.
/// @param remoteChainSelector The remote chain selector for which the rate limits apply.
/// @param outboundConfig The new outbound rate limiter config.
/// @param inboundConfig The new inbound rate limiter config.
function setChainRateLimiterConfig(
uint64 remoteChainSelector,
RateLimiter.Config memory outboundConfig,
RateLimiter.Config memory inboundConfig
) external override {
if (msg.sender != s_rateLimitAdmin && msg.sender != owner()) revert Unauthorized(msg.sender);

_setRateLimitConfig(remoteChainSelector, outboundConfig, inboundConfig);
}

/// @inheritdoc UpgradeableBurnMintTokenPoolAbstract
function _burn(uint256 amount) internal virtual override {
IBurnMintERC20(address(i_token)).burn(amount);
Expand Down

This file was deleted.

113 changes: 113 additions & 0 deletions contracts/src/v0.8/ccip/pools/GHO/UpgradeableBurnMintTokenPoolV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {Initializable} from "solidity-utils/contracts/transparent-proxy/Initializable.sol";

import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
import {IBurnMintERC20} from "../../../shared/token/ERC20/IBurnMintERC20.sol";

import {UpgradeableTokenPool} from "./UpgradeableTokenPool.sol";
import {UpgradeableBurnMintTokenPoolAbstract} from "./UpgradeableBurnMintTokenPoolAbstract.sol";
import {RateLimiter} from "../../libraries/RateLimiter.sol";

import {IRouter} from "../../interfaces/IRouter.sol";

/// @title UpgradeableBurnMintTokenPoolV2
/// @author Aave Labs
/// @notice Upgradeable version of Chainlink's CCIP BurnMintTokenPool
/// @dev Contract adaptations:
/// - Implementation of Initializable to allow upgrades
/// - Move of allowlist and router definition to initialization stage
contract UpgradeableBurnMintTokenPoolV2 is Initializable, UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion {
error Unauthorized(address caller);

string public constant override typeAndVersion = "BurnMintTokenPool 1.4.0";

/// @dev The unique burn mint pool flag to signal through EIP 165.
bytes4 private constant BURN_MINT_INTERFACE_ID = bytes4(keccak256("BurnMintTokenPool"));

/// @dev Whether or not the pool accepts liquidity.
/// External liquidity is not required when there is one canonical token deployed to a chain,
/// and CCIP is facilitating mint/burn on all the other chains, in which case the invariant
/// balanceOf(pool) on home chain == sum(totalSupply(mint/burn "wrapped" token) on all remote chains) should always hold
bool internal immutable i_acceptLiquidity;
/// @notice The address of the rebalancer.
address internal s_rebalancer;
/// @notice The address of the rate limiter admin.
/// @dev Can be address(0) if none is configured.
address internal s_rateLimitAdmin;

/// @notice Maximum amount of tokens that can be bridged to other chains
uint256 private s_bridgeLimit;
/// @notice Amount of tokens bridged (transferred out)
/// @dev Must always be equal to or below the bridge limit
uint256 private s_currentBridged;
/// @notice The address of the bridge limit admin.
/// @dev Can be address(0) if none is configured.
address internal s_bridgeLimitAdmin;

/// @dev Constructor
/// @param token The bridgeable token that is managed by this pool.
/// @param armProxy The address of the arm proxy
/// @param allowlistEnabled True if pool is set to access-controlled mode, false otherwise
constructor(
address token,
address armProxy,
bool allowlistEnabled,
bool acceptLiquidity
) UpgradeableTokenPool(IBurnMintERC20(token), armProxy, allowlistEnabled) {
i_acceptLiquidity = acceptLiquidity;
}

/// @dev Initializer
/// @dev The address passed as `owner` must accept ownership after initialization.
/// @dev The `allowlist` is only effective if pool is set to access-controlled mode
/// @param owner The address of the owner
/// @param allowlist A set of addresses allowed to trigger lockOrBurn as original senders
/// @param router The address of the router
function initialize(address owner, address[] memory allowlist, address router) public virtual initializer {
if (owner == address(0)) revert ZeroAddressNotAllowed();
if (router == address(0)) revert ZeroAddressNotAllowed();
_transferOwnership(owner);

s_router = IRouter(router);

// Pool can be set as permissioned or permissionless at deployment time only to save hot-path gas.
if (i_allowlistEnabled) {
_applyAllowListUpdates(new address[](0), allowlist);
}
}

/// @notice Sets the rate limiter admin address.
/// @dev Only callable by the owner.
/// @param rateLimitAdmin The new rate limiter admin address.
function setRateLimitAdmin(address rateLimitAdmin) external onlyOwner {
s_rateLimitAdmin = rateLimitAdmin;
}

/// @notice Gets the rate limiter admin address.
function getRateLimitAdmin() external view returns (address) {
return s_rateLimitAdmin;
}

/// @notice Sets the rate limiter admin address.
/// @dev Only callable by the owner or the rate limiter admin. NOTE: overwrites the normal
/// onlyAdmin check in the base implementation to also allow the rate limiter admin.
/// @param remoteChainSelector The remote chain selector for which the rate limits apply.
/// @param outboundConfig The new outbound rate limiter config.
/// @param inboundConfig The new inbound rate limiter config.
function setChainRateLimiterConfig(
uint64 remoteChainSelector,
RateLimiter.Config memory outboundConfig,
RateLimiter.Config memory inboundConfig
) external override {
if (msg.sender != s_rateLimitAdmin && msg.sender != owner()) revert Unauthorized(msg.sender);

_setRateLimitConfig(remoteChainSelector, outboundConfig, inboundConfig);
}

/// @inheritdoc UpgradeableBurnMintTokenPoolAbstract
function _burn(uint256 amount) internal virtual override {
IBurnMintERC20(address(i_token)).burn(amount);
}
}
16 changes: 8 additions & 8 deletions contracts/src/v0.8/ccip/test/pools/GHO/GhoBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {TransparentUpgradeableProxy} from "solidity-utils/contracts/transparent-
import {IBurnMintERC20} from "../../../../shared/token/ERC20/IBurnMintERC20.sol";
import {IPool} from "../../../interfaces/pools/IPool.sol";
import {UpgradeableLockReleaseTokenPool} from "../../../pools/GHO/UpgradeableLockReleaseTokenPool.sol";
import {UpgradeableBurnMintTokenPoolV2} from "../../../pools/GHO/UpgradeableBurnMintTokenPoolV2.sol";
import {UpgradeableBurnMintTokenPool} from "../../../pools/GHO/UpgradeableBurnMintTokenPool.sol";
import {UpgradeableBurnMintTokenPoolOld} from "../../../pools/GHO/UpgradeableBurnMintTokenPoolOld.sol";
import {UpgradeableTokenPool} from "../../../pools/GHO/UpgradeableTokenPool.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {BaseTest} from "../../BaseTest.t.sol";
Expand All @@ -35,15 +35,15 @@ abstract contract GhoBaseTest is BaseTest {
bool capacityBelowLevelUpdate;
}

function _deployUpgradeableBurnMintTokenPool(
function _deployUpgradeableBurnMintTokenPoolV2(
address ghoToken,
address arm,
address router,
address owner,
address proxyAdmin
) internal returns (address) {
// Deploy BurnMintTokenPool for GHO token on source chain
UpgradeableBurnMintTokenPool tokenPoolImpl = new UpgradeableBurnMintTokenPool(ghoToken, arm, false, false);
UpgradeableBurnMintTokenPoolV2 tokenPoolImpl = new UpgradeableBurnMintTokenPoolV2(ghoToken, arm, false, false);
// proxy deploy and init
address[] memory emptyArray = new address[](0);
bytes memory tokenPoolInitParams = abi.encodeWithSignature(
Expand All @@ -60,21 +60,21 @@ abstract contract GhoBaseTest is BaseTest {
// Manage ownership
vm.stopPrank();
vm.prank(owner);
UpgradeableBurnMintTokenPool(address(tokenPoolProxy)).acceptOwnership();
UpgradeableBurnMintTokenPoolV2(address(tokenPoolProxy)).acceptOwnership();
vm.startPrank(OWNER);

return address(tokenPoolProxy);
}

function _deployUpgradeableBurnMintTokenPoolOld(
function _deployUpgradeableBurnMintTokenPool(
address ghoToken,
address arm,
address router,
address owner,
address proxyAdmin
) internal returns (address) {
// Deploy BurnMintTokenPool for GHO token on source chain
UpgradeableBurnMintTokenPoolOld tokenPoolImpl = new UpgradeableBurnMintTokenPoolOld(ghoToken, arm, false);
UpgradeableBurnMintTokenPool tokenPoolImpl = new UpgradeableBurnMintTokenPool(ghoToken, arm, false);
// proxy deploy and init
address[] memory emptyArray = new address[](0);
bytes memory tokenPoolInitParams = abi.encodeWithSignature(
Expand All @@ -90,7 +90,7 @@ abstract contract GhoBaseTest is BaseTest {
);
// Manage ownership
changePrank(owner);
UpgradeableBurnMintTokenPoolOld(address(tokenPoolProxy)).acceptOwnership();
UpgradeableBurnMintTokenPool(address(tokenPoolProxy)).acceptOwnership();
vm.stopPrank();

return address(tokenPoolProxy);
Expand All @@ -103,7 +103,7 @@ abstract contract GhoBaseTest is BaseTest {
address proxyAdmin
) internal {
// Deploy BurnMintTokenPool for GHO token on source chain
UpgradeableBurnMintTokenPool tokenPoolImpl = new UpgradeableBurnMintTokenPool(ghoToken, arm, false, false);
UpgradeableBurnMintTokenPoolV2 tokenPoolImpl = new UpgradeableBurnMintTokenPoolV2(ghoToken, arm, false, false);
// proxy upgrade
vm.prank(proxyAdmin);
TransparentUpgradeableProxy(tokenPoolProxy).upgradeTo(address(tokenPoolImpl));
Expand Down
Loading

0 comments on commit 95faba9

Please sign in to comment.