@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/advanced.js
CHANGED
|
@@ -2,9 +2,7 @@ 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,
|
|
@@ -13,6 +11,7 @@ import {
|
|
|
13
11
|
CORRIDOR_FACTORIES,
|
|
14
12
|
ClientDisposed,
|
|
15
13
|
DEFAULT_INVOICE_EXPIRY_SECONDS,
|
|
14
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|
|
16
15
|
DiscoverySnapshotUnavailable,
|
|
17
16
|
FEED_TTL_MS,
|
|
18
17
|
INDEXED_NETWORKS,
|
|
@@ -21,14 +20,14 @@ import {
|
|
|
21
20
|
MaxFeeExceeded,
|
|
22
21
|
MissingCorridorDep,
|
|
23
22
|
NotCancellable,
|
|
24
|
-
|
|
23
|
+
OFFER_FILL_OWNERS,
|
|
24
|
+
OFFER_FILL_TEMPLATE,
|
|
25
25
|
ONCHAIN_CLAIM_FEE_RATE_SATVB,
|
|
26
26
|
OperatorUnreachable,
|
|
27
27
|
QuoteExpired,
|
|
28
28
|
QuoteVerificationFailed,
|
|
29
29
|
RAILS,
|
|
30
30
|
REGISTRY_URL,
|
|
31
|
-
RFQ_SWAP_ID_PREFIX,
|
|
32
31
|
SWAP_ERROR_NAMES,
|
|
33
32
|
SwapDriveRefusedError,
|
|
34
33
|
UnsupportedRoute,
|
|
@@ -37,15 +36,16 @@ import {
|
|
|
37
36
|
applyOfferSpend,
|
|
38
37
|
arkadeAsset,
|
|
39
38
|
arkadeCorridor,
|
|
40
|
-
artifactOf,
|
|
41
39
|
assembleRoute,
|
|
42
40
|
assetPartOf,
|
|
43
|
-
assetSwapIdOf,
|
|
44
41
|
attesting,
|
|
45
42
|
bitcoinNetworkOf,
|
|
43
|
+
btcAssetPart,
|
|
46
44
|
btcOn,
|
|
45
|
+
buildOfferFillPlan,
|
|
47
46
|
cancelSwap,
|
|
48
47
|
canonicalAssetId,
|
|
48
|
+
cardLegAssetId,
|
|
49
49
|
cardMarketOf,
|
|
50
50
|
chainSourceOver,
|
|
51
51
|
chooseMarket,
|
|
@@ -53,10 +53,13 @@ import {
|
|
|
53
53
|
corridorOfRail,
|
|
54
54
|
corridorRecordStore,
|
|
55
55
|
corridorSet,
|
|
56
|
+
createNostrTransportFactory,
|
|
56
57
|
createSwapClient,
|
|
57
58
|
createSwapDrive,
|
|
58
59
|
decodeBolt11,
|
|
59
60
|
decodeRfqAmount,
|
|
61
|
+
deepFreeze,
|
|
62
|
+
digestJointGraph,
|
|
60
63
|
discoveryIndex,
|
|
61
64
|
eligibleMarkets,
|
|
62
65
|
encodeRfqAmount,
|
|
@@ -64,48 +67,45 @@ import {
|
|
|
64
67
|
esploraChainSource,
|
|
65
68
|
esploraTip,
|
|
66
69
|
exchange,
|
|
67
|
-
|
|
70
|
+
fateMoved,
|
|
68
71
|
feedFetch,
|
|
72
|
+
feedSpread,
|
|
69
73
|
formatAssetId,
|
|
70
|
-
fromAtomicDecimal,
|
|
71
74
|
fromRfqAmountSide,
|
|
72
|
-
fundsFromWallet,
|
|
73
|
-
instrumentOf,
|
|
74
75
|
isAddressable,
|
|
75
76
|
isAssetId,
|
|
76
|
-
|
|
77
|
+
isBtcAsset,
|
|
78
|
+
isBtcAssetLenient,
|
|
77
79
|
isCardMarket,
|
|
78
80
|
isIndexedNetwork,
|
|
79
81
|
isNetworkRef,
|
|
80
82
|
isSwapError,
|
|
81
83
|
isUsableCard,
|
|
82
84
|
issuanceOf,
|
|
83
|
-
legOf,
|
|
84
85
|
liveArkadeInfo,
|
|
85
86
|
marketBackendOf,
|
|
86
87
|
marketKeyOf,
|
|
88
|
+
marketOf,
|
|
87
89
|
marketRefOf,
|
|
88
90
|
nostrTransportFactory,
|
|
89
91
|
offerFactsOf,
|
|
90
92
|
offerRecordSource,
|
|
93
|
+
pageRfqRecords,
|
|
91
94
|
parseAssetId,
|
|
92
95
|
parseRfqQuote,
|
|
93
96
|
pay,
|
|
94
97
|
publicAssetId,
|
|
95
98
|
quoteFromFeed,
|
|
96
|
-
quoteIdOfSwapId,
|
|
97
99
|
quoteViaRfq,
|
|
98
100
|
railOf,
|
|
99
101
|
railOfCorridor,
|
|
100
102
|
readableRecord,
|
|
101
103
|
receive,
|
|
102
|
-
recordArtifact,
|
|
103
|
-
recordEndpoint,
|
|
104
|
-
recordInstrument,
|
|
105
|
-
recordLeg,
|
|
106
104
|
resolveCorridorBase,
|
|
107
105
|
resolveCorridorDeps,
|
|
108
106
|
resolveRoute,
|
|
107
|
+
restoredCorridorRecord,
|
|
108
|
+
restoredOfferRecord,
|
|
109
109
|
rfqLeg,
|
|
110
110
|
rfqPairFor,
|
|
111
111
|
rfqRecordOf,
|
|
@@ -113,52 +113,81 @@ import {
|
|
|
113
113
|
satsOf,
|
|
114
114
|
scopedToRail,
|
|
115
115
|
splitRecords,
|
|
116
|
-
swapOf,
|
|
117
116
|
swapRecordOf,
|
|
118
|
-
toAtomicDecimal,
|
|
119
117
|
toDiscoveryLeg,
|
|
120
118
|
toRfqAmountSide,
|
|
121
119
|
toSafeNumber,
|
|
120
|
+
unsignedPsbtBytes,
|
|
122
121
|
usableMarkets,
|
|
122
|
+
verifiedCarrierSats,
|
|
123
|
+
verifyCrossAssetAmount,
|
|
124
|
+
verifyJointGraph,
|
|
125
|
+
verifyOfferFillPlan,
|
|
123
126
|
verifyPair,
|
|
127
|
+
verifyPlanLegs,
|
|
124
128
|
verifyQuoteTtl,
|
|
125
129
|
verifyQuotedAmount,
|
|
126
130
|
verifyReceiveInvoiceFacts,
|
|
127
131
|
verifyReceiveWindow,
|
|
132
|
+
verifyRefundWindow,
|
|
128
133
|
verifyResponder,
|
|
129
134
|
verifySendInvoice,
|
|
130
135
|
verifySendWindow,
|
|
131
136
|
verifyingDerivation,
|
|
132
137
|
walletLockupIndexer,
|
|
133
138
|
withCanonicalAmount,
|
|
134
|
-
|
|
139
|
+
withDepositFate,
|
|
135
140
|
withRfqState
|
|
136
|
-
} from "./chunk-
|
|
141
|
+
} from "./chunk-YHESEL4I.js";
|
|
137
142
|
import {
|
|
138
143
|
ACTIVITY_TOKEN,
|
|
144
|
+
Amount,
|
|
145
|
+
AmountFormatError,
|
|
139
146
|
CORRIDOR_PASS,
|
|
140
147
|
INVOICE_HRPS,
|
|
141
148
|
LIGHTNING_DRIVE,
|
|
142
149
|
LOCKUP_OWNER,
|
|
150
|
+
OFFER_SWAP_ID_PREFIX,
|
|
143
151
|
ONCHAIN_DRIVE,
|
|
152
|
+
RFQ_SWAP_ID_PREFIX,
|
|
153
|
+
artifactOf,
|
|
154
|
+
assetSwapIdOf,
|
|
144
155
|
corridorOutcome,
|
|
156
|
+
familyOfSwapId,
|
|
157
|
+
fromAtomicDecimal,
|
|
158
|
+
fundingWasNotSubmitted,
|
|
159
|
+
fundsFromWallet,
|
|
160
|
+
instrumentOf,
|
|
161
|
+
isAtomicDecimal,
|
|
162
|
+
legOf,
|
|
145
163
|
lightningCorridor,
|
|
146
164
|
networksOfInvoiceHrp,
|
|
147
165
|
offerOutcome,
|
|
148
166
|
onchainCorridor,
|
|
167
|
+
quoteIdOfSwapId,
|
|
149
168
|
readsChain,
|
|
150
|
-
|
|
151
|
-
|
|
169
|
+
recordArtifact,
|
|
170
|
+
recordEndpoint,
|
|
171
|
+
recordInstrument,
|
|
172
|
+
recordLeg,
|
|
173
|
+
recordOutcome,
|
|
174
|
+
swapOf,
|
|
175
|
+
toAtomicDecimal
|
|
176
|
+
} from "./chunk-T4FHBWZI.js";
|
|
152
177
|
import {
|
|
178
|
+
ARKADE_BTC,
|
|
153
179
|
SwapRefusal,
|
|
180
|
+
assertPairLength,
|
|
181
|
+
assertPreimageMatches,
|
|
182
|
+
bindsClaimAmount,
|
|
183
|
+
rfqPair,
|
|
154
184
|
sealClaimPacket
|
|
155
|
-
} from "./chunk-
|
|
185
|
+
} from "./chunk-FMRAV77W.js";
|
|
186
|
+
import "./chunk-A3SHHRX4.js";
|
|
156
187
|
|
|
157
188
|
// src/reveal.ts
|
|
158
189
|
import { base64, hex } from "@scure/base";
|
|
159
|
-
import {
|
|
160
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
161
|
-
import { ArkAddress } from "@arkade-os/sdk";
|
|
190
|
+
import { ArkAddress, assertTimerMs } from "@arkade-os/sdk";
|
|
162
191
|
var CovclaimdRevealError = class extends Error {
|
|
163
192
|
name = "CovclaimdRevealError";
|
|
164
193
|
status;
|
|
@@ -171,6 +200,13 @@ var CovclaimdRevealError = class extends Error {
|
|
|
171
200
|
this.retryable = status === 0 || status === 429 || status >= 500;
|
|
172
201
|
}
|
|
173
202
|
};
|
|
203
|
+
var assertRevealAmount = (minAmount) => {
|
|
204
|
+
if (typeof minAmount !== "bigint" || minAmount < 1n || minAmount > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`min_amount ${minAmount} is missing, not positive, or past what a JSON number carries`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
174
210
|
var decodeKey = (value, field) => {
|
|
175
211
|
if (typeof value !== "string") throw new Error(`covclaimd info: ${field} is not a string`);
|
|
176
212
|
let bytes;
|
|
@@ -198,6 +234,7 @@ var covclaimdClient = (baseUrl, options = {}) => {
|
|
|
198
234
|
const url = baseUrl.replace(/\/+$/, "");
|
|
199
235
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
200
236
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
237
|
+
assertTimerMs("timeoutMs", timeoutMs);
|
|
201
238
|
const send = async (what, path, init) => {
|
|
202
239
|
let response;
|
|
203
240
|
try {
|
|
@@ -239,12 +276,19 @@ var covclaimdClient = (baseUrl, options = {}) => {
|
|
|
239
276
|
};
|
|
240
277
|
},
|
|
241
278
|
async reveal(params) {
|
|
279
|
+
const { minAmount } = params;
|
|
280
|
+
if (minAmount !== void 0) assertRevealAmount(minAmount);
|
|
242
281
|
await send("reveal", "/v1/reveal", {
|
|
243
282
|
method: "POST",
|
|
244
283
|
headers: { "content-type": "application/json" },
|
|
245
284
|
body: JSON.stringify({
|
|
246
285
|
swap_address: params.swapAddress,
|
|
247
|
-
packet: {
|
|
286
|
+
packet: {
|
|
287
|
+
ciphertext: params.ciphertext,
|
|
288
|
+
arkade_script: params.arkadeScript,
|
|
289
|
+
// covclaimd reads an absent field as unbound
|
|
290
|
+
min_amount: minAmount === void 0 ? void 0 : Number(minAmount)
|
|
291
|
+
},
|
|
248
292
|
taptree: params.taptree
|
|
249
293
|
})
|
|
250
294
|
});
|
|
@@ -265,16 +309,246 @@ async function revealClaimPacket(client, input) {
|
|
|
265
309
|
if (hex.encode(ArkAddress.decode(input.address).pkScript) !== hex.encode(input.script.pkScript)) {
|
|
266
310
|
throw new Error("address does not belong to this covenant");
|
|
267
311
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
312
|
+
assertPreimageMatches(input.preimage, input.script.options.preimageHash);
|
|
313
|
+
assertRevealAmount(input.minAmount);
|
|
314
|
+
const minAmount = bindsClaimAmount() ? input.minAmount : void 0;
|
|
271
315
|
const { ciphertext } = await sealClaimPacket({
|
|
272
316
|
preimage: input.preimage,
|
|
273
|
-
covclaimdPubkey: (await client.info()).covclaimdPubkey
|
|
317
|
+
covclaimdPubkey: (await client.info()).covclaimdPubkey,
|
|
318
|
+
minAmount
|
|
274
319
|
});
|
|
275
|
-
await client.reveal({ swapAddress: input.address, ciphertext, ...fields });
|
|
320
|
+
await client.reveal({ swapAddress: input.address, ciphertext, minAmount, ...fields });
|
|
276
321
|
return { ciphertext };
|
|
277
322
|
}
|
|
323
|
+
|
|
324
|
+
// src/evmRfq.ts
|
|
325
|
+
import { hex as hex2 } from "@scure/base";
|
|
326
|
+
var EVM_CHAIN = "ethereum";
|
|
327
|
+
var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
328
|
+
var TOKEN_AMOUNT = /^(0|[1-9][0-9]*)$/;
|
|
329
|
+
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
330
|
+
var MAX_UINT256_DECIMAL = MAX_UINT256.toString();
|
|
331
|
+
var SEND_PAIR = /^arkade:BTC->ethereum:0x[0-9a-f]{40}$/;
|
|
332
|
+
var RECEIVE_PAIR = /^ethereum:0x[0-9a-f]{40}->arkade:BTC$/;
|
|
333
|
+
var evmTokenLeg = (tokenAddress) => `${EVM_CHAIN}:${assertEvmAddress(tokenAddress, "token address").toLowerCase()}`;
|
|
334
|
+
var evmSendPair = (tokenAddress) => {
|
|
335
|
+
const pair = rfqPair(ARKADE_BTC, evmTokenLeg(tokenAddress));
|
|
336
|
+
assertPairLength(pair);
|
|
337
|
+
return pair;
|
|
338
|
+
};
|
|
339
|
+
var evmReceivePair = (tokenAddress) => {
|
|
340
|
+
const pair = rfqPair(evmTokenLeg(tokenAddress), ARKADE_BTC);
|
|
341
|
+
assertPairLength(pair);
|
|
342
|
+
return pair;
|
|
343
|
+
};
|
|
344
|
+
var evmDirectionOf = (pair) => {
|
|
345
|
+
if (SEND_PAIR.test(pair)) return "send";
|
|
346
|
+
if (RECEIVE_PAIR.test(pair)) return "receive";
|
|
347
|
+
return null;
|
|
348
|
+
};
|
|
349
|
+
var evmTokenOf = (pair) => {
|
|
350
|
+
const direction = evmDirectionOf(pair);
|
|
351
|
+
if (direction === null) return null;
|
|
352
|
+
const [from, to] = pair.split("->");
|
|
353
|
+
return (direction === "send" ? to : from).slice(EVM_CHAIN.length + 1);
|
|
354
|
+
};
|
|
355
|
+
var evmAmountToWire = (units) => {
|
|
356
|
+
if (typeof units !== "bigint") throw new Error("token amount must be a bigint");
|
|
357
|
+
if (units < 0n) throw new Error(`token amount may not be negative, got ${units}`);
|
|
358
|
+
if (units > MAX_UINT256) throw new Error(`token amount must fit uint256, got ${units}`);
|
|
359
|
+
return units.toString();
|
|
360
|
+
};
|
|
361
|
+
var evmAmountFromWire = (value, field) => {
|
|
362
|
+
if (typeof value !== "string") {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`${field} must be a decimal string of atomic units, not a JSON ${typeof value}`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
if (!TOKEN_AMOUNT.test(value)) {
|
|
368
|
+
throw new Error(`${field} is not a canonical decimal amount: ${JSON.stringify(value)}`);
|
|
369
|
+
}
|
|
370
|
+
if (value.length > MAX_UINT256_DECIMAL.length || value.length === MAX_UINT256_DECIMAL.length && value > MAX_UINT256_DECIMAL) {
|
|
371
|
+
throw new Error(`${field} exceeds uint256`);
|
|
372
|
+
}
|
|
373
|
+
return BigInt(value);
|
|
374
|
+
};
|
|
375
|
+
var evmSendRequest = (input) => {
|
|
376
|
+
assertPositiveInteger(input.amountSats, "amountSats");
|
|
377
|
+
assertHash32(input.paymentHash, "paymentHash");
|
|
378
|
+
return {
|
|
379
|
+
v: 1,
|
|
380
|
+
type: "rfq_request",
|
|
381
|
+
rfq_id: input.rfqId,
|
|
382
|
+
pair: evmSendPair(input.tokenAddress),
|
|
383
|
+
amount_side: "from",
|
|
384
|
+
amount: input.amountSats,
|
|
385
|
+
profile: {
|
|
386
|
+
payment_hash: input.paymentHash,
|
|
387
|
+
evm_claim_address: assertEvmAddress(input.evmClaimAddress, "evmClaimAddress"),
|
|
388
|
+
refund_address: input.refundAddress,
|
|
389
|
+
client_refund_pubkey: hex2.encode(input.senderPubkey)
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
var evmReceiveRequest = (input) => {
|
|
394
|
+
assertPositiveInteger(input.evmTimeoutBlock, "evmTimeoutBlock");
|
|
395
|
+
assertHash32(input.paymentHash, "paymentHash");
|
|
396
|
+
if (input.evmAmount <= 0n) {
|
|
397
|
+
throw new Error(
|
|
398
|
+
`evmAmount must be a positive number of atomic units, got ${input.evmAmount}`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
return {
|
|
402
|
+
v: 1,
|
|
403
|
+
type: "rfq_request",
|
|
404
|
+
rfq_id: input.rfqId,
|
|
405
|
+
pair: evmReceivePair(input.tokenAddress),
|
|
406
|
+
amount_side: "from",
|
|
407
|
+
profile: {
|
|
408
|
+
payment_hash: input.paymentHash,
|
|
409
|
+
evm_amount: evmAmountToWire(input.evmAmount),
|
|
410
|
+
evm_timeout_block: input.evmTimeoutBlock,
|
|
411
|
+
evm_refund_address: assertEvmAddress(input.evmRefundAddress, "evmRefundAddress"),
|
|
412
|
+
payout_address: input.payoutAddress,
|
|
413
|
+
payout_pubkey: hex2.encode(input.payoutPubkey)
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
};
|
|
417
|
+
var readEvmSendQuote = (payload, expected) => {
|
|
418
|
+
assertHash32(expected.paymentHash, "expected.paymentHash");
|
|
419
|
+
assertPositiveInteger(expected.chainId, "expected.chainId");
|
|
420
|
+
assertPositiveInteger(expected.amountSats, "expected.amountSats");
|
|
421
|
+
const { quote, profile } = readEvmQuoteEnvelope(
|
|
422
|
+
payload,
|
|
423
|
+
evmSendPair(expected.tokenAddress),
|
|
424
|
+
expected.rfqId
|
|
425
|
+
);
|
|
426
|
+
readCommonProfile(profile, expected.paymentHash, expected.chainId);
|
|
427
|
+
assertHex(profile.receiver_pk_script, "profile.receiver_pk_script");
|
|
428
|
+
assertEvmAddress(
|
|
429
|
+
asString(profile.evm_refund_address, "profile.evm_refund_address"),
|
|
430
|
+
"profile.evm_refund_address"
|
|
431
|
+
);
|
|
432
|
+
assertPositiveInteger(profile.evm_timeout_block, "profile.evm_timeout_block");
|
|
433
|
+
assertPositiveTokenAmount(quote.to_amount, "to_amount");
|
|
434
|
+
assertPositiveInteger(quote.from_amount, "from_amount");
|
|
435
|
+
if (quote.from_amount !== expected.amountSats) {
|
|
436
|
+
throw new Error("quote from_amount does not match the requested sats amount");
|
|
437
|
+
}
|
|
438
|
+
return quote;
|
|
439
|
+
};
|
|
440
|
+
var readEvmReceiveQuote = (payload, expected) => {
|
|
441
|
+
assertHash32(expected.paymentHash, "expected.paymentHash");
|
|
442
|
+
assertPositiveInteger(expected.chainId, "expected.chainId");
|
|
443
|
+
if (expected.evmAmount <= 0n) throw new Error("expected.evmAmount must be positive");
|
|
444
|
+
evmAmountToWire(expected.evmAmount);
|
|
445
|
+
const { quote, profile } = readEvmQuoteEnvelope(
|
|
446
|
+
payload,
|
|
447
|
+
evmReceivePair(expected.tokenAddress),
|
|
448
|
+
expected.rfqId
|
|
449
|
+
);
|
|
450
|
+
readCommonProfile(profile, expected.paymentHash, expected.chainId);
|
|
451
|
+
assertHex(profile.solver_refund_pk_script, "profile.solver_refund_pk_script");
|
|
452
|
+
assertEvmAddress(
|
|
453
|
+
asString(profile.evm_claim_address, "profile.evm_claim_address"),
|
|
454
|
+
"profile.evm_claim_address"
|
|
455
|
+
);
|
|
456
|
+
if (assertPositiveTokenAmount(quote.from_amount, "from_amount") !== expected.evmAmount) {
|
|
457
|
+
throw new Error("quote from_amount does not match the requested token amount");
|
|
458
|
+
}
|
|
459
|
+
assertPositiveInteger(quote.to_amount, "to_amount");
|
|
460
|
+
return quote;
|
|
461
|
+
};
|
|
462
|
+
var evmQuoteTokenAmount = (quote) => {
|
|
463
|
+
const direction = evmDirectionOf(quote.pair);
|
|
464
|
+
if (direction === null) throw new Error(`not an EVM pair: ${JSON.stringify(quote.pair)}`);
|
|
465
|
+
return direction === "send" ? evmAmountFromWire(quote.to_amount, "to_amount") : evmAmountFromWire(quote.from_amount, "from_amount");
|
|
466
|
+
};
|
|
467
|
+
var evmQuoteSats = (quote) => {
|
|
468
|
+
const direction = evmDirectionOf(quote.pair);
|
|
469
|
+
if (direction === null) throw new Error(`not an EVM pair: ${JSON.stringify(quote.pair)}`);
|
|
470
|
+
const field = direction === "send" ? "from_amount" : "to_amount";
|
|
471
|
+
const sats = quote[field];
|
|
472
|
+
assertPositiveInteger(sats, field);
|
|
473
|
+
return sats;
|
|
474
|
+
};
|
|
475
|
+
var assertEvmAddress = (value, field) => {
|
|
476
|
+
if (!EVM_ADDRESS.test(value)) {
|
|
477
|
+
throw new Error(`${field} must be 0x then 40 hex, got ${JSON.stringify(value)}`);
|
|
478
|
+
}
|
|
479
|
+
return value;
|
|
480
|
+
};
|
|
481
|
+
var assertPositiveInteger = (value, field) => {
|
|
482
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
483
|
+
throw new Error(`${field} must be a positive integer, got ${String(value)}`);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
var assertNonNegativeInteger = (value, field) => {
|
|
487
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
|
|
488
|
+
throw new Error(`${field} must be a non-negative integer, got ${String(value)}`);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
var assertHex = (value, field) => {
|
|
492
|
+
if (typeof value !== "string" || value.length === 0 || value.length % 2 !== 0 || !/^[0-9a-f]+$/.test(value)) {
|
|
493
|
+
throw new Error(`${field} must be lowercase hex of whole bytes, got ${String(value)}`);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
var assertHash32 = (value, field) => {
|
|
497
|
+
if (typeof value !== "string" || !/^[0-9a-f]{64}$/.test(value)) {
|
|
498
|
+
throw new Error(`${field} must be 64 lowercase hex characters, got ${String(value)}`);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
var assertPositiveTokenAmount = (value, field) => {
|
|
502
|
+
const amount = evmAmountFromWire(value, field);
|
|
503
|
+
if (amount === 0n) throw new Error(`${field} must be positive`);
|
|
504
|
+
return amount;
|
|
505
|
+
};
|
|
506
|
+
var asString = (value, field) => {
|
|
507
|
+
if (typeof value !== "string") {
|
|
508
|
+
throw new Error(`${field} must be a string, got ${String(value)}`);
|
|
509
|
+
}
|
|
510
|
+
return value;
|
|
511
|
+
};
|
|
512
|
+
var readEvmQuoteEnvelope = (payload, expectedPair, expectedRfqId) => {
|
|
513
|
+
if (!payload || typeof payload !== "object") throw new Error("EVM quote is not an object");
|
|
514
|
+
const quote = payload;
|
|
515
|
+
if (quote.v !== 1) throw new Error(`expected EVM quote version 1, got ${String(quote.v)}`);
|
|
516
|
+
if (quote.type !== "rfq_quote") {
|
|
517
|
+
throw new Error(`expected an rfq_quote, got ${String(quote.type)}`);
|
|
518
|
+
}
|
|
519
|
+
if (quote.rfq_id !== expectedRfqId) {
|
|
520
|
+
throw new Error(
|
|
521
|
+
`quote is for rfq_id ${JSON.stringify(quote.rfq_id)}, not this negotiation's ${expectedRfqId}`
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
if (quote.pair !== expectedPair) {
|
|
525
|
+
throw new Error(`solver quoted ${JSON.stringify(quote.pair)}, not ${expectedPair}`);
|
|
526
|
+
}
|
|
527
|
+
asString(quote.solver_pubkey, "solver_pubkey");
|
|
528
|
+
assertPositiveInteger(quote.valid_until, "valid_until");
|
|
529
|
+
assertPositiveInteger(quote.refund_locktime, "refund_locktime");
|
|
530
|
+
if (!quote.profile || typeof quote.profile !== "object") {
|
|
531
|
+
throw new Error("EVM quote carries no profile");
|
|
532
|
+
}
|
|
533
|
+
return { quote, profile: quote.profile };
|
|
534
|
+
};
|
|
535
|
+
var readCommonProfile = (profile, paymentHash, chainId) => {
|
|
536
|
+
assertHash32(profile.payment_hash, "profile.payment_hash");
|
|
537
|
+
asString(profile.lockup_address, "profile.lockup_address");
|
|
538
|
+
assertEvmAddress(
|
|
539
|
+
asString(profile.evm_contract_address, "profile.evm_contract_address"),
|
|
540
|
+
"profile.evm_contract_address"
|
|
541
|
+
);
|
|
542
|
+
assertPositiveInteger(profile.evm_chain_id, "profile.evm_chain_id");
|
|
543
|
+
assertPositiveInteger(profile.min_confirmations, "profile.min_confirmations");
|
|
544
|
+
assertNonNegativeInteger(profile.min_age_seconds, "profile.min_age_seconds");
|
|
545
|
+
if (profile.payment_hash !== paymentHash) {
|
|
546
|
+
throw new Error("quote payment_hash does not match the request");
|
|
547
|
+
}
|
|
548
|
+
if (profile.evm_chain_id !== chainId) {
|
|
549
|
+
throw new Error("quote evm_chain_id does not match the expected chain");
|
|
550
|
+
}
|
|
551
|
+
};
|
|
278
552
|
export {
|
|
279
553
|
ACTIVITY_TOKEN,
|
|
280
554
|
ARKADE_ASSET_NAMESPACE,
|
|
@@ -293,7 +567,9 @@ export {
|
|
|
293
567
|
ClientDisposed,
|
|
294
568
|
CovclaimdRevealError,
|
|
295
569
|
DEFAULT_INVOICE_EXPIRY_SECONDS,
|
|
570
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|
|
296
571
|
DiscoverySnapshotUnavailable,
|
|
572
|
+
EVM_CHAIN,
|
|
297
573
|
FEED_TTL_MS,
|
|
298
574
|
INDEXED_NETWORKS,
|
|
299
575
|
INVOICE_HRPS,
|
|
@@ -304,6 +580,8 @@ export {
|
|
|
304
580
|
MaxFeeExceeded,
|
|
305
581
|
MissingCorridorDep,
|
|
306
582
|
NotCancellable,
|
|
583
|
+
OFFER_FILL_OWNERS,
|
|
584
|
+
OFFER_FILL_TEMPLATE,
|
|
307
585
|
OFFER_SWAP_ID_PREFIX,
|
|
308
586
|
ONCHAIN_CLAIM_FEE_RATE_SATVB,
|
|
309
587
|
ONCHAIN_DRIVE,
|
|
@@ -328,9 +606,12 @@ export {
|
|
|
328
606
|
assetSwapIdOf,
|
|
329
607
|
attesting,
|
|
330
608
|
bitcoinNetworkOf,
|
|
609
|
+
btcAssetPart,
|
|
331
610
|
btcOn,
|
|
611
|
+
buildOfferFillPlan,
|
|
332
612
|
cancelSwap,
|
|
333
613
|
canonicalAssetId,
|
|
614
|
+
cardLegAssetId,
|
|
334
615
|
cardMarketOf,
|
|
335
616
|
chainSourceOver,
|
|
336
617
|
chooseMarket,
|
|
@@ -340,27 +621,46 @@ export {
|
|
|
340
621
|
corridorRecordStore,
|
|
341
622
|
corridorSet,
|
|
342
623
|
covclaimdClient,
|
|
624
|
+
createNostrTransportFactory,
|
|
343
625
|
createSwapClient,
|
|
344
626
|
createSwapDrive,
|
|
345
627
|
decodeBolt11,
|
|
346
628
|
decodeRfqAmount,
|
|
629
|
+
deepFreeze,
|
|
630
|
+
digestJointGraph,
|
|
347
631
|
discoveryIndex,
|
|
348
632
|
eligibleMarkets,
|
|
349
633
|
encodeRfqAmount,
|
|
350
634
|
enforceFeeCeiling,
|
|
351
635
|
esploraChainSource,
|
|
352
636
|
esploraTip,
|
|
637
|
+
evmAmountFromWire,
|
|
638
|
+
evmAmountToWire,
|
|
639
|
+
evmDirectionOf,
|
|
640
|
+
evmQuoteSats,
|
|
641
|
+
evmQuoteTokenAmount,
|
|
642
|
+
evmReceivePair,
|
|
643
|
+
evmReceiveRequest,
|
|
644
|
+
evmSendPair,
|
|
645
|
+
evmSendRequest,
|
|
646
|
+
evmTokenLeg,
|
|
647
|
+
evmTokenOf,
|
|
353
648
|
exchange,
|
|
354
649
|
familyOfSwapId,
|
|
650
|
+
fateMoved,
|
|
355
651
|
feedFetch,
|
|
652
|
+
feedSpread,
|
|
356
653
|
formatAssetId,
|
|
357
654
|
fromAtomicDecimal,
|
|
358
655
|
fromRfqAmountSide,
|
|
656
|
+
fundingWasNotSubmitted,
|
|
359
657
|
fundsFromWallet,
|
|
360
658
|
instrumentOf,
|
|
361
659
|
isAddressable,
|
|
362
660
|
isAssetId,
|
|
363
661
|
isAtomicDecimal,
|
|
662
|
+
isBtcAsset,
|
|
663
|
+
isBtcAssetLenient,
|
|
364
664
|
isCardMarket,
|
|
365
665
|
isIndexedNetwork,
|
|
366
666
|
isNetworkRef,
|
|
@@ -372,6 +672,7 @@ export {
|
|
|
372
672
|
liveArkadeInfo,
|
|
373
673
|
marketBackendOf,
|
|
374
674
|
marketKeyOf,
|
|
675
|
+
marketOf,
|
|
375
676
|
marketRefOf,
|
|
376
677
|
networksOfInvoiceHrp,
|
|
377
678
|
nostrTransportFactory,
|
|
@@ -379,6 +680,7 @@ export {
|
|
|
379
680
|
offerOutcome,
|
|
380
681
|
offerRecordSource,
|
|
381
682
|
onchainCorridor,
|
|
683
|
+
pageRfqRecords,
|
|
382
684
|
parseAssetId,
|
|
383
685
|
parseRfqQuote,
|
|
384
686
|
pay,
|
|
@@ -388,6 +690,8 @@ export {
|
|
|
388
690
|
quoteViaRfq,
|
|
389
691
|
railOf,
|
|
390
692
|
railOfCorridor,
|
|
693
|
+
readEvmReceiveQuote,
|
|
694
|
+
readEvmSendQuote,
|
|
391
695
|
readableRecord,
|
|
392
696
|
readsChain,
|
|
393
697
|
receive,
|
|
@@ -399,6 +703,8 @@ export {
|
|
|
399
703
|
resolveCorridorBase,
|
|
400
704
|
resolveCorridorDeps,
|
|
401
705
|
resolveRoute,
|
|
706
|
+
restoredCorridorRecord,
|
|
707
|
+
restoredOfferRecord,
|
|
402
708
|
revealClaimPacket,
|
|
403
709
|
revealFieldsFromScript,
|
|
404
710
|
rfqLeg,
|
|
@@ -414,18 +720,25 @@ export {
|
|
|
414
720
|
toDiscoveryLeg,
|
|
415
721
|
toRfqAmountSide,
|
|
416
722
|
toSafeNumber,
|
|
723
|
+
unsignedPsbtBytes,
|
|
417
724
|
usableMarkets,
|
|
725
|
+
verifiedCarrierSats,
|
|
726
|
+
verifyCrossAssetAmount,
|
|
727
|
+
verifyJointGraph,
|
|
728
|
+
verifyOfferFillPlan,
|
|
418
729
|
verifyPair,
|
|
730
|
+
verifyPlanLegs,
|
|
419
731
|
verifyQuoteTtl,
|
|
420
732
|
verifyQuotedAmount,
|
|
421
733
|
verifyReceiveInvoiceFacts,
|
|
422
734
|
verifyReceiveWindow,
|
|
735
|
+
verifyRefundWindow,
|
|
423
736
|
verifyResponder,
|
|
424
737
|
verifySendInvoice,
|
|
425
738
|
verifySendWindow,
|
|
426
739
|
verifyingDerivation,
|
|
427
740
|
walletLockupIndexer,
|
|
428
741
|
withCanonicalAmount,
|
|
429
|
-
|
|
742
|
+
withDepositFate,
|
|
430
743
|
withRfqState
|
|
431
744
|
};
|