@arkade-os/swap 0.1.7 → 0.1.9
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 +653 -262
- package/dist/advanced.d.cts +9 -8
- package/dist/advanced.d.ts +9 -8
- package/dist/advanced.js +4 -3
- package/dist/{chunk-7BBQ74BG.js → chunk-552GDPBU.js} +484 -128
- package/dist/chunk-5QPJWOCN.js +16 -0
- package/dist/{chunk-QFM55KP2.js → chunk-FQNG4XMF.js} +9 -3
- package/dist/{chunk-SDPNWPGY.js → chunk-I7WEXXZX.js} +27 -16
- package/dist/index.cjs +669 -278
- 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 +594 -198
- 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/protocol.cjs
CHANGED
|
@@ -52,9 +52,9 @@ function onchainHtlcScript(params, network) {
|
|
|
52
52
|
if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
|
|
53
53
|
throw new Error("claimKey and refundKey must be 32-byte x-only keys");
|
|
54
54
|
}
|
|
55
|
-
if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
|
|
55
|
+
if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
|
|
56
56
|
throw new Error(
|
|
57
|
-
`refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
|
|
57
|
+
`refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
if (params.refundLocktime < LOCKTIME_THRESHOLD) {
|
|
@@ -147,15 +147,20 @@ async function claimOnchainFill(chain, input) {
|
|
|
147
147
|
}
|
|
148
148
|
async function classifyOnchainHtlc(chain, input) {
|
|
149
149
|
const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
const deep = (u) => u.confirmations >= input.minConfirmations;
|
|
151
|
+
const best = utxos.sort(
|
|
152
|
+
(a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
|
|
153
|
+
)[0];
|
|
154
|
+
const { funding } = input;
|
|
155
|
+
let spend = null;
|
|
156
|
+
if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
|
|
157
|
+
try {
|
|
158
|
+
spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (!best) throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (spend) {
|
|
159
164
|
const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
|
|
160
165
|
const txid = btc.Transaction.fromRaw(import_base.hex.decode(spend.txHex), {
|
|
161
166
|
allowUnknownInputs: true,
|
|
@@ -163,6 +168,7 @@ async function classifyOnchainHtlc(chain, input) {
|
|
|
163
168
|
}).id;
|
|
164
169
|
return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
|
|
165
170
|
}
|
|
171
|
+
if (!best) return { phase: "unfunded" };
|
|
166
172
|
if (best.confirmations < input.minConfirmations)
|
|
167
173
|
return { phase: "awaiting_confirmations", utxo: best };
|
|
168
174
|
const mtp = await chain.getMtp();
|
|
@@ -492,11 +498,248 @@ var init_lockupContract = __esm({
|
|
|
492
498
|
}
|
|
493
499
|
});
|
|
494
500
|
|
|
495
|
-
// src/swap
|
|
496
|
-
var
|
|
497
|
-
var
|
|
498
|
-
"src/swap
|
|
499
|
-
|
|
501
|
+
// src/contracts/asset-swap.json
|
|
502
|
+
var asset_swap_default;
|
|
503
|
+
var init_asset_swap = __esm({
|
|
504
|
+
"src/contracts/asset-swap.json"() {
|
|
505
|
+
asset_swap_default = {
|
|
506
|
+
formatVersion: 1,
|
|
507
|
+
contractName: "AssetSwap",
|
|
508
|
+
constructorInputs: [
|
|
509
|
+
{
|
|
510
|
+
name: "receiver",
|
|
511
|
+
type: "pubkey"
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
name: "amount",
|
|
515
|
+
type: "int"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
name: "assetTxid",
|
|
519
|
+
type: "bytes32"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
name: "assetGroupIndex",
|
|
523
|
+
type: "int"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: "user",
|
|
527
|
+
type: "pubkey"
|
|
528
|
+
}
|
|
529
|
+
],
|
|
530
|
+
functions: [
|
|
531
|
+
{
|
|
532
|
+
name: "fulfill",
|
|
533
|
+
arkade: {
|
|
534
|
+
inputs: [],
|
|
535
|
+
asm: [
|
|
536
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
537
|
+
"OP_DUP",
|
|
538
|
+
"<assetTxid>",
|
|
539
|
+
"<assetGroupIndex>",
|
|
540
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
541
|
+
"OP_VERIFY",
|
|
542
|
+
"<amount>",
|
|
543
|
+
"OP_GREATERTHANOREQUAL",
|
|
544
|
+
"OP_VERIFY",
|
|
545
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
546
|
+
"1",
|
|
547
|
+
"OP_NUMEQUALVERIFY",
|
|
548
|
+
"<receiver>",
|
|
549
|
+
"OP_EQUAL"
|
|
550
|
+
]
|
|
551
|
+
},
|
|
552
|
+
leaves: [
|
|
553
|
+
{
|
|
554
|
+
name: "fulfill",
|
|
555
|
+
witness: [
|
|
556
|
+
{
|
|
557
|
+
name: "serverSig",
|
|
558
|
+
type: "signature",
|
|
559
|
+
encoding: "schnorr-64",
|
|
560
|
+
injected: true
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: "emulatorSig",
|
|
564
|
+
type: "signature",
|
|
565
|
+
encoding: "schnorr-64",
|
|
566
|
+
injected: true
|
|
567
|
+
}
|
|
568
|
+
],
|
|
569
|
+
asm: [
|
|
570
|
+
"<SERVER_KEY>",
|
|
571
|
+
"OP_CHECKSIGVERIFY",
|
|
572
|
+
"<EMULATOR_KEY:fulfill>",
|
|
573
|
+
"OP_CHECKSIG"
|
|
574
|
+
]
|
|
575
|
+
}
|
|
576
|
+
]
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
name: "cancel",
|
|
580
|
+
leaves: [
|
|
581
|
+
{
|
|
582
|
+
name: "cancel",
|
|
583
|
+
witness: [
|
|
584
|
+
{
|
|
585
|
+
name: "userSig",
|
|
586
|
+
type: "signature",
|
|
587
|
+
encoding: "schnorr-64"
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: "serverSig",
|
|
591
|
+
type: "signature",
|
|
592
|
+
encoding: "schnorr-64",
|
|
593
|
+
injected: true
|
|
594
|
+
}
|
|
595
|
+
],
|
|
596
|
+
asm: [
|
|
597
|
+
"<user>",
|
|
598
|
+
"OP_CHECKSIGVERIFY",
|
|
599
|
+
"<SERVER_KEY>",
|
|
600
|
+
"OP_CHECKSIG"
|
|
601
|
+
]
|
|
602
|
+
}
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
],
|
|
606
|
+
source: {
|
|
607
|
+
entry: "asset-swap.ark",
|
|
608
|
+
files: {
|
|
609
|
+
"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"
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
compiler: {
|
|
613
|
+
name: "arkadec",
|
|
614
|
+
version: "0.1.0-rc.1",
|
|
615
|
+
options: {
|
|
616
|
+
optimize: true
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
updatedAt: "2026-11-02T17:43:42.615113722+00:00",
|
|
620
|
+
fingerprint: "sha256:e2b80add6237f6c7e2c69a96ae46d55abe6de5f71c3718106f4d5b22ac9e6d0a"
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
// src/contracts/sats-swap.json
|
|
626
|
+
var sats_swap_default;
|
|
627
|
+
var init_sats_swap = __esm({
|
|
628
|
+
"src/contracts/sats-swap.json"() {
|
|
629
|
+
sats_swap_default = {
|
|
630
|
+
formatVersion: 1,
|
|
631
|
+
contractName: "SatsSwap",
|
|
632
|
+
constructorInputs: [
|
|
633
|
+
{
|
|
634
|
+
name: "receiver",
|
|
635
|
+
type: "pubkey"
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "amount",
|
|
639
|
+
type: "int"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
name: "user",
|
|
643
|
+
type: "pubkey"
|
|
644
|
+
}
|
|
645
|
+
],
|
|
646
|
+
functions: [
|
|
647
|
+
{
|
|
648
|
+
name: "fulfill",
|
|
649
|
+
arkade: {
|
|
650
|
+
inputs: [],
|
|
651
|
+
asm: [
|
|
652
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
653
|
+
"OP_DUP",
|
|
654
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
655
|
+
"<amount>",
|
|
656
|
+
"OP_GREATERTHANOREQUAL",
|
|
657
|
+
"OP_VERIFY",
|
|
658
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
659
|
+
"1",
|
|
660
|
+
"OP_NUMEQUALVERIFY",
|
|
661
|
+
"<receiver>",
|
|
662
|
+
"OP_EQUAL"
|
|
663
|
+
]
|
|
664
|
+
},
|
|
665
|
+
leaves: [
|
|
666
|
+
{
|
|
667
|
+
name: "fulfill",
|
|
668
|
+
witness: [
|
|
669
|
+
{
|
|
670
|
+
name: "serverSig",
|
|
671
|
+
type: "signature",
|
|
672
|
+
encoding: "schnorr-64",
|
|
673
|
+
injected: true
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
name: "emulatorSig",
|
|
677
|
+
type: "signature",
|
|
678
|
+
encoding: "schnorr-64",
|
|
679
|
+
injected: true
|
|
680
|
+
}
|
|
681
|
+
],
|
|
682
|
+
asm: [
|
|
683
|
+
"<SERVER_KEY>",
|
|
684
|
+
"OP_CHECKSIGVERIFY",
|
|
685
|
+
"<EMULATOR_KEY:fulfill>",
|
|
686
|
+
"OP_CHECKSIG"
|
|
687
|
+
]
|
|
688
|
+
}
|
|
689
|
+
]
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
name: "cancel",
|
|
693
|
+
leaves: [
|
|
694
|
+
{
|
|
695
|
+
name: "cancel",
|
|
696
|
+
witness: [
|
|
697
|
+
{
|
|
698
|
+
name: "userSig",
|
|
699
|
+
type: "signature",
|
|
700
|
+
encoding: "schnorr-64"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
name: "serverSig",
|
|
704
|
+
type: "signature",
|
|
705
|
+
encoding: "schnorr-64",
|
|
706
|
+
injected: true
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
asm: [
|
|
710
|
+
"<user>",
|
|
711
|
+
"OP_CHECKSIGVERIFY",
|
|
712
|
+
"<SERVER_KEY>",
|
|
713
|
+
"OP_CHECKSIG"
|
|
714
|
+
]
|
|
715
|
+
}
|
|
716
|
+
]
|
|
717
|
+
}
|
|
718
|
+
],
|
|
719
|
+
source: {
|
|
720
|
+
entry: "sats-swap.ark",
|
|
721
|
+
files: {
|
|
722
|
+
"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"
|
|
723
|
+
}
|
|
724
|
+
},
|
|
725
|
+
compiler: {
|
|
726
|
+
name: "arkadec",
|
|
727
|
+
version: "0.1.0-rc.1",
|
|
728
|
+
options: {
|
|
729
|
+
optimize: true
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
updatedAt: "2026-11-02T17:43:42.616824535+00:00",
|
|
733
|
+
fingerprint: "sha256:d7a60ab2178ede40a2e4867816689ea022641531cc662b562bebd7caa1ef96c4"
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
// src/legacy/swap-want-asset.program.v1.json
|
|
739
|
+
var swap_want_asset_program_v1_default;
|
|
740
|
+
var init_swap_want_asset_program_v1 = __esm({
|
|
741
|
+
"src/legacy/swap-want-asset.program.v1.json"() {
|
|
742
|
+
swap_want_asset_program_v1_default = {
|
|
500
743
|
version: 1,
|
|
501
744
|
name: "banco-btc-to-asset",
|
|
502
745
|
params: [
|
|
@@ -537,11 +780,11 @@ var init_swap_want_asset_program = __esm({
|
|
|
537
780
|
}
|
|
538
781
|
});
|
|
539
782
|
|
|
540
|
-
// src/swap-want-btc.program.json
|
|
541
|
-
var
|
|
542
|
-
var
|
|
543
|
-
"src/swap-want-btc.program.json"() {
|
|
544
|
-
|
|
783
|
+
// src/legacy/swap-want-btc.program.v1.json
|
|
784
|
+
var swap_want_btc_program_v1_default;
|
|
785
|
+
var init_swap_want_btc_program_v1 = __esm({
|
|
786
|
+
"src/legacy/swap-want-btc.program.v1.json"() {
|
|
787
|
+
swap_want_btc_program_v1_default = {
|
|
545
788
|
version: 1,
|
|
546
789
|
name: "banco-asset-to-btc",
|
|
547
790
|
params: [
|
|
@@ -577,6 +820,80 @@ var init_swap_want_btc_program = __esm({
|
|
|
577
820
|
}
|
|
578
821
|
});
|
|
579
822
|
|
|
823
|
+
// src/rfq-contract.ts
|
|
824
|
+
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_BASELINE;
|
|
825
|
+
var init_rfq_contract = __esm({
|
|
826
|
+
"src/rfq-contract.ts"() {
|
|
827
|
+
"use strict";
|
|
828
|
+
RFQ_CONTRACT_VERSIONS_KEY = "contract_versions";
|
|
829
|
+
RFQ_CONTRACT_VERSION_KEY = "contract_version";
|
|
830
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
831
|
+
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
832
|
+
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
833
|
+
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
// src/program.ts
|
|
838
|
+
var import_sdk3, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
839
|
+
var init_program = __esm({
|
|
840
|
+
"src/program.ts"() {
|
|
841
|
+
"use strict";
|
|
842
|
+
import_sdk3 = require("@arkade-os/sdk");
|
|
843
|
+
init_asset_swap();
|
|
844
|
+
init_sats_swap();
|
|
845
|
+
init_swap_want_asset_program_v1();
|
|
846
|
+
init_swap_want_btc_program_v1();
|
|
847
|
+
init_rfq_contract();
|
|
848
|
+
init_rfq_contract();
|
|
849
|
+
swapPrograms = {
|
|
850
|
+
wantAsset: import_sdk3.arkade.programFromArtifact(asset_swap_default),
|
|
851
|
+
wantBtc: import_sdk3.arkade.programFromArtifact(sats_swap_default)
|
|
852
|
+
};
|
|
853
|
+
legacySwapPrograms = {
|
|
854
|
+
wantAsset: import_sdk3.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
855
|
+
wantBtc: import_sdk3.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
856
|
+
};
|
|
857
|
+
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
858
|
+
user,
|
|
859
|
+
server,
|
|
860
|
+
...exitDelay && { exitDelay }
|
|
861
|
+
});
|
|
862
|
+
ASSET_SWAP_CONTRACTS = {
|
|
863
|
+
[ASSET_SWAP_V2]: {
|
|
864
|
+
programs: legacySwapPrograms,
|
|
865
|
+
args: (inputs) => ({
|
|
866
|
+
makerWP: inputs.receiver,
|
|
867
|
+
wantAmount: inputs.amount,
|
|
868
|
+
...inputs.asset && {
|
|
869
|
+
wantAssetTxid: inputs.asset.txid,
|
|
870
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
871
|
+
},
|
|
872
|
+
...sharedArgs(inputs)
|
|
873
|
+
})
|
|
874
|
+
},
|
|
875
|
+
[ASSET_SWAP_V3]: {
|
|
876
|
+
programs: swapPrograms,
|
|
877
|
+
args: (inputs) => ({
|
|
878
|
+
receiver: inputs.receiver,
|
|
879
|
+
amount: inputs.amount,
|
|
880
|
+
...inputs.asset && {
|
|
881
|
+
assetTxid: inputs.asset.txid,
|
|
882
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
883
|
+
},
|
|
884
|
+
...sharedArgs(inputs)
|
|
885
|
+
})
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V3, ASSET_SWAP_V2];
|
|
889
|
+
assetSwapContractVersion = (id) => {
|
|
890
|
+
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
891
|
+
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
892
|
+
throw new Error(`unknown contract version ${id}`);
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
|
|
580
897
|
// src/rfqCorridor.ts
|
|
581
898
|
var RfqCorridorRegistry, rfqCorridorHandlers;
|
|
582
899
|
var init_rfqCorridor = __esm({
|
|
@@ -620,26 +937,26 @@ var init_rfqCorridor = __esm({
|
|
|
620
937
|
});
|
|
621
938
|
|
|
622
939
|
// src/repository.ts
|
|
623
|
-
var
|
|
940
|
+
var import_sdk4, collectAssetSwaps, collectRfqSwaps;
|
|
624
941
|
var init_repository = __esm({
|
|
625
942
|
"src/repository.ts"() {
|
|
626
943
|
"use strict";
|
|
627
|
-
|
|
628
|
-
collectAssetSwaps = (repository) => (0,
|
|
629
|
-
collectRfqSwaps = (repository, filter = {}) => (0,
|
|
944
|
+
import_sdk4 = require("@arkade-os/sdk");
|
|
945
|
+
collectAssetSwaps = (repository) => (0, import_sdk4.collectPages)((page) => repository.getAssetSwapsPage(page));
|
|
946
|
+
collectRfqSwaps = (repository, filter = {}) => (0, import_sdk4.collectPages)(
|
|
630
947
|
(page) => repository.getRfqSwapsPage(filter, page)
|
|
631
948
|
);
|
|
632
949
|
}
|
|
633
950
|
});
|
|
634
951
|
|
|
635
952
|
// src/store.ts
|
|
636
|
-
var import_base4, import_sha23,
|
|
953
|
+
var import_base4, import_sha23, import_sdk5, BTC_ASSET_ID, byNewest, getAssetSwapsOrThrow, getAssetSwaps, saveSwapOrThrow, addAssetSwap, updateAssetSwap, updateAssetSwapBestEffort, swapSecretsToRecord, decodeHex32, PreimageNotRecoverableError, preimageForSwapRecord;
|
|
637
954
|
var init_store = __esm({
|
|
638
955
|
"src/store.ts"() {
|
|
639
956
|
"use strict";
|
|
640
957
|
import_base4 = require("@scure/base");
|
|
641
958
|
import_sha23 = require("@noble/hashes/sha2.js");
|
|
642
|
-
|
|
959
|
+
import_sdk5 = require("@arkade-os/sdk");
|
|
643
960
|
init_repository();
|
|
644
961
|
BTC_ASSET_ID = "btc";
|
|
645
962
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
@@ -734,7 +1051,7 @@ var init_store = __esm({
|
|
|
734
1051
|
}
|
|
735
1052
|
let preimage;
|
|
736
1053
|
try {
|
|
737
|
-
preimage = await (0,
|
|
1054
|
+
preimage = await (0, import_sdk5.contractPreimage)(wallet, record.signingDescriptor, { stored, salt });
|
|
738
1055
|
} catch (cause) {
|
|
739
1056
|
throw new PreimageNotRecoverableError(
|
|
740
1057
|
"not-derivable",
|
|
@@ -846,37 +1163,60 @@ function withExitClosure(program, exit) {
|
|
|
846
1163
|
}
|
|
847
1164
|
};
|
|
848
1165
|
}
|
|
849
|
-
function swapProgramBinding(offer, operatorPubkey) {
|
|
1166
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion = ASSET_SWAP_BASELINE) {
|
|
850
1167
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
851
1168
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
852
1169
|
}
|
|
1170
|
+
const expected = offer.swapPkScript;
|
|
1171
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1172
|
+
const funded = import_base5.hex.encode(expected);
|
|
1173
|
+
const order = [
|
|
1174
|
+
ASSET_SWAP_BASELINE,
|
|
1175
|
+
...ASSET_SWAP_CONTRACT_VERSIONS.filter((v) => v !== ASSET_SWAP_BASELINE)
|
|
1176
|
+
];
|
|
1177
|
+
for (const version of order) {
|
|
1178
|
+
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
1179
|
+
if (pkOf(binding) === funded) return binding;
|
|
1180
|
+
}
|
|
1181
|
+
return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1182
|
+
}
|
|
1183
|
+
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1184
|
+
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1185
|
+
const user = offer.makerPublicKey;
|
|
1186
|
+
const assetId = offer.wantAsset;
|
|
853
1187
|
return {
|
|
854
|
-
program: withExitClosure(
|
|
855
|
-
|
|
856
|
-
offer.
|
|
857
|
-
|
|
858
|
-
args: {
|
|
859
|
-
makerWP: offer.makerPkScript.subarray(2),
|
|
860
|
-
wantAmount: offer.wantAmount,
|
|
861
|
-
server: operatorPubkey,
|
|
862
|
-
user: offer.makerPublicKey,
|
|
1188
|
+
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
1189
|
+
args: args({
|
|
1190
|
+
receiver: offer.makerPkScript.subarray(2),
|
|
1191
|
+
amount: offer.wantAmount,
|
|
863
1192
|
// internal byte order
|
|
864
|
-
...
|
|
865
|
-
|
|
866
|
-
wantAssetGroupIndex: offer.wantAsset.groupIndex
|
|
1193
|
+
...assetId && {
|
|
1194
|
+
asset: { txid: assetId.txid.slice().reverse(), groupIndex: assetId.groupIndex }
|
|
867
1195
|
},
|
|
1196
|
+
user,
|
|
1197
|
+
server: operatorPubkey,
|
|
868
1198
|
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
869
|
-
},
|
|
1199
|
+
}),
|
|
870
1200
|
keys: {
|
|
871
1201
|
serverKey: operatorPubkey,
|
|
872
|
-
userKey:
|
|
1202
|
+
userKey: user,
|
|
873
1203
|
emulatorKey: offer.emulatorPubkey
|
|
874
1204
|
}
|
|
875
1205
|
};
|
|
876
1206
|
}
|
|
877
|
-
function
|
|
878
|
-
|
|
879
|
-
|
|
1207
|
+
function compileSwapBinding(binding) {
|
|
1208
|
+
let script = compiledBindings.get(binding);
|
|
1209
|
+
if (!script) {
|
|
1210
|
+
script = new import_sdk6.arkade.ArkadeProgramScript(binding.program, binding.args, binding.keys);
|
|
1211
|
+
compiledBindings.set(binding, script);
|
|
1212
|
+
}
|
|
1213
|
+
return script;
|
|
1214
|
+
}
|
|
1215
|
+
function pkOf(binding) {
|
|
1216
|
+
return import_base5.hex.encode(compileSwapBinding(binding).pkScript);
|
|
1217
|
+
}
|
|
1218
|
+
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
1219
|
+
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
880
1220
|
}
|
|
881
1221
|
function u64(name, value) {
|
|
882
1222
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
@@ -992,8 +1332,8 @@ function decodeOffer(data) {
|
|
|
992
1332
|
return {
|
|
993
1333
|
swapPkScript: need("swapPkScript"),
|
|
994
1334
|
wantAmount: readU64(amount),
|
|
995
|
-
...fields.wantAsset && { wantAsset:
|
|
996
|
-
...fields.offerAsset && { offerAsset:
|
|
1335
|
+
...fields.wantAsset && { wantAsset: import_sdk6.asset.AssetId.fromBytes(fields.wantAsset) },
|
|
1336
|
+
...fields.offerAsset && { offerAsset: import_sdk6.asset.AssetId.fromBytes(fields.offerAsset) },
|
|
997
1337
|
makerPkScript: need("makerPkScript"),
|
|
998
1338
|
makerPublicKey: need("makerPublicKey"),
|
|
999
1339
|
emulatorPubkey: need("emulatorPubkey"),
|
|
@@ -1019,8 +1359,11 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
1019
1359
|
});
|
|
1020
1360
|
}
|
|
1021
1361
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
1022
|
-
const { program, args, keys } = swapProgramBinding(
|
|
1023
|
-
|
|
1362
|
+
const { program, args, keys } = swapProgramBinding(
|
|
1363
|
+
{ ...binding, swapPkScript: expectedPkScript },
|
|
1364
|
+
operatorPubkey
|
|
1365
|
+
);
|
|
1366
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, program, args, keys);
|
|
1024
1367
|
if (import_base5.hex.encode(contract.pkScript) !== import_base5.hex.encode(expectedPkScript)) {
|
|
1025
1368
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
1026
1369
|
}
|
|
@@ -1052,7 +1395,7 @@ function resolveReceivePkScript(receiveAddress, walletPkScript, hrp, serverPubKe
|
|
|
1052
1395
|
if (receiveAddress === void 0) return walletPkScript;
|
|
1053
1396
|
let address;
|
|
1054
1397
|
try {
|
|
1055
|
-
address =
|
|
1398
|
+
address = import_sdk6.ArkAddress.decode(receiveAddress);
|
|
1056
1399
|
} catch (cause) {
|
|
1057
1400
|
throw new Error("receiveAddress is not a valid Arkade address", { cause });
|
|
1058
1401
|
}
|
|
@@ -1087,13 +1430,13 @@ async function deriveOffer(wallet, params) {
|
|
|
1087
1430
|
wallet.getAddress(),
|
|
1088
1431
|
wallet.identity.xOnlyPublicKey()
|
|
1089
1432
|
]);
|
|
1090
|
-
return { pkScript:
|
|
1433
|
+
return { pkScript: import_sdk6.ArkAddress.decode(address).pkScript, publicKey };
|
|
1091
1434
|
})()
|
|
1092
1435
|
]);
|
|
1093
|
-
const operatorPubKey = import_base5.hex.decode((0,
|
|
1094
|
-
const network = (0,
|
|
1436
|
+
const operatorPubKey = import_base5.hex.decode((0, import_sdk6.toXOnlySignerHex)(info.signerPubkey));
|
|
1437
|
+
const network = (0, import_sdk6.networkFromOperatorInfo)(info);
|
|
1095
1438
|
const emuKey = import_base5.hex.decode(
|
|
1096
|
-
(0,
|
|
1439
|
+
(0, import_sdk6.toXOnlySignerHex)((0, import_sdk6.resolveEmulatorPubkey)(network, params.emulatorPubkey))
|
|
1097
1440
|
);
|
|
1098
1441
|
const binding = Object.freeze({
|
|
1099
1442
|
wantAmount: params.wantAmount,
|
|
@@ -1110,7 +1453,7 @@ async function deriveOffer(wallet, params) {
|
|
|
1110
1453
|
// checked before registration below. @see assertExitDelay
|
|
1111
1454
|
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
1112
1455
|
});
|
|
1113
|
-
const script = offerContract(binding, operatorPubKey);
|
|
1456
|
+
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
1114
1457
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
1115
1458
|
const payload = encodeOffer(offer);
|
|
1116
1459
|
return Object.freeze({
|
|
@@ -1172,7 +1515,7 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1172
1515
|
wallet.getArkadeReader(),
|
|
1173
1516
|
wallet.getArkadeBroadcaster()
|
|
1174
1517
|
]);
|
|
1175
|
-
const client = await
|
|
1518
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1176
1519
|
arkade: { getInfo: async () => info, ...broadcaster },
|
|
1177
1520
|
indexer: reader,
|
|
1178
1521
|
identity: wallet.identity,
|
|
@@ -1182,21 +1525,22 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1182
1525
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
1183
1526
|
oneShotSubmit: wallet.oneShotSubmit
|
|
1184
1527
|
});
|
|
1185
|
-
const operatorPubkey = swapAddress ?
|
|
1186
|
-
|
|
1528
|
+
const operatorPubkey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1529
|
+
let binding;
|
|
1187
1530
|
let rebuilt;
|
|
1188
1531
|
try {
|
|
1189
|
-
|
|
1532
|
+
binding = swapProgramBinding(offer, operatorPubkey);
|
|
1533
|
+
rebuilt = compileSwapBinding(binding);
|
|
1190
1534
|
} catch (cause) {
|
|
1191
1535
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript), { cause });
|
|
1192
1536
|
}
|
|
1193
1537
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1194
1538
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript));
|
|
1195
1539
|
}
|
|
1196
|
-
const contract = new
|
|
1540
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1197
1541
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
1198
1542
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
1199
|
-
const makerPkScript =
|
|
1543
|
+
const makerPkScript = import_sdk6.ArkAddress.decode(makerAddress).pkScript;
|
|
1200
1544
|
const cancel = contract.functions.cancel().from({ txid: vtxo.txid, vout: vtxo.vout, value: vtxo.value }).to(makerPkScript, BigInt(vtxo.value));
|
|
1201
1545
|
for (const a of vtxo.assets ?? []) {
|
|
1202
1546
|
cancel.withAsset({
|
|
@@ -1235,7 +1579,7 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1235
1579
|
offer,
|
|
1236
1580
|
vtxo,
|
|
1237
1581
|
solverFund: fund,
|
|
1238
|
-
solverPayout: payoutScript ??
|
|
1582
|
+
solverPayout: payoutScript ?? import_sdk6.ArkAddress.decode(takerAddress).pkScript,
|
|
1239
1583
|
assetCarrierSats
|
|
1240
1584
|
});
|
|
1241
1585
|
const { txid } = await fill.send();
|
|
@@ -1244,25 +1588,25 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1244
1588
|
async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
1245
1589
|
const { swapAddress, emulator, emulatorPubkey } = opts;
|
|
1246
1590
|
const contractManager = await wallet.getContractManager();
|
|
1247
|
-
const client = await
|
|
1248
|
-
arkade: new
|
|
1249
|
-
indexer: new
|
|
1591
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1592
|
+
arkade: new import_sdk6.RestOperatorProvider(arkServerUrl),
|
|
1593
|
+
indexer: new import_sdk6.RestIndexerProvider(arkServerUrl),
|
|
1250
1594
|
identity: wallet.identity,
|
|
1251
1595
|
contractManager,
|
|
1252
1596
|
...emulator !== void 0 ? {
|
|
1253
|
-
emulator: typeof emulator === "string" ? new
|
|
1597
|
+
emulator: typeof emulator === "string" ? new import_sdk6.RestEmulatorProvider(emulator) : emulator
|
|
1254
1598
|
} : {},
|
|
1255
1599
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
1256
1600
|
});
|
|
1257
|
-
const serverKey = swapAddress ?
|
|
1258
|
-
const
|
|
1259
|
-
const rebuilt =
|
|
1601
|
+
const serverKey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1602
|
+
const binding = swapProgramBinding(offer, serverKey);
|
|
1603
|
+
const rebuilt = compileSwapBinding(binding);
|
|
1260
1604
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1261
1605
|
throw new Error(
|
|
1262
1606
|
"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"
|
|
1263
1607
|
);
|
|
1264
1608
|
}
|
|
1265
|
-
return new
|
|
1609
|
+
return new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1266
1610
|
}
|
|
1267
1611
|
function resolveDeposit(vtxos, sel) {
|
|
1268
1612
|
const { fundingTxid, fundingOutpoint } = sel;
|
|
@@ -1551,7 +1895,7 @@ function assertScript(script, what) {
|
|
|
1551
1895
|
function assertAssetId(assetId, what) {
|
|
1552
1896
|
if (typeof assetId !== "string") throw new Error(`${what} must be an asset id string`);
|
|
1553
1897
|
try {
|
|
1554
|
-
return
|
|
1898
|
+
return import_sdk6.asset.AssetId.fromString(assetId).toString();
|
|
1555
1899
|
} catch {
|
|
1556
1900
|
throw new Error(`${what} is not a valid asset id`);
|
|
1557
1901
|
}
|
|
@@ -1573,22 +1917,18 @@ function assertFillCoin(coin, what) {
|
|
|
1573
1917
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
1574
1918
|
assertAssetEntries(coin.assets, what);
|
|
1575
1919
|
}
|
|
1576
|
-
var import_base5, import_utils2,
|
|
1920
|
+
var import_base5, import_utils2, import_sdk6, 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, offerVtxoScript;
|
|
1577
1921
|
var init_offer = __esm({
|
|
1578
1922
|
"src/offer.ts"() {
|
|
1579
1923
|
"use strict";
|
|
1580
1924
|
import_base5 = require("@scure/base");
|
|
1581
1925
|
import_utils2 = require("@scure/btc-signer/utils.js");
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
init_swap_want_btc_program();
|
|
1926
|
+
import_sdk6 = require("@arkade-os/sdk");
|
|
1927
|
+
init_program();
|
|
1585
1928
|
init_coverage();
|
|
1586
1929
|
init_rfqProfileParts();
|
|
1587
1930
|
init_store();
|
|
1588
|
-
|
|
1589
|
-
wantAsset: import_sdk5.arkade.parseArtifact(swap_want_asset_program_default),
|
|
1590
|
-
wantBtc: import_sdk5.arkade.parseArtifact(swap_want_btc_program_default)
|
|
1591
|
-
};
|
|
1931
|
+
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
1592
1932
|
OFFER_PACKET_TYPE = 3;
|
|
1593
1933
|
FIELDS = {
|
|
1594
1934
|
swapPkScript: { tag: 1, width: 34 },
|
|
@@ -1612,10 +1952,10 @@ var init_offer = __esm({
|
|
|
1612
1952
|
};
|
|
1613
1953
|
OFFER_CONTRACT_LABEL = "Arkade swap offer";
|
|
1614
1954
|
OFFER_CONTRACT_KIND = "asset-swap-offer";
|
|
1615
|
-
derivingClient = (wallet, info, contractManager) =>
|
|
1955
|
+
derivingClient = (wallet, info, contractManager) => import_sdk6.arkade.Arkade.connect({
|
|
1616
1956
|
arkade: { getInfo: async () => info },
|
|
1617
1957
|
identity: wallet.identity,
|
|
1618
|
-
network: (0,
|
|
1958
|
+
network: (0, import_sdk6.networkFromOperatorInfo)(info),
|
|
1619
1959
|
contractManager
|
|
1620
1960
|
});
|
|
1621
1961
|
NoSpendableDepositError = class extends Error {
|
|
@@ -1635,7 +1975,7 @@ var init_offer = __esm({
|
|
|
1635
1975
|
swapPkScript;
|
|
1636
1976
|
name = "OfferCovenantMismatchError";
|
|
1637
1977
|
};
|
|
1638
|
-
ASSET_CARRIER_SATS = BigInt(
|
|
1978
|
+
ASSET_CARRIER_SATS = BigInt(import_sdk6.ASSET_CARRIER_SATS);
|
|
1639
1979
|
amountOfAsset = (assets, assetId) => {
|
|
1640
1980
|
let total = BigInt(0);
|
|
1641
1981
|
for (const a of assets ?? []) {
|
|
@@ -1680,7 +2020,7 @@ function deriveLightningSend(input) {
|
|
|
1680
2020
|
throw new Error("lightning-send quote is missing profile.receiver_pk_script");
|
|
1681
2021
|
}
|
|
1682
2022
|
const contractParams = {
|
|
1683
|
-
solverPubkey: (0,
|
|
2023
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1684
2024
|
refundLocktime: quote.refund_locktime,
|
|
1685
2025
|
operatorPubkey: input.operatorPubkey,
|
|
1686
2026
|
paymentHash: input.paymentHash,
|
|
@@ -1711,7 +2051,7 @@ function deriveLightningSend(input) {
|
|
|
1711
2051
|
async function requestLightningSend(wallet, transport, params) {
|
|
1712
2052
|
const rfqId = params.rfqId ?? newRfqId();
|
|
1713
2053
|
const [secrets, info] = await Promise.all([
|
|
1714
|
-
(0,
|
|
2054
|
+
(0, import_sdk8.provisionRefundKey)(wallet),
|
|
1715
2055
|
wallet.getArkadeInfo({ requireLive: true })
|
|
1716
2056
|
]);
|
|
1717
2057
|
const senderPubkey = secrets.pubkey;
|
|
@@ -1731,16 +2071,16 @@ async function requestLightningSend(wallet, transport, params) {
|
|
|
1731
2071
|
`quote from_amount ${quote.from_amount} is below the invoice amount \u2014 a negative spread is not a quote`
|
|
1732
2072
|
);
|
|
1733
2073
|
}
|
|
1734
|
-
const operatorPubkey = (0,
|
|
1735
|
-
const network = (0,
|
|
2074
|
+
const operatorPubkey = (0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key");
|
|
2075
|
+
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
1736
2076
|
const derived = deriveLightningSend({
|
|
1737
2077
|
quote,
|
|
1738
2078
|
paymentHash: params.invoice.paymentHash,
|
|
1739
2079
|
senderPubkey,
|
|
1740
2080
|
refundPkScript: secrets.pkScript,
|
|
1741
2081
|
operatorPubkey,
|
|
1742
|
-
emulatorPubkey: (0,
|
|
1743
|
-
import_base6.hex.decode((0,
|
|
2082
|
+
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
2083
|
+
import_base6.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, params.emulatorPubkey)),
|
|
1744
2084
|
"emulator signer key"
|
|
1745
2085
|
),
|
|
1746
2086
|
claimDelay,
|
|
@@ -1773,35 +2113,38 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
1773
2113
|
if (!params.wantAsset && !params.offerAsset) {
|
|
1774
2114
|
throw new Error("set at least one of wantAsset or offerAsset; BTC-to-BTC is not a swap");
|
|
1775
2115
|
}
|
|
1776
|
-
const rfqId = params.rfqId ?? newRfqId();
|
|
1777
2116
|
const amountSide = params.amountSide ?? "from";
|
|
1778
2117
|
const receiveAddress = params.receiveAddress;
|
|
1779
2118
|
const [makerAddress, makerPublicKey] = await Promise.all([
|
|
1780
2119
|
wallet.getAddress(),
|
|
1781
2120
|
wallet.identity.xOnlyPublicKey()
|
|
1782
2121
|
]);
|
|
1783
|
-
const ownPkScript =
|
|
2122
|
+
const ownPkScript = import_sdk7.ArkAddress.decode(makerAddress).pkScript;
|
|
1784
2123
|
const info = receiveAddress === void 0 ? void 0 : await wallet.getArkadeInfo({ requireLive: true });
|
|
1785
2124
|
const makerPkScript = info === void 0 ? ownPkScript : resolveReceivePkScript(
|
|
1786
2125
|
receiveAddress,
|
|
1787
2126
|
ownPkScript,
|
|
1788
|
-
(0,
|
|
1789
|
-
(0,
|
|
2127
|
+
(0, import_sdk7.networkFromOperatorInfo)(info).hrp,
|
|
2128
|
+
(0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key")
|
|
1790
2129
|
);
|
|
1791
2130
|
const pair = rfqPair(
|
|
1792
2131
|
params.offerAsset ? arkadeAssetLeg(params.offerAsset) : ARKADE_BTC,
|
|
1793
2132
|
params.wantAsset ? arkadeAssetLeg(params.wantAsset) : ARKADE_BTC
|
|
1794
2133
|
);
|
|
1795
|
-
const
|
|
2134
|
+
const contractVersions = [...params.contractVersions ?? ASSET_SWAP_CONTRACT_VERSIONS];
|
|
2135
|
+
const { quote, rfqId, contractVersion } = await requestVersionedQuote(
|
|
2136
|
+
transport,
|
|
1796
2137
|
arkadeSwapRequest({
|
|
1797
|
-
rfqId,
|
|
2138
|
+
rfqId: params.rfqId ?? newRfqId(),
|
|
1798
2139
|
...params.offerAsset !== void 0 ? { offerAsset: params.offerAsset } : {},
|
|
1799
2140
|
...params.wantAsset !== void 0 ? { wantAsset: params.wantAsset } : {},
|
|
1800
2141
|
amount: params.amount,
|
|
1801
2142
|
amountSide,
|
|
1802
2143
|
makerPkScript,
|
|
1803
|
-
makerPublicKey
|
|
1804
|
-
|
|
2144
|
+
makerPublicKey,
|
|
2145
|
+
contractVersions
|
|
2146
|
+
}),
|
|
2147
|
+
contractVersions
|
|
1805
2148
|
);
|
|
1806
2149
|
if (quote.pair !== pair) {
|
|
1807
2150
|
throw new Error(`solver quoted ${JSON.stringify(quote.pair)}, not the requested ${pair}`);
|
|
@@ -1842,7 +2185,8 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
1842
2185
|
wantAmount: terms.wantAmount,
|
|
1843
2186
|
...terms.wantAsset !== void 0 ? { wantAsset: terms.wantAsset } : {},
|
|
1844
2187
|
...terms.offerAsset !== void 0 ? { offerAsset: terms.offerAsset } : {},
|
|
1845
|
-
...params.emulatorPubkey !== void 0 ? { emulatorPubkey: params.emulatorPubkey } : {}
|
|
2188
|
+
...params.emulatorPubkey !== void 0 ? { emulatorPubkey: params.emulatorPubkey } : {},
|
|
2189
|
+
contractVersion
|
|
1846
2190
|
});
|
|
1847
2191
|
verifyOfferAddress(quote, offer);
|
|
1848
2192
|
const fundAmount = BigInt(quote.from_amount);
|
|
@@ -1876,7 +2220,7 @@ function deriveOnchainSend(input) {
|
|
|
1876
2220
|
"onchain-send"
|
|
1877
2221
|
);
|
|
1878
2222
|
const contractParams = {
|
|
1879
|
-
solverPubkey: (0,
|
|
2223
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1880
2224
|
refundLocktime,
|
|
1881
2225
|
operatorPubkey: input.operatorPubkey,
|
|
1882
2226
|
paymentHash: input.paymentHash,
|
|
@@ -1885,7 +2229,7 @@ function deriveOnchainSend(input) {
|
|
|
1885
2229
|
emulatorPubkey: input.emulatorPubkey,
|
|
1886
2230
|
senderPubkey: input.senderPubkey,
|
|
1887
2231
|
receiverPkScript: solverHex(receiverPkScriptHex, "profile.receiver_pk_script"),
|
|
1888
|
-
refundPkScript:
|
|
2232
|
+
refundPkScript: import_sdk7.ArkAddress.decode(input.refundAddress).pkScript
|
|
1889
2233
|
};
|
|
1890
2234
|
const { script, address } = matchQuotedLockup(
|
|
1891
2235
|
quote,
|
|
@@ -1896,7 +2240,7 @@ function deriveOnchainSend(input) {
|
|
|
1896
2240
|
const htlcParams = {
|
|
1897
2241
|
paymentHash: input.paymentHash,
|
|
1898
2242
|
claimKey: input.payoutPubkey,
|
|
1899
|
-
refundKey: (0,
|
|
2243
|
+
refundKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(htlcPubkey), "solver L1 htlc key"),
|
|
1900
2244
|
refundLocktime: htlcLocktime
|
|
1901
2245
|
};
|
|
1902
2246
|
const htlc = onchainHtlcScript(htlcParams, input.l1Network);
|
|
@@ -1918,7 +2262,7 @@ function deriveOnchainSend(input) {
|
|
|
1918
2262
|
async function requestOnchainSend(wallet, transport, params) {
|
|
1919
2263
|
const rfqId = params.rfqId ?? newRfqId();
|
|
1920
2264
|
const [secrets, info, refundAddress] = await Promise.all([
|
|
1921
|
-
(0,
|
|
2265
|
+
(0, import_sdk8.provisionClaimSecret)(wallet, { preimage: params.preimage }),
|
|
1922
2266
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
1923
2267
|
wallet.getAddress()
|
|
1924
2268
|
]);
|
|
@@ -2091,7 +2435,7 @@ function deriveOnchainReceive(input) {
|
|
|
2091
2435
|
).matched;
|
|
2092
2436
|
const htlcParams = {
|
|
2093
2437
|
paymentHash: input.paymentHash,
|
|
2094
|
-
claimKey: (0,
|
|
2438
|
+
claimKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(claimPubkey), "solver L1 claim key"),
|
|
2095
2439
|
refundKey: input.refundPubkey,
|
|
2096
2440
|
refundLocktime: htlcLocktime
|
|
2097
2441
|
};
|
|
@@ -2165,21 +2509,23 @@ async function requestOnchainReceive(wallet, transport, params) {
|
|
|
2165
2509
|
secrets
|
|
2166
2510
|
};
|
|
2167
2511
|
}
|
|
2168
|
-
var import_base6, import_solver_discovery, import_legacy2,
|
|
2512
|
+
var import_base6, import_solver_discovery, import_legacy2, import_sdk7, import_sdk8, 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_TERMINAL_STATES, 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, httpTransport, relayTransport, SEQUENCE_GRANULARITY_SECONDS, SOLO_REFUND_HEADROOM_SECONDS, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, seconds, suiteVhtlc, quotedSoloRefundDelay, offerTermsFromQuote, verifyOfferAddress, assertArkadeFundable, quoteCarrierSats, l1NetworkFromArk, operatorTerms, onchainSendRequest, lightningReceiveRequest, onchainReceiveRequest, assertQuotedAmount, MIN_CLAIM_WINDOW_SECONDS, verifyReceiveInvoice, assertReceivable, matchReceiveLockup, provisionReceive, quoteReceive;
|
|
2169
2513
|
var init_rfq = __esm({
|
|
2170
2514
|
"src/rfq.ts"() {
|
|
2171
2515
|
"use strict";
|
|
2172
2516
|
import_base6 = require("@scure/base");
|
|
2173
2517
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
2174
2518
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
2175
|
-
|
|
2519
|
+
import_sdk7 = require("@arkade-os/sdk");
|
|
2176
2520
|
init_onchainHtlc();
|
|
2177
2521
|
init_onchainHtlc();
|
|
2178
|
-
|
|
2522
|
+
import_sdk8 = require("@arkade-os/sdk");
|
|
2179
2523
|
init_claimAmountGate();
|
|
2180
2524
|
init_claimPacket();
|
|
2181
2525
|
init_lockupContract();
|
|
2182
2526
|
init_offer();
|
|
2527
|
+
init_program();
|
|
2528
|
+
init_rfq_contract();
|
|
2183
2529
|
solverHex = (value, field) => {
|
|
2184
2530
|
try {
|
|
2185
2531
|
return import_base6.hex.decode(value);
|
|
@@ -2217,6 +2563,7 @@ var init_rfq = __esm({
|
|
|
2217
2563
|
RFQ_TERMINAL_STATES = ["settled", "refused", "expired", "refunded", "stuck"];
|
|
2218
2564
|
RFQ_REFUSAL_ERROR_CODES = [
|
|
2219
2565
|
"amount_side_unsupported",
|
|
2566
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED,
|
|
2220
2567
|
"exact_out_unsupported",
|
|
2221
2568
|
"invalid_amount",
|
|
2222
2569
|
"invalid_payout_address",
|
|
@@ -2332,6 +2679,7 @@ var init_rfq = __esm({
|
|
|
2332
2679
|
pair,
|
|
2333
2680
|
amount_side: input.amountSide ?? "from",
|
|
2334
2681
|
amount: canonicalAssetAmount(input.amount),
|
|
2682
|
+
...input.contractVersions && input.contractVersions.length > 0 ? { [RFQ_CONTRACT_VERSIONS_KEY]: [...input.contractVersions] } : {},
|
|
2335
2683
|
// The solver's `.strict()` schema refuses any undeclared key as `unsupported_payload`.
|
|
2336
2684
|
profile: {
|
|
2337
2685
|
maker_pk_script: normalizeMakerPkScript(input.makerPkScript),
|
|
@@ -2519,6 +2867,34 @@ var init_rfq = __esm({
|
|
|
2519
2867
|
}
|
|
2520
2868
|
return payload;
|
|
2521
2869
|
};
|
|
2870
|
+
requestVersionedQuote = async (transport, request, advertised) => {
|
|
2871
|
+
if (advertised.length === 0) {
|
|
2872
|
+
throw new Error("contractVersions is empty: advertise at least one contract version");
|
|
2873
|
+
}
|
|
2874
|
+
let sent = request;
|
|
2875
|
+
let quote;
|
|
2876
|
+
try {
|
|
2877
|
+
quote = await transport.requestQuote(request);
|
|
2878
|
+
} catch (error) {
|
|
2879
|
+
if (!(error instanceof SwapRefusal) || error.reason !== "unsupported_payload" || error.errorCode !== void 0 || !advertised.includes(ASSET_SWAP_BASELINE)) {
|
|
2880
|
+
throw error;
|
|
2881
|
+
}
|
|
2882
|
+
const { [RFQ_CONTRACT_VERSIONS_KEY]: _, ...baseline } = request;
|
|
2883
|
+
sent = { ...baseline, rfq_id: newRfqId() };
|
|
2884
|
+
quote = await transport.requestQuote(sent);
|
|
2885
|
+
}
|
|
2886
|
+
const selected = quote[RFQ_CONTRACT_VERSION_KEY];
|
|
2887
|
+
if (sent !== request && selected !== void 0) {
|
|
2888
|
+
throw new Error(`solver chose contract version ${selected}, but none was advertised`);
|
|
2889
|
+
}
|
|
2890
|
+
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2891
|
+
if (!advertised.includes(version)) {
|
|
2892
|
+
throw new Error(
|
|
2893
|
+
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
2897
|
+
};
|
|
2522
2898
|
pairOf = (payload) => typeof payload.pair === "string" ? payload.pair : void 0;
|
|
2523
2899
|
httpTransport = (baseUrl, options = {}) => {
|
|
2524
2900
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
@@ -2557,7 +2933,7 @@ var init_rfq = __esm({
|
|
|
2557
2933
|
};
|
|
2558
2934
|
relayTransport = (relayUrl, options) => {
|
|
2559
2935
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
2560
|
-
(0,
|
|
2936
|
+
(0, import_sdk7.assertTimerMs)("timeoutMs", timeoutMs);
|
|
2561
2937
|
const Ctor = options.WebSocketCtor ?? WebSocket;
|
|
2562
2938
|
const pending = /* @__PURE__ */ new Map();
|
|
2563
2939
|
let sequence = 0;
|
|
@@ -2661,7 +3037,7 @@ var init_rfq = __esm({
|
|
|
2661
3037
|
type: "seconds",
|
|
2662
3038
|
value: BigInt(value)
|
|
2663
3039
|
});
|
|
2664
|
-
suiteVhtlc = (params, roles) => new
|
|
3040
|
+
suiteVhtlc = (params, roles) => new import_sdk7.VHTLC.ScriptV2({
|
|
2665
3041
|
sender: roles.sender,
|
|
2666
3042
|
receiver: roles.receiver,
|
|
2667
3043
|
server: params.operatorPubkey,
|
|
@@ -2731,11 +3107,11 @@ var init_rfq = __esm({
|
|
|
2731
3107
|
};
|
|
2732
3108
|
l1NetworkFromArk = (network) => network === "bitcoin" ? "bitcoin" : network === "regtest" ? "regtest" : "testnet";
|
|
2733
3109
|
operatorTerms = (info, emulatorPubkey) => {
|
|
2734
|
-
const network = (0,
|
|
3110
|
+
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
2735
3111
|
return {
|
|
2736
|
-
operatorPubkey: (0,
|
|
2737
|
-
emulatorPubkey: (0,
|
|
2738
|
-
import_base6.hex.decode((0,
|
|
3112
|
+
operatorPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key"),
|
|
3113
|
+
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
3114
|
+
import_base6.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, emulatorPubkey)),
|
|
2739
3115
|
"emulator signer key"
|
|
2740
3116
|
),
|
|
2741
3117
|
claimDelay: unilateralClaimDelay(Number(info.unilateralExitDelay)),
|
|
@@ -2835,6 +3211,9 @@ var init_rfq = __esm({
|
|
|
2835
3211
|
if (input.now >= input.payDeadline) {
|
|
2836
3212
|
throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
|
|
2837
3213
|
}
|
|
3214
|
+
if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
|
|
3215
|
+
throw gateError("non_positive_amount", "quote carries a non-positive amount");
|
|
3216
|
+
}
|
|
2838
3217
|
if (input.quote.refund_locktime === void 0) {
|
|
2839
3218
|
throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
|
|
2840
3219
|
}
|
|
@@ -2854,7 +3233,7 @@ var init_rfq = __esm({
|
|
|
2854
3233
|
};
|
|
2855
3234
|
matchReceiveLockup = (input, refundLocktime, solverRefundPkScriptHex) => {
|
|
2856
3235
|
const contractParams = {
|
|
2857
|
-
solverPubkey: (0,
|
|
3236
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(input.quote.solver_pubkey), "solver key"),
|
|
2858
3237
|
refundLocktime,
|
|
2859
3238
|
operatorPubkey: input.operatorPubkey,
|
|
2860
3239
|
paymentHash: input.paymentHash,
|
|
@@ -2862,7 +3241,7 @@ var init_rfq = __esm({
|
|
|
2862
3241
|
emulatorPubkey: input.emulatorPubkey,
|
|
2863
3242
|
solverRefundPkScript: solverHex(solverRefundPkScriptHex, "profile.solver_refund_pk_script"),
|
|
2864
3243
|
payoutPubkey: input.payoutPubkey,
|
|
2865
|
-
payoutPkScript:
|
|
3244
|
+
payoutPkScript: import_sdk7.ArkAddress.decode(input.payoutAddress).pkScript
|
|
2866
3245
|
};
|
|
2867
3246
|
const matched = matchQuotedLockup(
|
|
2868
3247
|
input.quote,
|
|
@@ -2874,7 +3253,7 @@ var init_rfq = __esm({
|
|
|
2874
3253
|
};
|
|
2875
3254
|
provisionReceive = async (wallet, params, persistBefore) => {
|
|
2876
3255
|
const [secrets, info, payoutAddress] = await Promise.all([
|
|
2877
|
-
(0,
|
|
3256
|
+
(0, import_sdk8.provisionClaimSecret)(wallet),
|
|
2878
3257
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
2879
3258
|
wallet.getAddress()
|
|
2880
3259
|
]);
|
|
@@ -3057,14 +3436,14 @@ __export(nostr_exports, {
|
|
|
3057
3436
|
nostrRfqTransport: () => nostrRfqTransport,
|
|
3058
3437
|
sharedNostrPool: () => sharedNostrPool
|
|
3059
3438
|
});
|
|
3060
|
-
var import_solver_discovery4,
|
|
3439
|
+
var import_solver_discovery4, import_sdk18, import_nostr_tools2, RFQ_DIRECTED_KIND, DEFAULT_TIMEOUT_MS, CONNECTION_FAILURE, CARD_FETCH_TIMEOUT_MS, RelayUnavailable, TransportClosed, closeReasons, nostrRfqTransport, isNewer, nostrCardFetcher;
|
|
3061
3440
|
var init_nostr = __esm({
|
|
3062
3441
|
"src/nostr.ts"() {
|
|
3063
3442
|
"use strict";
|
|
3064
3443
|
import_solver_discovery4 = require("@arkade-os/solver-discovery");
|
|
3065
3444
|
init_rfq();
|
|
3066
3445
|
init_nostrPool();
|
|
3067
|
-
|
|
3446
|
+
import_sdk18 = require("@arkade-os/sdk");
|
|
3068
3447
|
import_nostr_tools2 = require("nostr-tools");
|
|
3069
3448
|
init_nostrPool();
|
|
3070
3449
|
RFQ_DIRECTED_KIND = 24859;
|
|
@@ -3091,7 +3470,7 @@ var init_nostr = __esm({
|
|
|
3091
3470
|
return url ? `${url}: ${reason ?? "closed"}` : reason ?? "closed";
|
|
3092
3471
|
});
|
|
3093
3472
|
nostrRfqTransport = (options) => {
|
|
3094
|
-
(0,
|
|
3473
|
+
(0, import_sdk18.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
3095
3474
|
const relays = options.relays;
|
|
3096
3475
|
const solverPubkey = options.solverPubkey;
|
|
3097
3476
|
const secretKey = options.secretKey ?? (0, import_nostr_tools2.generateSecretKey)();
|
|
@@ -3203,7 +3582,7 @@ var init_nostr = __esm({
|
|
|
3203
3582
|
};
|
|
3204
3583
|
isNewer = (event, held) => !held || event.created_at > held.created_at || event.created_at === held.created_at && event.id < held.id;
|
|
3205
3584
|
nostrCardFetcher = (options = {}) => {
|
|
3206
|
-
(0,
|
|
3585
|
+
(0, import_sdk18.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
3207
3586
|
if (options.timeoutMs === 0) throw new Error("timeoutMs must be positive");
|
|
3208
3587
|
const seen = /* @__PURE__ */ new Map();
|
|
3209
3588
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -3285,6 +3664,10 @@ var protocol_exports = {};
|
|
|
3285
3664
|
__export(protocol_exports, {
|
|
3286
3665
|
ARKADE_BTC: () => ARKADE_BTC,
|
|
3287
3666
|
ASSET_CARRIER_SATS: () => ASSET_CARRIER_SATS,
|
|
3667
|
+
ASSET_SWAP_BASELINE: () => ASSET_SWAP_BASELINE,
|
|
3668
|
+
ASSET_SWAP_CONTRACT_VERSIONS: () => ASSET_SWAP_CONTRACT_VERSIONS,
|
|
3669
|
+
ASSET_SWAP_V2: () => ASSET_SWAP_V2,
|
|
3670
|
+
ASSET_SWAP_V3: () => ASSET_SWAP_V3,
|
|
3288
3671
|
AddressMismatch: () => AddressMismatch,
|
|
3289
3672
|
BTC_ASSET_ID: () => BTC_ASSET_ID,
|
|
3290
3673
|
CROSS_ASSET_RAIL: () => CROSS_ASSET_RAIL,
|
|
@@ -3325,6 +3708,7 @@ __export(protocol_exports, {
|
|
|
3325
3708
|
arkadeRefunder: () => arkadeRefunder,
|
|
3326
3709
|
arkadeSwapRequest: () => arkadeSwapRequest,
|
|
3327
3710
|
assertArkadeFundable: () => assertArkadeFundable,
|
|
3711
|
+
assetSwapContractVersion: () => assetSwapContractVersion,
|
|
3328
3712
|
awaitOnchainFill: () => awaitOnchainFill,
|
|
3329
3713
|
awaitRfqResolution: () => awaitRfqResolution,
|
|
3330
3714
|
buildHtlcClaim: () => buildHtlcClaim,
|
|
@@ -3418,18 +3802,18 @@ __export(protocol_exports, {
|
|
|
3418
3802
|
module.exports = __toCommonJS(protocol_exports);
|
|
3419
3803
|
|
|
3420
3804
|
// src/activity.ts
|
|
3421
|
-
var
|
|
3805
|
+
var import_sdk16 = require("@arkade-os/sdk");
|
|
3422
3806
|
var import_base11 = require("@scure/base");
|
|
3423
3807
|
|
|
3424
3808
|
// src/swapManager.ts
|
|
3425
3809
|
var import_base10 = require("@scure/base");
|
|
3426
|
-
var
|
|
3810
|
+
var import_sdk12 = require("@arkade-os/sdk");
|
|
3427
3811
|
init_onchainHtlc();
|
|
3428
3812
|
|
|
3429
3813
|
// src/refund.ts
|
|
3430
3814
|
var import_base7 = require("@scure/base");
|
|
3431
3815
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
3432
|
-
var
|
|
3816
|
+
var import_sdk9 = require("@arkade-os/sdk");
|
|
3433
3817
|
init_onchainHtlc();
|
|
3434
3818
|
init_rfq();
|
|
3435
3819
|
var isRfqTerminal = (state) => RFQ_TERMINAL_STATES.includes(state);
|
|
@@ -3470,7 +3854,7 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3470
3854
|
const out = [];
|
|
3471
3855
|
for (const vtxo of row?.vtxos ?? []) {
|
|
3472
3856
|
if (vtxo.isUnrolled) continue;
|
|
3473
|
-
if ((0,
|
|
3857
|
+
if ((0, import_sdk9.isVtxoSpent)(vtxo)) continue;
|
|
3474
3858
|
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
3475
3859
|
if (seen.has(key)) continue;
|
|
3476
3860
|
seen.add(key);
|
|
@@ -3486,17 +3870,17 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3486
3870
|
}
|
|
3487
3871
|
var hashesTo = (candidate, paymentHash) => import_base7.hex.encode((0, import_sha24.sha256)(candidate)) === paymentHash;
|
|
3488
3872
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
3489
|
-
...(0,
|
|
3873
|
+
...(0, import_sdk9.getArkPsbtFields)(tx, inputIndex, import_sdk9.ConditionWitness).flat(),
|
|
3490
3874
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
3491
3875
|
];
|
|
3492
3876
|
var refundLeafScript = (tx, inputIndex) => {
|
|
3493
3877
|
const input = tx.getInput(inputIndex);
|
|
3494
3878
|
const witness = input.finalScriptWitness;
|
|
3495
3879
|
const leaves = input.tapLeafScript ?? [];
|
|
3496
|
-
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0,
|
|
3880
|
+
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0, import_sdk9.scriptFromTapLeafScript)(leaves[0]) : void 0;
|
|
3497
3881
|
if (!script) return void 0;
|
|
3498
3882
|
try {
|
|
3499
|
-
const { type } = (0,
|
|
3883
|
+
const { type } = (0, import_sdk9.decodeTapscript)(script);
|
|
3500
3884
|
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
|
|
3501
3885
|
} catch {
|
|
3502
3886
|
return void 0;
|
|
@@ -3506,7 +3890,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3506
3890
|
const { vtxos } = await indexer.getVtxos({ scripts: [import_base7.hex.encode(input.swapPkScript)] });
|
|
3507
3891
|
const all = vtxos ?? [];
|
|
3508
3892
|
if (all.length === 0) return { fate: "unknown" };
|
|
3509
|
-
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0,
|
|
3893
|
+
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0, import_sdk9.isVtxoSpent)(vtxo));
|
|
3510
3894
|
if (exited.length > 0) {
|
|
3511
3895
|
return {
|
|
3512
3896
|
fate: "exited",
|
|
@@ -3518,7 +3902,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3518
3902
|
let sweptLeft = false;
|
|
3519
3903
|
let live = false;
|
|
3520
3904
|
for (const vtxo of all) {
|
|
3521
|
-
if (!(0,
|
|
3905
|
+
if (!(0, import_sdk9.isVtxoSpent)(vtxo)) {
|
|
3522
3906
|
if (input.receiver && vtxo.isSwept) sweptLeft = true;
|
|
3523
3907
|
else live = true;
|
|
3524
3908
|
continue;
|
|
@@ -3545,7 +3929,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3545
3929
|
for (const raw of txs) {
|
|
3546
3930
|
let tx;
|
|
3547
3931
|
try {
|
|
3548
|
-
tx =
|
|
3932
|
+
tx = import_sdk9.Transaction.fromPSBT(import_base7.base64.decode(raw));
|
|
3549
3933
|
} catch {
|
|
3550
3934
|
continue;
|
|
3551
3935
|
}
|
|
@@ -3595,10 +3979,10 @@ var assertNoneSwept = (vtxos, contract) => {
|
|
|
3595
3979
|
};
|
|
3596
3980
|
var operatorUnrollScript = async (operator, network) => {
|
|
3597
3981
|
const info = await operator.getInfo();
|
|
3598
|
-
return (0,
|
|
3982
|
+
return (0, import_sdk9.assertValidServerUnrollScript)(
|
|
3599
3983
|
info.checkpointTapscript,
|
|
3600
|
-
network ?? (0,
|
|
3601
|
-
(0,
|
|
3984
|
+
network ?? (0, import_sdk9.networkFromOperatorInfo)(info),
|
|
3985
|
+
(0, import_sdk9.toXOnly)(import_base7.hex.decode(info.forfeitPubkey), "forfeit key")
|
|
3602
3986
|
);
|
|
3603
3987
|
};
|
|
3604
3988
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
@@ -3618,7 +4002,7 @@ var lockupAssetOutputs = (vtxos) => {
|
|
|
3618
4002
|
address: "",
|
|
3619
4003
|
assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
|
|
3620
4004
|
};
|
|
3621
|
-
return [
|
|
4005
|
+
return [import_sdk9.Extension.create([(0, import_sdk9.createAssetPacket)(inputs, [receiver])]).txOut()];
|
|
3622
4006
|
};
|
|
3623
4007
|
var lockupInputs = (vtxos, contract, leaf) => {
|
|
3624
4008
|
const tapTree = contract.encode();
|
|
@@ -3643,7 +4027,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
3643
4027
|
const leaf = input.contract.refundWithoutReceiver();
|
|
3644
4028
|
const vtxos = boundedLockupSpend(input.vtxos);
|
|
3645
4029
|
const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
3646
|
-
const txid = await (0,
|
|
4030
|
+
const txid = await (0, import_sdk9.signAndSubmitOffchainTx)({
|
|
3647
4031
|
identity: input.sender,
|
|
3648
4032
|
provider: operator,
|
|
3649
4033
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
@@ -3665,7 +4049,7 @@ init_lockupContract();
|
|
|
3665
4049
|
init_repository();
|
|
3666
4050
|
|
|
3667
4051
|
// src/rfqRecord.ts
|
|
3668
|
-
var
|
|
4052
|
+
var import_sdk10 = require("@arkade-os/sdk");
|
|
3669
4053
|
var import_base9 = require("@scure/base");
|
|
3670
4054
|
|
|
3671
4055
|
// src/rfqSwapState.ts
|
|
@@ -3915,7 +4299,7 @@ function assertSameSwap(origin, swap) {
|
|
|
3915
4299
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
3916
4300
|
);
|
|
3917
4301
|
}
|
|
3918
|
-
const funded = import_base9.hex.encode(
|
|
4302
|
+
const funded = import_base9.hex.encode(import_sdk10.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
3919
4303
|
const watched = import_base9.hex.encode(swap.lockupPkScript);
|
|
3920
4304
|
if (funded !== watched) {
|
|
3921
4305
|
throw new Error(
|
|
@@ -3962,8 +4346,8 @@ function rfqSwapOriginOf(record) {
|
|
|
3962
4346
|
};
|
|
3963
4347
|
}
|
|
3964
4348
|
function lockupScript(params, lockupAddress) {
|
|
3965
|
-
const script =
|
|
3966
|
-
const funded =
|
|
4349
|
+
const script = import_sdk10.VHTLCV2ContractHandler.createScript(params);
|
|
4350
|
+
const funded = import_sdk10.ArkAddress.decode(lockupAddress).pkScript;
|
|
3967
4351
|
if (import_base9.hex.encode(funded) !== import_base9.hex.encode(script.pkScript)) {
|
|
3968
4352
|
throw new Error(
|
|
3969
4353
|
`rfq swap covenant params derive ${import_base9.hex.encode(script.pkScript)}, but the record's lockup address holds ${import_base9.hex.encode(funded)} \u2014 these params are not this swap's`
|
|
@@ -3999,7 +4383,7 @@ function shouldRetainRfqSwap(record, now) {
|
|
|
3999
4383
|
}
|
|
4000
4384
|
|
|
4001
4385
|
// src/refundBlocked.ts
|
|
4002
|
-
var
|
|
4386
|
+
var import_sdk11 = require("@arkade-os/sdk");
|
|
4003
4387
|
var RefundNotLocallyPossibleError = class extends Error {
|
|
4004
4388
|
constructor(reason, message, options) {
|
|
4005
4389
|
super(message, options);
|
|
@@ -4016,16 +4400,16 @@ async function senderIdentityForSwapRecord(wallet, record) {
|
|
|
4016
4400
|
);
|
|
4017
4401
|
}
|
|
4018
4402
|
try {
|
|
4019
|
-
return await (0,
|
|
4403
|
+
return await (0, import_sdk11.contractSigner)(wallet, record.signingDescriptor);
|
|
4020
4404
|
} catch (cause) {
|
|
4021
|
-
if (cause instanceof
|
|
4405
|
+
if (cause instanceof import_sdk11.WalletCannotSignError) {
|
|
4022
4406
|
throw new RefundNotLocallyPossibleError(
|
|
4023
4407
|
"unsignable-wallet",
|
|
4024
4408
|
`this wallet holds ${record.signingDescriptor} but cannot sign with it; attach its signer`,
|
|
4025
4409
|
{ cause }
|
|
4026
4410
|
);
|
|
4027
4411
|
}
|
|
4028
|
-
if (cause instanceof
|
|
4412
|
+
if (cause instanceof import_sdk11.ForeignDescriptorError) {
|
|
4029
4413
|
throw new RefundNotLocallyPossibleError(
|
|
4030
4414
|
"foreign-descriptor",
|
|
4031
4415
|
`this wallet cannot derive ${record.signingDescriptor}; the swap was created on another wallet`,
|
|
@@ -4163,7 +4547,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4163
4547
|
timer = null;
|
|
4164
4548
|
running = false;
|
|
4165
4549
|
constructor(deps, config = {}) {
|
|
4166
|
-
(0,
|
|
4550
|
+
(0, import_sdk12.assertTimerMs)("pollIntervalMs", config.pollIntervalMs);
|
|
4167
4551
|
this.deps = deps;
|
|
4168
4552
|
this.config = {
|
|
4169
4553
|
enableAutoActions: config.enableAutoActions ?? true,
|
|
@@ -4547,7 +4931,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4547
4931
|
});
|
|
4548
4932
|
return;
|
|
4549
4933
|
}
|
|
4550
|
-
if (!(0,
|
|
4934
|
+
if (!(0, import_sdk12.isContractVtxoEvent)(event)) return;
|
|
4551
4935
|
const swap = this.byLockupScript.get(event.contractScript);
|
|
4552
4936
|
if (!swap) return;
|
|
4553
4937
|
void this.pollSwap(swap).catch(() => {
|
|
@@ -4784,10 +5168,10 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4784
5168
|
return;
|
|
4785
5169
|
}
|
|
4786
5170
|
if (!partiallyClaimed) {
|
|
4787
|
-
if (!Number.
|
|
5171
|
+
if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
|
|
4788
5172
|
return this.block(
|
|
4789
5173
|
swap,
|
|
4790
|
-
`expectedAmount is not a
|
|
5174
|
+
`expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
|
|
4791
5175
|
);
|
|
4792
5176
|
}
|
|
4793
5177
|
const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
@@ -4817,8 +5201,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4817
5201
|
this.setState(swap, "claimed");
|
|
4818
5202
|
this.emitAction(swap, "claimLockup");
|
|
4819
5203
|
} catch (error) {
|
|
4820
|
-
const ark = (0,
|
|
4821
|
-
if ((0,
|
|
5204
|
+
const ark = (0, import_sdk12.isArkError)(error) ? error : (0, import_sdk12.maybeArkError)(error);
|
|
5205
|
+
if ((0, import_sdk12.isArkError)(ark, import_sdk12.ArkErrorName.VTXO_ALREADY_SPENT)) {
|
|
4822
5206
|
if (swap.claimFailure !== void 0) {
|
|
4823
5207
|
delete swap.claimFailure;
|
|
4824
5208
|
this.touch(swap);
|
|
@@ -5048,6 +5432,9 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
5048
5432
|
utxo,
|
|
5049
5433
|
bump ? { bump } : void 0
|
|
5050
5434
|
);
|
|
5435
|
+
if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
|
|
5436
|
+
swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
|
|
5437
|
+
}
|
|
5051
5438
|
swap.claimTxid = txid;
|
|
5052
5439
|
swap.claimBroadcastAt = this.config.now();
|
|
5053
5440
|
delete swap.claimConfirmed;
|
|
@@ -5109,8 +5496,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
5109
5496
|
this.refundRefused.add(swap.rfqId);
|
|
5110
5497
|
return this.block(swap, error.message);
|
|
5111
5498
|
}
|
|
5112
|
-
const ark = (0,
|
|
5113
|
-
if ((0,
|
|
5499
|
+
const ark = (0, import_sdk12.isArkError)(error) ? error : (0, import_sdk12.maybeArkError)(error);
|
|
5500
|
+
if ((0, import_sdk12.isArkError)(ark, import_sdk12.ArkErrorName.VTXO_ALREADY_SPENT)) return;
|
|
5114
5501
|
this.emitFailed(swap, error);
|
|
5115
5502
|
if (now >= swap.refundLocktime + REFUND_MTP_LAG_SECONDS) {
|
|
5116
5503
|
swap.failure = errorMessage(error);
|
|
@@ -5302,7 +5689,7 @@ var errorMessage = (error) => error instanceof Error ? error.message : String(er
|
|
|
5302
5689
|
var outpointKey = (vtxo) => `${vtxo.txid}:${vtxo.vout}`;
|
|
5303
5690
|
|
|
5304
5691
|
// src/client/assetPayment.ts
|
|
5305
|
-
var
|
|
5692
|
+
var import_sdk13 = require("@arkade-os/sdk");
|
|
5306
5693
|
var import_solver_discovery2 = require("@arkade-os/solver-discovery");
|
|
5307
5694
|
var MAX_SATS = 2100000000000000n;
|
|
5308
5695
|
var MAX_BITCOIN_SATS_DECIMAL = MAX_SATS.toString();
|
|
@@ -5312,7 +5699,7 @@ var import_solver_discovery3 = require("@arkade-os/solver-discovery");
|
|
|
5312
5699
|
var ATOMIC_CEILING = 10n ** 30n;
|
|
5313
5700
|
|
|
5314
5701
|
// src/client/corridors/lightning.ts
|
|
5315
|
-
var
|
|
5702
|
+
var import_sdk14 = require("@arkade-os/sdk");
|
|
5316
5703
|
var INVOICE_HRPS = [
|
|
5317
5704
|
["lnbcrt", ["regtest"]],
|
|
5318
5705
|
["lntbs", ["signet", "mutinynet"]],
|
|
@@ -5342,7 +5729,7 @@ var lightningCorridor = Object.assign(
|
|
|
5342
5729
|
deps,
|
|
5343
5730
|
drive: LIGHTNING_DRIVE,
|
|
5344
5731
|
matches(raw) {
|
|
5345
|
-
const invoice = (0,
|
|
5732
|
+
const invoice = (0, import_sdk14.invoiceTarget)(raw);
|
|
5346
5733
|
if (invoice === void 0) return void 0;
|
|
5347
5734
|
const networks = networksOfInvoiceHrp(invoice);
|
|
5348
5735
|
if (networks === void 0) {
|
|
@@ -5388,11 +5775,11 @@ var lightningCorridor = Object.assign(
|
|
|
5388
5775
|
};
|
|
5389
5776
|
}
|
|
5390
5777
|
}),
|
|
5391
|
-
{ target:
|
|
5778
|
+
{ target: import_sdk14.invoiceTarget }
|
|
5392
5779
|
);
|
|
5393
5780
|
|
|
5394
5781
|
// src/client/corridors/onchain.ts
|
|
5395
|
-
var
|
|
5782
|
+
var import_sdk15 = require("@arkade-os/sdk");
|
|
5396
5783
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
5397
5784
|
init_onchainHtlc();
|
|
5398
5785
|
init_rfq();
|
|
@@ -5422,14 +5809,14 @@ var onchainCorridor = Object.assign(
|
|
|
5422
5809
|
deps,
|
|
5423
5810
|
drive: ONCHAIN_DRIVE,
|
|
5424
5811
|
matches(raw) {
|
|
5425
|
-
const target = (0,
|
|
5812
|
+
const target = (0, import_sdk15.btcTarget)(raw);
|
|
5426
5813
|
if (target === void 0) return void 0;
|
|
5427
5814
|
try {
|
|
5428
5815
|
btc2.Address(L1_NETWORKS[l1]).decode(target);
|
|
5429
5816
|
} catch {
|
|
5430
5817
|
return { refused: `this is not a ${l1} address` };
|
|
5431
5818
|
}
|
|
5432
|
-
const amount =
|
|
5819
|
+
const amount = import_sdk15.BIP21.amountSats(raw);
|
|
5433
5820
|
return {
|
|
5434
5821
|
claimed: {
|
|
5435
5822
|
kind: "address",
|
|
@@ -5440,7 +5827,7 @@ var onchainCorridor = Object.assign(
|
|
|
5440
5827
|
}
|
|
5441
5828
|
};
|
|
5442
5829
|
},
|
|
5443
|
-
{ target:
|
|
5830
|
+
{ target: import_sdk15.btcTarget }
|
|
5444
5831
|
);
|
|
5445
5832
|
|
|
5446
5833
|
// src/client/outcome.ts
|
|
@@ -5572,7 +5959,7 @@ async function activityInputOf(stored, indexer) {
|
|
|
5572
5959
|
async function lockupTxids(indexer, record, wantFunding) {
|
|
5573
5960
|
let script;
|
|
5574
5961
|
try {
|
|
5575
|
-
script = import_base11.hex.encode(
|
|
5962
|
+
script = import_base11.hex.encode(import_sdk16.ArkAddress.decode(record.lockupAddress).pkScript);
|
|
5576
5963
|
} catch {
|
|
5577
5964
|
return [];
|
|
5578
5965
|
}
|
|
@@ -5679,7 +6066,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
5679
6066
|
|
|
5680
6067
|
// src/claim.ts
|
|
5681
6068
|
var import_base13 = require("@scure/base");
|
|
5682
|
-
var
|
|
6069
|
+
var import_sdk17 = require("@arkade-os/sdk");
|
|
5683
6070
|
init_onchainHtlc();
|
|
5684
6071
|
var LockupAmountMismatchError = class extends Error {
|
|
5685
6072
|
name = "LockupAmountMismatchError";
|
|
@@ -5706,6 +6093,9 @@ async function pushClaim(operator, input) {
|
|
|
5706
6093
|
assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
|
|
5707
6094
|
if (!input.partiallyClaimed) {
|
|
5708
6095
|
assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
|
|
6096
|
+
if (input.expectedAmount <= 0) {
|
|
6097
|
+
throw gateError("invalid_gate_input", "expectedAmount is not positive");
|
|
6098
|
+
}
|
|
5709
6099
|
if (funded < input.expectedAmount) {
|
|
5710
6100
|
throw new LockupAmountMismatchError(input.expectedAmount, funded);
|
|
5711
6101
|
}
|
|
@@ -5715,8 +6105,8 @@ async function pushClaim(operator, input) {
|
|
|
5715
6105
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
5716
6106
|
const serverUnrollScript = await operatorUnrollScript(operator, input.network);
|
|
5717
6107
|
const leaf = input.contract.claim();
|
|
5718
|
-
const txid = await (0,
|
|
5719
|
-
identity: (0,
|
|
6108
|
+
const txid = await (0, import_sdk17.signAndSubmitOffchainTx)({
|
|
6109
|
+
identity: (0, import_sdk17.claimWithPreimageIdentity)(input.receiver, input.preimage),
|
|
5720
6110
|
provider: operator,
|
|
5721
6111
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
5722
6112
|
// One aggregate output: this leaf inspects nothing about the output set.
|
|
@@ -5737,7 +6127,7 @@ init_lockupContract();
|
|
|
5737
6127
|
|
|
5738
6128
|
// src/markets.ts
|
|
5739
6129
|
var import_solver_discovery5 = require("@arkade-os/solver-discovery");
|
|
5740
|
-
var
|
|
6130
|
+
var import_sdk19 = require("@arkade-os/sdk");
|
|
5741
6131
|
|
|
5742
6132
|
// src/marketShape.ts
|
|
5743
6133
|
var MARKET_CORRIDORS = ["arkade", "bolt11", "bitcoin", "eip155"];
|
|
@@ -5772,7 +6162,7 @@ var marketCorridor = (market, side) => {
|
|
|
5772
6162
|
init_store();
|
|
5773
6163
|
var QUOTE_OPTIONS = { safetyBps: 0 };
|
|
5774
6164
|
var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
|
|
5775
|
-
(0,
|
|
6165
|
+
(0, import_sdk19.assertNonNegativeMs)("ttlMs", ttlMs);
|
|
5776
6166
|
const cache = /* @__PURE__ */ new Map();
|
|
5777
6167
|
const inflight = /* @__PURE__ */ new Map();
|
|
5778
6168
|
return async (input, init) => {
|
|
@@ -5950,7 +6340,7 @@ var discoverMarkets = async (options) => {
|
|
|
5950
6340
|
return markets;
|
|
5951
6341
|
};
|
|
5952
6342
|
var watchMarkets = (options, onMarkets) => {
|
|
5953
|
-
(0,
|
|
6343
|
+
(0, import_sdk19.assertTimerMs)("intervalMs", options.intervalMs);
|
|
5954
6344
|
if (options.intervalMs === 0) throw new Error("intervalMs must be positive");
|
|
5955
6345
|
let digest;
|
|
5956
6346
|
let reading = false;
|
|
@@ -6028,23 +6418,24 @@ var validatePlan = (plan, giveBalance, dust) => {
|
|
|
6028
6418
|
const receiveIsBtc = plan.receive.asset.id === BTC_ASSET_ID;
|
|
6029
6419
|
if (depositIsBtc || receiveIsBtc) {
|
|
6030
6420
|
const btcSide = depositIsBtc ? plan.deposit.atomic : plan.receive.atomic;
|
|
6031
|
-
if ((0,
|
|
6421
|
+
if ((0, import_sdk19.isSubdust)(btcSide, dust)) return "below-dust";
|
|
6032
6422
|
}
|
|
6033
6423
|
return void 0;
|
|
6034
6424
|
};
|
|
6035
6425
|
|
|
6036
6426
|
// src/protocol.ts
|
|
6037
6427
|
init_offer();
|
|
6428
|
+
init_program();
|
|
6038
6429
|
init_onchainHtlc();
|
|
6039
6430
|
|
|
6040
6431
|
// src/payment/crossAsset.ts
|
|
6041
|
-
var
|
|
6432
|
+
var import_sdk20 = require("@arkade-os/sdk");
|
|
6042
6433
|
init_offer();
|
|
6043
6434
|
init_store();
|
|
6044
6435
|
var CROSS_ASSET_RAIL = "cross-asset";
|
|
6045
6436
|
var parseAssetId = (assetId) => {
|
|
6046
6437
|
try {
|
|
6047
|
-
return
|
|
6438
|
+
return import_sdk20.asset.AssetId.fromString(assetId);
|
|
6048
6439
|
} catch {
|
|
6049
6440
|
return void 0;
|
|
6050
6441
|
}
|
|
@@ -6062,9 +6453,9 @@ function crossAssetRail(deps) {
|
|
|
6062
6453
|
};
|
|
6063
6454
|
return {
|
|
6064
6455
|
id: CROSS_ASSET_RAIL,
|
|
6065
|
-
match: (req) => (0,
|
|
6456
|
+
match: (req) => (0, import_sdk20.arkTarget)(req.raw) !== void 0,
|
|
6066
6457
|
available: async (req) => {
|
|
6067
|
-
const assets = (0,
|
|
6458
|
+
const assets = (0, import_sdk20.assetsOf)(req);
|
|
6068
6459
|
if (assets.length !== 1) return false;
|
|
6069
6460
|
const [asset4] = assets;
|
|
6070
6461
|
if (asset4.assetId === BTC_ASSET_ID) return false;
|
|
@@ -6074,8 +6465,8 @@ function crossAssetRail(deps) {
|
|
|
6074
6465
|
return planned !== void 0 && planned.error === void 0;
|
|
6075
6466
|
},
|
|
6076
6467
|
quote: async (req, ctx) => {
|
|
6077
|
-
const payTo = (0,
|
|
6078
|
-
const asset4 = (0,
|
|
6468
|
+
const payTo = (0, import_sdk20.arkTarget)(req.raw);
|
|
6469
|
+
const asset4 = (0, import_sdk20.resolveAssetAmount)(CROSS_ASSET_RAIL, req);
|
|
6079
6470
|
const wantAsset = parseAssetId(asset4.assetId);
|
|
6080
6471
|
if (!wantAsset) {
|
|
6081
6472
|
throw new Error(
|
|
@@ -6098,7 +6489,7 @@ function crossAssetRail(deps) {
|
|
|
6098
6489
|
);
|
|
6099
6490
|
}
|
|
6100
6491
|
const depositSats = Number(plan.deposit.atomic);
|
|
6101
|
-
const carrier = deps.carrierSats ??
|
|
6492
|
+
const carrier = deps.carrierSats ?? import_sdk20.ASSET_CARRIER_SATS;
|
|
6102
6493
|
return {
|
|
6103
6494
|
railId: CROSS_ASSET_RAIL,
|
|
6104
6495
|
// OPEN QUESTION for review: `total = amount + fee` forces the
|
|
@@ -6116,7 +6507,7 @@ function crossAssetRail(deps) {
|
|
|
6116
6507
|
priceDisplay: plan.priceDisplay,
|
|
6117
6508
|
give: plan.give
|
|
6118
6509
|
},
|
|
6119
|
-
send: async () => (0,
|
|
6510
|
+
send: async () => (0, import_sdk20.makeHandle)(CROSS_ASSET_RAIL, async (emit) => {
|
|
6120
6511
|
const offer = await createOffer(ctx.wallet, {
|
|
6121
6512
|
wantAmount: asset4.amount,
|
|
6122
6513
|
wantAsset,
|
|
@@ -6200,11 +6591,11 @@ var solverRendezvous = (markets, payoutCorridor, amountSats, fallbackEmulatorPub
|
|
|
6200
6591
|
};
|
|
6201
6592
|
|
|
6202
6593
|
// src/payment/solverLightning.ts
|
|
6203
|
-
var
|
|
6594
|
+
var import_sdk22 = require("@arkade-os/sdk");
|
|
6204
6595
|
init_rfq();
|
|
6205
6596
|
|
|
6206
6597
|
// src/payment/solverOnchain.ts
|
|
6207
|
-
var
|
|
6598
|
+
var import_sdk21 = require("@arkade-os/sdk");
|
|
6208
6599
|
init_rfq();
|
|
6209
6600
|
init_onchainHtlc();
|
|
6210
6601
|
var SOLVER_ONCHAIN_RAIL = "solver-onchain";
|
|
@@ -6233,24 +6624,24 @@ function solverOnchainRail(deps) {
|
|
|
6233
6624
|
const rendezvousFor = async (amount) => solverOnchainRendezvous(await deps.discover(), amount, deps.fallbackEmulatorPubkey);
|
|
6234
6625
|
return {
|
|
6235
6626
|
id: SOLVER_ONCHAIN_RAIL,
|
|
6236
|
-
match: (req) => (0,
|
|
6627
|
+
match: (req) => (0, import_sdk21.btcTarget)(req.raw) !== void 0,
|
|
6237
6628
|
available: async (req) => {
|
|
6238
|
-
if ((0,
|
|
6239
|
-
const address = (0,
|
|
6629
|
+
if ((0, import_sdk21.assetsOf)(req).length > 0) return false;
|
|
6630
|
+
const address = (0, import_sdk21.btcTarget)(req.raw);
|
|
6240
6631
|
if (!address) return false;
|
|
6241
6632
|
try {
|
|
6242
6633
|
l1ScriptForAddress(address, deps.l1Network);
|
|
6243
6634
|
} catch {
|
|
6244
6635
|
return false;
|
|
6245
6636
|
}
|
|
6246
|
-
const amount = (0,
|
|
6637
|
+
const amount = (0, import_sdk21.tryResolveSendAmount)(req.raw, req.amount);
|
|
6247
6638
|
if (amount === void 0) return false;
|
|
6248
6639
|
return await rendezvousFor(amount) !== void 0;
|
|
6249
6640
|
},
|
|
6250
6641
|
quote: async (req, ctx) => {
|
|
6251
|
-
const address = (0,
|
|
6252
|
-
(0,
|
|
6253
|
-
const amount = (0,
|
|
6642
|
+
const address = (0, import_sdk21.btcTarget)(req.raw);
|
|
6643
|
+
(0, import_sdk21.assertNoAssets)(SOLVER_ONCHAIN_RAIL, req);
|
|
6644
|
+
const amount = (0, import_sdk21.resolveSendAmount)(SOLVER_ONCHAIN_RAIL, req.raw, req.amount);
|
|
6254
6645
|
const payoutPkScript = l1ScriptForAddress(address, deps.l1Network);
|
|
6255
6646
|
const rendezvous = await rendezvousFor(amount);
|
|
6256
6647
|
if (!rendezvous) {
|
|
@@ -6289,7 +6680,7 @@ function solverOnchainRail(deps) {
|
|
|
6289
6680
|
// not knowable now, so `amount` is the payout, not the net.
|
|
6290
6681
|
claimFeeDeductedFromPayout: true
|
|
6291
6682
|
},
|
|
6292
|
-
send: async () => (0,
|
|
6683
|
+
send: async () => (0, import_sdk21.makeHandle)(SOLVER_ONCHAIN_RAIL, async (emit) => {
|
|
6293
6684
|
assertFundable({
|
|
6294
6685
|
quote: swap.quote,
|
|
6295
6686
|
now: Math.floor(Date.now() / 1e3),
|
|
@@ -6316,7 +6707,7 @@ function solverOnchainRail(deps) {
|
|
|
6316
6707
|
// src/payment/solverLightning.ts
|
|
6317
6708
|
var SOLVER_LIGHTNING_RAIL = "solver-lightning";
|
|
6318
6709
|
var factsOf = (raw, decode, now) => {
|
|
6319
|
-
const invoice = (0,
|
|
6710
|
+
const invoice = (0, import_sdk22.invoiceTarget)(raw);
|
|
6320
6711
|
if (!invoice) return void 0;
|
|
6321
6712
|
let facts;
|
|
6322
6713
|
try {
|
|
@@ -6328,22 +6719,22 @@ var factsOf = (raw, decode, now) => {
|
|
|
6328
6719
|
if (facts.expiresAt <= now) return void 0;
|
|
6329
6720
|
return facts;
|
|
6330
6721
|
};
|
|
6331
|
-
var contradicts = (req, facts) => req.amount !== void 0 && req.amount !== facts.amountSats && req.amount !==
|
|
6722
|
+
var contradicts = (req, facts) => req.amount !== void 0 && req.amount !== facts.amountSats && req.amount !== import_sdk22.BIP21.amountSats(req.raw);
|
|
6332
6723
|
var solverLightningRendezvous = (markets, amountSats, fallbackEmulatorPubkey) => solverRendezvous(markets, "lightning", amountSats, fallbackEmulatorPubkey);
|
|
6333
6724
|
function solverLightningRail(deps) {
|
|
6334
6725
|
const rendezvousFor = async (amountSats) => solverLightningRendezvous(await deps.discover(), amountSats, deps.fallbackEmulatorPubkey);
|
|
6335
6726
|
return {
|
|
6336
6727
|
id: SOLVER_LIGHTNING_RAIL,
|
|
6337
|
-
match: (req) => (0,
|
|
6728
|
+
match: (req) => (0, import_sdk22.invoiceTarget)(req.raw) !== void 0,
|
|
6338
6729
|
available: async (req) => {
|
|
6339
|
-
if ((0,
|
|
6730
|
+
if ((0, import_sdk22.assetsOf)(req).length > 0) return false;
|
|
6340
6731
|
const facts = factsOf(req.raw, deps.decodeInvoice, Math.floor(Date.now() / 1e3));
|
|
6341
6732
|
if (!facts) return false;
|
|
6342
6733
|
if (contradicts(req, facts)) return false;
|
|
6343
6734
|
return await rendezvousFor(facts.amountSats) !== void 0;
|
|
6344
6735
|
},
|
|
6345
6736
|
quote: async (req, ctx) => {
|
|
6346
|
-
(0,
|
|
6737
|
+
(0, import_sdk22.assertNoAssets)(SOLVER_LIGHTNING_RAIL, req);
|
|
6347
6738
|
const facts = factsOf(req.raw, deps.decodeInvoice, Math.floor(Date.now() / 1e3));
|
|
6348
6739
|
if (!facts) {
|
|
6349
6740
|
throw new Error(
|
|
@@ -6386,7 +6777,7 @@ function solverLightningRail(deps) {
|
|
|
6386
6777
|
invoiceExpiresAt: facts.expiresAt,
|
|
6387
6778
|
solverPubkey: rendezvous.solverPubkey
|
|
6388
6779
|
},
|
|
6389
|
-
send: async () => (0,
|
|
6780
|
+
send: async () => (0, import_sdk22.makeHandle)(SOLVER_LIGHTNING_RAIL, async (emit) => {
|
|
6390
6781
|
assertFundable({
|
|
6391
6782
|
quote: swap.quote,
|
|
6392
6783
|
invoiceExpiresAt: facts.expiresAt,
|
|
@@ -6408,7 +6799,7 @@ function solverLightningRail(deps) {
|
|
|
6408
6799
|
|
|
6409
6800
|
// src/restore.ts
|
|
6410
6801
|
var import_base15 = require("@scure/base");
|
|
6411
|
-
var
|
|
6802
|
+
var import_sdk23 = require("@arkade-os/sdk");
|
|
6412
6803
|
init_offer();
|
|
6413
6804
|
init_store();
|
|
6414
6805
|
var TXS_PER_REQUEST = 50;
|
|
@@ -6426,7 +6817,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
6426
6817
|
if (result.status !== "fulfilled") continue;
|
|
6427
6818
|
for (const psbt of result.value) {
|
|
6428
6819
|
try {
|
|
6429
|
-
const parsed =
|
|
6820
|
+
const parsed = import_sdk23.Transaction.fromPSBT(import_base15.base64.decode(psbt));
|
|
6430
6821
|
parsedByTxid.set(parsed.id, parsed);
|
|
6431
6822
|
} catch {
|
|
6432
6823
|
}
|
|
@@ -6455,7 +6846,7 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
6455
6846
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
6456
6847
|
if (import_base15.hex.encode(input.txid) !== deposit.txid) continue;
|
|
6457
6848
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
6458
|
-
const spent = import_base15.hex.encode((0,
|
|
6849
|
+
const spent = import_base15.hex.encode((0, import_sdk23.scriptFromTapLeafScript)(leaf));
|
|
6459
6850
|
if (leaves.returned.some((back) => spent === import_base15.hex.encode(back))) return "cancelled";
|
|
6460
6851
|
if (leaves.fulfill && spent === import_base15.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
6461
6852
|
}
|
|
@@ -6509,7 +6900,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6509
6900
|
if (!fundingTx) continue;
|
|
6510
6901
|
fetchedTxids.push(txid);
|
|
6511
6902
|
try {
|
|
6512
|
-
const packet =
|
|
6903
|
+
const packet = import_sdk23.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
6513
6904
|
if (!packet) continue;
|
|
6514
6905
|
const payload = packet.serialize();
|
|
6515
6906
|
found.push({
|
|
@@ -6626,7 +7017,7 @@ init_store();
|
|
|
6626
7017
|
|
|
6627
7018
|
// src/watch.ts
|
|
6628
7019
|
var import_base16 = require("@scure/base");
|
|
6629
|
-
var
|
|
7020
|
+
var import_sdk24 = require("@arkade-os/sdk");
|
|
6630
7021
|
init_coverage();
|
|
6631
7022
|
init_offer();
|
|
6632
7023
|
init_store();
|
|
@@ -6661,7 +7052,7 @@ async function watchOfferSwaps({
|
|
|
6661
7052
|
wallet.getAddress(),
|
|
6662
7053
|
wallet.getArkadeReader()
|
|
6663
7054
|
]);
|
|
6664
|
-
const operatorPubkey =
|
|
7055
|
+
const operatorPubkey = import_sdk24.ArkAddress.decode(address).serverPubKey;
|
|
6665
7056
|
let queue = Promise.resolve();
|
|
6666
7057
|
const enqueue = (task) => {
|
|
6667
7058
|
queue = queue.then(task).catch(() => {
|
|
@@ -6676,7 +7067,7 @@ async function watchOfferSwaps({
|
|
|
6676
7067
|
return classifyDepositSpend(
|
|
6677
7068
|
decodeOffer(import_base16.hex.decode(swap.offerHex)),
|
|
6678
7069
|
operatorPubkey,
|
|
6679
|
-
txs.map((psbt) =>
|
|
7070
|
+
txs.map((psbt) => import_sdk24.Transaction.fromPSBT(import_base16.base64.decode(psbt))),
|
|
6680
7071
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
6681
7072
|
);
|
|
6682
7073
|
} catch {
|
|
@@ -6704,7 +7095,7 @@ async function watchOfferSwaps({
|
|
|
6704
7095
|
}
|
|
6705
7096
|
};
|
|
6706
7097
|
const unsubscribe = manager.onContractEvent((event) => {
|
|
6707
|
-
if (!(0,
|
|
7098
|
+
if (!(0, import_sdk24.isContractVtxoEvent)(event) || event.type !== "vtxo_spent") return;
|
|
6708
7099
|
enqueue(() => handleSpend(event));
|
|
6709
7100
|
});
|
|
6710
7101
|
return {
|
|
@@ -6716,6 +7107,10 @@ async function watchOfferSwaps({
|
|
|
6716
7107
|
0 && (module.exports = {
|
|
6717
7108
|
ARKADE_BTC,
|
|
6718
7109
|
ASSET_CARRIER_SATS,
|
|
7110
|
+
ASSET_SWAP_BASELINE,
|
|
7111
|
+
ASSET_SWAP_CONTRACT_VERSIONS,
|
|
7112
|
+
ASSET_SWAP_V2,
|
|
7113
|
+
ASSET_SWAP_V3,
|
|
6719
7114
|
AddressMismatch,
|
|
6720
7115
|
BTC_ASSET_ID,
|
|
6721
7116
|
CROSS_ASSET_RAIL,
|
|
@@ -6756,6 +7151,7 @@ async function watchOfferSwaps({
|
|
|
6756
7151
|
arkadeRefunder,
|
|
6757
7152
|
arkadeSwapRequest,
|
|
6758
7153
|
assertArkadeFundable,
|
|
7154
|
+
assetSwapContractVersion,
|
|
6759
7155
|
awaitOnchainFill,
|
|
6760
7156
|
awaitRfqResolution,
|
|
6761
7157
|
buildHtlcClaim,
|