diff --git a/dapp/src/web3/relayer-depositor-proxy.ts b/dapp/src/web3/relayer-depositor-proxy.ts index 6ef83b38e..7207df6f9 100644 --- a/dapp/src/web3/relayer-depositor-proxy.ts +++ b/dapp/src/web3/relayer-depositor-proxy.ts @@ -72,7 +72,7 @@ class RelayerDepositorProxy if (!extraData) throw new Error("Invalid extra data") - const { staker, referral } = + const { depositOwner, referral } = this.#bitcoinDepositor.decodeExtraData(extraData) // TODO: Catch and handle errors + sentry. @@ -81,7 +81,7 @@ class RelayerDepositorProxy { fundingTx, reveal, - staker: `0x${staker.identifierHex}`, + depositOwner: `0x${depositOwner.identifierHex}`, referral, }, ) diff --git a/sdk/src/lib/contracts/bitcoin-depositor.ts b/sdk/src/lib/contracts/bitcoin-depositor.ts index 749f78b73..f221f39ce 100644 --- a/sdk/src/lib/contracts/bitcoin-depositor.ts +++ b/sdk/src/lib/contracts/bitcoin-depositor.ts @@ -5,7 +5,7 @@ import { DepositorProxy } from "./depositor-proxy" export { DepositReceipt } from "@keep-network/tbtc-v2.ts" export type DecodedExtraData = { - staker: ChainIdentifier + depositOwner: ChainIdentifier referral: number } @@ -24,14 +24,14 @@ export interface BitcoinDepositor extends DepositorProxy { getTbtcVaultChainIdentifier(): Promise /** - * Encodes staker address and referral as extra data. - * @param staker The address to which the stBTC shares will be minted. + * Encodes deposit owner address and referral as extra data. + * @param depositOwner The address to which the stBTC shares will be minted. * @param referral Data used for referral program. */ - encodeExtraData(staker: ChainIdentifier, referral: number): Hex + encodeExtraData(depositOwner: ChainIdentifier, referral: number): Hex /** - * Decodes staker address and referral from extra data. + * Decodes depositOwner address and referral from extra data. * @param extraData Encoded extra data. */ decodeExtraData(extraData: string): DecodedExtraData diff --git a/sdk/src/lib/ethereum/bitcoin-depositor.ts b/sdk/src/lib/ethereum/bitcoin-depositor.ts index d968ee5b6..60e868680 100644 --- a/sdk/src/lib/ethereum/bitcoin-depositor.ts +++ b/sdk/src/lib/ethereum/bitcoin-depositor.ts @@ -84,12 +84,12 @@ class EthereumBitcoinDepositor if (!extraData) throw new Error("Invalid extra data") - const { staker, referral } = this.decodeExtraData(extraData) + const { depositOwner, referral } = this.decodeExtraData(extraData) - const tx = await this.instance.initializeStake( + const tx = await this.instance.initializeDeposit( fundingTx, reveal, - `0x${staker.identifierHex}`, + `0x${depositOwner.identifierHex}`, referral, ) @@ -98,19 +98,19 @@ class EthereumBitcoinDepositor /** * @see {BitcoinDepositor#encodeExtraData} - * @dev Packs the data to bytes32: 20 bytes of staker address and 2 bytes of + * @dev Packs the data to bytes32: 20 bytes of deposit owner address and 2 bytes of * referral, 10 bytes of trailing zeros. */ // eslint-disable-next-line class-methods-use-this - encodeExtraData(staker: ChainIdentifier, referral: number): Hex { - const stakerAddress = `0x${staker.identifierHex}` + encodeExtraData(depositOwner: ChainIdentifier, referral: number): Hex { + const depositOwnerAddress = `0x${depositOwner.identifierHex}` - if (!isAddress(stakerAddress) || stakerAddress === ZeroAddress) - throw new Error("Invalid staker address") + if (!isAddress(depositOwnerAddress) || depositOwnerAddress === ZeroAddress) + throw new Error("Invalid deposit owner address") const encodedData = solidityPacked( ["address", "uint16"], - [stakerAddress, referral], + [depositOwnerAddress, referral], ) return Hex.from(zeroPadBytes(encodedData, 32)) @@ -118,15 +118,17 @@ class EthereumBitcoinDepositor /** * @see {BitcoinDepositor#decodeExtraData} - * @dev Unpacks the data from bytes32: 20 bytes of staker address and 2 + * @dev Unpacks the data from bytes32: 20 bytes of deposit owner address and 2 * bytes of referral, 10 bytes of trailing zeros. */ // eslint-disable-next-line class-methods-use-this decodeExtraData(extraData: string): DecodedExtraData { - const staker = EthereumAddress.from(getAddress(dataSlice(extraData, 0, 20))) + const depositOwner = EthereumAddress.from( + getAddress(dataSlice(extraData, 0, 20)), + ) const referral = Number(dataSlice(extraData, 20, 22)) - return { staker, referral } + return { depositOwner, referral } } } diff --git a/sdk/src/modules/staking/stake-initialization.ts b/sdk/src/modules/staking/stake-initialization.ts index 869de4452..9ed9b31a5 100644 --- a/sdk/src/modules/staking/stake-initialization.ts +++ b/sdk/src/modules/staking/stake-initialization.ts @@ -27,6 +27,7 @@ type StakeOptions = { backoffStepMs: BackoffRetrierParameters[1] } +// TODO: Rename to `DepositInitialization` to be consistent with the naming. /** * Represents an instance of the staking flow. Staking flow requires a few steps * which should be done to stake BTC. diff --git a/sdk/test/lib/ethereum/data.ts b/sdk/test/lib/ethereum/data.ts index 597364a21..b4deab283 100644 --- a/sdk/test/lib/ethereum/data.ts +++ b/sdk/test/lib/ethereum/data.ts @@ -3,48 +3,60 @@ import { EthereumAddress } from "../../../src" // eslint-disable-next-line import/prefer-default-export export const extraDataValidTestData: { testDescription: string - staker: EthereumAddress + depositOwner: EthereumAddress referral: number extraData: string }[] = [ { - testDescription: "staker has leading zeros", - staker: EthereumAddress.from("0x000055d85E80A49B5930C4a77975d44f012D86C1"), + testDescription: "depositOwner has leading zeros", + depositOwner: EthereumAddress.from( + "0x000055d85E80A49B5930C4a77975d44f012D86C1", + ), referral: 6851, // hex: 0x1ac3 extraData: "0x000055d85e80a49b5930c4a77975d44f012d86c11ac300000000000000000000", }, { - testDescription: "staker has trailing zeros", - staker: EthereumAddress.from("0x2d2F8BC7923F7F806Dc9bb2e17F950b42CfE0000"), + testDescription: "depositOwner has trailing zeros", + depositOwner: EthereumAddress.from( + "0x2d2F8BC7923F7F806Dc9bb2e17F950b42CfE0000", + ), referral: 6851, // hex: 0x1ac3 extraData: "0x2d2f8bc7923f7f806dc9bb2e17f950b42cfe00001ac300000000000000000000", }, { testDescription: "referral is zero", - staker: EthereumAddress.from("0xeb098d6cDE6A202981316b24B19e64D82721e89E"), + depositOwner: EthereumAddress.from( + "0xeb098d6cDE6A202981316b24B19e64D82721e89E", + ), referral: 0, extraData: "0xeb098d6cde6a202981316b24b19e64d82721e89e000000000000000000000000", }, { testDescription: "referral has leading zeros", - staker: EthereumAddress.from("0xeb098d6cDE6A202981316b24B19e64D82721e89E"), + depositOwner: EthereumAddress.from( + "0xeb098d6cDE6A202981316b24B19e64D82721e89E", + ), referral: 31, // hex: 0x001f extraData: "0xeb098d6cde6a202981316b24b19e64d82721e89e001f00000000000000000000", }, { testDescription: "referral has trailing zeros", - staker: EthereumAddress.from("0xeb098d6cDE6A202981316b24B19e64D82721e89E"), + depositOwner: EthereumAddress.from( + "0xeb098d6cDE6A202981316b24B19e64D82721e89E", + ), referral: 19712, // hex: 0x4d00 extraData: "0xeb098d6cde6a202981316b24b19e64d82721e89e4d0000000000000000000000", }, { testDescription: "referral is maximum value", - staker: EthereumAddress.from("0xeb098d6cDE6A202981316b24B19e64D82721e89E"), + depositOwner: EthereumAddress.from( + "0xeb098d6cDE6A202981316b24B19e64D82721e89E", + ), referral: 65535, // max uint16 extraData: "0xeb098d6cde6a202981316b24b19e64d82721e89effff00000000000000000000", diff --git a/sdk/test/lib/ethereum/tbtc-depositor.test.ts b/sdk/test/lib/ethereum/tbtc-depositor.test.ts index 7368af30a..5941d0442 100644 --- a/sdk/test/lib/ethereum/tbtc-depositor.test.ts +++ b/sdk/test/lib/ethereum/tbtc-depositor.test.ts @@ -64,7 +64,7 @@ describe("BitcoinDepositor", () => { }) describe("revealDeposit", () => { - const staker = EthereumAddress.from( + const depositOwner = EthereumAddress.from( "0x000055d85E80A49B5930C4a77975d44f012D86C1", ) const bitcoinFundingTransaction = { @@ -79,11 +79,11 @@ describe("BitcoinDepositor", () => { refundPublicKeyHash: Hex.from("28e081f285138ccbe389c1eb8985716230129f89"), blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: Hex.from("60bcea61"), - depositor: staker, + depositor: depositOwner, } describe("when extra data is defined", () => { const extraData = { - staker, + depositOwner, referral: 6851, hex: Hex.from( "0x000055d85e80a49b5930c4a77975d44f012d86c11ac300000000000000000000", @@ -157,7 +157,7 @@ describe("BitcoinDepositor", () => { expect(mockedContractInstance.initializeStake).toHaveBeenCalledWith( btcTxInfo, revealInfo, - `0x${staker.identifierHex}`, + `0x${depositOwner.identifierHex}`, referral, ) expect(result.toPrefixedString()).toBe(mockedTx.toPrefixedString()) @@ -184,20 +184,20 @@ describe("BitcoinDepositor", () => { it.each(extraDataValidTestData)( "$testDescription", - ({ staker, referral, extraData }) => { - const result = depositor.encodeExtraData(staker, referral) + ({ depositOwner, referral, extraData }) => { + const result = depositor.encodeExtraData(depositOwner, referral) expect(spyOnSolidityPacked).toHaveBeenCalledWith( ["address", "uint16"], - [`0x${staker.identifierHex}`, referral], + [`0x${depositOwner.identifierHex}`, referral], ) expect(result.toPrefixedString()).toEqual(extraData) }, ) - describe("when staker is zero address", () => { - const staker = EthereumAddress.from(ZeroAddress) + describe("when deposit owner is zero address", () => { + const depositOwner = EthereumAddress.from(ZeroAddress) beforeEach(() => { spyOnSolidityPacked.mockClear() @@ -205,8 +205,8 @@ describe("BitcoinDepositor", () => { it("should throw an error", () => { expect(() => { - depositor.encodeExtraData(staker, 0) - }).toThrow("Invalid staker address") + depositor.encodeExtraData(depositOwner, 0) + }).toThrow("Invalid deposit owner address") expect(spyOnSolidityPacked).not.toHaveBeenCalled() }) }) @@ -219,8 +219,12 @@ describe("BitcoinDepositor", () => { it.each(extraDataValidTestData)( "$testDescription", - ({ staker: expectedStaker, extraData, referral: expectedReferral }) => { - const { staker, referral } = depositor.decodeExtraData(extraData) + ({ + depositOwner: expectedDepositOwner, + extraData, + referral: expectedReferral, + }) => { + const { depositOwner, referral } = depositor.decodeExtraData(extraData) expect(spyOnEthersDataSlice).toHaveBeenNthCalledWith( 1, @@ -236,7 +240,7 @@ describe("BitcoinDepositor", () => { 22, ) - expect(expectedStaker.equals(staker)).toBeTruthy() + expect(expectedDepositOwner.equals(depositOwner)).toBeTruthy() expect(expectedReferral).toBe(referral) }, )