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 positions' liquidity and collects their fees, burning the position NFT on a full withdrawal; several positions go into one transaction.

exchange.IO(k, positionIds)
exchange.IO(k, positionIds, ratio)
exchange.IO(k, positionIds, ratio, sell)

Examples

Withdraw every position and sell the returned ETH for USDC.

javascript
function main() { var ids = exchange.IO("lp.positions", "ETH_USDC").filter(function (p) { return !p.closed }).map(function (p) { return p.id }) if (ids.length == 0) { Log("No positions") return } var r = exchange.IO("lp.remove", ids, 1, true) if (!r) { Log("Withdrawal failed:", GetLastError()) return } r.positions.forEach(function (p) { Log(p.id, "received:", p.receivedBase, "ETH +", p.receivedQuote, "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.remove to withdraw liquidity.

positionIds

string / number / array

Yes

Position IDs: one ID (string or number) or an array of IDs, such as "1381183" or ["v4:123", "456"]; several IDs may also be written as the leading arguments.

ratio

number

No

Ratio to withdraw, above 0 and at most 1; 1 by default (everything, burning the NFT).

sell

bool

No

true sells the returned base token for the quote token at market; false by default.

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).

Several positions share one transaction where possible; when several transactions are needed (such as V3 and V4/Infinity CL positions together, which have different PositionManagers), txHash is the last one and txHashes lists them all. A full withdrawal collects the fees and burns the NFT in the same transaction, after which lp.positions no longer lists the position.

Arguments: the first number between 0 and 1 after the IDs is ratio and a boolean is sell. A V3 position ID written as a number (such as 1) would be read as the ratio, so write IDs as strings or an array, such as exchange.IO("lp.remove", ["1381183", "1381190"], 1, true).

Aerodrome and Velodrome: staked positions are first taken out of the gauge (claiming the rewards, see exchange.IO("lp.unstake")); a full withdrawal from a basic pool also sends a claimFees transaction for the fees.