From 533e889c3cd16fb7e46dbba2235c26c1cad97bb7 Mon Sep 17 00:00:00 2001 From: Lukasz Zimnoch Date: Fri, 1 Mar 2024 12:41:40 +0100 Subject: [PATCH] Deployment scripts for Base Here we add deployment scripts for both `L*BitcoinDepositor` contracts. We use Base as the reference chain. --- .../00_deploy_base_l1_bitcoin_depositor.ts | 53 +++++++++++++++++++ .../01_attach_base_l2_bitcoin_depositor.ts | 25 +++++++++ ...fer_base_l1_bitcoin_depositor_ownership.ts | 19 +++++++ .../25_deploy_base_l2_bitcoin_depositor.ts | 48 +++++++++++++++++ .../26_attach_base_l1_bitcoin_depositor.ts | 25 +++++++++ ...fer_base_l2_bitcoin_depositor_ownership.ts | 19 +++++++ cross-chain/base/hardhat.config.ts | 9 ++-- 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 cross-chain/base/deploy_l1/00_deploy_base_l1_bitcoin_depositor.ts create mode 100644 cross-chain/base/deploy_l1/01_attach_base_l2_bitcoin_depositor.ts create mode 100644 cross-chain/base/deploy_l1/03_transfer_base_l1_bitcoin_depositor_ownership.ts create mode 100644 cross-chain/base/deploy_l2/25_deploy_base_l2_bitcoin_depositor.ts create mode 100644 cross-chain/base/deploy_l2/26_attach_base_l1_bitcoin_depositor.ts create mode 100644 cross-chain/base/deploy_l2/27_transfer_base_l2_bitcoin_depositor_ownership.ts diff --git a/cross-chain/base/deploy_l1/00_deploy_base_l1_bitcoin_depositor.ts b/cross-chain/base/deploy_l1/00_deploy_base_l1_bitcoin_depositor.ts new file mode 100644 index 000000000..6bf2e6f29 --- /dev/null +++ b/cross-chain/base/deploy_l1/00_deploy_base_l1_bitcoin_depositor.ts @@ -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"] diff --git a/cross-chain/base/deploy_l1/01_attach_base_l2_bitcoin_depositor.ts b/cross-chain/base/deploy_l1/01_attach_base_l2_bitcoin_depositor.ts new file mode 100644 index 000000000..c35aaa21d --- /dev/null +++ b/cross-chain/base/deploy_l1/01_attach_base_l2_bitcoin_depositor.ts @@ -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"] diff --git a/cross-chain/base/deploy_l1/03_transfer_base_l1_bitcoin_depositor_ownership.ts b/cross-chain/base/deploy_l1/03_transfer_base_l1_bitcoin_depositor_ownership.ts new file mode 100644 index 000000000..7c7d230de --- /dev/null +++ b/cross-chain/base/deploy_l1/03_transfer_base_l1_bitcoin_depositor_ownership.ts @@ -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 diff --git a/cross-chain/base/deploy_l2/25_deploy_base_l2_bitcoin_depositor.ts b/cross-chain/base/deploy_l2/25_deploy_base_l2_bitcoin_depositor.ts new file mode 100644 index 000000000..fd24fd0b2 --- /dev/null +++ b/cross-chain/base/deploy_l2/25_deploy_base_l2_bitcoin_depositor.ts @@ -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"] diff --git a/cross-chain/base/deploy_l2/26_attach_base_l1_bitcoin_depositor.ts b/cross-chain/base/deploy_l2/26_attach_base_l1_bitcoin_depositor.ts new file mode 100644 index 000000000..d945af44b --- /dev/null +++ b/cross-chain/base/deploy_l2/26_attach_base_l1_bitcoin_depositor.ts @@ -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"] diff --git a/cross-chain/base/deploy_l2/27_transfer_base_l2_bitcoin_depositor_ownership.ts b/cross-chain/base/deploy_l2/27_transfer_base_l2_bitcoin_depositor_ownership.ts new file mode 100644 index 000000000..2c499eead --- /dev/null +++ b/cross-chain/base/deploy_l2/27_transfer_base_l2_bitcoin_depositor_ownership.ts @@ -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 diff --git a/cross-chain/base/hardhat.config.ts b/cross-chain/base/hardhat.config.ts index 9ab642587..9e47a214a 100644 --- a/cross-chain/base/hardhat.config.ts +++ b/cross-chain/base/hardhat.config.ts @@ -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 || "", @@ -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 || "",