feat: change fee model to one that cannot be gamed #74
Description
2 parameters
maxLiquidityRemaining
zeroLiquidityRemaining
if your swap leaves max liquidity remaining in the pool, you paymaxLiquidityRemaining%
fees. If your swap leaves no liquidity remaining in the pool, you payzeroLiquidityRemaining%
fees
current fee model incentivises splitting up into smaller swaps so as to not incur higher fees: see the difference in fees paid (red rectangles' area) when you split unstake into two swaps versus doing it in one big swap
suggest changing this to the following:
- let the amount requested be
amountRequested
- calculate
feeAtCurrentLiquidity
(linear interpolation between max and zero) - calculate
feeAtCompletedLiquidity
(fee that will be charged after this swap, again, linear interpolation)
total fee charged as follows:
amountRequested
* feeAtCurrentLiquidity
+ 1/2 * amountRequested
* (feeAtCompletedLiquidity
- feeAtCurrentLiquidity
)
Compared to the current fee model, this fee model means that you cannot get a lower fee by splitting up your swap into smaller swaps