Skip to content

Commit

Permalink
feat(evm): adds amb deploy tasks and refactors the hashi ones
Browse files Browse the repository at this point in the history
  • Loading branch information
allemanfredi committed Nov 8, 2023
1 parent 3a1962c commit 42f14eb
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 107 deletions.
55 changes: 31 additions & 24 deletions packages/evm/tasks/deploy/amb.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
import { ethers } from "ethers"
import { task, types } from "hardhat/config"
import type { TaskArguments } from "hardhat/types"

import { verify } from "."
import type { AMBAdapter } from "../../types/contracts/adapters/AMB/AMBAdapter"
import type { AMBHeaderReporter } from "../../types/contracts/adapters/AMB/AMBHeaderReporter"
import type { AMBMessageRelay } from "../../types/contracts/adapters/AMB/AMBMessageRelay"
import type { AMBAdapter__factory } from "../../types/factories/contracts/adapters/AMB/AMBAdapter__factory"
import { AMBHeaderReporter__factory } from "../../types/factories/contracts/adapters/AMB/AMBHeaderReporter__factory"
import { AMBMessageRelay__factory } from "../../types/factories/contracts/adapters/AMB/AMBMessageRelay__factory"

const toBytes32 = (_n: number) => ethers.utils.hexZeroPad(ethers.utils.hexlify(_n), 32)

// Deploy source chain
task("deploy:AMB:MessageRelay")
.addParam("amb", "address of the AMB contract", undefined, types.string)
.addParam("yaho", "address of the yaho contract", undefined, types.string)
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying AMBMessageRelay...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const ambMessageRelayFactory: AMBMessageRelay__factory = <AMBMessageRelay__factory>(
await hre.ethers.getContractFactory("AMBMessageRelay")
)
const constructorArguments = [taskArguments.amb, taskArguments.yaho] as const
const ambMessageRelay: AMBMessageRelay = <AMBMessageRelay>(
await ambMessageRelayFactory.connect(signers[0]).deploy(...constructorArguments)
)
await ambMessageRelay.deployed()
console.log("AMBMessageRelay deployed to:", ambMessageRelay.address)
if (taskArguments.verify) await verify(hre, ambMessageRelay, constructorArguments)
})

// Deploy on destination chain
task("deploy:AMB:Adapter")
.addParam("amb", "address of the AMB contract", undefined, types.string)
.addParam("reporter", "address of the hash reporter", undefined, types.string)
.addParam("messageRelay", "address of the message relay", undefined, types.string)
.addParam("chainId", "chainId of the source chain", undefined, types.int)
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
Expand All @@ -20,31 +43,15 @@ task("deploy:AMB:Adapter")
const ambAdapterFactory: AMBAdapter__factory = <AMBAdapter__factory>(
await hre.ethers.getContractFactory("AMBAdapter")
)
const constructorArguments = [taskArguments.amb, taskArguments.reporter, taskArguments.chainId] as const
const constructorArguments = [
taskArguments.amb,
taskArguments.messageRelay,
toBytes32(taskArguments.chainId),
] as const
const ambAdapter: AMBAdapter = <AMBAdapter>(
await ambAdapterFactory.connect(signers[0]).deploy(...constructorArguments)
)
await ambAdapter.deployed()
console.log("AMBAdapter deployed to:", ambAdapter.address)
if (taskArguments.verify) await verify(hre, ambAdapter, constructorArguments)
})

// Deploy source chain
task("deploy:AMB:HeaderReporter")
.addParam("amb", "address of the AMB contract", undefined, types.string)
.addParam("headerStorage", "address of the header storage contract", undefined, types.string)
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying AMBHeaderReporter...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const ambHeaderReporterFactory: AMBHeaderReporter__factory = <AMBHeaderReporter__factory>(
await hre.ethers.getContractFactory("AMBHeaderReporter")
)
const constructorArguments = [taskArguments.amb, taskArguments.reporter, taskArguments.chainId] as const
const ambHeaderReporter: AMBHeaderReporter = <AMBHeaderReporter>(
await ambHeaderReporterFactory.connect(signers[0]).deploy(...constructorArguments)
)
await ambHeaderReporter.deployed()
console.log("AMBHeaderReporter deployed to:", ambHeaderReporter.address)
if (taskArguments.verify) await verify(hre, ambHeaderReporter, constructorArguments)
})
167 changes: 88 additions & 79 deletions packages/evm/tasks/deploy/hashi.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,71 @@
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"
import { task, types } from "hardhat/config"
import { task } from "hardhat/config"
import type { TaskArguments } from "hardhat/types"

