Skip to content

Infinity SDK

TypeScript SDK for PancakeSwap Infinity. Supports both concentrated liquidity (CL) pools and Liquidity Book (Bin) pools. Provides pool math, position management, and calldata builders for the Infinity contracts.

Installation

npm install @pancakeswap/infinity-sdk

Quick start

import {
  CLPool,
  CLPositionManager,
  PoolKey,
} from '@pancakeswap/infinity-sdk'
import { Token, CurrencyAmount } from '@pancakeswap/swap-sdk-core'
import { ChainId } from '@pancakeswap/chains'
 
const USDC = new Token(ChainId.BSC, '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', 18, 'USDC')
const CAKE = new Token(ChainId.BSC, '0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82', 18, 'CAKE')
 
// Define a pool key
const poolKey: PoolKey = {
  currency0: USDC,
  currency1: CAKE,
  fee: 2500,
  tickSpacing: 50,
  hooks: '0x0000000000000000000000000000000000000000',
}
 
// Build add-liquidity calldata for CL
const { calldata, value } = CLPositionManager.addLiquidity({
  poolKey,
  tickLower: -100,
  tickUpper:  100,
  amount0Desired: CurrencyAmount.fromRawAmount(USDC, 1_000_000n),
  amount1Desired: CurrencyAmount.fromRawAmount(CAKE, 10n ** 18n),
  recipient: '0xYOUR_ADDRESS',
  deadline: Math.floor(Date.now() / 1000) + 60 * 20,
})

PoolKey

Uniquely identifies an Infinity pool.

interface PoolKey {
  currency0: Currency   // lower-sorted token
  currency1: Currency   // higher-sorted token
  fee: number           // fee in hundredths of a bip (e.g. 2500 = 0.25%)
  tickSpacing: number   // tick spacing for CL pools
  hooks: string         // hooks contract address (use zero address for no hooks)
}

CLPool

CL (concentrated liquidity) pool state and swap simulation.

new CLPool(currency0, currency1, fee, tickSpacing, hooks, sqrtPriceX96, liquidity, tick, ticks?)

Properties

PropertyTypeDescription
currency0CurrencyThe lower-sorted token
currency1CurrencyThe higher-sorted token
feenumberFee tier
tickSpacingnumberTick spacing
hooksstringHooks contract address
sqrtPriceX96bigintCurrent sqrt price in Q64.96 format
liquiditybigintActive liquidity at the current tick
ticknumberCurrent tick index

Methods

MethodSignatureDescription
getOutputAmount(inputAmount) → [CurrencyAmount, CLPool]Simulate a swap and return output + resulting pool state
getInputAmount(outputAmount) → [CurrencyAmount, CLPool]Compute required input for a desired output
priceOf(currency) → PricePrice of a currency in terms of the other

CLPositionManager

Static helpers for building calldata targeting the Infinity CL position manager.

MethodSignatureDescription
addLiquidity(options) → { calldata: string, value: string }Mint a new CL position or increase an existing one
removeLiquidity(options) → { calldata: string, value: string }Decrease liquidity and receive tokens
collect(options) → { calldata: string, value: string }Collect accumulated fees
burn(options) → { calldata: string, value: string }Burn an empty position NFT

addLiquidity options

OptionTypeDescription
poolKeyPoolKeyPool identifier
tickLowernumberLower tick of the range
tickUppernumberUpper tick of the range
amount0DesiredCurrencyAmountDesired token0 deposit
amount1DesiredCurrencyAmountDesired token1 deposit
amount0MinCurrencyAmountMinimum token0 (slippage guard)
amount1MinCurrencyAmountMinimum token1 (slippage guard)
recipientstringAddress to receive the position NFT
deadlinenumberUnix timestamp deadline
tokenIdbigintIf set, increases an existing position

BinPool

Liquidity Book (Bin) pool state.

Properties

PropertyTypeDescription
currency0CurrencyThe lower-sorted token
currency1CurrencyThe higher-sorted token
feenumberFee tier
binStepnumberBin step (price granularity)
hooksstringHooks contract address
activeIdnumberCurrently active bin ID

Methods

MethodSignatureDescription
getOutputAmount(inputAmount) → [CurrencyAmount, BinPool]Simulate a swap
priceOf(currency) → PricePrice of a currency in terms of the other
BinPool.getPriceFromId(binId, binStep) → bigintCompute the price at a given bin ID
BinPool.getIdFromPrice(price, binStep) → numberCompute the bin ID for a given price

BinPositionManager

Static helpers for building Bin position calldata.

MethodSignatureDescription
addLiquidity(options) → { calldata: string, value: string }Add liquidity to one or more bins
removeLiquidity(options) → { calldata: string, value: string }Remove liquidity from bins

Vault

Interact with the Infinity Vault — the central settlement contract.

MethodSignatureDescription
Vault.take(currency, to, amount) → stringEncode a take (withdraw) action
Vault.settle(currency) → stringEncode a settle (deposit) action
Vault.sync(currency) → stringSync vault accounting for a currency

Infinity contracts

See Infinity contract addresses for deployed addresses.