@arkade-os/swap 0.1.0-rc.2 → 0.1.0-rc.21

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 (54) hide show
  1. package/README.md +52 -2
  2. package/dist/advanced.cjs +8376 -0
  3. package/dist/advanced.d.cts +550 -0
  4. package/dist/advanced.d.ts +550 -0
  5. package/dist/advanced.js +451 -0
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-HUQQVBC4.js +4262 -0
  8. package/dist/{chunk-EOYGUCDM.js → chunk-ITFCQWPG.js} +755 -1382
  9. package/dist/chunk-PVB7EBAM.js +2517 -0
  10. package/dist/errors-C3h8ANmE.d.ts +1560 -0
  11. package/dist/errors-hm7aqnRM.d.cts +1560 -0
  12. package/dist/index.cjs +4861 -3988
  13. package/dist/index.d.cts +69 -2812
  14. package/dist/index.d.ts +69 -2812
  15. package/dist/index.js +179 -3719
  16. package/dist/lockupContract-5r5RlgOJ.d.cts +137 -0
  17. package/dist/lockupContract-5r5RlgOJ.d.ts +137 -0
  18. package/dist/node/index.cjs +61 -10
  19. package/dist/node/index.d.cts +249 -591
  20. package/dist/node/index.d.ts +249 -591
  21. package/dist/node/index.js +65 -10
  22. package/dist/nostr.cjs +191 -11
  23. package/dist/nostr.d.cts +23 -68
  24. package/dist/nostr.d.ts +23 -68
  25. package/dist/nostr.js +3 -4
  26. package/dist/offer-Bd9Yvd8Z.d.ts +261 -0
  27. package/dist/offer-F88rtL_I.d.cts +261 -0
  28. package/dist/protocol.cjs +4086 -3706
  29. package/dist/protocol.d.cts +163 -768
  30. package/dist/protocol.d.ts +163 -768
  31. package/dist/protocol.js +190 -173
  32. package/dist/repositories/realm/index.cjs +55 -11
  33. package/dist/repositories/realm/index.d.cts +18 -30
  34. package/dist/repositories/realm/index.d.ts +18 -30
  35. package/dist/repositories/realm/index.js +49 -12
  36. package/dist/repositories/sqlite/index.cjs +61 -10
  37. package/dist/repositories/sqlite/index.d.cts +7 -6
  38. package/dist/repositories/sqlite/index.d.ts +7 -6
  39. package/dist/repositories/sqlite/index.js +57 -11
  40. package/dist/repository-BuYWGAKz.d.cts +2261 -0
  41. package/dist/repository-DYnRLPt-.d.ts +2261 -0
  42. package/dist/rfq-60PGpQ_x.d.cts +950 -0
  43. package/dist/rfq-60PGpQ_x.d.ts +950 -0
  44. package/dist/watch-BTyiBLSd.d.ts +74 -0
  45. package/dist/watch-M_KY-5ho.d.cts +74 -0
  46. package/package.json +20 -10
  47. package/dist/chunk-LYCMM3VB.js +0 -1357
  48. package/dist/chunk-U7VWWTL6.js +0 -66
  49. package/dist/repository-_zU9_pM3.d.cts +0 -3426
  50. package/dist/repository-kO95noyv.d.ts +0 -3426
  51. package/dist/rfq-DdBV4JO5.d.cts +0 -1097
  52. package/dist/rfq-DdBV4JO5.d.ts +0 -1097
  53. package/dist/watch-CQqvwgwY.d.cts +0 -96
  54. package/dist/watch-wMbmfN4p.d.ts +0 -96
