+
Skip to content

[Bug]: StateLibrary.getLiquidity docstring is incorrect #984

@woolgathering

Description

@woolgathering

Describe the bug

Code is here:

/**
* @notice Retrieves total the liquidity of a pool.
* @dev Corresponds to pools[poolId].liquidity
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @return liquidity The liquidity of the pool.
*/
function getLiquidity(IPoolManager manager, PoolId poolId) internal view returns (uint128 liquidity) {
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State: `uint128 liquidity`
bytes32 slot = bytes32(uint256(stateSlot) + LIQUIDITY_OFFSET);
liquidity = uint128(uint256(manager.extsload(slot)));
}

The docstring states that the function "[r]etrieves total the liquidity of a pool" but an examination of the code reveals that it instead gets the active liquidity, not total liquidity. Active liquidity is fine but the doscstring is misleading.

Expected Behavior

Expected behavior is that the function would return the total liquidity.

To Reproduce

It's a lot of overhead to show it in code (you can just look at what the source does) but it can be confirmed by doing the following:

  1. Make a new, empty pool with some starting price with tick t.
  2. Add single-sided liquidity at tick t' where t != t'.
  3. Check that tokens were moved into the pool manager via getBalance.
  4. Call StateLibrary.getLiquidity(). It will return 0 since the current price/tick is not in the range of liquidity added.

Obviously one must take are that t' is not in the same tick-spacing-bin as t.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载