LogoLogo
ston.fi/docs
ston.fi/docs
  • User section
    • About
    • STON.fi Protocol
    • Fees
    • Glossary
    • Procedure for Adding Tokens to the Default List
    • Whitepaper
  • Developer section
    • Architecture
    • SDK
      • DEX v1 guide
        • reference
        • swap
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
      • DEX v2 guide
        • swap
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
        • withdraw fee from vault
      • Farm guide
        • stake in farm
        • claim farm rewards
        • unstake from farm
        • destroy farm NFT
      • Transaction sending guide
        • via ton
        • via tonweb
        • via tonconnect
      • v0.5 > v1.0.0 migration guide
      • v0.5 (deprecated)
        • DEX guide
          • swap
          • provide liquidity
          • refund liquidity
          • burn liquidity tokens
        • Farm guide
          • stake in farm
          • claim farm rewards
          • unstake from farm
          • destroy farm NFT
        • Transaction sending guide
          • via ton
          • via tonweb
          • via tonconnect
      • v0.4 > v0.5 migration guide
      • v0.4 (deprecated)
        • perform a swap operation
        • provide liquidity
        • refund liquidity
        • burn liquidity tokens
        • using get methods
        • create a custom router revision
    • API reference v1
      • Router
      • Pool
      • LpAccount
      • LpWallet
    • API reference v2
      • Router
      • Pool
      • LpAccount
      • LpWallet
      • Vault
      • Swap examples
      • LpProvide examples
      • Vault examples
      • Op Codes
    • DEX API
    • OMNISTON
      • Resolvers (How to become a resolver)
      • Swap overview
      • Swap extra
      • Swap grpc
      • React
      • Nodejs
      • Referral fees
    • Quickstart Guides
      • Swap Guide
      • Omniston Guide
  • Help
    • Contact Us
Powered by GitBook
On this page
  • Jetton1/Jetton2 pool
  • Proxy-ton/Jetton pool
Export as PDF
  1. Developer section
  2. SDK
  3. v0.4 (deprecated)

provide liquidity

This section contains SDK example for providing liquidity in DEX

Jetton1/Jetton2 pool

Provide liquidity for a liquidity pool of 2 Jettons.

import TonWeb from 'tonweb';

import { Router, ROUTER_REVISION, ROUTER_REVISION_ADDRESS } from '@ston-fi/sdk';

/**
 * This example shows how to provide liquidity to the pool
 * As a result, you will get LP tokens that can be used to refund your tokens from the pool.
 */
(async () => {
  const WALLET_ADDRESS = ''; // ! replace with your address
  const JETTON0 = 'EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO'; // STON
  const JETTON1 = 'EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA'; // jUSDT

  const provider = new TonWeb.HttpProvider();

  const router = new Router(provider, {
    revision: ROUTER_REVISION.V1,
    address: ROUTER_REVISION_ADDRESS.V1,
  });

  // transaction to provide 0.5 JETTON0 to JETTON0/JETTON1 pool
  const jetton0ProvisionTxParams =
    await router.buildProvideLiquidityJettonTxParams({
      // address of the wallet that holds jetton you want to provide
      userWalletAddress: WALLET_ADDRESS,
      // address of the jetton you want to provide
      sendTokenAddress: JETTON0,
      // amount of the jetton you want to provide
      sendAmount: new TonWeb.utils.BN('500000000'),
      // address of the second jetton you want to provide
      otherTokenAddress: JETTON1,
      // minimal amount of the LP tokens you want to receive as a result of the provision
      minLpOut: new TonWeb.utils.BN(1),
      // query id to identify your transaction in the blockchain (optional)
      queryId: 12345,
    });

  // to execute the transaction you need to send transaction to the blockchain
  // (replace with your wallet implementation, logging is used for demonstration purposes)
  console.log({
    to: jetton0ProvisionTxParams.to,
    amount: jetton0ProvisionTxParams.gasAmount,
    payload: jetton0ProvisionTxParams.payload,
  });

  // transaction to provide 0.2 JETTON1 to to JETTON0/JETTON1 pool
  const jetton1ProvisionTxParams =
    await router.buildProvideLiquidityJettonTxParams({
      // address of the wallet that holds jetton you want to provide
      userWalletAddress: WALLET_ADDRESS,
      // address of the jetton you want to provide
      sendTokenAddress: JETTON1,
      // amount of the jetton you want to provide
      sendAmount: new TonWeb.utils.BN('200000000'),
      // address of the second jetton you want to provide
      otherTokenAddress: JETTON0,
      // minimal amount of the LP tokens you want to receive as a result of the provision
      minLpOut: new TonWeb.utils.BN(1),
      // query id to identify your transaction in the blockchain (optional)
      queryId: 12345,
    });

  // to execute the transaction you need to send transaction to the blockchain
  // (replace with your wallet implementation, logging is used for demonstration purposes)
  console.log({
    to: jetton1ProvisionTxParams.to,
    amount: jetton1ProvisionTxParams.gasAmount,
    payload: jetton1ProvisionTxParams.payload,
  });

  // after execution of both transactions liquidity provision process will be completed
  // and you will receive pool LP tokens
})();

