Get CLMM Pools
Retrieve pool information from the Ferra protocol.
Overview
The SDK provides multiple methods to fetch pool data, from basic immutable info to complete pool state with real-time data.
Quick Start
import { clmmMainnet, initFerraSDK } from '@ferra-labs/clmm'
// Initialize SDK
const sdk = initFerraSDK({
...clmmMainnet,
network: 'beta',
fullNodeUrl: 'https://...',
wallet: '0x...'
})
// Get a single pool
const pool = await sdk.Pool.getPool('0x...')
// Get multiple pools
const pools = await sdk.Pool.getPools()
Get Single Pool
Fetch complete pool data with current state:
const poolId = '0x...'
const pool = await sdk.Pool.getPool(poolId)
console.log({
address: pool.poolAddress,
coinTypeA: pool.coinTypeA,
coinTypeB: pool.coinTypeB,
currentPrice: pool.current_sqrt_price,
currentTick: pool.current_tick_index,
liquidity: pool.liquidity,
feeRate: pool.fee_rate,
tvlA: pool.coinAmountA,
tvlB: pool.coinAmountB
})
Get Multiple Pools
Basic Usage
// Get first 10 pools
const pools = await sdk.Pool.getPools([], 0, 10)
// Get specific pools
const poolIds = ['0x...', '0x...']
const pools = await sdk.Pool.getPools(poolIds)
With Pagination
// Advanced pagination
const result = await sdk.Pool.getPoolsWithPage(
[], // Pool IDs (empty = all)
{ // Pagination args
limit: 20,
cursor: nextCursor
}
)
Get Pool Immutables
Lightweight method for basic pool info:
// Get pool addresses and coin types only
const poolInfos = await sdk.Pool.getPoolImmutables()
poolInfos.forEach(info => {
console.log({
pool: info.poolAddress,
coinA: info.coinTypeA,
coinB: info.coinTypeB,
tickSpacing: info.tickSpacing
})
})
Pool Data Structure
interface Pool {
poolAddress: string
coinTypeA: string
coinTypeB: string
// Current state
current_sqrt_price: string
current_tick_index: number
liquidity: string
// TVL
coinAmountA: string
coinAmountB: string
// Config
fee_rate: string
tick_spacing: number
// Rewarders
rewarder_infos: RewarderInfo[]
// Internal handles
ticks_handle: string
positions_handle: string
}
Filtering Pools
By Coin Types
// Get all pools
const allPools = await sdk.Pool.getPools()
// Filter by coin pair
const suiUsdcPools = allPools.filter(pool =>
(pool.coinTypeA.includes('sui') && pool.coinTypeB.includes('usdc')) ||
(pool.coinTypeA.includes('usdc') && pool.coinTypeB.includes('sui'))
)
Real-time Updates
// Force refresh for latest data
const pool = await sdk.Pool.getPool(poolId, true)
// Auto-refresh example
setInterval(async () => {
const freshPool = await sdk.Pool.getPool(poolId, true)
updateUI(freshPool)
}, 5000) // Every 5 seconds
Error Handling
try {
const pool = await sdk.Pool.getPool(poolId)
} catch (error) {
if (error.code === 'InvalidPoolObject') {
console.error('Pool not found')
}
}
Last updated