Code Monkey home page Code Monkey logo

devtools's Introduction

LayerZero

Homepage | Docs | Developers

LayerZero Developer Utilities

Development | Cheatsheet | Examples


Please note that this repository is in a beta state and backwards-incompatible changes might be introduced in future releases. While we strive to comply to semver, we can not guarantee to avoid breaking changes in minor releases.


Introduction

This toolkit is designed to streamline the process of building, testing, and deploying omnichain applications (OApps) using LayerZero. This tool is meant to support you through the end-to-end development lifecycle of a cross-chain project.

Visit our developer docs to get started building omnichain applications.

Bootstrapping an Example Cross-Chain Project

Kick-start your development with our create-lz-oapp CLI utility. This command-line tool facilitates the creation of a new omnichain application project, setting up the necessary environment and dependencies:

npx create-lz-oapp@latest

Following this, you will be guided through setting up a project template. Choose from a variety of examples to match your project needs.

Writing Smart Contracts

Our example project offers templates for both the Omnichain Application (OApp) and Omnichain Fungible Token (OFT) contracts. Select the template that suits your project:

Writing Unit Tests

Testing your contracts is crucial. We support both Hardhat and Foundry frameworks for writing and running unit tests for your LayerZero contracts.

Use npx hardhat compile or forge build to compile your smart contracts.

Test your contract using npx hardhat test or forge test.

Deploying Contracts

To deploy your contracts to your desired blockchains, run the following command in your project's folder:

npx hardhat lz:deploy

More information about available CLI arguments can be found using the --help flag:

npx hardhat lz:deploy --help

Configuring contracts

The examples come with basic layerzero.config.ts files that should get you started on testnet straight away.

More information on how to configure your OApp will be available in our docs soon.

Wiring Contracts

Pair your deployed contracts using:

npx hardhat lz:oapp:wire --oapp-config layerzero.config.ts

By following these steps, you can focus more on creating innovative omnichain solutions and less on the complexities of cross-chain communication.



Join our community on Discord | Follow us on Twitter

devtools's People

Contributors

0xfoobar avatar 0xiryna avatar chengenh avatar enjoyooor avatar intensodefi avatar janjakubnanista avatar karthik-gupta avatar layerzero-bot avatar nazreen avatar ravinagill15 avatar ryandgoulding avatar sirarthurmoney avatar st0rmbr3w avatar trileyschwarz avatar wyattwestdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

devtools's Issues

🧹 Replace hardhat node with anvil in CI/CD

Is your feature request related to a problem? Please describe.

Currently the EVM nodes that support the test runs are hardhat nodes. This slows down the pipeline in two ways:

  • The docker container needs to be built for the nodes to start
  • The node itself is lower performance than anvil

Describe the solution you'd like

Replace the test-evm-node package and its usage with anvil-based node implementation

Problem solution

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Guidance on testing OFT contracts locally (LZ endpoint mock/local deploy)

Thanks @kushdave95 for your support in DM, as requested an issue with details on my testing questions.

Is your feature request related to a problem? Please describe.

When building an LZ OFT contract and wanting to test it locally with hardhat/foundry, the OFT contract requires an LZ endpoint to be deployed (or perhaps mocked).

I would appreciate guidance on how to best do this. Note that this example in this repository does NOT show how to do this. It only tests a mock OFT contract.

Describe the solution you'd like

A clear example (or docs) on how to test an OFT contract locally in hardhat. I assume this means having a clear mock of an LZ endpoint (and how to implement it in a testing context).

Describe alternatives you've considered

I tried this repo's examples but as #399 indicates, this did not actually show how to test the contract, only the mock.

Additional context

From a DX perspective this would be very appreciated, as testing only on live testnets is suboptimal at best.

bug: [bug summary]

there is a typo while running the following command : npx create-lz-oapp@latest

instead of dapp it shows deap

UlnOptionsMock deployment is incompatible with foundry fork tests

Describe the bug
When using Foundry fork tests, any local deployments made before the fork is set up, will be overwritten to have empty code. And in OptionsHelper.sol the line UlnOptionsMock ulnOptions = new UlnOptionsMock(); is preformed at deployment, while the fork is set up in the setUp() function.

This leads to a confusing EVM revert when trying to call verifyPackets() in a forked test

To Reproduce
Steps to reproduce the behavior:

  1. deploy your contracts and fork in setUp() function
  2. Write a test to preform an OApp.bridge() followed by a call to verifyPackets()

Expected behavior
The expectation is that whatever functionality in the receiver contract's _lzReceive() will be executed

Environment

  • OS: Debian
  • OS Version 12 (bookworm)

Additional context
My solution in OptionsHelper.sol was to replace:

    UlnOptionsMock ulnOptions = new UlnOptionsMock();

with

    UlnOptionsMock ulnOptions;

    function setUp() public virtual {
        ulnOptions = new UlnOptionsMock();
    }

Note that this setUp() function must be overriden in TestHelperOz5.sol and also called in the setUp of your test

🗞️ Export Safe-compatible JSON from lz:oapp:wire and lz:ownable:transfer-ownership

