ModifyLiquidity

The ModifyLiquidity event is emitted whenever a liquidity position is changed in a Uniswap V4 pool. It tracks changes in liquidity for a specific position, identified by the owner's address and the tick range (lower and upper tick boundaries). The event captures the amount of liquidity being added (positive delta) or removed (negative delta), along with the current timestamp and pool information.

Here's the event signature:

event ModifyLiquidity(
    address indexed owner,
    address indexed pool,
    int24 tickLower,
    int24 tickUpper,
    int256 liquidityDelta,
    uint256 timestamp
);

Each ModifyLiquidity event is processed by Hookrank in the following way:

  1. Load and update Position poolId, liquidity, tickLower, tickUpper;

  2. load both pool tokens;

  3. calculate amounts for tokens using Uniswap position math;

  4. calculate total amount of liquidity modification in USD: amountUSD = amount0 * token0DerivedETH * ethPriceUSD + amount1 * token1DerivedETH * ethPriceUSD;

  5. decrement PoolManager TVL by old Pool TVL until new amounts are calculated

  6. increment PoolManager txCount by 1;

  7. increment each Token txCount by 1;

  8. increment each Token totalValueLocked by token amount;

  9. increment each Token totalValueLockedUSD by token amount in USD;

  10. increment PooltxCount by 1;

  11. if the new position includes the current tick, then increment Pool liquidity by event liquidityDelta;

  12. update Pool TVL in both tokens, ETH and USD;

  13. update Pool gasAccumulatedByModifyLiqs and gasAccumulatedByModifyLiqsInEth by respective values from event;

  14. if liquidityDelta > 0 then increment Pool addLiqCount by 1 else increment removeLiqCount by 1;

  15. update PoolManager TVL by updated pool values;

  16. if there is a hook for the pool then update Hook TVL: decrement by pool TVL before event and increment by TVL after event;

  17. update HookgasAccumulatedByModifyLiqs and gasAccumulatedByModifyLiqsInEth by respective values from event;

  18. if liquidityDelta > 0 then increment HookaddLiqCount by 1 else increment removeLiqCount by 1;

  19. create new ModifyLiquidityentity with respective values;

  20. load or create new Tick for each tickLower and tickUpper;

  21. update for both ticks liquidityGross and liquidityNet incrementing it by liquidityDelta;

  22. update UniswapDayData, PoolDayData, PoolHourData, TokenDayData TokenHourData with values calculated earlier;

Last updated