Operation - Borrow

Key Steps

  1. Parse Borrowing Amount:

    • Convert the desired borrowing amount into the correct unit using the parseUnits function. This function requires specifying the number of decimals to use, which aligns with the debt token's specifications (usually 18 decimals, like Ethereum).

  2. Execute Borrowing Transaction:

    • Call the doBorrow function with the necessary parameters, including the public and wallet clients, protocol configuration, collateral information, and the parsed borrowing amount.

Usage

This function is typically used when a user needs to:

  • Increase Leverage: Borrow additional stablecoins to leverage their investment position further without selling existing collateral.

  • Manage Financial Needs: Access additional funds for other investment opportunities or personal expenditures without liquidating their assets.

Example

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

const DEBT_TOKEN_DECIMALS = 18; // Standard decimals for Ethereum-based tokens

async function increaseBorrowing() {
  // Step 1: Define the amount to borrow
  const addBorrowingAmt = parseUnits('5', DEBT_TOKEN_DECIMALS);  // Borrow an additional 5 SAT stablecoins

  // Step 2: Execute the borrowing transaction
  const receipt = await satoshiClient.Postition.doBorrow({
    publicClient,
    walletClient,
    protocolConfig,
    collateral,
    addBorrowingAmt,
  });

  console.log('Borrowing additional stablecoins successful:', receipt);
}

increaseBorrowing();

Last updated