UNPKG

@kamino-finance/klend-sdk

Version:

Typescript SDK for interacting with the Kamino Lending (klend) protocol

211 lines 10.2 kB
import { PublicKey } from '@solana/web3.js'; import Decimal from 'decimal.js'; import { KaminoReserve } from './reserve'; import { Obligation } from '../idl_codegen/accounts'; import { ElevationGroupDescription, KaminoMarket } from './market'; import { ObligationCollateral, ObligationLiquidity } from '../idl_codegen/types'; import { ActionType } from './action'; export type Position = { reserveAddress: PublicKey; mintAddress: PublicKey; /** * Amount of tokens in lamports, including decimal places for interest accrued (no borrow factor weighting) */ amount: Decimal; /** * Market value of the position in USD (no borrow factor weighting) */ marketValueRefreshed: Decimal; }; export type ObligationStats = { userTotalDeposit: Decimal; userTotalCollateralDeposit: Decimal; userTotalBorrow: Decimal; userTotalBorrowBorrowFactorAdjusted: Decimal; borrowLimit: Decimal; borrowLiquidationLimit: Decimal; borrowUtilization: Decimal; netAccountValue: Decimal; loanToValue: Decimal; liquidationLtv: Decimal; leverage: Decimal; potentialElevationGroupUpdate: number; }; interface BorrowStats { borrows: Map<PublicKey, Position>; userTotalBorrow: Decimal; userTotalBorrowBorrowFactorAdjusted: Decimal; positions: number; } interface DepositStats { deposits: Map<PublicKey, Position>; userTotalDeposit: Decimal; userTotalCollateralDeposit: Decimal; borrowLimit: Decimal; liquidationLtv: Decimal; borrowLiquidationLimit: Decimal; } export declare class KaminoObligation { obligationAddress: PublicKey; state: Obligation; /** * Deposits stored in a map of reserve address to position */ deposits: Map<PublicKey, Position>; /** * Borrows stored in a map of reserve address to position */ borrows: Map<PublicKey, Position>; refreshedStats: ObligationStats; obligationTag: number; /** * Initialise a new Obligation from the deserialized state * @param market * @param obligationAddress * @param obligation * @param collateralExchangeRates - rates from the market by reserve address, will be calculated if not provided * @param cumulativeBorrowRates - rates from the market by reserve address, will be calculated if not provided */ constructor(market: KaminoMarket, obligationAddress: PublicKey, obligation: Obligation, collateralExchangeRates: Map<PublicKey, Decimal>, cumulativeBorrowRates: Map<PublicKey, Decimal>); static load(kaminoMarket: KaminoMarket, obligationAddress: PublicKey): Promise<KaminoObligation | null>; static loadAll(kaminoMarket: KaminoMarket, obligationAddresses: PublicKey[], slot?: number): Promise<(KaminoObligation | null)[]>; /** * @returns the obligation borrows as a list */ getBorrows(): Array<Position>; /** * @returns the obligation borrows as a list */ getDeposits(): Array<Position>; /** * @returns the total deposited value of the obligation (sum of all deposits) */ getDepositedValue(): Decimal; /** * @returns the total borrowed value of the obligation (sum of all borrows -- no borrow factor) */ getBorrowedMarketValue(): Decimal; /** * @returns the total borrowed value of the obligation (sum of all borrows -- with borrow factor weighting) */ getBorrowedMarketValueBFAdjusted(): Decimal; /** * @returns total borrow power of the obligation, relative to max LTV of each asset's reserve */ getAllowedBorrowValue(): Decimal; /** * @returns the borrow value at which the obligation gets liquidatable * (relative to the liquidation threshold of each asset's reserve) */ getUnhealthyBorrowValue(): Decimal; /** * * @returns Market value of the deposit in the specified obligation collateral/deposit asset (USD) */ getDepositMarketValue(deposit: ObligationCollateral): Decimal; getBorrowByReserve(reserve: PublicKey): Position | undefined; getDepositByReserve(reserve: PublicKey): Position | undefined; getBorrowByMint(mint: PublicKey): Position | undefined; getDepositByMint(mint: PublicKey): Position | undefined; /** * * @returns Market value of the borrow in the specified obligation liquidity/borrow asset (USD) (no borrow factor weighting) */ getBorrowMarketValue(borrow: ObligationLiquidity): Decimal; /** * * @returns Market value of the borrow in the specified obligation liquidity/borrow asset (USD) (with borrow factor weighting) */ getBorrowMarketValueBFAdjusted(borrow: ObligationLiquidity): Decimal; /** * Calculate the current ratio of borrowed value to deposited value */ loanToValue(): Decimal; /** * @returns the total number of positions (deposits + borrows) */ getNumberOfPositions(): number; getNetAccountValue(): Decimal; /** * Get the loan to value and liquidation loan to value for a collateral token reserve as ratios, accounting for the obligation elevation group if it is active * @param market * @param reserve */ getLtvForReserve(market: KaminoMarket, reserve: KaminoReserve): { maxLtv: Decimal; liquidationLtv: Decimal; }; /** * @returns the potential elevation groups the obligation qualifies for */ getElevationGroups(kaminoMarket: KaminoMarket): Array<number>; static getElevationGroupsForReserves(reserves: Array<KaminoReserve>): Array<number>; simulateDepositChange(obligationDeposits: ObligationCollateral[], changeInLamports: number, changeReserve: PublicKey, collateralExchangeRates: Map<PublicKey, Decimal>): ObligationCollateral[]; simulateBorrowChange(obligationBorrows: ObligationLiquidity[], changeInLamports: number, changeReserve: PublicKey, cumulativeBorrowRate: Decimal): ObligationLiquidity[]; /** * Calculate the newly modified stats of the obligation */ getSimulatedObligationStats(params: { amountCollateral?: Decimal; amountDebt?: Decimal; action: ActionType; mintCollateral?: PublicKey; mintDebt?: PublicKey; market: KaminoMarket; reserves: Map<PublicKey, KaminoReserve>; slot: number; elevationGroupOverride?: number; }): { stats: ObligationStats; deposits: Map<PublicKey, Position>; borrows: Map<PublicKey, Position>; }; estimateObligationInterestRate: (market: KaminoMarket, reserve: KaminoReserve, borrow: ObligationLiquidity, currentSlot: number) => Decimal; private calculatePositions; static calculateObligationDeposits(market: KaminoMarket, obligationDeposits: ObligationCollateral[], collateralExchangeRates: Map<PublicKey, Decimal> | null, elevationGroup: number, getPx: (reserve: KaminoReserve) => Decimal): DepositStats; static calculateObligationBorrows(market: KaminoMarket, obligationBorrows: ObligationLiquidity[], cumulativeBorrowRates: Map<PublicKey, Decimal> | null, elevationGroup: number, getPx: (reserve: KaminoReserve) => Decimal): BorrowStats; getMaxLoanLtvGivenElevationGroup(market: KaminoMarket, elevationGroup: number, slot: number): Decimal; getBorrowPower(market: KaminoMarket, liquidityMint: PublicKey, slot: number, elevationGroup?: number): Decimal; getMaxBorrowAmountV2(market: KaminoMarket, liquidityMint: PublicKey, slot: number, elevationGroup?: number): Decimal; isLoanEligibleForElevationGroup(market: KaminoMarket, slot: number, elevationGroup: number): boolean; getElevationGroupsForObligation(market: KaminoMarket): ElevationGroupDescription[]; getMaxBorrowAmount(market: KaminoMarket, liquidityMint: PublicKey, slot: number, requestElevationGroup: boolean): Decimal; getMaxWithdrawAmount(market: KaminoMarket, tokenMint: PublicKey, slot: number): Decimal; /** * * @returns Total borrowed amount for the specified obligation liquidity/borrow asset */ static getBorrowAmount(borrow: ObligationLiquidity): Decimal; /** * * @returns Cumulative borrow rate for the specified obligation liquidity/borrow asset */ static getCumulativeBorrowRate(borrow: ObligationLiquidity): Decimal; static getRatesForObligation(kaminoMarket: KaminoMarket, obligation: Obligation, slot: number, additionalReserves?: PublicKey[]): { collateralExchangeRates: Map<PublicKey, Decimal>; cumulativeBorrowRates: Map<PublicKey, Decimal>; }; static addRatesForObligation(kaminoMarket: KaminoMarket, obligation: Obligation, collateralExchangeRates: Map<PublicKey, Decimal>, cumulativeBorrowRates: Map<PublicKey, Decimal>, slot: number): void; static getCollateralExchangeRatesForObligation(kaminoMarket: KaminoMarket, obligation: Obligation, slot: number, additionalReserves: PublicKey[]): Map<PublicKey, Decimal>; static addCollateralExchangeRatesForObligation(kaminoMarket: KaminoMarket, collateralExchangeRates: Map<PublicKey, Decimal>, obligation: Obligation, slot: number): void; static getCumulativeBorrowRatesForObligation(kaminoMarket: KaminoMarket, obligation: Obligation, slot: number, additionalReserves?: PublicKey[]): Map<PublicKey, Decimal>; static addCumulativeBorrowRatesForObligation(kaminoMarket: KaminoMarket, cumulativeBorrowRates: Map<PublicKey, Decimal>, obligation: Obligation, slot: number): void; /** * Get the borrow factor for a borrow reserve, accounting for the obligation elevation group if it is active * @param reserve * @param elevationGroup */ static getBorrowFactorForReserve(reserve: KaminoReserve, elevationGroup: number): Decimal; /** * Get the loan to value and liquidation loan to value for a collateral reserve as ratios, accounting for the obligation elevation group if it is active * @param market * @param reserve * @param elevationGroup */ static getLtvForReserve(market: KaminoMarket, reserve: KaminoReserve, elevationGroup: number): { maxLtv: Decimal; liquidationLtv: Decimal; }; } export {}; //# sourceMappingURL=obligation.d.ts.map