Indexing Swaps

If you are reading Flaunch swap data, you would need to do a little more than just read from the Uniswap V4 events.

Our PositionManager implement additional fair launch and internal swap mechanisms that occurs before the standard Uniswap swap flow. This internal swap is used to handle fee conversions and distributions within the protocol and Fair Launch is used to handle swaps before committing liquidity to Uniswap.

When indexing these swaps, we need to account for both the standard Uniswap swap metrics and the internal swap components, which are emitted through the PoolSwap event.

event PoolSwap(
  PoolId indexed poolId, 
  int flAmount0, int flAmount1,   // Fair Launch stage amounts
  int flFee0, int flFee1,         // Fair Launch stage fees
  int ispAmount0, int ispAmount1, // Internal Swap stage amounts
  int ispFee0, int ispFee1,       // Internal Swap stage fees
  int uniAmount0, int uniAmount1, // amounts returned with Uniswap delta
  int uniFee0, int uniFee1        // Uniswap fees
);

Each swap mechanism includes the amount swapped and the fee taken at each point. A few points of note:

  • If the value is negative then this indicates that the user has sent this amount into the swap

  • If the value is positive then this means that the user has received this amount in the swap

  • The 0/ 1 suffix refers to token0 and token1 of the PoolKey respectively

Variable Name
Definition

poolId

The V4 PoolId that has been swapped against

flAmount0

Fair Launch token0 change

flAmount1

Fair Launch token1 change

flFee0

Fair Launch token0 fee taken

flFee1

Fair Launch token1 fee taken

ispAmount0

Internal Swap Pool token0 change

ispAmount1

Internal Swap Pool token1 change

ispFee0

Internal Swap Pool token0 fee taken

ispFee1

Internal Swap Pool token1 fee taken

uniAmount0

Uniswap Pool token0 change

uniAmount1

Uniswap Pool token1 change

uniFee0

Uniswap Pool token0 fee taken

uniFee1

Uniswap Pool token1 fee taken

Therefore, additional indexing needs to be added:

  1. Internal swap amounts to be calculated: amount = flAmount + ispAmount + uniAmount;

  2. Internal swap fees to be calculated: fees = flFee + ispFee + uniFee;

These can then be summed up for token0 and token1 to get a complete picture of the swap.


Uniswap Native Hooks

Following the announcement of a standards Uniswap V4 hook data standards, we have upgraded our protocol to incorporate the proposed HookSwap and HookFee events into future deployments of our PositionManager. Unfortunately, these standards were announced after our initial launch, and as such are not included in our core PositionManager , which needs to implement data tracking as above.

You can track emitted events, but to get a complete picture, you must monitor both:

  • Swap events from the v4 core contract.

  • HookSwap events from delta-returning hook contracts (e.g., custom curves). Relying only on Swap events will miss volume facilitated by delta-returning hooks.

Both events will still be emitted, as our core PoolSwap event provides more detailed information regarding which mechanism contributed to the swap in more granular detail. But for a simplified, standardised approach that will work out the box, we have the following events defined:

HookSwap

event HookSwap(
    bytes32 indexed id,       // v4 pool id
    address indexed sender,   // router of the swap
    int128 amount0,
    int128 amount1,
    uint128 hookLPfeeAmount0,
    uint128 hookLPfeeAmount1
);

HookFee

Provides information on fees taken from the swaps.

event HookFee(
    bytes32 indexed id,       // v4 pool id
    address indexed sender,   // router of the swap
    uint128 feeAmount0,
    uint128 feeAmount1
);

Last updated

Was this helpful?