Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Pool – Uniswap SDK
Skip to content

Pool

The Pool class represents a Uniswap V3 pool with its current state, including the tokens, fee tier, current price, and liquidity.

Import

import { Pool } from '@uniswap/v3-sdk'

Constructor

Creates a new Pool instance.

new Pool(
  tokenA: Token,
  tokenB: Token,
  fee: FeeAmount,
  sqrtRatioX96: BigintIsh,
  liquidity: BigintIsh,
  tickCurrent: number,
  ticks?: TickDataProvider | (Tick | TickConstructorArgs)[]
)

Parameters

ParameterTypeDescription
tokenATokenOne of the tokens in the pool
tokenBTokenThe other token in the pool
feeFeeAmountThe fee in hundredths of a bips of the input amount of every swap
sqrtRatioX96BigintIshThe sqrt of the current ratio of amounts of token1 to token0
liquidityBigintIshThe current value of in range liquidity
tickCurrentnumberThe current tick of the pool
ticksTickDataProvider | (Tick | TickConstructorArgs)[]Optional tick data provider or array of ticks

Example

import { Pool, FeeAmount } from '@uniswap/v3-sdk'
import { Token } from '@uniswap/sdk-core'
 
const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC')
const WETH = new Token(1, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH')
 
const pool = new Pool(
  USDC,
  WETH,
  FeeAmount.MEDIUM,
  '1234567890123456789012345678', // sqrtRatioX96
  '1000000000000000000', // liquidity
  100 // tickCurrent
)

Properties

PropertyTypeDescription
token0TokenThe first token of the pool, sorted by address
token1TokenThe second token of the pool, sorted by address
feeFeeAmountThe fee tier of the pool
sqrtRatioX96bigintThe current sqrt price as a Q64.96 value
liquiditybigintThe current in-range liquidity
tickCurrentnumberThe current tick
tickDataProviderTickDataProviderThe tick data provider for this pool

Getters

token0Price

Returns the current mid price of the pool in terms of token0 (the ratio of token1 over token0).

get token0Price(): Price<Token, Token>

token1Price

Returns the current mid price of the pool in terms of token1 (the ratio of token0 over token1).

get token1Price(): Price<Token, Token>

chainId

Returns the chain ID of the tokens in the pool.

get chainId(): number

tickSpacing

Returns the tick spacing for this pool's fee tier.

get tickSpacing(): number

Static Methods

getAddress

Computes the pool address for the given tokens and fee.

static getAddress(
  tokenA: Token,
  tokenB: Token,
  fee: FeeAmount,
  initCodeHashManualOverride?: `0x${string}`,
  factoryAddressOverride?: Address.Address
): Address.Address

Parameters

ParameterTypeDescription
tokenATokenThe first token
tokenBTokenThe second token
feeFeeAmountThe fee tier
initCodeHashManualOverride`0x${string}`Optional override for init code hash
factoryAddressOverrideAddress.AddressOptional override for factory address

Example

const poolAddress = Pool.getAddress(USDC, WETH, FeeAmount.MEDIUM)

Methods

involvesToken

Returns true if the token is either token0 or token1.

involvesToken(token: Token): boolean

priceOf

Returns the price of the given token in terms of the other token in the pool.

priceOf(token: Token): Price<Token, Token>

getOutputAmount

Given an input amount of a token, returns the computed output amount and a pool with updated state.

async getOutputAmount(
  inputAmount: CurrencyAmount<Token>,
  sqrtPriceLimitX96?: bigint
): Promise<[CurrencyAmount<Token>, Pool]>

Parameters

ParameterTypeDescription
inputAmountCurrencyAmount<Token>The input amount for which to quote the output amount
sqrtPriceLimitX96bigintOptional Q64.96 sqrt price limit

Example

const inputAmount = CurrencyAmount.fromRawAmount(USDC, '1000000')
const [outputAmount, updatedPool] = await pool.getOutputAmount(inputAmount)

getInputAmount

Given a desired output amount of a token, returns the computed input amount and a pool with updated state.

async getInputAmount(
  outputAmount: CurrencyAmount<Token>,
  sqrtPriceLimitX96?: bigint
): Promise<[CurrencyAmount<Token>, Pool]>

Parameters

ParameterTypeDescription
outputAmountCurrencyAmount<Token>The output amount for which to quote the input amount
sqrtPriceLimitX96bigintOptional Q64.96 sqrt price limit

Example

const outputAmount = CurrencyAmount.fromRawAmount(WETH, '1000000000000000000')
const [inputAmount, updatedPool] = await pool.getInputAmount(outputAmount)