Skip to content

Commit 7ab56b6

Browse files
committed
create lz-config and lz-set-config tasks to set tasks for LZ bridging
1 parent 77a2bd6 commit 7ab56b6

File tree

4 files changed

+494
-1
lines changed

4 files changed

+494
-1
lines changed

hardhat.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
2020
});
2121

2222
import "./tasks/bridge";
23+
import "./tasks/lz-config";
24+
import "./tasks/lz-set-config";
2325

2426
const config: HardhatUserConfig = {
2527
solidity: {

helper-hardhat-config.ts

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ export interface networkConfigItem {
55
timelock?: TimeLockInfo
66
lzEndpoint?: string
77
lzEid?: number
8+
lzSendLib?: string
9+
lzReceiveLib?: string
10+
lzExecutor?: string
11+
lzSendULNConfig?: dvnConfigInfo
12+
lzReceiveULNConfig?: dvnConfigInfo
813
initialGSTokenAmt?: string
914
mintGSTokenTo?: string
1015
}
1116

17+
export interface dvnConfigItem {
18+
requiredDVNCount: number
19+
confirmations: number
20+
requiredDVNs: string[]
21+
optionalDVNCount?: number
22+
optionalDVNThreshold?: number
23+
optionalDVNs?: string[]
24+
}
25+
26+
export interface dvnConfigInfo {
27+
[key: string]: dvnConfigItem
28+
}
29+
1230
export interface networkConfigInfo {
1331
[key: string]: networkConfigItem
1432
}
@@ -43,6 +61,26 @@ export const networkConfig: networkConfigInfo = {
4361
gs: '0x64d3CAe387405d91f7b0D91fb1D824A281719500',
4462
weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
4563
usdc: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
64+
},
65+
lzSendULNConfig: {
66+
sonic: {
67+
confirmations: 15,
68+
requiredDVNCount: 2,
69+
requiredDVNs: [
70+
'0x589dEDbD617e0CBcB916A9223F4d1300c294236b',
71+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
72+
]
73+
}
74+
},
75+
lzReceiveULNConfig: {
76+
sonic: {
77+
confirmations: 20,
78+
requiredDVNCount: 2,
79+
requiredDVNs: [
80+
'0x589dEDbD617e0CBcB916A9223F4d1300c294236b',
81+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
82+
]
83+
}
4684
}
4785
},
4886
sepolia: {
@@ -68,7 +106,7 @@ export const networkConfig: networkConfigInfo = {
68106
timelock: {
69107
proposers: ["0x7B08e1Cf4C60Fd942Fa0C004F2739B8B8fA46e80","0x3429de008b6d3c85744b639511c8854d52c8f6ab"],
70108
executors: ["0x7B08e1Cf4C60Fd942Fa0C004F2739B8B8fA46e80","0x3429de008b6d3c85744b639511c8854d52c8f6ab"],
71-
}
109+
},
72110
},
73111
arbitrum: {
74112
blockConfirmations: 2,
@@ -99,6 +137,26 @@ export const networkConfig: networkConfigInfo = {
99137
gns: '0x18c11FD286C5EC11c3b683Caa813B77f5163A122',
100138
ptWEETH26SEP2024: '0xb8b0a120f6a68dd06209619f62429fb1a8e92fec',
101139
ptEZETH26SEP2024: '0x2ccfce9be49465cc6f947b5f6ac9383673733da9',
140+
},
141+
lzSendULNConfig: {
142+
sonic: {
143+
confirmations: 20,
144+
requiredDVNCount: 2,
145+
requiredDVNs: [
146+
'0x2f55C492897526677C5B68fb199ea31E2c126416',
147+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
148+
]
149+
}
150+
},
151+
lzReceiveULNConfig: {
152+
sonic: {
153+
confirmations: 10,
154+
requiredDVNCount: 2,
155+
requiredDVNs: [
156+
'0x2f55C492897526677C5B68fb199ea31E2c126416',
157+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
158+
]
159+
}
102160
}
103161
},
104162
base: {
@@ -117,6 +175,26 @@ export const networkConfig: networkConfigInfo = {
117175
weth: '0x4200000000000000000000000000000000000006',
118176
usdc: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
119177
},
178+
lzSendULNConfig: {
179+
sonic: {
180+
confirmations: 10,
181+
requiredDVNCount: 2,
182+
requiredDVNs: [
183+
'0x9e059a54699a285714207b43B055483E78FAac25',
184+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
185+
]
186+
}
187+
},
188+
lzReceiveULNConfig: {
189+
sonic: {
190+
confirmations: 20,
191+
requiredDVNCount: 2,
192+
requiredDVNs: [
193+
'0x9e059a54699a285714207b43B055483E78FAac25',
194+
'0xD56e4eAb23cb81f43168F9F45211Eb027b9aC7cc'
195+
]
196+
}
197+
}
120198
},
121199
baseSepolia: {
122200
blockConfirmations: 2,
@@ -142,6 +220,58 @@ export const networkConfig: networkConfigInfo = {
142220
gs: '0xf9F143705b2BBDE9b4ABfD0320F328aE59364f5e',
143221
weth: '0x50c42deacd8fc9773493ed674b675be577f2634b',
144222
},
223+
lzSendULNConfig: {
224+
base: {
225+
confirmations: 20,
226+
requiredDVNCount: 2,
227+
requiredDVNs: [
228+
'0x282b3386571f7f794450d5789911a9804fa346b4',
229+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
230+
]
231+
},
232+
arbitrum: {
233+
confirmations: 10,
234+
requiredDVNCount: 2,
235+
requiredDVNs: [
236+
'0x282b3386571f7f794450d5789911a9804fa346b4',
237+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
238+
]
239+
},
240+
mainnet: {
241+
confirmations: 20,
242+
requiredDVNCount: 2,
243+
requiredDVNs: [
244+
'0x282b3386571f7f794450d5789911a9804fa346b4',
245+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
246+
]
247+
}
248+
},
249+
lzReceiveULNConfig: {
250+
base: {
251+
confirmations: 10,
252+
requiredDVNCount: 2,
253+
requiredDVNs: [
254+
'0x282b3386571f7f794450d5789911a9804fa346b4',
255+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
256+
]
257+
},
258+
arbitrum: {
259+
confirmations: 20,
260+
requiredDVNCount: 2,
261+
requiredDVNs: [
262+
'0x282b3386571f7f794450d5789911a9804fa346b4',
263+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
264+
]
265+
},
266+
mainnet: {
267+
confirmations: 15,
268+
requiredDVNCount: 2,
269+
requiredDVNs: [
270+
'0x282b3386571f7f794450d5789911a9804fa346b4',
271+
'0xdd7b5e1db4aafd5c8ec3b764efb8ed265aa5445b'
272+
]
273+
}
274+
}
145275
},
146276
sonicTestnet: { // Blaze
147277
blockConfirmations: 2,

tasks/lz-config.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { task } from "hardhat/config"
2+
import { networkConfig } from "../helper-hardhat-config";
3+
4+
// run as "npx hardhat --network arbitrumSepolia lz-config --dest baseSepolia"
5+
task("lz-config", "Checks LZ configurations from current network to destination network")
6+
.addParam("dest", "destination network")
7+
.setAction(async (taskArgs, hre) => {
8+
if (hre.network.name === "hardhat") {
9+
console.warn(
10+
"You are running on Hardhat network, which" +
11+
"gets automatically created and destroyed every time. Use the Hardhat" +
12+
" option '--network localhost'"
13+
)
14+
}
15+
16+
const { deployments, network } = hre
17+
const { get } = deployments
18+
19+
// Define the smart contract address and ABI
20+
const ethereumLzEndpointABI = [
21+
'function getConfig(address _oapp, address _lib, uint32 _eid, uint32 _configType) external view returns (bytes memory config)',
22+
'function getSendLibrary(address _sender, uint32 _dstEid) external view returns (address lib)',
23+
'function getReceiveLibrary(address _receiver, uint32 _srcEid) external view returns (address lib, bool isDefault)'
24+
];
25+
26+
// Create a contract instance
27+
// Define the addresses and parameters
28+
let oappAddress = (await get('GS')).address
29+
console.log("oappAddress:",oappAddress)
30+
let oappContract = await hre.ethers.getContractAt("GS", oappAddress);
31+
const endpointAddr = await oappContract.endpoint();
32+
console.log("endpointAddr:",endpointAddr)
33+
const contract = await hre.ethers.getContractAt(ethereumLzEndpointABI, endpointAddr);
34+
35+
const dstNetwork = taskArgs.dest
36+
37+
const destCfg = networkConfig[dstNetwork]
38+
if(!destCfg) {
39+
console.log("Please provide network `--net` e.g. arbitrumSepolia, sepolia, etc.")
40+
return;
41+
}
42+
43+
const destEid = Number(destCfg.lzEid || "0");
44+
console.log("destEid:",destEid)
45+
46+
const srcCfg = networkConfig[network.name]
47+
if(!srcCfg) {
48+
console.log("Please provide network `--net` e.g. arbitrumSepolia, sepolia, etc.")
49+
return;
50+
}
51+
const srcEid = Number(srcCfg.lzEid || "0");
52+
console.log("srcEid:",srcEid)
53+
54+
let sendLibAddress = await contract.getSendLibrary(oappAddress, destEid);
55+
let receiveLibAddress = (await contract.getReceiveLibrary(oappAddress, srcEid))?.lib || "0x";
56+
console.log("sendLibAddress:",sendLibAddress)
57+
console.log("receiveLibAddress:",receiveLibAddress)
58+
const executorConfigType = 1; // 1 for executor
59+
const ulnConfigType = 2; // 2 for UlnConfig
60+
61+
try {
62+
// Fetch and decode for sendLib (both Executor and ULN Config)
63+
const sendExecutorConfigBytes = await contract.getConfig(
64+
oappAddress,
65+
sendLibAddress,
66+
destEid,
67+
executorConfigType,
68+
);
69+
const executorConfigAbi = ['tuple(uint32 maxMessageSize, address executorAddress)'];
70+
const executorConfigArray = hre.ethers.utils.defaultAbiCoder.decode(
71+
executorConfigAbi,
72+
sendExecutorConfigBytes,
73+
);
74+
console.log('Send Library Executor Config:', executorConfigArray);
75+
76+
const sendUlnConfigBytes = await contract.getConfig(
77+
oappAddress,
78+
sendLibAddress,
79+
destEid,
80+
ulnConfigType,
81+
);
82+
const ulnConfigStructType = [
83+
'tuple(uint64 confirmations, uint8 requiredDVNCount, uint8 optionalDVNCount, uint8 optionalDVNThreshold, address[] requiredDVNs, address[] optionalDVNs)',
84+
];
85+
const sendUlnConfigArray = hre.ethers.utils.defaultAbiCoder.decode(
86+
ulnConfigStructType,
87+
sendUlnConfigBytes,
88+
);
89+
console.log('Send Library ULN Config:', sendUlnConfigArray);
90+
91+
// Fetch and decode for receiveLib (only ULN Config)
92+
const receiveUlnConfigBytes = await contract.getConfig(
93+
oappAddress,
94+
receiveLibAddress,
95+
destEid,
96+
ulnConfigType,
97+
);
98+
const receiveUlnConfigArray = hre.ethers.utils.defaultAbiCoder.decode(
99+
ulnConfigStructType,
100+
receiveUlnConfigBytes,
101+
);
102+
console.log('Receive Library ULN Config:', receiveUlnConfigArray);
103+
} catch (error) {
104+
console.error('Error fetching or decoding config:', error);
105+
}
106+
107+
})

0 commit comments

Comments
 (0)