Skip to content

Instantly share code, notes, and snippets.

@Sahilsen
Created November 6, 2023 15:19
Show Gist options
  • Save Sahilsen/ebb2cbd3c4ac12b753b37fdd1288b635 to your computer and use it in GitHub Desktop.
Save Sahilsen/ebb2cbd3c4ac12b753b37fdd1288b635 to your computer and use it in GitHub Desktop.
const CHAIN_ID = require("../constants/chainIds.json")
const ENDPOINTS = require("../constants/layerzeroEndpoints.json")
module.exports = async function (taskArgs, hre) {
const remoteChainId = CHAIN_ID[taskArgs.targetNetwork]
const omniCounter = await ethers.getContract("OmniCounter")
// quote fee with default adapterParams
let adapterParams = ethers.utils.solidityPack(["uint16", "uint256"], [1, 200000]) // default adapterParams example
const endpoint = await ethers.getContractAt("ILayerZeroEndpoint", ENDPOINTS[hre.network.name])
let fees = await endpoint.estimateFees(remoteChainId, omniCounter.address, "0x", false, adapterParams)
console.log(`fees[0] (wei): ${fees[0]} / (eth): ${ethers.utils.formatEther(fees[0])}`)
let increasedFee = fees[0].add(ethers.utils.parseEther("0.01")); // Adding 0.01 ETH for buffer
console.log(`Sending with increased fee (wei): ${increasedFee} / (eth): ${ethers.utils.formatEther(increasedFee)}`);
let tx = await (await omniCounter.incrementCounter(remoteChainId, { value: increasedFee })).wait()
console.log(`✅ Message Sent [${hre.network.name}] incrementCounter on destination OmniCounter @ [${remoteChainId}]`)
console.log(`tx: ${tx.transactionHash}`)
console.log(``)
console.log(`Note: to poll/wait for the message to arrive on the destination use the command:`)
console.log(` (it may take a minute to arrive, be patient!)`)
console.log("")
console.log(` $ npx hardhat --network ${taskArgs.targetNetwork} ocPoll`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment