ModifyLiquidity
Last updated
Last updated
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:
Each ModifyLiquidity event is processed by Hookrank in the following way:
Load and update 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 TVL by old TVL until new amounts are calculated
increment txCount
by 1;
increment each txCount
by 1;
increment each totalValueLocked
by token amount;
increment each totalValueLockedUSD
by token amount in USD;
increment txCount
by 1;
if the new position includes the current tick, then increment liquidity
by event liquidityDelta;
update TVL in both tokens, ETH and USD;
update gasAccumulatedByModifyLiqs
and gasAccumulatedByModifyLiqsInEth
by respective values from event;
if liquidityDelta > 0
then increment addLiqCount
by 1 else increment removeLiqCount
by 1;
update TVL by updated pool values;
if there is a hook for the pool then update TVL: decrement by pool TVL before event and increment by TVL after event;
update gasAccumulatedByModifyLiqs
and gasAccumulatedByModifyLiqsInEth
by respective values from event;
if liquidityDelta > 0
then increment addLiqCount
by 1 else increment removeLiqCount
by 1;
create new entity with respective values;
load or create new for each tickLower
and tickUpper;
update for both ticks liquidityGross
and liquidityNet
incrementing it by liquidityDelta;
update , , , with values calculated earlier;