@arkade-os/swap 0.1.9 → 0.1.10

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.
Files changed (45) hide show
  1. package/dist/advanced.cjs +1097 -541
  2. package/dist/advanced.d.cts +19 -21
  3. package/dist/advanced.d.ts +19 -21
  4. package/dist/advanced.js +40 -34
  5. package/dist/{chunk-FQNG4XMF.js → chunk-2HQZLIVX.js} +98 -37
  6. package/dist/{chunk-5QPJWOCN.js → chunk-6RJVT65W.js} +2 -0
  7. package/dist/chunk-AUJDREZN.js +445 -0
  8. package/dist/{chunk-I7WEXXZX.js → chunk-FWRDAL73.js} +157 -477
  9. package/dist/{chunk-552GDPBU.js → chunk-LCO6AJOS.js} +433 -59
  10. package/dist/index.cjs +1083 -530
  11. package/dist/index.d.cts +5 -6
  12. package/dist/index.d.ts +5 -6
  13. package/dist/index.js +24 -22
  14. package/dist/{lockupContract-DguuT7NK.d.cts → lockupContract-BTTRVwOt.d.cts} +1 -1
  15. package/dist/{lockupContract-BUOsghl1.d.ts → lockupContract-aFarhlxj.d.ts} +1 -1
  16. package/dist/node/index.d.cts +97 -67
  17. package/dist/node/index.d.ts +97 -67
  18. package/dist/nostr.cjs +925 -516
  19. package/dist/nostr.d.cts +1 -1
  20. package/dist/nostr.d.ts +1 -1
  21. package/dist/nostr.js +3 -2
  22. package/dist/{offerFillPlan-_AOLo6kh.d.ts → offerFillPlan-CJC5tnEd.d.ts} +10 -42
  23. package/dist/{offerFillPlan-Bp6-z6dS.d.cts → offerFillPlan-FmyaQoYT.d.cts} +10 -42
  24. package/dist/protocol.cjs +1054 -175
  25. package/dist/protocol.d.cts +42 -23
  26. package/dist/protocol.d.ts +42 -23
  27. package/dist/protocol.js +20 -7
  28. package/dist/repositories/realm/index.d.cts +3 -2
  29. package/dist/repositories/realm/index.d.ts +3 -2
  30. package/dist/repositories/sqlite/index.d.cts +3 -2
  31. package/dist/repositories/sqlite/index.d.ts +3 -2
  32. package/dist/{repository-CkKK0dGO.d.ts → repository-CwwhIAEd.d.cts} +406 -74
  33. package/dist/{repository--pfikw2R.d.cts → repository-DO6QKxBx.d.ts} +406 -74
  34. package/dist/{rfq-IzhOCG02.d.ts → rfq-CYxOyniL.d.ts} +52 -11
  35. package/dist/rfq-contract.cjs +3 -0
  36. package/dist/rfq-contract.d.cts +3 -1
  37. package/dist/rfq-contract.d.ts +3 -1
  38. package/dist/rfq-contract.js +3 -1
  39. package/dist/{rfq-BRpo5uWU.d.cts → rfq-nMGywkqI.d.cts} +52 -11
  40. package/dist/verify-ENO36VPK.js +33 -0
  41. package/dist/{watch-pvTVFp6-.d.cts → watch-DpDSP2tu.d.cts} +4 -3
  42. package/dist/{watch-DDNycuUa.d.ts → watch-_fZSgx_l.d.ts} +4 -3
  43. package/package.json +2 -2
  44. package/dist/offer-BhonWuKR.d.ts +0 -274
  45. package/dist/offer-D_qHpWo2.d.cts +0 -274
@@ -1,6 +1,398 @@
1
1
  import { DiscoveredMarket } from '@arkade-os/solver-discovery';