import { verify } from "."
import type { Hashi } from "../../types/contracts/Hashi"
import type { Yaho } from "../../types/contracts/Yaho"
import type { Yaru } from "../../types/contracts/Yaru"
import type { GiriGiriBashi } from "../../types/contracts/ownable/GiriGiriBashi"
import type { HeaderReporter } from "../../types/contracts/headers/HeaderReporter"
import type { HeaderStorage } from "../../types/contracts/headers/HeaderStorage"
import type { HeaderVault } from "../../types/contracts/headers/HeaderVault"
import type { ShoyuBashi } from "../../types/contracts/ownable/ShoyuBashi"
import type { HeaderStorage } from "../../types/contracts/utils/HeaderStorage"
import type { HashiModule } from "../../types/contracts/zodiac/HashiModule"
import type { Hashi__factory } from "../../types/factories/contracts/Hashi__factory"
import type { Yaho__factory } from "../../types/factories/contracts/Yaho__factory"
import type { Yaru__factory } from "../../types/factories/contracts/Yaru__factory"
import type { GiriGiriBashi__factory } from "../../types/factories/contracts/ownable/GiriGiriBashi__factory"
import type { HeaderReporter__factory } from "../../types/factories/contracts/headers/HeaderReporter__factory"
import type { HeaderStorage__factory } from "../../types/factories/contracts/headers/HeaderStorage__factory"
import type { HeaderVault__factory } from "../../types/factories/contracts/headers/HeaderVault__factory"
import type { ShoyuBashi__factory } from "../../types/factories/contracts/ownable/ShoyuBashi__factory"
import type { HeaderStorage__factory } from "../../types/factories/contracts/utils/HeaderStorage__factory"
import type { HashiModule__factory } from "../../types/factories/contracts/zodiac/HashiModule__factory"

task("deploy:Hashi")
// NOTE: Deploy on the source chain
task("deploy:HeaderStorage")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Hashi...")
console.log("Deploying HeaderStorage...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const hashiFactory: Hashi__factory = <Hashi__factory>await hre.ethers.getContractFactory("Hashi")
const hashi: Hashi = <Hashi>await hashiFactory.connect(signers[0]).deploy()
await hashi.deployed()
console.log("Hashi deployed to:", hashi.address)
if (taskArguments.verify) await verify(hre, hashi)
const headerStorageFactory: HeaderStorage__factory = <HeaderStorage__factory>(
await hre.ethers.getContractFactory("HeaderStorage")
)
const headerStorage: HeaderStorage = <HeaderStorage>await headerStorageFactory.connect(signers[0]).deploy()
await headerStorage.deployed()
console.log("HeaderStorage deployed to:", headerStorage.address)
if (taskArguments.verify) await verify(hre, headerStorage)
})

task("deploy:HeaderReporter")
.addParam("headerStorage", "address of the header storage contract")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying HeaderReporter...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const headerReporterFactory: HeaderReporter__factory = <HeaderReporter__factory>(
await hre.ethers.getContractFactory("HeaderReporter")
)
const constructorArguments = [taskArguments.headerStorage] as const
const headerReporter: HeaderReporter = <HeaderReporter>(
await headerReporterFactory.connect(signers[0]).deploy(...constructorArguments)
)
await headerReporter.deployed()
console.log("HeaderReporter deployed to:", headerReporter.address)
if (taskArguments.verify) await verify(hre, headerReporter)
})

task("deploy:Yaho")
.addParam("headerReporter", "address of the header reporter contract")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Yaho...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const yahoFactory: Yaho__factory = <Yaho__factory>await hre.ethers.getContractFactory("Yaho")
const constructorArguments = [taskArguments.headerReporter] as const
const yaho: Yaho = <Yaho>await yahoFactory.connect(signers[0]).deploy(...constructorArguments)
await yaho.deployed()
console.log("Yaho deployed to:", yaho.address)
if (taskArguments.verify) await verify(hre, yaho)
})

// NOTE: Deploy on the destination chain
task("deploy:ShoyuBashi")
.addParam("owner", "address to set as the owner of this contract")
.addParam("hashi", "address of the hashi contract")
Expand All @@ -49,94 +85,67 @@ task("deploy:ShoyuBashi")
if (taskArguments.verify) await verify(hre, shoyuBashi, constructorArguments)
})

task("deploy:GiriGiriBashi")
.addParam("owner", "address to set as the owner of this contract")
.addParam("hashi", "address of the hashi contract")
.addParam("recipient", "address that will receive bonds for unsuccessful challenges")
task("deploy:Hashi")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying GiriGiriBashi...")
console.log("Deploying Hashi...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const giriGiriBashiFactory: GiriGiriBashi__factory = <GiriGiriBashi__factory>(
await hre.ethers.getContractFactory("GiriGiriBashi")
)
const constructorArguments = [taskArguments.owner, taskArguments.hashi, taskArguments.recipient] as const
const giriGiriBashi: GiriGiriBashi = <GiriGiriBashi>(
await giriGiriBashiFactory.connect(signers[0]).deploy(...constructorArguments)
)
await giriGiriBashi.deployed()
console.log("giriGiriBashi deployed to:", giriGiriBashi.address)
if (taskArguments.verify) await verify(hre, giriGiriBashi, constructorArguments)
const hashiFactory: Hashi__factory = <Hashi__factory>await hre.ethers.getContractFactory("Hashi")
const hashi: Hashi = <Hashi>await hashiFactory.connect(signers[0]).deploy()
await hashi.deployed()
console.log("Hashi deployed to:", hashi.address)
if (taskArguments.verify) await verify(hre, hashi)
})

task("deploy:HeaderStorage")
task("deploy:HeaderVault")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying HeaderStorage...")
console.log("Deploying HeaderVault...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const headerStorageFactory: HeaderStorage__factory = <HeaderStorage__factory>(
await hre.ethers.getContractFactory("HeaderStorage")
const headerVaultFactory: HeaderVault__factory = <HeaderVault__factory>(
await hre.ethers.getContractFactory("HeaderVault")
)
const headerStorage: HeaderStorage = <HeaderStorage>await headerStorageFactory.connect(signers[0]).deploy()
await headerStorage.deployed()
console.log("HeaderStorage deployed to:", headerStorage.address)
if (taskArguments.verify) await verify(hre, headerStorage)
})

task("deploy:Yaho")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Yaho...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const yahoFactory: Yaho__factory = <Yaho__factory>await hre.ethers.getContractFactory("Yaho")
const yaho: Yaho = <Yaho>await yahoFactory.connect(signers[0]).deploy()
await yaho.deployed()
console.log("yahoBashi deployed to:", yaho.address)
if (taskArguments.verify) await verify(hre, yaho)
const headerVault: HeaderVault = <HeaderVault>await headerVaultFactory.connect(signers[0]).deploy()
await headerVault.deployed()
console.log("HeaderVault deployed to:", headerVault.address)
if (taskArguments.verify) await verify(hre, headerVault)
})

task("deploy:Yaru")
.addParam("hashi", "address of the hashi contract")
.addParam("yaho", "address of the yaho instance to receive messages from")
.addParam("chainid", "id of the chain to receive messages from", 1, types.int)
.addParam("headerVault", "address of the header vault instance")
.addFlag("verify", "whether to verify the contract on Etherscan")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Yaru...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const yaruFactory: Yaru__factory = <Yaru__factory>await hre.ethers.getContractFactory("Yaru")
const constructorArguments = [taskArguments.hashi, taskArguments.yaho, taskArguments.chainid] as const
const constructorArguments = [taskArguments.hashi, taskArguments.headerVault] as const
const yaru: Yaru = <Yaru>await yaruFactory.connect(signers[0]).deploy(...constructorArguments)
await yaru.deployed()
console.log("yaru deployed to:", yaru.address)
console.log("Yaru deployed to:", yaru.address)
if (taskArguments.verify) await verify(hre, yaru, constructorArguments)
})

