|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import { Script } from "forge-std/Script.sol"; |
| 5 | +import { console } from "forge-std/console.sol"; |
| 6 | +import { ChainUtils } from "../utils/ChainUtils.sol"; |
| 7 | +import { AcrossOriginSettler } from "../../contracts/erc7683/AcrossOriginSettler.sol"; |
| 8 | +import { SpokePool } from "../../contracts/SpokePool.sol"; |
| 9 | +import { IPermit2 } from "../../contracts/external/interfaces/IPermit2.sol"; |
| 10 | + |
| 11 | +/** |
| 12 | + * @title DeployAcrossOriginSettler |
| 13 | + * @notice Deploy script for the AcrossOriginSettler contract |
| 14 | + * @dev This contract deploys AcrossOriginSettler and sets up destination settlers for all supported chains |
| 15 | + */ |
| 16 | +contract DeployAcrossOriginSettler is Script, ChainUtils { |
| 17 | + // Standard Permit2 address on most chains |
| 18 | + address constant PERMIT2_ADDRESS = 0x000000000022D473030F116dDEE9F6B43aC78BA3; |
| 19 | + |
| 20 | + // Time parameter for calculating quote timestamp |
| 21 | + uint256 constant QUOTE_BEFORE_DEADLINE = 1800; // 30 minutes in seconds |
| 22 | + |
| 23 | + // JSON file containing deployments |
| 24 | + string constant DEPLOYMENTS_FILE = "./deployments/deployments.json"; |
| 25 | + |
| 26 | + function run() external { |
| 27 | + string memory deployerMnemonic = vm.envString("MNEMONIC"); |
| 28 | + uint256 deployerPrivateKey = vm.deriveKey(deployerMnemonic, 0); |
| 29 | + address deployer = vm.addr(deployerPrivateKey); |
| 30 | + uint256 chainId = block.chainid; |
| 31 | + |
| 32 | + // Get current chain's SpokePool address |
| 33 | + address spokePoolAddress = getSpokePoolFromDeployments(chainId); |
| 34 | + |
| 35 | + // If no SpokePool deployment found, use a dummy address for testing |
| 36 | + if (spokePoolAddress == address(0)) { |
| 37 | + console.log("No SpokePool deployment found for chain %s, using dummy address for testing", chainId); |
| 38 | + spokePoolAddress = address(0x1234567890123456789012345678901234567890); |
| 39 | + } |
| 40 | + |
| 41 | + console.log("Deploying AcrossOriginSettler on chain %s", chainId); |
| 42 | + console.log("Deployer: %s", deployer); |
| 43 | + console.log("SpokePool: %s", spokePoolAddress); |
| 44 | + console.log("Permit2: %s", PERMIT2_ADDRESS); |
| 45 | + console.log("Quote Before Deadline: %s", QUOTE_BEFORE_DEADLINE); |
| 46 | + |
| 47 | + vm.startBroadcast(deployerPrivateKey); |
| 48 | + |
| 49 | + // Deploy AcrossOriginSettler |
| 50 | + AcrossOriginSettler originSettler = new AcrossOriginSettler( |
| 51 | + SpokePool(payable(spokePoolAddress)), |
| 52 | + IPermit2(PERMIT2_ADDRESS), |
| 53 | + QUOTE_BEFORE_DEADLINE |
| 54 | + ); |
| 55 | + console.log("AcrossOriginSettler deployed at: %s", address(originSettler)); |
| 56 | + |
| 57 | + // Set up destination settlers for supported chains |
| 58 | + // Each supported chain will have its SpokePool registered as a destination settler |
| 59 | + setDestinationSettlers(originSettler); |
| 60 | + |
| 61 | + // Renounce ownership after setting up all destination settlers |
| 62 | + // This means no further changes can be made to the destination settlers |
| 63 | + console.log("Renouncing ownership of AcrossOriginSettler contract"); |
| 64 | + originSettler.renounceOwnership(); |
| 65 | + console.log("Ownership renounced"); |
| 66 | + |
| 67 | + // Log deployment information for manual addition to deployments.json |
| 68 | + console.log(""); |
| 69 | + console.log("=== DEPLOYMENT SUMMARY ==="); |
| 70 | + console.log("Chain ID: %s", chainId); |
| 71 | + console.log("AcrossOriginSettler deployed at: %s", address(originSettler)); |
| 72 | + console.log("Block number: %s", block.number); |
| 73 | + console.log(""); |
| 74 | + console.log("Please add this entry to deployments.json:"); |
| 75 | + console.log("{"); |
| 76 | + console.log(' "%s": {', chainId); |
| 77 | + console.log(' "AcrossOriginSettler": {'); |
| 78 | + console.log(' "address": "%s",', address(originSettler)); |
| 79 | + console.log(' "blockNumber": %s', block.number); |
| 80 | + console.log(" }"); |
| 81 | + console.log(" }"); |
| 82 | + console.log("}"); |
| 83 | + console.log("========================="); |
| 84 | + |
| 85 | + vm.stopBroadcast(); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @notice Set destination settlers for all supported chains |
| 90 | + * @param originSettler The deployed AcrossOriginSettler contract |
| 91 | + */ |
| 92 | + function setDestinationSettlers(AcrossOriginSettler originSettler) internal { |
| 93 | + // Array of supported chain IDs to set destinations for |
| 94 | + uint256[] memory supportedChains = getSupportedChains(); |
| 95 | + |
| 96 | + for (uint256 i = 0; i < supportedChains.length; i++) { |
| 97 | + uint256 destChainId = supportedChains[i]; |
| 98 | + |
| 99 | + // Skip current chain as we don't need to set it as a destination |
| 100 | + if (destChainId == block.chainid) continue; |
| 101 | + |
| 102 | + // Get the SpokePool address from deployments.json |
| 103 | + address spokePoolAddress = getSpokePoolFromDeployments(destChainId); |
| 104 | + |
| 105 | + // Skip chains with no deployment |
| 106 | + if (spokePoolAddress == address(0)) { |
| 107 | + console.log("No SpokePool found for chain %s, skipping", destChainId); |
| 108 | + continue; |
| 109 | + } |
| 110 | + |
| 111 | + console.log("Setting destination settler for chain %s: %s", destChainId, spokePoolAddress); |
| 112 | + originSettler.setDestinationSettler(destChainId, spokePoolAddress); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @notice Returns list of supported chain IDs |
| 118 | + * @return Array of supported chain IDs |
| 119 | + */ |
| 120 | + function getSupportedChains() internal pure returns (uint256[] memory) { |
| 121 | + // Include all mainnet chains from deployments.json |
| 122 | + uint256[] memory chains = new uint256[](15); |
| 123 | + chains[0] = MAINNET; // Ethereum |
| 124 | + chains[1] = OPTIMISM; // Optimism |
| 125 | + chains[2] = ARBITRUM; // Arbitrum |
| 126 | + chains[3] = POLYGON; // Polygon |
| 127 | + chains[4] = BASE; // Base |
| 128 | + chains[5] = ZK_SYNC; // ZkSync |
| 129 | + chains[6] = LINEA; // Linea |
| 130 | + chains[7] = SCROLL; // Scroll |
| 131 | + chains[8] = BLAST; // Blast |
| 132 | + chains[9] = MODE; // Mode |
| 133 | + chains[10] = ZORA; // Zora |
| 134 | + chains[11] = BSC; // BNB Chain |
| 135 | + chains[12] = 41455; // Aleph Zero (actual chain ID used in deployments.json) |
| 136 | + chains[13] = 232; // Lisk (based on deployments.json) |
| 137 | + chains[14] = 57073; // Redstone (based on deployments.json) |
| 138 | + return chains; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * @notice Get SpokePool address from deployments.json |
| 143 | + * @param chainId The chain ID to find the SpokePool for |
| 144 | + * @return The SpokePool address for the given chain, or address(0) if not found |
| 145 | + */ |
| 146 | + function getSpokePoolFromDeployments(uint256 chainId) internal view returns (address) { |
| 147 | + string memory json = vm.readFile(DEPLOYMENTS_FILE); |
| 148 | + string memory chainIdStr = vm.toString(chainId); |
| 149 | + string memory queryPath = string.concat(".", chainIdStr, ".SpokePool.address"); |
| 150 | + |
| 151 | + console.log("Looking for SpokePool for chain ID %s", chainIdStr); |
| 152 | + |
| 153 | + try vm.parseJson(json, queryPath) returns (bytes memory data) { |
| 154 | + address spokePoolAddress = abi.decode(data, (address)); |
| 155 | + if (spokePoolAddress != address(0)) { |
| 156 | + console.log("Found SpokePool entry in deployments.json: %s", spokePoolAddress); |
| 157 | + return spokePoolAddress; |
| 158 | + } |
| 159 | + } catch (bytes memory) { |
| 160 | + // Try SVM spoke for Solana-based chains |
| 161 | + try vm.parseJson(json, string.concat(".", chainIdStr, ".SvmSpoke.address")) returns (bytes memory data) { |
| 162 | + address spokePoolAddress = abi.decode(data, (address)); |
| 163 | + if (spokePoolAddress != address(0)) { |
| 164 | + console.log("Found SvmSpoke entry in deployments.json: %s", spokePoolAddress); |
| 165 | + return spokePoolAddress; |
| 166 | + } |
| 167 | + } catch (bytes memory) { |
| 168 | + console.log("No SpokePool entry found in deployments.json for chain %s", chainIdStr); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + return address(0); |
| 173 | + } |
| 174 | +} |
0 commit comments