@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,274 +0,0 @@
1
- import { arkade, asset, RelativeTimelock, OperatorInfo, ArkTxInput, Outpoint, IWallet, EmulatorProvider } from '@arkade-os/sdk';
2
- import { ASSET_SWAP_V2, ASSET_SWAP_V3 } from './rfq-contract.js';
3
- import { d as AssetSwapRepository } from './repository-CkKK0dGO.js';
4
-
5
- /** `asset-swap` and `sats-swap`. Exit is appended later; it is not in either artifact.
6
- *
7
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
8
- */
9
- declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
10
- type AssetSwapContractVersion = typeof ASSET_SWAP_V2 | typeof ASSET_SWAP_V3;
11
- /** The versions every asset RFQ advertises by default, most preferred first. */
12
- declare const ASSET_SWAP_CONTRACT_VERSIONS: readonly ["asset-swap-v3", "asset-swap-v2"];
13
- /** Absent means {@link ASSET_SWAP_BASELINE}; an id this build cannot derive throws. */
14
- declare const assetSwapContractVersion: (id: string | undefined) => AssetSwapContractVersion;
15
-
16
- /**
17
- * Coverage: whether an offer's script is in the wallet's watched set. `createOffer` promotes; the
18
- * watcher and restore consumer retire. Identical offers share one script, so a late demotion would
19
- * unwatch an address the user was just told to fund. Guards: per-script serialization (the watch
20
- * state is a read-modify-write), and an issuance mark for created-but-unfunded offers, which have no
21
- * record yet. The mark is per process; the restore scan backstops other contexts and restarts.
22
- */
23
-
24
- interface CoverageRegistrationOptions {
25
- readonly coverageId?: string;
26
- /** Use the wallet object: a worker can return a fresh manager proxy on every call. */
27
- readonly scope?: object;
28
- }
29
-
30
- /** A full-fill offer. Exactly one field names an asset: `wantAsset` = the fill must deliver that
31
- * asset (the deposit is whatever the funding vtxo holds); `offerAsset` = the user deposits that
32
- * asset and wants sats.
33
- *
34
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
35
- */
36
- interface Offer {
37
- /** The scriptPubKey of the swap contract. */
38
- swapPkScript: Uint8Array;
39
- /** Amount the user wants (asset units, or sats when wanting BTC). */
40
- wantAmount: bigint;
41
- /** The asset the user wants. Omitted when wanting BTC. */
42
- wantAsset?: asset.AssetId;
43
- /** The asset the user deposits. Omitted when depositing BTC. */
44
- offerAsset?: asset.AssetId;
45
- /** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
46
- makerPkScript: Uint8Array;
47
- /** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
48
- makerPublicKey: Uint8Array;
49
- /** X-only key (32 bytes) of the operator's cosigner that emulates Arkade Script. */
50
- emulatorPubkey: Uint8Array;
51
- /** Partial-fill numerator. Reserved wire space in V1: carried through the
52
- * codec so an offer that sets it decodes, never interpreted here. */
53
- ratioNum?: bigint;
54
- /** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
55
- ratioDen?: bigint;
56
- /** The maker's unilateral exit path. Present adds a third closure to the
57
- * taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
58
- exitDelay?: RelativeTimelock;
59
- }
60
- /** Compile the offer's contract: program + args -> taproot tree.
61
- *
62
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
63
- */
64
- declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array, contractVersion?: AssetSwapContractVersion): InstanceType<typeof arkade.ArkadeProgramScript>;
65
- /** Extension packet type tag for Arkade Intents offers.
66
- *
67
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
68
- */
69
- declare const OFFER_PACKET_TYPE = 3;
70
- /** Serialize an offer to TLV bytes (the packet payload).
71
- *
72
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
73
- */
74
- declare function encodeOffer(offer: Offer): Uint8Array;
75
- /** Parse TLV bytes into an offer. Throws on malformed or unknown records.
76
- *
77
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
78
- */
79
- declare function decodeOffer(data: Uint8Array): Offer;
80
- /**
81
- * Build a new offer for `wallet` (the user). Fund `address` with the side
82
- * you deposit, embedding the returned extension, and the solver does the rest:
83
- *
84
- * // BTC -> asset
85
- * const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
86
- * await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
87
- *
88
- * // asset -> BTC (the sats are the VTXO carrier for the asset)
89
- * const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
90
- * await wallet.send({ address: o.address, amount: 500,
91
- * assets: [{ assetId, amount: 1000n }],
92
- * extensions: [o.extension] })
93
- *
94
- * Broadcasts nothing, but registers the covenant before returning the address: a failure now is
95
- * retryable, whereas after `wallet.send` it would leave a funded deposit unwatched. The unilateral
96
- * exit closure is built by default (operator's `unilateralExitDelay`, as solverd does); without it only
97
- * the operator-cosigned `cancel` gets the deposit out, and an offer never expires.
98
- *
99
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
100
- */
101
- declare function createOffer(wallet: IWallet, params: OfferParams, options?: CoverageRegistrationOptions): Promise<{
102
- /** The encoded offer, hex. **Persist this** — it is the only input `cancelOffer` needs to
103
- * rebuild the covenant. */
104
- offerHex: string;
105
- /** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
106
- extension: {
107
- type: number;
108
- payload: Uint8Array;
109
- };
110
- /** The swap address to fund. Identical offers derive an identical address, so the funding
111
- * txid — not the address — identifies one deposit. */
112
- address: string;
113
- /** The covenant's scriptPubKey: the key an indexer watches to spot the
114
- * deposit and its later spend (`AssetSwap.swapPkScript`). */
115
- swapPkScript: Uint8Array;
116
- }>;
117
- interface OfferParams {
118
- receiveAddress?: string;
119
- wantAmount: bigint;
120
- wantAsset?: asset.AssetId;
121
- offerAsset?: asset.AssetId;
122
- /** Co-signer key override (33-byte compressed hex); see
123
- * {@link resolveEmulatorPubkey}. */
124
- emulatorPubkey?: string;
125
- /** Override the exit closure's delay. Defaults to the operator's own
126
- * `unilateralExitDelay`, which is the delay solverd uses too. */
127
- exitDelay?: RelativeTimelock;
128
- /** Publish without the exit closure, leaving `cancel` — which needs the
129
- * operator — as the only way back out. See the note on {@link createOffer}. */
130
- noExit?: boolean;
131
- /**
132
- * A live `getArkadeInfo` the caller already made.
133
- *
134
- * Passing it is what lets one live read bind both the derivation and the
135
- * registration that follows it; omitting it makes the read here. It must be
136
- * live for the reason {@link createOffer} reads live — the info's
137
- * `signerPubkey` ends up in a covenant leaf.
138
- */
139
- info?: OperatorInfo;
140
- /**
141
- * The maker position, when the caller already read it.
142
- *
143
- * The RFQ path reads it BEFORE it sends the request — the profile commits
144
- * to this script and this key — so re-reading it here would let an address
145
- * rotation between the two reads derive a covenant the solver never quoted.
146
- */
147
- maker?: {
148
- pkScript: Uint8Array;
149
- publicKey: Uint8Array;
150
- };
151
- /** Defaults to {@link ASSET_SWAP_BASELINE}. */
152
- contractVersion?: AssetSwapContractVersion;
153
- }
154
- /**
155
- * Everything an offer commits to, derived and encoded, with nothing written.
156
- *
157
- * The split exists because `quote()` must derive the covenant it verifies the
158
- * solver's `offer_address` against while persisting and registering nothing,
159
- * and `accept()` must register **that** derivation rather than a second one
160
- * built from the same terms. So the tree's own parameters travel on this value:
161
- * two derivations that can disagree is the failure the hand-off deletes.
162
- */
163
- interface DerivedOffer {
164
- readonly offerHex: string;
165
- readonly extension: {
166
- readonly type: number;
167
- readonly payload: Uint8Array;
168
- };
169
- readonly address: string;
170
- readonly swapPkScript: Uint8Array;
171
- /** The covenant's parameters — {@link registerDerivedOffer}'s only input. */
172
- readonly binding: Readonly<Omit<Offer, "swapPkScript">>;
173
- /** The live info this covenant is bound to. */
174
- readonly info: OperatorInfo;
175
- readonly operatorPubkey: Uint8Array;
176
- }
177
- /**
178
- * Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid. No path is on a
179
- * deadline, so an unfilled deposit stays at the swap address until the user cancels.
180
- *
181
- * Routes out: `fulfill` (operator alone, but constrained to pay `makerWP` at least `wantAmount`),
182
- * `cancel` (user+operator 2-of-2, no solver involved), `exit` (user alone after a CSV unless `noExit`;
183
- * reached by unrolling onchain, not here).
184
- *
185
- * Cancel races a fill: if `fulfill` spent first this throws "no spendable VTXO at the swap address",
186
- * which means the swap completed (`classifySpend` tells the spends apart by leaf). The escrow marker
187
- * gates implicit coin selection only; cancel names its input explicitly.
188
- *
189
- * `fundingTxid` selects the deposit (identical offers share an address); without it the address must
190
- * hold exactly one. `swapAddress` pins the funding-time operator key across a signer rotation. When
191
- * `repository` holds the record, this writes `cancelling` (crash marker) then `cancelled`, so the
192
- * watcher has nothing to decide for our own cancels; otherwise the watcher/restore scan classifies.
193
- *
194
- * @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
195
- */
196
- declare function cancelOffer(wallet: IWallet, offerHex: string, opts: {
197
- repository: AssetSwapRepository;
198
- fundingTxid?: string;
199
- fundingOutpoint?: FillOutpoint;
200
- swapAddress?: string;
201
- }): Promise<string>;
202
- /**
203
- * No deposit left to cancel at the swap address — almost always the fill winning the race. Typed so
204
- * the v2 client's `cancel()` reconciles by `instanceof` (see `client/cancel.ts`); message is v1's.
205
- *
206
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
207
- */
208
- declare class NoSpendableDepositError extends Error {
209
- readonly name = "NoSpendableDepositError";
210
- constructor(options?: ErrorOptions);
211
- }
212
- /**
213
- * The rebuilt covenant disagrees with the offer's `swapPkScript`: the pinned operator key is not the
214
- * one the covenant was funded with (rotated signer, a wrong `swapAddress`, or a corrupt record).
215
- * Fires before any broadcast.
216
- *
217
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
218
- */
219
- declare class OfferCovenantMismatchError extends Error {
220
- readonly swapPkScript: string;
221
- readonly name = "OfferCovenantMismatchError";
222
- constructor(swapPkScript: string, options?: ErrorOptions);
223
- }
224
- /** Sats carried by output 0 when the maker is paid in an ASSET: the covenant checks the asset, and
225
- * the output still needs its own carrier. Overridable per fill via `assetCarrierSats`.
226
- *
227
- * @deprecated Read it from `@arkade-os/sdk`, which owns the constant. Moved off the package root to `@arkade-os/swap/protocol`.
228
- */
229
- declare const ASSET_CARRIER_SATS: bigint;
230
- /**
231
- * A coin the taker supplies, plus the assets it carries. `ArkTxInput` is sats-only, and **arkd
232
- * refuses a spend whose asset packet omits an asset one of its inputs owns** (`ASSET_NOT_FOUND`), so
233
- * every asset on a funding coin must be declared. A wallet's own coins already carry this shape.
234
- */
235
- type FillFunding = ArkTxInput & {
236
- assets?: readonly {
237
- assetId: string;
238
- amount: bigint | number;
239
- }[];
240
- };
241
- /** @deprecated Use `Outpoint` from `@arkade-os/sdk`. */
242
- type FillOutpoint = Outpoint;
243
- type FillInputOwner = "solver" | "sponsor";
244
- /**
245
- * Fill an offer — the TAKER's side, and the counterpart to {@link createOffer}. Composes the
246
- * `fulfill` spend; it does not weaken or reinterpret the covenant.
247
- *
248
- * `fulfill` reads the output at the spending input's index. This builder puts the deposit at
249
- * input 0 and the maker payout at output 0. An ASSET want is the first packet group on that
250
- * output, which carries only a dust carrier ({@link ASSET_CARRIER_SATS}). Every other asset
251
- * goes to the taker's payout; see {@link FillFunding}.
252
- *
253
- * Writes NO local swap record: the maker learns the outcome from the chain (RFQ protocol § 7.2).
254
- * `fund` is explicit because only the caller knows which coins are reserved (e.g. a corridor's
255
- * float). Racing a cancel is NORMAL: "no spendable VTXO at the swap address" means the offer is gone.
256
- *
257
- * @deprecated The v2 client has no taker-side fill, so there is no replacement:
258
- * `accept()` funds a covenant of your own; it does not spend someone else's
259
- * offer through its `fulfill` leaf. Moved off the package root to `@arkade-os/swap/protocol`.
260
- */
261
- declare function fillOffer(wallet: IWallet, arkServerUrl: string, offerHex: string, opts: {
262
- fund: FillFunding[];
263
- payoutScript?: Uint8Array;
264
- fundingTxid?: string;
265
- fundingOutpoint?: FillOutpoint;
266
- swapAddress?: string;
267
- assetCarrierSats?: bigint;
268
- emulator: EmulatorProvider | string;
269
- emulatorPubkey?: string;
270
- }): Promise<string>;
271
- /** @deprecated Use `offerContract` from `@arkade-os/swap/protocol`. */
272
- declare const offerVtxoScript: typeof offerContract;
273
-
274
- export { ASSET_CARRIER_SATS as A, type CoverageRegistrationOptions as C, type DerivedOffer as D, type FillFunding as F, NoSpendableDepositError as N, type Offer as O, type FillOutpoint as a, type FillInputOwner as b, ASSET_SWAP_CONTRACT_VERSIONS as c, type AssetSwapContractVersion as d, OFFER_PACKET_TYPE as e, OfferCovenantMismatchError as f, assetSwapContractVersion as g, cancelOffer as h, createOffer as i, decodeOffer as j, encodeOffer as k, fillOffer as l, offerVtxoScript as m, offerContract as o, swapPrograms as s };
@@ -1,274 +0,0 @@
1
- import { arkade, asset, RelativeTimelock, OperatorInfo, ArkTxInput, Outpoint, IWallet, EmulatorProvider } from '@arkade-os/sdk';
2
- import { ASSET_SWAP_V2, ASSET_SWAP_V3 } from './rfq-contract.cjs';
3
- import { d as AssetSwapRepository } from './repository--pfikw2R.cjs';
4
-
5
- /** `asset-swap` and `sats-swap`. Exit is appended later; it is not in either artifact.
6
- *
7
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
8
- */
9
- declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
10
- type AssetSwapContractVersion = typeof ASSET_SWAP_V2 | typeof ASSET_SWAP_V3;
11
- /** The versions every asset RFQ advertises by default, most preferred first. */
12
- declare const ASSET_SWAP_CONTRACT_VERSIONS: readonly ["asset-swap-v3", "asset-swap-v2"];
13
- /** Absent means {@link ASSET_SWAP_BASELINE}; an id this build cannot derive throws. */
14
- declare const assetSwapContractVersion: (id: string | undefined) => AssetSwapContractVersion;
15
-
16
- /**
17
- * Coverage: whether an offer's script is in the wallet's watched set. `createOffer` promotes; the
18
- * watcher and restore consumer retire. Identical offers share one script, so a late demotion would
19
- * unwatch an address the user was just told to fund. Guards: per-script serialization (the watch
20
- * state is a read-modify-write), and an issuance mark for created-but-unfunded offers, which have no
21
- * record yet. The mark is per process; the restore scan backstops other contexts and restarts.
22
- */
23
-
24
- interface CoverageRegistrationOptions {
25
- readonly coverageId?: string;
26
- /** Use the wallet object: a worker can return a fresh manager proxy on every call. */
27
- readonly scope?: object;
28
- }
29
-
30
- /** A full-fill offer. Exactly one field names an asset: `wantAsset` = the fill must deliver that
31
- * asset (the deposit is whatever the funding vtxo holds); `offerAsset` = the user deposits that
32
- * asset and wants sats.
33
- *
34
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
35
- */
36
- interface Offer {
37
- /** The scriptPubKey of the swap contract. */
38
- swapPkScript: Uint8Array;
39
- /** Amount the user wants (asset units, or sats when wanting BTC). */
40
- wantAmount: bigint;
41
- /** The asset the user wants. Omitted when wanting BTC. */
42
- wantAsset?: asset.AssetId;
43
- /** The asset the user deposits. Omitted when depositing BTC. */
44
- offerAsset?: asset.AssetId;
45
- /** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
46
- makerPkScript: Uint8Array;
47
- /** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
48
- makerPublicKey: Uint8Array;
49
- /** X-only key (32 bytes) of the operator's cosigner that emulates Arkade Script. */
50
- emulatorPubkey: Uint8Array;
51
- /** Partial-fill numerator. Reserved wire space in V1: carried through the
52
- * codec so an offer that sets it decodes, never interpreted here. */
53
- ratioNum?: bigint;
54
- /** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
55
- ratioDen?: bigint;
56
- /** The maker's unilateral exit path. Present adds a third closure to the
57
- * taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
58
- exitDelay?: RelativeTimelock;
59
- }
60
- /** Compile the offer's contract: program + args -> taproot tree.
61
- *
62
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
63
- */
64
- declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array, contractVersion?: AssetSwapContractVersion): InstanceType<typeof arkade.ArkadeProgramScript>;
65
- /** Extension packet type tag for Arkade Intents offers.
66
- *
67
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
68
- */
69
- declare const OFFER_PACKET_TYPE = 3;
70
- /** Serialize an offer to TLV bytes (the packet payload).
71
- *
72
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
73
- */
74
- declare function encodeOffer(offer: Offer): Uint8Array;
75
- /** Parse TLV bytes into an offer. Throws on malformed or unknown records.
76
- *
77
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
78
- */
79
- declare function decodeOffer(data: Uint8Array): Offer;
80
- /**
81
- * Build a new offer for `wallet` (the user). Fund `address` with the side
82
- * you deposit, embedding the returned extension, and the solver does the rest:
83
- *
84
- * // BTC -> asset
85
- * const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
86
- * await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
87
- *
88
- * // asset -> BTC (the sats are the VTXO carrier for the asset)
89
- * const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
90
- * await wallet.send({ address: o.address, amount: 500,
91
- * assets: [{ assetId, amount: 1000n }],
92
- * extensions: [o.extension] })
93
- *
94
- * Broadcasts nothing, but registers the covenant before returning the address: a failure now is
95
- * retryable, whereas after `wallet.send` it would leave a funded deposit unwatched. The unilateral
96
- * exit closure is built by default (operator's `unilateralExitDelay`, as solverd does); without it only
97
- * the operator-cosigned `cancel` gets the deposit out, and an offer never expires.
98
- *
99
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
100
- */
101
- declare function createOffer(wallet: IWallet, params: OfferParams, options?: CoverageRegistrationOptions): Promise<{
102
- /** The encoded offer, hex. **Persist this** — it is the only input `cancelOffer` needs to
103
- * rebuild the covenant. */
104
- offerHex: string;
105
- /** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
106
- extension: {
107
- type: number;
108
- payload: Uint8Array;
109
- };
110
- /** The swap address to fund. Identical offers derive an identical address, so the funding
111
- * txid — not the address — identifies one deposit. */
112
- address: string;
113
- /** The covenant's scriptPubKey: the key an indexer watches to spot the
114
- * deposit and its later spend (`AssetSwap.swapPkScript`). */
115
- swapPkScript: Uint8Array;
116
- }>;
117
- interface OfferParams {
118
- receiveAddress?: string;
119
- wantAmount: bigint;
120
- wantAsset?: asset.AssetId;
121
- offerAsset?: asset.AssetId;
122
- /** Co-signer key override (33-byte compressed hex); see
123
- * {@link resolveEmulatorPubkey}. */
124
- emulatorPubkey?: string;
125
- /** Override the exit closure's delay. Defaults to the operator's own
126
- * `unilateralExitDelay`, which is the delay solverd uses too. */
127
- exitDelay?: RelativeTimelock;
128
- /** Publish without the exit closure, leaving `cancel` — which needs the
129
- * operator — as the only way back out. See the note on {@link createOffer}. */
130
- noExit?: boolean;
131
- /**
132
- * A live `getArkadeInfo` the caller already made.
133
- *
134
- * Passing it is what lets one live read bind both the derivation and the
135
- * registration that follows it; omitting it makes the read here. It must be
136
- * live for the reason {@link createOffer} reads live — the info's
137
- * `signerPubkey` ends up in a covenant leaf.
138
- */
139
- info?: OperatorInfo;
140
- /**
141
- * The maker position, when the caller already read it.
142
- *
143
- * The RFQ path reads it BEFORE it sends the request — the profile commits
144
- * to this script and this key — so re-reading it here would let an address
145
- * rotation between the two reads derive a covenant the solver never quoted.
146
- */
147
- maker?: {
148
- pkScript: Uint8Array;
149
- publicKey: Uint8Array;
150
- };
151
- /** Defaults to {@link ASSET_SWAP_BASELINE}. */
152
- contractVersion?: AssetSwapContractVersion;
153
- }
154
- /**
155
- * Everything an offer commits to, derived and encoded, with nothing written.
156
- *
157
- * The split exists because `quote()` must derive the covenant it verifies the
158
- * solver's `offer_address` against while persisting and registering nothing,
159
- * and `accept()` must register **that** derivation rather than a second one
160
- * built from the same terms. So the tree's own parameters travel on this value:
161
- * two derivations that can disagree is the failure the hand-off deletes.
162
- */
163
- interface DerivedOffer {
164
- readonly offerHex: string;
165
- readonly extension: {
166
- readonly type: number;
167
- readonly payload: Uint8Array;
168
- };
169
- readonly address: string;
170
- readonly swapPkScript: Uint8Array;
171
- /** The covenant's parameters — {@link registerDerivedOffer}'s only input. */
172
- readonly binding: Readonly<Omit<Offer, "swapPkScript">>;
173
- /** The live info this covenant is bound to. */
174
- readonly info: OperatorInfo;
175
- readonly operatorPubkey: Uint8Array;
176
- }
177
- /**
178
- * Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid. No path is on a
179
- * deadline, so an unfilled deposit stays at the swap address until the user cancels.
180
- *
181
- * Routes out: `fulfill` (operator alone, but constrained to pay `makerWP` at least `wantAmount`),
182
- * `cancel` (user+operator 2-of-2, no solver involved), `exit` (user alone after a CSV unless `noExit`;
183
- * reached by unrolling onchain, not here).
184
- *
185
- * Cancel races a fill: if `fulfill` spent first this throws "no spendable VTXO at the swap address",
186
- * which means the swap completed (`classifySpend` tells the spends apart by leaf). The escrow marker
187
- * gates implicit coin selection only; cancel names its input explicitly.
188
- *
189
- * `fundingTxid` selects the deposit (identical offers share an address); without it the address must
190
- * hold exactly one. `swapAddress` pins the funding-time operator key across a signer rotation. When
191
- * `repository` holds the record, this writes `cancelling` (crash marker) then `cancelled`, so the
192
- * watcher has nothing to decide for our own cancels; otherwise the watcher/restore scan classifies.
193
- *
194
- * @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
195
- */
196
- declare function cancelOffer(wallet: IWallet, offerHex: string, opts: {
197
- repository: AssetSwapRepository;
198
- fundingTxid?: string;
199
- fundingOutpoint?: FillOutpoint;
200
- swapAddress?: string;
201
- }): Promise<string>;
202
- /**
203
- * No deposit left to cancel at the swap address — almost always the fill winning the race. Typed so
204
- * the v2 client's `cancel()` reconciles by `instanceof` (see `client/cancel.ts`); message is v1's.
205
- *
206
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
207
- */
208
- declare class NoSpendableDepositError extends Error {
209
- readonly name = "NoSpendableDepositError";
210
- constructor(options?: ErrorOptions);
211
- }
212
- /**
213
- * The rebuilt covenant disagrees with the offer's `swapPkScript`: the pinned operator key is not the
214
- * one the covenant was funded with (rotated signer, a wrong `swapAddress`, or a corrupt record).
215
- * Fires before any broadcast.
216
- *
217
- * @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
218
- */
219
- declare class OfferCovenantMismatchError extends Error {
220
- readonly swapPkScript: string;
221
- readonly name = "OfferCovenantMismatchError";
222
- constructor(swapPkScript: string, options?: ErrorOptions);
223
- }
224
- /** Sats carried by output 0 when the maker is paid in an ASSET: the covenant checks the asset, and
225
- * the output still needs its own carrier. Overridable per fill via `assetCarrierSats`.
226
- *
227
- * @deprecated Read it from `@arkade-os/sdk`, which owns the constant. Moved off the package root to `@arkade-os/swap/protocol`.
228
- */
229
- declare const ASSET_CARRIER_SATS: bigint;
230
- /**
231
- * A coin the taker supplies, plus the assets it carries. `ArkTxInput` is sats-only, and **arkd
232
- * refuses a spend whose asset packet omits an asset one of its inputs owns** (`ASSET_NOT_FOUND`), so
233
- * every asset on a funding coin must be declared. A wallet's own coins already carry this shape.
234
- */
235
- type FillFunding = ArkTxInput & {
236
- assets?: readonly {
237
- assetId: string;
238
- amount: bigint | number;
239
- }[];
240
- };
241
- /** @deprecated Use `Outpoint` from `@arkade-os/sdk`. */
242
- type FillOutpoint = Outpoint;
243
- type FillInputOwner = "solver" | "sponsor";
244
- /**
245
- * Fill an offer — the TAKER's side, and the counterpart to {@link createOffer}. Composes the
246
- * `fulfill` spend; it does not weaken or reinterpret the covenant.
247
- *
248
- * `fulfill` reads the output at the spending input's index. This builder puts the deposit at
249
- * input 0 and the maker payout at output 0. An ASSET want is the first packet group on that
250
- * output, which carries only a dust carrier ({@link ASSET_CARRIER_SATS}). Every other asset
251
- * goes to the taker's payout; see {@link FillFunding}.
252
- *
253
- * Writes NO local swap record: the maker learns the outcome from the chain (RFQ protocol § 7.2).
254
- * `fund` is explicit because only the caller knows which coins are reserved (e.g. a corridor's
255
- * float). Racing a cancel is NORMAL: "no spendable VTXO at the swap address" means the offer is gone.
256
- *
257
- * @deprecated The v2 client has no taker-side fill, so there is no replacement:
258
- * `accept()` funds a covenant of your own; it does not spend someone else's
259
- * offer through its `fulfill` leaf. Moved off the package root to `@arkade-os/swap/protocol`.
260
- */
261
- declare function fillOffer(wallet: IWallet, arkServerUrl: string, offerHex: string, opts: {
262
- fund: FillFunding[];
263
- payoutScript?: Uint8Array;
264
- fundingTxid?: string;
265
- fundingOutpoint?: FillOutpoint;
266
- swapAddress?: string;
267
- assetCarrierSats?: bigint;
268
- emulator: EmulatorProvider | string;
269
- emulatorPubkey?: string;
270
- }): Promise<string>;
271
- /** @deprecated Use `offerContract` from `@arkade-os/swap/protocol`. */
272
- declare const offerVtxoScript: typeof offerContract;
273
-
274
- export { ASSET_CARRIER_SATS as A, type CoverageRegistrationOptions as C, type DerivedOffer as D, type FillFunding as F, NoSpendableDepositError as N, type Offer as O, type FillOutpoint as a, type FillInputOwner as b, ASSET_SWAP_CONTRACT_VERSIONS as c, type AssetSwapContractVersion as d, OFFER_PACKET_TYPE as e, OfferCovenantMismatchError as f, assetSwapContractVersion as g, cancelOffer as h, createOffer as i, decodeOffer as j, encodeOffer as k, fillOffer as l, offerVtxoScript as m, offerContract as o, swapPrograms as s };