@@ -0,0 +1,261 @@
1
+ import { asset, RelativeTimelock, ArkadeInfo, ArkTxInput, IWallet, EmulatorProvider, arkade } from '@arkade-os/sdk';
2
+ import { d as AssetSwapRepository } from './repository-DYnRLPt-.js';
3
+
4
+ /**
5
+ * The contracts, one per WANT side — pure data, shared verbatim with any other implementation.
6
+ *
7
+ * An offer carrying an exit delay compiles a third closure that is in neither file (see
8
+ * {@link withExitClosure}); the golden in `offer.test.ts` pins the artifact it produces.
9
+ *
10
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
11
+ */
12
+ declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
13
+ /** A full-fill offer. Exactly one field names an asset: `wantAsset` = the fill must deliver that
14
+ * asset (the deposit is whatever the funding vtxo holds); `offerAsset` = the user deposits that
15
+ * asset and wants sats.
16
+ *
17
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
18
+ */
19
+ interface Offer {
20
+ /** The scriptPubKey of the swap contract. */
21
+ swapPkScript: Uint8Array;
22
+ /** Amount the user wants (asset units, or sats when wanting BTC). */
23
+ wantAmount: bigint;
24
+ /** The asset the user wants. Omitted when wanting BTC. */
25
+ wantAsset?: asset.AssetId;
26
+ /** The asset the user deposits. Omitted when depositing BTC. */
27
+ offerAsset?: asset.AssetId;
28
+ /** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
29
+ makerPkScript: Uint8Array;
30
+ /** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
31
+ makerPublicKey: Uint8Array;
32
+ /** Covenant co-signer (emulator) x-only key (32 bytes). */
33
+ emulatorPubkey: Uint8Array;
34
+ /** Partial-fill numerator. Reserved wire space in V1: carried through the
35
+ * codec so an offer that sets it decodes, never interpreted here. */
36
+ ratioNum?: bigint;
37
+ /** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
38
+ ratioDen?: bigint;
39
+ /** The maker's unilateral exit path. Present adds a third closure to the
40
+ * taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
41
+ exitDelay?: RelativeTimelock;
42
+ }
43
+ /** Compile the offer's contract: program + args -> taproot tree.
44
+ *
45
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
46
+ */
47
+ declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array): InstanceType<typeof arkade.ArkadeProgramScript>;
48
+ /** Extension packet type tag for Arkade Intents offers.
49
+ *
50
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
51
+ */
52
+ declare const OFFER_PACKET_TYPE = 3;
53
+ /** Serialize an offer to TLV bytes (the packet payload).
54
+ *
55
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
56
+ */
57
+ declare function encodeOffer(offer: Offer): Uint8Array;
58
+ /** Parse TLV bytes into an offer. Throws on malformed or unknown records.
59
+ *
60
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
61
+ */
62
+ declare function decodeOffer(data: Uint8Array): Offer;
63
+ /**
64
+ * Build a new offer for `wallet` (the user). Fund `address` with the side
65
+ * you deposit, embedding the returned extension, and the solver does the rest:
66
+ *
67
+ * // BTC -> asset
68
+ * const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
69
+ * await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
70
+ *
71
+ * // asset -> BTC (the sats are the VTXO carrier for the asset)
72
+ * const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
73
+ * await wallet.send({ address: o.address, amount: 500,
74
+ * assets: [{ assetId, amount: 1000n }],
75
+ * extensions: [o.extension] })
76
+ *
77
+ * Broadcasts nothing, but registers the covenant before returning the address: a failure now is
78
+ * retryable, whereas after `wallet.send` it would leave a funded deposit unwatched. The unilateral
79
+ * exit closure is built by default (server's `unilateralExitDelay`, as solverd does); without it only
80
+ * the server-co-signed `cancel` gets the deposit out, and an offer never expires.
81
+ *
82
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
83
+ */
84
+ declare function createOffer(wallet: IWallet, params: OfferParams): Promise<{
85
+ /** The encoded offer, hex. **Persist this** — it is the only input `cancelOffer` needs to
86
+ * rebuild the covenant. */
87
+ offerHex: string;
88
+ /** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
89
+ extension: {
90
+ type: number;
91
+ payload: Uint8Array;
92
+ };
93
+ /** The swap address to fund. Identical offers derive an identical address, so the funding
94
+ * txid — not the address — identifies one deposit. */
95
+ address: string;
96
+ /** The covenant's scriptPubKey: the key an indexer watches to spot the
97
+ * deposit and its later spend (`AssetSwap.swapPkScript`). */
98
+ swapPkScript: Uint8Array;
99
+ }>;
100
+ interface OfferParams {
101
+ wantAmount: bigint;
102
+ wantAsset?: asset.AssetId;
103
+ offerAsset?: asset.AssetId;
104
+ /** Co-signer key override (33-byte compressed hex); see
105
+ * {@link resolveEmulatorPubkey}. */
106
+ emulatorPubkey?: string;
107
+ /** Override the exit closure's delay. Defaults to the server's own
108
+ * `unilateralExitDelay`, which is the delay solverd uses too. */
109
+ exitDelay?: RelativeTimelock;
110
+ /** Publish without the exit closure, leaving `cancel` — which needs the
111
+ * server — as the only way back out. See the note on {@link createOffer}. */
112
+ noExit?: boolean;
113
+ /**
114
+ * A live `getArkadeInfo` the caller already made.
115
+ *
116
+ * Passing it is what lets one live read bind both the derivation and the
117
+ * registration that follows it; omitting it makes the read here. It must be
118
+ * live for the reason {@link createOffer} reads live — the info's
119
+ * `signerPubkey` ends up in a covenant leaf.
120
+ */
121
+ info?: ArkadeInfo;
122
+ /**
123
+ * The maker position, when the caller already read it.
124
+ *
125
+ * The RFQ path reads it BEFORE it sends the request — the profile commits
126
+ * to this script and this key — so re-reading it here would let an address
127
+ * rotation between the two reads derive a covenant the solver never quoted.
128
+ */
129
+ maker?: {
130
+ pkScript: Uint8Array;
131
+ publicKey: Uint8Array;
132
+ };
133
+ }
134
+ /**
135
+ * Everything an offer commits to, derived and encoded, with nothing written.
136
+ *
137
+ * The split exists because `quote()` must derive the covenant it verifies the
138
+ * solver's `offer_address` against while persisting and registering nothing,
139
+ * and `accept()` must register **that** derivation rather than a second one
140
+ * built from the same terms. So the tree's own parameters travel on this value:
141
+ * two derivations that can disagree is the failure the hand-off deletes.
142
+ */
143
+ interface DerivedOffer {
144
+ readonly offerHex: string;
145
+ readonly extension: {
146
+ readonly type: number;
147
+ readonly payload: Uint8Array;
148
+ };
149
+ readonly address: string;
150
+ readonly swapPkScript: Uint8Array;
151
+ /** The covenant's parameters — {@link registerDerivedOffer}'s only input. */
152
+ readonly binding: Readonly<Omit<Offer, "swapPkScript">>;
153
+ /** The live info this covenant is bound to. */
154
+ readonly info: ArkadeInfo;
155
+ readonly operatorPubkey: Uint8Array;
156
+ }
157
+ /**
158
+ * Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid. No path is on a
159
+ * deadline, so an unfilled deposit stays at the swap address until the user cancels.
160
+ *
161
+ * Routes out: `fulfill` (server alone, but constrained to pay `makerWP` at least `wantAmount`),
162
+ * `cancel` (user+server 2-of-2, no solver involved), `exit` (user alone after a CSV unless `noExit`;
163
+ * reached by unrolling onchain, not here).
164
+ *
165
+ * Cancel races a fill: if `fulfill` spent first this throws "no spendable VTXO at the swap address",
166
+ * which means the swap completed (`classifySpend` tells the spends apart by leaf). The escrow marker
167
+ * gates implicit coin selection only; cancel names its input explicitly.
168
+ *
169
+ * `fundingTxid` selects the deposit (identical offers share an address); without it the address must
170
+ * hold exactly one. `swapAddress` pins the funding-time operator key across a signer rotation. When
171
+ * `repository` holds the record, this writes `cancelling` (crash marker) then `cancelled`, so the
172
+ * watcher has nothing to decide for our own cancels; otherwise the watcher/restore scan classifies.
173
+ *
174
+ * @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
175
+ */
176
+ declare function cancelOffer(wallet: IWallet, offerHex: string, opts: {
177
+ repository: AssetSwapRepository;
178
+ fundingTxid?: string;
179
+ swapAddress?: string;
180
+ }): Promise<string>;
181
+ /**
182
+ * No deposit left to cancel at the swap address — almost always the fill winning the race. Typed so
183
+ * the v2 client's `cancel()` reconciles by `instanceof` (see `client/cancel.ts`); message is v1's.
184
+ *
185
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
186
+ */
187
+ declare class NoSpendableDepositError extends Error {
188
+ readonly name = "NoSpendableDepositError";
189
+ constructor(options?: ErrorOptions);
190
+ }
191
+ /**
192
+ * The rebuilt covenant disagrees with the offer's `swapPkScript`: the pinned operator key is not the
193
+ * one the covenant was funded with (rotated signer, a wrong `swapAddress`, or a corrupt record).
194
+ * Fires before any broadcast.
195
+ *
196
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
197
+ */
198
+ declare class OfferCovenantMismatchError extends Error {
199
+ readonly swapPkScript: string;
200
+ readonly name = "OfferCovenantMismatchError";
201
+ constructor(swapPkScript: string, options?: ErrorOptions);
202
+ }
203
+ /** Sats carried by output 0 when the maker is paid in an ASSET: the covenant checks the asset, and
204
+ * the output still needs its own carrier. Overridable per fill via `assetCarrierSats`.
205
+ *
206
+ * @deprecated Read it from `@arkade-os/sdk`, which owns the constant. Moved off the package root to `@arkade-os/swap/protocol`.
207
+ */
208
+ declare const ASSET_CARRIER_SATS: bigint;
209
+ /**
210
+ * A coin the taker supplies, plus the assets it carries. `ArkTxInput` is sats-only, and **arkd
211
+ * refuses a spend whose asset packet omits an asset one of its inputs owns** (`ASSET_NOT_FOUND`), so
212
+ * every asset on a funding coin must be declared. A wallet's own coins already carry this shape.
213
+ *
214
+ * @deprecated Taken by `fillOffer`, which itself has no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
215
+ */
216
+ type FillFunding = ArkTxInput & {
217
+ assets?: readonly {
218
+ assetId: string;
219
+ amount: bigint | number;
220
+ }[];
221
+ };
222
+ /**
223
+ * Fill an offer — the TAKER's side, and the counterpart to {@link createOffer}. Composes the
224
+ * `fulfill` spend; it does not weaken or reinterpret the covenant.
225
+ *
226
+ * For an ASSET want the covenant reads output 0 through `OP_INSPECTOUTASSETLOOKUP` with
227
+ * `lookup_index = 0`, so the wanted asset must be the FIRST group in the packet (groups keep insertion
228
+ * order) and output 0 carries only a dust carrier ({@link ASSET_CARRIER_SATS}). Every other asset in
229
+ * the spend goes to the taker's payout; see {@link FillFunding}.
230
+ *
231
+ * Writes NO local swap record: the maker learns the outcome from the chain (RFQ protocol § 7.2).
232
+ * `fund` is explicit because only the caller knows which coins are reserved (e.g. a corridor's
233
+ * float). Racing a cancel is NORMAL: "no spendable VTXO at the swap address" means the offer is gone.
234
+ *
235
+ * @deprecated The v2 client has no taker-side fill, so there is no replacement:
236
+ * `accept()` funds a covenant of your own; it does not spend someone else's
237
+ * offer through its `fulfill` leaf. Moved off the package root to `@arkade-os/swap/protocol`.
238
+ */
239
+ declare function fillOffer(wallet: IWallet, arkServerUrl: string, offerHex: string, opts: {
240
+ /** Coins the taker supplies to pay `wantAmount`, with any assets they
241
+ * carry. Become inputs 1..n. @see FillFunding */
242
+ fund: FillFunding[];
243
+ /** Where the taker's proceeds land. Defaults to the wallet's own address. */
244
+ payoutScript?: Uint8Array;
245
+ /** Selects the deposit when the swap address holds more than one. */
246
+ fundingTxid?: string;
247
+ /** The funded address, to pin the server key the covenant was built with. */
248
+ swapAddress?: string;
249
+ /** Sats at output 0 on an asset want. Defaults to {@link ASSET_CARRIER_SATS};
250
+ * raise it for a server whose dust threshold is higher. */
251
+ assetCarrierSats?: bigint;
252
+ /** The co-signing service — a base URL, or a provider of your own. Required: the emulator
253
+ * executes the `fulfill` covenant script, and without one the spend is refused at submit. */
254
+ emulator: EmulatorProvider | string;
255
+ /** Co-signer key override (33-byte compressed hex), as `createOffer`
256
+ * takes. Needed on a network the SDK pins no emulator key for, where
257
+ * connecting with an emulator otherwise throws. */
258
+ emulatorPubkey?: string;
259
+ }): Promise<string>;
260
+
261
+ export { ASSET_CARRIER_SATS as A, type DerivedOffer as D, type FillFunding as F, NoSpendableDepositError as N, type Offer as O, OFFER_PACKET_TYPE as a, OfferCovenantMismatchError as b, cancelOffer as c, createOffer as d, decodeOffer as e, encodeOffer as f, fillOffer as g, offerContract as o, swapPrograms as s };
@@ -0,0 +1,261 @@
1
+ import { asset, RelativeTimelock, ArkadeInfo, ArkTxInput, IWallet, EmulatorProvider, arkade } from '@arkade-os/sdk';
2
+ import { d as AssetSwapRepository } from './repository-BuYWGAKz.cjs';
3
+
4
+ /**
5
+ * The contracts, one per WANT side — pure data, shared verbatim with any other implementation.
6
+ *
7
+ * An offer carrying an exit delay compiles a third closure that is in neither file (see
8
+ * {@link withExitClosure}); the golden in `offer.test.ts` pins the artifact it produces.
9
+ *
10
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
11
+ */
12
+ declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
13
+ /** A full-fill offer. Exactly one field names an asset: `wantAsset` = the fill must deliver that
14
+ * asset (the deposit is whatever the funding vtxo holds); `offerAsset` = the user deposits that
15
+ * asset and wants sats.
16
+ *
17
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
18
+ */
19
+ interface Offer {
20
+ /** The scriptPubKey of the swap contract. */
21
+ swapPkScript: Uint8Array;
22
+ /** Amount the user wants (asset units, or sats when wanting BTC). */
23
+ wantAmount: bigint;
24
+ /** The asset the user wants. Omitted when wanting BTC. */
25
+ wantAsset?: asset.AssetId;
26
+ /** The asset the user deposits. Omitted when depositing BTC. */
27
+ offerAsset?: asset.AssetId;
28
+ /** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
29
+ makerPkScript: Uint8Array;
30
+ /** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
31
+ makerPublicKey: Uint8Array;
32
+ /** Covenant co-signer (emulator) x-only key (32 bytes). */
33
+ emulatorPubkey: Uint8Array;
34
+ /** Partial-fill numerator. Reserved wire space in V1: carried through the
35
+ * codec so an offer that sets it decodes, never interpreted here. */
36
+ ratioNum?: bigint;
37
+ /** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
38
+ ratioDen?: bigint;
39
+ /** The maker's unilateral exit path. Present adds a third closure to the
40
+ * taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
41
+ exitDelay?: RelativeTimelock;
42
+ }
43
+ /** Compile the offer's contract: program + args -> taproot tree.
44
+ *
45
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
46
+ */
47
+ declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array): InstanceType<typeof arkade.ArkadeProgramScript>;
48
+ /** Extension packet type tag for Arkade Intents offers.
49
+ *
50
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
51
+ */
52
+ declare const OFFER_PACKET_TYPE = 3;
53
+ /** Serialize an offer to TLV bytes (the packet payload).
54
+ *
55
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
56
+ */
57
+ declare function encodeOffer(offer: Offer): Uint8Array;
58
+ /** Parse TLV bytes into an offer. Throws on malformed or unknown records.
59
+ *
60
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
61
+ */
62
+ declare function decodeOffer(data: Uint8Array): Offer;
63
+ /**
64
+ * Build a new offer for `wallet` (the user). Fund `address` with the side
65
+ * you deposit, embedding the returned extension, and the solver does the rest:
66
+ *
67
+ * // BTC -> asset
68
+ * const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
69
+ * await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
70
+ *
71
+ * // asset -> BTC (the sats are the VTXO carrier for the asset)
72
+ * const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
73
+ * await wallet.send({ address: o.address, amount: 500,
74
+ * assets: [{ assetId, amount: 1000n }],
75
+ * extensions: [o.extension] })
76
+ *
77
+ * Broadcasts nothing, but registers the covenant before returning the address: a failure now is
78
+ * retryable, whereas after `wallet.send` it would leave a funded deposit unwatched. The unilateral
79
+ * exit closure is built by default (server's `unilateralExitDelay`, as solverd does); without it only
80
+ * the server-co-signed `cancel` gets the deposit out, and an offer never expires.
81
+ *
82
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
83
+ */
84
+ declare function createOffer(wallet: IWallet, params: OfferParams): Promise<{
85
+ /** The encoded offer, hex. **Persist this** — it is the only input `cancelOffer` needs to
86
+ * rebuild the covenant. */
87
+ offerHex: string;
88
+ /** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
89
+ extension: {
90
+ type: number;
91
+ payload: Uint8Array;
92
+ };
93
+ /** The swap address to fund. Identical offers derive an identical address, so the funding
94
+ * txid — not the address — identifies one deposit. */
95
+ address: string;
96
+ /** The covenant's scriptPubKey: the key an indexer watches to spot the
97
+ * deposit and its later spend (`AssetSwap.swapPkScript`). */
98
+ swapPkScript: Uint8Array;
99
+ }>;
100
+ interface OfferParams {
101
+ wantAmount: bigint;
102
+ wantAsset?: asset.AssetId;
103
+ offerAsset?: asset.AssetId;
104
+ /** Co-signer key override (33-byte compressed hex); see
105
+ * {@link resolveEmulatorPubkey}. */
106
+ emulatorPubkey?: string;
107
+ /** Override the exit closure's delay. Defaults to the server's own
108
+ * `unilateralExitDelay`, which is the delay solverd uses too. */
109
+ exitDelay?: RelativeTimelock;
110
+ /** Publish without the exit closure, leaving `cancel` — which needs the
111
+ * server — as the only way back out. See the note on {@link createOffer}. */
112
+ noExit?: boolean;
113
+ /**
114
+ * A live `getArkadeInfo` the caller already made.
115
+ *
116
+ * Passing it is what lets one live read bind both the derivation and the
117
+ * registration that follows it; omitting it makes the read here. It must be
118
+ * live for the reason {@link createOffer} reads live — the info's
119
+ * `signerPubkey` ends up in a covenant leaf.
120
+ */
121
+ info?: ArkadeInfo;
122
+ /**
123
+ * The maker position, when the caller already read it.
124
+ *
125
+ * The RFQ path reads it BEFORE it sends the request — the profile commits
126
+ * to this script and this key — so re-reading it here would let an address
127
+ * rotation between the two reads derive a covenant the solver never quoted.
128
+ */
129
+ maker?: {
130
+ pkScript: Uint8Array;
131
+ publicKey: Uint8Array;
132
+ };
133
+ }
134
+ /**
135
+ * Everything an offer commits to, derived and encoded, with nothing written.
136
+ *
137
+ * The split exists because `quote()` must derive the covenant it verifies the
138
+ * solver's `offer_address` against while persisting and registering nothing,
139
+ * and `accept()` must register **that** derivation rather than a second one
140
+ * built from the same terms. So the tree's own parameters travel on this value:
141
+ * two derivations that can disagree is the failure the hand-off deletes.
142
+ */
143
+ interface DerivedOffer {
144
+ readonly offerHex: string;
145
+ readonly extension: {
146
+ readonly type: number;
147
+ readonly payload: Uint8Array;
148
+ };
149
+ readonly address: string;
150
+ readonly swapPkScript: Uint8Array;
151
+ /** The covenant's parameters — {@link registerDerivedOffer}'s only input. */
152
+ readonly binding: Readonly<Omit<Offer, "swapPkScript">>;
153
+ /** The live info this covenant is bound to. */
154
+ readonly info: ArkadeInfo;
155
+ readonly operatorPubkey: Uint8Array;
156
+ }
157
+ /**
158
+ * Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid. No path is on a
159
+ * deadline, so an unfilled deposit stays at the swap address until the user cancels.
160
+ *
161
+ * Routes out: `fulfill` (server alone, but constrained to pay `makerWP` at least `wantAmount`),
162
+ * `cancel` (user+server 2-of-2, no solver involved), `exit` (user alone after a CSV unless `noExit`;
163
+ * reached by unrolling onchain, not here).
164
+ *
165
+ * Cancel races a fill: if `fulfill` spent first this throws "no spendable VTXO at the swap address",
166
+ * which means the swap completed (`classifySpend` tells the spends apart by leaf). The escrow marker
167
+ * gates implicit coin selection only; cancel names its input explicitly.
168
+ *
169
+ * `fundingTxid` selects the deposit (identical offers share an address); without it the address must
170
+ * hold exactly one. `swapAddress` pins the funding-time operator key across a signer rotation. When
171
+ * `repository` holds the record, this writes `cancelling` (crash marker) then `cancelled`, so the
172
+ * watcher has nothing to decide for our own cancels; otherwise the watcher/restore scan classifies.
173
+ *
174
+ * @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
175
+ */
176
+ declare function cancelOffer(wallet: IWallet, offerHex: string, opts: {
177
+ repository: AssetSwapRepository;
178
+ fundingTxid?: string;
179
+ swapAddress?: string;
180
+ }): Promise<string>;
181
+ /**
182
+ * No deposit left to cancel at the swap address — almost always the fill winning the race. Typed so
183
+ * the v2 client's `cancel()` reconciles by `instanceof` (see `client/cancel.ts`); message is v1's.
184
+ *
185
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
186
+ */
187
+ declare class NoSpendableDepositError extends Error {
188
+ readonly name = "NoSpendableDepositError";
189
+ constructor(options?: ErrorOptions);
190
+ }
191
+ /**
192
+ * The rebuilt covenant disagrees with the offer's `swapPkScript`: the pinned operator key is not the
193
+ * one the covenant was funded with (rotated signer, a wrong `swapAddress`, or a corrupt record).
194
+ * Fires before any broadcast.
195
+ *
196
+ * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
197
+ */
198
+ declare class OfferCovenantMismatchError extends Error {
199
+ readonly swapPkScript: string;
200
+ readonly name = "OfferCovenantMismatchError";
201
+ constructor(swapPkScript: string, options?: ErrorOptions);
202
+ }
203
+ /** Sats carried by output 0 when the maker is paid in an ASSET: the covenant checks the asset, and
204
+ * the output still needs its own carrier. Overridable per fill via `assetCarrierSats`.
205
+ *
206
+ * @deprecated Read it from `@arkade-os/sdk`, which owns the constant. Moved off the package root to `@arkade-os/swap/protocol`.
207
+ */
208
+ declare const ASSET_CARRIER_SATS: bigint;
209
+ /**
210
+ * A coin the taker supplies, plus the assets it carries. `ArkTxInput` is sats-only, and **arkd
211
+ * refuses a spend whose asset packet omits an asset one of its inputs owns** (`ASSET_NOT_FOUND`), so
212
+ * every asset on a funding coin must be declared. A wallet's own coins already carry this shape.
213
+ *
214
+ * @deprecated Taken by `fillOffer`, which itself has no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
215
+ */
216
+ type FillFunding = ArkTxInput & {
217
+ assets?: readonly {
218
+ assetId: string;
219
+ amount: bigint | number;
220
+ }[];
221
+ };
222
+ /**
223
+ * Fill an offer — the TAKER's side, and the counterpart to {@link createOffer}. Composes the
224
+ * `fulfill` spend; it does not weaken or reinterpret the covenant.
225
+ *
226
+ * For an ASSET want the covenant reads output 0 through `OP_INSPECTOUTASSETLOOKUP` with
227
+ * `lookup_index = 0`, so the wanted asset must be the FIRST group in the packet (groups keep insertion
228
+ * order) and output 0 carries only a dust carrier ({@link ASSET_CARRIER_SATS}). Every other asset in
229
+ * the spend goes to the taker's payout; see {@link FillFunding}.
230
+ *
231
+ * Writes NO local swap record: the maker learns the outcome from the chain (RFQ protocol § 7.2).
232
+ * `fund` is explicit because only the caller knows which coins are reserved (e.g. a corridor's
233
+ * float). Racing a cancel is NORMAL: "no spendable VTXO at the swap address" means the offer is gone.
234
+ *
235
+ * @deprecated The v2 client has no taker-side fill, so there is no replacement:
236
+ * `accept()` funds a covenant of your own; it does not spend someone else's
237
+ * offer through its `fulfill` leaf. Moved off the package root to `@arkade-os/swap/protocol`.
238
+ */
239
+ declare function fillOffer(wallet: IWallet, arkServerUrl: string, offerHex: string, opts: {
240
+ /** Coins the taker supplies to pay `wantAmount`, with any assets they
241
+ * carry. Become inputs 1..n. @see FillFunding */
242
+ fund: FillFunding[];
243
+ /** Where the taker's proceeds land. Defaults to the wallet's own address. */
244
+ payoutScript?: Uint8Array;
245
+ /** Selects the deposit when the swap address holds more than one. */
246
+ fundingTxid?: string;
247
+ /** The funded address, to pin the server key the covenant was built with. */
248
+ swapAddress?: string;
249
+ /** Sats at output 0 on an asset want. Defaults to {@link ASSET_CARRIER_SATS};
250
+ * raise it for a server whose dust threshold is higher. */
251
+ assetCarrierSats?: bigint;
252
+ /** The co-signing service — a base URL, or a provider of your own. Required: the emulator
253
+ * executes the `fulfill` covenant script, and without one the spend is refused at submit. */
254
+ emulator: EmulatorProvider | string;
255
+ /** Co-signer key override (33-byte compressed hex), as `createOffer`
256
+ * takes. Needed on a network the SDK pins no emulator key for, where
257
+ * connecting with an emulator otherwise throws. */
258
+ emulatorPubkey?: string;
259
+ }): Promise<string>;
260
+
261
+ export { ASSET_CARRIER_SATS as A, type DerivedOffer as D, type FillFunding as F, NoSpendableDepositError as N, type Offer as O, OFFER_PACKET_TYPE as a, OfferCovenantMismatchError as b, cancelOffer as c, createOffer as d, decodeOffer as e, encodeOffer as f, fillOffer as g, offerContract as o, swapPrograms as s };