diff --git a/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/StakeDetails.tsx b/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/StakeDetails.tsx index bba5a7c28..9f6d8ebf3 100644 --- a/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/StakeDetails.tsx +++ b/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/StakeDetails.tsx @@ -11,12 +11,12 @@ function StakeDetails({ maxTokenAmount, }: { currency: CurrencyType - minTokenAmount: string - maxTokenAmount: string + minTokenAmount: bigint + maxTokenAmount: bigint }) { const value = useTokenAmountFormValue() ?? 0n - const isMaximumValueExceeded = value > BigInt(maxTokenAmount) - const isMinimumValueFulfilled = value >= BigInt(minTokenAmount) + const isMaximumValueExceeded = value > maxTokenAmount + const isMinimumValueFulfilled = value >= minTokenAmount // Let's not calculate the details of the transaction when the value is not valid. const amount = !isMaximumValueExceeded && isMinimumValueFulfilled ? value : 0n const details = useTransactionDetails(amount) diff --git a/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/index.tsx b/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/index.tsx index 5f80d9576..7e627e73d 100644 --- a/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/index.tsx +++ b/dapp/src/components/TransactionModal/ActiveStakingStep/StakeFormModal/index.tsx @@ -1,8 +1,7 @@ import React from "react" -import { BITCOIN_MIN_AMOUNT } from "#/constants" import TokenAmountForm from "#/components/shared/TokenAmountForm" import { TokenAmountFormValues } from "#/components/shared/TokenAmountForm/TokenAmountFormBase" -import { useWalletContext } from "#/hooks" +import { useMinDepositAmount, useWalletContext } from "#/hooks" import { FormSubmitButton } from "#/components/shared/Form" import StakeDetails from "./StakeDetails" @@ -11,20 +10,21 @@ function StakeFormModal({ }: { onSubmitForm: (values: TokenAmountFormValues) => void }) { + const minDepositAmount = useMinDepositAmount() const { btcAccount } = useWalletContext() - const tokenBalance = btcAccount?.balance.toString() ?? "0" + const tokenBalance = BigInt(btcAccount?.balance.toString() ?? "0") return ( Stake diff --git a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx index 85ec4c38e..981a43b62 100644 --- a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx +++ b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx @@ -1,27 +1,29 @@ import React from "react" import { Card, CardBody, Flex, HStack } from "@chakra-ui/react" -import { BITCOIN_MIN_AMOUNT } from "#/constants" import TokenAmountForm from "#/components/shared/TokenAmountForm" import { TokenAmountFormValues } from "#/components/shared/TokenAmountForm/TokenAmountFormBase" import { TextMd, TextSm } from "#/components/shared/Typography" import Spinner from "#/components/shared/Spinner" import { FormSubmitButton } from "#/components/shared/Form" +import { useMinDepositAmount } from "#/hooks" import UnstakeDetails from "./UnstakeDetails" // TODO: Use a position amount -const MOCK_POSITION_AMOUNT = "2398567898" +const MOCK_POSITION_AMOUNT = BigInt("2398567898") function UnstakeFormModal({ onSubmitForm, }: { onSubmitForm: (values: TokenAmountFormValues) => void }) { + const minDepositAmount = useMinDepositAmount() + return ( diff --git a/dapp/src/components/shared/CurrencyBalance/index.tsx b/dapp/src/components/shared/CurrencyBalance/index.tsx index d8620ffb6..7302a7d40 100644 --- a/dapp/src/components/shared/CurrencyBalance/index.tsx +++ b/dapp/src/components/shared/CurrencyBalance/index.tsx @@ -9,7 +9,7 @@ import { CurrencyType } from "#/types" export type CurrencyBalanceProps = { currency: CurrencyType - amount?: string | number + amount?: string | number | bigint shouldBeFormatted?: boolean desiredDecimals?: number size?: string @@ -40,7 +40,7 @@ export function CurrencyBalance({ const balance = useMemo(() => { const value = amount ?? 0 - if (shouldBeFormatted) + if (shouldBeFormatted || typeof value === "bigint") return formatTokenAmount(value, decimals, desiredDecimals) return numberToLocaleString(value, desiredDecimals) diff --git a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx index 18e4bd712..55a1151f8 100644 --- a/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx +++ b/dapp/src/components/shared/TokenAmountForm/TokenAmountFormBase.tsx @@ -19,7 +19,7 @@ export const useTokenAmountFormValue = () => { export type TokenAmountFormBaseProps = { formId?: string - tokenBalance: string + tokenBalance: bigint tokenBalanceInputPlaceholder: string currency: CurrencyType children?: React.ReactNode diff --git a/dapp/src/components/shared/TokenAmountForm/index.tsx b/dapp/src/components/shared/TokenAmountForm/index.tsx index d8c6fabf0..80850c4e0 100644 --- a/dapp/src/components/shared/TokenAmountForm/index.tsx +++ b/dapp/src/components/shared/TokenAmountForm/index.tsx @@ -7,7 +7,7 @@ import TokenAmountFormBase, { type TokenAmountFormProps = { onSubmitForm: (values: TokenAmountFormValues) => void - minTokenAmount: string + minTokenAmount: bigint } & TokenAmountFormBaseProps const TokenAmountForm = withFormik( diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index de55b64dd..f9edbd942 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -87,7 +87,7 @@ function FiatCurrencyBalance({ export type TokenBalanceInputProps = { amount?: bigint currency: CurrencyType - tokenBalance: string | number + tokenBalance: bigint placeholder?: string size?: "lg" | "md" setAmount: (value?: bigint) => void @@ -143,9 +143,7 @@ export default function TokenBalanceInput({ placeholder={placeholder} {...inputProps} value={ - amount - ? fixedPointNumberToString(BigInt(amount), decimals) - : undefined + amount ? fixedPointNumberToString(amount, decimals) : undefined } onValueChange={(values: NumberFormatInputValues) => handleValueChange(values.value) @@ -155,7 +153,7 @@ export default function TokenBalanceInput({ }} /> - diff --git a/dapp/src/constants/currency.ts b/dapp/src/constants/currency.ts index de7a788d7..483da1dbd 100644 --- a/dapp/src/constants/currency.ts +++ b/dapp/src/constants/currency.ts @@ -1,13 +1,13 @@ import { Currency, CurrencyType } from "#/types" import { EthereumNetwork } from "@acre-btc/sdk" import { ETHEREUM_NETWORK } from "./chains" -import { BITCOIN_DESIRED_DECIMALS } from "./staking" export const BITCOIN: Currency = { name: "Bitcoin", symbol: "BTC", decimals: 8, - desiredDecimals: BITCOIN_DESIRED_DECIMALS, + // TODO: Change when min amount of BTC will be updated + desiredDecimals: 5, } export const STBTC: Currency = { diff --git a/dapp/src/constants/staking.ts b/dapp/src/constants/staking.ts index c7e2e980d..f7664b0f2 100644 --- a/dapp/src/constants/staking.ts +++ b/dapp/src/constants/staking.ts @@ -1,11 +1 @@ -import { getDesiredDecimals } from "#/utils/numbers" - -// TODO: Read the value from the SDK, once we expose it -export const BITCOIN_MIN_AMOUNT = String(1e4) // 0.0001 BTC - -export const BITCOIN_DESIRED_DECIMALS = getDesiredDecimals( - BITCOIN_MIN_AMOUNT, - 8, -) - export const REFERRAL = import.meta.env.VITE_REFERRAL diff --git a/dapp/src/hooks/index.ts b/dapp/src/hooks/index.ts index 8cbe7c13b..a443f5ae5 100644 --- a/dapp/src/hooks/index.ts +++ b/dapp/src/hooks/index.ts @@ -1,4 +1,5 @@ export * from "./store" +export * from "./sdk" export * from "./useDetectThemeMode" export * from "./useRequestBitcoinAccount" export * from "./useRequestEthereumAccount" @@ -9,7 +10,6 @@ export * from "./useModalFlowContext" export * from "./useTransactionContext" export * from "./useTransactionDetails" export * from "./useDepositBTCTransaction" -export * from "./useInitializeAcreSdk" export * from "./useTransactionHistoryTable" export * from "./useExecuteFunction" export * from "./useStakeFlowContext" @@ -19,5 +19,4 @@ export * from "./useDepositTelemetry" export * from "./useFetchBTCPriceUSD" export * from "./useCountdown" export * from "./useActivities" -export * from "./useFetchBTCBalance" export * from "./useSize" diff --git a/dapp/src/hooks/sdk/index.ts b/dapp/src/hooks/sdk/index.ts new file mode 100644 index 000000000..8d103f71e --- /dev/null +++ b/dapp/src/hooks/sdk/index.ts @@ -0,0 +1,4 @@ +export * from "./useInitializeAcreSdk" +export * from "./useFetchMinDepositAmount" +export * from "./useInitDataFromSdk" +export * from "./useFetchBTCBalance" diff --git a/dapp/src/hooks/useFetchBTCBalance.ts b/dapp/src/hooks/sdk/useFetchBTCBalance.ts similarity index 89% rename from dapp/src/hooks/useFetchBTCBalance.ts rename to dapp/src/hooks/sdk/useFetchBTCBalance.ts index 360135312..ab73285d3 100644 --- a/dapp/src/hooks/useFetchBTCBalance.ts +++ b/dapp/src/hooks/sdk/useFetchBTCBalance.ts @@ -3,8 +3,8 @@ import { EthereumAddress } from "@acre-btc/sdk" import { useAcreContext } from "#/acre-react/hooks" import { logPromiseFailure } from "#/utils" import { setEstimatedBtcBalance, setSharesBalance } from "#/store/btc" -import { useWalletContext } from "./useWalletContext" -import { useAppDispatch } from "./store" +import { useWalletContext } from "../useWalletContext" +import { useAppDispatch } from "../store/useAppDispatch" export function useFetchBTCBalance() { const { acre, isInitialized } = useAcreContext() diff --git a/dapp/src/hooks/sdk/useFetchMinDepositAmount.ts b/dapp/src/hooks/sdk/useFetchMinDepositAmount.ts new file mode 100644 index 000000000..835de9918 --- /dev/null +++ b/dapp/src/hooks/sdk/useFetchMinDepositAmount.ts @@ -0,0 +1,22 @@ +import { useEffect } from "react" +import { setMinDepositAmount } from "#/store/btc" +import { logPromiseFailure } from "#/utils" +import { useAcreContext } from "#/acre-react/hooks" +import { useAppDispatch } from "../store/useAppDispatch" + +export function useFetchMinDepositAmount() { + const { acre, isInitialized } = useAcreContext() + const dispatch = useAppDispatch() + + useEffect(() => { + if (!isInitialized || !acre) return + + const fetchMinDepositAmount = async () => { + const minDepositAmount = await acre.staking.minDepositAmount() + + dispatch(setMinDepositAmount(minDepositAmount)) + } + + logPromiseFailure(fetchMinDepositAmount()) + }, [acre, dispatch, isInitialized]) +} diff --git a/dapp/src/hooks/sdk/useInitDataFromSdk.ts b/dapp/src/hooks/sdk/useInitDataFromSdk.ts new file mode 100644 index 000000000..56ade2b6a --- /dev/null +++ b/dapp/src/hooks/sdk/useInitDataFromSdk.ts @@ -0,0 +1,7 @@ +import { useFetchBTCBalance } from "./useFetchBTCBalance" +import { useFetchMinDepositAmount } from "./useFetchMinDepositAmount" + +export function useInitDataFromSdk() { + useFetchBTCBalance() + useFetchMinDepositAmount() +} diff --git a/dapp/src/hooks/useInitializeAcreSdk.ts b/dapp/src/hooks/sdk/useInitializeAcreSdk.ts similarity index 90% rename from dapp/src/hooks/useInitializeAcreSdk.ts rename to dapp/src/hooks/sdk/useInitializeAcreSdk.ts index ab05a9aac..56af453e1 100644 --- a/dapp/src/hooks/useInitializeAcreSdk.ts +++ b/dapp/src/hooks/sdk/useInitializeAcreSdk.ts @@ -2,7 +2,7 @@ import { useEffect } from "react" import { ETHEREUM_NETWORK } from "#/constants" import { logPromiseFailure } from "#/utils" import { useAcreContext } from "#/acre-react/hooks" -import { useWalletContext } from "./useWalletContext" +import { useWalletContext } from "../useWalletContext" export function useInitializeAcreSdk() { const { ethAccount } = useWalletContext() diff --git a/dapp/src/hooks/store/index.ts b/dapp/src/hooks/store/index.ts index ac22e8a41..bdad282f8 100644 --- a/dapp/src/hooks/store/index.ts +++ b/dapp/src/hooks/store/index.ts @@ -2,3 +2,4 @@ export * from "./useAppDispatch" export * from "./useAppSelector" export * from "./useEstimatedBTCBalance" export * from "./useSharesBalance" +export * from "./useMinDepositAmount" diff --git a/dapp/src/hooks/store/useMinDepositAmount.ts b/dapp/src/hooks/store/useMinDepositAmount.ts new file mode 100644 index 000000000..082a0a68a --- /dev/null +++ b/dapp/src/hooks/store/useMinDepositAmount.ts @@ -0,0 +1,6 @@ +import { selectMinDepositAmount } from "#/store/btc" +import { useAppSelector } from "./useAppSelector" + +export function useMinDepositAmount() { + return useAppSelector(selectMinDepositAmount) +} diff --git a/dapp/src/hooks/useCurrencyConversion.ts b/dapp/src/hooks/useCurrencyConversion.ts index f3279c86e..d16925b2e 100644 --- a/dapp/src/hooks/useCurrencyConversion.ts +++ b/dapp/src/hooks/useCurrencyConversion.ts @@ -7,7 +7,7 @@ import { useAppSelector } from "./store" type CurrencyConversionType = { currency: CurrencyType - amount?: number | string + amount?: number | string | bigint } // TODO: should be updated to handle another currencies diff --git a/dapp/src/hooks/useInitApp.ts b/dapp/src/hooks/useInitApp.ts index 906bcd608..250c784af 100644 --- a/dapp/src/hooks/useInitApp.ts +++ b/dapp/src/hooks/useInitApp.ts @@ -1,13 +1,12 @@ +import { useInitDataFromSdk, useInitializeAcreSdk } from "./sdk" import { useSentry } from "./sentry" -import { useInitializeAcreSdk } from "./useInitializeAcreSdk" import { useFetchBTCPriceUSD } from "./useFetchBTCPriceUSD" -import { useFetchBTCBalance } from "./useFetchBTCBalance" export function useInitApp() { // TODO: Let's uncomment when dark mode is ready // useDetectThemeMode() useSentry() useInitializeAcreSdk() + useInitDataFromSdk() useFetchBTCPriceUSD() - useFetchBTCBalance() } diff --git a/dapp/src/store/btc/btcSelector.ts b/dapp/src/store/btc/btcSelector.ts index 806f5b65b..88a511361 100644 --- a/dapp/src/store/btc/btcSelector.ts +++ b/dapp/src/store/btc/btcSelector.ts @@ -2,7 +2,12 @@ import { RootState } from ".." export const selectEstimatedBtcBalance = (state: RootState): bigint => state.btc.estimatedBtcBalance + export const selectSharesBalance = (state: RootState): bigint => state.btc.sharesBalance + export const selectBtcUsdPrice = (state: RootState): number => state.btc.usdPrice + +export const selectMinDepositAmount = (state: RootState) => + state.btc.minDepositAmount diff --git a/dapp/src/store/btc/btcSlice.ts b/dapp/src/store/btc/btcSlice.ts index a3e7ce9fc..0f69fb13e 100644 --- a/dapp/src/store/btc/btcSlice.ts +++ b/dapp/src/store/btc/btcSlice.ts @@ -6,6 +6,7 @@ type BtcState = { sharesBalance: bigint isLoadingPriceUSD: boolean usdPrice: number + minDepositAmount: bigint } const initialState: BtcState = { @@ -13,6 +14,7 @@ const initialState: BtcState = { sharesBalance: 0n, isLoadingPriceUSD: false, usdPrice: 0, + minDepositAmount: 0n, } // Store Bitcoin data such as balance, balance in usd and other related data to Bitcoin chain. @@ -26,6 +28,9 @@ export const btcSlice = createSlice({ setEstimatedBtcBalance(state, action: PayloadAction) { state.estimatedBtcBalance = action.payload }, + setMinDepositAmount(state, action: PayloadAction) { + state.minDepositAmount = action.payload + }, }, extraReducers: (builder) => { builder.addCase(fetchBTCPriceUSD.pending, (state) => { @@ -44,4 +49,5 @@ export const btcSlice = createSlice({ }, }) -export const { setSharesBalance, setEstimatedBtcBalance } = btcSlice.actions +export const { setSharesBalance, setEstimatedBtcBalance, setMinDepositAmount } = + btcSlice.actions diff --git a/dapp/src/utils/forms.ts b/dapp/src/utils/forms.ts index ba11af6d1..d1c8caf4f 100644 --- a/dapp/src/utils/forms.ts +++ b/dapp/src/utils/forms.ts @@ -17,24 +17,21 @@ export function getErrorsObj(errors: { [key in keyof T]: string }) { export function validateTokenAmount( value: bigint | undefined, - maxValue: string, - minValue: string, + maxValue: bigint, + minValue: bigint, currency: CurrencyType, ): string | undefined { if (value === undefined) return ERRORS.REQUIRED const { decimals } = getCurrencyByType(currency) - const maxValueInBI = BigInt(maxValue) - const minValueInBI = BigInt(minValue) - - const isMaximumValueExceeded = value > maxValueInBI - const isMinimumValueFulfilled = value >= minValueInBI + const isMaximumValueExceeded = value > maxValue + const isMinimumValueFulfilled = value >= minValue if (isMaximumValueExceeded) return ERRORS.EXCEEDED_VALUE if (!isMinimumValueFulfilled) return ERRORS.INSUFFICIENT_VALUE( - fixedPointNumberToString(BigInt(minValue), decimals), + fixedPointNumberToString(minValue, decimals), ) return undefined diff --git a/dapp/src/utils/numbers.ts b/dapp/src/utils/numbers.ts index 9cf07bcbf..a0a5c0baa 100644 --- a/dapp/src/utils/numbers.ts +++ b/dapp/src/utils/numbers.ts @@ -48,7 +48,7 @@ export function bigIntToUserAmount( * */ export const formatTokenAmount = ( - amount: number | string, + amount: number | string | bigint, decimals = 18, desiredDecimals = 2, ) => { @@ -201,12 +201,6 @@ export function userAmountToBigInt( export const randomInteger = (min: number, max: number) => Math.floor(Math.random() * (max - min + 1)) + min -export function getDesiredDecimals(amount: string | number, decimals: number) { - const undecimaledAmount = amount.toString() - const desiredDecimals = decimals - undecimaledAmount.length + 1 - return desiredDecimals > 0 ? desiredDecimals : 2 -} - export const addLeadingZero = (num: number): string => num >= 0 && num <= 9 ? `0${num}` : `${num}` diff --git a/sdk/src/lib/contracts/bitcoin-depositor.ts b/sdk/src/lib/contracts/bitcoin-depositor.ts index f221f39ce..05d3dd887 100644 --- a/sdk/src/lib/contracts/bitcoin-depositor.ts +++ b/sdk/src/lib/contracts/bitcoin-depositor.ts @@ -35,4 +35,9 @@ export interface BitcoinDepositor extends DepositorProxy { * @param extraData Encoded extra data. */ decodeExtraData(extraData: string): DecodedExtraData + + /** + * @returns Minimum deposit amount. + */ + minDepositAmount(): Promise } diff --git a/sdk/src/lib/ethereum/bitcoin-depositor.ts b/sdk/src/lib/ethereum/bitcoin-depositor.ts index 4d44853ca..9680c818c 100644 --- a/sdk/src/lib/ethereum/bitcoin-depositor.ts +++ b/sdk/src/lib/ethereum/bitcoin-depositor.ts @@ -130,6 +130,14 @@ class EthereumBitcoinDepositor return { depositOwner, referral } } + + /** + * @see {BitcoinDepositor#minDepositAmount} + * @dev The value in tBTC token precision (1e18 precision). + */ + async minDepositAmount(): Promise { + return this.instance.minDepositAmount() + } } export { EthereumBitcoinDepositor, packRevealDepositParameters } diff --git a/sdk/src/lib/utils/index.ts b/sdk/src/lib/utils/index.ts index 294cd1874..70c6b147c 100644 --- a/sdk/src/lib/utils/index.ts +++ b/sdk/src/lib/utils/index.ts @@ -1,3 +1,4 @@ export * from "./hex" export * from "./ethereum-signer" export * from "./backoff" +export * from "./satoshi-converter" diff --git a/sdk/src/lib/utils/satoshi-converter.ts b/sdk/src/lib/utils/satoshi-converter.ts new file mode 100644 index 000000000..8178a15d4 --- /dev/null +++ b/sdk/src/lib/utils/satoshi-converter.ts @@ -0,0 +1,15 @@ +/** + * Multiplier to convert satoshi to 1e18 precision. + */ +const SATOSHI_MULTIPLIER = 10n ** 10n + +export function toSatoshi(amount: bigint) { + const remainder = amount % SATOSHI_MULTIPLIER + const satoshis = (amount - remainder) / SATOSHI_MULTIPLIER + + return satoshis +} + +export function fromSatoshi(amount: bigint) { + return amount * SATOSHI_MULTIPLIER +} diff --git a/sdk/src/modules/staking/index.ts b/sdk/src/modules/staking/index.ts index 97159b0b2..bf6a69a93 100644 --- a/sdk/src/modules/staking/index.ts +++ b/sdk/src/modules/staking/index.ts @@ -2,6 +2,7 @@ import { ChainIdentifier, TBTC } from "@keep-network/tbtc-v2.ts" import { AcreContracts, DepositorProxy } from "../../lib/contracts" import { ChainEIP712Signer } from "../../lib/eip712-signer" import { StakeInitialization } from "./stake-initialization" +import { toSatoshi } from "../../lib/utils" /** * Module exposing features related to the staking. @@ -78,6 +79,14 @@ class StakingModule { estimatedBitcoinBalance(identifier: ChainIdentifier) { return this.#contracts.stBTC.assetsBalanceOf(identifier) } + + /** + * @returns Minimum deposit amount in 1e8 satoshi precision. + */ + async minDepositAmount() { + const value = await this.#contracts.bitcoinDepositor.minDepositAmount() + return toSatoshi(value) + } } export { StakingModule, StakeInitialization } diff --git a/sdk/test/lib/ethereum/tbtc-depositor.test.ts b/sdk/test/lib/ethereum/tbtc-depositor.test.ts index 07dcf6e98..fed57e00a 100644 --- a/sdk/test/lib/ethereum/tbtc-depositor.test.ts +++ b/sdk/test/lib/ethereum/tbtc-depositor.test.ts @@ -18,10 +18,12 @@ describe("BitcoinDepositor", () => { const vaultAddress = EthereumAddress.from( ethers.Wallet.createRandom().address, ) + const minDepositAmount = BigInt(0.015 * 1e18) const mockedContractInstance = { tbtcVault: jest.fn().mockImplementation(() => vaultAddress.identifierHex), initializeDeposit: jest.fn(), + minDepositAmount: jest.fn().mockImplementation(() => minDepositAmount), } let depositor: EthereumBitcoinDepositor let depositorAddress: EthereumAddress @@ -245,4 +247,12 @@ describe("BitcoinDepositor", () => { }, ) }) + + describe("minDepositAmount", () => { + it("should return minimum deposit amount", async () => { + const result = await depositor.minDepositAmount() + + expect(result).toEqual(minDepositAmount) + }) + }) }) diff --git a/sdk/test/modules/staking.test.ts b/sdk/test/modules/staking.test.ts index 6eaca2ead..e8a91b214 100644 --- a/sdk/test/modules/staking.test.ts +++ b/sdk/test/modules/staking.test.ts @@ -12,6 +12,7 @@ import { import { MockAcreContracts } from "../utils/mock-acre-contracts" import { MockMessageSigner } from "../utils/mock-message-signer" import { MockTBTC } from "../utils/mock-tbtc" +import * as satoshiConverterUtils from "../../src/lib/utils/satoshi-converter" const stakingModuleData: { initializeStake: { @@ -395,4 +396,30 @@ describe("Staking", () => { expect(result).toEqual(expectedResult) }) }) + + describe("minDepositAmount", () => { + describe("should return minimum deposit amount", () => { + const spyOnToSatoshi = jest.spyOn(satoshiConverterUtils, "toSatoshi") + const mockedResult = BigInt(0.015 * 1e18) + // The returned result should be in satoshi precision + const expectedResult = BigInt(0.015 * 1e8) + let result: bigint + + beforeAll(async () => { + contracts.bitcoinDepositor.minDepositAmount = jest + .fn() + .mockResolvedValue(mockedResult) + result = await staking.minDepositAmount() + }) + + it("should convert value to 1e8 satoshi precision", () => { + expect(spyOnToSatoshi).toHaveBeenCalledWith(mockedResult) + expect(spyOnToSatoshi).toHaveReturnedWith(expectedResult) + }) + + it(`should return ${expectedResult}`, () => { + expect(result).toBe(expectedResult) + }) + }) + }) }) diff --git a/sdk/test/utils/mock-acre-contracts.ts b/sdk/test/utils/mock-acre-contracts.ts index dfefb5463..6cdc670c3 100644 --- a/sdk/test/utils/mock-acre-contracts.ts +++ b/sdk/test/utils/mock-acre-contracts.ts @@ -13,6 +13,7 @@ export class MockAcreContracts implements AcreContracts { decodeExtraData: jest.fn(), encodeExtraData: jest.fn(), revealDeposit: jest.fn(), + minDepositAmount: jest.fn(), } as BitcoinDepositor this.stBTC = {