diff --git a/dapp/src/contexts/StakeFlowContext.tsx b/dapp/src/contexts/StakeFlowContext.tsx index 8afe6870b..d19cad509 100644 --- a/dapp/src/contexts/StakeFlowContext.tsx +++ b/dapp/src/contexts/StakeFlowContext.tsx @@ -6,7 +6,7 @@ import { } from "#/acre-react/hooks" import { REFERRAL } from "#/constants" import { RelayerDepositorProxy } from "#/web3" -import { EthereumTBTCDepositor } from "@acre-btc/sdk" +import { EthereumBitcoinDepositor } from "@acre-btc/sdk" type StakeFlowContextValue = Omit & { initStake: ( @@ -39,8 +39,8 @@ export function StakeFlowProvider({ children }: { children: React.ReactNode }) { bitcoinRecoveryAddress, ethereumAddress, REFERRAL, - RelayerDepositorProxy.fromEthereumTbtcDepositor( - acre.contracts.tbtcDepositor as EthereumTBTCDepositor, + RelayerDepositorProxy.fromEthereumBitcoinDepositor( + acre.contracts.bitcoinDepositor as EthereumBitcoinDepositor, ), ) }, diff --git a/dapp/src/web3/relayer-depositor-proxy.ts b/dapp/src/web3/relayer-depositor-proxy.ts index 9d6f3fe0b..6ef83b38e 100644 --- a/dapp/src/web3/relayer-depositor-proxy.ts +++ b/dapp/src/web3/relayer-depositor-proxy.ts @@ -1,12 +1,12 @@ import { BitcoinRawTxVectors, DepositorProxy, - EthereumTBTCDepositor, + EthereumBitcoinDepositor, ChainIdentifier, DepositReceipt, Hex, packRevealDepositParameters, - TBTCDepositor, + BitcoinDepositor, } from "@acre-btc/sdk" import axios from "axios" @@ -18,11 +18,13 @@ const DEFENDER_WEBHOOK_URL = import.meta.env.VITE_DEFENDER_RELAYER_WEBHOOK_URL * Sends the HTTP POST request to the webhook at the provided URL with the data * necessary to initialize stake. */ -class RelayerDepositorProxy implements DepositorProxy { +class RelayerDepositorProxy + implements DepositorProxy +{ /** - * Chain-specific handle to @see TBTCDepositor contract. + * Chain-specific handle to @see BitcoinDepositor contract. */ - #tbtcDepositor: T + #bitcoinDepositor: T /** * Defines the Open Zeppelin Defender webhook URL. @@ -31,17 +33,17 @@ class RelayerDepositorProxy implements DepositorProxy { /** * Creates the instance of the relayer depositor proxy for Ethereum chain. - * @param tbtcDepositor Ethereum handle to @see TBTCDepositor contract. + * @param bitcoinDepositor Ethereum handle to @see BitcoinDepositor contract. * @returns Instance of @see RelayerDepositorProxy. */ - static fromEthereumTbtcDepositor( - tbtcDepositor: EthereumTBTCDepositor, - ): RelayerDepositorProxy { - return new RelayerDepositorProxy(tbtcDepositor, DEFENDER_WEBHOOK_URL) + static fromEthereumBitcoinDepositor( + bitcoinDepositor: EthereumBitcoinDepositor, + ): RelayerDepositorProxy { + return new RelayerDepositorProxy(bitcoinDepositor, DEFENDER_WEBHOOK_URL) } - private constructor(_tbtcDepositor: T, _defenderWebhookUr: string) { - this.#tbtcDepositor = _tbtcDepositor + private constructor(_bitcoinDepositor: T, _defenderWebhookUr: string) { + this.#bitcoinDepositor = _bitcoinDepositor this.#defenderWebhookUrl = _defenderWebhookUr } @@ -49,7 +51,7 @@ class RelayerDepositorProxy implements DepositorProxy { * @see {DepositorProxy#getChainIdentifier} */ getChainIdentifier(): ChainIdentifier { - return this.#tbtcDepositor.getChainIdentifier() + return this.#bitcoinDepositor.getChainIdentifier() } /** @@ -65,12 +67,13 @@ class RelayerDepositorProxy implements DepositorProxy { depositTx, depositOutputIndex, deposit, - await this.#tbtcDepositor.getTbtcVaultChainIdentifier(), + await this.#bitcoinDepositor.getTbtcVaultChainIdentifier(), ) if (!extraData) throw new Error("Invalid extra data") - const { staker, referral } = this.#tbtcDepositor.decodeExtraData(extraData) + const { staker, referral } = + this.#bitcoinDepositor.decodeExtraData(extraData) // TODO: Catch and handle errors + sentry. const response = await axios.post<{ result: string }>( diff --git a/sdk/src/lib/contracts/tbtc-depositor.ts b/sdk/src/lib/contracts/bitcoin-depositor.ts similarity index 87% rename from sdk/src/lib/contracts/tbtc-depositor.ts rename to sdk/src/lib/contracts/bitcoin-depositor.ts index 393221c36..960bc4e1f 100644 --- a/sdk/src/lib/contracts/tbtc-depositor.ts +++ b/sdk/src/lib/contracts/bitcoin-depositor.ts @@ -10,9 +10,9 @@ export type DecodedExtraData = { } /** - * Interface for communication with the TBTCDepositor on-chain contract. + * Interface for communication with the AcreBitcoinDepositor on-chain contract. */ -export interface TBTCDepositor extends DepositorProxy { +export interface BitcoinDepositor extends DepositorProxy { /** * @returns The chain-specific identifier of this contract. */ diff --git a/sdk/src/lib/contracts/index.ts b/sdk/src/lib/contracts/index.ts index fc0664ae1..0bfa7309a 100644 --- a/sdk/src/lib/contracts/index.ts +++ b/sdk/src/lib/contracts/index.ts @@ -1,6 +1,6 @@ -import { TBTCDepositor } from "./tbtc-depositor" +import { BitcoinDepositor } from "./bitcoin-depositor" -export * from "./tbtc-depositor" +export * from "./bitcoin-depositor" export * from "./chain-identifier" export * from "./depositor-proxy" @@ -8,5 +8,5 @@ export * from "./depositor-proxy" * Represents all contracts that allow interaction with the Acre network. */ export type AcreContracts = { - tbtcDepositor: TBTCDepositor + bitcoinDepositor: BitcoinDepositor } diff --git a/sdk/src/lib/ethereum/tbtc-depositor.ts b/sdk/src/lib/ethereum/bitcoin-depositor.ts similarity index 87% rename from sdk/src/lib/ethereum/tbtc-depositor.ts rename to sdk/src/lib/ethereum/bitcoin-depositor.ts index 9379bed76..e5b33ca80 100644 --- a/sdk/src/lib/ethereum/tbtc-depositor.ts +++ b/sdk/src/lib/ethereum/bitcoin-depositor.ts @@ -11,7 +11,7 @@ import { import { ChainIdentifier, DecodedExtraData, - TBTCDepositor, + BitcoinDepositor, DepositReceipt, } from "../contracts" import { BitcoinRawTxVectors } from "../bitcoin" @@ -26,17 +26,15 @@ import { EthereumNetwork } from "./network" import SepoliaBitcoinDepositor from "./artifacts/sepolia/AcreBitcoinDepositor.json" -// TODO: Rename TBTCDepositor to AcreBitcoinDepositor - /** - * Ethereum implementation of the TBTCDepositor. + * Ethereum implementation of the BitcoinDepositor. */ -class EthereumTBTCDepositor +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 - implements TBTCDepositor + implements BitcoinDepositor { constructor(config: EthersContractConfig, network: EthereumNetwork) { let artifact: EthersContractDeployment @@ -54,14 +52,14 @@ class EthereumTBTCDepositor } /** - * @see {TBTCDepositor#getChainIdentifier} + * @see {BitcoinDepositor#getChainIdentifier} */ getChainIdentifier(): ChainIdentifier { return this.getAddress() } /** - * @see {TBTCDepositor#getTbtcVaultChainIdentifier} + * @see {BitcoinDepositor#getTbtcVaultChainIdentifier} */ async getTbtcVaultChainIdentifier(): Promise { const vault = await this.instance.tbtcVault() @@ -70,7 +68,7 @@ class EthereumTBTCDepositor } /** - * @see {TBTCDepositor#revealDeposit} + * @see {BitcoinDepositor#revealDeposit} */ async revealDeposit( depositTx: BitcoinRawTxVectors, @@ -99,7 +97,7 @@ class EthereumTBTCDepositor } /** - * @see {TBTCDepositor#encodeExtraData} + * @see {BitcoinDepositor#encodeExtraData} * @dev Packs the data to bytes32: 20 bytes of staker address and 2 bytes of * referral, 10 bytes of trailing zeros. */ @@ -119,7 +117,7 @@ class EthereumTBTCDepositor } /** - * @see {TBTCDepositor#decodeExtraData} + * @see {BitcoinDepositor#decodeExtraData} * @dev Unpacks the data from bytes32: 20 bytes of staker address and 2 * bytes of referral, 10 bytes of trailing zeros. */ @@ -132,4 +130,4 @@ class EthereumTBTCDepositor } } -export { EthereumTBTCDepositor, packRevealDepositParameters } +export { EthereumBitcoinDepositor, packRevealDepositParameters } diff --git a/sdk/src/lib/ethereum/index.ts b/sdk/src/lib/ethereum/index.ts index 874aef6ad..3e21778fe 100644 --- a/sdk/src/lib/ethereum/index.ts +++ b/sdk/src/lib/ethereum/index.ts @@ -1,10 +1,10 @@ import { AcreContracts } from "../contracts" import { EthereumSigner } from "./contract" -import { EthereumTBTCDepositor } from "./tbtc-depositor" +import { EthereumBitcoinDepositor } from "./bitcoin-depositor" import { EthereumNetwork } from "./network" export * from "./eip712-signer" -export * from "./tbtc-depositor" +export * from "./bitcoin-depositor" export * from "./address" export { EthereumSigner } @@ -12,9 +12,9 @@ function getEthereumContracts( signer: EthereumSigner, network: EthereumNetwork, ): AcreContracts { - const tbtcDepositor = new EthereumTBTCDepositor({ signer }, network) + const bitcoinDepositor = new EthereumBitcoinDepositor({ signer }, network) - return { tbtcDepositor } + return { bitcoinDepositor } } export { getEthereumContracts, EthereumNetwork } diff --git a/sdk/src/modules/staking/index.ts b/sdk/src/modules/staking/index.ts index f4fd6b181..9f8cca1be 100644 --- a/sdk/src/modules/staking/index.ts +++ b/sdk/src/modules/staking/index.ts @@ -50,8 +50,8 @@ class StakingModule { ) { const deposit = await this.#tbtc.deposits.initiateDepositWithProxy( bitcoinRecoveryAddress, - depositorProxy ?? this.#contracts.tbtcDepositor, - this.#contracts.tbtcDepositor.encodeExtraData(staker, referral), + depositorProxy ?? this.#contracts.bitcoinDepositor, + this.#contracts.bitcoinDepositor.encodeExtraData(staker, referral), ) return new StakeInitialization( diff --git a/sdk/src/modules/staking/stake-initialization.ts b/sdk/src/modules/staking/stake-initialization.ts index 95af9eb13..437b62285 100644 --- a/sdk/src/modules/staking/stake-initialization.ts +++ b/sdk/src/modules/staking/stake-initialization.ts @@ -105,9 +105,9 @@ class StakeInitialization { */ #getStakeMessageTypedData() { const domain: Domain = { - name: "TbtcDepositor", + name: "AcreBitcoinDepositor", version: "1", - verifyingContract: this.#contracts.tbtcDepositor.getChainIdentifier(), + verifyingContract: this.#contracts.bitcoinDepositor.getChainIdentifier(), } // TODO: revisit the message structure before the launch. Let's think about @@ -131,7 +131,7 @@ class StakeInitialization { } /** - * Stakes BTC based on the Bitcoin funding transaction via TBTCDepositor + * Stakes BTC based on the Bitcoin funding transaction via BitcoinDepositor * contract. It requires signed staking message, which means `stake` should be * called after message signing. By default, it detects and uses the outpoint * of the recent Bitcoin funding transaction and throws if such a transaction diff --git a/sdk/test/lib/ethereum/eip712.test.ts b/sdk/test/lib/ethereum/eip712.test.ts index 66966faba..5e342e0ac 100644 --- a/sdk/test/lib/ethereum/eip712.test.ts +++ b/sdk/test/lib/ethereum/eip712.test.ts @@ -7,7 +7,7 @@ import { const signMessageData = { domain: { - name: "TBTCDepositor", + name: "AcreBitcoinDepositor", version: "1", verifyingContract: EthereumAddress.from( ethers.Wallet.createRandom().address, diff --git a/sdk/test/lib/ethereum/tbtc-depositor.test.ts b/sdk/test/lib/ethereum/tbtc-depositor.test.ts index a631bbefe..7368af30a 100644 --- a/sdk/test/lib/ethereum/tbtc-depositor.test.ts +++ b/sdk/test/lib/ethereum/tbtc-depositor.test.ts @@ -1,6 +1,6 @@ import ethers, { Contract, ZeroAddress } from "ethers" import { - EthereumTBTCDepositor, + EthereumBitcoinDepositor, EthereumAddress, Hex, EthereumSigner, @@ -12,7 +12,7 @@ jest.mock("ethers", (): object => ({ ...jest.requireActual("ethers"), })) -describe("TBTCDepositor", () => { +describe("BitcoinDepositor", () => { const spyOnEthersDataSlice = jest.spyOn(ethers, "dataSlice") const vaultAddress = EthereumAddress.from( @@ -23,7 +23,7 @@ describe("TBTCDepositor", () => { tbtcVault: jest.fn().mockImplementation(() => vaultAddress.identifierHex), initializeStake: jest.fn(), } - let depositor: EthereumTBTCDepositor + let depositor: EthereumBitcoinDepositor let depositorAddress: EthereumAddress beforeEach(async () => { @@ -38,7 +38,7 @@ describe("TBTCDepositor", () => { await ethers.Wallet.createRandom().getAddress(), ) - depositor = new EthereumTBTCDepositor( + depositor = new EthereumBitcoinDepositor( { signer: {} as EthereumSigner, address: depositorAddress.identifierHex, diff --git a/sdk/test/modules/staking.test.ts b/sdk/test/modules/staking.test.ts index ee355cb89..353c2efda 100644 --- a/sdk/test/modules/staking.test.ts +++ b/sdk/test/modules/staking.test.ts @@ -79,11 +79,11 @@ describe("Staking", () => { let result: StakeInitialization beforeEach(async () => { - contracts.tbtcDepositor.decodeExtraData = jest + contracts.bitcoinDepositor.decodeExtraData = jest .fn() .mockReturnValue({ staker, referral }) - contracts.tbtcDepositor.encodeExtraData = jest + contracts.bitcoinDepositor.encodeExtraData = jest .fn() .mockReturnValue(extraData) @@ -101,13 +101,13 @@ describe("Staking", () => { }) it("should encode extra data", () => { - expect(contracts.tbtcDepositor.encodeExtraData(staker, referral)) + expect(contracts.bitcoinDepositor.encodeExtraData(staker, referral)) }) it("should initiate tBTC deposit", () => { expect(tbtc.deposits.initiateDepositWithProxy).toHaveBeenCalledWith( bitcoinRecoveryAddress, - contracts.tbtcDepositor, + contracts.bitcoinDepositor, extraData, ) }) @@ -148,7 +148,7 @@ describe("Staking", () => { beforeEach(async () => { mockedSignedMessage.verify.mockReturnValue(staker) - contracts.tbtcDepositor.getChainIdentifier = jest + contracts.bitcoinDepositor.getChainIdentifier = jest .fn() .mockReturnValue(EthereumAddress.from(depositorAddress)) @@ -158,10 +158,10 @@ describe("Staking", () => { it("should sign message", () => { expect(messageSigner.sign).toHaveBeenCalledWith( { - name: "TbtcDepositor", + name: "AcreBitcoinDepositor", version: "1", verifyingContract: - contracts.tbtcDepositor.getChainIdentifier(), + contracts.bitcoinDepositor.getChainIdentifier(), }, { Stake: [ @@ -244,7 +244,7 @@ describe("Staking", () => { let result: StakeInitialization beforeEach(async () => { - contracts.tbtcDepositor.encodeExtraData = jest + contracts.bitcoinDepositor.encodeExtraData = jest .fn() .mockReturnValue(extraData) diff --git a/sdk/test/utils/mock-acre-contracts.ts b/sdk/test/utils/mock-acre-contracts.ts index 111554b39..0c36aaf76 100644 --- a/sdk/test/utils/mock-acre-contracts.ts +++ b/sdk/test/utils/mock-acre-contracts.ts @@ -1,16 +1,16 @@ -import { AcreContracts, TBTCDepositor } from "../../src/lib/contracts" +import { AcreContracts, BitcoinDepositor } from "../../src/lib/contracts" // eslint-disable-next-line import/prefer-default-export export class MockAcreContracts implements AcreContracts { - public readonly tbtcDepositor: TBTCDepositor + public readonly bitcoinDepositor: BitcoinDepositor constructor() { - this.tbtcDepositor = { + this.bitcoinDepositor = { getChainIdentifier: jest.fn(), getTbtcVaultChainIdentifier: jest.fn(), decodeExtraData: jest.fn(), encodeExtraData: jest.fn(), revealDeposit: jest.fn(), - } as TBTCDepositor + } as BitcoinDepositor } }