# 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.&#x20;

Here's the event signature:

```solidity
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 [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#position) `poolId, liquidity, tickLower, tickUpper;`
2. load both pool tokens;
3. calculate amounts for tokens using Uniswap [position math](https://github.com/Uniswap/v3-sdk/blob/4e16fe8e56c8c26541545f138c89133794c7ce72/src/entities/position.ts#L68-L127);
4. calculate total amount of liquidity modification in USD:\
   `amountUSD = amount0 * token0DerivedETH * ethPriceUSD + amount1 * token1DerivedETH * ethPriceUSD;`
5. decrement [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#poolmanager) TVL by old [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool) TVL until new amounts are calculated
6. increment [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#poolmanager) `txCount` by 1;
7. increment each [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#token) `txCount` by 1;
8. increment each [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#token) `totalValueLocked` by token amount;
9. increment each [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#token) `totalValueLockedUSD` by token amount in USD;
10. increment [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool)`txCount` by 1;
11. if the new position includes the current tick, then increment [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool) `liquidity` by event `liquidityDelta;`
12. update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool) TVL in both tokens, ETH and USD;
13. update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool) `gasAccumulatedByModifyLiqs` and `gasAccumulatedByModifyLiqsInEth` by respective values from event;
14. if `liquidityDelta > 0` then increment [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pool) `addLiqCount` by 1 else increment `removeLiqCount` by 1;
15. update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#poolmanager) TVL by updated pool values;
16. if there is a hook for the pool then update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#hook) TVL: decrement by pool TVL before event and increment by TVL after event;
17. update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#hook)`gasAccumulatedByModifyLiqs` and `gasAccumulatedByModifyLiqsInEth` by respective values from event;
18. if `liquidityDelta > 0` then increment [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#hook)`addLiqCount` by 1 else increment `removeLiqCount` by 1;
19. create new [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#modifyliquidity)entity with respective values;
20. load or create new [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#tick) for each `tickLower` and `tickUpper;`
21. update for both ticks `liquidityGross` and `liquidityNet` incrementing it by `liquidityDelta;`
22. update [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#uniswapdaydata), [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#pooldaydata), [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#poolhourdata), [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#tokendaydata) [Tracked Data](/hookrank/hookrank-indexing/tracked-data.md#tokenhourdata) with values calculated earlier;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hookrank.gitbook.io/hookrank/hookrank-indexing/events/modifyliquidity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
