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