Skip to content

Commit d103291

Browse files
authored
DEVREL-518 Feat: add send task to oft (#1561)
1 parent 2648a5c commit d103291

28 files changed

Lines changed: 1502 additions & 116 deletions

.changeset/flat-bears-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/oft-example": minor
3+
---
4+
5+
Adds a normalized send script that can be extended for other VMs

.changeset/orange-sheep-provide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/mint-burn-oft-adapter-example": minor
3+
---
4+
5+
Adds a send script and simple config to the MABA example

.changeset/tricky-spies-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/oft-adapter-example": minor
3+
---
4+
5+
Adds send task to oft-adapter

examples/mint-burn-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
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import assert from 'assert'
2+
3+
import { type DeployFunction } from 'hardhat-deploy/types'
4+
5+
const contractName = 'MintBurnERC20Mock'
6+
7+
const deploy: DeployFunction = async (hre) => {
8+
const { getNamedAccounts, deployments } = hre
9+
10+
const { deploy } = deployments
11+
const { deployer } = await getNamedAccounts()
12+
13+
assert(deployer, 'Missing named deployer account')
14+
15+
console.log(`Network: ${hre.network.name}`)
16+
console.log(`Deployer: ${deployer}`)
17+
18+
// Token configuration
19+
const tokenName = 'Mock Mint Burn Token'
20+
const tokenSymbol = 'MMBT'
21+
const initialMintAmount = hre.ethers.utils.parseEther('1000000') // 1M tokens
22+
23+
const { address } = await deploy(contractName, {
24+
from: deployer,
25+
args: [
26+
tokenName, // Token name
27+
tokenSymbol, // Token symbol
28+
],
29+
log: true,
30+
skipIfAlreadyDeployed: false,
31+
})
32+
33+
console.log(`Deployed contract: ${contractName}, network: ${hre.network.name}, address: ${address}`)
34+
console.log(`Token: ${tokenName} (${tokenSymbol})`)
35+
36+
// Mint initial tokens to the deployer
37+
const [signer] = await hre.ethers.getSigners()
38+
const mintBurnToken = await hre.ethers.getContractAt(contractName, address, signer)
39+
40+
const mintTx = await mintBurnToken.mint(deployer, initialMintAmount)
41+
await mintTx.wait()
42+
43+
const balance = await mintBurnToken.balanceOf(deployer)
44+
console.log(`Minted ${hre.ethers.utils.formatEther(balance)} ${tokenSymbol} tokens to deployer: ${deployer}`)
45+
}
46+
47+
deploy.tags = [contractName]
48+
49+
export default deploy

examples/mint-burn-oft-adapter/hardhat.config.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { EndpointId } from '@layerzerolabs/lz-definitions'
1515

1616
import './type-extensions'
1717

18+
import './tasks/sendOFT'
19+
1820
// Set your preferred authentication method
1921
//
2022
// If you prefer using a mnemonic, set a MNEMONIC environment variable
@@ -54,9 +56,9 @@ const config: HardhatUserConfig = {
5456
],
5557
},
5658
networks: {
57-
'sepolia-testnet': {
58-
eid: EndpointId.SEPOLIA_V2_TESTNET,
59-
url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/',
59+
'optimism-testnet': {
60+
eid: EndpointId.OPTSEP_V2_TESTNET,
61+
url: process.env.RPC_URL_OP_SEPOLIA || 'https://optimism-sepolia.gateway.tenderly.co',
6062
accounts,
6163
oftAdapter: {
6264
tokenAddress: '0x0', // Set the token address for the OFT adapter
@@ -66,11 +68,17 @@ const config: HardhatUserConfig = {
6668
eid: EndpointId.AVALANCHE_V2_TESTNET,
6769
url: process.env.RPC_URL_FUJI || 'https://rpc.ankr.com/avalanche_fuji',
6870
accounts,
71+
oftAdapter: {
72+
tokenAddress: '0x0', // Set the token address for the OFT adapter
73+
},
6974
},
70-
'amoy-testnet': {
71-
eid: EndpointId.AMOY_V2_TESTNET,
72-
url: process.env.RPC_URL_AMOY || 'https://polygon-amoy-bor-rpc.publicnode.com',
75+
'arbitrum-testnet': {
76+
eid: EndpointId.ARBSEP_V2_TESTNET,
77+
url: process.env.RPC_URL_ARB_SEPOLIA || 'https://arbitrum-sepolia.gateway.tenderly.co',
7378
accounts,
79+
oftAdapter: {
80+
tokenAddress: '0x0', // Set the token address for the OFT adapter
81+
},
7482
},
7583
hardhat: {
7684
// Need this for testing because TestHelperOz5.sol is exceeding the compiled contract size limit
Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,73 @@
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

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,
2210
contractName: 'MyMintBurnOFTAdapter',
2311
}
2412

25-
const fujiContract: OmniPointHardhat = {
13+
const avalancheContract: OmniPointHardhat = {
2614
eid: EndpointId.AVALANCHE_V2_TESTNET,
2715
contractName: 'MyOFT',
2816
}
2917

30-
const amoyContract: OmniPointHardhat = {
31-
eid: EndpointId.AMOY_V2_TESTNET,
18+
const arbitrumContract: OmniPointHardhat = {
19+
eid: EndpointId.ARBSEP_V2_TESTNET,
3220
contractName: 'MyOFT',
3321
}
3422

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
4649
],
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
7256
],
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+
]
7465

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+
}

examples/mint-burn-oft-adapter/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
},
2323
"devDependencies": {
2424
"@babel/core": "^7.23.9",
25+
"@layerzerolabs/devtools-evm-hardhat": "^3.1.0",
2526
"@layerzerolabs/eslint-config-next": "~2.3.39",
27+
"@layerzerolabs/io-devtools": "~0.2.0",
2628
"@layerzerolabs/lz-definitions": "^3.0.75",
2729
"@layerzerolabs/lz-evm-messagelib-v2": "^3.0.75",
2830
"@layerzerolabs/lz-evm-protocol-v2": "^3.0.75",
2931
"@layerzerolabs/lz-evm-v1-0.7": "^3.0.75",
3032
"@layerzerolabs/lz-v2-utilities": "^3.0.75",
33+
"@layerzerolabs/metadata-tools": "^2.0.0",
3134
"@layerzerolabs/oapp-evm": "^0.3.2",
3235
"@layerzerolabs/oft-evm": "^3.1.3",
3336
"@layerzerolabs/prettier-config-next": "^2.3.39",

0 commit comments

Comments
 (0)