-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add additional safety checks and add new token pool type
- Loading branch information
1 parent
2a08e17
commit 72a0c6f
Showing
5 changed files
with
177 additions
and
27 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
contracts/src/v0.8/ccip/pools/USDC/BurnMintWithLockReleaseFlagTokenPool.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import {IBurnMintERC20} from "../../../shared/token/ERC20/IBurnMintERC20.sol"; | ||
|
||
import {Pool} from "../../libraries/Pool.sol"; | ||
import {BurnMintTokenPool} from "../BurnMintTokenPool.sol"; | ||
|
||
contract BurnMintWithLockReleaseFlagTokenPool is BurnMintTokenPool { | ||
/// bytes4(keccak256("NO_CCTP_USE_LOCK_RELEASE")) | ||
bytes4 public constant LOCK_RELEASE_FLAG = 0xfa7c07de; | ||
|
||
constructor( | ||
IBurnMintERC20 token, | ||
address[] memory allowlist, | ||
address rmnProxy, | ||
address router | ||
) BurnMintTokenPool(token, allowlist, rmnProxy, router) {} | ||
|
||
/// @notice Burn the token in the pool | ||
/// @dev The _validateLockOrBurn check is an essential security check | ||
function lockOrBurn( | ||
Pool.LockOrBurnInV1 calldata lockOrBurnIn | ||
) external virtual override returns (Pool.LockOrBurnOutV1 memory) { | ||
_validateLockOrBurn(lockOrBurnIn); | ||
|
||
_burn(lockOrBurnIn.amount); | ||
|
||
emit Burned(msg.sender, lockOrBurnIn.amount); | ||
|
||
return Pool.LockOrBurnOutV1({ | ||
destTokenAddress: getRemoteToken(lockOrBurnIn.remoteChainSelector), | ||
destPoolData: abi.encode(LOCK_RELEASE_FLAG) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
contracts/src/v0.8/ccip/test/pools/BurnMintWithLockReleaseFlagTokenPool.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.24; | ||
|
||
import {Pool} from "../../libraries/Pool.sol"; | ||
import {RateLimiter} from "../../libraries/RateLimiter.sol"; | ||
|
||
import {TokenPool} from "../../pools/TokenPool.sol"; | ||
import {BurnMintWithLockReleaseFlagTokenPool} from "../../pools/USDC/BurnMintWithLockReleaseFlagTokenPool.sol"; | ||
import {BurnMintSetup} from "./BurnMintSetup.t.sol"; | ||
|
||
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol"; | ||
|
||
contract BurnMintWithLockReleaseFlagTokenPoolSetup is BurnMintSetup { | ||
BurnMintWithLockReleaseFlagTokenPool internal s_pool; | ||
|
||
function setUp() public virtual override { | ||
BurnMintSetup.setUp(); | ||
|
||
s_pool = new BurnMintWithLockReleaseFlagTokenPool( | ||
s_burnMintERC677, new address[](0), address(s_mockRMN), address(s_sourceRouter) | ||
); | ||
s_burnMintERC677.grantMintAndBurnRoles(address(s_pool)); | ||
|
||
_applyChainUpdates(address(s_pool)); | ||
} | ||
} | ||
|
||
contract BurnMintWithLockReleaseFlagTokenPool_lockOrBurn is BurnMintWithLockReleaseFlagTokenPoolSetup { | ||
function test_Setup_Success() public view { | ||
assertEq(address(s_burnMintERC677), address(s_pool.getToken())); | ||
assertEq(address(s_mockRMN), s_pool.getRmnProxy()); | ||
assertEq(false, s_pool.getAllowListEnabled()); | ||
assertEq("BurnMintTokenPool 1.5.0", s_pool.typeAndVersion()); | ||
} | ||
|
||
function test_PoolBurn_CorrectReturnData_Success() public { | ||
uint256 burnAmount = 20_000e18; | ||
|
||
deal(address(s_burnMintERC677), address(s_pool), burnAmount); | ||
assertEq(s_burnMintERC677.balanceOf(address(s_pool)), burnAmount); | ||
|
||
vm.startPrank(s_burnMintOnRamp); | ||
|
||
vm.expectEmit(); | ||
emit RateLimiter.TokensConsumed(burnAmount); | ||
|
||
vm.expectEmit(); | ||
emit IERC20.Transfer(address(s_pool), address(0), burnAmount); | ||
|
||
vm.expectEmit(); | ||
emit TokenPool.Burned(address(s_burnMintOnRamp), burnAmount); | ||
|
||
bytes4 expectedSignature = bytes4(keccak256("burn(uint256)")); | ||
vm.expectCall(address(s_burnMintERC677), abi.encodeWithSelector(expectedSignature, burnAmount)); | ||
|
||
Pool.LockOrBurnOutV1 memory lockOrBurnOut = s_pool.lockOrBurn( | ||
Pool.LockOrBurnInV1({ | ||
originalSender: OWNER, | ||
receiver: bytes(""), | ||
amount: burnAmount, | ||
remoteChainSelector: DEST_CHAIN_SELECTOR, | ||
localToken: address(s_burnMintERC677) | ||
}) | ||
); | ||
|
||
assertEq(s_burnMintERC677.balanceOf(address(s_pool)), 0); | ||
|
||
assertEq(bytes4(lockOrBurnOut.destPoolData), s_pool.LOCK_RELEASE_FLAG()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters