Skip to content

Commit

Permalink
Deployment scripts for Base
Browse files Browse the repository at this point in the history
Here we add deployment scripts for both `L*BitcoinDepositor` contracts.
We use Base as the reference chain.
  • Loading branch information
lukasz-zimnoch committed Mar 1, 2024
1 parent 7f81fbe commit 533e889
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 3 deletions.
53 changes: 53 additions & 0 deletions cross-chain/base/deploy_l1/00_deploy_base_l1_bitcoin_depositor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"
import { getWormholeChains } from "../deploy_helpers/wormhole_chains"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { ethers, getNamedAccounts, helpers, deployments } = hre
const { deployer } = await getNamedAccounts()
const l2Deployments = hre.companionNetworks.l2.deployments

const wormholeChains = getWormholeChains(hre.network.name)

const tbtcBridge = await deployments.get("Bridge")
const tbtcVault = await deployments.get("TBTCVault")
const wormhole = await deployments.get("Wormhole")
const wormholeRelayer = await deployments.get("WormholeRelayer")
const wormholeTokenBridge = await deployments.get("TokenBridge")
const baseWormholeGateway = await l2Deployments.get("BaseWormholeGateway")

const [, proxyDeployment] = await helpers.upgrades.deployProxy(
"BaseL1BitcoinDepositor",
{
contractName:
"@keep-network/tbtc-v2/contracts/l2/L1BitcoinDepositor.sol:L1BitcoinDepositor",
initializerArgs: [
tbtcBridge.address,
tbtcVault.address,
wormhole.address,
wormholeRelayer.address,
wormholeTokenBridge.address,
baseWormholeGateway.address,
wormholeChains.l2ChainId,
],
factoryOpts: { signer: await ethers.getSigner(deployer) },
proxyOpts: {
kind: "transparent",
},
}
)

if (hre.network.tags.etherscan) {
// We use `verify` instead of `verify:verify` as the `verify` task is defined
// in "@openzeppelin/hardhat-upgrades" to perform Etherscan verification
// of Proxy and Implementation contracts.
await hre.run("verify", {
address: proxyDeployment.address,
constructorArgsParams: proxyDeployment.args,
})
}
}

export default func

func.tags = ["BaseL1BitcoinDepositor"]
25 changes: 25 additions & 0 deletions cross-chain/base/deploy_l1/01_attach_base_l2_bitcoin_depositor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts } = hre
const { deployer } = await getNamedAccounts()
const { execute } = deployments
const l2Deployments = hre.companionNetworks.l2.deployments

const baseL2BitcoinDepositor = await l2Deployments.get(
"BaseL2BitcoinDepositor"
)

await execute(
"BaseL1BitcoinDepositor",
{ from: deployer, log: true, waitConfirmations: 1 },
"attachL2BitcoinDepositor",
baseL2BitcoinDepositor.address
)
}

export default func

func.tags = ["AttachBaseL2BitcoinDepositor"]
func.dependencies = ["BaseL1BitcoinDepositor"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, helpers } = hre
const { deployer, governance } = await getNamedAccounts()

await helpers.ownable.transferOwnership(
"BaseL1BitcoinDepositor",
governance,
deployer
)
}

export default func

func.tags = ["TransferBaseL1BitcoinDepositorOwnership"]
func.dependencies = ["BaseL1BitcoinDepositor"]
func.runAtTheEnd = true
48 changes: 48 additions & 0 deletions cross-chain/base/deploy_l2/25_deploy_base_l2_bitcoin_depositor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"
import { getWormholeChains } from "../deploy_helpers/wormhole_chains"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { ethers, getNamedAccounts, helpers, deployments } = hre
const { deployer } = await getNamedAccounts()

const wormholeChains = getWormholeChains(hre.network.name)

const baseWormholeRelayer = await deployments.get("BaseWormholeRelayer")
const baseWormholeGateway = await deployments.get("BaseWormholeGateway")

const [, proxyDeployment] = await helpers.upgrades.deployProxy(
"BaseL2BitcoinDepositor",
{
contractName:
"@keep-network/tbtc-v2/contracts/l2/L2BitcoinDepositor.sol:L2BitcoinDepositor",
initializerArgs: [
baseWormholeRelayer.address,
baseWormholeGateway.address,
wormholeChains.l1ChainId,
],
factoryOpts: { signer: await ethers.getSigner(deployer) },
proxyOpts: {
kind: "transparent",
},
}
)

// Contracts can be verified on L2 Base Etherscan in a similar way as we
// do it on L1 Etherscan
if (hre.network.tags.basescan) {
// We use `verify` instead of `verify:verify` as the `verify` task is defined
// in "@openzeppelin/hardhat-upgrades" to verify the proxy’s implementation
// contract, the proxy itself and any proxy-related contracts, as well as
// link the proxy to the implementation contract’s ABI on (Ether)scan.
await hre.run("verify", {
address: proxyDeployment.address,
constructorArgsParams: [],
})
}
}

export default func

func.tags = ["BaseL2BitcoinDepositor"]
func.dependencies = ["BaseWormholeGateway"]
25 changes: 25 additions & 0 deletions cross-chain/base/deploy_l2/26_attach_base_l1_bitcoin_depositor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts } = hre
const { deployer } = await getNamedAccounts()
const { execute } = deployments
const l1Deployments = hre.companionNetworks.l1.deployments

const baseL1BitcoinDepositor = await l1Deployments.get(
"BaseL1BitcoinDepositor"
)

await execute(
"BaseL2BitcoinDepositor",
{ from: deployer, log: true, waitConfirmations: 1 },
"attachL1BitcoinDepositor",
baseL1BitcoinDepositor.address
)
}

export default func

func.tags = ["AttachBaseL1BitcoinDepositor"]
func.dependencies = ["BaseL2BitcoinDepositor"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts, helpers } = hre
const { deployer, governance } = await getNamedAccounts()

await helpers.ownable.transferOwnership(
"BaseL2BitcoinDepositor",
governance,
deployer
)
}

export default func

func.tags = ["TransferBaseL2BitcoinDepositorOwnership"]
func.dependencies = ["BaseL2BitcoinDepositor"]
func.runAtTheEnd = true
9 changes: 6 additions & 3 deletions cross-chain/base/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const config: HardhatUserConfig = {
? process.env.L1_ACCOUNTS_PRIVATE_KEYS.split(",")
: undefined,
tags: ["etherscan"],
companionNetworks: {
l2: "baseSepolia",
},
},
mainnet: {
url: process.env.L1_CHAIN_API_URL || "",
Expand Down Expand Up @@ -88,9 +91,9 @@ const config: HardhatUserConfig = {
// In case of deployment failing with underpriced transaction error set
// the `gasPrice` parameter.
// gasPrice: 1000000000,
// companionNetworks: {
// l1: "sepolia",
// },
companionNetworks: {
l1: "sepolia",
},
},
base: {
url: process.env.L2_CHAIN_API_URL || "",
Expand Down

0 comments on commit 533e889

Please sign in to comment.