import { ApiPromise } from "@polkadot/api"; import { AddressOrPair } from "@polkadot/api/submittable/types"; import { AccountId, Hash, H256 } from "@polkadot/types/interfaces"; import { EventRecord } from "@polkadot/types/interfaces/system"; import { Bytes } from "@polkadot/types"; import { Network } from "bitcoinjs-lib"; import Big from "big.js"; import BN from "bn.js"; import { ElectrsAPI } from "../external"; import { DefaultTransactionAPI, TransactionAPI } from "./transaction"; import { RedeemRequest } from "../interfaces/default"; export declare type RequestResult = { id: Hash; redeemRequest: RedeemRequestExt; }; export interface RedeemRequestExt extends Omit { btc_address: string; } export declare function encodeRedeemRequest(req: RedeemRequest, network: Network): RedeemRequestExt; /** * @category PolkaBTC Bridge * The type Big represents DOT or PolkaBTC denominations, * while the type BN represents Planck or Satoshi denominations. */ export interface RedeemAPI extends TransactionAPI { /** * @returns An array containing the redeem requests */ list(): Promise; /** * Send a redeem request transaction * @param amount PolkaBTC amount (denoted in Bitcoin) to redeem * @param btcAddressEnc Bitcoin address where the redeemed BTC should be sent * @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 retries (optional) Number of times to re-try redeeming, if some of the requests fail. Defaults to 0. * @param availableVaults (optional) A list of all vaults usable for redeem. If not provided, will fetch from the parachain. * @returns An array of type {redeemId, redeemRequest} if the requests succeeded. The function throws an error otherwise. */ request(amount: Big, btcAddressEnc: string, atomic?: boolean, retries?: number, availableVaults?: Map): Promise; /** * Send a batch of aggregated redeem transactions (to one or more vaults) * @param amountsPerVault A mapping of vaults to redeem from, and PolkaBTC amounts (in Satoshi) 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 An array of type {redeemId, vault} if the requests succeeded. * @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): 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 txId (Optional) The ID of the Bitcoin transaction that sends funds from the vault to the redeemer's address * @param merkleProof (Optional) The merkle inclusion proof of the Bitcoin transaction. * @param rawTx (Optional) The raw bytes of the Bitcoin transaction * @returns A boolean value indicating whether the execution was successful. The function throws an error otherwise. */ execute(redeemId: string, txId?: string, merkleProof?: Bytes, rawTx?: Bytes): Promise; /** * Send a redeem cancellation transaction. After the redeem period has elapsed, * the redeemal of PolkaBTC 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: * - `false` = retry redeeming, with a different Vault * - `true` = accept reimbursement in polkaBTC */ cancel(redeemId: H256, reimburse?: boolean): Promise; /** * @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. */ setRedeemPeriod(blocks: number): Promise; /** * * @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; /** * Set an account to use when sending transactions from this API * @param account Keyring account */ setAccount(account: AddressOrPair): void; /** * @param account The ID of the account whose redeem requests are to be retrieved * @returns A mapping from the redeem request ID to the redeem request object, corresponding to the requests of * the given account */ mapForUser(account: AccountId): Promise>; /** * @param redeemId The ID of the redeem request to fetch * @returns A redeem request object */ getRequestById(redeemId: H256): Promise; getRequestsById(redeemIds: H256[]): Promise; /** * Whenever a redeem request associated with `account` expires, call the callback function with the * ID of the expired request. Already expired requests are stored in memory, so as not to call back * twice for the same request. * @param account The ID of the account whose redeem requests are to be checked for expiry * @param callback Function to be called whenever a redeem request expires */ subscribeToRedeemExpiry(account: AccountId, callback: (requestRedeemId: H256) => void): Promise<() => void>; /** * @returns The minimum amount of btc 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 amountBtc The amount, in BTC, for which to compute the redeem fees * @returns The fees, in BTC */ getFeesToPay(amount: Big): Promise; /** * @returns If users execute a redeem with a Vault flagged for premium redeem, * they can earn a DOT premium, slashed from the Vault's collateral. */ getPremiumRedeemFee(): Promise; /** * Burn wrapped tokens for a premium * @param amount The amount of PolkaBTC to burn, denominated as PolkaBTC */ burn(amount: Big): Promise; /** * @returns The maximum amount of tokens that can be burned through a liquidation redeem */ getMaxBurnableTokens(): Promise; /** * @returns The exchange rate (collateral currency to wrapped token currency) * used when burning tokens */ getBurnExchangeRate(): 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 extends DefaultTransactionAPI implements RedeemAPI { private btcNetwork; private electrsAPI; private vaultsAPI; private collateralAPI; private oracleAPI; requestHash: Hash; events: EventRecord[]; constructor(api: ApiPromise, btcNetwork: Network, electrsAPI: ElectrsAPI, account?: AddressOrPair); private getRedeemIdsFromEvents; request(amount: Big, btcAddressEnc: string, atomic?: boolean, retries?: number, cachedVaults?: Map): Promise; requestAdvanced(amountsPerVault: Map, btcAddressEnc: string, atomic: boolean): Promise; execute(requestId: string, btcTxId?: string, merkleProof?: Bytes, rawTx?: Bytes): Promise; cancel(redeemId: H256, reimburse?: boolean): Promise; burn(amount: Big): Promise; setRedeemPeriod(blocks: number): Promise; getRedeemPeriod(): Promise; getMaxBurnableTokens(): Promise; getBurnExchangeRate(): Promise; getCurrentInclusionFee(): Promise; list(): Promise; mapForUser(account: AccountId): Promise>; subscribeToRedeemExpiry(account: AccountId, callback: (requestRedeemId: H256) => void): Promise<() => void>; subscribeToRedeemCompletion(account: AccountId, callback: (requestRedeemId: H256) => void): Promise<() => void>; onRedeem(account: AccountId, fn: (set: Set, request: RedeemRequestExt, id: H256, blockNumber: BN) => void): Promise<() => void>; getFeesToPay(amount: Big): Promise; getFeeRate(): Promise; getDustValue(): Promise; getPremiumRedeemFee(): Promise; getRequestById(redeemId: H256): Promise; getRequestsById(redeemIds: H256[]): Promise; }