Skip to content

Commit

Permalink
Health factor fixed. Dynamic collateral factor fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
faurdent committed Feb 6, 2025
1 parent fa6796e commit 2e04cfc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions web_app/contract_tools/blockchain_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ async def get_available_zklend_reserves(self) -> dict[str, list[int]]:
)
}

async def get_z_addresses(self) -> dict[str, tuple[int, int]]:
async def get_z_addresses(self) -> dict[str, tuple[int, int, int]]:
"""
Get ZkLend addresses.
:return: A dictionary with token names as keys and tuples of addresses as values.
"""
reserves = await self.get_available_zklend_reserves()
return {token: (reserve[1], reserve[2]) for token, reserve in reserves.items()}
return {token: (reserve[1], reserve[2], reserve[4]) for token, reserve in reserves.items()}

async def get_zklend_debt(self, user: str, token: str) -> list[int]:
"""
Expand Down
4 changes: 3 additions & 1 deletion web_app/contract_tools/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
STRK = "STRK"
USDC = "USDC"

ZKLEND_SCALE_DECIMALS = Decimal("1000000000000000000000000000")


@dataclass(frozen=True)
class TokenConfig:
Expand Down Expand Up @@ -60,7 +62,7 @@ class TokenParams:
name=STRK,
address="0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
decimals=Decimal("18"),
collateral_factor=Decimal("0.50"),
collateral_factor=Decimal("0.60"),
borrow_factor=Decimal("1"),
)
USDC = TokenConfig(
Expand Down
4 changes: 2 additions & 2 deletions web_app/contract_tools/mixins/health_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pragma_sdk.common.types.types import AggregationMode
from pragma_sdk.onchain.client import PragmaOnChainClient
from web_app.contract_tools.blockchain_call import CLIENT
from web_app.contract_tools.constants import TokenParams
from web_app.contract_tools.constants import TokenParams, ZKLEND_SCALE_DECIMALS

PRAGMA = PragmaOnChainClient(
network="mainnet",
Expand Down Expand Up @@ -79,7 +79,7 @@ async def _get_deposited_tokens(
reserves = await CLIENT.get_z_addresses()
deposits = await cls._get_z_balances(reserves, deposit_contract_address)
return {
token: amount * TokenParams.get_token_collateral_factor(token)
token: amount * Decimal(reserves[token][2]) / ZKLEND_SCALE_DECIMALS
for token, amount in deposits.items()
if amount != 0
}
Expand Down

0 comments on commit 2e04cfc

Please sign in to comment.