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

Withdraws a ratio of a position's liquidity and collects all its fees; the position stays (a ratio of 1 empties it without burning the NFT).

exchange.IO(k, positionId, ratio)
exchange.IO(k, positionId, ratio, options)

Examples

Withdraw half of the liquidity and sell the returned ETH for USDC.

javascript
function main() { var id = "1381183" // position ID from lp.add or lp.positions var r = exchange.IO("lp.decrease", id, 0.5, {sell: true}) if (!r) { Log("Decrease failed:", GetLastError()) return } var p = r.positions[0] Log("Principal:", p.principalBase, "ETH +", p.principalQuote, "USDC") Log("Fees:", p.feesBase, "ETH +", p.feesQuote, "USDC") Log("Sold:", r.sells) }

Returns

TypeDescription

object / null value

{txHash, positions: [{id, symbol, principalBase, principalQuote, feesBase, feesQuote, receivedBase, receivedQuote}], sells}; see the remarks. Null with an error on failure.

Arguments

NameTypeRequiredDescription

k

string

Yes

Set to lp.decrease to reduce a position.

positionId

string / number

Yes

Position ID.

ratio

number

Yes

Ratio to withdraw, above 0 and at most 1.

options

object

No

{slippage, sell}, both optional: slippage is the price protection (0.01 by default), and sell true sells the returned base token for the quote token at market.

See Also

Remarks

Fields: txHash is the transaction; positions gives, per position, the withdrawn principal principalBase and principalQuote, the collected fees feesBase and feesQuote, and what actually arrived, receivedBase and receivedQuote (principal plus fees); sells lists the market orders selling back to the quote token, [{symbol, qty, txHash}], with {symbol, qty, error} for a sale that failed without affecting the others, and is empty without selling. Amounts are in token units, oriented by the position's pair (the stablecoin is the quote by default).

Compared with exchange.IO("lp.remove", ...): lp.decrease handles one position with price protection and always keeps the NFT; lp.remove takes several positions at once and burns the NFT on a full withdrawal. To collect fees without touching the principal use lp.collect.

In V3 and Slipstream pools the native coin takes part as its wrapped token, so it comes back wrapped (such as WETH); use exchange.IO("unwrap", ...) for the native coin. Aerodrome and Velodrome: a staked position must first be taken out with exchange.IO("lp.unstake") (a basic pool only needs enough unstaked LP tokens in the wallet); basic pools redeem the tokens behind that share of the LP tokens.