River
Satoshi Protocol V1
Satoshi Protocol V1
  • Intro
    • πŸ”οΈIntroduction
    • πŸ§‘β€πŸš€Mission
    • ❔FAQs
  • Mechanism
    • πŸ—ΊοΈOverview
    • 🏦Minting
    • πŸ›‘οΈStability Pool and Liquidations
    • βš–οΈRedemption & Price Stability
    • 🏧Nexus Yield Module (NYM)
    • ♻️Swap
    • 🌎MultiChain
    • 🌑️Recovery Mode
    • πŸ’°Revenue Structure
    • ⚑Risk Management
  • outro
    • πŸ”—Official Links
    • βš–οΈOracle
    • πŸ“”Deployed Contracts
    • πŸ”Audit Reports
  • How to use
    • πŸ—οΈCreate Position
    • πŸͺ£Deposit into Stability Pool
  • SDK
    • Introduction
    • Get Started
    • Position
      • Operation - OpenTrove
      • Operation - Deposit
      • Operation - Mint
      • Operation - Withdraw
      • Operation - Repay
      • Operation - Redemption
    • Stability Pool
      • Operation - Deposit
      • Operation - Withdraw
      • Operation - Claim rewards
    • Nexus Yield Module
      • Operation - Swap In
      • Operation - Swap Out
      • Operation - Withdraw
Powered by GitBook
On this page
  • Key Steps
  • Usage
  • Example
  1. SDK
  2. Position

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 minting amount.

Usage

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.

Example

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

// Step 1: Parse the minting amount and collateral amount
const mintingAmt = 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({
  collateral,
  mintingAmt,
  totalCollAmt,
});

PreviousPositionNextOperation - Deposit

Last updated 9 months ago