Proxy-ton/Jetton pool

Provide liquidity for a liquidity pool with proxy ton.

import TonWeb from 'tonweb';

import { Router, ROUTER_REVISION, ROUTER_REVISION_ADDRESS } from '@ston-fi/sdk';

/**
 * This example shows how to provide liquidity to the pool where one of the tokens is TON
 * As a result, you will get LP tokens that can be used to refund your tokens from the pool.
 */
(async () => {
  const WALLET_ADDRESS = ''; // ! replace with your address
  const JETTON0 = 'EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO'; // STON
  const PROXY_TON = 'EQCM3B12QK1e4yZSf8GtBRT0aLMNyEsBc_DhVfRRtOEffLez'; // ProxyTON

  const provider = new TonWeb.HttpProvider();

  const router = new Router(provider, {
    revision: ROUTER_REVISION.V1,
    address: ROUTER_REVISION_ADDRESS.V1,
  });

  // Because TON is not a jetton, to be able to swap TON to jetton
  // you need to use special SDK method to build transaction to swap TON to jetton
  // using proxy jetton contract.

  // transaction to provide 1.0 TON to STON/TON pool
  const tonProvisionTxParams =
    await router.buildProvideLiquidityProxyTonTxParams({
      // address of the wallet that holds jetton you want to provide
      userWalletAddress: WALLET_ADDRESS,
      proxyTonAddress: PROXY_TON,
      // amount of TON you want to provide
      sendAmount: new TonWeb.utils.BN('1000000000'),
      // address of the second jetton you want to provide
      otherTokenAddress: JETTON0,
      // minimal amount of the LP tokens you want to receive as a result of the provision
      minLpOut: new TonWeb.utils.BN(1),
      // query id to identify your transaction in the blockchain (optional)
      queryId: 12345,
    });

  // to execute the transaction you need to send transaction to the blockchain
  // (replace with your wallet implementation, logging is used for demonstration purposes)
  console.log({
    to: tonProvisionTxParams.to,
    amount: tonProvisionTxParams.gasAmount,
    payload: tonProvisionTxParams.payload,
  });

  // transaction to provide 0.5 STON to STON/TON pool
  const jettonProvisionTxParams =
    await router.buildProvideLiquidityJettonTxParams({
      // address of the wallet that holds jetton you want to provide
      userWalletAddress: WALLET_ADDRESS,
      // address of the jetton you want to provide
      sendTokenAddress: JETTON0,
      // amount of the jetton you want to provide
      sendAmount: new TonWeb.utils.BN('500000000'),
      // address of the second jetton you want to provide
      otherTokenAddress: PROXY_TON,
      // minimal amount of the LP tokens you want to receive as a result of the provision
      minLpOut: new TonWeb.utils.BN(1),
      // query id to identify your transaction in the blockchain (optional)
      queryId: 12345,
    });

  // to execute the transaction you need to send transaction to the blockchain
  // (replace with your wallet implementation, logging is used for demonstration purposes)
  console.log({
    to: jettonProvisionTxParams.to,
    amount: jettonProvisionTxParams.gasAmount,
    payload: jettonProvisionTxParams.payload,
  });

  // after execution of both transactions liquidity provision process will be completed
  // and you will receive pool LP tokens
})();
Previousperform a swap operationNextrefund liquidity

Last updated 2 months ago