zelos-alpha / demeter

Better backtest toolkit for Uniswap v3 and Aave.

Home Page:https://medium.com/zelos-research

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Granting too much fees when opening up multiple high liquidity positions

mbartn opened this issue · comments

The function demeter.uniswap.market.UniLpMarket.__update_fee updates LP fees for each position opened.

However, if position_liquidity > pool_liquidity, the position's share is 1 so it receives all the fees generated by the pool in the current timestamp_index. This leads to a bug where for n positions opened, broker earns n * all_fees_generated_in_current_timestamp_index

I think when calculating share, liquidity of all brokker's positions should be considered as well

def calc_amounts():
if position.liquidity >= state.current_liquidity:
share = Decimal(1)
else:
share = Decimal(position.liquidity) / Decimal(state.current_liquidity)

commented

I think it is caused by its assumption. During backtesting, your liquidity will not add to the market's total liquidity. "If" of Share calculation is defensive code.

commented

We will take your case into consideration, and maybe fix it in the next version. Or, you can help us fix it, and make a PR.

This bug has fixed and will be available in next release.