From 4d123d745eda977c13d529110ab662733b55fce4 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Fri, 1 Dec 2023 15:33:09 +0100 Subject: [PATCH] Add deploymet script for Acre including tBTC reference Acre contract requires tBTC address as argument. We add `00_resolve_tbtc.ts` script that will ensure tBTC deployment artifact reference is available based on the network. For networks marked with `allowStubs` tag (hardhat local network for running tests) a stub ERC20 contract will be deployed. --- core/.eslintrc | 9 ++++++++- core/deploy/00_resolve_tbtc.ts | 30 ++++++++++++++++++++++++++++++ core/deploy/01_deploy_acre.ts | 19 +++++++++++++++---- core/hardhat.config.ts | 3 +++ core/helpers/address.ts | 6 ++++++ core/tsconfig.json | 2 +- 6 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 core/deploy/00_resolve_tbtc.ts create mode 100644 core/helpers/address.ts diff --git a/core/.eslintrc b/core/.eslintrc index 727b7ad1e..39419600b 100644 --- a/core/.eslintrc +++ b/core/.eslintrc @@ -4,7 +4,14 @@ "rules": { "import/no-extraneous-dependencies": [ "error", - { "devDependencies": ["hardhat.config.ts", "test/**"] } + { + "devDependencies": [ + "hardhat.config.ts", + "deploy/**", + "helpers/**", + "test/**" + ] + } ] } } diff --git a/core/deploy/00_resolve_tbtc.ts b/core/deploy/00_resolve_tbtc.ts new file mode 100644 index 000000000..83f796ceb --- /dev/null +++ b/core/deploy/00_resolve_tbtc.ts @@ -0,0 +1,30 @@ +import type { HardhatRuntimeEnvironment } from "hardhat/types" +import type { DeployFunction } from "hardhat-deploy/types" +import { isNonZeroAddress } from "../helpers/address" + +const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { + const { getNamedAccounts, deployments } = hre + const { log } = deployments + const { deployer } = await getNamedAccounts() + + const tbtc = await deployments.getOrNull("TBTC") + + if (tbtc && isNonZeroAddress(tbtc.address)) { + log(`using TBTC contract at ${tbtc.address}`) + } else if (!hre.network.tags.allowStubs) { + throw new Error("deployed TBTC contract not found") + } else { + log("deploying TBTC contract stub") + + await deployments.deploy("TBTC", { + contract: "TestToken", // TODO: Rename to TestERC20 + from: deployer, + log: true, + waitConfirmations: 1, + }) + } +} + +export default func + +func.tags = ["TBTC"] diff --git a/core/deploy/01_deploy_acre.ts b/core/deploy/01_deploy_acre.ts index 3266a1986..531fc6c12 100644 --- a/core/deploy/01_deploy_acre.ts +++ b/core/deploy/01_deploy_acre.ts @@ -1,13 +1,24 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types" import type { DeployFunction } from "hardhat-deploy/types" -const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const { deployments } = hre - const { log } = deployments +const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { + const { getNamedAccounts, deployments } = hre + const { deployer } = await getNamedAccounts() - log("Deploying Acre contract") + const tbtc = await deployments.get("TBTC") + + await deployments.deploy("Acre", { + from: deployer, + args: [tbtc.address], + log: true, + waitConfirmations: 1, + }) + + // TODO: Add Etherscan verification + // TODO: Add Tenderly verification } export default func func.tags = ["Acre"] +func.dependencies = ["TBTC"] diff --git a/core/hardhat.config.ts b/core/hardhat.config.ts index 64e14bce6..2390d0d19 100644 --- a/core/hardhat.config.ts +++ b/core/hardhat.config.ts @@ -23,6 +23,9 @@ const config: HardhatUserConfig = { }, networks: { + hardhat: { + tags: ["allowStubs"], + }, sepolia: { url: process.env.CHAIN_API_URL || "", chainId: 11155111, diff --git a/core/helpers/address.ts b/core/helpers/address.ts new file mode 100644 index 000000000..5d5105819 --- /dev/null +++ b/core/helpers/address.ts @@ -0,0 +1,6 @@ +import { ethers } from "ethers" + +// eslint-disable-next-line import/prefer-default-export +export function isNonZeroAddress(address: string): boolean { + return ethers.getAddress(address) !== ethers.ZeroAddress +} diff --git a/core/tsconfig.json b/core/tsconfig.json index 81b5d7d52..3f8c9f270 100644 --- a/core/tsconfig.json +++ b/core/tsconfig.json @@ -9,5 +9,5 @@ "resolveJsonModule": true }, "files": ["./hardhat.config.ts"], - "include": ["./deploy", "./test", "./typechain"] + "include": ["./deploy", "./test", "./typechain", "./helpers/"] }