Refund Liquidity (v2)
Refund liquidity on STON.fi v2 - handle failed operations with vault-based architecture
Mainnet workflow
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,
});Deriving the LP account address
Testnet refund (manual setup)
Last updated