How to understand the Uniswap V3 swap fee calculation

Viewed 433

i read the whitepaper and the code about uniswapv3. but i am still confused about uni-v3 swap fee calculation.

i can‘t understand 3 formula

qustion1 cant understand Tick struct field feeGrowthOutside(0/1)X128

   
    struct Info {

        uint256 feeGrowthOutside0X128;
        uint256 feeGrowthOutside1X128;

    }

which at whitepaper is enter image description here

if swap cross it will be

enter image description here

question2 cant understand above tick i and below tick i formula

which at whitepaper is enter image description here

i know at uniswapv3 code. when add/remove liquidity will calculate fee owned because liqudity is discrete。 but i really dont konw what 3 formula mean although i tried the fee distribution result is right

1 Answers

feeGrowthOutside tracks how much fee has grown "outside" the tick. In case of the price goes past the tick lower bound from left to right, it is how much fee growth when the price was on the left side of the bound. Noted that, once the price goes past to the right side of the lower bound, the fee earned on its left side will stay the same, and hence, f_o will then be constant.

f_g or feeGrowthGlobal, will still growing no matter the current price is on the left, right side, or inside of the tick, hence the fee earned for the right side of the lower bound of the tick, in this case, is f_g - f_o.

Related