UNPKG

@arkade-os/boltz-swap

Version:

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

94 lines (90 loc) 3.8 kB
import { AsyncStorageTaskQueue, TaskProcessor } from '@arkade-os/sdk/worker/expo'; import { Identity, ArkProvider, IndexerProvider, IWallet } from '@arkade-os/sdk'; import { m as SwapRepository, N as Network, r as BoltzSwapProvider, A as ArkadeSwapsConfig } from './types-BKEkNZxK.cjs'; /** * Dependencies injected into every swap processor at runtime. * * Unlike the wallet's `TaskDependencies`, these are swap-specific: * we need the Boltz provider, swap repository, and identity to * poll status and attempt claim/refund. */ interface SwapTaskDependencies { swapRepository: SwapRepository; swapProvider: BoltzSwapProvider; arkProvider: ArkProvider; indexerProvider: IndexerProvider; identity: Identity; wallet: IWallet; } /** * Minimal config persisted to AsyncStorage for background rehydration. * * The background handler runs in a fresh JS context without access to * the foreground's in-memory state, so we persist just enough to * reconstruct providers and identity. */ interface PersistedSwapBackgroundConfig { boltzApiUrl: string; arkServerUrl: string; network: Network; } /** * Background scheduling configuration for {@link ExpoArkadeSwaps}. * * OS-level task registration is **not** part of this config — call * `registerExpoSwapBackgroundTask` from `@arkade-os/boltz-swap/expo/background` * explicitly. Splitting that step out keeps `/expo` free of the * `expo-task-manager` / `expo-background-task` dependencies. */ interface ExpoSwapBackgroundConfig { /** Persistence layer for foreground ↔ background handoff. */ taskQueue: AsyncStorageTaskQueue; /** If set, acknowledges background results at this interval (ms) while the app is in the foreground. */ foregroundIntervalMs?: number; } /** * Options for {@link defineExpoSwapBackgroundTask}. */ interface DefineSwapBackgroundTaskOptions { /** AsyncStorage-backed queue (must match the one passed to ExpoArkadeSwaps.setup). */ taskQueue: AsyncStorageTaskQueue; /** Swap repository (fresh instance is fine — connects to the same DB). */ swapRepository: SwapRepository; /** Factory to reconstruct Identity from secure storage in the background. */ identityFactory: () => Promise<Identity>; } /** * Configuration for {@link ExpoArkadeSwaps.setup}. */ interface ExpoArkadeSwapsConfig extends ArkadeSwapsConfig { /** * Ark server base URL (e.g. "https://ark.example.com"). * * Recommended for type-safe background rehydration. If omitted, * ExpoArkadeSwaps will attempt to derive it from the ArkProvider. */ arkServerUrl?: string; background: ExpoSwapBackgroundConfig; } /** @deprecated Use ExpoArkadeSwapsConfig instead */ type ExpoArkadeLightningConfig = ExpoArkadeSwapsConfig; /** * Task type identifier for {@link swapsPollProcessor}. */ declare const SWAP_POLL_TASK_TYPE = "swap-poll"; /** * Stateless processor that polls Boltz for swap status updates and * attempts best-effort claim/refund for actionable swaps. * * Designed for Expo background tasks (~30s window) and follows the * same `TaskProcessor` pattern as `contractPollProcessor` in ts-sdk. * * Steps: * 1. Read all non-final swaps from SwapRepository * 2. Poll Boltz HTTP API for each swap's current status * 3. Persist status changes immediately * 4. For actionable statuses: attempt claimVHTLC / refundVHTLC (best-effort) * 5. Return summary metrics */ declare const swapsPollProcessor: TaskProcessor<SwapTaskDependencies>; export { type DefineSwapBackgroundTaskOptions as D, type ExpoArkadeSwapsConfig as E, type PersistedSwapBackgroundConfig as P, SWAP_POLL_TASK_TYPE as S, type SwapTaskDependencies as a, type ExpoArkadeLightningConfig as b, type ExpoSwapBackgroundConfig as c, swapsPollProcessor as s };