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