Skip to main content
Helpful?

StateView

Git Source - Generated with forge doc

Inherits: ImmutableState

A view only contract wrapping the StateLibrary.sol library for reading storage in v4-core.

Functions

constructor

constructor(IPoolManager _poolManager) ImmutableState(_poolManager);

getSlot0

Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee

Corresponds to pools[poolId].slot0

function getSlot0(PoolId poolId)
external
view
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.

Returns

NameTypeDescription
sqrtPriceX96uint160The square root of the price of the pool, in Q96 precision.
tickint24The current tick of the pool.
protocolFeeuint24The protocol fee of the pool.
lpFeeuint24The swap fee of the pool.

getTickInfo

Retrieves the tick information of a pool at a specific tick.

Corresponds to pools[poolId].ticks[tick]

function getTickInfo(PoolId poolId, int24 tick)
external
view
returns (uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
tickint24The tick to retrieve information for.

Returns

NameTypeDescription
liquidityGrossuint128The total position liquidity that references this tick
liquidityNetint128The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)
feeGrowthOutside0X128uint256fee growth per unit of liquidity on the other side of this tick (relative to the current tick)
feeGrowthOutside1X128uint256fee growth per unit of liquidity on the other side of this tick (relative to the current tick)

getTickLiquidity

Retrieves the liquidity information of a pool at a specific tick.

Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo

function getTickLiquidity(PoolId poolId, int24 tick)
external
view
returns (uint128 liquidityGross, int128 liquidityNet);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
tickint24The tick to retrieve liquidity for.

Returns

NameTypeDescription
liquidityGrossuint128The total position liquidity that references this tick
liquidityNetint128The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)

getTickFeeGrowthOutside

Retrieves the fee growth outside a tick range of a pool

Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo

function getTickFeeGrowthOutside(PoolId poolId, int24 tick)
external
view
returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
tickint24The tick to retrieve fee growth for.

Returns

NameTypeDescription
feeGrowthOutside0X128uint256fee growth per unit of liquidity on the other side of this tick (relative to the current tick)
feeGrowthOutside1X128uint256fee growth per unit of liquidity on the other side of this tick (relative to the current tick)

getFeeGrowthGlobals

Retrieves the global fee growth of a pool.

Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128

function getFeeGrowthGlobals(PoolId poolId)
external
view
returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.

Returns

NameTypeDescription
feeGrowthGlobal0uint256The global fee growth for token0.
feeGrowthGlobal1uint256The global fee growth for token1.

getLiquidity

Retrieves the total liquidity of a pool.

Corresponds to pools[poolId].liquidity

function getLiquidity(PoolId poolId) external view returns (uint128 liquidity);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.

Returns

NameTypeDescription
liquidityuint128The liquidity of the pool.

getTickBitmap

Retrieves the tick bitmap of a pool at a specific tick.

Corresponds to pools[poolId].tickBitmap[tick]

function getTickBitmap(PoolId poolId, int16 tick) external view returns (uint256 tickBitmap);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
tickint16The tick to retrieve the bitmap for.

Returns

NameTypeDescription
tickBitmapuint256The bitmap of the tick.

getPositionInfo

Retrieves the position info without needing to calculate the positionId.

Corresponds to pools[poolId].positions[positionId]

function getPositionInfo(PoolId poolId, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
owneraddressThe owner of the liquidity position.
tickLowerint24The lower tick of the liquidity range.
tickUpperint24The upper tick of the liquidity range.
saltbytes32The bytes32 randomness to further distinguish position state.

Returns

NameTypeDescription
liquidityuint128The liquidity of the position.
feeGrowthInside0LastX128uint256The fee growth inside the position for token0.
feeGrowthInside1LastX128uint256The fee growth inside the position for token1.

getPositionInfo

Retrieves the position information of a pool at a specific position ID.

Corresponds to pools[poolId].positions[positionId]

function getPositionInfo(PoolId poolId, bytes32 positionId)
external
view
returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
positionIdbytes32The ID of the position.

Returns

NameTypeDescription
liquidityuint128The liquidity of the position.
feeGrowthInside0LastX128uint256The fee growth inside the position for token0.
feeGrowthInside1LastX128uint256The fee growth inside the position for token1.

getPositionLiquidity

Retrieves the liquidity of a position.

Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieving liquidity as compared to getPositionInfo

function getPositionLiquidity(PoolId poolId, bytes32 positionId) external view returns (uint128 liquidity);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
positionIdbytes32The ID of the position.

Returns

NameTypeDescription
liquidityuint128The liquidity of the position.

getFeeGrowthInside

Calculate the fee growth inside a tick range of a pool

pools[poolId].feeGrowthInside0LastX128 in Position.Info is cached and can become stale. This function will calculate the up to date feeGrowthInside

function getFeeGrowthInside(PoolId poolId, int24 tickLower, int24 tickUpper)
external
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128);

Parameters

NameTypeDescription
poolIdPoolIdThe ID of the pool.
tickLowerint24The lower tick of the range.
tickUpperint24The upper tick of the range.

Returns

NameTypeDescription
feeGrowthInside0X128uint256The fee growth inside the tick range for token0.
feeGrowthInside1X128uint256The fee growth inside the tick range for token1.
Helpful?