Skip to content

Commit

Permalink
fix: improve collateral and debt value calculation with safe token pr…
Browse files Browse the repository at this point in the history
…ice checks and default rates
  • Loading branch information
MrRoudyk committed Dec 23, 2024
1 parent 3b3d240 commit 8eae891
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions apps/shared/loan_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ def compute_collateral_usd(
return sum(
float(token_amount)
/ (10 ** collateral_token_parameters[token].decimals)
* (
collateral_token_parameters[token].collateral_factor
if risk_adjusted
else 1.0
)
* float(collateral_interest_rate_model[token])
* prices[collateral_token_parameters[token].underlying_address]
for token, token_amount in self.collateral.items()
* (collateral_token_parameters[token].collateral_factor if risk_adjusted else 1.0)
* float(collateral_interest_rate_model.get(token, 1.0))
* prices[underlying_address]
for token, token_amount in self.collateral.values.items()
if (underlying_address := collateral_token_parameters[token].underlying_address)
in prices
)

def compute_debt_usd(
Expand All @@ -74,9 +72,10 @@ def compute_debt_usd(
float(token_amount)
/ (10 ** debt_token_parameters[token].decimals)
/ (debt_token_parameters[token].debt_factor if risk_adjusted else 1.0)
* float(debt_interest_rate_model[token])
* prices[debt_token_parameters[token].underlying_address]
for token, token_amount in self.debt.items()
* float(debt_interest_rate_model.get(token, 1.0))
* prices[underlying_address]
for token, token_amount in self.debt.values.items()
if (underlying_address := debt_token_parameters[token].underlying_address) in prices
)

@abstractmethod
Expand Down

0 comments on commit 8eae891

Please sign in to comment.