UNPKG

@arkade-os/boltz-swap

Version:

A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.

901 lines (888 loc) 36.1 kB
import { Q as QuoteSwapOptions, I as IArkadeSwaps, V as VhtlcTimeouts } from './arkade-swaps-BG3xEK31.cjs'; export { A as ArkadeSwaps } from './arkade-swaps-BG3xEK31.cjs'; import { B as BoltzSwap, D as DecodedInvoice, a as BoltzChainSwap, b as BoltzReverseSwap, c as BoltzSubmarineSwap, A as ArkadeSwapsConfig, N as Network, C as CreateLightningInvoiceRequest, S as SendLightningPaymentRequest, F as FeesResponse, d as Chain, e as CreateLightningInvoiceResponse, O as OptimisticSendLightningPaymentResponse, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, j as ArkToBtcResponse, k as BtcToArkResponse, l as ChainArkRefundOutcome, m as SwapRepository, n as SwapManagerClient, o as SendLightningPaymentResponse, p as GetSwapsFilter } from './types-BKEkNZxK.cjs'; export { q as ArkadeSwapsCreateConfig, r as BoltzSwapProvider, s as BoltzSwapStatus, I as IncomingPaymentSubscription, P as PendingChainSwap, t as PendingReverseSwap, u as PendingSubmarineSwap, v as PendingSwap, w as SubmarineProgressionStatus, x as SubmarineRecoveryStatus, y as SwapManager, z as SwapManagerCallbacks, E as SwapManagerConfig, H as SwapManagerEvents, V as Vtxo, J as hasSubmarineStatusReached, K as isChainClaimableStatus, M as isChainFailedStatus, Q as isChainFinalStatus, R as isChainPendingStatus, T as isChainRefundableStatus, U as isChainSignableStatus, W as isChainSuccessStatus, X as isChainSwapClaimable, Y as isChainSwapRefundable, Z as isPendingChainSwap, _ as isPendingReverseSwap, $ as isPendingSubmarineSwap, a0 as isReverseClaimableStatus, a1 as isReverseFailedStatus, a2 as isReverseFinalStatus, a3 as isReversePendingStatus, a4 as isReverseSuccessStatus, a5 as isReverseSwapClaimable, a6 as isSubmarineFailedStatus, a7 as isSubmarineFinalStatus, a8 as isSubmarinePendingStatus, a9 as isSubmarineRefundableStatus, aa as isSubmarineSuccessStatus, ab as isSubmarineSwapRefundable } from './types-BKEkNZxK.cjs'; import { Transaction } from '@scure/btc-signer'; import { MessageHandler, RequestEnvelope, ArkInfo, ResponseEnvelope, IWallet, IReadonlyWallet, VHTLC, Identity, ArkTxInput } from '@arkade-os/sdk'; import { TransactionOutput } from '@scure/btc-signer/psbt.js'; /** Options for constructing swap errors. */ interface ErrorOptions { /** Custom error message (overrides the default). */ message?: string; /** Whether the swap's funds can still be claimed. */ isClaimable?: boolean; /** Whether the swap's funds can be refunded. */ isRefundable?: boolean; /** The associated pending swap, if available. */ pendingSwap?: BoltzSwap; /** * Underlying cause. Preserved on the resulting `Error.cause`, so callers * that wrap a typed error (e.g. autopilot wrapping `QuoteRejectedError`) * can still recover the inner instance for programmatic branching. */ cause?: unknown; } /** * Base error class for all swap-related errors. * Extends Error with swap-specific metadata (`isClaimable`, `isRefundable`, `pendingSwap`). */ declare class SwapError extends Error { /** Whether the swap can still be claimed (default: false). */ isClaimable: boolean; /** Whether the swap can be refunded (default: false). */ isRefundable: boolean; /** The pending swap associated with this error, if available. */ pendingSwap?: BoltzSwap; constructor(options?: ErrorOptions); } /** Thrown when a Lightning invoice expires before being paid. The swap may be refundable. */ declare class InvoiceExpiredError extends SwapError { constructor(options?: ErrorOptions); } /** Thrown when Boltz fails to route the Lightning payment to the destination. Typically refundable. */ declare class InvoiceFailedToPayError extends SwapError { constructor(options?: ErrorOptions); } /** Thrown when the wallet does not have enough funds to complete the swap. */ declare class InsufficientFundsError extends SwapError { constructor(options?: ErrorOptions); } /** * Thrown for HTTP/network failures when communicating with the Boltz API. * Not a SwapError — does not carry swap metadata. */ declare class NetworkError extends Error { /** HTTP status code from the failed request, if available. */ statusCode?: number; /** Raw error payload from the Boltz API, if available. */ errorData?: any; constructor(message: string, statusCode?: number, errorData?: any); } /** * Thrown when Boltz responds to `GET /v2/swap/{id}` with HTTP 404 and a body * matching `{"error":"could not find swap with id: ..."}`. Signals that the * configured Boltz instance has no record of this swap — typically because * the swap was created against a different Boltz endpoint. Distinct from a * generic 404 (route change, proxy misconfig) so the polling loop can drive * a per-swap "unknown to provider" counter without conflating it with * transient network errors. */ declare class SwapNotFoundError extends NetworkError { /** The swap ID Boltz did not recognise. */ readonly swapId: string; constructor(swapId: string, errorData?: any); } /** Thrown when the Boltz API returns a response that doesn't match the expected schema. */ declare class SchemaError extends SwapError { constructor(options?: ErrorOptions); } /** Thrown when a swap exceeds its time limit. May be refundable depending on swap type. */ declare class SwapExpiredError extends SwapError { constructor(options?: ErrorOptions); } /** Thrown when an on-chain or off-chain transaction fails. */ declare class TransactionFailedError extends SwapError { constructor(options?: ErrorOptions); } /** * Thrown when a submarine swap's Lightning payment settles but retrieving the * preimage from Boltz fails. The payment was made but proof-of-payment is unavailable. */ declare class PreimageFetchError extends SwapError { constructor(options?: ErrorOptions); } /** Reason a `quoteSwap` was rejected before being posted to Boltz. */ type QuoteRejectionReason = "below_floor" | "non_positive" | "non_safe_integer" | "no_baseline"; type QuoteRejectedOptions = ErrorOptions & ({ reason: "below_floor"; quotedAmount: number; floor: number; } | { reason: "non_positive"; quotedAmount: number; } | { reason: "non_safe_integer"; quotedAmount: number; } | { reason: "no_baseline"; }); /** * Thrown when a Boltz-returned chain-swap quote fails local validation * (below the acceptable floor, non-positive, or missing a baseline to * compare against). The acceptance is never posted on failure. */ declare class QuoteRejectedError extends SwapError { readonly reason: QuoteRejectionReason; readonly quotedAmount?: number; readonly floor?: number; constructor(options: QuoteRejectedOptions); private static defaultMessage; /** * Serialize into a plain `Error` whose `.message` carries the full * rejection payload as JSON behind a marker prefix. Structured clone * (used by `postMessage` between page and service worker) preserves * `Error.message` reliably but strips custom `.name` and own properties, * so we move the typed data into the message field for transport. */ toTransportError(): Error; /** * Inverse of `toTransportError`. Returns a real `QuoteRejectedError` if * `error` carries the transport prefix, else `null`. */ static fromTransportError(error: unknown): QuoteRejectedError | null; } /** * Thrown when the Boltz API rejects a refund request * (e.g. outpoint mismatch after an Ark round). */ declare class BoltzRefundError extends Error { readonly cause?: unknown | undefined; constructor(message: string, cause?: unknown | undefined); } /** * Decodes a Lightning invoice. * @param invoice - The Lightning invoice to decode. * @returns The decoded invoice. */ declare const decodeInvoice: (invoice: string) => DecodedInvoice; declare const getInvoiceSatoshis: (invoice: string) => number; declare const getInvoicePaymentHash: (invoice: string) => string; declare const isValidArkAddress: (address: string) => boolean; /** * Verifies that a transaction input has valid tapscript signatures * from all required signers for a specific tapscript leaf. * * @param tx - The transaction to verify. * @param inputIndex - The index of the input to check. * @param requiredSigners - Hex-encoded x-only public keys of all required signers. * @param expectedLeafHash - The tapscript leaf hash that signatures must commit to. * @returns `true` if all required signers have valid signatures on the expected leaf, `false` otherwise. */ declare const verifySignatures: (tx: Transaction, inputIndex: number, requiredSigners: string[], expectedLeafHash: Uint8Array) => boolean; /** * Generic type for swap save functions */ type SwapSaver = { saveChainSwap?: (swap: BoltzChainSwap) => Promise<void>; saveReverseSwap?: (swap: BoltzReverseSwap) => Promise<void>; saveSubmarineSwap?: (swap: BoltzSubmarineSwap) => Promise<void>; }; /** * Save a swap of any type using the appropriate saver function * This eliminates the need for type checking in multiple places */ declare function saveSwap(swap: BoltzSwap, saver: SwapSaver): Promise<void>; /** * Update a reverse swap's status and save it */ declare function updateReverseSwapStatus(swap: BoltzReverseSwap, status: BoltzReverseSwap["status"], saveFunc: (swap: BoltzReverseSwap) => Promise<void>, additionalFields?: Partial<BoltzReverseSwap>): Promise<void>; /** * Update a submarine swap's status and save it */ declare function updateSubmarineSwapStatus(swap: BoltzSubmarineSwap, status: BoltzSubmarineSwap["status"], saveFunc: (swap: BoltzSubmarineSwap) => Promise<void>, additionalFields?: Partial<BoltzSubmarineSwap>): Promise<void>; /** * Update a chain swap's status and save it */ declare function updateChainSwapStatus(swap: BoltzChainSwap, status: BoltzChainSwap["status"], saveFunc: (swap: BoltzChainSwap) => Promise<void>, additionalFields?: Partial<BoltzChainSwap>): Promise<void>; /** * Enrich a reverse swap with its preimage after validation. */ declare function enrichReverseSwapPreimage(swap: BoltzReverseSwap, preimage: string): BoltzReverseSwap; /** * Enrich a submarine swap with its invoice after validation. */ declare function enrichSubmarineSwapInvoice(swap: BoltzSubmarineSwap, invoice: string): BoltzSubmarineSwap; type RequestInitArkSwaps = RequestEnvelope & { type: "INIT_ARKADE_SWAPS"; payload: Omit<ArkadeSwapsConfig, "wallet" | "swapRepository" | "swapProvider" | "indexerProvider"> & { network: Network; arkServerUrl: string; referralId?: string; swapProvider: { baseUrl: string; }; }; }; type ResponseInitArkSwaps = ResponseEnvelope & { type: "ARKADE_SWAPS_INITIALIZED"; }; type RequestCreateLightningInvoice = RequestEnvelope & { type: "CREATE_LIGHTNING_INVOICE"; payload: CreateLightningInvoiceRequest; }; type ResponseCreateLightningInvoice = ResponseEnvelope & { type: "LIGHTNING_INVOICE_CREATED"; payload: CreateLightningInvoiceResponse; }; type RequestSendLightningPayment = RequestEnvelope & { type: "SEND_LIGHTNING_PAYMENT"; payload: SendLightningPaymentRequest; }; type ResponseSendLightningPayment = ResponseEnvelope & { type: "LIGHTNING_PAYMENT_SENT"; /** Strict SendLightningPaymentResponse unless the request used waitFor: "funded". */ payload: OptimisticSendLightningPaymentResponse; }; type RequestCreateSubmarineSwap = RequestEnvelope & { type: "CREATE_SUBMARINE_SWAP"; payload: SendLightningPaymentRequest; }; type ResponseCreateSubmarineSwap = ResponseEnvelope & { type: "SUBMARINE_SWAP_CREATED"; payload: BoltzSubmarineSwap; }; type RequestCreateReverseSwap = RequestEnvelope & { type: "CREATE_REVERSE_SWAP"; payload: CreateLightningInvoiceRequest; }; type ResponseCreateReverseSwap = ResponseEnvelope & { type: "REVERSE_SWAP_CREATED"; payload: BoltzReverseSwap; }; type RequestClaimVhtlc = RequestEnvelope & { type: "CLAIM_VHTLC"; payload: BoltzReverseSwap; }; type ResponseClaimVhtlc = ResponseEnvelope & { type: "VHTLC_CLAIMED"; }; type RequestRefundVhtlc = RequestEnvelope & { type: "REFUND_VHTLC"; payload: BoltzSubmarineSwap; }; type ResponseRefundVhtlc = ResponseEnvelope & { type: "VHTLC_REFUNDED"; payload: SubmarineRefundOutcome; }; type RequestInspectSubmarineRecovery = RequestEnvelope & { type: "INSPECT_SUBMARINE_RECOVERY"; payload: BoltzSubmarineSwap; }; type ResponseInspectSubmarineRecovery = ResponseEnvelope & { type: "SUBMARINE_RECOVERY_INSPECTED"; payload: SubmarineRecoveryInfo; }; type RequestScanRecoverableSubmarineSwaps = RequestEnvelope & { type: "SCAN_RECOVERABLE_SUBMARINE_SWAPS"; }; type ResponseScanRecoverableSubmarineSwaps = ResponseEnvelope & { type: "RECOVERABLE_SUBMARINE_SWAPS_SCANNED"; payload: SubmarineRecoveryInfo[]; }; type RequestRecoverSubmarineFunds = RequestEnvelope & { type: "RECOVER_SUBMARINE_FUNDS"; payload: BoltzSubmarineSwap; }; type ResponseRecoverSubmarineFunds = ResponseEnvelope & { type: "SUBMARINE_FUNDS_RECOVERED"; payload: SubmarineRefundOutcome; }; type RequestRecoverAllSubmarineFunds = RequestEnvelope & { type: "RECOVER_ALL_SUBMARINE_FUNDS"; payload: BoltzSubmarineSwap[]; }; type ResponseRecoverAllSubmarineFunds = ResponseEnvelope & { type: "ALL_SUBMARINE_FUNDS_RECOVERED"; payload: SubmarineRecoveryResult[]; }; type RequestWaitAndClaim = RequestEnvelope & { type: "WAIT_AND_CLAIM"; payload: BoltzReverseSwap; }; type ResponseWaitAndClaim = ResponseEnvelope & { type: "WAIT_AND_CLAIMED"; payload: { txid: string; }; }; type RequestWaitForSwapSettlement = RequestEnvelope & { type: "WAIT_FOR_SWAP_SETTLEMENT"; payload: BoltzSubmarineSwap; }; type ResponseWaitForSwapSettlement = ResponseEnvelope & { type: "SWAP_SETTLED"; payload: { preimage: string; }; }; type RequestWaitForSwapFunded = RequestEnvelope & { type: "WAIT_FOR_SWAP_FUNDED"; payload: BoltzSubmarineSwap; }; type ResponseWaitForSwapFunded = ResponseEnvelope & { type: "SWAP_FUNDED"; }; type RequestRestoreSwaps = RequestEnvelope & { type: "RESTORE_SWAPS"; payload?: FeesResponse; }; type ResponseRestoreSwaps = ResponseEnvelope & { type: "SWAPS_RESTORED"; payload: { chainSwaps: BoltzChainSwap[]; reverseSwaps: BoltzReverseSwap[]; submarineSwaps: BoltzSubmarineSwap[]; }; }; type RequestEnrichReverseSwapPreimage = RequestEnvelope & { type: "ENRICH_REVERSE_SWAP_PREIMAGE"; payload: { swap: BoltzReverseSwap; preimage: string; }; }; type ResponseEnrichReverseSwapPreimage = ResponseEnvelope & { type: "REVERSE_SWAP_PREIMAGE_ENRICHED"; payload: BoltzReverseSwap; }; type RequestEnrichSubmarineSwapInvoice = RequestEnvelope & { type: "ENRICH_SUBMARINE_SWAP_INVOICE"; payload: { swap: BoltzSubmarineSwap; invoice: string; }; }; type ResponseEnrichSubmarineSwapInvoice = ResponseEnvelope & { type: "SUBMARINE_SWAP_INVOICE_ENRICHED"; payload: BoltzSubmarineSwap; }; type RequestGetFees = RequestEnvelope & { type: "GET_FEES"; payload?: { from: Chain; to: Chain; }; }; type ResponseGetFees = ResponseEnvelope & { type: "FEES"; payload: FeesResponse | ChainFeesResponse; }; type RequestGetLimits = RequestEnvelope & { type: "GET_LIMITS"; payload?: { from: Chain; to: Chain; }; }; type ResponseGetLimits = ResponseEnvelope & { type: "LIMITS"; payload: LimitsResponse; }; type RequestGetSwapStatus = RequestEnvelope & { type: "GET_SWAP_STATUS"; payload: { swapId: string; }; }; type ResponseGetSwapStatus = ResponseEnvelope & { type: "SWAP_STATUS"; payload: GetSwapStatusResponse; }; type RequestGetPendingSubmarineSwaps = RequestEnvelope & { type: "GET_PENDING_SUBMARINE_SWAPS"; }; type ResponseGetPendingSubmarineSwaps = ResponseEnvelope & { type: "PENDING_SUBMARINE_SWAPS"; payload: BoltzSubmarineSwap[]; }; type RequestGetPendingReverseSwaps = RequestEnvelope & { type: "GET_PENDING_REVERSE_SWAPS"; }; type ResponseGetPendingReverseSwaps = ResponseEnvelope & { type: "PENDING_REVERSE_SWAPS"; payload: BoltzReverseSwap[]; }; type RequestGetPendingChainSwaps = RequestEnvelope & { type: "GET_PENDING_CHAIN_SWAPS"; }; type ResponseGetPendingChainSwaps = ResponseEnvelope & { type: "PENDING_CHAIN_SWAPS"; payload: BoltzChainSwap[]; }; type RequestGetSwapHistory = RequestEnvelope & { type: "GET_SWAP_HISTORY"; }; type ResponseGetSwapHistory = ResponseEnvelope & { type: "SWAP_HISTORY"; payload: (BoltzReverseSwap | BoltzSubmarineSwap | BoltzChainSwap)[]; }; type RequestRefreshSwapsStatus = RequestEnvelope & { type: "REFRESH_SWAPS_STATUS"; }; type ResponseRefreshSwapsStatus = ResponseEnvelope & { type: "SWAPS_STATUS_REFRESHED"; }; type RequestArkToBtc = RequestEnvelope & { type: "ARK_TO_BTC"; payload: { btcAddress: string; senderLockAmount?: number; receiverLockAmount?: number; feeSatsPerByte?: number; }; }; type ResponseArkToBtc = ResponseEnvelope & { type: "ARK_TO_BTC_CREATED"; payload: ArkToBtcResponse; }; type RequestBtcToArk = RequestEnvelope & { type: "BTC_TO_ARK"; payload: { feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }; }; type ResponseBtcToArk = ResponseEnvelope & { type: "BTC_TO_ARK_CREATED"; payload: BtcToArkResponse; }; type RequestCreateChainSwap = RequestEnvelope & { type: "CREATE_CHAIN_SWAP"; payload: { to: Chain; from: Chain; toAddress: string; feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }; }; type ResponseCreateChainSwap = ResponseEnvelope & { type: "CHAIN_SWAP_CREATED"; payload: BoltzChainSwap; }; type RequestWaitAndClaimChain = RequestEnvelope & { type: "WAIT_AND_CLAIM_CHAIN"; payload: BoltzChainSwap; }; type ResponseWaitAndClaimChain = ResponseEnvelope & { type: "CHAIN_CLAIMED"; payload: { txid: string; }; }; type RequestWaitAndClaimArk = RequestEnvelope & { type: "WAIT_AND_CLAIM_ARK"; payload: BoltzChainSwap; }; type ResponseWaitAndClaimArk = ResponseEnvelope & { type: "ARK_CLAIMED"; payload: { txid: string; }; }; type RequestWaitAndClaimBtc = RequestEnvelope & { type: "WAIT_AND_CLAIM_BTC"; payload: BoltzChainSwap; }; type ResponseWaitAndClaimBtc = ResponseEnvelope & { type: "BTC_CLAIMED"; payload: { txid: string; }; }; type RequestClaimArk = RequestEnvelope & { type: "CLAIM_ARK"; payload: BoltzChainSwap; }; type ResponseClaimArk = ResponseEnvelope & { type: "ARK_CLAIM_EXECUTED"; payload: { txid: string; }; }; type RequestClaimBtc = RequestEnvelope & { type: "CLAIM_BTC"; payload: BoltzChainSwap; }; type ResponseClaimBtc = ResponseEnvelope & { type: "BTC_CLAIM_EXECUTED"; payload: { txid: string; }; }; type RequestRefundArk = RequestEnvelope & { type: "REFUND_ARK"; payload: BoltzChainSwap; }; type ResponseRefundArk = ResponseEnvelope & { type: "ARK_REFUND_EXECUTED"; payload: ChainArkRefundOutcome; }; type RequestSignServerClaim = RequestEnvelope & { type: "SIGN_SERVER_CLAIM"; payload: BoltzChainSwap; }; type ResponseSignServerClaim = ResponseEnvelope & { type: "SERVER_CLAIM_SIGNED"; }; type RequestVerifyChainSwap = RequestEnvelope & { type: "VERIFY_CHAIN_SWAP"; payload: { to: Chain; from: Chain; swap: BoltzChainSwap; arkInfo: ArkInfo; }; }; type ResponseVerifyChainSwap = ResponseEnvelope & { type: "CHAIN_SWAP_VERIFIED"; payload: { verified: boolean; }; }; type RequestQuoteSwap = RequestEnvelope & { type: "QUOTE_SWAP"; payload: { swapId: string; options?: QuoteSwapOptions; }; }; type ResponseQuoteSwap = ResponseEnvelope & { type: "SWAP_QUOTED"; payload: { amount: number; }; }; type RequestGetSwapQuote = RequestEnvelope & { type: "GET_SWAP_QUOTE"; payload: { swapId: string; }; }; type ResponseGetSwapQuote = ResponseEnvelope & { type: "SWAP_QUOTE_RETRIEVED"; payload: { amount: number; }; }; type RequestAcceptSwapQuote = RequestEnvelope & { type: "ACCEPT_SWAP_QUOTE"; payload: { swapId: string; amount: number; options?: QuoteSwapOptions; }; }; type ResponseAcceptSwapQuote = ResponseEnvelope & { type: "SWAP_QUOTE_ACCEPTED"; payload: { amount: number; }; }; type RequestSwapManagerStart = RequestEnvelope & { type: "SM-START"; }; type ResponseSwapManagerStart = ResponseEnvelope & { type: "SM-STARTED"; }; type RequestSwapManagerStop = RequestEnvelope & { type: "SM-STOP"; }; type ResponseSwapManagerStop = ResponseEnvelope & { type: "SM-STOPPED"; }; type RequestSwapManagerAddSwap = RequestEnvelope & { type: "SM-ADD_SWAP"; payload: BoltzReverseSwap | BoltzSubmarineSwap | BoltzChainSwap; }; type ResponseSwapManagerAddSwap = ResponseEnvelope & { type: "SM-SWAP_ADDED"; }; type RequestSwapManagerRemoveSwap = RequestEnvelope & { type: "SM-REMOVE_SWAP"; payload: { swapId: string; }; }; type ResponseSwapManagerRemoveSwap = ResponseEnvelope & { type: "SM-SWAP_REMOVED"; }; type RequestSwapManagerGetPending = RequestEnvelope & { type: "SM-GET_PENDING_SWAPS"; }; type ResponseSwapManagerGetPending = ResponseEnvelope & { type: "SM-PENDING_SWAPS"; payload: (BoltzReverseSwap | BoltzSubmarineSwap | BoltzChainSwap)[]; }; type RequestSwapManagerHasSwap = RequestEnvelope & { type: "SM-HAS_SWAP"; payload: { swapId: string; }; }; type ResponseSwapManagerHasSwap = ResponseEnvelope & { type: "SM-HAS_SWAP_RESULT"; payload: { has: boolean; }; }; type RequestSwapManagerIsProcessing = RequestEnvelope & { type: "SM-IS_PROCESSING"; payload: { swapId: string; }; }; type ResponseSwapManagerIsProcessing = ResponseEnvelope & { type: "SM-IS_PROCESSING_RESULT"; payload: { processing: boolean; }; }; type RequestSwapManagerGetStats = RequestEnvelope & { type: "SM-GET_STATS"; }; type ResponseSwapManagerGetStats = ResponseEnvelope & { type: "SM-STATS"; payload: { isRunning: boolean; monitoredSwaps: number; websocketConnected: boolean; usePollingFallback: boolean; currentReconnectDelay: number; currentPollRetryDelay: number; }; }; type RequestSwapManagerWaitForCompletion = RequestEnvelope & { type: "SM-WAIT_FOR_COMPLETION"; payload: { swapId: string; }; }; type ResponseSwapManagerWaitForCompletion = ResponseEnvelope & { type: "SM-COMPLETED"; payload: { txid: string; }; }; type ArkadeSwapsUpdaterRequest = RequestInitArkSwaps | RequestCreateLightningInvoice | RequestSendLightningPayment | RequestCreateSubmarineSwap | RequestCreateReverseSwap | RequestClaimVhtlc | RequestRefundVhtlc | RequestInspectSubmarineRecovery | RequestScanRecoverableSubmarineSwaps | RequestRecoverSubmarineFunds | RequestRecoverAllSubmarineFunds | RequestWaitAndClaim | RequestWaitForSwapSettlement | RequestWaitForSwapFunded | RequestRestoreSwaps | RequestEnrichReverseSwapPreimage | RequestEnrichSubmarineSwapInvoice | RequestGetFees | RequestGetLimits | RequestGetSwapStatus | RequestGetPendingSubmarineSwaps | RequestGetPendingReverseSwaps | RequestGetPendingChainSwaps | RequestGetSwapHistory | RequestRefreshSwapsStatus | RequestArkToBtc | RequestBtcToArk | RequestCreateChainSwap | RequestWaitAndClaimChain | RequestWaitAndClaimArk | RequestWaitAndClaimBtc | RequestClaimArk | RequestClaimBtc | RequestRefundArk | RequestSignServerClaim | RequestVerifyChainSwap | RequestQuoteSwap | RequestGetSwapQuote | RequestAcceptSwapQuote | RequestSwapManagerStart | RequestSwapManagerStop | RequestSwapManagerAddSwap | RequestSwapManagerRemoveSwap | RequestSwapManagerGetPending | RequestSwapManagerHasSwap | RequestSwapManagerIsProcessing | RequestSwapManagerGetStats | RequestSwapManagerWaitForCompletion; type ArkadeSwapsUpdaterResponse = ResponseInitArkSwaps | ResponseCreateLightningInvoice | ResponseSendLightningPayment | ResponseCreateSubmarineSwap | ResponseCreateReverseSwap | ResponseClaimVhtlc | ResponseRefundVhtlc | ResponseInspectSubmarineRecovery | ResponseScanRecoverableSubmarineSwaps | ResponseRecoverSubmarineFunds | ResponseRecoverAllSubmarineFunds | ResponseWaitAndClaim | ResponseWaitForSwapSettlement | ResponseWaitForSwapFunded | ResponseRestoreSwaps | ResponseEnrichReverseSwapPreimage | ResponseEnrichSubmarineSwapInvoice | ResponseGetFees | ResponseGetLimits | ResponseGetSwapStatus | ResponseGetPendingSubmarineSwaps | ResponseGetPendingReverseSwaps | ResponseGetPendingChainSwaps | ResponseGetSwapHistory | ResponseRefreshSwapsStatus | ResponseArkToBtc | ResponseBtcToArk | ResponseCreateChainSwap | ResponseWaitAndClaimChain | ResponseWaitAndClaimArk | ResponseWaitAndClaimBtc | ResponseClaimArk | ResponseClaimBtc | ResponseRefundArk | ResponseSignServerClaim | ResponseVerifyChainSwap | ResponseQuoteSwap | ResponseGetSwapQuote | ResponseAcceptSwapQuote | ResponseSwapManagerStart | ResponseSwapManagerStop | ResponseSwapManagerAddSwap | ResponseSwapManagerRemoveSwap | ResponseSwapManagerGetPending | ResponseSwapManagerHasSwap | ResponseSwapManagerIsProcessing | ResponseSwapManagerGetStats | ResponseSwapManagerWaitForCompletion; declare class ArkadeSwapsMessageHandler implements MessageHandler<ArkadeSwapsUpdaterRequest, ArkadeSwapsUpdaterResponse> { private readonly swapRepository; static messageTag: string; readonly messageTag: string; private arkProvider; private indexerProvider; private swapProvider; private wallet; private handler; private swapManager; constructor(swapRepository: SwapRepository); private getSwapManagerOrThrow; start(opts: { wallet?: IWallet; readonlyWallet: IReadonlyWallet; }): Promise<void>; stop(): Promise<void>; tick(_now: number): Promise<never[]>; isLongRunning(message: ArkadeSwapsUpdaterRequest): boolean; private tagged; private broadcastEvent; handleMessage(message: ArkadeSwapsUpdaterRequest): Promise<ArkadeSwapsUpdaterResponse>; private handleInit; } type SvcWrkArkadeSwapsConfig = Pick<ArkadeSwapsConfig, "swapManager" | "swapProvider" | "swapRepository"> & { serviceWorker: ServiceWorker; messageTag?: string; network: Network; arkServerUrl: string; referralId?: string; }; declare class ServiceWorkerArkadeSwaps implements IArkadeSwaps { private readonly messageTag; readonly serviceWorker: ServiceWorker; readonly swapRepository: SwapRepository; private readonly withSwapManager; private eventListenerInitialized; private swapUpdateListeners; private swapCompletedListeners; private swapFailedListeners; private actionExecutedListeners; private wsConnectedListeners; private wsDisconnectedListeners; private initPayload; private reinitPromise; private pingPromise; private inflightRequests; private constructor(); static create(config: SvcWrkArkadeSwapsConfig): Promise<ServiceWorkerArkadeSwaps>; startSwapManager(): Promise<void>; stopSwapManager(): Promise<void>; getSwapManager(): SwapManagerClient | null; createLightningInvoice(args: CreateLightningInvoiceRequest): Promise<CreateLightningInvoiceResponse>; sendLightningPayment(args: SendLightningPaymentRequest & { waitFor?: "settled"; }): Promise<SendLightningPaymentResponse>; sendLightningPayment(args: SendLightningPaymentRequest): Promise<OptimisticSendLightningPaymentResponse>; createSubmarineSwap(args: SendLightningPaymentRequest): Promise<BoltzSubmarineSwap>; createReverseSwap(args: CreateLightningInvoiceRequest): Promise<BoltzReverseSwap>; claimVHTLC(pendingSwap: BoltzReverseSwap): Promise<void>; refundVHTLC(pendingSwap: BoltzSubmarineSwap): Promise<SubmarineRefundOutcome>; inspectSubmarineRecovery(swap: BoltzSubmarineSwap): Promise<SubmarineRecoveryInfo>; scanRecoverableSubmarineSwaps(): Promise<SubmarineRecoveryInfo[]>; recoverSubmarineFunds(swap: BoltzSubmarineSwap): Promise<SubmarineRefundOutcome>; recoverAllSubmarineFunds(swaps: BoltzSubmarineSwap[]): Promise<SubmarineRecoveryResult[]>; waitAndClaim(pendingSwap: BoltzReverseSwap): Promise<{ txid: string; }>; waitForSwapSettlement(pendingSwap: BoltzSubmarineSwap): Promise<{ preimage: string; }>; waitForSwapFunded(pendingSwap: BoltzSubmarineSwap): Promise<void>; restoreSwaps(boltzFees?: FeesResponse): Promise<{ chainSwaps: BoltzChainSwap[]; reverseSwaps: BoltzReverseSwap[]; submarineSwaps: BoltzSubmarineSwap[]; }>; arkToBtc(args: { btcAddress: string; senderLockAmount?: number; receiverLockAmount?: number; feeSatsPerByte?: number; }): Promise<ArkToBtcResponse>; btcToArk(args: { feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }): Promise<BtcToArkResponse>; createChainSwap(args: { to: Chain; from: Chain; toAddress: string; feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }): Promise<BoltzChainSwap>; waitAndClaimChain(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; waitAndClaimArk(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; waitAndClaimBtc(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; claimArk(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; claimBtc(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; refundArk(pendingSwap: BoltzChainSwap): Promise<ChainArkRefundOutcome>; signCooperativeClaimForServer(pendingSwap: BoltzChainSwap): Promise<void>; verifyChainSwap(args: { to: Chain; from: Chain; swap: BoltzChainSwap; arkInfo: ArkInfo; }): Promise<boolean>; quoteSwap(swapId: string, options?: QuoteSwapOptions): Promise<number>; getSwapQuote(swapId: string): Promise<number>; acceptSwapQuote(swapId: string, amount: number, options?: QuoteSwapOptions): Promise<number>; enrichReverseSwapPreimage(swap: BoltzReverseSwap, preimage: string): BoltzReverseSwap; enrichSubmarineSwapInvoice(swap: BoltzSubmarineSwap, invoice: string): BoltzSubmarineSwap; createVHTLCScript(_args: { network: string; preimageHash: Uint8Array; receiverPubkey: string; senderPubkey: string; serverPubkey: string; timeoutBlockHeights: VhtlcTimeouts; }): { vhtlcScript: VHTLC.Script; vhtlcAddress: string; }; joinBatch(_identity: Identity, _input: ArkTxInput, _output: TransactionOutput, _arkInfo: ArkInfo, _isRecoverable?: boolean): Promise<string>; getFees(): Promise<FeesResponse>; getFees(from: Chain, to: Chain): Promise<ChainFeesResponse>; getLimits(): Promise<LimitsResponse>; getLimits(from: Chain, to: Chain): Promise<LimitsResponse>; getSwapStatus(swapId: string): Promise<GetSwapStatusResponse>; getPendingSubmarineSwaps(): Promise<BoltzSubmarineSwap[]>; getPendingReverseSwaps(): Promise<BoltzReverseSwap[]>; getPendingChainSwaps(): Promise<BoltzChainSwap[]>; getSwapHistory(): Promise<(BoltzReverseSwap | BoltzSubmarineSwap | BoltzChainSwap)[]>; refreshSwapsStatus(): Promise<void>; /** * Reset all swap state: stops the SwapManager and clears the swap repository. * * **Destructive** — any swap in a non-terminal state will lose its * refund/claim path. Intended for wallet-reset / dev / test scenarios only. */ reset(): Promise<void>; dispose(): Promise<void>; [Symbol.asyncDispose](): Promise<void>; private sendMessageDirect; private sendMessage; private pingServiceWorker; private sendMessageWithRetry; private reinitialize; private initEventStream; private handleEventMessage; } /** * Reader and Writer functions for a key-value storage. * It mimics the deprecated StorageAdapter interface from @arkade-os/sdk. */ type LegacyStorageAccessor = { getItem: (key: string) => Promise<string | null>; setItem(key: string, value: string): Promise<void>; }; /** * Migrates the swaps stored in the old ContractRepository to the new SwapRepository. * It accepts a generic reader/writer interface, once it's done it will set a flag * in the storage to avoid running it again. * * @param storageAdapter - The storage adapter to read the swaps from. * @param fresh - The new swap repository to save the swaps to. * * @return true if data was migrated */ declare function migrateToSwapRepository(storageAdapter: LegacyStorageAccessor, fresh: SwapRepository): Promise<boolean>; /** * Logger interface for customizing log output */ interface Logger { log: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void; } /** * Default logger using console */ declare let logger: Logger; /** * Set a custom logger to override the default console logging */ declare function setLogger(customLogger: Logger): void; declare class IndexedDbSwapRepository implements SwapRepository { private readonly dbName; readonly version: 1; private db; constructor(dbName?: string); private getDB; saveSwap<T extends BoltzSwap>(swap: T): Promise<void>; deleteSwap(id: string): Promise<void>; getAllSwaps<T extends BoltzSwap>(filter?: GetSwapsFilter): Promise<T[]>; clear(): Promise<void>; private getSwapsByIndexValues; private getAllSwapsFromStore; private getAllSwapsByCreatedAt; [Symbol.asyncDispose](): Promise<void>; } declare class InMemorySwapRepository implements SwapRepository { readonly version: 1; private readonly swaps; saveSwap<T extends BoltzSwap>(swap: T): Promise<void>; deleteSwap(id: string): Promise<void>; getAllSwaps<T extends BoltzSwap>(filter?: GetSwapsFilter): Promise<T[]>; clear(): Promise<void>; [Symbol.asyncDispose](): Promise<void>; } /** * This SDK plugin's own version string, sourced from package.json, and scoped * by plugin name. */ declare const sdkVersion: string; export { ArkToBtcResponse, ArkadeSwapsMessageHandler as ArkadeLightningMessageHandler, ArkadeSwapsConfig, ArkadeSwapsMessageHandler, BoltzChainSwap, BoltzRefundError, BoltzReverseSwap, BoltzSubmarineSwap, BoltzSwap, BtcToArkResponse, Chain, ChainFeesResponse, CreateLightningInvoiceRequest, CreateLightningInvoiceResponse, DecodedInvoice, FeesResponse, InMemorySwapRepository, IndexedDbSwapRepository, InsufficientFundsError, InvoiceExpiredError, InvoiceFailedToPayError, LimitsResponse, type Logger, Network, NetworkError, OptimisticSendLightningPaymentResponse, PreimageFetchError, QuoteRejectedError, type QuoteRejectionReason, QuoteSwapOptions, SchemaError, SendLightningPaymentRequest, SendLightningPaymentResponse, ServiceWorkerArkadeSwaps as ServiceWorkerArkadeLightning, ServiceWorkerArkadeSwaps, SubmarineRecoveryInfo, SubmarineRecoveryResult, SubmarineRefundOutcome, SwapError, SwapExpiredError, SwapManagerClient, SwapNotFoundError, SwapRepository, type SwapSaver, TransactionFailedError, decodeInvoice, enrichReverseSwapPreimage, enrichSubmarineSwapInvoice, getInvoicePaymentHash, getInvoiceSatoshis, isValidArkAddress, logger, migrateToSwapRepository, saveSwap, sdkVersion, setLogger, updateChainSwapStatus, updateReverseSwapStatus, updateSubmarineSwapStatus, verifySignatures };