task("deploy:HashiModule")
.addParam("owner", "address to set as the owner of this contract")
.addParam("avatar", "address that will execute transactions (probably a Safe)")
.addParam("target", "address that this contract will call (probably a Safe)")
.addParam("yaru", "address of the yaru instance that will call this contract")
.addParam("controller", "address of the controller that can pass messages to this contract")
.addParam("chainid", "id of the chain to receive messages from", 1, types.int)
.addFlag("verify", "whether to verify the contract on Etherscan")
task("deploy:HeaderVault:InitializeYaru")
.addParam("headerVault", "address of the header vault contract")
.addParam("yaru", "address of the yaru contract")
.setAction(async function (taskArguments: TaskArguments, hre) {
console.log("Deploying Hashi Module...")
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const hashiModuleFactory: HashiModule__factory = <HashiModule__factory>(
await hre.ethers.getContractFactory("HashiModule")
const headerVaultFactory: HeaderVault__factory = <HeaderVault__factory>(
await hre.ethers.getContractFactory("HeaderVault")
)
const constructorArguments = [
taskArguments.owner,
taskArguments.avatar,
taskArguments.target,
taskArguments.yaru,
taskArguments.controller,
taskArguments.chainid,
] as const
const hashiModule: HashiModule = <HashiModule>(
await hashiModuleFactory.connect(signers[0]).deploy(...constructorArguments)
)
await hashiModule.deployed()
console.log("hashi deployed to:", hashiModule.address)
if (taskArguments.verify) await verify(hre, hashiModule, constructorArguments)
const headerVault: HeaderVault = <HeaderVault>await headerVaultFactory.attach(taskArguments.headerVault)
await headerVault.initializeYaru(taskArguments.yaru)
console.log("Yaru initialized!")
})

task("deploy:Yaru:InitializeForChainId")
.addParam("chainId", "chain id where yaho is deployed")
.addParam("yaho", "address of the yaho contract")
.addParam("yaru", "address of the yaru contract")
.setAction(async function (taskArguments: TaskArguments, hre) {
const signers: SignerWithAddress[] = await hre.ethers.getSigners()
const yaruFactory: Yaru__factory = <Yaru__factory>await hre.ethers.getContractFactory("Yaru")
const yaru: Yaru = <Yaru>await yaruFactory.connect(signers[0]).attach(taskArguments.yaru)
await yaru.initializeForChainId(taskArguments.chainId, taskArguments.yaho)
console.log("InitializeForChainId completed!")
})
1 change: 1 addition & 0 deletions packages/evm/tasks/deploy/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Contract } from "ethers"
import { HardhatRuntimeEnvironment } from "hardhat/types"

import "./amb"
import "./hashi"
import "./replay"

Expand Down
8 changes: 4 additions & 4 deletions packages/evm/test/utils/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Chains } from "../constants"
type Configs = {
data: string
from: `0x${string}`
messageId: string
id: string
to: `0x${string}`
fromChainId: number
toChainId: number
Expand All @@ -19,8 +19,8 @@ class Message {
public fromChainId
public data

constructor({ data, from, fromChainId = Chains.Hardhat, messageId, to, toChainId }: Configs) {
this.id = messageId
constructor({ data, from, fromChainId = Chains.Hardhat, id, to, toChainId }: Configs) {
this.id = id
this.from = from
this.toChainId = toChainId
this.to = to
Expand All @@ -38,7 +38,7 @@ class Message {
)
const messages = logs.map(({ topics, data }) => iface.parseLog({ topics, data }))
return messages.map(
({ args: { data, from, messageId, to, toChainId } }) => new Message({ data, from, messageId, to, toChainId }),
({ args: { data, from, messageId, to, toChainId } }) => new Message({ data, from, id: messageId, to, toChainId }),
)
}

Expand Down

0 comments on commit 42f14eb

Please sign in to comment.