Skip to content

Commit

Permalink
Add deploymet script for Acre including tBTC reference
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nkuba committed Dec 1, 2023
1 parent faa694d commit 4d123d7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
9 changes: 8 additions & 1 deletion core/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
"rules": {
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": ["hardhat.config.ts", "test/**"] }
{
"devDependencies": [
"hardhat.config.ts",
"deploy/**",
"helpers/**",
"test/**"
]
}
]
}
}
30 changes: 30 additions & 0 deletions core/deploy/00_resolve_tbtc.ts
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 15 additions & 4 deletions core/deploy/01_deploy_acre.ts
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 3 additions & 0 deletions core/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const config: HardhatUserConfig = {
},

networks: {
hardhat: {
tags: ["allowStubs"],
},
sepolia: {
url: process.env.CHAIN_API_URL || "",
chainId: 11155111,
Expand Down
6 changes: 6 additions & 0 deletions core/helpers/address.ts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"resolveJsonModule": true
},
"files": ["./hardhat.config.ts"],
"include": ["./deploy", "./test", "./typechain"]
"include": ["./deploy", "./test", "./typechain", "./helpers/"]
}

0 comments on commit 4d123d7

Please sign in to comment.