Add liquidity
Simulate a deposit, preserve its message legs, and check issued LP tokens.
Deposit assets into a STON.fi pool to receive LP tokens representing your share. This guide uses DEX v2 contracts and SDK 2.x. See Setup and environments for client setup and router selection.
Mainnet-first workflow
STON.fi’s REST API (api.ston.fi) serves mainnet data. For a mainnet liquidity deposit:
Simulate the provision to obtain routing metadata (pool address, token amounts, and the full router object).
Feed
simulationResult.routerdirectly intodexFactory()to build contracts dynamically.Generate the liquidity provision transaction parameters with the router helpers.
import { Client, dexFactory, toUnits } from "@ston-fi/sdk";
import { StonApiClient } from "@ston-fi/api";
const tonClient = new Client({
endpoint: "https://toncenter.com/api/v2/jsonRPC",
});
const apiClient = new StonApiClient();
const userWalletAddress = "<your wallet address>";
const tokenA = await apiClient.getAsset("<asset A address or 'ton'>");
const tokenB = await apiClient.getAsset("<asset B address>");
const amountA = "10"; // human-readable amount (e.g. "10")
const amountB = "5"; // human-readable amount for the second token
const slippageTolerance = "0.001";
// Discover existing pools for the pair. If none are found we are creating a new pool.
const [poolInfo] = await apiClient.getPoolsByAssetPair({
asset0Address: tokenA.contractAddress,
asset1Address: tokenB.contractAddress,
});
const baseInput = {
tokenA: tokenA.contractAddress,
tokenB: tokenB.contractAddress,
slippageTolerance,
walletAddress: userWalletAddress,
};
const simulationInput: Parameters<StonApiClient["simulateLiquidityProvision"]>[0] =
poolInfo
? {
...baseInput,
provisionType: "Balanced",
poolAddress: poolInfo.address,
// Supply one side; the API calculates the matching amount.
tokenAUnits: toUnits(amountA, tokenA.decimals).toString(),
}
: {
...baseInput,
provisionType: "Initial",
tokenAUnits: toUnits(amountA, tokenA.decimals).toString(),
tokenBUnits: toUnits(amountB, tokenB.decimals).toString(),
};
const simulationResult = await apiClient.simulateLiquidityProvision(simulationInput);
// 2. Router metadata ships with the simulation result
const { router: routerInfo } = simulationResult;
const dexContracts = dexFactory(routerInfo);
// 3. Open the router contract
const router = tonClient.open(
dexContracts.Router.create(routerInfo.address)
);
// Optional helper when TON is part of the provision
const proxyTon = dexContracts.pTON.create(routerInfo.ptonMasterAddress);The simulationResult object contains provisionType, tokenA, tokenB, tokenAUnits, tokenBUnits, minLpUnits, and router. Reuse those values when building the actual provision transaction to ensure the signed payload matches the simulated path.
Interpreting simulation results
Initial: no pool exists yet. Provide positive amounts for both assets; the router will deploy the pool and mint the first LP tokens.
Balanced: an existing pool is topped up at the current ratio. Provide one token amount (the other is computed by the API). The result always contains two positive
token*Unitsvalues.Arbitrary: to use this mode, replace the existing-pool input above with
provisionType: "Arbitrary", thepoolAddress, and bothtokenAUnitsandtokenBUnits. To perform a single-sided deposit, set one of the amounts to"0"; build the corresponding single-sided v2 provision message. Pending deposits belong to LP accounts, not referral-fee Vaults.
Generating transaction messages
Define the TON address and convert each non-zero asset amount in the simulation result into a message. Single-sided Arbitrary provisions use one non-zero amount.
Send the resulting txParams array in a single transaction. See our transaction sending guide for wallet-specific examples.
Testnet provisions (manual setup)
To add liquidity on TON testnet, configure testnet contracts and obtain the required testnet jettons. The api.ston.fi endpoint serves mainnet data.
To mirror the examples above on testnet, testers often use TesREED/TestBlue and run both single-sided and balanced deposits.
This manual approach is strictly for testing. Switch back to the API-driven workflow for anything mainnet-facing.
Check the result
An implementation reference is available in the liquidity demo and SDK example application.
Inspect the submitted operation and the wallet’s LP position. A completed deposit mints LP tokens. To reclaim tokens remaining in the LP account, use Recover pending liquidity. A two-sided deposit requires both non-empty messages; verify that the wallet can send both before submission.
Use the REST transaction action tree to inspect the submitted operation.
Last updated