Skip to content

Commit

Permalink
Added simple test of find_partial_liquidation_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
poliwop committed Jan 24, 2024
1 parent 0d4f87e commit 6348822
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions hydradx/tests/test_liquidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from hydradx.model.amm.liquidations import CDP, liquidate_cdp
from hydradx.model.amm.agents import Agent
from hydradx.model.amm.omnipool_amm import OmnipoolState
from hydradx.model.amm.global_state import find_partial_liquidation_amount


def test_liquidate_cdp():
Expand All @@ -25,3 +27,41 @@ def test_liquidate_cdp():
raise
if cdp.collateral_amt != pytest.approx(init_collat_amt * (1 - liquidate_pct)):
raise


def test_find_partial_liquidation_amount():
# find_partial_liquidation_amount(omnipool: OmnipoolState, cdp: CDP, penalty: float)

prices = {'DOT': 6, 'HDX': 0.02, 'USDT': 1, 'WETH': 2500, 'iBTC': 45000}

assets = {
'DOT': {'usd price': prices['DOT'], 'weight': 0.40},
'HDX': {'usd price': prices['HDX'], 'weight': 0.10},
'USDT': {'usd price': prices['USDT'], 'weight': 0.30},
'WETH': {'usd price': prices['WETH'], 'weight': 0.10},
'iBTC': {'usd price': prices['iBTC'], 'weight': 0.10}
}

lrna_price_usd = 35
initial_omnipool_tvl = 20000000
liquidity = {}
lrna = {}

for tkn, info in assets.items():
liquidity[tkn] = initial_omnipool_tvl * info['weight'] / info['usd price']
lrna[tkn] = initial_omnipool_tvl * info['weight'] / lrna_price_usd

omnipool = OmnipoolState(
tokens={
tkn: {'liquidity': liquidity[tkn], 'LRNA': lrna[tkn]} for tkn in assets
},
preferred_stablecoin='USDT',
)

cdp = CDP('USDT', 'DOT', 1000, 200, True)
penalty = 0.01

liquidation_amount = find_partial_liquidation_amount(omnipool, cdp, penalty)

if liquidation_amount != pytest.approx(1000 * (1 + penalty)):
raise

0 comments on commit 6348822

Please sign in to comment.