Skip to content

Commit

Permalink
fix errors in lrna fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jepidoptera committed Dec 13, 2024
1 parent 8d803f6 commit 5596894
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions hydradx/model/amm/omnipool_amm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(
self,
minimum: float = 0,
maximum: float = float('inf'),
amplification: float = 1,
decay: float = 0.001,
amplification: float = 0,
decay: float = 0,
# ^^ if these four are provided, we can figure the rest out.
current: dict[str: float] = None,
liquidity: dict = None,
Expand Down Expand Up @@ -191,8 +191,6 @@ def get_last_volume():
return return_val
elif isinstance(value, dict):
return DynamicFee(
amplification=0,
decay=0,
current={
tkn: value[tkn] if tkn in value else (
self.last_lrna_fee[tkn] if tkn in self.last_lrna_fee else self._lrna_fee.minimum
Expand All @@ -202,8 +200,6 @@ def get_last_volume():
)
else:
return DynamicFee(
amplification=0,
decay=0,
current={tkn: value for tkn in self.asset_list},
liquidity={tkn: self.liquidity[tkn] for tkn in self.liquidity},
net_volume=get_last_volume()
Expand Down Expand Up @@ -701,7 +697,7 @@ def _lrna_swap(
elif delta_qa > 0:
# buying LRNA
lrna_fee_total = delta_qa / (1 - lrna_fee) - delta_qa
lrna_fee_burn = delta_qa / (1 - (min_lrna_fee + (lrna_fee - min_lrna_fee) * (1 - self.lp_lrna_share))) - delta_qa
lrna_fee_burn = lrna_fee_total * (1 - (1 - min_lrna_fee / lrna_fee) * self.lp_lrna_share)
delta_qi = -delta_qa - lrna_fee_total
lp_deposit = lrna_fee_total - lrna_fee_burn
if delta_qi + self.lrna[tkn] <= 0:
Expand All @@ -721,8 +717,8 @@ def _lrna_swap(
lrna_fee_burn = -delta_qi * (min_lrna_fee + (lrna_fee - min_lrna_fee) * (1 - self.lp_lrna_share))
lp_deposit = lrna_fee_total - lrna_fee_burn
delta_qa = -delta_qi - lrna_fee_total
self.lrna[tkn] += delta_qi
self.liquidity[tkn] -= delta_ra + lp_deposit
self.lrna[tkn] += delta_qi + lp_deposit
self.liquidity[tkn] -= delta_ra

else:
return self.fail_transaction('All deltas are zero.', agent)
Expand Down

0 comments on commit 5596894

Please sign in to comment.