Refund Liquidity (v2)

Refund liquidity on STON.fi v2 - handle failed operations with vault-based architecture

Refund tokens that were sent to an LP account but were not added to the pool.

The production-ready approach is API-driven. Use the STON.fi API to resolve router metadata, construct contracts via dexFactory, and let the SDK derive the correct on-chain calls. This avoids hardcoding addresses and remains forward-compatible with router updates.

Mainnet workflow

  1. Determine the router and LP account that needs the refund. You can fetch them from the simulation result, from getPoolsByAssetPair, or from getWalletLpAccounts on the STON.fi API.

  2. Fetch the router metadata with getRouter(routerAddress) and build the contract instances dynamically.

  3. Call getRefundTxParams on the LP account to obtain the message you need to send on-chain.

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,
});

const apiClient = new StonApiClient();

const routerMetadata = await apiClient.getRouter("<router address>");
const dexContracts = dexFactory(routerMetadata);

const lpAccount = tonClient.open(
  dexContracts.LpAccount.create("<lp account address>"),
);

// Optional: inspect the pending balances before refunding
const lpAccountData = await lpAccount.getLpAccountData();
console.log({
  routerAddress: lpAccountData.routerAddress?.toString(),
  poolAddress: lpAccountData.poolAddress?.toString(),
  tokenABalance: lpAccountData.amount0.toString(),
  tokenBBalance: lpAccountData.amount1.toString(),
});

const refundTxParams = await lpAccount.getRefundTxParams({
  queryId: 12345,
});

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

Deriving the LP account address

If you only know the assets and the user wallet:

You can then pass lpAccountAddress into the main workflow above.

TON pools: When a pool includes TON, the router metadata exposes ptonMasterAddress. dexFactory automatically wires the correct pool/LP implementations—no manual proxy setup is required.

Testnet refund (manual setup)

Only rely on testnet for experimentation. Because api.ston.fi is mainnet-only, you must hardcode contract addresses, mint or source the testnet jettons (TesREED/TestBlue), and create funded pools before you can refund LP accounts.

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

Last updated