Is your feature request related to a problem? Please describe.
Some of the Safe UIs are not compatible with the current way of signing safe transactions. The aforementioned tasks should support a JSON-compatible output generation so that the user can export the transactions and upload them manually to the Safe UI

Describe the solution you'd like
Add a CLI flag to the tasks that will make them either:

  • Export a JSON file to filesystem
  • Print out the JSON file to the console

bug: Incorrect message in unit test of OApp example

Describe the bug
Should replace Nothing received yet. with Test message. in the line 74.

To Reproduce
No need

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

Environment (please complete the following information):
No need

Additional context
LayerZero docs notes that make sure that the arguments passed into the _quote function identically match the parameters used in the lzSend function. If parameters mismatch, you may run into errors as your msg.value will not match the actual gas quote.
So the bug may lead beginners to be confused.

bug: README's wiring command is missing the --oapp-config flag

Describe the bug
The README says to run npx hardhat lz:oapp:wire when wiring contracts.

To Reproduce
Steps to reproduce the behavior:

  1. Run npx create-lz-oapp@latest to scaffold a new LayerZero OApp/ONft
  2. (Assuming you have a valid pk defined in the .env and that address has sufficient gas tokens on all chains) Run npx hardhat lz:deploy
  3. Run npx hardhat lz:oapp:wire

Expected behavior
Wiring continues successfully.

Screenshots
image

Environment (please complete the following information):

  • OS: macOS
  • OS Version: 14.2.1
  • VM: node
  • VM Version: 18.19.0

Additional context
Add any other context about the problem here.

bug: fail to create oapp with create-lz-oapp@latest

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

❯ npx create-lz-oapp@latest

Expected behavior
This command will create of a new omnichain application project, set up the necessary environment and dependencies.

Screenshots

✔ Where do you want to start your project? … ./my-lz-oapp
✔ Which example would you like to use as a starting point? › OFT
✔ What package manager would you like to use in your project? › pnpm

Will create a project in ./my-lz-oapp directory (/Users/gx/temp/demo/my-lz-oapp)
Will use the OFT example
Will use pnpm to install dependencies

✔ Do you want to continue? … yes
𐄂 Getting example source code
  Error: Unknown error during example cloning
○ Installing dependencies

Environment (please complete the following information):

❯ uname -a
Darwin MacBook-Pro-3.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:43:05 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6020 arm64
❯ node --version           
v18.12.0
❯ which pnpm     
/Users/gx/.nvm/versions/node/v18.12.0/bin/pnpm
  • OS: macOS
  • OS Version: 14.0
  • VM: Node
  • VM Version: 18.12.0

Additional context
Add any other context about the problem here.

bug: No param `baseGas` in `DstConfigParam` struct

Describe the bug
After $ npx create-lz-oapp@latest, I faced error when compiling.

To Reproduce
Steps to reproduce the behavior:

  1. $ npx create-lz-oapp@latest to create a project.
  2. Select OFT option
  3. $ pnpm compile gives this error:
$ pnpm compile

> @layerzerolabs/[email protected] compile /Users/abhi3700/F/coding/github_repos/subspace/layerzero-demo2/my-lz-oapp
> $npm_execpath run compile:forge && $npm_execpath run compile:hardhat


> @layerzerolabs/[email protected] compile:forge /Users/abhi3700/F/coding/github_repos/subspace/layerzero-demo2/my-lz-oapp
> forge build

[⠊] Compiling...
[⠔] Compiling 122 files with 0.8.22
[⠒] Solc 0.8.22 finished in 439.99ms
Error:
Compiler run failed:
Error (9582): Member "baseGas" not found or not visible after argument-dependent lookup in struct IExecutor.DstConfigParam memory.
  --> node_modules/@layerzerolabs/test-devtools-evm-foundry/contracts/mocks/ExecutorMock.sol:46:17:
   |
46 |                 param.baseGas,
   |                 ^^^^^^^^^^^^^

 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

Expected behavior
It should have compiled successfully. Clearly, the parameter baseGas is not present in DstConfigParam struct in IExecutor.sol. Screenshot attached

Screenshots
image
image

Environment (please complete the following information):

  • OS: macOS
  • OS Sonoma 14.4.1
  • VM: node
  • VM Version: v18.18.0

Additional context
None

bug: OFT Arbitrum-Sepolia -> Sepolia Config Errors and OFT contract Gas Estimation Problems

Hi there,

Looking to deploy an OFT for multiple chains, but starting on Testnets of course. I have Both OFTs Deployed to Arbitrum-Sepolia and to ETH-Sepolia, and I have been facing two Errors.

  1. Error: An error occurred while getting the OApp configuration: AssertionError [ERR_ASSERTION]: Could not find a deployment for address '0xa96b3749D01A50c4353f66455dBD92a52778C65A' on ARBSEP_V2_TESTNET (arbitrumSepolia)

This error occurs when attempting to run the wiring with this command:
npx hardhat lz:oapp:peers:get --oapp-config layerzero.config.ts

and this HardHat Config

