import { ApiPromise } from "@polkadot/api"; import { AccountId, H256 } from "@polkadot/types/interfaces"; import { AddressOrPair } from "@polkadot/api/types"; import Big from "big.js"; import BN from "bn.js"; import { Network } from "bitcoinjs-lib"; import { Vault, SystemVault } from "../interfaces/default"; import { CollateralAPI } from "./collateral"; import { OracleAPI } from "./oracle"; import { IssueRequestExt } from "./issue"; import { RedeemRequestExt } from "./redeem"; import { ReplaceRequestExt } from "./replace"; import { FeeAPI } from "./fee"; import { DefaultTransactionAPI, TransactionAPI } from "./transaction"; export interface WalletExt { publicKey: string; btcAddress?: string; addresses: Array; } export interface VaultExt extends Omit { wallet: WalletExt; } export declare function encodeVault(vault: Vault, network: Network): VaultExt; /** * @category PolkaBTC Bridge * The type Big represents DOT or PolkaBTC denominations, * while the type BN represents Planck or Satoshi denominations. */ export interface VaultsAPI extends TransactionAPI { /** * @returns An array containing the vaults with non-zero backing collateral */ list(): Promise; /** * Fetch the issue requests associated with a vault * * @param vaultId - The AccountId of the vault used to filter issue requests * @returns A map with issue ids to issue requests involving said vault */ mapIssueRequests(vaultId: AccountId): Promise>; /** * Fetch the redeem requests associated with a vault * * @param vaultId - The AccountId of the vault used to filter redeem requests * @returns A map with redeem ids to redeem requests involving said vault */ mapRedeemRequests(vaultId: AccountId): Promise>; /** * Fetch the replace requests associated with a vault. In the returned requests, * the vault is either the replaced or the replacing one. * * @param vaultId - The AccountId of the vault used to filter replace requests * @returns A map with replace ids to replace requests involving said vault as new vault and old vault */ mapReplaceRequests(vaultId: AccountId): Promise>; /** * @param vaultId The ID of the vault to fetch * @returns A vault object */ get(vaultId: AccountId): Promise; /** * Get the collateralization of a single vault measured by the amount of issued PolkaBTC * divided by the total locked DOT 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 vaultId the vault account id * @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(vaultId: AccountId, newCollateral?: Big, onlyIssued?: boolean): Promise; /** * Get the total system collateralization measured by the amount of issued PolkaBTC * divided by the total locked DOT collateral. * * @returns The total system collateralization */ getSystemCollateralization(): Promise; /** * Get the amount of collateral required for the given vault to be at the * current SecureCollateralThreshold with the current exchange rate * * @param vaultId The vault account ID * @returns The required collateral the vault needs to deposit to stay * above the threshold limit */ getRequiredCollateralForVault(vaultId: AccountId): Promise; /** * Get the minimum amount of collateral required for the given amount of btc * with the current threshold and exchange rate * * @param amount Amount to issue, denominated in BTC * @returns The required collateral for issuing, denominated in DOT */ getRequiredCollateralForWrapped(amount: Big): Promise; /** * @param vaultId The vault account ID * @returns The amount of PolkaBTC issued by the given vault */ getIssuedAmount(vaultId: AccountId): Promise; /** * @param vaultId The vault account ID * @returns The amount of PolkaBTC issuable by this vault */ getIssuableAmount(vaultId: AccountId): Promise; /** * @returns The total amount of PolkaBTC issued by the vaults */ getTotalIssuedAmount(): Promise; /** * @returns The total amount of PolkaBTC that can be issued, considering the DOT * locked by the vaults */ getTotalIssuableAmount(): Promise; /** * @param amount PolkaBTC amount to issue * @returns A vault that has sufficient DOT collateral to issue the given PolkaBTC amount */ selectRandomVaultIssue(amount: Big): Promise; /** * @param amount PolkaBTC amount to redeem * @returns A vault that has issued sufficient PolkaBTC to redeem the given PolkaBTC amount */ selectRandomVaultRedeem(amount: Big): Promise; /** * @returns Vaults below the premium redeem threshold, sorted in descending order of their redeemable tokens */ getPremiumRedeemVaults(): Promise>; /** * @returns Vaults with issuable tokens, sorted in descending order of this value */ getVaultsWithIssuableTokens(): Promise>; /** * @returns Vaults with redeemable tokens, sorted in descending order of this value */ getVaultsWithRedeemableTokens(): Promise>; /** * @param vaultId The vault account ID * @returns A bollean value */ isVaultFlaggedForTheft(vaultId: AccountId): Promise; /** * @returns The lower bound for the collateral rate in PolkaBTC. * If a Vault’s collateral rate * drops below this, automatic liquidation (forced Redeem) is triggered. */ getLiquidationCollateralThreshold(): Promise; /** * @returns The collateral rate of Vaults at which users receive * a premium in DOT, allocated from the * Vault’s collateral, when performing a redeem with this Vault. */ getPremiumRedeemThreshold(): Promise; /** * @returns The over-collateralization rate for DOT collateral locked * by Vaults, necessary for issuing PolkaBTC */ getSecureCollateralThreshold(): Promise; /** * @param vaultId The vault account ID * @returns The total PolkaBTC reward collected by the vault */ getFeesWrapped(vaultId: AccountId): Promise; /** * @param vaultId The vault account ID * @returns The total DOT reward collected by the vault */ getFeesCollateral(vaultId: AccountId): Promise; /** * Get the total APY for a vault based on the income in PolkaBTC and DOT * divided by the locked DOT. * * @note this does not account for interest compounding * * @param vaultId the id of the vault * @returns the APY as a percentage string */ getAPY(vaultId: AccountId): Promise; /** * @param vaultId The vault account ID * @returns The SLA score of the given vault, an integer in the range [0, MaxSLA] */ getSLA(vaultId: AccountId): Promise; /** * @returns The maximum SLA score, a positive integer */ getMaxSLA(): Promise; /** * @returns Fee that a Vault has to pay if it fails to execute redeem or replace requests * (for redeem, on top of the slashed BTC-in-DOT value of the request). The fee is * paid in DOT based on the PolkaBTC amount at the current exchange rate. */ getPunishmentFee(): Promise; /** * Set an account to use when sending transactions from this API * @param account Keyring account */ setAccount(account: AddressOrPair): void; /** * @param amount Value to withdraw from staking */ withdrawCollateral(amount: Big): Promise; /** * @param amount Value to increase stake by */ lockAdditionalCollateral(amount: Big): Promise; /** * @returns The account id of the liquidation vault */ getLiquidationVaultId(): Promise; /** * @returns A vault object representing the liquidation vault */ getLiquidationVault(): Promise; } export declare class DefaultVaultsAPI extends DefaultTransactionAPI implements VaultsAPI { granularity: number; private btcNetwork; collateralAPI: CollateralAPI; oracleAPI: OracleAPI; feeAPI: FeeAPI; constructor(api: ApiPromise, btcNetwork: Network, account?: AddressOrPair); register(planckCollateral: BN, publicKey: string): Promise; withdrawCollateral(amount: Big): Promise; lockAdditionalCollateral(amount: Big): Promise; list(): Promise; mapIssueRequests(vaultId: AccountId): Promise>; mapRedeemRequests(vaultId: AccountId): Promise>; mapReplaceRequests(vaultId: AccountId): Promise>; get(vaultId: AccountId): Promise; getLiquidationVaultId(): Promise; getLiquidationVault(): Promise; private isNoTokensIssuedError; getVaultCollateralization(vaultId: AccountId, newCollateral?: Big, onlyIssued?: boolean): Promise; getSystemCollateralization(): Promise; getRequiredCollateralForVault(vaultId: AccountId): Promise; getRequiredCollateralForWrapped(amount: Big): Promise; getIssuedAmount(vaultId: AccountId): Promise; getIssuableAmount(vaultId: AccountId): Promise; private getIssuedAmounts; getTotalIssuedAmount(): Promise; getTotalIssuableAmount(): Promise; private calculateCapacity; selectRandomVaultIssue(amount: Big): Promise; selectRandomVaultRedeem(amount: Big): Promise; getPremiumRedeemVaults(): Promise>; getVaultsWithIssuableTokens(): Promise>; getVaultsWithRedeemableTokens(): Promise>; isVaultFlaggedForTheft(vaultId: AccountId): Promise; getLiquidationCollateralThreshold(): Promise; getPremiumRedeemThreshold(): Promise; getSecureCollateralThreshold(): Promise; getFeesWrapped(vaultId: AccountId): Promise; getFeesCollateral(vaultId: AccountId): Promise; getAPY(vaultId: AccountId): Promise; getSLA(vaultId: AccountId): Promise; getMaxSLA(): Promise; /** * @returns Fee that a Vault has to pay if it fails to execute redeem or replace requests * (for redeem, on top of the slashed BTC-in-DOT value of the request). The fee is * paid in DOT based on the PolkaBTC amount at the current exchange rate. */ getPunishmentFee(): Promise; private wrapCurrency; private unwrapCurrency; }