@arkade-os/swap 0.1.0-rc.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -10
- package/dist/advanced.cjs +6429 -3083
- package/dist/advanced.d.cts +325 -282
- package/dist/advanced.d.ts +325 -282
- package/dist/advanced.js +343 -34
- package/dist/chunk-A3SHHRX4.js +104 -0
- package/dist/chunk-FMRAV77W.js +3065 -0
- package/dist/{chunk-HV7EIUE2.js → chunk-HRMWBULL.js} +1773 -634
- package/dist/chunk-WKJFXXSR.js +3382 -0
- package/dist/index.cjs +6868 -3837
- package/dist/index.d.cts +71 -243
- package/dist/index.d.ts +71 -243
- package/dist/index.js +139 -167
- package/dist/lockupContract-D7BNjksX.d.ts +148 -0
- package/dist/lockupContract-G-9CNRMq.d.cts +148 -0
- package/dist/node/index.cjs +61 -10
- package/dist/node/index.d.cts +310 -639
- package/dist/node/index.d.ts +310 -639
- package/dist/node/index.js +65 -10
- package/dist/nostr.cjs +428 -49
- package/dist/nostr.d.cts +59 -70
- package/dist/nostr.d.ts +59 -70
- package/dist/nostr.js +268 -36
- package/dist/offer-CcJfx5Fj.d.cts +269 -0
- package/dist/offer-DdB1M6FZ.d.ts +269 -0
- package/dist/offerFillPlan-BII0PW92.d.cts +1642 -0
- package/dist/offerFillPlan-CNTLVD7j.d.ts +1642 -0
- package/dist/protocol.cjs +5591 -4064
- package/dist/protocol.d.cts +258 -355
- package/dist/protocol.d.ts +258 -355
- package/dist/protocol.js +209 -228
- package/dist/repositories/realm/index.cjs +55 -11
- package/dist/repositories/realm/index.d.cts +18 -30
- package/dist/repositories/realm/index.d.ts +18 -30
- package/dist/repositories/realm/index.js +49 -12
- package/dist/repositories/sqlite/index.cjs +61 -10
- package/dist/repositories/sqlite/index.d.cts +7 -6
- package/dist/repositories/sqlite/index.d.ts +7 -6
- package/dist/repositories/sqlite/index.js +57 -11
- package/dist/repository-DmPzpbd7.d.ts +2342 -0
- package/dist/repository-DqdLVrVv.d.cts +2342 -0
- package/dist/rfq-C0tHOvn6.d.cts +983 -0
- package/dist/rfq-C0tHOvn6.d.ts +983 -0
- package/dist/watch-BonYT9af.d.cts +74 -0
- package/dist/watch-CmJQDtsy.d.ts +74 -0
- package/package.json +12 -12
- package/dist/chunk-4PATNGYQ.js +0 -3297
- package/dist/chunk-ARYFNDJY.js +0 -1432
- package/dist/chunk-U7VWWTL6.js +0 -66
- package/dist/errors-CSpOUdCN.d.ts +0 -2216
- package/dist/errors-DVn92LQd.d.cts +0 -2216
- package/dist/lockupContract-6TYZOBbn.d.ts +0 -490
- package/dist/lockupContract-aLCQQiSu.d.cts +0 -490
- package/dist/repository-D0gFF_GA.d.cts +0 -3491
- package/dist/repository-tDT8p-Nx.d.ts +0 -3491
- package/dist/rfq-DhkgiwQ7.d.cts +0 -1126
- package/dist/rfq-DhkgiwQ7.d.ts +0 -1126
- package/dist/watch-C4cMEeZT.d.cts +0 -96
- package/dist/watch-DbWXdpzm.d.ts +0 -96
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
import { asset, RelativeTimelock, IWallet, arkade, RestIndexerProvider, Transaction, VHTLC, IContractManager } from '@arkade-os/sdk';
|
|
2
|
-
import { c as AssetSwapRepository, aW as AssetSwap } from './repository-tDT8p-Nx.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The contracts, one per WANT side — pure data, shared verbatim with any other
|
|
6
|
-
* implementation.
|
|
7
|
-
*
|
|
8
|
-
* **These are the base: an offer carrying an exit delay compiles to a third
|
|
9
|
-
* closure that is not in either file.** The tree is not fixed-shape — the
|
|
10
|
-
* protocol defines the exit as `iff ExitDelay`, and solverd appends it the same
|
|
11
|
-
* way (`pkg/swap/contract/offer.go`, `VtxoScript`) — so it cannot be a function
|
|
12
|
-
* in a static artifact without splitting these into one file per exit variant.
|
|
13
|
-
* {@link withExitClosure} owns that step, and the golden in `offer.test.ts`
|
|
14
|
-
* pins the artifact it produces so the whole contract is still readable as data.
|
|
15
|
-
*
|
|
16
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
17
|
-
*/
|
|
18
|
-
declare const swapPrograms: Record<"wantAsset" | "wantBtc", ReturnType<typeof arkade.parseArtifact>>;
|
|
19
|
-
/** A full-fill offer. Exactly one field names an asset: `wantAsset` set = the
|
|
20
|
-
* fill must deliver that asset (the deposit may be BTC or another asset,
|
|
21
|
-
* identified by the funding vtxo itself); `offerAsset` set = the user
|
|
22
|
-
* deposits that asset and wants sats.
|
|
23
|
-
*
|
|
24
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
25
|
-
*/
|
|
26
|
-
interface Offer {
|
|
27
|
-
/** The scriptPubKey of the swap contract. */
|
|
28
|
-
swapPkScript: Uint8Array;
|
|
29
|
-
/** Amount the user wants (asset units, or sats when wanting BTC). */
|
|
30
|
-
wantAmount: bigint;
|
|
31
|
-
/** The asset the user wants. Omitted when wanting BTC. */
|
|
32
|
-
wantAsset?: asset.AssetId;
|
|
33
|
-
/** The asset the user deposits. Omitted when depositing BTC. */
|
|
34
|
-
offerAsset?: asset.AssetId;
|
|
35
|
-
/** Maker's taproot scriptPubKey (34 bytes) — where the fill must pay. */
|
|
36
|
-
makerPkScript: Uint8Array;
|
|
37
|
-
/** Maker's x-only key (32 bytes) — the cancel path's `user` signer. */
|
|
38
|
-
makerPublicKey: Uint8Array;
|
|
39
|
-
/** Covenant co-signer (emulator) x-only key (32 bytes). */
|
|
40
|
-
emulatorPubkey: Uint8Array;
|
|
41
|
-
/** Partial-fill numerator. Reserved wire space in V1: carried through the
|
|
42
|
-
* codec so an offer that sets it decodes, never interpreted here. */
|
|
43
|
-
ratioNum?: bigint;
|
|
44
|
-
/** Partial-fill denominator. Set with {@link Offer.ratioNum} or not at all. */
|
|
45
|
-
ratioDen?: bigint;
|
|
46
|
-
/** The maker's unilateral exit path. Present adds a third closure to the
|
|
47
|
-
* taproot tree, so it changes `swapPkScript` — see {@link offerVtxoScript}. */
|
|
48
|
-
exitDelay?: RelativeTimelock;
|
|
49
|
-
}
|
|
50
|
-
/** Compile the offer's contract: program + args -> taproot tree.
|
|
51
|
-
*
|
|
52
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
53
|
-
*/
|
|
54
|
-
declare function offerContract(offer: Omit<Offer, "swapPkScript">, operatorPubkey: Uint8Array): InstanceType<typeof arkade.ArkadeProgramScript>;
|
|
55
|
-
/** Extension packet type tag for Arkade Intents offers.
|
|
56
|
-
*
|
|
57
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
58
|
-
*/
|
|
59
|
-
declare const OFFER_PACKET_TYPE = 3;
|
|
60
|
-
/** Serialize an offer to TLV bytes (the packet payload).
|
|
61
|
-
*
|
|
62
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
63
|
-
*/
|
|
64
|
-
declare function encodeOffer(offer: Offer): Uint8Array;
|
|
65
|
-
/** Parse TLV bytes into an offer. Throws on malformed or unknown records.
|
|
66
|
-
*
|
|
67
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
68
|
-
*/
|
|
69
|
-
declare function decodeOffer(data: Uint8Array): Offer;
|
|
70
|
-
/**
|
|
71
|
-
* Build a new offer for `wallet` (the user). Fund `address` with the side
|
|
72
|
-
* you deposit, embedding the returned extension, and the solver does the rest:
|
|
73
|
-
*
|
|
74
|
-
* // BTC -> asset
|
|
75
|
-
* const o = await createOffer(wallet, { wantAmount: 1000n, wantAsset })
|
|
76
|
-
* await wallet.send({ address: o.address, amount: 1000, extensions: [o.extension] })
|
|
77
|
-
*
|
|
78
|
-
* // asset -> BTC (the sats are the VTXO carrier for the asset)
|
|
79
|
-
* const o = await createOffer(wallet, { wantAmount: 1000n, offerAsset })
|
|
80
|
-
* await wallet.send({ address: o.address, amount: 500,
|
|
81
|
-
* assets: [{ assetId, amount: 1000n }],
|
|
82
|
-
* extensions: [o.extension] })
|
|
83
|
-
*
|
|
84
|
-
* Broadcasts nothing, but does write locally: the covenant is registered with
|
|
85
|
-
* the wallet's contract manager before the address is returned, so the deposit
|
|
86
|
-
* is watched from the moment it lands and is marked as escrow (see
|
|
87
|
-
* {@link registerOfferContract}). Registration deliberately happens *before*
|
|
88
|
-
* funding rather than after: nothing is at stake yet, so a failure can throw
|
|
89
|
-
* and be retried, where the same failure after `wallet.send` would leave a
|
|
90
|
-
* funded deposit unwatched with no way to notice.
|
|
91
|
-
*
|
|
92
|
-
* **The maker's unilateral exit closure is built by default**, at the server's
|
|
93
|
-
* own `unilateralExitDelay` — the same thing solverd does. Without it `cancel`
|
|
94
|
-
* is the only way back out, and `cancel` needs the server's signature: a server
|
|
95
|
-
* that will not co-sign leaves the deposit stuck at the swap address until the
|
|
96
|
-
* VTXO expires and the operator sweeps it. An offer has no expiry of its own,
|
|
97
|
-
* so that exposure has no end. `noExit` opts out for a caller who wants the
|
|
98
|
-
* smaller tree and accepts the dependency.
|
|
99
|
-
*
|
|
100
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
101
|
-
*/
|
|
102
|
-
declare function createOffer(wallet: IWallet, params: {
|
|
103
|
-
wantAmount: bigint;
|
|
104
|
-
wantAsset?: asset.AssetId;
|
|
105
|
-
offerAsset?: asset.AssetId;
|
|
106
|
-
/** Co-signer key override (33-byte compressed hex); see
|
|
107
|
-
* {@link resolveEmulatorPubkey}. */
|
|
108
|
-
emulatorPubkey?: string;
|
|
109
|
-
/** Override the exit closure's delay. Defaults to the server's own
|
|
110
|
-
* `unilateralExitDelay`, which is the delay solverd uses too. */
|
|
111
|
-
exitDelay?: RelativeTimelock;
|
|
112
|
-
/** Publish without the exit closure, leaving `cancel` — which needs the
|
|
113
|
-
* server — as the only way back out. See the note on this function. */
|
|
114
|
-
noExit?: boolean;
|
|
115
|
-
}): Promise<{
|
|
116
|
-
/** The encoded offer, hex. **Persist this** — it is the only input
|
|
117
|
-
* `cancelOffer` needs to rebuild the covenant, and the restore scan reads
|
|
118
|
-
* the same bytes back off the funding tx into `AssetSwap.offerHex`. */
|
|
119
|
-
offerHex: string;
|
|
120
|
-
/** Ready for `wallet.send`'s `extensions` — the caller never handles the packet type. */
|
|
121
|
-
extension: {
|
|
122
|
-
type: number;
|
|
123
|
-
payload: Uint8Array;
|
|
124
|
-
};
|
|
125
|
-
/** The swap address to fund. Nothing exists on chain until the deposit
|
|
126
|
-
* lands here: `createOffer` is pure derivation and broadcasts nothing.
|
|
127
|
-
* Identical offers derive an identical address, so the funding txid — not
|
|
128
|
-
* the address — is what identifies one deposit. */
|
|
129
|
-
address: string;
|
|
130
|
-
/** The covenant's scriptPubKey: the key an indexer watches to spot the
|
|
131
|
-
* deposit and its later spend (`AssetSwap.swapPkScript`). */
|
|
132
|
-
swapPkScript: Uint8Array;
|
|
133
|
-
}>;
|
|
134
|
-
/**
|
|
135
|
-
* Cancel an offer: spend the swap VTXO back to the user. Returns the ark txid.
|
|
136
|
-
*
|
|
137
|
-
* This is the cooperative refund path — how a user takes back a deposit no
|
|
138
|
-
* solver filled. **No path here is on a deadline**, so an unfilled deposit
|
|
139
|
-
* keeps its place at the swap address rather than expiring: nothing to miss and
|
|
140
|
-
* no "expired" state to unwind, at the cost of the refund being something the
|
|
141
|
-
* user asks for rather than something a clock delivers.
|
|
142
|
-
*
|
|
143
|
-
* The routes out of the covenant are deliberately asymmetric:
|
|
144
|
-
* - `fulfill` is signed by the **server alone**, but the covenant constrains
|
|
145
|
-
* it to pay output 0 to `makerWP` for at least `wantAmount` — a solver
|
|
146
|
-
* cannot take the deposit without delivering.
|
|
147
|
-
* - `cancel` is a **2-of-2 of the user and the server**, so cancelling is
|
|
148
|
-
* cooperative: the server co-signs. No solver signature is involved, so the
|
|
149
|
-
* refund never depends on the counterparty being reachable.
|
|
150
|
-
* - `exit` is the user **alone** after a relative timelock, present unless the
|
|
151
|
-
* offer was created with `noExit`. It is the route that survives a server
|
|
152
|
-
* that will not co-sign this one, and it is reached by unrolling the VTXO
|
|
153
|
-
* onchain rather than through this function.
|
|
154
|
-
*
|
|
155
|
-
* Cancel therefore races a fill rather than pre-empting it. An offer the solver
|
|
156
|
-
* is filling in the same moment may be spent by `fulfill` first, in which case
|
|
157
|
-
* this throws "no spendable VTXO at the swap address" — which means the swap
|
|
158
|
-
* completed, not that anything failed. `restoreAssetSwaps` classifies the two
|
|
159
|
-
* spends apart afterwards by the leaf each took (see `classifySpend`).
|
|
160
|
-
*
|
|
161
|
-
* Marking the deposit as escrow (see {@link registerOfferContract}) does not
|
|
162
|
-
* close this path: the gate's subject is *implicit* coin selection, and cancel
|
|
163
|
-
* names its input outpoint explicitly. The user keeps the only spend route
|
|
164
|
-
* that was ever theirs to take.
|
|
165
|
-
*
|
|
166
|
-
* Identical offers derive the same address, so `fundingTxid` selects the exact
|
|
167
|
-
* deposit; without it the address must hold exactly one spendable VTXO — with
|
|
168
|
-
* several, cancel refuses to guess and throws.
|
|
169
|
-
* `swapAddress` (the funded address) pins the operator key the covenant was
|
|
170
|
-
* built with, so cancel keeps working across an operator signer rotation; without
|
|
171
|
-
* it a rotated key is detected and reported rather than reading as a missing
|
|
172
|
-
* VTXO.
|
|
173
|
-
*
|
|
174
|
-
* **When the matching swap record is present, this records its own outcome,
|
|
175
|
-
* and that is what makes the live watcher cheap.** `cancel` is a 2-of-2 of
|
|
176
|
-
* user and server, so a cancel can only be the user's own act: on a
|
|
177
|
-
* successful submit this *is* the authoritative answer, and writing it here
|
|
178
|
-
* means `watchOfferSwaps` has nothing left to decide for our own cancels — it
|
|
179
|
-
* sees a terminal record and leaves it alone. The status moves to `cancelling`
|
|
180
|
-
* first so a crash between submit and record leaves a marker rather than a
|
|
181
|
-
* swap that still looks pending.
|
|
182
|
-
*
|
|
183
|
-
* Passing a repository that does not contain the swap record is allowed: the
|
|
184
|
-
* cancel still submits and returns its txid, but no local status is written,
|
|
185
|
-
* so the watcher or restore scan must classify the spend later.
|
|
186
|
-
*
|
|
187
|
-
* When a local record exists, the txid is only knowable after `send()`
|
|
188
|
-
* returns, so a spend event that arrives in that window finds a `cancelling`
|
|
189
|
-
* record and classifies the spend by its covenant leaf instead — the same
|
|
190
|
-
* answer, one indexer read more.
|
|
191
|
-
*
|
|
192
|
-
* Takes no server URL, like every other entrypoint here: broadcast comes from
|
|
193
|
-
* `wallet.getArkadeBroadcaster()` and the indexer fallback from
|
|
194
|
-
* `wallet.getArkadeReader()`, so the wallet's own connection is the only one
|
|
195
|
-
* used (#734).
|
|
196
|
-
*
|
|
197
|
-
* @deprecated Use `client.cancel()`. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
198
|
-
*/
|
|
199
|
-
declare function cancelOffer(wallet: IWallet, offerHex: string, opts: {
|
|
200
|
-
repository: AssetSwapRepository;
|
|
201
|
-
fundingTxid?: string;
|
|
202
|
-
swapAddress?: string;
|
|
203
|
-
}): Promise<string>;
|
|
204
|
-
/**
|
|
205
|
-
* No deposit left to cancel at the swap address.
|
|
206
|
-
*
|
|
207
|
-
* Almost always the fill winning the race — v1's documented
|
|
208
|
-
* throw-means-completed trap, which the v2 client's `cancel()` reconciles
|
|
209
|
-
* against the covenant's leaves instead of surfacing (see `client/cancel.ts`).
|
|
210
|
-
* Typed so that reconciliation is an `instanceof`, not a message match; the
|
|
211
|
-
* message is v1's, unchanged.
|
|
212
|
-
*
|
|
213
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
214
|
-
*/
|
|
215
|
-
declare class NoSpendableDepositError extends Error {
|
|
216
|
-
readonly name = "NoSpendableDepositError";
|
|
217
|
-
constructor(options?: ErrorOptions);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* The rebuilt covenant disagrees with the offer's own `swapPkScript`: the
|
|
221
|
-
* operator key the rebuild pinned is not the one the covenant was funded with.
|
|
222
|
-
*
|
|
223
|
-
* v1's fallback read this as a missing VTXO; with a pinned `swapAddress` the
|
|
224
|
-
* only remaining causes are a record corrupted or a `swapAddress` that is not
|
|
225
|
-
* the one funded — so the condition is typed rather than left to surface raw.
|
|
226
|
-
* Fires before any broadcast, where §7's law still governs.
|
|
227
|
-
*
|
|
228
|
-
* @deprecated Internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
229
|
-
*/
|
|
230
|
-
declare class OfferCovenantMismatchError extends Error {
|
|
231
|
-
readonly swapPkScript: string;
|
|
232
|
-
readonly name = "OfferCovenantMismatchError";
|
|
233
|
-
constructor(swapPkScript: string, options?: ErrorOptions);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* The subset of a wallet transaction record the swap scan reads.
|
|
238
|
-
*
|
|
239
|
-
* No `assets`: a spend is classified from the covenant leaf it took, read off
|
|
240
|
-
* the spending transaction itself (see {@link classifySpend}). A wallet
|
|
241
|
-
* record's asset field is a net delta — an asset offer's cancel moves the asset
|
|
242
|
-
* out and back, netting to nothing — so it cannot answer the question.
|
|
243
|
-
*
|
|
244
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
245
|
-
*/
|
|
246
|
-
interface Tx {
|
|
247
|
-
type: string;
|
|
248
|
-
/** The virtual (ark) txid; the funding tx's identity. */
|
|
249
|
-
redeemTxid: string;
|
|
250
|
-
boardingTxid?: string;
|
|
251
|
-
roundTxid?: string;
|
|
252
|
-
/** Unix seconds. */
|
|
253
|
-
createdAt?: number;
|
|
254
|
-
}
|
|
255
|
-
/** The indexer surface the restore scan needs — narrower than a full provider.
|
|
256
|
-
*
|
|
257
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
258
|
-
*/
|
|
259
|
-
type RestoreIndexer = Pick<RestIndexerProvider, "getVirtualTxs" | "getVtxos">;
|
|
260
|
-
/**
|
|
261
|
-
* What became of a deposit, as the spending transaction reports it.
|
|
262
|
-
*
|
|
263
|
-
* `indeterminate` is not a third outcome — it is the absence of one, and the
|
|
264
|
-
* caller decides whether to retry or accept a default.
|
|
265
|
-
*
|
|
266
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
267
|
-
*/
|
|
268
|
-
type SpendKind = "cancelled" | "fulfilled" | "indeterminate";
|
|
269
|
-
/**
|
|
270
|
-
* Classify a spend by the covenant leaf it took.
|
|
271
|
-
*
|
|
272
|
-
* The vocabulary is what became of the deposit, not which key moved it:
|
|
273
|
-
* `fulfill` is the solver paying for it, and everything else returns it to the
|
|
274
|
-
* user. A submitted ark tx keeps each input's `tapLeafScript`, so the spend
|
|
275
|
-
* *states* which one it used — this reads an answer rather than inferring one.
|
|
276
|
-
*
|
|
277
|
-
* **`exit` reports `cancelled`, like `cancel` does.** The two differ in who had
|
|
278
|
-
* to agree — `cancel` is cooperative with the signer, `exit` is the maker alone
|
|
279
|
-
* after a delay — but not in outcome: the deposit went back unfilled either
|
|
280
|
-
* way, which is the question this answers. Reporting the exit leaf as
|
|
281
|
-
* `indeterminate` instead would be worse than imprecise: no status is written,
|
|
282
|
-
* so the swap stays `pending`, `restoreAssetSwaps` re-queues it on every scan,
|
|
283
|
-
* and `retireOfferContract` never runs — leaving a dead script in the
|
|
284
|
-
* subscription and the failsafe poll for the life of the wallet.
|
|
285
|
-
*
|
|
286
|
-
* **Hand it the transaction that actually spends the deposit outpoint, which is
|
|
287
|
-
* the checkpoint, not the ark tx.** A spend is two linked transactions: the
|
|
288
|
-
* checkpoint (`vtxo.spentBy`) takes the deposit outpoint and carries the
|
|
289
|
-
* covenant leaf, and the ark tx (`vtxo.arkTxId`) spends the checkpoint's output
|
|
290
|
-
* — carrying the same leaf, but over an outpoint that is not the deposit's. A
|
|
291
|
-
* caller that offers only the ark tx gets `indeterminate` for every real spend,
|
|
292
|
-
* which is exactly what the first version of this function did.
|
|
293
|
-
* {@link classifyDepositSpend} takes both and picks whichever answers.
|
|
294
|
-
*
|
|
295
|
-
* What it replaces, and why: the previous test asked what the transaction
|
|
296
|
-
* moved. That works only while the deposit is invisible to the wallet. Once the
|
|
297
|
-
* covenant is a registered contract the deposit joins the wallet's own coins,
|
|
298
|
-
* every wallet-level asset figure becomes a *net* delta, and an asset offer's
|
|
299
|
-
* cancel — asset out of the covenant, same asset back to the user — nets to
|
|
300
|
-
* zero and reads exactly like its fill. Leaves do not have that failure mode,
|
|
301
|
-
* and they also survive batching: a solver filling several offers in one tx
|
|
302
|
-
* gives each input its own leaf.
|
|
303
|
-
*
|
|
304
|
-
* `operatorPubkey` must be the key the covenant was *funded* against. If it has
|
|
305
|
-
* rotated since, the rebuilt script will not match the offer's own
|
|
306
|
-
* `swapPkScript` and this returns `indeterminate` rather than guessing —
|
|
307
|
-
* `cancelOffer` diagnoses the same mismatch the same way.
|
|
308
|
-
*
|
|
309
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
310
|
-
*/
|
|
311
|
-
declare function classifySpend(offer: Offer, operatorPubkey: Uint8Array, spendTx: Transaction, deposit: {
|
|
312
|
-
txid: string;
|
|
313
|
-
vout: number;
|
|
314
|
-
}): SpendKind;
|
|
315
|
-
/**
|
|
316
|
-
* The txids that may hold a deposit's spend, in the order worth trying: the
|
|
317
|
-
* checkpoint first, since it is the one carrying the deposit outpoint.
|
|
318
|
-
*
|
|
319
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
320
|
-
*/
|
|
321
|
-
declare const spendTxidsOf: (vtxo: {
|
|
322
|
-
spentBy?: string;
|
|
323
|
-
arkTxId?: string;
|
|
324
|
-
}) => string[];
|
|
325
|
-
/**
|
|
326
|
-
* Classify a deposit's spend across both halves of it.
|
|
327
|
-
*
|
|
328
|
-
* A caller holds two txids for one spend — `spentBy` (the checkpoint, which
|
|
329
|
-
* takes the deposit outpoint) and `arkTxId` (the ark tx built on it) — and
|
|
330
|
-
* cannot tell from the outside which shape a given deployment produced: for a
|
|
331
|
-
* settlement they may be the same id. Try each and take the first definite
|
|
332
|
-
* answer, so the classification does not depend on that distinction.
|
|
333
|
-
*
|
|
334
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
335
|
-
*/
|
|
336
|
-
declare function classifyDepositSpend(offer: Offer, operatorPubkey: Uint8Array, spendTxs: Iterable<Transaction>, deposit: {
|
|
337
|
-
txid: string;
|
|
338
|
-
vout: number;
|
|
339
|
-
}): SpendKind;
|
|
340
|
-
/**
|
|
341
|
-
* Scan the given candidates for offer packets and rebuild the AssetSwap
|
|
342
|
-
* records the store lost. Returns the rebuilt swaps plus the txids that got
|
|
343
|
-
* an authoritative answer (fetched fine, vtxo lookup fine) — the caller
|
|
344
|
-
* persists those so they are never fetched again.
|
|
345
|
-
*
|
|
346
|
-
* ## A spent deposit is classified or left alone — never guessed
|
|
347
|
-
*
|
|
348
|
-
* Whether a spent deposit was filled or cancelled is read from the spending
|
|
349
|
-
* transaction's covenant leaf ({@link classifySpend}), fetched from the same
|
|
350
|
-
* indexer as everything else rather than from the `txs` you pass. A spend that
|
|
351
|
-
* cannot be classified — not fetchable yet, or gone by neither leaf — leaves
|
|
352
|
-
* the funding txid unanswered, so nothing is persisted and a later scan decides
|
|
353
|
-
* it. Nothing sticky is written on a guess.
|
|
354
|
-
*
|
|
355
|
-
* That is a deliberate reversal: this used to restore an unclassifiable spend
|
|
356
|
-
* as `fulfilled`, which a persisted record then made permanent, because the
|
|
357
|
-
* spending tx came from the caller's possibly-lagging history. It no longer
|
|
358
|
-
* does, so the `existingIds` escape hatch is no longer a correction mechanism
|
|
359
|
-
* for a wrong label — it is only a skip list.
|
|
360
|
-
*
|
|
361
|
-
* `operatorPubkey` must be the operator key the covenants were funded against; a
|
|
362
|
-
* key that has rotated since makes every affected swap unclassifiable rather
|
|
363
|
-
* than misclassified.
|
|
364
|
-
*
|
|
365
|
-
* ## `client.ready` is not a substitute for this
|
|
366
|
-
*
|
|
367
|
-
* The drive's construction restore reads the repository and nothing else, so it
|
|
368
|
-
* revives the records a store still holds and rediscovers none that it lost. A
|
|
369
|
-
* store wiped after a deposit was funded therefore leaves the offer invisible to
|
|
370
|
-
* the client and the deposit escrowed out of generic coin selection — recovered
|
|
371
|
-
* only by running this scan, which the package deliberately never calls for you.
|
|
372
|
-
* Pinned in `test/e2e/offerCancel.test.ts`.
|
|
373
|
-
*
|
|
374
|
-
* @deprecated There is no replacement — `client.ready` restores the records a store still holds and never rediscovers a lost one. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
375
|
-
*/
|
|
376
|
-
declare function restoreAssetSwaps(indexer: RestoreIndexer, txs: Tx[], existingIds: ReadonlySet<string>, opts: {
|
|
377
|
-
operatorPubkey: Uint8Array;
|
|
378
|
-
scanned?: ReadonlySet<string>;
|
|
379
|
-
reopen?: AssetSwap[];
|
|
380
|
-
}): Promise<{
|
|
381
|
-
restored: AssetSwap[];
|
|
382
|
-
scannedTxids: string[];
|
|
383
|
-
}>;
|
|
384
|
-
|
|
385
|
-
/** The contract type a swap lockup registers under. `@arkade-os/sdk`'s handler
|
|
386
|
-
* for `VHTLC.ScriptV2` — the covenant script this corridor builds.
|
|
387
|
-
*
|
|
388
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
389
|
-
*/
|
|
390
|
-
declare const SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
|
|
391
|
-
/** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
|
|
392
|
-
declare const SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
|
|
393
|
-
/** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
|
|
394
|
-
declare const SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
|
|
395
|
-
/** The write seam registration needs, narrowed to the one method — the same
|
|
396
|
-
* injection style as `SwapContractRegistry`, and satisfied by a real
|
|
397
|
-
* `ContractManager` (`await wallet.getContractManager()`).
|
|
398
|
-
*
|
|
399
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
400
|
-
*/
|
|
401
|
-
type LockupContractWriter = Pick<IContractManager, "createContract">;
|
|
402
|
-
/** The read seam {@link lockupContractParams} needs. Same narrowing, same
|
|
403
|
-
* `ContractManager` satisfies it.
|
|
404
|
-
*
|
|
405
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
406
|
-
*/
|
|
407
|
-
type LockupContractReader = Pick<IContractManager, "getContracts">;
|
|
408
|
-
/**
|
|
409
|
-
* No row for a lockup a record claims was funded.
|
|
410
|
-
*
|
|
411
|
-
* Separate from a rebuild failure on purpose: the record is fine and its money
|
|
412
|
-
* may well be at the address — what is missing is the wallet's copy of the
|
|
413
|
-
* covenant, which registration writes before the address can be funded. So this
|
|
414
|
-
* means the contract store was cleared or was never the one that registered
|
|
415
|
-
* this swap, and the remedy is a store, not a re-quote.
|
|
416
|
-
*
|
|
417
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
418
|
-
*/
|
|
419
|
-
declare class LockupContractMissing extends Error {
|
|
420
|
-
/** The lockup whose row is absent. */
|
|
421
|
-
readonly address: string;
|
|
422
|
-
/** Its pkScript hex — the key the row would have been under. */
|
|
423
|
-
readonly script: string;
|
|
424
|
-
constructor(address: string, script: string);
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* The lockup could not be written locally.
|
|
428
|
-
*
|
|
429
|
-
* Deliberately NOT a {@link SwapRefusal} or an {@link AddressMismatch}: those
|
|
430
|
-
* say "the quote is bad, never fund it", while this says "the quote is fine and
|
|
431
|
-
* your own store failed".
|
|
432
|
-
*
|
|
433
|
-
* The throw is the safe point: nothing is funded, and on the receive legs the
|
|
434
|
-
* invoice never left the function, so the abandoned quote is inert and simply
|
|
435
|
-
* retrying the request is the recovery. `script` travels beside `address` so a
|
|
436
|
-
* caller that still holds the swap — `RfqSwapManager`'s `ensureRegistered`, or
|
|
437
|
-
* one resuming from its own record — can retry `registerLockupContract` alone
|
|
438
|
-
* instead of re-quoting. It is NOT enough to resume a request that threw here:
|
|
439
|
-
* that caller never received the invoice or `secrets`.
|
|
440
|
-
*
|
|
441
|
-
* A root export because `client.accept()` throws it: a caller catching that
|
|
442
|
-
* refusal names this class.
|
|
443
|
-
*/
|
|
444
|
-
declare class LockupRegistrationFailed extends Error {
|
|
445
|
-
/** The lockup address that was never registered — never fund it: nothing
|
|
446
|
-
* is watching it. */
|
|
447
|
-
readonly address: string;
|
|
448
|
-
/** The covenant the row would have been written from — the other half of
|
|
449
|
-
* `registerLockupContract`, so the write is retryable without a quote. */
|
|
450
|
-
readonly script: InstanceType<typeof VHTLC.ScriptV2>;
|
|
451
|
-
constructor(script: InstanceType<typeof VHTLC.ScriptV2>, address: string, cause: unknown);
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Register a lockup covenant so its VTXOs are watched, annotatable and — via
|
|
455
|
-
* `vhtlc-v2`'s own handler, which is never generically spendable — kept out of
|
|
456
|
-
* ordinary coin selection.
|
|
457
|
-
*
|
|
458
|
-
* The row carries script-level facts only. Per-swap identity and key material
|
|
459
|
-
* stay in the swap record: rows are keyed by script and first-writer-wins, so
|
|
460
|
-
* anything per-swap written here is stale from the second swap onward.
|
|
461
|
-
*
|
|
462
|
-
* Takes the derived script rather than a script hex plus params, so the row
|
|
463
|
-
* cannot describe a script other than the one it is keyed by.
|
|
464
|
-
*
|
|
465
|
-
* Throws {@link LockupRegistrationFailed}, so a caller can tell a local
|
|
466
|
-
* storage problem from a reason to walk away from the quote.
|
|
467
|
-
*
|
|
468
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
469
|
-
*/
|
|
470
|
-
declare function registerLockupContract(contracts: LockupContractWriter, script: InstanceType<typeof VHTLC.ScriptV2>, address: string): Promise<void>;
|
|
471
|
-
/**
|
|
472
|
-
* The stored covenant parameters of a funded lockup — the other half of
|
|
473
|
-
* `rebuildRfqSwap`.
|
|
474
|
-
*
|
|
475
|
-
* The row is the wallet's own copy of the tree, written from the covenant
|
|
476
|
-
* before the address could be funded and keyed by the script it derives, which
|
|
477
|
-
* `createContract` refuses to write unless the params reproduce it. That is why
|
|
478
|
-
* an RFQ swap record stores no tree parameters of its own.
|
|
479
|
-
*
|
|
480
|
-
* Looked up by script rather than address: the script is the row's key, and
|
|
481
|
-
* decoding it here means a record whose address does not decode fails as a bad
|
|
482
|
-
* address instead of as a missing row.
|
|
483
|
-
*
|
|
484
|
-
* Throws {@link LockupContractMissing} when there is no row.
|
|
485
|
-
*
|
|
486
|
-
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
487
|
-
*/
|
|
488
|
-
declare function lockupContractParams(contracts: LockupContractReader, lockupAddress: string): Promise<Record<string, string>>;
|
|
489
|
-
|
|
490
|
-
export { LockupRegistrationFailed as L, NoSpendableDepositError as N, OFFER_PACKET_TYPE as O, type RestoreIndexer as R, SWAP_LOCKUP_CONTRACT_KIND as S, type Tx as T, LockupContractMissing as a, type LockupContractReader as b, type LockupContractWriter as c, type Offer as d, OfferCovenantMismatchError as e, SWAP_LOCKUP_CONTRACT_LABEL as f, SWAP_LOCKUP_CONTRACT_TYPE as g, type SpendKind as h, cancelOffer as i, classifyDepositSpend as j, classifySpend as k, createOffer as l, decodeOffer as m, encodeOffer as n, lockupContractParams as o, offerContract as p, restoreAssetSwaps as q, registerLockupContract as r, spendTxidsOf as s, swapPrograms as t };
|