Initialize

The Initialize event in Uniswap V4 is emitted when a new pool is created in the PoolManager contract. It marks the initial setup of a liquidity pool between two tokens with specific parameters. When this event is emitted, it indicates that a new trading pair has been established with defined characteristics including the two tokens (currency0 and currency1), the fee tier, tick spacing, and initial price (represented as sqrtPriceX96). A unique feature of Uniswap V4 is the inclusion of hooks in pool initialization, allowing for customizable pool behavior through hook contracts. The Initialize event captures this hook address along with other pool parameters, making it a crucial event for tracking the creation and configuration of new pools in the protocol. As seen in the provided code, this event triggers various setup processes including token data initialization, price calculations, and the creation of related entities in the subgraph for analytics and tracking purposes. Event signature:

event Initialize(
    uint256 indexed id,
    address indexed currency0,
    address indexed currency1,
    uint24 fee,
    int24 tickSpacing,
    address hooks,
    uint160 sqrtPriceX96,
    int24 tick
)

Initialize event is handled by HookRank in the following order:

  1. Load or create new PoolManager entity;

  2. increment PoolManager poolCount value by 1;

  3. load or create new Token entity for each token in event;

  4. load or create new Hook entity;

  5. increment PoolManager hookCount value by 1;

  6. create new Pool entity;

  7. calculate token prices by AMM formula and update Pool;

Last updated