2
- import { IWallet, ProvisionedKey, ProvisionedClaimSecret, OperatorProvider, Asset, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, asset, PageRequest, PageResult } from '@arkade-os/sdk';
3
- import { e as RfqTransport, E as RfqStatus, O as OnchainHtlc, l as ChainUtxo, C as ChainSource, z as OnchainHtlcPhase } from './rfq-IzhOCG02.js';
2
+ import { arkade, asset, RelativeTimelock, OperatorInfo, ArkTxInput, Outpoint, IWallet, EmulatorProvider, ProvisionedKey, ProvisionedClaimSecret, OperatorProvider, Asset, RestIndexerProvider, IContractManager, VHTLC, Identity, Network, InputExpiryFloor, NetworkName, PageRequest, PageResult } from '@arkade-os/sdk';
3
+ import { ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_V4 } from './rfq-contract.cjs';
4
+ import { m as RfqTransport, U as RfqStatus, O as OnchainHtlc, s as ChainUtxo, C as ChainSource, K as OnchainHtlcPhase, H as Hex, P as Pubkey } from './rfq-nMGywkqI.cjs';
5
+
6
+ /** `asset-swap` and `sats-swap`. Exit is appended later; it is not in either artifact.
7
+ *
8
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
9
+ */
10
+ declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
11
+ type AssetSwapContractVersion = typeof ASSET_SWAP_V2 | typeof ASSET_SWAP_V3 | typeof ASSET_SWAP_V4;
12
+ /** What every asset RFQ advertises: the directed covenant alone. */
13
+ declare const ASSET_SWAP_CONTRACT_VERSIONS: readonly ["asset-swap-v4"];
14
+ /** Every version this build derives: the registry's keys, not a preference. */
15
+ declare const ASSET_SWAP_DERIVABLE_VERSIONS: readonly ["asset-swap-v4", "asset-swap-v3", "asset-swap-v2"];
16
+ /** Absent means {@link ASSET_SWAP_BASELINE}; an id this build cannot derive throws. */
17
+ declare const assetSwapContractVersion: (id: string | undefined) => AssetSwapContractVersion;
18
+
19
+ /**
20
+ * Where a monitored RFQ swap stands, and which of those states end it. Its own module so the
21
+ * record layer (retention via {@link isRfqSwapTerminal}) and the manager need not import each
22
+ * other at runtime; `swapManager.ts` re-exports all three names.
23
+ */
24
+ /**
25
+ * Where a monitored swap stands; the vocabulary of `CorridorSwapRecord.state`. `Outcome`, from
26
+ * `client.onUpdate()`, is the client-level projection over it.
27
+ *
28
+ * `claimable`/`claimed` apply when the TRADER has something to claim: the L1 fill on an onchain
29
+ * send, the solver-funded lockup on a receive. `lightning_send` has neither; the trader's only
30
+ * move there is the refund.
31
+ */
32
+ type RfqSwapState =
33
+ /** Live; nothing actionable yet. On a receive leg this covers the whole
34
+ * stretch before the solver funds anything. */
35
+ "pending"
36
+ /** There is something for the trader to take, and the window to take it is
37
+ * open: the confirmed L1 fill on an onchain send, or a lockup funded for at
38
+ * least `expectedAmount` on a receive. */
39
+ | "claimable"
40
+ /**
41
+ * The trader's claim has been made (L1 broadcast on an onchain send, Arkade submission on a
42
+ * receive). **On a receive this is a local belief, not a chain fact**, hence not terminal:
43
+ * `refunded` is still reachable if the claim never lands.
44
+ */
45
+ | "claimed"
46
+ /**
47
+ * This wallet will not act, and only the counterparty can change that
48
+ * (`RfqSwapCommon.blockedReason` says why).
49
+ *
50
+ * Send leg: the Arkade refund cannot be pushed from here (no secrets, foreign descriptor, or
51
+ * nothing wired). Receive leg: the lockup cannot be claimed — underfunded (publishing `P`
52
+ * for it is the attack `LockupAmountMismatchError` refuses) or its claim window shut.
53
+ *
54
+ * **Not terminal.** The money is still at the lockup and the refusal is re-checked every
55
+ * pass, so fixing the cause returns the swap to `pending`. On an onchain send the L1 half
56
+ * keeps being driven regardless.
57
+ */
58
+ | "needs_counterparty"
59
+ /**
60
+ * Terminal: the lockup was spent by a hash-verified claim, read off chain, never reported.
61
+ * On a send leg it is the counterparty's claim; on a receive leg the TRADER's own, matched by
62
+ * hash rather than our txid so a claim that lands without us still counts.
63
+ */
64
+ | "settled"
65
+ /**
66
+ * Terminal: the lockup was spent by something other than a claim. On a send leg that is the
67
+ * money coming back. **On a receive leg it is a LOSS**: every non-claim leaf is the
68
+ * solver's. Also where a receive swap ends when its window closes with nothing to observe.
69
+ */
70
+ | "refunded"
71
+ /** Terminal: an action failed and its window closed. */
72
+ | "failed";
73
+ /** Whether `CorridorSwapRecord.state` ends the swap. */
74
+ declare const isRfqSwapTerminal: (state: RfqSwapState) => boolean;
75
+
76
+ /**
77
+ * Coverage: whether an offer's script is in the wallet's watched set. `createOffer` promotes; the
78
+ * watcher and restore consumer retire. Identical offers share one script, so a late demotion would
79
+ * unwatch an address the user was just told to fund. Guards: per-script serialization (the watch
80
+ * state is a read-modify-write), and an issuance mark for created-but-unfunded offers, which have no
81
+ * record yet. The mark is per process; the restore scan backstops other contexts and restarts.
82
+ */
83
+
84
+ interface CoverageRegistrationOptions {
85
+ readonly coverageId?: string;
86
+ /** Use the wallet object: a worker can return a fresh manager proxy on every call. */
87
+ readonly scope?: object;
88
+ }
89
+
90
+ /** A full-fill offer. Exactly one field names an asset: `wantAsset` = the fill must deliver that
91
+ * asset (the deposit is whatever the funding vtxo holds); `offerAsset` = the user deposits that
92
+ * asset and wants sats.
93
+ *
94
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
95
+ */
96
+ interface Offer {
97
+ /** The scriptPubKey of the swap contract. */
98
+ swapPkScript: Uint8Array;
99
+ /** Amount the user wants (asset units, or sats when wanting BTC). */
100
+ wantAmount: bigint;
101
+ /** The asset the user wants. Omitted when wanting BTC. */
102
+ wantAsset?: asset.AssetId;
103
+ /** The asset the user deposits. Omitted when depositing BTC. */
104
+ offerAsset?: asset.AssetId;
105
+ /** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
106
+ makerPkScript: Uint8Array;
107
+ /** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
108
+ makerPublicKey: Uint8Array;
109
+ /** X-only key (32 bytes) of the operator's cosigner that emulates Arkade Script. */
110
+ emulatorPubkey: Uint8Array;
111
+ /** Partial-fill numerator. Reserved wire space in V1: carried through the
112
+ * codec so an offer that sets it decodes, never interpreted here. */
113
+ ratioNum?: bigint;
114
+ /** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
115
+ ratioDen?: bigint;
116
+ /** The maker's unilateral exit path. Present adds a third closure to the
117
+ * taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
118
+ exitDelay?: RelativeTimelock;
119
+ /** The solver key `fulfill` requires, x-only. Present on directed versions only, and its
120
+ * presence is what selects the `asset-swap-v4` tree. */
121
+ taker?: Uint8Array;
122
+ }
123
+ /** Program + args + keys of an offer's contract: the single source for address derivation and
124
+ * cancel (any change here changes derived swap addresses — see the golden test). Spelled via the
125
+ * public `arkade` namespace so tsc can emit a portable declaration. */
126
+ type SwapProgramBinding = {
127
+ version: AssetSwapContractVersion;
128
+ program: ConstructorParameters<typeof arkade.ArkadeProgramScript>[0];
129
+ args: ConstructorParameters<typeof arkade.ArkadeProgramScript>[1];
130
+ keys: ConstructorParameters<typeof arkade.ArkadeProgramScript>[2];
131
+ };
132
+ /** Compile the offer's contract: program + args -> taproot tree.
133
+ *
134
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
135
+ */
136
+ declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array, contractVersion?: AssetSwapContractVersion): InstanceType<typeof arkade.ArkadeProgramScript>;
137
+ /** Everything needed to recompile an offer covenant, with no TLV in the loop. */
138
+ interface OfferBinding {
139
+ /** Selects the program pair, so nothing is trial-compiled. */
140
+ readonly version: AssetSwapContractVersion;
141
+ /** 34-byte taproot scriptPubKey the fill must pay. */
142
+ readonly receiverPkScript: Uint8Array;
143
+ /** Asset units, or sats when the want side is BTC. */
144
+ readonly amount: bigint;
145
+ /** Exactly one of these two. */
146
+ readonly wantAsset?: asset.AssetId;
147
+ readonly offerAsset?: asset.AssetId;
148
+ /** The funder's x-only key: `cancel`'s and `exit`'s signer. */
149
+ readonly userPublicKey: Uint8Array;
150
+ /** x-only Arkade Service key the covenant was funded under. */
151
+ readonly serverPublicKey: Uint8Array;
152
+ readonly emulatorPublicKey: Uint8Array;
153
+ /** Omitted removes the exit leaf, which changes the address. */
154
+ readonly exitDelay?: RelativeTimelock;
155
+ /** The solver key `fulfill` requires; `asset-swap-v4` only. */
156
+ readonly taker?: Uint8Array;
157
+ }
158
+ /** The binding's program, args and keys, at the binding's own version. */
159
+ declare function bindingProgram(binding: OfferBinding): SwapProgramBinding;
160
+ /**
161
+ * A decoded offer as a binding, at whichever version reproduces its `swapPkScript` under
162
+ * `operatorPubkey`. Throws {@link OfferCovenantMismatchError} when none does.
163
+ */
164
+ declare function bindingFromOffer(offer: Offer, operatorPubkey: Uint8Array): OfferBinding;
165
+ /** The offer a binding compiles to: what its packet encodes. */
166
+ declare function offerFromBinding(binding: OfferBinding): Offer;
167
+ /** {@link OfferBinding} as a record stores it: hex and decimal strings, so the record stays JSON. */
168
+ interface RecordedOfferBinding {
169
+ readonly version: AssetSwapContractVersion;
170
+ readonly receiverPkScript: string;
171
+ readonly amount: string;
172
+ readonly wantAsset?: string;
173
+ readonly offerAsset?: string;
174
+ readonly userPublicKey: string;
175
+ readonly serverPublicKey: string;
176
+ readonly emulatorPublicKey: string;
177
+ readonly exitDelay?: {
178
+ readonly type: RelativeTimelock["type"];
179
+ readonly value: string;
180
+ };
181
+ readonly taker?: string;
182
+ }
183
+ /** Extension packet type tag for Arkade Intents offers.
184
+ *
185
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
186
+ */
187
+ declare const OFFER_PACKET_TYPE = 3;
188
+ /** Serialize an offer to TLV bytes (the packet payload).
189
+ *
190
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
191
+ */
192
+ declare function encodeOffer(offer: Offer): Uint8Array;
193
+ /** Parse TLV bytes into an offer. Throws on malformed or unknown records.
194
+ *
195
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
196
+ */
197
+ declare function decodeOffer(data: Uint8Array): Offer;
198
+ /**
199
+ * Build a new offer for `wallet` (the user). Fund `address` with the side
200
+ * you deposit, embedding the returned extension, and the solver does the rest:
201
+ *
202
+ * // BTC -> asset
203
+ * const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
204
+ * await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
205
+ *
206
+ * // asset -> BTC (the sats are the VTXO carrier for the asset)
207
+ * const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
208
+ * await wallet.send({ address: o.address, amount: 500,
209
+ * assets: [{ assetId, amount: 1000n }],
210
+ * extensions: [o.extension] })
211
+ *
212
+ * Broadcasts nothing, but registers the covenant before returning the address: a failure now is
213
+ * retryable, whereas after `wallet.send` it would leave a funded deposit unwatched. The unilateral
214
+ * exit closure is built by default (operator's `unilateralExitDelay`, as solverd does); without it only
215
+ * the operator-cosigned `cancel` gets the deposit out, and an offer never expires.
216
+ *
217
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
218
+ */
219
+ declare function createOffer(wallet: IWallet, params: OfferParams, options?: CoverageRegistrationOptions): Promise<{
220
+ /** The encoded offer, hex. **Persist this** — it is the only input `cancelOffer` needs to
221
+ * rebuild the covenant. */
222
+ offerHex: string;
223
+ /** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
224
+ extension: {
225
+ type: number;
226
+ payload: Uint8Array;
227
+ };
228
+ /** The swap address to fund. Identical offers derive an identical address, so the funding
229
+ * txid — not the address — identifies one deposit. */
230
+ address: string;
231
+ /** The covenant's scriptPubKey: the key an indexer watches to spot the
232
+ * deposit and its later spend (`AssetSwap.swapPkScript`). */
233
+ swapPkScript: Uint8Array;
234
+ }>;
235
+ interface OfferParams {
236
+ receiveAddress?: string;
237
+ wantAmount: bigint;
238
+ wantAsset?: asset.AssetId;
239
+ offerAsset?: asset.AssetId;
240
+ /** Co-signer key override (33-byte compressed hex); see
241
+ * {@link resolveEmulatorPubkey}. */
242
+ emulatorPubkey?: string;
243
+ /** Override the exit closure's delay. Defaults to the operator's own
244
+ * `unilateralExitDelay`, which is the delay solverd uses too. */
245
+ exitDelay?: RelativeTimelock;
246
+ /** Publish without the exit closure, leaving `cancel` — which needs the
247
+ * operator — as the only way back out. See the note on {@link createOffer}. */
248
+ noExit?: boolean;
249
+ /**
250
+ * A live `getArkadeInfo` the caller already made.
251
+ *
252
+ * Passing it is what lets one live read bind both the derivation and the
253
+ * registration that follows it; omitting it makes the read here. It must be
254
+ * live for the reason {@link createOffer} reads live — the info's
255
+ * `signerPubkey` ends up in a covenant leaf.
256
+ */
257
+ info?: OperatorInfo;
258
+ /**
259
+ * The maker position, when the caller already read it.
260
+ *
261
+ * The RFQ path reads it BEFORE it sends the request — the profile commits
262
+ * to this script and this key — so re-reading it here would let an address
263
+ * rotation between the two reads derive a covenant the solver never quoted.
264
+ */
265
+ maker?: {
266
+ pkScript: Uint8Array;
267
+ publicKey: Uint8Array;
268
+ };
269
+ /** Defaults to {@link ASSET_SWAP_BASELINE}, or to `asset-swap-v4` with a `taker`. */
270
+ contractVersion?: AssetSwapContractVersion;
271
+ /** The quoting solver's x-only key, for a directed offer. */
272
+ taker?: Uint8Array;
273
+ }
274
+ /**
275
+ * Everything an offer commits to, derived and encoded, with nothing written.
276
+ *
277
+ * The split exists because `quote()` must derive the covenant it verifies the
278
+ * solver's `offer_address` against while persisting and registering nothing,
279
+ * and `accept()` must register **that** derivation rather than a second one
280
+ * built from the same terms. So the tree's own parameters travel on this value:
281
+ * two derivations that can disagree is the failure the hand-off deletes.
282
+ */
283
+ interface DerivedOffer {
284
+ readonly offerHex: string;
285
+ readonly extension: {
286
+ readonly type: number;
287
+ readonly payload: Uint8Array;
288
+ };
289
+ readonly address: string;
290
+ readonly swapPkScript: Uint8Array;
291
+ /** The covenant's parameters — {@link registerDerivedOffer}'s only input. */
292
+ readonly binding: Readonly<Omit<Offer, "swapPkScript">>;
293
+ /** The same covenant with its version: what a directed record stores in place of `offerHex`. */
294
+ readonly offerBinding: OfferBinding;
295
+ /** The live info this covenant is bound to. */
296
+ readonly info: OperatorInfo;
297
+ readonly operatorPubkey: Uint8Array;
298
+ }
299
+ /**
300
+ * Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid. No path is on a
301
+ * deadline, so an unfilled deposit stays at the swap address until the user cancels.
302
+ *
303
+ * Routes out: `fulfill` (operator alone, but constrained to pay `makerWP` at least `wantAmount`),
304
+ * `cancel` (user+operator 2-of-2, no solver involved), `exit` (user alone after a CSV unless `noExit`;
305
+ * reached by unrolling onchain, not here).
306
+ *
307
+ * Cancel races a fill: if `fulfill` spent first this throws "no spendable VTXO at the swap address",
308
+ * which means the swap completed (`classifySpend` tells the spends apart by leaf). The escrow marker
309
+ * gates implicit coin selection only; cancel names its input explicitly.
310
+ *
311
+ * `fundingTxid` selects the deposit (identical offers share an address); without it the address must
312
+ * hold exactly one. `swapAddress` pins the funding-time operator key across a signer rotation, and
313
+ * for an {@link OfferBinding}, which pins its own, must be the address it compiles to. When
314
+ * `repository` holds the record, this writes `cancelling` (crash marker) then `cancelled`, so the
315
+ * watcher has nothing to decide for our own cancels; otherwise the watcher/restore scan classifies.
316
+ *
317
+ * @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
318
+ */
319
+ declare function cancelOffer(wallet: IWallet, offerHex: string | OfferBinding, opts: {
320
+ repository: AssetSwapRepository;
321
+ fundingTxid?: string;
322
+ fundingOutpoint?: FillOutpoint;
323
+ swapAddress?: string;
324
+ }): Promise<string>;
325
+ /**
326
+ * No deposit left to cancel at the swap address — almost always the fill winning the race. Typed so
327
+ * the v2 client's `cancel()` reconciles by `instanceof` (see `client/cancel.ts`); message is v1's.
328
+ *
329
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
330
+ */
331
+ declare class NoSpendableDepositError extends Error {
332
+ readonly name = "NoSpendableDepositError";
333
+ constructor(options?: ErrorOptions);
334
+ }
335
+ /**
336
+ * The rebuilt covenant disagrees with the offer's `swapPkScript`: the pinned operator key is not the
337
+ * one the covenant was funded with (rotated signer, a wrong `swapAddress`, or a corrupt record).
338
+ * Fires before any broadcast.
339
+ *
340
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
341
+ */
342
+ declare class OfferCovenantMismatchError extends Error {
343
+ readonly swapPkScript: string;
344
+ readonly name = "OfferCovenantMismatchError";
345
+ constructor(swapPkScript: string, options?: ErrorOptions);
346
+ }
347
+ /** Sats carried by output 0 when the maker is paid in an ASSET: the covenant checks the asset, and
348
+ * the output still needs its own carrier. Overridable per fill via `assetCarrierSats`.
349
+ *
350
+ * @deprecated Read it from `@arkade-os/sdk`, which owns the constant. Moved off the package root to `@arkade-os/swap/protocol`.
351
+ */
352
+ declare const ASSET_CARRIER_SATS: bigint;
353
+ /**
354
+ * A coin the taker supplies, plus the assets it carries. `ArkTxInput` is sats-only, and **arkd
355
+ * refuses a spend whose asset packet omits an asset one of its inputs owns** (`ASSET_NOT_FOUND`), so
356
+ * every asset on a funding coin must be declared. A wallet's own coins already carry this shape.
357
+ */
358
+ type FillFunding = ArkTxInput & {
359
+ assets?: readonly {
360
+ assetId: string;
361
+ amount: bigint | number;
362
+ }[];
363
+ };
364
+ /** @deprecated Use `Outpoint` from `@arkade-os/sdk`. */
365
+ type FillOutpoint = Outpoint;
366
+ type FillInputOwner = "solver" | "sponsor";
367
+ /**
368
+ * Fill an offer — the TAKER's side, and the counterpart to {@link createOffer}. Composes the
369
+ * `fulfill` spend; it does not weaken or reinterpret the covenant.
370
+ *
371
+ * `fulfill` reads the output at the spending input's index. This builder puts the deposit at
372
+ * input 0 and the maker payout at output 0. An ASSET want is the first packet group on that
373
+ * output, which carries only a dust carrier ({@link ASSET_CARRIER_SATS}). Every other asset
374
+ * goes to the taker's payout; see {@link FillFunding}.
375
+ *
376
+ * Writes NO local swap record: the maker learns the outcome from the chain (RFQ protocol § 7.2).
377
+ * `fund` is explicit because only the caller knows which coins are reserved (e.g. a corridor's
378
+ * float). Racing a cancel is NORMAL: "no spendable VTXO at the swap address" means the offer is gone.
379
+ *
380
+ * @deprecated The v2 client has no taker-side fill, so there is no replacement:
381
+ * `accept()` funds a covenant of your own; it does not spend someone else's
382
+ * offer through its `fulfill` leaf. Moved off the package root to `@arkade-os/swap/protocol`.
383
+ */
384
+ declare function fillOffer(wallet: IWallet, arkServerUrl: string, offerHex: string | OfferBinding, opts: {
385
+ fund: FillFunding[];
386
+ payoutScript?: Uint8Array;
387
+ fundingTxid?: string;
388
+ fundingOutpoint?: FillOutpoint;
389
+ swapAddress?: string;
390
+ assetCarrierSats?: bigint;
391
+ emulator: EmulatorProvider | string;
392
+ emulatorPubkey?: string;
393
+ }): Promise<string>;
394
+ /** @deprecated Use `offerContract` from `@arkade-os/swap/protocol`. */
395
+ declare const offerVtxoScript: typeof offerContract;
4
396
 
