@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/index.cjs
CHANGED
|
@@ -760,6 +760,141 @@ var init_asset_swap = __esm({
|
|
|
760
760
|
}
|
|
761
761
|
});
|
|
762
762
|
|
|
763
|
+
// src/contracts/asset-swap-v4.json
|
|
764
|
+
var asset_swap_v4_default;
|
|
765
|
+
var init_asset_swap_v4 = __esm({
|
|
766
|
+
"src/contracts/asset-swap-v4.json"() {
|
|
767
|
+
asset_swap_v4_default = {
|
|
768
|
+
formatVersion: 1,
|
|
769
|
+
contractName: "AssetSwap",
|
|
770
|
+
constructorInputs: [
|
|
771
|
+
{
|
|
772
|
+
name: "receiver",
|
|
773
|
+
type: "pubkey"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
name: "amount",
|
|
777
|
+
type: "int"
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
name: "assetTxid",
|
|
781
|
+
type: "bytes32"
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
name: "assetGroupIndex",
|
|
785
|
+
type: "int"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
name: "user",
|
|
789
|
+
type: "pubkey"
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
name: "taker",
|
|
793
|
+
type: "pubkey"
|
|
794
|
+
}
|
|
795
|
+
],
|
|
796
|
+
functions: [
|
|
797
|
+
{
|
|
798
|
+
name: "fulfill",
|
|
799
|
+
arkade: {
|
|
800
|
+
inputs: [],
|
|
801
|
+
asm: [
|
|
802
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
803
|
+
"OP_DUP",
|
|
804
|
+
"<assetTxid>",
|
|
805
|
+
"<assetGroupIndex>",
|
|
806
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
807
|
+
"OP_VERIFY",
|
|
808
|
+
"<amount>",
|
|
809
|
+
"OP_GREATERTHANOREQUAL",
|
|
810
|
+
"OP_VERIFY",
|
|
811
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
812
|
+
"1",
|
|
813
|
+
"OP_NUMEQUALVERIFY",
|
|
814
|
+
"<receiver>",
|
|
815
|
+
"OP_EQUAL"
|
|
816
|
+
]
|
|
817
|
+
},
|
|
818
|
+
leaves: [
|
|
819
|
+
{
|
|
820
|
+
name: "fulfill",
|
|
821
|
+
witness: [
|
|
822
|
+
{
|
|
823
|
+
name: "takerSig",
|
|
824
|
+
type: "signature",
|
|
825
|
+
encoding: "schnorr-64"
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
name: "serverSig",
|
|
829
|
+
type: "signature",
|
|
830
|
+
encoding: "schnorr-64",
|
|
831
|
+
injected: true
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
name: "emulatorSig",
|
|
835
|
+
type: "signature",
|
|
836
|
+
encoding: "schnorr-64",
|
|
837
|
+
injected: true
|
|
838
|
+
}
|
|
839
|
+
],
|
|
840
|
+
asm: [
|
|
841
|
+
"<taker>",
|
|
842
|
+
"OP_CHECKSIGVERIFY",
|
|
843
|
+
"<SERVER_KEY>",
|
|
844
|
+
"OP_CHECKSIGVERIFY",
|
|
845
|
+
"<EMULATOR_KEY:fulfill>",
|
|
846
|
+
"OP_CHECKSIG"
|
|
847
|
+
]
|
|
848
|
+
}
|
|
849
|
+
]
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
name: "cancel",
|
|
853
|
+
leaves: [
|
|
854
|
+
{
|
|
855
|
+
name: "cancel",
|
|
856
|
+
witness: [
|
|
857
|
+
{
|
|
858
|
+
name: "userSig",
|
|
859
|
+
type: "signature",
|
|
860
|
+
encoding: "schnorr-64"
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
name: "serverSig",
|
|
864
|
+
type: "signature",
|
|
865
|
+
encoding: "schnorr-64",
|
|
866
|
+
injected: true
|
|
867
|
+
}
|
|
868
|
+
],
|
|
869
|
+
asm: [
|
|
870
|
+
"<user>",
|
|
871
|
+
"OP_CHECKSIGVERIFY",
|
|
872
|
+
"<SERVER_KEY>",
|
|
873
|
+
"OP_CHECKSIG"
|
|
874
|
+
]
|
|
875
|
+
}
|
|
876
|
+
]
|
|
877
|
+
}
|
|
878
|
+
],
|
|
879
|
+
source: {
|
|
880
|
+
entry: "asset-swap-v4.ark",
|
|
881
|
+
files: {
|
|
882
|
+
"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"
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
compiler: {
|
|
886
|
+
name: "arkadec",
|
|
887
|
+
version: "0.1.0-rc.1",
|
|
888
|
+
options: {
|
|
889
|
+
optimize: true
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
updatedAt: "2026-11-19T20:57:50.605738400+00:00",
|
|
893
|
+
fingerprint: "sha256:d830de32cd1d286a0a1fac698ff114a6c8ef5338a69f9f813717d1038ab2fb4a"
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
|
|
763
898
|
// src/contracts/sats-swap.json
|
|
764
899
|
var sats_swap_default;
|
|
765
900
|
var init_sats_swap = __esm({
|
|
@@ -873,6 +1008,130 @@ var init_sats_swap = __esm({
|
|
|
873
1008
|
}
|
|
874
1009
|
});
|
|
875
1010
|
|
|
1011
|
+
// src/contracts/sats-swap-v4.json
|
|
1012
|
+
var sats_swap_v4_default;
|
|
1013
|
+
var init_sats_swap_v4 = __esm({
|
|
1014
|
+
"src/contracts/sats-swap-v4.json"() {
|
|
1015
|
+
sats_swap_v4_default = {
|
|
1016
|
+
formatVersion: 1,
|
|
1017
|
+
contractName: "SatsSwap",
|
|
1018
|
+
constructorInputs: [
|
|
1019
|
+
{
|
|
1020
|
+
name: "receiver",
|
|
1021
|
+
type: "pubkey"
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: "amount",
|
|
1025
|
+
type: "int"
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
name: "user",
|
|
1029
|
+
type: "pubkey"
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
name: "taker",
|
|
1033
|
+
type: "pubkey"
|
|
1034
|
+
}
|
|
1035
|
+
],
|
|
1036
|
+
functions: [
|
|
1037
|
+
{
|
|
1038
|
+
name: "fulfill",
|
|
1039
|
+
arkade: {
|
|
1040
|
+
inputs: [],
|
|
1041
|
+
asm: [
|
|
1042
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
1043
|
+
"OP_DUP",
|
|
1044
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
1045
|
+
"<amount>",
|
|
1046
|
+
"OP_GREATERTHANOREQUAL",
|
|
1047
|
+
"OP_VERIFY",
|
|
1048
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
1049
|
+
"1",
|
|
1050
|
+
"OP_NUMEQUALVERIFY",
|
|
1051
|
+
"<receiver>",
|
|
1052
|
+
"OP_EQUAL"
|
|
1053
|
+
]
|
|
1054
|
+
},
|
|
1055
|
+
leaves: [
|
|
1056
|
+
{
|
|
1057
|
+
name: "fulfill",
|
|
1058
|
+
witness: [
|
|
1059
|
+
{
|
|
1060
|
+
name: "takerSig",
|
|
1061
|
+
type: "signature",
|
|
1062
|
+
encoding: "schnorr-64"
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
name: "serverSig",
|
|
1066
|
+
type: "signature",
|
|
1067
|
+
encoding: "schnorr-64",
|
|
1068
|
+
injected: true
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
name: "emulatorSig",
|
|
1072
|
+
type: "signature",
|
|
1073
|
+
encoding: "schnorr-64",
|
|
1074
|
+
injected: true
|
|
1075
|
+
}
|
|
1076
|
+
],
|
|
1077
|
+
asm: [
|
|
1078
|
+
"<taker>",
|
|
1079
|
+
"OP_CHECKSIGVERIFY",
|
|
1080
|
+
"<SERVER_KEY>",
|
|
1081
|
+
"OP_CHECKSIGVERIFY",
|
|
1082
|
+
"<EMULATOR_KEY:fulfill>",
|
|
1083
|
+
"OP_CHECKSIG"
|
|
1084
|
+
]
|
|
1085
|
+
}
|
|
1086
|
+
]
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
name: "cancel",
|
|
1090
|
+
leaves: [
|
|
1091
|
+
{
|
|
1092
|
+
name: "cancel",
|
|
1093
|
+
witness: [
|
|
1094
|
+
{
|
|
1095
|
+
name: "userSig",
|
|
1096
|
+
type: "signature",
|
|
1097
|
+
encoding: "schnorr-64"
|
|
1098
|
+
},
|
|
1099
|
+
{
|
|
1100
|
+
name: "serverSig",
|
|
1101
|
+
type: "signature",
|
|
1102
|
+
encoding: "schnorr-64",
|
|
1103
|
+
injected: true
|
|
1104
|
+
}
|
|
1105
|
+
],
|
|
1106
|
+
asm: [
|
|
1107
|
+
"<user>",
|
|
1108
|
+
"OP_CHECKSIGVERIFY",
|
|
1109
|
+
"<SERVER_KEY>",
|
|
1110
|
+
"OP_CHECKSIG"
|
|
1111
|
+
]
|
|
1112
|
+
}
|
|
1113
|
+
]
|
|
1114
|
+
}
|
|
1115
|
+
],
|
|
1116
|
+
source: {
|
|
1117
|
+
entry: "sats-swap-v4.ark",
|
|
1118
|
+
files: {
|
|
1119
|
+
"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"
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
compiler: {
|
|
1123
|
+
name: "arkadec",
|
|
1124
|
+
version: "0.1.0-rc.1",
|
|
1125
|
+
options: {
|
|
1126
|
+
optimize: true
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1129
|
+
updatedAt: "2026-11-19T20:57:50.848496600+00:00",
|
|
1130
|
+
fingerprint: "sha256:6ca61bf7ed8d8f65af3141da4e95fcc896863650127dd20949a84e72258053f4"
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
|
|
876
1135
|
// src/legacy/swap-want-asset.program.v1.json
|
|
877
1136
|
var swap_want_asset_program_v1_default;
|
|
878
1137
|
var init_swap_want_asset_program_v1 = __esm({
|
|
@@ -959,7 +1218,7 @@ var init_swap_want_btc_program_v1 = __esm({
|
|
|
959
1218
|
});
|
|
960
1219
|
|
|
961
1220
|
// src/rfq-contract.ts
|
|
962
|
-
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_V3, ASSET_SWAP_BASELINE;
|
|
1221
|
+
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;
|
|
963
1222
|
var init_rfq_contract = __esm({
|
|
964
1223
|
"src/rfq-contract.ts"() {
|
|
965
1224
|
"use strict";
|
|
@@ -968,18 +1227,21 @@ var init_rfq_contract = __esm({
|
|
|
968
1227
|
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
969
1228
|
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
970
1229
|
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
1230
|
+
ASSET_SWAP_V4 = "asset-swap-v4";
|
|
971
1231
|
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
972
1232
|
}
|
|
973
1233
|
});
|
|
974
1234
|
|
|
975
1235
|
// src/program.ts
|
|
976
|
-
var import_sdk4, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
1236
|
+
var import_sdk4, swapPrograms, legacySwapPrograms, directedSwapPrograms, sharedArgs, refuseTaker, v3Args, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
977
1237
|
var init_program = __esm({
|
|
978
1238
|
"src/program.ts"() {
|
|
979
1239
|
"use strict";
|
|
980
1240
|
import_sdk4 = require("@arkade-os/sdk");
|
|
981
1241
|
init_asset_swap();
|
|
1242
|
+
init_asset_swap_v4();
|
|
982
1243
|
init_sats_swap();
|
|
1244
|
+
init_sats_swap_v4();
|
|
983
1245
|
init_swap_want_asset_program_v1();
|
|
984
1246
|
init_swap_want_btc_program_v1();
|
|
985
1247
|
init_rfq_contract();
|
|
@@ -992,38 +1254,59 @@ var init_program = __esm({
|
|
|
992
1254
|
wantAsset: import_sdk4.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
993
1255
|
wantBtc: import_sdk4.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
994
1256
|
};
|
|
1257
|
+
directedSwapPrograms = {
|
|
1258
|
+
wantAsset: import_sdk4.arkade.programFromArtifact(asset_swap_v4_default),
|
|
1259
|
+
wantBtc: import_sdk4.arkade.programFromArtifact(sats_swap_v4_default)
|
|
1260
|
+
};
|
|
995
1261
|
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
996
1262
|
user,
|
|
997
1263
|
server,
|
|
998
1264
|
...exitDelay && { exitDelay }
|
|
999
1265
|
});
|
|
1266
|
+
refuseTaker = (version, { taker }) => {
|
|
1267
|
+
if (taker !== void 0) throw new Error(`${version} binds no taker key`);
|
|
1268
|
+
};
|
|
1269
|
+
v3Args = (inputs) => ({
|
|
1270
|
+
receiver: inputs.receiver,
|
|
1271
|
+
amount: inputs.amount,
|
|
1272
|
+
...inputs.asset && {
|
|
1273
|
+
assetTxid: inputs.asset.txid,
|
|
1274
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
1275
|
+
},
|
|
1276
|
+
...sharedArgs(inputs)
|
|
1277
|
+
});
|
|
1000
1278
|
ASSET_SWAP_CONTRACTS = {
|
|
1001
1279
|
[ASSET_SWAP_V2]: {
|
|
1002
1280
|
programs: legacySwapPrograms,
|
|
1003
|
-
args: (inputs) =>
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1281
|
+
args: (inputs) => {
|
|
1282
|
+
refuseTaker(ASSET_SWAP_V2, inputs);
|
|
1283
|
+
return {
|
|
1284
|
+
makerWP: inputs.receiver,
|
|
1285
|
+
wantAmount: inputs.amount,
|
|
1286
|
+
...inputs.asset && {
|
|
1287
|
+
wantAssetTxid: inputs.asset.txid,
|
|
1288
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
1289
|
+
},
|
|
1290
|
+
...sharedArgs(inputs)
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1012
1293
|
},
|
|
1013
1294
|
[ASSET_SWAP_V3]: {
|
|
1014
1295
|
programs: swapPrograms,
|
|
1015
|
-
args: (inputs) =>
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1296
|
+
args: (inputs) => {
|
|
1297
|
+
refuseTaker(ASSET_SWAP_V3, inputs);
|
|
1298
|
+
return v3Args(inputs);
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
[ASSET_SWAP_V4]: {
|
|
1302
|
+
programs: directedSwapPrograms,
|
|
1303
|
+
args: (inputs) => {
|
|
1304
|
+
if (inputs.taker === void 0) throw new Error(`${ASSET_SWAP_V4} needs a taker key`);
|
|
1305
|
+
return { ...v3Args(inputs), taker: inputs.taker };
|
|
1306
|
+
}
|
|
1024
1307
|
}
|
|
1025
1308
|
};
|
|
1026
|
-
ASSET_SWAP_CONTRACT_VERSIONS = [
|
|
1309
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V4];
|
|
1027
1310
|
assetSwapContractVersion = (id) => {
|
|
1028
1311
|
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
1029
1312
|
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
@@ -1087,9 +1370,9 @@ var init_store = __esm({
|
|
|
1087
1370
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
1088
1371
|
getAssetSwapsOrThrow = async (repository) => {
|
|
1089
1372
|
return (await collectAssetSwaps(repository)).filter(
|
|
1090
|
-
(s) => s && typeof s.id === "string" && // offer swaps carry the TLV; onchain-corridor swaps carry
|
|
1091
|
-
// the payment hash instead —
|
|
1092
|
-
(typeof s.offerHex === "string" || typeof s.paymentHash === "string")
|
|
1373
|
+
(s) => s && typeof s.id === "string" && // offer swaps carry the TLV or the binding; onchain-corridor swaps carry
|
|
1374
|
+
// the payment hash instead — any of them marks a valid record
|
|
1375
|
+
(typeof s.offerHex === "string" || s.binding !== void 0 || typeof s.paymentHash === "string")
|
|
1093
1376
|
).sort(byNewest);
|
|
1094
1377
|
};
|
|
1095
1378
|
getAssetSwaps = async (repository) => {
|
|
@@ -1292,28 +1575,28 @@ function withExitClosure(program, exit) {
|
|
|
1292
1575
|
}
|
|
1293
1576
|
};
|
|
1294
1577
|
}
|
|
1295
|
-
function swapProgramBinding(offer, operatorPubkey, contractVersion
|
|
1578
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion) {
|
|
1296
1579
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
1297
1580
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
1298
1581
|
}
|
|
1582
|
+
const directed = offer.taker !== void 0;
|
|
1583
|
+
const version = contractVersion ?? (directed ? ASSET_SWAP_V4 : ASSET_SWAP_BASELINE);
|
|
1299
1584
|
const expected = offer.swapPkScript;
|
|
1300
|
-
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey,
|
|
1585
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, version);
|
|
1301
1586
|
const funded = import_base5.hex.encode(expected);
|
|
1302
|
-
const order = [
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
];
|
|
1306
|
-
for (const version of order) {
|
|
1307
|
-
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
1587
|
+
const order = directed ? [ASSET_SWAP_V4] : [ASSET_SWAP_BASELINE, ASSET_SWAP_V3];
|
|
1588
|
+
for (const candidate of order) {
|
|
1589
|
+
const binding = bindSwapProgram(offer, operatorPubkey, candidate);
|
|
1308
1590
|
if (pkOf(binding) === funded) return binding;
|
|
1309
1591
|
}
|
|
1310
|
-
return bindSwapProgram(offer, operatorPubkey,
|
|
1592
|
+
return bindSwapProgram(offer, operatorPubkey, directed ? ASSET_SWAP_V4 : version);
|
|
1311
1593
|
}
|
|
1312
1594
|
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1313
1595
|
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1314
1596
|
const user = offer.makerPublicKey;
|
|
1315
1597
|
const assetId = offer.wantAsset;
|
|
1316
1598
|
return {
|
|
1599
|
+
version: contractVersion,
|
|
1317
1600
|
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
1318
1601
|
args: args({
|
|
1319
1602
|
receiver: offer.makerPkScript.subarray(2),
|
|
@@ -1324,7 +1607,8 @@ function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
|
1324
1607
|
},
|
|
1325
1608
|
user,
|
|
1326
1609
|
server: operatorPubkey,
|
|
1327
|
-
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
1610
|
+
...offer.exitDelay && { exitDelay: offer.exitDelay.value },
|
|
1611
|
+
...offer.taker && { taker: offer.taker }
|
|
1328
1612
|
}),
|
|
1329
1613
|
keys: {
|
|
1330
1614
|
serverKey: operatorPubkey,
|
|
@@ -1347,6 +1631,33 @@ function pkOf(binding) {
|
|
|
1347
1631
|
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
1348
1632
|
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
1349
1633
|
}
|
|
1634
|
+
function bindingProgram(binding) {
|
|
1635
|
+
if (Boolean(binding.wantAsset) === Boolean(binding.offerAsset)) {
|
|
1636
|
+
throw new Error("an offer binding names exactly one of wantAsset or offerAsset");
|
|
1637
|
+
}
|
|
1638
|
+
return swapProgramBinding(termsOf(binding), binding.serverPublicKey, binding.version);
|
|
1639
|
+
}
|
|
1640
|
+
function bindingFromOffer(offer, operatorPubkey) {
|
|
1641
|
+
const program = swapProgramBinding(offer, operatorPubkey);
|
|
1642
|
+
if (pkOf(program) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1643
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript));
|
|
1644
|
+
}
|
|
1645
|
+
return {
|
|
1646
|
+
version: program.version,
|
|
1647
|
+
receiverPkScript: offer.makerPkScript,
|
|
1648
|
+
amount: offer.wantAmount,
|
|
1649
|
+
...offer.wantAsset && { wantAsset: offer.wantAsset },
|
|
1650
|
+
...offer.offerAsset && { offerAsset: offer.offerAsset },
|
|
1651
|
+
userPublicKey: offer.makerPublicKey,
|
|
1652
|
+
serverPublicKey: operatorPubkey,
|
|
1653
|
+
emulatorPublicKey: offer.emulatorPubkey,
|
|
1654
|
+
...offer.exitDelay && { exitDelay: offer.exitDelay },
|
|
1655
|
+
...offer.taker && { taker: offer.taker }
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
function offerFromBinding(binding) {
|
|
1659
|
+
return offerOf(binding, compileSwapBinding(bindingProgram(binding)).pkScript);
|
|
1660
|
+
}
|
|
1350
1661
|
function u64(name, value) {
|
|
1351
1662
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
1352
1663
|
throw new Error(`${name} does not fit the offer wire format (u64)`);
|
|
@@ -1373,6 +1684,9 @@ function encodeOffer(offer) {
|
|
|
1373
1684
|
throw new Error(`${name} must be ${FIELDS[name].width} bytes`);
|
|
1374
1685
|
}
|
|
1375
1686
|
}
|
|
1687
|
+
if (offer.taker !== void 0 && offer.taker.length !== FIELDS.taker.width) {
|
|
1688
|
+
throw new Error(`taker must be ${FIELDS.taker.width} bytes`);
|
|
1689
|
+
}
|
|
1376
1690
|
const ratioNum = setRatio("ratioNum", offer.ratioNum);
|
|
1377
1691
|
const ratioDen = setRatio("ratioDen", offer.ratioDen);
|
|
1378
1692
|
if (ratioNum === void 0 !== (ratioDen === void 0)) {
|
|
@@ -1388,9 +1702,10 @@ function encodeOffer(offer) {
|
|
|
1388
1702
|
if (offer.offerAsset) recs.push(tlv2(FIELDS.offerAsset.tag, offer.offerAsset.serialize()));
|
|
1389
1703
|
recs.push(
|
|
1390
1704
|
tlv2(FIELDS.makerPkScript.tag, offer.makerPkScript),
|
|
1391
|
-
tlv2(FIELDS.makerPublicKey.tag, offer.makerPublicKey)
|
|
1392
|
-
tlv2(FIELDS.emulatorPubkey.tag, offer.emulatorPubkey)
|
|
1705
|
+
tlv2(FIELDS.makerPublicKey.tag, offer.makerPublicKey)
|
|
1393
1706
|
);
|
|
1707
|
+
if (offer.taker) recs.push(tlv2(FIELDS.taker.tag, offer.taker));
|
|
1708
|
+
recs.push(tlv2(FIELDS.emulatorPubkey.tag, offer.emulatorPubkey));
|
|
1394
1709
|
if (offer.exitDelay) recs.push(tlv2(FIELDS.exitTimelock.tag, encodeExitDelay(offer.exitDelay)));
|
|
1395
1710
|
return (0, import_utils2.concatBytes)(...recs);
|
|
1396
1711
|
}
|
|
@@ -1468,7 +1783,8 @@ function decodeOffer(data) {
|
|
|
1468
1783
|
emulatorPubkey: need("emulatorPubkey"),
|
|
1469
1784
|
...ratioNum !== void 0 && { ratioNum },
|
|
1470
1785
|
...ratioDen !== void 0 && { ratioDen },
|
|
1471
|
-
...fields.exitTimelock && { exitDelay: decodeExitDelay(fields.exitTimelock) }
|
|
1786
|
+
...fields.exitTimelock && { exitDelay: decodeExitDelay(fields.exitTimelock) },
|
|
1787
|
+
...fields.taker && { taker: fields.taker }
|
|
1472
1788
|
};
|
|
1473
1789
|
}
|
|
1474
1790
|
function decodeExitDelay(value) {
|
|
@@ -1488,10 +1804,7 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
1488
1804
|
});
|
|
1489
1805
|
}
|
|
1490
1806
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
1491
|
-
const { program, args, keys } = swapProgramBinding(
|
|
1492
|
-
{ ...binding, swapPkScript: expectedPkScript },
|
|
1493
|
-
operatorPubkey
|
|
1494
|
-
);
|
|
1807
|
+
const { program, args, keys } = "version" in binding ? bindingProgram(binding) : swapProgramBinding({ ...binding, swapPkScript: expectedPkScript }, operatorPubkey);
|
|
1495
1808
|
const contract = new import_sdk6.arkade.ArkadeContract(client, program, args, keys);
|
|
1496
1809
|
if (import_base5.hex.encode(contract.pkScript) !== import_base5.hex.encode(expectedPkScript)) {
|
|
1497
1810
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
@@ -1523,7 +1836,7 @@ async function restoreOfferCoverage(wallet, swaps) {
|
|
|
1523
1836
|
if (seen.has(swap.swapPkScript)) continue;
|
|
1524
1837
|
seen.add(swap.swapPkScript);
|
|
1525
1838
|
try {
|
|
1526
|
-
const
|
|
1839
|
+
const binding = storedOffer(swap);
|
|
1527
1840
|
const stored = fundedKey.get(swap.swapPkScript);
|
|
1528
1841
|
covenants.push({
|
|
1529
1842
|
script: swap.swapPkScript,
|
|
@@ -1632,7 +1945,8 @@ async function deriveOffer(wallet, params) {
|
|
|
1632
1945
|
makerPublicKey: maker.publicKey,
|
|
1633
1946
|
emulatorPubkey: emuKey,
|
|
1634
1947
|
// checked before registration below. @see assertExitDelay
|
|
1635
|
-
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
1948
|
+
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay),
|
|
1949
|
+
...params.taker && { taker: params.taker }
|
|
1636
1950
|
});
|
|
1637
1951
|
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
1638
1952
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
@@ -1645,6 +1959,7 @@ async function deriveOffer(wallet, params) {
|
|
|
1645
1959
|
address: script.address(network.hrp, operatorPubKey).encode(),
|
|
1646
1960
|
swapPkScript: script.pkScript,
|
|
1647
1961
|
binding,
|
|
1962
|
+
offerBinding: Object.freeze(bindingFromOffer(offer, operatorPubKey)),
|
|
1648
1963
|
info,
|
|
1649
1964
|
operatorPubkey: operatorPubKey
|
|
1650
1965
|
});
|
|
@@ -1661,7 +1976,7 @@ async function registerDerivedOffer(wallet, derived, options = {}) {
|
|
|
1661
1976
|
}
|
|
1662
1977
|
async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
1663
1978
|
const { fundingTxid, fundingOutpoint, swapAddress } = opts;
|
|
1664
|
-
const
|
|
1979
|
+
const decoded = typeof offerHex === "string" ? decodeOffer(import_base5.hex.decode(offerHex)) : isOfferBinding(offerHex) ? void 0 : offerHex;
|
|
1665
1980
|
const [contractManager, info, reader, broadcaster] = await Promise.all([
|
|
1666
1981
|
wallet.getContractManager(),
|
|
1667
1982
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
@@ -1678,18 +1993,20 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1678
1993
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
1679
1994
|
oneShotSubmit: wallet.oneShotSubmit
|
|
1680
1995
|
});
|
|
1681
|
-
const
|
|
1996
|
+
const pinned = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress) : void 0;
|
|
1997
|
+
const funded = decoded ? decoded.swapPkScript : pinned?.pkScript;
|
|
1682
1998
|
let binding;
|
|
1683
1999
|
let rebuilt;
|
|
1684
2000
|
try {
|
|
1685
|
-
binding = swapProgramBinding(
|
|
2001
|
+
binding = decoded ? swapProgramBinding(decoded, pinned?.serverPubKey ?? client.serverKey) : bindingProgram(offerHex);
|
|
1686
2002
|
rebuilt = compileSwapBinding(binding);
|
|
1687
2003
|
} catch (cause) {
|
|
1688
|
-
throw new OfferCovenantMismatchError(import_base5.hex.encode(
|
|
2004
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(funded ?? new Uint8Array()), { cause });
|
|
1689
2005
|
}
|
|
1690
|
-
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(
|
|
1691
|
-
throw new OfferCovenantMismatchError(import_base5.hex.encode(
|
|
2006
|
+
if (funded && import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(funded)) {
|
|
2007
|
+
throw new OfferCovenantMismatchError(import_base5.hex.encode(funded));
|
|
1692
2008
|
}
|
|
2009
|
+
const offer = decoded ?? offerOf(offerHex, rebuilt.pkScript);
|
|
1693
2010
|
const contract = new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1694
2011
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
1695
2012
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
@@ -1721,10 +2038,11 @@ async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
|
1721
2038
|
} : {},
|
|
1722
2039
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
1723
2040
|
});
|
|
1724
|
-
const
|
|
1725
|
-
const binding = swapProgramBinding(offer, serverKey);
|
|
2041
|
+
const pinned = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress) : void 0;
|
|
2042
|
+
const binding = isOfferBinding(offer) ? bindingProgram(offer) : swapProgramBinding(offer, pinned?.serverPubKey ?? client.serverKey);
|
|
2043
|
+
const funded = isOfferBinding(offer) ? pinned?.pkScript : offer.swapPkScript;
|
|
1726
2044
|
const rebuilt = compileSwapBinding(binding);
|
|
1727
|
-
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(
|
|
2045
|
+
if (funded && import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(funded)) {
|
|
1728
2046
|
throw new Error(
|
|
1729
2047
|
"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"
|
|
1730
2048
|
);
|
|
@@ -2040,7 +2358,7 @@ function assertFillCoin(coin, what) {
|
|
|
2040
2358
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
2041
2359
|
assertAssetEntries(coin.assets, what);
|
|
2042
2360
|
}
|
|
2043
|
-
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;
|
|
2361
|
+
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;
|
|
2044
2362
|
var init_offer = __esm({
|
|
2045
2363
|
"src/offer.ts"() {
|
|
2046
2364
|
"use strict";
|
|
@@ -2052,11 +2370,67 @@ var init_offer = __esm({
|
|
|
2052
2370
|
init_rfqProfileParts();
|
|
2053
2371
|
init_store();
|
|
2054
2372
|
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
2373
|
+
isOfferBinding = (offer) => "version" in offer;
|
|
2374
|
+
termsOf = (binding) => ({
|
|
2375
|
+
wantAmount: binding.amount,
|
|
2376
|
+
...binding.wantAsset && { wantAsset: binding.wantAsset },
|
|
2377
|
+
...binding.offerAsset && { offerAsset: binding.offerAsset },
|
|
2378
|
+
makerPkScript: binding.receiverPkScript,
|
|
2379
|
+
makerPublicKey: binding.userPublicKey,
|
|
2380
|
+
emulatorPubkey: binding.emulatorPublicKey,
|
|
2381
|
+
...binding.exitDelay && { exitDelay: binding.exitDelay },
|
|
2382
|
+
...binding.taker && { taker: binding.taker }
|
|
2383
|
+
});
|
|
2384
|
+
offerOf = (offer, swapPkScript) => isOfferBinding(offer) ? { ...termsOf(offer), swapPkScript } : offer;
|
|
2385
|
+
recordOfferBinding = (binding) => ({
|
|
2386
|
+
version: binding.version,
|
|
2387
|
+
receiverPkScript: import_base5.hex.encode(binding.receiverPkScript),
|
|
2388
|
+
amount: binding.amount.toString(),
|
|
2389
|
+
...binding.wantAsset && { wantAsset: binding.wantAsset.toString() },
|
|
2390
|
+
...binding.offerAsset && { offerAsset: binding.offerAsset.toString() },
|
|
2391
|
+
userPublicKey: import_base5.hex.encode(binding.userPublicKey),
|
|
2392
|
+
serverPublicKey: import_base5.hex.encode(binding.serverPublicKey),
|
|
2393
|
+
emulatorPublicKey: import_base5.hex.encode(binding.emulatorPublicKey),
|
|
2394
|
+
...binding.exitDelay && {
|
|
2395
|
+
exitDelay: { type: binding.exitDelay.type, value: binding.exitDelay.value.toString() }
|
|
2396
|
+
},
|
|
2397
|
+
...binding.taker && { taker: import_base5.hex.encode(binding.taker) }
|
|
2398
|
+
});
|
|
2399
|
+
decimal = (value, name) => {
|
|
2400
|
+
if (!/^\d+$/.test(value)) throw new Error(`recorded binding ${name} is not a decimal amount`);
|
|
2401
|
+
return BigInt(value);
|
|
2402
|
+
};
|
|
2403
|
+
offerBindingOf = (recorded) => {
|
|
2404
|
+
if (typeof recorded.version !== "string" || !Object.hasOwn(ASSET_SWAP_CONTRACTS, recorded.version)) {
|
|
2405
|
+
throw new Error(`recorded binding names no known contract version (${recorded.version})`);
|
|
2406
|
+
}
|
|
2407
|
+
const { exitDelay, wantAsset, offerAsset, taker } = recorded;
|
|
2408
|
+
return {
|
|
2409
|
+
version: recorded.version,
|
|
2410
|
+
receiverPkScript: import_base5.hex.decode(recorded.receiverPkScript),
|
|
2411
|
+
amount: decimal(recorded.amount, "amount"),
|
|
2412
|
+
...wantAsset !== void 0 && { wantAsset: import_sdk6.asset.AssetId.fromString(wantAsset) },
|
|
2413
|
+
...offerAsset !== void 0 && { offerAsset: import_sdk6.asset.AssetId.fromString(offerAsset) },
|
|
2414
|
+
userPublicKey: import_base5.hex.decode(recorded.userPublicKey),
|
|
2415
|
+
serverPublicKey: import_base5.hex.decode(recorded.serverPublicKey),
|
|
2416
|
+
emulatorPublicKey: import_base5.hex.decode(recorded.emulatorPublicKey),
|
|
2417
|
+
...exitDelay && {
|
|
2418
|
+
exitDelay: { type: exitDelay.type, value: decimal(exitDelay.value, "exitDelay") }
|
|
2419
|
+
},
|
|
2420
|
+
...taker !== void 0 && { taker: import_base5.hex.decode(taker) }
|
|
2421
|
+
};
|
|
2422
|
+
};
|
|
2423
|
+
storedOffer = (swap) => {
|
|
2424
|
+
if (swap.binding !== void 0) return offerBindingOf(swap.binding);
|
|
2425
|
+
if (typeof swap.offerHex === "string") return decodeOffer(import_base5.hex.decode(swap.offerHex));
|
|
2426
|
+
throw new Error("this offer swap carries neither a binding nor an offerHex to rebuild from");
|
|
2427
|
+
};
|
|
2055
2428
|
OFFER_PACKET_TYPE = 3;
|
|
2056
2429
|
FIELDS = {
|
|
2057
2430
|
swapPkScript: { tag: 1, width: 34 },
|
|
2058
2431
|
wantAmount: { tag: 2, width: 8 },
|
|
2059
2432
|
wantAsset: { tag: 3, width: void 0 },
|
|
2433
|
+
taker: { tag: 4, width: 32 },
|
|
2060
2434
|
makerPkScript: { tag: 5, width: 34 },
|
|
2061
2435
|
makerPublicKey: { tag: 7, width: 32 },
|
|
2062
2436
|
emulatorPubkey: { tag: 8, width: 32 },
|
|
@@ -2677,7 +3051,7 @@ var init_rfq = __esm({
|
|
|
2677
3051
|
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2678
3052
|
if (!advertised.includes(version)) {
|
|
2679
3053
|
throw new Error(
|
|
2680
|
-
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
3054
|
+
selected === void 0 ? `solver negotiated no contract version; advertised ${advertised.join(", ")}` : `solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2681
3055
|
);
|
|
2682
3056
|
}
|
|
2683
3057
|
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
@@ -2857,6 +3231,191 @@ var init_rfq = __esm({
|
|
|
2857
3231
|
}
|
|
2858
3232
|
});
|
|
2859
3233
|
|
|
3234
|
+
// src/client/errors.ts
|
|
3235
|
+
function isSwapError(e, name) {
|
|
3236
|
+
if (!(e instanceof Error)) return false;
|
|
3237
|
+
const table = SWAP_ERRORS;
|
|
3238
|
+
const ctor = table[e.name];
|
|
3239
|
+
if (ctor === void 0 || !(e instanceof ctor)) return false;
|
|
3240
|
+
return name === void 0 || e.name === name;
|
|
3241
|
+
}
|
|
3242
|
+
var AmbiguousDestination, UnsupportedRoute, DiscoverySnapshotUnavailable, AmountMismatch, AmountEncodingUnsupported, QuoteVerificationFailed, QuoteExpired, MaxFeeExceeded, InsufficientFunds, AcceptConflict, ClientDisposed, NotCancellable, InconsistentRoute, OperatorUnreachable, MissingCorridorDep, SWAP_ERRORS, SWAP_ERROR_NAMES;
|
|
3243
|
+
var init_errors = __esm({
|
|
3244
|
+
"src/client/errors.ts"() {
|
|
3245
|
+
"use strict";
|
|
3246
|
+
init_rfq();
|
|
3247
|
+
AmbiguousDestination = class extends Error {
|
|
3248
|
+
constructor(destination, detail) {
|
|
3249
|
+
super(`cannot route ${JSON.stringify(destination)}: ${detail}`);
|
|
3250
|
+
this.destination = destination;
|
|
3251
|
+
}
|
|
3252
|
+
destination;
|
|
3253
|
+
name = "AmbiguousDestination";
|
|
3254
|
+
};
|
|
3255
|
+
UnsupportedRoute = class extends Error {
|
|
3256
|
+
name = "UnsupportedRoute";
|
|
3257
|
+
give;
|
|
3258
|
+
take;
|
|
3259
|
+
constructor(detail, corridors = {}) {
|
|
3260
|
+
super(`unsupported route: ${detail}`);
|
|
3261
|
+
this.give = corridors.give;
|
|
3262
|
+
this.take = corridors.take;
|
|
3263
|
+
}
|
|
3264
|
+
};
|
|
3265
|
+
DiscoverySnapshotUnavailable = class extends Error {
|
|
3266
|
+
constructor(network, detail) {
|
|
3267
|
+
super(`cannot resolve on ${network} offline: ${detail}`);
|
|
3268
|
+
this.network = network;
|
|
3269
|
+
}
|
|
3270
|
+
network;
|
|
3271
|
+
name = "DiscoverySnapshotUnavailable";
|
|
3272
|
+
};
|
|
3273
|
+
AmountMismatch = class extends Error {
|
|
3274
|
+
constructor(sources) {
|
|
3275
|
+
super(`exactly one amount may be pinned; got ${sources[0]} and ${sources[1]}`);
|
|
3276
|
+
this.sources = sources;
|
|
3277
|
+
}
|
|
3278
|
+
sources;
|
|
3279
|
+
name = "AmountMismatch";
|
|
3280
|
+
};
|
|
3281
|
+
AmountEncodingUnsupported = class extends Error {
|
|
3282
|
+
constructor(field, value, detail, options) {
|
|
3283
|
+
super(`${field}: ${detail}`, options);
|
|
3284
|
+
this.field = field;
|
|
3285
|
+
this.value = value;
|
|
3286
|
+
}
|
|
3287
|
+
field;
|
|
3288
|
+
value;
|
|
3289
|
+
name = "AmountEncodingUnsupported";
|
|
3290
|
+
};
|
|
3291
|
+
QuoteVerificationFailed = class extends Error {
|
|
3292
|
+
constructor(check, expected, actual, options) {
|
|
3293
|
+
super(`quote failed the ${check} check \u2014 refusing to fund`, options);
|
|
3294
|
+
this.check = check;
|
|
3295
|
+
this.expected = expected;
|
|
3296
|
+
this.actual = actual;
|
|
3297
|
+
}
|
|
3298
|
+
check;
|
|
3299
|
+
name = "QuoteVerificationFailed";
|
|
3300
|
+
expected;
|
|
3301
|
+
actual;
|
|
3302
|
+
};
|
|
3303
|
+
QuoteExpired = class extends Error {
|
|
3304
|
+
constructor(quoteId, expiresAt, now) {
|
|
3305
|
+
super(`quote ${quoteId} expired at ${expiresAt}, ${now - expiresAt} ago`);
|
|
3306
|
+
this.quoteId = quoteId;
|
|
3307
|
+
this.expiresAt = expiresAt;
|
|
3308
|
+
this.now = now;
|
|
3309
|
+
}
|
|
3310
|
+
quoteId;
|
|
3311
|
+
expiresAt;
|
|
3312
|
+
now;
|
|
3313
|
+
name = "QuoteExpired";
|
|
3314
|
+
};
|
|
3315
|
+
MaxFeeExceeded = class extends Error {
|
|
3316
|
+
constructor(quoteId, asset8, fee, maxFee) {
|
|
3317
|
+
super(`fee ${fee} of ${asset8} exceeds the ${maxFee} ceiling`);
|
|
3318
|
+
this.quoteId = quoteId;
|
|
3319
|
+
this.asset = asset8;
|
|
3320
|
+
this.fee = fee;
|
|
3321
|
+
this.maxFee = maxFee;
|
|
3322
|
+
}
|
|
3323
|
+
quoteId;
|
|
3324
|
+
asset;
|
|
3325
|
+
fee;
|
|
3326
|
+
maxFee;
|
|
3327
|
+
name = "MaxFeeExceeded";
|
|
3328
|
+
};
|
|
3329
|
+
InsufficientFunds = class extends Error {
|
|
3330
|
+
constructor(asset8, required, available) {
|
|
3331
|
+
super(
|
|
3332
|
+
`funding needs ${required} of ${asset8}` + (available === void 0 ? "" : `, wallet holds ${available}`)
|
|
3333
|
+
);
|
|
3334
|
+
this.asset = asset8;
|
|
3335
|
+
this.required = required;
|
|
3336
|
+
this.available = available;
|
|
3337
|
+
}
|
|
3338
|
+
asset;
|
|
3339
|
+
required;
|
|
3340
|
+
name = "InsufficientFunds";
|
|
3341
|
+
available;
|
|
3342
|
+
};
|
|
3343
|
+
AcceptConflict = class extends Error {
|
|
3344
|
+
constructor(quoteId, swapId, fields) {
|
|
3345
|
+
super(`accept ${quoteId} conflicts with swap ${swapId} on ${fields.join(", ")}`);
|
|
3346
|
+
this.quoteId = quoteId;
|
|
3347
|
+
this.swapId = swapId;
|
|
3348
|
+
this.fields = fields;
|
|
3349
|
+
}
|
|
3350
|
+
quoteId;
|
|
3351
|
+
swapId;
|
|
3352
|
+
fields;
|
|
3353
|
+
name = "AcceptConflict";
|
|
3354
|
+
};
|
|
3355
|
+
ClientDisposed = class extends Error {
|
|
3356
|
+
constructor(method) {
|
|
3357
|
+
super(`${method}() called after the client was disposed`);
|
|
3358
|
+
this.method = method;
|
|
3359
|
+
}
|
|
3360
|
+
method;
|
|
3361
|
+
name = "ClientDisposed";
|
|
3362
|
+
};
|
|
3363
|
+
NotCancellable = class extends Error {
|
|
3364
|
+
constructor(swapId) {
|
|
3365
|
+
super(`swap ${swapId} is not a cancellable asset swap`);
|
|
3366
|
+
this.swapId = swapId;
|
|
3367
|
+
}
|
|
3368
|
+
swapId;
|
|
3369
|
+
name = "NotCancellable";
|
|
3370
|
+
};
|
|
3371
|
+
InconsistentRoute = class extends Error {
|
|
3372
|
+
constructor(asset8, destination) {
|
|
3373
|
+
super(`destination ${JSON.stringify(destination)} is not on ${asset8}'s chain`);
|
|
3374
|
+
this.asset = asset8;
|
|
3375
|
+
this.destination = destination;
|
|
3376
|
+
}
|
|
3377
|
+
asset;
|
|
3378
|
+
destination;
|
|
3379
|
+
name = "InconsistentRoute";
|
|
3380
|
+
};
|
|
3381
|
+
OperatorUnreachable = class extends Error {
|
|
3382
|
+
name = "OperatorUnreachable";
|
|
3383
|
+
constructor(detail, options) {
|
|
3384
|
+
super(`cannot derive a covenant: ${detail}`, options);
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
MissingCorridorDep = class extends Error {
|
|
3388
|
+
constructor(corridor, dep) {
|
|
3389
|
+
super(`the ${corridor} corridor has no ${dep}`);
|
|
3390
|
+
this.corridor = corridor;
|
|
3391
|
+
this.dep = dep;
|
|
3392
|
+
}
|
|
3393
|
+
corridor;
|
|
3394
|
+
dep;
|
|
3395
|
+
name = "MissingCorridorDep";
|
|
3396
|
+
};
|
|
3397
|
+
SWAP_ERRORS = {
|
|
3398
|
+
AmbiguousDestination,
|
|
3399
|
+
UnsupportedRoute,
|
|
3400
|
+
DiscoverySnapshotUnavailable,
|
|
3401
|
+
AmountMismatch,
|
|
3402
|
+
AmountEncodingUnsupported,
|
|
3403
|
+
QuoteVerificationFailed,
|
|
3404
|
+
SwapRefusal,
|
|
3405
|
+
QuoteExpired,
|
|
3406
|
+
MaxFeeExceeded,
|
|
3407
|
+
InsufficientFunds,
|
|
3408
|
+
AcceptConflict,
|
|
3409
|
+
ClientDisposed,
|
|
3410
|
+
NotCancellable,
|
|
3411
|
+
InconsistentRoute,
|
|
3412
|
+
OperatorUnreachable,
|
|
3413
|
+
MissingCorridorDep
|
|
3414
|
+
};
|
|
3415
|
+
SWAP_ERROR_NAMES = Object.keys(SWAP_ERRORS);
|
|
3416
|
+
}
|
|
3417
|
+
});
|
|
3418
|
+
|
|
2860
3419
|
// src/closeOnceWebSocket.ts
|
|
2861
3420
|
var CloseOnceWebSocket;
|
|
2862
3421
|
var init_closeOnceWebSocket = __esm({
|
|
@@ -3056,6 +3615,7 @@ var init_nostr = __esm({
|
|
|
3056
3615
|
{ kinds: [RFQ_DIRECTED_KIND], "#p": [pubkey], authors: [solverPubkey] },
|
|
3057
3616
|
{
|
|
3058
3617
|
onevent(event) {
|
|
3618
|
+
if (event.pubkey !== solverPubkey || !(0, import_nostr_tools2.verifyEvent)(event)) return;
|
|
3059
3619
|
let payload;
|
|
3060
3620
|
try {
|
|
3061
3621
|
payload = JSON.parse(import_nostr_tools2.nip44.v2.decrypt(event.content, conversationKey));
|
|
@@ -3224,7 +3784,246 @@ var init_nostr = __esm({
|
|
|
3224
3784
|
if (inflight.get(key) === task) inflight.delete(key);
|
|
3225
3785
|
}
|
|
3226
3786
|
}
|
|
3227
|
-
};
|
|
3787
|
+
};
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
});
|
|
3791
|
+
|
|
3792
|
+
// src/client/policy.ts
|
|
3793
|
+
var DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
3794
|
+
var init_policy = __esm({
|
|
3795
|
+
"src/client/policy.ts"() {
|
|
3796
|
+
"use strict";
|
|
3797
|
+
DEFAULT_MAX_REFUND_WINDOW_SECONDS = 30 * 24 * 3600;
|
|
3798
|
+
}
|
|
3799
|
+
});
|
|
3800
|
+
|
|
3801
|
+
// src/client/verify.ts
|
|
3802
|
+
var import_base21, reasonOf, CHECK_BY_REASON, gated, verifyResponder, verifyTaker, verifyPair, verifyingDerivation, verifySendWindow, verifyReceiveWindow, verifySendInvoice, verifyReceiveInvoiceFacts, verifyQuoteTtl, CSV_GRANULARITY_SECONDS, verifyRefundWindow, verifyQuotedAmount, verifyCrossAssetAmount, verifiedCarrierSats, verifyPinnedAmount;
|
|
3803
|
+
var init_verify = __esm({
|
|
3804
|
+
"src/client/verify.ts"() {
|
|
3805
|
+
"use strict";
|
|
3806
|
+
import_base21 = require("@scure/base");
|
|
3807
|
+
init_rfq();
|
|
3808
|
+
init_errors();
|
|
3809
|
+
init_policy();
|
|
3810
|
+
reasonOf = (error) => error instanceof Error && typeof error.reason === "string" ? error.reason : void 0;
|
|
3811
|
+
CHECK_BY_REASON = {
|
|
3812
|
+
invoice_expired: "invoice",
|
|
3813
|
+
invoice_undecodable: "invoice",
|
|
3814
|
+
invoice_hash_mismatch: "invoice",
|
|
3815
|
+
invoice_amount_mismatch: "invoice",
|
|
3816
|
+
insufficient_headroom: "refund_window",
|
|
3817
|
+
missing_refund_locktime: "refund_window",
|
|
3818
|
+
claim_window_too_short: "refund_window",
|
|
3819
|
+
confirmations_out_of_range: "refund_window",
|
|
3820
|
+
timelock_order: "refund_window",
|
|
3821
|
+
quote_malformed: "refund_window"
|
|
3822
|
+
};
|
|
3823
|
+
gated = (run, quote) => {
|
|
3824
|
+
try {
|
|
3825
|
+
run();
|
|
3826
|
+
} catch (error) {
|
|
3827
|
+
const reason = reasonOf(error);
|
|
3828
|
+
if (reason === "quote_expired") {
|
|
3829
|
+
throw new QuoteExpired(quote.id, quote.expiresAt, quote.now);
|
|
3830
|
+
}
|
|
3831
|
+
const check = reason === void 0 ? void 0 : CHECK_BY_REASON[reason];
|
|
3832
|
+
if (check === void 0) throw error;
|
|
3833
|
+
throw new QuoteVerificationFailed(
|
|
3834
|
+
check,
|
|
3835
|
+
void 0,
|
|
3836
|
+
error instanceof Error ? error.message : String(error),
|
|
3837
|
+
{ cause: error }
|
|
3838
|
+
);
|
|
3839
|
+
}
|
|
3840
|
+
};
|
|
3841
|
+
verifyResponder = (input) => {
|
|
3842
|
+
if (!input.pinnable || input.expected === void 0) {
|
|
3843
|
+
throw new QuoteVerificationFailed(
|
|
3844
|
+
"responder",
|
|
3845
|
+
"a registry-served card naming the solver's discovery key",
|
|
3846
|
+
input.expected === void 0 ? "the card names no discovery key" : "the card came out of the local cache, which does not authenticate it"
|
|
3847
|
+
);
|
|
3848
|
+
}
|
|
3849
|
+
if (input.attested === void 0) {
|
|
3850
|
+
throw new QuoteVerificationFailed(
|
|
3851
|
+
"responder",
|
|
3852
|
+
input.expected,
|
|
3853
|
+
"the transport attests nobody"
|
|
3854
|
+
);
|
|
3855
|
+
}
|
|
3856
|
+
if (input.attested !== input.expected) {
|
|
3857
|
+
throw new QuoteVerificationFailed("responder", input.expected, input.attested);
|
|
3858
|
+
}
|
|
3859
|
+
};
|
|
3860
|
+
verifyTaker = (input) => {
|
|
3861
|
+
const xOnly = (key) => typeof key === "string" && /^[0-9a-f]{64}$/i.test(key) ? import_base21.hex.decode(key.toLowerCase()) : void 0;
|
|
3862
|
+
const taker = xOnly(input.solverPubkey);
|
|
3863
|
+
const attested = xOnly(input.attested);
|
|
3864
|
+
if (taker === void 0 || attested === void 0 || import_base21.hex.encode(taker) !== import_base21.hex.encode(attested)) {
|
|
3865
|
+
throw new QuoteVerificationFailed("responder", input.attested, String(input.solverPubkey));
|
|
3866
|
+
}
|
|
3867
|
+
return taker;
|
|
3868
|
+
};
|
|
3869
|
+
verifyPair = (quoted, requested) => {
|
|
3870
|
+
if (quoted !== requested) {
|
|
3871
|
+
throw new QuoteVerificationFailed("pair", requested, String(quoted));
|
|
3872
|
+
}
|
|
3873
|
+
};
|
|
3874
|
+
verifyingDerivation = (derive) => {
|
|
3875
|
+
try {
|
|
3876
|
+
return derive();
|
|
3877
|
+
} catch (error) {
|
|
3878
|
+
if (error instanceof AddressMismatch) {
|
|
3879
|
+
const derived = Array.isArray(error.derived) ? error.derived.join(", ") : error.derived;
|
|
3880
|
+
throw new QuoteVerificationFailed("lockup_address", derived, error.quoted, {
|
|
3881
|
+
cause: error
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
if (error instanceof Error) {
|
|
3885
|
+
throw new QuoteVerificationFailed("lockup_address", void 0, error.message, {
|
|
3886
|
+
cause: error
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
throw error;
|
|
3890
|
+
}
|
|
3891
|
+
};
|
|
3892
|
+
verifySendWindow = (input) => {
|
|
3893
|
+
gated(
|
|
3894
|
+
() => assertFundable({
|
|
3895
|
+
quote: input.quote,
|
|
3896
|
+
now: input.now,
|
|
3897
|
+
...input.invoiceExpiresAt === void 0 ? {} : { invoiceExpiresAt: input.invoiceExpiresAt },
|
|
3898
|
+
...input.onchain === void 0 ? {} : { onchain: input.onchain }
|
|
3899
|
+
}),
|
|
3900
|
+
{ id: input.quoteId, expiresAt: input.quote.valid_until, now: input.now }
|
|
3901
|
+
);
|
|
3902
|
+
};
|
|
3903
|
+
verifyReceiveWindow = (input) => {
|
|
3904
|
+
gated(
|
|
3905
|
+
() => assertReceivable({
|
|
3906
|
+
quote: input.quote,
|
|
3907
|
+
payDeadline: input.payDeadline,
|
|
3908
|
+
now: input.now
|
|
3909
|
+
}),
|
|
3910
|
+
{ id: input.quoteId, expiresAt: input.payDeadline, now: input.now }
|
|
3911
|
+
);
|
|
3912
|
+
};
|
|
3913
|
+
verifySendInvoice = (input) => {
|
|
3914
|
+
const invoiced = input.invoiced;
|
|
3915
|
+
if (input.take !== invoiced) {
|
|
3916
|
+
throw new QuoteVerificationFailed("invoice", `${invoiced}`, `${input.take}`);
|
|
3917
|
+
}
|
|
3918
|
+
if (input.give < input.take) {
|
|
3919
|
+
throw new QuoteVerificationFailed(
|
|
3920
|
+
"invoice",
|
|
3921
|
+
`at least the invoice's ${invoiced}`,
|
|
3922
|
+
`${input.give}, a negative spread`
|
|
3923
|
+
);
|
|
3924
|
+
}
|
|
3925
|
+
};
|
|
3926
|
+
verifyReceiveInvoiceFacts = (input) => {
|
|
3927
|
+
let decoded;
|
|
3928
|
+
try {
|
|
3929
|
+
decoded = input.decode(input.invoice);
|
|
3930
|
+
} catch (cause) {
|
|
3931
|
+
throw new QuoteVerificationFailed(
|
|
3932
|
+
"invoice",
|
|
3933
|
+
"a decodable BOLT11",
|
|
3934
|
+
cause instanceof Error ? cause.message : String(cause),
|
|
3935
|
+
{ cause }
|
|
3936
|
+
);
|
|
3937
|
+
}
|
|
3938
|
+
if (!Number.isFinite(decoded.expiresAt)) {
|
|
3939
|
+
throw new QuoteVerificationFailed("invoice", "a finite expiry", `${decoded.expiresAt}`);
|
|
3940
|
+
}
|
|
3941
|
+
if (!Number.isFinite(input.validUntil)) {
|
|
3942
|
+
throw new QuoteVerificationFailed(
|
|
3943
|
+
"refund_window",
|
|
3944
|
+
"a finite valid_until",
|
|
3945
|
+
`${input.validUntil}`
|
|
3946
|
+
);
|
|
3947
|
+
}
|
|
3948
|
+
if (decoded.paymentHash !== input.paymentHash) {
|
|
3949
|
+
throw new QuoteVerificationFailed("invoice", input.paymentHash, decoded.paymentHash);
|
|
3950
|
+
}
|
|
3951
|
+
if (!Number.isSafeInteger(decoded.amountSats) || decoded.amountSats <= 0) {
|
|
3952
|
+
throw new QuoteVerificationFailed(
|
|
3953
|
+
"invoice",
|
|
3954
|
+
`${input.payAmount}`,
|
|
3955
|
+
"the invoice names no amount"
|
|
3956
|
+
);
|
|
3957
|
+
}
|
|
3958
|
+
if (BigInt(decoded.amountSats) !== input.payAmount) {
|
|
3959
|
+
throw new QuoteVerificationFailed("invoice", `${input.payAmount}`, `${decoded.amountSats}`);
|
|
3960
|
+
}
|
|
3961
|
+
return { payDeadline: Math.min(decoded.expiresAt, input.validUntil) };
|
|
3962
|
+
};
|
|
3963
|
+
verifyQuoteTtl = (input) => {
|
|
3964
|
+
const floor = input.floorSeconds ?? 0;
|
|
3965
|
+
if (input.expiresAt - input.now <= floor) {
|
|
3966
|
+
throw new QuoteExpired(input.quoteId, input.expiresAt, input.now);
|
|
3967
|
+
}
|
|
3968
|
+
};
|
|
3969
|
+
CSV_GRANULARITY_SECONDS = 512;
|
|
3970
|
+
verifyRefundWindow = (input) => {
|
|
3971
|
+
const max = input.maxSeconds ?? DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
3972
|
+
const window = input.refundLocktime - input.now;
|
|
3973
|
+
if (!(window <= max)) {
|
|
3974
|
+
throw new QuoteVerificationFailed("refund_window", `at most ${max}s`, `${window}s`);
|
|
3975
|
+
}
|
|
3976
|
+
const delay = input.refundWithoutReceiverDelay;
|
|
3977
|
+
if (delay !== void 0 && !(delay < max + CSV_GRANULARITY_SECONDS)) {
|
|
3978
|
+
throw new QuoteVerificationFailed(
|
|
3979
|
+
"refund_window",
|
|
3980
|
+
`a solo-refund delay of at most ${max}s`,
|
|
3981
|
+
`${delay}s`
|
|
3982
|
+
);
|
|
3983
|
+
}
|
|
3984
|
+
};
|
|
3985
|
+
verifyQuotedAmount = (input) => {
|
|
3986
|
+
verifyPinnedAmount(input);
|
|
3987
|
+
if (input.take > input.give) {
|
|
3988
|
+
throw new QuoteVerificationFailed(
|
|
3989
|
+
"pair",
|
|
3990
|
+
`${input.pair} give >= take`,
|
|
3991
|
+
`give=${input.give} take=${input.take}`
|
|
3992
|
+
);
|
|
3993
|
+
}
|
|
3994
|
+
};
|
|
3995
|
+
verifyCrossAssetAmount = (input) => {
|
|
3996
|
+
verifyPinnedAmount(input);
|
|
3997
|
+
if (input.give <= 0n || input.take <= 0n) {
|
|
3998
|
+
throw new QuoteVerificationFailed(
|
|
3999
|
+
"pair",
|
|
4000
|
+
`${input.pair} give > 0 take > 0`,
|
|
4001
|
+
`give=${input.give} take=${input.take}`
|
|
4002
|
+
);
|
|
4003
|
+
}
|
|
4004
|
+
};
|
|
4005
|
+
verifiedCarrierSats = (quote) => {
|
|
4006
|
+
try {
|
|
4007
|
+
return quoteCarrierSats(quote);
|
|
4008
|
+
} catch (error) {
|
|
4009
|
+
if (reasonOf(error) !== "carrier_malformed") throw error;
|
|
4010
|
+
throw new QuoteVerificationFailed(
|
|
4011
|
+
"pair",
|
|
4012
|
+
"carrier_sats a non-negative integer",
|
|
4013
|
+
String(quote.carrier_sats),
|
|
4014
|
+
{ cause: error }
|
|
4015
|
+
);
|
|
4016
|
+
}
|
|
4017
|
+
};
|
|
4018
|
+
verifyPinnedAmount = (input) => {
|
|
4019
|
+
const quoted = input.pinned.on === "give" ? input.give : input.take;
|
|
4020
|
+
if (quoted !== input.pinned.value) {
|
|
4021
|
+
throw new QuoteVerificationFailed(
|
|
4022
|
+
"pair",
|
|
4023
|
+
`${input.pair} ${input.pinned.on}=${input.pinned.value}`,
|
|
4024
|
+
`${input.pair} ${input.pinned.on}=${quoted}`
|
|
4025
|
+
);
|
|
4026
|
+
}
|
|
3228
4027
|
};
|
|
3229
4028
|
}
|
|
3230
4029
|
});
|
|
@@ -3321,7 +4120,7 @@ __export(index_exports, {
|
|
|
3321
4120
|
module.exports = __toCommonJS(index_exports);
|
|
3322
4121
|
|
|
3323
4122
|
// src/client/client.ts
|
|
3324
|
-
var
|
|
4123
|
+
var import_base24 = require("@scure/base");
|
|
3325
4124
|
var import_sdk38 = require("@arkade-os/sdk");
|
|
3326
4125
|
init_repository();
|
|
3327
4126
|
|
|
@@ -3574,184 +4373,8 @@ var CORRIDOR_BY_RAIL = {
|
|
|
3574
4373
|
var railOfCorridor = (corridor) => corridor in RAIL_BY_CORRIDOR ? RAIL_BY_CORRIDOR[corridor] : "eip155";
|
|
3575
4374
|
var corridorOfRail = (rail) => rail === "eip155" ? void 0 : CORRIDOR_BY_RAIL[rail];
|
|
3576
4375
|
|
|
3577
|
-
// src/client/
|
|
3578
|
-
|
|
3579
|
-
var AmbiguousDestination = class extends Error {
|
|
3580
|
-
constructor(destination, detail) {
|
|
3581
|
-
super(`cannot route ${JSON.stringify(destination)}: ${detail}`);
|
|
3582
|
-
this.destination = destination;
|
|
3583
|
-
}
|
|
3584
|
-
destination;
|
|
3585
|
-
name = "AmbiguousDestination";
|
|
3586
|
-
};
|
|
3587
|
-
var UnsupportedRoute = class extends Error {
|
|
3588
|
-
name = "UnsupportedRoute";
|
|
3589
|
-
give;
|
|
3590
|
-
take;
|
|
3591
|
-
constructor(detail, corridors = {}) {
|
|
3592
|
-
super(`unsupported route: ${detail}`);
|
|
3593
|
-
this.give = corridors.give;
|
|
3594
|
-
this.take = corridors.take;
|
|
3595
|
-
}
|
|
3596
|
-
};
|
|
3597
|
-
var DiscoverySnapshotUnavailable = class extends Error {
|
|
3598
|
-
constructor(network, detail) {
|
|
3599
|
-
super(`cannot resolve on ${network} offline: ${detail}`);
|
|
3600
|
-
this.network = network;
|
|
3601
|
-
}
|
|
3602
|
-
network;
|
|
3603
|
-
name = "DiscoverySnapshotUnavailable";
|
|
3604
|
-
};
|
|
3605
|
-
var AmountMismatch = class extends Error {
|
|
3606
|
-
constructor(sources) {
|
|
3607
|
-
super(`exactly one amount may be pinned; got ${sources[0]} and ${sources[1]}`);
|
|
3608
|
-
this.sources = sources;
|
|
3609
|
-
}
|
|
3610
|
-
sources;
|
|
3611
|
-
name = "AmountMismatch";
|
|
3612
|
-
};
|
|
3613
|
-
var AmountEncodingUnsupported = class extends Error {
|
|
3614
|
-
constructor(field, value, detail, options) {
|
|
3615
|
-
super(`${field}: ${detail}`, options);
|
|
3616
|
-
this.field = field;
|
|
3617
|
-
this.value = value;
|
|
3618
|
-
}
|
|
3619
|
-
field;
|
|
3620
|
-
value;
|
|
3621
|
-
name = "AmountEncodingUnsupported";
|
|
3622
|
-
};
|
|
3623
|
-
var QuoteVerificationFailed = class extends Error {
|
|
3624
|
-
constructor(check, expected, actual, options) {
|
|
3625
|
-
super(`quote failed the ${check} check \u2014 refusing to fund`, options);
|
|
3626
|
-
this.check = check;
|
|
3627
|
-
this.expected = expected;
|
|
3628
|
-
this.actual = actual;
|
|
3629
|
-
}
|
|
3630
|
-
check;
|
|
3631
|
-
name = "QuoteVerificationFailed";
|
|
3632
|
-
expected;
|
|
3633
|
-
actual;
|
|
3634
|
-
};
|
|
3635
|
-
var QuoteExpired = class extends Error {
|
|
3636
|
-
constructor(quoteId, expiresAt, now) {
|
|
3637
|
-
super(`quote ${quoteId} expired at ${expiresAt}, ${now - expiresAt} ago`);
|
|
3638
|
-
this.quoteId = quoteId;
|
|
3639
|
-
this.expiresAt = expiresAt;
|
|
3640
|
-
this.now = now;
|
|
3641
|
-
}
|
|
3642
|
-
quoteId;
|
|
3643
|
-
expiresAt;
|
|
3644
|
-
now;
|
|
3645
|
-
name = "QuoteExpired";
|
|
3646
|
-
};
|
|
3647
|
-
var MaxFeeExceeded = class extends Error {
|
|
3648
|
-
constructor(quoteId, asset8, fee, maxFee) {
|
|
3649
|
-
super(`fee ${fee} of ${asset8} exceeds the ${maxFee} ceiling`);
|
|
3650
|
-
this.quoteId = quoteId;
|
|
3651
|
-
this.asset = asset8;
|
|
3652
|
-
this.fee = fee;
|
|
3653
|
-
this.maxFee = maxFee;
|
|
3654
|
-
}
|
|
3655
|
-
quoteId;
|
|
3656
|
-
asset;
|
|
3657
|
-
fee;
|
|
3658
|
-
maxFee;
|
|
3659
|
-
name = "MaxFeeExceeded";
|
|
3660
|
-
};
|
|
3661
|
-
var InsufficientFunds = class extends Error {
|
|
3662
|
-
constructor(asset8, required, available) {
|
|
3663
|
-
super(
|
|
3664
|
-
`funding needs ${required} of ${asset8}` + (available === void 0 ? "" : `, wallet holds ${available}`)
|
|
3665
|
-
);
|
|
3666
|
-
this.asset = asset8;
|
|
3667
|
-
this.required = required;
|
|
3668
|
-
this.available = available;
|
|
3669
|
-
}
|
|
3670
|
-
asset;
|
|
3671
|
-
required;
|
|
3672
|
-
name = "InsufficientFunds";
|
|
3673
|
-
available;
|
|
3674
|
-
};
|
|
3675
|
-
var AcceptConflict = class extends Error {
|
|
3676
|
-
constructor(quoteId, swapId, fields) {
|
|
3677
|
-
super(`accept ${quoteId} conflicts with swap ${swapId} on ${fields.join(", ")}`);
|
|
3678
|
-
this.quoteId = quoteId;
|
|
3679
|
-
this.swapId = swapId;
|
|
3680
|
-
this.fields = fields;
|
|
3681
|
-
}
|
|
3682
|
-
quoteId;
|
|
3683
|
-
swapId;
|
|
3684
|
-
fields;
|
|
3685
|
-
name = "AcceptConflict";
|
|
3686
|
-
};
|
|
3687
|
-
var ClientDisposed = class extends Error {
|
|
3688
|
-
constructor(method) {
|
|
3689
|
-
super(`${method}() called after the client was disposed`);
|
|
3690
|
-
this.method = method;
|
|
3691
|
-
}
|
|
3692
|
-
method;
|
|
3693
|
-
name = "ClientDisposed";
|
|
3694
|
-
};
|
|
3695
|
-
var NotCancellable = class extends Error {
|
|
3696
|
-
constructor(swapId) {
|
|
3697
|
-
super(`swap ${swapId} is not a cancellable asset swap`);
|
|
3698
|
-
this.swapId = swapId;
|
|
3699
|
-
}
|
|
3700
|
-
swapId;
|
|
3701
|
-
name = "NotCancellable";
|
|
3702
|
-
};
|
|
3703
|
-
var InconsistentRoute = class extends Error {
|
|
3704
|
-
constructor(asset8, destination) {
|
|
3705
|
-
super(`destination ${JSON.stringify(destination)} is not on ${asset8}'s chain`);
|
|
3706
|
-
this.asset = asset8;
|
|
3707
|
-
this.destination = destination;
|
|
3708
|
-
}
|
|
3709
|
-
asset;
|
|
3710
|
-
destination;
|
|
3711
|
-
name = "InconsistentRoute";
|
|
3712
|
-
};
|
|
3713
|
-
var OperatorUnreachable = class extends Error {
|
|
3714
|
-
name = "OperatorUnreachable";
|
|
3715
|
-
constructor(detail, options) {
|
|
3716
|
-
super(`cannot derive a covenant: ${detail}`, options);
|
|
3717
|
-
}
|
|
3718
|
-
};
|
|
3719
|
-
var MissingCorridorDep = class extends Error {
|
|
3720
|
-
constructor(corridor, dep) {
|
|
3721
|
-
super(`the ${corridor} corridor has no ${dep}`);
|
|
3722
|
-
this.corridor = corridor;
|
|
3723
|
-
this.dep = dep;
|
|
3724
|
-
}
|
|
3725
|
-
corridor;
|
|
3726
|
-
dep;
|
|
3727
|
-
name = "MissingCorridorDep";
|
|
3728
|
-
};
|
|
3729
|
-
var SWAP_ERRORS = {
|
|
3730
|
-
AmbiguousDestination,
|
|
3731
|
-
UnsupportedRoute,
|
|
3732
|
-
DiscoverySnapshotUnavailable,
|
|
3733
|
-
AmountMismatch,
|
|
3734
|
-
AmountEncodingUnsupported,
|
|
3735
|
-
QuoteVerificationFailed,
|
|
3736
|
-
SwapRefusal,
|
|
3737
|
-
QuoteExpired,
|
|
3738
|
-
MaxFeeExceeded,
|
|
3739
|
-
InsufficientFunds,
|
|
3740
|
-
AcceptConflict,
|
|
3741
|
-
ClientDisposed,
|
|
3742
|
-
NotCancellable,
|
|
3743
|
-
InconsistentRoute,
|
|
3744
|
-
OperatorUnreachable,
|
|
3745
|
-
MissingCorridorDep
|
|
3746
|
-
};
|
|
3747
|
-
var SWAP_ERROR_NAMES = Object.keys(SWAP_ERRORS);
|
|
3748
|
-
function isSwapError(e, name) {
|
|
3749
|
-
if (!(e instanceof Error)) return false;
|
|
3750
|
-
const table = SWAP_ERRORS;
|
|
3751
|
-
const ctor = table[e.name];
|
|
3752
|
-
if (ctor === void 0 || !(e instanceof ctor)) return false;
|
|
3753
|
-
return name === void 0 || e.name === name;
|
|
3754
|
-
}
|
|
4376
|
+
// src/client/corridors/registry.ts
|
|
4377
|
+
init_errors();
|
|
3755
4378
|
|
|
3756
4379
|
// src/client/corridors/arkade.ts
|
|
3757
4380
|
var import_sdk10 = require("@arkade-os/sdk");
|
|
@@ -3835,6 +4458,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
3835
4458
|
// src/client/corridors/deps.ts
|
|
3836
4459
|
init_onchainHtlc();
|
|
3837
4460
|
init_rfq();
|
|
4461
|
+
init_errors();
|
|
3838
4462
|
|
|
3839
4463
|
// src/client/corridors/bolt11.ts
|
|
3840
4464
|
var import_light_bolt11_decoder = __toESM(require("light-bolt11-decoder"), 1);
|
|
@@ -4542,6 +5166,7 @@ var issuanceOf = (id) => {
|
|
|
4542
5166
|
};
|
|
4543
5167
|
|
|
4544
5168
|
// src/client/aliases.ts
|
|
5169
|
+
init_errors();
|
|
4545
5170
|
var toDiscoveryLeg = (id) => {
|
|
4546
5171
|
const { rail, reference, assetNamespace, assetReference } = parseAssetId(id);
|
|
4547
5172
|
const asset8 = `${assetNamespace}:${assetReference}`;
|
|
@@ -4594,6 +5219,7 @@ var canonicalAssetId = (input, table) => {
|
|
|
4594
5219
|
};
|
|
4595
5220
|
|
|
4596
5221
|
// src/client/discovery.ts
|
|
5222
|
+
init_errors();
|
|
4597
5223
|
var REGISTRY_URL = {
|
|
4598
5224
|
bitcoin: "https://arkade-os.github.io/solver-registry/bitcoin.json",
|
|
4599
5225
|
signet: "https://arkade-os.github.io/solver-registry/signet.json",
|
|
@@ -4750,6 +5376,9 @@ var discoveryIndex = (input) => {
|
|
|
4750
5376
|
return { peek, load };
|
|
4751
5377
|
};
|
|
4752
5378
|
|
|
5379
|
+
// src/client/client.ts
|
|
5380
|
+
init_errors();
|
|
5381
|
+
|
|
4753
5382
|
// src/client/accept.ts
|
|
4754
5383
|
var import_base12 = require("@scure/base");
|
|
4755
5384
|
var import_solver_discovery9 = require("@arkade-os/solver-discovery");
|
|
@@ -5537,8 +6166,12 @@ var recordOutcome = (record) => {
|
|
|
5537
6166
|
return record.status === void 0 ? "funding" : offerOutcome(record.status);
|
|
5538
6167
|
};
|
|
5539
6168
|
|
|
6169
|
+
// src/client/accept.ts
|
|
6170
|
+
init_errors();
|
|
6171
|
+
|
|
5540
6172
|
// src/client/rfqAmount.ts
|
|
5541
6173
|
var import_solver_discovery8 = require("@arkade-os/solver-discovery");
|
|
6174
|
+
init_errors();
|
|
5542
6175
|
var toRfqAmountSide = (on) => on === "give" ? "from" : "to";
|
|
5543
6176
|
var encodeRfqAmount = (value, field) => {
|
|
5544
6177
|
try {
|
|
@@ -5788,7 +6421,8 @@ var acceptQuoteBody = async (input) => {
|
|
|
5788
6421
|
}
|
|
5789
6422
|
const funds = fundsFromWallet(quote.route);
|
|
5790
6423
|
if (funds) await assertFundable2(wallet, quote);
|
|
5791
|
-
const
|
|
6424
|
+
const built = preparation.backend === "feed" ? await registeredOfferRecord(input, preparation) : preparation.route === "arkade->arkade" ? await registeredAssetRecord(input, preparation) : await registeredCorridorRecord(input, preparation);
|
|
6425
|
+
const record = built.family === "offer" && input.attachOfferPacket === false ? { ...built, attachOfferPacket: false } : built;
|
|
5792
6426
|
await repository.saveSwapRecord(record);
|
|
5793
6427
|
if (!funds) return answer(record);
|
|
5794
6428
|
return answer(
|
|
@@ -5808,7 +6442,7 @@ var acceptQuoteBody = async (input) => {
|
|
|
5808
6442
|
var registeredOfferRecord = async (input, preparation) => {
|
|
5809
6443
|
const { quote, wallet, corridors, now } = input;
|
|
5810
6444
|
const { plan } = preparation;
|
|
5811
|
-
const
|
|
6445
|
+
const arkade5 = corridors.get("arkade").deps;
|
|
5812
6446
|
const receiveIsBtc = plan.receive.asset.id === BTC_ASSET_ID;
|
|
5813
6447
|
const offer = await createOffer(
|
|
5814
6448
|
wallet,
|
|
@@ -5816,7 +6450,7 @@ var registeredOfferRecord = async (input, preparation) => {
|
|
|
5816
6450
|
// Keyed on the receive side: the covenant binds what the fill delivers.
|
|
5817
6451
|
wantAmount: plan.receive.atomic,
|
|
5818
6452
|
...receiveIsBtc ? { offerAsset: import_sdk21.asset.AssetId.fromString(plan.deposit.asset.id) } : { wantAsset: import_sdk21.asset.AssetId.fromString(plan.receive.asset.id) },
|
|
5819
|
-
emulatorPubkey:
|
|
6453
|
+
emulatorPubkey: arkade5.emulatorPubkey
|
|
5820
6454
|
},
|
|
5821
6455
|
{ coverageId: quote.id }
|
|
5822
6456
|
);
|
|
@@ -5844,7 +6478,9 @@ var registeredAssetRecord = async (input, preparation) => {
|
|
|
5844
6478
|
...preparation.assetPayment === void 0 ? {} : { assetPayment: recordAssetPayment(preparation.assetPayment) },
|
|
5845
6479
|
family: "offer",
|
|
5846
6480
|
status: "pending",
|
|
5847
|
-
|
|
6481
|
+
// a directed covenant is kept as its binding alone, which an older reader drops whole
|
|
6482
|
+
// rather than half-reads
|
|
6483
|
+
...preparation.offer.offerBinding.taker === void 0 ? { offerHex: preparation.offer.offerHex } : { binding: recordOfferBinding(preparation.offer.offerBinding) },
|
|
5848
6484
|
swapAddress: preparation.offer.address,
|
|
5849
6485
|
swapPkScript: import_base12.hex.encode(preparation.offer.swapPkScript),
|
|
5850
6486
|
...preparation.carrierSats === void 0 ? {} : { carrierSats: preparation.carrierSats.toString() }
|
|
@@ -5929,7 +6565,7 @@ var fund = async (input, record) => {
|
|
|
5929
6565
|
{ assetId: toDiscoveryLeg(record.route.give.asset).assetId, amount }
|
|
5930
6566
|
]
|
|
5931
6567
|
},
|
|
5932
|
-
extensions: [offerExtensionOf(record)]
|
|
6568
|
+
...record.attachOfferPacket === false ? {} : { extensions: [offerExtensionOf(record)] }
|
|
5933
6569
|
});
|
|
5934
6570
|
}
|
|
5935
6571
|
if (record.kind === "lightning_receive" || record.kind === "onchain_receive") {
|
|
@@ -5940,10 +6576,13 @@ var fund = async (input, record) => {
|
|
|
5940
6576
|
amount: toSafeNumber(fromAtomicDecimal(record.give.amount), "give.amount")
|
|
5941
6577
|
});
|
|
5942
6578
|
};
|
|
5943
|
-
var offerExtensionOf = (record) =>
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
6579
|
+
var offerExtensionOf = (record) => {
|
|
6580
|
+
const stored = storedOffer(record);
|
|
6581
|
+
return {
|
|
6582
|
+
type: OFFER_PACKET_TYPE,
|
|
6583
|
+
payload: record.offerHex !== void 0 ? import_base12.hex.decode(record.offerHex) : encodeOffer("version" in stored ? offerFromBinding(stored) : stored)
|
|
6584
|
+
};
|
|
6585
|
+
};
|
|
5947
6586
|
var reconcileFunding = async (input, record) => {
|
|
5948
6587
|
const script = record.family === "offer" ? record.swapPkScript : record.lockupPkScript;
|
|
5949
6588
|
const expected = BigInt(record.give.amount);
|
|
@@ -6009,8 +6648,16 @@ var unscannedSwapCandidates = (txs, existingIds, scanned) => txs.filter(
|
|
|
6009
6648
|
function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
6010
6649
|
let leaves;
|
|
6011
6650
|
try {
|
|
6012
|
-
|
|
6013
|
-
if (
|
|
6651
|
+
let script;
|
|
6652
|
+
if ("version" in offer) {
|
|
6653
|
+
const { program, args, keys } = bindingProgram(offer);
|
|
6654
|
+
script = new import_sdk22.arkade.ArkadeProgramScript(program, args, keys);
|
|
6655
|
+
} else {
|
|
6656
|
+
script = offerContract(offer, operatorPubkey);
|
|
6657
|
+
if (import_base13.hex.encode(script.pkScript) !== import_base13.hex.encode(offer.swapPkScript)) {
|
|
6658
|
+
return "indeterminate";
|
|
6659
|
+
}
|
|
6660
|
+
}
|
|
6014
6661
|
leaves = {
|
|
6015
6662
|
// `exit` is absent on an offer with no exit closure, and drops out here
|
|
6016
6663
|
returned: ["cancel", "exit"].map((name) => script.functionByName(name)?.leafScript).filter((leaf) => leaf !== void 0),
|
|
@@ -6039,21 +6686,56 @@ function classifyDepositSpend(offer, operatorPubkey, spendTxs, deposit) {
|
|
|
6039
6686
|
}
|
|
6040
6687
|
return "indeterminate";
|
|
6041
6688
|
}
|
|
6689
|
+
var encodesOffer = (offerHex, offer) => {
|
|
6690
|
+
try {
|
|
6691
|
+
const { ratioNum: _num, ratioDen: _den, ...terms } = decodeOffer(import_base13.hex.decode(offerHex));
|
|
6692
|
+
return import_base13.hex.encode(encodeOffer(terms)) === import_base13.hex.encode(encodeOffer(offer));
|
|
6693
|
+
} catch {
|
|
6694
|
+
return false;
|
|
6695
|
+
}
|
|
6696
|
+
};
|
|
6697
|
+
var packetRecoverySource = (indexer) => ({
|
|
6698
|
+
name: "packet",
|
|
6699
|
+
async discover({ candidateTxids, operatorPubkey }) {
|
|
6700
|
+
const found = [];
|
|
6701
|
+
const declined = [];
|
|
6702
|
+
for (const [txid, parsed] of await fetchParsedTxs(indexer, [...candidateTxids])) {
|
|
6703
|
+
let packet;
|
|
6704
|
+
try {
|
|
6705
|
+
packet = import_sdk22.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
6706
|
+
} catch {
|
|
6707
|
+
}
|
|
6708
|
+
if (!packet) {
|
|
6709
|
+
declined.push(txid);
|
|
6710
|
+
continue;
|
|
6711
|
+
}
|
|
6712
|
+
const payload = packet.serialize();
|
|
6713
|
+
try {
|
|
6714
|
+
const binding = bindingFromOffer(decodeOffer(payload), operatorPubkey);
|
|
6715
|
+
found.push({ fundingTxid: txid, binding, offerHex: import_base13.hex.encode(payload) });
|
|
6716
|
+
} catch {
|
|
6717
|
+
}
|
|
6718
|
+
}
|
|
6719
|
+
return { found, declined };
|
|
6720
|
+
}
|
|
6721
|
+
});
|
|
6042
6722
|
async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
6043
6723
|
const {
|
|
6044
6724
|
operatorPubkey,
|
|
6045
6725
|
scanned = /* @__PURE__ */ new Set(),
|
|
6046
6726
|
reopen = [],
|
|
6047
6727
|
hrp,
|
|
6048
|
-
recoveredIn = /* @__PURE__ */ new Set()
|
|
6728
|
+
recoveredIn = /* @__PURE__ */ new Set(),
|
|
6729
|
+
sources = [packetRecoverySource(indexer)]
|
|
6049
6730
|
} = opts;
|
|
6050
6731
|
const reopened = [];
|
|
6051
6732
|
for (const swap of reopen) {
|
|
6052
6733
|
try {
|
|
6734
|
+
const source = storedOffer(swap);
|
|
6053
6735
|
reopened.push({
|
|
6054
6736
|
fundingTx: { type: "sent", redeemTxid: swap.fundingTxid },
|
|
6055
|
-
offer:
|
|
6056
|
-
|
|
6737
|
+
offer: "version" in source ? offerFromBinding(source) : source,
|
|
6738
|
+
source,
|
|
6057
6739
|
existing: swap
|
|
6058
6740
|
});
|
|
6059
6741
|
} catch {
|
|
@@ -6067,29 +6749,40 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6067
6749
|
return { restored: [], scannedTxids: [] };
|
|
6068
6750
|
}
|
|
6069
6751
|
const byTxid = new Map(candidates.map((tx) => [tx.redeemTxid, tx]));
|
|
6070
|
-
const
|
|
6071
|
-
indexer,
|
|
6072
|
-
candidates.map((tx) => tx.redeemTxid)
|
|
6073
|
-
);
|
|
6074
|
-
const fetchedTxids = [];
|
|
6752
|
+
const candidateTxids = candidates.map((tx) => tx.redeemTxid);
|
|
6075
6753
|
const found = [...reopened];
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6754
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
6755
|
+
const declined = /* @__PURE__ */ new Set();
|
|
6756
|
+
for (const recovery of candidateTxids.length === 0 ? [] : sources) {
|
|
6757
|
+
let answer;
|
|
6080
6758
|
try {
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6759
|
+
answer = await recovery.discover({ candidateTxids, operatorPubkey });
|
|
6760
|
+
} catch (error) {
|
|
6761
|
+
console.warn(`[swap] recovery source ${recovery.name} failed`, error);
|
|
6762
|
+
continue;
|
|
6763
|
+
}
|
|
6764
|
+
for (const txid of answer.declined) declined.add(txid);
|
|
6765
|
+
for (const { fundingTxid, binding, offerHex } of answer.found) {
|
|
6766
|
+
const fundingTx = byTxid.get(fundingTxid);
|
|
6767
|
+
if (!fundingTx || claimed.has(fundingTxid)) continue;
|
|
6768
|
+
let offer;
|
|
6769
|
+
try {
|
|
6770
|
+
offer = offerFromBinding(binding);
|
|
6771
|
+
} catch (error) {
|
|
6772
|
+
console.warn(`[swap] ${recovery.name} sent a binding that does not compile`, error);
|
|
6773
|
+
continue;
|
|
6774
|
+
}
|
|
6775
|
+
if (offerHex !== void 0 && !encodesOffer(offerHex, offer)) {
|
|
6776
|
+
console.warn(`[swap] ${recovery.name} sent a packet its binding does not match`);
|
|
6777
|
+
continue;
|
|
6778
|
+
}
|
|
6779
|
+
claimed.add(fundingTxid);
|
|
6780
|
+
const packet = offerHex ?? import_base13.hex.encode(encodeOffer(offer));
|
|
6781
|
+
found.push({ fundingTx, offer, source: binding, offerHex: packet });
|
|
6090
6782
|
}
|
|
6091
6783
|
}
|
|
6092
|
-
|
|
6784
|
+
const answered = [...claimed, ...[...declined].filter((txid) => !claimed.has(txid))];
|
|
6785
|
+
if (found.length === 0) return { restored: [], scannedTxids: answered };
|
|
6093
6786
|
const scripts = [...new Set(found.map((f) => import_base13.hex.encode(f.offer.swapPkScript)))];
|
|
6094
6787
|
const { vtxos } = await indexer.getVtxos({ scripts });
|
|
6095
6788
|
const vtxoByScriptAndTxid = new Map(vtxos.map((v) => [`${v.script}:${v.txid}`, v]));
|
|
@@ -6110,7 +6803,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6110
6803
|
const spendTxByTxid = await fetchParsedTxs(indexer, [...spendTxids]);
|
|
6111
6804
|
const restored = [];
|
|
6112
6805
|
const unresolved = /* @__PURE__ */ new Set();
|
|
6113
|
-
for (const { fundingTx, offer, offerHex, existing } of found) {
|
|
6806
|
+
for (const { fundingTx, offer, source, offerHex, existing } of found) {
|
|
6114
6807
|
const swapPkScript = import_base13.hex.encode(offer.swapPkScript);
|
|
6115
6808
|
const vtxo = vtxoByScriptAndTxid.get(`${swapPkScript}:${fundingTx.redeemTxid}`);
|
|
6116
6809
|
if (!vtxo) {
|
|
@@ -6139,7 +6832,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6139
6832
|
} else if (vtxo.isSwept && !vtxo.isSpent) status = "recoverable";
|
|
6140
6833
|
else if (vtxo.isSpent) {
|
|
6141
6834
|
const spendTxs = spendTxidsOf(vtxo).map((id) => spendTxByTxid.get(id)).filter((tx) => tx !== void 0);
|
|
6142
|
-
const kind = classifyDepositSpend(
|
|
6835
|
+
const kind = classifyDepositSpend(source, operatorPubkey, spendTxs, {
|
|
6143
6836
|
txid: vtxo.txid,
|
|
6144
6837
|
vout: vtxo.vout
|
|
6145
6838
|
});
|
|
@@ -6155,20 +6848,19 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6155
6848
|
restored.push({ ...existing, status, spentTxid, ...completion });
|
|
6156
6849
|
continue;
|
|
6157
6850
|
}
|
|
6851
|
+
if (!("version" in source)) continue;
|
|
6158
6852
|
let swapAddress = "";
|
|
6159
6853
|
try {
|
|
6160
|
-
const compiled = offerContract(offer, operatorPubkey);
|
|
6161
|
-
if (import_base13.hex.encode(compiled.pkScript) !== swapPkScript) {
|
|
6162
|
-
unresolved.add(fundingTx.redeemTxid);
|
|
6163
|
-
continue;
|
|
6164
|
-
}
|
|
6165
6854
|
if (hrp !== void 0) {
|
|
6166
|
-
|
|
6855
|
+
const { program, args, keys } = bindingProgram(source);
|
|
6856
|
+
const compiled = new import_sdk22.arkade.ArkadeProgramScript(program, args, keys);
|
|
6857
|
+
swapAddress = compiled.address(hrp, source.serverPublicKey).encode();
|
|
6167
6858
|
}
|
|
6168
6859
|
} catch {
|
|
6169
6860
|
unresolved.add(fundingTx.redeemTxid);
|
|
6170
6861
|
continue;
|
|
6171
6862
|
}
|
|
6863
|
+
const covenant = source.taker === void 0 ? { offerHex: offerHex ?? import_base13.hex.encode(encodeOffer(offer)) } : { binding: recordOfferBinding(source) };
|
|
6172
6864
|
restored.push({
|
|
6173
6865
|
id: fundingTx.redeemTxid,
|
|
6174
6866
|
fromAsset,
|
|
@@ -6177,7 +6869,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6177
6869
|
toAmount: offer.wantAmount.toString(),
|
|
6178
6870
|
swapAddress,
|
|
6179
6871
|
swapPkScript,
|
|
6180
|
-
|
|
6872
|
+
...covenant,
|
|
6181
6873
|
fundingTxid: fundingTx.redeemTxid,
|
|
6182
6874
|
spentTxid,
|
|
6183
6875
|
status,
|
|
@@ -6185,7 +6877,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
6185
6877
|
...completion
|
|
6186
6878
|
});
|
|
6187
6879
|
}
|
|
6188
|
-
return { restored, scannedTxids:
|
|
6880
|
+
return { restored, scannedTxids: answered.filter((id) => !unresolved.has(id)) };
|
|
6189
6881
|
}
|
|
6190
6882
|
|
|
6191
6883
|
// src/client/cancel.ts
|
|
@@ -6444,11 +7136,15 @@ var corridorRecordStore = (repository, onRecord = () => {
|
|
|
6444
7136
|
}
|
|
6445
7137
|
};
|
|
6446
7138
|
};
|
|
7139
|
+
var covenantOf = (swap) => ({
|
|
7140
|
+
...swap.offerHex === void 0 ? {} : { offerHex: swap.offerHex },
|
|
7141
|
+
...swap.binding === void 0 ? {} : { binding: swap.binding }
|
|
7142
|
+
});
|
|
6447
7143
|
var offerFactsOf = (record) => ({
|
|
6448
7144
|
id: record.id,
|
|
6449
7145
|
coverageId: record.id,
|
|
6450
7146
|
status: record.status,
|
|
6451
|
-
|
|
7147
|
+
...covenantOf(record),
|
|
6452
7148
|
swapPkScript: record.swapPkScript,
|
|
6453
7149
|
...record.fundingTxid === void 0 ? {} : { fundingTxid: record.fundingTxid },
|
|
6454
7150
|
...record.spentTxid === void 0 ? {} : { spentTxid: record.spentTxid },
|
|
@@ -6520,7 +7216,7 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
6520
7216
|
market: { kind: "restored", backend: "feed" },
|
|
6521
7217
|
expiresAt: createdAt,
|
|
6522
7218
|
status: swap.status,
|
|
6523
|
-
|
|
7219
|
+
...covenantOf(swap),
|
|
6524
7220
|
swapAddress: swap.swapAddress,
|
|
6525
7221
|
swapPkScript: swap.swapPkScript,
|
|
6526
7222
|
fundingTxid: swap.fundingTxid,
|
|
@@ -6531,6 +7227,20 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
6531
7227
|
now
|
|
6532
7228
|
);
|
|
6533
7229
|
};
|
|
7230
|
+
var reopenedDeposit = (record, fundingTxid) => ({
|
|
7231
|
+
id: fundingTxid,
|
|
7232
|
+
fromAsset: record.give.asset,
|
|
7233
|
+
toAsset: record.take.asset,
|
|
7234
|
+
fromAmount: record.give.amount,
|
|
7235
|
+
toAmount: record.take.amount,
|
|
7236
|
+
swapAddress: record.swapAddress,
|
|
7237
|
+
swapPkScript: record.swapPkScript,
|
|
7238
|
+
...covenantOf(record),
|
|
7239
|
+
fundingTxid,
|
|
7240
|
+
...record.spentTxid === void 0 ? {} : { spentTxid: record.spentTxid },
|
|
7241
|
+
status: record.status,
|
|
7242
|
+
createdAt: record.createdAt * 1e3
|
|
7243
|
+
});
|
|
6534
7244
|
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network, import_sdk24.asset.AssetId.fromString(id));
|
|
6535
7245
|
var RESTORED_CORRIDORS = {
|
|
6536
7246
|
lightning_send: ["arkade", "lightning"],
|
|
@@ -6595,12 +7305,13 @@ var cancelSwap = async (input) => {
|
|
|
6595
7305
|
if (outcome === "cancelled" || outcome === "filled" || outcome === "needs_recovery") {
|
|
6596
7306
|
return { outcome };
|
|
6597
7307
|
}
|
|
7308
|
+
const offer = storedOffer(record);
|
|
6598
7309
|
const gated2 = withStatus(record, "cancelling", now());
|
|
6599
7310
|
await repository.saveSwapRecord(gated2);
|
|
6600
7311
|
drive.ingest(gated2);
|
|
6601
7312
|
let prepared;
|
|
6602
7313
|
try {
|
|
6603
|
-
prepared = await prepareOfferCancel(wallet,
|
|
7314
|
+
prepared = await prepareOfferCancel(wallet, offer, {
|
|
6604
7315
|
swapAddress: record.swapAddress,
|
|
6605
7316
|
...record.fundingTxid === void 0 ? {} : { fundingTxid: record.fundingTxid }
|
|
6606
7317
|
});
|
|
@@ -6647,7 +7358,7 @@ var cancelSwap = async (input) => {
|
|
|
6647
7358
|
return { outcome: "cancelled" };
|
|
6648
7359
|
};
|
|
6649
7360
|
var reconcileDepositSpend = async (record, indexer) => {
|
|
6650
|
-
const offer =
|
|
7361
|
+
const offer = storedOffer(record);
|
|
6651
7362
|
const { vtxos } = await indexer.getVtxos({ scripts: [record.swapPkScript] });
|
|
6652
7363
|
const all = vtxos ?? [];
|
|
6653
7364
|
const deposit = record.fundingTxid === void 0 ? all.length === 1 ? all[0] : void 0 : all.find((vtxo) => vtxo.txid === record.fundingTxid);
|
|
@@ -8400,7 +9111,7 @@ async function watchOfferSwaps({
|
|
|
8400
9111
|
if (candidates.length === 0) return "indeterminate";
|
|
8401
9112
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
8402
9113
|
return classifyDepositSpend(
|
|
8403
|
-
|
|
9114
|
+
storedOffer(swap),
|
|
8404
9115
|
operatorPubkey,
|
|
8405
9116
|
txs.map((psbt) => import_sdk30.Transaction.fromPSBT(import_base19.base64.decode(psbt))),
|
|
8406
9117
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
@@ -8439,6 +9150,9 @@ async function watchOfferSwaps({
|
|
|
8439
9150
|
};
|
|
8440
9151
|
}
|
|
8441
9152
|
|
|
9153
|
+
// src/client/drive.ts
|
|
9154
|
+
init_errors();
|
|
9155
|
+
|
|
8442
9156
|
// src/client/legacyRecords.ts
|
|
8443
9157
|
var import_sdk31 = require("@arkade-os/sdk");
|
|
8444
9158
|
init_repository();
|
|
@@ -8510,7 +9224,7 @@ var readLegacyAssetSwaps = async (repository) => {
|
|
|
8510
9224
|
};
|
|
8511
9225
|
var legacyOfferDepositsToAdopt = async (repository) => {
|
|
8512
9226
|
const unadopted = (await readLegacyAssetSwaps(repository)).filter(
|
|
8513
|
-
(swap) => !!swap.offerHex && !!swap.fundingTxid
|
|
9227
|
+
(swap) => (!!swap.offerHex || !!swap.binding) && !!swap.fundingTxid
|
|
8514
9228
|
);
|
|
8515
9229
|
if (unadopted.length === 0) return /* @__PURE__ */ new Set();
|
|
8516
9230
|
const { offer } = splitRecords(await collectSwapRecords(repository));
|
|
@@ -8530,6 +9244,7 @@ var SwapDriveRefusedError = class extends Error {
|
|
|
8530
9244
|
name = "SwapDriveRefusedError";
|
|
8531
9245
|
};
|
|
8532
9246
|
var OFFER_LIVE = (status) => status === "pending" || status === "cancelling";
|
|
9247
|
+
var DIRECTED_CANCEL_GRACE_SECONDS = 60;
|
|
8533
9248
|
var traderClaimTxid2 = (swap) => swap.kind === "lightning_send" ? void 0 : swap.claimTxid;
|
|
8534
9249
|
var readableRecord = (record) => {
|
|
8535
9250
|
if (typeof record?.id !== "string" || record.route?.give === void 0) return false;
|
|
@@ -8543,7 +9258,7 @@ var readableRecord = (record) => {
|
|
|
8543
9258
|
if (record.family === "rfq") {
|
|
8544
9259
|
return typeof record.rfqId === "string" && typeof record.lockupAddress === "string";
|
|
8545
9260
|
}
|
|
8546
|
-
return record.family === "offer" && typeof record.offerHex === "string";
|
|
9261
|
+
return record.family === "offer" && (typeof record.offerHex === "string" || record.binding !== void 0);
|
|
8547
9262
|
};
|
|
8548
9263
|
var createSwapDrive = (config) => {
|
|
8549
9264
|
const { wallet, operator, repository, corridors, indexer } = config;
|
|
@@ -8916,11 +9631,15 @@ var createSwapDrive = (config) => {
|
|
|
8916
9631
|
const reopened = await legacyOfferDepositsToAdopt(store);
|
|
8917
9632
|
for (const txid of reopen) reopened.add(txid);
|
|
8918
9633
|
const cursor = reopened.size === 0 ? scanned : new Set([...scanned].filter((txid) => !reopened.has(txid)));
|
|
9634
|
+
const bound = [...records.values()].flatMap(
|
|
9635
|
+
(record) => record.family === "offer" && record.binding !== void 0 && record.fundingTxid !== void 0 && !RETIRABLE.includes(record.status) ? [reopenedDeposit(record, record.fundingTxid)] : []
|
|
9636
|
+
);
|
|
8919
9637
|
const { restored, scannedTxids } = await restoreAssetSwaps(indexer, txs, /* @__PURE__ */ new Set(), {
|
|
8920
9638
|
operatorPubkey,
|
|
8921
9639
|
scanned: cursor,
|
|
8922
9640
|
hrp,
|
|
8923
|
-
recoveredIn
|
|
9641
|
+
recoveredIn,
|
|
9642
|
+
reopen: bound
|
|
8924
9643
|
});
|
|
8925
9644
|
const { offer } = splitRecords(await collectSwapRecords(store));
|
|
8926
9645
|
const current = new Map(offer.map((record) => [record.id, record]));
|
|
@@ -9012,6 +9731,33 @@ var createSwapDrive = (config) => {
|
|
|
9012
9731
|
onUpdate: (swap) => emit(swap.id)
|
|
9013
9732
|
});
|
|
9014
9733
|
}
|
|
9734
|
+
if (!lapseTimer) {
|
|
9735
|
+
lapseTimer = setInterval(cancelLapsed, config.pollIntervalMs ?? 5e3);
|
|
9736
|
+
cancelLapsed();
|
|
9737
|
+
}
|
|
9738
|
+
};
|
|
9739
|
+
const lapsing = /* @__PURE__ */ new Set();
|
|
9740
|
+
let lapseTimer;
|
|
9741
|
+
const cancelLapsed = () => {
|
|
9742
|
+
if (disposed || !repository) return;
|
|
9743
|
+
for (const record of records.values()) {
|
|
9744
|
+
if (record.family !== "offer" || record.binding?.taker === void 0 || record.market.kind === "restored" || record.fundingTxid === void 0 || !OFFER_LIVE(record.status) || fundingWasNotSubmitted(record) || now() <= record.expiresAt + DIRECTED_CANCEL_GRACE_SECONDS || lapsing.has(record.id)) {
|
|
9745
|
+
continue;
|
|
9746
|
+
}
|
|
9747
|
+
lapsing.add(record.id);
|
|
9748
|
+
void track(
|
|
9749
|
+
cancelSwap({
|
|
9750
|
+
wallet,
|
|
9751
|
+
repository,
|
|
9752
|
+
record,
|
|
9753
|
+
drive: { ingest: remember },
|
|
9754
|
+
indexer,
|
|
9755
|
+
now
|
|
9756
|
+
}).catch((error) => {
|
|
9757
|
+
console.warn(`[swap] could not cancel lapsed swap ${record.id}`, error);
|
|
9758
|
+
}).finally(() => lapsing.delete(record.id))
|
|
9759
|
+
);
|
|
9760
|
+
}
|
|
9015
9761
|
};
|
|
9016
9762
|
const registerRestoredOffers = async (offers2) => {
|
|
9017
9763
|
if (mode === "readonly") return;
|
|
@@ -9150,6 +9896,8 @@ var createSwapDrive = (config) => {
|
|
|
9150
9896
|
const stop = async () => {
|
|
9151
9897
|
await queue;
|
|
9152
9898
|
await manager.stop();
|
|
9899
|
+
clearInterval(lapseTimer);
|
|
9900
|
+
lapseTimer = void 0;
|
|
9153
9901
|
watcher?.stop();
|
|
9154
9902
|
await watcher?.idle();
|
|
9155
9903
|
watcher = void 0;
|
|
@@ -9317,6 +10065,10 @@ var createSwapDrive = (config) => {
|
|
|
9317
10065
|
// src/client/quoteOffer.ts
|
|
9318
10066
|
var import_solver_discovery11 = require("@arkade-os/solver-discovery");
|
|
9319
10067
|
init_offer();
|
|
10068
|
+
init_errors();
|
|
10069
|
+
|
|
10070
|
+
// src/client/resolve.ts
|
|
10071
|
+
init_errors();
|
|
9320
10072
|
|
|
9321
10073
|
// src/client/aliasTable.ts
|
|
9322
10074
|
init_store();
|
|
@@ -9578,224 +10330,8 @@ var pinAmount = (input, takeInstrument) => {
|
|
|
9578
10330
|
return void 0;
|
|
9579
10331
|
};
|
|
9580
10332
|
|
|
9581
|
-
// src/client/verify.ts
|
|
9582
|
-
init_rfq();
|
|
9583
|
-
|
|
9584
|
-
// src/client/policy.ts
|
|
9585
|
-
var DEFAULT_MAX_REFUND_WINDOW_SECONDS = 30 * 24 * 3600;
|
|
9586
|
-
|
|
9587
|
-
// src/client/verify.ts
|
|
9588
|
-
var reasonOf = (error) => error instanceof Error && typeof error.reason === "string" ? error.reason : void 0;
|
|
9589
|
-
var CHECK_BY_REASON = {
|
|
9590
|
-
invoice_expired: "invoice",
|
|
9591
|
-
invoice_undecodable: "invoice",
|
|
9592
|
-
invoice_hash_mismatch: "invoice",
|
|
9593
|
-
invoice_amount_mismatch: "invoice",
|
|
9594
|
-
insufficient_headroom: "refund_window",
|
|
9595
|
-
missing_refund_locktime: "refund_window",
|
|
9596
|
-
claim_window_too_short: "refund_window",
|
|
9597
|
-
confirmations_out_of_range: "refund_window",
|
|
9598
|
-
timelock_order: "refund_window",
|
|
9599
|
-
quote_malformed: "refund_window"
|
|
9600
|
-
};
|
|
9601
|
-
var gated = (run, quote) => {
|
|
9602
|
-
try {
|
|
9603
|
-
run();
|
|
9604
|
-
} catch (error) {
|
|
9605
|
-
const reason = reasonOf(error);
|
|
9606
|
-
if (reason === "quote_expired") {
|
|
9607
|
-
throw new QuoteExpired(quote.id, quote.expiresAt, quote.now);
|
|
9608
|
-
}
|
|
9609
|
-
const check = reason === void 0 ? void 0 : CHECK_BY_REASON[reason];
|
|
9610
|
-
if (check === void 0) throw error;
|
|
9611
|
-
throw new QuoteVerificationFailed(
|
|
9612
|
-
check,
|
|
9613
|
-
void 0,
|
|
9614
|
-
error instanceof Error ? error.message : String(error),
|
|
9615
|
-
{ cause: error }
|
|
9616
|
-
);
|
|
9617
|
-
}
|
|
9618
|
-
};
|
|
9619
|
-
var verifyResponder = (input) => {
|
|
9620
|
-
if (!input.pinnable || input.expected === void 0) {
|
|
9621
|
-
throw new QuoteVerificationFailed(
|
|
9622
|
-
"responder",
|
|
9623
|
-
"a registry-served card naming the solver's discovery key",
|
|
9624
|
-
input.expected === void 0 ? "the card names no discovery key" : "the card came out of the local cache, which does not authenticate it"
|
|
9625
|
-
);
|
|
9626
|
-
}
|
|
9627
|
-
if (input.attested === void 0) {
|
|
9628
|
-
throw new QuoteVerificationFailed(
|
|
9629
|
-
"responder",
|
|
9630
|
-
input.expected,
|
|
9631
|
-
"the transport attests nobody"
|
|
9632
|
-
);
|
|
9633
|
-
}
|
|
9634
|
-
if (input.attested !== input.expected) {
|
|
9635
|
-
throw new QuoteVerificationFailed("responder", input.expected, input.attested);
|
|
9636
|
-
}
|
|
9637
|
-
};
|
|
9638
|
-
var verifyPair = (quoted, requested) => {
|
|
9639
|
-
if (quoted !== requested) {
|
|
9640
|
-
throw new QuoteVerificationFailed("pair", requested, String(quoted));
|
|
9641
|
-
}
|
|
9642
|
-
};
|
|
9643
|
-
var verifyingDerivation = (derive) => {
|
|
9644
|
-
try {
|
|
9645
|
-
return derive();
|
|
9646
|
-
} catch (error) {
|
|
9647
|
-
if (error instanceof AddressMismatch) {
|
|
9648
|
-
const derived = Array.isArray(error.derived) ? error.derived.join(", ") : error.derived;
|
|
9649
|
-
throw new QuoteVerificationFailed("lockup_address", derived, error.quoted, {
|
|
9650
|
-
cause: error
|
|
9651
|
-
});
|
|
9652
|
-
}
|
|
9653
|
-
if (error instanceof Error) {
|
|
9654
|
-
throw new QuoteVerificationFailed("lockup_address", void 0, error.message, {
|
|
9655
|
-
cause: error
|
|
9656
|
-
});
|
|
9657
|
-
}
|
|
9658
|
-
throw error;
|
|
9659
|
-
}
|
|
9660
|
-
};
|
|
9661
|
-
var verifySendWindow = (input) => {
|
|
9662
|
-
gated(
|
|
9663
|
-
() => assertFundable({
|
|
9664
|
-
quote: input.quote,
|
|
9665
|
-
now: input.now,
|
|
9666
|
-
...input.invoiceExpiresAt === void 0 ? {} : { invoiceExpiresAt: input.invoiceExpiresAt },
|
|
9667
|
-
...input.onchain === void 0 ? {} : { onchain: input.onchain }
|
|
9668
|
-
}),
|
|
9669
|
-
{ id: input.quoteId, expiresAt: input.quote.valid_until, now: input.now }
|
|
9670
|
-
);
|
|
9671
|
-
};
|
|
9672
|
-
var verifyReceiveWindow = (input) => {
|
|
9673
|
-
gated(
|
|
9674
|
-
() => assertReceivable({
|
|
9675
|
-
quote: input.quote,
|
|
9676
|
-
payDeadline: input.payDeadline,
|
|
9677
|
-
now: input.now
|
|
9678
|
-
}),
|
|
9679
|
-
{ id: input.quoteId, expiresAt: input.payDeadline, now: input.now }
|
|
9680
|
-
);
|
|
9681
|
-
};
|
|
9682
|
-
var verifySendInvoice = (input) => {
|
|
9683
|
-
const invoiced = input.invoiced;
|
|
9684
|
-
if (input.take !== invoiced) {
|
|
9685
|
-
throw new QuoteVerificationFailed("invoice", `${invoiced}`, `${input.take}`);
|
|
9686
|
-
}
|
|
9687
|
-
if (input.give < input.take) {
|
|
9688
|
-
throw new QuoteVerificationFailed(
|
|
9689
|
-
"invoice",
|
|
9690
|
-
`at least the invoice's ${invoiced}`,
|
|
9691
|
-
`${input.give}, a negative spread`
|
|
9692
|
-
);
|
|
9693
|
-
}
|
|
9694
|
-
};
|
|
9695
|
-
var verifyReceiveInvoiceFacts = (input) => {
|
|
9696
|
-
let decoded;
|
|
9697
|
-
try {
|
|
9698
|
-
decoded = input.decode(input.invoice);
|
|
9699
|
-
} catch (cause) {
|
|
9700
|
-
throw new QuoteVerificationFailed(
|
|
9701
|
-
"invoice",
|
|
9702
|
-
"a decodable BOLT11",
|
|
9703
|
-
cause instanceof Error ? cause.message : String(cause),
|
|
9704
|
-
{ cause }
|
|
9705
|
-
);
|
|
9706
|
-
}
|
|
9707
|
-
if (!Number.isFinite(decoded.expiresAt)) {
|
|
9708
|
-
throw new QuoteVerificationFailed("invoice", "a finite expiry", `${decoded.expiresAt}`);
|
|
9709
|
-
}
|
|
9710
|
-
if (!Number.isFinite(input.validUntil)) {
|
|
9711
|
-
throw new QuoteVerificationFailed(
|
|
9712
|
-
"refund_window",
|
|
9713
|
-
"a finite valid_until",
|
|
9714
|
-
`${input.validUntil}`
|
|
9715
|
-
);
|
|
9716
|
-
}
|
|
9717
|
-
if (decoded.paymentHash !== input.paymentHash) {
|
|
9718
|
-
throw new QuoteVerificationFailed("invoice", input.paymentHash, decoded.paymentHash);
|
|
9719
|
-
}
|
|
9720
|
-
if (!Number.isSafeInteger(decoded.amountSats) || decoded.amountSats <= 0) {
|
|
9721
|
-
throw new QuoteVerificationFailed(
|
|
9722
|
-
"invoice",
|
|
9723
|
-
`${input.payAmount}`,
|
|
9724
|
-
"the invoice names no amount"
|
|
9725
|
-
);
|
|
9726
|
-
}
|
|
9727
|
-
if (BigInt(decoded.amountSats) !== input.payAmount) {
|
|
9728
|
-
throw new QuoteVerificationFailed("invoice", `${input.payAmount}`, `${decoded.amountSats}`);
|
|
9729
|
-
}
|
|
9730
|
-
return { payDeadline: Math.min(decoded.expiresAt, input.validUntil) };
|
|
9731
|
-
};
|
|
9732
|
-
var verifyQuoteTtl = (input) => {
|
|
9733
|
-
const floor = input.floorSeconds ?? 0;
|
|
9734
|
-
if (input.expiresAt - input.now <= floor) {
|
|
9735
|
-
throw new QuoteExpired(input.quoteId, input.expiresAt, input.now);
|
|
9736
|
-
}
|
|
9737
|
-
};
|
|
9738
|
-
var CSV_GRANULARITY_SECONDS = 512;
|
|
9739
|
-
var verifyRefundWindow = (input) => {
|
|
9740
|
-
const max = input.maxSeconds ?? DEFAULT_MAX_REFUND_WINDOW_SECONDS;
|
|
9741
|
-
const window = input.refundLocktime - input.now;
|
|
9742
|
-
if (!(window <= max)) {
|
|
9743
|
-
throw new QuoteVerificationFailed("refund_window", `at most ${max}s`, `${window}s`);
|
|
9744
|
-
}
|
|
9745
|
-
const delay = input.refundWithoutReceiverDelay;
|
|
9746
|
-
if (delay !== void 0 && !(delay < max + CSV_GRANULARITY_SECONDS)) {
|
|
9747
|
-
throw new QuoteVerificationFailed(
|
|
9748
|
-
"refund_window",
|
|
9749
|
-
`a solo-refund delay of at most ${max}s`,
|
|
9750
|
-
`${delay}s`
|
|
9751
|
-
);
|
|
9752
|
-
}
|
|
9753
|
-
};
|
|
9754
|
-
var verifyQuotedAmount = (input) => {
|
|
9755
|
-
verifyPinnedAmount(input);
|
|
9756
|
-
if (input.take > input.give) {
|
|
9757
|
-
throw new QuoteVerificationFailed(
|
|
9758
|
-
"pair",
|
|
9759
|
-
`${input.pair} give >= take`,
|
|
9760
|
-
`give=${input.give} take=${input.take}`
|
|
9761
|
-
);
|
|
9762
|
-
}
|
|
9763
|
-
};
|
|
9764
|
-
var verifyCrossAssetAmount = (input) => {
|
|
9765
|
-
verifyPinnedAmount(input);
|
|
9766
|
-
if (input.give <= 0n || input.take <= 0n) {
|
|
9767
|
-
throw new QuoteVerificationFailed(
|
|
9768
|
-
"pair",
|
|
9769
|
-
`${input.pair} give > 0 take > 0`,
|
|
9770
|
-
`give=${input.give} take=${input.take}`
|
|
9771
|
-
);
|
|
9772
|
-
}
|
|
9773
|
-
};
|
|
9774
|
-
var verifiedCarrierSats = (quote) => {
|
|
9775
|
-
try {
|
|
9776
|
-
return quoteCarrierSats(quote);
|
|
9777
|
-
} catch (error) {
|
|
9778
|
-
if (reasonOf(error) !== "carrier_malformed") throw error;
|
|
9779
|
-
throw new QuoteVerificationFailed(
|
|
9780
|
-
"pair",
|
|
9781
|
-
"carrier_sats a non-negative integer",
|
|
9782
|
-
String(quote.carrier_sats),
|
|
9783
|
-
{ cause: error }
|
|
9784
|
-
);
|
|
9785
|
-
}
|
|
9786
|
-
};
|
|
9787
|
-
var verifyPinnedAmount = (input) => {
|
|
9788
|
-
const quoted = input.pinned.on === "give" ? input.give : input.take;
|
|
9789
|
-
if (quoted !== input.pinned.value) {
|
|
9790
|
-
throw new QuoteVerificationFailed(
|
|
9791
|
-
"pair",
|
|
9792
|
-
`${input.pair} ${input.pinned.on}=${input.pinned.value}`,
|
|
9793
|
-
`${input.pair} ${input.pinned.on}=${quoted}`
|
|
9794
|
-
);
|
|
9795
|
-
}
|
|
9796
|
-
};
|
|
9797
|
-
|
|
9798
10333
|
// src/client/quoteOffer.ts
|
|
10334
|
+
init_verify();
|
|
9799
10335
|
var FEED_TTL_MS = 3e4;
|
|
9800
10336
|
var feedFetch = (base = fetch) => {
|
|
9801
10337
|
const at2 = /* @__PURE__ */ new Map();
|
|
@@ -9884,12 +10420,12 @@ var verifyPlanLegs = (plan, legs, give) => {
|
|
|
9884
10420
|
};
|
|
9885
10421
|
|
|
9886
10422
|
// src/client/quoteRfq.ts
|
|
9887
|
-
var
|
|
10423
|
+
var import_base23 = require("@scure/base");
|
|
9888
10424
|
var import_sdk36 = require("@arkade-os/sdk");
|
|
9889
10425
|
var import_solver_discovery12 = require("@arkade-os/solver-discovery");
|
|
9890
10426
|
|
|
9891
10427
|
// src/jointGraph.ts
|
|
9892
|
-
var
|
|
10428
|
+
var import_base22 = require("@scure/base");
|
|
9893
10429
|
var import_sha26 = require("@noble/hashes/sha2.js");
|
|
9894
10430
|
var import_sdk33 = require("@arkade-os/sdk");
|
|
9895
10431
|
function digestJointGraph(plan, template) {
|
|
@@ -9925,7 +10461,7 @@ function digestJointGraph(plan, template) {
|
|
|
9925
10461
|
preimage.set(part, at2);
|
|
9926
10462
|
at2 += part.length;
|
|
9927
10463
|
}
|
|
9928
|
-
return
|
|
10464
|
+
return import_base22.hex.encode((0, import_sha26.sha256)(preimage));
|
|
9929
10465
|
}
|
|
9930
10466
|
function verifyJointGraph(plan, template) {
|
|
9931
10467
|
try {
|
|
@@ -9953,7 +10489,7 @@ function verifyJointGraph(plan, template) {
|
|
|
9953
10489
|
}
|
|
9954
10490
|
}
|
|
9955
10491
|
function parseGraphTx(psbt) {
|
|
9956
|
-
return import_sdk33.Transaction.fromPSBT(
|
|
10492
|
+
return import_sdk33.Transaction.fromPSBT(import_base22.base64.decode(psbt));
|
|
9957
10493
|
}
|
|
9958
10494
|
function deepFreeze(value) {
|
|
9959
10495
|
if (value !== null && typeof value === "object") {
|
|
@@ -9985,8 +10521,10 @@ init_onchainHtlc();
|
|
|
9985
10521
|
|
|
9986
10522
|
// src/payment/swapRail.ts
|
|
9987
10523
|
var import_sdk34 = require("@arkade-os/sdk");
|
|
10524
|
+
init_errors();
|
|
9988
10525
|
|
|
9989
10526
|
// src/client/sats.ts
|
|
10527
|
+
init_errors();
|
|
9990
10528
|
var satsOf = (value, field) => {
|
|
9991
10529
|
if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
9992
10530
|
throw new AmountEncodingUnsupported(
|
|
@@ -10171,7 +10709,9 @@ function onchainSwapRail(client, deps) {
|
|
|
10171
10709
|
}
|
|
10172
10710
|
|
|
10173
10711
|
// src/client/quoteRfq.ts
|
|
10712
|
+
init_rfq_contract();
|
|
10174
10713
|
init_rfq();
|
|
10714
|
+
init_errors();
|
|
10175
10715
|
|
|
10176
10716
|
// src/client/rfqWire.ts
|
|
10177
10717
|
init_rfq();
|
|
@@ -10204,6 +10744,7 @@ var parseRfqQuote = (quote) => ({
|
|
|
10204
10744
|
});
|
|
10205
10745
|
|
|
10206
10746
|
// src/client/quoteRfq.ts
|
|
10747
|
+
init_verify();
|
|
10207
10748
|
var lockupOf = (derived) => ({
|
|
10208
10749
|
address: derived.address,
|
|
10209
10750
|
script: derived.script,
|
|
@@ -10211,12 +10752,12 @@ var lockupOf = (derived) => ({
|
|
|
10211
10752
|
});
|
|
10212
10753
|
var covenantInputs = (input) => {
|
|
10213
10754
|
const network = (0, import_sdk36.networkFromOperatorInfo)(input.info);
|
|
10214
|
-
const
|
|
10755
|
+
const arkade5 = input.corridors.get("arkade").deps;
|
|
10215
10756
|
return {
|
|
10216
|
-
operatorPubkey: (0, import_sdk36.toXOnly)(
|
|
10757
|
+
operatorPubkey: (0, import_sdk36.toXOnly)(import_base23.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
10217
10758
|
// The resolved per-network pin, never operator-reported: it lands in a covenant leaf
|
|
10218
10759
|
// that decides who can move the funds.
|
|
10219
|
-
emulatorPubkey: (0, import_sdk36.toXOnly)(
|
|
10760
|
+
emulatorPubkey: (0, import_sdk36.toXOnly)(import_base23.hex.decode(arkade5.emulatorPubkey), "emulator signer key"),
|
|
10220
10761
|
claimDelay: unilateralClaimDelay(Number(input.info.unilateralExitDelay)),
|
|
10221
10762
|
hrp: network.hrp
|
|
10222
10763
|
};
|
|
@@ -10224,7 +10765,7 @@ var covenantInputs = (input) => {
|
|
|
10224
10765
|
var sealingKey = (deps) => {
|
|
10225
10766
|
const configured = deps.covclaimd?.pubkey;
|
|
10226
10767
|
if (configured === void 0) return void 0;
|
|
10227
|
-
const key =
|
|
10768
|
+
const key = import_base23.hex.decode(configured);
|
|
10228
10769
|
if (key.length !== 33) {
|
|
10229
10770
|
throw new Error(
|
|
10230
10771
|
`the covclaimd deployment key must be 33-byte compressed hex, got ${key.length} bytes`
|
|
@@ -10280,7 +10821,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10280
10821
|
receiveAddress,
|
|
10281
10822
|
maker.pkScript,
|
|
10282
10823
|
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp,
|
|
10283
|
-
(0, import_sdk36.toXOnly)(
|
|
10824
|
+
(0, import_sdk36.toXOnly)(import_base23.hex.decode(input.info.signerPubkey), "ark signer key")
|
|
10284
10825
|
);
|
|
10285
10826
|
const choice = payment?.carrier;
|
|
10286
10827
|
const carrierRequest = choice === void 0 ? void 0 : choice.mode === "purchase" ? { mode: "purchase" } : {
|
|
@@ -10292,7 +10833,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10292
10833
|
if (choice?.mode === "recycleReceiver") {
|
|
10293
10834
|
if (choice.quote.assetId !== sides.wantAsset?.toString())
|
|
10294
10835
|
throw new Error("carrier quote assetId differs from requested asset");
|
|
10295
|
-
if (choice.quote.senderKey !==
|
|
10836
|
+
if (choice.quote.senderKey !== import_base23.hex.encode(maker.publicKey))
|
|
10296
10837
|
throw new Error("carrier quote senderKey differs from wallet identity");
|
|
10297
10838
|
if (input.now >= choice.quote.expiresAt - 30)
|
|
10298
10839
|
throw new Error("carrier quote expired before RFQ");
|
|
@@ -10323,6 +10864,10 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10323
10864
|
);
|
|
10324
10865
|
verifyPair(wire.pair, pair);
|
|
10325
10866
|
const parsed = parseRfqQuote(wire);
|
|
10867
|
+
const taker = contractVersion === ASSET_SWAP_V4 ? verifyTaker({
|
|
10868
|
+
attested: input.transport.attestedResponder,
|
|
10869
|
+
solverPubkey: parsed.solver
|
|
10870
|
+
}) : void 0;
|
|
10326
10871
|
verifyCrossAssetAmount({ pair, pinned, give: parsed.give, take: parsed.take });
|
|
10327
10872
|
verifyQuoteTtl({
|
|
10328
10873
|
quoteId: input.quoteId,
|
|
@@ -10354,7 +10899,7 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10354
10899
|
if (input.now >= validUntil) throw new Error("asset payment terms lapsed before funding");
|
|
10355
10900
|
assetPayment = {
|
|
10356
10901
|
receiveAddress: receiveAddress ?? new import_sdk36.ArkAddress(
|
|
10357
|
-
(0, import_sdk36.toXOnly)(
|
|
10902
|
+
(0, import_sdk36.toXOnly)(import_base23.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
10358
10903
|
maker.pkScript.slice(2),
|
|
10359
10904
|
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp
|
|
10360
10905
|
).encode(),
|
|
@@ -10368,7 +10913,9 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10368
10913
|
const reference = await (0, import_solver_discovery12.quoteOffer)(input.candidate.card, {
|
|
10369
10914
|
give: input.candidate.give,
|
|
10370
10915
|
giveAmount: parsed.give,
|
|
10371
|
-
|
|
10916
|
+
// Unconditional: a card charging for the delivered carrier refuses to price without
|
|
10917
|
+
// it whichever leg gives, and a BTC deposit funds none of its own to publish.
|
|
10918
|
+
carrierSats: carrierSats ?? ASSET_CARRIER_SATS,
|
|
10372
10919
|
...QUOTE_OPTIONS,
|
|
10373
10920
|
fetchImpl: input.feed.fetch
|
|
10374
10921
|
});
|
|
@@ -10382,7 +10929,8 @@ var quoteArkadeAsset = async (input) => {
|
|
|
10382
10929
|
maker,
|
|
10383
10930
|
...receiveAddress === void 0 ? {} : { receiveAddress },
|
|
10384
10931
|
info: input.info,
|
|
10385
|
-
contractVersion
|
|
10932
|
+
contractVersion,
|
|
10933
|
+
...taker === void 0 ? {} : { taker }
|
|
10386
10934
|
});
|
|
10387
10935
|
verifyingDerivation(() => verifyOfferAddress(wire, offer));
|
|
10388
10936
|
return {
|
|
@@ -10532,7 +11080,7 @@ var quoteLightningReceive = async (input) => {
|
|
|
10532
11080
|
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10533
11081
|
input.wallet.getAddress()
|
|
10534
11082
|
]);
|
|
10535
|
-
const paymentHash =
|
|
11083
|
+
const paymentHash = import_base23.hex.encode(secrets.paymentHash);
|
|
10536
11084
|
const lightning = input.corridors.get("lightning").deps;
|
|
10537
11085
|
const sealTo = sealingKey(lightning);
|
|
10538
11086
|
const sealsAmount = pinned.on === "take" && input.legs.take.assetId === BTC_ASSET_ID;
|
|
@@ -10652,7 +11200,7 @@ var quoteOnchainSend = async (input) => {
|
|
|
10652
11200
|
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10653
11201
|
(0, import_sdk36.provisionRefundKey)(input.wallet)
|
|
10654
11202
|
]);
|
|
10655
|
-
const paymentHash =
|
|
11203
|
+
const paymentHash = import_base23.hex.encode(secrets.paymentHash);
|
|
10656
11204
|
const wire = await input.transport.requestQuote(
|
|
10657
11205
|
withCanonicalAmount(
|
|
10658
11206
|
onchainSendRequest({
|
|
@@ -10763,7 +11311,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10763
11311
|
input.wallet.getAddress(),
|
|
10764
11312
|
input.wallet.getBoardingAddress()
|
|
10765
11313
|
]);
|
|
10766
|
-
const paymentHash =
|
|
11314
|
+
const paymentHash = import_base23.hex.encode(secrets.paymentHash);
|
|
10767
11315
|
const refundPkScript = l1ScriptForAddress(boardingAddress, l1Network);
|
|
10768
11316
|
const wire = await input.transport.requestQuote(
|
|
10769
11317
|
withCanonicalAmount(
|
|
@@ -10870,6 +11418,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10870
11418
|
|
|
10871
11419
|
// src/client/verbs.ts
|
|
10872
11420
|
var import_sdk37 = require("@arkade-os/sdk");
|
|
11421
|
+
init_errors();
|
|
10873
11422
|
var enforceFeeCeiling = (quote, call, policy) => {
|
|
10874
11423
|
let ceiling;
|
|
10875
11424
|
for (const [source, limit] of [
|
|
@@ -10894,14 +11443,14 @@ var settle = async (deps, input, maxFee) => {
|
|
|
10894
11443
|
return deps.accept(quote);
|
|
10895
11444
|
};
|
|
10896
11445
|
var pay = async (deps, destination, options = {}) => {
|
|
10897
|
-
const
|
|
10898
|
-
if (
|
|
11446
|
+
const arkade5 = (0, import_sdk37.arkTarget)(destination);
|
|
11447
|
+
if (arkade5 !== void 0) {
|
|
10899
11448
|
const amount = (0, import_sdk37.resolveSendAmount)(
|
|
10900
11449
|
"ark",
|
|
10901
11450
|
destination,
|
|
10902
11451
|
options.amount === void 0 ? void 0 : satsOf(options.amount, "amount")
|
|
10903
11452
|
);
|
|
10904
|
-
return { kind: "payment", txid: await deps.wallet.send({ address:
|
|
11453
|
+
return { kind: "payment", txid: await deps.wallet.send({ address: arkade5, amount }) };
|
|
10905
11454
|
}
|
|
10906
11455
|
const swap = await settle(
|
|
10907
11456
|
deps,
|
|
@@ -10963,7 +11512,7 @@ var nostrTransportFactory = createNostrTransportFactory();
|
|
|
10963
11512
|
|
|
10964
11513
|
// src/client/client.ts
|
|
10965
11514
|
var PREPARATIONS_HELD = 64;
|
|
10966
|
-
var mintQuoteId = () =>
|
|
11515
|
+
var mintQuoteId = () => import_base24.hex.encode(crypto.getRandomValues(new Uint8Array(16)));
|
|
10967
11516
|
var createSwapClient = (config) => {
|
|
10968
11517
|
const { wallet } = config;
|
|
10969
11518
|
const operator = config.operator ?? walletOperator(wallet);
|
|
@@ -11116,6 +11665,7 @@ var createSwapClient = (config) => {
|
|
|
11116
11665
|
return acceptQuote({
|
|
11117
11666
|
quote,
|
|
11118
11667
|
...validUntil === void 0 ? {} : { validUntil },
|
|
11668
|
+
...options?.attachOfferPacket === false ? { attachOfferPacket: false } : {},
|
|
11119
11669
|
...preparation === void 0 ? {} : { preparation },
|
|
11120
11670
|
wallet,
|
|
11121
11671
|
repository: config.repository,
|
|
@@ -11218,6 +11768,8 @@ var createSwapClient = (config) => {
|
|
|
11218
11768
|
};
|
|
11219
11769
|
|
|
11220
11770
|
// src/index.ts
|
|
11771
|
+
init_policy();
|
|
11772
|
+
init_errors();
|
|
11221
11773
|
init_rfq();
|
|
11222
11774
|
init_repository();
|
|
11223
11775
|
|
|
@@ -11481,7 +12033,7 @@ function createSwapPaymentRouter(wallet, client, config) {
|
|
|
11481
12033
|
}
|
|
11482
12034
|
|
|
11483
12035
|
// src/offerFillPlan.ts
|
|
11484
|
-
var
|
|
12036
|
+
var import_base25 = require("@scure/base");
|
|
11485
12037
|
var import_sdk42 = require("@arkade-os/sdk");
|
|
11486
12038
|
init_offer();
|
|
11487
12039
|
var OFFER_FILL_TEMPLATE = "offer-fill/1";
|
|
@@ -11496,8 +12048,9 @@ async function buildOfferFillPlan(wallet, arkServerUrl, offerHex, opts) {
|
|
|
11496
12048
|
assetCarrierSats = ASSET_CARRIER_SATS,
|
|
11497
12049
|
sponsor
|
|
11498
12050
|
} = opts;
|
|
11499
|
-
const
|
|
11500
|
-
const contract = await connectFillContract(wallet, arkServerUrl,
|
|
12051
|
+
const target = typeof offerHex === "string" ? decodeOffer(import_base25.hex.decode(offerHex)) : offerHex;
|
|
12052
|
+
const contract = await connectFillContract(wallet, arkServerUrl, target, { swapAddress });
|
|
12053
|
+
const offer = offerOf(target, contract.pkScript);
|
|
11501
12054
|
const vtxos = await contract.getUtxos();
|
|
11502
12055
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
11503
12056
|
const solverPayout = payoutScript ?? import_sdk42.ArkAddress.decode(await wallet.getAddress()).pkScript;
|
|
@@ -11545,7 +12098,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11545
12098
|
}
|
|
11546
12099
|
layout.inputs.forEach((input, i) => {
|
|
11547
12100
|
const spent = checkpoints[i].getInput(0);
|
|
11548
|
-
if (!(spent.txid instanceof Uint8Array) ||
|
|
12101
|
+
if (!(spent.txid instanceof Uint8Array) || import_base25.hex.encode(spent.txid) !== input.txid || spent.index !== input.vout) {
|
|
11549
12102
|
throw new Error(`fill plan checkpoint ${i} does not spend ${input.txid}:${input.vout}`);
|
|
11550
12103
|
}
|
|
11551
12104
|
});
|
|
@@ -11557,7 +12110,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11557
12110
|
}
|
|
11558
12111
|
layout.outputs.forEach((expected, i) => {
|
|
11559
12112
|
const out = arkTx.getOutput(i);
|
|
11560
|
-
if (!out?.script ||
|
|
12113
|
+
if (!out?.script || import_base25.hex.encode(out.script) !== import_base25.hex.encode(expected.script)) {
|
|
11561
12114
|
throw new Error(`fill plan output ${i} is not the ${expected.role} script`);
|
|
11562
12115
|
}
|
|
11563
12116
|
if (out.amount !== expected.sats) {
|
|
@@ -11571,7 +12124,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11571
12124
|
throw new Error(`fill plan output ${payments} is not the extension packet`);
|
|
11572
12125
|
}
|
|
11573
12126
|
const anchor = arkTx.getOutput(payments + 1);
|
|
11574
|
-
if (!anchor?.script ||
|
|
12127
|
+
if (!anchor?.script || import_base25.hex.encode(anchor.script) !== import_base25.hex.encode(import_sdk42.P2A.script) || anchor.amount !== import_sdk42.P2A.amount) {
|
|
11575
12128
|
throw new Error(`fill plan output ${payments + 1} is not the anchor`);
|
|
11576
12129
|
}
|
|
11577
12130
|
const packet = import_sdk42.Extension.fromTx(arkTx).getAssetPacket();
|
|
@@ -11603,8 +12156,8 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11603
12156
|
);
|
|
11604
12157
|
}
|
|
11605
12158
|
}
|
|
11606
|
-
const arkTxPsbt =
|
|
11607
|
-
const checkpointPsbts = checkpoints.map((c) =>
|
|
12159
|
+
const arkTxPsbt = import_base25.base64.encode(arkTx.toPSBT());
|
|
12160
|
+
const checkpointPsbts = checkpoints.map((c) => import_base25.base64.encode(c.toPSBT()));
|
|
11608
12161
|
const inputOwners = layout.inputs.map((input) => input.owner);
|
|
11609
12162
|
const graph = {
|
|
11610
12163
|
arkTx: arkTxPsbt,
|