@satora/swap 0.0.5-rc.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/bitcoin-reader-esplora-GRUP7RAG.js +11 -0
- package/dist/bitcoin-reader-esplora-GRUP7RAG.js.map +1 -0
- package/dist/chunk-J35RZBDW.js +65 -0
- package/dist/chunk-J35RZBDW.js.map +1 -0
- package/dist/index.cjs +1856 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +955 -3
- package/dist/index.d.ts +955 -3
- package/dist/index.js +1770 -0
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +2 -0
- package/dist/node.d.ts +2 -0
- package/package.json +10 -3
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @satora/swap — the Satora-scoped name for the swap client.\n *\n * Re-exports the legacy `@lendasat/lendaswap-sdk-pure` bundle verbatim\n * (Client, ClientBuilder, signer helpers, etc.) so new code can import\n * `@satora/swap` while the published legacy package keeps working. This\n * is the seam for migrating implementation into `@satora/*` later.\n */\nexport * from \"@lendasat/lendaswap-sdk-pure\";\n"],"mappings":";AAQA,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/actions/derive.ts","../src/actions/status.ts","../src/client.ts","../src/contracts/arkade-manager.ts","../src/contracts/arkade.ts","../src/contracts/preimage.ts","../src/contracts/arkade-network.ts","../src/contracts/bitcoin-manager.ts","../src/contracts/bitcoin.ts","../src/contracts/evm.ts","../src/contracts/types.ts","../src/contracts/evm-manager.ts","../src/contracts/evm-reader-viem.ts","../src/contracts/arkade-vhtlc.ts","../src/tracker/from-swap.ts","../src/tracker/swap-tracker.ts"],"sourcesContent":["/**\n * @satora/swap — the Satora swap client.\n *\n * Re-exports the legacy `@lendasat/lendaswap-sdk-pure` bundle (types, signer\n * helpers, storage, etc.), but shadows `Client` and `ClientBuilder` with the\n * Satora-native versions from `./client`. Those are drop-in replacements — same\n * public surface, forwarding to an internal legacy client for now — and are the\n * seam for migrating implementation into `@satora/*` and adding new features.\n *\n * Explicit named exports below take precedence over the `export *` star for the\n * same names, so consumers importing `{ Client, ClientBuilder }` get the new\n * ones while everything else stays legacy.\n */\nexport * from \"@lendasat/lendaswap-sdk-pure\";\n// Satora-native features.\nexport { deriveSwapActions } from \"./actions/derive.js\";\nexport { deriveSwapStatus } from \"./actions/status.js\";\nexport type * from \"./actions/types.js\";\nexport { Client, ClientBuilder } from \"./client.js\";\n// Observe-mode tracking: per-ledger monitors + the recovery-bundle mapper.\nexport {\n ArkadeContractManager,\n type ArkadeContractManagerDeps,\n type ArkadeCreateConfig,\n} from \"./contracts/arkade-manager.js\";\nexport { defaultArkadeServerUrl } from \"./contracts/arkade-network.js\";\nexport {\n type ArkadeVhtlcInput,\n buildArkadeVhtlcRef,\n} from \"./contracts/arkade-vhtlc.js\";\nexport {\n type BitcoinChainReader,\n BitcoinContractManager,\n type BitcoinContractManagerDeps,\n type BitcoinCreateConfig,\n} from \"./contracts/bitcoin-manager.js\";\nexport {\n DEFAULT_ESPLORA_URLS,\n esploraReader,\n htlcFactsFromEsploraTxs,\n} from \"./contracts/bitcoin-reader-esplora.js\";\nexport {\n type EvmChainReader,\n EvmContractManager,\n type EvmContractManagerDeps,\n} from \"./contracts/evm-manager.js\";\nexport {\n createEvmRpcReader,\n DEFAULT_EVM_RPCS,\n defaultEvmReaders,\n type EvmLogClient,\n evmReaderFromClient,\n} from \"./contracts/evm-reader-viem.js\";\nexport type * from \"./contracts/types.js\";\nexport { htlcKey } from \"./contracts/types.js\";\nexport { swapToTracked } from \"./tracker/from-swap.js\";\nexport {\n type ActionSubscriber,\n SwapTracker,\n type TrackedSwap,\n} from \"./tracker/swap-tracker.js\";\n","import type {\n ClaimAction,\n FundAction,\n NoneAction,\n RefundUnilateralAction,\n SwapActionInput,\n SwapActions,\n WaitAction,\n} from \"./types.js\";\n\nexport function deriveSwapActions(input: SwapActionInput): SwapActions {\n const {\n status,\n clientChainNow,\n serverChainNow,\n clientRefundLocktime,\n serverRefundLocktime,\n clientFunds = true,\n } = input;\n\n switch (status) {\n case \"pending\": {\n // Pay-on-Lightning: the client's \"funding\" is paying the invoice off-chain\n // (handled by their Lightning wallet), not an on-chain deposit — there is\n // nothing for us to recommend funding, so just wait for the invoice to land\n // as a funded HTLC we can claim.\n if (!clientFunds) {\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason: \"Waiting for the Lightning payment to be locked in.\",\n };\n return { recommended: \"wait\", actions: [wait] };\n }\n\n // Funding is \"too late\" once past the client's refund locktime (the funded\n // deposit would be immediately refundable).\n if (clientChainNow >= clientRefundLocktime) return { actions: [] };\n\n const fund: FundAction = {\n id: \"fund\",\n recommended: true,\n // Funding spends new user money, so it is never auto-run.\n automation: \"manual\",\n reason: \"Send the deposit to start the swap.\",\n };\n return { recommended: \"fund\", actions: [fund] };\n }\n\n case \"clientfundingseen\": {\n // Funding tx seen but not yet confirmed — wait for confirmation (then the\n // server funds its side). Nothing to refund until the HTLC confirms.\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason: \"Waiting for your funding transaction to confirm.\",\n };\n return { recommended: \"wait\", actions: [wait] };\n }\n\n case \"clientfunded\": {\n const refundUnlocked = clientChainNow >= clientRefundLocktime;\n\n if (refundUnlocked) {\n // Timelock passed: reclaiming the deposit is the recommended way out.\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: true,\n automation: \"confirm\",\n reason: \"Reclaim your deposit.\",\n };\n return { recommended: \"refund_unilateral\", actions: [refund] };\n }\n\n // Still within the timelock: wait for the server; refund is a valid but\n // not-yet-runnable option, surfaced so the UI can show when it unlocks.\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason: \"Waiting for the server to fund the swap.\",\n };\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: false,\n automation: \"confirm\",\n reason: \"Refund becomes available once the timelock passes.\",\n blockedBy: {\n kind: \"timelock_not_expired\",\n message: \"The refund timelock has not passed yet.\",\n },\n };\n return { recommended: \"wait\", actions: [wait, refund] };\n }\n\n case \"serverfunded\": {\n // The client created the swap, so it always holds the preimage.\n const claimWindowClosed = serverChainNow >= serverRefundLocktime;\n\n if (!claimWindowClosed) {\n // Server can't refund yet, so revealing the preimage by claiming is safe.\n // Claiming secures the user's funds, so it is safe to auto-run.\n const claim: ClaimAction = {\n id: \"claim\",\n recommended: true,\n automation: \"auto\",\n reason: \"Redeem the swap with your preimage.\",\n };\n return { recommended: \"claim\", actions: [claim] };\n }\n\n // Pay-on-Lightning: the client has no on-chain deposit at risk, so there is\n // nothing to protect by keeping the secret and nothing to refund. Once the\n // claim window closed the leg is (being) reclaimed by the server; the\n // client's Lightning payment unwinds on its own. Terminal.\n if (!clientFunds) {\n const done: NoneAction = {\n id: \"none\",\n recommended: true,\n automation: \"auto\",\n reason:\n \"The claim window passed — your Lightning payment will be refunded automatically.\",\n };\n return { recommended: \"none\", actions: [done] };\n }\n\n // Claim window closed: the server can now refund its HTLC, and claiming\n // would reveal the preimage — letting the server also take the client's\n // deposit. Never claim now; refund instead (keeping the secret). Refund\n // unlocks at the client's own, later timelock.\n const refundUnlocked = clientChainNow >= clientRefundLocktime;\n\n if (refundUnlocked) {\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: true,\n automation: \"confirm\",\n reason:\n \"Reclaim your deposit — do not claim, as revealing the preimage would let the server take it.\",\n };\n return { recommended: \"refund_unilateral\", actions: [refund] };\n }\n\n // Refund not unlocked yet: wait for the client timelock, then refund. Still\n // must not claim.\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason:\n \"Wait for your refund timelock — do not claim, as revealing the preimage would let the server take your deposit.\",\n };\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: false,\n automation: \"confirm\",\n reason: \"Refund becomes available once the timelock passes.\",\n blockedBy: {\n kind: \"timelock_not_expired\",\n message: \"The refund timelock has not passed yet.\",\n },\n };\n return { recommended: \"wait\", actions: [wait, refund] };\n }\n\n case \"clientredeeming\": {\n // The client's claim (redeem) is in flight — wait for it to confirm, then\n // the funds are received.\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason: \"Redeeming your funds — waiting for the claim to confirm.\",\n };\n return { recommended: \"wait\", actions: [wait] };\n }\n\n case \"clientredeemed\":\n case \"serverredeemed\": {\n // The client claimed its funds — done from the client's side. The server\n // will sweep the client's deposit with the now-public preimage (and\n // `serverredeemed` means it already has); the client must not try to refund\n // it. Both are terminal successes — nothing to do.\n const done: NoneAction = {\n id: \"none\",\n recommended: true,\n automation: \"auto\",\n reason: \"Swap complete — you've received your funds.\",\n };\n return { recommended: \"none\", actions: [done] };\n }\n\n case \"expired\": {\n // \"Pending → Expired\": the funding window passed without the client\n // funding, so nothing is locked and there is nothing to refund. Terminal.\n const done: NoneAction = {\n id: \"none\",\n recommended: true,\n automation: \"auto\",\n reason: \"The swap expired without funding — nothing was locked.\",\n };\n return { recommended: \"none\", actions: [done] };\n }\n\n case \"clientrefunded\":\n case \"clientrefundedserverrefunded\":\n case \"clientrefundedserverfunded\": {\n // Terminal: the client's deposit was refunded. (`*serverrefunded` also\n // returned the server's; `clientrefundedserverfunded` is the backend's\n // \"should never occur\" error where the server funded after the client\n // refunded — the server's problem, not the client's.) Nothing to do.\n const done: NoneAction = {\n id: \"none\",\n recommended: true,\n automation: \"auto\",\n reason: \"Refunded — your deposit was returned.\",\n };\n return { recommended: \"none\", actions: [done] };\n }\n\n case \"clientredeemedandclientrefunded\": {\n // Error state: the client both redeemed and refunded (took both sides).\n // Anomalous but terminal — nothing for the client to do.\n const done: NoneAction = {\n id: \"none\",\n recommended: true,\n automation: \"auto\",\n reason:\n \"This swap ended in an anomalous state (redeemed and refunded); no action needed.\",\n };\n return { recommended: \"none\", actions: [done] };\n }\n\n case \"clientfundedserverrefunded\":\n case \"serverwontfund\":\n case \"clientfundedtoolate\":\n case \"clientinvalidfunded\": {\n // The swap failed with the client's deposit funded — the only path is to\n // reclaim it via the client's refund timelock. (No happy-path wait: unlike\n // `clientfunded`, the swap will not complete.)\n const refundUnlocked = clientChainNow >= clientRefundLocktime;\n\n if (refundUnlocked) {\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: true,\n automation: \"confirm\",\n reason: \"Reclaim your deposit — the swap did not complete.\",\n };\n return { recommended: \"refund_unilateral\", actions: [refund] };\n }\n\n // Refund not unlocked yet: wait for the client timelock, then refund.\n const wait: WaitAction = {\n id: \"wait\",\n recommended: true,\n automation: \"auto\",\n reason:\n \"The swap did not complete; waiting for the refund timelock to reclaim your deposit.\",\n };\n const refund: RefundUnilateralAction = {\n id: \"refund_unilateral\",\n recommended: false,\n automation: \"confirm\",\n reason: \"Refund becomes available once the timelock passes.\",\n blockedBy: {\n kind: \"timelock_not_expired\",\n message: \"The refund timelock has not passed yet.\",\n },\n };\n return { recommended: \"wait\", actions: [wait, refund] };\n }\n\n default:\n return assertNever(status);\n }\n}\n\n/** Exhaustiveness guard: a compile error here means a `SwapStatus` case is missing. */\nfunction assertNever(status: never): never {\n throw new Error(`unhandled swap status: ${String(status)}`);\n}\n","/**\n * Derive a swap's lifecycle status from on-chain observations alone — the\n * trusted, server-independent source of truth.\n *\n * Pure: `deriveSwapStatus(observations) -> SwapStatus | undefined`. The wrapper\n * gathers the {@link SwapObservations} from chain (the server's status is only a\n * hint used to fetch efficiently), then cross-checks: if this disagrees with the\n * server, act on this. If the server is unavailable, derive from the local\n * recovery bundle's HTLC addresses — recovery still works.\n *\n * Returns `undefined` for contradictory/indeterminate observations (e.g. the\n * server's HTLC swept-by-claim while the client's HTLC was never involved — the\n * server can't hold the preimage before the client reveals it).\n *\n * Scope: this maps *settled* HTLC state to a status. Time- or param-dependent\n * refinements aren't derivable from HTLC state alone and are layered on\n * afterwards (or collapse into the state here):\n * - `expired` / `clientfundedtoolate`: `pending`/`clientfunded` + a clock check.\n * - `clientinvalidfunded`: needs the expected HTLC params, not just \"confirmed\".\n * - `serverwontfund`: a server intention, invisible on-chain — acts like\n * `clientfunded` (refund after the timelock), so it never needs deriving.\n * - `clientredeeming`: an in-flight (mempool) claim — a transient, not modelled\n * from settled state here.\n */\nimport type { SwapStatus } from \"@lendasat/lendaswap-sdk-pure\";\nimport type { HtlcObservation, SwapObservations } from \"./types.js\";\n\nexport function deriveSwapStatus(\n obs: SwapObservations,\n): SwapStatus | undefined {\n const { clientHtlc, serverHtlc } = obs;\n\n // Lightning swaps watch a single on-chain leg; the other side is an off-chain\n // Lightning payment with no HTLC (see SwapObservations). Derive from the leg\n // that exists.\n if (serverHtlc === undefined && clientHtlc !== undefined) {\n return receiveOnLightningStatus(clientHtlc); // *_to_lightning\n }\n if (clientHtlc === undefined && serverHtlc !== undefined) {\n return payOnLightningStatus(serverHtlc); // lightning_to_*\n }\n if (clientHtlc === undefined || serverHtlc === undefined) return undefined;\n\n // A spend on either HTLC has resolved (part of) the swap — check these first.\n if (clientHtlc === \"spent_claim\" && serverHtlc === \"spent_claim\") {\n return \"serverredeemed\"; // client redeemed, server swept — fully complete\n }\n if (clientHtlc === \"spent_refund\" && serverHtlc === \"spent_claim\") {\n return \"clientredeemedandclientrefunded\"; // client took both sides (anomaly)\n }\n if (clientHtlc === \"spent_refund\" && serverHtlc === \"spent_refund\") {\n return \"clientrefundedserverrefunded\";\n }\n if (clientHtlc === \"spent_refund\" && serverHtlc === \"confirmed\") {\n return \"clientrefundedserverfunded\"; // error state per the backend\n }\n if (\n clientHtlc === \"spent_refund\" &&\n (serverHtlc === \"absent\" || serverHtlc === \"mempool\")\n ) {\n return \"clientrefunded\";\n }\n if (clientHtlc === \"confirmed\" && serverHtlc === \"spent_claim\") {\n return \"clientredeemed\"; // client claimed the server's HTLC\n }\n if (clientHtlc === \"confirmed\" && serverHtlc === \"spent_refund\") {\n return \"clientfundedserverrefunded\"; // server let its HTLC time out\n }\n\n // Client funded, but not on the swap's terms (e.g. under the expected amount) —\n // the swap won't complete honestly, so reclaim the deposit.\n if (clientHtlc === \"invalid\") return \"clientinvalidfunded\";\n\n // No relevant spend — funding progression. `serverfunded` requires the server's\n // HTLC to be `confirmed` (correct amount/terms); an `invalid` server funding is\n // deliberately NOT serverfunded, so the client never claims a bad server leg —\n // it stays `clientfunded` and the client refunds after its timelock.\n if (clientHtlc === \"absent\") return \"pending\";\n if (clientHtlc === \"mempool\") return \"clientfundingseen\";\n if (clientHtlc === \"confirmed\") {\n return serverHtlc === \"confirmed\" ? \"serverfunded\" : \"clientfunded\";\n }\n\n // Contradictory (e.g. the client's HTLC swept-by-claim while the server's HTLC\n // isn't also claimed — impossible without the preimage having been revealed).\n return undefined;\n}\n\n/**\n * Receive-on-Lightning (`arkade_to_lightning`, `evm_to_lightning`): the client\n * funds a single on-chain HTLC and receives via Lightning. There is no\n * client-claimed server leg — the server sweeping the client's HTLC with the\n * preimage (it obtained by paying the client's Lightning invoice) is the success\n * signal. So the whole lifecycle derives from the client's leg alone.\n */\nfunction receiveOnLightningStatus(clientHtlc: HtlcObservation): SwapStatus {\n switch (clientHtlc) {\n case \"spent_claim\":\n return \"serverredeemed\"; // server swept the deposit ⟹ it paid the invoice\n case \"spent_refund\":\n return \"clientrefunded\";\n case \"invalid\":\n return \"clientinvalidfunded\";\n case \"confirmed\":\n return \"clientfunded\"; // funded; waiting for the server to pay + sweep\n case \"mempool\":\n return \"clientfundingseen\";\n case \"absent\":\n return \"pending\";\n }\n}\n\n/**\n * Pay-on-Lightning (`lightning_to_arkade`, `lightning_to_evm`): the client pays a\n * Lightning invoice (off-chain, nothing for us to watch) and claims a single\n * on-chain HTLC. That claim completes the swap. The client has no on-chain\n * deposit at risk, so there is never a refund — a hold invoice that never settles\n * is auto-cancelled by the Lightning wallet.\n */\nfunction payOnLightningStatus(serverHtlc: HtlcObservation): SwapStatus {\n switch (serverHtlc) {\n case \"spent_claim\":\n return \"clientredeemed\"; // client claimed the on-chain leg ⟹ complete\n case \"confirmed\":\n return \"serverfunded\"; // ready to claim\n case \"spent_refund\":\n // The server reclaimed its leg — the swap failed; the client's Lightning\n // payment unwinds on its own. Terminal, nothing on-chain for the client.\n return \"clientrefunded\";\n case \"invalid\":\n case \"mempool\":\n case \"absent\":\n // Nothing (correct) to claim yet — keep waiting for the invoice to land as a\n // funded HTLC. `invalid` (wrong amount/terms) also stays a wait: the client\n // must not claim a bad leg, and the Lightning payment will unwind.\n return \"pending\";\n }\n}\n","/**\n * @satora/swap — the Satora swap client.\n *\n * A standalone `Client` with the same public surface as the legacy\n * `@lendasat/lendaswap-sdk-pure` client, so it is a drop-in replacement. For\n * now every legacy method is forwarded to an internally-owned legacy client\n * instance (see the `@deprecated` delegators below). New Satora-native features\n * are added directly on this class, and\n * individual delegators get replaced with native implementations over time.\n */\nimport {\n Client as LegacyClient,\n type ClientBuilder as LegacyClientBuilder,\n} from \"@lendasat/lendaswap-sdk-pure\";\nimport { ArkadeContractManager } from \"./contracts/arkade-manager.js\";\nimport { defaultArkadeServerUrl } from \"./contracts/arkade-network.js\";\nimport { BitcoinContractManager } from \"./contracts/bitcoin-manager.js\";\nimport { DEFAULT_ESPLORA_URLS } from \"./contracts/bitcoin-reader-esplora.js\";\nimport { EvmContractManager } from \"./contracts/evm-manager.js\";\nimport { defaultEvmReaders } from \"./contracts/evm-reader-viem.js\";\nimport type { ContractManager, Ledger } from \"./contracts/types.js\";\nimport { swapToTracked } from \"./tracker/from-swap.js\";\nimport {\n type ActionSubscriber,\n SwapTracker,\n type TrackedSwap,\n} from \"./tracker/swap-tracker.js\";\n\n/** How the client should set up observe-mode tracking. */\ntype TrackingConfig = {\n /** Whether tracking is enabled at all (default on; `withoutTracking()` clears). */\n enabled: boolean;\n /** Explicit per-ledger managers, bypassing auto-construction (advanced/testing). */\n managers?: Map<Ledger, ContractManager>;\n /** Ark server URL override; defaults to the mainnet server when unset. */\n arkadeServerUrl?: string;\n /** Per-chain EVM RPC overrides; the EVM manager is auto-built either way. */\n evmRpcUrls?: Record<number, string>;\n /** Esplora REST URL override for the Bitcoin manager; defaults to mainnet mempool.space. */\n esploraUrl?: string;\n /** Poll interval (ms) for advancing observations/clocks; defaults to 5s. */\n refreshIntervalMs?: number;\n};\n\nexport class Client {\n /** The wrapped legacy client. Calls are forwarded here until migrated. */\n readonly #legacy: LegacyClient;\n /** Tracking configuration; managers are built lazily from it on first use. */\n readonly #tracking: TrackingConfig;\n /** Per-ledger monitors, resolved once from {@link #tracking}. */\n #managers: Map<Ledger, ContractManager> | undefined;\n #tracker: SwapTracker | undefined;\n #started = false;\n\n /**\n * Creates a new Client instance.\n *\n * Prefer {@link Client.builder} for new code.\n */\n constructor(...args: ConstructorParameters<typeof LegacyClient>);\n /** @internal Wrap an already-built legacy client, optionally with tracking. */\n constructor(legacy: LegacyClient, tracking?: TrackingConfig);\n constructor(\n ...args:\n | ConstructorParameters<typeof LegacyClient>\n | [legacy: LegacyClient, tracking?: TrackingConfig]\n ) {\n if (args[0] instanceof LegacyClient) {\n this.#legacy = args[0];\n this.#tracking = (args[1] as TrackingConfig | undefined) ?? {\n enabled: false,\n };\n } else {\n this.#legacy = new LegacyClient(\n ...(args as ConstructorParameters<typeof LegacyClient>),\n );\n // A raw (non-builder) client has no tracking config to build from.\n this.#tracking = { enabled: false };\n }\n }\n\n /** Start building a {@link Client}. */\n static builder(): ClientBuilder {\n return new ClientBuilder();\n }\n\n /** Escape hatch: the underlying legacy client, during migration. */\n get legacy(): LegacyClient {\n return this.#legacy;\n }\n\n // --- delegated legacy surface (getters) ---\n\n /** Delegated to the legacy client (migration checkpoint). */\n get api(): LegacyClient[\"api\"] {\n return this.#legacy.api;\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n get baseUrl(): LegacyClient[\"baseUrl\"] {\n return this.#legacy.baseUrl;\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n get cctpInbound(): LegacyClient[\"cctpInbound\"] {\n return this.#legacy.cctpInbound;\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n get swapStorage(): LegacyClient[\"swapStorage\"] {\n return this.#legacy.swapStorage;\n }\n\n // --- delegated legacy surface (methods) ---\n\n /** Delegated to the legacy client (migration checkpoint). */\n subscribeToSwaps(\n ...args: Parameters<LegacyClient[\"subscribeToSwaps\"]>\n ): ReturnType<LegacyClient[\"subscribeToSwaps\"]> {\n return this.#legacy.subscribeToSwaps(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n unsubscribeFromSwaps(\n ...args: Parameters<LegacyClient[\"unsubscribeFromSwaps\"]>\n ): ReturnType<LegacyClient[\"unsubscribeFromSwaps\"]> {\n return this.#legacy.unsubscribeFromSwaps(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n closeSwapStatusSocket(\n ...args: Parameters<LegacyClient[\"closeSwapStatusSocket\"]>\n ): ReturnType<LegacyClient[\"closeSwapStatusSocket\"]> {\n return this.#legacy.closeSwapStatusSocket(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getMnemonic(\n ...args: Parameters<LegacyClient[\"getMnemonic\"]>\n ): ReturnType<LegacyClient[\"getMnemonic\"]> {\n return this.#legacy.getMnemonic(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n loadMnemonic(\n ...args: Parameters<LegacyClient[\"loadMnemonic\"]>\n ): ReturnType<LegacyClient[\"loadMnemonic\"]> {\n return this.#legacy.loadMnemonic(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getNostrKeyHex(\n ...args: Parameters<LegacyClient[\"getNostrKeyHex\"]>\n ): ReturnType<LegacyClient[\"getNostrKeyHex\"]> {\n return this.#legacy.getNostrKeyHex(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getUserIdXpub(\n ...args: Parameters<LegacyClient[\"getUserIdXpub\"]>\n ): ReturnType<LegacyClient[\"getUserIdXpub\"]> {\n return this.#legacy.getUserIdXpub(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n deriveSwapParams(\n ...args: Parameters<LegacyClient[\"deriveSwapParams\"]>\n ): ReturnType<LegacyClient[\"deriveSwapParams\"]> {\n return this.#legacy.deriveSwapParams(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n deriveSwapParamsAtIndex(\n ...args: Parameters<LegacyClient[\"deriveSwapParamsAtIndex\"]>\n ): ReturnType<LegacyClient[\"deriveSwapParamsAtIndex\"]> {\n return this.#legacy.deriveSwapParamsAtIndex(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getEvmAddress(\n ...args: Parameters<LegacyClient[\"getEvmAddress\"]>\n ): ReturnType<LegacyClient[\"getEvmAddress\"]> {\n return this.#legacy.getEvmAddress(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getKeyIndex(\n ...args: Parameters<LegacyClient[\"getKeyIndex\"]>\n ): ReturnType<LegacyClient[\"getKeyIndex\"]> {\n return this.#legacy.getKeyIndex(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n setKeyIndex(\n ...args: Parameters<LegacyClient[\"setKeyIndex\"]>\n ): ReturnType<LegacyClient[\"setKeyIndex\"]> {\n return this.#legacy.setKeyIndex(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getStatus(\n ...args: Parameters<LegacyClient[\"getStatus\"]>\n ): ReturnType<LegacyClient[\"getStatus\"]> {\n return this.#legacy.getStatus(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n healthCheck(\n ...args: Parameters<LegacyClient[\"healthCheck\"]>\n ): ReturnType<LegacyClient[\"healthCheck\"]> {\n return this.#legacy.healthCheck(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getVersion(\n ...args: Parameters<LegacyClient[\"getVersion\"]>\n ): ReturnType<LegacyClient[\"getVersion\"]> {\n return this.#legacy.getVersion(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getSupportAgents(\n ...args: Parameters<LegacyClient[\"getSupportAgents\"]>\n ): ReturnType<LegacyClient[\"getSupportAgents\"]> {\n return this.#legacy.getSupportAgents(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getMtp(\n ...args: Parameters<LegacyClient[\"getMtp\"]>\n ): ReturnType<LegacyClient[\"getMtp\"]> {\n return this.#legacy.getMtp(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getTokens(\n ...args: Parameters<LegacyClient[\"getTokens\"]>\n ): ReturnType<LegacyClient[\"getTokens\"]> {\n return this.#legacy.getTokens(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getSwapPairs(\n ...args: Parameters<LegacyClient[\"getSwapPairs\"]>\n ): ReturnType<LegacyClient[\"getSwapPairs\"]> {\n return this.#legacy.getSwapPairs(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getChainConfig(\n ...args: Parameters<LegacyClient[\"getChainConfig\"]>\n ): ReturnType<LegacyClient[\"getChainConfig\"]> {\n return this.#legacy.getChainConfig(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getReferralFee(\n ...args: Parameters<LegacyClient[\"getReferralFee\"]>\n ): ReturnType<LegacyClient[\"getReferralFee\"]> {\n return this.#legacy.getReferralFee(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getNetworkFees(\n ...args: Parameters<LegacyClient[\"getNetworkFees\"]>\n ): ReturnType<LegacyClient[\"getNetworkFees\"]> {\n return this.#legacy.getNetworkFees(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getDexQuote(\n ...args: Parameters<LegacyClient[\"getDexQuote\"]>\n ): ReturnType<LegacyClient[\"getDexQuote\"]> {\n return this.#legacy.getDexQuote(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n composeQuote(\n ...args: Parameters<LegacyClient[\"composeQuote\"]>\n ): ReturnType<LegacyClient[\"composeQuote\"]> {\n return this.#legacy.composeQuote(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getQuote(\n ...args: Parameters<LegacyClient[\"getQuote\"]>\n ): ReturnType<LegacyClient[\"getQuote\"]> {\n return this.#legacy.getQuote(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getSwap(\n ...args: Parameters<LegacyClient[\"getSwap\"]>\n ): ReturnType<LegacyClient[\"getSwap\"]> {\n return this.#legacy.getSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getBulkStatus(\n ...args: Parameters<LegacyClient[\"getBulkStatus\"]>\n ): ReturnType<LegacyClient[\"getBulkStatus\"]> {\n return this.#legacy.getBulkStatus(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getStoredSwap(\n ...args: Parameters<LegacyClient[\"getStoredSwap\"]>\n ): ReturnType<LegacyClient[\"getStoredSwap\"]> {\n return this.#legacy.getStoredSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n listAllSwaps(\n ...args: Parameters<LegacyClient[\"listAllSwaps\"]>\n ): ReturnType<LegacyClient[\"listAllSwaps\"]> {\n return this.#legacy.listAllSwaps(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n deleteSwap(\n ...args: Parameters<LegacyClient[\"deleteSwap\"]>\n ): ReturnType<LegacyClient[\"deleteSwap\"]> {\n return this.#legacy.deleteSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n clearSwapStorage(\n ...args: Parameters<LegacyClient[\"clearSwapStorage\"]>\n ): ReturnType<LegacyClient[\"clearSwapStorage\"]> {\n return this.#legacy.clearSwapStorage(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n recoverSwaps(\n ...args: Parameters<LegacyClient[\"recoverSwaps\"]>\n ): ReturnType<LegacyClient[\"recoverSwaps\"]> {\n return this.#legacy.recoverSwaps(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n recoverAllSwaps(\n ...args: Parameters<LegacyClient[\"recoverAllSwaps\"]>\n ): ReturnType<LegacyClient[\"recoverAllSwaps\"]> {\n return this.#legacy.recoverAllSwaps(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n amountsForSwap(\n ...args: Parameters<LegacyClient[\"amountsForSwap\"]>\n ): ReturnType<LegacyClient[\"amountsForSwap\"]> {\n return this.#legacy.amountsForSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n claim(\n ...args: Parameters<LegacyClient[\"claim\"]>\n ): ReturnType<LegacyClient[\"claim\"]> {\n return this.#legacy.claim(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n claimViaGasless(\n ...args: Parameters<LegacyClient[\"claimViaGasless\"]>\n ): ReturnType<LegacyClient[\"claimViaGasless\"]> {\n return this.#legacy.claimViaGasless(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n claimArkade(\n ...args: Parameters<LegacyClient[\"claimArkade\"]>\n ): ReturnType<LegacyClient[\"claimArkade\"]> {\n return this.#legacy.claimArkade(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n continueArkadeClaimSwap(\n ...args: Parameters<LegacyClient[\"continueArkadeClaimSwap\"]>\n ): ReturnType<LegacyClient[\"continueArkadeClaimSwap\"]> {\n return this.#legacy.continueArkadeClaimSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n refundSwap(\n ...args: Parameters<LegacyClient[\"refundSwap\"]>\n ): ReturnType<LegacyClient[\"refundSwap\"]> {\n return this.#legacy.refundSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getCollabRefundEvmParams(\n ...args: Parameters<LegacyClient[\"getCollabRefundEvmParams\"]>\n ): ReturnType<LegacyClient[\"getCollabRefundEvmParams\"]> {\n return this.#legacy.getCollabRefundEvmParams(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n buildCollabRefundEvmTypedData(\n ...args: Parameters<LegacyClient[\"buildCollabRefundEvmTypedData\"]>\n ): ReturnType<LegacyClient[\"buildCollabRefundEvmTypedData\"]> {\n return this.#legacy.buildCollabRefundEvmTypedData(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n collabRefundEvmSwap(\n ...args: Parameters<LegacyClient[\"collabRefundEvmSwap\"]>\n ): ReturnType<LegacyClient[\"collabRefundEvmSwap\"]> {\n return this.#legacy.collabRefundEvmSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n submitCollabRefundEvm(\n ...args: Parameters<LegacyClient[\"submitCollabRefundEvm\"]>\n ): ReturnType<LegacyClient[\"submitCollabRefundEvm\"]> {\n return this.#legacy.submitCollabRefundEvm(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createSwap(\n ...args: Parameters<LegacyClient[\"createSwap\"]>\n ): ReturnType<LegacyClient[\"createSwap\"]> {\n return this.#legacy.createSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createArkadeToEvmSwapGeneric(\n ...args: Parameters<LegacyClient[\"createArkadeToEvmSwapGeneric\"]>\n ): ReturnType<LegacyClient[\"createArkadeToEvmSwapGeneric\"]> {\n return this.#legacy.createArkadeToEvmSwapGeneric(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createLightningToEvmSwapGeneric(\n ...args: Parameters<LegacyClient[\"createLightningToEvmSwapGeneric\"]>\n ): ReturnType<LegacyClient[\"createLightningToEvmSwapGeneric\"]> {\n return this.#legacy.createLightningToEvmSwapGeneric(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createBitcoinToEvmSwap(\n ...args: Parameters<LegacyClient[\"createBitcoinToEvmSwap\"]>\n ): ReturnType<LegacyClient[\"createBitcoinToEvmSwap\"]> {\n return this.#legacy.createBitcoinToEvmSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createBitcoinToArkadeSwap(\n ...args: Parameters<LegacyClient[\"createBitcoinToArkadeSwap\"]>\n ): ReturnType<LegacyClient[\"createBitcoinToArkadeSwap\"]> {\n return this.#legacy.createBitcoinToArkadeSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createLightningToArkadeSwap(\n ...args: Parameters<LegacyClient[\"createLightningToArkadeSwap\"]>\n ): ReturnType<LegacyClient[\"createLightningToArkadeSwap\"]> {\n return this.#legacy.createLightningToArkadeSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createArkadeToLightningSwap(\n ...args: Parameters<LegacyClient[\"createArkadeToLightningSwap\"]>\n ): ReturnType<LegacyClient[\"createArkadeToLightningSwap\"]> {\n return this.#legacy.createArkadeToLightningSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getArkadeToLightningQuote(\n ...args: Parameters<LegacyClient[\"getArkadeToLightningQuote\"]>\n ): ReturnType<LegacyClient[\"getArkadeToLightningQuote\"]> {\n return this.#legacy.getArkadeToLightningQuote(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n retryArkadeToLightningSwap(\n ...args: Parameters<LegacyClient[\"retryArkadeToLightningSwap\"]>\n ): ReturnType<LegacyClient[\"retryArkadeToLightningSwap\"]> {\n return this.#legacy.retryArkadeToLightningSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createEvmToArkadeSwapGeneric(\n ...args: Parameters<LegacyClient[\"createEvmToArkadeSwapGeneric\"]>\n ): ReturnType<LegacyClient[\"createEvmToArkadeSwapGeneric\"]> {\n return this.#legacy.createEvmToArkadeSwapGeneric(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createEvmToBitcoinSwap(\n ...args: Parameters<LegacyClient[\"createEvmToBitcoinSwap\"]>\n ): ReturnType<LegacyClient[\"createEvmToBitcoinSwap\"]> {\n return this.#legacy.createEvmToBitcoinSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n createEvmToLightningSwapGeneric(\n ...args: Parameters<LegacyClient[\"createEvmToLightningSwapGeneric\"]>\n ): ReturnType<LegacyClient[\"createEvmToLightningSwapGeneric\"]> {\n return this.#legacy.createEvmToLightningSwapGeneric(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getCoordinatorFundingCallDataPermit2(\n ...args: Parameters<LegacyClient[\"getCoordinatorFundingCallDataPermit2\"]>\n ): ReturnType<LegacyClient[\"getCoordinatorFundingCallDataPermit2\"]> {\n return this.#legacy.getCoordinatorFundingCallDataPermit2(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getPermit2FundingParamsUnsigned(\n ...args: Parameters<LegacyClient[\"getPermit2FundingParamsUnsigned\"]>\n ): ReturnType<LegacyClient[\"getPermit2FundingParamsUnsigned\"]> {\n return this.#legacy.getPermit2FundingParamsUnsigned(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n fundSwap(\n ...args: Parameters<LegacyClient[\"fundSwap\"]>\n ): ReturnType<LegacyClient[\"fundSwap\"]> {\n return this.#legacy.fundSwap(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n refundEvmWithSigner(\n ...args: Parameters<LegacyClient[\"refundEvmWithSigner\"]>\n ): ReturnType<LegacyClient[\"refundEvmWithSigner\"]> {\n return this.#legacy.refundEvmWithSigner(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n collabRefundEvmWithSigner(\n ...args: Parameters<LegacyClient[\"collabRefundEvmWithSigner\"]>\n ): ReturnType<LegacyClient[\"collabRefundEvmWithSigner\"]> {\n return this.#legacy.collabRefundEvmWithSigner(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n fundSwapGasless(\n ...args: Parameters<LegacyClient[\"fundSwapGasless\"]>\n ): ReturnType<LegacyClient[\"fundSwapGasless\"]> {\n return this.#legacy.fundSwapGasless(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getSwapDepositorKey(\n ...args: Parameters<LegacyClient[\"getSwapDepositorKey\"]>\n ): ReturnType<LegacyClient[\"getSwapDepositorKey\"]> {\n return this.#legacy.getSwapDepositorKey(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n getEvmDepositorKey(\n ...args: Parameters<LegacyClient[\"getEvmDepositorKey\"]>\n ): ReturnType<LegacyClient[\"getEvmDepositorKey\"]> {\n return this.#legacy.getEvmDepositorKey(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n recoverGaslessFunds(\n ...args: Parameters<LegacyClient[\"recoverGaslessFunds\"]>\n ): ReturnType<LegacyClient[\"recoverGaslessFunds\"]> {\n return this.#legacy.recoverGaslessFunds(...args);\n }\n\n /** Delegated to the legacy client (migration checkpoint). */\n hasReceivedVtxo(\n ...args: Parameters<LegacyClient[\"hasReceivedVtxo\"]>\n ): ReturnType<LegacyClient[\"hasReceivedVtxo\"]> {\n return this.#legacy.hasReceivedVtxo(...args);\n }\n\n // --- Satora-native features go below ---\n\n /**\n * Start observing the user's active swaps and deriving each one's next action.\n *\n * Loads stored swaps, maps the ones whose ledgers are observable to\n * {@link TrackedSwap}s, and runs the per-ledger monitors. Idempotent. Requires\n * the client to have been built with {@link ClientBuilder.withTracking}.\n * Subscribe with {@link subscribeToActions}; release with\n * {@link stopTracking}.\n */\n async startTracking(): Promise<void> {\n if (!this.#tracking.enabled)\n throw new Error(\n \"tracking is disabled — remove .withoutTracking() to enable it\",\n );\n if (this.#started) return;\n this.#started = true;\n try {\n const tracker = new SwapTracker(await this.#ensureManagers(), {\n refreshIntervalMs: this.#tracking.refreshIntervalMs ?? 5_000,\n });\n this.#tracker = tracker;\n const swaps = await this.listAllSwaps();\n const tracked = swaps\n .map(swapToTracked)\n .filter((s): s is TrackedSwap => s !== undefined);\n await tracker.startTracking(tracked);\n } catch (error) {\n // A partway failure (e.g. a ledger register/refresh erroring on an RPC or\n // indexer hiccup) left `#tracker` set and some legs registered. Tear it down\n // so `subscribeToActions` still reports \"not started\" and a retry begins\n // clean, instead of leaking the partial tracker's registrations/listeners.\n this.#tracker?.stop();\n this.#tracker = undefined;\n this.#started = false;\n throw error;\n }\n }\n\n /**\n * Subscribe to next-action updates: `cb` fires with the current action for each\n * tracked swap immediately, then on every change. Call after\n * {@link startTracking}. Returns an unsubscribe fn.\n */\n subscribeToActions(cb: ActionSubscriber): () => void {\n if (!this.#tracker)\n throw new Error(\"call startTracking() before subscribeToActions()\");\n return this.#tracker.subscribeToActions(cb);\n }\n\n /** Stop tracking and drop subscribers. The managers themselves are not disposed. */\n stopTracking(): void {\n this.#tracker?.stop();\n this.#tracker = undefined;\n this.#started = false;\n }\n\n /**\n * Resolve the per-ledger managers once — the explicit override if given, else\n * auto-built from config: an {@link ArkadeContractManager} from the configured\n * Ark server URL (defaulting to the mainnet server), clocked by `getMtp`, and an\n * {@link EvmContractManager} from the tested default RPCs.\n */\n async #ensureManagers(): Promise<Map<Ledger, ContractManager>> {\n if (this.#managers) return this.#managers;\n if (this.#tracking.managers) {\n this.#managers = this.#tracking.managers;\n return this.#managers;\n }\n const managers = new Map<Ledger, ContractManager>();\n const { arkadeServerUrl, evmRpcUrls, esploraUrl } = this.#tracking;\n // Arkade + Bitcoin share the Bitcoin MTP clock.\n const chainTime = async () => (await this.getMtp()).mtp * 1000;\n\n // Default to mainnet; dev/other networks override via withArkadeServerUrl.\n const arkadeUrl = arkadeServerUrl ?? defaultArkadeServerUrl(\"bitcoin\");\n if (arkadeUrl) {\n managers.set(\n \"arkade\",\n await ArkadeContractManager.create({ serverUrl: arkadeUrl, chainTime }),\n );\n }\n // EVM tracks out of the box via tested default RPCs; overrides take priority.\n const readers = defaultEvmReaders(evmRpcUrls);\n if (readers.size > 0)\n managers.set(\"evm\", EvmContractManager.fromDeps({ readers }));\n // Bitcoin observes on-chain HTLCs via esplora. Default to the public pair\n // (mempool.space + blockstream.info) with rotation/failover; an explicit URL\n // replaces them (a dev/regtest node must not fail over to mainnet).\n managers.set(\n \"bitcoin\",\n await BitcoinContractManager.create({\n esploraUrl: esploraUrl ? [esploraUrl] : DEFAULT_ESPLORA_URLS,\n chainTime,\n }),\n );\n this.#managers = managers;\n return managers;\n }\n}\n\n/**\n * Builds a {@link Client}. Mirrors the legacy `ClientBuilder` fluent surface and\n * constructs the legacy client internally, then wraps it.\n */\nexport class ClientBuilder {\n readonly #inner: LegacyClientBuilder = LegacyClient.builder();\n // Observe-mode tracking is on by default; the built client auto-builds its\n // managers from config unless disabled or given an explicit override.\n #trackingEnabled = true;\n #arkadeServerUrl: string | undefined;\n #esploraUrl: string | undefined;\n #evmRpcUrls: Record<number, string> | undefined;\n #managers: Map<Ledger, ContractManager> | undefined;\n\n /**\n * Override the EVM JSON-RPC endpoint per chainId. Optional — tracking uses\n * tested public defaults otherwise; an override is tried first, with the\n * defaults kept as fallbacks.\n */\n withEvmRpcUrls(urls: Record<number, string>): this {\n this.#evmRpcUrls = urls;\n return this;\n }\n\n /** Turn observe-mode tracking off. */\n withoutTracking(): this {\n this.#trackingEnabled = false;\n return this;\n }\n\n /**\n * Advanced: supply per-ledger {@link ContractManager}s explicitly instead of\n * letting the client auto-build them from config (useful for tests or custom\n * chain sources).\n */\n withContractManagers(managers: Map<Ledger, ContractManager>): this {\n this.#managers = managers;\n return this;\n }\n\n withBaseUrl(...args: Parameters<LegacyClientBuilder[\"withBaseUrl\"]>): this {\n this.#inner.withBaseUrl(...args);\n return this;\n }\n\n withReferralCode(\n ...args: Parameters<LegacyClientBuilder[\"withReferralCode\"]>\n ): this {\n this.#inner.withReferralCode(...args);\n return this;\n }\n\n withOrgCode(...args: Parameters<LegacyClientBuilder[\"withOrgCode\"]>): this {\n this.#inner.withOrgCode(...args);\n return this;\n }\n\n withDefaultHeaders(\n ...args: Parameters<LegacyClientBuilder[\"withDefaultHeaders\"]>\n ): this {\n this.#inner.withDefaultHeaders(...args);\n return this;\n }\n\n /**\n * Override the Esplora REST URL. Optional for tracking — the Bitcoin manager\n * otherwise defaults to mainnet mempool.space; set this for a dev/regtest node.\n */\n withEsploraUrl(url: string): this {\n this.#inner.withEsploraUrl(url);\n this.#esploraUrl = url;\n return this;\n }\n\n /**\n * Override the Ark server URL. Optional for tracking — it otherwise defaults to\n * the mainnet server; set this to track a non-mainnet (dev/signet) deployment.\n */\n withArkadeServerUrl(url: string): this {\n this.#inner.withArkadeServerUrl(url);\n this.#arkadeServerUrl = url;\n return this;\n }\n\n withSignerStorage(\n ...args: Parameters<LegacyClientBuilder[\"withSignerStorage\"]>\n ): this {\n this.#inner.withSignerStorage(...args);\n return this;\n }\n\n withSwapStorage(\n ...args: Parameters<LegacyClientBuilder[\"withSwapStorage\"]>\n ): this {\n this.#inner.withSwapStorage(...args);\n return this;\n }\n\n withMnemonic(...args: Parameters<LegacyClientBuilder[\"withMnemonic\"]>): this {\n this.#inner.withMnemonic(...args);\n return this;\n }\n\n withXprv(...args: Parameters<LegacyClientBuilder[\"withXprv\"]>): this {\n this.#inner.withXprv(...args);\n return this;\n }\n\n withAa(...args: Parameters<LegacyClientBuilder[\"withAa\"]>): this {\n this.#inner.withAa(...args);\n return this;\n }\n\n withLogger(...args: Parameters<LegacyClientBuilder[\"withLogger\"]>): this {\n this.#inner.withLogger(...args);\n return this;\n }\n\n withLogLevel(...args: Parameters<LegacyClientBuilder[\"withLogLevel\"]>): this {\n this.#inner.withLogLevel(...args);\n return this;\n }\n\n async build(): Promise<Client> {\n return new Client(await this.#inner.build(), {\n enabled: this.#trackingEnabled,\n managers: this.#managers,\n arkadeServerUrl: this.#arkadeServerUrl,\n esploraUrl: this.#esploraUrl,\n evmRpcUrls: this.#evmRpcUrls,\n });\n }\n}\n","/**\n * The Arkade {@link ContractManager} — the stateful I/O adapter that observes a\n * swap's VHTLC by polling the Ark indexer.\n *\n * We deliberately do NOT use `@arkade-os/sdk`'s `ContractManager`: its vtxo\n * annotation calls `script.forfeit()` on every contract, but a VHTLC script has\n * no `forfeit()` leaf (it exposes `claim()`/`refund()`), so watching a VHTLC\n * through it throws. Instead we read vtxos directly by pkScript — exactly what\n * the legacy SDK's claim/refund paths do — and map them with the pure helpers in\n * `./arkade.js`.\n *\n * There is no event push here, so observations advance when {@link refresh} runs;\n * the SwapTracker drives that (initial prime + periodic poll).\n */\nimport { RestIndexerProvider, type VirtualCoin } from \"@arkade-os/sdk\";\nimport { hex } from \"@scure/base\";\nimport type { HtlcObservation } from \"../actions/types.js\";\nimport type { VirtualTxSource } from \"./arkade.js\";\nimport { arkadeObservation, fetchArkadeSpend } from \"./arkade.js\";\nimport type { ContractManager, HtlcRef, Ledger } from \"./types.js\";\n\n/** The Ark indexer surface the observer needs (RestIndexerProvider satisfies it). */\nexport type ArkadeIndexer = VirtualTxSource & {\n getVtxos(opts: {\n scripts: string[];\n spendableOnly?: boolean;\n }): Promise<{ vtxos: VirtualCoin[] }>;\n};\n\nexport type ArkadeCreateConfig = {\n /** Ark server base URL — used for the indexer. */\n serverUrl: string;\n /**\n * The current Bitcoin MTP (ms) for evaluating VHTLC timelocks. Typically\n * `async () => (await client.getMtp()).mtp * 1000`.\n */\n chainTime?: () => Promise<number>;\n};\n\nexport type ArkadeContractManagerDeps = {\n indexer: ArkadeIndexer;\n /**\n * The current Bitcoin MTP (ms) — arkade CLTV timelocks are evaluated against\n * Bitcoin's clock, not the Ark server's. Optional: until wired, `chainNow()`\n * reports `undefined` and the tracker holds swaps as provisional.\n */\n chainTime?: () => Promise<number>;\n};\n\n/** True when a vtxo is a live funding of the contract (not yet spent). */\nfunction isFunded(vtxo: VirtualCoin): boolean {\n const { state } = vtxo.virtualStatus;\n return state === \"preconfirmed\" || state === \"settled\";\n}\n\n/**\n * The offchain txid that spent this contract's VHTLC, if any. Mirrors the backend\n * watcher (`unified_watcher.rs`), which keys spend detection on `arkTxId` — the\n * offchain Arkade tx whose input[0] condition witness carries the revealed\n * preimage. Falls back to `spentBy` (the checkpoint tx, which also reveals it) so\n * a spend is caught under either field: reading only `spentBy` silently missed\n * spent vtxos that expose the spend solely via `arkTxId`, leaving them classified\n * as `confirmed` forever (never emitting spent_claim/spent_refund).\n */\nfunction spendTxid(vtxos: VirtualCoin[]): string | undefined {\n const spent = vtxos.find(\n (v) =>\n v.arkTxId || v.spentBy || v.isSpent || v.virtualStatus.state === \"spent\",\n );\n return spent?.arkTxId ?? spent?.spentBy;\n}\n\nexport class ArkadeContractManager implements ContractManager {\n readonly ledger: Ledger = \"arkade\";\n\n readonly #indexer: ArkadeIndexer;\n readonly #chainTime?: () => Promise<number>;\n\n /** pkScript → the ref we're tracking. */\n readonly #refs = new Map<string, Extract<HtlcRef, { ledger: \"arkade\" }>>();\n /** pkScript → last known observation. */\n readonly #obs = new Map<string, HtlcObservation>();\n /** pkScript → the verified preimage recovered from a claim spend. */\n readonly #preimages = new Map<string, Uint8Array>();\n readonly #listeners = new Set<\n (ref: HtlcRef, state: HtlcObservation) => void\n >();\n\n #now: number | undefined;\n\n private constructor(deps: ArkadeContractManagerDeps) {\n this.#indexer = deps.indexer;\n this.#chainTime = deps.chainTime;\n }\n\n static fromDeps(deps: ArkadeContractManagerDeps): ArkadeContractManager {\n return new ArkadeContractManager(deps);\n }\n\n /** Construct a manager backed by a `RestIndexerProvider` over the Ark server. */\n static async create(\n config: ArkadeCreateConfig,\n ): Promise<ArkadeContractManager> {\n const indexer = new RestIndexerProvider(config.serverUrl);\n return ArkadeContractManager.fromDeps({\n indexer,\n chainTime: config.chainTime,\n });\n }\n\n async register(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"arkade\")\n throw new Error(\n `ArkadeContractManager can't track a '${ref.ledger}' HTLC`,\n );\n this.#refs.set(ref.script, ref);\n await this.#reconcileRef(ref);\n }\n\n async unregister(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"arkade\") return;\n this.#refs.delete(ref.script);\n this.#obs.delete(ref.script);\n this.#preimages.delete(ref.script);\n }\n\n getState(ref: HtlcRef): HtlcObservation | undefined {\n return ref.ledger === \"arkade\" ? this.#obs.get(ref.script) : undefined;\n }\n\n chainNow(_ref: HtlcRef): number | undefined {\n // Arkade CLTV timelocks share one clock (Bitcoin MTP), so the ref is unused.\n return this.#now;\n }\n\n onEvent(cb: (ref: HtlcRef, state: HtlcObservation) => void): () => void {\n this.#listeners.add(cb);\n return () => this.#listeners.delete(cb);\n }\n\n async refresh(): Promise<void> {\n if (this.#chainTime) this.#now = await this.#chainTime();\n await Promise.all(\n [...this.#refs.values()].map((ref) => this.#reconcileRef(ref)),\n );\n }\n\n dispose(): void {\n this.#listeners.clear();\n }\n\n /** The verified preimage recovered from a claim spend, if one was seen. */\n getPreimage(ref: HtlcRef): Uint8Array | undefined {\n return ref.ledger === \"arkade\"\n ? this.#preimages.get(ref.script)\n : undefined;\n }\n\n /** Read the VHTLC's vtxos and map them to an observation. */\n async #reconcileRef(\n ref: Extract<HtlcRef, { ledger: \"arkade\" }>,\n ): Promise<void> {\n const { vtxos } = await this.#indexer.getVtxos({ scripts: [ref.script] });\n const spend = spendTxid(vtxos);\n if (spend) {\n const resolved = await fetchArkadeSpend(\n this.#indexer,\n spend,\n hex.decode(ref.preimageHash),\n );\n if (resolved) {\n if (resolved.spend === \"claim\")\n this.#preimages.set(ref.script, resolved.preimage);\n this.#set(\n ref.script,\n arkadeObservation({ funded: true, spend: resolved.spend }),\n );\n return;\n }\n }\n const funded = vtxos.filter(isFunded);\n const total = funded.reduce((sum, vtxo) => sum + vtxo.value, 0);\n this.#set(\n ref.script,\n arkadeObservation({\n funded: funded.length > 0,\n sufficient: total >= ref.expectedSats,\n }),\n );\n }\n\n /** Update an observation and notify on change; never downgrade a resolved spend. */\n #set(script: string, observation: HtlcObservation): void {\n const ref = this.#refs.get(script);\n if (!ref) return;\n const current = this.#obs.get(script);\n if (current === observation) return;\n // A resolved spend is terminal for the HTLC — a later funded/absent poll\n // (e.g. spent vtxos dropping out of the listing) must not undo it.\n const spendStates: HtlcObservation[] = [\"spent_claim\", \"spent_refund\"];\n if (\n current &&\n spendStates.includes(current) &&\n !spendStates.includes(observation)\n )\n return;\n this.#obs.set(script, observation);\n for (const listener of this.#listeners) listener(ref, observation);\n }\n}\n","/**\n * The `ArkadeContractManager`'s pure core.\n *\n * The manager (built on `@arkade-os/sdk`'s ContractManager) gathers facts about a\n * VHTLC — is it funded, and if spent, how — and this maps them to an\n * {@link HtlcObservation} the swap pipeline consumes.\n */\nimport {\n ConditionWitness,\n getArkPsbtFields,\n Transaction,\n} from \"@arkade-os/sdk\";\nimport { base64 } from \"@scure/base\";\nimport type { HtlcObservation } from \"../actions/types.js\";\nimport { preimageMatches } from \"./preimage.js\";\n\n/** Facts about a VHTLC gathered from the Ark indexer/manager. */\nexport type ArkadeVtxoFacts = {\n /** A vtxo exists at the VHTLC address (it was funded). */\n funded: boolean;\n /**\n * Whether the funding meets the swap's expected amount. Only consulted when\n * `funded`; `false` → the VHTLC is funded but short → `invalid`, not confirmed.\n */\n sufficient?: boolean;\n /**\n * If the VHTLC output was spent, which path the spending tx took — resolved\n * from the spend tx's `ConditionWitness` (preimage present → `claim`).\n */\n spend?: \"claim\" | \"refund\";\n};\n\n/**\n * Map gathered VHTLC facts to an on-chain observation.\n *\n * Note: there is no `mempool` here. An Arkade `preconfirmed` vtxo is server-\n * signed (a far stronger trust assumption than a droppable Bitcoin mempool tx),\n * so a funded VHTLC — preconfirmed or settled — is treated as `confirmed`.\n * `mempool` is reserved for Bitcoin on-chain observers.\n */\nexport function arkadeObservation(facts: ArkadeVtxoFacts): HtlcObservation {\n if (facts.spend === \"claim\") return \"spent_claim\";\n if (facts.spend === \"refund\") return \"spent_refund\";\n if (!facts.funded) return \"absent\";\n return facts.sufficient === false ? \"invalid\" : \"confirmed\";\n}\n\n/** How a VHTLC output was spent. A claim also yields the verified preimage. */\nexport type ArkadeSpend =\n | { spend: \"claim\"; preimage: Uint8Array }\n | { spend: \"refund\" };\n\n/**\n * Classify how a VHTLC output was spent from the spending tx's PSBT.\n *\n * The claim path finalizes the VHTLC's condition-multisig closure, so the spend\n * tx witnesses the preimage in the `ConditionWitness` proprietary field; the\n * unilateral refund path (CSV timelock) never carries it. But we don't trust the\n * field's mere presence — we verify a revealed element actually hashes to *this*\n * swap's `paymentHash` (the SHA-256 preimage hash, i.e. the Lightning\n * payment_hash). That turns \"looks like a claim\" into \"this is the claim of our\n * swap, and here is the verified preimage\" — which the caller needs to settle the\n * counterparty leg (the same reason the backend extracts it in\n * `unified_watcher.rs`). Anything else — no field, or a non-matching field — is a\n * refund.\n *\n * Operates on the already-fetched, base64-encoded PSBT so it stays pure and\n * unit-testable; {@link fetchArkadeSpend} does the indexer I/O.\n */\nexport function classifyArkadeSpend(\n encodedSpendTx: string,\n paymentHash: Uint8Array,\n): ArkadeSpend {\n const tx = Transaction.fromPSBT(base64.decode(encodedSpendTx));\n // The VHTLC is always the spending tx's first input; the condition witness is\n // a stack of elements, one of which (on a claim) is the 32-byte preimage.\n for (const witness of getArkPsbtFields(tx, 0, ConditionWitness)) {\n for (const element of witness) {\n if (element.length === 32 && preimageMatches(element, paymentHash)) {\n return { spend: \"claim\", preimage: element };\n }\n }\n }\n return { spend: \"refund\" };\n}\n\n/** The slice of `@arkade-os/sdk`'s indexer the spend classifier needs. */\nexport type VirtualTxSource = {\n getVirtualTxs(txids: string[]): Promise<{ txs: string[] }>;\n};\n\n/**\n * Fetch the tx that spent a VHTLC and classify its path. Returns `undefined`\n * when the indexer can't yet return the spending tx (e.g. not indexed), so the\n * caller keeps the output as `confirmed` rather than guessing.\n */\nexport async function fetchArkadeSpend(\n source: VirtualTxSource,\n spentByTxid: string,\n paymentHash: Uint8Array,\n): Promise<ArkadeSpend | undefined> {\n const { txs } = await source.getVirtualTxs([spentByTxid]);\n const encoded = txs[0];\n return encoded ? classifyArkadeSpend(encoded, paymentHash) : undefined;\n}\n","/**\n * Verify a revealed witness element is the preimage for a swap's hash lock.\n *\n * The hash length selects the algorithm, so callers don't need to know the swap\n * direction: a 20-byte lock is HASH160 = `ripemd160(sha256(preimage))`\n * (`btc_to_arkade`, matching Bitcoin's `OP_HASH160` and the Arkade VHTLC); any\n * other length is `sha256(preimage)` (32 bytes, the EVM/Lightning directions,\n * i.e. the Lightning payment_hash).\n */\nimport { ripemd160 } from \"@noble/hashes/legacy.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { hex } from \"@scure/base\";\n\nexport function preimageMatches(\n element: Uint8Array,\n hashLock: Uint8Array,\n): boolean {\n const digest =\n hashLock.length === 20 ? ripemd160(sha256(element)) : sha256(element);\n return hex.encode(digest) === hex.encode(hashLock);\n}\n","/**\n * Default Arkade server URLs by Bitcoin network, mirroring the legacy SDK's\n * `arkade-network.ts`. Used so tracking can auto-build the Arkade manager without\n * an explicit server URL; a caller can still override via\n * `ClientBuilder.withArkadeServerUrl`.\n */\nconst DEFAULT_ARKADE_URLS: Record<string, string> = {\n bitcoin: \"https://arkade.computer\",\n mainnet: \"https://arkade.computer\",\n signet: \"https://mutinynet.arkade.sh\",\n mutinynet: \"https://mutinynet.arkade.sh\",\n};\n\n/**\n * The default Ark server URL for a Bitcoin network name (case-insensitive), or\n * `undefined` for networks without a public default (e.g. regtest/testnet),\n * where a URL must be supplied explicitly.\n */\nexport function defaultArkadeServerUrl(network: string): string | undefined {\n return DEFAULT_ARKADE_URLS[network.toLowerCase()];\n}\n","/**\n * The Bitcoin {@link ContractManager} — the stateful I/O adapter that observes a\n * swap's on-chain HTLC by polling esplora.\n *\n * Modeled on the Arkade manager: reading is delegated to an injected\n * {@link BitcoinChainReader} (so the package stays free of a bundled esplora\n * client and the adapter is testable against a fake), and there's no event push,\n * so observations advance when {@link refresh} runs — the SwapTracker drives that.\n * The clock is Bitcoin MTP (the same source the Arkade manager uses), so\n * {@link chainNow} is ref-less.\n */\nimport { hex } from \"@scure/base\";\nimport type { HtlcObservation } from \"../actions/types.js\";\nimport { type BitcoinHtlcFacts, bitcoinObservation } from \"./bitcoin.js\";\nimport type { ContractManager, HtlcRef, Ledger } from \"./types.js\";\n\n/** The esplora surface the observer needs (a `BitcoinReaderEsplora` satisfies it). */\nexport type BitcoinChainReader = {\n /** Funding + spend facts for an HTLC witness-script address. */\n getHtlcFacts(address: string): Promise<BitcoinHtlcFacts>;\n};\n\nexport type BitcoinCreateConfig = {\n /** One or more esplora REST base URLs; several are tried in rotation with failover. */\n esploraUrl: string | string[];\n /** The current Bitcoin MTP (ms); typically `async () => (await client.getMtp()).mtp * 1000`. */\n chainTime?: () => Promise<number>;\n};\n\nexport type BitcoinContractManagerDeps = {\n reader: BitcoinChainReader;\n chainTime?: () => Promise<number>;\n};\n\nexport class BitcoinContractManager implements ContractManager {\n readonly ledger: Ledger = \"bitcoin\";\n\n readonly #reader: BitcoinChainReader;\n readonly #chainTime?: () => Promise<number>;\n\n /** address → the ref we're tracking. */\n readonly #refs = new Map<string, Extract<HtlcRef, { ledger: \"bitcoin\" }>>();\n /** address → last known observation. */\n readonly #obs = new Map<string, HtlcObservation>();\n /** address → the preimage a claim revealed. */\n readonly #preimages = new Map<string, Uint8Array>();\n readonly #listeners = new Set<\n (ref: HtlcRef, state: HtlcObservation) => void\n >();\n\n #now: number | undefined;\n\n private constructor(deps: BitcoinContractManagerDeps) {\n this.#reader = deps.reader;\n this.#chainTime = deps.chainTime;\n }\n\n static fromDeps(deps: BitcoinContractManagerDeps): BitcoinContractManager {\n return new BitcoinContractManager(deps);\n }\n\n static async create(\n config: BitcoinCreateConfig,\n ): Promise<BitcoinContractManager> {\n const { esploraReader } = await import(\"./bitcoin-reader-esplora.js\");\n return BitcoinContractManager.fromDeps({\n reader: esploraReader(config.esploraUrl),\n chainTime: config.chainTime,\n });\n }\n\n async register(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"bitcoin\")\n throw new Error(\n `BitcoinContractManager can't track a '${ref.ledger}' HTLC`,\n );\n this.#refs.set(ref.address, ref);\n await this.#reconcileRef(ref);\n }\n\n async unregister(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"bitcoin\") return;\n this.#refs.delete(ref.address);\n this.#obs.delete(ref.address);\n this.#preimages.delete(ref.address);\n }\n\n getState(ref: HtlcRef): HtlcObservation | undefined {\n return ref.ledger === \"bitcoin\" ? this.#obs.get(ref.address) : undefined;\n }\n\n chainNow(_ref: HtlcRef): number | undefined {\n // Bitcoin timelocks share one clock (MTP), so the ref is unused.\n return this.#now;\n }\n\n onEvent(cb: (ref: HtlcRef, state: HtlcObservation) => void): () => void {\n this.#listeners.add(cb);\n return () => this.#listeners.delete(cb);\n }\n\n async refresh(): Promise<void> {\n if (this.#chainTime) this.#now = await this.#chainTime();\n await Promise.all(\n [...this.#refs.values()].map((ref) => this.#reconcileRef(ref)),\n );\n }\n\n dispose(): void {\n this.#listeners.clear();\n }\n\n /** The preimage a claim revealed on this HTLC, if one was seen. */\n getPreimage(ref: HtlcRef): Uint8Array | undefined {\n return ref.ledger === \"bitcoin\"\n ? this.#preimages.get(ref.address)\n : undefined;\n }\n\n async #reconcileRef(\n ref: Extract<HtlcRef, { ledger: \"bitcoin\" }>,\n ): Promise<void> {\n const facts = await this.#reader.getHtlcFacts(ref.address);\n const { observation, preimage } = bitcoinObservation(\n facts,\n hex.decode(ref.preimageHash),\n ref.expectedSats,\n );\n if (preimage) this.#preimages.set(ref.address, preimage);\n this.#set(ref.address, observation);\n }\n\n /** Update an observation and notify on change; never downgrade a resolved spend. */\n #set(address: string, observation: HtlcObservation): void {\n const ref = this.#refs.get(address);\n if (!ref) return;\n const current = this.#obs.get(address);\n if (current === observation) return;\n const spendStates: HtlcObservation[] = [\"spent_claim\", \"spent_refund\"];\n if (\n current &&\n spendStates.includes(current) &&\n !spendStates.includes(observation)\n )\n return;\n this.#obs.set(address, observation);\n for (const listener of this.#listeners) listener(ref, observation);\n }\n}\n","/**\n * The `BitcoinContractManager`'s pure core.\n *\n * A Bitcoin HTLC is an on-chain output at a witness-script address. It's observed\n * from esplora: an output paying the address means it's funded; a spend of that\n * output resolves it. The spend's witness reveals the preimage on a claim (a\n * timelock refund does not), so — script-agnostically, as on Arkade/EVM — a spend\n * is a claim iff a witness element hashes to the swap's `paymentHash`.\n */\nimport { hex } from \"@scure/base\";\nimport type { HtlcObservation } from \"../actions/types.js\";\nimport { preimageMatches } from \"./preimage.js\";\n\n/** On-chain funding state of the HTLC address. */\nexport type BitcoinFunding = \"absent\" | \"mempool\" | \"confirmed\";\n\n/** Facts gathered for an HTLC address from esplora. */\nexport type BitcoinHtlcFacts = {\n funding: BitcoinFunding;\n /** Total sats paid to the HTLC address by the funding tx (0 when absent). */\n fundedSats: number;\n /**\n * The witness stack (hex items) of the input that spent the HTLC output, if it\n * was spent. Absent while the output is still unspent.\n */\n spendWitness?: string[];\n};\n\n/** An HTLC's observation, plus the preimage if a claim revealed it. */\nexport type BitcoinHtlcState = {\n observation: HtlcObservation;\n preimage?: Uint8Array;\n};\n\n/**\n * Classify a spend from its witness: a claim path reveals the preimage in the\n * witness (verified against `paymentHash` — SHA-256, or HASH160 for the\n * `btc_to_arkade` script; {@link preimageMatches} picks by length); a timelock\n * refund path does not.\n */\nexport function classifyBitcoinSpend(\n witness: string[],\n paymentHash: Uint8Array,\n): { spend: \"claim\"; preimage: Uint8Array } | { spend: \"refund\" } {\n for (const item of witness) {\n // The preimage is 32 bytes (64 hex chars); skip signatures, pubkeys, scripts.\n if (item.length !== 64) continue;\n const bytes = hex.decode(item);\n if (preimageMatches(bytes, paymentHash))\n return { spend: \"claim\", preimage: bytes };\n }\n return { spend: \"refund\" };\n}\n\n/**\n * Reduce gathered HTLC facts to an observation (+ the preimage on a claim). A\n * confirmed funding below `expectedSats` is `invalid` (funded, but not on the\n * swap's terms) rather than `confirmed`, so the client never claims a\n * short-funded server leg. An unconfirmed (`mempool`) funding isn't actionable\n * yet, so its amount is re-checked once it confirms.\n */\nexport function bitcoinObservation(\n facts: BitcoinHtlcFacts,\n paymentHash: Uint8Array,\n expectedSats: number,\n): BitcoinHtlcState {\n if (facts.spendWitness) {\n const spend = classifyBitcoinSpend(facts.spendWitness, paymentHash);\n return spend.spend === \"claim\"\n ? { observation: \"spent_claim\", preimage: spend.preimage }\n : { observation: \"spent_refund\" };\n }\n if (facts.funding === \"confirmed\" && facts.fundedSats < expectedSats) {\n return { observation: \"invalid\" };\n }\n return { observation: facts.funding };\n}\n","/**\n * The `EvmContractManager`'s pure core.\n *\n * An EVM HTLC (an `HTLCErc20` swap) exposes its lifecycle as three events, all\n * indexed by the swap's `preimageHash`: `SwapCreated` (funded), `SwapRedeemed`\n * (claimed — reveals the preimage), and `SwapRefunded` (reclaimed after the\n * timelock). This maps a decoded event history to an {@link HtlcObservation}.\n */\nimport type { HtlcObservation } from \"../actions/types.js\";\n\n/** One decoded `HTLCErc20` lifecycle event for a single swap's `preimageHash`. */\nexport type EvmHtlcEvent =\n | { kind: \"created\"; amount: bigint; token: `0x${string}` }\n | { kind: \"redeemed\"; preimage: `0x${string}` }\n | { kind: \"refunded\" };\n\n/** An EVM HTLC's observation, plus the preimage if a claim revealed it. */\nexport type EvmHtlcState = {\n observation: HtlcObservation;\n preimage?: `0x${string}`;\n};\n\n/** What a `SwapCreated` must satisfy to be `confirmed` (else `invalid`). */\nexport type EvmExpectation = {\n /** Minimum locked amount (token's smallest unit). */\n amount: bigint;\n /** Expected token address; verified when provided. */\n token?: `0x${string}`;\n};\n\n/**\n * Reduce an HTLC's on-chain event history to an observation.\n *\n * A terminal spend wins over funding regardless of ordering: `SwapRedeemed`\n * reveals the preimage → `spent_claim` (plus the recovered preimage, which the\n * caller needs to settle the counterparty leg — as on Arkade); `SwapRefunded` →\n * `spent_refund`. A `SwapCreated` is `confirmed` only if it locks at least\n * `expected.amount` of the expected token — otherwise `invalid`, so the client\n * never claims a leg funded on the wrong terms. `pending` marks a broadcast-but-\n * unmined funding tx (`mempool`); otherwise `absent`.\n */\nexport function evmObservation(\n events: EvmHtlcEvent[],\n expected: EvmExpectation,\n pending = false,\n): EvmHtlcState {\n const redeemed = events.find((e) => e.kind === \"redeemed\");\n if (redeemed?.kind === \"redeemed\")\n return { observation: \"spent_claim\", preimage: redeemed.preimage };\n if (events.some((e) => e.kind === \"refunded\"))\n return { observation: \"spent_refund\" };\n const created = events.find((e) => e.kind === \"created\");\n if (created?.kind === \"created\") {\n const amountOk = created.amount >= expected.amount;\n const tokenOk =\n expected.token === undefined ||\n created.token.toLowerCase() === expected.token.toLowerCase();\n return { observation: amountOk && tokenOk ? \"confirmed\" : \"invalid\" };\n }\n return { observation: pending ? \"mempool\" : \"absent\" };\n}\n","/**\n * The contract-monitoring layer — modeled on @arkade-os/sdk's\n * `ContractManager`.\n *\n * A {@link ContractManager} is the per-ledger, stateful I/O layer that watches a\n * set of HTLCs and maps their on-chain state to {@link HtlcObservation}. The pure\n * pipeline (`deriveSwapStatus` → `deriveSwapActions`) consumes the observations\n * it produces; a `SwapTracker` (built later) combines the two ledgers of each\n * swap and notifies subscribers of the next action.\n */\nimport type { HtlcObservation } from \"../actions/types.js\";\n\n/** Ledgers a swap HTLC can live on. */\nexport type Ledger = \"arkade\" | \"bitcoin\" | \"evm\" | \"lightning\";\n\n/**\n * Identifies and parameterises one HTLC on its ledger — enough for a\n * {@link ContractManager} to observe it. Sourced from the swap's recovery\n * bundle. Discriminated by `ledger`.\n */\nexport type HtlcRef =\n | {\n ledger: \"arkade\";\n /** VHTLC pkScript (hex) — the contract's unique id. */\n script: string;\n address: string;\n /** SHA256 of the preimage, to tell a claim spend from a refund spend. */\n preimageHash: string;\n /**\n * Expected funding amount in sats. A funding below this is `invalid` (not on\n * the swap's terms) rather than `confirmed` — so the client never claims a\n * server leg the server short-funded.\n */\n expectedSats: number;\n /**\n * Serialized VHTLC parameters (`@arkade-os/sdk`'s `Contract.params`) — the\n * sender/receiver/server keys, preimage hash, and timelocks needed to\n * register the contract for watching. Opaque here: the Client serializes\n * it from the swap's recovery bundle so this layer stays VHTLC-agnostic.\n */\n params: Record<string, string>;\n }\n | {\n ledger: \"bitcoin\";\n /** HTLC witness-script address — the contract's unique id. */\n address: string;\n preimageHash: string;\n /** Expected funding amount in sats; a funding below this is `invalid`. */\n expectedSats: number;\n }\n | {\n ledger: \"evm\";\n chainId: number;\n /** The HTLCErc20 contract holding this leg — where its events are emitted. */\n htlc: `0x${string}`;\n /**\n * SHA256 preimage hash (`0x`-prefixed) — the indexed topic that identifies\n * this swap's HTLC in the contract's `SwapCreated`/`SwapRedeemed`/\n * `SwapRefunded` events. Serves as the contract's unique id here.\n */\n preimageHash: `0x${string}`;\n /**\n * The address that can claim this HTLC — the second indexed topic used to\n * filter `SwapCreated`, so only the HTLC actually claimable on the swap's\n * terms is observed (an HTLC with our hash but a different recipient is\n * never seen). Client's EVM address for a server-funded leg; the server's\n * for the client's own leg.\n */\n claimAddress: `0x${string}`;\n /**\n * Expected locked amount (token's smallest unit). A `SwapCreated` below this\n * → `invalid`, so the client never claims a short-funded leg.\n */\n expectedAmount: bigint;\n /** Expected token address; the funding is `invalid` if it locks another token. */\n expectedToken?: `0x${string}`;\n }\n | {\n ledger: \"lightning\";\n /** Payment hash — the contract's unique id. */\n paymentHash: string;\n };\n\n/** Stable, cross-ledger unique key for an {@link HtlcRef}. */\nexport function htlcKey(ref: HtlcRef): string {\n switch (ref.ledger) {\n case \"arkade\":\n return `arkade:${ref.script}`;\n case \"bitcoin\":\n return `bitcoin:${ref.address}`;\n case \"evm\":\n return `evm:${ref.chainId}:${ref.preimageHash}`;\n case \"lightning\":\n return `lightning:${ref.paymentHash}`;\n }\n}\n\n/**\n * Per-ledger contract monitor. Implementations keep an internal, event-driven\n * cache: `register` seeds it, `onEvent` pushes changes, `getState` reads it\n * synchronously, `dispose` tears down subscriptions/loops.\n *\n * One manager exists per ledger actually in use and watches every tracked HTLC\n * on that ledger at once (one connection, not one per HTLC).\n */\nexport interface ContractManager {\n /** The ledger this manager observes. */\n readonly ledger: Ledger;\n\n /** Start tracking an HTLC (idempotent); seeds its state from the ledger. */\n register(ref: HtlcRef): Promise<void>;\n\n /** Stop tracking an HTLC. */\n unregister(ref: HtlcRef): Promise<void>;\n\n /**\n * Current known observation for a tracked HTLC, or `undefined` if it isn't\n * tracked or its state isn't known yet.\n */\n getState(ref: HtlcRef): HtlcObservation | undefined;\n\n /**\n * The current clock (ms) for evaluating this HTLC's timelock — MTP for\n * Bitcoin/Arkade, `block.timestamp` for EVM. Ref-scoped because one ledger can\n * span several chains with independent clocks (EVM chains); managers whose\n * ledger has a single clock (Arkade) ignore the ref. `undefined` until known.\n */\n chainNow(ref: HtlcRef): number | undefined;\n\n /** Subscribe to observation changes for any tracked HTLC. Returns unsubscribe. */\n onEvent(cb: (ref: HtlcRef, state: HtlcObservation) => void): () => void;\n\n /** Force a reconcile from the ledger. */\n refresh(): Promise<void>;\n\n /** Tear down subscriptions and background work. */\n dispose(): void;\n}\n","/**\n * The EVM {@link ContractManager} — the stateful I/O adapter that observes\n * `HTLCErc20` swaps across one or more EVM chains.\n *\n * Reading chain state is delegated to an injected {@link EvmChainReader} (one per\n * chainId) rather than a bundled viem/ethers client, so the swap package stays\n * chain-library-agnostic and this adapter is testable against a fake. The pure\n * event→observation mapping lives in `./evm.js`.\n *\n * Unlike Arkade, EVM spans multiple chains with independent `block.timestamp`\n * clocks, so this manager is chain-aware: it routes each ref by `chainId` and\n * {@link chainNow} is ref-scoped.\n */\nimport type { HtlcObservation } from \"../actions/types.js\";\nimport { type EvmHtlcEvent, evmObservation } from \"./evm.js\";\nimport {\n type ContractManager,\n type HtlcRef,\n htlcKey,\n type Ledger,\n} from \"./types.js\";\n\ntype EvmRef = Extract<HtlcRef, { ledger: \"evm\" }>;\n\n/** Reads `HTLCErc20` state for one EVM chain. Implemented over viem/ethers/etc. */\nexport type EvmChainReader = {\n /**\n * The decoded lifecycle events (oldest→newest) for the HTLC identified by\n * `(htlc contract, preimageHash)`.\n */\n getHtlcEvents(\n htlc: `0x${string}`,\n preimageHash: `0x${string}`,\n claimAddress: `0x${string}`,\n ): Promise<EvmHtlcEvent[]>;\n /** The latest block's `block.timestamp`, in ms. */\n getBlockTimeMs(): Promise<number>;\n /** Fire `cb` when new blocks/logs may have changed watched HTLCs; returns unsubscribe. */\n watch(cb: () => void): () => void;\n};\n\nexport type EvmContractManagerDeps = {\n /** A chain reader per EVM `chainId` this manager serves. */\n readers: Map<number, EvmChainReader>;\n};\n\nexport class EvmContractManager implements ContractManager {\n readonly ledger: Ledger = \"evm\";\n\n readonly #readers: Map<number, EvmChainReader>;\n /** htlcKey → the ref we're tracking. */\n readonly #refs = new Map<string, EvmRef>();\n /** htlcKey → last known observation. */\n readonly #obs = new Map<string, HtlcObservation>();\n /** htlcKey → the preimage a claim revealed. */\n readonly #preimages = new Map<string, `0x${string}`>();\n /** chainId → its latest block time (ms). */\n readonly #now = new Map<number, number>();\n /** chainId → unsubscribe for its (single, shared) watch. */\n readonly #watchUnsubs = new Map<number, () => void>();\n /** chainId → a block-event reconcile is currently running (coalescing). */\n readonly #reconciling = new Set<number>();\n /** chainId → a block event arrived mid-reconcile; run exactly one more. */\n readonly #reconcileAgain = new Set<number>();\n readonly #listeners = new Set<\n (ref: HtlcRef, state: HtlcObservation) => void\n >();\n\n private constructor(deps: EvmContractManagerDeps) {\n this.#readers = deps.readers;\n }\n\n static fromDeps(deps: EvmContractManagerDeps): EvmContractManager {\n return new EvmContractManager(deps);\n }\n\n async register(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"evm\")\n throw new Error(`EvmContractManager can't track a '${ref.ledger}' HTLC`);\n // Fail loudly on an unconfigured chain rather than storing a ref we can never\n // observe (its state/clock would stay undefined and the tracker would wait on\n // it forever). The caller must add the chain via ClientBuilder.withEvmRpcUrls().\n if (!this.#readers.has(ref.chainId))\n throw new Error(\n `no EVM reader for chain ${ref.chainId} — configure it via ClientBuilder.withEvmRpcUrls()`,\n );\n this.#refs.set(htlcKey(ref), ref);\n this.#ensureWatch(ref.chainId);\n await this.#reconcileChain(ref.chainId);\n }\n\n async unregister(ref: HtlcRef): Promise<void> {\n if (ref.ledger !== \"evm\") return;\n const key = htlcKey(ref);\n this.#refs.delete(key);\n this.#obs.delete(key);\n this.#preimages.delete(key);\n // Drop the chain's watch once nothing on it is tracked anymore.\n if (![...this.#refs.values()].some((r) => r.chainId === ref.chainId)) {\n this.#watchUnsubs.get(ref.chainId)?.();\n this.#watchUnsubs.delete(ref.chainId);\n this.#now.delete(ref.chainId);\n this.#reconcileAgain.delete(ref.chainId);\n }\n }\n\n getState(ref: HtlcRef): HtlcObservation | undefined {\n return ref.ledger === \"evm\" ? this.#obs.get(htlcKey(ref)) : undefined;\n }\n\n chainNow(ref: HtlcRef): number | undefined {\n return ref.ledger === \"evm\" ? this.#now.get(ref.chainId) : undefined;\n }\n\n onEvent(cb: (ref: HtlcRef, state: HtlcObservation) => void): () => void {\n this.#listeners.add(cb);\n return () => this.#listeners.delete(cb);\n }\n\n async refresh(): Promise<void> {\n const chainIds = new Set([...this.#refs.values()].map((r) => r.chainId));\n await Promise.all([...chainIds].map((c) => this.#reconcileChain(c)));\n }\n\n dispose(): void {\n for (const unsub of this.#watchUnsubs.values()) unsub();\n this.#watchUnsubs.clear();\n this.#reconciling.clear();\n this.#reconcileAgain.clear();\n this.#listeners.clear();\n }\n\n /** The preimage a claim revealed on this HTLC, if one was seen. */\n getPreimage(ref: HtlcRef): `0x${string}` | undefined {\n return ref.ledger === \"evm\" ? this.#preimages.get(htlcKey(ref)) : undefined;\n }\n\n #ensureWatch(chainId: number): void {\n if (this.#watchUnsubs.has(chainId)) return;\n const reader = this.#readers.get(chainId);\n if (!reader) return;\n this.#watchUnsubs.set(\n chainId,\n reader.watch(() => this.#scheduleReconcile(chainId)),\n );\n }\n\n /**\n * Reconcile a chain in response to a block/log event, coalesced: at most one\n * reconcile runs per chain at a time, with at most one queued rerun to pick up\n * changes that arrived mid-run. This stops fast chains / slow RPCs from stacking\n * redundant full-log scans (which amplify rate limits), and the `.catch` keeps a\n * transient RPC failure in a background reconcile from becoming an unhandled\n * rejection. `register`/`refresh` still await `#reconcileChain` directly.\n */\n #scheduleReconcile(chainId: number): void {\n if (this.#reconciling.has(chainId)) {\n this.#reconcileAgain.add(chainId);\n return;\n }\n this.#reconciling.add(chainId);\n void this.#reconcileChain(chainId)\n .catch((error) => {\n console.warn(`EVM reconcile failed for chain ${chainId}:`, error);\n })\n .finally(() => {\n this.#reconciling.delete(chainId);\n if (this.#reconcileAgain.delete(chainId))\n this.#scheduleReconcile(chainId);\n });\n }\n\n /** Refresh one chain's clock and re-observe every HTLC tracked on it. */\n async #reconcileChain(chainId: number): Promise<void> {\n const reader = this.#readers.get(chainId);\n if (!reader) return;\n this.#now.set(chainId, await reader.getBlockTimeMs());\n await Promise.all(\n [...this.#refs.values()]\n .filter((r) => r.chainId === chainId)\n .map((r) => this.#reconcileRef(reader, r)),\n );\n }\n\n async #reconcileRef(reader: EvmChainReader, ref: EvmRef): Promise<void> {\n const events = await reader.getHtlcEvents(\n ref.htlc,\n ref.preimageHash,\n ref.claimAddress,\n );\n const { observation, preimage } = evmObservation(events, {\n amount: ref.expectedAmount,\n token: ref.expectedToken,\n });\n const key = htlcKey(ref);\n if (preimage) this.#preimages.set(key, preimage);\n this.#set(key, observation);\n }\n\n /** Update an observation and notify on change; never downgrade a resolved spend. */\n #set(key: string, observation: HtlcObservation): void {\n const ref = this.#refs.get(key);\n if (!ref) return;\n const current = this.#obs.get(key);\n if (current === observation) return;\n const spendStates: HtlcObservation[] = [\"spent_claim\", \"spent_refund\"];\n if (\n current &&\n spendStates.includes(current) &&\n !spendStates.includes(observation)\n )\n return;\n this.#obs.set(key, observation);\n for (const listener of this.#listeners) listener(ref, observation);\n }\n}\n","/**\n * A viem-backed {@link EvmChainReader} — the concrete chain source the\n * {@link EvmContractManager} uses in production.\n *\n * Kept separate from the manager so the manager itself stays free of any\n * chain-library dependency (and unit-testable against a fake reader). This module\n * is the only place that touches viem and the `HTLCErc20` ABI.\n */\nimport {\n type Block,\n createPublicClient,\n fallback,\n http,\n type Log,\n parseAbiItem,\n} from \"viem\";\nimport type { EvmHtlcEvent } from \"./evm.js\";\nimport type { EvmChainReader } from \"./evm-manager.js\";\n\n/**\n * Tested public RPC endpoints per supported chainId, tried in order via viem's\n * ranked `fallback`. Mirrors the frontend's `evmTransport.ts` list — the client\n * uses these by default so Arkade↔EVM tracking works out of the box; a caller can\n * override per chain with `ClientBuilder.withEvmRpcUrls`.\n */\nexport const DEFAULT_EVM_RPCS: Record<number, string[]> = {\n // Polygon — viem's default (polygon.drpc.org) misbehaves for some calls, so\n // list working public RPCs explicitly.\n 137: [\n \"https://polygon.drpc.org\",\n \"https://tenderly.rpc.polygon.community\",\n \"https://polygon-bor-rpc.publicnode.com\",\n ],\n 1: [\n \"https://ethereum-rpc.publicnode.com\",\n \"https://rpc.ankr.com/eth\",\n \"https://eth.drpc.org\",\n ],\n 42161: [\n \"https://arbitrum-one-rpc.publicnode.com\",\n \"https://rpc.ankr.com/arbitrum\",\n \"https://arb1.arbitrum.io/rpc\",\n ],\n};\n\n// The three `HTLCErc20` lifecycle events, each indexed by `preimageHash`.\nconst SWAP_CREATED = parseAbiItem(\n \"event SwapCreated(bytes32 indexed preimageHash, address indexed refundAddress, address indexed claimAddress, address token, uint256 amount, uint256 timelock)\",\n);\nconst SWAP_REDEEMED = parseAbiItem(\n \"event SwapRedeemed(bytes32 indexed preimageHash, bytes32 preimage)\",\n);\nconst SWAP_REFUNDED = parseAbiItem(\n \"event SwapRefunded(bytes32 indexed preimageHash)\",\n);\n\n/** The viem surface the reader needs — a seam so it can be faked in tests. */\nexport type EvmLogClient = {\n getLogs(args: {\n address: `0x${string}`;\n event: typeof SWAP_CREATED | typeof SWAP_REDEEMED | typeof SWAP_REFUNDED;\n args: { preimageHash: `0x${string}`; claimAddress?: `0x${string}` };\n fromBlock: bigint | \"earliest\";\n }): Promise<Log[]>;\n getBlock(): Promise<Pick<Block, \"timestamp\">>;\n watchBlocks(args: { onBlock: () => void }): () => void;\n};\n\n/** Build an {@link EvmChainReader} over an existing viem-like client. */\nexport function evmReaderFromClient(client: EvmLogClient): EvmChainReader {\n return {\n async getHtlcEvents(htlc, preimageHash, claimAddress) {\n const [created, redeemed, refunded] = await Promise.all([\n // Filter by claimAddress too (also indexed), so only the HTLC actually\n // claimable on the swap's terms is seen.\n client.getLogs({\n address: htlc,\n event: SWAP_CREATED,\n args: { preimageHash, claimAddress },\n fromBlock: \"earliest\",\n }),\n client.getLogs({\n address: htlc,\n event: SWAP_REDEEMED,\n args: { preimageHash },\n fromBlock: \"earliest\",\n }),\n client.getLogs({\n address: htlc,\n event: SWAP_REFUNDED,\n args: { preimageHash },\n fromBlock: \"earliest\",\n }),\n ]);\n // Order doesn't matter — evmObservation resolves precedence.\n const events: EvmHtlcEvent[] = [];\n for (const log of created) {\n const args = (\n log as { args?: { amount?: bigint; token?: `0x${string}` } }\n ).args;\n events.push({\n kind: \"created\",\n amount: args?.amount ?? 0n,\n token: args?.token ?? \"0x\",\n });\n }\n for (const log of redeemed) {\n const preimage = (log as { args?: { preimage?: `0x${string}` } }).args\n ?.preimage;\n if (preimage) events.push({ kind: \"redeemed\", preimage });\n }\n if (refunded.length > 0) events.push({ kind: \"refunded\" });\n return events;\n },\n async getBlockTimeMs() {\n const block = await client.getBlock();\n return Number(block.timestamp) * 1000;\n },\n watch(cb) {\n return client.watchBlocks({ onBlock: () => cb() });\n },\n };\n}\n\n/**\n * Build an {@link EvmChainReader} over one or more EVM JSON-RPC endpoints. With\n * several, viem's ranked `fallback` picks the healthiest and fails over.\n */\nexport function createEvmRpcReader(rpcUrls: string | string[]): EvmChainReader {\n const urls = Array.isArray(rpcUrls) ? rpcUrls : [rpcUrls];\n const transport =\n urls.length > 1\n ? fallback(\n urls.map((url) => http(url)),\n { rank: { interval: 60_000, sampleCount: 3, timeout: 1_000 } },\n )\n : http(urls[0]);\n const client = createPublicClient({ transport });\n return evmReaderFromClient(client as unknown as EvmLogClient);\n}\n\n/**\n * Resolve the per-chain readers used for tracking: the tested {@link\n * DEFAULT_EVM_RPCS} by default, with any `overrides` taking priority for their\n * chain (kept ahead of the defaults, which remain as fallbacks).\n */\nexport function defaultEvmReaders(\n overrides?: Record<number, string>,\n): Map<number, EvmChainReader> {\n const chainIds = new Set<number>([\n ...Object.keys(DEFAULT_EVM_RPCS).map(Number),\n ...Object.keys(overrides ?? {}).map(Number),\n ]);\n const readers = new Map<number, EvmChainReader>();\n for (const chainId of chainIds) {\n const override = overrides?.[chainId];\n const defaults = DEFAULT_EVM_RPCS[chainId] ?? [];\n const urls = override ? [override, ...defaults] : defaults;\n if (urls.length > 0) readers.set(chainId, createEvmRpcReader(urls));\n }\n return readers;\n}\n","/**\n * Build the Arkade {@link HtlcRef} for a swap's VHTLC leg from the plain swap\n * fields, deriving the pkScript and serialized contract params the\n * `ArkadeContractManager` needs to register it for watching.\n *\n * This is the one place that reconstructs the VHTLC from a swap, mirroring the\n * legacy SDK's `VHTLC.Script` construction, so the mapper and manager stay free\n * of VHTLC internals.\n */\nimport { VHTLC, VHTLCContractHandler } from \"@arkade-os/sdk\";\nimport { ripemd160 } from \"@noble/hashes/legacy.js\";\nimport { hex } from \"@scure/base\";\nimport type { HtlcRef } from \"./types.js\";\n\ntype ArkadeRef = Extract<HtlcRef, { ledger: \"arkade\" }>;\n\nexport type ArkadeVhtlcInput = {\n /** Pubkey hex (x-only or compressed) for each VHTLC role. */\n senderPk: string;\n receiverPk: string;\n serverPk: string;\n /**\n * The swap's `hash_lock`, hex, `0x`-prefixed or not. Either `sha256(preimage)`\n * (32 bytes — most directions) or the `ripemd160(sha256(preimage))` HASH160 the\n * VHTLC commits to directly (20 bytes — `btc_to_arkade`). Length disambiguates.\n */\n hashLock: string;\n /** The VHTLC address the server reported. */\n address: string;\n /** Absolute CLTV refund locktime (unix seconds). */\n refundLocktime: number;\n /** Relative unilateral delays (seconds). */\n unilateralClaimDelay: number;\n unilateralRefundDelay: number;\n unilateralRefundWithoutReceiverDelay: number;\n /** Expected funding amount in sats (a short funding is `invalid`, not confirmed). */\n expectedSats: number;\n};\n\nfunction strip0x(value: string): string {\n return value.startsWith(\"0x\") ? value.slice(2) : value;\n}\n\n/** Normalize a pubkey hex to the 32-byte x-only form the VHTLC expects. */\nfunction xOnly(pubKeyHex: string): Uint8Array {\n const bytes = hex.decode(strip0x(pubKeyHex));\n if (bytes.length === 33) return bytes.slice(1);\n if (bytes.length === 32) return bytes;\n throw new Error(`invalid public key length: ${bytes.length}`);\n}\n\nconst seconds = (value: number) =>\n ({ type: \"seconds\", value: BigInt(value) }) as const;\n\n/**\n * The VHTLC always commits to `ripemd160(sha256(preimage))` (HASH160). When\n * `hashLock` is `sha256(preimage)` (32 bytes) we hash it once more to get that;\n * when it is already the HASH160 (20 bytes, `btc_to_arkade`) we use it as-is. The\n * ref keeps `preimageHash` as the raw `hashLock` — whatever length — and the spend\n * classifier verifies a revealed preimage against it, auto-detecting the algorithm\n * from that length.\n */\nexport function buildArkadeVhtlcRef(input: ArkadeVhtlcInput): ArkadeRef {\n const hashLockBytes = hex.decode(strip0x(input.hashLock));\n const params = {\n sender: xOnly(input.senderPk),\n receiver: xOnly(input.receiverPk),\n server: xOnly(input.serverPk),\n preimageHash:\n hashLockBytes.length === 20 ? hashLockBytes : ripemd160(hashLockBytes),\n refundLocktime: BigInt(input.refundLocktime),\n unilateralClaimDelay: seconds(input.unilateralClaimDelay),\n unilateralRefundDelay: seconds(input.unilateralRefundDelay),\n unilateralRefundWithoutReceiverDelay: seconds(\n input.unilateralRefundWithoutReceiverDelay,\n ),\n };\n const vhtlc = new VHTLC.Script(params);\n return {\n ledger: \"arkade\",\n script: hex.encode(vhtlc.pkScript),\n address: input.address,\n preimageHash: strip0x(input.hashLock),\n expectedSats: input.expectedSats,\n params: VHTLCContractHandler.serializeParams(params),\n };\n}\n","/**\n * Map a stored swap to the {@link TrackedSwap} the {@link SwapTracker} watches.\n *\n * The recovery bundle (`StoredSwap.response`) is a discriminated union over swap\n * directions; each carries the two HTLC legs and their refund locktimes. This\n * extracts the client-funded and server-funded HTLCs plus their locktimes so the\n * pure pipeline can derive the next action.\n *\n * Directions whose both legs are observable today (Arkade↔EVM, Bitcoin↔EVM) are\n * mapped; others return `undefined` until their ledger managers exist, rather than\n * producing a half-watchable swap.\n */\nimport type { StoredSwap } from \"@lendasat/lendaswap-sdk-pure\";\nimport { buildArkadeVhtlcRef } from \"../contracts/arkade-vhtlc.js\";\nimport type { HtlcRef } from \"../contracts/types.js\";\nimport type { TrackedSwap } from \"./swap-tracker.js\";\n\n/** Locktimes are unix seconds on the wire; the resolver works in ms. */\nconst ms = (seconds: number): number => seconds * 1000;\n\nconst ensure0x = (value: string): `0x${string}` =>\n (value.startsWith(\"0x\") ? value : `0x${value}`) as `0x${string}`;\nconst strip0x = (value: string): string =>\n value.startsWith(\"0x\") ? value.slice(2) : value;\n\n/**\n * The Arkade VHTLC leg. The three pubkeys the response reports are the exact keys\n * the server used to build the on-chain VHTLC, so feeding them back into\n * `VHTLC.Script` reproduces the funded pkScript regardless of which side funds or\n * claims — the manager watches by that script. `address` names the field the\n * response carries it in (`btc_vhtlc_address` for Arkade↔EVM, `arkade_vhtlc_address`\n * for Arkade↔Lightning).\n */\ntype ArkadeVhtlcFields = {\n sender_pk: string;\n receiver_pk: string;\n arkade_server_pk: string;\n hash_lock: string;\n vhtlc_refund_locktime: number;\n unilateral_claim_delay: number;\n unilateral_refund_delay: number;\n unilateral_refund_without_receiver_delay: number;\n};\n\nfunction arkadeLeg(\n r: ArkadeVhtlcFields,\n address: string,\n expectedSats: number,\n): HtlcRef {\n return buildArkadeVhtlcRef({\n senderPk: r.sender_pk,\n receiverPk: r.receiver_pk,\n serverPk: r.arkade_server_pk,\n hashLock: r.hash_lock,\n address,\n refundLocktime: r.vhtlc_refund_locktime,\n unilateralClaimDelay: r.unilateral_claim_delay,\n unilateralRefundDelay: r.unilateral_refund_delay,\n unilateralRefundWithoutReceiverDelay:\n r.unilateral_refund_without_receiver_delay,\n expectedSats,\n });\n}\n\n/**\n * The EVM HTLC leg. `claimAddress` is who can claim (the client for a\n * server-funded leg, the server for the client's own); `expectedSats`/`token`\n * are what the HTLC must lock (the leg is `invalid` otherwise).\n */\nfunction evmLeg(args: {\n chainId: number;\n htlc: string;\n hashLock: string;\n claimAddress: string;\n expectedSats: string;\n token?: string;\n}): HtlcRef {\n return {\n ledger: \"evm\",\n chainId: args.chainId,\n htlc: ensure0x(args.htlc),\n preimageHash: ensure0x(args.hashLock),\n claimAddress: ensure0x(args.claimAddress),\n expectedAmount: BigInt(args.expectedSats),\n expectedToken: args.token ? ensure0x(args.token) : undefined,\n };\n}\n\n/**\n * The Bitcoin HTLC leg. `hashLock` is the SHA-256 preimage hash (`evm_hash_lock`);\n * the on-chain script commits `ripemd160` of it, but the classifier verifies a\n * revealed preimage as `sha256(preimage) === hashLock`.\n */\nfunction bitcoinLeg(\n address: string,\n hashLock: string,\n expectedSats: number,\n): HtlcRef {\n return {\n ledger: \"bitcoin\",\n address,\n preimageHash: strip0x(hashLock),\n expectedSats,\n };\n}\n\nexport function swapToTracked(stored: StoredSwap): TrackedSwap | undefined {\n const r = stored.response;\n switch (r.direction) {\n // Client sends Arkade (funds the VHTLC with source_amount sats) and claims EVM.\n case \"arkade_to_evm\":\n return {\n swapId: r.id,\n clientHtlc: arkadeLeg(r, r.btc_vhtlc_address, Number(r.source_amount)),\n serverHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.hash_lock,\n claimAddress: r.client_evm_address, // the client claims the server's EVM HTLC\n expectedSats: r.evm_expected_sats,\n token: r.wbtc_address,\n }),\n clientRefundLocktime: ms(r.vhtlc_refund_locktime),\n serverRefundLocktime: ms(r.evm_refund_locktime),\n };\n // Client sends EVM and claims the Arkade VHTLC (server funds it with target_amount sats).\n case \"evm_to_arkade\":\n return {\n swapId: r.id,\n clientHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.hash_lock,\n claimAddress: r.server_evm_address, // the server claims the client's EVM HTLC\n expectedSats: r.evm_expected_sats,\n // evm_to_arkade doesn't expose the locked token — verify amount only.\n }),\n serverHtlc: arkadeLeg(r, r.btc_vhtlc_address, Number(r.target_amount)),\n clientRefundLocktime: ms(r.evm_refund_locktime),\n serverRefundLocktime: ms(r.vhtlc_refund_locktime),\n };\n // Client sends BTC (funds the on-chain HTLC with source_amount sats) and claims EVM.\n case \"bitcoin_to_evm\":\n return {\n swapId: r.id,\n clientHtlc: bitcoinLeg(\n r.btc_htlc_address,\n r.evm_hash_lock,\n Number(r.source_amount),\n ),\n serverHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.evm_hash_lock,\n claimAddress: r.client_evm_address, // the client claims the server's EVM HTLC\n expectedSats: r.evm_expected_sats,\n token: r.wbtc_address,\n }),\n clientRefundLocktime: ms(r.btc_refund_locktime),\n serverRefundLocktime: ms(r.evm_refund_locktime),\n };\n // Client sends EVM and claims the BTC HTLC (server funds it with target_amount sats).\n case \"evm_to_bitcoin\":\n return {\n swapId: r.id,\n clientHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.evm_hash_lock,\n claimAddress: r.server_evm_address, // the server claims the client's EVM HTLC\n expectedSats: r.evm_expected_sats,\n token: r.wbtc_address,\n }),\n serverHtlc: bitcoinLeg(\n r.btc_htlc_address,\n r.evm_hash_lock,\n Number(r.target_amount),\n ),\n clientRefundLocktime: ms(r.evm_refund_locktime),\n serverRefundLocktime: ms(r.btc_refund_locktime),\n };\n\n // Client sends BTC (funds the on-chain HTLC) and claims the Arkade VHTLC (the\n // server funds it). Unlike the other Arkade directions, the VHTLC's receiver is\n // the client's own key (not in the response) and its funder is `server_vhtlc_pk`;\n // the hash lock is a 20-byte HASH160, which buildArkadeVhtlcRef takes as-is.\n case \"btc_to_arkade\":\n return {\n swapId: r.id,\n clientHtlc: bitcoinLeg(\n r.btc_htlc_address,\n r.hash_lock,\n Number(r.source_amount),\n ),\n serverHtlc: buildArkadeVhtlcRef({\n senderPk: r.server_vhtlc_pk, // the server funds the VHTLC\n receiverPk: stored.publicKey, // the client claims it\n serverPk: r.arkade_server_pk,\n hashLock: r.hash_lock,\n address: r.arkade_vhtlc_address,\n refundLocktime: r.vhtlc_refund_locktime,\n unilateralClaimDelay: r.unilateral_claim_delay,\n unilateralRefundDelay: r.unilateral_refund_delay,\n unilateralRefundWithoutReceiverDelay:\n r.unilateral_refund_without_receiver_delay,\n expectedSats: Number(r.target_amount),\n }),\n clientRefundLocktime: ms(r.btc_refund_locktime),\n serverRefundLocktime: ms(r.vhtlc_refund_locktime),\n };\n\n // ─── Lightning: one on-chain leg, one off-chain LN payment ───────────────\n // Receive-on-Lightning: the client funds an on-chain HTLC and is paid over\n // Lightning. No server leg to watch — the server sweeping the client's leg\n // (with the preimage it got by paying the invoice) is the done signal.\n\n // Client funds the Arkade VHTLC; Boltz pays the invoice. The deposit is\n // `boltz_amount_sats` (source minus fees) — the amount actually locked, not\n // `source_amount` — else the client's own funding reads as under-funded.\n case \"arkade_to_lightning\":\n return {\n swapId: r.id,\n clientHtlc: arkadeLeg(\n r,\n r.arkade_vhtlc_address,\n Number(r.boltz_amount_sats),\n ),\n clientRefundLocktime: ms(r.vhtlc_refund_locktime),\n serverRefundLocktime: 0, // no on-chain server leg\n };\n // Client funds the EVM HTLC (server claims it after paying the invoice).\n case \"evm_to_lightning\":\n return {\n swapId: r.id,\n clientHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.hash_lock,\n claimAddress: r.server_evm_address, // the server claims the client's leg\n expectedSats: r.evm_expected_sats,\n // evm_to_lightning doesn't expose the locked token — verify amount only.\n }),\n clientRefundLocktime: ms(r.evm_refund_locktime),\n serverRefundLocktime: 0, // no on-chain server leg\n };\n\n // Pay-on-Lightning: the client pays a Lightning invoice (off-chain, nothing to\n // watch) and claims an on-chain HTLC. No client-funded leg — the client's\n // claim completes the swap; a hold invoice that never settles auto-unwinds.\n\n // Client pays the invoice, then claims the Arkade VHTLC (target_amount).\n case \"lightning_to_arkade\":\n return {\n swapId: r.id,\n serverHtlc: arkadeLeg(\n r,\n r.arkade_vhtlc_address,\n Number(r.target_amount),\n ),\n clientRefundLocktime: 0, // no on-chain client leg\n serverRefundLocktime: ms(r.vhtlc_refund_locktime),\n };\n // Client pays the invoice, then claims the EVM HTLC.\n case \"lightning_to_evm\":\n return {\n swapId: r.id,\n serverHtlc: evmLeg({\n chainId: r.evm_chain_id,\n htlc: r.evm_htlc_address,\n hashLock: r.hash_lock,\n claimAddress: r.client_evm_address, // the client claims the server's leg\n expectedSats: r.evm_expected_sats,\n token: r.wbtc_address,\n }),\n clientRefundLocktime: 0, // no on-chain client leg\n serverRefundLocktime: ms(r.evm_refund_locktime),\n };\n\n default:\n return undefined;\n }\n}\n","/**\n * The reactive orchestration.\n *\n * A {@link SwapTracker} watches each tracked swap's on-chain HTLC leg(s) via\n * per-ledger {@link ContractManager}s (two legs for chain↔chain swaps, one for\n * Lightning). On any change it recomputes the next action\n * (`deriveSwapStatus` → `deriveSwapActions`), and — deduped — notifies\n * subscribers, dropping a swap once it reaches a terminal state.\n *\n * This is the observe-mode layer: it *notifies*. Auto-execution (recover/auto\n * mode running the action) is a policy layer built on top of these same\n * notifications, gated by each action's `automation`.\n */\nimport { deriveSwapActions } from \"../actions/derive.js\";\nimport { deriveSwapStatus } from \"../actions/status.js\";\nimport type { HtlcObservation, SwapActions } from \"../actions/types.js\";\nimport type { ContractManager, HtlcRef, Ledger } from \"../contracts/types.js\";\n\n/**\n * A swap the tracker watches: its HTLC legs + refund locktimes (from the recovery\n * bundle). Chain↔chain swaps have both legs; Lightning swaps have exactly one\n * on-chain leg (the other side is an off-chain Lightning payment) — see\n * {@link SwapObservations}.\n */\nexport type TrackedSwap = {\n swapId: string;\n clientHtlc?: HtlcRef;\n serverHtlc?: HtlcRef;\n clientRefundLocktime: number;\n serverRefundLocktime: number;\n};\n\nexport type ActionSubscriber = (swapId: string, actions: SwapActions) => void;\n\nexport type SwapTrackerOptions = {\n /**\n * How often (ms) to re-poll every manager to advance clocks and reconcile\n * observations. Needed because some ledgers (Arkade) have no event push, so\n * state only moves on a poll. `0` disables the timer (tests drive `refresh`).\n */\n refreshIntervalMs?: number;\n};\n\nexport class SwapTracker {\n readonly #managers: Map<Ledger, ContractManager>;\n readonly #swaps = new Map<string, TrackedSwap>();\n /** Last actions emitted per swap — for dedupe and the subscribe-time snapshot. */\n readonly #lastActions = new Map<string, SwapActions>();\n readonly #subscribers = new Set<ActionSubscriber>();\n readonly #refreshIntervalMs: number;\n #eventUnsubs: Array<() => void> = [];\n #timer: ReturnType<typeof setInterval> | undefined;\n\n constructor(\n managers: Map<Ledger, ContractManager>,\n options?: SwapTrackerOptions,\n ) {\n this.#managers = managers;\n this.#refreshIntervalMs = options?.refreshIntervalMs ?? 0;\n }\n\n /** Register each swap's on-chain leg(s), subscribe to manager events, and seed state. */\n async startTracking(swaps: TrackedSwap[]): Promise<void> {\n for (const swap of swaps) {\n this.#swaps.set(swap.swapId, swap);\n for (const leg of legsOf(swap)) await this.#managerFor(leg).register(leg);\n }\n for (const manager of new Set(this.#managers.values())) {\n this.#eventUnsubs.push(manager.onEvent(() => this.#recomputeAll()));\n }\n // Prime each manager: seeds its clock and does a full reconcile, so the first\n // recompute has both observations AND clocks. Without this a ledger whose\n // clock is only populated on refresh (Arkade's MTP) stays `undefined` and the\n // recompute bails forever — nothing is ever emitted.\n await this.#refreshManagers();\n this.#recomputeAll();\n // Poll onward: Arkade has no event push, and clocks advance with wall time.\n if (this.#refreshIntervalMs > 0)\n this.#timer = setInterval(\n () => void this.#tick(),\n this.#refreshIntervalMs,\n );\n }\n\n async #tick(): Promise<void> {\n await this.#refreshManagers();\n this.#recomputeAll();\n }\n\n /**\n * Re-poll the managers that have a registered leg — seeding/advancing their\n * clocks and reconciling observations. Managers with nothing tracked are\n * skipped: refreshing them still hits their clock source (e.g. Arkade/Bitcoin\n * MTP via the API), so a swap that doesn't touch a ledger can't fail on that\n * ledger's endpoint being down (the default client builds every manager).\n */\n async #refreshManagers(): Promise<void> {\n const active = new Set<Ledger>();\n for (const swap of this.#swaps.values())\n for (const leg of legsOf(swap)) active.add(leg.ledger);\n const managers = new Set(\n [...active]\n .map((ledger) => this.#managers.get(ledger))\n .filter((m): m is ContractManager => m !== undefined),\n );\n await Promise.all([...managers].map((manager) => manager.refresh()));\n }\n\n /** Notify `cb` of the current action for each tracked swap, then on every change. */\n subscribeToActions(cb: ActionSubscriber): () => void {\n this.#subscribers.add(cb);\n for (const [swapId, actions] of this.#lastActions) cb(swapId, actions);\n return () => this.#subscribers.delete(cb);\n }\n\n /**\n * Stop tracking: unregister every still-tracked leg (releasing its manager's\n * watch — e.g. the EVM per-chain block watch that only `unregister` tears down),\n * drop the poll timer, and detach event listeners + subscribers. Mirrors\n * `startTracking`'s `register`, so no manager keeps watching a stopped tracker's\n * swaps. The managers themselves are not owned here, so they are unregistered but\n * never disposed.\n */\n stop(): void {\n if (this.#timer) clearInterval(this.#timer);\n this.#timer = undefined;\n for (const unsub of this.#eventUnsubs) unsub();\n this.#eventUnsubs = [];\n for (const swap of this.#swaps.values())\n for (const leg of legsOf(swap))\n void this.#managerFor(leg).unregister(leg);\n this.#swaps.clear();\n this.#subscribers.clear();\n }\n\n #managerFor(ref: HtlcRef): ContractManager {\n const manager = this.#managers.get(ref.ledger);\n if (!manager)\n throw new Error(`no ContractManager for ledger '${ref.ledger}'`);\n return manager;\n }\n\n #recomputeAll(): void {\n for (const swap of this.#swaps.values()) this.#recompute(swap);\n }\n\n #recompute(swap: TrackedSwap): void {\n // A Lightning swap has one on-chain leg; the absent leg stays `undefined` (its\n // status is derived from the leg that exists). Gate only on present legs — a\n // leg with no observation or clock yet means \"not enough known\", so bail.\n let clientHtlc: HtlcObservation | undefined;\n let serverHtlc: HtlcObservation | undefined;\n let clientChainNow = 0;\n let serverChainNow = 0;\n\n if (swap.clientHtlc) {\n const m = this.#managerFor(swap.clientHtlc);\n clientHtlc = m.getState(swap.clientHtlc);\n const now = m.chainNow(swap.clientHtlc);\n if (clientHtlc === undefined || now === undefined) return;\n clientChainNow = now;\n }\n if (swap.serverHtlc) {\n const m = this.#managerFor(swap.serverHtlc);\n serverHtlc = m.getState(swap.serverHtlc);\n const now = m.chainNow(swap.serverHtlc);\n if (serverHtlc === undefined || now === undefined) return;\n serverChainNow = now;\n }\n\n const status = deriveSwapStatus({ clientHtlc, serverHtlc });\n if (status === undefined) return; // contradictory observations\n\n const actions = deriveSwapActions({\n status,\n clientChainNow,\n serverChainNow,\n clientRefundLocktime: swap.clientRefundLocktime,\n serverRefundLocktime: swap.serverRefundLocktime,\n // Pay-on-Lightning swaps have no client-funded on-chain leg.\n clientFunds: swap.clientHtlc !== undefined,\n });\n\n const previous = this.#lastActions.get(swap.swapId);\n if (previous && JSON.stringify(previous) === JSON.stringify(actions))\n return;\n\n this.#lastActions.set(swap.swapId, actions);\n for (const cb of this.#subscribers) cb(swap.swapId, actions);\n\n // Terminal: stop watching (retain lastActions so late subscribers still see it).\n if (actions.recommended === \"none\") this.#untrack(swap);\n }\n\n #untrack(swap: TrackedSwap): void {\n this.#swaps.delete(swap.swapId);\n for (const leg of legsOf(swap)) void this.#managerFor(leg).unregister(leg);\n }\n}\n\n/** The on-chain legs actually present on a swap (one for Lightning, two otherwise). */\nfunction legsOf(swap: TrackedSwap): HtlcRef[] {\n const legs: HtlcRef[] = [];\n if (swap.clientHtlc) legs.push(swap.clientHtlc);\n if (swap.serverHtlc) legs.push(swap.serverHtlc);\n return legs;\n}\n"],"mappings":";;;;;;;AAaA,cAAc;;;ACHP,SAAS,kBAAkB,OAAqC;AACrE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,EAChB,IAAI;AAEJ,UAAQ,QAAQ;AAAA,IACd,KAAK,WAAW;AAKd,UAAI,CAAC,aAAa;AAChB,cAAM,OAAmB;AAAA,UACvB,IAAI;AAAA,UACJ,aAAa;AAAA,UACb,YAAY;AAAA,UACZ,QAAQ;AAAA,QACV;AACA,eAAO,EAAE,aAAa,QAAQ,SAAS,CAAC,IAAI,EAAE;AAAA,MAChD;AAIA,UAAI,kBAAkB,qBAAsB,QAAO,EAAE,SAAS,CAAC,EAAE;AAEjE,YAAM,OAAmB;AAAA,QACvB,IAAI;AAAA,QACJ,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,YAAY,MAAyD;AACnE,SAAK,OAAO,SAAS,GAAG,IAAI;AAC5B,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,MAAuD;AAC/D,SAAK,OAAO,OAAO,GAAG,IAAI;AAC1B,WAAO;AAAA,EACT;AAAA,EAEA,cAAc,MAA2D;AACvE,SAAK,OAAO,WAAW,GAAG,IAAI;AAC9B,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,MAA6D;AAC3E,SAAK,OAAO,aAAa,GAAG,IAAI;AAChC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,QAAyB;AAC7B,WAAO,IAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,MAC3C,SAAS,KAAK;AAAA,MACd,UAAU,KAAK;AAAA,MACf,iBAAiB,KAAK;AAAA,MACtB,YAAY,KAAK;AAAA,MACjB,YAAY,KAAK;AAAA,IACnB,CAAC;AAAA,EACH;AACF;","names":["refund","hex","hex","hex","hex","hex","esploraReader","hex","ripemd160","hex","seconds","strip0x"]}
|
package/dist/node.d.cts
CHANGED
package/dist/node.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satora/swap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Satora swap client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -52,12 +52,17 @@
|
|
|
52
52
|
"dist"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@
|
|
55
|
+
"@arkade-os/sdk": "^0.4.45",
|
|
56
|
+
"@lendasat/lendaswap-sdk-pure": "^0.4.0",
|
|
57
|
+
"@noble/hashes": "^2.2.0",
|
|
58
|
+
"@scure/base": "^2.0.0",
|
|
59
|
+
"viem": "2.52.2"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
62
|
"@biomejs/biome": "2.3.15",
|
|
59
63
|
"tsup": "^8.5.1",
|
|
60
|
-
"typescript": "^5.7.0"
|
|
64
|
+
"typescript": "^5.7.0",
|
|
65
|
+
"vitest": "^3.0.0"
|
|
61
66
|
},
|
|
62
67
|
"license": "MIT",
|
|
63
68
|
"publishConfig": {
|
|
@@ -66,6 +71,8 @@
|
|
|
66
71
|
"scripts": {
|
|
67
72
|
"build": "tsup",
|
|
68
73
|
"check-types": "tsc -p tsconfig.json --noEmit",
|
|
74
|
+
"test": "vitest",
|
|
75
|
+
"test:run": "vitest run",
|
|
69
76
|
"lint": "biome check .",
|
|
70
77
|
"lint:fix": "biome check --write .",
|
|
71
78
|
"clean": "rm -rf dist"
|