Skip to content

Commit

Permalink
Add min stake amount to the staking module
Browse files Browse the repository at this point in the history
The minimum amount of BTC deposit should be taken from  `BitcoinDepositor` contract. The amount is in tBTC token precision before export this value in SDK has to be converted to satoshi precision.
  • Loading branch information
kkosiorowska committed Apr 9, 2024
1 parent d7884f8 commit 4244f92
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/src/lib/contracts/bitcoin-depositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ export interface BitcoinDepositor extends DepositorProxy {
* @param extraData Encoded extra data.
*/
decodeExtraData(extraData: string): DecodedExtraData

/**
* @returns Minimum stake amount.
*/
minStake(): Promise<bigint>
}
8 changes: 8 additions & 0 deletions sdk/src/lib/ethereum/bitcoin-depositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ class EthereumBitcoinDepositor

return { staker, referral }
}

/**
* @see {BitcoinDepositor#minStake}
* @dev The value in tBTC token precision (1e18 precision).
*/
async minStake(): Promise<bigint> {
return this.instance.minStake()
}
}

export { EthereumBitcoinDepositor, packRevealDepositParameters }
9 changes: 9 additions & 0 deletions sdk/src/modules/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -78,6 +79,14 @@ class StakingModule {
estimatedBitcoinBalance(identifier: ChainIdentifier) {
return this.#contracts.stBTC.assetsBalanceOf(identifier)
}

/**
* @returns Minimum stake amount in 1e8 satoshi precision.
*/
async minStakeAmount() {
const value = await this.#contracts.bitcoinDepositor.minStake()
return toSatoshi(value)
}
}

export { StakingModule, StakeInitialization }
1 change: 1 addition & 0 deletions sdk/test/utils/mock-acre-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class MockAcreContracts implements AcreContracts {
decodeExtraData: jest.fn(),
encodeExtraData: jest.fn(),
revealDeposit: jest.fn(),
minStake: jest.fn(),
} as BitcoinDepositor

this.stBTC = {
Expand Down

0 comments on commit 4244f92

Please sign in to comment.