|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import { console } from "forge-std/console.sol"; |
| 5 | + |
| 6 | +import { DeploymentUtils } from "../../utils/DeploymentUtils.sol"; |
| 7 | + |
| 8 | +// How to run: |
| 9 | +// 1. source .env (needs MNEMONIC and the relevant NODE_URL_*) |
| 10 | +// 2. forge script script/mintburn/cctp/SetUpTokens.s.sol:SetUpTokens --rpc-url <chain> --sig "run(string)" <chain> -vvvv |
| 11 | +contract SetUpTokens is DeploymentUtils { |
| 12 | + function run(string calldata chain) external { |
| 13 | + console.log("Setting up core token info..."); |
| 14 | + console.log("Chain ID:", block.chainid); |
| 15 | + |
| 16 | + string memory deployerMnemonic = vm.envString("MNEMONIC"); |
| 17 | + uint256 deployerPrivateKey = vm.deriveKey(deployerMnemonic, 0); |
| 18 | + address deployer = vm.addr(deployerPrivateKey); |
| 19 | + console.log("Deployer:", deployer); |
| 20 | + |
| 21 | + _loadConfig("./script/mintburn/cctp/config.toml", false); |
| 22 | + |
| 23 | + address dstPeriphery = config.get("sponsoredCCTPDstPeriphery").toAddress(); |
| 24 | + address baseToken = config.get("baseToken").toAddress(); |
| 25 | + uint256 coreIndex = config.get("coreIndex").toUint256(); |
| 26 | + uint256 accountActivationFeeCore = config.get("accountActivationFeeCore").toUint256(); |
| 27 | + uint256 bridgeSafetyBufferCore = config.get("bridgeSafetyBufferCore").toUint256(); |
| 28 | + bool canBeUsedForAccountActivation = config.get("canBeUsedForAccountActivation").toBool(); |
| 29 | + |
| 30 | + string memory chain = chain; |
| 31 | + string memory dstPeripheryStr = vm.toString(dstPeriphery); |
| 32 | + string memory baseTokenStr = vm.toString(baseToken); |
| 33 | + string memory coreIndexStr = vm.toString(coreIndex); |
| 34 | + string memory accountActivationFeeCoreStr = vm.toString(accountActivationFeeCore); |
| 35 | + string memory bridgeSafetyBufferCoreStr = vm.toString(bridgeSafetyBufferCore); |
| 36 | + string memory canBeUsedForAccountActivationStr = canBeUsedForAccountActivation ? "true" : "false"; |
| 37 | + |
| 38 | + // 1. Check DEFAULT_ADMIN_ROLE |
| 39 | + console.log("# Checking DEFAULT_ADMIN_ROLE..."); |
| 40 | + string[] memory callCmd = new string[](6); |
| 41 | + callCmd[0] = "cast"; |
| 42 | + callCmd[1] = "call"; |
| 43 | + callCmd[2] = dstPeripheryStr; |
| 44 | + callCmd[3] = "DEFAULT_ADMIN_ROLE()(bytes32)"; |
| 45 | + callCmd[4] = "--rpc-url"; |
| 46 | + callCmd[5] = chain; |
| 47 | + bytes memory roleResult = vm.ffi(callCmd); |
| 48 | + // vm.ffi hex-decodes output starting with 0x, so convert raw bytes back to a hex string. |
| 49 | + string memory role = vm.toString(bytes32(roleResult)); |
| 50 | + console.log("DEFAULT_ADMIN_ROLE:", role); |
| 51 | + |
| 52 | + // 2. Check if deployer has DEFAULT_ADMIN_ROLE |
| 53 | + console.log("# Checking if deployer has DEFAULT_ADMIN_ROLE..."); |
| 54 | + string[] memory hasRoleCmd = new string[](8); |
| 55 | + hasRoleCmd[0] = "cast"; |
| 56 | + hasRoleCmd[1] = "call"; |
| 57 | + hasRoleCmd[2] = dstPeripheryStr; |
| 58 | + hasRoleCmd[3] = "hasRole(bytes32,address)(bool)"; |
| 59 | + hasRoleCmd[4] = role; |
| 60 | + hasRoleCmd[5] = vm.toString(deployer); |
| 61 | + hasRoleCmd[6] = "--rpc-url"; |
| 62 | + hasRoleCmd[7] = chain; |
| 63 | + bytes memory hasRoleResult = vm.ffi(hasRoleCmd); |
| 64 | + console.log("Deployer has admin role:", string(hasRoleResult)); |
| 65 | + |
| 66 | + // 3. Set core token info |
| 67 | + console.log("# Setting core token info..."); |
| 68 | + string[] memory sendCmd = new string[](13); |
| 69 | + sendCmd[0] = "cast"; |
| 70 | + sendCmd[1] = "send"; |
| 71 | + sendCmd[2] = dstPeripheryStr; |
| 72 | + sendCmd[3] = "setCoreTokenInfo(address,uint32,bool,uint64,uint64)"; |
| 73 | + sendCmd[4] = baseTokenStr; |
| 74 | + sendCmd[5] = coreIndexStr; |
| 75 | + sendCmd[6] = canBeUsedForAccountActivationStr; |
| 76 | + sendCmd[7] = accountActivationFeeCoreStr; |
| 77 | + sendCmd[8] = bridgeSafetyBufferCoreStr; |
| 78 | + sendCmd[9] = "--account"; |
| 79 | + sendCmd[10] = "dev"; |
| 80 | + sendCmd[11] = "--rpc-url"; |
| 81 | + sendCmd[12] = chain; |
| 82 | + |
| 83 | + bytes memory sendResult = vm.ffi(sendCmd); |
| 84 | + console.log("setCoreTokenInfo result:", string(sendResult)); |
| 85 | + } |
| 86 | +} |
0 commit comments