Pools
Hydrex pools are concentrated-liquidity AMM pools deployed via a pool deployer factory. The SDK provides utilities to compute pool addresses and model their on-chain state.
Computing Pool Addresses
Pool.getAddress is the recommended surface — it automatically uses POOL_DEPLOYER_ADDRESSES for the token's chain. For custom deployer addresses, use computePoolAddress directly.
typescript
import { Pool } from '@hydrexfi/hydrex-sdk';
// Recommended: uses POOL_DEPLOYER_ADDRESSES for the token's chain automatically
const poolAddress = Pool.getAddress(USDC, WETH);Lower-level: computePoolAddress
typescript
import { computePoolAddress, POOL_DEPLOYER_ADDRESSES, ChainId } from '@hydrexfi/hydrex-sdk';
// Standard pool
const poolAddress = computePoolAddress({
poolDeployer: POOL_DEPLOYER_ADDRESSES[ChainId.Base],
tokenA: USDC,
tokenB: WETH,
});
// Custom deployer
const customPoolAddress = computePoolAddress({
poolDeployer: '0xYourCustomDeployer',
tokenA: USDC,
tokenB: WETH,
});Creating a Pool Instance
The Pool constructor requires the pool deployer address and tick spacing in addition to the standard Uniswap V3 parameters. Pool data is typically fetched on-chain via your RPC.
typescript
import {
Pool,
POOL_DEPLOYER_ADDRESSES,
INITIAL_POOL_FEE,
DEFAULT_TICK_SPACING,
ChainId,
} from '@hydrexfi/hydrex-sdk';
const pool = new Pool(
USDC, // tokenA
WETH, // tokenB
INITIAL_POOL_FEE, // fee tier (100)
sqrtRatioX96, // current sqrt price (Q64.96)
POOL_DEPLOYER_ADDRESSES[ChainId.Base], // deployer address
liquidity, // in-range liquidity
tickCurrent, // current tick
DEFAULT_TICK_SPACING, // tick spacing (60)
ticks // TickDataProvider or array
);
// Derived prices
const token0Price = pool.token0Price;
const token1Price = pool.token1Price;
// Pool address
const address = Pool.getAddress(USDC, WETH);
// Simulate a swap
const [outputAmount, updatedPool] = await pool.getOutputAmount(inputAmount);Pool constructor parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tokenA | Token | required | First token of the pair (order will be sorted internally). |
tokenB | Token | required | Second token of the pair. |
fee | number | required | Fee tier in hundredths of a bip. Default: INITIAL_POOL_FEE (100). |
sqrtRatioX96 | BigintIsh | required | Current sqrt price as a Q64.96 fixed-point number. |
poolDeployer | string | required | Address of the pool deployer factory contract. |
liquidity | BigintIsh | required | Total in-range liquidity at the current tick. |
tickCurrent | number | required | Current active tick index. |
tickSpacing | number | required | Tick spacing for this pool. Default: DEFAULT_TICK_SPACING (60). |
ticks | TickDataProvider | Tick[] | optional | Tick data for the pool, used in swap simulation. |
ℹ
Default constants
Use
INITIAL_POOL_FEE (100) and DEFAULT_TICK_SPACING (60) for standard Hydrex pools. Custom fee tiers may use different tick spacings.