import { Bitcoin, ExchangeRate, MonetaryAmount } from "@interlay/monetary-js"; import { AccountId } from "@polkadot/types/interfaces"; import Big from "big.js"; import { CurrencyExt, WrappedCurrency } from "./currency"; interface LoanPosition { amount: MonetaryAmount; } interface CollateralPosition extends LoanPosition { isCollateral: boolean; vaultCollateralAmount: MonetaryAmount; } interface BorrowPosition extends LoanPosition { accumulatedDebt: MonetaryAmount; } type LoanAction = "lend" | "withdraw" | "borrow" | "repay"; interface LendingStats { totalLentBtc: MonetaryAmount; totalBorrowedBtc: MonetaryAmount; totalCollateralBtc: MonetaryAmount; borrowLimitBtc: MonetaryAmount; ltv: Big; collateralThresholdWeightedAverage: Big; liquidationThresholdWeightedAverage: Big; calculateBorrowLimitBtcChange: (action: LoanAction, amount: MonetaryAmount) => MonetaryAmount; calculateLtvAndThresholdsChange: (action: LoanAction, amount: MonetaryAmount) => { ltv: Big; collateralThresholdWeightedAverage: Big; liquidationThresholdWeightedAverage: Big; }; } interface LoanAsset { currency: CurrencyExt; lendApy: Big; borrowApy: Big; lendReward: MonetaryAmount | null; borrowReward: MonetaryAmount | null; totalLiquidity: MonetaryAmount; availableCapacity: MonetaryAmount; totalBorrows: MonetaryAmount; liquidationThreshold: Big; collateralThreshold: Big; isActive: boolean; supplyCap: MonetaryAmount; borrowCap: MonetaryAmount; exchangeRate: ExchangeRate; } type TickerToData = { [ticker: string]: T; }; interface LoanMarket { lendTokenId: number; } /** * The liquidity status of an account, based on the value of its collateral and loans. * * `liquidity` is `max(totalCollateralValueAsWrapped - totalBorrowedValueAsWrapped, 0)`, where each * item in the `totalCollateralValueAsWrapped` sum is first scaled down by the collateralization * required by that market (e.g `100 satoshi * 0.75 + 150 satoshi * 0.8`, where `0.75` and `0.8` * are the collateralization thresholds). * * `shortfall` is very similar to liquidity: `max(totalBorrowedValueAsWrapped - totalCollateralValueAsWrapped, 0)` * so it is only positive when the total borrowed amount exceeds what the collateral can cover. */ type AccountLiquidity = { liquidity: MonetaryAmount; shortfall: MonetaryAmount; }; type UndercollateralizedPosition = { accountId: AccountId; shortfall: MonetaryAmount; collateralPositions: Array; borrowPositions: Array; }; interface AccruedRewards { total: MonetaryAmount; perMarket: TickerToData<{ lend: MonetaryAmount | null; borrow: MonetaryAmount | null; }>; } export type { AccruedRewards, LoanPosition, CollateralPosition, BorrowPosition, LoanAsset, TickerToData, LoanMarket, LendingStats, LoanAction, AccountLiquidity, UndercollateralizedPosition, };