import { AccountId } from "@polkadot/types/interfaces";
import { MonetaryAmount } from "@interlay/monetary-js";
import { BorrowPosition, CurrencyExt, LoanAsset, LendPosition, TickerToData, LendToken, LoanMarket, SubsidyReward, LoanPosition } from "../types";
import { AssetRegistryAPI } from "./asset-registry";
import { ApiPromise } from "@polkadot/api";
import Big from "big.js";
import { InterbtcPrimitivesCurrencyId, PalletLoansMarket } 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>>;
    /**
     * 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.
     *        await this._checkMarketState(underlyingCurrency, "withdraw");
     * @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 reward for specified currency.
     *
     * @param currency Currency for which to claim reward.
     * @throws If no position exists for `currency` and account.
     */
    claimSubsidyReward(currency: CurrencyExt): Promise<void>;
    /**
     * Claim subsidy rewards for all currencies available for account.
     */
    claimAllSubsidyRewards(): Promise<void>;
    /**
     * Borrow currency from the protocol.
     *
     * @param currency Currency to borrow.
     * @param amount Amount of currency to borrow.
     * @throws If there is no active market for `currency`.
     * @throws If there is not enough collateral provided by account for
     * `amount` of `currency`.
     * @throws If `amount` is higher than available amount of `currency`
     * in the protocol.
     */
    borrow(currency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    /**
     * Repay borrowed loan.
     *
     * @param currency Currency to repay.
     * @param amount Amount of currency to repay.
     * @throws If there is no active market for `currency`.
     * @throws If `amount` is higher than available balance of account.
     * @throws If `amount` is higher than outstanding loan.
     */
    repay(currency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    /**
     * Same as `repay`, but repays full loan.
     *
     * @param currency Currency to repay.
     */
    repayAll(currency: CurrencyExt): Promise<void>;
}
export declare class DefaultLoansAPI implements LoansAPI {
    private api;
    private assetRegistryAPI;
    private transactionAPI;
    constructor(api: ApiPromise, assetRegistryAPI: AssetRegistryAPI, transactionAPI: TransactionAPI);
    static parseMarket(market: PalletLoansMarket): LoanMarket;
    getLoansMarketsEntries(): Promise<[StorageKey<[InterbtcPrimitivesCurrencyId]>, Option<PalletLoansMarket>][]>;
    static getLendTokenFromUnderlyingCurrency(currency: CurrencyExt, lendTokenId: InterbtcPrimitivesCurrencyId): LendToken;
    getUnderlyingCurrencyFromLendTokenId(lendTokenId: InterbtcPrimitivesCurrencyId): Promise<CurrencyExt>;
    getLendTokenIdFromUnderlyingCurrency(currency: CurrencyExt): Promise<InterbtcPrimitivesCurrencyId>;
    convertLendTokenToUnderlyingCurrency(amount: Big, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<Big>;
    getLendAmountInUnderlyingCurrency(accountId: AccountId, lendTokenId: InterbtcPrimitivesCurrencyId, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<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>;
    _getTotalLiquidityAndCapacity(underlyingCurrency: CurrencyExt, underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<[MonetaryAmount<CurrencyExt>, MonetaryAmount<CurrencyExt>]>;
    _getLendAndBorrowYearlyRewardAmount(underlyingCurrencyId: InterbtcPrimitivesCurrencyId): Promise<[Big, Big]>;
    _constructSubsidyReward(amount: Big, currency: CurrencyExt): SubsidyReward | null;
    _getLoanAsset(underlyingCurrencyId: InterbtcPrimitivesCurrencyId, marketData: PalletLoansMarket): Promise<[CurrencyExt, LoanAsset]>;
    getLoanAssets(): Promise<TickerToData<LoanAsset>>;
    _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>;
    claimSubsidyReward(currency: CurrencyExt): Promise<void>;
    claimAllSubsidyRewards(): Promise<void>;
    borrow(currency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    repay(currency: CurrencyExt, amount: MonetaryAmount<CurrencyExt>): Promise<void>;
    repayAll(currency: CurrencyExt): Promise<void>;
}
