import { ApiPromise } from "@polkadot/api"; import { AccountId, BlockHash } from "@polkadot/types/interfaces"; import Big from "big.js"; import { MonetaryAmount, Currency } from "@interlay/monetary-js"; import { InterbtcPrimitivesVaultId, VaultRegistryVault } from "@polkadot/types/lookup"; import { TokensAPI } from "./tokens"; import { OracleAPI } from "./oracle"; import { FeeAPI } from "./fee"; import { TransactionAPI } from "./transaction"; import { ElectrsAPI } from "../external"; import { VaultExt, SystemVaultExt, CollateralCurrencyExt, WrappedCurrency, GovernanceCurrency, ExtrinsicData } from "../types"; import { RewardsAPI } from "./rewards"; import { SystemAPI } from "./index"; import { ApiTypes, AugmentedEvent, SubmittableExtrinsic } from "@polkadot/api/types"; import { ISubmittableResult, AnyTuple } from "@polkadot/types/types"; /** * @category BTC Bridge */ export interface VaultsAPI { /** * @returns An array containing the vaults with non-zero backing collateral */ list(atBlock?: BlockHash): Promise; /** * Get a vault by account ID and collateral currency. * Does not reject if the vault does not exist, but returns null instead. * @param vaultAccountId The ID of the vault to fetch * @param collateralCurrency Collateral used by vault * @returns A vault object, or null if no vault with the given ID and currency pair exists */ getOrNull(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; /** * Get a vault by account ID and collateral currency. Rejects if no vault exists. * @param vaultAccountId The ID of the vault to fetch * @param collateralCurrency Collateral used by vault * @returns A vault object, rejects if no vault with the given ID and currency pair exists */ get(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; /** * Get the collateralization of a single vault measured by dividing the value of issued (wrapped) tokens * by the value of total locked collateral. * * @remarks Undefined collateralization is handled as infinite collateralization in the UI. * If no tokens have been issued, the `collateralFunds / issuedFunds` ratio divides by zero, * which means collateralization is infinite. * @param vaultAccountId the vault account id * @param collateralCurrency Collateral used by vault * @param newCollateral use this instead of the vault's actual collateral * @param onlyIssued optional, defaults to `false`. Specifies whether the collateralization * should only include the issued tokens, leaving out unsettled ("to-be-issued") tokens * @returns the vault collateralization */ getVaultCollateralization(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt, newCollateral?: MonetaryAmount, onlyIssued?: boolean): Promise; /** * Get the amount of collateral required for the given vault to be at the * current SecureCollateralThreshold with the current exchange rate * * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @returns The required collateral the vault needs to deposit to stay * above the threshold limit */ getRequiredCollateralForVault(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; /** * Get the minimum secured collateral amount required to activate a vault * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @returns the minimum collateral to register a vault */ getMinimumCollateral(collateralCurrency: CollateralCurrencyExt): Promise>; /** * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset * @returns The amount of wrapped tokens issued by the given vault */ getIssuedAmount(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; /** * @returns The total amount of wrapped tokens issued by the vaults */ getTotalIssuedAmount(): Promise>; /** * @returns The total amount of wrapped tokens that can be issued, considering the collateral * locked by the vaults */ getTotalIssuableAmount(): Promise>; /** * @param collateral Amount of collateral to calculate issuable capacity for * @returns Issuable amount by the vault, given the collateral amount */ calculateCapacity(collateral: MonetaryAmount): Promise>; /** * @param amount Wrapped tokens amount to issue * @returns A vault that has sufficient collateral to issue the given amount */ selectRandomVaultIssue(amount: MonetaryAmount): Promise; /** * @param amount Wrapped tokens amount to redeem * @returns A vault that has issued sufficient wrapped tokens to redeem the given amount */ selectRandomVaultRedeem(amount: MonetaryAmount): Promise; /** * @returns Vaults below the premium redeem threshold, sorted in descending order of their redeemable tokens */ getPremiumRedeemVaults(): Promise>>; /** * @returns Vaults with issuable tokens, not sorted in any particular order. * @remarks The result is not sorted as an attempt to randomize the assignment of requests to vaults. */ getVaultsWithIssuableTokens(): Promise>>; /** * @returns Vaults with redeemable tokens, sorted in descending order. */ getVaultsWithRedeemableTokens(): Promise>>; /** * @param vaultId The vault ID * @param btcTxId ID of the Bitcoin transaction to check * @returns A bollean value */ isVaultFlaggedForTheft(vaultId: InterbtcPrimitivesVaultId, btcTxId: string): Promise; /** * @param collateralCurrency * @returns The lower bound for vault collateralization. * If a Vault’s collateral rate * drops below this, automatic liquidation (forced Redeem) is triggered. */ getLiquidationCollateralThreshold(collateralCurrency: CollateralCurrencyExt): Promise; /** * @param collateralCurrency * @returns The collateral rate at which users receive * a premium allocated from the Vault’s collateral, when performing a redeem with this Vault. */ getPremiumRedeemThreshold(collateralCurrency: CollateralCurrencyExt): Promise; /** * Get the global secure collateral threshold. * @param collateralCurrency * @returns The global over-collateralization rate for collateral locked * by Vaults, necessary for issuing wrapped tokens */ getSecureCollateralThreshold(collateralCurrency: CollateralCurrencyExt): Promise; /** * Get the total APY for a vault based on the income in wrapped and collateral tokens * divided by the locked collateral. * * @note this does not account for interest compounding * * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @param governanceCurrency The governance currency we're using for block rewards * @returns the APY as a percentage string */ getAPY(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; /** * Gets the estimated APY for just the block rewards (in governance tokens). * @param vaultAccountId: the vault account ID * @param collateralCurrency: the vault's collateral currency * @returns the APY as a percentage */ getBlockRewardAPY(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; /** * @returns Fee that a Vault has to pay, as a percentage, if it fails to execute * redeem or replace requests (for redeem, on top of the slashed wrapped-token-to-collateral * value of the request). The fee is paid in collateral currency based on the wrapped token * amount at the current exchange rate. */ getPunishmentFee(): Promise; /** * Build withdraw collateral extrinsic (transaction) without sending it. * * @param amount The amount of collateral to withdraw * @returns A withdraw collateral submittable extrinsic as promise. */ buildWithdrawCollateralExtrinsic(amount: MonetaryAmount): Promise>; /** * @param amount The amount of collateral to withdraw * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ withdrawCollateral(amount: MonetaryAmount): Promise; /** * Build withdraw collateral extrinsic (transaction) without sending it. * * @param collateralCurrency The collateral currency for which to withdraw all * @returns A withdraw collateral submittable extrinsic as promise. */ buildWithdrawAllCollateralExtrinsic(collateralCurrency: CollateralCurrencyExt): Promise>; /** * @param collateralCurrency The collateral currency for which to withdraw all * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ withdrawAllCollateral(collateralCurrency: CollateralCurrencyExt): Promise; /** * Build deposit collateral extrinsic (transaction) without sending it. * * @param amount The amount of extra collateral to lock * @returns A deposit collateral submittable extrinsic. */ buildDepositCollateralExtrinsic(amount: MonetaryAmount): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * @param amount The amount of extra collateral to lock * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ depositCollateral(amount: MonetaryAmount): ExtrinsicData; /** * @param collateralCurrency * @returns A vault object representing the liquidation vault */ getLiquidationVault(collateralCurrency: CollateralCurrencyExt): Promise; /** * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @returns The collateral of a vault, taking slashes into account. */ getCollateral(vaultId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; /** * Returns issuable amount for a given vault * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @returns The issuable amount of a vault */ getIssuableTokensFromVault(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; /** * @param collateralCurrency The collateral currency specification, a `Monetary.js` object or `ForeignAsset` * @returns The maximum collateral a vault can accept as nomination, as a ratio of its own collateral */ getMaxNominationRatio(collateralCurrency: CollateralCurrencyExt): Promise; /** * @param vaultAccountId The vault account ID * @param collateralCurrency The currency specification, a `Monetary.js` object or `ForeignAsset` * @returns Staking capacity, as a collateral currency (e.g. DOT) */ getStakingCapacity(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; /** * @param vaultId Vault ID object * @param nonce Nonce of the staking pool * @returns The entire collateral backing a vault's issued tokens. */ computeBackingCollateral(vaultId: InterbtcPrimitivesVaultId, nonce?: number): Promise>; /** * @returns The wrapped currency issued by the vaults */ getWrappedCurrency(): WrappedCurrency; /** * Compute the total reward, including the staking (local) pool and the rewards (global) pool * @param vaultAccountId The vault ID whose reward pool to check * @param vaultCollateral Collateral used by the vault. This is the currency used as * stake in the `staking` and `rewards` pools. * @param rewardCurrency The reward currency, e.g. kBTC, KINT, interBTC, INTR * @returns A Monetary.js amount object, representing the total reward in the given currency */ computeReward(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt, rewardCurrency: Currency): Promise>; /** * @param vaultAccountId The vault ID whose reward pool to check * @param vaultCollateral Collateral used by the vault * @param rewardCurrency The fee reward currency * @returns The total reward collected by the vault */ getWrappedReward(vaultAccountId: AccountId, vaultCollateral: CollateralCurrencyExt, rewardCurrency: WrappedCurrency): Promise>; /** * @param vaultAccountId The vault ID whose reward pool to check * @param vaultCollateral Collateral used by the vault * @param governanceCurrency The fee reward currency * @returns The total reward collected by the vault */ getGovernanceReward(vaultAccountId: AccountId, vaultCollateral: CollateralCurrencyExt, governanceCurrency: GovernanceCurrency): Promise>; /** * Build accept new issues extrinsic without sending it. * * @param collateralCurrency the collateral currency for which to change the accepting status, * @param acceptNewIssues Boolean denoting whether issuing should be enabled or not * @returns An accept new issues submittable extrinsic. */ buildAcceptNewIssuesExtrinsic(collateralCurrency: CollateralCurrencyExt, acceptNewIssues: boolean): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Enables or disables issue requests for given vault * @param vaultId The vault ID whose issuing will be toggled * @param acceptNewIssues Boolean denoting whether issuing should be enabled or not * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ toggleIssueRequests(vaultId: InterbtcPrimitivesVaultId, acceptNewIssues: boolean): Promise; /** * Build extrinsic to register a public key. * * This extrinsic can be used together with a register vault extrinsic (see: {@link buildRegisterVaultExtrinsic}) * to register the first vault for the logged in account id. * * Registering the public key should only be done once per account id when it is not associated with a running vault, yet. * * @param publicKey The BTC public key of the vault to derive deposit keys with * the {@link https://spec.interlay.io/security_performance/xclaim-security.html#okd | On-Chain Key Derivation Scheme}. * @returns A register vault submittable extrinsic. */ buildRegisterPublicKeyExtrinsic(publicKey: string): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Build extrinsic to register a new vault. * * @param collateralAmount The collateral amount to register the vault with - in the new collateral currency. * @returns A register vault submittable extrinsic. */ buildRegisterVaultExtrinsic(collateralAmount: MonetaryAmount): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Registers a new vault for the current account ID with a new collateral amount. * Only applicable if the connected account ID already has a running vault with a different collateral currency. * * Rejects with an Error if unable to register. * * @param collateralAmount The collateral amount to register the vault with - in the new collateral currency * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ registerNewCollateralVault(collateralAmount: MonetaryAmount): ExtrinsicData; /** * Get the target exchange rate at which a vault will be forced to liquidate, given its * current locked collateral and issued as well as to be issued tokens. * * @param vaultAccountId The vault's account ID * @param collateralCurrency The collateral currency for the vault with the account id above * @returns The theoretical collateral per wrapped currency rate below which the vault would be liquidated. * Returns undefined if a value cannot be calculated, eg. if the vault has no issued tokens. */ getExchangeRateForLiquidation(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; } export declare const NO_LIQUIDATION_VAULT_FOUND_REJECTION = "No liquidation vault found"; export declare class DefaultVaultsAPI implements VaultsAPI { private api; private electrsAPI; private wrappedCurrency; private governanceCurrency; private tokensAPI; private oracleAPI; private feeAPI; private rewardsAPI; private systemAPI; private transactionAPI; constructor(api: ApiPromise, electrsAPI: ElectrsAPI, wrappedCurrency: WrappedCurrency, governanceCurrency: GovernanceCurrency, tokensAPI: TokensAPI, oracleAPI: OracleAPI, feeAPI: FeeAPI, rewardsAPI: RewardsAPI, systemAPI: SystemAPI, transactionAPI: TransactionAPI); getWrappedCurrency(): WrappedCurrency; registerNewCollateralVault(collateralAmount: MonetaryAmount): ExtrinsicData; getRegisterVaultEvent(): AugmentedEvent; buildRegisterVaultExtrinsic(collateralAmount: MonetaryAmount): SubmittableExtrinsic<"promise", ISubmittableResult>; buildRegisterPublicKeyExtrinsic(publicKey: string): SubmittableExtrinsic<"promise", ISubmittableResult>; buildWithdrawCollateralExtrinsic(amount: MonetaryAmount): Promise>; withdrawCollateral(amount: MonetaryAmount): Promise; buildWithdrawAllCollateralExtrinsic(collateralCurrency: CollateralCurrencyExt): Promise>; withdrawAllCollateral(collateralCurrency: CollateralCurrencyExt): Promise; buildDepositCollateralExtrinsic(amount: MonetaryAmount): SubmittableExtrinsic<"promise", ISubmittableResult>; depositCollateral(amount: MonetaryAmount): ExtrinsicData; list(atBlock?: BlockHash): Promise; getOrNull(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; get(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; getCollateral(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; getMinimumCollateral(collateralCurrency: CollateralCurrencyExt): Promise>; getMaxNominationRatio(collateralCurrency: CollateralCurrencyExt): Promise; computeBackingCollateral(vaultId: InterbtcPrimitivesVaultId, nonce?: number): Promise>; backingCollateralProportion(vaultAccountId: AccountId, nominatorId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; getBlockRewardAPY(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; computeReward(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt, rewardCurrency: Currency): Promise>; getWrappedReward(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; getGovernanceReward(vaultAccountId: AccountId, vaultCollateral: CollateralCurrencyExt, governanceCurrency: GovernanceCurrency): Promise>; getStakingCapacity(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; getLiquidationVault(collateralCurrency: CollateralCurrencyExt): Promise; private isNoTokensIssuedError; isBelowPremiumThreshold(vaultId: InterbtcPrimitivesVaultId): Promise; getVaultCollateralization(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt, newCollateral?: MonetaryAmount, onlyIssued?: boolean): Promise; getCollateralizationFromVault(vaultId: InterbtcPrimitivesVaultId, onlyIssued?: boolean): Promise; getCollateralizationFromVaultAndCollateral(vaultId: InterbtcPrimitivesVaultId, newCollateral: MonetaryAmount, onlyIssued: boolean): Promise; getSystemCollateralization(): Promise; getRequiredCollateralForVault(vaultAccountId: AccountId, currency: CollateralCurrencyExt): Promise>; getRequiredCollateralForWrapped(wrappedAmount: MonetaryAmount, currency: CollateralCurrencyExt): Promise>; getIssuedAmount(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; getTotalIssuedAmount(): Promise>; getTotalIssuableAmount(): Promise>; calculateCapacity(collateral: MonetaryAmount): Promise>; getIssuableTokensFromVault(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise>; selectRandomVaultIssue(amount: MonetaryAmount): Promise; selectRandomVaultRedeem(amount: MonetaryAmount): Promise; getPremiumRedeemVaults(): Promise>>; getVaultsWithIssuableTokens(): Promise>>; private isVaultEligibleForRedeem; private getVaultsEligibleForRedeeming; getVaultsWithRedeemableTokens(): Promise>>; isVaultFlaggedForTheft(vaultId: InterbtcPrimitivesVaultId, btcTxId: string): Promise; getLiquidationCollateralThreshold(collateralCurrency: CollateralCurrencyExt): Promise; getPremiumRedeemThreshold(collateralCurrency: CollateralCurrencyExt): Promise; getSecureCollateralThreshold(collateralCurrency: CollateralCurrencyExt): Promise; getAPY(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; getPunishmentFee(): Promise; private parseVaultStatus; parseVault(vault: VaultRegistryVault): Promise; buildAcceptNewIssuesExtrinsic(collateralCurrency: CollateralCurrencyExt, acceptNewIssues: boolean): SubmittableExtrinsic<"promise", ISubmittableResult>; toggleIssueRequests(vaultId: InterbtcPrimitivesVaultId, acceptNewIssues: boolean): Promise; getExchangeRateForLiquidation(vaultAccountId: AccountId, collateralCurrency: CollateralCurrencyExt): Promise; }