Skip to content

Commit

Permalink
Merge remote-tracking branch 'aave-orig/feat/gho-token-pool' into cer…
Browse files Browse the repository at this point in the history
…tora
  • Loading branch information
nisnislevi committed May 22, 2024
2 parents eef1b61 + a666880 commit 53397f7
Show file tree
Hide file tree
Showing 13 changed files with 3,184 additions and 3 deletions.
24 changes: 21 additions & 3 deletions contracts/src/v0.8/ccip/pools/UpgradeableLockReleaseTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract UpgradeableLockReleaseTokenPool is
error Unauthorized(address caller);

error BridgeLimitExceeded(uint256 bridgeLimit);
error InvalidAmountToBurn();
error NotEnoughBridgedAmount();
event BridgeLimitUpdated(uint256 oldBridgeLimit, uint256 newBridgeLimit);

string public constant override typeAndVersion = "LockReleaseTokenPool 1.4.0";
Expand All @@ -57,6 +57,9 @@ contract UpgradeableLockReleaseTokenPool is
/// @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.
Expand Down Expand Up @@ -138,7 +141,7 @@ contract UpgradeableLockReleaseTokenPool is
bytes memory
) external virtual override onlyOffRamp(remoteChainSelector) whenHealthy {
// This should never occur. Amount should never exceed the current bridged amount
if (amount > s_currentBridged) revert InvalidAmountToBurn();
if (amount > s_currentBridged) revert NotEnoughBridgedAmount();
// Reduce bridged amount because tokens are back to source chain
s_currentBridged -= amount;

Expand Down Expand Up @@ -180,13 +183,23 @@ contract UpgradeableLockReleaseTokenPool is
}

