Skip to content

Instantly share code, notes, and snippets.

@sekrystal
Created March 30, 2023 14:52
Show Gist options
  • Save sekrystal/528f6d567e04e963b568d80e3f4b6c39 to your computer and use it in GitHub Desktop.
Save sekrystal/528f6d567e04e963b568d80e3f4b6c39 to your computer and use it in GitHub Desktop.
Insolvent Position Analyisis
from io import BytesIO
from binascii import unhexlify
from dataclasses import dataclass
@dataclass(frozen=True)
class UserAccountData:
totalCollateralETH: int
totalDebtETH: int
availableBorrowsETH: int
currentLiquidationThreshold: int
ltv: int
healthFactor: int
def parse_user_account_data(uacd: str) -> UserAccountData:
uacd_bytes = unhexlify(uacd[2:])
assert len(uacd_bytes) == 192
uacd_bytes = BytesIO(uacd_bytes)
total_collateral_eth = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
total_debt_eth = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
available_borrows_eth = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
current_liquidation_threshold = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
ltv = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
health_factor = int.from_bytes(bytes=uacd_bytes.read(32), byteorder="big", signed=False)
return UserAccountData(
totalCollateralETH=total_collateral_eth,
totalDebtETH=total_debt_eth,
availableBorrowsETH=available_borrows_eth,
currentLiquidationThreshold=current_liquidation_threshold,
ltv=ltv,
healthFactor=health_factor,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment