CrocQuery Contract

The CrocQuery contract provides a set of convenient view functions for querying the state of pool parameters, liquidity curves, tick boundaries, user LP positions, and user surplus collateral positions within the core CrocSwapDex contract.

The CrocQuery contract can be found at

Mainnet: 0xCA00926b6190c2C59336E73F02569c356d7B6b56

Scroll: 0x62223e90605845Cf5CC6DAE6E0de4CDA130d6DDf

Pool Price

The below functions are used to query the pool's instantenous price and prick tick respectively.

function queryPrice (address base, 
                     address quote, 
                     uint256 poolIdx) 
   public view returns (uint128)

The parameter types are as follows:

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

Return value is the current price of the pool, where price is represented as a Q64.64 fixed point representation of the square-root of the current base to quote exchange rate in the pool.

function queryCurveTick (address base, 
                         address quote, 
                         uint256 poolIdx) 
   public view returns (int24)

The parameter types are as follows:

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

Return value is the current price tick of the pool, where tick is defined as the floor of the base 1.0001 logarithm of the pool price.

Pool Liquidity

The queryLiquidity function returns the liquidity in a pool at its current tick. This can be used to estimate a price impact for small swaps, assuming they don't cross a tick boundary.

function queryLiquidity (address base, 
                         address quote, 
                         uint256 poolIdx) 
   public view returns (uint128)

The parameter types are as follows:

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

Return value is the current liquidity in the pool, where liquidity is represented as the square-root of the full-range equivalent of the product of the base and quote virtual liquidity in the pool.

Ambient Liquidity Positions

The below function returns information associated with a full range ambient liquidity position

function queryAmbientTokens (address owner, 
                             address base, 
                             address quote,
                             uint256 poolIdx)
        public view returns (uint128 liq, 
                             uint128 baseQty, 
                             uint128 quoteQty) 

The parameter types are as follows:

  • owner - The address of the position's owner

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

Return values are as follows:

  • liq - The full range liquidity contribution of this position as the square root of the base and quote tokens

  • baseQty - The total amount of base side tokens currently owned by this position

  • quoteQty The total amount of quote side tokens currently owned by this position

Range Liquidity Positions

The below function returns information associated with a concrentrated range liquidity position

function queryAmbientTokens (address owner, 
                             address base, 
                             address quote,
                             uint256 poolIdx,
                             int24 lowerTick,
                             int24 uppeTick)
        public view returns (uint128 liq, 
                             uint128 baseQty, 
                             uint128 quoteQty) 

The parameter types are as follows:

  • owner - The address of the position's owner

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

  • lowerTick - The tick index of the lower boundary of the range position

  • upperTick - The tick index of the upper boundary of the range position

Return values are as follows:

  • liq - The in-range liquidity contribution of this position as the square root of the virtual base and quote tokens

  • baseQty - The total amount of base side tokens currently owned by this position

  • quoteQty The total amount of quote side tokens currently owned by this position

Range Liquidity Positions

The below function returns information associated with a knockout liquidity or limit order position

function queryKnockoutTokens (address owner, 
                              address base, 
                              address quote,
                              uint256 poolIdx, 
                              uint32 pivot, 
                              bool isBid,
                              int24 lowerTick, 
                              int24 upperTick)
        public view returns (uint128 liq, 
                             uint128 baseQty, 
                             uint128 quoteQty, 
                             bool knockedOut) 

The parameter types are as follows:

  • owner - The address of the position's owner

  • base - The address of the base-side token in the pool's pair (always the smaller address)

  • quote - The address of the quote-side token in the pool's pair

  • poolIdx - The pool type index. (Defaults to 420 for standard pools)

  • pivot - The EVM tick of when the limit order tick was created (used to distinguish knockout orders created at different times)

  • isBid - If true, indicates the this was a limit order swapping base tokens for quote tokens. Vice versa if otherwise

  • lowerTick - The tick index of the lower boundary of the range position

  • upperTick - The tick index of the upper boundary of the range position

Return values are as follows:

  • liq - The in-range liquidity contribution of this position as the square root of the virtual base and quote tokens

  • baseQty - The total amount of base side tokens currently owned by this position

  • quoteQty The total amount of quote side tokens currently owned by this position

  • knockedOut - If true, indicates that the order has been atomically knocked out and the position is locked and no longer active on the liquidity curve.

Last updated