Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Withdraw liquidity

Burn issued LP tokens and release the underlying pool assets.

This operation withdraws assets by burning issued LP tokens; the example burns the full balance. For tokens still pending in an LP account, use Recover pending liquidity. Use a wallet owning the LP tokens and matching DEX v2 router metadata; see Setup and environments.

Mainnet workflow

  1. Locate the target pool via the STON.fi API (for example with getPoolsByAssetPair or getPool).

  2. Fetch the router metadata with getRouter(pool.routerAddress).

  3. Build the pool and LP wallet contracts dynamically with dexFactory and TonClient.

  4. Read the LP balance and generate the burn transaction parameters.

import { Client, dexFactory } from "@ston-fi/sdk";
import { StonApiClient } from "@ston-fi/api";

const tonClient = new Client({
  endpoint: "https://toncenter.com/api/v2/jsonRPC",
  apiKey: process.env.TON_API_KEY, // optional but recommended for higher rate limits
});

const apiClient = new StonApiClient();

// Discover the pool you want to exit (replace addresses with your assets)
const [poolInfo] = await apiClient.getPoolsByAssetPair({
  asset0Address: "<token A address or 'ton'>",
  asset1Address: "<token B address>",
});

if (!poolInfo) {
  throw new Error("Liquidity pool not found for the provided asset pair");
}

// Load router metadata and initialize contracts
const routerMetadata = await apiClient.getRouter(poolInfo.routerAddress);
const dexContracts = dexFactory(routerMetadata);

const pool = tonClient.open(
  dexContracts.Pool.create(poolInfo.address),
);

if (!("getPoolType" in pool)) {
  throw new Error("Use the DEX v1 burn guide for a v1 pool");
}

// Fetch the LP wallet owned by the user and read the balance
const lpWallet = tonClient.open(
  await pool.getJettonWallet({ ownerAddress: "<your wallet address>" }),
);

const { balance } = await lpWallet.getWalletData();

const burnTxParams = await pool.getBurnTxParams({
  amount: balance,
  userWalletAddress: "<your wallet address>",
  queryId: 12345,
});

Send the resulting transaction parameters using your preferred wallet integration (see the transaction sending guide).

Tip: If one side of the pool is TON, the API already exposes the correct routerMetadata.ptonMasterAddress. You do not need to hardcode the proxy TON contract. dexFactory picks the right implementation for you.

Testnet burn (manual setup)

To burn LP tokens on TON testnet, configure testnet contracts and use a wallet that holds LP tokens from the selected pool. The api.ston.fi endpoint serves mainnet data.

This manual approach is strictly for testing. Switch back to the API-driven workflow for any mainnet-facing integration.

Check the result

After the burn is processed, inspect the LP wallet balance and the returned underlying asset transfers. A broadcast alone is not a completed withdrawal. Pending LP-account balances are separate; use Recover pending liquidity for those.

Use the REST transaction action tree to inspect the submitted operation.

Last updated