|
1 | | -import { HardhatRuntimeEnvironment } from "hardhat/types"; |
2 | | -import { HYPERLANE_CONFIG } from "../config"; |
3 | 1 | import { task } from "hardhat/config"; |
| 2 | +import { hyperlaneConfig } from "../hyperlane.config"; |
4 | 3 |
|
5 | | -task("enroll-routers", "Enrolls remote routers for contracts") |
6 | | - .addOptionalParam("contract", "Name of specific contract to enroll") |
7 | | - .setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => { |
8 | | - const { network, ethers, deployments } = hre; |
9 | | - const [signer] = await ethers.getSigners(); |
| 4 | +task("enroll-routers", "Enrolls remote routers for current network").setAction(async (_, hre) => { |
| 5 | + const { ethers, config, network } = hre; |
| 6 | + const [signer] = await ethers.getSigners(); |
| 7 | + const currentNetwork = network.name; |
10 | 8 |
|
11 | | - if (!network.config.chainId) { |
12 | | - throw new Error("ChainId must be defined in network config"); |
13 | | - } |
14 | | - |
15 | | - const contractsToProcess = taskArgs.contract |
16 | | - ? [[taskArgs.contract, HYPERLANE_CONFIG.deployments[taskArgs.contract]]] |
17 | | - : Object.entries(HYPERLANE_CONFIG.deployments).filter( |
18 | | - ([_, deployments]) => deployments[network.name] !== undefined, |
19 | | - ); |
| 9 | + const { networks } = hyperlaneConfig[0]; |
| 10 | + if (!networks[currentNetwork]) return; |
20 | 11 |
|
21 | | - for (const [contractName, contractDeployments] of contractsToProcess) { |
22 | | - console.log(`Processing ${contractName}...`); |
| 12 | + console.log("Enrollment Starting..."); |
23 | 13 |
|
24 | | - const currentDeployment = contractDeployments[network.name]; |
25 | | - if (!currentDeployment) { |
26 | | - continue; |
27 | | - } |
| 14 | + const sourceSettings = networks[currentNetwork]; |
| 15 | + const sourceContract = await ethers.getContractAt( |
| 16 | + sourceSettings.contractName, |
| 17 | + (await require(`../deployments/${currentNetwork}/${sourceSettings.contractName}.json`)) |
| 18 | + .address, |
| 19 | + signer, |
| 20 | + ); |
28 | 21 |
|
29 | | - const deployment = await deployments.get(contractName); |
30 | | - const contract = await ethers.getContractAt(contractName, deployment.address, signer); |
31 | | - |
32 | | - const relationships = HYPERLANE_CONFIG.relationships[contractName] || []; |
33 | | - const relevantRelationships = relationships.filter( |
34 | | - ([source]) => source === network.name, |
35 | | - ); |
| 22 | + for (const [destNetwork, destSettings] of Object.entries(networks)) { |
| 23 | + if (destNetwork === currentNetwork) continue; |
36 | 24 |
|
37 | | - for (const [_, destinationNetwork] of relevantRelationships) { |
38 | | - const destNetworkConfig = HYPERLANE_CONFIG.networks[destinationNetwork]; |
39 | | - if (!destNetworkConfig) { |
40 | | - throw new Error(`Missing network configuration for ${destinationNetwork}`); |
41 | | - } |
| 25 | + try { |
| 26 | + const destAddress = ( |
| 27 | + await require(`../deployments/${destNetwork}/${destSettings.contractName}.json`) |
| 28 | + ).address; |
42 | 29 |
|
43 | | - try { |
44 | | - if (destNetworkConfig.gasAmount) { |
45 | | - const gasConfig = [ |
46 | | - { |
47 | | - domain: destNetworkConfig.chainId, |
48 | | - gas: destNetworkConfig.gasAmount, |
49 | | - }, |
50 | | - ]; |
51 | | - //@ts-expect-error |
52 | | - const gasConfigTx = await contract.setDestinationGas(gasConfig); |
53 | | - await gasConfigTx.wait(1); |
54 | | - console.log(`Gas config set for ${destinationNetwork}`); |
55 | | - } |
56 | | - |
57 | | - // Find the corresponding contract for the destination |
58 | | - const destinationContractName = Object.keys(HYPERLANE_CONFIG.deployments).find( |
59 | | - (name) => HYPERLANE_CONFIG.deployments[name][destinationNetwork], |
60 | | - ); |
61 | | - |
62 | | - if (!destinationContractName) { |
63 | | - throw new Error(`No contract found for ${destinationNetwork}`); |
64 | | - } |
| 30 | + if (config.networks[destNetwork].chainId === undefined) { |
| 31 | + throw new Error("Chain Id required"); |
| 32 | + } |
65 | 33 |
|
66 | | - const destinationDeployment = |
67 | | - HYPERLANE_CONFIG.deployments[destinationContractName][destinationNetwork]; |
| 34 | + const destDomain = config.networks[destNetwork].chainId.toString(); |
68 | 35 |
|
69 | | - const enroll = await contract.enrollRemoteRouter( |
70 | | - destNetworkConfig.chainId, |
71 | | - ethers.zeroPadValue(destinationDeployment.address, 32), |
72 | | - ); |
73 | | - await enroll.wait(1); |
74 | | - console.log( |
75 | | - `Enrolled ${contractName} from ${network.name} to ${destinationNetwork}`, |
76 | | - ); |
77 | | - } catch (error) { |
78 | | - console.error(`Failed to enroll router: ${error}`); |
79 | | - throw error; |
80 | | - } |
| 36 | + if (sourceSettings.gas) { |
| 37 | + const gasTx = await sourceContract.setDestinationGas([ |
| 38 | + { domain: destDomain, gas: sourceSettings.gas }, |
| 39 | + ]); |
| 40 | + await gasTx.wait(2); |
81 | 41 | } |
| 42 | + const enrollTx = await sourceContract.enrollRemoteRouter( |
| 43 | + destDomain, |
| 44 | + ethers.zeroPadValue(destAddress, 32), |
| 45 | + ); |
| 46 | + await enrollTx.wait(2); |
| 47 | + console.log(`✓ Enrolled router for ${destNetwork}`); |
| 48 | + } catch (error) { |
| 49 | + console.error(`✗ Failed to enroll router for ${destNetwork}:`, error); |
82 | 50 | } |
83 | | - }); |
| 51 | + } |
| 52 | +}); |
0 commit comments