UNPKG

@arkade-os/boltz-swap

Version:

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

185 lines (182 loc) 8.62 kB
import { I as IArkadeSwaps, A as ArkadeSwaps, Q as QuoteSwapOptions, V as VhtlcTimeouts } from '../arkade-swaps-BG3xEK31.cjs'; import { n as SwapManagerClient, C as CreateLightningInvoiceRequest, e as CreateLightningInvoiceResponse, S as SendLightningPaymentRequest, o as SendLightningPaymentResponse, O as OptimisticSendLightningPaymentResponse, c as BoltzSubmarineSwap, b as BoltzReverseSwap, f as SubmarineRefundOutcome, g as SubmarineRecoveryInfo, h as SubmarineRecoveryResult, F as FeesResponse, a as BoltzChainSwap, j as ArkToBtcResponse, l as ChainArkRefundOutcome, k as BtcToArkResponse, d as Chain, i as ChainFeesResponse, L as LimitsResponse, G as GetSwapStatusResponse, B as BoltzSwap } from '../types-BKEkNZxK.cjs'; import { E as ExpoArkadeSwapsConfig } from '../swapsPollProcessor-CIqTFkV1.cjs'; export { D as DefineSwapBackgroundTaskOptions, b as ExpoArkadeLightningConfig, c as ExpoSwapBackgroundConfig, P as PersistedSwapBackgroundConfig, S as SWAP_POLL_TASK_TYPE, a as SwapTaskDependencies } from '../swapsPollProcessor-CIqTFkV1.cjs'; import { ArkInfo, Identity, ArkTxInput, VHTLC } from '@arkade-os/sdk'; import { TransactionOutput } from '@scure/btc-signer/psbt.js'; import '@arkade-os/sdk/worker/expo'; /** * Expo/React Native wrapper for ArkadeSwaps with background task support. * * In the foreground, delegates to a full {@link ArkadeSwaps} instance * with SwapManager (WebSocket) for real-time swap monitoring and auto * claim/refund. * * In the background (Expo BackgroundTask), a separate * {@link import("./swapsPollProcessor").swapsPollProcessor} handles HTTP-based polling and best-effort * claim/refund within the ~30s execution window. * * The foreground interval does NOT run swap polling — it only * acknowledges background outbox results and re-seeds the task queue * for the next background wake. * * OS-level task registration is the consumer's responsibility — call * `registerExpoSwapBackgroundTask` from * `@arkade-os/boltz-swap/expo/background` after `setup()`. Keeping * registration out of `setup()` lets this entrypoint avoid pulling * `expo-task-manager` / `expo-background-task` into the `/expo` bundle. * * @example * ```ts * import { ExpoArkadeSwaps } from "@arkade-os/boltz-swap/expo"; * import { registerExpoSwapBackgroundTask } from "@arkade-os/boltz-swap/expo/background"; * * const arkSwaps = await ExpoArkadeSwaps.setup({ * wallet, * arkServerUrl: "https://ark.example.com", * swapProvider, * swapManager: true, * background: { * taskQueue: swapTaskQueue, * foregroundIntervalMs: 20_000, * }, * }); * * // Activate the OS scheduler (Expo Android/iOS only) * await registerExpoSwapBackgroundTask("ark-swap-poll", { minimumInterval: 15 }); * * await arkSwaps.createLightningInvoice({ amount: 1000 }); * ``` */ declare class ExpoArkadeSwaps implements IArkadeSwaps { private readonly inner; private readonly config; readonly swapRepository: ArkadeSwaps["swapRepository"]; private foregroundIntervalId?; private constructor(); /** * Create an ExpoArkadeSwaps with foreground/background queue handoff. * * 1. Creates the inner {@link ArkadeSwaps} with SwapManager enabled. * 2. Persists {@link PersistedSwapBackgroundConfig} for background rehydration. * 3. Seeds the task queue with a swap-poll task. * 4. Starts the foreground interval (if configured). * * OS-level scheduling lives in * `@arkade-os/boltz-swap/expo/background` and is invoked separately * by the consumer. */ static setup(config: ExpoArkadeSwapsConfig): Promise<ExpoArkadeSwaps>; private startForegroundPolling; private runForegroundPoll; private seedSwapPollTask; /** * Reset all swap state: stops polling 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>; 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[]; }>; enrichReverseSwapPreimage(swap: BoltzReverseSwap, preimage: string): BoltzReverseSwap; enrichSubmarineSwapInvoice(swap: BoltzSubmarineSwap, invoice: string): BoltzSubmarineSwap; arkToBtc(args: { btcAddress: string; senderLockAmount?: number; receiverLockAmount?: number; feeSatsPerByte?: number; }): Promise<ArkToBtcResponse>; waitAndClaimBtc(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; claimBtc(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; refundArk(pendingSwap: BoltzChainSwap): Promise<ChainArkRefundOutcome>; btcToArk(args: { feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }): Promise<BtcToArkResponse>; waitAndClaimArk(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; claimArk(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; signCooperativeClaimForServer(pendingSwap: BoltzChainSwap): Promise<void>; waitAndClaimChain(pendingSwap: BoltzChainSwap): Promise<{ txid: string; }>; createChainSwap(args: { to: Chain; from: Chain; toAddress: string; feeSatsPerByte?: number; senderLockAmount?: number; receiverLockAmount?: number; }): Promise<BoltzChainSwap>; 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>; joinBatch(identity: Identity, input: ArkTxInput, output: TransactionOutput, arkInfo: ArkInfo, isRecoverable?: boolean): Promise<string>; createVHTLCScript(params: { network: string; preimageHash: Uint8Array; receiverPubkey: string; senderPubkey: string; serverPubkey: string; timeoutBlockHeights: VhtlcTimeouts; }): { vhtlcScript: VHTLC.Script; vhtlcAddress: 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<BoltzSwap[]>; refreshSwapsStatus(): Promise<void>; } /** @deprecated Use ExpoArkadeSwaps instead */ declare const ExpoArkadeLightning: typeof ExpoArkadeSwaps; export { ExpoArkadeLightning, ExpoArkadeSwaps, ExpoArkadeSwapsConfig };