@arkade-os/swap 0.1.0-rc.9 → 0.1.1
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 +6613 -3224
- package/dist/advanced.d.cts +328 -283
- package/dist/advanced.d.ts +328 -283
- package/dist/advanced.js +347 -34
- package/dist/chunk-A3SHHRX4.js +104 -0
- package/dist/chunk-FMRAV77W.js +3065 -0
- package/dist/chunk-T4FHBWZI.js +3459 -0
- package/dist/{chunk-NS3K6BZG.js → chunk-YHESEL4I.js} +1792 -636
- package/dist/index.cjs +6901 -3901
- package/dist/index.d.cts +71 -243
- package/dist/index.d.ts +71 -243
- package/dist/index.js +131 -167
- package/dist/lockupContract-CIXkJPxV.d.ts +148 -0
- package/dist/lockupContract-CkhWMKCo.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-BPD2ortO.d.ts +269 -0
- package/dist/offer-Diff5Flc.d.cts +269 -0
- package/dist/offerFillPlan-B-5ae_gQ.d.cts +1671 -0
- package/dist/offerFillPlan-CJzneX6F.d.ts +1671 -0
- package/dist/protocol.cjs +5717 -4275
- 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-BBVRh9ez.d.ts +2357 -0
- package/dist/repository-C4pvymhs.d.cts +2357 -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-7BiRa4oB.d.ts +74 -0
- package/dist/watch-Bxq-lx_6.d.cts +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
package/dist/index.js
CHANGED
|
@@ -2,20 +2,21 @@ import {
|
|
|
2
2
|
ARKADE_ASSET_NAMESPACE,
|
|
3
3
|
AcceptConflict,
|
|
4
4
|
AmbiguousDestination,
|
|
5
|
-
Amount,
|
|
6
5
|
AmountEncodingUnsupported,
|
|
7
|
-
AmountFormatError,
|
|
8
6
|
AmountMismatch,
|
|
9
7
|
AssetIdError,
|
|
10
8
|
BITCOIN_RAILS,
|
|
11
9
|
BTC_ASSET_PART,
|
|
12
10
|
ClientDisposed,
|
|
11
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|
|
13
12
|
DiscoverySnapshotUnavailable,
|
|
14
13
|
InconsistentRoute,
|
|
15
14
|
InsufficientFunds,
|
|
16
15
|
MaxFeeExceeded,
|
|
17
16
|
MissingCorridorDep,
|
|
18
17
|
NotCancellable,
|
|
18
|
+
OFFER_FILL_OWNERS,
|
|
19
|
+
OFFER_FILL_TEMPLATE,
|
|
19
20
|
ONCHAIN_SWAP_RAIL,
|
|
20
21
|
OperatorUnreachable,
|
|
21
22
|
PAYMENT_STATUS,
|
|
@@ -29,18 +30,20 @@ import {
|
|
|
29
30
|
UnsupportedRoute,
|
|
30
31
|
arkadeAsset,
|
|
31
32
|
assetPartOf,
|
|
32
|
-
assetSwapIdOf,
|
|
33
33
|
bitcoinNetworkOf,
|
|
34
|
+
btcAssetPart,
|
|
34
35
|
btcOn,
|
|
36
|
+
buildOfferFillPlan,
|
|
35
37
|
canonicalAssetId,
|
|
36
38
|
claimFeeSats,
|
|
37
39
|
createSwapClient,
|
|
40
|
+
deepFreeze,
|
|
41
|
+
digestJointGraph,
|
|
38
42
|
exchange,
|
|
39
|
-
familyOfSwapId,
|
|
40
43
|
formatAssetId,
|
|
41
|
-
fromAtomicDecimal,
|
|
42
44
|
isAssetId,
|
|
43
|
-
|
|
45
|
+
isBtcAsset,
|
|
46
|
+
isBtcAssetLenient,
|
|
44
47
|
isNetworkRef,
|
|
45
48
|
isSwapError,
|
|
46
49
|
isTerminalStatus,
|
|
@@ -49,21 +52,28 @@ import {
|
|
|
49
52
|
parseAssetId,
|
|
50
53
|
pay,
|
|
51
54
|
paymentStatusOf,
|
|
52
|
-
|
|
55
|
+
quoteMeta,
|
|
53
56
|
railAvailable,
|
|
54
57
|
railOf,
|
|
55
58
|
receive,
|
|
56
59
|
receiverExact,
|
|
57
60
|
sameAsset,
|
|
58
61
|
swapHandle,
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
unsignedPsbtBytes,
|
|
63
|
+
verifyJointGraph,
|
|
64
|
+
verifyOfferFillPlan
|
|
65
|
+
} from "./chunk-YHESEL4I.js";
|
|
61
66
|
import {
|
|
62
|
-
|
|
67
|
+
Amount,
|
|
68
|
+
AmountFormatError,
|
|
69
|
+
assetSwapIdOf,
|
|
70
|
+
familyOfSwapId,
|
|
71
|
+
fromAtomicDecimal,
|
|
72
|
+
isAtomicDecimal,
|
|
63
73
|
isRfqSwapTerminal,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
} from "./chunk-
|
|
74
|
+
quoteIdOfSwapId,
|
|
75
|
+
toAtomicDecimal
|
|
76
|
+
} from "./chunk-T4FHBWZI.js";
|
|
67
77
|
import {
|
|
68
78
|
CLAIM_PACKET_TYPE,
|
|
69
79
|
LockupRegistrationFailed,
|
|
@@ -73,25 +83,31 @@ import {
|
|
|
73
83
|
appendArkadeScript,
|
|
74
84
|
claimPacketShape,
|
|
75
85
|
isRfqRefusalErrorCode
|
|
76
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-FMRAV77W.js";
|
|
77
87
|
import {
|
|
78
88
|
InMemoryAssetSwapRepository,
|
|
89
|
+
assertRfqSwapPageFilter,
|
|
79
90
|
marketsCacheKey
|
|
80
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-A3SHHRX4.js";
|
|
81
92
|
|
|
82
93
|
// src/indexedDbRepository.ts
|
|
83
94
|
import {
|
|
84
95
|
awaitTransaction,
|
|
85
96
|
createManagedConnection,
|
|
86
|
-
promisifyRequest
|
|
97
|
+
promisifyRequest,
|
|
98
|
+
assertPageRequest,
|
|
99
|
+
pageResult
|
|
87
100
|
} from "@arkade-os/sdk";
|
|
88
101
|
var DEFAULT_DB_NAME = "arkade-intents";
|
|
89
|
-
var DB_VERSION =
|
|
102
|
+
var DB_VERSION = 5;
|
|
90
103
|
var STORE_SWAPS = "swaps";
|
|
91
104
|
var STORE_RFQ_SWAPS = "rfqSwaps";
|
|
92
105
|
var STORE_SWAP_RECORDS = "swapRecords";
|
|
93
106
|
var STORE_SCANNED = "scannedTxids";
|
|
94
107
|
var STORE_MARKETS = "markets";
|
|
108
|
+
var STATE_HISTORY_INDEX = "byStateUpdatedAtAndRfqId";
|
|
109
|
+
var HISTORY_INDEX = "byUpdatedAtAndRfqId";
|
|
110
|
+
var LEGACY_STATE_ID_INDEX = "byStateAndRfqId";
|
|
95
111
|
var STORES = [
|
|
96
112
|
[STORE_SWAPS, { keyPath: "id" }],
|
|
97
113
|
// v2. Separate from `swaps` rather than sharing it: the two record types
|
|
@@ -105,12 +121,19 @@ var STORES = [
|
|
|
105
121
|
[STORE_SCANNED],
|
|
106
122
|
[STORE_MARKETS]
|
|
107
123
|
];
|
|
108
|
-
function initDatabase(db,
|
|
109
|
-
void oldVersion;
|
|
110
|
-
void transaction;
|
|
124
|
+
function initDatabase(db, _oldVersion, transaction) {
|
|
111
125
|
for (const [name, options] of STORES) {
|
|
112
126
|
if (!db.objectStoreNames.contains(name)) db.createObjectStore(name, options);
|
|
113
127
|
}
|
|
128
|
+
if (!transaction) throw new Error("IndexedDB upgrade transaction is missing");
|
|
129
|
+
const rfq = transaction.objectStore(STORE_RFQ_SWAPS);
|
|
130
|
+
if (!rfq.indexNames.contains(STATE_HISTORY_INDEX)) {
|
|
131
|
+
rfq.createIndex(STATE_HISTORY_INDEX, ["state", "updatedAt", "rfqId"]);
|
|
132
|
+
}
|
|
133
|
+
if (!rfq.indexNames.contains(HISTORY_INDEX)) {
|
|
134
|
+
rfq.createIndex(HISTORY_INDEX, ["updatedAt", "rfqId"]);
|
|
135
|
+
}
|
|
136
|
+
if (rfq.indexNames.contains(LEGACY_STATE_ID_INDEX)) rfq.deleteIndex(LEGACY_STATE_ID_INDEX);
|
|
114
137
|
}
|
|
115
138
|
var IndexedDbAssetSwapRepository = class {
|
|
116
139
|
version = 5;
|
|
@@ -138,8 +161,8 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
138
161
|
store.put(swap);
|
|
139
162
|
});
|
|
140
163
|
}
|
|
141
|
-
async
|
|
142
|
-
return
|
|
164
|
+
async getAssetSwapsPage(page) {
|
|
165
|
+
return this.pageStore(STORE_SWAPS, page);
|
|
143
166
|
}
|
|
144
167
|
async saveRfqSwap(record) {
|
|
145
168
|
await this.write(STORE_RFQ_SWAPS, (store) => {
|
|
@@ -149,8 +172,44 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
149
172
|
async getRfqSwap(rfqId) {
|
|
150
173
|
return promisifyRequest((await this.readStore(STORE_RFQ_SWAPS)).get(rfqId));
|
|
151
174
|
}
|
|
152
|
-
async
|
|
153
|
-
|
|
175
|
+
async getRfqSwapsPage(filter, page) {
|
|
176
|
+
assertPageRequest(page);
|
|
177
|
+
assertRfqSwapPageFilter(filter);
|
|
178
|
+
const store = await this.readStore(STORE_RFQ_SWAPS);
|
|
179
|
+
const state = filter.state;
|
|
180
|
+
const index = store.index(state === void 0 ? HISTORY_INDEX : STATE_HISTORY_INDEX);
|
|
181
|
+
const after = page.after;
|
|
182
|
+
const useAfter = after !== void 0 && after.updatedAt >= (filter.since ?? 0);
|
|
183
|
+
const start = state === void 0 ? [] : [state];
|
|
184
|
+
const range = useAfter ? IDBKeyRange.lowerBound([...start, after.updatedAt, after.rfqId], true) : IDBKeyRange.lowerBound([...start, filter.since ?? 0]);
|
|
185
|
+
const request = index.openCursor(range);
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
const rows = [];
|
|
188
|
+
request.onerror = () => reject(request.error);
|
|
189
|
+
request.onsuccess = () => {
|
|
190
|
+
const cursor = request.result;
|
|
191
|
+
if (!cursor || state !== void 0 && cursor.key[0] !== state) {
|
|
192
|
+
resolve(
|
|
193
|
+
pageResult(rows, page.limit, (row) => ({
|
|
194
|
+
updatedAt: row.updatedAt,
|
|
195
|
+
rfqId: row.rfqId
|
|
196
|
+
}))
|
|
197
|
+
);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
rows.push(cursor.value);
|
|
201
|
+
if (rows.length > page.limit) {
|
|
202
|
+
resolve(
|
|
203
|
+
pageResult(rows, page.limit, (row) => ({
|
|
204
|
+
updatedAt: row.updatedAt,
|
|
205
|
+
rfqId: row.rfqId
|
|
206
|
+
}))
|
|
207
|
+
);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
cursor.continue();
|
|
211
|
+
};
|
|
212
|
+
});
|
|
154
213
|
}
|
|
155
214
|
async removeRfqSwap(rfqId) {
|
|
156
215
|
await this.write(STORE_RFQ_SWAPS, (store) => {
|
|
@@ -165,8 +224,38 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
165
224
|
async getSwapRecord(id) {
|
|
166
225
|
return promisifyRequest((await this.readStore(STORE_SWAP_RECORDS)).get(id));
|
|
167
226
|
}
|
|
168
|
-
async
|
|
169
|
-
return
|
|
227
|
+
async getSwapRecordsPage(page) {
|
|
228
|
+
return this.pageStore(STORE_SWAP_RECORDS, page);
|
|
229
|
+
}
|
|
230
|
+
async pageStore(name, page) {
|
|
231
|
+
assertPageRequest(page);
|
|
232
|
+
const store = await this.readStore(name);
|
|
233
|
+
const range = page.after === void 0 ? void 0 : IDBKeyRange.lowerBound(page.after, true);
|
|
234
|
+
const request = store.openCursor(range);
|
|
235
|
+
return new Promise((resolve, reject) => {
|
|
236
|
+
const rows = [];
|
|
237
|
+
request.onerror = () => reject(request.error);
|
|
238
|
+
request.onsuccess = () => {
|
|
239
|
+
const cursor = request.result;
|
|
240
|
+
if (!cursor) {
|
|
241
|
+
resolve(this.resultOfPage(rows, page.limit));
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
rows.push({ key: cursor.key, value: cursor.value });
|
|
245
|
+
if (rows.length > page.limit) {
|
|
246
|
+
resolve(this.resultOfPage(rows, page.limit));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
cursor.continue();
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
resultOfPage(rows, limit) {
|
|
254
|
+
const result = pageResult(rows, limit, (row) => row.key);
|
|
255
|
+
return {
|
|
256
|
+
items: result.items.map((row) => row.value),
|
|
257
|
+
...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
|
|
258
|
+
};
|
|
170
259
|
}
|
|
171
260
|
async removeSwapRecord(id) {
|
|
172
261
|
await this.write(STORE_SWAP_RECORDS, (store) => {
|
|
@@ -206,124 +295,6 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
206
295
|
}
|
|
207
296
|
};
|
|
208
297
|
|
|
209
|
-
// src/restoreRepository.ts
|
|
210
|
-
var isOpen = (swap) => swap.status === "pending" || swap.status === "cancelling";
|
|
211
|
-
var isOfferSwap = (swap) => typeof swap.offerHex === "string";
|
|
212
|
-
var restoreCoverage = async (wallet, swaps) => {
|
|
213
|
-
const offers = swaps.filter(isOfferSwap);
|
|
214
|
-
if (offers.length > 0) await restoreOfferCoverage(wallet, offers);
|
|
215
|
-
};
|
|
216
|
-
var aborted = (swaps) => ({
|
|
217
|
-
swaps,
|
|
218
|
-
changes: [],
|
|
219
|
-
scannedTxids: [],
|
|
220
|
-
aborted: true
|
|
221
|
-
});
|
|
222
|
-
async function restoreAssetSwapRepository(opts) {
|
|
223
|
-
const { wallet, indexer, repository, txs, operatorPubkey, prepareNew, signal } = opts;
|
|
224
|
-
const [existing, scanned] = await Promise.all([
|
|
225
|
-
getAssetSwapsOrThrow(repository),
|
|
226
|
-
repository.getScannedTxids()
|
|
227
|
-
]);
|
|
228
|
-
if (signal?.aborted) return aborted(existing);
|
|
229
|
-
let scan;
|
|
230
|
-
try {
|
|
231
|
-
scan = await restoreAssetSwaps(indexer, txs, new Set(existing.map((swap) => swap.id)), {
|
|
232
|
-
operatorPubkey,
|
|
233
|
-
scanned,
|
|
234
|
-
reopen: existing.filter((swap) => isOpen(swap) && isOfferSwap(swap))
|
|
235
|
-
});
|
|
236
|
-
} catch (scanError) {
|
|
237
|
-
if (!signal?.aborted) {
|
|
238
|
-
try {
|
|
239
|
-
await restoreCoverage(wallet, existing);
|
|
240
|
-
} catch (coverageError2) {
|
|
241
|
-
throw new AggregateError(
|
|
242
|
-
[scanError, coverageError2],
|
|
243
|
-
"asset-swap scan and covenant coverage restore both failed"
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
throw scanError;
|
|
248
|
-
}
|
|
249
|
-
if (signal?.aborted) return aborted(existing);
|
|
250
|
-
const before = new Map(existing.map((swap) => [swap.id, swap]));
|
|
251
|
-
const changes = [];
|
|
252
|
-
const cancelledAfterCommit = async (scannedTxids = []) => ({
|
|
253
|
-
swaps: await getAssetSwapsOrThrow(repository),
|
|
254
|
-
changes,
|
|
255
|
-
scannedTxids,
|
|
256
|
-
aborted: true
|
|
257
|
-
});
|
|
258
|
-
for (const restored of scan.restored) {
|
|
259
|
-
if (signal?.aborted) return cancelledAfterCommit();
|
|
260
|
-
const previous = before.get(restored.id);
|
|
261
|
-
const current = previous !== void 0 || !prepareNew ? restored : await prepareNew(restored);
|
|
262
|
-
if (current.id !== restored.id) {
|
|
263
|
-
throw new Error("prepareNew must not change an asset swap id");
|
|
264
|
-
}
|
|
265
|
-
if (signal?.aborted) return cancelledAfterCommit();
|
|
266
|
-
await repository.saveSwap(current);
|
|
267
|
-
changes.push(previous ? { previous, current } : { current });
|
|
268
|
-
if (signal?.aborted) return cancelledAfterCommit();
|
|
269
|
-
}
|
|
270
|
-
if (signal?.aborted) return cancelledAfterCommit();
|
|
271
|
-
if (scan.scannedTxids.length > 0) {
|
|
272
|
-
await repository.markTxidsScanned(scan.scannedTxids);
|
|
273
|
-
}
|
|
274
|
-
const swaps = await getAssetSwapsOrThrow(repository);
|
|
275
|
-
if (signal?.aborted) return cancelledAfterCommit(scan.scannedTxids);
|
|
276
|
-
let coverageError;
|
|
277
|
-
try {
|
|
278
|
-
await restoreCoverage(wallet, swaps);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
coverageError = error;
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
swaps,
|
|
284
|
-
changes,
|
|
285
|
-
scannedTxids: scan.scannedTxids,
|
|
286
|
-
aborted: false,
|
|
287
|
-
...coverageError === void 0 ? {} : { coverageError }
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// src/registerRestore.ts
|
|
292
|
-
import { hex } from "@scure/base";
|
|
293
|
-
import {
|
|
294
|
-
registerWalletRestoreHook,
|
|
295
|
-
toXOnlySignerHex
|
|
296
|
-
} from "@arkade-os/sdk";
|
|
297
|
-
var toRestoreTx = (tx) => ({
|
|
298
|
-
type: tx.type.toLowerCase(),
|
|
299
|
-
redeemTxid: tx.key.arkTxid,
|
|
300
|
-
boardingTxid: tx.key.boardingTxid,
|
|
301
|
-
roundTxid: tx.key.commitmentTxid,
|
|
302
|
-
createdAt: Math.floor(tx.createdAt / 1e3)
|
|
303
|
-
});
|
|
304
|
-
function registerAssetSwapRestore(wallet, options) {
|
|
305
|
-
return registerWalletRestoreHook(wallet, {
|
|
306
|
-
id: "arkade-os:asset-swap",
|
|
307
|
-
restore: async (restoredWallet) => {
|
|
308
|
-
const [history, indexer, info] = await Promise.all([
|
|
309
|
-
restoredWallet.getTransactionHistory(),
|
|
310
|
-
options.indexer ?? restoredWallet.getArkadeReader(),
|
|
311
|
-
options.operatorPubkey ? void 0 : restoredWallet.getArkadeInfo({ requireLive: true })
|
|
312
|
-
]);
|
|
313
|
-
const operatorPubkey = options.operatorPubkey ?? hex.decode(toXOnlySignerHex(info.signerPubkey));
|
|
314
|
-
const result = await restoreAssetSwapRepository({
|
|
315
|
-
wallet: restoredWallet,
|
|
316
|
-
indexer,
|
|
317
|
-
repository: options.repository,
|
|
318
|
-
txs: history.map(toRestoreTx),
|
|
319
|
-
operatorPubkey,
|
|
320
|
-
prepareNew: options.prepareNew
|
|
321
|
-
});
|
|
322
|
-
await options.onResult?.(result);
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
298
|
// src/payment/lightning.ts
|
|
328
299
|
import { assertNoAssets, assetsOf, invoiceTarget } from "@arkade-os/sdk";
|
|
329
300
|
var LIGHTNING_RAIL = "lightning";
|
|
@@ -334,8 +305,7 @@ var inputFor = (invoice, amount) => ({
|
|
|
334
305
|
function lightningRail(client) {
|
|
335
306
|
return {
|
|
336
307
|
id: LIGHTNING_RAIL,
|
|
337
|
-
//
|
|
338
|
-
// keeps `match` from being a second gate on top of `available`.
|
|
308
|
+
// classification only, so `match` is not a second gate on top of `available`
|
|
339
309
|
match: (req) => invoiceTarget(req.raw) !== void 0,
|
|
340
310
|
available: async (req) => {
|
|
341
311
|
if (assetsOf(req).length > 0) return false;
|
|
@@ -358,18 +328,7 @@ function lightningRail(client) {
|
|
|
358
328
|
return {
|
|
359
329
|
railId: LIGHTNING_RAIL,
|
|
360
330
|
...amounts,
|
|
361
|
-
meta:
|
|
362
|
-
quoteId: quote.id,
|
|
363
|
-
// A `RouteQuote` carries no expiry of its own, so a held one
|
|
364
|
-
// can outlive the terms behind it. This is where a caller
|
|
365
|
-
// can see that; `send()` refuses with `QuoteExpired` rather
|
|
366
|
-
// than silently re-quoting.
|
|
367
|
-
expiresAt: quote.expiresAt,
|
|
368
|
-
...quote.refundLocktime === void 0 ? {} : { refundLocktime: quote.refundLocktime },
|
|
369
|
-
...quote.solver === void 0 ? {} : { solver: quote.solver },
|
|
370
|
-
...quote.lock === void 0 ? {} : { paymentHash: quote.lock.hash },
|
|
371
|
-
market: quote.market.key
|
|
372
|
-
},
|
|
331
|
+
meta: quoteMeta(quote),
|
|
373
332
|
send: () => swapHandle(LIGHTNING_RAIL, client, quote)
|
|
374
333
|
};
|
|
375
334
|
}
|
|
@@ -388,12 +347,7 @@ function createSwapPaymentRouter(wallet, client, config) {
|
|
|
388
347
|
return new Router({
|
|
389
348
|
wallet,
|
|
390
349
|
prefs: { priority: [...SWAP_ROUTER_PRIORITY], ...config.prefs }
|
|
391
|
-
}).use(arkRail()).use(onchainRail({ feeInfo: walletFeeSource(wallet) })).use(lightningRail(client)).use(
|
|
392
|
-
onchainSwapRail(client, {
|
|
393
|
-
claimFeeRateSatVb: config.claimFeeRateSatVb,
|
|
394
|
-
...config.claimVsize === void 0 ? {} : { claimVsize: config.claimVsize }
|
|
395
|
-
})
|
|
396
|
-
);
|
|
350
|
+
}).use(arkRail()).use(onchainRail({ feeInfo: walletFeeSource(wallet) })).use(lightningRail(client)).use(onchainSwapRail(client, config));
|
|
397
351
|
}
|
|
398
352
|
export {
|
|
399
353
|
ARKADE_ASSET_NAMESPACE,
|
|
@@ -408,6 +362,7 @@ export {
|
|
|
408
362
|
BTC_ASSET_PART,
|
|
409
363
|
CLAIM_PACKET_TYPE,
|
|
410
364
|
ClientDisposed,
|
|
365
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|
|
411
366
|
DiscoverySnapshotUnavailable,
|
|
412
367
|
InMemoryAssetSwapRepository,
|
|
413
368
|
InconsistentRoute,
|
|
@@ -418,6 +373,8 @@ export {
|
|
|
418
373
|
MaxFeeExceeded,
|
|
419
374
|
MissingCorridorDep,
|
|
420
375
|
NotCancellable,
|
|
376
|
+
OFFER_FILL_OWNERS,
|
|
377
|
+
OFFER_FILL_TEMPLATE,
|
|
421
378
|
ONCHAIN_SWAP_RAIL,
|
|
422
379
|
OperatorUnreachable,
|
|
423
380
|
PAYMENT_STATUS,
|
|
@@ -438,18 +395,24 @@ export {
|
|
|
438
395
|
assetPartOf,
|
|
439
396
|
assetSwapIdOf,
|
|
440
397
|
bitcoinNetworkOf,
|
|
398
|
+
btcAssetPart,
|
|
441
399
|
btcOn,
|
|
400
|
+
buildOfferFillPlan,
|
|
442
401
|
canonicalAssetId,
|
|
443
402
|
claimFeeSats,
|
|
444
403
|
claimPacketShape,
|
|
445
404
|
createSwapClient,
|
|
446
405
|
createSwapPaymentRouter,
|
|
406
|
+
deepFreeze,
|
|
407
|
+
digestJointGraph,
|
|
447
408
|
exchange,
|
|
448
409
|
familyOfSwapId,
|
|
449
410
|
formatAssetId,
|
|
450
411
|
fromAtomicDecimal,
|
|
451
412
|
isAssetId,
|
|
452
413
|
isAtomicDecimal,
|
|
414
|
+
isBtcAsset,
|
|
415
|
+
isBtcAssetLenient,
|
|
453
416
|
isNetworkRef,
|
|
454
417
|
isRfqRefusalErrorCode,
|
|
455
418
|
isRfqSwapTerminal,
|
|
@@ -466,9 +429,10 @@ export {
|
|
|
466
429
|
railOf,
|
|
467
430
|
receive,
|
|
468
431
|
receiverExact,
|
|
469
|
-
registerAssetSwapRestore,
|
|
470
|
-
restoreAssetSwapRepository,
|
|
471
432
|
sameAsset,
|
|
472
433
|
swapHandle,
|
|
473
|
-
toAtomicDecimal
|
|
434
|
+
toAtomicDecimal,
|
|
435
|
+
unsignedPsbtBytes,
|
|
436
|
+
verifyJointGraph,
|
|
437
|
+
verifyOfferFillPlan
|
|
474
438
|
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { C as CoverageRegistrationOptions } from './offer-BPD2ortO.js';
|
|
2
|
+
import { VHTLC, IContractManager } from '@arkade-os/sdk';
|
|
3
|
+
|
|
4
|
+
interface SealedClaimPacket {
|
|
5
|
+
/** `ephPub(33) ‖ nonce(12) ‖ ciphertext`, base64 (93 bytes decoded). The legacy
|
|
6
|
+
* `claim_packet` shape: usable only via covclaimd's Reveal API, which silently
|
|
7
|
+
* needs both sides on the SAME covclaimd, and opens only beside the same `min_amount`
|
|
8
|
+
* when sealed with one. Prefer {@link SealedClaimPacket.packet}. */
|
|
9
|
+
ciphertext: string;
|
|
10
|
+
/**
|
|
11
|
+
* covclaimd's serialised `ClaimPacket` body, base64: TLV `0x01` ciphertext and `0x03`
|
|
12
|
+
* covclaimd_pub_key. **This is what `claim_packet` should carry** (§ 7.1.2). The
|
|
13
|
+
* solver stamps it as Arkade extension packet `0x04`; covclaimd filters on `0x03`, so
|
|
14
|
+
* the client alone chooses which covclaimd.
|
|
15
|
+
*
|
|
16
|
+
* `0x02` arkade_script is deliberately absent: the covenant commits to
|
|
17
|
+
* `taggedHash("ArkScriptHash", script)`, so only the funder's copy is guaranteed to
|
|
18
|
+
* match (see {@link appendArkadeScript}); a client-derived one could strand the claim.
|
|
19
|
+
*/
|
|
20
|
+
packet: string;
|
|
21
|
+
}
|
|
22
|
+
interface ClaimPacketInput {
|
|
23
|
+
preimage: Uint8Array;
|
|
24
|
+
/** covclaimd's public key, 33-byte compressed (from its /v1 info). */
|
|
25
|
+
covclaimdPubkey: Uint8Array;
|
|
26
|
+
/** Sats the funded lockup must carry for covclaimd to claim it, as TLV `0x04` and in the
|
|
27
|
+
* AEAD's additional data so a courier cannot strip it. Unset: the unbound legacy bytes. */
|
|
28
|
+
minAmount?: bigint;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Seal a preimage to covclaimd.
|
|
32
|
+
*
|
|
33
|
+
* The ephemeral key and nonce CANNOT be caller-supplied: AES-GCM under a repeated
|
|
34
|
+
* (key, nonce) pair is a total break (forgery and plaintext recovery).
|
|
35
|
+
*/
|
|
36
|
+
declare function sealClaimPacket(input: ClaimPacketInput): Promise<SealedClaimPacket>;
|
|
37
|
+
/** `ephPub(33) ‖ nonce(12) ‖ preimage(32) ‖ GCM tag(16)`. Distinguishes the two
|
|
38
|
+
* `claim_packet` shapes: a TLV body carrying it is ≥96 bytes, so lengths cannot collide. */
|
|
39
|
+
declare const SEALED_CIPHERTEXT_LENGTH = 93;
|
|
40
|
+
/** The Arkade extension packet type covclaimd scans the arkd tx stream for. */
|
|
41
|
+
declare const CLAIM_PACKET_TYPE = 4;
|
|
42
|
+
/**
|
|
43
|
+
* Stamp the covenant script into a client's packet — the solver's half.
|
|
44
|
+
*
|
|
45
|
+
* Appending rather than rebuilding is safe: covclaimd's `DeserializeClaim` is
|
|
46
|
+
* order-agnostic, so `0x01, 0x03, 0x02` reads back like its own `0x01, 0x02, 0x03`.
|
|
47
|
+
*/
|
|
48
|
+
declare const appendArkadeScript: (body: Uint8Array, arkadeScript: Uint8Array) => Uint8Array;
|
|
49
|
+
type ClaimPacketShape = {
|
|
50
|
+
kind: "ciphertext";
|
|
51
|
+
} | {
|
|
52
|
+
kind: "packet";
|
|
53
|
+
body: Uint8Array;
|
|
54
|
+
covclaimdPubkey?: Uint8Array;
|
|
55
|
+
needsArkadeScript: boolean;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Which of the two `claim_packet` shapes a base64 field carries.
|
|
59
|
+
*
|
|
60
|
+
* Never throws: anything not unambiguously a packet reads as the legacy ciphertext,
|
|
61
|
+
* keeping the Reveal-API path rather than failing a swap over an unfamiliar field.
|
|
62
|
+
*/
|
|
63
|
+
declare const claimPacketShape: (b64: string) => ClaimPacketShape;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The contract row an RFQ lockup registers as — one definition, two writers (`request*Send` and
|
|
67
|
+
* `RfqSwapManager.ensureRegistered`). `createContract` is first-writer-wins, so the second write
|
|
68
|
+
* is a no-op only while both write the SAME row, hence this module.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/** The contract type a swap lockup registers under: the SDK's handler for `VHTLC.ScriptV2`.
|
|
72
|
+
*
|
|
73
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
74
|
+
*/
|
|
75
|
+
declare const SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
|
|
76
|
+
/** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
|
|
77
|
+
declare const SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
|
|
78
|
+
/** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
|
|
79
|
+
declare const SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
|
|
80
|
+
/** The write seam registration needs; a real `ContractManager` satisfies it.
|
|
81
|
+
*
|
|
82
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
83
|
+
*/
|
|
84
|
+
type LockupContractWriter = Pick<IContractManager, "createContract">;
|
|
85
|
+
/** The read seam {@link lockupContractParams} needs.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
88
|
+
*/
|
|
89
|
+
type LockupContractReader = Pick<IContractManager, "getContracts">;
|
|
90
|
+
/**
|
|
91
|
+
* No row for a lockup a record claims was funded. The record is fine and its money may be at the
|
|
92
|
+
* address; the wallet's copy of the covenant is missing (store cleared, or a different store
|
|
93
|
+
* registered it). The remedy is a store, not a re-quote.
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
96
|
+
*/
|
|
97
|
+
declare class LockupContractMissing extends Error {
|
|
98
|
+
/** The lockup whose row is absent. */
|
|
99
|
+
readonly address: string;
|
|
100
|
+
/** Its pkScript hex — the key the row would have been under. */
|
|
101
|
+
readonly script: string;
|
|
102
|
+
constructor(address: string, script: string);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The lockup could not be written locally: "the quote is fine and your own store failed", unlike
|
|
106
|
+
* {@link SwapRefusal} / {@link AddressMismatch} ("never fund it"). Thrown by `client.accept()`.
|
|
107
|
+
*
|
|
108
|
+
* Nothing is funded yet and on receive legs the invoice never left, so retrying the request is
|
|
109
|
+
* the recovery. `script` lets a caller still holding the swap retry `registerLockupContract`
|
|
110
|
+
* alone; it is NOT enough to resume a request that threw here (no invoice or `secrets`).
|
|
111
|
+
*/
|
|
112
|
+
declare class LockupRegistrationFailed extends Error {
|
|
113
|
+
/** The lockup address that was never registered — never fund it: nothing
|
|
114
|
+
* is watching it. */
|
|
115
|
+
readonly address: string;
|
|
116
|
+
/** The covenant the row would have been written from, so the write is retryable without a
|
|
117
|
+
* quote. */
|
|
118
|
+
readonly script: InstanceType<typeof VHTLC.ScriptV2>;
|
|
119
|
+
constructor(script: InstanceType<typeof VHTLC.ScriptV2>, address: string, cause: unknown);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Register a lockup covenant so its VTXOs are watched and — via `vhtlc-v2`'s handler, never
|
|
123
|
+
* generically spendable — kept out of ordinary coin selection.
|
|
124
|
+
*
|
|
125
|
+
* The row carries script-level facts only: rows are keyed by script and first-writer-wins, so
|
|
126
|
+
* anything per-swap written here is stale from the second swap onward. Taking the derived script
|
|
127
|
+
* means the row cannot describe a script other than its key.
|
|
128
|
+
*
|
|
129
|
+
* @throws {LockupRegistrationFailed} so a caller can tell local storage trouble from a bad quote.
|
|
130
|
+
*
|
|
131
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
132
|
+
*/
|
|
133
|
+
declare function registerLockupContract(contracts: LockupContractWriter, script: InstanceType<typeof VHTLC.ScriptV2>, address: string, options?: CoverageRegistrationOptions): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* The stored covenant parameters of a funded lockup — the other half of `rebuildRfqSwap`. The row
|
|
136
|
+
* is the wallet's own copy of the tree (`createContract` refuses params that do not reproduce the
|
|
137
|
+
* script), which is why an RFQ swap record stores no tree parameters.
|
|
138
|
+
*
|
|
139
|
+
* Looked up by script, decoded from the address here, so a bad address fails as such rather than
|
|
140
|
+
* as a missing row.
|
|
141
|
+
*
|
|
142
|
+
* @throws {LockupContractMissing} when there is no row.
|
|
143
|
+
*
|
|
144
|
+
* @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
|
|
145
|
+
*/
|
|
146
|
+
declare function lockupContractParams(contracts: LockupContractReader, lockupAddress: string): Promise<Record<string, string>>;
|
|
147
|
+
|
|
148
|
+
export { CLAIM_PACKET_TYPE as C, LockupRegistrationFailed as L, SEALED_CIPHERTEXT_LENGTH as S, type ClaimPacketShape as a, appendArkadeScript as b, claimPacketShape as c, type ClaimPacketInput as d, LockupContractMissing as e, type LockupContractReader as f, type LockupContractWriter as g, SWAP_LOCKUP_CONTRACT_KIND as h, SWAP_LOCKUP_CONTRACT_LABEL as i, SWAP_LOCKUP_CONTRACT_TYPE as j, type SealedClaimPacket as k, lockupContractParams as l, registerLockupContract as r, sealClaimPacket as s };
|