-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCCIPv1_5ForkBurnMintPoolFork.t.sol
283 lines (225 loc) · 12 KB
/
CCIPv1_5ForkBurnMintPoolFork.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, Vm} from "forge-std/Test.sol";
import {CCIPLocalSimulatorFork, Register} from "../../../src/ccip/CCIPLocalSimulatorFork.sol";
import {BurnMintTokenPool, TokenPool} from "@chainlink/contracts-ccip/src/v0.8/ccip/pools/BurnMintTokenPool.sol";
import {LockReleaseTokenPool} from "@chainlink/contracts-ccip/src/v0.8/ccip/pools/LockReleaseTokenPool.sol"; // not used in this test
import {IBurnMintERC20} from "@chainlink/contracts-ccip/src/v0.8/shared/token/ERC20/IBurnMintERC20.sol";
import {RegistryModuleOwnerCustom} from
"@chainlink/contracts-ccip/src/v0.8/ccip/tokenAdminRegistry/RegistryModuleOwnerCustom.sol";
import {TokenAdminRegistry} from "@chainlink/contracts-ccip/src/v0.8/ccip/tokenAdminRegistry/TokenAdminRegistry.sol";
import {RateLimiter} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/RateLimiter.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {
ERC20,
ERC20Burnable,
IERC20
} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {AccessControl} from
"@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/access/AccessControl.sol";
contract MockERC20BurnAndMintToken is IBurnMintERC20, ERC20Burnable, AccessControl {
address internal immutable i_CCIPAdmin;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
constructor() ERC20("MockERC20BurnAndMintToken", "MTK") {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(MINTER_ROLE, msg.sender);
_grantRole(BURNER_ROLE, msg.sender);
i_CCIPAdmin = msg.sender;
}
function mint(address account, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(account, amount);
}
function burn(uint256 amount) public override(IBurnMintERC20, ERC20Burnable) onlyRole(BURNER_ROLE) {
super.burn(amount);
}
function burnFrom(address account, uint256 amount)
public
override(IBurnMintERC20, ERC20Burnable)
onlyRole(BURNER_ROLE)
{
super.burnFrom(account, amount);
}
function burn(address account, uint256 amount) public virtual override {
burnFrom(account, amount);
}
function getCCIPAdmin() public view returns (address) {
return i_CCIPAdmin;
}
}
contract CCIPv1_5BurnMintPoolFork is Test {
CCIPLocalSimulatorFork public ccipLocalSimulatorFork;
MockERC20BurnAndMintToken public mockERC20TokenEthSepolia;
MockERC20BurnAndMintToken public mockERC20TokenBaseSepolia;
BurnMintTokenPool public burnMintTokenPoolEthSepolia;
BurnMintTokenPool public burnMintTokenPoolBaseSepolia;
Register.NetworkDetails ethSepoliaNetworkDetails;
Register.NetworkDetails baseSepoliaNetworkDetails;
uint256 ethSepoliaFork;
uint256 baseSepoliaFork;
address alice;
function setUp() public {
alice = makeAddr("alice");
string memory ETHEREUM_SEPOLIA_RPC_URL = vm.envString("ETHEREUM_SEPOLIA_RPC_URL");
string memory BASE_SEPOLIA_RPC_URL = vm.envString("BASE_SEPOLIA_RPC_URL");
ethSepoliaFork = vm.createSelectFork(ETHEREUM_SEPOLIA_RPC_URL);
baseSepoliaFork = vm.createFork(BASE_SEPOLIA_RPC_URL);
ccipLocalSimulatorFork = new CCIPLocalSimulatorFork();
vm.makePersistent(address(ccipLocalSimulatorFork));
// Step 1) Deploy token on Ethereum Sepolia
vm.startPrank(alice);
mockERC20TokenEthSepolia = new MockERC20BurnAndMintToken();
vm.stopPrank();
// Step 2) Deploy token on Base Sepolia
vm.selectFork(baseSepoliaFork);
vm.startPrank(alice);
mockERC20TokenBaseSepolia = new MockERC20BurnAndMintToken();
vm.stopPrank();
}
function test_forkSupportNewCCIPToken() public {
// Step 3) Deploy BurnMintTokenPool on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
ethSepoliaNetworkDetails = ccipLocalSimulatorFork.getNetworkDetails(block.chainid);
address[] memory allowlist = new address[](0);
uint8 localTokenDecimals = 18;
vm.startPrank(alice);
burnMintTokenPoolEthSepolia = new BurnMintTokenPool(
IBurnMintERC20(address(mockERC20TokenEthSepolia)),
localTokenDecimals,
allowlist,
ethSepoliaNetworkDetails.rmnProxyAddress,
ethSepoliaNetworkDetails.routerAddress
);
vm.stopPrank();
// Step 4) Deploy BurnMintTokenPool on Base Sepolia
vm.selectFork(baseSepoliaFork);
baseSepoliaNetworkDetails = ccipLocalSimulatorFork.getNetworkDetails(block.chainid);
vm.startPrank(alice);
burnMintTokenPoolBaseSepolia = new BurnMintTokenPool(
IBurnMintERC20(address(mockERC20TokenBaseSepolia)),
localTokenDecimals,
allowlist,
baseSepoliaNetworkDetails.rmnProxyAddress,
baseSepoliaNetworkDetails.routerAddress
);
vm.stopPrank();
// Step 5) Grant Mint and Burn roles to BurnMintTokenPool on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
vm.startPrank(alice);
mockERC20TokenEthSepolia.grantRole(mockERC20TokenEthSepolia.MINTER_ROLE(), address(burnMintTokenPoolEthSepolia));
mockERC20TokenEthSepolia.grantRole(mockERC20TokenEthSepolia.BURNER_ROLE(), address(burnMintTokenPoolEthSepolia));
vm.stopPrank();
// Step 6) Grant Mint and Burn roles to BurnMintTokenPool on Base Sepolia
vm.selectFork(baseSepoliaFork);
vm.startPrank(alice);
mockERC20TokenBaseSepolia.grantRole(
mockERC20TokenBaseSepolia.MINTER_ROLE(), address(burnMintTokenPoolBaseSepolia)
);
mockERC20TokenBaseSepolia.grantRole(
mockERC20TokenBaseSepolia.BURNER_ROLE(), address(burnMintTokenPoolBaseSepolia)
);
vm.stopPrank();
// Step 7) Claim Admin role on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
RegistryModuleOwnerCustom registryModuleOwnerCustomEthSepolia =
RegistryModuleOwnerCustom(ethSepoliaNetworkDetails.registryModuleOwnerCustomAddress);
vm.startPrank(alice);
registryModuleOwnerCustomEthSepolia.registerAdminViaGetCCIPAdmin(address(mockERC20TokenEthSepolia));
vm.stopPrank();
// Step 8) Claim Admin role on Base Sepolia
vm.selectFork(baseSepoliaFork);
RegistryModuleOwnerCustom registryModuleOwnerCustomBaseSepolia =
RegistryModuleOwnerCustom(baseSepoliaNetworkDetails.registryModuleOwnerCustomAddress);
vm.startPrank(alice);
registryModuleOwnerCustomBaseSepolia.registerAdminViaGetCCIPAdmin(address(mockERC20TokenBaseSepolia));
vm.stopPrank();
// Step 9) Accept Admin role on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
TokenAdminRegistry tokenAdminRegistryEthSepolia =
TokenAdminRegistry(ethSepoliaNetworkDetails.tokenAdminRegistryAddress);
vm.startPrank(alice);
tokenAdminRegistryEthSepolia.acceptAdminRole(address(mockERC20TokenEthSepolia));
vm.stopPrank();
// Step 10) Accept Admin role on Base Sepolia
vm.selectFork(baseSepoliaFork);
TokenAdminRegistry tokenAdminRegistryBaseSepolia =
TokenAdminRegistry(baseSepoliaNetworkDetails.tokenAdminRegistryAddress);
vm.startPrank(alice);
tokenAdminRegistryBaseSepolia.acceptAdminRole(address(mockERC20TokenBaseSepolia));
vm.stopPrank();
// Step 11) Link token to pool on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
vm.startPrank(alice);
tokenAdminRegistryEthSepolia.setPool(address(mockERC20TokenEthSepolia), address(burnMintTokenPoolEthSepolia));
vm.stopPrank();
// Step 12) Link token to pool on Base Sepolia
vm.selectFork(baseSepoliaFork);
vm.startPrank(alice);
tokenAdminRegistryBaseSepolia.setPool(address(mockERC20TokenBaseSepolia), address(burnMintTokenPoolBaseSepolia));
vm.stopPrank();
// Step 13) Configure Token Pool on Ethereum Sepolia
vm.selectFork(ethSepoliaFork);
vm.startPrank(alice);
TokenPool.ChainUpdate[] memory chains = new TokenPool.ChainUpdate[](1);
bytes[] memory remotePoolAddressesEthSepolia = new bytes[](1);
remotePoolAddressesEthSepolia[0] = abi.encode(address(burnMintTokenPoolEthSepolia));
chains[0] = TokenPool.ChainUpdate({
remoteChainSelector: baseSepoliaNetworkDetails.chainSelector,
remotePoolAddresses: remotePoolAddressesEthSepolia,
remoteTokenAddress: abi.encode(address(mockERC20TokenBaseSepolia)),
outboundRateLimiterConfig: RateLimiter.Config({isEnabled: true, capacity: 100_000, rate: 167}),
inboundRateLimiterConfig: RateLimiter.Config({isEnabled: true, capacity: 100_000, rate: 167})
});
uint64[] memory remoteChainSelectorsToRemove = new uint64[](0);
burnMintTokenPoolEthSepolia.applyChainUpdates(remoteChainSelectorsToRemove, chains);
vm.stopPrank();
// Step 14) Configure Token Pool on Base Sepolia
vm.selectFork(baseSepoliaFork);
vm.startPrank(alice);
chains = new TokenPool.ChainUpdate[](1);
bytes[] memory remotePoolAddressesBaseSepolia = new bytes[](1);
remotePoolAddressesBaseSepolia[0] = abi.encode(address(burnMintTokenPoolEthSepolia));
chains[0] = TokenPool.ChainUpdate({
remoteChainSelector: ethSepoliaNetworkDetails.chainSelector,
remotePoolAddresses: remotePoolAddressesBaseSepolia,
remoteTokenAddress: abi.encode(address(mockERC20TokenEthSepolia)),
outboundRateLimiterConfig: RateLimiter.Config({isEnabled: true, capacity: 100_000, rate: 167}),
inboundRateLimiterConfig: RateLimiter.Config({isEnabled: true, capacity: 100_000, rate: 167})
});
burnMintTokenPoolBaseSepolia.applyChainUpdates(remoteChainSelectorsToRemove, chains);
vm.stopPrank();
// Step 15) Mint tokens on Ethereum Sepolia and transfer them to Base Sepolia
vm.selectFork(ethSepoliaFork);
address linkSepolia = ethSepoliaNetworkDetails.linkAddress;
ccipLocalSimulatorFork.requestLinkFromFaucet(address(alice), 20 ether);
uint256 amountToSend = 100;
Client.EVMTokenAmount[] memory tokenToSendDetails = new Client.EVMTokenAmount[](1);
Client.EVMTokenAmount memory tokenAmount =
Client.EVMTokenAmount({token: address(mockERC20TokenEthSepolia), amount: amountToSend});
tokenToSendDetails[0] = tokenAmount;
vm.startPrank(alice);
mockERC20TokenEthSepolia.mint(address(alice), amountToSend);
mockERC20TokenEthSepolia.approve(ethSepoliaNetworkDetails.routerAddress, amountToSend);
IERC20(linkSepolia).approve(ethSepoliaNetworkDetails.routerAddress, 20 ether);
uint256 balanceOfAliceBeforeEthSepolia = mockERC20TokenEthSepolia.balanceOf(alice);
IRouterClient routerEthSepolia = IRouterClient(ethSepoliaNetworkDetails.routerAddress);
routerEthSepolia.ccipSend(
baseSepoliaNetworkDetails.chainSelector,
Client.EVM2AnyMessage({
receiver: abi.encode(address(alice)),
data: "",
tokenAmounts: tokenToSendDetails,
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({gasLimit: 0})),
feeToken: linkSepolia
})
);
uint256 balanceOfAliceAfterEthSepolia = mockERC20TokenEthSepolia.balanceOf(alice);
vm.stopPrank();
assertEq(balanceOfAliceAfterEthSepolia, balanceOfAliceBeforeEthSepolia - amountToSend);
ccipLocalSimulatorFork.switchChainAndRouteMessage(baseSepoliaFork);
uint256 balanceOfAliceAfterBaseSepolia = mockERC20TokenBaseSepolia.balanceOf(alice);
assertEq(balanceOfAliceAfterBaseSepolia, amountToSend);
}
}