/// @notice Sets the bridge limit, the maximum amount of tokens that can be bridged out
/// @dev Only callable by the owner or the bridge limit admin.
/// @dev Bridge limit changes should be carefully managed, specially when reducing below the current bridged amount
/// @param newBridgeLimit The new bridge limit
function setBridgeLimit(uint256 newBridgeLimit) external onlyOwner {
function setBridgeLimit(uint256 newBridgeLimit) external {
if (msg.sender != s_bridgeLimitAdmin && msg.sender != owner()) revert Unauthorized(msg.sender);
uint256 oldBridgeLimit = s_bridgeLimit;
s_bridgeLimit = newBridgeLimit;
emit BridgeLimitUpdated(oldBridgeLimit, newBridgeLimit);
}

/// @notice Sets the bridge limit admin address.
/// @dev Only callable by the owner.
/// @param bridgeLimitAdmin The new bridge limit admin address.
function setBridgeLimitAdmin(address bridgeLimitAdmin) external onlyOwner {
s_bridgeLimitAdmin = bridgeLimitAdmin;
}

/// @notice Gets the bridge limit
/// @return The maximum amount of tokens that can be transferred out to other chains
function getBridgeLimit() external view virtual returns (uint256) {
Expand All @@ -204,6 +217,11 @@ contract UpgradeableLockReleaseTokenPool is
return s_rateLimitAdmin;
}

/// @notice Gets the bridge limiter admin address.
function getBridgeLimitAdmin() external view returns (address) {
return s_bridgeLimitAdmin;
}

/// @notice Checks if the pool can accept liquidity.
/// @return true if the pool can accept liquidity, false otherwise.
function canAcceptLiquidity() external view returns (bool) {
Expand Down
83 changes: 83 additions & 0 deletions contracts/src/v0.8/ccip/script.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {Script, console2} from 'forge-std/Script.sol';
import {TransparentUpgradeableProxy} from "solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol";
import {UpgradeableLockReleaseTokenPool} from "./pools/UpgradeableLockReleaseTokenPool.sol";
import {UpgradeableBurnMintTokenPool} from "./pools/UpgradeableBurnMintTokenPool.sol";
import {UpgradeableTokenPool} from "./pools/UpgradeableTokenPool.sol";


contract DeployLockReleaseTokenPool is Script {
// ETH SEPOLIA - 11155111
address GHO_TOKEN = 0xc4bF5CbDaBE595361438F8c6a187bDc330539c60;
address PROXY_ADMIN = 0xfA0e305E0f46AB04f00ae6b5f4560d61a2183E00;
address ARM_PROXY = 0xba3f6251de62dED61Ff98590cB2fDf6871FbB991;
address ROUTER = 0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59;
address TOKEN_POOL_OWNER = 0xa4b184737418B3014b3B1b1f0bE6700Bd9640FfE;

// ARB SEPOLIA - 421614
// address GHO_TOKEN = 0xb13Cfa6f8B2Eed2C37fB00fF0c1A59807C585810;
// address PROXY_ADMIN = 0xfA0e305E0f46AB04f00ae6b5f4560d61a2183E00;
// address ARM_PROXY = 0x9527E2d01A3064ef6b50c1Da1C0cC523803BCFF2;
// address ROUTER = 0x2a9C5afB0d0e4BAb2BCdaE109EC4b0c4Be15a165;
// address TOKEN_POOL_OWNER = 0xa4b184737418B3014b3B1b1f0bE6700Bd9640FfE;

// BASE SEPOLIA - 84532
// address GHO_TOKEN = 0x7CFa3f3d1cded0Da930881c609D4Dbf0012c14Bb;
// address PROXY_ADMIN = 0xfA0e305E0f46AB04f00ae6b5f4560d61a2183E00;
// address ARM_PROXY = 0x99360767a4705f68CcCb9533195B761648d6d807;
// address ROUTER = 0xD3b06cEbF099CE7DA4AcCf578aaebFDBd6e88a93;
// address TOKEN_POOL_OWNER = 0xa4b184737418B3014b3B1b1f0bE6700Bd9640FfE;

// FUJI - 43113
// address GHO_TOKEN = 0x9c04928Cc678776eC1C1C0E46ecC03a5F47A7723;
// address PROXY_ADMIN = 0xfA0e305E0f46AB04f00ae6b5f4560d61a2183E00;
// address ARM_PROXY = 0xAc8CFc3762a979628334a0E4C1026244498E821b;
// address ROUTER = 0xF694E193200268f9a4868e4Aa017A0118C9a8177;
// address TOKEN_POOL_OWNER = 0xa4b184737418B3014b3B1b1f0bE6700Bd9640FfE;

function run() external {
console2.log('Block Number: ', block.number);
vm.startBroadcast();

UpgradeableLockReleaseTokenPool tokenPoolImpl = new UpgradeableLockReleaseTokenPool(GHO_TOKEN, ARM_PROXY, false, true);
// Imple init
address[] memory emptyArray = new address[](0);
tokenPoolImpl.initialize(TOKEN_POOL_OWNER, emptyArray, ROUTER, 10e18);
// proxy deploy and init
bytes memory tokenPoolInitParams = abi.encodeWithSignature(
"initialize(address,address[],address,uint256)",
TOKEN_POOL_OWNER,
emptyArray,
ROUTER,
10e18
);
TransparentUpgradeableProxy tokenPoolProxy = new TransparentUpgradeableProxy(
address(tokenPoolImpl),
PROXY_ADMIN,
tokenPoolInitParams
);

vm.stopBroadcast();
// Manage ownership
// UpgradeableLockReleaseTokenPool(address(tokenPoolProxy)).acceptOwnership();

}
}

contract Accept is Script {

function run() external {
console2.log('Block Number: ', block.number);
vm.startBroadcast();

console2.log(UpgradeableLockReleaseTokenPool(0x50A715d63bDcd5455a3308932a624263d170Dd74).getBridgeLimit());

// Manage ownership
UpgradeableLockReleaseTokenPool(0x50A715d63bDcd5455a3308932a624263d170Dd74).acceptOwnership();
vm.stopBroadcast();

}
}

92 changes: 92 additions & 0 deletions contracts/src/v0.8/ccip/test/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {Test, stdError} from "forge-std/Test.sol";
import {MockARM} from "./mocks/MockARM.sol";
import {StructFactory} from "./StructFactory.sol";

import {TransparentUpgradeableProxy} from "solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol";
import {UpgradeableLockReleaseTokenPool} from "../pools/UpgradeableLockReleaseTokenPool.sol";
import {UpgradeableBurnMintTokenPool} from "../pools/UpgradeableBurnMintTokenPool.sol";
import {IBurnMintERC20} from "../../shared/token/ERC20/IBurnMintERC20.sol";

contract BaseTest is Test, StructFactory {
bool private s_baseTestInitialized;

Expand All @@ -26,4 +31,91 @@ contract BaseTest is Test, StructFactory {

s_mockARM = new MockARM();
}

function _deployUpgradeableBurnMintTokenPool(
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);
// Imple init
address[] memory emptyArray = new address[](0);
tokenPoolImpl.initialize(owner, emptyArray, router);
// proxy deploy and init
bytes memory tokenPoolInitParams = abi.encodeWithSignature(
"initialize(address,address[],address)",
owner,
emptyArray,
router
);
TransparentUpgradeableProxy tokenPoolProxy = new TransparentUpgradeableProxy(
address(tokenPoolImpl),
proxyAdmin,
tokenPoolInitParams
);
// Manage ownership
vm.stopPrank();
vm.prank(owner);
UpgradeableBurnMintTokenPool(address(tokenPoolProxy)).acceptOwnership();
vm.startPrank(OWNER);

return address(tokenPoolProxy);
}

function _deployUpgradeableLockReleaseTokenPool(
address ghoToken,
address arm,
address router,
address owner,
uint256 bridgeLimit,
address proxyAdmin
) internal returns (address) {
UpgradeableLockReleaseTokenPool tokenPoolImpl = new UpgradeableLockReleaseTokenPool(ghoToken, arm, false, true);
// Imple init
address[] memory emptyArray = new address[](0);
tokenPoolImpl.initialize(owner, emptyArray, router, bridgeLimit);
// proxy deploy and init
bytes memory tokenPoolInitParams = abi.encodeWithSignature(
"initialize(address,address[],address,uint256)",
owner,
emptyArray,
router,
bridgeLimit
);
TransparentUpgradeableProxy tokenPoolProxy = new TransparentUpgradeableProxy(
address(tokenPoolImpl),
proxyAdmin,
tokenPoolInitParams
);

// Manage ownership
vm.stopPrank();
vm.prank(owner);
UpgradeableLockReleaseTokenPool(address(tokenPoolProxy)).acceptOwnership();
vm.startPrank(OWNER);

return address(tokenPoolProxy);
}

function _inflateFacilitatorLevel(address tokenPool, address ghoToken, uint256 amount) internal {
vm.stopPrank();
vm.prank(tokenPool);
IBurnMintERC20(ghoToken).mint(address(0), amount);
}

function _getProxyAdminAddress(address proxy) internal view returns (address) {
bytes32 ERC1967_ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
bytes32 adminSlot = vm.load(proxy, ERC1967_ADMIN_SLOT);
return address(uint160(uint256(adminSlot)));
}

function _getProxyImplementationAddress(address proxy) internal view returns (address) {
bytes32 ERC1967_IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 implSlot = vm.load(proxy, ERC1967_IMPLEMENTATION_SLOT);
return address(uint160(uint256(implSlot)));
}

}
36 changes: 36 additions & 0 deletions contracts/src/v0.8/ccip/test/mocks/MockUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {VersionedInitializable} from "../../pools/VersionedInitializable.sol";

/**
* @dev Mock contract to test upgrades, not to be used in production.
*/
contract MockUpgradeable is VersionedInitializable {
/**
* @dev Constructor
*/
constructor() {
// Intentionally left bank
}

/**
* @dev Initializer
*/
function initialize() public initializer {
// Intentionally left bank
}

/**
* @notice Returns the revision number
* @return The revision number
*/
function REVISION() public pure returns (uint256) {
return 2;
}

/// @inheritdoc VersionedInitializable
function getRevision() internal pure virtual override returns (uint256) {
return REVISION();
}
}
19 changes: 19 additions & 0 deletions contracts/src/v0.8/ccip/test/pools/End2End.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.19;

import "../helpers/MerkleHelper.sol";
import "../commitStore/CommitStore.t.sol";
import "../onRamp/EVM2EVMOnRampSetup.t.sol";
import "../offRamp/EVM2EVMOffRampSetup.t.sol";

contract E2E is EVM2EVMOnRampSetup, CommitStoreSetup, EVM2EVMOffRampSetup {
using Internal for Internal.EVM2EVMMessage;

function setUp() public virtual override(EVM2EVMOnRampSetup, CommitStoreSetup, EVM2EVMOffRampSetup) {
EVM2EVMOnRampSetup.setUp();
CommitStoreSetup.setUp();
EVM2EVMOffRampSetup.setUp();

deployOffRamp(s_commitStore, s_destRouter, address(0));
}
}
Loading

0 comments on commit 53397f7

Please sign in to comment.