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
txCount
by 1;increment each Token
txCount
by 1;increment each Token
totalValueLocked
by token amount;increment each Token
totalValueLockedUSD
by token amount in USD;increment Pool
txCount
by 1;if the new position includes the current tick, then increment Pool
liquidity
by eventliquidityDelta;
update Pool TVL in both tokens, ETH and USD;
update Pool
gasAccumulatedByModifyLiqs
andgasAccumulatedByModifyLiqsInEth
by respective values from event;if
liquidityDelta > 0
then increment PooladdLiqCount
by 1 else incrementremoveLiqCount
by 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
gasAccumulatedByModifyLiqs
andgasAccumulatedByModifyLiqsInEth
by respective values from event;if
liquidityDelta > 0
then increment HookaddLiqCount
by 1 else incrementremoveLiqCount
by 1;create new ModifyLiquidityentity with respective values;
load or create new Tick for each
tickLower
andtickUpper;
update for both ticks
liquidityGross
andliquidityNet
incrementing it byliquidityDelta;
update UniswapDayData, PoolDayData, PoolHourData, TokenDayData TokenHourData with values calculated earlier;
Last updated