Skip to content

Commit

Permalink
fix: token pool storage layout
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Nov 1, 2024
1 parent c2daa1c commit d7a845d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import {IRouter} from "../../interfaces/IRouter.sol";
/// - Implementation of Initializable to allow upgrades
/// - Move of allowlist and router definition to initialization stage
/// - Inclusion of rate limit admin who may configure rate limits in addition to owner
contract UpgradeableBurnMintTokenPool is UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion, Initializable {
contract UpgradeableBurnMintTokenPool is Initializable, UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion {
string public constant override typeAndVersion = "BurnMintTokenPool 1.5.0";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {IRouter} from "../../interfaces/IRouter.sol";
/// - Implementation of Initializable to allow upgrades
/// - Move of allowlist and router definition to initialization stage
/// - Addition of a bridge limit to regulate the maximum amount of tokens that can be transferred out (burned/locked)
contract UpgradeableLockReleaseTokenPool is UpgradeableTokenPool, ILiquidityContainer, ITypeAndVersion, Initializable {
contract UpgradeableLockReleaseTokenPool is Initializable, UpgradeableTokenPool, ILiquidityContainer, ITypeAndVersion {
using SafeERC20 for IERC20;

error InsufficientLiquidity();
Expand Down Expand Up @@ -58,14 +58,12 @@ contract UpgradeableLockReleaseTokenPool is UpgradeableTokenPool, ILiquidityCont
// / @param allowlistEnabled True if pool is set to access-controlled mode, false otherwise
// / @param acceptLiquidity True if the pool accepts liquidity, false otherwise
constructor(
IERC20 token,
address token,
address rmnProxy,
bool allowListEnabled,
bool acceptLiquidity
) UpgradeableTokenPool(token, rmnProxy, allowListEnabled) {
) UpgradeableTokenPool(IERC20(token), rmnProxy, allowListEnabled) {
i_acceptLiquidity = acceptLiquidity;

_disableInitializers();
}

/// @dev Initializer
Expand Down Expand Up @@ -96,7 +94,6 @@ contract UpgradeableLockReleaseTokenPool is UpgradeableTokenPool, ILiquidityCont
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
// Increase bridged amount because tokens are leaving the source chain
if ((s_currentBridged += lockOrBurnIn.amount) > s_bridgeLimit) revert BridgeLimitExceeded(s_bridgeLimit);

_validateLockOrBurn(lockOrBurnIn);

emit Locked(msg.sender, lockOrBurnIn.amount);
Expand All @@ -109,13 +106,13 @@ contract UpgradeableLockReleaseTokenPool is UpgradeableTokenPool, ILiquidityCont
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
_validateReleaseOrMint(releaseOrMintIn);

// This should never occur. Amount should never exceed the current bridged amount
if (releaseOrMintIn.amount > s_currentBridged) revert NotEnoughBridgedAmount();
// Reduce bridged amount because tokens are back to source chain
s_currentBridged -= releaseOrMintIn.amount;

_validateReleaseOrMint(releaseOrMintIn);

// Release to the recipient
getToken().safeTransfer(releaseOrMintIn.receiver, releaseOrMintIn.amount);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```diff
diff --git a/src/v0.8/ccip/pools/BurnMintTokenPool.sol b/src/v0.8/ccip/pools/GHO/UpgradeableBurnMintTokenPool.sol
index c48c8e51fb..df35f45684 100644
index c48c8e51fb..007f9e4f14 100644
--- a/src/v0.8/ccip/pools/BurnMintTokenPool.sol
+++ b/src/v0.8/ccip/pools/GHO/UpgradeableBurnMintTokenPool.sol
@@ -1,29 +1,56 @@
Expand Down Expand Up @@ -35,24 +35,26 @@ index c48c8e51fb..df35f45684 100644
+/// - Implementation of Initializable to allow upgrades
+/// - Move of allowlist and router definition to initialization stage
+/// - Inclusion of rate limit admin who may configure rate limits in addition to owner
+contract UpgradeableBurnMintTokenPool is UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion, Initializable {
+contract UpgradeableBurnMintTokenPool is Initializable, UpgradeableBurnMintTokenPoolAbstract, ITypeAndVersion {
string public constant override typeAndVersion = "BurnMintTokenPool 1.5.0";

+ /// @dev Constructor
+ /// @param token The bridgeable token that is managed by this pool.
+ /// @param rmnProxy The address of the arm proxy
+ /// @param allowlistEnabled True if pool is set to access-controlled mode, false otherwise
constructor(
IBurnMintERC20 token,
- IBurnMintERC20 token,
- address[] memory allowlist,
+ address token,
address rmnProxy,
- address router
- ) TokenPool(token, allowlist, rmnProxy, router) {}
+ bool allowlistEnabled
+ ) UpgradeableTokenPool(token, rmnProxy, allowlistEnabled) {
+ ) UpgradeableTokenPool(IBurnMintERC20(token), rmnProxy, allowlistEnabled) {
+ _disableInitializers();
+ }
+

- /// @inheritdoc BurnMintTokenPoolAbstract
+ /// @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
Expand All @@ -70,8 +72,7 @@ index c48c8e51fb..df35f45684 100644
+ _applyAllowListUpdates(new address[](0), allowlist);
+ }
+ }

- /// @inheritdoc BurnMintTokenPoolAbstract
+
+ /// @inheritdoc UpgradeableBurnMintTokenPoolAbstract
function _burn(uint256 amount) internal virtual override {
IBurnMintERC20(address(i_token)).burn(amount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
```diff
diff --git a/src/v0.8/ccip/pools/LockReleaseTokenPool.sol b/src/v0.8/ccip/pools/GHO/UpgradeableLockReleaseTokenPool.sol
index 3a4a4aef6d..70adc38030 100644
index 3a4a4aef6d..6165ea6bc0 100644
--- a/src/v0.8/ccip/pools/LockReleaseTokenPool.sol
+++ b/src/v0.8/ccip/pools/GHO/UpgradeableLockReleaseTokenPool.sol
@@ -1,24 +1,35 @@
Expand Down Expand Up @@ -38,7 +38,7 @@ index 3a4a4aef6d..70adc38030 100644
+/// - Implementation of Initializable to allow upgrades
+/// - Move of allowlist and router definition to initialization stage
+/// - Addition of a bridge limit to regulate the maximum amount of tokens that can be transferred out (burned/locked)
+contract UpgradeableLockReleaseTokenPool is UpgradeableTokenPool, ILiquidityContainer, ITypeAndVersion, Initializable {
+contract UpgradeableLockReleaseTokenPool is Initializable, UpgradeableTokenPool, ILiquidityContainer, ITypeAndVersion {
using SafeERC20 for IERC20;

error InsufficientLiquidity();
Expand All @@ -51,7 +51,7 @@ index 3a4a4aef6d..70adc38030 100644

event LiquidityTransferred(address indexed from, uint256 amount);

@@ -32,14 +43,50 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
@@ -32,21 +43,57 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
/// @notice The address of the rebalancer.
address internal s_rebalancer;

Expand All @@ -70,20 +70,19 @@ index 3a4a4aef6d..70adc38030 100644
+ // / @param allowlistEnabled True if pool is set to access-controlled mode, false otherwise
+ // / @param acceptLiquidity True if the pool accepts liquidity, false otherwise
constructor(
IERC20 token,
- IERC20 token,
- address[] memory allowlist,
+ address token,
address rmnProxy,
- bool acceptLiquidity,
- address router
- ) TokenPool(token, allowlist, rmnProxy, router) {
+ bool allowListEnabled,
+ bool acceptLiquidity
+ ) UpgradeableTokenPool(token, rmnProxy, allowListEnabled) {
+ ) UpgradeableTokenPool(IERC20(token), rmnProxy, allowListEnabled) {
i_acceptLiquidity = acceptLiquidity;
+
+ _disableInitializers();
+ }
+
}

+ /// @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
Expand All @@ -103,32 +102,31 @@ index 3a4a4aef6d..70adc38030 100644
+ s_router = IRouter(router);
+ if (i_allowlistEnabled) _applyAllowListUpdates(new address[](0), allowlist);
+ s_bridgeLimit = bridgeLimit;
}

+ }
+
/// @notice Locks the token in the pool
@@ -47,6 +94,9 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
+ // Increase bridged amount because tokens are leaving the source chain
+ if ((s_currentBridged += lockOrBurnIn.amount) > s_bridgeLimit) revert BridgeLimitExceeded(s_bridgeLimit);
+
_validateLockOrBurn(lockOrBurnIn);

emit Locked(msg.sender, lockOrBurnIn.amount);
@@ -59,6 +109,11 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
@@ -61,6 +108,11 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
_validateReleaseOrMint(releaseOrMintIn);

+ // This should never occur. Amount should never exceed the current bridged amount
+ if (releaseOrMintIn.amount > s_currentBridged) revert NotEnoughBridgedAmount();
+ // Reduce bridged amount because tokens are back to source chain
+ s_currentBridged -= releaseOrMintIn.amount;
+
_validateReleaseOrMint(releaseOrMintIn);

// Release to the recipient
@@ -69,6 +124,38 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
getToken().safeTransfer(releaseOrMintIn.receiver, releaseOrMintIn.amount);

@@ -69,6 +121,38 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
return Pool.ReleaseOrMintOutV1({destinationAmount: releaseOrMintIn.amount});
}

Expand Down Expand Up @@ -167,7 +165,7 @@ index 3a4a4aef6d..70adc38030 100644
// @inheritdoc IERC165
function supportsInterface(bytes4 interfaceId) public pure virtual override returns (bool) {
return interfaceId == type(ILiquidityContainer).interfaceId || super.supportsInterface(interfaceId);
@@ -80,6 +167,11 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
@@ -80,6 +164,11 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
return s_rebalancer;
}

Expand All @@ -179,7 +177,7 @@ index 3a4a4aef6d..70adc38030 100644
/// @notice Sets the LiquidityManager address.
/// @dev Only callable by the owner.
function setRebalancer(address rebalancer) external onlyOwner {
@@ -124,7 +216,7 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
@@ -124,7 +213,7 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion
/// @param from The address of the old pool.
/// @param amount The amount of liquidity to transfer.
function transferLiquidity(address from, uint256 amount) external onlyOwner {
Expand Down

0 comments on commit d7a845d

Please sign in to comment.