Fetching Pool Data

Read pool state, active liquidity, and tick parameters directly from your smart contracts.

This guide explains how to fetch state and metadata directly from a Rapiddex v3 pool contract in Solidity. It covers reading the primary pool variables, such as slot0 and active liquidity, as well as tick-specific variables.

Core Pool Variables

Every Rapiddex v3 pool maintains state variables related to its configuration, current pricing, and active liquidity. The most frequently read state is packed into a single storage slot called slot0 to reduce gas costs during transactions.

Solidity Querier Example

The following Solidity contract shows how to reference a pool and query its state parameters directly from another contract:

solidity// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@rapiddex/v3-core/contracts/interfaces/IRapiddexV3Pool.sol";

contract PoolDataQuerier {
    /// @notice Fetches the current slot0 state, liquidity, and token addresses of a pool
    function getPoolState(address poolAddress)
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint128 liquidity,
            address token0,
            address token1,
            uint24 fee
        )
    {
        IRapiddexV3Pool pool = IRapiddexV3Pool(poolAddress);
        
        // Fetch current slot0 values (sqrtPriceX96, current tick, etc.)
        (sqrtPriceX96, tick, , , , , ) = pool.slot0();
        
        // Fetch current active liquidity inside the active tick range
        liquidity = pool.liquidity();
        
        // Fetch pool configuration details
        token0 = pool.token0();
        token1 = pool.token1();
        fee = pool.fee();
    }

    /// @notice Fetch details for a specific tick index
    function getTickData(address poolAddress, int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint256 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        )
    {
        // Query the ticks mapping in the pool
        return IRapiddexV3Pool(poolAddress).ticks(tick);
    }
}
Read-only view calls Since these are view functions, calling them externally via JSON-RPC or from another view function does not consume gas.

Parameters and Outputs Reference

1. slot0

Queries the primary state variables of the pool contract. Designed to return multiple values packed into one storage slot.

Output Parameter Type Description
sqrtPriceX96 uint160 The square root of the pool's current price represented in Q64.96 format.
tick int24 The current price tick index (integer representing log price $1.0001^t$).
observationIndex uint16 Disabled. Internal oracle tracker (returns 0 or static default values).
observationCardinality uint16 Disabled. Active oracle observations buffer length (returns 0 or static default values).
observationCardinalityNext uint16 Disabled. Configured next oracle observations buffer length (returns 0 or static default values).
feeProtocol uint8 The active protocol fee fraction allocated to RAPID token governance.
unlocked bool Re-entrancy lock status. true indicates the pool is unlocked and swaps can occur.

2. liquidity

Queries the active liquidity units currently supported at the current tick index.

Output: liquidity (uint128) - The amount of virtual liquidity active in the pool range.