@arkade-os/swap 0.1.9 → 0.1.10
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 +1097 -541
- package/dist/advanced.d.cts +19 -21
- package/dist/advanced.d.ts +19 -21
- package/dist/advanced.js +40 -34
- package/dist/{chunk-FQNG4XMF.js → chunk-2HQZLIVX.js} +98 -37
- package/dist/{chunk-5QPJWOCN.js → chunk-6RJVT65W.js} +2 -0
- package/dist/chunk-AUJDREZN.js +445 -0
- package/dist/{chunk-I7WEXXZX.js → chunk-FWRDAL73.js} +157 -477
- package/dist/{chunk-552GDPBU.js → chunk-LCO6AJOS.js} +433 -59
- package/dist/index.cjs +1083 -530
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +24 -22
- package/dist/{lockupContract-DguuT7NK.d.cts → lockupContract-BTTRVwOt.d.cts} +1 -1
- package/dist/{lockupContract-BUOsghl1.d.ts → lockupContract-aFarhlxj.d.ts} +1 -1
- package/dist/node/index.d.cts +97 -67
- package/dist/node/index.d.ts +97 -67
- package/dist/nostr.cjs +925 -516
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +3 -2
- package/dist/{offerFillPlan-_AOLo6kh.d.ts → offerFillPlan-CJC5tnEd.d.ts} +10 -42
- package/dist/{offerFillPlan-Bp6-z6dS.d.cts → offerFillPlan-FmyaQoYT.d.cts} +10 -42
- package/dist/protocol.cjs +1054 -175
- package/dist/protocol.d.cts +42 -23
- package/dist/protocol.d.ts +42 -23
- package/dist/protocol.js +20 -7
- 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-CkKK0dGO.d.ts → repository-CwwhIAEd.d.cts} +406 -74
- package/dist/{repository--pfikw2R.d.cts → repository-DO6QKxBx.d.ts} +406 -74
- package/dist/{rfq-IzhOCG02.d.ts → rfq-CYxOyniL.d.ts} +52 -11
- package/dist/rfq-contract.cjs +3 -0
- package/dist/rfq-contract.d.cts +3 -1
- package/dist/rfq-contract.d.ts +3 -1
- package/dist/rfq-contract.js +3 -1
- package/dist/{rfq-BRpo5uWU.d.cts → rfq-nMGywkqI.d.cts} +52 -11
- package/dist/verify-ENO36VPK.js +33 -0
- package/dist/{watch-pvTVFp6-.d.cts → watch-DpDSP2tu.d.cts} +4 -3
- package/dist/{watch-DDNycuUa.d.ts → watch-_fZSgx_l.d.ts} +4 -3
- package/package.json +2 -2
- package/dist/offer-BhonWuKR.d.ts +0 -274
- package/dist/offer-D_qHpWo2.d.cts +0 -274
package/dist/protocol.cjs
CHANGED
|
@@ -622,6 +622,141 @@ var init_asset_swap = __esm({
|
|
|
622
622
|
}
|
|
623
623
|
});
|
|
624
624
|
|
|
625
|
+
// src/contracts/asset-swap-v4.json
|
|
626
|
+
var asset_swap_v4_default;
|
|
627
|
+
var init_asset_swap_v4 = __esm({
|
|
628
|
+
"src/contracts/asset-swap-v4.json"() {
|
|
629
|
+
asset_swap_v4_default = {
|
|
630
|
+
formatVersion: 1,
|
|
631
|
+
contractName: "AssetSwap",
|
|
632
|
+
constructorInputs: [
|
|
633
|
+
{
|
|
634
|
+
name: "receiver",
|
|
635
|
+
type: "pubkey"
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "amount",
|
|
639
|
+
type: "int"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
name: "assetTxid",
|
|
643
|
+
type: "bytes32"
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
name: "assetGroupIndex",
|
|
647
|
+
type: "int"
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
name: "user",
|
|
651
|
+
type: "pubkey"
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
name: "taker",
|
|
655
|
+
type: "pubkey"
|
|
656
|
+
}
|
|
657
|
+
],
|
|
658
|
+
functions: [
|
|
659
|
+
{
|
|
660
|
+
name: "fulfill",
|
|
661
|
+
arkade: {
|
|
662
|
+
inputs: [],
|
|
663
|
+
asm: [
|
|
664
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
665
|
+
"OP_DUP",
|
|
666
|
+
"<assetTxid>",
|
|
667
|
+
"<assetGroupIndex>",
|
|
668
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
669
|
+
"OP_VERIFY",
|
|
670
|
+
"<amount>",
|
|
671
|
+
"OP_GREATERTHANOREQUAL",
|
|
672
|
+
"OP_VERIFY",
|
|
673
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
674
|
+
"1",
|
|
675
|
+
"OP_NUMEQUALVERIFY",
|
|
676
|
+
"<receiver>",
|
|
677
|
+
"OP_EQUAL"
|
|
678
|
+
]
|
|
679
|
+
},
|
|
680
|
+
leaves: [
|
|
681
|
+
{
|
|
682
|
+
name: "fulfill",
|
|
683
|
+
witness: [
|
|
684
|
+
{
|
|
685
|
+
name: "takerSig",
|
|
686
|
+
type: "signature",
|
|
687
|
+
encoding: "schnorr-64"
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
name: "serverSig",
|
|
691
|
+
type: "signature",
|
|
692
|
+
encoding: "schnorr-64",
|
|
693
|
+
injected: true
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
name: "emulatorSig",
|
|
697
|
+
type: "signature",
|
|
698
|
+
encoding: "schnorr-64",
|
|
699
|
+
injected: true
|
|
700
|
+
}
|
|
701
|
+
],
|
|
702
|
+
asm: [
|
|
703
|
+
"<taker>",
|
|
704
|
+
"OP_CHECKSIGVERIFY",
|
|
705
|
+
"<SERVER_KEY>",
|
|
706
|
+
"OP_CHECKSIGVERIFY",
|
|
707
|
+
"<EMULATOR_KEY:fulfill>",
|
|
708
|
+
"OP_CHECKSIG"
|
|
709
|
+
]
|
|
710
|
+
}
|
|
711
|
+
]
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
name: "cancel",
|
|
715
|
+
leaves: [
|
|
716
|
+
{
|
|
717
|
+
name: "cancel",
|
|
718
|
+
witness: [
|
|
719
|
+
{
|
|
720
|
+
name: "userSig",
|
|
721
|
+
type: "signature",
|
|
722
|
+
encoding: "schnorr-64"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
name: "serverSig",
|
|
726
|
+
type: "signature",
|
|
727
|
+
encoding: "schnorr-64",
|
|
728
|
+
injected: true
|
|
729
|
+
}
|
|
730
|
+
],
|
|
731
|
+
asm: [
|
|
732
|
+
"<user>",
|
|
733
|
+
"OP_CHECKSIGVERIFY",
|
|
734
|
+
"<SERVER_KEY>",
|
|
735
|
+
"OP_CHECKSIG"
|
|
736
|
+
]
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
}
|
|
740
|
+
],
|
|
741
|
+
source: {
|
|
742
|
+
entry: "asset-swap-v4.ark",
|
|
743
|
+
files: {
|
|
744
|
+
"asset-swap-v4.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` of the asset,\n// and only `taker` can make that spend.\ncontract AssetSwap(\n pubkey receiver,\n int amount,\n bytes32 assetTxid,\n int assetGroupIndex,\n pubkey user,\n pubkey taker\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 // Replaces the synthesized collaborative leaf: the quoting solver is a third\n // conjunct, so an observer who reads the deposit cannot complete it.\n function fulfill(signature takerSig, signature serverSig, signature emulatorSig) tapscript {\n require(checkMultisig([taker, server, emulator], [takerSig, serverSig, emulatorSig], 3));\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
compiler: {
|
|
748
|
+
name: "arkadec",
|
|
749
|
+
version: "0.1.0-rc.1",
|
|
750
|
+
options: {
|
|
751
|
+
optimize: true
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
updatedAt: "2026-11-19T20:57:50.605738400+00:00",
|
|
755
|
+
fingerprint: "sha256:d830de32cd1d286a0a1fac698ff114a6c8ef5338a69f9f813717d1038ab2fb4a"
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
|
|
625
760
|
// src/contracts/sats-swap.json
|
|
626
761
|
var sats_swap_default;
|
|
627
762
|
var init_sats_swap = __esm({
|
|
@@ -735,6 +870,130 @@ var init_sats_swap = __esm({
|
|
|
735
870
|
}
|
|
736
871
|
});
|
|
737
872
|
|
|
873
|
+
// src/contracts/sats-swap-v4.json
|
|
874
|
+
var sats_swap_v4_default;
|
|
875
|
+
var init_sats_swap_v4 = __esm({
|
|
876
|
+
"src/contracts/sats-swap-v4.json"() {
|
|
877
|
+
sats_swap_v4_default = {
|
|
878
|
+
formatVersion: 1,
|
|
879
|
+
contractName: "SatsSwap",
|
|
880
|
+
constructorInputs: [
|
|
881
|
+
{
|
|
882
|
+
name: "receiver",
|
|
883
|
+
type: "pubkey"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
name: "amount",
|
|
887
|
+
type: "int"
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
name: "user",
|
|
891
|
+
type: "pubkey"
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
name: "taker",
|
|
895
|
+
type: "pubkey"
|
|
896
|
+
}
|
|
897
|
+
],
|
|
898
|
+
functions: [
|
|
899
|
+
{
|
|
900
|
+
name: "fulfill",
|
|
901
|
+
arkade: {
|
|
902
|
+
inputs: [],
|
|
903
|
+
asm: [
|
|
904
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
905
|
+
"OP_DUP",
|
|
906
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
907
|
+
"<amount>",
|
|
908
|
+
"OP_GREATERTHANOREQUAL",
|
|
909
|
+
"OP_VERIFY",
|
|
910
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
911
|
+
"1",
|
|
912
|
+
"OP_NUMEQUALVERIFY",
|
|
913
|
+
"<receiver>",
|
|
914
|
+
"OP_EQUAL"
|
|
915
|
+
]
|
|
916
|
+
},
|
|
917
|
+
leaves: [
|
|
918
|
+
{
|
|
919
|
+
name: "fulfill",
|
|
920
|
+
witness: [
|
|
921
|
+
{
|
|
922
|
+
name: "takerSig",
|
|
923
|
+
type: "signature",
|
|
924
|
+
encoding: "schnorr-64"
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
name: "serverSig",
|
|
928
|
+
type: "signature",
|
|
929
|
+
encoding: "schnorr-64",
|
|
930
|
+
injected: true
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
name: "emulatorSig",
|
|
934
|
+
type: "signature",
|
|
935
|
+
encoding: "schnorr-64",
|
|
936
|
+
injected: true
|
|
937
|
+
}
|
|
938
|
+
],
|
|
939
|
+
asm: [
|
|
940
|
+
"<taker>",
|
|
941
|
+
"OP_CHECKSIGVERIFY",
|
|
942
|
+
"<SERVER_KEY>",
|
|
943
|
+
"OP_CHECKSIGVERIFY",
|
|
944
|
+
"<EMULATOR_KEY:fulfill>",
|
|
945
|
+
"OP_CHECKSIG"
|
|
946
|
+
]
|
|
947
|
+
}
|
|
948
|
+
]
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
name: "cancel",
|
|
952
|
+
leaves: [
|
|
953
|
+
{
|
|
954
|
+
name: "cancel",
|
|
955
|
+
witness: [
|
|
956
|
+
{
|
|
957
|
+
name: "userSig",
|
|
958
|
+
type: "signature",
|
|
959
|
+
encoding: "schnorr-64"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
name: "serverSig",
|
|
963
|
+
type: "signature",
|
|
964
|
+
encoding: "schnorr-64",
|
|
965
|
+
injected: true
|
|
966
|
+
}
|
|
967
|
+
],
|
|
968
|
+
asm: [
|
|
969
|
+
"<user>",
|
|
970
|
+
"OP_CHECKSIGVERIFY",
|
|
971
|
+
"<SERVER_KEY>",
|
|
972
|
+
"OP_CHECKSIG"
|
|
973
|
+
]
|
|
974
|
+
}
|
|
975
|
+
]
|
|
976
|
+
}
|
|
977
|
+
],
|
|
978
|
+
source: {
|
|
979
|
+
entry: "sats-swap-v4.ark",
|
|
980
|
+
files: {
|
|
981
|
+
"sats-swap-v4.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` sats,\n// and only `taker` can make that spend.\ncontract SatsSwap(\n pubkey receiver,\n int amount,\n pubkey user,\n pubkey taker\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 fulfill(signature takerSig, signature serverSig, signature emulatorSig) tapscript {\n require(checkMultisig([taker, server, emulator], [takerSig, serverSig, emulatorSig], 3));\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
compiler: {
|
|
985
|
+
name: "arkadec",
|
|
986
|
+
version: "0.1.0-rc.1",
|
|
987
|
+
options: {
|
|
988
|
+
optimize: true
|
|
989
|
+
}
|
|
990
|
+
},
|
|
991
|
+
updatedAt: "2026-11-19T20:57:50.848496600+00:00",
|
|
992
|
+
fingerprint: "sha256:6ca61bf7ed8d8f65af3141da4e95fcc896863650127dd20949a84e72258053f4"
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
|
|
738
997
|
// src/legacy/swap-want-asset.program.v1.json
|
|
739
998
|
var swap_want_asset_program_v1_default;
|
|
740
999
|
var init_swap_want_asset_program_v1 = __esm({
|
|
@@ -821,7 +1080,7 @@ var init_swap_want_btc_program_v1 = __esm({
|
|
|
821
1080
|
});
|
|
822
1081
|
|
|
823
1082
|
// 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;
|
|
1083
|
+
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_V4, ASSET_SWAP_BASELINE;
|
|
825
1084
|
var init_rfq_contract = __esm({
|
|
826
1085
|
"src/rfq-contract.ts"() {
|
|
827
1086
|
"use strict";
|
|
@@ -830,18 +1089,21 @@ var init_rfq_contract = __esm({
|
|
|
830
1089
|
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
831
1090
|
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
832
1091
|
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
1092
|
+
ASSET_SWAP_V4 = "asset-swap-v4";
|
|
833
1093
|
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
834
1094
|
}
|
|
835
1095
|
});
|
|
836
1096
|
|
|
837
1097
|
// src/program.ts
|
|
838
|
-
var import_sdk3, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
1098
|
+
var import_sdk3, swapPrograms, legacySwapPrograms, directedSwapPrograms, sharedArgs, refuseTaker, v3Args, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, ASSET_SWAP_DERIVABLE_VERSIONS, assetSwapContractVersion;
|
|
839
1099
|
var init_program = __esm({
|
|
840
1100
|
"src/program.ts"() {
|
|
841
1101
|
"use strict";
|
|
842
1102
|
import_sdk3 = require("@arkade-os/sdk");
|
|
843
1103
|
init_asset_swap();
|
|
1104
|
+
init_asset_swap_v4();
|
|
844
1105
|
init_sats_swap();
|
|
1106
|
+
init_sats_swap_v4();
|
|
845
1107
|
init_swap_want_asset_program_v1();
|
|
846
1108
|
init_swap_want_btc_program_v1();
|
|
847
1109
|
init_rfq_contract();
|
|
@@ -854,38 +1116,60 @@ var init_program = __esm({
|
|
|
854
1116
|
wantAsset: import_sdk3.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
855
1117
|
wantBtc: import_sdk3.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
856
1118
|
};
|
|
1119
|
+
directedSwapPrograms = {
|
|
1120
|
+
wantAsset: import_sdk3.arkade.programFromArtifact(asset_swap_v4_default),
|
|
1121
|
+
wantBtc: import_sdk3.arkade.programFromArtifact(sats_swap_v4_default)
|
|
1122
|
+
};
|
|
857
1123
|
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
858
1124
|
user,
|
|
859
1125
|
server,
|
|
860
1126
|
...exitDelay && { exitDelay }
|
|
861
1127
|
});
|
|
1128
|
+
refuseTaker = (version, { taker }) => {
|
|
1129
|
+
if (taker !== void 0) throw new Error(`${version} binds no taker key`);
|
|
1130
|
+
};
|
|
1131
|
+
v3Args = (inputs) => ({
|
|
1132
|
+
receiver: inputs.receiver,
|
|
1133
|
+
amount: inputs.amount,
|
|
1134
|
+
...inputs.asset && {
|
|
1135
|
+
assetTxid: inputs.asset.txid,
|
|
1136
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
1137
|
+
},
|
|
1138
|
+
...sharedArgs(inputs)
|
|
1139
|
+
});
|
|
862
1140
|
ASSET_SWAP_CONTRACTS = {
|
|
863
1141
|
[ASSET_SWAP_V2]: {
|
|
864
1142
|
programs: legacySwapPrograms,
|
|
865
|
-
args: (inputs) =>
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1143
|
+
args: (inputs) => {
|
|
1144
|
+
refuseTaker(ASSET_SWAP_V2, inputs);
|
|
1145
|
+
return {
|
|
1146
|
+
makerWP: inputs.receiver,
|
|
1147
|
+
wantAmount: inputs.amount,
|
|
1148
|
+
...inputs.asset && {
|
|
1149
|
+
wantAssetTxid: inputs.asset.txid,
|
|
1150
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
1151
|
+
},
|
|
1152
|
+
...sharedArgs(inputs)
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
874
1155
|
},
|
|
875
1156
|
[ASSET_SWAP_V3]: {
|
|
876
1157
|
programs: swapPrograms,
|
|
877
|
-
args: (inputs) =>
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1158
|
+
args: (inputs) => {
|
|
1159
|
+
refuseTaker(ASSET_SWAP_V3, inputs);
|
|
1160
|
+
return v3Args(inputs);
|
|
1161
|
+
}
|
|
1162
|
+
},
|
|
1163
|
+
[ASSET_SWAP_V4]: {
|
|
1164
|
+
programs: directedSwapPrograms,
|
|
1165
|
+
args: (inputs) => {
|
|
1166
|
+
if (inputs.taker === void 0) throw new Error(`${ASSET_SWAP_V4} needs a taker key`);
|
|
1167
|
+
return { ...v3Args(inputs), taker: inputs.taker };
|
|
1168
|
+
}
|
|
886
1169
|
}
|
|
887
1170
|
};
|
|
888
|
-
ASSET_SWAP_CONTRACT_VERSIONS = [
|
|
1171
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V4];
|
|
1172
|
+
ASSET_SWAP_DERIVABLE_VERSIONS = [ASSET_SWAP_V4, ASSET_SWAP_V3, ASSET_SWAP_V2];
|
|
889
1173
|
assetSwapContractVersion = (id) => {
|
|
890
1174
|
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
891
1175
|
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
@@ -962,9 +1246,9 @@ var init_store = __esm({
|
|
|
962
1246
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
963
1247
|
getAssetSwapsOrThrow = async (repository) => {
|
|
964
1248
|
return (await collectAssetSwaps(repository)).filter(
|
|
965
|
-
(s) => s && typeof s.id === "string" && // offer swaps carry the TLV; onchain-corridor swaps carry
|
|
966
|
-
// the payment hash instead —
|
|
967
|
-
(typeof s.offerHex === "string" || typeof s.paymentHash === "string")
|
|
1249
|
+
(s) => s && typeof s.id === "string" && // offer swaps carry the TLV or the binding; onchain-corridor swaps carry
|
|
1250
|
+
// the payment hash instead — any of them marks a valid record
|
|
1251
|
+
(typeof s.offerHex === "string" || s.binding !== void 0 || typeof s.paymentHash === "string")
|
|
968
1252
|
).sort(byNewest);
|
|
969
1253
|
};
|
|
970
1254
|
getAssetSwaps = async (repository) => {
|
|
@@ -1163,28 +1447,28 @@ function withExitClosure(program, exit) {
|
|
|
1163
1447
|
}
|
|
1164
1448
|
};
|
|
1165
1449
|
}
|
|
1166
|
-
function swapProgramBinding(offer, operatorPubkey, contractVersion
|
|
1450
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion) {
|
|
1167
1451
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
1168
1452
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
1169
1453
|
}
|
|
1454
|
+
const directed = offer.taker !== void 0;
|
|
1455
|
+
const version = contractVersion ?? (directed ? ASSET_SWAP_V4 : ASSET_SWAP_BASELINE);
|
|
1170
1456
|
const expected = offer.swapPkScript;
|
|
1171
|
-
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey,
|
|
1457
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, version);
|
|
1172
1458
|
const funded = import_base5.hex.encode(expected);
|
|
1173
|
-
const order = [
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
];
|
|
1177
|
-
for (const version of order) {
|
|
1178
|
-
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
1459
|
+
const order = directed ? [ASSET_SWAP_V4] : [ASSET_SWAP_BASELINE, ASSET_SWAP_V3];
|
|
1460
|
+
for (const candidate of order) {
|
|
1461
|
+
const binding = bindSwapProgram(offer, operatorPubkey, candidate);
|
|
1179
1462
|
if (pkOf(binding) === funded) return binding;
|
|
1180
1463
|
}
|
|
1181
|
-
return bindSwapProgram(offer, operatorPubkey,
|
|
1464
|
+
return bindSwapProgram(offer, operatorPubkey, directed ? ASSET_SWAP_V4 : version);
|
|
1182
1465
|
}
|
|
1183
1466
|
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1184
1467
|
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1185
1468
|
const user = offer.makerPublicKey;
|
|
1186
1469
|
const assetId = offer.wantAsset;
|
|
1187
1470
|
return {
|
|
1471
|
+
version: contractVersion,
|
|
1188
1472
|
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
1189
1473
|
args: args({
|
|
1190
1474
|
receiver: offer.makerPkScript.subarray(2),
|
|
@@ -1195,7 +1479,8 @@ function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
|
1195
1479
|
},
|
|
1196
1480
|
user,
|
|
1197
1481
|
server: operatorPubkey,
|
|
1198
|
-
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
1482
|
+
...offer.exitDelay && { exitDelay: offer.exitDelay.value },
|
|
1483
|
+
...offer.taker && { taker: offer.taker }
|
|
1199
1484
|
}),
|
|
1200
1485
|
keys: {
|
|
1201
1486
|
serverKey: operatorPubkey,
|
|
@@ -1218,6 +1503,33 @@ function pkOf(binding) {
|
|
|
1218
1503
|
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
1219
1504
|
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
1220
1505
|
}
|
|
1506
|
+
function bindingProgram(binding) {
|
|
1507
|
+
if (Boolean(binding.wantAsset) === Boolean(binding.offerAsset)) {
|
|
1508
|
+
throw new Error("an offer binding names exactly one of wantAsset or offerAsset");
|
|
1509
|
+
}
|
|
1510
|
+
return swapProgramBinding(termsOf(binding), binding.serverPublicKey, binding.version);
|
|
1511
|
+
}
|
|
1512
|
+
function bindingFromOffer(offer, operatorPubkey) {
|
|
1513
|
+
const program = swapProgramBinding(offer, operatorPubkey);
|
|
1514
|
+
if (pkOf(program) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1515
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript));
|
|
1516
|
+
}
|
|
1517
|
+
return {
|
|
1518
|
+
version: program.version,
|
|
1519
|
+
receiverPkScript: offer.makerPkScript,
|
|
1520
|
+
amount: offer.wantAmount,
|
|
1521
|
+
...offer.wantAsset && { wantAsset: offer.wantAsset },
|
|
1522
|
+
...offer.offerAsset && { offerAsset: offer.offerAsset },
|
|
1523
|
+
userPublicKey: offer.makerPublicKey,
|
|
1524
|
+
serverPublicKey: operatorPubkey,
|
|
1525
|
+
emulatorPublicKey: offer.emulatorPubkey,
|
|
1526
|
+
...offer.exitDelay && { exitDelay: offer.exitDelay },
|
|
1527
|
+
...offer.taker && { taker: offer.taker }
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
function offerFromBinding(binding) {
|
|
1531
|
+
return offerOf(binding, compileSwapBinding(bindingProgram(binding)).pkScript);
|
|
1532
|
+
}
|
|
1221
1533
|
function u64(name, value) {
|
|
1222
1534
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
1223
1535
|
throw new Error(`${name} does not fit the offer wire format (u64)`);
|
|
@@ -1244,6 +1556,9 @@ function encodeOffer(offer) {
|
|
|
1244
1556
|
throw new Error(`${name} must be ${FIELDS[name].width} bytes`);
|
|
1245
1557
|
}
|
|
1246
1558
|
}
|
|
1559
|
+
if (offer.taker !== void 0 && offer.taker.length !== FIELDS.taker.width) {
|
|
1560
|
+
throw new Error(`taker must be ${FIELDS.taker.width} bytes`);
|
|
1561
|
+
}
|
|
1247
1562
|
const ratioNum = setRatio("ratioNum", offer.ratioNum);
|
|
1248
1563
|
const ratioDen = setRatio("ratioDen", offer.ratioDen);
|
|
1249
1564
|
if (ratioNum === void 0 !== (ratioDen === void 0)) {
|
|
@@ -1259,9 +1574,10 @@ function encodeOffer(offer) {
|
|
|
1259
1574
|
if (offer.offerAsset) recs.push(tlv2(FIELDS.offerAsset.tag, offer.offerAsset.serialize()));
|
|
1260
1575
|
recs.push(
|
|
1261
1576
|
tlv2(FIELDS.makerPkScript.tag, offer.makerPkScript),
|
|
1262
|
-
tlv2(FIELDS.makerPublicKey.tag, offer.makerPublicKey)
|
|
1263
|
-
tlv2(FIELDS.emulatorPubkey.tag, offer.emulatorPubkey)
|
|
1577
|
+
tlv2(FIELDS.makerPublicKey.tag, offer.makerPublicKey)
|
|
1264
1578
|
);
|
|
1579
|
+
if (offer.taker) recs.push(tlv2(FIELDS.taker.tag, offer.taker));
|
|
1580
|
+
recs.push(tlv2(FIELDS.emulatorPubkey.tag, offer.emulatorPubkey));
|
|
1265
1581
|
if (offer.exitDelay) recs.push(tlv2(FIELDS.exitTimelock.tag, encodeExitDelay(offer.exitDelay)));
|
|
1266
1582
|
return (0, import_utils2.concatBytes)(...recs);
|
|
1267
1583
|
}
|
|
@@ -1339,7 +1655,8 @@ function decodeOffer(data) {
|
|
|
1339
1655
|
emulatorPubkey: need("emulatorPubkey"),
|
|
1340
1656
|
...ratioNum !== void 0 && { ratioNum },
|
|
1341
1657
|
...ratioDen !== void 0 && { ratioDen },
|
|
1342
|
-
...fields.exitTimelock && { exitDelay: decodeExitDelay(fields.exitTimelock) }
|
|
1658
|
+
...fields.exitTimelock && { exitDelay: decodeExitDelay(fields.exitTimelock) },
|
|
1659
|
+
...fields.taker && { taker: fields.taker }
|
|
1343
1660
|
};
|
|
1344
1661
|
}
|
|
1345
1662
|
function decodeExitDelay(value) {
|
|
@@ -1359,10 +1676,7 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
1359
1676
|
});
|
|
1360
1677
|
}
|
|
1361
1678
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
1362
|
-
const { program, args, keys } = swapProgramBinding(
|
|
1363
|
-
{ ...binding, swapPkScript: expectedPkScript },
|
|
1364
|
-
operatorPubkey
|
|
1365
|
-
);
|
|
1679
|
+
const { program, args, keys } = "version" in binding ? bindingProgram(binding) : swapProgramBinding({ ...binding, swapPkScript: expectedPkScript }, operatorPubkey);
|
|
1366
1680
|
const contract = new import_sdk6.arkade.ArkadeContract(client, program, args, keys);
|
|
1367
1681
|
if (import_base5.hex.encode(contract.pkScript) !== import_base5.hex.encode(expectedPkScript)) {
|
|
1368
1682
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
@@ -1451,7 +1765,8 @@ async function deriveOffer(wallet, params) {
|
|
|
1451
1765
|
makerPublicKey: maker.publicKey,
|
|
1452
1766
|
emulatorPubkey: emuKey,
|
|
1453
1767
|
// checked before registration below. @see assertExitDelay
|
|
1454
|
-
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
1768
|
+
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay),
|
|
1769
|
+
...params.taker && { taker: params.taker }
|
|
1455
1770
|
});
|
|
1456
1771
|
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
1457
1772
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
@@ -1464,6 +1779,7 @@ async function deriveOffer(wallet, params) {
|
|
|
1464
1779
|
address: script.address(network.hrp, operatorPubKey).encode(),
|
|
1465
1780
|
swapPkScript: script.pkScript,
|
|
1466
1781
|
binding,
|
|
1782
|
+
offerBinding: Object.freeze(bindingFromOffer(offer, operatorPubKey)),
|
|
1467
1783
|
info,
|
|
1468
1784
|
operatorPubkey: operatorPubKey
|
|
1469
1785
|
});
|
|
@@ -1508,7 +1824,7 @@ async function cancelOffer(wallet, offerHex, opts) {
|
|
|
1508
1824
|
}
|
|
1509
1825
|
async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
1510
1826
|
const { fundingTxid, fundingOutpoint, swapAddress } = opts;
|
|
1511
|
-
const
|
|
1827
|
+
const decoded = typeof offerHex === "string" ? decodeOffer(import_base5.hex.decode(offerHex)) : isOfferBinding(offerHex) ? void 0 : offerHex;
|
|
1512
1828
|
const [contractManager, info, reader, broadcaster] = await Promise.all([
|
|
1513
1829
|
wallet.getContractManager(),
|
|
1514
1830
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
@@ -1525,18 +1841,20 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1525
1841
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
1526
1842
|
oneShotSubmit: wallet.oneShotSubmit
|
|
1527
1843
|
});
|
|
1528
|
-
const
|
|
1844
|
+
const pinned = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress) : void 0;
|
|
1845
|
+
const funded = decoded ? decoded.swapPkScript : pinned?.pkScript;
|
|
1529
1846
|
let binding;
|
|
1530
1847
|
let rebuilt;
|
|
1531
1848
|
try {
|
|
1532
|
-
binding = swapProgramBinding(
|
|
1849
|
+
binding = decoded ? swapProgramBinding(decoded, pinned?.serverPubKey ?? client.serverKey) : bindingProgram(offerHex);
|
|
1533
1850
|
rebuilt = compileSwapBinding(binding);
|
|
1534
1851
|
} catch (cause) {
|
|
1535
|
-
throw new OfferCovenantMismatchError(import_base5.hex.encode(
|
|
1852
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(funded ?? new Uint8Array()), { cause });
|
|
1536
1853
|
}
|
|
1537
|
-
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(
|
|
1538
|
-
throw new OfferCovenantMismatchError(import_base5.hex.encode(
|
|
1854
|
+
if (funded && import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(funded)) {
|
|
1855
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(funded));
|
|
1539
1856
|
}
|
|
1857
|
+
const offer = decoded ?? offerOf(offerHex, rebuilt.pkScript);
|
|
1540
1858
|
const contract = new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1541
1859
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
1542
1860
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
@@ -1566,8 +1884,8 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1566
1884
|
emulator,
|
|
1567
1885
|
emulatorPubkey
|
|
1568
1886
|
} = opts;
|
|
1569
|
-
const
|
|
1570
|
-
const contract = await connectFillContract(wallet, arkServerUrl,
|
|
1887
|
+
const target = typeof offerHex === "string" ? decodeOffer(import_base5.hex.decode(offerHex)) : offerHex;
|
|
1888
|
+
const contract = await connectFillContract(wallet, arkServerUrl, target, {
|
|
1571
1889
|
swapAddress,
|
|
1572
1890
|
emulator,
|
|
1573
1891
|
emulatorPubkey
|
|
@@ -1576,7 +1894,7 @@ async function fillOffer(wallet, arkServerUrl, offerHex, opts) {
|
|
|
1576
1894
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
1577
1895
|
const fill = contract.functions.fulfill();
|
|
1578
1896
|
assembleOfferFill(fill, {
|
|
1579
|
-
offer,
|
|
1897
|
+
offer: offerOf(target, contract.pkScript),
|
|
1580
1898
|
vtxo,
|
|
1581
1899
|
solverFund: fund,
|
|
1582
1900
|
solverPayout: payoutScript ?? import_sdk6.ArkAddress.decode(takerAddress).pkScript,
|
|
@@ -1598,10 +1916,11 @@ async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
|
1598
1916
|
} : {},
|
|
1599
1917
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
1600
1918
|
});
|
|
1601
|
-
const
|
|
1602
|
-
const binding = swapProgramBinding(offer, serverKey);
|
|
1919
|
+
const pinned = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress) : void 0;
|
|
1920
|
+
const binding = isOfferBinding(offer) ? bindingProgram(offer) : swapProgramBinding(offer, pinned?.serverPubKey ?? client.serverKey);
|
|
1921
|
+
const funded = isOfferBinding(offer) ? pinned?.pkScript : offer.swapPkScript;
|
|
1603
1922
|
const rebuilt = compileSwapBinding(binding);
|
|
1604
|
-
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(
|
|
1923
|
+
if (funded && import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(funded)) {
|
|
1605
1924
|
throw new Error(
|
|
1606
1925
|
"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"
|
|
1607
1926
|
);
|
|
@@ -1917,7 +2236,7 @@ function assertFillCoin(coin, what) {
|
|
|
1917
2236
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
1918
2237
|
assertAssetEntries(coin.assets, what);
|
|
1919
2238
|
}
|
|
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;
|
|
2239
|
+
var import_base5, import_utils2, import_sdk6, compiledBindings, isOfferBinding, termsOf, offerOf, recordOfferBinding, decimal, offerBindingOf, storedOffer, 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;
|
|
1921
2240
|
var init_offer = __esm({
|
|
1922
2241
|
"src/offer.ts"() {
|
|
1923
2242
|
"use strict";
|
|
@@ -1929,11 +2248,67 @@ var init_offer = __esm({
|
|
|
1929
2248
|
init_rfqProfileParts();
|
|
1930
2249
|
init_store();
|
|
1931
2250
|
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
2251
|
+
isOfferBinding = (offer) => "version" in offer;
|
|
2252
|
+
termsOf = (binding) => ({
|
|
2253
|
+
wantAmount: binding.amount,
|
|
2254
|
+
...binding.wantAsset && { wantAsset: binding.wantAsset },
|
|
2255
|
+
...binding.offerAsset && { offerAsset: binding.offerAsset },
|
|
2256
|
+
makerPkScript: binding.receiverPkScript,
|
|
2257
|
+
makerPublicKey: binding.userPublicKey,
|
|
2258
|
+
emulatorPubkey: binding.emulatorPublicKey,
|
|
2259
|
+
...binding.exitDelay && { exitDelay: binding.exitDelay },
|
|
2260
|
+
...binding.taker && { taker: binding.taker }
|
|
2261
|
+
});
|
|
2262
|
+
offerOf = (offer, swapPkScript) => isOfferBinding(offer) ? { ...termsOf(offer), swapPkScript } : offer;
|
|
2263
|
+
recordOfferBinding = (binding) => ({
|
|
2264
|
+
version: binding.version,
|
|
2265
|
+
receiverPkScript: import_base5.hex.encode(binding.receiverPkScript),
|
|
2266
|
+
amount: binding.amount.toString(),
|
|
2267
|
+
...binding.wantAsset && { wantAsset: binding.wantAsset.toString() },
|
|
2268
|
+
...binding.offerAsset && { offerAsset: binding.offerAsset.toString() },
|
|
2269
|
+
userPublicKey: import_base5.hex.encode(binding.userPublicKey),
|
|
2270
|
+
serverPublicKey: import_base5.hex.encode(binding.serverPublicKey),
|
|
2271
|
+
emulatorPublicKey: import_base5.hex.encode(binding.emulatorPublicKey),
|
|
2272
|
+
...binding.exitDelay && {
|
|
2273
|
+
exitDelay: { type: binding.exitDelay.type, value: binding.exitDelay.value.toString() }
|
|
2274
|
+
},
|
|
2275
|
+
...binding.taker && { taker: import_base5.hex.encode(binding.taker) }
|
|
2276
|
+
});
|
|
2277
|
+
decimal = (value, name) => {
|
|
2278
|
+
if (!/^\d+$/.test(value)) throw new Error(`recorded binding ${name} is not a decimal amount`);
|
|
2279
|
+
return BigInt(value);
|
|
2280
|
+
};
|
|
2281
|
+
offerBindingOf = (recorded) => {
|
|
2282
|
+
if (typeof recorded.version !== "string" || !Object.hasOwn(ASSET_SWAP_CONTRACTS, recorded.version)) {
|
|
2283
|
+
throw new Error(`recorded binding names no known contract version (${recorded.version})`);
|
|
2284
|
+
}
|
|
2285
|
+
const { exitDelay, wantAsset, offerAsset, taker } = recorded;
|
|
2286
|
+
return {
|
|
2287
|
+
version: recorded.version,
|
|
2288
|
+
receiverPkScript: import_base5.hex.decode(recorded.receiverPkScript),
|
|
2289
|
+
amount: decimal(recorded.amount, "amount"),
|
|
2290
|
+
...wantAsset !== void 0 && { wantAsset: import_sdk6.asset.AssetId.fromString(wantAsset) },
|
|
2291
|
+
...offerAsset !== void 0 && { offerAsset: import_sdk6.asset.AssetId.fromString(offerAsset) },
|
|
2292
|
+
userPublicKey: import_base5.hex.decode(recorded.userPublicKey),
|
|
2293
|
+
serverPublicKey: import_base5.hex.decode(recorded.serverPublicKey),
|
|
2294
|
+
emulatorPublicKey: import_base5.hex.decode(recorded.emulatorPublicKey),
|
|
2295
|
+
...exitDelay && {
|
|
2296
|
+
exitDelay: { type: exitDelay.type, value: decimal(exitDelay.value, "exitDelay") }
|
|
2297
|
+
},
|
|
2298
|
+
...taker !== void 0 && { taker: import_base5.hex.decode(taker) }
|
|
2299
|
+
};
|
|
2300
|
+
};
|
|
2301
|
+
storedOffer = (swap) => {
|
|
2302
|
+
if (swap.binding !== void 0) return offerBindingOf(swap.binding);
|
|
2303
|
+
if (typeof swap.offerHex === "string") return decodeOffer(import_base5.hex.decode(swap.offerHex));
|
|
2304
|
+
throw new Error("this offer swap carries neither a binding nor an offerHex to rebuild from");
|
|
2305
|
+
};
|
|
1932
2306
|
OFFER_PACKET_TYPE = 3;
|
|
1933
2307
|
FIELDS = {
|
|
1934
2308
|
swapPkScript: { tag: 1, width: 34 },
|
|
1935
2309
|
wantAmount: { tag: 2, width: 8 },
|
|
1936
2310
|
wantAsset: { tag: 3, width: void 0 },
|
|
2311
|
+
taker: { tag: 4, width: 32 },
|
|
1937
2312
|
makerPkScript: { tag: 5, width: 34 },
|
|
1938
2313
|
makerPublicKey: { tag: 7, width: 32 },
|
|
1939
2314
|
emulatorPubkey: { tag: 8, width: 32 },
|
|
@@ -1989,6 +2364,439 @@ var init_offer = __esm({
|
|
|
1989
2364
|
}
|
|
1990
2365
|
});
|
|
1991
2366
|
|
|
2367
|
+
// src/client/errors.ts
|
|
2368
|
+
var AmbiguousDestination, UnsupportedRoute, DiscoverySnapshotUnavailable, AmountMismatch, AmountEncodingUnsupported, QuoteVerificationFailed, QuoteExpired, MaxFeeExceeded, InsufficientFunds, AcceptConflict, ClientDisposed, NotCancellable, InconsistentRoute, OperatorUnreachable, MissingCorridorDep, SWAP_ERRORS, SWAP_ERROR_NAMES;
|
|
2369
|
+
var init_errors = __esm({
|
|
2370
|
+
"src/client/errors.ts"() {
|
|
2371
|
+
"use strict";
|
|
2372
|
+
init_rfq();
|
|
2373
|
+
AmbiguousDestination = class extends Error {
|
|
2374
|
+
constructor(destination, detail) {
|
|
2375
|
+
super(`cannot route ${JSON.stringify(destination)}: ${detail}`);
|
|
2376
|
+
this.destination = destination;
|
|
2377
|
+
}
|
|
2378
|
+
destination;
|
|
2379
|
+
name = "AmbiguousDestination";
|
|
2380
|
+
};
|
|
2381
|
+
UnsupportedRoute = class extends Error {
|
|
2382
|
+
name = "UnsupportedRoute";
|
|
2383
|
+
give;
|
|
2384
|
+
take;
|
|
2385
|
+
constructor(detail, corridors = {}) {
|
|
2386
|
+
super(`unsupported route: ${detail}`);
|
|
2387
|
+
this.give = corridors.give;
|
|
2388
|
+
this.take = corridors.take;
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
DiscoverySnapshotUnavailable = class extends Error {
|
|
2392
|
+
constructor(network, detail) {
|
|
2393
|
+
super(`cannot resolve on ${network} offline: ${detail}`);
|
|
2394
|
+
this.network = network;
|
|
2395
|
+
}
|
|
2396
|
+
network;
|
|
2397
|
+
name = "DiscoverySnapshotUnavailable";
|
|
2398
|
+
};
|
|
2399
|
+
AmountMismatch = class extends Error {
|
|
2400
|
+
constructor(sources) {
|
|
2401
|
+
super(`exactly one amount may be pinned; got ${sources[0]} and ${sources[1]}`);
|
|
2402
|
+
this.sources = sources;
|
|
2403
|
+
}
|
|
2404
|
+
sources;
|
|
2405
|
+
name = "AmountMismatch";
|
|
2406
|
+
};
|
|
2407
|
+
AmountEncodingUnsupported = class extends Error {
|
|
2408
|
+
constructor(field, value, detail, options) {
|
|
2409
|
+
super(`${field}: ${detail}`, options);
|
|
2410
|
+
this.field = field;
|
|
2411
|
+
this.value = value;
|
|
2412
|
+
}
|
|
2413
|
+
field;
|
|
2414
|
+
value;
|
|
2415
|
+
name = "AmountEncodingUnsupported";
|
|
2416
|
+
};
|
|
2417
|
+
QuoteVerificationFailed = class extends Error {
|
|
2418
|
+
constructor(check, expected, actual, options) {
|
|
2419
|
+
super(`quote failed the ${check} check \u2014 refusing to fund`, options);
|
|
2420
|
+
this.check = check;
|
|
2421
|
+
this.expected = expected;
|
|
2422
|
+
this.actual = actual;
|
|
2423
|
+
}
|
|
2424
|
+
check;
|
|
2425
|
+
name = "QuoteVerificationFailed";
|
|
2426
|
+
expected;
|
|
2427
|
+
actual;
|
|
2428
|
+
};
|
|
2429
|
+
QuoteExpired = class extends Error {
|
|
2430
|
+
constructor(quoteId, expiresAt, now) {
|
|
2431
|
+
super(`quote ${quoteId} expired at ${expiresAt}, ${now - expiresAt} ago`);
|
|
2432
|
+
this.quoteId = quoteId;
|
|
2433
|
+
this.expiresAt = expiresAt;
|
|
2434
|
+
this.now = now;
|
|
2435
|
+
}
|
|
2436
|
+
quoteId;
|
|
2437
|
+
expiresAt;
|
|
2438
|
+
now;
|
|
2439
|
+
name = "QuoteExpired";
|
|
2440
|
+
};
|
|
2441
|
+
MaxFeeExceeded = class extends Error {
|
|
2442
|
+
constructor(quoteId, asset4, fee, maxFee) {
|
|
2443
|
+
super(`fee ${fee} of ${asset4} exceeds the ${maxFee} ceiling`);
|
|
2444
|
+
this.quoteId = quoteId;
|
|
2445
|
+
this.asset = asset4;
|
|
2446
|
+
this.fee = fee;
|
|
2447
|
+
this.maxFee = maxFee;
|
|
2448
|
+
}
|
|
2449
|
+
quoteId;
|
|
2450
|
+
asset;
|
|
2451
|
+
fee;
|
|
2452
|
+
maxFee;
|
|
2453
|
+
name = "MaxFeeExceeded";
|
|
2454
|
+
};
|
|
2455
|
+
InsufficientFunds = class extends Error {
|
|
2456
|
+
constructor(asset4, required, available) {
|
|
2457
|
+
super(
|
|
2458
|
+
`funding needs ${required} of ${asset4}` + (available === void 0 ? "" : `, wallet holds ${available}`)
|
|
2459
|
+
);
|
|
2460
|
+
this.asset = asset4;
|
|
2461
|
+
this.required = required;
|
|
2462
|
+
this.available = available;
|
|
2463
|
+
}
|
|
2464
|
+
asset;
|
|
2465
|
+
required;
|
|
2466
|
+
name = "InsufficientFunds";
|
|
2467
|
+
available;
|
|
2468
|
+
};
|
|
2469
|
+
AcceptConflict = class extends Error {
|
|
2470
|
+
constructor(quoteId, swapId, fields) {
|
|
2471
|
+
super(`accept ${quoteId} conflicts with swap ${swapId} on ${fields.join(", ")}`);
|
|
2472
|
+
this.quoteId = quoteId;
|
|
2473
|
+
this.swapId = swapId;
|
|
2474
|
+
this.fields = fields;
|
|
2475
|
+
}
|
|
2476
|
+
quoteId;
|
|
2477
|
+
swapId;
|
|
2478
|
+
fields;
|
|
2479
|
+
name = "AcceptConflict";
|
|
2480
|
+
};
|
|
2481
|
+
ClientDisposed = class extends Error {
|
|
2482
|
+
constructor(method) {
|
|
2483
|
+
super(`${method}() called after the client was disposed`);
|
|
2484
|
+
this.method = method;
|
|
2485
|
+
}
|
|
2486
|
+
method;
|
|
2487
|
+
name = "ClientDisposed";
|
|
2488
|
+
};
|
|
2489
|
+
NotCancellable = class extends Error {
|
|
2490
|
+
constructor(swapId) {
|
|
2491
|
+
super(`swap ${swapId} is not a cancellable asset swap`);
|
|
2492
|
+
this.swapId = swapId;
|
|
2493
|
+
}
|
|
2494
|
+
swapId;
|
|
2495
|
+
name = "NotCancellable";
|
|
2496
|
+
};
|
|
2497
|
+
InconsistentRoute = class extends Error {
|
|
2498
|
+
constructor(asset4, destination) {
|
|
2499
|
+
super(`destination ${JSON.stringify(destination)} is not on ${asset4}'s chain`);
|
|
2500
|
+
this.asset = asset4;
|
|
2501
|
+
this.destination = destination;
|
|
2502
|
+
}
|
|
2503
|
+
asset;
|
|
2504
|
+
destination;
|
|
2505
|
+
name = "InconsistentRoute";
|
|
2506
|
+
};
|
|
2507
|
+
OperatorUnreachable = class extends Error {
|
|
2508
|
+
name = "OperatorUnreachable";
|
|
2509
|
+
constructor(detail, options) {
|
|
2510
|
+
super(`cannot derive a covenant: ${detail}`, options);
|
|
2511
|
+
}
|
|
2512
|
+
};
|
|
2513
|
+
MissingCorridorDep = class extends Error {
|
|
2514
|
+
constructor(corridor, dep) {
|
|
2515
|
+
super(`the ${corridor} corridor has no ${dep}`);
|
|
2516
|
+
this.corridor = corridor;
|
|
2517
|
+
this.dep = dep;
|
|
2518
|
+
}
|
|
2519
|
+
corridor;
|
|
2520
|
+
dep;
|
|
2521
|
+
name = "MissingCorridorDep";
|
|
2522
|
+
};
|
|
2523
|
+
SWAP_ERRORS = {
|
|
2524
|
+
AmbiguousDestination,
|
|
2525
|
+
UnsupportedRoute,
|
|
2526
|
+
DiscoverySnapshotUnavailable,
|
|
2527
|
+
AmountMismatch,
|
|
2528
|
+
AmountEncodingUnsupported,
|
|
2529
|
+
QuoteVerificationFailed,
|
|
2530
|
+
SwapRefusal,
|
|
2531
|
+
QuoteExpired,
|
|
2532
|
+
MaxFeeExceeded,
|
|
2533
|
+
InsufficientFunds,
|
|
2534
|
+
AcceptConflict,
|
|
2535
|
+
ClientDisposed,
|
|
2536
|
+
NotCancellable,
|
|
2537
|
+
InconsistentRoute,
|
|
2538
|
+
OperatorUnreachable,
|
|
2539
|
+
MissingCorridorDep
|
|
2540
|
+
};
|
|
2541
|
+
SWAP_ERROR_NAMES = Object.keys(SWAP_ERRORS);
|
|
2542
|
+
}
|
|
2543
|
+
});
|
|
2544
|
+
|
|
2545
|
+
// src/client/policy.ts
|
|
2546
|
+
var DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
2547
|
+
var init_policy = __esm({
|
|
2548
|
+
"src/client/policy.ts"() {
|
|
2549
|
+
"use strict";
|
|
2550
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS = 30 * 24 * 3600;
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
|
|
2554
|
+
// src/client/verify.ts
|
|
2555
|
+
var verify_exports = {};
|
|
2556
|
+
__export(verify_exports, {
|
|
2557
|
+
verifiedCarrierSats: () => verifiedCarrierSats,
|
|
2558
|
+
verifyCrossAssetAmount: () => verifyCrossAssetAmount,
|
|
2559
|
+
verifyPair: () => verifyPair,
|
|
2560
|
+
verifyQuoteTtl: () => verifyQuoteTtl,
|
|
2561
|
+
verifyQuotedAmount: () => verifyQuotedAmount,
|
|
2562
|
+
verifyReceiveInvoiceFacts: () => verifyReceiveInvoiceFacts,
|
|
2563
|
+
verifyReceiveWindow: () => verifyReceiveWindow,
|
|
2564
|
+
verifyRefundWindow: () => verifyRefundWindow,
|
|
2565
|
+
verifyResponder: () => verifyResponder,
|
|
2566
|
+
verifySendInvoice: () => verifySendInvoice,
|
|
2567
|
+
verifySendWindow: () => verifySendWindow,
|
|
2568
|
+
verifyTaker: () => verifyTaker,
|
|
2569
|
+
verifyingDerivation: () => verifyingDerivation
|
|
2570
|
+
});
|
|
2571
|
+
var import_base6, reasonOf, CHECK_BY_REASON, gated, verifyResponder, verifyTaker, verifyPair, verifyingDerivation, verifySendWindow, verifyReceiveWindow, verifySendInvoice, verifyReceiveInvoiceFacts, verifyQuoteTtl, CSV_GRANULARITY_SECONDS, verifyRefundWindow, verifyQuotedAmount, verifyCrossAssetAmount, verifiedCarrierSats, verifyPinnedAmount;
|
|
2572
|
+
var init_verify = __esm({
|
|
2573
|
+
"src/client/verify.ts"() {
|
|
2574
|
+
"use strict";
|
|
2575
|
+
import_base6 = require("@scure/base");
|
|
2576
|
+
init_rfq();
|
|
2577
|
+
init_errors();
|
|
2578
|
+
init_policy();
|
|
2579
|
+
reasonOf = (error) => error instanceof Error && typeof error.reason === "string" ? error.reason : void 0;
|
|
2580
|
+
CHECK_BY_REASON = {
|
|
2581
|
+
invoice_expired: "invoice",
|
|
2582
|
+
invoice_undecodable: "invoice",
|
|
2583
|
+
invoice_hash_mismatch: "invoice",
|
|
2584
|
+
invoice_amount_mismatch: "invoice",
|
|
2585
|
+
insufficient_headroom: "refund_window",
|
|
2586
|
+
missing_refund_locktime: "refund_window",
|
|
2587
|
+
claim_window_too_short: "refund_window",
|
|
2588
|
+
confirmations_out_of_range: "refund_window",
|
|
2589
|
+
timelock_order: "refund_window",
|
|
2590
|
+
quote_malformed: "refund_window"
|
|
2591
|
+
};
|
|
2592
|
+
gated = (run, quote) => {
|
|
2593
|
+
try {
|
|
2594
|
+
run();
|
|
2595
|
+
} catch (error) {
|
|
2596
|
+
const reason = reasonOf(error);
|
|
2597
|
+
if (reason === "quote_expired") {
|
|
2598
|
+
throw new QuoteExpired(quote.id, quote.expiresAt, quote.now);
|
|
2599
|
+
}
|
|
2600
|
+
const check = reason === void 0 ? void 0 : CHECK_BY_REASON[reason];
|
|
2601
|
+
if (check === void 0) throw error;
|
|
2602
|
+
throw new QuoteVerificationFailed(
|
|
2603
|
+
check,
|
|
2604
|
+
void 0,
|
|
2605
|
+
error instanceof Error ? error.message : String(error),
|
|
2606
|
+
{ cause: error }
|
|
2607
|
+
);
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2610
|
+
verifyResponder = (input) => {
|
|
2611
|
+
if (!input.pinnable || input.expected === void 0) {
|
|
2612
|
+
throw new QuoteVerificationFailed(
|
|
2613
|
+
"responder",
|
|
2614
|
+
"a registry-served card naming the solver's discovery key",
|
|
2615
|
+
input.expected === void 0 ? "the card names no discovery key" : "the card came out of the local cache, which does not authenticate it"
|
|
2616
|
+
);
|
|
2617
|
+
}
|
|
2618
|
+
if (input.attested === void 0) {
|
|
2619
|
+
throw new QuoteVerificationFailed(
|
|
2620
|
+
"responder",
|
|
2621
|
+
input.expected,
|
|
2622
|
+
"the transport attests nobody"
|
|
2623
|
+
);
|
|
2624
|
+
}
|
|
2625
|
+
if (input.attested !== input.expected) {
|
|
2626
|
+
throw new QuoteVerificationFailed("responder", input.expected, input.attested);
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
verifyTaker = (input) => {
|
|
2630
|
+
const xOnly = (key) => typeof key === "string" && /^[0-9a-f]{64}$/i.test(key) ? import_base6.hex.decode(key.toLowerCase()) : void 0;
|
|
2631
|
+
const taker = xOnly(input.solverPubkey);
|
|
2632
|
+
const attested = xOnly(input.attested);
|
|
2633
|
+
if (taker === void 0 || attested === void 0 || import_base6.hex.encode(taker) !== import_base6.hex.encode(attested)) {
|
|
2634
|
+
throw new QuoteVerificationFailed("responder", input.attested, String(input.solverPubkey));
|
|
2635
|
+
}
|
|
2636
|
+
return taker;
|
|
2637
|
+
};
|
|
2638
|
+
verifyPair = (quoted, requested) => {
|
|
2639
|
+
if (quoted !== requested) {
|
|
2640
|
+
throw new QuoteVerificationFailed("pair", requested, String(quoted));
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
verifyingDerivation = (derive) => {
|
|
2644
|
+
try {
|
|
2645
|
+
return derive();
|
|
2646
|
+
} catch (error) {
|
|
2647
|
+
if (error instanceof AddressMismatch) {
|
|
2648
|
+
const derived = Array.isArray(error.derived) ? error.derived.join(", ") : error.derived;
|
|
2649
|
+
throw new QuoteVerificationFailed("lockup_address", derived, error.quoted, {
|
|
2650
|
+
cause: error
|
|
2651
|
+
});
|
|
2652
|
+
}
|
|
2653
|
+
if (error instanceof Error) {
|
|
2654
|
+
throw new QuoteVerificationFailed("lockup_address", void 0, error.message, {
|
|
2655
|
+
cause: error
|
|
2656
|
+
});
|
|
2657
|
+
}
|
|
2658
|
+
throw error;
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
verifySendWindow = (input) => {
|
|
2662
|
+
gated(
|
|
2663
|
+
() => assertFundable({
|
|
2664
|
+
quote: input.quote,
|
|
2665
|
+
now: input.now,
|
|
2666
|
+
...input.invoiceExpiresAt === void 0 ? {} : { invoiceExpiresAt: input.invoiceExpiresAt },
|
|
2667
|
+
...input.onchain === void 0 ? {} : { onchain: input.onchain }
|
|
2668
|
+
}),
|
|
2669
|
+
{ id: input.quoteId, expiresAt: input.quote.valid_until, now: input.now }
|
|
2670
|
+
);
|
|
2671
|
+
};
|
|
2672
|
+
verifyReceiveWindow = (input) => {
|
|
2673
|
+
gated(
|
|
2674
|
+
() => assertReceivable({
|
|
2675
|
+
quote: input.quote,
|
|
2676
|
+
payDeadline: input.payDeadline,
|
|
2677
|
+
now: input.now
|
|
2678
|
+
}),
|
|
2679
|
+
{ id: input.quoteId, expiresAt: input.payDeadline, now: input.now }
|
|
2680
|
+
);
|
|
2681
|
+
};
|
|
2682
|
+
verifySendInvoice = (input) => {
|
|
2683
|
+
const invoiced = input.invoiced;
|
|
2684
|
+
if (input.take !== invoiced) {
|
|
2685
|
+
throw new QuoteVerificationFailed("invoice", `${invoiced}`, `${input.take}`);
|
|
2686
|
+
}
|
|
2687
|
+
if (input.give < input.take) {
|
|
2688
|
+
throw new QuoteVerificationFailed(
|
|
2689
|
+
"invoice",
|
|
2690
|
+
`at least the invoice's ${invoiced}`,
|
|
2691
|
+
`${input.give}, a negative spread`
|
|
2692
|
+
);
|
|
2693
|
+
}
|
|
2694
|
+
};
|
|
2695
|
+
verifyReceiveInvoiceFacts = (input) => {
|
|
2696
|
+
let decoded;
|
|
2697
|
+
try {
|
|
2698
|
+
decoded = input.decode(input.invoice);
|
|
2699
|
+
} catch (cause) {
|
|
2700
|
+
throw new QuoteVerificationFailed(
|
|
2701
|
+
"invoice",
|
|
2702
|
+
"a decodable BOLT11",
|
|
2703
|
+
cause instanceof Error ? cause.message : String(cause),
|
|
2704
|
+
{ cause }
|
|
2705
|
+
);
|
|
2706
|
+
}
|
|
2707
|
+
if (!Number.isFinite(decoded.expiresAt)) {
|
|
2708
|
+
throw new QuoteVerificationFailed("invoice", "a finite expiry", `${decoded.expiresAt}`);
|
|
2709
|
+
}
|
|
2710
|
+
if (!Number.isFinite(input.validUntil)) {
|
|
2711
|
+
throw new QuoteVerificationFailed(
|
|
2712
|
+
"refund_window",
|
|
2713
|
+
"a finite valid_until",
|
|
2714
|
+
`${input.validUntil}`
|
|
2715
|
+
);
|
|
2716
|
+
}
|
|
2717
|
+
if (decoded.paymentHash !== input.paymentHash) {
|
|
2718
|
+
throw new QuoteVerificationFailed("invoice", input.paymentHash, decoded.paymentHash);
|
|
2719
|
+
}
|
|
2720
|
+
if (!Number.isSafeInteger(decoded.amountSats) || decoded.amountSats <= 0) {
|
|
2721
|
+
throw new QuoteVerificationFailed(
|
|
2722
|
+
"invoice",
|
|
2723
|
+
`${input.payAmount}`,
|
|
2724
|
+
"the invoice names no amount"
|
|
2725
|
+
);
|
|
2726
|
+
}
|
|
2727
|
+
if (BigInt(decoded.amountSats) !== input.payAmount) {
|
|
2728
|
+
throw new QuoteVerificationFailed("invoice", `${input.payAmount}`, `${decoded.amountSats}`);
|
|
2729
|
+
}
|
|
2730
|
+
return { payDeadline: Math.min(decoded.expiresAt, input.validUntil) };
|
|
2731
|
+
};
|
|
2732
|
+
verifyQuoteTtl = (input) => {
|
|
2733
|
+
const floor = input.floorSeconds ?? 0;
|
|
2734
|
+
if (input.expiresAt - input.now <= floor) {
|
|
2735
|
+
throw new QuoteExpired(input.quoteId, input.expiresAt, input.now);
|
|
2736
|
+
}
|
|
2737
|
+
};
|
|
2738
|
+
CSV_GRANULARITY_SECONDS = 512;
|
|
2739
|
+
verifyRefundWindow = (input) => {
|
|
2740
|
+
const max = input.maxSeconds ?? DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
2741
|
+
const window = input.refundLocktime - input.now;
|
|
2742
|
+
if (!(window <= max)) {
|
|
2743
|
+
throw new QuoteVerificationFailed("refund_window", `at most ${max}s`, `${window}s`);
|
|
2744
|
+
}
|
|
2745
|
+
const delay = input.refundWithoutReceiverDelay;
|
|
2746
|
+
if (delay !== void 0 && !(delay < max + CSV_GRANULARITY_SECONDS)) {
|
|
2747
|
+
throw new QuoteVerificationFailed(
|
|
2748
|
+
"refund_window",
|
|
2749
|
+
`a solo-refund delay of at most ${max}s`,
|
|
2750
|
+
`${delay}s`
|
|
2751
|
+
);
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
verifyQuotedAmount = (input) => {
|
|
2755
|
+
verifyPinnedAmount(input);
|
|
2756
|
+
if (input.take > input.give) {
|
|
2757
|
+
throw new QuoteVerificationFailed(
|
|
2758
|
+
"pair",
|
|
2759
|
+
`${input.pair} give >= take`,
|
|
2760
|
+
`give=${input.give} take=${input.take}`
|
|
2761
|
+
);
|
|
2762
|
+
}
|
|
2763
|
+
};
|
|
2764
|
+
verifyCrossAssetAmount = (input) => {
|
|
2765
|
+
verifyPinnedAmount(input);
|
|
2766
|
+
if (input.give <= 0n || input.take <= 0n) {
|
|
2767
|
+
throw new QuoteVerificationFailed(
|
|
2768
|
+
"pair",
|
|
2769
|
+
`${input.pair} give > 0 take > 0`,
|
|
2770
|
+
`give=${input.give} take=${input.take}`
|
|
2771
|
+
);
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
verifiedCarrierSats = (quote) => {
|
|
2775
|
+
try {
|
|
2776
|
+
return quoteCarrierSats(quote);
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
if (reasonOf(error) !== "carrier_malformed") throw error;
|
|
2779
|
+
throw new QuoteVerificationFailed(
|
|
2780
|
+
"pair",
|
|
2781
|
+
"carrier_sats a non-negative integer",
|
|
2782
|
+
String(quote.carrier_sats),
|
|
2783
|
+
{ cause: error }
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
};
|
|
2787
|
+
verifyPinnedAmount = (input) => {
|
|
2788
|
+
const quoted = input.pinned.on === "give" ? input.give : input.take;
|
|
2789
|
+
if (quoted !== input.pinned.value) {
|
|
2790
|
+
throw new QuoteVerificationFailed(
|
|
2791
|
+
"pair",
|
|
2792
|
+
`${input.pair} ${input.pinned.on}=${input.pinned.value}`,
|
|
2793
|
+
`${input.pair} ${input.pinned.on}=${quoted}`
|
|
2794
|
+
);
|
|
2795
|
+
}
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
|
|
1992
2800
|
// src/rfq.ts
|
|
1993
2801
|
function lightningSendContract(params) {
|
|
1994
2802
|
return suiteVhtlc(params, {
|
|
@@ -2020,7 +2828,7 @@ function deriveLightningSend(input) {
|
|
|
2020
2828
|
throw new Error("lightning-send quote is missing profile.receiver_pk_script");
|
|
2021
2829
|
}
|
|
2022
2830
|
const contractParams = {
|
|
2023
|
-
solverPubkey: (0, import_sdk7.toXOnly)(
|
|
2831
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(quote.solver_pubkey), "solver key"),
|
|
2024
2832
|
refundLocktime: quote.refund_locktime,
|
|
2025
2833
|
operatorPubkey: input.operatorPubkey,
|
|
2026
2834
|
paymentHash: input.paymentHash,
|
|
@@ -2071,7 +2879,7 @@ async function requestLightningSend(wallet, transport, params) {
|
|
|
2071
2879
|
`quote from_amount ${quote.from_amount} is below the invoice amount \u2014 a negative spread is not a quote`
|
|
2072
2880
|
);
|
|
2073
2881
|
}
|
|
2074
|
-
const operatorPubkey = (0, import_sdk7.toXOnly)(
|
|
2882
|
+
const operatorPubkey = (0, import_sdk7.toXOnly)(import_base7.hex.decode(info.signerPubkey), "ark signer key");
|
|
2075
2883
|
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
2076
2884
|
const derived = deriveLightningSend({
|
|
2077
2885
|
quote,
|
|
@@ -2080,7 +2888,7 @@ async function requestLightningSend(wallet, transport, params) {
|
|
|
2080
2888
|
refundPkScript: secrets.pkScript,
|
|
2081
2889
|
operatorPubkey,
|
|
2082
2890
|
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
2083
|
-
|
|
2891
|
+
import_base7.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, params.emulatorPubkey)),
|
|
2084
2892
|
"emulator signer key"
|
|
2085
2893
|
),
|
|
2086
2894
|
claimDelay,
|
|
@@ -2125,13 +2933,12 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
2125
2933
|
receiveAddress,
|
|
2126
2934
|
ownPkScript,
|
|
2127
2935
|
(0, import_sdk7.networkFromOperatorInfo)(info).hrp,
|
|
2128
|
-
(0, import_sdk7.toXOnly)(
|
|
2936
|
+
(0, import_sdk7.toXOnly)(import_base7.hex.decode(info.signerPubkey), "ark signer key")
|
|
2129
2937
|
);
|
|
2130
2938
|
const pair = rfqPair(
|
|
2131
2939
|
params.offerAsset ? arkadeAssetLeg(params.offerAsset) : ARKADE_BTC,
|
|
2132
2940
|
params.wantAsset ? arkadeAssetLeg(params.wantAsset) : ARKADE_BTC
|
|
2133
2941
|
);
|
|
2134
|
-
const contractVersions = [...params.contractVersions ?? ASSET_SWAP_CONTRACT_VERSIONS];
|
|
2135
2942
|
const { quote, rfqId, contractVersion } = await requestVersionedQuote(
|
|
2136
2943
|
transport,
|
|
2137
2944
|
arkadeSwapRequest({
|
|
@@ -2142,13 +2949,17 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
2142
2949
|
amountSide,
|
|
2143
2950
|
makerPkScript,
|
|
2144
2951
|
makerPublicKey,
|
|
2145
|
-
contractVersions
|
|
2952
|
+
contractVersions: ASSET_SWAP_CONTRACT_VERSIONS
|
|
2146
2953
|
}),
|
|
2147
|
-
|
|
2954
|
+
ASSET_SWAP_CONTRACT_VERSIONS
|
|
2148
2955
|
);
|
|
2149
2956
|
if (quote.pair !== pair) {
|
|
2150
2957
|
throw new Error(`solver quoted ${JSON.stringify(quote.pair)}, not the requested ${pair}`);
|
|
2151
2958
|
}
|
|
2959
|
+
const taker = contractVersion === ASSET_SWAP_V4 ? (await Promise.resolve().then(() => (init_verify(), verify_exports))).verifyTaker({
|
|
2960
|
+
attested: transport.attestedResponder,
|
|
2961
|
+
solverPubkey: quote.solver_pubkey
|
|
2962
|
+
}) : void 0;
|
|
2152
2963
|
assertArkadeFundable({ quote, ...params.now !== void 0 ? { now: params.now } : {} });
|
|
2153
2964
|
const terms = offerTermsFromQuote(quote, {
|
|
2154
2965
|
...params.offerAsset !== void 0 ? { offerAsset: params.offerAsset } : {},
|
|
@@ -2186,7 +2997,8 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
2186
2997
|
...terms.wantAsset !== void 0 ? { wantAsset: terms.wantAsset } : {},
|
|
2187
2998
|
...terms.offerAsset !== void 0 ? { offerAsset: terms.offerAsset } : {},
|
|
2188
2999
|
...params.emulatorPubkey !== void 0 ? { emulatorPubkey: params.emulatorPubkey } : {},
|
|
2189
|
-
contractVersion
|
|
3000
|
+
contractVersion,
|
|
3001
|
+
...taker === void 0 ? {} : { taker }
|
|
2190
3002
|
});
|
|
2191
3003
|
verifyOfferAddress(quote, offer);
|
|
2192
3004
|
const fundAmount = BigInt(quote.from_amount);
|
|
@@ -2220,7 +3032,7 @@ function deriveOnchainSend(input) {
|
|
|
2220
3032
|
"onchain-send"
|
|
2221
3033
|
);
|
|
2222
3034
|
const contractParams = {
|
|
2223
|
-
solverPubkey: (0, import_sdk7.toXOnly)(
|
|
3035
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(quote.solver_pubkey), "solver key"),
|
|
2224
3036
|
refundLocktime,
|
|
2225
3037
|
operatorPubkey: input.operatorPubkey,
|
|
2226
3038
|
paymentHash: input.paymentHash,
|
|
@@ -2240,7 +3052,7 @@ function deriveOnchainSend(input) {
|
|
|
2240
3052
|
const htlcParams = {
|
|
2241
3053
|
paymentHash: input.paymentHash,
|
|
2242
3054
|
claimKey: input.payoutPubkey,
|
|
2243
|
-
refundKey: (0, import_sdk7.toXOnly)(
|
|
3055
|
+
refundKey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(htlcPubkey), "solver L1 htlc key"),
|
|
2244
3056
|
refundLocktime: htlcLocktime
|
|
2245
3057
|
};
|
|
2246
3058
|
const htlc = onchainHtlcScript(htlcParams, input.l1Network);
|
|
@@ -2271,7 +3083,7 @@ async function requestOnchainSend(wallet, transport, params) {
|
|
|
2271
3083
|
"[swap] this swap's preimage cannot be re-derived from the seed and MUST be persisted with the record before funding"
|
|
2272
3084
|
);
|
|
2273
3085
|
}
|
|
2274
|
-
const paymentHash =
|
|
3086
|
+
const paymentHash = import_base7.hex.encode(secrets.paymentHash);
|
|
2275
3087
|
const senderPubkey = secrets.pubkey;
|
|
2276
3088
|
const quote = await transport.requestQuote(
|
|
2277
3089
|
onchainSendRequest({
|
|
@@ -2435,7 +3247,7 @@ function deriveOnchainReceive(input) {
|
|
|
2435
3247
|
).matched;
|
|
2436
3248
|
const htlcParams = {
|
|
2437
3249
|
paymentHash: input.paymentHash,
|
|
2438
|
-
claimKey: (0, import_sdk7.toXOnly)(
|
|
3250
|
+
claimKey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(claimPubkey), "solver L1 claim key"),
|
|
2439
3251
|
refundKey: input.refundPubkey,
|
|
2440
3252
|
refundLocktime: htlcLocktime
|
|
2441
3253
|
};
|
|
@@ -2509,11 +3321,11 @@ async function requestOnchainReceive(wallet, transport, params) {
|
|
|
2509
3321
|
secrets
|
|
2510
3322
|
};
|
|
2511
3323
|
}
|
|
2512
|
-
var
|
|
3324
|
+
var import_base7, 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;
|
|
2513
3325
|
var init_rfq = __esm({
|
|
2514
3326
|
"src/rfq.ts"() {
|
|
2515
3327
|
"use strict";
|
|
2516
|
-
|
|
3328
|
+
import_base7 = require("@scure/base");
|
|
2517
3329
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
2518
3330
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
2519
3331
|
import_sdk7 = require("@arkade-os/sdk");
|
|
@@ -2528,7 +3340,7 @@ var init_rfq = __esm({
|
|
|
2528
3340
|
init_rfq_contract();
|
|
2529
3341
|
solverHex = (value, field) => {
|
|
2530
3342
|
try {
|
|
2531
|
-
return
|
|
3343
|
+
return import_base7.hex.decode(value);
|
|
2532
3344
|
} catch {
|
|
2533
3345
|
throw new Error(`solver sent malformed hex for ${field}`);
|
|
2534
3346
|
}
|
|
@@ -2648,7 +3460,7 @@ var init_rfq = __esm({
|
|
|
2648
3460
|
this.quoted = quoted;
|
|
2649
3461
|
}
|
|
2650
3462
|
};
|
|
2651
|
-
newRfqId = () =>
|
|
3463
|
+
newRfqId = () => import_base7.hex.encode(crypto.getRandomValues(new Uint8Array(32)));
|
|
2652
3464
|
lightningSendRequest = (input) => ({
|
|
2653
3465
|
v: 1,
|
|
2654
3466
|
type: "rfq_request",
|
|
@@ -2658,7 +3470,7 @@ var init_rfq = __esm({
|
|
|
2658
3470
|
profile: {
|
|
2659
3471
|
invoice: input.invoice,
|
|
2660
3472
|
refund_address: input.refundAddress,
|
|
2661
|
-
client_refund_pubkey:
|
|
3473
|
+
client_refund_pubkey: import_base7.hex.encode(input.senderPubkey)
|
|
2662
3474
|
}
|
|
2663
3475
|
});
|
|
2664
3476
|
arkadeSwapRequest = (input) => {
|
|
@@ -2712,7 +3524,7 @@ var init_rfq = __esm({
|
|
|
2712
3524
|
const got = bytes instanceof Uint8Array ? bytes.length : typeof bytes;
|
|
2713
3525
|
throw new Error(`${label} must be ${expectedBytes} bytes, got ${got}`);
|
|
2714
3526
|
}
|
|
2715
|
-
return
|
|
3527
|
+
return import_base7.hex.encode(bytes);
|
|
2716
3528
|
};
|
|
2717
3529
|
normalizeMakerPkScript = (value) => {
|
|
2718
3530
|
const encoded = normalizeHexBytes(value, 34, "maker_pk_script");
|
|
@@ -2722,7 +3534,7 @@ var init_rfq = __esm({
|
|
|
2722
3534
|
return encoded;
|
|
2723
3535
|
};
|
|
2724
3536
|
normalizeMakerPublicKey = (value) => {
|
|
2725
|
-
const raw = typeof value === "string" ? value :
|
|
3537
|
+
const raw = typeof value === "string" ? value : import_base7.hex.encode(value);
|
|
2726
3538
|
const bytes = solverHex(raw, "maker_public_key");
|
|
2727
3539
|
if (bytes.length === 33) {
|
|
2728
3540
|
throw new Error("maker_public_key must be x-only (32 bytes), not compressed (33 bytes)");
|
|
@@ -2890,7 +3702,7 @@ var init_rfq = __esm({
|
|
|
2890
3702
|
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2891
3703
|
if (!advertised.includes(version)) {
|
|
2892
3704
|
throw new Error(
|
|
2893
|
-
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
3705
|
+
selected === void 0 ? `solver negotiated no contract version; advertised ${advertised.join(", ")}` : `solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2894
3706
|
);
|
|
2895
3707
|
}
|
|
2896
3708
|
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
@@ -3041,7 +3853,7 @@ var init_rfq = __esm({
|
|
|
3041
3853
|
sender: roles.sender,
|
|
3042
3854
|
receiver: roles.receiver,
|
|
3043
3855
|
server: params.operatorPubkey,
|
|
3044
|
-
preimageHash: (0, import_legacy2.ripemd160)(
|
|
3856
|
+
preimageHash: (0, import_legacy2.ripemd160)(import_base7.hex.decode(params.paymentHash)),
|
|
3045
3857
|
refundLocktime: BigInt(params.refundLocktime),
|
|
3046
3858
|
unilateralClaimDelay: seconds(params.claimDelay),
|
|
3047
3859
|
unilateralRefundDelay: seconds(unilateralRefundDelay(params.claimDelay)),
|
|
@@ -3074,7 +3886,7 @@ var init_rfq = __esm({
|
|
|
3074
3886
|
verifyOfferAddress = (quote, derived) => {
|
|
3075
3887
|
const quotedAddress = quote.profile?.offer_address;
|
|
3076
3888
|
const quotedScript = quote.profile?.offer_pk_script;
|
|
3077
|
-
const derivedScript =
|
|
3889
|
+
const derivedScript = import_base7.hex.encode(derived.swapPkScript);
|
|
3078
3890
|
if (quotedAddress !== derived.address || quotedScript !== derivedScript) {
|
|
3079
3891
|
throw new AddressMismatch([derived.address], quotedAddress);
|
|
3080
3892
|
}
|
|
@@ -3109,9 +3921,9 @@ var init_rfq = __esm({
|
|
|
3109
3921
|
operatorTerms = (info, emulatorPubkey) => {
|
|
3110
3922
|
const network = (0, import_sdk7.networkFromOperatorInfo)(info);
|
|
3111
3923
|
return {
|
|
3112
|
-
operatorPubkey: (0, import_sdk7.toXOnly)(
|
|
3924
|
+
operatorPubkey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(info.signerPubkey), "ark signer key"),
|
|
3113
3925
|
emulatorPubkey: (0, import_sdk7.toXOnly)(
|
|
3114
|
-
|
|
3926
|
+
import_base7.hex.decode((0, import_sdk7.resolveEmulatorPubkey)(network, emulatorPubkey)),
|
|
3115
3927
|
"emulator signer key"
|
|
3116
3928
|
),
|
|
3117
3929
|
claimDelay: unilateralClaimDelay(Number(info.unilateralExitDelay)),
|
|
@@ -3127,9 +3939,9 @@ var init_rfq = __esm({
|
|
|
3127
3939
|
amount: input.amount,
|
|
3128
3940
|
profile: {
|
|
3129
3941
|
payment_hash: input.paymentHash,
|
|
3130
|
-
payout_pubkey:
|
|
3942
|
+
payout_pubkey: import_base7.hex.encode(input.payoutPubkey),
|
|
3131
3943
|
refund_address: input.refundAddress,
|
|
3132
|
-
client_refund_pubkey:
|
|
3944
|
+
client_refund_pubkey: import_base7.hex.encode(input.senderPubkey)
|
|
3133
3945
|
}
|
|
3134
3946
|
});
|
|
3135
3947
|
lightningReceiveRequest = (input) => ({
|
|
@@ -3142,7 +3954,7 @@ var init_rfq = __esm({
|
|
|
3142
3954
|
profile: {
|
|
3143
3955
|
payment_hash: input.paymentHash,
|
|
3144
3956
|
payout_address: input.payoutAddress,
|
|
3145
|
-
payout_pubkey:
|
|
3957
|
+
payout_pubkey: import_base7.hex.encode(input.payoutPubkey),
|
|
3146
3958
|
...input.claimPacket === void 0 ? {} : { claim_packet: input.claimPacket }
|
|
3147
3959
|
}
|
|
3148
3960
|
});
|
|
@@ -3156,9 +3968,9 @@ var init_rfq = __esm({
|
|
|
3156
3968
|
profile: {
|
|
3157
3969
|
payment_hash: input.paymentHash,
|
|
3158
3970
|
...input.claimPacket === void 0 ? {} : { claim_packet: input.claimPacket },
|
|
3159
|
-
refund_pubkey:
|
|
3971
|
+
refund_pubkey: import_base7.hex.encode(input.refundPubkey),
|
|
3160
3972
|
payout_address: input.payoutAddress,
|
|
3161
|
-
payout_pubkey:
|
|
3973
|
+
payout_pubkey: import_base7.hex.encode(input.payoutPubkey)
|
|
3162
3974
|
}
|
|
3163
3975
|
});
|
|
3164
3976
|
assertQuotedAmount = (quote, amountSide, amount) => {
|
|
@@ -3233,7 +4045,7 @@ var init_rfq = __esm({
|
|
|
3233
4045
|
};
|
|
3234
4046
|
matchReceiveLockup = (input, refundLocktime, solverRefundPkScriptHex) => {
|
|
3235
4047
|
const contractParams = {
|
|
3236
|
-
solverPubkey: (0, import_sdk7.toXOnly)(
|
|
4048
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base7.hex.decode(input.quote.solver_pubkey), "solver key"),
|
|
3237
4049
|
refundLocktime,
|
|
3238
4050
|
operatorPubkey: input.operatorPubkey,
|
|
3239
4051
|
paymentHash: input.paymentHash,
|
|
@@ -3263,7 +4075,7 @@ var init_rfq = __esm({
|
|
|
3263
4075
|
);
|
|
3264
4076
|
}
|
|
3265
4077
|
const preimage = secrets.preimage;
|
|
3266
|
-
const paymentHash =
|
|
4078
|
+
const paymentHash = import_base7.hex.encode(secrets.paymentHash);
|
|
3267
4079
|
const payoutPubkey = secrets.pubkey;
|
|
3268
4080
|
const binds = bindsClaimAmount();
|
|
3269
4081
|
const claimPacket = params.covclaimdPubkey && (!binds || params.amountSide === "to") ? await sealClaimPacket({
|
|
@@ -3486,6 +4298,7 @@ var init_nostr = __esm({
|
|
|
3486
4298
|
{ kinds: [RFQ_DIRECTED_KIND], "#p": [pubkey], authors: [solverPubkey] },
|
|
3487
4299
|
{
|
|
3488
4300
|
onevent(event) {
|
|
4301
|
+
if (event.pubkey !== solverPubkey || !(0, import_nostr_tools2.verifyEvent)(event)) return;
|
|
3489
4302
|
let payload;
|
|
3490
4303
|
try {
|
|
3491
4304
|
payload = JSON.parse(import_nostr_tools2.nip44.v2.decrypt(event.content, conversationKey));
|
|
@@ -3666,8 +4479,10 @@ __export(protocol_exports, {
|
|
|
3666
4479
|
ASSET_CARRIER_SATS: () => ASSET_CARRIER_SATS,
|
|
3667
4480
|
ASSET_SWAP_BASELINE: () => ASSET_SWAP_BASELINE,
|
|
3668
4481
|
ASSET_SWAP_CONTRACT_VERSIONS: () => ASSET_SWAP_CONTRACT_VERSIONS,
|
|
4482
|
+
ASSET_SWAP_DERIVABLE_VERSIONS: () => ASSET_SWAP_DERIVABLE_VERSIONS,
|
|
3669
4483
|
ASSET_SWAP_V2: () => ASSET_SWAP_V2,
|
|
3670
4484
|
ASSET_SWAP_V3: () => ASSET_SWAP_V3,
|
|
4485
|
+
ASSET_SWAP_V4: () => ASSET_SWAP_V4,
|
|
3671
4486
|
AddressMismatch: () => AddressMismatch,
|
|
3672
4487
|
BTC_ASSET_ID: () => BTC_ASSET_ID,
|
|
3673
4488
|
CROSS_ASSET_RAIL: () => CROSS_ASSET_RAIL,
|
|
@@ -3711,6 +4526,8 @@ __export(protocol_exports, {
|
|
|
3711
4526
|
assetSwapContractVersion: () => assetSwapContractVersion,
|
|
3712
4527
|
awaitOnchainFill: () => awaitOnchainFill,
|
|
3713
4528
|
awaitRfqResolution: () => awaitRfqResolution,
|
|
4529
|
+
bindingFromOffer: () => bindingFromOffer,
|
|
4530
|
+
bindingProgram: () => bindingProgram,
|
|
3714
4531
|
buildHtlcClaim: () => buildHtlcClaim,
|
|
3715
4532
|
buildHtlcRefund: () => buildHtlcRefund,
|
|
3716
4533
|
cancelOffer: () => cancelOffer,
|
|
@@ -3750,12 +4567,14 @@ __export(protocol_exports, {
|
|
|
3750
4567
|
normalizeMakerPublicKey: () => normalizeMakerPublicKey,
|
|
3751
4568
|
normalizeRfqSwapRecord: () => normalizeRfqSwapRecord,
|
|
3752
4569
|
offerContract: () => offerContract,
|
|
4570
|
+
offerFromBinding: () => offerFromBinding,
|
|
3753
4571
|
offerVtxoScript: () => offerVtxoScript,
|
|
3754
4572
|
onchainHtlcScript: () => onchainHtlcScript,
|
|
3755
4573
|
onchainReceiveProfile: () => onchainReceiveProfile,
|
|
3756
4574
|
onchainReceiveRequest: () => onchainReceiveRequest,
|
|
3757
4575
|
onchainSendProfile: () => onchainSendProfile,
|
|
3758
4576
|
onchainSendRequest: () => onchainSendRequest,
|
|
4577
|
+
packetRecoverySource: () => packetRecoverySource,
|
|
3759
4578
|
paymentHashOf: () => paymentHashOf,
|
|
3760
4579
|
preimageForSwapRecord: () => preimageForSwapRecord,
|
|
3761
4580
|
pushClaim: () => pushClaim,
|
|
@@ -3803,15 +4622,15 @@ module.exports = __toCommonJS(protocol_exports);
|
|
|
3803
4622
|
|
|
3804
4623
|
// src/activity.ts
|
|
3805
4624
|
var import_sdk16 = require("@arkade-os/sdk");
|
|
3806
|
-
var
|
|
4625
|
+
var import_base12 = require("@scure/base");
|
|
3807
4626
|
|
|
3808
4627
|
// src/swapManager.ts
|
|
3809
|
-
var
|
|
4628
|
+
var import_base11 = require("@scure/base");
|
|
3810
4629
|
var import_sdk12 = require("@arkade-os/sdk");
|
|
3811
4630
|
init_onchainHtlc();
|
|
3812
4631
|
|
|
3813
4632
|
// src/refund.ts
|
|
3814
|
-
var
|
|
4633
|
+
var import_base8 = require("@scure/base");
|
|
3815
4634
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
3816
4635
|
var import_sdk9 = require("@arkade-os/sdk");
|
|
3817
4636
|
init_onchainHtlc();
|
|
@@ -3848,7 +4667,7 @@ var LockupNeedsRecoveryError = class extends Error {
|
|
|
3848
4667
|
};
|
|
3849
4668
|
async function findLockupVtxos(contracts, swapPkScript) {
|
|
3850
4669
|
const [row] = await contracts.getContractsWithVtxos({
|
|
3851
|
-
script:
|
|
4670
|
+
script: import_base8.hex.encode(swapPkScript)
|
|
3852
4671
|
});
|
|
3853
4672
|
const seen = /* @__PURE__ */ new Set();
|
|
3854
4673
|
const out = [];
|
|
@@ -3868,7 +4687,7 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3868
4687
|
}
|
|
3869
4688
|
return out;
|
|
3870
4689
|
}
|
|
3871
|
-
var hashesTo = (candidate, paymentHash) =>
|
|
4690
|
+
var hashesTo = (candidate, paymentHash) => import_base8.hex.encode((0, import_sha24.sha256)(candidate)) === paymentHash;
|
|
3872
4691
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
3873
4692
|
...(0, import_sdk9.getArkPsbtFields)(tx, inputIndex, import_sdk9.ConditionWitness).flat(),
|
|
3874
4693
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
@@ -3887,7 +4706,7 @@ var refundLeafScript = (tx, inputIndex) => {
|
|
|
3887
4706
|
}
|
|
3888
4707
|
};
|
|
3889
4708
|
async function readLockupFate(indexer, input) {
|
|
3890
|
-
const { vtxos } = await indexer.getVtxos({ scripts: [
|
|
4709
|
+
const { vtxos } = await indexer.getVtxos({ scripts: [import_base8.hex.encode(input.swapPkScript)] });
|
|
3891
4710
|
const all = vtxos ?? [];
|
|
3892
4711
|
if (all.length === 0) return { fate: "unknown" };
|
|
3893
4712
|
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0, import_sdk9.isVtxoSpent)(vtxo));
|
|
@@ -3929,7 +4748,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3929
4748
|
for (const raw of txs) {
|
|
3930
4749
|
let tx;
|
|
3931
4750
|
try {
|
|
3932
|
-
tx = import_sdk9.Transaction.fromPSBT(
|
|
4751
|
+
tx = import_sdk9.Transaction.fromPSBT(import_base8.base64.decode(raw));
|
|
3933
4752
|
} catch {
|
|
3934
4753
|
continue;
|
|
3935
4754
|
}
|
|
@@ -3938,7 +4757,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3938
4757
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
3939
4758
|
const spent = tx.getInput(i);
|
|
3940
4759
|
if (!spent.txid) continue;
|
|
3941
|
-
const txid =
|
|
4760
|
+
const txid = import_base8.hex.encode(spent.txid);
|
|
3942
4761
|
if (!checkpoint) {
|
|
3943
4762
|
if (spent.index !== 0 || !spentBy.has(txid)) continue;
|
|
3944
4763
|
const preimage = candidateWitnessItems(tx, i).find(
|
|
@@ -3961,7 +4780,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3961
4780
|
const leafScript = refundLeafScript(tx, i);
|
|
3962
4781
|
if (leafScript) {
|
|
3963
4782
|
refunded.add(`${vtxo.txid}:${vtxo.vout}`);
|
|
3964
|
-
leafScripts.add(
|
|
4783
|
+
leafScripts.add(import_base8.hex.encode(leafScript));
|
|
3965
4784
|
}
|
|
3966
4785
|
}
|
|
3967
4786
|
}
|
|
@@ -3982,7 +4801,7 @@ var operatorUnrollScript = async (operator, network) => {
|
|
|
3982
4801
|
return (0, import_sdk9.assertValidServerUnrollScript)(
|
|
3983
4802
|
info.checkpointTapscript,
|
|
3984
4803
|
network ?? (0, import_sdk9.networkFromOperatorInfo)(info),
|
|
3985
|
-
(0, import_sdk9.toXOnly)(
|
|
4804
|
+
(0, import_sdk9.toXOnly)(import_base8.hex.decode(info.forfeitPubkey), "forfeit key")
|
|
3986
4805
|
);
|
|
3987
4806
|
};
|
|
3988
4807
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
@@ -4050,7 +4869,7 @@ init_repository();
|
|
|
4050
4869
|
|
|
4051
4870
|
// src/rfqRecord.ts
|
|
4052
4871
|
var import_sdk10 = require("@arkade-os/sdk");
|
|
4053
|
-
var
|
|
4872
|
+
var import_base10 = require("@scure/base");
|
|
4054
4873
|
|
|
4055
4874
|
// src/rfqSwapState.ts
|
|
4056
4875
|
var RFQ_SWAP_TERMINAL_STATES = ["settled", "refunded", "failed"];
|
|
@@ -4067,7 +4886,7 @@ var isRecheckableRefundedSend = (record) => record.kind === "lightning_send" &&
|
|
|
4067
4886
|
init_rfqCorridor();
|
|
4068
4887
|
|
|
4069
4888
|
// src/rfqCorridors.ts
|
|
4070
|
-
var
|
|
4889
|
+
var import_base9 = require("@scure/base");
|
|
4071
4890
|
init_rfqCorridor();
|
|
4072
4891
|
init_rfqProfileParts();
|
|
4073
4892
|
init_onchainHtlc();
|
|
@@ -4106,14 +4925,14 @@ var LightningReceiveCorridor = {
|
|
|
4106
4925
|
};
|
|
4107
4926
|
function onchainSendProfile(result) {
|
|
4108
4927
|
return {
|
|
4109
|
-
claimKey:
|
|
4110
|
-
refundKey:
|
|
4928
|
+
claimKey: import_base9.hex.encode(result.htlcParams.claimKey),
|
|
4929
|
+
refundKey: import_base9.hex.encode(result.htlcParams.refundKey),
|
|
4111
4930
|
htlcLocktime: result.htlcParams.refundLocktime,
|
|
4112
4931
|
network: result.l1Network,
|
|
4113
4932
|
htlcAddress: result.htlc.address,
|
|
4114
4933
|
minConfirmations: result.minConfirmations,
|
|
4115
4934
|
expectedAmount: result.expectedAmount,
|
|
4116
|
-
payoutPkScript:
|
|
4935
|
+
payoutPkScript: import_base9.hex.encode(result.payoutPkScript)
|
|
4117
4936
|
};
|
|
4118
4937
|
}
|
|
4119
4938
|
var OnchainSendCorridor = {
|
|
@@ -4151,8 +4970,8 @@ var OnchainSendCorridor = {
|
|
|
4151
4970
|
// From the profile, not the covenant: the lockup commits to `hash160(P)`, the
|
|
4152
4971
|
// HTLC needs `sha256(P)`.
|
|
4153
4972
|
paymentHash,
|
|
4154
|
-
claimKey:
|
|
4155
|
-
refundKey:
|
|
4973
|
+
claimKey: import_base9.hex.decode(profile.claimKey),
|
|
4974
|
+
refundKey: import_base9.hex.decode(profile.refundKey),
|
|
4156
4975
|
refundLocktime: profile.htlcLocktime
|
|
4157
4976
|
},
|
|
4158
4977
|
profile.network
|
|
@@ -4169,7 +4988,7 @@ var OnchainSendCorridor = {
|
|
|
4169
4988
|
expectedAmount: profile.expectedAmount,
|
|
4170
4989
|
// Optional here, required at the write: throwing on an older
|
|
4171
4990
|
// record would strand the refund it is still owed.
|
|
4172
|
-
...profile.payoutPkScript ? { payoutPkScript:
|
|
4991
|
+
...profile.payoutPkScript ? { payoutPkScript: import_base9.hex.decode(profile.payoutPkScript) } : {},
|
|
4173
4992
|
...profile.funding ? { funding: profile.funding } : {},
|
|
4174
4993
|
...profile.claimTxid ? { claimTxid: profile.claimTxid } : {},
|
|
4175
4994
|
...typeof profile.claimFeeRateSatVb === "number" ? { claimFeeRateSatVb: profile.claimFeeRateSatVb } : {},
|
|
@@ -4184,13 +5003,13 @@ var OnchainSendCorridor = {
|
|
|
4184
5003
|
};
|
|
4185
5004
|
function onchainReceiveProfile(result) {
|
|
4186
5005
|
return {
|
|
4187
|
-
claimKey:
|
|
4188
|
-
refundKey:
|
|
5006
|
+
claimKey: import_base9.hex.encode(result.htlcParams.claimKey),
|
|
5007
|
+
refundKey: import_base9.hex.encode(result.htlcParams.refundKey),
|
|
4189
5008
|
htlcLocktime: result.htlcParams.refundLocktime,
|
|
4190
5009
|
network: result.l1Network,
|
|
4191
5010
|
htlcAddress: result.htlc.address,
|
|
4192
5011
|
minConfirmations: result.minConfirmations,
|
|
4193
|
-
refundPkScript:
|
|
5012
|
+
refundPkScript: import_base9.hex.encode(result.refundPkScript),
|
|
4194
5013
|
...result.refundDescriptor === void 0 ? {} : { refundDescriptor: result.refundDescriptor }
|
|
4195
5014
|
};
|
|
4196
5015
|
}
|
|
@@ -4227,8 +5046,8 @@ var OnchainReceiveCorridor = {
|
|
|
4227
5046
|
const htlc = onchainHtlcScript(
|
|
4228
5047
|
{
|
|
4229
5048
|
paymentHash,
|
|
4230
|
-
claimKey:
|
|
4231
|
-
refundKey:
|
|
5049
|
+
claimKey: import_base9.hex.decode(profile.claimKey),
|
|
5050
|
+
refundKey: import_base9.hex.decode(profile.refundKey),
|
|
4232
5051
|
refundLocktime: profile.htlcLocktime
|
|
4233
5052
|
},
|
|
4234
5053
|
profile.network
|
|
@@ -4243,7 +5062,7 @@ var OnchainReceiveCorridor = {
|
|
|
4243
5062
|
htlc,
|
|
4244
5063
|
expectedAmount: profile.expectedAmount,
|
|
4245
5064
|
minConfirmations: profile.minConfirmations,
|
|
4246
|
-
refundPkScript:
|
|
5065
|
+
refundPkScript: import_base9.hex.decode(profile.refundPkScript),
|
|
4247
5066
|
...profile.claimTxid ? { claimTxid: profile.claimTxid } : {},
|
|
4248
5067
|
...profile.funding ? { funding: profile.funding } : {}
|
|
4249
5068
|
};
|
|
@@ -4299,8 +5118,8 @@ function assertSameSwap(origin, swap) {
|
|
|
4299
5118
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
4300
5119
|
);
|
|
4301
5120
|
}
|
|
4302
|
-
const funded =
|
|
4303
|
-
const watched =
|
|
5121
|
+
const funded = import_base10.hex.encode(import_sdk10.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
5122
|
+
const watched = import_base10.hex.encode(swap.lockupPkScript);
|
|
4304
5123
|
if (funded !== watched) {
|
|
4305
5124
|
throw new Error(
|
|
4306
5125
|
`rfq swap record's lockup address holds ${funded}, but the swap watches ${watched} \u2014 these are not the same swap`
|
|
@@ -4348,9 +5167,9 @@ function rfqSwapOriginOf(record) {
|
|
|
4348
5167
|
function lockupScript(params, lockupAddress) {
|
|
4349
5168
|
const script = import_sdk10.VHTLCV2ContractHandler.createScript(params);
|
|
4350
5169
|
const funded = import_sdk10.ArkAddress.decode(lockupAddress).pkScript;
|
|
4351
|
-
if (
|
|
5170
|
+
if (import_base10.hex.encode(funded) !== import_base10.hex.encode(script.pkScript)) {
|
|
4352
5171
|
throw new Error(
|
|
4353
|
-
`rfq swap covenant params derive ${
|
|
5172
|
+
`rfq swap covenant params derive ${import_base10.hex.encode(script.pkScript)}, but the record's lockup address holds ${import_base10.hex.encode(funded)} \u2014 these params are not this swap's`
|
|
4354
5173
|
);
|
|
4355
5174
|
}
|
|
4356
5175
|
return script;
|
|
@@ -4902,13 +5721,13 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4902
5721
|
// ── internals ────────────────────────────────────────────────────────────
|
|
4903
5722
|
track(swap) {
|
|
4904
5723
|
this.monitored.set(swap.rfqId, swap);
|
|
4905
|
-
this.byLockupScript.set(
|
|
5724
|
+
this.byLockupScript.set(import_base11.hex.encode(swap.lockupPkScript), swap);
|
|
4906
5725
|
}
|
|
4907
5726
|
/** Drops the swap from BOTH indexes. `pollSwap`'s `monitored` check also stops a late
|
|
4908
5727
|
* event, deliberately redundant so neither change alone re-drives a removed swap. */
|
|
4909
5728
|
untrack(rfqId) {
|
|
4910
5729
|
const swap = this.monitored.get(rfqId);
|
|
4911
|
-
if (swap) this.byLockupScript.delete(
|
|
5730
|
+
if (swap) this.byLockupScript.delete(import_base11.hex.encode(swap.lockupPkScript));
|
|
4912
5731
|
this.monitored.delete(rfqId);
|
|
4913
5732
|
this.refundRefused.delete(rfqId);
|
|
4914
5733
|
this.claimedOutpoints.delete(rfqId);
|
|
@@ -4954,7 +5773,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4954
5773
|
if (!lockup) {
|
|
4955
5774
|
try {
|
|
4956
5775
|
const [existing] = await contracts.getContracts({
|
|
4957
|
-
script:
|
|
5776
|
+
script: import_base11.hex.encode(swap.lockupPkScript)
|
|
4958
5777
|
});
|
|
4959
5778
|
if (existing) {
|
|
4960
5779
|
this.registered.set(swap.rfqId, true);
|
|
@@ -4973,13 +5792,13 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4973
5792
|
);
|
|
4974
5793
|
return;
|
|
4975
5794
|
}
|
|
4976
|
-
const script =
|
|
4977
|
-
if (script !==
|
|
5795
|
+
const script = import_base11.hex.encode(lockup.script.pkScript);
|
|
5796
|
+
if (script !== import_base11.hex.encode(swap.lockupPkScript)) {
|
|
4978
5797
|
this.registered.set(swap.rfqId, false);
|
|
4979
5798
|
this.emitFailed(
|
|
4980
5799
|
swap,
|
|
4981
5800
|
new Error(
|
|
4982
|
-
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${
|
|
5801
|
+
`swap ${swap.rfqId} lockup script ${script} does not match its lockupPkScript ${import_base11.hex.encode(swap.lockupPkScript)}`
|
|
4983
5802
|
)
|
|
4984
5803
|
);
|
|
4985
5804
|
return;
|
|
@@ -4996,7 +5815,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
4996
5815
|
retireContract(swap) {
|
|
4997
5816
|
if (!this.deps.contracts || !this.registered.get(swap.rfqId)) return;
|
|
4998
5817
|
if (!LOCKUP_RETIRABLE.includes(swap.state)) return;
|
|
4999
|
-
void this.deps.contracts.setContractWatchState(
|
|
5818
|
+
void this.deps.contracts.setContractWatchState(import_base11.hex.encode(swap.lockupPkScript), "retained").catch((error) => this.emitFailed(swap, error));
|
|
5000
5819
|
}
|
|
5001
5820
|
arm() {
|
|
5002
5821
|
if (!this.running) return;
|
|
@@ -5566,7 +6385,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
5566
6385
|
*/
|
|
5567
6386
|
stampSettlementPreimage(swap, preimage) {
|
|
5568
6387
|
if (swap.kind !== "lightning_send") return;
|
|
5569
|
-
swap.settlementPreimageHex =
|
|
6388
|
+
swap.settlementPreimageHex = import_base11.hex.encode(preimage);
|
|
5570
6389
|
this.touch(swap);
|
|
5571
6390
|
}
|
|
5572
6391
|
touch(swap) {
|
|
@@ -5959,7 +6778,7 @@ async function activityInputOf(stored, indexer) {
|
|
|
5959
6778
|
async function lockupTxids(indexer, record, wantFunding) {
|
|
5960
6779
|
let script;
|
|
5961
6780
|
try {
|
|
5962
|
-
script =
|
|
6781
|
+
script = import_base12.hex.encode(import_sdk16.ArkAddress.decode(record.lockupAddress).pkScript);
|
|
5963
6782
|
} catch {
|
|
5964
6783
|
return [];
|
|
5965
6784
|
}
|
|
@@ -6017,7 +6836,7 @@ function arkadeRefunder(deps) {
|
|
|
6017
6836
|
|
|
6018
6837
|
// src/chainSource.ts
|
|
6019
6838
|
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
6020
|
-
var
|
|
6839
|
+
var import_base13 = require("@scure/base");
|
|
6021
6840
|
init_onchainHtlc();
|
|
6022
6841
|
var addressOf = (pkScript, network) => btc3.Address(L1_NETWORKS[network]).encode(btc3.OutScript.decode(pkScript));
|
|
6023
6842
|
var chainSourceFrom = (provider, network) => {
|
|
@@ -6047,7 +6866,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
6047
6866
|
const spender = outspend.txid || await spenderFromHistory(txid, vout, pkScript);
|
|
6048
6867
|
if (!spender) return null;
|
|
6049
6868
|
const raw = await provider.getRawTransaction(spender);
|
|
6050
|
-
return { txHex:
|
|
6869
|
+
return { txHex: import_base13.hex.encode(raw) };
|
|
6051
6870
|
},
|
|
6052
6871
|
broadcast(txHex) {
|
|
6053
6872
|
return provider.broadcastTransaction(txHex);
|
|
@@ -6065,7 +6884,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
6065
6884
|
};
|
|
6066
6885
|
|
|
6067
6886
|
// src/claim.ts
|
|
6068
|
-
var
|
|
6887
|
+
var import_base14 = require("@scure/base");
|
|
6069
6888
|
var import_sdk17 = require("@arkade-os/sdk");
|
|
6070
6889
|
init_onchainHtlc();
|
|
6071
6890
|
var LockupAmountMismatchError = class extends Error {
|
|
@@ -6429,6 +7248,7 @@ init_program();
|
|
|
6429
7248
|
init_onchainHtlc();
|
|
6430
7249
|
|
|
6431
7250
|
// src/payment/crossAsset.ts
|
|
7251
|
+
var import_base15 = require("@scure/base");
|
|
6432
7252
|
var import_sdk20 = require("@arkade-os/sdk");
|
|
6433
7253
|
init_offer();
|
|
6434
7254
|
init_store();
|
|
@@ -6542,7 +7362,7 @@ function crossAssetRail(deps) {
|
|
|
6542
7362
|
const result = {
|
|
6543
7363
|
railId: CROSS_ASSET_RAIL,
|
|
6544
7364
|
txid,
|
|
6545
|
-
swapId: offer.
|
|
7365
|
+
swapId: import_base15.hex.encode(offer.swapPkScript)
|
|
6546
7366
|
};
|
|
6547
7367
|
emit({ status: "settled", result });
|
|
6548
7368
|
return result;
|
|
@@ -6554,7 +7374,7 @@ function crossAssetRail(deps) {
|
|
|
6554
7374
|
|
|
6555
7375
|
// src/payment/rendezvous.ts
|
|
6556
7376
|
var import_solver_discovery6 = require("@arkade-os/solver-discovery");
|
|
6557
|
-
var
|
|
7377
|
+
var import_base16 = require("@scure/base");
|
|
6558
7378
|
var XONLY_HEX = /^[0-9a-f]{64}$/;
|
|
6559
7379
|
var rendezvousOf = (market, pinned) => {
|
|
6560
7380
|
const transports = { nostr: { relays: market.transports?.nostr?.relays ?? [] } };
|
|
@@ -6573,7 +7393,7 @@ var rendezvousOf = (market, pinned) => {
|
|
|
6573
7393
|
};
|
|
6574
7394
|
};
|
|
6575
7395
|
var solverRendezvous = (markets, payoutCorridor, amountSats, fallbackEmulatorPubkey) => {
|
|
6576
|
-
const pinned = fallbackEmulatorPubkey ?
|
|
7396
|
+
const pinned = fallbackEmulatorPubkey ? import_base16.hex.encode(fallbackEmulatorPubkey) : void 0;
|
|
6577
7397
|
if (pinned !== void 0 && !XONLY_HEX.test(pinned)) return void 0;
|
|
6578
7398
|
const quoteCorridor = payoutCorridor === "lightning" ? "bolt11" : "bitcoin";
|
|
6579
7399
|
const isBtc = (id) => id === "btc" || /^(?:arkade|bolt11|bitcoin):[^/]+\/slip44:(?:0|1)$/.test(id ?? "");
|
|
@@ -6798,7 +7618,7 @@ function solverLightningRail(deps) {
|
|
|
6798
7618
|
}
|
|
6799
7619
|
|
|
6800
7620
|
// src/restore.ts
|
|
6801
|
-
var
|
|
7621
|
+
var import_base17 = require("@scure/base");
|
|
6802
7622
|
var import_sdk23 = require("@arkade-os/sdk");
|
|
6803
7623
|
init_offer();
|
|
6804
7624
|
init_store();
|
|
@@ -6817,7 +7637,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
6817
7637
|
if (result.status !== "fulfilled") continue;
|
|
6818
7638
|
for (const psbt of result.value) {
|
|
6819
7639
|
try {
|
|
6820
|
-
const parsed = import_sdk23.Transaction.fromPSBT(
|
|
7640
|
+
const parsed = import_sdk23.Transaction.fromPSBT(import_base17.base64.decode(psbt));
|
|
6821
7641
|
parsedByTxid.set(parsed.id, parsed);
|
|
6822
7642
|
} catch {
|
|
6823
7643
|
}
|
|
@@ -6831,8 +7651,16 @@ var unscannedSwapCandidates = (txs, existingIds, scanned) => txs.filter(
|
|
|
6831
7651
|
function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
6832
7652
|
let leaves;
|
|
6833
7653
|
try {
|
|
6834
|
-
|
|
6835
|
-
if (
|
|
7654
|
+
let script;
|
|
7655
|
+
if ("version" in offer) {
|
|
7656
|
+
const { program, args, keys } = bindingProgram(offer);
|
|
7657
|
+
script = new import_sdk23.arkade.ArkadeProgramScript(program, args, keys);
|
|
7658
|
+
} else {
|
|
7659
|
+
script = offerContract(offer, operatorPubkey);
|
|
7660
|
+
if (import_base17.hex.encode(script.pkScript) !== import_base17.hex.encode(offer.swapPkScript)) {
|
|
7661
|
+
return "indeterminate";
|
|
7662
|
+
}
|
|
7663
|
+
}
|
|
6836
7664
|
leaves = {
|
|
6837
7665
|
// `exit` is absent on an offer with no exit closure, and drops out here
|
|
6838
7666
|
returned: ["cancel", "exit"].map((name) => script.functionByName(name)?.leafScript).filter((leaf) => leaf !== void 0),
|
|
@@ -6844,11 +7672,11 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
6844
7672
|
for (let i = 0; i < spendTx.inputsLength; i++) {
|
|
6845
7673
|
const input = spendTx.getInput(i);
|
|
6846
7674
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
6847
|
-
if (
|
|
7675
|
+
if (import_base17.hex.encode(input.txid) !== deposit.txid) continue;
|
|
6848
7676
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
6849
|
-
const spent =
|
|
6850
|
-
if (leaves.returned.some((back) => spent ===
|
|
6851
|
-
if (leaves.fulfill && spent ===
|
|
7677
|
+
const spent = import_base17.hex.encode((0, import_sdk23.scriptFromTapLeafScript)(leaf));
|
|
7678
|
+
if (leaves.returned.some((back) => spent === import_base17.hex.encode(back))) return "cancelled";
|
|
7679
|
+
if (leaves.fulfill && spent === import_base17.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
6852
7680
|
}
|
|
6853
7681
|
}
|
|
6854
7682
|
return "indeterminate";
|
|
@@ -6861,21 +7689,56 @@ function classifyDepositSpend(offer, operatorPubkey, spendTxs, deposit) {
|
|
|
6861
7689
|
}
|
|
6862
7690
|
return "indeterminate";
|
|
6863
7691
|
}
|
|
7692
|
+
var encodesOffer = (offerHex, offer) => {
|
|
7693
|
+
try {
|
|
7694
|
+
const { ratioNum: _num, ratioDen: _den, ...terms } = decodeOffer(import_base17.hex.decode(offerHex));
|
|
7695
|
+
return import_base17.hex.encode(encodeOffer(terms)) === import_base17.hex.encode(encodeOffer(offer));
|
|
7696
|
+
} catch {
|
|
7697
|
+
return false;
|
|
7698
|
+
}
|
|
7699
|
+
};
|
|
7700
|
+
var packetRecoverySource = (indexer) => ({
|
|
7701
|
+
name: "packet",
|
|
7702
|
+
async discover({ candidateTxids, operatorPubkey }) {
|
|
7703
|
+
const found = [];
|
|
7704
|
+
const declined = [];
|
|
7705
|
+
for (const [txid, parsed] of await fetchParsedTxs(indexer, [...candidateTxids])) {
|
|
7706
|
+
let packet;
|
|
7707
|
+
try {
|
|
7708
|
+
packet = import_sdk23.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
7709
|
+
} catch {
|
|
7710
|
+
}
|
|
7711
|
+
if (!packet) {
|
|
7712
|
+
declined.push(txid);
|
|
7713
|
+
continue;
|
|
7714
|
+
}
|
|
7715
|
+
const payload = packet.serialize();
|
|
7716
|
+
try {
|
|
7717
|
+
const binding = bindingFromOffer(decodeOffer(payload), operatorPubkey);
|
|
7718
|
+
found.push({ fundingTxid: txid, binding, offerHex: import_base17.hex.encode(payload) });
|
|
7719
|
+
} catch {
|
|
7720
|
+
}
|
|
7721
|
+
}
|
|
7722
|
+
return { found, declined };
|
|
7723
|
+
}
|
|
7724
|
+
});
|
|
6864
7725
|
async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
6865
7726
|
const {
|
|
6866
7727
|
operatorPubkey,
|
|
6867
7728
|
scanned = /* @__PURE__ */ new Set(),
|
|
6868
7729
|
reopen = [],
|
|
6869
7730
|
hrp,
|
|
6870
|
-
recoveredIn = /* @__PURE__ */ new Set()
|
|
7731
|
+
recoveredIn = /* @__PURE__ */ new Set(),
|
|
7732
|
+
sources = [packetRecoverySource(indexer)]
|
|
6871
7733
|
} = opts;
|
|
6872
7734
|
const reopened = [];
|
|
6873
7735
|
for (const swap of reopen) {
|
|
6874
7736
|
try {
|
|
7737
|
+
const source = storedOffer(swap);
|
|
6875
7738
|
reopened.push({
|
|
6876
7739
|
fundingTx: { type: "sent", redeemTxid: swap.fundingTxid },
|
|
6877
|
-
offer:
|
|
6878
|
-
|
|
7740
|
+
offer: "version" in source ? offerFromBinding(source) : source,
|
|
7741
|
+
source,
|
|
6879
7742
|
existing: swap
|
|
6880
7743
|
});
|
|
6881
7744
|
} catch {
|
|
@@ -6889,30 +7752,41 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6889
7752
|
return { restored: [], scannedTxids: [] };
|
|
6890
7753
|
}
|
|
6891
7754
|
const byTxid = new Map(candidates.map((tx) => [tx.redeemTxid, tx]));
|
|
6892
|
-
const
|
|
6893
|
-
indexer,
|
|
6894
|
-
candidates.map((tx) => tx.redeemTxid)
|
|
6895
|
-
);
|
|
6896
|
-
const fetchedTxids = [];
|
|
7755
|
+
const candidateTxids = candidates.map((tx) => tx.redeemTxid);
|
|
6897
7756
|
const found = [...reopened];
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
7757
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
7758
|
+
const declined = /* @__PURE__ */ new Set();
|
|
7759
|
+
for (const recovery of candidateTxids.length === 0 ? [] : sources) {
|
|
7760
|
+
let answer;
|
|
6902
7761
|
try {
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
7762
|
+
answer = await recovery.discover({ candidateTxids, operatorPubkey });
|
|
7763
|
+
} catch (error) {
|
|
7764
|
+
console.warn(`[swap] recovery source ${recovery.name} failed`, error);
|
|
7765
|
+
continue;
|
|
7766
|
+
}
|
|
7767
|
+
for (const txid of answer.declined) declined.add(txid);
|
|
7768
|
+
for (const { fundingTxid, binding, offerHex } of answer.found) {
|
|
7769
|
+
const fundingTx = byTxid.get(fundingTxid);
|
|
7770
|
+
if (!fundingTx || claimed.has(fundingTxid)) continue;
|
|
7771
|
+
let offer;
|
|
7772
|
+
try {
|
|
7773
|
+
offer = offerFromBinding(binding);
|
|
7774
|
+
} catch (error) {
|
|
7775
|
+
console.warn(`[swap] ${recovery.name} sent a binding that does not compile`, error);
|
|
7776
|
+
continue;
|
|
7777
|
+
}
|
|
7778
|
+
if (offerHex !== void 0 && !encodesOffer(offerHex, offer)) {
|
|
7779
|
+
console.warn(`[swap] ${recovery.name} sent a packet its binding does not match`);
|
|
7780
|
+
continue;
|
|
7781
|
+
}
|
|
7782
|
+
claimed.add(fundingTxid);
|
|
7783
|
+
const packet = offerHex ?? import_base17.hex.encode(encodeOffer(offer));
|
|
7784
|
+
found.push({ fundingTx, offer, source: binding, offerHex: packet });
|
|
6912
7785
|
}
|
|
6913
7786
|
}
|
|
6914
|
-
|
|
6915
|
-
|
|
7787
|
+
const answered = [...claimed, ...[...declined].filter((txid) => !claimed.has(txid))];
|
|
7788
|
+
if (found.length === 0) return { restored: [], scannedTxids: answered };
|
|
7789
|
+
const scripts = [...new Set(found.map((f) => import_base17.hex.encode(f.offer.swapPkScript)))];
|
|
6916
7790
|
const { vtxos } = await indexer.getVtxos({ scripts });
|
|
6917
7791
|
const vtxoByScriptAndTxid = new Map(vtxos.map((v) => [`${v.script}:${v.txid}`, v]));
|
|
6918
7792
|
const txByAnyId = /* @__PURE__ */ new Map();
|
|
@@ -6924,7 +7798,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6924
7798
|
const spendTxids = /* @__PURE__ */ new Set();
|
|
6925
7799
|
for (const { fundingTx, offer } of found) {
|
|
6926
7800
|
const vtxo = vtxoByScriptAndTxid.get(
|
|
6927
|
-
`${
|
|
7801
|
+
`${import_base17.hex.encode(offer.swapPkScript)}:${fundingTx.redeemTxid}`
|
|
6928
7802
|
);
|
|
6929
7803
|
if (!vtxo?.isSpent) continue;
|
|
6930
7804
|
for (const txid of spendTxidsOf(vtxo)) spendTxids.add(txid);
|
|
@@ -6932,8 +7806,8 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6932
7806
|
const spendTxByTxid = await fetchParsedTxs(indexer, [...spendTxids]);
|
|
6933
7807
|
const restored = [];
|
|
6934
7808
|
const unresolved = /* @__PURE__ */ new Set();
|
|
6935
|
-
for (const { fundingTx, offer, offerHex, existing } of found) {
|
|
6936
|
-
const swapPkScript =
|
|
7809
|
+
for (const { fundingTx, offer, source, offerHex, existing } of found) {
|
|
7810
|
+
const swapPkScript = import_base17.hex.encode(offer.swapPkScript);
|
|
6937
7811
|
const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
|
|
6938
7812
|
if (!vtxo) {
|
|
6939
7813
|
unresolved.add(fundingTx.redeemTxid);
|
|
@@ -6961,7 +7835,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6961
7835
|
} else if (vtxo.isSwept && !vtxo.isSpent) status = "recoverable";
|
|
6962
7836
|
else if (vtxo.isSpent) {
|
|
6963
7837
|
const spendTxs = spendTxidsOf(vtxo).map((id) => spendTxByTxid.get(id)).filter((tx) => tx !== void 0);
|
|
6964
|
-
const kind = classifyDepositSpend(
|
|
7838
|
+
const kind = classifyDepositSpend(source, operatorPubkey, spendTxs, {
|
|
6965
7839
|
txid: vtxo.txid,
|
|
6966
7840
|
vout: vtxo.vout
|
|
6967
7841
|
});
|
|
@@ -6977,20 +7851,19 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6977
7851
|
restored.push({ ...existing, status, spentTxid, ...completion });
|
|
6978
7852
|
continue;
|
|
6979
7853
|
}
|
|
7854
|
+
if (!("version" in source)) continue;
|
|
6980
7855
|
let swapAddress = "";
|
|
6981
7856
|
try {
|
|
6982
|
-
const compiled = offerContract(offer, operatorPubkey);
|
|
6983
|
-
if (import_base15.hex.encode(compiled.pkScript) !== swapPkScript) {
|
|
6984
|
-
unresolved.add(fundingTx.redeemTxid);
|
|
6985
|
-
continue;
|
|
6986
|
-
}
|
|
6987
7857
|
if (hrp !== void 0) {
|
|
6988
|
-
|
|
7858
|
+
const { program, args, keys } = bindingProgram(source);
|
|
7859
|
+
const compiled = new import_sdk23.arkade.ArkadeProgramScript(program, args, keys);
|
|
7860
|
+
swapAddress = compiled.address(hrp, source.serverPublicKey).encode();
|
|
6989
7861
|
}
|
|
6990
7862
|
} catch {
|
|
6991
7863
|
unresolved.add(fundingTx.redeemTxid);
|
|
6992
7864
|
continue;
|
|
6993
7865
|
}
|
|
7866
|
+
const covenant = source.taker === void 0 ? { offerHex: offerHex ?? import_base17.hex.encode(encodeOffer(offer)) } : { binding: recordOfferBinding(source) };
|
|
6994
7867
|
restored.push({
|
|
6995
7868
|
id: fundingTx.redeemTxid,
|
|
6996
7869
|
fromAsset,
|
|
@@ -6999,7 +7872,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6999
7872
|
toAmount: offer.wantAmount.toString(),
|
|
7000
7873
|
swapAddress,
|
|
7001
7874
|
swapPkScript,
|
|
7002
|
-
|
|
7875
|
+
...covenant,
|
|
7003
7876
|
fundingTxid: fundingTx.redeemTxid,
|
|
7004
7877
|
spentTxid,
|
|
7005
7878
|
status,
|
|
@@ -7007,7 +7880,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
7007
7880
|
...completion
|
|
7008
7881
|
});
|
|
7009
7882
|
}
|
|
7010
|
-
return { restored, scannedTxids:
|
|
7883
|
+
return { restored, scannedTxids: answered.filter((id) => !unresolved.has(id)) };
|
|
7011
7884
|
}
|
|
7012
7885
|
|
|
7013
7886
|
// src/protocol.ts
|
|
@@ -7016,7 +7889,7 @@ init_rfqProfileParts();
|
|
|
7016
7889
|
init_store();
|
|
7017
7890
|
|
|
7018
7891
|
// src/watch.ts
|
|
7019
|
-
var
|
|
7892
|
+
var import_base18 = require("@scure/base");
|
|
7020
7893
|
var import_sdk24 = require("@arkade-os/sdk");
|
|
7021
7894
|
init_coverage();
|
|
7022
7895
|
init_offer();
|
|
@@ -7065,9 +7938,9 @@ async function watchOfferSwaps({
|
|
|
7065
7938
|
if (candidates.length === 0) return "indeterminate";
|
|
7066
7939
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
7067
7940
|
return classifyDepositSpend(
|
|
7068
|
-
|
|
7941
|
+
storedOffer(swap),
|
|
7069
7942
|
operatorPubkey,
|
|
7070
|
-
txs.map((psbt) => import_sdk24.Transaction.fromPSBT(
|
|
7943
|
+
txs.map((psbt) => import_sdk24.Transaction.fromPSBT(import_base18.base64.decode(psbt))),
|
|
7071
7944
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
7072
7945
|
);
|
|
7073
7946
|
} catch {
|
|
@@ -7109,8 +7982,10 @@ async function watchOfferSwaps({
|
|
|
7109
7982
|
ASSET_CARRIER_SATS,
|
|
7110
7983
|
ASSET_SWAP_BASELINE,
|
|
7111
7984
|
ASSET_SWAP_CONTRACT_VERSIONS,
|
|
7985
|
+
ASSET_SWAP_DERIVABLE_VERSIONS,
|
|
7112
7986
|
ASSET_SWAP_V2,
|
|
7113
7987
|
ASSET_SWAP_V3,
|
|
7988
|
+
ASSET_SWAP_V4,
|
|
7114
7989
|
AddressMismatch,
|
|
7115
7990
|
BTC_ASSET_ID,
|
|
7116
7991
|
CROSS_ASSET_RAIL,
|
|
@@ -7154,6 +8029,8 @@ async function watchOfferSwaps({
|
|
|
7154
8029
|
assetSwapContractVersion,
|
|
7155
8030
|
awaitOnchainFill,
|
|
7156
8031
|
awaitRfqResolution,
|
|
8032
|
+
bindingFromOffer,
|
|
8033
|
+
bindingProgram,
|
|
7157
8034
|
buildHtlcClaim,
|
|
7158
8035
|
buildHtlcRefund,
|
|
7159
8036
|
cancelOffer,
|
|
@@ -7193,12 +8070,14 @@ async function watchOfferSwaps({
|
|
|
7193
8070
|
normalizeMakerPublicKey,
|
|
7194
8071
|
normalizeRfqSwapRecord,
|
|
7195
8072
|
offerContract,
|
|
8073
|
+
offerFromBinding,
|
|
7196
8074
|
offerVtxoScript,
|
|
7197
8075
|
onchainHtlcScript,
|
|
7198
8076
|
onchainReceiveProfile,
|
|
7199
8077
|
onchainReceiveRequest,
|
|
7200
8078
|
onchainSendProfile,
|
|
7201
8079
|
onchainSendRequest,
|
|
8080
|
+
packetRecoverySource,
|
|
7202
8081
|
paymentHashOf,
|
|
7203
8082
|
preimageForSwapRecord,
|
|
7204
8083
|
pushClaim,
|