@arkade-os/swap 0.1.6 → 0.1.8
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 +625 -249
- package/dist/advanced.d.cts +9 -8
- package/dist/advanced.d.ts +9 -8
- package/dist/advanced.js +4 -3
- package/dist/chunk-5QPJWOCN.js +16 -0
- package/dist/{chunk-QFM55KP2.js → chunk-ISWLKKSS.js} +1 -1
- package/dist/{chunk-7BBQ74BG.js → chunk-PDNVKH5L.js} +464 -117
- package/dist/{chunk-SDPNWPGY.js → chunk-ZBJGLLYV.js} +27 -16
- package/dist/index.cjs +641 -265
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +4 -3
- package/dist/{lockupContract-CKPFpIt9.d.ts → lockupContract-BUOsghl1.d.ts} +1 -1
- package/dist/{lockupContract-CpJXTjX_.d.cts → lockupContract-DguuT7NK.d.cts} +1 -1
- package/dist/nostr.cjs +290 -17
- package/dist/nostr.d.cts +2 -1
- package/dist/nostr.d.ts +2 -1
- package/dist/nostr.js +2 -1
- package/dist/{offer-Drw1k_jt.d.ts → offer-BhonWuKR.d.ts} +22 -17
- package/dist/{offer-Boxive2u.d.cts → offer-D_qHpWo2.d.cts} +22 -17
- package/dist/{offerFillPlan-BxNkWLtw.d.cts → offerFillPlan-Bp6-z6dS.d.cts} +3 -3
- package/dist/{offerFillPlan-D2N4s7Xe.d.ts → offerFillPlan-_AOLo6kh.d.ts} +3 -3
- package/dist/protocol.cjs +566 -185
- package/dist/protocol.d.cts +9 -8
- package/dist/protocol.d.ts +9 -8
- package/dist/protocol.js +14 -2
- 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-DFDNvcZ7.d.cts → repository--pfikw2R.d.cts} +1 -1
- package/dist/{repository-Dn1V17T2.d.ts → repository-CkKK0dGO.d.ts} +1 -1
- package/dist/{rfq-CP-P0PSL.d.ts → rfq-BRpo5uWU.d.cts} +14 -2
- package/dist/{rfq-CP-P0PSL.d.cts → rfq-IzhOCG02.d.ts} +14 -2
- package/dist/rfq-contract.cjs +45 -0
- package/dist/rfq-contract.d.cts +9 -0
- package/dist/rfq-contract.d.ts +9 -0
- package/dist/rfq-contract.js +16 -0
- package/dist/{watch-D-mc_wfD.d.ts → watch-DDNycuUa.d.ts} +1 -1
- package/dist/{watch-DFNMY2K-.d.cts → watch-pvTVFp6-.d.cts} +1 -1
- package/package.json +13 -3
package/dist/advanced.cjs
CHANGED
|
@@ -35,11 +35,248 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
35
35
|
));
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
|
|
38
|
-
// src/swap
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
"src/swap
|
|
42
|
-
|
|
38
|
+
// src/contracts/asset-swap.json
|
|
39
|
+
var asset_swap_default;
|
|
40
|
+
var init_asset_swap = __esm({
|
|
41
|
+
"src/contracts/asset-swap.json"() {
|
|
42
|
+
asset_swap_default = {
|
|
43
|
+
formatVersion: 1,
|
|
44
|
+
contractName: "AssetSwap",
|
|
45
|
+
constructorInputs: [
|
|
46
|
+
{
|
|
47
|
+
name: "receiver",
|
|
48
|
+
type: "pubkey"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "amount",
|
|
52
|
+
type: "int"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "assetTxid",
|
|
56
|
+
type: "bytes32"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "assetGroupIndex",
|
|
60
|
+
type: "int"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "user",
|
|
64
|
+
type: "pubkey"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
functions: [
|
|
68
|
+
{
|
|
69
|
+
name: "fulfill",
|
|
70
|
+
arkade: {
|
|
71
|
+
inputs: [],
|
|
72
|
+
asm: [
|
|
73
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
74
|
+
"OP_DUP",
|
|
75
|
+
"<assetTxid>",
|
|
76
|
+
"<assetGroupIndex>",
|
|
77
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
78
|
+
"OP_VERIFY",
|
|
79
|
+
"<amount>",
|
|
80
|
+
"OP_GREATERTHANOREQUAL",
|
|
81
|
+
"OP_VERIFY",
|
|
82
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
83
|
+
"1",
|
|
84
|
+
"OP_NUMEQUALVERIFY",
|
|
85
|
+
"<receiver>",
|
|
86
|
+
"OP_EQUAL"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
leaves: [
|
|
90
|
+
{
|
|
91
|
+
name: "fulfill",
|
|
92
|
+
witness: [
|
|
93
|
+
{
|
|
94
|
+
name: "serverSig",
|
|
95
|
+
type: "signature",
|
|
96
|
+
encoding: "schnorr-64",
|
|
97
|
+
injected: true
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "emulatorSig",
|
|
101
|
+
type: "signature",
|
|
102
|
+
encoding: "schnorr-64",
|
|
103
|
+
injected: true
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
asm: [
|
|
107
|
+
"<SERVER_KEY>",
|
|
108
|
+
"OP_CHECKSIGVERIFY",
|
|
109
|
+
"<EMULATOR_KEY:fulfill>",
|
|
110
|
+
"OP_CHECKSIG"
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "cancel",
|
|
117
|
+
leaves: [
|
|
118
|
+
{
|
|
119
|
+
name: "cancel",
|
|
120
|
+
witness: [
|
|
121
|
+
{
|
|
122
|
+
name: "userSig",
|
|
123
|
+
type: "signature",
|
|
124
|
+
encoding: "schnorr-64"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "serverSig",
|
|
128
|
+
type: "signature",
|
|
129
|
+
encoding: "schnorr-64",
|
|
130
|
+
injected: true
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
asm: [
|
|
134
|
+
"<user>",
|
|
135
|
+
"OP_CHECKSIGVERIFY",
|
|
136
|
+
"<SERVER_KEY>",
|
|
137
|
+
"OP_CHECKSIG"
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
source: {
|
|
144
|
+
entry: "asset-swap.ark",
|
|
145
|
+
files: {
|
|
146
|
+
"asset-swap.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` of the asset.\n// Coordination of who funds it lives outside the contract.\ncontract AssetSwap(\n pubkey receiver,\n int amount,\n bytes32 assetTxid,\n int assetGroupIndex,\n pubkey user\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].assets.lookup(assetTxid, assetGroupIndex) >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
compiler: {
|
|
150
|
+
name: "arkadec",
|
|
151
|
+
version: "0.1.0-rc.1",
|
|
152
|
+
options: {
|
|
153
|
+
optimize: true
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
updatedAt: "2026-11-02T17:43:42.615113722+00:00",
|
|
157
|
+
fingerprint: "sha256:e2b80add6237f6c7e2c69a96ae46d55abe6de5f71c3718106f4d5b22ac9e6d0a"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// src/contracts/sats-swap.json
|
|
163
|
+
var sats_swap_default;
|
|
164
|
+
var init_sats_swap = __esm({
|
|
165
|
+
"src/contracts/sats-swap.json"() {
|
|
166
|
+
sats_swap_default = {
|
|
167
|
+
formatVersion: 1,
|
|
168
|
+
contractName: "SatsSwap",
|
|
169
|
+
constructorInputs: [
|
|
170
|
+
{
|
|
171
|
+
name: "receiver",
|
|
172
|
+
type: "pubkey"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "amount",
|
|
176
|
+
type: "int"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: "user",
|
|
180
|
+
type: "pubkey"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
functions: [
|
|
184
|
+
{
|
|
185
|
+
name: "fulfill",
|
|
186
|
+
arkade: {
|
|
187
|
+
inputs: [],
|
|
188
|
+
asm: [
|
|
189
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
190
|
+
"OP_DUP",
|
|
191
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
192
|
+
"<amount>",
|
|
193
|
+
"OP_GREATERTHANOREQUAL",
|
|
194
|
+
"OP_VERIFY",
|
|
195
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
196
|
+
"1",
|
|
197
|
+
"OP_NUMEQUALVERIFY",
|
|
198
|
+
"<receiver>",
|
|
199
|
+
"OP_EQUAL"
|
|
200
|
+
]
|
|
201
|
+
},
|
|
202
|
+
leaves: [
|
|
203
|
+
{
|
|
204
|
+
name: "fulfill",
|
|
205
|
+
witness: [
|
|
206
|
+
{
|
|
207
|
+
name: "serverSig",
|
|
208
|
+
type: "signature",
|
|
209
|
+
encoding: "schnorr-64",
|
|
210
|
+
injected: true
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "emulatorSig",
|
|
214
|
+
type: "signature",
|
|
215
|
+
encoding: "schnorr-64",
|
|
216
|
+
injected: true
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
asm: [
|
|
220
|
+
"<SERVER_KEY>",
|
|
221
|
+
"OP_CHECKSIGVERIFY",
|
|
222
|
+
"<EMULATOR_KEY:fulfill>",
|
|
223
|
+
"OP_CHECKSIG"
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
]
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: "cancel",
|
|
230
|
+
leaves: [
|
|
231
|
+
{
|
|
232
|
+
name: "cancel",
|
|
233
|
+
witness: [
|
|
234
|
+
{
|
|
235
|
+
name: "userSig",
|
|
236
|
+
type: "signature",
|
|
237
|
+
encoding: "schnorr-64"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "serverSig",
|
|
241
|
+
type: "signature",
|
|
242
|
+
encoding: "schnorr-64",
|
|
243
|
+
injected: true
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
asm: [
|
|
247
|
+
"<user>",
|
|
248
|
+
"OP_CHECKSIGVERIFY",
|
|
249
|
+
"<SERVER_KEY>",
|
|
250
|
+
"OP_CHECKSIG"
|
|
251
|
+
]
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
source: {
|
|
257
|
+
entry: "sats-swap.ark",
|
|
258
|
+
files: {
|
|
259
|
+
"sats-swap.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` sats.\n// Coordination of who funds it lives outside the contract.\ncontract SatsSwap(\n pubkey receiver,\n int amount,\n pubkey user\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].value >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
compiler: {
|
|
263
|
+
name: "arkadec",
|
|
264
|
+
version: "0.1.0-rc.1",
|
|
265
|
+
options: {
|
|
266
|
+
optimize: true
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
updatedAt: "2026-11-02T17:43:42.616824535+00:00",
|
|
270
|
+
fingerprint: "sha256:d7a60ab2178ede40a2e4867816689ea022641531cc662b562bebd7caa1ef96c4"
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// src/legacy/swap-want-asset.program.v1.json
|
|
276
|
+
var swap_want_asset_program_v1_default;
|
|
277
|
+
var init_swap_want_asset_program_v1 = __esm({
|
|
278
|
+
"src/legacy/swap-want-asset.program.v1.json"() {
|
|
279
|
+
swap_want_asset_program_v1_default = {
|
|
43
280
|
version: 1,
|
|
44
281
|
name: "banco-btc-to-asset",
|
|
45
282
|
params: [
|
|
@@ -80,11 +317,11 @@ var init_swap_want_asset_program = __esm({
|
|
|
80
317
|
}
|
|
81
318
|
});
|
|
82
319
|
|
|
83
|
-
// src/swap-want-btc.program.json
|
|
84
|
-
var
|
|
85
|
-
var
|
|
86
|
-
"src/swap-want-btc.program.json"() {
|
|
87
|
-
|
|
320
|
+
// src/legacy/swap-want-btc.program.v1.json
|
|
321
|
+
var swap_want_btc_program_v1_default;
|
|
322
|
+
var init_swap_want_btc_program_v1 = __esm({
|
|
323
|
+
"src/legacy/swap-want-btc.program.v1.json"() {
|
|
324
|
+
swap_want_btc_program_v1_default = {
|
|
88
325
|
version: 1,
|
|
89
326
|
name: "banco-asset-to-btc",
|
|
90
327
|
params: [
|
|
@@ -120,6 +357,80 @@ var init_swap_want_btc_program = __esm({
|
|
|
120
357
|
}
|
|
121
358
|
});
|
|
122
359
|
|
|
360
|
+
// src/rfq-contract.ts
|
|
361
|
+
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_BASELINE;
|
|
362
|
+
var init_rfq_contract = __esm({
|
|
363
|
+
"src/rfq-contract.ts"() {
|
|
364
|
+
"use strict";
|
|
365
|
+
RFQ_CONTRACT_VERSIONS_KEY = "contract_versions";
|
|
366
|
+
RFQ_CONTRACT_VERSION_KEY = "contract_version";
|
|
367
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
368
|
+
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
369
|
+
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
370
|
+
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// src/program.ts
|
|
375
|
+
var import_sdk, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
376
|
+
var init_program = __esm({
|
|
377
|
+
"src/program.ts"() {
|
|
378
|
+
"use strict";
|
|
379
|
+
import_sdk = require("@arkade-os/sdk");
|
|
380
|
+
init_asset_swap();
|
|
381
|
+
init_sats_swap();
|
|
382
|
+
init_swap_want_asset_program_v1();
|
|
383
|
+
init_swap_want_btc_program_v1();
|
|
384
|
+
init_rfq_contract();
|
|
385
|
+
init_rfq_contract();
|
|
386
|
+
swapPrograms = {
|
|
387
|
+
wantAsset: import_sdk.arkade.programFromArtifact(asset_swap_default),
|
|
388
|
+
wantBtc: import_sdk.arkade.programFromArtifact(sats_swap_default)
|
|
389
|
+
};
|
|
390
|
+
legacySwapPrograms = {
|
|
391
|
+
wantAsset: import_sdk.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
392
|
+
wantBtc: import_sdk.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
393
|
+
};
|
|
394
|
+
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
395
|
+
user,
|
|
396
|
+
server,
|
|
397
|
+
...exitDelay && { exitDelay }
|
|
398
|
+
});
|
|
399
|
+
ASSET_SWAP_CONTRACTS = {
|
|
400
|
+
[ASSET_SWAP_V2]: {
|
|
401
|
+
programs: legacySwapPrograms,
|
|
402
|
+
args: (inputs) => ({
|
|
403
|
+
makerWP: inputs.receiver,
|
|
404
|
+
wantAmount: inputs.amount,
|
|
405
|
+
...inputs.asset && {
|
|
406
|
+
wantAssetTxid: inputs.asset.txid,
|
|
407
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
408
|
+
},
|
|
409
|
+
...sharedArgs(inputs)
|
|
410
|
+
})
|
|
411
|
+
},
|
|
412
|
+
[ASSET_SWAP_V3]: {
|
|
413
|
+
programs: swapPrograms,
|
|
414
|
+
args: (inputs) => ({
|
|
415
|
+
receiver: inputs.receiver,
|
|
416
|
+
amount: inputs.amount,
|
|
417
|
+
...inputs.asset && {
|
|
418
|
+
assetTxid: inputs.asset.txid,
|
|
419
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
420
|
+
},
|
|
421
|
+
...sharedArgs(inputs)
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V3, ASSET_SWAP_V2];
|
|
426
|
+
assetSwapContractVersion = (id) => {
|
|
427
|
+
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
428
|
+
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
429
|
+
throw new Error(`unknown contract version ${id}`);
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
123
434
|
// src/coverage.ts
|
|
124
435
|
function markIssued(script, issued, options) {
|
|
125
436
|
const scope = options.scope ?? legacyScope;
|
|
@@ -253,27 +564,27 @@ function assertRfqSwapPageFilter(filter) {
|
|
|
253
564
|
throw new RangeError("RFQ history since must be non-negative Unix seconds");
|
|
254
565
|
}
|
|
255
566
|
}
|
|
256
|
-
var
|
|
567
|
+
var import_sdk2, collectAssetSwaps, collectRfqSwaps, collectSwapRecords;
|
|
257
568
|
var init_repository = __esm({
|
|
258
569
|
"src/repository.ts"() {
|
|
259
570
|
"use strict";
|
|
260
|
-
|
|
261
|
-
collectAssetSwaps = (repository) => (0,
|
|
262
|
-
collectRfqSwaps = (repository, filter = {}) => (0,
|
|
571
|
+
import_sdk2 = require("@arkade-os/sdk");
|
|
572
|
+
collectAssetSwaps = (repository) => (0, import_sdk2.collectPages)((page) => repository.getAssetSwapsPage(page));
|
|
573
|
+
collectRfqSwaps = (repository, filter = {}) => (0, import_sdk2.collectPages)(
|
|
263
574
|
(page) => repository.getRfqSwapsPage(filter, page)
|
|
264
575
|
);
|
|
265
|
-
collectSwapRecords = (repository) => (0,
|
|
576
|
+
collectSwapRecords = (repository) => (0, import_sdk2.collectPages)((page) => repository.getSwapRecordsPage(page));
|
|
266
577
|
}
|
|
267
578
|
});
|
|
268
579
|
|
|
269
580
|
// src/store.ts
|
|
270
|
-
var import_base, import_sha2,
|
|
581
|
+
var import_base, import_sha2, import_sdk3, BTC_ASSET_ID, byNewest, getAssetSwapsOrThrow, getAssetSwaps, saveSwapOrThrow, updateAssetSwap, updateAssetSwapBestEffort, swapSecretsToRecord, decodeHex32, PreimageNotRecoverableError, preimageForSwapRecord;
|
|
271
582
|
var init_store = __esm({
|
|
272
583
|
"src/store.ts"() {
|
|
273
584
|
"use strict";
|
|
274
585
|
import_base = require("@scure/base");
|
|
275
586
|
import_sha2 = require("@noble/hashes/sha2.js");
|
|
276
|
-
|
|
587
|
+
import_sdk3 = require("@arkade-os/sdk");
|
|
277
588
|
init_repository();
|
|
278
589
|
BTC_ASSET_ID = "btc";
|
|
279
590
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
@@ -359,7 +670,7 @@ var init_store = __esm({
|
|
|
359
670
|
}
|
|
360
671
|
let preimage;
|
|
361
672
|
try {
|
|
362
|
-
preimage = await (0,
|
|
673
|
+
preimage = await (0, import_sdk3.contractPreimage)(wallet, record.signingDescriptor, { stored, salt });
|
|
363
674
|
} catch (cause) {
|
|
364
675
|
throw new PreimageNotRecoverableError(
|
|
365
676
|
"not-derivable",
|
|
@@ -484,37 +795,60 @@ function withExitClosure(program, exit) {
|
|
|
484
795
|
}
|
|
485
796
|
};
|
|
486
797
|
}
|
|
487
|
-
function swapProgramBinding(offer, operatorPubkey) {
|
|
798
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion = ASSET_SWAP_BASELINE) {
|
|
488
799
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
489
800
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
490
801
|
}
|
|
802
|
+
const expected = offer.swapPkScript;
|
|
803
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
804
|
+
const funded = import_base2.hex.encode(expected);
|
|
805
|
+
const order = [
|
|
806
|
+
ASSET_SWAP_BASELINE,
|
|
807
|
+
...ASSET_SWAP_CONTRACT_VERSIONS.filter((v) => v !== ASSET_SWAP_BASELINE)
|
|
808
|
+
];
|
|
809
|
+
for (const version of order) {
|
|
810
|
+
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
811
|
+
if (pkOf(binding) === funded) return binding;
|
|
812
|
+
}
|
|
813
|
+
return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
814
|
+
}
|
|
815
|
+
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
816
|
+
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
817
|
+
const user = offer.makerPublicKey;
|
|
818
|
+
const assetId = offer.wantAsset;
|
|
491
819
|
return {
|
|
492
|
-
program: withExitClosure(
|
|
493
|
-
|
|
494
|
-
offer.
|
|
495
|
-
|
|
496
|
-
args: {
|
|
497
|
-
makerWP: offer.makerPkScript.subarray(2),
|
|
498
|
-
wantAmount: offer.wantAmount,
|
|
499
|
-
server: operatorPubkey,
|
|
500
|
-
user: offer.makerPublicKey,
|
|
820
|
+
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
821
|
+
args: args({
|
|
822
|
+
receiver: offer.makerPkScript.subarray(2),
|
|
823
|
+
amount: offer.wantAmount,
|
|
501
824
|
// internal byte order
|
|
502
|
-
...
|
|
503
|
-
|
|
504
|
-
wantAssetGroupIndex: offer.wantAsset.groupIndex
|
|
825
|
+
...assetId && {
|
|
826
|
+
asset: { txid: assetId.txid.slice().reverse(), groupIndex: assetId.groupIndex }
|
|
505
827
|
},
|
|
828
|
+
user,
|
|
829
|
+
server: operatorPubkey,
|
|
506
830
|
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
507
|
-
},
|
|
831
|
+
}),
|
|
508
832
|
keys: {
|
|
509
833
|
serverKey: operatorPubkey,
|
|
510
|
-
userKey:
|
|
834
|
+
userKey: user,
|
|
511
835
|
emulatorKey: offer.emulatorPubkey
|
|
512
836
|
}
|
|
513
837
|
};
|
|
514
838
|
}
|
|
515
|
-
function
|
|
516
|
-
|
|
517
|
-
|
|
839
|
+
function compileSwapBinding(binding) {
|
|
840
|
+
let script = compiledBindings.get(binding);
|
|
841
|
+
if (!script) {
|
|
842
|
+
script = new import_sdk4.arkade.ArkadeProgramScript(binding.program, binding.args, binding.keys);
|
|
843
|
+
compiledBindings.set(binding, script);
|
|
844
|
+
}
|
|
845
|
+
return script;
|
|
846
|
+
}
|
|
847
|
+
function pkOf(binding) {
|
|
848
|
+
return import_base2.hex.encode(compileSwapBinding(binding).pkScript);
|
|
849
|
+
}
|
|
850
|
+
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
851
|
+
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
518
852
|
}
|
|
519
853
|
function u64(name, value) {
|
|
520
854
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
@@ -630,8 +964,8 @@ function decodeOffer(data) {
|
|
|
630
964
|
return {
|
|
631
965
|
swapPkScript: need("swapPkScript"),
|
|
632
966
|
wantAmount: readU64(amount),
|
|
633
|
-
...fields.wantAsset && { wantAsset:
|
|
634
|
-
...fields.offerAsset && { offerAsset:
|
|
967
|
+
...fields.wantAsset && { wantAsset: import_sdk4.asset.AssetId.fromBytes(fields.wantAsset) },
|
|
968
|
+
...fields.offerAsset && { offerAsset: import_sdk4.asset.AssetId.fromBytes(fields.offerAsset) },
|
|
635
969
|
makerPkScript: need("makerPkScript"),
|
|
636
970
|
makerPublicKey: need("makerPublicKey"),
|
|
637
971
|
emulatorPubkey: need("emulatorPubkey"),
|
|
@@ -657,8 +991,11 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
657
991
|
});
|
|
658
992
|
}
|
|
659
993
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
660
|
-
const { program, args, keys } = swapProgramBinding(
|
|
661
|
-
|
|
994
|
+
const { program, args, keys } = swapProgramBinding(
|
|
995
|
+
{ ...binding, swapPkScript: expectedPkScript },
|
|
996
|
+
operatorPubkey
|
|
997
|
+
);
|
|
998
|
+
const contract = new import_sdk4.arkade.ArkadeContract(client, program, args, keys);
|
|
662
999
|
if (import_base2.hex.encode(contract.pkScript) !== import_base2.hex.encode(expectedPkScript)) {
|
|
663
1000
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
664
1001
|
}
|
|
@@ -675,7 +1012,7 @@ async function restoreOfferCoverage(wallet, swaps) {
|
|
|
675
1012
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
676
1013
|
wallet.getContractManager()
|
|
677
1014
|
]);
|
|
678
|
-
const operatorPubkey = import_base2.hex.decode((0,
|
|
1015
|
+
const operatorPubkey = import_base2.hex.decode((0, import_sdk4.toXOnlySignerHex)(info.signerPubkey));
|
|
679
1016
|
const client = await derivingClient(wallet, info, contractManager);
|
|
680
1017
|
const rows = await contractManager.getContracts({
|
|
681
1018
|
script: live.map((swap) => swap.swapPkScript)
|
|
@@ -698,7 +1035,7 @@ async function restoreOfferCoverage(wallet, swaps) {
|
|
|
698
1035
|
params: offerContractParams(
|
|
699
1036
|
client,
|
|
700
1037
|
binding,
|
|
701
|
-
stored ? import_base2.hex.decode((0,
|
|
1038
|
+
stored ? import_base2.hex.decode((0, import_sdk4.toXOnlySignerHex)(stored)) : operatorPubkey,
|
|
702
1039
|
import_base2.hex.decode(swap.swapPkScript)
|
|
703
1040
|
)
|
|
704
1041
|
});
|
|
@@ -742,7 +1079,7 @@ function resolveReceivePkScript(receiveAddress, walletPkScript, hrp, serverPubKe
|
|
|
742
1079
|
if (receiveAddress === void 0) return walletPkScript;
|
|
743
1080
|
let address;
|
|
744
1081
|
try {
|
|
745
|
-
address =
|
|
1082
|
+
address = import_sdk4.ArkAddress.decode(receiveAddress);
|
|
746
1083
|
} catch (cause) {
|
|
747
1084
|
throw new Error("receiveAddress is not a valid Arkade address", { cause });
|
|
748
1085
|
}
|
|
@@ -777,13 +1114,13 @@ async function deriveOffer(wallet, params) {
|
|
|
777
1114
|
wallet.getAddress(),
|
|
778
1115
|
wallet.identity.xOnlyPublicKey()
|
|
779
1116
|
]);
|
|
780
|
-
return { pkScript:
|
|
1117
|
+
return { pkScript: import_sdk4.ArkAddress.decode(address).pkScript, publicKey };
|
|
781
1118
|
})()
|
|
782
1119
|
]);
|
|
783
|
-
const operatorPubKey = import_base2.hex.decode((0,
|
|
784
|
-
const network = (0,
|
|
1120
|
+
const operatorPubKey = import_base2.hex.decode((0, import_sdk4.toXOnlySignerHex)(info.signerPubkey));
|
|
1121
|
+
const network = (0, import_sdk4.networkFromOperatorInfo)(info);
|
|
785
1122
|
const emuKey = import_base2.hex.decode(
|
|
786
|
-
(0,
|
|
1123
|
+
(0, import_sdk4.toXOnlySignerHex)((0, import_sdk4.resolveEmulatorPubkey)(network, params.emulatorPubkey))
|
|
787
1124
|
);
|
|
788
1125
|
const binding = Object.freeze({
|
|
789
1126
|
wantAmount: params.wantAmount,
|
|
@@ -800,7 +1137,7 @@ async function deriveOffer(wallet, params) {
|
|
|
800
1137
|
// checked before registration below. @see assertExitDelay
|
|
801
1138
|
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
802
1139
|
});
|
|
803
|
-
const script = offerContract(binding, operatorPubKey);
|
|
1140
|
+
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
804
1141
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
805
1142
|
const payload = encodeOffer(offer);
|
|
806
1143
|
return Object.freeze({
|
|
@@ -834,7 +1171,7 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
834
1171
|
wallet.getArkadeReader(),
|
|
835
1172
|
wallet.getArkadeBroadcaster()
|
|
836
1173
|
]);
|
|
837
|
-
const client = await
|
|
1174
|
+
const client = await import_sdk4.arkade.Arkade.connect({
|
|
838
1175
|
arkade: { getInfo: async () => info, ...broadcaster },
|
|
839
1176
|
indexer: reader,
|
|
840
1177
|
identity: wallet.identity,
|
|
@@ -844,21 +1181,22 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
844
1181
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
845
1182
|
oneShotSubmit: wallet.oneShotSubmit
|
|
846
1183
|
});
|
|
847
|
-
const operatorPubkey = swapAddress ?
|
|
848
|
-
|
|
1184
|
+
const operatorPubkey = swapAddress ? import_sdk4.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1185
|
+
let binding;
|
|
849
1186
|
let rebuilt;
|
|
850
1187
|
try {
|
|
851
|
-
|
|
1188
|
+
binding = swapProgramBinding(offer, operatorPubkey);
|
|
1189
|
+
rebuilt = compileSwapBinding(binding);
|
|
852
1190
|
} catch (cause) {
|
|
853
1191
|
throw new OfferCovenantMismatchError(import_base2.hex.encode(offer.swapPkScript), { cause });
|
|
854
1192
|
}
|
|
855
1193
|
if (import_base2.hex.encode(rebuilt.pkScript) !== import_base2.hex.encode(offer.swapPkScript)) {
|
|
856
1194
|
throw new OfferCovenantMismatchError(import_base2.hex.encode(offer.swapPkScript));
|
|
857
1195
|
}
|
|
858
|
-
const contract = new
|
|
1196
|
+
const contract = new import_sdk4.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
859
1197
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
860
1198
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
861
|
-
const makerPkScript =
|
|
1199
|
+
const makerPkScript = import_sdk4.ArkAddress.decode(makerAddress).pkScript;
|
|
862
1200
|
const cancel = contract.functions.cancel().from({ txid: vtxo.txid, vout: vtxo.vout, value: vtxo.value }).to(makerPkScript, BigInt(vtxo.value));
|
|
863
1201
|
for (const a of vtxo.assets ?? []) {
|
|
864
1202
|
cancel.withAsset({
|
|
@@ -876,25 +1214,25 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
876
1214
|
async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
877
1215
|
const { swapAddress, emulator, emulatorPubkey } = opts;
|
|
878
1216
|
const contractManager = await wallet.getContractManager();
|
|
879
|
-
const client = await
|
|
880
|
-
arkade: new
|
|
881
|
-
indexer: new
|
|
1217
|
+
const client = await import_sdk4.arkade.Arkade.connect({
|
|
1218
|
+
arkade: new import_sdk4.RestOperatorProvider(arkServerUrl),
|
|
1219
|
+
indexer: new import_sdk4.RestIndexerProvider(arkServerUrl),
|
|
882
1220
|
identity: wallet.identity,
|
|
883
1221
|
contractManager,
|
|
884
1222
|
...emulator !== void 0 ? {
|
|
885
|
-
emulator: typeof emulator === "string" ? new
|
|
1223
|
+
emulator: typeof emulator === "string" ? new import_sdk4.RestEmulatorProvider(emulator) : emulator
|
|
886
1224
|
} : {},
|
|
887
1225
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
888
1226
|
});
|
|
889
|
-
const serverKey = swapAddress ?
|
|
890
|
-
const
|
|
891
|
-
const rebuilt =
|
|
1227
|
+
const serverKey = swapAddress ? import_sdk4.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1228
|
+
const binding = swapProgramBinding(offer, serverKey);
|
|
1229
|
+
const rebuilt = compileSwapBinding(binding);
|
|
892
1230
|
if (import_base2.hex.encode(rebuilt.pkScript) !== import_base2.hex.encode(offer.swapPkScript)) {
|
|
893
1231
|
throw new Error(
|
|
894
1232
|
"rebuilt covenant does not match the offer's swapPkScript \u2014 the server signing key has likely rotated since funding; pass swapAddress (the funded address) to pin the original key"
|
|
895
1233
|
);
|
|
896
1234
|
}
|
|
897
|
-
return new
|
|
1235
|
+
return new import_sdk4.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
898
1236
|
}
|
|
899
1237
|
function resolveDeposit(vtxos, sel) {
|
|
900
1238
|
const { fundingTxid, fundingOutpoint } = sel;
|
|
@@ -1183,7 +1521,7 @@ function assertScript(script, what) {
|
|
|
1183
1521
|
function assertAssetId(assetId, what) {
|
|
1184
1522
|
if (typeof assetId !== "string") throw new Error(`${what} must be an asset id string`);
|
|
1185
1523
|
try {
|
|
1186
|
-
return
|
|
1524
|
+
return import_sdk4.asset.AssetId.fromString(assetId).toString();
|
|
1187
1525
|
} catch {
|
|
1188
1526
|
throw new Error(`${what} is not a valid asset id`);
|
|
1189
1527
|
}
|
|
@@ -1205,22 +1543,18 @@ function assertFillCoin(coin, what) {
|
|
|
1205
1543
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
1206
1544
|
assertAssetEntries(coin.assets, what);
|
|
1207
1545
|
}
|
|
1208
|
-
var import_base2, import_utils,
|
|
1546
|
+
var import_base2, import_utils, import_sdk4, compiledBindings, OFFER_PACKET_TYPE, FIELDS, EXIT_TYPES, NAMES, readU64, setRatio, OFFER_CONTRACT_LABEL, OFFER_CONTRACT_KIND, derivingClient, NoSpendableDepositError, OfferCovenantMismatchError, ASSET_CARRIER_SATS, amountOfAsset, U64_MAX, MAX_SAFE_SATS;
|
|
1209
1547
|
var init_offer = __esm({
|
|
1210
1548
|
"src/offer.ts"() {
|
|
1211
1549
|
"use strict";
|
|
1212
1550
|
import_base2 = require("@scure/base");
|
|
1213
1551
|
import_utils = require("@scure/btc-signer/utils.js");
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
init_swap_want_btc_program();
|
|
1552
|
+
import_sdk4 = require("@arkade-os/sdk");
|
|
1553
|
+
init_program();
|
|
1217
1554
|
init_coverage();
|
|
1218
1555
|
init_rfqProfileParts();
|
|
1219
1556
|
init_store();
|
|
1220
|
-
|
|
1221
|
-
wantAsset: import_sdk3.arkade.parseArtifact(swap_want_asset_program_default),
|
|
1222
|
-
wantBtc: import_sdk3.arkade.parseArtifact(swap_want_btc_program_default)
|
|
1223
|
-
};
|
|
1557
|
+
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
1224
1558
|
OFFER_PACKET_TYPE = 3;
|
|
1225
1559
|
FIELDS = {
|
|
1226
1560
|
swapPkScript: { tag: 1, width: 34 },
|
|
@@ -1244,10 +1578,10 @@ var init_offer = __esm({
|
|
|
1244
1578
|
};
|
|
1245
1579
|
OFFER_CONTRACT_LABEL = "Arkade swap offer";
|
|
1246
1580
|
OFFER_CONTRACT_KIND = "asset-swap-offer";
|
|
1247
|
-
derivingClient = (wallet, info, contractManager) =>
|
|
1581
|
+
derivingClient = (wallet, info, contractManager) => import_sdk4.arkade.Arkade.connect({
|
|
1248
1582
|
arkade: { getInfo: async () => info },
|
|
1249
1583
|
identity: wallet.identity,
|
|
1250
|
-
network: (0,
|
|
1584
|
+
network: (0, import_sdk4.networkFromOperatorInfo)(info),
|
|
1251
1585
|
contractManager
|
|
1252
1586
|
});
|
|
1253
1587
|
NoSpendableDepositError = class extends Error {
|
|
@@ -1267,7 +1601,7 @@ var init_offer = __esm({
|
|
|
1267
1601
|
swapPkScript;
|
|
1268
1602
|
name = "OfferCovenantMismatchError";
|
|
1269
1603
|
};
|
|
1270
|
-
ASSET_CARRIER_SATS = BigInt(
|
|
1604
|
+
ASSET_CARRIER_SATS = BigInt(import_sdk4.ASSET_CARRIER_SATS);
|
|
1271
1605
|
amountOfAsset = (assets, assetId) => {
|
|
1272
1606
|
let total = BigInt(0);
|
|
1273
1607
|
for (const a of assets ?? []) {
|
|
@@ -1287,7 +1621,7 @@ async function registerLockupContract(contracts, script, address, options = {})
|
|
|
1287
1621
|
import_base3.hex.encode(script.pkScript),
|
|
1288
1622
|
() => contracts.createContract({
|
|
1289
1623
|
type: SWAP_LOCKUP_CONTRACT_TYPE,
|
|
1290
|
-
params:
|
|
1624
|
+
params: import_sdk5.VHTLCV2ContractHandler.serializeParams(script.options),
|
|
1291
1625
|
script: import_base3.hex.encode(script.pkScript),
|
|
1292
1626
|
address,
|
|
1293
1627
|
label: SWAP_LOCKUP_CONTRACT_LABEL,
|
|
@@ -1300,18 +1634,18 @@ async function registerLockupContract(contracts, script, address, options = {})
|
|
|
1300
1634
|
}
|
|
1301
1635
|
}
|
|
1302
1636
|
async function lockupContractParams(contracts, lockupAddress) {
|
|
1303
|
-
const script = import_base3.hex.encode(
|
|
1637
|
+
const script = import_base3.hex.encode(import_sdk5.ArkAddress.decode(lockupAddress).pkScript);
|
|
1304
1638
|
const [row] = await contracts.getContracts({ script });
|
|
1305
1639
|
if (!row) throw new LockupContractMissing(lockupAddress, script);
|
|
1306
1640
|
return row.params;
|
|
1307
1641
|
}
|
|
1308
|
-
var import_base3,
|
|
1642
|
+
var import_base3, import_sdk5, SWAP_LOCKUP_CONTRACT_TYPE, SWAP_LOCKUP_CONTRACT_LABEL, SWAP_LOCKUP_CONTRACT_KIND, LockupContractMissing, LockupRegistrationFailed;
|
|
1309
1643
|
var init_lockupContract = __esm({
|
|
1310
1644
|
"src/lockupContract.ts"() {
|
|
1311
1645
|
"use strict";
|
|
1312
1646
|
init_coverage();
|
|
1313
1647
|
import_base3 = require("@scure/base");
|
|
1314
|
-
|
|
1648
|
+
import_sdk5 = require("@arkade-os/sdk");
|
|
1315
1649
|
SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
|
|
1316
1650
|
SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
|
|
1317
1651
|
SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
|
|
@@ -1464,7 +1798,7 @@ async function classifyOnchainHtlc(chain, input) {
|
|
|
1464
1798
|
if (mtp >= input.htlc.refundLocktime) return { phase: "refundable", utxo: best };
|
|
1465
1799
|
return { phase: "claimable", utxo: best };
|
|
1466
1800
|
}
|
|
1467
|
-
var import_base4, import_sha22, import_legacy, btc,
|
|
1801
|
+
var import_base4, import_sha22, import_legacy, btc, import_sdk6, ONCHAIN_ORDER_MARGIN_SECONDS, ONCHAIN_CLAIM_MARGIN_SECONDS, ONCHAIN_CLAIM_BUMP_SECONDS, MAX_MIN_CONFIRMATIONS, LOCKTIME_THRESHOLD, ONCHAIN_SECONDS_PER_BLOCK, ONCHAIN_DUST_SATS, ONCHAIN_CLAIM_VSIZE, paymentHashOf, h160FromPaymentHash, assertPreimageMatches, gateError, L1_NETWORKS, l1ScriptForAddress, buildLeafSpend, buildHtlcClaim, buildHtlcRefund;
|
|
1468
1802
|
var init_onchainHtlc = __esm({
|
|
1469
1803
|
"src/onchainHtlc.ts"() {
|
|
1470
1804
|
"use strict";
|
|
@@ -1472,7 +1806,7 @@ var init_onchainHtlc = __esm({
|
|
|
1472
1806
|
import_sha22 = require("@noble/hashes/sha2.js");
|
|
1473
1807
|
import_legacy = require("@noble/hashes/legacy.js");
|
|
1474
1808
|
btc = __toESM(require("@scure/btc-signer"), 1);
|
|
1475
|
-
|
|
1809
|
+
import_sdk6 = require("@arkade-os/sdk");
|
|
1476
1810
|
ONCHAIN_ORDER_MARGIN_SECONDS = 2 * 60 * 60;
|
|
1477
1811
|
ONCHAIN_CLAIM_MARGIN_SECONDS = 90 * 60;
|
|
1478
1812
|
ONCHAIN_CLAIM_BUMP_SECONDS = 20 * 60;
|
|
@@ -1672,7 +2006,7 @@ function deriveLightningSend(input) {
|
|
|
1672
2006
|
throw new Error("lightning-send quote is missing profile.receiver_pk_script");
|
|
1673
2007
|
}
|
|
1674
2008
|
const contractParams = {
|
|
1675
|
-
solverPubkey: (0,
|
|
2009
|
+
solverPubkey: (0, import_sdk8.toXOnly)(import_base7.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1676
2010
|
refundLocktime: quote.refund_locktime,
|
|
1677
2011
|
operatorPubkey: input.operatorPubkey,
|
|
1678
2012
|
paymentHash: input.paymentHash,
|
|
@@ -1718,7 +2052,7 @@ function deriveOnchainSend(input) {
|
|
|
1718
2052
|
"onchain-send"
|
|
1719
2053
|
);
|
|
1720
2054
|
const contractParams = {
|
|
1721
|
-
solverPubkey: (0,
|
|
2055
|
+
solverPubkey: (0, import_sdk8.toXOnly)(import_base7.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1722
2056
|
refundLocktime,
|
|
1723
2057
|
operatorPubkey: input.operatorPubkey,
|
|
1724
2058
|
paymentHash: input.paymentHash,
|
|
@@ -1727,7 +2061,7 @@ function deriveOnchainSend(input) {
|
|
|
1727
2061
|
emulatorPubkey: input.emulatorPubkey,
|
|
1728
2062
|
senderPubkey: input.senderPubkey,
|
|
1729
2063
|
receiverPkScript: solverHex(receiverPkScriptHex, "profile.receiver_pk_script"),
|
|
1730
|
-
refundPkScript:
|
|
2064
|
+
refundPkScript: import_sdk8.ArkAddress.decode(input.refundAddress).pkScript
|
|
1731
2065
|
};
|
|
1732
2066
|
const { script, address } = matchQuotedLockup(
|
|
1733
2067
|
quote,
|
|
@@ -1738,7 +2072,7 @@ function deriveOnchainSend(input) {
|
|
|
1738
2072
|
const htlcParams = {
|
|
1739
2073
|
paymentHash: input.paymentHash,
|
|
1740
2074
|
claimKey: input.payoutPubkey,
|
|
1741
|
-
refundKey: (0,
|
|
2075
|
+
refundKey: (0, import_sdk8.toXOnly)(import_base7.hex.decode(htlcPubkey), "solver L1 htlc key"),
|
|
1742
2076
|
refundLocktime: htlcLocktime
|
|
1743
2077
|
};
|
|
1744
2078
|
const htlc = onchainHtlcScript(htlcParams, input.l1Network);
|
|
@@ -1810,7 +2144,7 @@ function deriveOnchainReceive(input) {
|
|
|
1810
2144
|
).matched;
|
|
1811
2145
|
const htlcParams = {
|
|
1812
2146
|
paymentHash: input.paymentHash,
|
|
1813
|
-
claimKey: (0,
|
|
2147
|
+
claimKey: (0, import_sdk8.toXOnly)(import_base7.hex.decode(claimPubkey), "solver L1 claim key"),
|
|
1814
2148
|
refundKey: input.refundPubkey,
|
|
1815
2149
|
refundLocktime: htlcLocktime
|
|
1816
2150
|
};
|
|
@@ -1827,21 +2161,23 @@ function deriveOnchainReceive(input) {
|
|
|
1827
2161
|
minConfirmations
|
|
1828
2162
|
};
|
|
1829
2163
|
}
|
|
1830
|
-
var import_base7, import_solver_discovery, import_legacy2,
|
|
2164
|
+
var import_base7, import_solver_discovery, import_legacy2, import_sdk8, import_sdk9, solverHex, quoteSats, quoteAmountSats, quoteExpectedSats, ARKADE_BTC, LIGHTNING_BTC, ONCHAIN_BTC, arkadeAssetLeg, rfqPair, LIGHTNING_SEND_PAIR, LIGHTNING_RECEIVE_PAIR, ONCHAIN_SEND_PAIR, ONCHAIN_RECEIVE_PAIR, RFQ_REFUSAL_ERROR_CODES, isRfqRefusalErrorCode, REFUSAL_FIELDS, REFUSAL_UNITS, safeInteger, safeRefusalDetail, refusalMessage, SwapRefusal, AddressMismatch, newRfqId, lightningSendRequest, arkadeSwapRequest, canonicalAssetAmount, normalizeHexBytes, normalizeMakerPkScript, normalizeMakerPublicKey, MIN_HEADROOM_SECONDS, assertFinite, MAX_PAIR_LENGTH, assertPairLength, verifyLockupAddress, LOCKUP_SHAPE_VARIANTS, matchQuotedLockup, assertFundable, expectQuote, requestVersionedQuote, pairOf, SEQUENCE_GRANULARITY_SECONDS, SOLO_REFUND_HEADROOM_SECONDS, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, seconds, suiteVhtlc, quotedSoloRefundDelay, offerTermsFromQuote, verifyOfferAddress, quoteCarrierSats, l1NetworkFromArk, onchainSendRequest, lightningReceiveRequest, onchainReceiveRequest, MIN_CLAIM_WINDOW_SECONDS, assertReceivable, matchReceiveLockup;
|
|
1831
2165
|
var init_rfq = __esm({
|
|
1832
2166
|
"src/rfq.ts"() {
|
|
1833
2167
|
"use strict";
|
|
1834
2168
|
import_base7 = require("@scure/base");
|
|
1835
2169
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
1836
2170
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
1837
|
-
|
|
2171
|
+
import_sdk8 = require("@arkade-os/sdk");
|
|
1838
2172
|
init_onchainHtlc();
|
|
1839
2173
|
init_onchainHtlc();
|
|
1840
|
-
|
|
2174
|
+
import_sdk9 = require("@arkade-os/sdk");
|
|
1841
2175
|
init_claimAmountGate();
|
|
1842
2176
|
init_claimPacket();
|
|
1843
2177
|
init_lockupContract();
|
|
1844
2178
|
init_offer();
|
|
2179
|
+
init_program();
|
|
2180
|
+
init_rfq_contract();
|
|
1845
2181
|
solverHex = (value, field) => {
|
|
1846
2182
|
try {
|
|
1847
2183
|
return import_base7.hex.decode(value);
|
|
@@ -1878,6 +2214,7 @@ var init_rfq = __esm({
|
|
|
1878
2214
|
ONCHAIN_RECEIVE_PAIR = rfqPair(ONCHAIN_BTC, ARKADE_BTC);
|
|
1879
2215
|
RFQ_REFUSAL_ERROR_CODES = [
|
|
1880
2216
|
"amount_side_unsupported",
|
|
2217
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED,
|
|
1881
2218
|
"exact_out_unsupported",
|
|
1882
2219
|
"invalid_amount",
|
|
1883
2220
|
"invalid_payout_address",
|
|
@@ -1993,6 +2330,7 @@ var init_rfq = __esm({
|
|
|
1993
2330
|
pair,
|
|
1994
2331
|
amount_side: input.amountSide ?? "from",
|
|
1995
2332
|
amount: canonicalAssetAmount(input.amount),
|
|
2333
|
+
...input.contractVersions && input.contractVersions.length > 0 ? { [RFQ_CONTRACT_VERSIONS_KEY]: [...input.contractVersions] } : {},
|
|
1996
2334
|
// The solver's `.strict()` schema refuses any undeclared key as `unsupported_payload`.
|
|
1997
2335
|
profile: {
|
|
1998
2336
|
maker_pk_script: normalizeMakerPkScript(input.makerPkScript),
|
|
@@ -2180,6 +2518,34 @@ var init_rfq = __esm({
|
|
|
2180
2518
|
}
|
|
2181
2519
|
return payload;
|
|
2182
2520
|
};
|
|
2521
|
+
requestVersionedQuote = async (transport, request, advertised) => {
|
|
2522
|
+
if (advertised.length === 0) {
|
|
2523
|
+
throw new Error("contractVersions is empty: advertise at least one contract version");
|
|
2524
|
+
}
|
|
2525
|
+
let sent = request;
|
|
2526
|
+
let quote;
|
|
2527
|
+
try {
|
|
2528
|
+
quote = await transport.requestQuote(request);
|
|
2529
|
+
} catch (error) {
|
|
2530
|
+
if (!(error instanceof SwapRefusal) || error.reason !== "unsupported_payload" || error.errorCode !== void 0 || !advertised.includes(ASSET_SWAP_BASELINE)) {
|
|
2531
|
+
throw error;
|
|
2532
|
+
}
|
|
2533
|
+
const { [RFQ_CONTRACT_VERSIONS_KEY]: _, ...baseline } = request;
|
|
2534
|
+
sent = { ...baseline, rfq_id: newRfqId() };
|
|
2535
|
+
quote = await transport.requestQuote(sent);
|
|
2536
|
+
}
|
|
2537
|
+
const selected = quote[RFQ_CONTRACT_VERSION_KEY];
|
|
2538
|
+
if (sent !== request && selected !== void 0) {
|
|
2539
|
+
throw new Error(`solver chose contract version ${selected}, but none was advertised`);
|
|
2540
|
+
}
|
|
2541
|
+
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2542
|
+
if (!advertised.includes(version)) {
|
|
2543
|
+
throw new Error(
|
|
2544
|
+
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
2548
|
+
};
|
|
2183
2549
|
pairOf = (payload) => typeof payload.pair === "string" ? payload.pair : void 0;
|
|
2184
2550
|
SEQUENCE_GRANULARITY_SECONDS = 512;
|
|
2185
2551
|
SOLO_REFUND_HEADROOM_SECONDS = 8 * SEQUENCE_GRANULARITY_SECONDS;
|
|
@@ -2202,7 +2568,7 @@ var init_rfq = __esm({
|
|
|
2202
2568
|
type: "seconds",
|
|
2203
2569
|
value: BigInt(value)
|
|
2204
2570
|
});
|
|
2205
|
-
suiteVhtlc = (params, roles) => new
|
|
2571
|
+
suiteVhtlc = (params, roles) => new import_sdk8.VHTLC.ScriptV2({
|
|
2206
2572
|
sender: roles.sender,
|
|
2207
2573
|
receiver: roles.receiver,
|
|
2208
2574
|
server: params.operatorPubkey,
|
|
@@ -2331,7 +2697,7 @@ var init_rfq = __esm({
|
|
|
2331
2697
|
};
|
|
2332
2698
|
matchReceiveLockup = (input, refundLocktime, solverRefundPkScriptHex) => {
|
|
2333
2699
|
const contractParams = {
|
|
2334
|
-
solverPubkey: (0,
|
|
2700
|
+
solverPubkey: (0, import_sdk8.toXOnly)(import_base7.hex.decode(input.quote.solver_pubkey), "solver key"),
|
|
2335
2701
|
refundLocktime,
|
|
2336
2702
|
operatorPubkey: input.operatorPubkey,
|
|
2337
2703
|
paymentHash: input.paymentHash,
|
|
@@ -2339,7 +2705,7 @@ var init_rfq = __esm({
|
|
|
2339
2705
|
emulatorPubkey: input.emulatorPubkey,
|
|
2340
2706
|
solverRefundPkScript: solverHex(solverRefundPkScriptHex, "profile.solver_refund_pk_script"),
|
|
2341
2707
|
payoutPubkey: input.payoutPubkey,
|
|
2342
|
-
payoutPkScript:
|
|
2708
|
+
payoutPkScript: import_sdk8.ArkAddress.decode(input.payoutAddress).pkScript
|
|
2343
2709
|
};
|
|
2344
2710
|
const matched = matchQuotedLockup(
|
|
2345
2711
|
input.quote,
|
|
@@ -2501,14 +2867,14 @@ __export(nostr_exports, {
|
|
|
2501
2867
|
nostrRfqTransport: () => nostrRfqTransport,
|
|
2502
2868
|
sharedNostrPool: () => sharedNostrPool
|
|
2503
2869
|
});
|
|
2504
|
-
var import_solver_discovery7,
|
|
2870
|
+
var import_solver_discovery7, import_sdk20, import_nostr_tools2, RFQ_DIRECTED_KIND, DEFAULT_TIMEOUT_MS, CONNECTION_FAILURE, CARD_FETCH_TIMEOUT_MS, RelayUnavailable, TransportClosed, closeReasons, nostrRfqTransport, isNewer, nostrCardFetcher;
|
|
2505
2871
|
var init_nostr = __esm({
|
|
2506
2872
|
"src/nostr.ts"() {
|
|
2507
2873
|
"use strict";
|
|
2508
2874
|
import_solver_discovery7 = require("@arkade-os/solver-discovery");
|
|
2509
2875
|
init_rfq();
|
|
2510
2876
|
init_nostrPool();
|
|
2511
|
-
|
|
2877
|
+
import_sdk20 = require("@arkade-os/sdk");
|
|
2512
2878
|
import_nostr_tools2 = require("nostr-tools");
|
|
2513
2879
|
init_nostrPool();
|
|
2514
2880
|
RFQ_DIRECTED_KIND = 24859;
|
|
@@ -2535,7 +2901,7 @@ var init_nostr = __esm({
|
|
|
2535
2901
|
return url ? `${url}: ${reason ?? "closed"}` : reason ?? "closed";
|
|
2536
2902
|
});
|
|
2537
2903
|
nostrRfqTransport = (options) => {
|
|
2538
|
-
(0,
|
|
2904
|
+
(0, import_sdk20.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
2539
2905
|
const relays = options.relays;
|
|
2540
2906
|
const solverPubkey = options.solverPubkey;
|
|
2541
2907
|
const secretKey = options.secretKey ?? (0, import_nostr_tools2.generateSecretKey)();
|
|
@@ -2647,7 +3013,7 @@ var init_nostr = __esm({
|
|
|
2647
3013
|
};
|
|
2648
3014
|
isNewer = (event, held) => !held || event.created_at > held.created_at || event.created_at === held.created_at && event.id < held.id;
|
|
2649
3015
|
nostrCardFetcher = (options = {}) => {
|
|
2650
|
-
(0,
|
|
3016
|
+
(0, import_sdk20.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
2651
3017
|
if (options.timeoutMs === 0) throw new Error("timeoutMs must be positive");
|
|
2652
3018
|
const seen = /* @__PURE__ */ new Map();
|
|
2653
3019
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -2925,7 +3291,7 @@ module.exports = __toCommonJS(advanced_exports);
|
|
|
2925
3291
|
// src/client/accept.ts
|
|
2926
3292
|
var import_base9 = require("@scure/base");
|
|
2927
3293
|
var import_solver_discovery6 = require("@arkade-os/solver-discovery");
|
|
2928
|
-
var
|
|
3294
|
+
var import_sdk14 = require("@arkade-os/sdk");
|
|
2929
3295
|
init_offer();
|
|
2930
3296
|
init_coverage();
|
|
2931
3297
|
init_lockupContract();
|
|
@@ -3126,7 +3492,7 @@ init_rfqProfileParts();
|
|
|
3126
3492
|
init_store();
|
|
3127
3493
|
|
|
3128
3494
|
// src/client/assetId.ts
|
|
3129
|
-
var
|
|
3495
|
+
var import_sdk7 = require("@arkade-os/sdk");
|
|
3130
3496
|
var RAILS = ["arkade", "bitcoin", "bolt11", "eip155"];
|
|
3131
3497
|
var BITCOIN_RAILS = ["arkade", "bitcoin", "bolt11"];
|
|
3132
3498
|
var BTC_ASSET_PART = "slip44:0";
|
|
@@ -3155,7 +3521,7 @@ var CHAIN_REFERENCE = /^[-_a-z0-9]{1,32}$/;
|
|
|
3155
3521
|
var CHAIN_ID = /^(0|[1-9][0-9]*)$/;
|
|
3156
3522
|
var ASSET_REFERENCE = /^[-.%a-z0-9]{1,128}$/;
|
|
3157
3523
|
var isRail = (value) => RAILS.includes(value);
|
|
3158
|
-
var isNetworkRef = (value) => Object.hasOwn(
|
|
3524
|
+
var isNetworkRef = (value) => Object.hasOwn(import_sdk7.networks, value);
|
|
3159
3525
|
var parseAssetId = (value) => {
|
|
3160
3526
|
if (/[A-Z]/.test(value)) {
|
|
3161
3527
|
throw new AssetIdError(
|
|
@@ -3220,7 +3586,7 @@ var parseAssetId = (value) => {
|
|
|
3220
3586
|
}
|
|
3221
3587
|
if (namespace === ARKADE_ASSET_NAMESPACE) {
|
|
3222
3588
|
try {
|
|
3223
|
-
|
|
3589
|
+
import_sdk7.asset.AssetId.fromString(assetReference);
|
|
3224
3590
|
} catch (cause) {
|
|
3225
3591
|
throw new AssetIdError(
|
|
3226
3592
|
"invalid_asset_reference",
|
|
@@ -3276,7 +3642,7 @@ var isBtcAssetLenient = (id) => {
|
|
|
3276
3642
|
var arkadeAsset = (network, id) => `arkade:${network}/${ARKADE_ASSET_NAMESPACE}:${id.toString()}`;
|
|
3277
3643
|
var issuanceOf = (id) => {
|
|
3278
3644
|
const { assetNamespace, assetReference } = parseAssetId(id);
|
|
3279
|
-
return assetNamespace === ARKADE_ASSET_NAMESPACE ?
|
|
3645
|
+
return assetNamespace === ARKADE_ASSET_NAMESPACE ? import_sdk7.asset.AssetId.fromString(assetReference) : void 0;
|
|
3280
3646
|
};
|
|
3281
3647
|
|
|
3282
3648
|
// src/client/aliases.ts
|
|
@@ -3516,7 +3882,7 @@ var canonicalAssetId = (input, table) => {
|
|
|
3516
3882
|
};
|
|
3517
3883
|
|
|
3518
3884
|
// src/client/assetPayment.ts
|
|
3519
|
-
var
|
|
3885
|
+
var import_sdk10 = require("@arkade-os/sdk");
|
|
3520
3886
|
var import_solver_discovery3 = require("@arkade-os/solver-discovery");
|
|
3521
3887
|
var DECIMAL = /^(0|[1-9][0-9]*)$/;
|
|
3522
3888
|
var MAX_SATS = 2100000000000000n;
|
|
@@ -3567,7 +3933,7 @@ function validateReceiverPaidQuoteShape(q) {
|
|
|
3567
3933
|
throw new Error("carrier receiver-paid quote needs an assetId");
|
|
3568
3934
|
}
|
|
3569
3935
|
try {
|
|
3570
|
-
|
|
3936
|
+
import_sdk10.asset.AssetId.fromString(q.assetId);
|
|
3571
3937
|
} catch {
|
|
3572
3938
|
throw new Error("carrier receiver-paid quote assetId is not a valid SDK asset id");
|
|
3573
3939
|
}
|
|
@@ -3806,7 +4172,7 @@ var assetPaymentOf = (stored, quoteExpiry) => {
|
|
|
3806
4172
|
};
|
|
3807
4173
|
|
|
3808
4174
|
// src/client/fundingNotSubmitted.ts
|
|
3809
|
-
var
|
|
4175
|
+
var import_sdk11 = require("@arkade-os/sdk");
|
|
3810
4176
|
var import_base8 = require("@scure/base");
|
|
3811
4177
|
init_coverage();
|
|
3812
4178
|
init_repository();
|
|
@@ -4024,7 +4390,7 @@ var retireUnsubmittedFunding = async (wallet, repository, record, contracts) =>
|
|
|
4024
4390
|
status: row.family === "offer" ? row.status : fundingWasNotSubmitted(row) ? "cancelled" : row.state === "settled" || row.state === "refunded" ? "fulfilled" : "pending"
|
|
4025
4391
|
}));
|
|
4026
4392
|
const legacy = (await collectRfqSwaps(repository)).map((row) => ({
|
|
4027
|
-
swapPkScript: import_base8.hex.encode(
|
|
4393
|
+
swapPkScript: import_base8.hex.encode(import_sdk11.ArkAddress.decode(row.lockupAddress).pkScript),
|
|
4028
4394
|
createdAt: row.createdAt * 1e3,
|
|
4029
4395
|
status: row.state === "settled" || row.state === "refunded" ? "fulfilled" : "pending"
|
|
4030
4396
|
}));
|
|
@@ -4039,7 +4405,7 @@ var retireUnsubmittedFunding = async (wallet, repository, record, contracts) =>
|
|
|
4039
4405
|
};
|
|
4040
4406
|
|
|
4041
4407
|
// src/client/corridors/lightning.ts
|
|
4042
|
-
var
|
|
4408
|
+
var import_sdk12 = require("@arkade-os/sdk");
|
|
4043
4409
|
var INVOICE_HRPS = [
|
|
4044
4410
|
["lnbcrt", ["regtest"]],
|
|
4045
4411
|
["lntbs", ["signet", "mutinynet"]],
|
|
@@ -4069,7 +4435,7 @@ var lightningCorridor = Object.assign(
|
|
|
4069
4435
|
deps,
|
|
4070
4436
|
drive: LIGHTNING_DRIVE,
|
|
4071
4437
|
matches(raw) {
|
|
4072
|
-
const invoice = (0,
|
|
4438
|
+
const invoice = (0, import_sdk12.invoiceTarget)(raw);
|
|
4073
4439
|
if (invoice === void 0) return void 0;
|
|
4074
4440
|
const networks2 = networksOfInvoiceHrp(invoice);
|
|
4075
4441
|
if (networks2 === void 0) {
|
|
@@ -4115,11 +4481,11 @@ var lightningCorridor = Object.assign(
|
|
|
4115
4481
|
};
|
|
4116
4482
|
}
|
|
4117
4483
|
}),
|
|
4118
|
-
{ target:
|
|
4484
|
+
{ target: import_sdk12.invoiceTarget }
|
|
4119
4485
|
);
|
|
4120
4486
|
|
|
4121
4487
|
// src/client/corridors/onchain.ts
|
|
4122
|
-
var
|
|
4488
|
+
var import_sdk13 = require("@arkade-os/sdk");
|
|
4123
4489
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
4124
4490
|
init_onchainHtlc();
|
|
4125
4491
|
init_rfq();
|
|
@@ -4149,14 +4515,14 @@ var onchainCorridor = Object.assign(
|
|
|
4149
4515
|
deps,
|
|
4150
4516
|
drive: ONCHAIN_DRIVE,
|
|
4151
4517
|
matches(raw) {
|
|
4152
|
-
const target = (0,
|
|
4518
|
+
const target = (0, import_sdk13.btcTarget)(raw);
|
|
4153
4519
|
if (target === void 0) return void 0;
|
|
4154
4520
|
try {
|
|
4155
4521
|
btc2.Address(L1_NETWORKS[l1]).decode(target);
|
|
4156
4522
|
} catch {
|
|
4157
4523
|
return { refused: `this is not a ${l1} address` };
|
|
4158
4524
|
}
|
|
4159
|
-
const amount =
|
|
4525
|
+
const amount = import_sdk13.BIP21.amountSats(raw);
|
|
4160
4526
|
return {
|
|
4161
4527
|
claimed: {
|
|
4162
4528
|
kind: "address",
|
|
@@ -4167,7 +4533,7 @@ var onchainCorridor = Object.assign(
|
|
|
4167
4533
|
}
|
|
4168
4534
|
};
|
|
4169
4535
|
},
|
|
4170
|
-
{ target:
|
|
4536
|
+
{ target: import_sdk13.btcTarget }
|
|
4171
4537
|
);
|
|
4172
4538
|
|
|
4173
4539
|
// src/client/outcome.ts
|
|
@@ -4521,15 +4887,15 @@ var acceptQuoteBody = async (input) => {
|
|
|
4521
4887
|
var registeredOfferRecord = async (input, preparation) => {
|
|
4522
4888
|
const { quote, wallet, corridors, now } = input;
|
|
4523
4889
|
const { plan } = preparation;
|
|
4524
|
-
const
|
|
4890
|
+
const arkade4 = corridors.get("arkade").deps;
|
|
4525
4891
|
const receiveIsBtc = plan.receive.asset.id === BTC_ASSET_ID;
|
|
4526
4892
|
const offer = await createOffer(
|
|
4527
4893
|
wallet,
|
|
4528
4894
|
{
|
|
4529
4895
|
// Keyed on the receive side: the covenant binds what the fill delivers.
|
|
4530
4896
|
wantAmount: plan.receive.atomic,
|
|
4531
|
-
...receiveIsBtc ? { offerAsset:
|
|
4532
|
-
emulatorPubkey:
|
|
4897
|
+
...receiveIsBtc ? { offerAsset: import_sdk14.asset.AssetId.fromString(plan.deposit.asset.id) } : { wantAsset: import_sdk14.asset.AssetId.fromString(plan.receive.asset.id) },
|
|
4898
|
+
emulatorPubkey: arkade4.emulatorPubkey
|
|
4533
4899
|
},
|
|
4534
4900
|
{ coverageId: quote.id }
|
|
4535
4901
|
);
|
|
@@ -4592,7 +4958,7 @@ var fundAndStamp = async (input, record, repository) => {
|
|
|
4592
4958
|
const txid = await fund({ ...input, ...bounds, validUntil }, record);
|
|
4593
4959
|
return stampFunding(repository, record, txid, input.now);
|
|
4594
4960
|
} catch (error) {
|
|
4595
|
-
if (input.firstFundingAttempt && validUntil !== void 0 && error instanceof
|
|
4961
|
+
if (input.firstFundingAttempt && validUntil !== void 0 && error instanceof import_sdk14.SendDeadlineExceededError) {
|
|
4596
4962
|
const stopped = {
|
|
4597
4963
|
...record,
|
|
4598
4964
|
...record.family === "offer" ? { status: "cancelled" } : { state: "failed" },
|
|
@@ -4661,7 +5027,7 @@ var reconcileFunding = async (input, record) => {
|
|
|
4661
5027
|
const script = record.family === "offer" ? record.swapPkScript : record.lockupPkScript;
|
|
4662
5028
|
const expected = BigInt(record.give.amount);
|
|
4663
5029
|
const reader = await input.wallet.getArkadeReader();
|
|
4664
|
-
const vtxos = await (0,
|
|
5030
|
+
const vtxos = await (0, import_sdk14.getAllNormalizedVtxos)(reader, [script]);
|
|
4665
5031
|
const deposit = vtxos.find((vtxo) => depositMatches(vtxo, record, expected));
|
|
4666
5032
|
return deposit?.txid;
|
|
4667
5033
|
};
|
|
@@ -4771,13 +5137,13 @@ var scopedToRail = (table, rail) => ({
|
|
|
4771
5137
|
|
|
4772
5138
|
// src/client/client.ts
|
|
4773
5139
|
var import_base23 = require("@scure/base");
|
|
4774
|
-
var
|
|
5140
|
+
var import_sdk38 = require("@arkade-os/sdk");
|
|
4775
5141
|
init_repository();
|
|
4776
5142
|
|
|
4777
5143
|
// src/refund.ts
|
|
4778
5144
|
var import_base10 = require("@scure/base");
|
|
4779
5145
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
4780
|
-
var
|
|
5146
|
+
var import_sdk15 = require("@arkade-os/sdk");
|
|
4781
5147
|
init_onchainHtlc();
|
|
4782
5148
|
init_rfq();
|
|
4783
5149
|
var walletOperator = (wallet) => {
|
|
@@ -4815,7 +5181,7 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
4815
5181
|
const out = [];
|
|
4816
5182
|
for (const vtxo of row?.vtxos ?? []) {
|
|
4817
5183
|
if (vtxo.isUnrolled) continue;
|
|
4818
|
-
if ((0,
|
|
5184
|
+
if ((0, import_sdk15.isVtxoSpent)(vtxo)) continue;
|
|
4819
5185
|
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
4820
5186
|
if (seen.has(key)) continue;
|
|
4821
5187
|
seen.add(key);
|
|
@@ -4831,17 +5197,17 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
4831
5197
|
}
|
|
4832
5198
|
var hashesTo = (candidate, paymentHash) => import_base10.hex.encode((0, import_sha24.sha256)(candidate)) === paymentHash;
|
|
4833
5199
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
4834
|
-
...(0,
|
|
5200
|
+
...(0, import_sdk15.getArkPsbtFields)(tx, inputIndex, import_sdk15.ConditionWitness).flat(),
|
|
4835
5201
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
4836
5202
|
];
|
|
4837
5203
|
var refundLeafScript = (tx, inputIndex) => {
|
|
4838
5204
|
const input = tx.getInput(inputIndex);
|
|
4839
5205
|
const witness = input.finalScriptWitness;
|
|
4840
5206
|
const leaves = input.tapLeafScript ?? [];
|
|
4841
|
-
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0,
|
|
5207
|
+
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0, import_sdk15.scriptFromTapLeafScript)(leaves[0]) : void 0;
|
|
4842
5208
|
if (!script) return void 0;
|
|
4843
5209
|
try {
|
|
4844
|
-
const { type } = (0,
|
|
5210
|
+
const { type } = (0, import_sdk15.decodeTapscript)(script);
|
|
4845
5211
|
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
|
|
4846
5212
|
} catch {
|
|
4847
5213
|
return void 0;
|
|
@@ -4851,7 +5217,7 @@ async function readLockupFate(indexer, input) {
|
|
|
4851
5217
|
const { vtxos } = await indexer.getVtxos({ scripts: [import_base10.hex.encode(input.swapPkScript)] });
|
|
4852
5218
|
const all = vtxos ?? [];
|
|
4853
5219
|
if (all.length === 0) return { fate: "unknown" };
|
|
4854
|
-
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0,
|
|
5220
|
+
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0, import_sdk15.isVtxoSpent)(vtxo));
|
|
4855
5221
|
if (exited.length > 0) {
|
|
4856
5222
|
return {
|
|
4857
5223
|
fate: "exited",
|
|
@@ -4863,7 +5229,7 @@ async function readLockupFate(indexer, input) {
|
|
|
4863
5229
|
let sweptLeft = false;
|
|
4864
5230
|
let live = false;
|
|
4865
5231
|
for (const vtxo of all) {
|
|
4866
|
-
if (!(0,
|
|
5232
|
+
if (!(0, import_sdk15.isVtxoSpent)(vtxo)) {
|
|
4867
5233
|
if (input.receiver && vtxo.isSwept) sweptLeft = true;
|
|
4868
5234
|
else live = true;
|
|
4869
5235
|
continue;
|
|
@@ -4890,7 +5256,7 @@ async function readLockupFate(indexer, input) {
|
|
|
4890
5256
|
for (const raw of txs) {
|
|
4891
5257
|
let tx;
|
|
4892
5258
|
try {
|
|
4893
|
-
tx =
|
|
5259
|
+
tx = import_sdk15.Transaction.fromPSBT(import_base10.base64.decode(raw));
|
|
4894
5260
|
} catch {
|
|
4895
5261
|
continue;
|
|
4896
5262
|
}
|
|
@@ -4940,10 +5306,10 @@ var assertNoneSwept = (vtxos, contract) => {
|
|
|
4940
5306
|
};
|
|
4941
5307
|
var operatorUnrollScript = async (operator, network) => {
|
|
4942
5308
|
const info = await operator.getInfo();
|
|
4943
|
-
return (0,
|
|
5309
|
+
return (0, import_sdk15.assertValidServerUnrollScript)(
|
|
4944
5310
|
info.checkpointTapscript,
|
|
4945
|
-
network ?? (0,
|
|
4946
|
-
(0,
|
|
5311
|
+
network ?? (0, import_sdk15.networkFromOperatorInfo)(info),
|
|
5312
|
+
(0, import_sdk15.toXOnly)(import_base10.hex.decode(info.forfeitPubkey), "forfeit key")
|
|
4947
5313
|
);
|
|
4948
5314
|
};
|
|
4949
5315
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
@@ -4963,7 +5329,7 @@ var lockupAssetOutputs = (vtxos) => {
|
|
|
4963
5329
|
address: "",
|
|
4964
5330
|
assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
|
|
4965
5331
|
};
|
|
4966
|
-
return [
|
|
5332
|
+
return [import_sdk15.Extension.create([(0, import_sdk15.createAssetPacket)(inputs, [receiver])]).txOut()];
|
|
4967
5333
|
};
|
|
4968
5334
|
var lockupInputs = (vtxos, contract, leaf) => {
|
|
4969
5335
|
const tapTree = contract.encode();
|
|
@@ -4988,7 +5354,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
4988
5354
|
const leaf = input.contract.refundWithoutReceiver();
|
|
4989
5355
|
const vtxos = boundedLockupSpend(input.vtxos);
|
|
4990
5356
|
const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
4991
|
-
const txid = await (0,
|
|
5357
|
+
const txid = await (0, import_sdk15.signAndSubmitOffchainTx)({
|
|
4992
5358
|
identity: input.sender,
|
|
4993
5359
|
provider: operator,
|
|
4994
5360
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
@@ -5006,10 +5372,10 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
5006
5372
|
var REFUND_MTP_LAG_SECONDS = 2 * 60 * 60;
|
|
5007
5373
|
|
|
5008
5374
|
// src/client/corridors/registry.ts
|
|
5009
|
-
var
|
|
5375
|
+
var import_sdk19 = require("@arkade-os/sdk");
|
|
5010
5376
|
|
|
5011
5377
|
// src/client/corridors/arkade.ts
|
|
5012
|
-
var
|
|
5378
|
+
var import_sdk16 = require("@arkade-os/sdk");
|
|
5013
5379
|
var ARKADE_DRIVE = {};
|
|
5014
5380
|
var messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
5015
5381
|
var arkadeCorridor = Object.assign(
|
|
@@ -5018,11 +5384,11 @@ var arkadeCorridor = Object.assign(
|
|
|
5018
5384
|
deps,
|
|
5019
5385
|
drive: ARKADE_DRIVE,
|
|
5020
5386
|
matches(raw) {
|
|
5021
|
-
const target = (0,
|
|
5387
|
+
const target = (0, import_sdk16.arkTarget)(raw);
|
|
5022
5388
|
if (target === void 0) return void 0;
|
|
5023
5389
|
try {
|
|
5024
|
-
const address =
|
|
5025
|
-
(0,
|
|
5390
|
+
const address = import_sdk16.ArkAddress.decode(target);
|
|
5391
|
+
(0, import_sdk16.assertRecipientArkadeAddress)(target, address, {
|
|
5026
5392
|
hrp: deps.network.hrp,
|
|
5027
5393
|
signerSet: deps.signerSet
|
|
5028
5394
|
});
|
|
@@ -5032,11 +5398,11 @@ var arkadeCorridor = Object.assign(
|
|
|
5032
5398
|
return { claimed: { kind: "address", address: target } };
|
|
5033
5399
|
}
|
|
5034
5400
|
}),
|
|
5035
|
-
{ target:
|
|
5401
|
+
{ target: import_sdk16.arkTarget }
|
|
5036
5402
|
);
|
|
5037
5403
|
|
|
5038
5404
|
// src/client/corridors/deps.ts
|
|
5039
|
-
var
|
|
5405
|
+
var import_sdk18 = require("@arkade-os/sdk");
|
|
5040
5406
|
|
|
5041
5407
|
// src/chainSource.ts
|
|
5042
5408
|
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -5120,7 +5486,7 @@ var decodeBolt11 = (invoice) => {
|
|
|
5120
5486
|
// src/client/corridors/chainSource.ts
|
|
5121
5487
|
var import_base12 = require("@scure/base");
|
|
5122
5488
|
var btc4 = __toESM(require("@scure/btc-signer"), 1);
|
|
5123
|
-
var
|
|
5489
|
+
var import_sdk17 = require("@arkade-os/sdk");
|
|
5124
5490
|
var addressOfScript = (script, network) => btc4.Address(network).encode(btc4.OutScript.decode(script));
|
|
5125
5491
|
var chainSourceOver = (backend, network) => {
|
|
5126
5492
|
const spenderFromVins = async (txid, vout, pkScript) => {
|
|
@@ -5187,7 +5553,7 @@ var esploraTip = async (esploraUrl, fetchImpl) => {
|
|
|
5187
5553
|
};
|
|
5188
5554
|
var esploraChainSource = (input) => chainSourceOver(
|
|
5189
5555
|
{
|
|
5190
|
-
provider: new
|
|
5556
|
+
provider: new import_sdk17.EsploraProvider(input.esploraUrl),
|
|
5191
5557
|
tip: () => esploraTip(input.esploraUrl, input.fetchImpl)
|
|
5192
5558
|
},
|
|
5193
5559
|
input.network
|
|
@@ -5213,10 +5579,10 @@ var refusedIfMalformed = (value, dep) => {
|
|
|
5213
5579
|
};
|
|
5214
5580
|
var emulatorPubkeyFor = (base) => {
|
|
5215
5581
|
if (base.emulatorPubkey !== void 0) {
|
|
5216
|
-
return (0,
|
|
5582
|
+
return (0, import_sdk18.resolveEmulatorPubkey)(base.network, base.emulatorPubkey);
|
|
5217
5583
|
}
|
|
5218
5584
|
try {
|
|
5219
|
-
return (0,
|
|
5585
|
+
return (0, import_sdk18.defaultEmulatorPubkey)(base.network);
|
|
5220
5586
|
} catch {
|
|
5221
5587
|
throw new MissingCorridorDep(
|
|
5222
5588
|
"arkade",
|
|
@@ -5267,7 +5633,7 @@ function resolveCorridorDeps(corridor, overrides, base) {
|
|
|
5267
5633
|
return {
|
|
5268
5634
|
networkName: base.networkName,
|
|
5269
5635
|
chain: chain && "provider" in chain ? chainSourceFrom(chain.provider, l1Network) : esploraChainSource({
|
|
5270
|
-
esploraUrl: chain?.esploraUrl ??
|
|
5636
|
+
esploraUrl: chain?.esploraUrl ?? import_sdk18.ESPLORA_URL[base.networkName],
|
|
5271
5637
|
network: L1_NETWORKS[l1Network],
|
|
5272
5638
|
fetchImpl: base.fetchImpl
|
|
5273
5639
|
}),
|
|
@@ -5298,8 +5664,8 @@ var resolveCorridorBase = async (input) => {
|
|
|
5298
5664
|
wallet: input.wallet,
|
|
5299
5665
|
operator: input.operator,
|
|
5300
5666
|
networkName,
|
|
5301
|
-
network: (0,
|
|
5302
|
-
signerSet: (0,
|
|
5667
|
+
network: (0, import_sdk18.getNetwork)(networkName),
|
|
5668
|
+
signerSet: (0, import_sdk18.signerSetFromInfo)(info),
|
|
5303
5669
|
emulatorPubkey: input.emulatorPubkey,
|
|
5304
5670
|
fetchImpl: input.fetchImpl,
|
|
5305
5671
|
repository: input.repository
|
|
@@ -5329,7 +5695,7 @@ var corridorSet = (base, overrides) => {
|
|
|
5329
5695
|
(corridor) => CORRIDOR_FACTORIES[corridor].target(raw) !== void 0
|
|
5330
5696
|
);
|
|
5331
5697
|
if (owners.length === 0) {
|
|
5332
|
-
if ((0,
|
|
5698
|
+
if ((0, import_sdk19.isLnurl)(raw)) return void 0;
|
|
5333
5699
|
throw new AmbiguousDestination(raw, "no corridor recognises this destination");
|
|
5334
5700
|
}
|
|
5335
5701
|
const claims = [];
|
|
@@ -5357,11 +5723,11 @@ var import_solver_discovery9 = require("@arkade-os/solver-discovery");
|
|
|
5357
5723
|
|
|
5358
5724
|
// src/markets.ts
|
|
5359
5725
|
var import_solver_discovery8 = require("@arkade-os/solver-discovery");
|
|
5360
|
-
var
|
|
5726
|
+
var import_sdk21 = require("@arkade-os/sdk");
|
|
5361
5727
|
init_store();
|
|
5362
5728
|
var QUOTE_OPTIONS = { safetyBps: 0 };
|
|
5363
5729
|
var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
|
|
5364
|
-
(0,
|
|
5730
|
+
(0, import_sdk21.assertNonNegativeMs)("ttlMs", ttlMs);
|
|
5365
5731
|
const cache = /* @__PURE__ */ new Map();
|
|
5366
5732
|
const inflight = /* @__PURE__ */ new Map();
|
|
5367
5733
|
return async (input, init) => {
|
|
@@ -5626,13 +5992,13 @@ var discoveryIndex = (input) => {
|
|
|
5626
5992
|
|
|
5627
5993
|
// src/client/cancel.ts
|
|
5628
5994
|
var import_base16 = require("@scure/base");
|
|
5629
|
-
var
|
|
5995
|
+
var import_sdk25 = require("@arkade-os/sdk");
|
|
5630
5996
|
init_coverage();
|
|
5631
5997
|
init_offer();
|
|
5632
5998
|
|
|
5633
5999
|
// src/restore.ts
|
|
5634
6000
|
var import_base13 = require("@scure/base");
|
|
5635
|
-
var
|
|
6001
|
+
var import_sdk22 = require("@arkade-os/sdk");
|
|
5636
6002
|
init_offer();
|
|
5637
6003
|
init_store();
|
|
5638
6004
|
var TXS_PER_REQUEST = 50;
|
|
@@ -5657,7 +6023,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
5657
6023
|
if (result.status !== "fulfilled") continue;
|
|
5658
6024
|
for (const psbt of result.value) {
|
|
5659
6025
|
try {
|
|
5660
|
-
const parsed =
|
|
6026
|
+
const parsed = import_sdk22.Transaction.fromPSBT(import_base13.base64.decode(psbt));
|
|
5661
6027
|
parsedByTxid.set(parsed.id, parsed);
|
|
5662
6028
|
} catch {
|
|
5663
6029
|
}
|
|
@@ -5686,7 +6052,7 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
5686
6052
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
5687
6053
|
if (import_base13.hex.encode(input.txid) !== deposit.txid) continue;
|
|
5688
6054
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
5689
|
-
const spent = import_base13.hex.encode((0,
|
|
6055
|
+
const spent = import_base13.hex.encode((0, import_sdk22.scriptFromTapLeafScript)(leaf));
|
|
5690
6056
|
if (leaves.returned.some((back) => spent === import_base13.hex.encode(back))) return "cancelled";
|
|
5691
6057
|
if (leaves.fulfill && spent === import_base13.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
5692
6058
|
}
|
|
@@ -5740,7 +6106,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5740
6106
|
if (!fundingTx) continue;
|
|
5741
6107
|
fetchedTxids.push(txid);
|
|
5742
6108
|
try {
|
|
5743
|
-
const packet =
|
|
6109
|
+
const packet = import_sdk22.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
5744
6110
|
if (!packet) continue;
|
|
5745
6111
|
const payload = packet.serialize();
|
|
5746
6112
|
found.push({
|
|
@@ -5857,7 +6223,7 @@ init_repository();
|
|
|
5857
6223
|
init_repository();
|
|
5858
6224
|
|
|
5859
6225
|
// src/rfqRecord.ts
|
|
5860
|
-
var
|
|
6226
|
+
var import_sdk23 = require("@arkade-os/sdk");
|
|
5861
6227
|
var import_base14 = require("@scure/base");
|
|
5862
6228
|
|
|
5863
6229
|
// src/rfqSwapState.ts
|
|
@@ -5915,7 +6281,7 @@ function assertSameSwap(origin, swap) {
|
|
|
5915
6281
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
5916
6282
|
);
|
|
5917
6283
|
}
|
|
5918
|
-
const funded = import_base14.hex.encode(
|
|
6284
|
+
const funded = import_base14.hex.encode(import_sdk23.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
5919
6285
|
const watched = import_base14.hex.encode(swap.lockupPkScript);
|
|
5920
6286
|
if (funded !== watched) {
|
|
5921
6287
|
throw new Error(
|
|
@@ -5962,8 +6328,8 @@ function rfqSwapOriginOf(record) {
|
|
|
5962
6328
|
};
|
|
5963
6329
|
}
|
|
5964
6330
|
function lockupScript(params, lockupAddress) {
|
|
5965
|
-
const script =
|
|
5966
|
-
const funded =
|
|
6331
|
+
const script = import_sdk23.VHTLCV2ContractHandler.createScript(params);
|
|
6332
|
+
const funded = import_sdk23.ArkAddress.decode(lockupAddress).pkScript;
|
|
5967
6333
|
if (import_base14.hex.encode(funded) !== import_base14.hex.encode(script.pkScript)) {
|
|
5968
6334
|
throw new Error(
|
|
5969
6335
|
`rfq swap covenant params derive ${import_base14.hex.encode(script.pkScript)}, but the record's lockup address holds ${import_base14.hex.encode(funded)} \u2014 these params are not this swap's`
|
|
@@ -6000,7 +6366,7 @@ function shouldRetainRfqSwap(record, now) {
|
|
|
6000
6366
|
|
|
6001
6367
|
// src/client/driveRecords.ts
|
|
6002
6368
|
init_store();
|
|
6003
|
-
var
|
|
6369
|
+
var import_sdk24 = require("@arkade-os/sdk");
|
|
6004
6370
|
var import_sha25 = require("@noble/hashes/sha2.js");
|
|
6005
6371
|
var import_base15 = require("@scure/base");
|
|
6006
6372
|
var splitRecords = (records) => {
|
|
@@ -6055,7 +6421,7 @@ var pageRfqRecords = (records, filter, page) => {
|
|
|
6055
6421
|
).sort(
|
|
6056
6422
|
(a, b) => a.updatedAt - b.updatedAt || (a.rfqId < b.rfqId ? -1 : a.rfqId > b.rfqId ? 1 : 0)
|
|
6057
6423
|
).slice(0, page.limit + 1);
|
|
6058
|
-
return (0,
|
|
6424
|
+
return (0, import_sdk24.pageResult)(rows, page.limit, (record) => ({
|
|
6059
6425
|
updatedAt: record.updatedAt,
|
|
6060
6426
|
rfqId: record.rfqId
|
|
6061
6427
|
}));
|
|
@@ -6081,7 +6447,7 @@ var corridorRecordStore = (repository, onRecord = () => {
|
|
|
6081
6447
|
index,
|
|
6082
6448
|
quoteIdOf: (rfqId) => byRfqId.get(rfqId),
|
|
6083
6449
|
async getRfqSwapsPage(filter, page) {
|
|
6084
|
-
(0,
|
|
6450
|
+
(0, import_sdk24.assertPageRequest)(page);
|
|
6085
6451
|
assertRfqSwapPageFilter(filter);
|
|
6086
6452
|
const { corridor } = splitRecords(await collectSwapRecords(repository));
|
|
6087
6453
|
for (const record of corridor) index(record);
|
|
@@ -6193,7 +6559,7 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
6193
6559
|
now
|
|
6194
6560
|
);
|
|
6195
6561
|
};
|
|
6196
|
-
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network,
|
|
6562
|
+
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network, import_sdk24.asset.AssetId.fromString(id));
|
|
6197
6563
|
var RESTORED_CORRIDORS = {
|
|
6198
6564
|
lightning_send: ["arkade", "lightning"],
|
|
6199
6565
|
lightning_receive: ["lightning", "arkade"],
|
|
@@ -6225,7 +6591,7 @@ var restoredCorridorRecord = (stored, network, refundLocktime) => {
|
|
|
6225
6591
|
kind: v1.kind,
|
|
6226
6592
|
rfqId: v1.rfqId,
|
|
6227
6593
|
lockupAddress: v1.lockupAddress,
|
|
6228
|
-
lockupPkScript: import_base15.hex.encode(
|
|
6594
|
+
lockupPkScript: import_base15.hex.encode(import_sdk24.ArkAddress.decode(v1.lockupAddress).pkScript),
|
|
6229
6595
|
lock: { hash },
|
|
6230
6596
|
refundLocktime,
|
|
6231
6597
|
profile: v1.profile,
|
|
@@ -6321,12 +6687,12 @@ var reconcileDepositSpend = async (record, indexer) => {
|
|
|
6321
6687
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
6322
6688
|
const parsed = txs.map((psbt) => {
|
|
6323
6689
|
try {
|
|
6324
|
-
return
|
|
6690
|
+
return import_sdk25.Transaction.fromPSBT(import_base16.base64.decode(psbt));
|
|
6325
6691
|
} catch {
|
|
6326
6692
|
return void 0;
|
|
6327
6693
|
}
|
|
6328
6694
|
}).filter((tx) => tx !== void 0);
|
|
6329
|
-
const operatorPubkey =
|
|
6695
|
+
const operatorPubkey = import_sdk25.ArkAddress.decode(record.swapAddress).serverPubKey;
|
|
6330
6696
|
const kind = classifyDepositSpend(offer, operatorPubkey, parsed, {
|
|
6331
6697
|
txid: deposit.txid,
|
|
6332
6698
|
vout: deposit.vout
|
|
@@ -6365,12 +6731,12 @@ var retireOfferScripts = async (wallet, repository, record) => {
|
|
|
6365
6731
|
};
|
|
6366
6732
|
|
|
6367
6733
|
// src/client/drive.ts
|
|
6368
|
-
var
|
|
6734
|
+
var import_sdk32 = require("@arkade-os/sdk");
|
|
6369
6735
|
var import_base20 = require("@scure/base");
|
|
6370
6736
|
|
|
6371
6737
|
// src/claim.ts
|
|
6372
6738
|
var import_base17 = require("@scure/base");
|
|
6373
|
-
var
|
|
6739
|
+
var import_sdk26 = require("@arkade-os/sdk");
|
|
6374
6740
|
init_onchainHtlc();
|
|
6375
6741
|
var LockupAmountMismatchError = class extends Error {
|
|
6376
6742
|
name = "LockupAmountMismatchError";
|
|
@@ -6406,8 +6772,8 @@ async function pushClaim(operator, input) {
|
|
|
6406
6772
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
6407
6773
|
const serverUnrollScript = await operatorUnrollScript(operator, input.network);
|
|
6408
6774
|
const leaf = input.contract.claim();
|
|
6409
|
-
const txid = await (0,
|
|
6410
|
-
identity: (0,
|
|
6775
|
+
const txid = await (0, import_sdk26.signAndSubmitOffchainTx)({
|
|
6776
|
+
identity: (0, import_sdk26.claimWithPreimageIdentity)(input.receiver, input.preimage),
|
|
6411
6777
|
provider: operator,
|
|
6412
6778
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
6413
6779
|
// One aggregate output: this leaf inspects nothing about the output set.
|
|
@@ -6428,7 +6794,7 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6428
6794
|
});
|
|
6429
6795
|
const byArkTx = /* @__PURE__ */ new Map();
|
|
6430
6796
|
for (const vtxo of vtxos ?? []) {
|
|
6431
|
-
if (!(0,
|
|
6797
|
+
if (!(0, import_sdk26.isVtxoSpent)(vtxo) || !vtxo.spentBy || !vtxo.arkTxId) continue;
|
|
6432
6798
|
byArkTx.set(vtxo.arkTxId, [...byArkTx.get(vtxo.arkTxId) ?? [], vtxo]);
|
|
6433
6799
|
}
|
|
6434
6800
|
if (byArkTx.size === 0) return [];
|
|
@@ -6438,9 +6804,9 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6438
6804
|
current,
|
|
6439
6805
|
...(deprecatedSigners ?? []).flatMap(
|
|
6440
6806
|
({ pubkey }) => pubkey ? [
|
|
6441
|
-
|
|
6807
|
+
import_sdk26.CSVMultisigTapscript.encode({
|
|
6442
6808
|
...current.params,
|
|
6443
|
-
pubkeys: [(0,
|
|
6809
|
+
pubkeys: [(0, import_sdk26.toXOnly)(import_base17.hex.decode(pubkey), "deprecated signer")]
|
|
6444
6810
|
})
|
|
6445
6811
|
] : []
|
|
6446
6812
|
)
|
|
@@ -6455,7 +6821,7 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6455
6821
|
}));
|
|
6456
6822
|
const total = live.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
6457
6823
|
const checkpoints = unrollScripts.map(
|
|
6458
|
-
(unroll) => (0,
|
|
6824
|
+
(unroll) => (0, import_sdk26.buildOffchainTx)(
|
|
6459
6825
|
lockupInputs(live, input.contract, input.contract.claim()),
|
|
6460
6826
|
[{ script: input.contract.pkScript, amount: BigInt(total) }],
|
|
6461
6827
|
unroll
|
|
@@ -6471,14 +6837,14 @@ async function finalizePendingClaim(operator, indexer, input) {
|
|
|
6471
6837
|
const claims = await findPendingClaims(operator, indexer, input);
|
|
6472
6838
|
if (claims.length === 0) return [];
|
|
6473
6839
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
6474
|
-
const signer = (0,
|
|
6840
|
+
const signer = (0, import_sdk26.claimWithPreimageIdentity)(input.receiver, input.preimage);
|
|
6475
6841
|
const ours = import_base17.hex.encode(await input.receiver.xOnlyPublicKey());
|
|
6476
6842
|
const finalized = [];
|
|
6477
6843
|
for (const { arkTxid, checkpoints } of claims) {
|
|
6478
6844
|
const { txs } = await indexer.getVirtualTxs(checkpoints.map((checkpoint) => checkpoint.id));
|
|
6479
6845
|
const stored = new Map(
|
|
6480
6846
|
txs.map((raw) => {
|
|
6481
|
-
const tx =
|
|
6847
|
+
const tx = import_sdk26.Transaction.fromPSBT(import_base17.base64.decode(raw));
|
|
6482
6848
|
return [tx.id, tx];
|
|
6483
6849
|
})
|
|
6484
6850
|
);
|
|
@@ -6516,7 +6882,7 @@ init_onchainHtlc();
|
|
|
6516
6882
|
init_coverage();
|
|
6517
6883
|
|
|
6518
6884
|
// src/migrateOfferRows.ts
|
|
6519
|
-
var
|
|
6885
|
+
var import_sdk27 = require("@arkade-os/sdk");
|
|
6520
6886
|
|
|
6521
6887
|
// src/legacy/swap-want-asset.program.v0.json
|
|
6522
6888
|
var swap_want_asset_program_v0_default = {
|
|
@@ -6608,14 +6974,14 @@ function withExitV0(program, exit) {
|
|
|
6608
6974
|
}
|
|
6609
6975
|
var V0_TO_V1 = /* @__PURE__ */ new Map();
|
|
6610
6976
|
for (const [v0, v1] of [
|
|
6611
|
-
[swap_want_btc_program_v0_default,
|
|
6612
|
-
[swap_want_asset_program_v0_default,
|
|
6977
|
+
[swap_want_btc_program_v0_default, legacySwapPrograms.wantBtc],
|
|
6978
|
+
[swap_want_asset_program_v0_default, legacySwapPrograms.wantAsset]
|
|
6613
6979
|
]) {
|
|
6614
6980
|
for (const exit of [void 0, "blocks", "seconds"]) {
|
|
6615
6981
|
const timelock = exit && { type: exit, value: BigInt(0) };
|
|
6616
6982
|
V0_TO_V1.set(
|
|
6617
6983
|
JSON.stringify(withExitV0(v0, exit)),
|
|
6618
|
-
|
|
6984
|
+
import_sdk27.arkade.stringifyArtifact(withExitClosure(v1, timelock))
|
|
6619
6985
|
);
|
|
6620
6986
|
}
|
|
6621
6987
|
}
|
|
@@ -6654,7 +7020,7 @@ init_offer();
|
|
|
6654
7020
|
init_lockupContract();
|
|
6655
7021
|
|
|
6656
7022
|
// src/refundBlocked.ts
|
|
6657
|
-
var
|
|
7023
|
+
var import_sdk28 = require("@arkade-os/sdk");
|
|
6658
7024
|
var RefundNotLocallyPossibleError = class extends Error {
|
|
6659
7025
|
constructor(reason, message, options) {
|
|
6660
7026
|
super(message, options);
|
|
@@ -6671,16 +7037,16 @@ async function senderIdentityForSwapRecord(wallet, record) {
|
|
|
6671
7037
|
);
|
|
6672
7038
|
}
|
|
6673
7039
|
try {
|
|
6674
|
-
return await (0,
|
|
7040
|
+
return await (0, import_sdk28.contractSigner)(wallet, record.signingDescriptor);
|
|
6675
7041
|
} catch (cause) {
|
|
6676
|
-
if (cause instanceof
|
|
7042
|
+
if (cause instanceof import_sdk28.WalletCannotSignError) {
|
|
6677
7043
|
throw new RefundNotLocallyPossibleError(
|
|
6678
7044
|
"unsignable-wallet",
|
|
6679
7045
|
`this wallet holds ${record.signingDescriptor} but cannot sign with it; attach its signer`,
|
|
6680
7046
|
{ cause }
|
|
6681
7047
|
);
|
|
6682
7048
|
}
|
|
6683
|
-
if (cause instanceof
|
|
7049
|
+
if (cause instanceof import_sdk28.ForeignDescriptorError) {
|
|
6684
7050
|
throw new RefundNotLocallyPossibleError(
|
|
6685
7051
|
"foreign-descriptor",
|
|
6686
7052
|
`this wallet cannot derive ${record.signingDescriptor}; the swap was created on another wallet`,
|
|
@@ -6737,7 +7103,7 @@ init_repository();
|
|
|
6737
7103
|
|
|
6738
7104
|
// src/swapManager.ts
|
|
6739
7105
|
var import_base18 = require("@scure/base");
|
|
6740
|
-
var
|
|
7106
|
+
var import_sdk29 = require("@arkade-os/sdk");
|
|
6741
7107
|
init_onchainHtlc();
|
|
6742
7108
|
init_lockupContract();
|
|
6743
7109
|
init_repository();
|
|
@@ -6868,7 +7234,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6868
7234
|
timer = null;
|
|
6869
7235
|
running = false;
|
|
6870
7236
|
constructor(deps, config = {}) {
|
|
6871
|
-
(0,
|
|
7237
|
+
(0, import_sdk29.assertTimerMs)("pollIntervalMs", config.pollIntervalMs);
|
|
6872
7238
|
this.deps = deps;
|
|
6873
7239
|
this.config = {
|
|
6874
7240
|
enableAutoActions: config.enableAutoActions ?? true,
|
|
@@ -7252,7 +7618,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7252
7618
|
});
|
|
7253
7619
|
return;
|
|
7254
7620
|
}
|
|
7255
|
-
if (!(0,
|
|
7621
|
+
if (!(0, import_sdk29.isContractVtxoEvent)(event)) return;
|
|
7256
7622
|
const swap = this.byLockupScript.get(event.contractScript);
|
|
7257
7623
|
if (!swap) return;
|
|
7258
7624
|
void this.pollSwap(swap).catch(() => {
|
|
@@ -7522,8 +7888,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7522
7888
|
this.setState(swap, "claimed");
|
|
7523
7889
|
this.emitAction(swap, "claimLockup");
|
|
7524
7890
|
} catch (error) {
|
|
7525
|
-
const ark = (0,
|
|
7526
|
-
if ((0,
|
|
7891
|
+
const ark = (0, import_sdk29.isArkError)(error) ? error : (0, import_sdk29.maybeArkError)(error);
|
|
7892
|
+
if ((0, import_sdk29.isArkError)(ark, import_sdk29.ArkErrorName.VTXO_ALREADY_SPENT)) {
|
|
7527
7893
|
if (swap.claimFailure !== void 0) {
|
|
7528
7894
|
delete swap.claimFailure;
|
|
7529
7895
|
this.touch(swap);
|
|
@@ -7814,8 +8180,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7814
8180
|
this.refundRefused.add(swap.rfqId);
|
|
7815
8181
|
return this.block(swap, error.message);
|
|
7816
8182
|
}
|
|
7817
|
-
const ark = (0,
|
|
7818
|
-
if ((0,
|
|
8183
|
+
const ark = (0, import_sdk29.isArkError)(error) ? error : (0, import_sdk29.maybeArkError)(error);
|
|
8184
|
+
if ((0, import_sdk29.isArkError)(ark, import_sdk29.ArkErrorName.VTXO_ALREADY_SPENT)) return;
|
|
7819
8185
|
this.emitFailed(swap, error);
|
|
7820
8186
|
if (now >= swap.refundLocktime + REFUND_MTP_LAG_SECONDS) {
|
|
7821
8187
|
swap.failure = errorMessage(error);
|
|
@@ -8008,7 +8374,7 @@ var outpointKey = (vtxo) => `${vtxo.txid}:${vtxo.vout}`;
|
|
|
8008
8374
|
|
|
8009
8375
|
// src/watch.ts
|
|
8010
8376
|
var import_base19 = require("@scure/base");
|
|
8011
|
-
var
|
|
8377
|
+
var import_sdk30 = require("@arkade-os/sdk");
|
|
8012
8378
|
init_coverage();
|
|
8013
8379
|
init_offer();
|
|
8014
8380
|
init_store();
|
|
@@ -8043,7 +8409,7 @@ async function watchOfferSwaps({
|
|
|
8043
8409
|
wallet.getAddress(),
|
|
8044
8410
|
wallet.getArkadeReader()
|
|
8045
8411
|
]);
|
|
8046
|
-
const operatorPubkey =
|
|
8412
|
+
const operatorPubkey = import_sdk30.ArkAddress.decode(address).serverPubKey;
|
|
8047
8413
|
let queue = Promise.resolve();
|
|
8048
8414
|
const enqueue = (task) => {
|
|
8049
8415
|
queue = queue.then(task).catch(() => {
|
|
@@ -8058,7 +8424,7 @@ async function watchOfferSwaps({
|
|
|
8058
8424
|
return classifyDepositSpend(
|
|
8059
8425
|
decodeOffer(import_base19.hex.decode(swap.offerHex)),
|
|
8060
8426
|
operatorPubkey,
|
|
8061
|
-
txs.map((psbt) =>
|
|
8427
|
+
txs.map((psbt) => import_sdk30.Transaction.fromPSBT(import_base19.base64.decode(psbt))),
|
|
8062
8428
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
8063
8429
|
);
|
|
8064
8430
|
} catch {
|
|
@@ -8086,7 +8452,7 @@ async function watchOfferSwaps({
|
|
|
8086
8452
|
}
|
|
8087
8453
|
};
|
|
8088
8454
|
const unsubscribe = manager.onContractEvent((event) => {
|
|
8089
|
-
if (!(0,
|
|
8455
|
+
if (!(0, import_sdk30.isContractVtxoEvent)(event) || event.type !== "vtxo_spent") return;
|
|
8090
8456
|
enqueue(() => handleSpend(event));
|
|
8091
8457
|
});
|
|
8092
8458
|
return {
|
|
@@ -8096,7 +8462,7 @@ async function watchOfferSwaps({
|
|
|
8096
8462
|
}
|
|
8097
8463
|
|
|
8098
8464
|
// src/client/legacyRecords.ts
|
|
8099
|
-
var
|
|
8465
|
+
var import_sdk31 = require("@arkade-os/sdk");
|
|
8100
8466
|
init_repository();
|
|
8101
8467
|
var readLegacyRfqSwaps = async (repository, filter = {}) => {
|
|
8102
8468
|
try {
|
|
@@ -8113,7 +8479,7 @@ var withLegacyRfqSwaps = (bridge, repository, admits) => {
|
|
|
8113
8479
|
index: bridge.index,
|
|
8114
8480
|
quoteIdOf: bridge.quoteIdOf,
|
|
8115
8481
|
async getRfqSwapsPage(filter, page) {
|
|
8116
|
-
(0,
|
|
8482
|
+
(0, import_sdk31.assertPageRequest)(page);
|
|
8117
8483
|
assertRfqSwapPageFilter(filter);
|
|
8118
8484
|
const v2 = await collectRfqSwaps(bridge, filter);
|
|
8119
8485
|
const held = new Set(
|
|
@@ -8369,7 +8735,7 @@ var createSwapDrive = (config) => {
|
|
|
8369
8735
|
const secret = rfqClaimSecretOf(record);
|
|
8370
8736
|
if (!secret) throw new Error(`rfq swap ${swap.rfqId} carries no claim secret`);
|
|
8371
8737
|
const preimage = await preimageForSwapRecord(wallet, secret);
|
|
8372
|
-
const signer = await (0,
|
|
8738
|
+
const signer = await (0, import_sdk32.contractSigner)(wallet, await (0, import_sdk32.identityDescriptor)(wallet.identity));
|
|
8373
8739
|
const claimKey = record.profile.claimKey;
|
|
8374
8740
|
if (typeof claimKey === "string") {
|
|
8375
8741
|
const held = import_base20.hex.encode(await signer.xOnlyPublicKey());
|
|
@@ -8415,7 +8781,7 @@ var createSwapDrive = (config) => {
|
|
|
8415
8781
|
`rfq swap ${swap.rfqId} carries no refund descriptor; wire the onchain corridor's refund callback to take its L1 funding back`
|
|
8416
8782
|
);
|
|
8417
8783
|
}
|
|
8418
|
-
const signer = await (0,
|
|
8784
|
+
const signer = await (0, import_sdk32.contractSigner)(wallet, descriptor);
|
|
8419
8785
|
const held = import_base20.hex.encode(await signer.xOnlyPublicKey());
|
|
8420
8786
|
if (held !== record.profile.refundKey) {
|
|
8421
8787
|
throw new Error(
|
|
@@ -8455,7 +8821,7 @@ var createSwapDrive = (config) => {
|
|
|
8455
8821
|
}
|
|
8456
8822
|
};
|
|
8457
8823
|
const drivable = async (record) => !readsChain(record.kind) || await resolveOnchain();
|
|
8458
|
-
const pinnedNetwork = async () => (0,
|
|
8824
|
+
const pinnedNetwork = async () => (0, import_sdk32.getNetwork)(await config.network());
|
|
8459
8825
|
const claimSecretOf = async (swap) => {
|
|
8460
8826
|
const record = await corridorStore().getRfqSwap(swap.rfqId);
|
|
8461
8827
|
if (!record) throw new Error(`rfq swap ${swap.rfqId} has no stored record to claim from`);
|
|
@@ -8479,7 +8845,7 @@ var createSwapDrive = (config) => {
|
|
|
8479
8845
|
await track(
|
|
8480
8846
|
finalizePendingClaim(operator, indexer, {
|
|
8481
8847
|
contract: script,
|
|
8482
|
-
receiver: await (0,
|
|
8848
|
+
receiver: await (0, import_sdk32.contractSigner)(wallet, secret.signingDescriptor),
|
|
8483
8849
|
preimage: await preimageForSwapRecord(wallet, secret),
|
|
8484
8850
|
network: await pinnedNetwork()
|
|
8485
8851
|
})
|
|
@@ -8494,10 +8860,10 @@ var createSwapDrive = (config) => {
|
|
|
8494
8860
|
return track(
|
|
8495
8861
|
pushClaim(operator, {
|
|
8496
8862
|
contract: script,
|
|
8497
|
-
receiver: await (0,
|
|
8863
|
+
receiver: await (0, import_sdk32.contractSigner)(wallet, secret.signingDescriptor),
|
|
8498
8864
|
preimage: await preimageForSwapRecord(wallet, secret),
|
|
8499
8865
|
vtxos,
|
|
8500
|
-
destinationPkScript:
|
|
8866
|
+
destinationPkScript: import_sdk32.ArkAddress.decode(payoutAddress).pkScript,
|
|
8501
8867
|
// Passed through: `pushClaim`'s own value check decides whether `P` is published.
|
|
8502
8868
|
expectedAmount: swap.expectedAmount,
|
|
8503
8869
|
partiallyClaimed,
|
|
@@ -8568,7 +8934,7 @@ var createSwapDrive = (config) => {
|
|
|
8568
8934
|
config.network()
|
|
8569
8935
|
]);
|
|
8570
8936
|
const txs = history.map(toRestoreTx);
|
|
8571
|
-
const { hrp, serverPubKey: operatorPubkey } =
|
|
8937
|
+
const { hrp, serverPubKey: operatorPubkey } = import_sdk32.ArkAddress.decode(address);
|
|
8572
8938
|
const reopened = await legacyOfferDepositsToAdopt(store);
|
|
8573
8939
|
for (const txid of reopen) reopened.add(txid);
|
|
8574
8940
|
const cursor = reopened.size === 0 ? scanned : new Set([...scanned].filter((txid) => !reopened.has(txid)));
|
|
@@ -9502,13 +9868,13 @@ var verifyPlanLegs = (plan, legs, give) => {
|
|
|
9502
9868
|
|
|
9503
9869
|
// src/client/quoteRfq.ts
|
|
9504
9870
|
var import_base22 = require("@scure/base");
|
|
9505
|
-
var
|
|
9871
|
+
var import_sdk36 = require("@arkade-os/sdk");
|
|
9506
9872
|
var import_solver_discovery12 = require("@arkade-os/solver-discovery");
|
|
9507
9873
|
|
|
9508
9874
|
// src/jointGraph.ts
|
|
9509
9875
|
var import_base21 = require("@scure/base");
|
|
9510
9876
|
var import_sha26 = require("@noble/hashes/sha2.js");
|
|
9511
|
-
var
|
|
9877
|
+
var import_sdk33 = require("@arkade-os/sdk");
|
|
9512
9878
|
function digestJointGraph(plan, template) {
|
|
9513
9879
|
const parts = [];
|
|
9514
9880
|
const pushU32 = (value) => {
|
|
@@ -9570,7 +9936,7 @@ function verifyJointGraph(plan, template) {
|
|
|
9570
9936
|
}
|
|
9571
9937
|
}
|
|
9572
9938
|
function parseGraphTx(psbt) {
|
|
9573
|
-
return
|
|
9939
|
+
return import_sdk33.Transaction.fromPSBT(import_base21.base64.decode(psbt));
|
|
9574
9940
|
}
|
|
9575
9941
|
function deepFreeze(value) {
|
|
9576
9942
|
if (value !== null && typeof value === "object") {
|
|
@@ -9591,16 +9957,17 @@ function unsignedPsbtBytes(tx) {
|
|
|
9591
9957
|
init_claimAmountGate();
|
|
9592
9958
|
init_claimPacket();
|
|
9593
9959
|
init_offer();
|
|
9960
|
+
init_program();
|
|
9594
9961
|
init_store();
|
|
9595
9962
|
init_onchainHtlc();
|
|
9596
9963
|
init_onchainHtlc();
|
|
9597
9964
|
|
|
9598
9965
|
// src/payment/onchainSwap.ts
|
|
9599
|
-
var
|
|
9966
|
+
var import_sdk35 = require("@arkade-os/sdk");
|
|
9600
9967
|
init_onchainHtlc();
|
|
9601
9968
|
|
|
9602
9969
|
// src/payment/swapRail.ts
|
|
9603
|
-
var
|
|
9970
|
+
var import_sdk34 = require("@arkade-os/sdk");
|
|
9604
9971
|
|
|
9605
9972
|
// src/client/sats.ts
|
|
9606
9973
|
var satsOf = (value, field) => {
|
|
@@ -9657,13 +10024,13 @@ var lockupOf = (derived) => ({
|
|
|
9657
10024
|
pkScript: derived.swapPkScript
|
|
9658
10025
|
});
|
|
9659
10026
|
var covenantInputs = (input) => {
|
|
9660
|
-
const network = (0,
|
|
9661
|
-
const
|
|
10027
|
+
const network = (0, import_sdk36.networkFromOperatorInfo)(input.info);
|
|
10028
|
+
const arkade4 = input.corridors.get("arkade").deps;
|
|
9662
10029
|
return {
|
|
9663
|
-
operatorPubkey: (0,
|
|
10030
|
+
operatorPubkey: (0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9664
10031
|
// The resolved per-network pin, never operator-reported: it lands in a covenant leaf
|
|
9665
10032
|
// that decides who can move the funds.
|
|
9666
|
-
emulatorPubkey: (0,
|
|
10033
|
+
emulatorPubkey: (0, import_sdk36.toXOnly)(import_base22.hex.decode(arkade4.emulatorPubkey), "emulator signer key"),
|
|
9667
10034
|
claimDelay: unilateralClaimDelay(Number(input.info.unilateralExitDelay)),
|
|
9668
10035
|
hrp: network.hrp
|
|
9669
10036
|
};
|
|
@@ -9721,14 +10088,13 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9721
10088
|
);
|
|
9722
10089
|
}
|
|
9723
10090
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
9724
|
-
const rfqId = newRfqId();
|
|
9725
10091
|
const maker = await makerPosition(input.wallet);
|
|
9726
10092
|
const receiveAddress = payment?.receiveAddress;
|
|
9727
10093
|
const receivePkScript = resolveReceivePkScript(
|
|
9728
10094
|
receiveAddress,
|
|
9729
10095
|
maker.pkScript,
|
|
9730
|
-
(0,
|
|
9731
|
-
(0,
|
|
10096
|
+
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp,
|
|
10097
|
+
(0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key")
|
|
9732
10098
|
);
|
|
9733
10099
|
const choice = payment?.carrier;
|
|
9734
10100
|
const carrierRequest = choice === void 0 ? void 0 : choice.mode === "purchase" ? { mode: "purchase" } : {
|
|
@@ -9746,20 +10112,29 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9746
10112
|
throw new Error("carrier quote expired before RFQ");
|
|
9747
10113
|
}
|
|
9748
10114
|
const request = arkadeSwapRequest({
|
|
9749
|
-
rfqId,
|
|
10115
|
+
rfqId: newRfqId(),
|
|
9750
10116
|
...sides,
|
|
9751
10117
|
amount: pinned.value,
|
|
9752
10118
|
amountSide: toRfqAmountSide(pinned.on),
|
|
9753
10119
|
makerPkScript: receivePkScript,
|
|
9754
|
-
makerPublicKey: maker.publicKey
|
|
9755
|
-
|
|
9756
|
-
const wire = await input.transport.requestQuote({
|
|
9757
|
-
...request,
|
|
9758
|
-
profile: {
|
|
9759
|
-
...request.profile,
|
|
9760
|
-
...carrierRequest === void 0 ? {} : { carrier: encodeCarrierRequest(carrierRequest) }
|
|
9761
|
-
}
|
|
10120
|
+
makerPublicKey: maker.publicKey,
|
|
10121
|
+
contractVersions: ASSET_SWAP_CONTRACT_VERSIONS
|
|
9762
10122
|
});
|
|
10123
|
+
const {
|
|
10124
|
+
quote: wire,
|
|
10125
|
+
rfqId,
|
|
10126
|
+
contractVersion
|
|
10127
|
+
} = await requestVersionedQuote(
|
|
10128
|
+
input.transport,
|
|
10129
|
+
{
|
|
10130
|
+
...request,
|
|
10131
|
+
profile: {
|
|
10132
|
+
...request.profile,
|
|
10133
|
+
...carrierRequest === void 0 ? {} : { carrier: encodeCarrierRequest(carrierRequest) }
|
|
10134
|
+
}
|
|
10135
|
+
},
|
|
10136
|
+
ASSET_SWAP_CONTRACT_VERSIONS
|
|
10137
|
+
);
|
|
9763
10138
|
verifyPair(wire.pair, pair);
|
|
9764
10139
|
const parsed = parseRfqQuote(wire);
|
|
9765
10140
|
verifyCrossAssetAmount({ pair, pinned, give: parsed.give, take: parsed.take });
|
|
@@ -9792,10 +10167,10 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9792
10167
|
) - 30;
|
|
9793
10168
|
if (input.now >= validUntil) throw new Error("asset payment terms lapsed before funding");
|
|
9794
10169
|
assetPayment = {
|
|
9795
|
-
receiveAddress: receiveAddress ?? new
|
|
9796
|
-
(0,
|
|
10170
|
+
receiveAddress: receiveAddress ?? new import_sdk36.ArkAddress(
|
|
10171
|
+
(0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9797
10172
|
maker.pkScript.slice(2),
|
|
9798
|
-
(0,
|
|
10173
|
+
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp
|
|
9799
10174
|
).encode(),
|
|
9800
10175
|
validUntil,
|
|
9801
10176
|
...carrier === void 0 ? {} : { carrier },
|
|
@@ -9820,7 +10195,8 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9820
10195
|
emulatorPubkey: input.corridors.get("arkade").deps.emulatorPubkey,
|
|
9821
10196
|
maker,
|
|
9822
10197
|
...receiveAddress === void 0 ? {} : { receiveAddress },
|
|
9823
|
-
info: input.info
|
|
10198
|
+
info: input.info,
|
|
10199
|
+
contractVersion
|
|
9824
10200
|
});
|
|
9825
10201
|
verifyingDerivation(() => verifyOfferAddress(wire, offer));
|
|
9826
10202
|
return {
|
|
@@ -9875,14 +10251,14 @@ var assetSidesOf = (legs) => {
|
|
|
9875
10251
|
{ give: "arkade", take: "arkade" }
|
|
9876
10252
|
);
|
|
9877
10253
|
}
|
|
9878
|
-
return giveIsBtc ? { wantAsset:
|
|
10254
|
+
return giveIsBtc ? { wantAsset: import_sdk36.asset.AssetId.fromString(legs.take.assetId) } : { offerAsset: import_sdk36.asset.AssetId.fromString(legs.give.assetId) };
|
|
9879
10255
|
};
|
|
9880
10256
|
var makerPosition = async (wallet) => {
|
|
9881
10257
|
const [address, publicKey] = await Promise.all([
|
|
9882
10258
|
wallet.getAddress(),
|
|
9883
10259
|
wallet.identity.xOnlyPublicKey()
|
|
9884
10260
|
]);
|
|
9885
|
-
return { pkScript:
|
|
10261
|
+
return { pkScript: import_sdk36.ArkAddress.decode(address).pkScript, publicKey };
|
|
9886
10262
|
};
|
|
9887
10263
|
var quoteLightningSend = async (input) => {
|
|
9888
10264
|
const invoice = input.endpoints.take.instrument;
|
|
@@ -9891,7 +10267,7 @@ var quoteLightningSend = async (input) => {
|
|
|
9891
10267
|
}
|
|
9892
10268
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
9893
10269
|
const rfqId = newRfqId();
|
|
9894
|
-
const secrets = await (0,
|
|
10270
|
+
const secrets = await (0, import_sdk36.provisionRefundKey)(input.wallet);
|
|
9895
10271
|
const wire = await input.transport.requestQuote(
|
|
9896
10272
|
lightningSendRequest({
|
|
9897
10273
|
rfqId,
|
|
@@ -9967,7 +10343,7 @@ var quoteLightningReceive = async (input) => {
|
|
|
9967
10343
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
9968
10344
|
const rfqId = newRfqId();
|
|
9969
10345
|
const [secrets, payoutAddress] = await Promise.all([
|
|
9970
|
-
(0,
|
|
10346
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
9971
10347
|
input.wallet.getAddress()
|
|
9972
10348
|
]);
|
|
9973
10349
|
const paymentHash = import_base22.hex.encode(secrets.paymentHash);
|
|
@@ -10087,8 +10463,8 @@ var quoteOnchainSend = async (input) => {
|
|
|
10087
10463
|
}) : void 0;
|
|
10088
10464
|
const quoted = claimFee === void 0 ? pinned : { on: pinned.on, value: pinned.value + claimFee, source: pinned.source };
|
|
10089
10465
|
const [secrets, payoutKey] = await Promise.all([
|
|
10090
|
-
(0,
|
|
10091
|
-
(0,
|
|
10466
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10467
|
+
(0, import_sdk36.provisionRefundKey)(input.wallet)
|
|
10092
10468
|
]);
|
|
10093
10469
|
const paymentHash = import_base22.hex.encode(secrets.paymentHash);
|
|
10094
10470
|
const wire = await input.transport.requestQuote(
|
|
@@ -10196,8 +10572,8 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10196
10572
|
const rfqId = newRfqId();
|
|
10197
10573
|
const l1Network = l1NetworkFromArk(input.info.network);
|
|
10198
10574
|
const [secrets, refundKey, payoutAddress, boardingAddress] = await Promise.all([
|
|
10199
|
-
(0,
|
|
10200
|
-
(0,
|
|
10575
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10576
|
+
(0, import_sdk36.provisionRefundKey)(input.wallet),
|
|
10201
10577
|
input.wallet.getAddress(),
|
|
10202
10578
|
input.wallet.getBoardingAddress()
|
|
10203
10579
|
]);
|
|
@@ -10307,7 +10683,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10307
10683
|
};
|
|
10308
10684
|
|
|
10309
10685
|
// src/client/verbs.ts
|
|
10310
|
-
var
|
|
10686
|
+
var import_sdk37 = require("@arkade-os/sdk");
|
|
10311
10687
|
var enforceFeeCeiling = (quote, call, policy) => {
|
|
10312
10688
|
let ceiling;
|
|
10313
10689
|
for (const [source, limit] of [
|
|
@@ -10332,14 +10708,14 @@ var settle = async (deps, input, maxFee) => {
|
|
|
10332
10708
|
return deps.accept(quote);
|
|
10333
10709
|
};
|
|
10334
10710
|
var pay = async (deps, destination, options = {}) => {
|
|
10335
|
-
const
|
|
10336
|
-
if (
|
|
10337
|
-
const amount = (0,
|
|
10711
|
+
const arkade4 = (0, import_sdk37.arkTarget)(destination);
|
|
10712
|
+
if (arkade4 !== void 0) {
|
|
10713
|
+
const amount = (0, import_sdk37.resolveSendAmount)(
|
|
10338
10714
|
"ark",
|
|
10339
10715
|
destination,
|
|
10340
10716
|
options.amount === void 0 ? void 0 : satsOf(options.amount, "amount")
|
|
10341
10717
|
);
|
|
10342
|
-
return { kind: "payment", txid: await deps.wallet.send({ address:
|
|
10718
|
+
return { kind: "payment", txid: await deps.wallet.send({ address: arkade4, amount }) };
|
|
10343
10719
|
}
|
|
10344
10720
|
const swap = await settle(
|
|
10345
10721
|
deps,
|
|
@@ -10545,7 +10921,7 @@ var createSwapClient = (config) => {
|
|
|
10545
10921
|
}
|
|
10546
10922
|
},
|
|
10547
10923
|
accept: async (quote, options) => {
|
|
10548
|
-
const validUntil = (0,
|
|
10924
|
+
const validUntil = (0, import_sdk38.captureSendDeadline)(options?.validUntil);
|
|
10549
10925
|
ensureLive("accept");
|
|
10550
10926
|
const { corridors } = await resolved();
|
|
10551
10927
|
const drive2 = driving();
|
|
@@ -10657,7 +11033,7 @@ var createSwapClient = (config) => {
|
|
|
10657
11033
|
|
|
10658
11034
|
// src/reveal.ts
|
|
10659
11035
|
var import_base24 = require("@scure/base");
|
|
10660
|
-
var
|
|
11036
|
+
var import_sdk39 = require("@arkade-os/sdk");
|
|
10661
11037
|
init_claimAmountGate();
|
|
10662
11038
|
init_claimPacket();
|
|
10663
11039
|
init_onchainHtlc();
|
|
@@ -10707,7 +11083,7 @@ var covclaimdClient = (baseUrl, options = {}) => {
|
|
|
10707
11083
|
const url = baseUrl.replace(/\/+$/, "");
|
|
10708
11084
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
10709
11085
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
10710
|
-
(0,
|
|
11086
|
+
(0, import_sdk39.assertTimerMs)("timeoutMs", timeoutMs);
|
|
10711
11087
|
const send = async (what, path, init) => {
|
|
10712
11088
|
let response;
|
|
10713
11089
|
try {
|
|
@@ -10779,7 +11155,7 @@ function revealFieldsFromScript(script) {
|
|
|
10779
11155
|
}
|
|
10780
11156
|
async function revealClaimPacket(client, input) {
|
|
10781
11157
|
const fields = revealFieldsFromScript(input.script);
|
|
10782
|
-
if (import_base24.hex.encode(
|
|
11158
|
+
if (import_base24.hex.encode(import_sdk39.ArkAddress.decode(input.address).pkScript) !== import_base24.hex.encode(input.script.pkScript)) {
|
|
10783
11159
|
throw new Error("address does not belong to this covenant");
|
|
10784
11160
|
}
|
|
10785
11161
|
assertPreimageMatches(input.preimage, input.script.options.preimageHash);
|
|
@@ -10796,7 +11172,7 @@ async function revealClaimPacket(client, input) {
|
|
|
10796
11172
|
|
|
10797
11173
|
// src/offerFillPlan.ts
|
|
10798
11174
|
var import_base25 = require("@scure/base");
|
|
10799
|
-
var
|
|
11175
|
+
var import_sdk40 = require("@arkade-os/sdk");
|
|
10800
11176
|
init_offer();
|
|
10801
11177
|
var OFFER_FILL_TEMPLATE = "offer-fill/1";
|
|
10802
11178
|
var OFFER_FILL_OWNERS = [null, "solver", "sponsor"];
|
|
@@ -10814,7 +11190,7 @@ async function buildOfferFillPlan(wallet, arkServerUrl, offerHex, opts) {
|
|
|
10814
11190
|
const contract = await connectFillContract(wallet, arkServerUrl, offer, { swapAddress });
|
|
10815
11191
|
const vtxos = await contract.getUtxos();
|
|
10816
11192
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
10817
|
-
const solverPayout = payoutScript ??
|
|
11193
|
+
const solverPayout = payoutScript ?? import_sdk40.ArkAddress.decode(await wallet.getAddress()).pkScript;
|
|
10818
11194
|
const sponsorLeg = sponsor !== void 0 ? normalizeSponsor(sponsor, assetCarrierSats) : void 0;
|
|
10819
11195
|
const fill = contract.functions.fulfill();
|
|
10820
11196
|
const layout = assembleOfferFill(fill, {
|
|
@@ -10881,14 +11257,14 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10881
11257
|
}
|
|
10882
11258
|
});
|
|
10883
11259
|
const ext = arkTx.getOutput(payments);
|
|
10884
|
-
if (!ext?.script || !
|
|
11260
|
+
if (!ext?.script || !import_sdk40.Extension.isExtension(ext.script)) {
|
|
10885
11261
|
throw new Error(`fill plan output ${payments} is not the extension packet`);
|
|
10886
11262
|
}
|
|
10887
11263
|
const anchor = arkTx.getOutput(payments + 1);
|
|
10888
|
-
if (!anchor?.script || import_base25.hex.encode(anchor.script) !== import_base25.hex.encode(
|
|
11264
|
+
if (!anchor?.script || import_base25.hex.encode(anchor.script) !== import_base25.hex.encode(import_sdk40.P2A.script) || anchor.amount !== import_sdk40.P2A.amount) {
|
|
10889
11265
|
throw new Error(`fill plan output ${payments + 1} is not the anchor`);
|
|
10890
11266
|
}
|
|
10891
|
-
const packet =
|
|
11267
|
+
const packet = import_sdk40.Extension.fromTx(arkTx).getAssetPacket();
|
|
10892
11268
|
for (const group of packet?.groups ?? []) {
|
|
10893
11269
|
if (group.assetId === null) throw new Error("fill plan carries an issuance group");
|
|
10894
11270
|
const assetId = group.assetId.toString();
|
|
@@ -10899,7 +11275,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
10899
11275
|
}
|
|
10900
11276
|
for (const output of group.outputs) {
|
|
10901
11277
|
const hosted = arkTx.getOutput(output.vout);
|
|
10902
|
-
if (output.vout >= payments || !hosted?.script ||
|
|
11278
|
+
if (output.vout >= payments || !hosted?.script || import_sdk40.Extension.isExtension(hosted.script)) {
|
|
10903
11279
|
throw new Error(
|
|
10904
11280
|
`fill plan asset ${assetId} pays nonexistent output ${output.vout}`
|
|
10905
11281
|
);
|