Operation - OpenTrove

Key Steps

  1. Chain and Account Validation:

    • Ensures the operation is being performed on a supported chain and that a wallet account is connected.

  2. Set Referrer:

    • Optionally sets a referrer if one is provided, validating the referrer details.

  3. Delegate Approval:

    • Check if the delegate is approved, and if not, perform the approval.

  4. Collateral Checks:

    • Verifies the user has enough ERC20 token balance and allowance to proceed with opening a trove.

  5. Open Trove:

    • Executes the transaction to open a trove, calculating the total debt amount based on the borrowing amount.


This function can be called with appropriate parameters to open a trove. It handles all necessary checks and operations to ensure the transaction is successfully executed.


import { parseUnits, parseEther } from 'viem';
import { walletClient, publicClient, protocolConfig, collateral, wbtcABI, DEBT_TOKEN_DECIMALS } from 'satoshi-sdk';

// Step 1: Parse the borrowing amount and collateral amount
const borrowingAmt = parseUnits('10', DEBT_TOKEN_DECIMALS); // Converts the string '10' into a BigNumber using the specified number of decimals
const totalCollAmt = parseEther('0.1'); // Converts the Ether string '0.1' to its Wei equivalent as a BigNumber

// Step 2: convert BEVM BTC to WBTC
const depositHash = await walletClient.writeContract({
  chain: protocolConfig.CHAIN,
  account: walletClient.account,
  address: collateral.ADDRESS,
  abi: wbtcABI,
  functionName: 'deposit',
  args: [],
  value: totalCollAmt,
await waitTxReceipt({ publicClient }, depositHash); // Wait for the transaction to be confirmed

// Step 3: Open a trove
const receipt = await satoshiClient.Postition.doOpenTrove({

Last updated