import { AccountId } from "@polkadot/types/interfaces";
import { MonetaryAmount } from "@interlay/monetary-js";
import { BorrowPosition, CurrencyExt, LoanAsset, LendPosition, TickerToData, LendToken, LoanPosition } from "../types";
import { AssetRegistryAPI } from "./asset-registry";
import { ApiPromise } from "@polkadot/api";
import Big from "big.js";
import { InterbtcPrimitivesCurrencyId, LoansMarket } from "@polkadot/types/lookup";
import { StorageKey, Option } from "@polkadot/types";
import { TransactionAPI } from "./transaction";
/**
 * @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<Array<LendPosition>>;
    /**
     * 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<Array<BorrowPosition>>;
    /**
     * 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<TickerToData<LoanAsset>>;
    /**
     * Get underlying currency of lend token id,
     *
     * @param lendTokenId Currency id of the lend token to get currency from
     * @returns Underlying CurrencyExt for provided lend token
     */
    getUnderlyingCurrencyFromLendTokenId(lendTokenId: InterbtcPrimitivesCurrencyId): Promise<CurrencyExt>;
    /**
     * Get all lend token currencies.
     *
     * @returns Array of all LendToken currencies.
     */
    getLendTokens(): Promise<Array<LendToken>>;
    /**
     * Get accrued subsidy rewards amount for the account
     *
     * @param accountId Account to get rewards for
     * @returns {MonetaryAmount<CurrencyExt>} Amount how much rewards the account can claim.
     */
    getAccruedRewardsOfAccount(accountId: AccountId): Promise<MonetaryAmount<CurrencyExt>>;
    /**
     * Lend currency to protocol for borrowing.
     *
     * @param {CurrencyExt} underlyingCurrency  Currency to lend.
     * @param {MonetaryAmount<CurrencyExt>} amount Amount of currency to lend.
     * @throws If there is not active market for `underlyingCurrency`.
     * @throws If `amount` is exceeding available balance of account.
     */
    lend(underlyingCurrency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    /**
     * Withdraw previously lent currency from protocol.
     *
     * @param {CurrencyExt} underlyingCurrency Currency to witdhraw.
     * @param {MonetaryAmount<CurrencyExt>} amount Amount of currency to withdraw.
     * @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<CurrencyExt>): Promise<void>;
    /**
     * Same as `withdraw`, but exits full position.
     *
     * @param underlyingCurrency Currency to fully withdraw.
     */
    withdrawAll(underlyingCurrency: CurrencyExt): Promise<void>;
    /**
     * Enable lend position of account as collateral for borrowing.
     *
     * @param underlyingCurrency Currency to enable as collateral.
     * @throws If there is no existing lend position for `currency`.
     */
    enableAsCollateral(underlyingCurrency: CurrencyExt): Promise<void>;
    /**
     * Enable lend position of account as collateral for borrowing.
     *
     * @param underlyingCurrency Currency to enable as collateral.
     * @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<void>;
    /**
     * Claim subsidy rewards for all markets available for account.
     */
    claimAllSubsidyRewards(): Promise<void>;
    /**
     * Borrow currency from the protocol.
     *
     * @param underlyingCurrency Currency to borrow.
     * @param amount Amount of currency to borrow.
     * @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<CurrencyExt>): Promise<void>;
    /**
     * Repay borrowed loan.
     *
     * @param underlyingCurrency Currency to repay.
     * @param amount Amount of currency to repay.
     * @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<CurrencyExt>): Promise<void>;
    /**
     * Same as `repay`, but repays full loan.
     *
     * @param underlyingCurrency Currency to repay.
     */
    repayAll(underlyingCurrency: CurrencyExt): Promise<void>;
    /**
     * 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.
     */
    liquidateBorrowPosition(borrower: AccountId, liquidationCurrency: CurrencyExt, repayAmount: MonetaryAmount<CurrencyExt>, collateralCurrency: CurrencyExt): Promise<void>;
}
export declare class DefaultLoansAPI implements LoansAPI {
    private api;
    private assetRegistryAPI;
    private transactionAPI;
    constructor(api: ApiPromise, assetRegistryAPI: AssetRegistryAPI, transactionAPI: TransactionAPI);
    getLoansMarketsEntries(): Promise<[StorageKey<[InterbtcPrimitivesCurrencyId]>, Option<LoansMarket>][]>;
    static getLendTokenFromUnderlyingCurrency(currency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId): LendToken;
    getUnderlyingCurrencyFromLendTokenId(lendTokenId: InterbtcPrimitivesCurrencyId): Promise<CurrencyExt>;
    getLendTokenIdFromUnderlyingCurrency(currency: CurrencyExt): Promise<InterbtcPrimitivesCurrencyId>;
    convertLendTokenToUnderlyingCurrency(amount: Big, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<Big>;
    /**
     * 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<LendToken[]>;
    _getLendPosition(accountId: AccountId, underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId, lendTokenId: InterbtcPrimitivesCurrencyId): Promise<LendPosition | null>;
    _calculateAccumulatedDebt(borrowedAmount: Big, snapshotBorrowIndex: Big, currentBorrowIndex: Big): Big;
    _getBorrowPosition(accountId: AccountId, underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<BorrowPosition | null>;
    _getPositionsOfAccount<Position extends LoanPosition>(accountId: AccountId, getSinglePosition: (accountId: AccountId, underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId, lendTokenId: InterbtcPrimitivesCurrencyId) => Promise<Position | null>): Promise<Array<Position>>;
    getLendPositionsOfAccount(accountId: AccountId): Promise<Array<LendPosition>>;
    getBorrowPositionsOfAccount(accountId: AccountId): Promise<Array<BorrowPosition>>;
    _getLendApy(underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<Big>;
    _getBorrowApy(underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<Big>;
    _getTotalLiquidityCapacityAndBorrows(underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>;
    _calculateLiquidityAndCapacityAmounts(underlyingCurrency: CurrencyExt, lendTokenTotalIssuance: Big, totalBorrows: Big, exchangeRate: Big): [MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>];
    /**
     * 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]>;
    _calculateAnnualizedRewardAmount(amountPerBlock: Big, blockTimeMs: number): Big;
    _getRewardCurrency(): Promise<CurrencyExt>;
    _getSubsidyReward(amount: Big, rewardCurrency: CurrencyExt): MonetaryAmount<CurrencyExt> | null;
    _getLoanAsset(underlyingCurrencyId: InterbtcPrimitivesCurrencyId, marketData: LoansMarket): Promise<[CurrencyExt, LoanAsset]>;
    getLoanAssets(): Promise<TickerToData<LoanAsset>>;
    getAccruedRewardsOfAccount(accountId: AccountId): Promise<MonetaryAmount<CurrencyExt>>;
    _checkMarketState(currency: CurrencyExt, action: string): Promise<void>;
    lend(underlyingCurrency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    withdraw(underlyingCurrency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    withdrawAll(underlyingCurrency: CurrencyExt): Promise<void>;
    enableAsCollateral(underlyingCurrency: CurrencyExt): Promise<void>;
    disableAsCollateral(underlyingCurrency: CurrencyExt): Promise<void>;
    claimAllSubsidyRewards(): Promise<void>;
    borrow(underlyingCurrency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    repay(underlyingCurrency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    repayAll(underlyingCurrency: CurrencyExt): Promise<void>;
    liquidateBorrowPosition(borrower: AccountId, liquidationCurrency: CurrencyExt, repayAmount: MonetaryAmount<CurrencyExt>, collateralCurrency: CurrencyExt): Promise<void>;
}
