@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.
- package/dist/advanced.cjs +1097 -541
- package/dist/advanced.d.cts +19 -21
- package/dist/advanced.d.ts +19 -21
- package/dist/advanced.js +40 -34
- package/dist/{chunk-FQNG4XMF.js → chunk-2HQZLIVX.js} +98 -37
- package/dist/{chunk-5QPJWOCN.js → chunk-6RJVT65W.js} +2 -0
- package/dist/chunk-AUJDREZN.js +445 -0
- package/dist/{chunk-I7WEXXZX.js → chunk-FWRDAL73.js} +157 -477
- package/dist/{chunk-552GDPBU.js → chunk-LCO6AJOS.js} +433 -59
- package/dist/index.cjs +1083 -530
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +24 -22
- package/dist/{lockupContract-DguuT7NK.d.cts → lockupContract-BTTRVwOt.d.cts} +1 -1
- package/dist/{lockupContract-BUOsghl1.d.ts → lockupContract-aFarhlxj.d.ts} +1 -1
- package/dist/node/index.d.cts +97 -67
- package/dist/node/index.d.ts +97 -67
- package/dist/nostr.cjs +925 -516
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +3 -2
- package/dist/{offerFillPlan-_AOLo6kh.d.ts → offerFillPlan-CJC5tnEd.d.ts} +10 -42
- package/dist/{offerFillPlan-Bp6-z6dS.d.cts → offerFillPlan-FmyaQoYT.d.cts} +10 -42
- package/dist/protocol.cjs +1054 -175
- package/dist/protocol.d.cts +42 -23
- package/dist/protocol.d.ts +42 -23
- package/dist/protocol.js +20 -7
- package/dist/repositories/realm/index.d.cts +3 -2
- package/dist/repositories/realm/index.d.ts +3 -2
- package/dist/repositories/sqlite/index.d.cts +3 -2
- package/dist/repositories/sqlite/index.d.ts +3 -2
- package/dist/{repository-CkKK0dGO.d.ts → repository-CwwhIAEd.d.cts} +406 -74
- package/dist/{repository--pfikw2R.d.cts → repository-DO6QKxBx.d.ts} +406 -74
- package/dist/{rfq-IzhOCG02.d.ts → rfq-CYxOyniL.d.ts} +52 -11
- package/dist/rfq-contract.cjs +3 -0
- package/dist/rfq-contract.d.cts +3 -1
- package/dist/rfq-contract.d.ts +3 -1
- package/dist/rfq-contract.js +3 -1
- package/dist/{rfq-BRpo5uWU.d.cts → rfq-nMGywkqI.d.cts} +52 -11
- package/dist/verify-ENO36VPK.js +33 -0
- package/dist/{watch-pvTVFp6-.d.cts → watch-DpDSP2tu.d.cts} +4 -3
- package/dist/{watch-DDNycuUa.d.ts → watch-_fZSgx_l.d.ts} +4 -3
- package/package.json +2 -2
- package/dist/offer-BhonWuKR.d.ts +0 -274
- package/dist/offer-D_qHpWo2.d.cts +0 -274
|
@@ -62,12 +62,41 @@ import {
|
|
|
62
62
|
undeliveredCarry,
|
|
63
63
|
walletOperator,
|
|
64
64
|
watchOfferSwaps
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-2HQZLIVX.js";
|
|
66
|
+
import {
|
|
67
|
+
AcceptConflict,
|
|
68
|
+
AmbiguousDestination,
|
|
69
|
+
AmountEncodingUnsupported,
|
|
70
|
+
AmountMismatch,
|
|
71
|
+
ClientDisposed,
|
|
72
|
+
DiscoverySnapshotUnavailable,
|
|
73
|
+
InsufficientFunds,
|
|
74
|
+
MaxFeeExceeded,
|
|
75
|
+
MissingCorridorDep,
|
|
76
|
+
NotCancellable,
|
|
77
|
+
OperatorUnreachable,
|
|
78
|
+
QuoteExpired,
|
|
79
|
+
QuoteVerificationFailed,
|
|
80
|
+
UnsupportedRoute,
|
|
81
|
+
isSwapError,
|
|
82
|
+
verifiedCarrierSats,
|
|
83
|
+
verifyCrossAssetAmount,
|
|
84
|
+
verifyPair,
|
|
85
|
+
verifyQuoteTtl,
|
|
86
|
+
verifyQuotedAmount,
|
|
87
|
+
verifyReceiveInvoiceFacts,
|
|
88
|
+
verifyReceiveWindow,
|
|
89
|
+
verifyRefundWindow,
|
|
90
|
+
verifyResponder,
|
|
91
|
+
verifySendInvoice,
|
|
92
|
+
verifySendWindow,
|
|
93
|
+
verifyTaker,
|
|
94
|
+
verifyingDerivation
|
|
95
|
+
} from "./chunk-AUJDREZN.js";
|
|
66
96
|
import {
|
|
67
97
|
ARKADE_BTC,
|
|
68
98
|
ASSET_CARRIER_SATS,
|
|
69
99
|
ASSET_SWAP_CONTRACT_VERSIONS,
|
|
70
|
-
AddressMismatch,
|
|
71
100
|
BTC_ASSET_ID,
|
|
72
101
|
L1_NETWORKS,
|
|
73
102
|
LIGHTNING_BTC,
|
|
@@ -80,12 +109,9 @@ import {
|
|
|
80
109
|
ONCHAIN_DUST_SATS,
|
|
81
110
|
OfferCovenantMismatchError,
|
|
82
111
|
RETIRABLE,
|
|
83
|
-
SwapRefusal,
|
|
84
112
|
arkadeSwapRequest,
|
|
85
113
|
assembleOfferFill,
|
|
86
|
-
assertFundable,
|
|
87
114
|
assertPairLength,
|
|
88
|
-
assertReceivable,
|
|
89
115
|
bindsClaimAmount,
|
|
90
116
|
buildHtlcRefund,
|
|
91
117
|
claimOnchainFill,
|
|
@@ -97,6 +123,7 @@ import {
|
|
|
97
123
|
deriveOffer,
|
|
98
124
|
deriveOnchainReceive,
|
|
99
125
|
deriveOnchainSend,
|
|
126
|
+
encodeOffer,
|
|
100
127
|
l1NetworkFromArk,
|
|
101
128
|
l1ScriptForAddress,
|
|
102
129
|
legacySwapPrograms,
|
|
@@ -105,13 +132,15 @@ import {
|
|
|
105
132
|
lockupContractParams,
|
|
106
133
|
newRfqId,
|
|
107
134
|
nextClaimFeeRate,
|
|
135
|
+
offerFromBinding,
|
|
136
|
+
offerOf,
|
|
108
137
|
offerTermsFromQuote,
|
|
109
138
|
onchainReceiveRequest,
|
|
110
139
|
onchainSendRequest,
|
|
111
140
|
preimageForSwapRecord,
|
|
112
141
|
prepareOfferCancel,
|
|
113
142
|
promoteOfferContract,
|
|
114
|
-
|
|
143
|
+
recordOfferBinding,
|
|
115
144
|
registerDerivedOffer,
|
|
116
145
|
registerLockupContract,
|
|
117
146
|
requestVersionedQuote,
|
|
@@ -126,10 +155,14 @@ import {
|
|
|
126
155
|
rfqSecretsProfile,
|
|
127
156
|
rfqSignerOf,
|
|
128
157
|
sealClaimPacket,
|
|
158
|
+
storedOffer,
|
|
129
159
|
unilateralClaimDelay,
|
|
130
160
|
verifyOfferAddress,
|
|
131
161
|
withExitClosure
|
|
132
|
-
} from "./chunk-
|
|
162
|
+
} from "./chunk-LCO6AJOS.js";
|
|
163
|
+
import {
|
|
164
|
+
ASSET_SWAP_V4
|
|
165
|
+
} from "./chunk-6RJVT65W.js";
|
|
133
166
|
import {
|
|
134
167
|
assertRfqSwapPageFilter,
|
|
135
168
|
collectAssetSwaps,
|
|
@@ -291,184 +324,6 @@ var issuanceOf = (id) => {
|
|
|
291
324
|
return assetNamespace === ARKADE_ASSET_NAMESPACE ? asset.AssetId.fromString(assetReference) : void 0;
|
|
292
325
|
};
|
|
293
326
|
|
|
294
|
-
// src/client/errors.ts
|
|
295
|
-
var AmbiguousDestination = class extends Error {
|
|
296
|
-
constructor(destination, detail) {
|
|
297
|
-
super(`cannot route ${JSON.stringify(destination)}: ${detail}`);
|
|
298
|
-
this.destination = destination;
|
|
299
|
-
}
|
|
300
|
-
destination;
|
|
301
|
-
name = "AmbiguousDestination";
|
|
302
|
-
};
|
|
303
|
-
var UnsupportedRoute = class extends Error {
|
|
304
|
-
name = "UnsupportedRoute";
|
|
305
|
-
give;
|
|
306
|
-
take;
|
|
307
|
-
constructor(detail, corridors = {}) {
|
|
308
|
-
super(`unsupported route: ${detail}`);
|
|
309
|
-
this.give = corridors.give;
|
|
310
|
-
this.take = corridors.take;
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
var DiscoverySnapshotUnavailable = class extends Error {
|
|
314
|
-
constructor(network, detail) {
|
|
315
|
-
super(`cannot resolve on ${network} offline: ${detail}`);
|
|
316
|
-
this.network = network;
|
|
317
|
-
}
|
|
318
|
-
network;
|
|
319
|
-
name = "DiscoverySnapshotUnavailable";
|
|
320
|
-
};
|
|
321
|
-
var AmountMismatch = class extends Error {
|
|
322
|
-
constructor(sources) {
|
|
323
|
-
super(`exactly one amount may be pinned; got ${sources[0]} and ${sources[1]}`);
|
|
324
|
-
this.sources = sources;
|
|
325
|
-
}
|
|
326
|
-
sources;
|
|
327
|
-
name = "AmountMismatch";
|
|
328
|
-
};
|
|
329
|
-
var AmountEncodingUnsupported = class extends Error {
|
|
330
|
-
constructor(field, value, detail, options) {
|
|
331
|
-
super(`${field}: ${detail}`, options);
|
|
332
|
-
this.field = field;
|
|
333
|
-
this.value = value;
|
|
334
|
-
}
|
|
335
|
-
field;
|
|
336
|
-
value;
|
|
337
|
-
name = "AmountEncodingUnsupported";
|
|
338
|
-
};
|
|
339
|
-
var QuoteVerificationFailed = class extends Error {
|
|
340
|
-
constructor(check, expected, actual, options) {
|
|
341
|
-
super(`quote failed the ${check} check \u2014 refusing to fund`, options);
|
|
342
|
-
this.check = check;
|
|
343
|
-
this.expected = expected;
|
|
344
|
-
this.actual = actual;
|
|
345
|
-
}
|
|
346
|
-
check;
|
|
347
|
-
name = "QuoteVerificationFailed";
|
|
348
|
-
expected;
|
|
349
|
-
actual;
|
|
350
|
-
};
|
|
351
|
-
var QuoteExpired = class extends Error {
|
|
352
|
-
constructor(quoteId, expiresAt, now) {
|
|
353
|
-
super(`quote ${quoteId} expired at ${expiresAt}, ${now - expiresAt} ago`);
|
|
354
|
-
this.quoteId = quoteId;
|
|
355
|
-
this.expiresAt = expiresAt;
|
|
356
|
-
this.now = now;
|
|
357
|
-
}
|
|
358
|
-
quoteId;
|
|
359
|
-
expiresAt;
|
|
360
|
-
now;
|
|
361
|
-
name = "QuoteExpired";
|
|
362
|
-
};
|
|
363
|
-
var MaxFeeExceeded = class extends Error {
|
|
364
|
-
constructor(quoteId, asset5, fee, maxFee) {
|
|
365
|
-
super(`fee ${fee} of ${asset5} exceeds the ${maxFee} ceiling`);
|
|
366
|
-
this.quoteId = quoteId;
|
|
367
|
-
this.asset = asset5;
|
|
368
|
-
this.fee = fee;
|
|
369
|
-
this.maxFee = maxFee;
|
|
370
|
-
}
|
|
371
|
-
quoteId;
|
|
372
|
-
asset;
|
|
373
|
-
fee;
|
|
374
|
-
maxFee;
|
|
375
|
-
name = "MaxFeeExceeded";
|
|
376
|
-
};
|
|
377
|
-
var InsufficientFunds = class extends Error {
|
|
378
|
-
constructor(asset5, required, available) {
|
|
379
|
-
super(
|
|
380
|
-
`funding needs ${required} of ${asset5}` + (available === void 0 ? "" : `, wallet holds ${available}`)
|
|
381
|
-
);
|
|
382
|
-
this.asset = asset5;
|
|
383
|
-
this.required = required;
|
|
384
|
-
this.available = available;
|
|
385
|
-
}
|
|
386
|
-
asset;
|
|
387
|
-
required;
|
|
388
|
-
name = "InsufficientFunds";
|
|
389
|
-
available;
|
|
390
|
-
};
|
|
391
|
-
var AcceptConflict = class extends Error {
|
|
392
|
-
constructor(quoteId, swapId, fields) {
|
|
393
|
-
super(`accept ${quoteId} conflicts with swap ${swapId} on ${fields.join(", ")}`);
|
|
394
|
-
this.quoteId = quoteId;
|
|
395
|
-
this.swapId = swapId;
|
|
396
|
-
this.fields = fields;
|
|
397
|
-
}
|
|
398
|
-
quoteId;
|
|
399
|
-
swapId;
|
|
400
|
-
fields;
|
|
401
|
-
name = "AcceptConflict";
|
|
402
|
-
};
|
|
403
|
-
var ClientDisposed = class extends Error {
|
|
404
|
-
constructor(method) {
|
|
405
|
-
super(`${method}() called after the client was disposed`);
|
|
406
|
-
this.method = method;
|
|
407
|
-
}
|
|
408
|
-
method;
|
|
409
|
-
name = "ClientDisposed";
|
|
410
|
-
};
|
|
411
|
-
var NotCancellable = class extends Error {
|
|
412
|
-
constructor(swapId) {
|
|
413
|
-
super(`swap ${swapId} is not a cancellable asset swap`);
|
|
414
|
-
this.swapId = swapId;
|
|
415
|
-
}
|
|
416
|
-
swapId;
|
|
417
|
-
name = "NotCancellable";
|
|
418
|
-
};
|
|
419
|
-
var InconsistentRoute = class extends Error {
|
|
420
|
-
constructor(asset5, destination) {
|
|
421
|
-
super(`destination ${JSON.stringify(destination)} is not on ${asset5}'s chain`);
|
|
422
|
-
this.asset = asset5;
|
|
423
|
-
this.destination = destination;
|
|
424
|
-
}
|
|
425
|
-
asset;
|
|
426
|
-
destination;
|
|
427
|
-
name = "InconsistentRoute";
|
|
428
|
-
};
|
|
429
|
-
var OperatorUnreachable = class extends Error {
|
|
430
|
-
name = "OperatorUnreachable";
|
|
431
|
-
constructor(detail, options) {
|
|
432
|
-
super(`cannot derive a covenant: ${detail}`, options);
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
var MissingCorridorDep = class extends Error {
|
|
436
|
-
constructor(corridor, dep) {
|
|
437
|
-
super(`the ${corridor} corridor has no ${dep}`);
|
|
438
|
-
this.corridor = corridor;
|
|
439
|
-
this.dep = dep;
|
|
440
|
-
}
|
|
441
|
-
corridor;
|
|
442
|
-
dep;
|
|
443
|
-
name = "MissingCorridorDep";
|
|
444
|
-
};
|
|
445
|
-
var SWAP_ERRORS = {
|
|
446
|
-
AmbiguousDestination,
|
|
447
|
-
UnsupportedRoute,
|
|
448
|
-
DiscoverySnapshotUnavailable,
|
|
449
|
-
AmountMismatch,
|
|
450
|
-
AmountEncodingUnsupported,
|
|
451
|
-
QuoteVerificationFailed,
|
|
452
|
-
SwapRefusal,
|
|
453
|
-
QuoteExpired,
|
|
454
|
-
MaxFeeExceeded,
|
|
455
|
-
InsufficientFunds,
|
|
456
|
-
AcceptConflict,
|
|
457
|
-
ClientDisposed,
|
|
458
|
-
NotCancellable,
|
|
459
|
-
InconsistentRoute,
|
|
460
|
-
OperatorUnreachable,
|
|
461
|
-
MissingCorridorDep
|
|
462
|
-
};
|
|
463
|
-
var SWAP_ERROR_NAMES = Object.keys(SWAP_ERRORS);
|
|
464
|
-
function isSwapError(e, name) {
|
|
465
|
-
if (!(e instanceof Error)) return false;
|
|
466
|
-
const table = SWAP_ERRORS;
|
|
467
|
-
const ctor = table[e.name];
|
|
468
|
-
if (ctor === void 0 || !(e instanceof ctor)) return false;
|
|
469
|
-
return name === void 0 || e.name === name;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
327
|
// src/client/aliases.ts
|
|
473
328
|
import { NETWORKS, isNetwork } from "@arkade-os/solver-discovery";
|
|
474
329
|
var toDiscoveryLeg = (id) => {
|
|
@@ -692,7 +547,7 @@ var recordedFacts = (quote) => ({
|
|
|
692
547
|
"market.source": marketSourceOf(quote.market)
|
|
693
548
|
});
|
|
694
549
|
var marketSourceOf = (market) => market.kind === "card" ? market.source : void 0;
|
|
695
|
-
var
|
|
550
|
+
var assertFundable = async (wallet, quote) => {
|
|
696
551
|
const give = quote.give;
|
|
697
552
|
const balance = await wallet.getBalance();
|
|
698
553
|
const available = isBtcAsset(give.asset) ? BigInt(balance.available) : balance.availableAssets.find((a) => give.asset.endsWith(a.assetId))?.amount ?? 0n;
|
|
@@ -815,8 +670,9 @@ var acceptQuoteBody = async (input) => {
|
|
|
815
670
|
);
|
|
816
671
|
}
|
|
817
672
|
const funds = fundsFromWallet(quote.route);
|
|
818
|
-
if (funds) await
|
|
819
|
-
const
|
|
673
|
+
if (funds) await assertFundable(wallet, quote);
|
|
674
|
+
const built = preparation.backend === "feed" ? await registeredOfferRecord(input, preparation) : preparation.route === "arkade->arkade" ? await registeredAssetRecord(input, preparation) : await registeredCorridorRecord(input, preparation);
|
|
675
|
+
const record = built.family === "offer" && input.attachOfferPacket === false ? { ...built, attachOfferPacket: false } : built;
|
|
820
676
|
await repository.saveSwapRecord(record);
|
|
821
677
|
if (!funds) return answer(record);
|
|
822
678
|
return answer(
|
|
@@ -872,7 +728,9 @@ var registeredAssetRecord = async (input, preparation) => {
|
|
|
872
728
|
...preparation.assetPayment === void 0 ? {} : { assetPayment: recordAssetPayment(preparation.assetPayment) },
|
|
873
729
|
family: "offer",
|
|
874
730
|
status: "pending",
|
|
875
|
-
|
|
731
|
+
// a directed covenant is kept as its binding alone, which an older reader drops whole
|
|
732
|
+
// rather than half-reads
|
|
733
|
+
...preparation.offer.offerBinding.taker === void 0 ? { offerHex: preparation.offer.offerHex } : { binding: recordOfferBinding(preparation.offer.offerBinding) },
|
|
876
734
|
swapAddress: preparation.offer.address,
|
|
877
735
|
swapPkScript: hex2.encode(preparation.offer.swapPkScript),
|
|
878
736
|
...preparation.carrierSats === void 0 ? {} : { carrierSats: preparation.carrierSats.toString() }
|
|
@@ -957,7 +815,7 @@ var fund = async (input, record) => {
|
|
|
957
815
|
{ assetId: toDiscoveryLeg(record.route.give.asset).assetId, amount }
|
|
958
816
|
]
|
|
959
817
|
},
|
|
960
|
-
extensions: [offerExtensionOf(record)]
|
|
818
|
+
...record.attachOfferPacket === false ? {} : { extensions: [offerExtensionOf(record)] }
|
|
961
819
|
});
|
|
962
820
|
}
|
|
963
821
|
if (record.kind === "lightning_receive" || record.kind === "onchain_receive") {
|
|
@@ -968,10 +826,13 @@ var fund = async (input, record) => {
|
|
|
968
826
|
amount: toSafeNumber(fromAtomicDecimal(record.give.amount), "give.amount")
|
|
969
827
|
});
|
|
970
828
|
};
|
|
971
|
-
var offerExtensionOf = (record) =>
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
829
|
+
var offerExtensionOf = (record) => {
|
|
830
|
+
const stored = storedOffer(record);
|
|
831
|
+
return {
|
|
832
|
+
type: OFFER_PACKET_TYPE,
|
|
833
|
+
payload: record.offerHex !== void 0 ? hex2.decode(record.offerHex) : encodeOffer("version" in stored ? offerFromBinding(stored) : stored)
|
|
834
|
+
};
|
|
835
|
+
};
|
|
975
836
|
var reconcileFunding = async (input, record) => {
|
|
976
837
|
const script = record.family === "offer" ? record.swapPkScript : record.lockupPkScript;
|
|
977
838
|
const expected = BigInt(record.give.amount);
|
|
@@ -1615,11 +1476,15 @@ var corridorRecordStore = (repository, onRecord = () => {
|
|
|
1615
1476
|
}
|
|
1616
1477
|
};
|
|
1617
1478
|
};
|
|
1479
|
+
var covenantOf = (swap) => ({
|
|
1480
|
+
...swap.offerHex === void 0 ? {} : { offerHex: swap.offerHex },
|
|
1481
|
+
...swap.binding === void 0 ? {} : { binding: swap.binding }
|
|
1482
|
+
});
|
|
1618
1483
|
var offerFactsOf = (record) => ({
|
|
1619
1484
|
id: record.id,
|
|
1620
1485
|
coverageId: record.id,
|
|
1621
1486
|
status: record.status,
|
|
1622
|
-
|
|
1487
|
+
...covenantOf(record),
|
|
1623
1488
|
swapPkScript: record.swapPkScript,
|
|
1624
1489
|
...record.fundingTxid === void 0 ? {} : { fundingTxid: record.fundingTxid },
|
|
1625
1490
|
...record.spentTxid === void 0 ? {} : { spentTxid: record.spentTxid },
|
|
@@ -1691,7 +1556,7 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
1691
1556
|
market: { kind: "restored", backend: "feed" },
|
|
1692
1557
|
expiresAt: createdAt,
|
|
1693
1558
|
status: swap.status,
|
|
1694
|
-
|
|
1559
|
+
...covenantOf(swap),
|
|
1695
1560
|
swapAddress: swap.swapAddress,
|
|
1696
1561
|
swapPkScript: swap.swapPkScript,
|
|
1697
1562
|
fundingTxid: swap.fundingTxid,
|
|
@@ -1702,6 +1567,20 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
1702
1567
|
now
|
|
1703
1568
|
);
|
|
1704
1569
|
};
|
|
1570
|
+
var reopenedDeposit = (record, fundingTxid) => ({
|
|
1571
|
+
id: fundingTxid,
|
|
1572
|
+
fromAsset: record.give.asset,
|
|
1573
|
+
toAsset: record.take.asset,
|
|
1574
|
+
fromAmount: record.give.amount,
|
|
1575
|
+
toAmount: record.take.amount,
|
|
1576
|
+
swapAddress: record.swapAddress,
|
|
1577
|
+
swapPkScript: record.swapPkScript,
|
|
1578
|
+
...covenantOf(record),
|
|
1579
|
+
fundingTxid,
|
|
1580
|
+
...record.spentTxid === void 0 ? {} : { spentTxid: record.spentTxid },
|
|
1581
|
+
status: record.status,
|
|
1582
|
+
createdAt: record.createdAt * 1e3
|
|
1583
|
+
});
|
|
1705
1584
|
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network, asset3.AssetId.fromString(id));
|
|
1706
1585
|
var RESTORED_CORRIDORS = {
|
|
1707
1586
|
lightning_send: ["arkade", "lightning"],
|
|
@@ -1759,7 +1638,7 @@ var walletLockupIndexer = (wallet) => {
|
|
|
1759
1638
|
};
|
|
1760
1639
|
|
|
1761
1640
|
// src/client/cancel.ts
|
|
1762
|
-
import { base64
|
|
1641
|
+
import { base64 } from "@scure/base";
|
|
1763
1642
|
import { ArkAddress as ArkAddress4, Transaction } from "@arkade-os/sdk";
|
|
1764
1643
|
var cancelSwap = async (input) => {
|
|
1765
1644
|
const { wallet, repository, record, drive, indexer } = input;
|
|
@@ -1768,12 +1647,13 @@ var cancelSwap = async (input) => {
|
|
|
1768
1647
|
if (outcome === "cancelled" || outcome === "filled" || outcome === "needs_recovery") {
|
|
1769
1648
|
return { outcome };
|
|
1770
1649
|
}
|
|
1771
|
-
const
|
|
1772
|
-
|
|
1773
|
-
|
|
1650
|
+
const offer = storedOffer(record);
|
|
1651
|
+
const gated = withStatus(record, "cancelling", now());
|
|
1652
|
+
await repository.saveSwapRecord(gated);
|
|
1653
|
+
drive.ingest(gated);
|
|
1774
1654
|
let prepared;
|
|
1775
1655
|
try {
|
|
1776
|
-
prepared = await prepareOfferCancel(wallet,
|
|
1656
|
+
prepared = await prepareOfferCancel(wallet, offer, {
|
|
1777
1657
|
swapAddress: record.swapAddress,
|
|
1778
1658
|
...record.fundingTxid === void 0 ? {} : { fundingTxid: record.fundingTxid }
|
|
1779
1659
|
});
|
|
@@ -1797,7 +1677,7 @@ var cancelSwap = async (input) => {
|
|
|
1797
1677
|
return { outcome: "needs_recovery" };
|
|
1798
1678
|
}
|
|
1799
1679
|
const { kind, spentTxid } = reconciled;
|
|
1800
|
-
const settled2 = withStatus(
|
|
1680
|
+
const settled2 = withStatus(gated, kind, now(), {
|
|
1801
1681
|
spentTxid,
|
|
1802
1682
|
// Mirrors the watcher: a completion time is a fill's, not a
|
|
1803
1683
|
// cancel's.
|
|
@@ -1811,7 +1691,7 @@ var cancelSwap = async (input) => {
|
|
|
1811
1691
|
throw error;
|
|
1812
1692
|
}
|
|
1813
1693
|
const txid = await prepared.send();
|
|
1814
|
-
const settled = withStatus(
|
|
1694
|
+
const settled = withStatus(gated, "cancelled", now(), { spentTxid: txid });
|
|
1815
1695
|
const { persisted } = await persistBestEffort(repository, settled);
|
|
1816
1696
|
drive.ingest(settled);
|
|
1817
1697
|
if (persisted) {
|
|
@@ -1820,7 +1700,7 @@ var cancelSwap = async (input) => {
|
|
|
1820
1700
|
return { outcome: "cancelled" };
|
|
1821
1701
|
};
|
|
1822
1702
|
var reconcileDepositSpend = async (record, indexer) => {
|
|
1823
|
-
const offer =
|
|
1703
|
+
const offer = storedOffer(record);
|
|
1824
1704
|
const { vtxos } = await indexer.getVtxos({ scripts: [record.swapPkScript] });
|
|
1825
1705
|
const all = vtxos ?? [];
|
|
1826
1706
|
const deposit = record.fundingTxid === void 0 ? all.length === 1 ? all[0] : void 0 : all.find((vtxo) => vtxo.txid === record.fundingTxid);
|
|
@@ -1882,7 +1762,7 @@ import {
|
|
|
1882
1762
|
getNetwork as getNetwork2,
|
|
1883
1763
|
identityDescriptor
|
|
1884
1764
|
} from "@arkade-os/sdk";
|
|
1885
|
-
import { hex as
|
|
1765
|
+
import { hex as hex5 } from "@scure/base";
|
|
1886
1766
|
|
|
1887
1767
|
// src/migrateOfferRows.ts
|
|
1888
1768
|
import { arkade } from "@arkade-os/sdk";
|
|
@@ -2087,7 +1967,7 @@ var readLegacyAssetSwaps = async (repository) => {
|
|
|
2087
1967
|
};
|
|
2088
1968
|
var legacyOfferDepositsToAdopt = async (repository) => {
|
|
2089
1969
|
const unadopted = (await readLegacyAssetSwaps(repository)).filter(
|
|
2090
|
-
(swap) => !!swap.offerHex && !!swap.fundingTxid
|
|
1970
|
+
(swap) => (!!swap.offerHex || !!swap.binding) && !!swap.fundingTxid
|
|
2091
1971
|
);
|
|
2092
1972
|
if (unadopted.length === 0) return /* @__PURE__ */ new Set();
|
|
2093
1973
|
const { offer } = splitRecords(await collectSwapRecords(repository));
|
|
@@ -2107,6 +1987,7 @@ var SwapDriveRefusedError = class extends Error {
|
|
|
2107
1987
|
name = "SwapDriveRefusedError";
|
|
2108
1988
|
};
|
|
2109
1989
|
var OFFER_LIVE = (status) => status === "pending" || status === "cancelling";
|
|
1990
|
+
var DIRECTED_CANCEL_GRACE_SECONDS = 60;
|
|
2110
1991
|
var traderClaimTxid = (swap) => swap.kind === "lightning_send" ? void 0 : swap.claimTxid;
|
|
2111
1992
|
var readableRecord = (record) => {
|
|
2112
1993
|
if (typeof record?.id !== "string" || record.route?.give === void 0) return false;
|
|
@@ -2120,7 +2001,7 @@ var readableRecord = (record) => {
|
|
|
2120
2001
|
if (record.family === "rfq") {
|
|
2121
2002
|
return typeof record.rfqId === "string" && typeof record.lockupAddress === "string";
|
|
2122
2003
|
}
|
|
2123
|
-
return record.family === "offer" && typeof record.offerHex === "string";
|
|
2004
|
+
return record.family === "offer" && (typeof record.offerHex === "string" || record.binding !== void 0);
|
|
2124
2005
|
};
|
|
2125
2006
|
var createSwapDrive = (config) => {
|
|
2126
2007
|
const { wallet, operator, repository, corridors, indexer } = config;
|
|
@@ -2293,7 +2174,7 @@ var createSwapDrive = (config) => {
|
|
|
2293
2174
|
const signer = await contractSigner(wallet, await identityDescriptor(wallet.identity));
|
|
2294
2175
|
const claimKey = record.profile.claimKey;
|
|
2295
2176
|
if (typeof claimKey === "string") {
|
|
2296
|
-
const held =
|
|
2177
|
+
const held = hex5.encode(await signer.xOnlyPublicKey());
|
|
2297
2178
|
if (held !== claimKey) {
|
|
2298
2179
|
throw new Error(
|
|
2299
2180
|
`this wallet's identity key ${held} is not the payout key ${claimKey} rfq swap ${swap.rfqId} was quoted against \u2014 a wrong seed, or key provisioning has drifted from the identity key`
|
|
@@ -2337,7 +2218,7 @@ var createSwapDrive = (config) => {
|
|
|
2337
2218
|
);
|
|
2338
2219
|
}
|
|
2339
2220
|
const signer = await contractSigner(wallet, descriptor);
|
|
2340
|
-
const held =
|
|
2221
|
+
const held = hex5.encode(await signer.xOnlyPublicKey());
|
|
2341
2222
|
if (held !== record.profile.refundKey) {
|
|
2342
2223
|
throw new Error(
|
|
2343
2224
|
`the key behind ${descriptor} is ${held}, not the refund key ${String(record.profile.refundKey)} rfq swap ${swap.rfqId}'s HTLC was derived with`
|
|
@@ -2493,11 +2374,15 @@ var createSwapDrive = (config) => {
|
|
|
2493
2374
|
const reopened = await legacyOfferDepositsToAdopt(store);
|
|
2494
2375
|
for (const txid of reopen) reopened.add(txid);
|
|
2495
2376
|
const cursor = reopened.size === 0 ? scanned : new Set([...scanned].filter((txid) => !reopened.has(txid)));
|
|
2377
|
+
const bound = [...records.values()].flatMap(
|
|
2378
|
+
(record) => record.family === "offer" && record.binding !== void 0 && record.fundingTxid !== void 0 && !RETIRABLE.includes(record.status) ? [reopenedDeposit(record, record.fundingTxid)] : []
|
|
2379
|
+
);
|
|
2496
2380
|
const { restored, scannedTxids } = await restoreAssetSwaps(indexer, txs, /* @__PURE__ */ new Set(), {
|
|
2497
2381
|
operatorPubkey,
|
|
2498
2382
|
scanned: cursor,
|
|
2499
2383
|
hrp,
|
|
2500
|
-
recoveredIn
|
|
2384
|
+
recoveredIn,
|
|
2385
|
+
reopen: bound
|
|
2501
2386
|
});
|
|
2502
2387
|
const { offer } = splitRecords(await collectSwapRecords(store));
|
|
2503
2388
|
const current = new Map(offer.map((record) => [record.id, record]));
|
|
@@ -2589,6 +2474,33 @@ var createSwapDrive = (config) => {
|
|
|
2589
2474
|
onUpdate: (swap) => emit(swap.id)
|
|
2590
2475
|
});
|
|
2591
2476
|
}
|
|
2477
|
+
if (!lapseTimer) {
|
|
2478
|
+
lapseTimer = setInterval(cancelLapsed, config.pollIntervalMs ?? 5e3);
|
|
2479
|
+
cancelLapsed();
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
const lapsing = /* @__PURE__ */ new Set();
|
|
2483
|
+
let lapseTimer;
|
|
2484
|
+
const cancelLapsed = () => {
|
|
2485
|
+
if (disposed || !repository) return;
|
|
2486
|
+
for (const record of records.values()) {
|
|
2487
|
+
if (record.family !== "offer" || record.binding?.taker === void 0 || record.market.kind === "restored" || record.fundingTxid === void 0 || !OFFER_LIVE(record.status) || fundingWasNotSubmitted(record) || now() <= record.expiresAt + DIRECTED_CANCEL_GRACE_SECONDS || lapsing.has(record.id)) {
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
lapsing.add(record.id);
|
|
2491
|
+
void track(
|
|
2492
|
+
cancelSwap({
|
|
2493
|
+
wallet,
|
|
2494
|
+
repository,
|
|
2495
|
+
record,
|
|
2496
|
+
drive: { ingest: remember },
|
|
2497
|
+
indexer,
|
|
2498
|
+
now
|
|
2499
|
+
}).catch((error) => {
|
|
2500
|
+
console.warn(`[swap] could not cancel lapsed swap ${record.id}`, error);
|
|
2501
|
+
}).finally(() => lapsing.delete(record.id))
|
|
2502
|
+
);
|
|
2503
|
+
}
|
|
2592
2504
|
};
|
|
2593
2505
|
const registerRestoredOffers = async (offers2) => {
|
|
2594
2506
|
if (mode === "readonly") return;
|
|
@@ -2727,6 +2639,8 @@ var createSwapDrive = (config) => {
|
|
|
2727
2639
|
const stop = async () => {
|
|
2728
2640
|
await queue;
|
|
2729
2641
|
await manager.stop();
|
|
2642
|
+
clearInterval(lapseTimer);
|
|
2643
|
+
lapseTimer = void 0;
|
|
2730
2644
|
watcher?.stop();
|
|
2731
2645
|
await watcher?.idle();
|
|
2732
2646
|
watcher = void 0;
|
|
@@ -2766,7 +2680,7 @@ var createSwapDrive = (config) => {
|
|
|
2766
2680
|
id
|
|
2767
2681
|
);
|
|
2768
2682
|
}
|
|
2769
|
-
const script =
|
|
2683
|
+
const script = hex5.decode(record.lockupPkScript);
|
|
2770
2684
|
const before = await recoverableAt(script);
|
|
2771
2685
|
if (before.length === 0) {
|
|
2772
2686
|
throw new SwapDriveRefusedError(
|
|
@@ -3118,220 +3032,6 @@ var pinAmount = (input, takeInstrument) => {
|
|
|
3118
3032
|
return void 0;
|
|
3119
3033
|
};
|
|
3120
3034
|
|
|
3121
|
-
// src/client/policy.ts
|
|
3122
|
-
var DEFAULT_MAX_REFUND_WINDOW_SECONDS = 30 * 24 * 3600;
|
|
3123
|
-
|
|
3124
|
-
// src/client/verify.ts
|
|
3125
|
-
var reasonOf = (error) => error instanceof Error && typeof error.reason === "string" ? error.reason : void 0;
|
|
3126
|
-
var CHECK_BY_REASON = {
|
|
3127
|
-
invoice_expired: "invoice",
|
|
3128
|
-
invoice_undecodable: "invoice",
|
|
3129
|
-
invoice_hash_mismatch: "invoice",
|
|
3130
|
-
invoice_amount_mismatch: "invoice",
|
|
3131
|
-
insufficient_headroom: "refund_window",
|
|
3132
|
-
missing_refund_locktime: "refund_window",
|
|
3133
|
-
claim_window_too_short: "refund_window",
|
|
3134
|
-
confirmations_out_of_range: "refund_window",
|
|
3135
|
-
timelock_order: "refund_window",
|
|
3136
|
-
quote_malformed: "refund_window"
|
|
3137
|
-
};
|
|
3138
|
-
var gated = (run, quote) => {
|
|
3139
|
-
try {
|
|
3140
|
-
run();
|
|
3141
|
-
} catch (error) {
|
|
3142
|
-
const reason = reasonOf(error);
|
|
3143
|
-
if (reason === "quote_expired") {
|
|
3144
|
-
throw new QuoteExpired(quote.id, quote.expiresAt, quote.now);
|
|
3145
|
-
}
|
|
3146
|
-
const check = reason === void 0 ? void 0 : CHECK_BY_REASON[reason];
|
|
3147
|
-
if (check === void 0) throw error;
|
|
3148
|
-
throw new QuoteVerificationFailed(
|
|
3149
|
-
check,
|
|
3150
|
-
void 0,
|
|
3151
|
-
error instanceof Error ? error.message : String(error),
|
|
3152
|
-
{ cause: error }
|
|
3153
|
-
);
|
|
3154
|
-
}
|
|
3155
|
-
};
|
|
3156
|
-
var verifyResponder = (input) => {
|
|
3157
|
-
if (!input.pinnable || input.expected === void 0) {
|
|
3158
|
-
throw new QuoteVerificationFailed(
|
|
3159
|
-
"responder",
|
|
3160
|
-
"a registry-served card naming the solver's discovery key",
|
|
3161
|
-
input.expected === void 0 ? "the card names no discovery key" : "the card came out of the local cache, which does not authenticate it"
|
|
3162
|
-
);
|
|
3163
|
-
}
|
|
3164
|
-
if (input.attested === void 0) {
|
|
3165
|
-
throw new QuoteVerificationFailed(
|
|
3166
|
-
"responder",
|
|
3167
|
-
input.expected,
|
|
3168
|
-
"the transport attests nobody"
|
|
3169
|
-
);
|
|
3170
|
-
}
|
|
3171
|
-
if (input.attested !== input.expected) {
|
|
3172
|
-
throw new QuoteVerificationFailed("responder", input.expected, input.attested);
|
|
3173
|
-
}
|
|
3174
|
-
};
|
|
3175
|
-
var verifyPair = (quoted, requested) => {
|
|
3176
|
-
if (quoted !== requested) {
|
|
3177
|
-
throw new QuoteVerificationFailed("pair", requested, String(quoted));
|
|
3178
|
-
}
|
|
3179
|
-
};
|
|
3180
|
-
var verifyingDerivation = (derive) => {
|
|
3181
|
-
try {
|
|
3182
|
-
return derive();
|
|
3183
|
-
} catch (error) {
|
|
3184
|
-
if (error instanceof AddressMismatch) {
|
|
3185
|
-
const derived = Array.isArray(error.derived) ? error.derived.join(", ") : error.derived;
|
|
3186
|
-
throw new QuoteVerificationFailed("lockup_address", derived, error.quoted, {
|
|
3187
|
-
cause: error
|
|
3188
|
-
});
|
|
3189
|
-
}
|
|
3190
|
-
if (error instanceof Error) {
|
|
3191
|
-
throw new QuoteVerificationFailed("lockup_address", void 0, error.message, {
|
|
3192
|
-
cause: error
|
|
3193
|
-
});
|
|
3194
|
-
}
|
|
3195
|
-
throw error;
|
|
3196
|
-
}
|
|
3197
|
-
};
|
|
3198
|
-
var verifySendWindow = (input) => {
|
|
3199
|
-
gated(
|
|
3200
|
-
() => assertFundable({
|
|
3201
|
-
quote: input.quote,
|
|
3202
|
-
now: input.now,
|
|
3203
|
-
...input.invoiceExpiresAt === void 0 ? {} : { invoiceExpiresAt: input.invoiceExpiresAt },
|
|
3204
|
-
...input.onchain === void 0 ? {} : { onchain: input.onchain }
|
|
3205
|
-
}),
|
|
3206
|
-
{ id: input.quoteId, expiresAt: input.quote.valid_until, now: input.now }
|
|
3207
|
-
);
|
|
3208
|
-
};
|
|
3209
|
-
var verifyReceiveWindow = (input) => {
|
|
3210
|
-
gated(
|
|
3211
|
-
() => assertReceivable({
|
|
3212
|
-
quote: input.quote,
|
|
3213
|
-
payDeadline: input.payDeadline,
|
|
3214
|
-
now: input.now
|
|
3215
|
-
}),
|
|
3216
|
-
{ id: input.quoteId, expiresAt: input.payDeadline, now: input.now }
|
|
3217
|
-
);
|
|
3218
|
-
};
|
|
3219
|
-
var verifySendInvoice = (input) => {
|
|
3220
|
-
const invoiced = input.invoiced;
|
|
3221
|
-
if (input.take !== invoiced) {
|
|
3222
|
-
throw new QuoteVerificationFailed("invoice", `${invoiced}`, `${input.take}`);
|
|
3223
|
-
}
|
|
3224
|
-
if (input.give < input.take) {
|
|
3225
|
-
throw new QuoteVerificationFailed(
|
|
3226
|
-
"invoice",
|
|
3227
|
-
`at least the invoice's ${invoiced}`,
|
|
3228
|
-
`${input.give}, a negative spread`
|
|
3229
|
-
);
|
|
3230
|
-
}
|
|
3231
|
-
};
|
|
3232
|
-
var verifyReceiveInvoiceFacts = (input) => {
|
|
3233
|
-
let decoded;
|
|
3234
|
-
try {
|
|
3235
|
-
decoded = input.decode(input.invoice);
|
|
3236
|
-
} catch (cause) {
|
|
3237
|
-
throw new QuoteVerificationFailed(
|
|
3238
|
-
"invoice",
|
|
3239
|
-
"a decodable BOLT11",
|
|
3240
|
-
cause instanceof Error ? cause.message : String(cause),
|
|
3241
|
-
{ cause }
|
|
3242
|
-
);
|
|
3243
|
-
}
|
|
3244
|
-
if (!Number.isFinite(decoded.expiresAt)) {
|
|
3245
|
-
throw new QuoteVerificationFailed("invoice", "a finite expiry", `${decoded.expiresAt}`);
|
|
3246
|
-
}
|
|
3247
|
-
if (!Number.isFinite(input.validUntil)) {
|
|
3248
|
-
throw new QuoteVerificationFailed(
|
|
3249
|
-
"refund_window",
|
|
3250
|
-
"a finite valid_until",
|
|
3251
|
-
`${input.validUntil}`
|
|
3252
|
-
);
|
|
3253
|
-
}
|
|
3254
|
-
if (decoded.paymentHash !== input.paymentHash) {
|
|
3255
|
-
throw new QuoteVerificationFailed("invoice", input.paymentHash, decoded.paymentHash);
|
|
3256
|
-
}
|
|
3257
|
-
if (!Number.isSafeInteger(decoded.amountSats) || decoded.amountSats <= 0) {
|
|
3258
|
-
throw new QuoteVerificationFailed(
|
|
3259
|
-
"invoice",
|
|
3260
|
-
`${input.payAmount}`,
|
|
3261
|
-
"the invoice names no amount"
|
|
3262
|
-
);
|
|
3263
|
-
}
|
|
3264
|
-
if (BigInt(decoded.amountSats) !== input.payAmount) {
|
|
3265
|
-
throw new QuoteVerificationFailed("invoice", `${input.payAmount}`, `${decoded.amountSats}`);
|
|
3266
|
-
}
|
|
3267
|
-
return { payDeadline: Math.min(decoded.expiresAt, input.validUntil) };
|
|
3268
|
-
};
|
|
3269
|
-
var verifyQuoteTtl = (input) => {
|
|
3270
|
-
const floor = input.floorSeconds ?? 0;
|
|
3271
|
-
if (input.expiresAt - input.now <= floor) {
|
|
3272
|
-
throw new QuoteExpired(input.quoteId, input.expiresAt, input.now);
|
|
3273
|
-
}
|
|
3274
|
-
};
|
|
3275
|
-
var CSV_GRANULARITY_SECONDS = 512;
|
|
3276
|
-
var verifyRefundWindow = (input) => {
|
|
3277
|
-
const max = input.maxSeconds ?? DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
3278
|
-
const window = input.refundLocktime - input.now;
|
|
3279
|
-
if (!(window <= max)) {
|
|
3280
|
-
throw new QuoteVerificationFailed("refund_window", `at most ${max}s`, `${window}s`);
|
|
3281
|
-
}
|
|
3282
|
-
const delay = input.refundWithoutReceiverDelay;
|
|
3283
|
-
if (delay !== void 0 && !(delay < max + CSV_GRANULARITY_SECONDS)) {
|
|
3284
|
-
throw new QuoteVerificationFailed(
|
|
3285
|
-
"refund_window",
|
|
3286
|
-
`a solo-refund delay of at most ${max}s`,
|
|
3287
|
-
`${delay}s`
|
|
3288
|
-
);
|
|
3289
|
-
}
|
|
3290
|
-
};
|
|
3291
|
-
var verifyQuotedAmount = (input) => {
|
|
3292
|
-
verifyPinnedAmount(input);
|
|
3293
|
-
if (input.take > input.give) {
|
|
3294
|
-
throw new QuoteVerificationFailed(
|
|
3295
|
-
"pair",
|
|
3296
|
-
`${input.pair} give >= take`,
|
|
3297
|
-
`give=${input.give} take=${input.take}`
|
|
3298
|
-
);
|
|
3299
|
-
}
|
|
3300
|
-
};
|
|
3301
|
-
var verifyCrossAssetAmount = (input) => {
|
|
3302
|
-
verifyPinnedAmount(input);
|
|
3303
|
-
if (input.give <= 0n || input.take <= 0n) {
|
|
3304
|
-
throw new QuoteVerificationFailed(
|
|
3305
|
-
"pair",
|
|
3306
|
-
`${input.pair} give > 0 take > 0`,
|
|
3307
|
-
`give=${input.give} take=${input.take}`
|
|
3308
|
-
);
|
|
3309
|
-
}
|
|
3310
|
-
};
|
|
3311
|
-
var verifiedCarrierSats = (quote) => {
|
|
3312
|
-
try {
|
|
3313
|
-
return quoteCarrierSats(quote);
|
|
3314
|
-
} catch (error) {
|
|
3315
|
-
if (reasonOf(error) !== "carrier_malformed") throw error;
|
|
3316
|
-
throw new QuoteVerificationFailed(
|
|
3317
|
-
"pair",
|
|
3318
|
-
"carrier_sats a non-negative integer",
|
|
3319
|
-
String(quote.carrier_sats),
|
|
3320
|
-
{ cause: error }
|
|
3321
|
-
);
|
|
3322
|
-
}
|
|
3323
|
-
};
|
|
3324
|
-
var verifyPinnedAmount = (input) => {
|
|
3325
|
-
const quoted = input.pinned.on === "give" ? input.give : input.take;
|
|
3326
|
-
if (quoted !== input.pinned.value) {
|
|
3327
|
-
throw new QuoteVerificationFailed(
|
|
3328
|
-
"pair",
|
|
3329
|
-
`${input.pair} ${input.pinned.on}=${input.pinned.value}`,
|
|
3330
|
-
`${input.pair} ${input.pinned.on}=${quoted}`
|
|
3331
|
-
);
|
|
3332
|
-
}
|
|
3333
|
-
};
|
|
3334
|
-
|
|
3335
3035
|
// src/client/quoteOffer.ts
|
|
3336
3036
|
import {
|
|
3337
3037
|
computeWantAmount,
|
|
@@ -3426,7 +3126,7 @@ var verifyPlanLegs = (plan, legs, give) => {
|
|
|
3426
3126
|
};
|
|
3427
3127
|
|
|
3428
3128
|
// src/jointGraph.ts
|
|
3429
|
-
import { base64 as base642, hex as
|
|
3129
|
+
import { base64 as base642, hex as hex6 } from "@scure/base";
|
|
3430
3130
|
import { sha256 as sha2562 } from "@noble/hashes/sha2.js";
|
|
3431
3131
|
import { Transaction as Transaction2 } from "@arkade-os/sdk";
|
|
3432
3132
|
function digestJointGraph(plan, template) {
|
|
@@ -3462,7 +3162,7 @@ function digestJointGraph(plan, template) {
|
|
|
3462
3162
|
preimage.set(part, at);
|
|
3463
3163
|
at += part.length;
|
|
3464
3164
|
}
|
|
3465
|
-
return
|
|
3165
|
+
return hex6.encode(sha2562(preimage));
|
|
3466
3166
|
}
|
|
3467
3167
|
function verifyJointGraph(plan, template) {
|
|
3468
3168
|
try {
|
|
@@ -3728,7 +3428,7 @@ var parseRfqQuote = (quote) => ({
|
|
|
3728
3428
|
});
|
|
3729
3429
|
|
|
3730
3430
|
// src/client/quoteRfq.ts
|
|
3731
|
-
import { hex as
|
|
3431
|
+
import { hex as hex7 } from "@scure/base";
|
|
3732
3432
|
import {
|
|
3733
3433
|
ArkAddress as ArkAddress6,
|
|
3734
3434
|
asset as asset4,
|
|
@@ -3747,10 +3447,10 @@ var covenantInputs = (input) => {
|
|
|
3747
3447
|
const network = networkFromOperatorInfo(input.info);
|
|
3748
3448
|
const arkade2 = input.corridors.get("arkade").deps;
|
|
3749
3449
|
return {
|
|
3750
|
-
operatorPubkey: toXOnly(
|
|
3450
|
+
operatorPubkey: toXOnly(hex7.decode(input.info.signerPubkey), "ark signer key"),
|
|
3751
3451
|
// The resolved per-network pin, never operator-reported: it lands in a covenant leaf
|
|
3752
3452
|
// that decides who can move the funds.
|
|
3753
|
-
emulatorPubkey: toXOnly(
|
|
3453
|
+
emulatorPubkey: toXOnly(hex7.decode(arkade2.emulatorPubkey), "emulator signer key"),
|
|
3754
3454
|
claimDelay: unilateralClaimDelay(Number(input.info.unilateralExitDelay)),
|
|
3755
3455
|
hrp: network.hrp
|
|
3756
3456
|
};
|
|
@@ -3758,7 +3458,7 @@ var covenantInputs = (input) => {
|
|
|
3758
3458
|
var sealingKey = (deps) => {
|
|
3759
3459
|
const configured = deps.covclaimd?.pubkey;
|
|
3760
3460
|
if (configured === void 0) return void 0;
|
|
3761
|
-
const key =
|
|
3461
|
+
const key = hex7.decode(configured);
|
|
3762
3462
|
if (key.length !== 33) {
|
|
3763
3463
|
throw new Error(
|
|
3764
3464
|
`the covclaimd deployment key must be 33-byte compressed hex, got ${key.length} bytes`
|
|
@@ -3814,7 +3514,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3814
3514
|
receiveAddress,
|
|
3815
3515
|
maker.pkScript,
|
|
3816
3516
|
networkFromOperatorInfo(input.info).hrp,
|
|
3817
|
-
toXOnly(
|
|
3517
|
+
toXOnly(hex7.decode(input.info.signerPubkey), "ark signer key")
|
|
3818
3518
|
);
|
|
3819
3519
|
const choice = payment?.carrier;
|
|
3820
3520
|
const carrierRequest = choice === void 0 ? void 0 : choice.mode === "purchase" ? { mode: "purchase" } : {
|
|
@@ -3826,7 +3526,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3826
3526
|
if (choice?.mode === "recycleReceiver") {
|
|
3827
3527
|
if (choice.quote.assetId !== sides.wantAsset?.toString())
|
|
3828
3528
|
throw new Error("carrier quote assetId differs from requested asset");
|
|
3829
|
-
if (choice.quote.senderKey !==
|
|
3529
|
+
if (choice.quote.senderKey !== hex7.encode(maker.publicKey))
|
|
3830
3530
|
throw new Error("carrier quote senderKey differs from wallet identity");
|
|
3831
3531
|
if (input.now >= choice.quote.expiresAt - 30)
|
|
3832
3532
|
throw new Error("carrier quote expired before RFQ");
|
|
@@ -3857,6 +3557,10 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3857
3557
|
);
|
|
3858
3558
|
verifyPair(wire.pair, pair);
|
|
3859
3559
|
const parsed = parseRfqQuote(wire);
|
|
3560
|
+
const taker = contractVersion === ASSET_SWAP_V4 ? verifyTaker({
|
|
3561
|
+
attested: input.transport.attestedResponder,
|
|
3562
|
+
solverPubkey: parsed.solver
|
|
3563
|
+
}) : void 0;
|
|
3860
3564
|
verifyCrossAssetAmount({ pair, pinned, give: parsed.give, take: parsed.take });
|
|
3861
3565
|
verifyQuoteTtl({
|
|
3862
3566
|
quoteId: input.quoteId,
|
|
@@ -3888,7 +3592,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3888
3592
|
if (input.now >= validUntil) throw new Error("asset payment terms lapsed before funding");
|
|
3889
3593
|
assetPayment = {
|
|
3890
3594
|
receiveAddress: receiveAddress ?? new ArkAddress6(
|
|
3891
|
-
toXOnly(
|
|
3595
|
+
toXOnly(hex7.decode(input.info.signerPubkey), "ark signer key"),
|
|
3892
3596
|
maker.pkScript.slice(2),
|
|
3893
3597
|
networkFromOperatorInfo(input.info).hrp
|
|
3894
3598
|
).encode(),
|
|
@@ -3902,7 +3606,9 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3902
3606
|
const reference = await quoteOffer2(input.candidate.card, {
|
|
3903
3607
|
give: input.candidate.give,
|
|
3904
3608
|
giveAmount: parsed.give,
|
|
3905
|
-
|
|
3609
|
+
// Unconditional: a card charging for the delivered carrier refuses to price without
|
|
3610
|
+
// it whichever leg gives, and a BTC deposit funds none of its own to publish.
|
|
3611
|
+
carrierSats: carrierSats ?? ASSET_CARRIER_SATS,
|
|
3906
3612
|
...QUOTE_OPTIONS,
|
|
3907
3613
|
fetchImpl: input.feed.fetch
|
|
3908
3614
|
});
|
|
@@ -3916,7 +3622,8 @@ var quoteArkadeAsset = async (input) => {
|
|
|
3916
3622
|
maker,
|
|
3917
3623
|
...receiveAddress === void 0 ? {} : { receiveAddress },
|
|
3918
3624
|
info: input.info,
|
|
3919
|
-
contractVersion
|
|
3625
|
+
contractVersion,
|
|
3626
|
+
...taker === void 0 ? {} : { taker }
|
|
3920
3627
|
});
|
|
3921
3628
|
verifyingDerivation(() => verifyOfferAddress(wire, offer));
|
|
3922
3629
|
return {
|
|
@@ -4066,7 +3773,7 @@ var quoteLightningReceive = async (input) => {
|
|
|
4066
3773
|
provisionClaimSecret(input.wallet),
|
|
4067
3774
|
input.wallet.getAddress()
|
|
4068
3775
|
]);
|
|
4069
|
-
const paymentHash =
|
|
3776
|
+
const paymentHash = hex7.encode(secrets.paymentHash);
|
|
4070
3777
|
const lightning = input.corridors.get("lightning").deps;
|
|
4071
3778
|
const sealTo = sealingKey(lightning);
|
|
4072
3779
|
const sealsAmount = pinned.on === "take" && input.legs.take.assetId === BTC_ASSET_ID;
|
|
@@ -4186,7 +3893,7 @@ var quoteOnchainSend = async (input) => {
|
|
|
4186
3893
|
provisionClaimSecret(input.wallet),
|
|
4187
3894
|
provisionRefundKey(input.wallet)
|
|
4188
3895
|
]);
|
|
4189
|
-
const paymentHash =
|
|
3896
|
+
const paymentHash = hex7.encode(secrets.paymentHash);
|
|
4190
3897
|
const wire = await input.transport.requestQuote(
|
|
4191
3898
|
withCanonicalAmount(
|
|
4192
3899
|
onchainSendRequest({
|
|
@@ -4297,7 +4004,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
4297
4004
|
input.wallet.getAddress(),
|
|
4298
4005
|
input.wallet.getBoardingAddress()
|
|
4299
4006
|
]);
|
|
4300
|
-
const paymentHash =
|
|
4007
|
+
const paymentHash = hex7.encode(secrets.paymentHash);
|
|
4301
4008
|
const refundPkScript = l1ScriptForAddress(boardingAddress, l1Network);
|
|
4302
4009
|
const wire = await input.transport.requestQuote(
|
|
4303
4010
|
withCanonicalAmount(
|
|
@@ -4496,10 +4203,10 @@ var createNostrTransportFactory = (pool) => {
|
|
|
4496
4203
|
var nostrTransportFactory = createNostrTransportFactory();
|
|
4497
4204
|
|
|
4498
4205
|
// src/client/client.ts
|
|
4499
|
-
import { hex as
|
|
4206
|
+
import { hex as hex8 } from "@scure/base";
|
|
4500
4207
|
import { captureSendDeadline } from "@arkade-os/sdk";
|
|
4501
4208
|
var PREPARATIONS_HELD = 64;
|
|
4502
|
-
var mintQuoteId = () =>
|
|
4209
|
+
var mintQuoteId = () => hex8.encode(crypto.getRandomValues(new Uint8Array(16)));
|
|
4503
4210
|
var createSwapClient = (config) => {
|
|
4504
4211
|
const { wallet } = config;
|
|
4505
4212
|
const operator = config.operator ?? walletOperator(wallet);
|
|
@@ -4652,6 +4359,7 @@ var createSwapClient = (config) => {
|
|
|
4652
4359
|
return acceptQuote({
|
|
4653
4360
|
quote,
|
|
4654
4361
|
...validUntil === void 0 ? {} : { validUntil },
|
|
4362
|
+
...options?.attachOfferPacket === false ? { attachOfferPacket: false } : {},
|
|
4655
4363
|
...preparation === void 0 ? {} : { preparation },
|
|
4656
4364
|
wallet,
|
|
4657
4365
|
repository: config.repository,
|
|
@@ -4754,7 +4462,7 @@ var createSwapClient = (config) => {
|
|
|
4754
4462
|
};
|
|
4755
4463
|
|
|
4756
4464
|
// src/offerFillPlan.ts
|
|
4757
|
-
import { base64 as base643, hex as
|
|
4465
|
+
import { base64 as base643, hex as hex9 } from "@scure/base";
|
|
4758
4466
|
import { ArkAddress as ArkAddress7, Extension, P2A } from "@arkade-os/sdk";
|
|
4759
4467
|
var OFFER_FILL_TEMPLATE = "offer-fill/1";
|
|
4760
4468
|
var OFFER_FILL_OWNERS = [null, "solver", "sponsor"];
|
|
@@ -4768,8 +4476,9 @@ async function buildOfferFillPlan(wallet, arkServerUrl, offerHex, opts) {
|
|
|
4768
4476
|
assetCarrierSats = ASSET_CARRIER_SATS,
|
|
4769
4477
|
sponsor
|
|
4770
4478
|
} = opts;
|
|
4771
|
-
const
|
|
4772
|
-
const contract = await connectFillContract(wallet, arkServerUrl,
|
|
4479
|
+
const target = typeof offerHex === "string" ? decodeOffer(hex9.decode(offerHex)) : offerHex;
|
|
4480
|
+
const contract = await connectFillContract(wallet, arkServerUrl, target, { swapAddress });
|
|
4481
|
+
const offer = offerOf(target, contract.pkScript);
|
|
4773
4482
|
const vtxos = await contract.getUtxos();
|
|
4774
4483
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
4775
4484
|
const solverPayout = payoutScript ?? ArkAddress7.decode(await wallet.getAddress()).pkScript;
|
|
@@ -4817,7 +4526,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
4817
4526
|
}
|
|
4818
4527
|
layout.inputs.forEach((input, i) => {
|
|
4819
4528
|
const spent = checkpoints[i].getInput(0);
|
|
4820
|
-
if (!(spent.txid instanceof Uint8Array) ||
|
|
4529
|
+
if (!(spent.txid instanceof Uint8Array) || hex9.encode(spent.txid) !== input.txid || spent.index !== input.vout) {
|
|
4821
4530
|
throw new Error(`fill plan checkpoint ${i} does not spend ${input.txid}:${input.vout}`);
|
|
4822
4531
|
}
|
|
4823
4532
|
});
|
|
@@ -4829,7 +4538,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
4829
4538
|
}
|
|
4830
4539
|
layout.outputs.forEach((expected, i) => {
|
|
4831
4540
|
const out = arkTx.getOutput(i);
|
|
4832
|
-
if (!out?.script ||
|
|
4541
|
+
if (!out?.script || hex9.encode(out.script) !== hex9.encode(expected.script)) {
|
|
4833
4542
|
throw new Error(`fill plan output ${i} is not the ${expected.role} script`);
|
|
4834
4543
|
}
|
|
4835
4544
|
if (out.amount !== expected.sats) {
|
|
@@ -4843,7 +4552,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
4843
4552
|
throw new Error(`fill plan output ${payments} is not the extension packet`);
|
|
4844
4553
|
}
|
|
4845
4554
|
const anchor = arkTx.getOutput(payments + 1);
|
|
4846
|
-
if (!anchor?.script ||
|
|
4555
|
+
if (!anchor?.script || hex9.encode(anchor.script) !== hex9.encode(P2A.script) || anchor.amount !== P2A.amount) {
|
|
4847
4556
|
throw new Error(`fill plan output ${payments + 1} is not the anchor`);
|
|
4848
4557
|
}
|
|
4849
4558
|
const packet = Extension.fromTx(arkTx).getAssetPacket();
|
|
@@ -4916,23 +4625,6 @@ export {
|
|
|
4916
4625
|
isBtcAssetLenient,
|
|
4917
4626
|
arkadeAsset,
|
|
4918
4627
|
issuanceOf,
|
|
4919
|
-
AmbiguousDestination,
|
|
4920
|
-
UnsupportedRoute,
|
|
4921
|
-
DiscoverySnapshotUnavailable,
|
|
4922
|
-
AmountMismatch,
|
|
4923
|
-
AmountEncodingUnsupported,
|
|
4924
|
-
QuoteVerificationFailed,
|
|
4925
|
-
QuoteExpired,
|
|
4926
|
-
MaxFeeExceeded,
|
|
4927
|
-
InsufficientFunds,
|
|
4928
|
-
AcceptConflict,
|
|
4929
|
-
ClientDisposed,
|
|
4930
|
-
NotCancellable,
|
|
4931
|
-
InconsistentRoute,
|
|
4932
|
-
OperatorUnreachable,
|
|
4933
|
-
MissingCorridorDep,
|
|
4934
|
-
SWAP_ERROR_NAMES,
|
|
4935
|
-
isSwapError,
|
|
4936
4628
|
toDiscoveryLeg,
|
|
4937
4629
|
INDEXED_NETWORKS,
|
|
4938
4630
|
isIndexedNetwork,
|
|
@@ -4979,6 +4671,7 @@ export {
|
|
|
4979
4671
|
withDepositFate,
|
|
4980
4672
|
fateMoved,
|
|
4981
4673
|
restoredOfferRecord,
|
|
4674
|
+
reopenedDeposit,
|
|
4982
4675
|
restoredCorridorRecord,
|
|
4983
4676
|
walletLockupIndexer,
|
|
4984
4677
|
cancelSwap,
|
|
@@ -4997,19 +4690,6 @@ export {
|
|
|
4997
4690
|
marketOf,
|
|
4998
4691
|
assembleRoute,
|
|
4999
4692
|
resolveRoute,
|
|
5000
|
-
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|
|
5001
|
-
verifyResponder,
|
|
5002
|
-
verifyPair,
|
|
5003
|
-
verifyingDerivation,
|
|
5004
|
-
verifySendWindow,
|
|
5005
|
-
verifyReceiveWindow,
|
|
5006
|
-
verifySendInvoice,
|
|
5007
|
-
verifyReceiveInvoiceFacts,
|
|
5008
|
-
verifyQuoteTtl,
|
|
5009
|
-
verifyRefundWindow,
|
|
5010
|
-
verifyQuotedAmount,
|
|
5011
|
-
verifyCrossAssetAmount,
|
|
5012
|
-
verifiedCarrierSats,
|
|
5013
4693
|
FEED_TTL_MS,
|
|
5014
4694
|
feedFetch,
|
|
5015
4695
|
quoteFromFeed,
|