Decrease Liquidity

This endpoint provides functionality for decreasing liquidity from existing Algebra positions. It supports both partial and full liquidity removal.

Using the SDK

import api, { IConnection } from "codemelt-retro-api-sdk"
import { ChangeLiquidityDTO } from 'codemelt-retro-api-sdk/structures/ChangeLiquidityDTO'

const connection: IConnection = {
  host: '<enter your host url here>',
  headers: {
    'x-api-key': '<enter your api key here>'
  }
}

const networkName = 'Zeta Mainnet'
const input: ChangeLiquidityDTO = {
  tickLower: Number(position.tickRange.lower),
  tickUpper: Number(position.tickRange.upper),
  networkName: networkName,
  tokenId: Number(position.tokenId),
  amountA: Number(firstTokenAmount),
  amountB: Number(secondTokenAmount),
  tokenAId: tokenA.id,
  tokenBId: tokenB.id,
  liquidity: position.liquidity,
  recipient: signer.address,
  // Percentage of liquidity to remove (0-100)
  //Percentage 100 will also burn the position
  liquidityPercent: 50
}

const resp = await api.functional.api.algebra.interactions.decrease.decreaseLiquidity(
  connection,
  input
)

Security Considerations

  1. Slippage Protection

    • Default slippage tolerance for all pools is 0.5%
  2. Position Validation

    • Position must exist and belong to the recipient
    • Position must have sufficient liquidity for the requested decrease
    • Minimum remaining liquidity requirements may apply
    • Unclaimed fees are automatically collected during decrease

Common Errors and Solutions

  1. Insufficient Liquidity
  • Most likely caused by stale tick data
  1. Position Verification
const resp = await api.algebra.pool.manual.getUserPools(
  connection,
  signer.address,
  networkName
)

const position = resp.data.data.positions.find(
  elm => elm.tokenId === desiredTokenId
)

if (!position) {
  throw new Error('Position not found or not owned by user')
}