import { ApiPromise } from "@polkadot/api"; import { SubmittableExtrinsic } from "@polkadot/api/submittable/types"; import { H256 } from "@polkadot/types/interfaces"; import { Network } from "bitcoinjs-lib"; import Big from "big.js"; import { Bitcoin, ExchangeRate, MonetaryAmount } from "@interlay/monetary-js"; import { ISubmittableResult } from "@polkadot/types/types"; import { InterbtcPrimitivesVaultId } from "@polkadot/types/lookup"; import { VaultsAPI } from "./vaults"; import { ElectrsAPI } from "../external"; import { TransactionAPI } from "./transaction"; import { OracleAPI } from "./oracle"; import { CollateralCurrencyExt, ExtrinsicData, Redeem, WrappedCurrency } from "../types"; import { SystemAPI } from "./system"; /** * @category BTC Bridge */ export interface RedeemAPI { /** * @returns An array containing the redeem requests */ list(): Promise; /** * Build a request redeem extrinsic (transaction) without sending it. * * @param vaultId ID of the vault to redeem with. * @param amount Wrapped token amount to redeem * @param btcAddress Bitcoin transaction ID * @returns A request redeem submittable extrinsic. */ buildRequestRedeemExtrinsic(vaultId: InterbtcPrimitivesVaultId, amount: MonetaryAmount, btcAddress: string): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Create a redeem request transaction * @param amount Wrapped token amount to redeem * @param btcAddressEnc Bitcoin address where the redeemed BTC should be sent * @param vaultId (optional) ID of the vault to redeem with. * @param atomic (optional) Whether the request should be handled atomically or not. Only makes a difference * if more than one vault is needed to fulfil it. Defaults to false. * @param availableVaults (optional) A list of all vaults usable for redeem. If not provided, will fetch from the parachain. * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ request(amount: MonetaryAmount, btcAddressEnc: string, vaultId?: InterbtcPrimitivesVaultId, atomic?: boolean, availableVaults?: Map>): Promise; /** * Create a batch of aggregated redeem transactions (to one or more vaults) * @param amountsPerVault A mapping of vaults to redeem from, and wrapped token amounts to redeem using each vault * @param btcAddressEnc Bitcoin address where the redeemed BTC should be sent * @param atomic Whether the issue request should be handled atomically or not. Only makes a difference if more than * one vault is needed to fulfil it. * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. * @throws Rejects the promise if none of the requests succeeded (or if at least one failed, when atomic=true). */ requestAdvanced(amountsPerVault: Map>, btcAddressEnc: string, atomic: boolean): ExtrinsicData; /** * Build a redeem execution extrinsic (transaction) without sending it. * * @param redeemId The ID returned by the issue request transaction * @param btcTxId Bitcoin transaction ID * @returns An execute redeem submittable extrinsic. */ buildExecuteRedeemExtrinsic(redeemId: string, btcTxId: string): Promise>; /** * Send a redeem execution transaction * @remarks If `txId` is not set, the `merkleProof` and `rawTx` must both be set. * * @param redeemId The ID generated by the redeem request transaction * @param btcTxId Bitcoin transaction ID * @returns {Promise} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ execute(requestId: string, btcTxId: string): Promise; /** * Build a cancel redeem extrinsic (transaction) without sending it. * * @param redeemId The ID returned by the redeem request transaction * @param reimburse In case of redeem failure: * - `false` = retry redeeming, with a different Vault * - `true` = accept reimbursement in wrapped token * @returns A cancel redeem submittable extrinsic. */ buildCancelRedeemExtrinsic(redeemId: string, reimburse: boolean): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Send a redeem cancellation transaction. After the redeem period has elapsed, * the redeemal request can be cancelled. As a result, the griefing collateral * of the vault will be slashed and sent to the redeemer * @param redeemId The ID returned by the redeem request transaction * @param reimburse (Optional) In case of redeem failure: * - (Default) `false` = retry redeeming, with a different Vault * - `true` = accept reimbursement in wrapped token * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ cancel(redeemId: string, reimburse?: boolean): ExtrinsicData; /** * @remarks Testnet utility function * @param blocks The time difference in number of blocks between a redeem request * is created and required completion time by a vault. * The redeem period has an upper limit to ensure the user gets their BTC in time * and to potentially punish a vault for inactivity or stealing BTC. * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ setRedeemPeriod(blocks: number): ExtrinsicData; /** * * @returns The time difference in number of blocks between a redeem request * is created and required completion time by a vault. * The redeem period has an upper limit to ensure the user gets their BTC in time * and to potentially punish a vault for inactivity or stealing BTC. */ getRedeemPeriod(): Promise; /** * @param redeemId The ID of the redeem request to fetch * @returns A redeem request object */ getRequestById(redeemId: H256 | string): Promise; getRequestsByIds(redeemIds: (H256 | string)[]): Promise; /** * @returns The minimum amount of wrapped tokens that is accepted for redeem requests; any lower values would * risk the bitcoin client to reject the payment */ getDustValue(): Promise>; /** * @returns The fee charged for redeeming. For instance, "0.005" stands for 0.5% */ getFeeRate(): Promise; /** * @param amount The amount of wrapped tokens for which to compute the redeem fees * @returns The fees */ getFeesToPay(amount: MonetaryAmount): Promise>; /** * @returns If users execute a redeem with a Vault flagged for premium redeem, * they can earn a premium, slashed from the Vault's collateral. * This value is a percentage of the redeemed amount. */ getPremiumRedeemFeeRate(): Promise; /** * Build liquidation redeem extrinsic (without sending it) to burn wrapped tokens for a premium * @param amount The amount of wrapped tokens to burn * @param collateralCurrency Liquidated collateral currency to use when burning wrapped tokens * @returns A liquidation redeem submittable extrinsic. */ buildLiquidationRedeemExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Burn wrapped tokens for a premium * @param amount The amount of wrapped tokens to burn * @param collateralCurrency Liquidated collateral currency to use when burning wrapped tokens * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ burn(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; /** * @param collateralCurrency Liquidated collateral currency to use when burning wrapped tokens * @returns The maximum amount of tokens that can be burned through a liquidation redeem */ getMaxBurnableTokens(collateralCurrency: CollateralCurrencyExt): Promise>; /** * @param collateralCurrency Currency whose exchange rate with BTC to fetch * @returns The exchange rate (collateral currency to wrapped token currency) * used when burning tokens */ getBurnExchangeRate(collateralCurrency: CollateralCurrencyExt): Promise>; /** * @returns The current inclusion fee based on the expected number of bytes * in the transaction, and the inclusion fee rate reported by the oracle */ getCurrentInclusionFee(): Promise>; } export declare class DefaultRedeemAPI implements RedeemAPI { private api; private btcNetwork; private electrsAPI; private wrappedCurrency; private vaultsAPI; private oracleAPI; private transactionAPI; private systemAPI; constructor(api: ApiPromise, btcNetwork: Network, electrsAPI: ElectrsAPI, wrappedCurrency: WrappedCurrency, vaultsAPI: VaultsAPI, oracleAPI: OracleAPI, transactionAPI: TransactionAPI, systemAPI: SystemAPI); request(amount: MonetaryAmount, btcAddressEnc: string, vaultId?: InterbtcPrimitivesVaultId, atomic?: boolean, cachedVaults?: Map>): Promise; buildRequestRedeemExtrinsic(vaultId: InterbtcPrimitivesVaultId, amount: MonetaryAmount, btcAddressEnc: string): SubmittableExtrinsic<"promise", ISubmittableResult>; requestAdvanced(amountsPerVault: Map>, btcAddressEnc: string, atomic: boolean): ExtrinsicData; buildExecuteRedeemExtrinsic(redeemId: string, btcTxId: string): Promise>; execute(requestId: string, btcTxId: string): Promise; buildCancelRedeemExtrinsic(redeemId: string, reimburse: boolean): SubmittableExtrinsic<"promise", ISubmittableResult>; cancel(requestId: string, reimburse?: boolean): ExtrinsicData; buildLiquidationRedeemExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; burn(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; setRedeemPeriod(blocks: number): ExtrinsicData; getRedeemPeriod(): Promise; getMaxBurnableTokens(collateralCurrency: CollateralCurrencyExt): Promise>; getBurnExchangeRate(collateralCurrency: CollateralCurrencyExt): Promise>; getCurrentInclusionFee(): Promise>; list(): Promise; getFeesToPay(amount: MonetaryAmount): Promise>; getFeeRate(): Promise; getDustValue(): Promise>; getPremiumRedeemFeeRate(): Promise; getRequestById(redeemId: H256 | string): Promise; getRequestsByIds(redeemIds: (H256 | string)[]): Promise; }