import { AccountId } from "@polkadot/types/interfaces"; import { MonetaryAmount } from "@interlay/monetary-js"; import { BorrowPosition, CurrencyExt, LoanAsset, LendingStats, TickerToData, LendToken, LoanPosition, AccountLiquidity, WrappedCurrency, CollateralPosition, UndercollateralizedPosition, ExtrinsicData, AccruedRewards } from "../types"; import { ApiPromise } from "@polkadot/api"; import Big from "big.js"; import { InterbtcPrimitivesCurrencyId, LoansMarket } from "@polkadot/types/lookup"; import { OracleAPI } from "./oracle"; import { CurrencyId } from "../interfaces"; /** * @category Lending protocol */ export interface LoansAPI { /** * Get the lend positions for given account. * * @param accountId the account Id for which to get supply positions * @returns Array of lend positions of account. */ getLendPositionsOfAccount(accountId: AccountId): Promise>; /** * Get the borrow positions for given account. * * @param accountId the account Id for which to get borrow positions * @returns Array of borrow positions of account. */ getBorrowPositionsOfAccount(accountId: AccountId): Promise>; /** * Get collateralization information about account's loans. * * @param lendPositions Lend positions of account. * @param borrowPositions Borrow positions of account. * @param loanAssets All loan assets data in TickerToData structure. * @return Collateral information about account based on passed positions. * @throws When `loanAssets` does not contain all of the loan positions currencies. */ getLendingStats(lendPositions: Array, borrowPositions: Array, loanAssets: TickerToData): LendingStats | undefined; /** * Get all loan assets. * * @returns Array of all assets that can be lent and borrowed. * @remarks Method could be refactored to compute APR in lib if we can get underlyingCurrency/rewardCurrency exchange rate, * but is it safe to assume that exchange rate for btc/underlyingCurrency will be * always fed to the oracle and available? */ getLoanAssets(): Promise>; /** * Get all lend token currencies. * * @returns Array of all LendToken currencies. */ getLendTokens(): Promise>; /** * @return Exchange rates for underlying currency -> lend token. * Representing amount of lend token equal to 1 of underlying currency. */ getLendTokenExchangeRates(): Promise>; /** * Get accrued subsidy rewards amounts for the account. * * @param accountId Account to get rewards for * @returns {Promise} Total amount how much rewards the account can claim and rewards per market. */ getAccruedRewardsOfAccount(accountId: AccountId): Promise; /** * Lend currency to protocol for borrowing. * * @param {CurrencyExt} underlyingCurrency Currency to lend. * @param {MonetaryAmount} amount Amount of currency to lend. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is not active market for `underlyingCurrency`. * @throws If `amount` is exceeding available balance of account. */ lend(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; /** * Withdraw previously lent currency from protocol. * * @param {CurrencyExt} underlyingCurrency Currency to witdhraw. * @param {MonetaryAmount} amount Amount of currency to withdraw. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is not active market for `underlyingCurrency`. * @throws If `amount` is exceeding lent amount of account. * @throws If `underlyingCurrency` is used as collateral and withdrawal of * `amount` would bring account under collateral threshold. * @throws If there is not enough of underlying currency currently * available in the protocol. */ withdraw(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; /** * Same as `withdraw`, but exits full position. * * @param underlyingCurrency Currency to fully withdraw. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ withdrawAll(underlyingCurrency: CurrencyExt): Promise; /** * Enable lend position of account as collateral for borrowing. * * @param underlyingCurrency Currency to enable as collateral. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is no existing lend position for `currency`. */ enableAsCollateral(underlyingCurrency: CurrencyExt): Promise; /** * Enable lend position of account as collateral for borrowing. * * @param underlyingCurrency Currency to enable as collateral. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is no existing lend position for `currency`. * @throws If disabling lend position of `currency` would bring * account under collateral threshold. */ disableAsCollateral(underlyingCurrency: CurrencyExt): Promise; /** * Claim subsidy rewards for all markets available for account. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ claimAllSubsidyRewards(): ExtrinsicData; /** * Borrow currency from the protocol. * * @param underlyingCurrency Currency to borrow. * @param amount Amount of currency to borrow. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is no active market for `underlyingCurrency`. * @throws If there is not enough collateral provided by account for * `amount` of `underlyingCurrency`. * @throws If `amount` is higher than available amount of `underlyingCurrency` * in the protocol. */ borrow(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; /** * Repay borrowed loan. * * @param underlyingCurrency Currency to repay. * @param amount Amount of currency to repay. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws If there is no active market for `underlyingCurrency`. * @throws If `amount` is higher than available balance of account. * @throws If `amount` is higher than outstanding loan. */ repay(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; /** * Same as `repay`, but repays full loan. * * @param underlyingCurrency Currency to repay. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ repayAll(underlyingCurrency: CurrencyExt): Promise; /** * Liquidates borrow position for exchange of collateral. * * @param borrower AccountId of borrower whose position will be liquidated. * @param liquidationCurrency Currency of position that will be liquidated. * @param repayAmount Amount to be repaid. * @param collateralCurrency Collateral currency which will be claimed by liquidator. * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ liquidateBorrowPosition(borrower: AccountId, liquidationCurrency: CurrencyExt, repayAmount: MonetaryAmount, collateralCurrency: CurrencyExt): ExtrinsicData; /** * @returns An array of `UndercollateralizedPosition`s, with all details needed to * liquidate them (accountId, shortfall - expressed in the wrapped currency, open borrow positions, collateral * deposits). */ getUndercollateralizedBorrowers(): Promise>; /** * @return An array of `AccountId`s which historically borrowed from the lending protocol. * This includes accounts with zero outstanding debt. */ getBorrowerAccountIds(): Promise>; /** * @param accountId The account whose liquidity to query from the chain * @returns An `AccountLiquidity` object, which is valid even for accounts that didn't use the loans pallet at all */ getLiquidationThresholdLiquidity(accountId: AccountId): Promise; /** * @returns An array of tuples denoting the underlying currency of a market, and the configuration of that market */ getLoansMarkets(): Promise<[CurrencyExt, LoansMarket][]>; } export declare class DefaultLoansAPI implements LoansAPI { private api; private wrappedCurrency; private oracleAPI; constructor(api: ApiPromise, wrappedCurrency: WrappedCurrency, oracleAPI: OracleAPI); getLoansMarkets(): Promise<[CurrencyExt, LoansMarket][]>; static getLendTokenFromUnderlyingCurrency(currency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId): LendToken; getLendTokenIdFromUnderlyingCurrency(currency: CurrencyExt): Promise; convertLendTokenToUnderlyingCurrency(amount: Big, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise; /** * Get lend position amounts in both underlying and lend currencies. * * @param accountId AccountId to get position information about * @param lendTokenId LendToken CurrencyId of the position * @param underlyingCurrencyId Underlying CurrencyId of the position * @returns Lend position amounts in underlying currency and lend token */ getLendPositionAmounts(accountId: AccountId, lendTokenId: InterbtcPrimitivesCurrencyId, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<[Big, Big]>; getLendTokens(): Promise; getLendTokenExchangeRates(): Promise>; getBorrowerAccountIds(): Promise>; getUndercollateralizedBorrowers(): Promise>; getLiquidationThresholdLiquidity(accountId: AccountId): Promise; _getLendPosition(accountId: AccountId, underlyingCurrency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId): Promise; _calculateAccumulatedDebt(borrowedAmount: Big, snapshotBorrowIndex: Big, currentBorrowIndex: Big): Big; _getBorrowPosition(accountId: AccountId, underlyingCurrency: CurrencyExt): Promise; _getPositionsOfAccount(accountId: AccountId, getSinglePosition: (accountId: AccountId, underlyingCurrency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId) => Promise): Promise>; getLendPositionsOfAccount(accountId: AccountId): Promise>; getBorrowPositionsOfAccount(accountId: AccountId): Promise>; private _checkLoanAssetDataAvailability; getLendingStats(lendPositions: Array, borrowPositions: Array, loanAssets: TickerToData): LendingStats; _getLendApy(underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise; _getBorrowApy(underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise; _getTotalLiquidityCapacityAndBorrows(underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<[MonetaryAmount, MonetaryAmount, MonetaryAmount]>; _calculateLiquidityAndCapacityAmounts(underlyingCurrency: CurrencyExt, lendTokenTotalIssuance: Big, totalBorrows: Big, exchangeRate: Big): [MonetaryAmount, MonetaryAmount]; /** * Get the lend and borrow annual rewards for 1 UNIT of a given underlying currency id. * * @param underlyingCurrencyId currency id to get reward amounts for. * @returns Annualized lend and borrow rewards for 1 unit of the given underlying currency. */ _getLendAndBorrowYearlyRewardAmount(underlyingCurrencyId: InterbtcPrimitivesCurrencyId, totalLiquidity: Big, totalBorrows: Big): Promise<[Big, Big]>; _getRewardCurrency(): Promise; _getSubsidyReward(amount: Big, rewardCurrency: CurrencyExt): MonetaryAmount | null; _getLoanAsset(underlyingCurrencyId: InterbtcPrimitivesCurrencyId, marketData: LoansMarket): Promise<[CurrencyExt, LoanAsset]>; getLoanAssets(): Promise>; _getLatestSupplyIndex(underlyingCurrencyId: CurrencyId, lendTokenId: CurrencyId, currentBlockNumber: number): Promise; _getAccruedSupplyReward(accountId: AccountId, underlyingCurrencyId: CurrencyId, lendTokenId: CurrencyId, rewardCurrency: CurrencyExt, currentBlock: number): Promise>; _getLatestBorrowIndex(underlyingCurrencyId: CurrencyId, currentBlockNumber: number): Promise; _getAccruedBorrowReward(accountId: AccountId, underlyingCurrencyId: CurrencyId, rewardCurrency: CurrencyExt, currentBlock: number): Promise>; getAccruedRewardsOfAccount(accountId: AccountId): Promise; _checkMarketState(currency: CurrencyExt, action: string): Promise; lend(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; withdraw(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; withdrawAll(underlyingCurrency: CurrencyExt): Promise; enableAsCollateral(underlyingCurrency: CurrencyExt): Promise; disableAsCollateral(underlyingCurrency: CurrencyExt): Promise; claimAllSubsidyRewards(): ExtrinsicData; borrow(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; repay(underlyingCurrency: CurrencyExt, amount: MonetaryAmount): Promise; repayAll(underlyingCurrency: CurrencyExt): Promise; liquidateBorrowPosition(borrower: AccountId, liquidationCurrency: CurrencyExt, repayAmount: MonetaryAmount, collateralCurrency: CurrencyExt): ExtrinsicData; }