5
397
  /** @deprecated Use `Outcome`. Moved off the package root to `@arkade-os/swap/protocol`. */
6
398
  type AssetSwapStatus = "pending" | "cancelling" | "fulfilled" | "cancelled" | "recoverable" | "awaiting_fill" | "claimable" | "claimed" | "refunded_l1";
@@ -38,8 +430,10 @@ interface AssetSwap extends SwapSecretsProjection {
38
430
  swapAddress: string;
39
431
  /** Hex pkScript of the swap contract — the indexer monitoring key. */
40
432
  swapPkScript: string;
41
- /** TLV offer — needed to rebuild the contract for cancel. */
42
- offerHex: string;
433
+ /** TLV offer — rebuilds the contract for cancel when there is no `binding`. */
434
+ offerHex?: string;
435
+ /** The covenant, structured. A directed offer carries this and no `offerHex`. */
436
+ binding?: RecordedOfferBinding;
43
437
  fundingTxid: string;
44
438
  spentTxid?: string;
45
439
  status: AssetSwapStatus;
@@ -329,63 +723,6 @@ declare function pushRefundWithoutReceiver(operator: SwapOperator, input: {
329
723
  */
330
724
  declare const REFUND_MTP_LAG_SECONDS: number;
331
725
 
332
- /**
333
- * Where a monitored RFQ swap stands, and which of those states end it. Its own module so the
334
- * record layer (retention via {@link isRfqSwapTerminal}) and the manager need not import each
335
- * other at runtime; `swapManager.ts` re-exports all three names.
336
- */
337
- /**
338
- * Where a monitored swap stands; the vocabulary of `CorridorSwapRecord.state`. `Outcome`, from
339
- * `client.onUpdate()`, is the client-level projection over it.
340
- *
341
- * `claimable`/`claimed` apply when the TRADER has something to claim: the L1 fill on an onchain
342
- * send, the solver-funded lockup on a receive. `lightning_send` has neither; the trader's only
343
- * move there is the refund.
344
- */
345
- type RfqSwapState =
346
- /** Live; nothing actionable yet. On a receive leg this covers the whole
347
- * stretch before the solver funds anything. */
348
- "pending"
349
- /** There is something for the trader to take, and the window to take it is
350
- * open: the confirmed L1 fill on an onchain send, or a lockup funded for at
351
- * least `expectedAmount` on a receive. */
352
- | "claimable"
353
- /**
354
- * The trader's claim has been made (L1 broadcast on an onchain send, Arkade submission on a
355
- * receive). **On a receive this is a local belief, not a chain fact**, hence not terminal:
356
- * `refunded` is still reachable if the claim never lands.
357
- */
358
- | "claimed"
359
- /**
360
- * This wallet will not act, and only the counterparty can change that
361
- * (`RfqSwapCommon.blockedReason` says why).
362
- *
363
- * Send leg: the Arkade refund cannot be pushed from here (no secrets, foreign descriptor, or
364
- * nothing wired). Receive leg: the lockup cannot be claimed — underfunded (publishing `P`
365
- * for it is the attack `LockupAmountMismatchError` refuses) or its claim window shut.
366
- *
367
- * **Not terminal.** The money is still at the lockup and the refusal is re-checked every
368
- * pass, so fixing the cause returns the swap to `pending`. On an onchain send the L1 half
369
- * keeps being driven regardless.
370
- */
371
- | "needs_counterparty"
372
- /**
373
- * Terminal: the lockup was spent by a hash-verified claim, read off chain, never reported.
374
- * On a send leg it is the counterparty's claim; on a receive leg the TRADER's own, matched by
375
- * hash rather than our txid so a claim that lands without us still counts.
376
- */
377
- | "settled"
378
- /**
379
- * Terminal: the lockup was spent by something other than a claim. On a send leg that is the
380
- * money coming back. **On a receive leg it is a LOSS**: every non-claim leaf is the
381
- * solver's. Also where a receive swap ends when its window closes with nothing to observe.
382
- */
383
- | "refunded"
384
- /** Terminal: an action failed and its window closed. */
385
- | "failed";
386
- /** Whether `CorridorSwapRecord.state` ends the swap. */
387
- declare const isRfqSwapTerminal: (state: RfqSwapState) => boolean;
388
-
389
726
  /**
390
727
  * What the manager needs to register a swap's lockup with the wallet, so the indexer
391
728
  * pushes its funding and spend.
@@ -1556,15 +1893,6 @@ declare const railOfCorridor: <C extends CorridorId>(corridor: C) => RailOf<C>;
1556
1893
  * reference this side cannot invent. */
1557
1894
  declare const corridorOfRail: (rail: Rail) => Corridor | undefined;
1558
1895
 
1559
- /**
1560
- * The two string aliases the v2 surface is written in. Aliases rather than branded types, so
1561
- * literals need no constructor.
1562
- */
1563
- /** Lowercase hex, no `0x` prefix — the encoding `@scure/base`'s `hex` emits. */
1564
- type Hex = string;
1565
- /** A secp256k1 public key as {@link Hex}: x-only (32 bytes) or compressed (33). */
1566
- type Pubkey = Hex;
1567
-
1568
1896
  /**
1569
1897
  * One outcome vocabulary over the protocol's two state machines (`RfqSwapState` for
1570
1898
  * corridors, `AssetSwapStatus` for offers), and the translation that produces it.
@@ -2135,19 +2463,23 @@ interface SwapRecordCommon {
2135
2463
  readonly createdAt: number;
2136
2464
  readonly updatedAt: number;
2137
2465
  }
2138
- /** `arkade <-> arkade`: the offer covenant. `offerHex` is the whole covenant, so no tree params. */
2466
+ /** `arkade <-> arkade`: the offer covenant, whole in `binding` or `offerHex`, so no tree params. */
2139
2467
  interface OfferSwapRecord extends SwapRecordCommon {
2140
2468
  readonly family: "offer";
2141
2469
  /** v1's raw status vocabulary, read verbatim by the drive's `RawState`. */
2142
2470
  readonly status: AssetSwapStatus;
2143
- /** The TLV offer, hex. The only input `cancelOffer` needs. */
2144
- readonly offerHex: string;
2471
+ /** The TLV offer, hex: what rebuilds the covenant when there is no `binding`. */
2472
+ readonly offerHex?: string;
2473
+ /** The covenant, structured. A directed swap carries this and no `offerHex`. */
2474
+ readonly binding?: RecordedOfferBinding;
2145
2475
  readonly swapAddress: string;
2146
2476
  /** The covenant's scriptPubKey, hex — the indexer's monitoring key and the reconcile's match key. */
2147
2477
  readonly swapPkScript: string;
2148
2478
  /** Sats riding an asset deposit, decimal: the solver's published carrier, which the fill is
2149
2479
  * priced against. Absent for a BTC deposit and for feed-priced swaps (the SDK default). */
2150
2480
  readonly carrierSats?: string;
2481
+ /** `false`: the funding carries no offer packet. Absent attaches it. */
2482
+ readonly attachOfferPacket?: false;
2151
2483
  readonly spentTxid?: string;
2152
2484
  readonly completedAt?: number;
2153
2485
  }
@@ -2377,4 +2709,4 @@ declare class InMemoryAssetSwapRepository implements AssetSwapRepository {
2377
2709
  [Symbol.asyncDispose](): Promise<void>;
2378
2710
  }
2379
2711
 
2380
- export { type DisplayDecimal as $, type AssetId as A, type AssetPaymentInput as B, type Corridor as C, type AssetPaymentTerms as D, type AssetRef as E, type AssetScale as F, type AssetSwapId as G, type AtomicDecimal as H, type Instrument as I, type AuctionMarketRef as J, type AuctionProvenance as K, type LockupSpendIndexer as L, BITCOIN_RAILS as M, type NetworkRef as N, type OfferSwapRecord as O, type PinnedAmount as P, type QuoteId as Q, type Rail as R, type SwapRecord as S, BTC_ASSET_PART as T, type BitcoinRail as U, CORRIDORS as V, CORRIDOR_PASS as W, type CardMarketRef as X, type CorridorId as Y, type CorridorKind as Z, type DepositArtifact as _, type RfqSwapRecordStore as a, recordArtifact as a$, type Endpoint as a0, type Ep as a1, type Hex as a2, LOCKUP_OWNER as a3, type MarketBackend as a4, type MarketRef as a5, OFFER_SWAP_ID_PREFIX as a6, type Outcome as a7, type ParsedAssetId as a8, type Quote as a9, bitcoinNetworkOf as aA, btcAssetPart as aB, btcOn as aC, corridorOfRail as aD, corridorOutcome as aE, decodeRfqAmount as aF, encodeRfqAmount as aG, familyOfSwapId as aH, formatAssetId as aI, fromAtomicDecimal as aJ, fromRfqAmountSide as aK, fundingWasNotSubmitted as aL, fundsFromWallet as aM, instrumentOf as aN, isAssetId as aO, isAtomicDecimal as aP, isBtcAsset as aQ, isBtcAssetLenient as aR, isNetworkRef as aS, issuanceOf as aT, legOf as aU, offerOutcome as aV, parseAssetId as aW, quoteIdOfSwapId as aX, railOf as aY, railOfCorridor as aZ, readsChain as a_, type QuoteLeg as aa, RAILS as ab, RFQ_SWAP_ID_PREFIX as ac, type RailOf as ad, type RankedBid as ae, type RawState as af, type ReceiverPaidCarrierQuote as ag, type RecordedArtifact as ah, type RecordedAssetPayment as ai, type RecordedEndpoint as aj, type RecordedInstrument as ak, type RecordedLeg as al, type RestoredMarketRef as am, type RfqAmountSide as an, type SnapshotRef as ao, type Swap as ap, type SwapFamily as aq, type SwapRecordCommon as ar, type SwapUpdate as as, type TaxiIdentity as at, type Unsubscribe as au, type VerifiedCarrierTerms as av, arkadeAsset as aw, artifactOf as ax, assetPartOf as ay, assetSwapIdOf as az, type CorridorSwapRecord as b, readLockupFate as b$, recordEndpoint as b0, recordInstrument as b1, recordLeg as b2, recordOutcome as b3, sameAsset as b4, swapOf as b5, toAtomicDecimal as b6, toRfqAmountSide as b7, toSafeNumber as b8, type MarketsCacheEntry as b9, type PreimageBlockedReason as bA, PreimageNotRecoverableError as bB, REFUND_MTP_LAG_SECONDS as bC, RFQ_SWAP_RETENTION_SECONDS as bD, type ReceiveLockupSwap as bE, type RfqRestoreFailure as bF, type RfqRestoreOptions as bG, type RfqRestoreResult as bH, type RfqSwapLockup as bI, RfqSwapManager as bJ, type RfqSwapManagerConfig as bK, type RfqSwapManagerDeps as bL, type RfqSwapManagerEvents as bM, type RfqSwapOrigin as bN, RfqSwapOriginRequired as bO, type RfqSwapOutcome as bP, addAssetSwap as bQ, awaitRfqResolution as bR, createRfqSwapRecord as bS, findLockupVtxos as bT, getAssetSwaps as bU, isRfqTerminal as bV, nextOnchainAction as bW, nextOnchainReceiveAction as bX, normalizeRfqSwapRecord as bY, preimageForSwapRecord as bZ, pushRefundWithoutReceiver as b_, InMemoryAssetSwapRepository as ba, type RfqSwapState as bb, type SwapContractRegistry as bc, type SwapOperator as bd, isRfqSwapTerminal as be, type RfqSwapManagerCallbacks as bf, type RfqSwapActionName as bg, type SwapSecretsProjection as bh, type LockupContractSource as bi, type RfqSwap as bj, type ArkadeRefundResult as bk, type LockupVtxo as bl, type AvailableRfqSwapManagerCallbacks as bm, BTC_ASSET_ID as bn, type LightningReceiveSwap as bo, type LightningSendSwap as bp, type LockupFate as bq, LockupNeedsRecoveryError as br, type LockupParams as bs, type LockupSpend as bt, type OnchainReceiveAction as bu, OnchainReceiveNeedsChainSource as bv, type OnchainReceiveSwap as bw, type OnchainSendAction as bx, type OnchainSendSwap as by, type PersistableRfqSwap as bz, type AssetSwapStatus as c, rebuildRfqSwap as c0, rfqSwapOriginOf as c1, shouldRetainRfqSwap as c2, swapSecretsToRecord as c3, updateAssetSwap as c4, updateRfqSwapRecord as c5, type AssetSwapRepository as d, type RfqSwapRecord as e, type RfqSwapPageFilter as f, type RfqSwapPageCursor as g, type AssetSwap as h, type RouteResolution as i, type ResolvedEndpoint as j, type Route as k, type QuoteInput as l, type Pubkey as m, ACTIVITY_TOKEN as n, ARKADE_ASSET_NAMESPACE as o, Amount as p, AmountFormatError as q, type AmountOn as r, type AmountRefusal as s, type ArkadeCarrierChoice as t, type Artifact as u, AssetIdError as v, type AssetIdRefusal as w, type AssetNamespace as x, type AssetOn as y, type AssetPart as z };
2712
+ export { type Endpoint as $, type AssetId as A, type AssetPaymentTerms as B, type Corridor as C, type AssetRef as D, type AssetScale as E, type AssetSwapId as F, type AtomicDecimal as G, type AuctionMarketRef as H, type Instrument as I, type AuctionProvenance as J, BITCOIN_RAILS as K, type LockupSpendIndexer as L, BTC_ASSET_PART as M, type NetworkRef as N, type OfferSwapRecord as O, type PinnedAmount as P, type QuoteId as Q, type Rail as R, type SwapRecord as S, type BitcoinRail as T, CORRIDORS as U, CORRIDOR_PASS as V, type CardMarketRef as W, type CorridorId as X, type CorridorKind as Y, type DepositArtifact as Z, type DisplayDecimal as _, type RfqSwapRecordStore as a, recordInstrument as a$, type Ep as a0, LOCKUP_OWNER as a1, type MarketBackend as a2, type MarketRef as a3, OFFER_SWAP_ID_PREFIX as a4, type Outcome as a5, type ParsedAssetId as a6, type Quote as a7, type QuoteLeg as a8, RAILS as a9, btcOn as aA, corridorOfRail as aB, corridorOutcome as aC, decodeRfqAmount as aD, encodeRfqAmount as aE, familyOfSwapId as aF, formatAssetId as aG, fromAtomicDecimal as aH, fromRfqAmountSide as aI, fundingWasNotSubmitted as aJ, fundsFromWallet as aK, instrumentOf as aL, isAssetId as aM, isAtomicDecimal as aN, isBtcAsset as aO, isBtcAssetLenient as aP, isNetworkRef as aQ, issuanceOf as aR, legOf as aS, offerOutcome as aT, parseAssetId as aU, quoteIdOfSwapId as aV, railOf as aW, railOfCorridor as aX, readsChain as aY, recordArtifact as aZ, recordEndpoint as a_, RFQ_SWAP_ID_PREFIX as aa, type RailOf as ab, type RankedBid as ac, type RawState as ad, type ReceiverPaidCarrierQuote as ae, type RecordedArtifact as af, type RecordedAssetPayment as ag, type RecordedEndpoint as ah, type RecordedInstrument as ai, type RecordedLeg as aj, type RestoredMarketRef as ak, type RfqAmountSide as al, type SnapshotRef as am, type Swap as an, type SwapFamily as ao, type SwapRecordCommon as ap, type SwapUpdate as aq, type TaxiIdentity as ar, type Unsubscribe as as, type VerifiedCarrierTerms as at, arkadeAsset as au, artifactOf as av, assetPartOf as aw, assetSwapIdOf as ax, bitcoinNetworkOf as ay, btcAssetPart as az, type CorridorSwapRecord as b, addAssetSwap as b$, recordLeg as b0, recordOutcome as b1, sameAsset as b2, swapOf as b3, toAtomicDecimal as b4, toRfqAmountSide as b5, toSafeNumber as b6, type MarketsCacheEntry as b7, InMemoryAssetSwapRepository as b8, type RfqSwapState as b9, type LockupParams as bA, type LockupSpend as bB, NoSpendableDepositError as bC, OFFER_PACKET_TYPE as bD, OfferCovenantMismatchError as bE, type OnchainReceiveAction as bF, OnchainReceiveNeedsChainSource as bG, type OnchainReceiveSwap as bH, type OnchainSendAction as bI, type OnchainSendSwap as bJ, type PersistableRfqSwap as bK, type PreimageBlockedReason as bL, PreimageNotRecoverableError as bM, REFUND_MTP_LAG_SECONDS as bN, RFQ_SWAP_RETENTION_SECONDS as bO, type ReceiveLockupSwap as bP, type RfqRestoreFailure as bQ, type RfqRestoreOptions as bR, type RfqRestoreResult as bS, type RfqSwapLockup as bT, RfqSwapManager as bU, type RfqSwapManagerConfig as bV, type RfqSwapManagerDeps as bW, type RfqSwapManagerEvents as bX, type RfqSwapOrigin as bY, RfqSwapOriginRequired as bZ, type RfqSwapOutcome as b_, type SwapContractRegistry as ba, type SwapOperator as bb, isRfqSwapTerminal as bc, type RfqSwapManagerCallbacks as bd, type RfqSwapActionName as be, type DerivedOffer as bf, type FillFunding as bg, type FillOutpoint as bh, type FillInputOwner as bi, type OfferBinding as bj, type SwapSecretsProjection as bk, type Offer as bl, type LockupContractSource as bm, type RfqSwap as bn, type ArkadeRefundResult as bo, type LockupVtxo as bp, ASSET_CARRIER_SATS as bq, ASSET_SWAP_CONTRACT_VERSIONS as br, ASSET_SWAP_DERIVABLE_VERSIONS as bs, type AssetSwapContractVersion as bt, type AvailableRfqSwapManagerCallbacks as bu, BTC_ASSET_ID as bv, type LightningReceiveSwap as bw, type LightningSendSwap as bx, type LockupFate as by, LockupNeedsRecoveryError as bz, type AssetSwapStatus as c, assetSwapContractVersion as c0, awaitRfqResolution as c1, bindingFromOffer as c2, bindingProgram as c3, cancelOffer as c4, createOffer as c5, createRfqSwapRecord as c6, decodeOffer as c7, encodeOffer as c8, fillOffer as c9, findLockupVtxos as ca, getAssetSwaps as cb, isRfqTerminal as cc, nextOnchainAction as cd, nextOnchainReceiveAction as ce, normalizeRfqSwapRecord as cf, offerContract as cg, offerFromBinding as ch, offerVtxoScript as ci, preimageForSwapRecord as cj, pushRefundWithoutReceiver as ck, readLockupFate as cl, rebuildRfqSwap as cm, rfqSwapOriginOf as cn, shouldRetainRfqSwap as co, swapPrograms as cp, swapSecretsToRecord as cq, updateAssetSwap as cr, updateRfqSwapRecord as cs, type RecordedOfferBinding as ct, type CoverageRegistrationOptions as cu, type AssetSwapRepository as d, type RfqSwapRecord as e, type RfqSwapPageFilter as f, type RfqSwapPageCursor as g, type AssetSwap as h, type RouteResolution as i, type ResolvedEndpoint as j, type Route as k, type QuoteInput as l, ACTIVITY_TOKEN as m, ARKADE_ASSET_NAMESPACE as n, Amount as o, AmountFormatError as p, type AmountOn as q, type AmountRefusal as r, type ArkadeCarrierChoice as s, type Artifact as t, AssetIdError as u, type AssetIdRefusal as v, type AssetNamespace as w, type AssetOn as x, type AssetPart as y, type AssetPaymentInput as z };