const config: HardhatUserConfig = {
    paths: {
        cache: 'cache/hardhat',
    },
    solidity: {
        compilers: [
            {
                version: '0.8.22',
                settings: {
                    optimizer: {
                        enabled: true,
                        runs: 200,
                    },
                },
            },
        ],
    },
    networks: {
        sepolia: {
            eid: EndpointId.SEPOLIA_V2_TESTNET,
            url: 'https://eth-sepolia.g.alchemy.com/v2/<API_KEY>',
            accounts,
        },
        arbitrumSepolia: {
            eid: EndpointId.ARBSEP_V2_TESTNET,
            url: 'https://arb-sepolia.g.alchemy.com/v2/<API_KEY>',
            accounts,
        },
    },
    namedAccounts: {
        deployer: {
            default: 0, // wallet address of index[0], of the mnemonic in .env
        },
    },

and this layerzeroConfig.ts

export const sepoliaContract: OmniPointHardhat = {
    eid: EndpointId.SEPOLIA_V2_TESTNET,

    contractName: 'GODOFT',
    address: '0xDee109faA9a53E6aBD3fE4ca2d1E423E4FC6D019',
}

export const arbSepContract: OmniPointHardhat = {
    eid: EndpointId.ARBSEP_V2_TESTNET,

    contractName: 'GODOFT',
    address: '0xa96b3749D01A50c4353f66455dBD92a52778C65A',
}

const config: OAppOmniGraphHardhat = {
    contracts: [
        {
            contract: arbSepContract,
        },
        {
            contract: sepoliaContract,
        },
    ],
    connections: [
        {
            from: arbSepContract,
            to: sepoliaContract,
        },
        {
            from: sepoliaContract,
            to: arbSepContract,
        },
    ],
}

export default config

Expected behavior
I would have expected in the first instance for the Configuration to find the Contract deployed on the Arbitrum Sepolia Network, as clearly the transactions and other infrastructure is functioning properly.

Both of the Contracts are IN-fact deployed and validated on testnets
https://sepolia.arbiscan.io/address/0xa96b3749D01A50c4353f66455dBD92a52778C65A
https://sepolia.etherscan.io/address/0xDee109faA9a53E6aBD3fE4ca2d1E423E4FC6D019

Screenshots

Environment (please complete the following information):

  • OS: [e.g. macOS]
  • OS Version [e.g. 14.1]
  • VM: [e.g. node]
  • VM Version: [e.g. 18.18.0] (Ive Attemped this on several different versions of Node 18 - 22)

Additional context
Additional Context about the Insane Gas Price issue:

Here is the Task that I created to test the bridging between the two test nets:

The second Problem is when trying to bridge any more than 1-10 tokens the Gas fee quickly jumps from Dust essentially to 10x or more as constituted by this error from hardhat.

 reason: 'insufficient funds for intrinsic transaction cost',
  code: 'INSUFFICIENT_FUNDS',
  error: ProviderError: insufficient funds for gas * price + value: balance 203411533023759192, queued cost 153614836329641605, tx cost 137077919996323037, overshot 87281223302205450
task('lz:oft:send', 'test send')
    .addParam('contractA', 'contract address on network A')
    .addParam('contractB', 'contract address on network B')
    .addParam('networkA', 'name of the network A')
    .addParam('networkB', 'name of the network B')
    .addParam('amount', 'amount to transfer in eth')
    .setAction(async (taskArgs, { ethers }) => {
        const eidA = getEidForNetworkName(taskArgs.networkA)
        const eidB = getEidForNetworkName(taskArgs.networkB)
        const contractA = taskArgs.contractA
        const contractB = taskArgs.contractB
        const environmentFactory = createGetHreByEid()
        const providerFactory = createProviderFactory(environmentFactory)
        const signer = (await providerFactory(eidA)).getSigner()

        const oftContractFactory = await ethers.getContractFactory('MyOFT', signer)
        const oft = oftContractFactory.attach(contractA)

        const decimals = await oft.decimals()
        const amount = ethers.utils.parseUnits(taskArgs.amount, decimals)
        const options = Options.newOptions().addExecutorLzReceiveOption(200000, 0).toHex().toString()

        const sender = await signer.getAddress()
        const sendParam = [eidB, ethers.utils.zeroPad(sender, 32), amount, amount, options, '0x', '0x']
        console.log(sendParam)
        const [nativeFee] = await oft.quoteSend(sendParam, false)
        console.log({ eidA, eidB, contractA, contractB, amount, sender, nativeFee })
        console.log(
            `sending ${taskArgs.amount} token(s) from network ${taskArgs.networkA} to network ${taskArgs.networkB}`
        )
        console.log(sendParam, [nativeFee, 0], sender, { value: nativeFee })

        const r = await oft.send(sendParam, [nativeFee, 0], sender, { value: nativeFee })
        console.log(`Tx initiated. See: https://layerzeroscan.com/tx/${r.hash}`)
    })

In Summary:

What am I missing in terms of configuration here to prevent the wild fluctuation in Gas Prices: and How can I get the Arbitrum Sepolia testnet to recognize the Contracts I have deployed to use these tools effectively

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.