Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Build all add-liquidity transactions of a plan and run them with the node's simulation, without signing or broadcasting.

exchange.IO(k, plan)
exchange.IO(k, plan, payer)

Examples

  • Plan, simulate, and add only when the simulation passes.

    javascript
    function main() { var plan = exchange.IO("lp.plan", {symbol: "SOL_USDC", budget: 100, range: {pct: [-5, 5]}}) if (!plan) { Log("Plan failed:", GetLastError()) return } var sim = exchange.IO("lp.simulate", plan) if (!sim) { Log("Simulation error:", GetLastError()) return } sim.positions.forEach(function(p) { Log(p.ok ? "ok" : "failed", p.amountBase, "SOL", p.amountQuote, "USDC", "compute units", p.unitsConsumed, p.error || "") }) Log("All passed:", sim.ok, sim.note) }
  • Check a plan with another wallet as payer (read-only).

    javascript
    var PAYER = "" // a wallet address holding SOL and USDC function main() { if (!PAYER) { Log("Set PAYER to a wallet address first") return } var sim = exchange.IO("lp.simulate", {symbol: "SOL_USDC", budget: 200, range: {pct: [-3, 3]}, shape: "spot", protocol: "meteora"}, PAYER) if (!sim) { Log("Simulation error:", GetLastError()) return } Log(sim.protocol, sim.pool, "payer", sim.payer, "all passed", sim.ok) sim.positions.forEach(function(p) { Log("bins", p.lowerBinId, p.upperBinId, p.ok, p.unitsConsumed, p.txBytes, p.error || "") }) }

Returns

TypeDescription

object / null value

{pool, protocol, payer, ok, positions, swapNeeded, shortfall, note}: ok tells whether all add transactions simulated successfully and positions holds the result of each transaction, fields in the remarks. A failed simulation is not an error (check ok and each row's error); a null value is returned when planning or a request fails.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to lp.simulate to simulate adding liquidity.

plan

object

Yes

A plan returned by lp.plan, or plan parameters (the params of lp.plan).

payer

string

No

Another wallet address, to simulate with it as payer and position owner (read-only, its private key is not needed), for checking a plan when your own wallet is empty.

See Also

Remarks

What is simulated
  • The plan is first re-planned from its params at the latest pool price and the payer's balances, then one complete add transaction is built per position and run with the node's simulateTransaction (no signature check).
  • No swap: when the plan needs a swap first (swap not null) the post-swap amounts are simulated and swapNeeded is true; with a swap or a shortfall, note warns that the payer must hold the planned amounts for the simulation to pass, otherwise note is an empty string.
  • Transactions by protocol: DLMM creates bin arrays, the position account and ATAs, wraps SOL, adds liquidity and unwraps; Raydium creates ATAs, wraps SOL, runs open_position_with_token22_nft (creating the position NFT and position account; missing TickArrays are created by the program) and unwraps; Orca creates ATAs, wraps SOL, creates dynamic tick arrays (initialize_dynamic_tick_array), opens the position (open_position_with_token_extensions), adds liquidity by token maxima (increase_liquidity_by_token_amounts_v2) and unwraps.

Each item of positions
FieldDescription
positionThe position account (DLMM) or position NFT mint (Raydium, Orca) generated for this simulation; lp.add generates another
lowerBinId, upperBinIdThe range (tickLower and tickUpper on Raydium and Orca)
amountBase, amountQuoteThe two token amounts this transaction deposits
ok, err, errorSuccess, the node's raw error and the failure reason (DLMM, Raydium CLMM and Orca Whirlpool error codes with their names)
logsThe tail of the program logs
unitsConsumed, txBytesCompute units consumed and transaction size in bytes

Common failures: AccountNotFound means the payer has no SOL (a new or empty wallet); a balance below the planned amounts makes the program report insufficient funds. Before funding your own wallet, set payer to a public wallet holding both tokens to check the plan itself.