Skip to main content

FeesCalc

Git Source

Author: Axicon Labs Limited

Compute fees accumulated within option position legs (a leg is a liquidity chunk).

Some options positions involve moving liquidity chunks to the AMM/Uniswap. Those chunks can then earn AMM swap fees.

Functions

calculateAMMSwapFees

Calculate the AMM swap fees accumulated by the liquidityChunk in each token of the pool.

Read from the Uniswap pool and compute the accumulated fees from swapping activity.

function calculateAMMSwapFees(
IUniswapV3Pool univ3pool,
int24 currentTick,
int24 tickLower,
int24 tickUpper,
uint128 liquidity
) public view returns (LeftRightSigned);

Parameters

NameTypeDescription
univ3poolIUniswapV3PoolThe AMM/Uniswap pool where fees are collected from
currentTickint24The current price tick
tickLowerint24The lower tick of the chunk to calculate fees for
tickUpperint24The upper tick of the chunk to calculate fees for
liquidityuint128The liquidity amount of the chunk to calculate fees for

Returns

NameTypeDescription
<none>LeftRightSignedThe fees collected from the AMM for each token (LeftRight-packed) with token0 in the right slot and token1 in the left slot

_getAMMSwapFeesPerLiquidityCollected

Calculates the fee growth that has occurred (per unit of liquidity) in the AMM/Uniswap for an option position's tick range.

Extracts the feeGrowth from the Uniswap V3 pool.

function _getAMMSwapFeesPerLiquidityCollected(
IUniswapV3Pool univ3pool,
int24 currentTick,
int24 tickLower,
int24 tickUpper
) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128);

Parameters

NameTypeDescription
univ3poolIUniswapV3PoolThe AMM pool where the leg is deployed
currentTickint24The current price tick in the AMM
tickLowerint24The lower tick of the option position leg (a liquidity chunk)
tickUpperint24The upper tick of the option position leg (a liquidity chunk)

Returns

NameTypeDescription
feeGrowthInside0X128uint256The fee growth in the AMM of token0
feeGrowthInside1X128uint256The fee growth in the AMM of token1