import { ApiPromise } from "@polkadot/api"; import { H256, AccountId, BlockHash } from "@polkadot/types/interfaces"; import { BlockNumber } from "@polkadot/types/interfaces/runtime"; import { Network } from "bitcoinjs-lib"; import { MonetaryAmount } from "@interlay/monetary-js"; import { InterbtcPrimitivesReplaceReplaceRequest } from "@polkadot/types/lookup"; import { ISubmittableResult } from "@polkadot/types/types"; import { ElectrsAPI } from "../external"; import { CollateralCurrencyExt, ExtrinsicData, ReplaceRequestExt, WrappedCurrency } from "../types"; import { SubmittableExtrinsic } from "@polkadot/api/types"; /** * @category BTC Bridge */ export interface ReplaceAPI { /** * @returns The minimum amount of btc that is accepted for replace requests; any lower values would * risk the bitcoin client to reject the payment */ getDustValue(): Promise>; /** * @returns The time difference in number of blocks between when a replace request is created * and required completion time by a vault. The replace period has an upper limit * to prevent griefing of vault collateral. */ getReplacePeriod(): Promise; /** * @returns An array containing the replace requests */ list(): Promise; /** * @returns A mapping from the replace request ID to the replace request object */ map(): Promise>; /** * @param replaceId The ID of the replace request to fetch * @returns A replace request object */ getRequestById(replaceId: H256 | string, atBlock?: BlockHash): Promise; /** * Build a request replace extrinsic (transaction) without sending it. * * @param amount Wrapped token amount to replace. * @param collateralCurrency Collateral currency to have replaced * @returns A request replace submittable extrinsic. */ buildRequestReplaceExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * @param amount Amount issued, denoted in Bitcoin, to have replaced by another vault * @param collateralCurrency Collateral currency to have replaced * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ request(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; /** * Build a withdraw replace extrinsic (transaction) without sending it. * * @param amount The amount of wrapped tokens to withdraw from the amount * requested to have replaced. * @param collateralCurrency Collateral currency to have replaced * @returns A withdraw replace submittable extrinsic. */ buildWithdrawReplaceExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Wihdraw a replace request * @param amount The amount of wrapped tokens to withdraw from the amount * requested to have replaced. * @param collateralCurrency Collateral currency of the request * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ withdraw(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; /** * Build an accept replace extrinsic (transaction) without sending it. * * @param oldVault account ID of the old vault that to be (possibly partially) replaced * @param amount Amount of issued tokens to be replaced * @param collateral The collateral for replacement * @param btcAddress The address that old-vault should transfer the btc to * @returns An accept replace submittable extrinsic. */ buildAcceptReplaceExtrinsic(oldVault: AccountId, amount: MonetaryAmount, collateral: MonetaryAmount, btcAddress: string): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Accept a replace request * @param oldVault ID of the old vault that to be (possibly partially) replaced * @param amount Amount of issued tokens to be replaced * @param collateral The collateral for replacement * @param btcAddress The address that old-vault should transfer the btc to * @returns {ExtrinsicData} A submittable extrinsic and an event that is emitted when extrinsic is submitted. */ accept(oldVault: AccountId, amount: MonetaryAmount, collateral: MonetaryAmount, btcAddress: string): ExtrinsicData; /** * Build an execute replace extrinsic (transaction) without sending it. * * @param requestId The ID generated by the replace request transaction * @param btcTxId Bitcoin transaction ID * @returns An execute replace submittable extrinsic. */ buildExecuteReplaceExtrinsic(requestId: string, btcTxId: string): Promise>; /** * Execute a replace request * @remarks If `txId` is not set, the `merkleProof` and `rawTx` must both be set. * * @param requestId The ID generated by the replace 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; /** * Fetch the replace requests associated with a vault. In the returned requests, * the vault is either the replaced or the replacing one. * * @param vaultAccountId The AccountId of the vault used to filter replace requests * @returns An array with replace requests involving said vault */ mapReplaceRequests(vaultAccountId: AccountId): Promise; } export declare class DefaultReplaceAPI implements ReplaceAPI { private api; private btcNetwork; private electrsAPI; private wrappedCurrency; constructor(api: ApiPromise, btcNetwork: Network, electrsAPI: ElectrsAPI, wrappedCurrency: WrappedCurrency); buildRequestReplaceExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; request(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; buildWithdrawReplaceExtrinsic(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): SubmittableExtrinsic<"promise", ISubmittableResult>; withdraw(amount: MonetaryAmount, collateralCurrency: CollateralCurrencyExt): ExtrinsicData; buildAcceptReplaceExtrinsic(oldVault: AccountId, amount: MonetaryAmount, collateral: MonetaryAmount, btcAddress: string): SubmittableExtrinsic<"promise", ISubmittableResult>; accept(oldVault: AccountId, amount: MonetaryAmount, collateral: MonetaryAmount, btcAddress: string): ExtrinsicData; buildExecuteReplaceExtrinsic(requestId: string, btcTxId: string): Promise>; execute(requestId: string, btcTxId: string): Promise; getDustValue(): Promise>; getReplacePeriod(): Promise; list(): Promise; map(): Promise>; getRequestById(replaceId: H256 | string, atBlock?: BlockHash): Promise; mapReplaceRequests(vaultAccountId: AccountId): Promise; getOldVaultReplaceRequests(vaultAccountId: AccountId): Promise; getNewVaultReplaceRequests(vaultAccountId: AccountId): Promise; parseRequestsAsync(requestPairs: [H256, InterbtcPrimitivesReplaceReplaceRequest][]): Promise<[H256, ReplaceRequestExt][]>; }