Torch DEX
WebsiteSwap
  • Overview
  • Terms of Use
  • Getting Started
    • Introduction
    • Challenges on TON
    • Solution for TON
    • Architecture
      • Concept
      • Core Components
        • Factory
        • Vault
        • Pool
        • LP Account
        • Oracle
      • Comparison
      • Interoperability
      • Meesage Flows
        • Deposit
        • Swap
        • Withdraw
        • Cross-Pool Operations
  • Developer Guide
    • DEX SDK Guide
      • Setup
      • Perform Swap
      • Deposit Liquidity
      • Withdraw Liquidity
      • How to send transaction
        • Mnemonic (Node JS)
        • TonConnect (React)
      • Deployments
  • USER Guide
    • Getting Started
  • Protocol
    • Audits
    • Tokenomics
  • Other
    • Brand Kit
    • Contacts
    • Achievements
  • FAQ
    • How to get Transaction hash by Message hash
    • React (Vite) - Buffer Issues
Powered by GitBook
On this page
  • Example: Depositing Assets into a Pool
  • 1. Initialize SDK
  • 2. Define Deposit Parameters
  • 3. Preview the Deposit
  • 4. Execute the Deposit
  1. Developer Guide
  2. DEX SDK Guide

Deposit Liquidity

This guide demonstrates how to perform a deposit into a liquidity pool using the Torch Finance SDK.

Example: Depositing Assets into a Pool

1. Initialize SDK

First, import the required modules and initialize the Torch Finance SDK:

import { TorchSDK, generateQueryId, DepositParams, toUnit } from '@torch-finance/sdk';
import { Asset } from '@torch-finance/core';

const sdk = new TorchSDK();

2. Define Deposit Parameters

Configure the parameters for depositing assets into a pool. For this example, we will

  1. Deposit 0.1 TON, 0.1 tsTON, and 0.1 stTON into a pool.

  2. Additionally, a subsequent 0.1 hTON deposit into a MetaPool will be prepared.

const queryId = await generateQueryId()

// Define assets
const TON_ASSET = Asset.ton();
const TSTON_ASSET = Asset.jetton("EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav");
const STTON_ASSET = Asset.jetton("EQDNhy-nxYFgUqzfUzImBEP67JqsyMIcyk2S5_RwNNEYku0k");
const HTON_ASSET = Asset.jetton("EQDPdq8xjAhytYqfGSX8KcFWIReCufsB9Wdg0pLlYSO_h76w");

const LSDPoolAddress = "EQD_pool_address_example";
const MetaPoolAddress = "EQD_meta_pool_address_example";

// Define deposit parameters
const depositParams: DepositParams = {
    queryId,
    pool: BasePoolAddress,
    depositAmounts: [
      {
        asset: TSTON_ASSET,
        value: toUnit('0.0000001', 9), // 0.0000001 TSTON in TriTON pool
      },
      {
        asset: STTON_ASSET,
        value: toUnit('0.0000001', 9), // 0.0000001 STTON in TriTON pool
      },
      {
        asset: TON_ASSET,
        value: toUnit('0.0000001', 9), // 0.0000001 TON in TriTON pool
      },
    ],
    nextDeposit: {
      pool: MetaPoolAddress,
      depositAmounts: { asset: HTON_ASSET, value: toUnit('0.0000001', 9) }, // 0.0000001 HTON in Meta USD pool
    },
    slippageTolerance: 0.01, // 1%
  };

3. Preview the Deposit

Simulate the deposit to preview important details such as the LP token master address and the estimated LP token amount.

// Simulate the deposit payload
const { result, getDepositPayload } = await sdk.simulateDeposit(depositParams);

console.log(`LP Tokens Out: ${result.lpTokenOut.toString()}`);
console.log(`LP Total Supply After: ${result.lpTotalSupplyAfter.toString()}`);
console.log(`Min LP Tokens Out: ${result.minLpTokenOut?.toString() || '(You did not specify slippage tolerance)'}`); // prettier-ignore

console.log(`Get ${lpTokenAmount} LP from ${lpTokenMaster}`);

Example Output

LP Tokens Out: 12345678901234567890
LP Total Supply After: 98765432109876543210
Min LP Tokens Out: 12000000000000000000

4. Execute the Deposit

Send the deposit transaction and retrieve the msgHash to track its status.

4.1 Execute Swap with Simulation Result

// Get BoC and send transaction
const sender = wallet.address;
const senderArgs = await sdk.getDepositPayload(sender, depositParams);

const msgHash = await send(senderArgs);
console.log(`Transaction sent with msghash: ${msgHash}`);

4.2 Execute Swap Directly with Swap Params

const sender = wallet.address;
const senderArgs = await sdk.getDepositPayload(sender, {
    blockNumber: blockNumber, // Optional, but it will speed up a lot if you provided the latest blockNumber here
  });
const msgHash = await send(senderArgs); 
console.log(`Transaction sent with msghash: ${msgHash}`)

PreviousPerform SwapNextWithdraw Liquidity

Last updated 3 months ago