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.
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 totoken0
andtoken1
of the PoolKey respectively
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:
Internal swap amounts to be calculated:
amount = flAmount + ispAmount + uniAmount;
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
We do not take LP fees, so hookLPfeeAmount0
and hookLPfeeAmount1
will always be zero values.
If you are looking for swap fees taken by the protocol for internal mechanisms and creator / community distributions, then you should digest the HookFee
event.
HookFee
Provides information on fees taken from the swaps.
Last updated
Was this helpful?