Skip to content

Commit 1447855

Browse files
committed
chore: add metadata tools to oft-adapter repo
1 parent 9606db5 commit 1447855

5 files changed

Lines changed: 69 additions & 51 deletions

File tree

examples/oft-adapter/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module.exports = {
77
// @layerzerolabs/eslint-config-next defines rules for turborepo-based projects
88
// that are not relevant for this particular project
99
'turbo/no-undeclared-env-vars': 'off',
10+
'import/no-unresolved': 'warn', // Updated to warn to avoid erratic popping up of this particular error for '@layerzerolabs/metadata-tools' even when the package has been installed correctly
1011
},
1112
};

examples/oft-adapter/hardhat.config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ const config: HardhatUserConfig = {
5555
],
5656
},
5757
networks: {
58-
'sepolia-testnet': {
59-
eid: EndpointId.SEPOLIA_V2_TESTNET,
60-
url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/',
58+
'optimism-testnet': {
59+
eid: EndpointId.OPTSEP_V2_TESTNET,
60+
url: process.env.RPC_URL_OP_SEPOLIA || 'https://optimism-sepolia.gateway.tenderly.co',
6161
accounts,
6262
oftAdapter: {
6363
tokenAddress: '0x0', // Set the token address for the OFT adapter
6464
},
6565
},
6666
'avalanche-testnet': {
6767
eid: EndpointId.AVALANCHE_V2_TESTNET,
68-
url: process.env.RPC_URL_FUJI || 'https://rpc.ankr.com/avalanche_fuji',
68+
url: process.env.RPC_URL_FUJI || 'https://avalanche-fuji.drpc.org',
6969
accounts,
7070
},
71-
'amoy-testnet': {
72-
eid: EndpointId.AMOY_V2_TESTNET,
73-
url: process.env.RPC_URL_AMOY || 'https://polygon-amoy-bor-rpc.publicnode.com',
71+
'arbitrum-testnet': {
72+
eid: EndpointId.ARBSEP_V2_TESTNET,
73+
url: process.env.RPC_URL_ARB_SEPOLIA || 'https://arbitrum-sepolia.gateway.tenderly.co',
7474
accounts,
7575
},
7676
hardhat: {
Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
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'
25

3-
import type { OAppOmniGraphHardhat, OmniPointHardhat } from '@layerzerolabs/toolbox-hardhat'
6+
import type { OmniPointHardhat } from '@layerzerolabs/toolbox-hardhat'
47

58
/**
69
* WARNING: ONLY 1 OFTAdapter should exist for a given global mesh.
@@ -17,59 +20,69 @@ import type { OAppOmniGraphHardhat, OmniPointHardhat } from '@layerzerolabs/tool
1720
* },
1821
* },
1922
*/
20-
const sepoliaContract: OmniPointHardhat = {
21-
eid: EndpointId.SEPOLIA_V2_TESTNET,
23+
const optimismContract: OmniPointHardhat = {
24+
eid: EndpointId.OPTSEP_V2_TESTNET,
2225
contractName: 'MyOFTAdapter',
2326
}
2427

25-
const fujiContract: OmniPointHardhat = {
28+
const avalancheContract: OmniPointHardhat = {
2629
eid: EndpointId.AVALANCHE_V2_TESTNET,
2730
contractName: 'MyOFT',
2831
}
2932

30-
const amoyContract: OmniPointHardhat = {
31-
eid: EndpointId.AMOY_V2_TESTNET,
33+
const arbitrumContract: OmniPointHardhat = {
34+
eid: EndpointId.ARBSEP_V2_TESTNET,
3235
contractName: 'MyOFT',
3336
}
3437

35-
const config: OAppOmniGraphHardhat = {
36-
contracts: [
37-
{
38-
contract: fujiContract,
39-
},
40-
{
41-
contract: sepoliaContract,
42-
},
43-
{
44-
contract: amoyContract,
45-
},
38+
// To connect all the above chains to each other, we need the following pathways:
39+
// Optimism <-> Avalanche
40+
// Optimism <-> Arbitrum
41+
// Avalanche <-> Arbitrum
42+
43+
// For this example's simplicity, we will use the same enforced options values for sending to all chains
44+
// 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
45+
// To learn more, read https://docs.layerzero.network/v2/concepts/applications/oapp-standard#execution-options-and-enforced-settings
46+
const EVM_ENFORCED_OPTIONS: OAppEnforcedOption[] = [
47+
{
48+
msgType: 1,
49+
optionType: ExecutorOptionType.LZ_RECEIVE,
50+
gas: 80000,
51+
value: 0,
52+
},
53+
]
54+
55+
// With the config generator, pathways declared are automatically bidirectional
56+
// i.e. if you declare A,B there's no need to declare B,A
57+
const pathways: TwoWayConfig[] = [
58+
[
59+
optimismContract, // Chain A contract
60+
avalancheContract, // Chain B contract
61+
[['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ]
62+
[1, 1], // [A to B confirmations, B to A confirmations]
63+
[EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain B enforcedOptions, Chain A enforcedOptions
4664
],
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-
},
65+
[
66+
optimismContract, // Chain A contract
67+
arbitrumContract, // Chain C contract
68+
[['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ]
69+
[1, 1], // [A to B confirmations, B to A confirmations]
70+
[EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain C enforcedOptions, Chain A enforcedOptions
7271
],
73-
}
72+
[
73+
avalancheContract, // Chain B contract
74+
arbitrumContract, // Chain C contract
75+
[['LayerZero Labs'], []], // [ requiredDVN[], [ optionalDVN[], threshold ] ]
76+
[1, 1], // [A to B confirmations, B to A confirmations]
77+
[EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS], // Chain C enforcedOptions, Chain B enforcedOptions
78+
],
79+
]
7480

75-
export default config
81+
export default async function () {
82+
// Generate the connections config based on the pathways
83+
const connections = await generateConnectionsConfig(pathways)
84+
return {
85+
contracts: [{ contract: optimismContract }, { contract: avalancheContract }, { contract: arbitrumContract }],
86+
connections,
87+
}
88+
}

examples/oft-adapter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@layerzerolabs/lz-evm-protocol-v2": "^3.0.75",
3131
"@layerzerolabs/lz-evm-v1-0.7": "^3.0.75",
3232
"@layerzerolabs/lz-v2-utilities": "^3.0.75",
33+
"@layerzerolabs/metadata-tools": "^2.0.0",
3334
"@layerzerolabs/oapp-evm": "^0.3.2",
3435
"@layerzerolabs/oft-evm": "^3.1.3",
3536
"@layerzerolabs/prettier-config-next": "^2.3.39",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)