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:
Load and update Position
poolId, liquidity, tickLower, tickUpper;load both pool tokens;
calculate amounts for tokens using Uniswap position math;
calculate total amount of liquidity modification in USD:
amountUSD = amount0 * token0DerivedETH * ethPriceUSD + amount1 * token1DerivedETH * ethPriceUSD;decrement PoolManager TVL by old Pool TVL until new amounts are calculated
increment PoolManager
txCountby 1;increment each Token
txCountby 1;increment each Token
totalValueLockedby token amount;increment each Token
totalValueLockedUSDby token amount in USD;increment Pool
txCountby 1;if the new position includes the current tick, then increment Pool
liquidityby eventliquidityDelta;update Pool TVL in both tokens, ETH and USD;
update Pool
gasAccumulatedByModifyLiqsandgasAccumulatedByModifyLiqsInEthby respective values from event;if
liquidityDelta > 0then increment PooladdLiqCountby 1 else incrementremoveLiqCountby 1;update PoolManager TVL by updated pool values;
if there is a hook for the pool then update Hook TVL: decrement by pool TVL before event and increment by TVL after event;
update Hook
gasAccumulatedByModifyLiqsandgasAccumulatedByModifyLiqsInEthby respective values from event;if
liquidityDelta > 0then increment HookaddLiqCountby 1 else incrementremoveLiqCountby 1;create new ModifyLiquidityentity with respective values;
load or create new Tick for each
tickLowerandtickUpper;update for both ticks
liquidityGrossandliquidityNetincrementing it byliquidityDelta;update UniswapDayData, PoolDayData, PoolHourData, TokenDayData TokenHourData with values calculated earlier;
Last updated
