Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: a better bootstrap experience #114

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions packages/ua-utils-evm-hardhat-test/deploy/001_bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { type DeployFunction } from 'hardhat-deploy/types'
import assert from 'assert'
import { TransactionReceipt, TransactionResponse } from '@ethersproject/providers'
import { formatEid } from '@layerzerolabs/utils'
import { wrapEIP1193Provider } from '@layerzerolabs/utils-evm-hardhat'
import env from 'hardhat'
import assert from 'assert'
import { Contract } from 'ethers'
import { TransactionReceipt, TransactionResponse } from '@ethersproject/providers'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

const DEFAULT_NATIVE_DECIMALS_RATE = '18' //ethers.utils.parseUnits('1', 18).toString()

/**
* This deploy function will deploy and configure LayerZero endpoint
* This `deploy` function will deploy and configure LayerZero EndpointV2. This includes:
* - EndpointV2
* - SendUln302
* - ReceiveUln302
* - PriceFeed
* - Executor
* - ExecutorFeeLib
* - DVN
* - DVNFeeLib
*
* @param env `HardhatRuntimeEnvironment`
* @param {HardhatRuntimeEnvironment} env
*/
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }) => {
const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => {
assert(network.config.eid != null, `Missing endpoint ID for network ${network.name}`)

const [deployer] = await getUnnamedAccounts()
assert(deployer, 'Missing deployer')
const signer = wrapEIP1193Provider(network.provider).getSigner()

await deployments.delete('EndpointV2')
const endpointV2Deployment = await deployments.deploy('EndpointV2', {
Expand Down Expand Up @@ -109,13 +118,15 @@ const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network
},
})

const signer = wrapEIP1193Provider(env.network.provider).getSigner()
const executorContract = new Contract(executor.address, executor.abi).connect(signer)
const setExecFeeLibResp: TransactionResponse = await executorContract.setWorkerFeeLib?.(executorFeeLib.address, {
from: await signer.getAddress(),
})
const setExecFeeLibReceipt: TransactionReceipt = await setExecFeeLibResp.wait()
const setExecFeeLibResp: TransactionResponse = await executorContract.setWorkerFeeLib(executorFeeLib.address)
const setExecFeeLibReceipt: TransactionReceipt = await setExecFeeLibResp.wait(1)
assert(setExecFeeLibReceipt?.status === 1)
const polledExecutorFeeLib = await executorContract.workerFeeLib?.()
assert(
polledExecutorFeeLib?.toLowerCase() === executorFeeLib.address.toLowerCase(),
'Executor worker fee lib not set correctly'
)

await deployments.delete('DVN')
const dvn = await deployments.deploy('DVN', {
Expand All @@ -137,11 +148,11 @@ const deploy: DeployFunction = async ({ getUnnamedAccounts, deployments, network
})

const dvnContract = new Contract(dvn.address, dvn.abi).connect(signer)
const setDvnFeeLibResp: TransactionResponse = await dvnContract.setWorkerFeeLib?.(dvnFeeLib.address, {
from: await signer.getAddress(),
})
const setDvnFeeLibResp: TransactionResponse = await dvnContract.setWorkerFeeLib?.(dvnFeeLib.address)
const setDvnFeeLibReceipt: TransactionReceipt = await setDvnFeeLibResp.wait()
assert(setDvnFeeLibReceipt?.status === 1)
const polledDvnFeeLib = await dvnContract.workerFeeLib?.()
assert(polledDvnFeeLib?.toLowerCase() === dvnFeeLib.address.toLowerCase(), 'DVN worker fee lib not set correctly')

console.table({
Network: `${network.name} (endpoint ${formatEid(network.config.eid)})`,
Expand Down