Discussion about "Swap Fees" #35
Replies: 1 comment
-
You'd have to provide liquidity before any swap is made because, during a swap, fees are averaged over the liquidity available during the swap: Let's assume you take a flash loan and use it to add liquidity to a pool. Since you have to return the flash loan in the same transaction, the only one who will be able to make a swap is... you :) If you make a swap, fees will be divided over the currently available liquidity. If you're the only liquidity provider at the current price, you'll get the entire fee. So, in the end, there's no profit for you. If there are other liquidity providers, they'll get their share of the fee and you'll lose the fee that you paid to them. If you burn liquidity, it will be excluded from the global liquidity counter, thus your liquidity won't accumulate fees. If a rich whale comes and provides just-in-time liquidity, then, yes, they can "steal" the fee. But they'll get only a portion that's proportional to the amount they provided. I hope I was able to make it clearer :) But I agree that it's a complicated topic and the gas optimized fee tracking of Uniswap doesn't make it easy. |
Beta Was this translation helpful? Give feedback.
-
❕I'm really poor at English writing, so the content below may not read smoothly.
The swap fee is such a complicated chapter that I'm not sure if I understand it correctly, so I'd like to share some of my understanding and confusion here, and welcome discussion about whether they are correct or how to understand it.
In reading the series of articles about Uniswap V2, I have always had some uncertainty that: the swap fee is accumulated globally, and when some LP burn liquidity, it just distribute the global fee proportional to the liquidity this LP burned. But consider a situation that, there has been some liquidity and accumulated swap fee in the pool; I flash loan to get a huge amount of tokens(or I'm just really rich) and deposit into the pool as liquidity, after any swap has happened, I burn these liquidity, and get a swap fee proportional to my liquidity provided. In this case, I actually contribute nothing to the pool, but I can get many accumulated swap fees in this way. I'm sure I didn't notice some details in the imlementation, but I don't know where the details are.
Before reading the "swap fees" chapter in this book, I also had this kind of questions. After much effort I spent to read this difficult chapter, I think my confusion above get partially solved, but not totally. Once someone provide liquidity, there is a unique "position" for this LP. And although the global fee or "fee outside a tick" does not consider who the LP is, the accured fee in the position is only counted when this position is minted/created. So this guy cannot get the swap fees that happened before his liquidity provision. Even though some malicious guy try to add huge liquidity in the exact same position he has before, the accured fee will update to collect the swap fees he really deserve, so that he also cannot utilize this to get undeserved profit.
Although I get some rough understanding of how Uniswap V3 solve this problem, I'm still little confused about the design 😕 . I still feel it's really dangerous for the protocol to accumulate all the fees globally, no matter who/when someone provide the liquidity, and only calculate it proportionally when update the position. But this is really gas-optimized conpared to compute the fee for each LP in every swap step.
So...maybe I just start this discussion to make some complaints about my clumsy brain😂
Beta Was this translation helpful? Give feedback.
All reactions