Add to New Position

Create a position NFT and add liquidity in a single transaction. This is the most efficient way to start providing liquidity in DLMM pools.

Prerequisites

  • Connected wallet with both tokens

  • Selected distribution strategy (SPOT, CURVE, etc.)

  • Calculated token amounts needed

  • Sufficient gas for transaction

Basic Usage

const pair = await sdk.Pair.getPair(pairAddress);

// Create position and add liquidity together
const tx = await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX: 1000000000n,  // 1 token X
  amountY: 2000000000n,  // 2 token Y
  deltaIds: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],
  distributionX: [0, 0, 0, 0, 0, 50, 50, 0, 0, 0, 0],
  distributionY: [0, 0, 0, 0, 0, 50, 50, 0, 0, 0, 0]
});

await sdk.fullClient.signAndExecuteTransaction({
  transaction: tx,
  signer: keypair
});

Method Parameters

interface AddLiquidityParams {
  amountX: bigint;           // Max token X to deposit
  amountY: bigint;           // Max token Y to deposit
  deltaIds: number[];        // Relative bin IDs from active
  distributionX: number[];   // X distribution (sums to 100)
  distributionY: number[];   // Y distribution (sums to 100)
}

Quick Examples

Concentrated Liquidity (±5 bins)

await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX: 1000000n,
  amountY: 1000000n,
  deltaIds: [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],
  distributionX: [0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0],
  distributionY: [0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0]
});

Wide Range (±20 bins)

const binCount = 41; // -20 to +20
const deltaIds = Array.from({length: binCount}, (_, i) => i - 20);
const uniformDist = Array(binCount).fill(100 / binCount);

await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX: 10000000n,
  amountY: 10000000n,
  deltaIds,
  distributionX: uniformDist,
  distributionY: uniformDist
});

Using Distribution Helpers

import { DistributionUtils } from '@ferra/dlmm-sdk';

// SPOT distribution
const spotParams = DistributionUtils.createParams(
  DistributionUtils.SPOT,
  {
    activeId: pair.parameters.active_id,
    binRange: [activeId - 10, activeId + 10],
    parsedAmounts: [amountX, amountY]
  }
);

await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX,
  amountY,
  ...spotParams
});

What Happens

  • Creates new position NFT

  • Deposits tokens into selected bins

  • Transfers position NFT to your wallet

  • Returns transaction hash

Common Patterns

Add Around Current Price

const activeId = pair.parameters.active_id;
const range = 10; // ±10 bins

await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX: amount,
  amountY: amount,
  deltaIds: Array.from({length: range * 2 + 1}, (_, i) => i - range),
  distributionX: [/* your distribution */],
  distributionY: [/* your distribution */]
});

Single Bin Liquidity

// Add to active bin only
await sdk.Pair.openPositionAndAddLiquidity(pair, {
  amountX: amount,
  amountY: amount,
  deltaIds: [0],  // Just active bin
  distributionX: [100],
  distributionY: [100]
});

Last updated