Skip to content

Commit 3740e41

Browse files
committed
add new enroll format
1 parent 3ce9bc1 commit 3740e41

2 files changed

Lines changed: 75 additions & 71 deletions

File tree

hyperlane.config.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Configuration interface for Hyperlane router deployment and enrollment
3+
*/
4+
export interface RouterConfig {
5+
/**
6+
* Network-specific configurations
7+
* @property contractName - Name of the contract deployed on this network
8+
* @property gas - Optional gas limit override. If not specified, uses Hyperlane's default (~50,000)
9+
*/
10+
networks: {
11+
[network: string]: {
12+
contractName: string;
13+
gas?: string;
14+
};
15+
};
16+
}
17+
18+
/**
19+
* Example configuration:
20+
* export const hyperlaneConfig: RouterConfig[] = [
21+
* {
22+
* networks: {
23+
* sepolia: {
24+
* contractName: "MyContract",
25+
* gas: "200000", // Optional: Overrides default gas limit
26+
* },
27+
* arbsepolia: {
28+
* contractName: "MyCollateralContract" // Uses default gas limit
29+
* }
30+
* }
31+
* }
32+
* ];
33+
*/
34+
35+
export const hyperlaneConfig: RouterConfig[] = [];

tasks/enrollRouter.ts

Lines changed: 40 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,52 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { HYPERLANE_CONFIG } from "../config";
31
import { task } from "hardhat/config";
2+
import { hyperlaneConfig } from "../hyperlane.config";
43

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;
108

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;
2011

21-
for (const [contractName, contractDeployments] of contractsToProcess) {
22-
console.log(`Processing ${contractName}...`);
12+
console.log("Enrollment Starting...");
2313

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+
);
2821

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;
3624

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;
4229

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+
}
6533

66-
const destinationDeployment =
67-
HYPERLANE_CONFIG.deployments[destinationContractName][destinationNetwork];
34+
const destDomain = config.networks[destNetwork].chainId.toString();
6835

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);
8141
}
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);
8250
}
83-
});
51+
}
52+
});

0 commit comments

Comments
 (0)