exchange.IO("lp.remove", ...)
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
| Type | Description |
object / null value |
|
Arguments
| Name | Type | Required | Description |
k | string | Yes | Set to |
positionIds | string / number / array | Yes | Position IDs: one ID (string or number) or an array of IDs, such as |
ratio | number | No | Ratio to withdraw, above 0 and at most 1; 1 by default (everything, burning the NFT). |
sell | bool | No |
|
See Also
Uniswap / PancakeSwap Aerodrome / Velodrome exchange.IO exchange.IO("lp.decrease") exchange.IO("lp.collect") exchange.IO("lp.positions") exchange.IO("lp.add")
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.