Skip to content

Commit

Permalink
refactor(tasks): refactors l0 adpter/reporter deployment tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed May 6, 2024
1 parent d08cd02 commit ead7541
Showing 1 changed file with 14 additions and 65 deletions.
79 changes: 14 additions & 65 deletions packages/evm/tasks/deploy/adapters/layerzero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import { task } from "hardhat/config"
import type { TaskArguments } from "hardhat/types"

import type { LayerZeroAdapter } from "../../../types/contracts/adapters/LayerZero/LayerZeroAdapter"
import type { LayerZeroHeaderReporter } from "../../../types/contracts/adapters/LayerZero/LayerZeroHeaderReporter"
import type { LayerZeroMessageRelay } from "../../../types/contracts/adapters/LayerZero/LayerZeroMessageRelay"
import type { LayerZeroReporter } from "../../../types/contracts/adapters/LayerZero/LayerZeroReporter"
import type { LayerZeroAdapter__factory } from "../../../types/factories/contracts/adapters/LayerZero/LayerZeroAdapter__factory"
import type { LayerZeroHeaderReporter__factory } from "../../../types/factories/contracts/adapters/LayerZero/LayerZeroHeaderReporter__factory"
import type { LayerZeroMessageRelay__factory } from "../../../types/factories/contracts/adapters/LayerZero/LayerZeroMessageRelay__factory"
import type { LayerZeroReporter__factory } from "../../../types/factories/contracts/adapters/LayerZero/LayerZeroReporter__factory"
import { verify } from "../index"

task("deploy:adapter:LayerZeroAdapter")
.addParam("chainId", "chain id of the reporter contract")
.addParam(
"lzChainId",
"layerzero chain id (according to https://layerzero.gitbook.io/docs/technical-reference/mainnet/supported-chain-ids)",
)
.addParam("reporter", "address of the reporter contract")
task("deploy:LayerZeroAdapter")
.addParam("lzEndpoint", "address of the LayerZero endpoint contract")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
Expand All @@ -25,12 +17,7 @@ task("deploy:adapter:LayerZeroAdapter")
const layerZeroAdapterFactory: LayerZeroAdapter__factory = <LayerZeroAdapter__factory>(
await hre.ethers.getContractFactory("LayerZeroAdapter")
)
const constructorArguments = [
taskArguments.chainId,
taskArguments.reporter,
taskArguments.lzEndpoint,
taskArguments.lzChainId,
] as const
const constructorArguments = [taskArguments.lzEndpoint] as const
const layerZeroAdapter: LayerZeroAdapter = <LayerZeroAdapter>(
await layerZeroAdapterFactory.connect(signers[0]).deploy(...constructorArguments)
)
Expand All @@ -39,60 +26,22 @@ task("deploy:adapter:LayerZeroAdapter")
if (taskArguments.verify) await verify(hre, layerZeroAdapter, constructorArguments)
})

task("deploy:adapter:LayerZeroHeaderReporter")
.addParam("chainId", "chain id of the adapter contract")
.addParam(
"lzChainId",
"layerzero chain id (according to https://layerzero.gitbook.io/docs/technical-reference/mainnet/supported-chain-ids)",
)
task("deploy:LayerZeroReporter")
.addParam("headerStorage", "address of the header storage contract")
.addParam("lzEndpoint", "address of the LayerZero endpoint contract")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying LayerZeroHeaderReporter...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const layerZeroHeaderReporterFactory: LayerZeroHeaderReporter__factory = <LayerZeroHeaderReporter__factory>(
await hre.ethers.getContractFactory("LayerZeroHeaderReporter")
)
const constructorArguments = [
taskArguments.headerStorage,
taskArguments.chainId,
taskArguments.lzEndpoint,
taskArguments.lzChainId,
] as const
const layerZeroHeaderReporter: LayerZeroHeaderReporter = <LayerZeroHeaderReporter>(
await layerZeroHeaderReporterFactory.connect(signers[0]).deploy(...constructorArguments)
)
await layerZeroHeaderReporter.deployed()
console.log("LayerZeroHeaderReporter deployed to:", layerZeroHeaderReporter.address)
if (taskArguments.verify) await verify(hre, layerZeroHeaderReporter, constructorArguments)
})

task("deploy:adapter:LayerZeroMessageRelay")
.addParam("chainId", "chain id of the adapter contract")
.addParam(
"lzChainId",
"layerzero chain id (according to https://layerzero.gitbook.io/docs/technical-reference/mainnet/supported-chain-ids)",
)
.addParam("yaho", "address of the Yaho contract")
.addParam("lzEndpoint", "address of the LayerZero endpoint contract")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying LayerZeroMessageRelay...")
console.log("Deploying LayerZeroReporter...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const layerZeroMessageRelayFactory: LayerZeroMessageRelay__factory = <LayerZeroMessageRelay__factory>(
await hre.ethers.getContractFactory("LayerZeroMessageRelay")
const layerZeroReporterFactory: LayerZeroReporter__factory = <LayerZeroReporter__factory>(
await hre.ethers.getContractFactory("LayerZeroReporter")
)
const constructorArguments = [
taskArguments.yaho,
taskArguments.chainId,
taskArguments.lzEndpoint,
taskArguments.lzChainId,
] as const
const layerZeroMessageRelay: LayerZeroMessageRelay = <LayerZeroMessageRelay>(
await layerZeroMessageRelayFactory.connect(signers[0]).deploy(...constructorArguments)
const constructorArguments = [taskArguments.headerStorage, taskArguments.yaho, taskArguments.lzEndpoint] as const
const layerZeroReporter: LayerZeroReporter = <LayerZeroReporter>(
await layerZeroReporterFactory.connect(signers[0]).deploy(...constructorArguments)
)
await layerZeroMessageRelay.deployed()
console.log("LayerZeroMessageRelay deployed to:", layerZeroMessageRelay.address)
if (taskArguments.verify) await verify(hre, layerZeroMessageRelay, constructorArguments)
await layerZeroReporter.deployed()
console.log("LayerZeroReporter deployed to:", layerZeroReporter.address)
if (taskArguments.verify) await verify(hre, layerZeroReporter, constructorArguments)
})

0 comments on commit ead7541

Please sign in to comment.