Skip to content

Commit

Permalink
Rename Bitcoin Depositor contract (#334)
Browse files Browse the repository at this point in the history
We renamed the depositor contract from AcreBitcoinDepositor to
BitcoinDepositor, as there is no point in prefixing the contract with
Acre.

We used to do that for ethereum typed messages clear signing, but we no
longer need ethereum messages signing with Bitcoin-only experience.
  • Loading branch information
dimpar authored Apr 9, 2024
2 parents 326d35d + cc0f316 commit 3b3c052
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "@keep-network/tbtc-v2/contracts/integrator/AbstractTBTCDepositor.sol";

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

/// @title Acre Bitcoin Depositor contract.
/// @title Bitcoin Depositor contract.
/// @notice The contract integrates Acre staking with tBTC minting.
/// User who wants to stake BTC in Acre should submit a Bitcoin transaction
/// to the most recently created off-chain ECDSA wallets of the tBTC Bridge
Expand All @@ -35,10 +35,7 @@ import {stBTC} from "./stBTC.sol";
/// Depositor address. After tBTC is minted to the Depositor, on the stake
/// finalization tBTC is staked in Acre and stBTC shares are emitted
/// to the staker.
contract AcreBitcoinDepositor is
AbstractTBTCDepositor,
Ownable2StepUpgradeable
{
contract BitcoinDepositor is AbstractTBTCDepositor, Ownable2StepUpgradeable {
using SafeERC20 for IERC20;

/// @notice State of the stake request.
Expand Down Expand Up @@ -146,7 +143,7 @@ contract AcreBitcoinDepositor is
_disableInitializers();
}

/// @notice Acre Bitcoin Depositor contract initializer.
/// @notice Bitcoin Depositor contract initializer.
/// @param bridge tBTC Bridge contract instance.
/// @param tbtcVault tBTC Vault contract instance.
/// @param _tbtcToken tBTC token contract instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* solhint-disable func-name-mixedcase */
pragma solidity ^0.8.21;

import {AcreBitcoinDepositor} from "../AcreBitcoinDepositor.sol";
import {BitcoinDepositor} from "../BitcoinDepositor.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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import "@keep-network/tbtc-v2/contracts/integrator/AbstractTBTCDepositor.sol";

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

/// @title AcreBitcoinDepositorV2
/// @dev This is a contract used to test Acre Bitcoin Depositor upgradeability.
/// It is a copy of AcreBitcoinDepositor contract with some differences
/// @title BitcoinDepositorV2
/// @dev This is a contract used to test Bitcoin Depositor upgradeability.
/// It is a copy of BitcoinDepositor contract with some differences
/// marked with `TEST:` comments.
contract AcreBitcoinDepositorV2 is
AbstractTBTCDepositor,
Ownable2StepUpgradeable
{
contract BitcoinDepositorV2 is AbstractTBTCDepositor, Ownable2StepUpgradeable {
using SafeERC20 for IERC20;

/// @notice State of the stake request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const tbtc = await deployments.get("TBTC")
const stbtc = await deployments.get("stBTC")

const [, acreBitcoinDepositorDeployment] = await helpers.upgrades.deployProxy(
"AcreBitcoinDepositor",
const [, deployment] = await helpers.upgrades.deployProxy(
"BitcoinDepositor",
{
factoryOpts: {
signer: deployer,
Expand All @@ -31,21 +31,15 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
},
)

if (
acreBitcoinDepositorDeployment.transactionHash &&
hre.network.tags.etherscan
) {
await waitForTransaction(
hre,
acreBitcoinDepositorDeployment.transactionHash,
)
await helpers.etherscan.verify(acreBitcoinDepositorDeployment)
if (deployment.transactionHash && hre.network.tags.etherscan) {
await waitForTransaction(hre, deployment.transactionHash)
await helpers.etherscan.verify(deployment)
}

// TODO: Add Tenderly verification
}

export default func

func.tags = ["AcreBitcoinDepositor"]
func.tags = ["BitcoinDepositor"]
func.dependencies = ["TBTC", "stBTC"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployer, governance } = await getNamedAccounts()
const { log } = deployments

log(
`transferring ownership of AcreBitcoinDepositor contract to ${governance}`,
)
log(`transferring ownership of BitcoinDepositor contract to ${governance}`)

await deployments.execute(
"AcreBitcoinDepositor",
"BitcoinDepositor",
{ from: deployer, log: true, waitConfirmations: 1 },
"transferOwnership",
governance,
)

if (hre.network.name !== "mainnet") {
await deployments.execute(
"AcreBitcoinDepositor",
"BitcoinDepositor",
{ from: governance, log: true, waitConfirmations: 1 },
"acceptOwnership",
)
Expand All @@ -28,6 +26,6 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {

export default func

func.tags = ["TransferOwnershipAcreBitcoinDepositor"]
func.dependencies = ["AcreBitcoinDepositor"]
func.tags = ["TransferOwnershipBitcoinDepositor"]
func.dependencies = ["BitcoinDepositor"]
func.runAtTheEnd = true
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
StBTC,
BridgeStub,
TBTCVaultStub,
AcreBitcoinDepositor,
BitcoinDepositor,
TestERC20,
} from "../typechain"
import { deployment } from "./helpers"
Expand All @@ -30,7 +30,7 @@ async function fixture() {
const { lastBlockTime } = helpers.time
const { getNamedSigners, getUnnamedSigners } = helpers.signers

describe("AcreBitcoinDepositor", () => {
describe("BitcoinDepositor", () => {
const defaultDepositDustThreshold = 1000000 // 1000000 satoshi = 0.01 BTC
const defaultDepositTreasuryFeeDivisor = 2000 // 1/2000 = 0.05% = 0.0005
const defaultDepositTxMaxFee = 1000 // 1000 satoshi = 0.00001 BTC
Expand All @@ -48,7 +48,7 @@ describe("AcreBitcoinDepositor", () => {
const depositorFee = to1ePrecision(10, 10) // 10 satoshi
const amountToStake = to1ePrecision(896501, 8) // 8965,01 satoshi

let bitcoinDepositor: AcreBitcoinDepositor
let bitcoinDepositor: BitcoinDepositor
let tbtcBridge: BridgeStub
let tbtcVault: TBTCVaultStub
let stbtc: StBTC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { beforeAfterSnapshotWrapper, deployment } from "./helpers"
import {
TestERC20,
StBTC,
AcreBitcoinDepositor,
BitcoinDepositor,
BridgeStub,
TBTCVaultStub,
AcreBitcoinDepositorV2,
BitcoinDepositorV2,
} from "../typechain"
import { to1e18 } from "./utils"

Expand All @@ -24,12 +24,12 @@ async function fixture() {
return { tbtc, stbtc, bitcoinDepositor, tbtcBridge, tbtcVault }
}

describe("AcreBitcoinDepositor contract upgrade", () => {
describe("BitcoinDepositor contract upgrade", () => {
let tbtc: TestERC20
let tbtcBridge: BridgeStub
let tbtcVault: TBTCVaultStub
let stbtc: StBTC
let bitcoinDepositor: AcreBitcoinDepositor
let bitcoinDepositor: BitcoinDepositor
let governance: HardhatEthersSigner

before(async () => {
Expand All @@ -40,7 +40,7 @@ describe("AcreBitcoinDepositor contract upgrade", () => {

context("when upgrading to a valid contract", () => {
const newVariable = 1n
let bitcoinDepositorV2: AcreBitcoinDepositorV2
let bitcoinDepositorV2: BitcoinDepositorV2
let v1InitialParameters: {
minStakeAmount: bigint
depositorFeeDivisor: bigint
Expand All @@ -59,8 +59,8 @@ describe("AcreBitcoinDepositor contract upgrade", () => {
}

const [upgradedDepositor] = await helpers.upgrades.upgradeProxy(
"AcreBitcoinDepositor",
"AcreBitcoinDepositorV2",
"BitcoinDepositor",
"BitcoinDepositorV2",
{
factoryOpts: { signer: governance },
proxyOpts: {
Expand All @@ -72,8 +72,7 @@ describe("AcreBitcoinDepositor contract upgrade", () => {
},
)

bitcoinDepositorV2 =
upgradedDepositor as unknown as AcreBitcoinDepositorV2
bitcoinDepositorV2 = upgradedDepositor as unknown as BitcoinDepositorV2
})

it("new instance should have the same address as the old one", async () => {
Expand Down
7 changes: 3 additions & 4 deletions core/test/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import type {
BridgeStub,
TestERC4626,
TBTCVaultStub,
AcreBitcoinDepositor,
BitcoinDepositor,
} from "../../typechain"

// eslint-disable-next-line import/prefer-default-export
export async function deployment() {
await deployments.fixture()

const stbtc: stBTC = await getDeployedContract("stBTC")
const bitcoinDepositor: AcreBitcoinDepositor = await getDeployedContract(
"AcreBitcoinDepositor",
)
const bitcoinDepositor: BitcoinDepositor =
await getDeployedContract("BitcoinDepositor")

const tbtc: TestERC20 = await getDeployedContract("TBTC")
const tbtcBridge: BridgeStub = await getDeployedContract("Bridge")
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/lib/contracts/bitcoin-depositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type DecodedExtraData = {
}

/**
* Interface for communication with the AcreBitcoinDepositor on-chain contract.
* Interface for communication with the BitcoinDepositor on-chain contract.
*/
export interface BitcoinDepositor extends DepositorProxy {
/**
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/lib/ethereum/bitcoin-depositor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { packRevealDepositParameters } from "@keep-network/tbtc-v2.ts"
import { AcreBitcoinDepositor as AcreBitcoinDepositorTypechain } from "@acre-btc/core/typechain/contracts/AcreBitcoinDepositor"
import { BitcoinDepositor as BitcoinDepositorTypechain } from "@acre-btc/core/typechain/contracts/BitcoinDepositor"
import {
ZeroAddress,
dataSlice,
Expand All @@ -24,16 +24,16 @@ import {
import { Hex } from "../utils"
import { EthereumNetwork } from "./network"

import SepoliaBitcoinDepositor from "./artifacts/sepolia/AcreBitcoinDepositor.json"
import SepoliaBitcoinDepositor from "./artifacts/sepolia/BitcoinDepositor.json"

/**
* Ethereum implementation of the BitcoinDepositor.
*/
class EthereumBitcoinDepositor
// @ts-expect-error TODO: Figure out why type generated by typechain does not
// satisfy the constraint `Contract`. Error: `Property '[internal]' is missing
// in type 'AcreBitcoinDepositor' but required in type 'Contract'`.
extends EthersContractWrapper<AcreBitcoinDepositorTypechain>
// in type 'BitcoinDepositor' but required in type 'Contract'`.
extends EthersContractWrapper<BitcoinDepositorTypechain>
implements BitcoinDepositor
{
constructor(config: EthersContractConfig, network: EthereumNetwork) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/modules/staking/stake-initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class StakeInitialization {
*/
#getStakeMessageTypedData() {
const domain: Domain = {
name: "AcreBitcoinDepositor",
name: "BitcoinDepositor",
version: "1",
verifyingContract: this.#contracts.bitcoinDepositor.getChainIdentifier(),
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/lib/ethereum/eip712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

const signMessageData = {
domain: {
name: "AcreBitcoinDepositor",
name: "BitcoinDepositor",
version: "1",
verifyingContract: EthereumAddress.from(
ethers.Wallet.createRandom().address,
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/modules/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("Staking", () => {
it("should sign message", () => {
expect(messageSigner.sign).toHaveBeenCalledWith(
{
name: "AcreBitcoinDepositor",
name: "BitcoinDepositor",
version: "1",
verifyingContract:
contracts.bitcoinDepositor.getChainIdentifier(),
Expand Down

0 comments on commit 3b3c052

Please sign in to comment.