Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of Bitcoin depositor (tBTC Depositor) #91

Merged
merged 139 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
f57fe76
Define external tbtc interfaces
nkuba Dec 22, 2023
a6d27d4
Implement tBTC Depositor contract
nkuba Dec 22, 2023
a95e09d
Add dependency to @keep-network/bitcoin-spv-sol
nkuba Dec 22, 2023
9733704
Add TODO about minimum limits
nkuba Dec 22, 2023
c1b4b12
Change referral type to uint16
nkuba Dec 22, 2023
6f48f76
Update referral type in StakeReferral event
nkuba Dec 22, 2023
27fb5ff
Fix formatting
nkuba Dec 22, 2023
d409aea
Fix ducumentation
nkuba Jan 3, 2024
e719485
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Jan 3, 2024
4ea8617
Emit events on stake initialization and finalization
nkuba Jan 3, 2024
be66889
Add missing dependency in Acre deployment script
nkuba Jan 4, 2024
e9af2ac
Make TbtcDepositor contract Ownable
nkuba Jan 4, 2024
c2720af
Define tBTC Depositor's depositor fee
nkuba Jan 4, 2024
74c7c30
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Jan 4, 2024
fda93b7
Define treasury address reference in Acre contract
nkuba Jan 4, 2024
dee6db3
Document minimum deposit amount
nkuba Jan 4, 2024
f24ccb8
Add function to help estimate fees
nkuba Jan 4, 2024
53e33f0
Add unit tests for extra data encode/decode functions
nkuba Jan 5, 2024
0648cb9
Add unit tests for updateDepositorFeeDivisor
nkuba Jan 5, 2024
9ee08d6
Use beforeAfterSnapshotWrapper in updateDepositorFeeDivisor tests
nkuba Jan 5, 2024
a111eba
Add unit test for calculateDepositKey function
nkuba Jan 5, 2024
81d9831
Add unit tests for initializeStake function
nkuba Jan 5, 2024
6f722e9
Add helper function to get latest block timestamp
nkuba Jan 5, 2024
f009b3c
Add test data for tBTC deposit
nkuba Jan 5, 2024
a9945a8
Add treasury address reference to Acre deployment script
nkuba Jan 5, 2024
b20f02b
Remove only from test
nkuba Jan 5, 2024
81aa38e
Add unit tests for finalizeStake function
nkuba Jan 15, 2024
b6f52f4
Add clarification for depositor address check
nkuba Jan 15, 2024
b918ee8
Use Math.min for OM fee divisors comparison
nkuba Jan 15, 2024
0909d82
Add name and symbol to TestERC20 constructor
nkuba Jan 15, 2024
4ca73bf
Remove estimateFee function
nkuba Jan 15, 2024
89d6df3
Add tBTC Bridge and tBTC Vault contracts stubs
nkuba Jan 15, 2024
8ed2a3b
Update deployment scripts for tBTC Depositor
nkuba Jan 15, 2024
7c2fea3
Fix solhint problems
nkuba Jan 15, 2024
5bd8a40
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Jan 15, 2024
c4c19b3
Let the user recall bridged tBTC
nkuba Jan 22, 2024
01c8feb
Add tBTC token reference in tBTC Depositor contract
nkuba Jan 22, 2024
4d5cdbb
Check revealed tBTC Vault matches the expected
nkuba Jan 22, 2024
2b9b222
Update initialize/finalize stake request function names in tests
nkuba Jan 23, 2024
8b5fdc8
Move TBTCVault check to the beginign of initializeStakeRequest
nkuba Jan 24, 2024
c78ec0a
Move Depositor address check to initializeStakeRequest
nkuba Jan 24, 2024
e1e9a1e
Update tests to reflect vault and depositor checks change
nkuba Jan 24, 2024
3d168b1
Fix conversion of fees from sat to tBTC
nkuba Jan 24, 2024
a06822a
Update unit tests for notify/finalize function changes
nkuba Jan 24, 2024
2c39ed5
Implement TBTCDepositorProxy
nkuba Feb 1, 2024
a82393e
Update unit tests for changes in TbtcDepositor contract
nkuba Feb 1, 2024
6d8d8c7
Remove external tbtc contracts
nkuba Feb 1, 2024
2a401f0
Update stub contracts
nkuba Feb 1, 2024
83da0c4
Disable no-use-before-define rule
nkuba Feb 1, 2024
5283f1e
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 1, 2024
10bcee4
Rename Acre contact references to stBTC
nkuba Feb 1, 2024
d5fe01f
Set entry fee basis points to zero
nkuba Feb 1, 2024
4dc776f
Move TbtcDepositor.sol file
nkuba Feb 1, 2024
10c4126
Move TbtcDepositor.sol file
nkuba Feb 1, 2024
9e9d975
Enable encode extra data test cases
nkuba Feb 1, 2024
0c151ac
Add unit tests for recallStakeRequest
nkuba Feb 1, 2024
610abb5
Update StakeRequestRecalled event
nkuba Feb 1, 2024
1d3cea3
Convert depositKey value to bigint
nkuba Feb 1, 2024
850f980
Upgrade dependency to tbtc-v2
nkuba Feb 2, 2024
cbf198b
Update tBTC contract mocks
nkuba Feb 2, 2024
e8227ab
Update name of used initialize function
nkuba Feb 2, 2024
e14ff0e
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 2, 2024
debc8dc
Fix not needed import
nkuba Feb 2, 2024
873e1cd
Update reference to @keep-network/tbtc-v2
nkuba Feb 2, 2024
1237ced
Fix slither errors
nkuba Feb 2, 2024
f541f7d
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 5, 2024
8fdab6f
Remove unused imports
nkuba Feb 7, 2024
fac63fd
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 7, 2024
bcb127e
Clarify minting process in docs
nkuba Feb 7, 2024
defea02
Use Ownable2Step instead of Ownable
nkuba Feb 7, 2024
ec35bed
Accept ownership transfer in deployment script
nkuba Feb 7, 2024
60740dd
Rename amount related variables
nkuba Feb 7, 2024
68f58b4
Introduce recalledAt property
nkuba Feb 7, 2024
932bd1b
Use helpers from @keep-network/hardhat-helpers
nkuba Feb 7, 2024
c73e98d
Fix tag of onwership transfer script
nkuba Feb 7, 2024
4c72591
Use Ownable2Step in all contracts
nkuba Feb 7, 2024
563cca9
Combine notifyBridgingCompleted and finalizeStakeRequest
nkuba Feb 8, 2024
e3afe46
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 8, 2024
abfe788
Check if notifyBridgingCompleted was already called
nkuba Feb 8, 2024
14e0c65
Update dependency to tbtc-v2 contracts
nkuba Feb 8, 2024
8c02617
Add decodeExtraData function back
nkuba Feb 13, 2024
ecdf80f
Introduce finalizeStakeRequest function and queue
nkuba Feb 13, 2024
c95f17a
Update unit tests after queue updates
nkuba Feb 13, 2024
7741b92
Update function order in TbtcDepositor contract
nkuba Feb 13, 2024
a56117e
Rename TbtcDepositor to AcreBitcoinDepositor
nkuba Feb 13, 2024
e3cbfdc
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 13, 2024
3485752
Add a TODO to SDK about renaming TBTC Depositor
nkuba Feb 13, 2024
a72344c
Update tbtc-v2 dependency to 1.6.0-dev.21
nkuba Feb 14, 2024
7295110
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 14, 2024
e30ff01
Remove updateEntryFeeBasisPoints call in tests
nkuba Feb 16, 2024
3e69dcd
Ensure max value can be set for fee divisor
nkuba Feb 16, 2024
f4b4c27
Use enum to track request state
nkuba Feb 16, 2024
b3949fe
Don't underscore parameters
nkuba Feb 21, 2024
4f4dd4a
User custom error instead of require
nkuba Feb 21, 2024
7a13d75
Add TODO to make contract pausable
nkuba Feb 21, 2024
005435d
Rename receiver to staker
nkuba Feb 21, 2024
29d054a
Remove empty line
nkuba Feb 21, 2024
9d745ce
Move decodeExtraData closer to emit BridgingCompleted
nkuba Feb 21, 2024
313d193
Clarify BridgingCompleted event emission
nkuba Feb 21, 2024
0b03bae
queueForStaking -> queueStake
nkuba Feb 21, 2024
fbbf10d
initializeStakeRequest -> initializeStake
nkuba Feb 21, 2024
327c9f4
finalizeStakeRequest -> finalizeStake
nkuba Feb 21, 2024
f226b56
Update test cases names for stakes
nkuba Feb 21, 2024
7f94c44
Minor docs improvements
nkuba Feb 21, 2024
ac3f268
Remove underscores for constructor params names
nkuba Feb 21, 2024
e7b7e07
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 21, 2024
628de75
Use initializeStake function instead of initializeStakeRequest
nkuba Feb 21, 2024
7529547
Fix initializeStake func name in depositor mock
nkuba Feb 22, 2024
18dc65c
Exclude contracts/test dir from slither checks
nkuba Feb 22, 2024
6f48b16
Rename recallFromQueue to cancelQueuedStake
nkuba Feb 22, 2024
55087ae
Rename stakeFromQueue to finalizeQueuedStake
nkuba Feb 22, 2024
3e1f42c
Add misfund recovery to the Depositor contract
nkuba Feb 22, 2024
0ff413a
Add missing TestERC721 type import
nkuba Feb 23, 2024
28b65a2
Add TestERC721 contract implementation
nkuba Feb 23, 2024
c03c37a
Store queued amount as uint88
nkuba Feb 26, 2024
79f4d43
Re-order state variables to optimize storage
nkuba Feb 26, 2024
48f6c37
Remove immutable variables from AcreBitcoinDepositor
nkuba Feb 26, 2024
591a9b3
Update TBTCDepositorProxy ref to AbstractTBTCDepositor
nkuba Feb 26, 2024
e0b8d6c
Check if depositor balance is enough for bridged amount
nkuba Feb 27, 2024
ea20b43
Revert "Add misfund recovery to the Depositor contract"
nkuba Feb 27, 2024
879eab5
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 27, 2024
4489d12
Disable slither checks for non-immutable vars
nkuba Feb 27, 2024
e3ff790
Remove unused import
nkuba Feb 27, 2024
c99f286
Fix the name of slither rule to disable
nkuba Feb 27, 2024
0355f7c
Fix slither disable rule
nkuba Feb 27, 2024
cfaec75
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 28, 2024
0ca396b
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Feb 28, 2024
c2b54db
Add etherscan verification for AcreBitcoinDepositor
nkuba Feb 29, 2024
c0c0746
Fix etherscan verification for Dispatcher
nkuba Feb 29, 2024
0e72db4
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Mar 1, 2024
6fc9ea9
Merge branch 'main' into tbtc-depositor
nkuba Mar 4, 2024
2e03a62
Docs improvements
nkuba Mar 6, 2024
46ae9a1
Improve variables naming
nkuba Mar 6, 2024
a335dad
Reorganize test contracts
nkuba Mar 6, 2024
cebb35e
Use waitConfirmationsNumber in deployment
nkuba Mar 6, 2024
a4b85c8
Merge remote-tracking branch 'origin/main' into tbtc-depositor
nkuba Mar 6, 2024
b6eea22
Disable func-name-mixedcase solhint rule for harness contract
nkuba Mar 6, 2024
54a2427
Use waitConfirmationsNumber in all deploy scripts
nkuba Mar 6, 2024
e4d3062
Add missing waitConfirmationsNumber import
nkuba Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
"test/**"
]
}
]
],
"@typescript-eslint/no-use-before-define": "off"
},
"overrides": [
{
"files": ["deploy/*.ts"],
"files": ["deploy/**/*.ts", "test/**/*.ts"],
"rules": {
"@typescript-eslint/unbound-method": "off"
}
Expand Down
524 changes: 524 additions & 0 deletions core/contracts/AcreBitcoinDepositor.sol

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/contracts/Dispatcher.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC4626.sol";
import "./Router.sol";
Expand All @@ -11,7 +11,7 @@ import "./stBTC.sol";
/// @notice Dispatcher is a contract that routes tBTC from stBTC to
/// yield vaults and back. Vaults supply yield strategies with tBTC that
/// generate yield for Bitcoin holders.
contract Dispatcher is Router, Ownable {
contract Dispatcher is Router, Ownable2Step {
using SafeERC20 for IERC20;

/// Struct holds information about a vault.
Expand Down
13 changes: 0 additions & 13 deletions core/contracts/TbtcDepositor.sol

This file was deleted.

11 changes: 8 additions & 3 deletions core/contracts/stBTC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.21;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "./Dispatcher.sol";

/// @title stBTC
Expand All @@ -17,7 +17,7 @@ import "./Dispatcher.sol";
/// of yield-bearing vaults. This contract facilitates the minting and
/// burning of shares (stBTC), which are represented as standard ERC20
/// tokens, providing a seamless exchange with tBTC tokens.
contract stBTC is ERC4626, Ownable {
contract stBTC is ERC4626, Ownable2Step {
using SafeERC20 for IERC20;

/// Dispatcher contract that routes tBTC from stBTC to a given vault and back.
Expand All @@ -26,8 +26,13 @@ contract stBTC is ERC4626, Ownable {
/// Address of the treasury wallet, where fees should be transferred to.
address public treasury;

/// Minimum amount for a single deposit operation.
/// Minimum amount for a single deposit operation. The value should be set
/// low enough so the deposits routed through Bitcoin Depositor contract won't
/// be rejected. It means that minimumDepositAmount should be lower than
/// tBTC protocol's depositDustThreshold reduced by all the minting fees taken
/// before depositing in the Acre contract.
uint256 public minimumDepositAmount;

/// Maximum total amount of tBTC token held by Acre protocol.
uint256 public maximumTotalAssets;

Expand Down
79 changes: 79 additions & 0 deletions core/contracts/test/AcreBitcoinDepositorHarness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-3.0-only
/* solhint-disable func-name-mixedcase */
pragma solidity ^0.8.21;

import {AcreBitcoinDepositor} from "../AcreBitcoinDepositor.sol";
import {MockBridge, MockTBTCVault} from "@keep-network/tbtc-v2/contracts/test/TestTBTCDepositor.sol";
import {IBridge} from "@keep-network/tbtc-v2/contracts/integrator/IBridge.sol";
import {IBridgeTypes} from "@keep-network/tbtc-v2/contracts/integrator/IBridge.sol";

import {TestERC20} from "./TestERC20.sol";

/// @dev A test contract to expose internal function from AcreBitcoinDepositor contract.
/// This solution follows Foundry recommendation:
/// https://book.getfoundry.sh/tutorials/best-practices#internal-functions
contract AcreBitcoinDepositorHarness is AcreBitcoinDepositor {
constructor(
address bridge,
address tbtcVault,
address tbtcToken,
address stbtc
) AcreBitcoinDepositor(bridge, tbtcVault, tbtcToken, stbtc) {}

function exposed_finalizeBridging(
uint256 depositKey
) external returns (uint256 amountToStake, address staker) {
return finalizeBridging(depositKey);
}
}

/// @dev A test contract to stub tBTC Bridge contract.
contract BridgeStub is MockBridge {}

/// @dev A test contract to stub tBTC Vault contract.
contract TBTCVaultStub is MockTBTCVault {
TestERC20 public immutable tbtc;
IBridge public immutable bridge;

/// @notice Multiplier to convert satoshi to TBTC token units.
uint256 public constant SATOSHI_MULTIPLIER = 10 ** 10;

constructor(TestERC20 _tbtc, IBridge _bridge) {
tbtc = _tbtc;
bridge = _bridge;
}

function finalizeOptimisticMintingRequest(
uint256 depositKey
) public override {
IBridgeTypes.DepositRequest memory deposit = bridge.deposits(
depositKey
);

uint256 amountSubTreasury = (deposit.amount - deposit.treasuryFee) *
SATOSHI_MULTIPLIER;

uint256 omFee = optimisticMintingFeeDivisor > 0
? (amountSubTreasury / optimisticMintingFeeDivisor)
: 0;

// The deposit transaction max fee is in the 1e8 satoshi precision.
// We need to convert them to the 1e18 TBTC precision.
// slither-disable-next-line unused-return
(, , uint64 depositTxMaxFee, ) = bridge.depositParameters();
uint256 txMaxFee = depositTxMaxFee * SATOSHI_MULTIPLIER;

uint256 amountToMint = amountSubTreasury - omFee - txMaxFee;

finalizeOptimisticMintingRequestWithAmount(depositKey, amountToMint);
}

function finalizeOptimisticMintingRequestWithAmount(
uint256 depositKey,
uint256 amountToMint
) public {
MockTBTCVault.finalizeOptimisticMintingRequest(depositKey);

tbtc.mint(bridge.deposits(depositKey).depositor, amountToMint);
}
}
2 changes: 1 addition & 1 deletion core/contracts/test/TestERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.21;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestERC20 is ERC20 {
constructor() ERC20("Test Token", "TEST") {}
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

function mint(address account, uint256 value) external {
_mint(account, value);
Expand Down
35 changes: 35 additions & 0 deletions core/deploy/00_resolve_tbtc_bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { DeployFunction } from "hardhat-deploy/types"
import type {
HardhatNetworkConfig,
HardhatRuntimeEnvironment,
} from "hardhat/types"
import { isNonZeroAddress } from "../helpers/address"
import { waitConfirmationsNumber } from "../helpers/deployment"

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { getNamedAccounts, deployments } = hre
const { log } = deployments
const { deployer } = await getNamedAccounts()

const bridge = await deployments.getOrNull("Bridge")

if (bridge && isNonZeroAddress(bridge.address)) {
log(`using Bridge contract at ${bridge.address}`)
} else if ((hre.network.config as HardhatNetworkConfig)?.forking?.enabled) {
throw new Error("deployed Bridge contract not found")
} else {
log("deploying Bridge contract stub")

await deployments.deploy("Bridge", {
contract: "BridgeStub",
args: [],
from: deployer,
log: true,
waitConfirmations: waitConfirmationsNumber(hre),
})
}
}

export default func

func.tags = ["TBTC", "Bridge"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import type { DeployFunction } from "hardhat-deploy/types"
import type {
HardhatNetworkConfig,
HardhatRuntimeEnvironment,
} from "hardhat/types"
import { isNonZeroAddress } from "../helpers/address"
import { waitConfirmationsNumber } from "../helpers/deployment"

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { getNamedAccounts, deployments } = hre
Expand All @@ -11,20 +15,24 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {

if (tbtc && isNonZeroAddress(tbtc.address)) {
log(`using TBTC contract at ${tbtc.address}`)
} else if (!hre.network.tags.allowStubs) {
} else if (
!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled
) {
throw new Error("deployed TBTC contract not found")
} else {
log("deploying TBTC contract stub")

await deployments.deploy("TBTC", {
contract: "TestERC20",
args: ["Test tBTC", "TestTBTC"],
from: deployer,
log: true,
waitConfirmations: 1,
waitConfirmations: waitConfirmationsNumber(hre),
})
}
}

export default func

func.tags = ["TBTC"]
func.tags = ["TBTC", "TBTCToken"]
42 changes: 42 additions & 0 deletions core/deploy/00_resolve_tbtc_vault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { DeployFunction } from "hardhat-deploy/types"
import type {
HardhatNetworkConfig,
HardhatRuntimeEnvironment,
} from "hardhat/types"
import { isNonZeroAddress } from "../helpers/address"
import { waitConfirmationsNumber } from "../helpers/deployment"

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { getNamedAccounts, deployments } = hre
const { log } = deployments
const { deployer } = await getNamedAccounts()

const tbtcVault = await deployments.getOrNull("TBTCVault")

if (tbtcVault && isNonZeroAddress(tbtcVault.address)) {
log(`using TBTCVault contract at ${tbtcVault.address}`)
} else if (
!hre.network.tags.allowStubs ||
(hre.network.config as HardhatNetworkConfig)?.forking?.enabled
) {
throw new Error("deployed TBTCVault contract not found")
} else {
log("deploying TBTCVault contract stub")

const tbtc = await deployments.get("TBTC")
const bridge = await deployments.get("Bridge")

await deployments.deploy("TBTCVault", {
contract: "TBTCVaultStub",
args: [tbtc.address, bridge.address],
from: deployer,
log: true,
waitConfirmations: waitConfirmationsNumber(hre),
})
}
}

export default func

func.tags = ["TBTC", "TBTCVault"]
func.dependencies = ["TBTCToken", "Bridge"]
4 changes: 2 additions & 2 deletions core/deploy/02_deploy_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const tbtc = await deployments.get("TBTC")
const stbtc = await deployments.get("stBTC")

await deployments.deploy("Dispatcher", {
const dispatcher = await deployments.deploy("Dispatcher", {
from: deployer,
args: [stbtc.address, tbtc.address],
log: true,
waitConfirmations: waitConfirmationsNumber(hre),
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(stbtc)
await helpers.etherscan.verify(dispatcher)
}

// TODO: Add Tenderly verification
Expand Down
35 changes: 35 additions & 0 deletions core/deploy/03_deploy_acre_bitcoin_depositor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { DeployFunction } from "hardhat-deploy/types"
import type { HardhatRuntimeEnvironment } from "hardhat/types"
import { waitConfirmationsNumber } from "../helpers/deployment"

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

const bridge = await deployments.get("Bridge")
const tbtcVault = await deployments.get("TBTCVault")
const tbtc = await deployments.get("TBTC")
const stbtc = await deployments.get("stBTC")

const depositor = await deployments.deploy("AcreBitcoinDepositor", {
contract:
process.env.HARDHAT_TEST === "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not biggy, but did you consider using func.skip just like we use for example in 00_resolve_testing_erc4626.ts? This way we'd need to almost duplicate this file, but we avoid logic in the deployment contracts and no need to use "test": "HARDHAT_TEST=true hardhat test" in package.json. Up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I wanted to achieve here is to deploy the contract but if the deployment is invoked for unit test execution use the alternative AcreBitcoinDepositorHarness contract. So the script should be executed always, just with a different contract.
I'm not sure what would be the best way to do it with the func.skip.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I know what you're trying to achieve. My proposition was having two deployment files: 03_deploy_acre_bitcoin_depositor.ts and 03_test_deploy_acre_bitcoin_depositor.ts. In the first one we add skip if the network is hardhat. For the latter script we can add skip in case the network is other than hardhat. This way the logic from deployment script and package.json will go away. Anyway, this is just another option, non blocker and up to you.

? "AcreBitcoinDepositorHarness"
: "AcreBitcoinDepositor",
from: deployer,
args: [bridge.address, tbtcVault.address, tbtc.address, stbtc.address],
log: true,
waitConfirmations: waitConfirmationsNumber(hre),
})

if (hre.network.tags.etherscan) {
await helpers.etherscan.verify(depositor)
}

// TODO: Add Tenderly verification
}

export default func

func.tags = ["AcreBitcoinDepositor"]
func.dependencies = ["TBTC", "stBTC"]
9 changes: 9 additions & 0 deletions core/deploy/21_transfer_ownership_stbtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
"transferOwnership",
governance,
)

if (hre.network.name !== "mainnet") {
await deployments.execute(
"stBTC",
{ from: governance, log: true, waitConfirmations: 1 },
"acceptOwnership",
)
}
}

export default func

func.tags = ["TransferOwnershipStBTC"]
func.dependencies = ["stBTC"]
8 changes: 8 additions & 0 deletions core/deploy/22_transfer_ownership_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
"transferOwnership",
governance,
)

if (hre.network.name !== "mainnet") {
await deployments.execute(
"Dispatcher",
{ from: governance, log: true, waitConfirmations: 1 },
"acceptOwnership",
)
}
}

export default func
Expand Down
Loading
Loading