|
1 | 1 | import { EndpointId } from '@layerzerolabs/lz-definitions' |
| 2 | +import { ExecutorOptionType } from '@layerzerolabs/lz-v2-utilities' |
| 3 | +import { TwoWayConfig, generateConnectionsConfig } from '@layerzerolabs/metadata-tools' |
| 4 | +import { OAppEnforcedOption } from '@layerzerolabs/toolbox-hardhat' |
2 | 5 |
|
3 | | -import type { OAppOmniGraphHardhat, OmniPointHardhat } from '@layerzerolabs/toolbox-hardhat' |
| 6 | +import type { OmniPointHardhat } from '@layerzerolabs/toolbox-hardhat' |
4 | 7 |
|
5 | | -/** |
6 | | - * WARNING: ONLY 1 OFTAdapter should exist for a given global mesh. |
7 | | - * The token address for the adapter should be defined in hardhat.config. This will be used in deployment. |
8 | | - * |
9 | | - * for example: |
10 | | - * |
11 | | - * sepolia: { |
12 | | - * eid: EndpointId.SEPOLIA_V2_TESTNET, |
13 | | - * url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/', |
14 | | - * accounts, |
15 | | - * oftAdapter: { |
16 | | - * tokenAddress: '0x0', // Set the token address for the OFT adapter |
17 | | - * }, |
18 | | - * }, |
19 | | - */ |
20 | | -const sepoliaContract: OmniPointHardhat = { |
21 | | - eid: EndpointId.SEPOLIA_V2_TESTNET, |
| 8 | +const optimismContract: OmniPointHardhat = { |
| 9 | + eid: EndpointId.OPTSEP_V2_TESTNET, |
22 | 10 | contractName: 'MyMintBurnOFTAdapter', |
23 | 11 | } |
24 | 12 |
|
25 | | -const fujiContract: OmniPointHardhat = { |
| 13 | +const avalancheContract: OmniPointHardhat = { |
26 | 14 | eid: EndpointId.AVALANCHE_V2_TESTNET, |
27 | 15 | contractName: 'MyOFT', |
28 | 16 | } |
29 | 17 |
|
30 | | -const amoyContract: OmniPointHardhat = { |
31 | | - eid: EndpointId.AMOY_V2_TESTNET, |
| 18 | +const arbitrumContract: OmniPointHardhat = { |
| 19 | + eid: EndpointId.ARBSEP_V2_TESTNET, |
32 | 20 | contractName: 'MyOFT', |
33 | 21 | } |
34 | 22 |
|
35 | | -const config: OAppOmniGraphHardhat = { |
36 | | - contracts: [ |
37 | | - { |
38 | | - contract: fujiContract, |
39 | | - }, |
40 | | - { |
41 | | - contract: sepoliaContract, |
42 | | - }, |
43 | | - { |
44 | | - contract: amoyContract, |
45 | | - }, |
| 23 | +// To connect all the above chains to each other, we need the following pathways: |
| 24 | +// Optimism <-> Avalanche |
| 25 | +// Optimism <-> Arbitrum |
| 26 | +// Avalanche <-> Arbitrum |
| 27 | + |
| 28 | +// For this example's simplicity, we will use the same enforced options values for sending to all chains |
| 29 | +// For production, you should ensure `gas` is set to the correct value through profiling the gas usage of calling OFT._lzReceive(...) on the destination chain |
| 30 | +// To learn more, read https://docs.layerzero.network/v2/concepts/applications/oapp-standard#execution-options-and-enforced-settings |
| 31 | +const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [ |
| 32 | + { |
| 33 | + msgType: 1, |
| 34 | + optionType: ExecutorOptionType.LZ_RECEIVE, |
| 35 | + gas: 80000, |
| 36 | + value: 0, |
| 37 | + }, |
| 38 | +] |
| 39 | + |
| 40 | +// With the config generator, pathways declared are automatically bidirectional |
| 41 | +// i.e. if you declare A,B there's no need to declare B,A |
| 42 | +const pathways: TwoWayConfig[] = [ |
| 43 | + [ |
| 44 | + optimismContract, // Chain A contract |
| 45 | + avalancheContract, // Chain B contract |
| 46 | + [['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ] |
| 47 | + [1, 1], // [A to B confirmations, B to A confirmations] |
| 48 | + [EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain B enforcedOptions, Chain A enforcedOptions |
46 | 49 | ], |
47 | | - connections: [ |
48 | | - { |
49 | | - from: fujiContract, |
50 | | - to: sepoliaContract, |
51 | | - }, |
52 | | - { |
53 | | - from: fujiContract, |
54 | | - to: amoyContract, |
55 | | - }, |
56 | | - { |
57 | | - from: sepoliaContract, |
58 | | - to: fujiContract, |
59 | | - }, |
60 | | - { |
61 | | - from: sepoliaContract, |
62 | | - to: amoyContract, |
63 | | - }, |
64 | | - { |
65 | | - from: amoyContract, |
66 | | - to: sepoliaContract, |
67 | | - }, |
68 | | - { |
69 | | - from: amoyContract, |
70 | | - to: fujiContract, |
71 | | - }, |
| 50 | + [ |
| 51 | + optimismContract, // Chain A contract |
| 52 | + arbitrumContract, // Chain C contract |
| 53 | + [['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ] |
| 54 | + [1, 1], // [A to B confirmations, B to A confirmations] |
| 55 | + [EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain C enforcedOptions, Chain A enforcedOptions |
72 | 56 | ], |
73 | | -} |
| 57 | + [ |
| 58 | + avalancheContract, // Chain B contract |
| 59 | + arbitrumContract, // Chain C contract |
| 60 | + [['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ] |
| 61 | + [1, 1], // [A to B confirmations, B to A confirmations] |
| 62 | + [EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain C enforcedOptions, Chain B enforcedOptions |
| 63 | + ], |
| 64 | +] |
74 | 65 |
|
75 | | -export default config |
| 66 | +export default async function () { |
| 67 | + // Generate the connections config based on the pathways |
| 68 | + const connections = await generateConnectionsConfig(pathways) |
| 69 | + return { |
| 70 | + contracts: [{ contract: optimismContract }, { contract: avalancheContract }, { contract: arbitrumContract }], |
| 71 | + connections, |
| 72 | + } |
| 73 | +} |
0 commit comments