Recover pending liquidity
Refund assets held in an LP account before LP issuance.
This operation returns tokens held in an LP account that have not been added to the pool. It does not burn an issued LP position; use Withdraw liquidity for that. Supply the actual LP account and owner wallet for the selected DEX v2 router; see Setup and environments.
Mainnet workflow
Determine the router and LP account that needs the refund. You can fetch them from the simulation result, from
getPoolsByAssetPair, or fromgetWalletLpAccountson the STON.fi API.Fetch the router metadata with
getRouter(routerAddress)and build the contract instances dynamically.Call
getRefundTxParamson 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({
userAddress: lpAccountData.userAddress.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.dexFactoryautomatically wires the correct pool/LP implementations. No manual proxy setup is required.
Testnet refund (manual setup)
To refund a testnet LP account, configure testnet contracts and use the wallet that owns the pending deposit. 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 processing, read the LP account again and inspect return transfers to its owner. Recovery changes pending balances; it does not represent withdrawing already minted LP tokens. Use Withdraw liquidity for an issued position.
Use the REST transaction action tree to inspect the submitted operation.
Last updated