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