@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/protocol.cjs
CHANGED
|
@@ -492,11 +492,248 @@ var init_lockupContract = __esm({
|
|
|
492
492
|
}
|
|
493
493
|
});
|
|
494
494
|
|
|
495
|
-
// src/swap
|
|
496
|
-
var
|
|
497
|
-
var
|
|
498
|
-
"src/swap
|
|
499
|
-
|
|
495
|
+
// src/contracts/asset-swap.json
|
|
496
|
+
var asset_swap_default;
|
|
497
|
+
var init_asset_swap = __esm({
|
|
498
|
+
"src/contracts/asset-swap.json"() {
|
|
499
|
+
asset_swap_default = {
|
|
500
|
+
formatVersion: 1,
|
|
501
|
+
contractName: "AssetSwap",
|
|
502
|
+
constructorInputs: [
|
|
503
|
+
{
|
|
504
|
+
name: "receiver",
|
|
505
|
+
type: "pubkey"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: "amount",
|
|
509
|
+
type: "int"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
name: "assetTxid",
|
|
513
|
+
type: "bytes32"
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
name: "assetGroupIndex",
|
|
517
|
+
type: "int"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: "user",
|
|
521
|
+
type: "pubkey"
|
|
522
|
+
}
|
|
523
|
+
],
|
|
524
|
+
functions: [
|
|
525
|
+
{
|
|
526
|
+
name: "fulfill",
|
|
527
|
+
arkade: {
|
|
528
|
+
inputs: [],
|
|
529
|
+
asm: [
|
|
530
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
531
|
+
"OP_DUP",
|
|
532
|
+
"<assetTxid>",
|
|
533
|
+
"<assetGroupIndex>",
|
|
534
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
535
|
+
"OP_VERIFY",
|
|
536
|
+
"<amount>",
|
|
537
|
+
"OP_GREATERTHANOREQUAL",
|
|
538
|
+
"OP_VERIFY",
|
|
539
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
540
|
+
"1",
|
|
541
|
+
"OP_NUMEQUALVERIFY",
|
|
542
|
+
"<receiver>",
|
|
543
|
+
"OP_EQUAL"
|
|
544
|
+
]
|
|
545
|
+
},
|
|
546
|
+
leaves: [
|
|
547
|
+
{
|
|
548
|
+
name: "fulfill",
|
|
549
|
+
witness: [
|
|
550
|
+
{
|
|
551
|
+
name: "serverSig",
|
|
552
|
+
type: "signature",
|
|
553
|
+
encoding: "schnorr-64",
|
|
554
|
+
injected: true
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
name: "emulatorSig",
|
|
558
|
+
type: "signature",
|
|
559
|
+
encoding: "schnorr-64",
|
|
560
|
+
injected: true
|
|
561
|
+
}
|
|
562
|
+
],
|
|
563
|
+
asm: [
|
|
564
|
+
"<SERVER_KEY>",
|
|
565
|
+
"OP_CHECKSIGVERIFY",
|
|
566
|
+
"<EMULATOR_KEY:fulfill>",
|
|
567
|
+
"OP_CHECKSIG"
|
|
568
|
+
]
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
name: "cancel",
|
|
574
|
+
leaves: [
|
|
575
|
+
{
|
|
576
|
+
name: "cancel",
|
|
577
|
+
witness: [
|
|
578
|
+
{
|
|
579
|
+
name: "userSig",
|
|
580
|
+
type: "signature",
|
|
581
|
+
encoding: "schnorr-64"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: "serverSig",
|
|
585
|
+
type: "signature",
|
|
586
|
+
encoding: "schnorr-64",
|
|
587
|
+
injected: true
|
|
588
|
+
}
|
|
589
|
+
],
|
|
590
|
+
asm: [
|
|
591
|
+
"<user>",
|
|
592
|
+
"OP_CHECKSIGVERIFY",
|
|
593
|
+
"<SERVER_KEY>",
|
|
594
|
+
"OP_CHECKSIG"
|
|
595
|
+
]
|
|
596
|
+
}
|
|
597
|
+
]
|
|
598
|
+
}
|
|
599
|
+
],
|
|
600
|
+
source: {
|
|
601
|
+
entry: "asset-swap.ark",
|
|
602
|
+
files: {
|
|
603
|
+
"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"
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
compiler: {
|
|
607
|
+
name: "arkadec",
|
|
608
|
+
version: "0.1.0-rc.1",
|
|
609
|
+
options: {
|
|
610
|
+
optimize: true
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
updatedAt: "2026-11-02T17:43:42.615113722+00:00",
|
|
614
|
+
fingerprint: "sha256:e2b80add6237f6c7e2c69a96ae46d55abe6de5f71c3718106f4d5b22ac9e6d0a"
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
// src/contracts/sats-swap.json
|
|
620
|
+
var sats_swap_default;
|
|
621
|
+
var init_sats_swap = __esm({
|
|
622
|
+
"src/contracts/sats-swap.json"() {
|
|
623
|
+
sats_swap_default = {
|
|
624
|
+
formatVersion: 1,
|
|
625
|
+
contractName: "SatsSwap",
|
|
626
|
+
constructorInputs: [
|
|
627
|
+
{
|
|
628
|
+
name: "receiver",
|
|
629
|
+
type: "pubkey"
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
name: "amount",
|
|
633
|
+
type: "int"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
name: "user",
|
|
637
|
+
type: "pubkey"
|
|
638
|
+
}
|
|
639
|
+
],
|
|
640
|
+
functions: [
|
|
641
|
+
{
|
|
642
|
+
name: "fulfill",
|
|
643
|
+
arkade: {
|
|
644
|
+
inputs: [],
|
|
645
|
+
asm: [
|
|
646
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
647
|
+
"OP_DUP",
|
|
648
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
649
|
+
"<amount>",
|
|
650
|
+
"OP_GREATERTHANOREQUAL",
|
|
651
|
+
"OP_VERIFY",
|
|
652
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
653
|
+
"1",
|
|
654
|
+
"OP_NUMEQUALVERIFY",
|
|
655
|
+
"<receiver>",
|
|
656
|
+
"OP_EQUAL"
|
|
657
|
+
]
|
|
658
|
+
},
|
|
659
|
+
leaves: [
|
|
660
|
+
{
|
|
661
|
+
name: "fulfill",
|
|
662
|
+
witness: [
|
|
663
|
+
{
|
|
664
|
+
name: "serverSig",
|
|
665
|
+
type: "signature",
|
|
666
|
+
encoding: "schnorr-64",
|
|
667
|
+
injected: true
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
name: "emulatorSig",
|
|
671
|
+
type: "signature",
|
|
672
|
+
encoding: "schnorr-64",
|
|
673
|
+
injected: true
|
|
674
|
+
}
|
|
675
|
+
],
|
|
676
|
+
asm: [
|
|
677
|
+
"<SERVER_KEY>",
|
|
678
|
+
"OP_CHECKSIGVERIFY",
|
|
679
|
+
"<EMULATOR_KEY:fulfill>",
|
|
680
|
+
"OP_CHECKSIG"
|
|
681
|
+
]
|
|
682
|
+
}
|
|
683
|
+
]
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
name: "cancel",
|
|
687
|
+
leaves: [
|
|
688
|
+
{
|
|
689
|
+
name: "cancel",
|
|
690
|
+
witness: [
|
|
691
|
+
{
|
|
692
|
+
name: "userSig",
|
|
693
|
+
type: "signature",
|
|
694
|
+
encoding: "schnorr-64"
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
name: "serverSig",
|
|
698
|
+
type: "signature",
|
|
699
|
+
encoding: "schnorr-64",
|
|
700
|
+
injected: true
|
|
701
|
+
}
|
|
702
|
+
],
|
|
703
|
+
asm: [
|
|
704
|
+
"<user>",
|
|
705
|
+
"OP_CHECKSIGVERIFY",
|
|
706
|
+
"<SERVER_KEY>",
|
|
707
|
+
"OP_CHECKSIG"
|
|
708
|
+
]
|
|
709
|
+
}
|
|
710
|
+
]
|
|
711
|
+
}
|
|
712
|
+
],
|
|
713
|
+
source: {
|
|
714
|
+
entry: "sats-swap.ark",
|
|
715
|
+
files: {
|
|
716
|
+
"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"
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
compiler: {
|
|
720
|
+
name: "arkadec",
|
|
721
|
+
version: "0.1.0-rc.1",
|
|
722
|
+
options: {
|
|
723
|
+
optimize: true
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
updatedAt: "2026-11-02T17:43:42.616824535+00:00",
|
|
727
|
+
fingerprint: "sha256:d7a60ab2178ede40a2e4867816689ea022641531cc662b562bebd7caa1ef96c4"
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
// src/legacy/swap-want-asset.program.v1.json
|
|
733
|
+
var swap_want_asset_program_v1_default;
|
|
734
|
+
var init_swap_want_asset_program_v1 = __esm({
|
|
735
|
+
"src/legacy/swap-want-asset.program.v1.json"() {
|
|
736
|
+
swap_want_asset_program_v1_default = {
|
|
500
737
|
version: 1,
|
|
501
738
|
name: "banco-btc-to-asset",
|
|
502
739
|
params: [
|
|
@@ -537,11 +774,11 @@ var init_swap_want_asset_program = __esm({
|
|
|
537
774
|
}
|
|
538
775
|
});
|
|
539
776
|
|
|
540
|
-
// src/swap-want-btc.program.json
|
|
541
|
-
var
|
|
542
|
-
var
|
|
543
|
-
"src/swap-want-btc.program.json"() {
|
|
544
|
-
|
|
777
|
+
// src/legacy/swap-want-btc.program.v1.json
|
|
778
|
+
var swap_want_btc_program_v1_default;
|
|
779
|
+
var init_swap_want_btc_program_v1 = __esm({
|
|
780
|
+
"src/legacy/swap-want-btc.program.v1.json"() {
|
|
781
|
+
swap_want_btc_program_v1_default = {
|
|
545
782
|
version: 1,
|
|
546
783
|
name: "banco-asset-to-btc",
|
|
547
784
|
params: [
|
|
@@ -577,6 +814,80 @@ var init_swap_want_btc_program = __esm({
|
|
|
577
814
|
}
|
|
578
815
|
});
|
|
579
816
|
|
|
817
|
+
// src/rfq-contract.ts
|
|
818
|
+
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_BASELINE;
|
|
819
|
+
var init_rfq_contract = __esm({
|
|
820
|
+
"src/rfq-contract.ts"() {
|
|
821
|
+
"use strict";
|
|
822
|
+
RFQ_CONTRACT_VERSIONS_KEY = "contract_versions";
|
|
823
|
+
RFQ_CONTRACT_VERSION_KEY = "contract_version";
|
|
824
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
825
|
+
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
826
|
+
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
827
|
+
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
828
|
+
}
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
// src/program.ts
|
|
832
|
+
var import_sdk3, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
833
|
+
var init_program = __esm({
|
|
834
|
+
"src/program.ts"() {
|
|
835
|
+
"use strict";
|
|
836
|
+
import_sdk3 = require("@arkade-os/sdk");
|
|
837
|
+
init_asset_swap();
|
|
838
|
+
init_sats_swap();
|
|
839
|
+
init_swap_want_asset_program_v1();
|
|
840
|
+
init_swap_want_btc_program_v1();
|
|
841
|
+
init_rfq_contract();
|
|
842
|
+
init_rfq_contract();
|
|
843
|
+
swapPrograms = {
|
|
844
|
+
wantAsset: import_sdk3.arkade.programFromArtifact(asset_swap_default),
|
|
845
|
+
wantBtc: import_sdk3.arkade.programFromArtifact(sats_swap_default)
|
|
846
|
+
};
|
|
847
|
+
legacySwapPrograms = {
|
|
848
|
+
wantAsset: import_sdk3.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
849
|
+
wantBtc: import_sdk3.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
850
|
+
};
|
|
851
|
+
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
852
|
+
user,
|
|
853
|
+
server,
|
|
854
|
+
...exitDelay && { exitDelay }
|
|
855
|
+
});
|
|
856
|
+
ASSET_SWAP_CONTRACTS = {
|
|
857
|
+
[ASSET_SWAP_V2]: {
|
|
858
|
+
programs: legacySwapPrograms,
|
|
859
|
+
args: (inputs) => ({
|
|
860
|
+
makerWP: inputs.receiver,
|
|
861
|
+
wantAmount: inputs.amount,
|
|
862
|
+
...inputs.asset && {
|
|
863
|
+
wantAssetTxid: inputs.asset.txid,
|
|
864
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
865
|
+
},
|
|
866
|
+
...sharedArgs(inputs)
|
|
867
|
+
})
|
|
868
|
+
},
|
|
869
|
+
[ASSET_SWAP_V3]: {
|
|
870
|
+
programs: swapPrograms,
|
|
871
|
+
args: (inputs) => ({
|
|
872
|
+
receiver: inputs.receiver,
|
|
873
|
+
amount: inputs.amount,
|
|
874
|
+
...inputs.asset && {
|
|
875
|
+
assetTxid: inputs.asset.txid,
|
|
876
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
877
|
+
},
|
|
878
|
+
...sharedArgs(inputs)
|
|
879
|
+
})
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V3, ASSET_SWAP_V2];
|
|
883
|
+
assetSwapContractVersion = (id) => {
|
|
884
|
+
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
885
|
+
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
886
|
+
throw new Error(`unknown contract version ${id}`);
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
|
|
580
891
|
// src/rfqCorridor.ts
|
|
581
892
|
var RfqCorridorRegistry, rfqCorridorHandlers;
|
|
582
893
|
var init_rfqCorridor = __esm({
|
|
@@ -620,26 +931,26 @@ var init_rfqCorridor = __esm({
|
|
|
620
931
|
});
|
|
621
932
|
|
|
622
933
|
// src/repository.ts
|
|
623
|
-
var
|
|
934
|
+
var import_sdk4, collectAssetSwaps, collectRfqSwaps;
|
|
624
935
|
var init_repository = __esm({
|
|
625
936
|
"src/repository.ts"() {
|
|
626
937
|
"use strict";
|
|
627
|
-
|
|
628
|
-
collectAssetSwaps = (repository) => (0,
|
|
629
|
-
collectRfqSwaps = (repository, filter = {}) => (0,
|
|
938
|
+
import_sdk4 = require("@arkade-os/sdk");
|
|
939
|
+
collectAssetSwaps = (repository) => (0, import_sdk4.collectPages)((page) => repository.getAssetSwapsPage(page));
|
|
940
|
+
collectRfqSwaps = (repository, filter = {}) => (0, import_sdk4.collectPages)(
|
|
630
941
|
(page) => repository.getRfqSwapsPage(filter, page)
|
|
631
942
|
);
|
|
632
943
|
}
|
|
633
944
|
});
|
|
634
945
|
|
|
635
946
|
// src/store.ts
|
|
636
|
-
var import_base4, import_sha23,
|
|
947
|
+
var import_base4, import_sha23, import_sdk5, BTC_ASSET_ID, byNewest, getAssetSwapsOrThrow, getAssetSwaps, saveSwapOrThrow, addAssetSwap, updateAssetSwap, updateAssetSwapBestEffort, swapSecretsToRecord, decodeHex32, PreimageNotRecoverableError, preimageForSwapRecord;
|
|
637
948
|
var init_store = __esm({
|
|
638
949
|
"src/store.ts"() {
|
|
639
950
|
"use strict";
|
|
640
951
|
import_base4 = require("@scure/base");
|
|
641
952
|
import_sha23 = require("@noble/hashes/sha2.js");
|
|
642
|
-
|
|
953
|
+
import_sdk5 = require("@arkade-os/sdk");
|
|
643
954
|
init_repository();
|
|
644
955
|
BTC_ASSET_ID = "btc";
|
|
645
956
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
@@ -734,7 +1045,7 @@ var init_store = __esm({
|
|
|
734
1045
|
}
|
|
735
1046
|
let preimage;
|
|
736
1047
|
try {
|
|
737
|
-
preimage = await (0,
|
|
1048
|
+
preimage = await (0, import_sdk5.contractPreimage)(wallet, record.signingDescriptor, { stored, salt });
|
|
738
1049
|
} catch (cause) {
|
|
739
1050
|
throw new PreimageNotRecoverableError(
|
|
740
1051
|
"not-derivable",
|
|
@@ -846,37 +1157,60 @@ function withExitClosure(program, exit) {
|
|
|
846
1157
|
}
|
|
847
1158
|
};
|
|
848
1159
|
}
|
|
849
|
-
function swapProgramBinding(offer, operatorPubkey) {
|
|
1160
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion = ASSET_SWAP_BASELINE) {
|
|
850
1161
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
851
1162
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
852
1163
|
}
|
|
1164
|
+
const expected = offer.swapPkScript;
|
|
1165
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1166
|
+
const funded = import_base5.hex.encode(expected);
|
|
1167
|
+
const order = [
|
|
1168
|
+
ASSET_SWAP_BASELINE,
|
|
1169
|
+
...ASSET_SWAP_CONTRACT_VERSIONS.filter((v) => v !== ASSET_SWAP_BASELINE)
|
|
1170
|
+
];
|
|
1171
|
+
for (const version of order) {
|
|
1172
|
+
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
1173
|
+
if (pkOf(binding) === funded) return binding;
|
|
1174
|
+
}
|
|
1175
|
+
return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1176
|
+
}
|
|
1177
|
+
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1178
|
+
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1179
|
+
const user = offer.makerPublicKey;
|
|
1180
|
+
const assetId = offer.wantAsset;
|
|
853
1181
|
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,
|
|
1182
|
+
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
1183
|
+
args: args({
|
|
1184
|
+
receiver: offer.makerPkScript.subarray(2),
|
|
1185
|
+
amount: offer.wantAmount,
|
|
863
1186
|
// internal byte order
|
|
864
|
-
...
|
|
865
|
-
|
|
866
|
-
wantAssetGroupIndex: offer.wantAsset.groupIndex
|
|
1187
|
+
...assetId && {
|
|
1188
|
+
asset: { txid: assetId.txid.slice().reverse(), groupIndex: assetId.groupIndex }
|
|
867
1189
|
},
|
|
1190
|
+
user,
|
|
1191
|
+
server: operatorPubkey,
|
|
868
1192
|
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
869
|
-
},
|
|
1193
|
+
}),
|
|
870
1194
|
keys: {
|
|
871
1195
|
serverKey: operatorPubkey,
|
|
872
|
-
userKey:
|
|
1196
|
+
userKey: user,
|
|
873
1197
|
emulatorKey: offer.emulatorPubkey
|
|
874
1198
|
}
|
|
875
1199
|
};
|
|
876
1200
|
}
|
|
877
|
-
function
|
|
878
|
-
|
|
879
|
-
|
|
1201
|
+
function compileSwapBinding(binding) {
|
|
1202
|
+
let script = compiledBindings.get(binding);
|
|
1203
|
+
if (!script) {
|
|
1204
|
+
script = new import_sdk6.arkade.ArkadeProgramScript(binding.program, binding.args, binding.keys);
|
|
1205
|
+
compiledBindings.set(binding, script);
|
|
1206
|
+
}
|
|
1207
|
+
return script;
|
|
1208
|
+
}
|
|
1209
|
+
function pkOf(binding) {
|
|
1210
|
+
return import_base5.hex.encode(compileSwapBinding(binding).pkScript);
|
|
1211
|
+
}
|
|
1212
|
+
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
1213
|
+
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
880
1214
|
}
|
|
881
1215
|
function u64(name, value) {
|
|
882
1216
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
@@ -992,8 +1326,8 @@ function decodeOffer(data) {
|
|
|
992
1326
|
return {
|
|
993
1327
|
swapPkScript: need("swapPkScript"),
|
|
994
1328
|
wantAmount: readU64(amount),
|
|
995
|
-
...fields.wantAsset && { wantAsset:
|
|
996
|
-
...fields.offerAsset && { offerAsset:
|
|
1329
|
+
...fields.wantAsset && { wantAsset: import_sdk6.asset.AssetId.fromBytes(fields.wantAsset) },
|
|
1330
|
+
...fields.offerAsset && { offerAsset: import_sdk6.asset.AssetId.fromBytes(fields.offerAsset) },
|
|
997
1331
|
makerPkScript: need("makerPkScript"),
|
|
998
1332
|
makerPublicKey: need("makerPublicKey"),
|
|
999
1333
|
emulatorPubkey: need("emulatorPubkey"),
|
|
@@ -1019,8 +1353,11 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
1019
1353
|
});
|
|
1020
1354
|
}
|
|
1021
1355
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
1022
|
-
const { program, args, keys } = swapProgramBinding(
|
|
1023
|
-
|
|
1356
|
+
const { program, args, keys } = swapProgramBinding(
|
|
1357
|
+
{ ...binding, swapPkScript: expectedPkScript },
|
|
1358
|
+
operatorPubkey
|
|
1359
|
+
);
|
|
1360
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, program, args, keys);
|
|
1024
1361
|
if (import_base5.hex.encode(contract.pkScript) !== import_base5.hex.encode(expectedPkScript)) {
|
|
1025
1362
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
1026
1363
|
}
|
|
@@ -1052,7 +1389,7 @@ function resolveReceivePkScript(receiveAddress, walletPkScript, hrp, serverPubKe
|
|
|
1052
1389
|
if (receiveAddress === void 0) return walletPkScript;
|
|
1053
1390
|
let address;
|
|
1054
1391
|
try {
|
|
1055
|
-
address =
|
|
1392
|
+
address = import_sdk6.ArkAddress.decode(receiveAddress);
|
|
1056
1393
|
} catch (cause) {
|
|
1057
1394
|
throw new Error("receiveAddress is not a valid Arkade address", { cause });
|
|
1058
1395
|
}
|
|
@@ -1087,13 +1424,13 @@ async function deriveOffer(wallet, params) {
|
|
|
1087
1424
|
wallet.getAddress(),
|
|
1088
1425
|
wallet.identity.xOnlyPublicKey()
|
|
1089
1426
|
]);
|
|
1090
|
-
return { pkScript:
|
|
1427
|
+
return { pkScript: import_sdk6.ArkAddress.decode(address).pkScript, publicKey };
|
|
1091
1428
|
})()
|
|
1092
1429
|
]);
|
|
1093
|
-
const operatorPubKey = import_base5.hex.decode((0,
|
|
1094
|
-
const network = (0,
|
|
1430
|
+
const operatorPubKey = import_base5.hex.decode((0, import_sdk6.toXOnlySignerHex)(info.signerPubkey));
|
|
1431
|
+
const network = (0, import_sdk6.networkFromOperatorInfo)(info);
|
|
1095
1432
|
const emuKey = import_base5.hex.decode(
|
|
1096
|
-
(0,
|
|
1433
|
+
(0, import_sdk6.toXOnlySignerHex)((0, import_sdk6.resolveEmulatorPubkey)(network, params.emulatorPubkey))
|
|
1097
1434
|
);
|
|
1098
1435
|
const binding = Object.freeze({
|
|
1099
1436
|
wantAmount: params.wantAmount,
|
|
@@ -1110,7 +1447,7 @@ async function deriveOffer(wallet, params) {
|
|
|
1110
1447
|
// checked before registration below. @see assertExitDelay
|
|
1111
1448
|
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
1112
1449
|
});
|
|
1113
|
-
const script = offerContract(binding, operatorPubKey);
|
|
1450
|
+
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
1114
1451
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
1115
1452
|
const payload = encodeOffer(offer);
|
|
1116
1453
|
return Object.freeze({
|
|
@@ -1172,7 +1509,7 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1172
1509
|
wallet.getArkadeReader(),
|
|
1173
1510
|
wallet.getArkadeBroadcaster()
|
|
1174
1511
|
]);
|
|
1175
|
-
const client = await
|
|
1512
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1176
1513
|
arkade: { getInfo: async () => info, ...broadcaster },
|
|
1177
1514
|
indexer: reader,
|
|
1178
1515
|
identity: wallet.identity,
|
|
@@ -1182,21 +1519,22 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1182
1519
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
1183
1520
|
oneShotSubmit: wallet.oneShotSubmit
|
|
1184
1521
|
});
|
|
1185
|
-
const operatorPubkey = swapAddress ?
|
|
1186
|
-
|
|
1522
|
+
const operatorPubkey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1523
|
+
let binding;
|
|
1187
1524
|
let rebuilt;
|
|
1188
1525
|
try {
|
|
1189
|
-
|
|
1526
|
+
binding = swapProgramBinding(offer, operatorPubkey);
|
|
1527
|
+
rebuilt = compileSwapBinding(binding);
|
|
1190
1528
|
} catch (cause) {
|
|
1191
1529
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript), { cause });
|
|
1192
1530
|
}
|
|
1193
1531
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1194
1532
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript));
|
|
1195
1533
|
}
|
|
1196
|
-
const contract = new
|
|
1534
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1197
1535
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
1198
1536
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
1199
|
-
const makerPkScript =
|
|
1537
|
+
const makerPkScript = import_sdk6.ArkAddress.decode(makerAddress).pkScript;
|
|
1200
1538
|
const cancel = contract.functions.cancel().from({ txid: vtxo.txid, vout: vtxo.vout, value: vtxo.value }).to(makerPkScript, BigInt(vtxo.value));
|
|
1201
1539
|
for (const a of vtxo.assets ?? []) {
|
|
1202
1540
|
cancel.withAsset({
|
|
@@ -1235,7 +1573,7 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1235
1573
|
offer,
|
|
1236
1574
|
vtxo,
|
|
1237
1575
|
solverFund: fund,
|
|
1238
|
-
solverPayout: payoutScript ??
|
|
1576
|
+
solverPayout: payoutScript ?? import_sdk6.ArkAddress.decode(takerAddress).pkScript,
|
|
1239
1577
|
assetCarrierSats
|
|
1240
1578
|
});
|
|
1241
1579
|
const { txid } = await fill.send();
|
|
@@ -1244,25 +1582,25 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1244
1582
|
async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
1245
1583
|
const { swapAddress, emulator, emulatorPubkey } = opts;
|
|
1246
1584
|
const contractManager = await wallet.getContractManager();
|
|
1247
|
-
const client = await
|
|
1248
|
-
arkade: new
|
|
1249
|
-
indexer: new
|
|
1585
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1586
|
+
arkade: new import_sdk6.RestOperatorProvider(arkServerUrl),
|
|
1587
|
+
indexer: new import_sdk6.RestIndexerProvider(arkServerUrl),
|
|
1250
1588
|
identity: wallet.identity,
|
|
1251
1589
|
contractManager,
|
|
1252
1590
|
...emulator !== void 0 ? {
|
|
1253
|
-
emulator: typeof emulator === "string" ? new
|
|
1591
|
+
emulator: typeof emulator === "string" ? new import_sdk6.RestEmulatorProvider(emulator) : emulator
|
|
1254
1592
|
} : {},
|
|
1255
1593
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
1256
1594
|
});
|
|
1257
|
-
const serverKey = swapAddress ?
|
|
1258
|
-
const
|
|
1259
|
-
const rebuilt =
|
|
1595
|
+
const serverKey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1596
|
+
const binding = swapProgramBinding(offer, serverKey);
|
|
1597
|
+
const rebuilt = compileSwapBinding(binding);
|
|
1260
1598
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1261
1599
|
throw new Error(
|
|
1262
1600
|
"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
1601
|
);
|
|
1264
1602
|
}
|
|
1265
|
-
return new
|
|
1603
|
+
return new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1266
1604
|
}
|
|
1267
1605
|
function resolveDeposit(vtxos, sel) {
|
|
1268
1606
|
const { fundingTxid, fundingOutpoint } = sel;
|
|
@@ -1551,7 +1889,7 @@ function assertScript(script, what) {
|
|
|
1551
1889
|
function assertAssetId(assetId, what) {
|
|
1552
1890
|
if (typeof assetId !== "string") throw new Error(`${what} must be an asset id string`);
|
|
1553
1891
|
try {
|
|
1554
|
-
return
|
|
1892
|
+
return import_sdk6.asset.AssetId.fromString(assetId).toString();
|
|
1555
1893
|
} catch {
|
|
1556
1894
|
throw new Error(`${what} is not a valid asset id`);
|
|
1557
1895
|
}
|
|
@@ -1573,22 +1911,18 @@ function assertFillCoin(coin, what) {
|
|
|
1573
1911
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
1574
1912
|
assertAssetEntries(coin.assets, what);
|
|
1575
1913
|
}
|
|
1576
|
-
var import_base5, import_utils2,
|
|
1914
|
+
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
1915
|
var init_offer = __esm({
|
|
1578
1916
|
"src/offer.ts"() {
|
|
1579
1917
|
"use strict";
|
|
1580
1918
|
import_base5 = require("@scure/base");
|
|
1581
1919
|
import_utils2 = require("@scure/btc-signer/utils.js");
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
init_swap_want_btc_program();
|
|
1920
|
+
import_sdk6 = require("@arkade-os/sdk");
|
|
1921
|
+
init_program();
|
|
1585
1922
|
init_coverage();
|
|
1586
1923
|
init_rfqProfileParts();
|
|
1587
1924
|
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
|
-
};
|
|
1925
|
+
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
1592
1926
|
OFFER_PACKET_TYPE = 3;
|
|
1593
1927
|
FIELDS = {
|
|
1594
1928
|
swapPkScript: { tag: 1, width: 34 },
|
|
@@ -1612,10 +1946,10 @@ var init_offer = __esm({
|
|
|
1612
1946
|
};
|
|
1613
1947
|
OFFER_CONTRACT_LABEL = "Arkade swap offer";
|
|
1614
1948
|
OFFER_CONTRACT_KIND = "asset-swap-offer";
|
|
1615
|
-
derivingClient = (wallet, info, contractManager) =>
|
|
1949
|
+
derivingClient = (wallet, info, contractManager) => import_sdk6.arkade.Arkade.connect({
|
|
1616
1950
|
arkade: { getInfo: async () => info },
|
|
1617
1951
|
identity: wallet.identity,
|
|
1618
|
-
network: (0,
|
|
1952
|
+
network: (0, import_sdk6.networkFromOperatorInfo)(info),
|
|
1619
1953
|
contractManager
|
|
1620
1954
|
});
|
|
1621
1955
|
NoSpendableDepositError = class extends Error {
|
|
@@ -1635,7 +1969,7 @@ var init_offer = __esm({
|
|
|
1635
1969
|
swapPkScript;
|
|
1636
1970
|
name = "OfferCovenantMismatchError";
|
|
1637
1971
|
};
|
|
1638
|
-
ASSET_CARRIER_SATS = BigInt(
|
|
1972
|
+
ASSET_CARRIER_SATS = BigInt(import_sdk6.ASSET_CARRIER_SATS);
|
|
1639
1973
|
amountOfAsset = (assets, assetId) => {
|
|
1640
1974
|
let total = BigInt(0);
|
|
1641
1975
|
for (const a of assets ?? []) {
|
|
@@ -1680,7 +2014,7 @@ function deriveLightningSend(input) {
|
|
|
1680
2014
|
throw new Error("lightning-send quote is missing profile.receiver_pk_script");
|
|
1681
2015
|
}
|
|
1682
2016
|
const contractParams = {
|
|
1683
|
-
solverPubkey: (0,
|
|
2017
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1684
2018
|
refundLocktime: quote.refund_locktime,
|
|
1685
2019
|
operatorPubkey: input.operatorPubkey,
|
|
1686
2020
|
paymentHash: input.paymentHash,
|
|
@@ -1711,7 +2045,7 @@ function deriveLightningSend(input) {
|
|
|
1711
2045
|
async function requestLightningSend(wallet, transport, params) {
|
|
1712
2046
|
const rfqId = params.rfqId ?? newRfqId();
|
|
1713
2047
|
const [secrets, info] = await Promise.all([
|
|
1714
|
-
(0,
|
|
2048
|
+
(0, import_sdk8.provisionRefundKey)(wallet),
|
|
1715
2049
|
wallet.getArkadeInfo({ requireLive: true })
|
|
1716
2050
|
]);
|
|
1717
2051
|
const senderPubkey = secrets.pubkey;
|
|
@@ -1731,16 +2065,16 @@ async function requestLightningSend(wallet, transport, params) {
|
|
|
1731
2065
|
`quote from_amount ${quote.from_amount} is below the invoice amount \u2014 a negative spread is not a quote`
|
|
1732
2066
|
);
|
|
1733
2067
|
}
|
|
1734
|
-
const operatorPubkey = (0,
|
|
1735
|
-
const network = (0,
|
|
2068
|
+
const operatorPubkey = (0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key");
|
|
2069
|
+
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
1736
2070
|
const derived = deriveLightningSend({
|
|
1737
2071
|
quote,
|
|
1738
2072
|
paymentHash: params.invoice.paymentHash,
|
|
1739
2073
|
senderPubkey,
|
|
1740
2074
|
refundPkScript: secrets.pkScript,
|
|
1741
2075
|
operatorPubkey,
|
|
1742
|
-
emulatorPubkey: (0,
|
|
1743
|
-
import_base6.hex.decode((0,
|
|
2076
|
+
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
2077
|
+
import_base6.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, params.emulatorPubkey)),
|
|
1744
2078
|
"emulator signer key"
|
|
1745
2079
|
),
|
|
1746
2080
|
claimDelay,
|
|
@@ -1773,35 +2107,38 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
1773
2107
|
if (!params.wantAsset && !params.offerAsset) {
|
|
1774
2108
|
throw new Error("set at least one of wantAsset or offerAsset; BTC-to-BTC is not a swap");
|
|
1775
2109
|
}
|
|
1776
|
-
const rfqId = params.rfqId ?? newRfqId();
|
|
1777
2110
|
const amountSide = params.amountSide ?? "from";
|
|
1778
2111
|
const receiveAddress = params.receiveAddress;
|
|
1779
2112
|
const [makerAddress, makerPublicKey] = await Promise.all([
|
|
1780
2113
|
wallet.getAddress(),
|
|
1781
2114
|
wallet.identity.xOnlyPublicKey()
|
|
1782
2115
|
]);
|
|
1783
|
-
const ownPkScript =
|
|
2116
|
+
const ownPkScript = import_sdk7.ArkAddress.decode(makerAddress).pkScript;
|
|
1784
2117
|
const info = receiveAddress === void 0 ? void 0 : await wallet.getArkadeInfo({ requireLive: true });
|
|
1785
2118
|
const makerPkScript = info === void 0 ? ownPkScript : resolveReceivePkScript(
|
|
1786
2119
|
receiveAddress,
|
|
1787
2120
|
ownPkScript,
|
|
1788
|
-
(0,
|
|
1789
|
-
(0,
|
|
2121
|
+
(0, import_sdk7.networkFromOperatorInfo)(info).hrp,
|
|
2122
|
+
(0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key")
|
|
1790
2123
|
);
|
|
1791
2124
|
const pair = rfqPair(
|
|
1792
2125
|
params.offerAsset ? arkadeAssetLeg(params.offerAsset) : ARKADE_BTC,
|
|
1793
2126
|
params.wantAsset ? arkadeAssetLeg(params.wantAsset) : ARKADE_BTC
|
|
1794
2127
|
);
|
|
1795
|
-
const
|
|
2128
|
+
const contractVersions = [...params.contractVersions ?? ASSET_SWAP_CONTRACT_VERSIONS];
|
|
2129
|
+
const { quote, rfqId, contractVersion } = await requestVersionedQuote(
|
|
2130
|
+
transport,
|
|
1796
2131
|
arkadeSwapRequest({
|
|
1797
|
-
rfqId,
|
|
2132
|
+
rfqId: params.rfqId ?? newRfqId(),
|
|
1798
2133
|
...params.offerAsset !== void 0 ? { offerAsset: params.offerAsset } : {},
|
|
1799
2134
|
...params.wantAsset !== void 0 ? { wantAsset: params.wantAsset } : {},
|
|
1800
2135
|
amount: params.amount,
|
|
1801
2136
|
amountSide,
|
|
1802
2137
|
makerPkScript,
|
|
1803
|
-
makerPublicKey
|
|
1804
|
-
|
|
2138
|
+
makerPublicKey,
|
|
2139
|
+
contractVersions
|
|
2140
|
+
}),
|
|
2141
|
+
contractVersions
|
|
1805
2142
|
);
|
|
1806
2143
|
if (quote.pair !== pair) {
|
|
1807
2144
|
throw new Error(`solver quoted ${JSON.stringify(quote.pair)}, not the requested ${pair}`);
|
|
@@ -1842,7 +2179,8 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
1842
2179
|
wantAmount: terms.wantAmount,
|
|
1843
2180
|
...terms.wantAsset !== void 0 ? { wantAsset: terms.wantAsset } : {},
|
|
1844
2181
|
...terms.offerAsset !== void 0 ? { offerAsset: terms.offerAsset } : {},
|
|
1845
|
-
...params.emulatorPubkey !== void 0 ? { emulatorPubkey: params.emulatorPubkey } : {}
|
|
2182
|
+
...params.emulatorPubkey !== void 0 ? { emulatorPubkey: params.emulatorPubkey } : {},
|
|
2183
|
+
contractVersion
|
|
1846
2184
|
});
|
|
1847
2185
|
verifyOfferAddress(quote, offer);
|
|
1848
2186
|
const fundAmount = BigInt(quote.from_amount);
|
|
@@ -1876,7 +2214,7 @@ function deriveOnchainSend(input) {
|
|
|
1876
2214
|
"onchain-send"
|
|
1877
2215
|
);
|
|
1878
2216
|
const contractParams = {
|
|
1879
|
-
solverPubkey: (0,
|
|
2217
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1880
2218
|
refundLocktime,
|
|
1881
2219
|
operatorPubkey: input.operatorPubkey,
|
|
1882
2220
|
paymentHash: input.paymentHash,
|
|
@@ -1885,7 +2223,7 @@ function deriveOnchainSend(input) {
|
|
|
1885
2223
|
emulatorPubkey: input.emulatorPubkey,
|
|
1886
2224
|
senderPubkey: input.senderPubkey,
|
|
1887
2225
|
receiverPkScript: solverHex(receiverPkScriptHex, "profile.receiver_pk_script"),
|
|
1888
|
-
refundPkScript:
|
|
2226
|
+
refundPkScript: import_sdk7.ArkAddress.decode(input.refundAddress).pkScript
|
|
1889
2227
|
};
|
|
1890
2228
|
const { script, address } = matchQuotedLockup(
|
|
1891
2229
|
quote,
|
|
@@ -1896,7 +2234,7 @@ function deriveOnchainSend(input) {
|
|
|
1896
2234
|
const htlcParams = {
|
|
1897
2235
|
paymentHash: input.paymentHash,
|
|
1898
2236
|
claimKey: input.payoutPubkey,
|
|
1899
|
-
refundKey: (0,
|
|
2237
|
+
refundKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(htlcPubkey), "solver L1 htlc key"),
|
|
1900
2238
|
refundLocktime: htlcLocktime
|
|
1901
2239
|
};
|
|
1902
2240
|
const htlc = onchainHtlcScript(htlcParams, input.l1Network);
|
|
@@ -1918,7 +2256,7 @@ function deriveOnchainSend(input) {
|
|
|
1918
2256
|
async function requestOnchainSend(wallet, transport, params) {
|
|
1919
2257
|
const rfqId = params.rfqId ?? newRfqId();
|
|
1920
2258
|
const [secrets, info, refundAddress] = await Promise.all([
|
|
1921
|
-
(0,
|
|
2259
|
+
(0, import_sdk8.provisionClaimSecret)(wallet, { preimage: params.preimage }),
|
|
1922
2260
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
1923
2261
|
wallet.getAddress()
|
|
1924
2262
|
]);
|
|
@@ -2091,7 +2429,7 @@ function deriveOnchainReceive(input) {
|
|
|
2091
2429
|
).matched;
|
|
2092
2430
|
const htlcParams = {
|
|
2093
2431
|
paymentHash: input.paymentHash,
|
|
2094
|
-
claimKey: (0,
|
|
2432
|
+
claimKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(claimPubkey), "solver L1 claim key"),
|
|
2095
2433
|
refundKey: input.refundPubkey,
|
|
2096
2434
|
refundLocktime: htlcLocktime
|
|
2097
2435
|
};
|
|
@@ -2165,21 +2503,23 @@ async function requestOnchainReceive(wallet, transport, params) {
|
|
|
2165
2503
|
secrets
|
|
2166
2504
|
};
|
|
2167
2505
|
}
|
|
2168
|
-
var import_base6, import_solver_discovery, import_legacy2,
|
|
2506
|
+
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
2507
|
var init_rfq = __esm({
|
|
2170
2508
|
"src/rfq.ts"() {
|
|
2171
2509
|
"use strict";
|
|
2172
2510
|
import_base6 = require("@scure/base");
|
|
2173
2511
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
2174
2512
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
2175
|
-
|
|
2513
|
+
import_sdk7 = require("@arkade-os/sdk");
|
|
2176
2514
|
init_onchainHtlc();
|
|
2177
2515
|
init_onchainHtlc();
|
|
2178
|
-
|
|
2516
|
+
import_sdk8 = require("@arkade-os/sdk");
|
|
2179
2517
|
init_claimAmountGate();
|
|
2180
2518
|
init_claimPacket();
|
|
2181
2519
|
init_lockupContract();
|
|
2182
2520
|
init_offer();
|
|
2521
|
+
init_program();
|
|
2522
|
+
init_rfq_contract();
|
|
2183
2523
|
solverHex = (value, field) => {
|
|
2184
2524
|
try {
|
|
2185
2525
|
return import_base6.hex.decode(value);
|
|
@@ -2217,6 +2557,7 @@ var init_rfq = __esm({
|
|
|
2217
2557
|
RFQ_TERMINAL_STATES = ["settled", "refused", "expired", "refunded", "stuck"];
|
|
2218
2558
|
RFQ_REFUSAL_ERROR_CODES = [
|
|
2219
2559
|
"amount_side_unsupported",
|
|
2560
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED,
|
|
2220
2561
|
"exact_out_unsupported",
|
|
2221
2562
|
"invalid_amount",
|
|
2222
2563
|
"invalid_payout_address",
|
|
@@ -2332,6 +2673,7 @@ var init_rfq = __esm({
|
|
|
2332
2673
|
pair,
|
|
2333
2674
|
amount_side: input.amountSide ?? "from",
|
|
2334
2675
|
amount: canonicalAssetAmount(input.amount),
|
|
2676
|
+
...input.contractVersions && input.contractVersions.length > 0 ? { [RFQ_CONTRACT_VERSIONS_KEY]: [...input.contractVersions] } : {},
|
|
2335
2677
|
// The solver's `.strict()` schema refuses any undeclared key as `unsupported_payload`.
|
|
2336
2678
|
profile: {
|
|
2337
2679
|
maker_pk_script: normalizeMakerPkScript(input.makerPkScript),
|
|
@@ -2519,6 +2861,34 @@ var init_rfq = __esm({
|
|
|
2519
2861
|
}
|
|
2520
2862
|
return payload;
|
|
2521
2863
|
};
|
|
2864
|
+
requestVersionedQuote = async (transport, request, advertised) => {
|
|
2865
|
+
if (advertised.length === 0) {
|
|
2866
|
+
throw new Error("contractVersions is empty: advertise at least one contract version");
|
|
2867
|
+
}
|
|
2868
|
+
let sent = request;
|
|
2869
|
+
let quote;
|
|
2870
|
+
try {
|
|
2871
|
+
quote = await transport.requestQuote(request);
|
|
2872
|
+
} catch (error) {
|
|
2873
|
+
if (!(error instanceof SwapRefusal) || error.reason !== "unsupported_payload" || error.errorCode !== void 0 || !advertised.includes(ASSET_SWAP_BASELINE)) {
|
|
2874
|
+
throw error;
|
|
2875
|
+
}
|
|
2876
|
+
const { [RFQ_CONTRACT_VERSIONS_KEY]: _, ...baseline } = request;
|
|
2877
|
+
sent = { ...baseline, rfq_id: newRfqId() };
|
|
2878
|
+
quote = await transport.requestQuote(sent);
|
|
2879
|
+
}
|
|
2880
|
+
const selected = quote[RFQ_CONTRACT_VERSION_KEY];
|
|
2881
|
+
if (sent !== request && selected !== void 0) {
|
|
2882
|
+
throw new Error(`solver chose contract version ${selected}, but none was advertised`);
|
|
2883
|
+
}
|
|
2884
|
+
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2885
|
+
if (!advertised.includes(version)) {
|
|
2886
|
+
throw new Error(
|
|
2887
|
+
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2888
|
+
);
|
|
2889
|
+
}
|
|
2890
|
+
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
2891
|
+
};
|
|
2522
2892
|
pairOf = (payload) => typeof payload.pair === "string" ? payload.pair : void 0;
|
|
2523
2893
|
httpTransport = (baseUrl, options = {}) => {
|
|
2524
2894
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
@@ -2557,7 +2927,7 @@ var init_rfq = __esm({
|
|
|
2557
2927
|
};
|
|
2558
2928
|
relayTransport = (relayUrl, options) => {
|
|
2559
2929
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
2560
|
-
(0,
|
|
2930
|
+
(0, import_sdk7.assertTimerMs)("timeoutMs", timeoutMs);
|
|
2561
2931
|
const Ctor = options.WebSocketCtor ?? WebSocket;
|
|
2562
2932
|
const pending = /* @__PURE__ */ new Map();
|
|
2563
2933
|
let sequence = 0;
|
|
@@ -2661,7 +3031,7 @@ var init_rfq = __esm({
|
|
|
2661
3031
|
type: "seconds",
|
|
2662
3032
|
value: BigInt(value)
|
|
2663
3033
|
});
|
|
2664
|
-
suiteVhtlc = (params, roles) => new
|
|
3034
|
+
suiteVhtlc = (params, roles) => new import_sdk7.VHTLC.ScriptV2({
|
|
2665
3035
|
sender: roles.sender,
|
|
2666
3036
|
receiver: roles.receiver,
|
|
2667
3037
|
server: params.operatorPubkey,
|
|
@@ -2731,11 +3101,11 @@ var init_rfq = __esm({
|
|
|
2731
3101
|
};
|
|
2732
3102
|
l1NetworkFromArk = (network) => network === "bitcoin" ? "bitcoin" : network === "regtest" ? "regtest" : "testnet";
|
|
2733
3103
|
operatorTerms = (info, emulatorPubkey) => {
|
|
2734
|
-
const network = (0,
|
|
3104
|
+
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
2735
3105
|
return {
|
|
2736
|
-
operatorPubkey: (0,
|
|
2737
|
-
emulatorPubkey: (0,
|
|
2738
|
-
import_base6.hex.decode((0,
|
|
3106
|
+
operatorPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(info.signerPubkey), "ark signer key"),
|
|
3107
|
+
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
3108
|
+
import_base6.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, emulatorPubkey)),
|
|
2739
3109
|
"emulator signer key"
|
|
2740
3110
|
),
|
|
2741
3111
|
claimDelay: unilateralClaimDelay(Number(info.unilateralExitDelay)),
|
|
@@ -2854,7 +3224,7 @@ var init_rfq = __esm({
|
|
|
2854
3224
|
};
|
|
2855
3225
|
matchReceiveLockup = (input, refundLocktime, solverRefundPkScriptHex) => {
|
|
2856
3226
|
const contractParams = {
|
|
2857
|
-
solverPubkey: (0,
|
|
3227
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(input.quote.solver_pubkey), "solver key"),
|
|
2858
3228
|
refundLocktime,
|
|
2859
3229
|
operatorPubkey: input.operatorPubkey,
|
|
2860
3230
|
paymentHash: input.paymentHash,
|
|
@@ -2862,7 +3232,7 @@ var init_rfq = __esm({
|
|
|
2862
3232
|
emulatorPubkey: input.emulatorPubkey,
|
|
2863
3233
|
solverRefundPkScript: solverHex(solverRefundPkScriptHex, "profile.solver_refund_pk_script"),
|
|
2864
3234
|
payoutPubkey: input.payoutPubkey,
|
|
2865
|
-
payoutPkScript:
|
|
3235
|
+
payoutPkScript: import_sdk7.ArkAddress.decode(input.payoutAddress).pkScript
|
|
2866
3236
|
};
|
|
2867
3237
|
const matched = matchQuotedLockup(
|
|
2868
3238
|
input.quote,
|
|
@@ -2874,7 +3244,7 @@ var init_rfq = __esm({
|
|
|
2874
3244
|
};
|
|
2875
3245
|
provisionReceive = async (wallet, params, persistBefore) => {
|
|
2876
3246
|
const [secrets, info, payoutAddress] = await Promise.all([
|
|
2877
|
-
(0,
|
|
3247
|
+
(0, import_sdk8.provisionClaimSecret)(wallet),
|
|
2878
3248
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
2879
3249
|
wallet.getAddress()
|
|
2880
3250
|
]);
|
|
@@ -3057,14 +3427,14 @@ __export(nostr_exports, {
|
|
|
3057
3427
|
nostrRfqTransport: () => nostrRfqTransport,
|
|
3058
3428
|
sharedNostrPool: () => sharedNostrPool
|
|
3059
3429
|
});
|
|
3060
|
-
var import_solver_discovery4,
|
|
3430
|
+
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
3431
|
var init_nostr = __esm({
|
|
3062
3432
|
"src/nostr.ts"() {
|
|
3063
3433
|
"use strict";
|
|
3064
3434
|
import_solver_discovery4 = require("@arkade-os/solver-discovery");
|
|
3065
3435
|
init_rfq();
|
|
3066
3436
|
init_nostrPool();
|
|
3067
|
-
|
|
3437
|
+
import_sdk18 = require("@arkade-os/sdk");
|
|
3068
3438
|
import_nostr_tools2 = require("nostr-tools");
|
|
3069
3439
|
init_nostrPool();
|
|
3070
3440
|
RFQ_DIRECTED_KIND = 24859;
|
|
@@ -3091,7 +3461,7 @@ var init_nostr = __esm({
|
|
|
3091
3461
|
return url ? `${url}: ${reason ?? "closed"}` : reason ?? "closed";
|
|
3092
3462
|
});
|
|
3093
3463
|
nostrRfqTransport = (options) => {
|
|
3094
|
-
(0,
|
|
3464
|
+
(0, import_sdk18.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
3095
3465
|
const relays = options.relays;
|
|
3096
3466
|
const solverPubkey = options.solverPubkey;
|
|
3097
3467
|
const secretKey = options.secretKey ?? (0, import_nostr_tools2.generateSecretKey)();
|
|
@@ -3203,7 +3573,7 @@ var init_nostr = __esm({
|
|
|
3203
3573
|
};
|
|
3204
3574
|
isNewer = (event, held) => !held || event.created_at > held.created_at || event.created_at === held.created_at && event.id < held.id;
|
|
3205
3575
|
nostrCardFetcher = (options = {}) => {
|
|
3206
|
-
(0,
|
|
3576
|
+
(0, import_sdk18.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
3207
3577
|
if (options.timeoutMs === 0) throw new Error("timeoutMs must be positive");
|
|
3208
3578
|
const seen = /* @__PURE__ */ new Map();
|
|
3209
3579
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -3285,6 +3655,10 @@ var protocol_exports = {};
|
|
|
3285
3655
|
__export(protocol_exports, {
|
|
3286
3656
|
ARKADE_BTC: () => ARKADE_BTC,
|
|
3287
3657
|
ASSET_CARRIER_SATS: () => ASSET_CARRIER_SATS,
|
|
3658
|
+
ASSET_SWAP_BASELINE: () => ASSET_SWAP_BASELINE,
|
|
3659
|
+
ASSET_SWAP_CONTRACT_VERSIONS: () => ASSET_SWAP_CONTRACT_VERSIONS,
|
|
3660
|
+
ASSET_SWAP_V2: () => ASSET_SWAP_V2,
|
|
3661
|
+
ASSET_SWAP_V3: () => ASSET_SWAP_V3,
|
|
3288
3662
|
AddressMismatch: () => AddressMismatch,
|
|
3289
3663
|
BTC_ASSET_ID: () => BTC_ASSET_ID,
|
|
3290
3664
|
CROSS_ASSET_RAIL: () => CROSS_ASSET_RAIL,
|
|
@@ -3325,6 +3699,7 @@ __export(protocol_exports, {
|
|
|
3325
3699
|
arkadeRefunder: () => arkadeRefunder,
|
|
3326
3700
|
arkadeSwapRequest: () => arkadeSwapRequest,
|
|
3327
3701
|
assertArkadeFundable: () => assertArkadeFundable,
|
|
3702
|
+
assetSwapContractVersion: () => assetSwapContractVersion,
|
|
3328
3703
|
awaitOnchainFill: () => awaitOnchainFill,
|
|
3329
3704
|
awaitRfqResolution: () => awaitRfqResolution,
|
|
3330
3705
|
buildHtlcClaim: () => buildHtlcClaim,
|
|
@@ -3418,18 +3793,18 @@ __export(protocol_exports, {
|
|
|
3418
3793
|
module.exports = __toCommonJS(protocol_exports);
|
|
3419
3794
|
|
|
3420
3795
|
// src/activity.ts
|
|
3421
|
-
var
|
|
3796
|
+
var import_sdk16 = require("@arkade-os/sdk");
|
|
3422
3797
|
var import_base11 = require("@scure/base");
|
|
3423
3798
|
|
|
3424
3799
|
// src/swapManager.ts
|
|
3425
3800
|
var import_base10 = require("@scure/base");
|
|
3426
|
-
var
|
|
3801
|
+
var import_sdk12 = require("@arkade-os/sdk");
|
|
3427
3802
|
init_onchainHtlc();
|
|
3428
3803
|
|
|
3429
3804
|
// src/refund.ts
|
|
3430
3805
|
var import_base7 = require("@scure/base");
|
|
3431
3806
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
3432
|
-
var
|
|
3807
|
+
var import_sdk9 = require("@arkade-os/sdk");
|
|
3433
3808
|
init_onchainHtlc();
|
|
3434
3809
|
init_rfq();
|
|
3435
3810
|
var isRfqTerminal = (state) => RFQ_TERMINAL_STATES.includes(state);
|
|
@@ -3470,7 +3845,7 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3470
3845
|
const out = [];
|
|
3471
3846
|
for (const vtxo of row?.vtxos ?? []) {
|
|
3472
3847
|
if (vtxo.isUnrolled) continue;
|
|
3473
|
-
if ((0,
|
|
3848
|
+
if ((0, import_sdk9.isVtxoSpent)(vtxo)) continue;
|
|
3474
3849
|
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
3475
3850
|
if (seen.has(key)) continue;
|
|
3476
3851
|
seen.add(key);
|
|
@@ -3486,17 +3861,17 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3486
3861
|
}
|
|
3487
3862
|
var hashesTo = (candidate, paymentHash) => import_base7.hex.encode((0, import_sha24.sha256)(candidate)) === paymentHash;
|
|
3488
3863
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
3489
|
-
...(0,
|
|
3864
|
+
...(0, import_sdk9.getArkPsbtFields)(tx, inputIndex, import_sdk9.ConditionWitness).flat(),
|
|
3490
3865
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
3491
3866
|
];
|
|
3492
3867
|
var refundLeafScript = (tx, inputIndex) => {
|
|
3493
3868
|
const input = tx.getInput(inputIndex);
|
|
3494
3869
|
const witness = input.finalScriptWitness;
|
|
3495
3870
|
const leaves = input.tapLeafScript ?? [];
|
|
3496
|
-
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0,
|
|
3871
|
+
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0, import_sdk9.scriptFromTapLeafScript)(leaves[0]) : void 0;
|
|
3497
3872
|
if (!script) return void 0;
|
|
3498
3873
|
try {
|
|
3499
|
-
const { type } = (0,
|
|
3874
|
+
const { type } = (0, import_sdk9.decodeTapscript)(script);
|
|
3500
3875
|
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
|
|
3501
3876
|
} catch {
|
|
3502
3877
|
return void 0;
|
|
@@ -3506,7 +3881,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3506
3881
|
const { vtxos } = await indexer.getVtxos({ scripts: [import_base7.hex.encode(input.swapPkScript)] });
|
|
3507
3882
|
const all = vtxos ?? [];
|
|
3508
3883
|
if (all.length === 0) return { fate: "unknown" };
|
|
3509
|
-
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0,
|
|
3884
|
+
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0, import_sdk9.isVtxoSpent)(vtxo));
|
|
3510
3885
|
if (exited.length > 0) {
|
|
3511
3886
|
return {
|
|
3512
3887
|
fate: "exited",
|
|
@@ -3518,7 +3893,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3518
3893
|
let sweptLeft = false;
|
|
3519
3894
|
let live = false;
|
|
3520
3895
|
for (const vtxo of all) {
|
|
3521
|
-
if (!(0,
|
|
3896
|
+
if (!(0, import_sdk9.isVtxoSpent)(vtxo)) {
|
|
3522
3897
|
if (input.receiver && vtxo.isSwept) sweptLeft = true;
|
|
3523
3898
|
else live = true;
|
|
3524
3899
|
continue;
|
|
@@ -3545,7 +3920,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3545
3920
|
for (const raw of txs) {
|
|
3546
3921
|
let tx;
|
|
3547
3922
|
try {
|
|
3548
|
-
tx =
|
|
3923
|
+
tx = import_sdk9.Transaction.fromPSBT(import_base7.base64.decode(raw));
|
|
3549
3924
|
} catch {
|
|
3550
3925
|
continue;
|
|
3551
3926
|
}
|
|
@@ -3595,10 +3970,10 @@ var assertNoneSwept = (vtxos, contract) => {
|
|
|
3595
3970
|
};
|
|
3596
3971
|
var operatorUnrollScript = async (operator, network) => {
|
|
3597
3972
|
const info = await operator.getInfo();
|
|
3598
|
-
return (0,
|
|
3973
|
+
return (0, import_sdk9.assertValidServerUnrollScript)(
|
|
3599
3974
|
info.checkpointTapscript,
|
|
3600
|
-
network ?? (0,
|
|
3601
|
-
(0,
|
|
3975
|
+
network ?? (0, import_sdk9.networkFromOperatorInfo)(info),
|
|
3976
|
+
(0, import_sdk9.toXOnly)(import_base7.hex.decode(info.forfeitPubkey), "forfeit key")
|
|
3602
3977
|
);
|
|
3603
3978
|
};
|
|
3604
3979
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
@@ -3618,7 +3993,7 @@ var lockupAssetOutputs = (vtxos) => {
|
|
|
3618
3993
|
address: "",
|
|
3619
3994
|
assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
|
|
3620
3995
|
};
|
|
3621
|
-
return [
|
|
3996
|
+
return [import_sdk9.Extension.create([(0, import_sdk9.createAssetPacket)(inputs, [receiver])]).txOut()];
|
|
3622
3997
|
};
|
|
3623
3998
|
var lockupInputs = (vtxos, contract, leaf) => {
|
|
3624
3999
|
const tapTree = contract.encode();
|
|
@@ -3643,7 +4018,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
3643
4018
|
const leaf = input.contract.refundWithoutReceiver();
|
|
3644
4019
|
const vtxos = boundedLockupSpend(input.vtxos);
|
|
3645
4020
|
const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
3646
|
-
const txid = await (0,
|
|
4021
|
+
const txid = await (0, import_sdk9.signAndSubmitOffchainTx)({
|
|
3647
4022
|
identity: input.sender,
|
|
3648
4023
|
provider: operator,
|
|
3649
4024
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
@@ -3665,7 +4040,7 @@ init_lockupContract();
|
|
|
3665
4040
|
init_repository();
|
|
3666
4041
|
|
|
3667
4042
|
// src/rfqRecord.ts
|
|
3668
|
-
var
|
|
4043
|
+
var import_sdk10 = require("@arkade-os/sdk");
|
|
3669
4044
|
var import_base9 = require("@scure/base");
|
|
3670
4045
|
|
|
3671
4046
|
// src/rfqSwapState.ts
|
|
@@ -3915,7 +4290,7 @@ function assertSameSwap(origin, swap) {
|
|
|
3915
4290
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
3916
4291
|
);
|
|
3917
4292
|
}
|
|
3918
|
-
const funded = import_base9.hex.encode(
|
|
4293
|
+
const funded = import_base9.hex.encode(import_sdk10.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
3919
4294
|
const watched = import_base9.hex.encode(swap.lockupPkScript);
|
|
3920
4295
|
if (funded !== watched) {
|
|
3921
4296
|
throw new Error(
|
|
@@ -3962,8 +4337,8 @@ function rfqSwapOriginOf(record) {
|
|
|
3962
4337
|
};
|
|
3963
4338
|
}
|
|
3964
4339
|
function lockupScript(params, lockupAddress) {
|
|
3965
|
-
const script =
|
|
3966
|
-
const funded =
|
|
4340
|
+
const script = import_sdk10.VHTLCV2ContractHandler.createScript(params);
|
|
4341
|
+
const funded = import_sdk10.ArkAddress.decode(lockupAddress).pkScript;
|
|
3967
4342
|
if (import_base9.hex.encode(funded) !== import_base9.hex.encode(script.pkScript)) {
|
|
3968
4343
|
throw new Error(
|
|
3969
4344
|
`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 +4374,7 @@ function shouldRetainRfqSwap(record, now) {
|
|
|
3999
4374
|
}
|
|
4000
4375
|
|
|
4001
4376
|
// src/refundBlocked.ts
|
|
4002
|
-
var
|
|
4377
|
+
var import_sdk11 = require("@arkade-os/sdk");
|
|
4003
4378
|
var RefundNotLocallyPossibleError = class extends Error {
|
|
4004
4379
|
constructor(reason, message, options) {
|
|
4005
4380
|
super(message, options);
|
|
@@ -4016,16 +4391,16 @@ async function senderIdentityForSwapRecord(wallet, record) {
|
|
|
4016
4391
|
);
|
|
4017
4392
|
}
|
|
4018
4393
|
try {
|
|
4019
|
-
return await (0,
|
|
4394
|
+
return await (0, import_sdk11.contractSigner)(wallet, record.signingDescriptor);
|
|
4020
4395
|
} catch (cause) {
|
|
4021
|
-
if (cause instanceof
|
|
4396
|
+
if (cause instanceof import_sdk11.WalletCannotSignError) {
|
|
4022
4397
|
throw new RefundNotLocallyPossibleError(
|
|
4023
4398
|
"unsignable-wallet",
|
|
4024
4399
|
`this wallet holds ${record.signingDescriptor} but cannot sign with it; attach its signer`,
|
|
4025
4400
|
{ cause }
|
|
4026
4401
|
);
|
|
4027
4402
|
}
|
|
4028
|
-
if (cause instanceof
|
|
4403
|
+
if (cause instanceof import_sdk11.ForeignDescriptorError) {
|
|
4029
4404
|
throw new RefundNotLocallyPossibleError(
|
|
4030
4405
|
"foreign-descriptor",
|
|
4031
4406
|
`this wallet cannot derive ${record.signingDescriptor}; the swap was created on another wallet`,
|
|
@@ -4163,7 +4538,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4163
4538
|
timer = null;
|
|
4164
4539
|
running = false;
|
|
4165
4540
|
constructor(deps, config = {}) {
|
|
4166
|
-
(0,
|
|
4541
|
+
(0, import_sdk12.assertTimerMs)("pollIntervalMs", config.pollIntervalMs);
|
|
4167
4542
|
this.deps = deps;
|
|
4168
4543
|
this.config = {
|
|
4169
4544
|
enableAutoActions: config.enableAutoActions ?? true,
|
|
@@ -4547,7 +4922,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4547
4922
|
});
|
|
4548
4923
|
return;
|
|
4549
4924
|
}
|
|
4550
|
-
if (!(0,
|
|
4925
|
+
if (!(0, import_sdk12.isContractVtxoEvent)(event)) return;
|
|
4551
4926
|
const swap = this.byLockupScript.get(event.contractScript);
|
|
4552
4927
|
if (!swap) return;
|
|
4553
4928
|
void this.pollSwap(swap).catch(() => {
|
|
@@ -4817,8 +5192,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4817
5192
|
this.setState(swap, "claimed");
|
|
4818
5193
|
this.emitAction(swap, "claimLockup");
|
|
4819
5194
|
} catch (error) {
|
|
4820
|
-
const ark = (0,
|
|
4821
|
-
if ((0,
|
|
5195
|
+
const ark = (0, import_sdk12.isArkError)(error) ? error : (0, import_sdk12.maybeArkError)(error);
|
|
5196
|
+
if ((0, import_sdk12.isArkError)(ark, import_sdk12.ArkErrorName.VTXO_ALREADY_SPENT)) {
|
|
4822
5197
|
if (swap.claimFailure !== void 0) {
|
|
4823
5198
|
delete swap.claimFailure;
|
|
4824
5199
|
this.touch(swap);
|
|
@@ -5109,8 +5484,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
5109
5484
|
this.refundRefused.add(swap.rfqId);
|
|
5110
5485
|
return this.block(swap, error.message);
|
|
5111
5486
|
}
|
|
5112
|
-
const ark = (0,
|
|
5113
|
-
if ((0,
|
|
5487
|
+
const ark = (0, import_sdk12.isArkError)(error) ? error : (0, import_sdk12.maybeArkError)(error);
|
|
5488
|
+
if ((0, import_sdk12.isArkError)(ark, import_sdk12.ArkErrorName.VTXO_ALREADY_SPENT)) return;
|
|
5114
5489
|
this.emitFailed(swap, error);
|
|
5115
5490
|
if (now >= swap.refundLocktime + REFUND_MTP_LAG_SECONDS) {
|
|
5116
5491
|
swap.failure = errorMessage(error);
|
|
@@ -5302,7 +5677,7 @@ var errorMessage = (error) => error instanceof Error ? error.message : String(er
|
|
|
5302
5677
|
var outpointKey = (vtxo) => `${vtxo.txid}:${vtxo.vout}`;
|
|
5303
5678
|
|
|
5304
5679
|
// src/client/assetPayment.ts
|
|
5305
|
-
var
|
|
5680
|
+
var import_sdk13 = require("@arkade-os/sdk");
|
|
5306
5681
|
var import_solver_discovery2 = require("@arkade-os/solver-discovery");
|
|
5307
5682
|
var MAX_SATS = 2100000000000000n;
|
|
5308
5683
|
var MAX_BITCOIN_SATS_DECIMAL = MAX_SATS.toString();
|
|
@@ -5312,7 +5687,7 @@ var import_solver_discovery3 = require("@arkade-os/solver-discovery");
|
|
|
5312
5687
|
var ATOMIC_CEILING = 10n ** 30n;
|
|
5313
5688
|
|
|
5314
5689
|
// src/client/corridors/lightning.ts
|
|
5315
|
-
var
|
|
5690
|
+
var import_sdk14 = require("@arkade-os/sdk");
|
|
5316
5691
|
var INVOICE_HRPS = [
|
|
5317
5692
|
["lnbcrt", ["regtest"]],
|
|
5318
5693
|
["lntbs", ["signet", "mutinynet"]],
|
|
@@ -5342,7 +5717,7 @@ var lightningCorridor = Object.assign(
|
|
|
5342
5717
|
deps,
|
|
5343
5718
|
drive: LIGHTNING_DRIVE,
|
|
5344
5719
|
matches(raw) {
|
|
5345
|
-
const invoice = (0,
|
|
5720
|
+
const invoice = (0, import_sdk14.invoiceTarget)(raw);
|
|
5346
5721
|
if (invoice === void 0) return void 0;
|
|
5347
5722
|
const networks = networksOfInvoiceHrp(invoice);
|
|
5348
5723
|
if (networks === void 0) {
|
|
@@ -5388,11 +5763,11 @@ var lightningCorridor = Object.assign(
|
|
|
5388
5763
|
};
|
|
5389
5764
|
}
|
|
5390
5765
|
}),
|
|
5391
|
-
{ target:
|
|
5766
|
+
{ target: import_sdk14.invoiceTarget }
|
|
5392
5767
|
);
|
|
5393
5768
|
|
|
5394
5769
|
// src/client/corridors/onchain.ts
|
|
5395
|
-
var
|
|
5770
|
+
var import_sdk15 = require("@arkade-os/sdk");
|
|
5396
5771
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
5397
5772
|
init_onchainHtlc();
|
|
5398
5773
|
init_rfq();
|
|
@@ -5422,14 +5797,14 @@ var onchainCorridor = Object.assign(
|
|
|
5422
5797
|
deps,
|
|
5423
5798
|
drive: ONCHAIN_DRIVE,
|
|
5424
5799
|
matches(raw) {
|
|
5425
|
-
const target = (0,
|
|
5800
|
+
const target = (0, import_sdk15.btcTarget)(raw);
|
|
5426
5801
|
if (target === void 0) return void 0;
|
|
5427
5802
|
try {
|
|
5428
5803
|
btc2.Address(L1_NETWORKS[l1]).decode(target);
|
|
5429
5804
|
} catch {
|
|
5430
5805
|
return { refused: `this is not a ${l1} address` };
|
|
5431
5806
|
}
|
|
5432
|
-
const amount =
|
|
5807
|
+
const amount = import_sdk15.BIP21.amountSats(raw);
|
|
5433
5808
|
return {
|
|
5434
5809
|
claimed: {
|
|
5435
5810
|
kind: "address",
|
|
@@ -5440,7 +5815,7 @@ var onchainCorridor = Object.assign(
|
|
|
5440
5815
|
}
|
|
5441
5816
|
};
|
|
5442
5817
|
},
|
|
5443
|
-
{ target:
|
|
5818
|
+
{ target: import_sdk15.btcTarget }
|
|
5444
5819
|
);
|
|
5445
5820
|
|
|
5446
5821
|
// src/client/outcome.ts
|
|
@@ -5572,7 +5947,7 @@ async function activityInputOf(stored, indexer) {
|
|
|
5572
5947
|
async function lockupTxids(indexer, record, wantFunding) {
|
|
5573
5948
|
let script;
|
|
5574
5949
|
try {
|
|
5575
|
-
script = import_base11.hex.encode(
|
|
5950
|
+
script = import_base11.hex.encode(import_sdk16.ArkAddress.decode(record.lockupAddress).pkScript);
|
|
5576
5951
|
} catch {
|
|
5577
5952
|
return [];
|
|
5578
5953
|
}
|
|
@@ -5679,7 +6054,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
5679
6054
|
|
|
5680
6055
|
// src/claim.ts
|
|
5681
6056
|
var import_base13 = require("@scure/base");
|
|
5682
|
-
var
|
|
6057
|
+
var import_sdk17 = require("@arkade-os/sdk");
|
|
5683
6058
|
init_onchainHtlc();
|
|
5684
6059
|
var LockupAmountMismatchError = class extends Error {
|
|
5685
6060
|
name = "LockupAmountMismatchError";
|
|
@@ -5715,8 +6090,8 @@ async function pushClaim(operator, input) {
|
|
|
5715
6090
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
5716
6091
|
const serverUnrollScript = await operatorUnrollScript(operator, input.network);
|
|
5717
6092
|
const leaf = input.contract.claim();
|
|
5718
|
-
const txid = await (0,
|
|
5719
|
-
identity: (0,
|
|
6093
|
+
const txid = await (0, import_sdk17.signAndSubmitOffchainTx)({
|
|
6094
|
+
identity: (0, import_sdk17.claimWithPreimageIdentity)(input.receiver, input.preimage),
|
|
5720
6095
|
provider: operator,
|
|
5721
6096
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
5722
6097
|
// One aggregate output: this leaf inspects nothing about the output set.
|
|
@@ -5737,7 +6112,7 @@ init_lockupContract();
|
|
|
5737
6112
|
|
|
5738
6113
|
// src/markets.ts
|
|
5739
6114
|
var import_solver_discovery5 = require("@arkade-os/solver-discovery");
|
|
5740
|
-
var
|
|
6115
|
+
var import_sdk19 = require("@arkade-os/sdk");
|
|
5741
6116
|
|
|
5742
6117
|
// src/marketShape.ts
|
|
5743
6118
|
var MARKET_CORRIDORS = ["arkade", "bolt11", "bitcoin", "eip155"];
|
|
@@ -5772,7 +6147,7 @@ var marketCorridor = (market, side) => {
|
|
|
5772
6147
|
init_store();
|
|
5773
6148
|
var QUOTE_OPTIONS = { safetyBps: 0 };
|
|
5774
6149
|
var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
|
|
5775
|
-
(0,
|
|
6150
|
+
(0, import_sdk19.assertNonNegativeMs)("ttlMs", ttlMs);
|
|
5776
6151
|
const cache = /* @__PURE__ */ new Map();
|
|
5777
6152
|
const inflight = /* @__PURE__ */ new Map();
|
|
5778
6153
|
return async (input, init) => {
|
|
@@ -5950,7 +6325,7 @@ var discoverMarkets = async (options) => {
|
|
|
5950
6325
|
return markets;
|
|
5951
6326
|
};
|
|
5952
6327
|
var watchMarkets = (options, onMarkets) => {
|
|
5953
|
-
(0,
|
|
6328
|
+
(0, import_sdk19.assertTimerMs)("intervalMs", options.intervalMs);
|
|
5954
6329
|
if (options.intervalMs === 0) throw new Error("intervalMs must be positive");
|
|
5955
6330
|
let digest;
|
|
5956
6331
|
let reading = false;
|
|
@@ -6028,23 +6403,24 @@ var validatePlan = (plan, giveBalance, dust) => {
|
|
|
6028
6403
|
const receiveIsBtc = plan.receive.asset.id === BTC_ASSET_ID;
|
|
6029
6404
|
if (depositIsBtc || receiveIsBtc) {
|
|
6030
6405
|
const btcSide = depositIsBtc ? plan.deposit.atomic : plan.receive.atomic;
|
|
6031
|
-
if ((0,
|
|
6406
|
+
if ((0, import_sdk19.isSubdust)(btcSide, dust)) return "below-dust";
|
|
6032
6407
|
}
|
|
6033
6408
|
return void 0;
|
|
6034
6409
|
};
|
|
6035
6410
|
|
|
6036
6411
|
// src/protocol.ts
|
|
6037
6412
|
init_offer();
|
|
6413
|
+
init_program();
|
|
6038
6414
|
init_onchainHtlc();
|
|
6039
6415
|
|
|
6040
6416
|
// src/payment/crossAsset.ts
|
|
6041
|
-
var
|
|
6417
|
+
var import_sdk20 = require("@arkade-os/sdk");
|
|
6042
6418
|
init_offer();
|
|
6043
6419
|
init_store();
|
|
6044
6420
|
var CROSS_ASSET_RAIL = "cross-asset";
|
|
6045
6421
|
var parseAssetId = (assetId) => {
|
|
6046
6422
|
try {
|
|
6047
|
-
return
|
|
6423
|
+
return import_sdk20.asset.AssetId.fromString(assetId);
|
|
6048
6424
|
} catch {
|
|
6049
6425
|
return void 0;
|
|
6050
6426
|
}
|
|
@@ -6062,9 +6438,9 @@ function crossAssetRail(deps) {
|
|
|
6062
6438
|
};
|
|
6063
6439
|
return {
|
|
6064
6440
|
id: CROSS_ASSET_RAIL,
|
|
6065
|
-
match: (req) => (0,
|
|
6441
|
+
match: (req) => (0, import_sdk20.arkTarget)(req.raw) !== void 0,
|
|
6066
6442
|
available: async (req) => {
|
|
6067
|
-
const assets = (0,
|
|
6443
|
+
const assets = (0, import_sdk20.assetsOf)(req);
|
|
6068
6444
|
if (assets.length !== 1) return false;
|
|
6069
6445
|
const [asset4] = assets;
|
|
6070
6446
|
if (asset4.assetId === BTC_ASSET_ID) return false;
|
|
@@ -6074,8 +6450,8 @@ function crossAssetRail(deps) {
|
|
|
6074
6450
|
return planned !== void 0 && planned.error === void 0;
|
|
6075
6451
|
},
|
|
6076
6452
|
quote: async (req, ctx) => {
|
|
6077
|
-
const payTo = (0,
|
|
6078
|
-
const asset4 = (0,
|
|
6453
|
+
const payTo = (0, import_sdk20.arkTarget)(req.raw);
|
|
6454
|
+
const asset4 = (0, import_sdk20.resolveAssetAmount)(CROSS_ASSET_RAIL, req);
|
|
6079
6455
|
const wantAsset = parseAssetId(asset4.assetId);
|
|
6080
6456
|
if (!wantAsset) {
|
|
6081
6457
|
throw new Error(
|
|
@@ -6098,7 +6474,7 @@ function crossAssetRail(deps) {
|
|
|
6098
6474
|
);
|
|
6099
6475
|
}
|
|
6100
6476
|
const depositSats = Number(plan.deposit.atomic);
|
|
6101
|
-
const carrier = deps.carrierSats ??
|
|
6477
|
+
const carrier = deps.carrierSats ?? import_sdk20.ASSET_CARRIER_SATS;
|
|
6102
6478
|
return {
|
|
6103
6479
|
railId: CROSS_ASSET_RAIL,
|
|
6104
6480
|
// OPEN QUESTION for review: `total = amount + fee` forces the
|
|
@@ -6116,7 +6492,7 @@ function crossAssetRail(deps) {
|
|
|
6116
6492
|
priceDisplay: plan.priceDisplay,
|
|
6117
6493
|
give: plan.give
|
|
6118
6494
|
},
|
|
6119
|
-
send: async () => (0,
|
|
6495
|
+
send: async () => (0, import_sdk20.makeHandle)(CROSS_ASSET_RAIL, async (emit) => {
|
|
6120
6496
|
const offer = await createOffer(ctx.wallet, {
|
|
6121
6497
|
wantAmount: asset4.amount,
|
|
6122
6498
|
wantAsset,
|
|
@@ -6200,11 +6576,11 @@ var solverRendezvous = (markets, payoutCorridor, amountSats, fallbackEmulatorPub
|
|
|
6200
6576
|
};
|
|
6201
6577
|
|
|
6202
6578
|
// src/payment/solverLightning.ts
|
|
6203
|
-
var
|
|
6579
|
+
var import_sdk22 = require("@arkade-os/sdk");
|
|
6204
6580
|
init_rfq();
|
|
6205
6581
|
|
|
6206
6582
|
// src/payment/solverOnchain.ts
|
|
6207
|
-
var
|
|
6583
|
+
var import_sdk21 = require("@arkade-os/sdk");
|
|
6208
6584
|
init_rfq();
|
|
6209
6585
|
init_onchainHtlc();
|
|
6210
6586
|
var SOLVER_ONCHAIN_RAIL = "solver-onchain";
|
|
@@ -6233,24 +6609,24 @@ function solverOnchainRail(deps) {
|
|
|
6233
6609
|
const rendezvousFor = async (amount) => solverOnchainRendezvous(await deps.discover(), amount, deps.fallbackEmulatorPubkey);
|
|
6234
6610
|
return {
|
|
6235
6611
|
id: SOLVER_ONCHAIN_RAIL,
|
|
6236
|
-
match: (req) => (0,
|
|
6612
|
+
match: (req) => (0, import_sdk21.btcTarget)(req.raw) !== void 0,
|
|
6237
6613
|
available: async (req) => {
|
|
6238
|
-
if ((0,
|
|
6239
|
-
const address = (0,
|
|
6614
|
+
if ((0, import_sdk21.assetsOf)(req).length > 0) return false;
|
|
6615
|
+
const address = (0, import_sdk21.btcTarget)(req.raw);
|
|
6240
6616
|
if (!address) return false;
|
|
6241
6617
|
try {
|
|
6242
6618
|
l1ScriptForAddress(address, deps.l1Network);
|
|
6243
6619
|
} catch {
|
|
6244
6620
|
return false;
|
|
6245
6621
|
}
|
|
6246
|
-
const amount = (0,
|
|
6622
|
+
const amount = (0, import_sdk21.tryResolveSendAmount)(req.raw, req.amount);
|
|
6247
6623
|
if (amount === void 0) return false;
|
|
6248
6624
|
return await rendezvousFor(amount) !== void 0;
|
|
6249
6625
|
},
|
|
6250
6626
|
quote: async (req, ctx) => {
|
|
6251
|
-
const address = (0,
|
|
6252
|
-
(0,
|
|
6253
|
-
const amount = (0,
|
|
6627
|
+
const address = (0, import_sdk21.btcTarget)(req.raw);
|
|
6628
|
+
(0, import_sdk21.assertNoAssets)(SOLVER_ONCHAIN_RAIL, req);
|
|
6629
|
+
const amount = (0, import_sdk21.resolveSendAmount)(SOLVER_ONCHAIN_RAIL, req.raw, req.amount);
|
|
6254
6630
|
const payoutPkScript = l1ScriptForAddress(address, deps.l1Network);
|
|
6255
6631
|
const rendezvous = await rendezvousFor(amount);
|
|
6256
6632
|
if (!rendezvous) {
|
|
@@ -6289,7 +6665,7 @@ function solverOnchainRail(deps) {
|
|
|
6289
6665
|
// not knowable now, so `amount` is the payout, not the net.
|
|
6290
6666
|
claimFeeDeductedFromPayout: true
|
|
6291
6667
|
},
|
|
6292
|
-
send: async () => (0,
|
|
6668
|
+
send: async () => (0, import_sdk21.makeHandle)(SOLVER_ONCHAIN_RAIL, async (emit) => {
|
|
6293
6669
|
assertFundable({
|
|
6294
6670
|
quote: swap.quote,
|
|
6295
6671
|
now: Math.floor(Date.now() / 1e3),
|
|
@@ -6316,7 +6692,7 @@ function solverOnchainRail(deps) {
|
|
|
6316
6692
|
// src/payment/solverLightning.ts
|
|
6317
6693
|
var SOLVER_LIGHTNING_RAIL = "solver-lightning";
|
|
6318
6694
|
var factsOf = (raw, decode, now) => {
|
|
6319
|
-
const invoice = (0,
|
|
6695
|
+
const invoice = (0, import_sdk22.invoiceTarget)(raw);
|
|
6320
6696
|
if (!invoice) return void 0;
|
|
6321
6697
|
let facts;
|
|
6322
6698
|
try {
|
|
@@ -6328,22 +6704,22 @@ var factsOf = (raw, decode, now) => {
|
|
|
6328
6704
|
if (facts.expiresAt <= now) return void 0;
|
|
6329
6705
|
return facts;
|
|
6330
6706
|
};
|
|
6331
|
-
var contradicts = (req, facts) => req.amount !== void 0 && req.amount !== facts.amountSats && req.amount !==
|
|
6707
|
+
var contradicts = (req, facts) => req.amount !== void 0 && req.amount !== facts.amountSats && req.amount !== import_sdk22.BIP21.amountSats(req.raw);
|
|
6332
6708
|
var solverLightningRendezvous = (markets, amountSats, fallbackEmulatorPubkey) => solverRendezvous(markets, "lightning", amountSats, fallbackEmulatorPubkey);
|
|
6333
6709
|
function solverLightningRail(deps) {
|
|
6334
6710
|
const rendezvousFor = async (amountSats) => solverLightningRendezvous(await deps.discover(), amountSats, deps.fallbackEmulatorPubkey);
|
|
6335
6711
|
return {
|
|
6336
6712
|
id: SOLVER_LIGHTNING_RAIL,
|
|
6337
|
-
match: (req) => (0,
|
|
6713
|
+
match: (req) => (0, import_sdk22.invoiceTarget)(req.raw) !== void 0,
|
|
6338
6714
|
available: async (req) => {
|
|
6339
|
-
if ((0,
|
|
6715
|
+
if ((0, import_sdk22.assetsOf)(req).length > 0) return false;
|
|
6340
6716
|
const facts = factsOf(req.raw, deps.decodeInvoice, Math.floor(Date.now() / 1e3));
|
|
6341
6717
|
if (!facts) return false;
|
|
6342
6718
|
if (contradicts(req, facts)) return false;
|
|
6343
6719
|
return await rendezvousFor(facts.amountSats) !== void 0;
|
|
6344
6720
|
},
|
|
6345
6721
|
quote: async (req, ctx) => {
|
|
6346
|
-
(0,
|
|
6722
|
+
(0, import_sdk22.assertNoAssets)(SOLVER_LIGHTNING_RAIL, req);
|
|
6347
6723
|
const facts = factsOf(req.raw, deps.decodeInvoice, Math.floor(Date.now() / 1e3));
|
|
6348
6724
|
if (!facts) {
|
|
6349
6725
|
throw new Error(
|
|
@@ -6386,7 +6762,7 @@ function solverLightningRail(deps) {
|
|
|
6386
6762
|
invoiceExpiresAt: facts.expiresAt,
|
|
6387
6763
|
solverPubkey: rendezvous.solverPubkey
|
|
6388
6764
|
},
|
|
6389
|
-
send: async () => (0,
|
|
6765
|
+
send: async () => (0, import_sdk22.makeHandle)(SOLVER_LIGHTNING_RAIL, async (emit) => {
|
|
6390
6766
|
assertFundable({
|
|
6391
6767
|
quote: swap.quote,
|
|
6392
6768
|
invoiceExpiresAt: facts.expiresAt,
|
|
@@ -6408,7 +6784,7 @@ function solverLightningRail(deps) {
|
|
|
6408
6784
|
|
|
6409
6785
|
// src/restore.ts
|
|
6410
6786
|
var import_base15 = require("@scure/base");
|
|
6411
|
-
var
|
|
6787
|
+
var import_sdk23 = require("@arkade-os/sdk");
|
|
6412
6788
|
init_offer();
|
|
6413
6789
|
init_store();
|
|
6414
6790
|
var TXS_PER_REQUEST = 50;
|
|
@@ -6426,7 +6802,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
6426
6802
|
if (result.status !== "fulfilled") continue;
|
|
6427
6803
|
for (const psbt of result.value) {
|
|
6428
6804
|
try {
|
|
6429
|
-
const parsed =
|
|
6805
|
+
const parsed = import_sdk23.Transaction.fromPSBT(import_base15.base64.decode(psbt));
|
|
6430
6806
|
parsedByTxid.set(parsed.id, parsed);
|
|
6431
6807
|
} catch {
|
|
6432
6808
|
}
|
|
@@ -6455,7 +6831,7 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
6455
6831
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
6456
6832
|
if (import_base15.hex.encode(input.txid) !== deposit.txid) continue;
|
|
6457
6833
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
6458
|
-
const spent = import_base15.hex.encode((0,
|
|
6834
|
+
const spent = import_base15.hex.encode((0, import_sdk23.scriptFromTapLeafScript)(leaf));
|
|
6459
6835
|
if (leaves.returned.some((back) => spent === import_base15.hex.encode(back))) return "cancelled";
|
|
6460
6836
|
if (leaves.fulfill && spent === import_base15.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
6461
6837
|
}
|
|
@@ -6509,7 +6885,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6509
6885
|
if (!fundingTx) continue;
|
|
6510
6886
|
fetchedTxids.push(txid);
|
|
6511
6887
|
try {
|
|
6512
|
-
const packet =
|
|
6888
|
+
const packet = import_sdk23.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
6513
6889
|
if (!packet) continue;
|
|
6514
6890
|
const payload = packet.serialize();
|
|
6515
6891
|
found.push({
|
|
@@ -6626,7 +7002,7 @@ init_store();
|
|
|
6626
7002
|
|
|
6627
7003
|
// src/watch.ts
|
|
6628
7004
|
var import_base16 = require("@scure/base");
|
|
6629
|
-
var
|
|
7005
|
+
var import_sdk24 = require("@arkade-os/sdk");
|
|
6630
7006
|
init_coverage();
|
|
6631
7007
|
init_offer();
|
|
6632
7008
|
init_store();
|
|
@@ -6661,7 +7037,7 @@ async function watchOfferSwaps({
|
|
|
6661
7037
|
wallet.getAddress(),
|
|
6662
7038
|
wallet.getArkadeReader()
|
|
6663
7039
|
]);
|
|
6664
|
-
const operatorPubkey =
|
|
7040
|
+
const operatorPubkey = import_sdk24.ArkAddress.decode(address).serverPubKey;
|
|
6665
7041
|
let queue = Promise.resolve();
|
|
6666
7042
|
const enqueue = (task) => {
|
|
6667
7043
|
queue = queue.then(task).catch(() => {
|
|
@@ -6676,7 +7052,7 @@ async function watchOfferSwaps({
|
|
|
6676
7052
|
return classifyDepositSpend(
|
|
6677
7053
|
decodeOffer(import_base16.hex.decode(swap.offerHex)),
|
|
6678
7054
|
operatorPubkey,
|
|
6679
|
-
txs.map((psbt) =>
|
|
7055
|
+
txs.map((psbt) => import_sdk24.Transaction.fromPSBT(import_base16.base64.decode(psbt))),
|
|
6680
7056
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
6681
7057
|
);
|
|
6682
7058
|
} catch {
|
|
@@ -6704,7 +7080,7 @@ async function watchOfferSwaps({
|
|
|
6704
7080
|
}
|
|
6705
7081
|
};
|
|
6706
7082
|
const unsubscribe = manager.onContractEvent((event) => {
|
|
6707
|
-
if (!(0,
|
|
7083
|
+
if (!(0, import_sdk24.isContractVtxoEvent)(event) || event.type !== "vtxo_spent") return;
|
|
6708
7084
|
enqueue(() => handleSpend(event));
|
|
6709
7085
|
});
|
|
6710
7086
|
return {
|
|
@@ -6716,6 +7092,10 @@ async function watchOfferSwaps({
|
|
|
6716
7092
|
0 && (module.exports = {
|
|
6717
7093
|
ARKADE_BTC,
|
|
6718
7094
|
ASSET_CARRIER_SATS,
|
|
7095
|
+
ASSET_SWAP_BASELINE,
|
|
7096
|
+
ASSET_SWAP_CONTRACT_VERSIONS,
|
|
7097
|
+
ASSET_SWAP_V2,
|
|
7098
|
+
ASSET_SWAP_V3,
|
|
6719
7099
|
AddressMismatch,
|
|
6720
7100
|
BTC_ASSET_ID,
|
|
6721
7101
|
CROSS_ASSET_RAIL,
|
|
@@ -6756,6 +7136,7 @@ async function watchOfferSwaps({
|
|
|
6756
7136
|
arkadeRefunder,
|
|
6757
7137
|
arkadeSwapRequest,
|
|
6758
7138
|
assertArkadeFundable,
|
|
7139
|
+
assetSwapContractVersion,
|
|
6759
7140
|
awaitOnchainFill,
|
|
6760
7141
|
awaitRfqResolution,
|
|
6761
7142
|
buildHtlcClaim,
|