Skip to content

Commit 393e7a3

Browse files
committed
feat: add set peer tasks
1 parent a3b16f8 commit 393e7a3

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

constants/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export const LZ_ENDPOINTS = {
44
ETHERLINK: "0xec28645346D781674B4272706D8a938dB2BAA2C6",
55
} as const;
66

7+
export const LZ_EID = {
8+
SEPOLIA: 40161,
9+
ETHERLINK: 40239,
10+
} as const;
11+
712
// Chain IDs for LayerZero
813
export const LZ_CHAIN_IDS = {
914
SEPOLIA: 40161,

hardhat.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import "./tasks/deployOFT";
99
import "./tasks/deployOFTAdapter";
1010
import "./tasks/deployToken";
1111
import "./tasks/lock";
12+
import "./tasks/setOFTAdapterPeer";
13+
import "./tasks/setOFTPeer";
1214
import "./tasks/verify";
1315

1416
// Load environment variables from .env file

tasks/setOFTAdapterPeer.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { zeroPad } from "@ethersproject/bytes";
2+
import * as fs from "fs";
3+
import { task } from "hardhat/config";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
5+
6+
import { NETWORK_NAMES, getLzChainId } from "../constants";
7+
8+
interface ContractsJson {
9+
oft?: string;
10+
oftAdapter?: string;
11+
token?: string;
12+
endpoint?: string;
13+
[key: string]: string | undefined;
14+
}
15+
16+
task("set-oftadapter-peer", "Sets peer for OFTAdapter contract").setAction(
17+
async (_, hre: HardhatRuntimeEnvironment) => {
18+
try {
19+
const network = hre.network.name;
20+
21+
if (network !== NETWORK_NAMES.SEPOLIA) {
22+
throw new Error("This task must be run on Sepolia network");
23+
}
24+
25+
// Read contract addresses from both networks
26+
const sepoliaContracts = JSON.parse(
27+
fs.readFileSync(`contracts.${NETWORK_NAMES.SEPOLIA}.json`, "utf8"),
28+
) as ContractsJson;
29+
30+
const etherlinkContracts = JSON.parse(
31+
fs.readFileSync(`contracts.${NETWORK_NAMES.ETHERLINK}.json`, "utf8"),
32+
) as ContractsJson;
33+
34+
if (!sepoliaContracts.oftAdapter) {
35+
throw new Error("OFTAdapter contract not found on Sepolia");
36+
}
37+
if (!etherlinkContracts.oft) {
38+
throw new Error("OFT contract not found on Etherlink");
39+
}
40+
41+
// Get the deployer account
42+
const [deployer] = await hre.ethers.getSigners();
43+
console.log("Setting OFTAdapter peer with account:", deployer.address);
44+
45+
// Get contract instance
46+
const MyOFTAdapter = await hre.ethers.getContractFactory("MyOFTAdapter");
47+
const oftAdapter = MyOFTAdapter.attach(sepoliaContracts.oftAdapter);
48+
49+
// Get Etherlink's EID
50+
const etherlinkEid = getLzChainId(NETWORK_NAMES.ETHERLINK);
51+
52+
console.log("\nSetting peer for OFTAdapter contract:");
53+
console.log("OFTAdapter address:", sepoliaContracts.oftAdapter);
54+
console.log("Etherlink EID:", etherlinkEid);
55+
console.log("OFT address:", etherlinkContracts.oft);
56+
57+
// Set the peer
58+
const tx = await oftAdapter.setPeer(etherlinkEid, zeroPad(etherlinkContracts.oft, 32));
59+
const receipt = await tx.wait();
60+
61+
console.log("\nPeer setup completed successfully");
62+
console.log("Transaction hash:", receipt.hash);
63+
64+
console.log("\nIMPORTANT: Make sure to also run set-oft-peer on Etherlink network");
65+
console.log("npx hardhat set-oft-peer --network etherlink");
66+
} catch (error) {
67+
console.error("Error setting OFTAdapter peer:", error);
68+
throw error;
69+
}
70+
},
71+
);

tasks/setOFTPeer.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { zeroPad } from "@ethersproject/bytes";
2+
import * as fs from "fs";
3+
import { task } from "hardhat/config";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
5+
6+
import { NETWORK_NAMES, getLzChainId } from "../constants";
7+
8+
interface ContractsJson {
9+
oft?: string;
10+
oftAdapter?: string;
11+
token?: string;
12+
endpoint?: string;
13+
[key: string]: string | undefined;
14+
}
15+
16+
task("set-oft-peer", "Sets peer for OFT contract").setAction(async (_, hre: HardhatRuntimeEnvironment) => {
17+
try {
18+
const network = hre.network.name;
19+
20+
if (network !== NETWORK_NAMES.ETHERLINK) {
21+
throw new Error("This task must be run on Etherlink network");
22+
}
23+
24+
// Read contract addresses from both networks
25+
const etherlinkContracts = JSON.parse(
26+
fs.readFileSync(`contracts.${NETWORK_NAMES.ETHERLINK}.json`, "utf8"),
27+
) as ContractsJson;
28+
29+
const sepoliaContracts = JSON.parse(
30+
fs.readFileSync(`contracts.${NETWORK_NAMES.SEPOLIA}.json`, "utf8"),
31+
) as ContractsJson;
32+
33+
if (!etherlinkContracts.oft) {
34+
throw new Error("OFT contract not found on Etherlink");
35+
}
36+
if (!sepoliaContracts.oftAdapter) {
37+
throw new Error("OFTAdapter contract not found on Sepolia");
38+
}
39+
40+
// Get the deployer account
41+
const [deployer] = await hre.ethers.getSigners();
42+
console.log("Setting OFT peer with account:", deployer.address);
43+
44+
// Get contract instance
45+
const MyOFT = await hre.ethers.getContractFactory("MyOFT");
46+
const oft = MyOFT.attach(etherlinkContracts.oft);
47+
48+
// Get Sepolia's EID
49+
const sepoliaEid = getLzChainId(NETWORK_NAMES.SEPOLIA);
50+
51+
console.log("\nSetting peer for OFT contract:");
52+
console.log("OFT address:", etherlinkContracts.oft);
53+
console.log("Sepolia EID:", sepoliaEid);
54+
console.log("OFTAdapter address:", sepoliaContracts.oftAdapter);
55+
56+
// Set the peer
57+
const tx = await oft.setPeer(sepoliaEid, zeroPad(sepoliaContracts.oftAdapter, 32));
58+
const receipt = await tx.wait();
59+
60+
console.log("\nPeer setup completed successfully");
61+
console.log("Transaction hash:", receipt.hash);
62+
63+
console.log("\nIMPORTANT: Make sure to also run set-oftadapter-peer on Sepolia network");
64+
console.log("npx hardhat set-oftadapter-peer --network sepolia");
65+
} catch (error) {
66+
console.error("Error setting OFT peer:", error);
67+
throw error;
68+
}
69+
});

0 commit comments

Comments
 (0)