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

Automatically selects an LP pool by rule: chooses the pool with the highest 24h trading volume among pools with sufficient liquidity, or the pool with a specified fee tier.

exchange.IO(k, token, budget)
exchange.IO(k, token, budget, options)

Examples

Select an ETH/USDC pool, then separately select one among V4 pools.

javascript
function main() { var p = exchange.IO("lp.select", "ETH", 1000, {quote: "USDC"}) if (!p) { Log("Pool selection failed:", GetLastError()) return } Log("Selected:", p.protocol, p.id, "Fee rate:", p.feeRate, "Reason:", p.reason) // Select only among V4 pools (use infinity for PancakeSwap, slipstream etc. for Aerodrome and Velodrome) var v4 = exchange.IO("lp.select", "ETH", 1000, {quote: "USDC", protocol: "v4"}) Log("V4 pool:", v4 ? v4.id : GetLastError()) }

Returns

TypeDescription

object / null value

The selected pool: one entry from the lp.pools result, plus a reason field (why it was selected). Returns null and reports an error when no pool has liquidity, when the specified fee tier does not exist (with exact set to true), and in similar cases.

Arguments

NameTypeRequiredDescription

k

string

Yes

Fixed as lp.select, used to select a pool.

token

string

Yes

Token name or contract address, e.g. ETH.

budget

number

Yes

Budget, denominated in the quote currency, used to set the liquidity threshold: the pool's TVL must be at least the greater of 5,000 USD and the budget.

options

object

No

Pool selection criteria {quote, fee, exact, protocol, tickSpacing}. Every field is optional; see the remarks for details.

See Also

Remarks

Fields of options:

KeyDescription
quoteQuote currency, e.g. USDC; if omitted, pools pairing the token with the chain's wrapped native token, USDC or USDT are all compared
feePreferred fee tier, in millionths, e.g. 500
exactWhen true, only the fee tier given by fee is used
protocolPool type, a string or an array: v3 or v4 for Uniswap; v3 or infinity for PancakeSwap; slipstream, slipstream2, volatile or stable for Aerodrome and Velodrome
tickSpacingOnly selects pools with this tick spacing (mainly for Slipstream, whose pools are distinguished by tick spacing)

Selection rules: first, empty pools and pools that do not match protocol or tickSpacing are excluded. If fee is specified, the pool with that fee tier is selected if it meets the liquidity threshold (reason is fee tier 500 requested); with exact set to true it is selected even if it does not meet the threshold; if no pool with that fee tier exists, an error is reported. Otherwise, among pools whose TVL is at least the greater of 5,000 USD and the budget, the one with the highest 24h trading volume is selected (largest 24h volume among pools with enough liquidity); if there is no volume data, the pool with the highest TVL is selected. If no pool meets the threshold, the pool with the highest TVL is selected and this is stated in reason.

The candidate pools are the pools listed by lp.pools (see the lp.pools page for where Uniswap V4 pools come from and when some may be missing). To use a pool not on that list, pass its PoolId directly as the pool of lp.plan.

When exchange.IO("lp.plan", ...) is called without pool, it selects a pool by the same rules (fee and tickSpacing are taken from the plan parameters; for Aerodrome and Velodrome, if range is specified, only Slipstream pools are considered). To open a position in a V4/Infinity CL pool on Uniswap or PancakeSwap, first select the pool with protocol, then pass its id as the plan's pool.