@arkade-os/swap 0.1.10 → 0.1.12
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/README.md +58 -0
- package/dist/advanced.cjs +1058 -414
- package/dist/advanced.d.cts +7 -64
- package/dist/advanced.d.ts +7 -64
- package/dist/advanced.js +29 -5
- package/dist/{chunk-AUJDREZN.js → chunk-CIDVLDDM.js} +1 -1
- package/dist/{chunk-FWRDAL73.js → chunk-F3BGKWIB.js} +758 -104
- package/dist/{chunk-LCO6AJOS.js → chunk-ISKJIONJ.js} +58 -285
- package/dist/{chunk-2HQZLIVX.js → chunk-JBTU7Y6M.js} +1 -1
- package/dist/chunk-UXK7YDA4.js +568 -0
- package/dist/{chunk-6RJVT65W.js → chunk-VPVSSBY2.js} +2 -4
- package/dist/index.cjs +1045 -414
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +15 -5
- package/dist/{lockupContract-BTTRVwOt.d.cts → lockupContract-B1mr672c.d.cts} +1 -1
- package/dist/{lockupContract-aFarhlxj.d.ts → lockupContract-BRpk0NxT.d.ts} +1 -1
- package/dist/node/index.d.cts +18 -18
- package/dist/node/index.d.ts +18 -18
- package/dist/nostr.cjs +276 -302
- package/dist/nostr.d.cts +20 -2
- package/dist/nostr.d.ts +20 -2
- package/dist/nostr.js +21 -357
- package/dist/{offerFillPlan-CJC5tnEd.d.ts → offerFillPlan-BMZXiVMB.d.ts} +213 -28
- package/dist/{offerFillPlan-FmyaQoYT.d.cts → offerFillPlan-CqJerwXd.d.cts} +213 -28
- package/dist/openRfq-Dx-vxOzl.d.cts +32 -0
- package/dist/openRfq-Dx-vxOzl.d.ts +32 -0
- package/dist/openRfqTransport-MQZ7JWYN.js +9 -0
- package/dist/protocol.cjs +301 -322
- package/dist/protocol.d.cts +5 -5
- package/dist/protocol.d.ts +5 -5
- package/dist/protocol.js +6 -8
- package/dist/repositories/realm/index.d.cts +1 -1
- package/dist/repositories/realm/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/{repository-CwwhIAEd.d.cts → repository-CFC0fHAy.d.cts} +26 -26
- package/dist/{repository-DO6QKxBx.d.ts → repository-suGldzOK.d.ts} +26 -26
- package/dist/rfq-contract.cjs +3 -6
- package/dist/rfq-contract.d.cts +3 -4
- package/dist/rfq-contract.d.ts +3 -4
- package/dist/rfq-contract.js +3 -5
- package/dist/transportErrors-DZuZqnF4.d.cts +8 -0
- package/dist/transportErrors-DZuZqnF4.d.ts +8 -0
- package/dist/{verify-ENO36VPK.js → verify-HU5COTNO.js} +3 -3
- package/dist/{watch-_fZSgx_l.d.ts → watch-C2z6Onak.d.ts} +1 -1
- package/dist/{watch-DpDSP2tu.d.cts → watch-CpYjItYX.d.cts} +1 -1
- package/package.json +3 -3
package/dist/protocol.cjs
CHANGED
|
@@ -289,6 +289,26 @@ var init_onchainHtlc = __esm({
|
|
|
289
289
|
}
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
+
// src/transportErrors.ts
|
|
293
|
+
var SolverUnavailable, SolverResponseInvalid;
|
|
294
|
+
var init_transportErrors = __esm({
|
|
295
|
+
"src/transportErrors.ts"() {
|
|
296
|
+
"use strict";
|
|
297
|
+
SolverUnavailable = class extends Error {
|
|
298
|
+
constructor(message, options) {
|
|
299
|
+
super(message, options);
|
|
300
|
+
this.name = "SolverUnavailable";
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
SolverResponseInvalid = class extends SolverUnavailable {
|
|
304
|
+
constructor(message, options) {
|
|
305
|
+
super(message, options);
|
|
306
|
+
this.name = "SolverResponseInvalid";
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
292
312
|
// src/claimAmountGate.ts
|
|
293
313
|
var bindsClaimAmount;
|
|
294
314
|
var init_claimAmountGate = __esm({
|
|
@@ -498,135 +518,11 @@ var init_lockupContract = __esm({
|
|
|
498
518
|
}
|
|
499
519
|
});
|
|
500
520
|
|
|
501
|
-
// src/contracts/asset-swap.json
|
|
502
|
-
var
|
|
503
|
-
var
|
|
504
|
-
"src/contracts/asset-swap.json"() {
|
|
505
|
-
|
|
506
|
-
formatVersion: 1,
|
|
507
|
-
contractName: "AssetSwap",
|
|
508
|
-
constructorInputs: [
|
|
509
|
-
{
|
|
510
|
-
name: "receiver",
|
|
511
|
-
type: "pubkey"
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
name: "amount",
|
|
515
|
-
type: "int"
|
|
516
|
-
},
|
|
517
|
-
{
|
|
518
|
-
name: "assetTxid",
|
|
519
|
-
type: "bytes32"
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
name: "assetGroupIndex",
|
|
523
|
-
type: "int"
|
|
524
|
-
},
|
|
525
|
-
{
|
|
526
|
-
name: "user",
|
|
527
|
-
type: "pubkey"
|
|
528
|
-
}
|
|
529
|
-
],
|
|
530
|
-
functions: [
|
|
531
|
-
{
|
|
532
|
-
name: "fulfill",
|
|
533
|
-
arkade: {
|
|
534
|
-
inputs: [],
|
|
535
|
-
asm: [
|
|
536
|
-
"OP_PUSHCURRENTINPUTINDEX",
|
|
537
|
-
"OP_DUP",
|
|
538
|
-
"<assetTxid>",
|
|
539
|
-
"<assetGroupIndex>",
|
|
540
|
-
"OP_INSPECTOUTASSETLOOKUP",
|
|
541
|
-
"OP_VERIFY",
|
|
542
|
-
"<amount>",
|
|
543
|
-
"OP_GREATERTHANOREQUAL",
|
|
544
|
-
"OP_VERIFY",
|
|
545
|
-
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
546
|
-
"1",
|
|
547
|
-
"OP_NUMEQUALVERIFY",
|
|
548
|
-
"<receiver>",
|
|
549
|
-
"OP_EQUAL"
|
|
550
|
-
]
|
|
551
|
-
},
|
|
552
|
-
leaves: [
|
|
553
|
-
{
|
|
554
|
-
name: "fulfill",
|
|
555
|
-
witness: [
|
|
556
|
-
{
|
|
557
|
-
name: "serverSig",
|
|
558
|
-
type: "signature",
|
|
559
|
-
encoding: "schnorr-64",
|
|
560
|
-
injected: true
|
|
561
|
-
},
|
|
562
|
-
{
|
|
563
|
-
name: "emulatorSig",
|
|
564
|
-
type: "signature",
|
|
565
|
-
encoding: "schnorr-64",
|
|
566
|
-
injected: true
|
|
567
|
-
}
|
|
568
|
-
],
|
|
569
|
-
asm: [
|
|
570
|
-
"<SERVER_KEY>",
|
|
571
|
-
"OP_CHECKSIGVERIFY",
|
|
572
|
-
"<EMULATOR_KEY:fulfill>",
|
|
573
|
-
"OP_CHECKSIG"
|
|
574
|
-
]
|
|
575
|
-
}
|
|
576
|
-
]
|
|
577
|
-
},
|
|
578
|
-
{
|
|
579
|
-
name: "cancel",
|
|
580
|
-
leaves: [
|
|
581
|
-
{
|
|
582
|
-
name: "cancel",
|
|
583
|
-
witness: [
|
|
584
|
-
{
|
|
585
|
-
name: "userSig",
|
|
586
|
-
type: "signature",
|
|
587
|
-
encoding: "schnorr-64"
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
name: "serverSig",
|
|
591
|
-
type: "signature",
|
|
592
|
-
encoding: "schnorr-64",
|
|
593
|
-
injected: true
|
|
594
|
-
}
|
|
595
|
-
],
|
|
596
|
-
asm: [
|
|
597
|
-
"<user>",
|
|
598
|
-
"OP_CHECKSIGVERIFY",
|
|
599
|
-
"<SERVER_KEY>",
|
|
600
|
-
"OP_CHECKSIG"
|
|
601
|
-
]
|
|
602
|
-
}
|
|
603
|
-
]
|
|
604
|
-
}
|
|
605
|
-
],
|
|
606
|
-
source: {
|
|
607
|
-
entry: "asset-swap.ark",
|
|
608
|
-
files: {
|
|
609
|
-
"asset-swap.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` of the asset.\n// Coordination of who funds it lives outside the contract.\ncontract AssetSwap(\n pubkey receiver,\n int amount,\n bytes32 assetTxid,\n int assetGroupIndex,\n pubkey user\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].assets.lookup(assetTxid, assetGroupIndex) >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
compiler: {
|
|
613
|
-
name: "arkadec",
|
|
614
|
-
version: "0.1.0-rc.1",
|
|
615
|
-
options: {
|
|
616
|
-
optimize: true
|
|
617
|
-
}
|
|
618
|
-
},
|
|
619
|
-
updatedAt: "2026-11-02T17:43:42.615113722+00:00",
|
|
620
|
-
fingerprint: "sha256:e2b80add6237f6c7e2c69a96ae46d55abe6de5f71c3718106f4d5b22ac9e6d0a"
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// src/contracts/asset-swap-v4.json
|
|
626
|
-
var asset_swap_v4_default;
|
|
627
|
-
var init_asset_swap_v4 = __esm({
|
|
628
|
-
"src/contracts/asset-swap-v4.json"() {
|
|
629
|
-
asset_swap_v4_default = {
|
|
521
|
+
// src/contracts/asset-swap-directed.json
|
|
522
|
+
var asset_swap_directed_default;
|
|
523
|
+
var init_asset_swap_directed = __esm({
|
|
524
|
+
"src/contracts/asset-swap-directed.json"() {
|
|
525
|
+
asset_swap_directed_default = {
|
|
630
526
|
formatVersion: 1,
|
|
631
527
|
contractName: "AssetSwap",
|
|
632
528
|
constructorInputs: [
|
|
@@ -739,9 +635,9 @@ var init_asset_swap_v4 = __esm({
|
|
|
739
635
|
}
|
|
740
636
|
],
|
|
741
637
|
source: {
|
|
742
|
-
entry: "asset-swap-
|
|
638
|
+
entry: "asset-swap-directed.ark",
|
|
743
639
|
files: {
|
|
744
|
-
"asset-swap-
|
|
640
|
+
"asset-swap-directed.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` of the asset,\n// and only `taker` can make that spend.\ncontract AssetSwap(\n pubkey receiver,\n int amount,\n bytes32 assetTxid,\n int assetGroupIndex,\n pubkey user,\n pubkey taker\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].assets.lookup(assetTxid, assetGroupIndex) >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n // Replaces the synthesized collaborative leaf: the quoting solver is a third\n // conjunct, so an observer who reads the deposit cannot complete it.\n function fulfill(signature takerSig, signature serverSig, signature emulatorSig) tapscript {\n require(checkMultisig([taker, server, emulator], [takerSig, serverSig, emulatorSig], 3));\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
745
641
|
}
|
|
746
642
|
},
|
|
747
643
|
compiler: {
|
|
@@ -757,124 +653,11 @@ var init_asset_swap_v4 = __esm({
|
|
|
757
653
|
}
|
|
758
654
|
});
|
|
759
655
|
|
|
760
|
-
// src/contracts/sats-swap.json
|
|
761
|
-
var
|
|
762
|
-
var
|
|
763
|
-
"src/contracts/sats-swap.json"() {
|
|
764
|
-
|
|
765
|
-
formatVersion: 1,
|
|
766
|
-
contractName: "SatsSwap",
|
|
767
|
-
constructorInputs: [
|
|
768
|
-
{
|
|
769
|
-
name: "receiver",
|
|
770
|
-
type: "pubkey"
|
|
771
|
-
},
|
|
772
|
-
{
|
|
773
|
-
name: "amount",
|
|
774
|
-
type: "int"
|
|
775
|
-
},
|
|
776
|
-
{
|
|
777
|
-
name: "user",
|
|
778
|
-
type: "pubkey"
|
|
779
|
-
}
|
|
780
|
-
],
|
|
781
|
-
functions: [
|
|
782
|
-
{
|
|
783
|
-
name: "fulfill",
|
|
784
|
-
arkade: {
|
|
785
|
-
inputs: [],
|
|
786
|
-
asm: [
|
|
787
|
-
"OP_PUSHCURRENTINPUTINDEX",
|
|
788
|
-
"OP_DUP",
|
|
789
|
-
"OP_INSPECTOUTPUTVALUE",
|
|
790
|
-
"<amount>",
|
|
791
|
-
"OP_GREATERTHANOREQUAL",
|
|
792
|
-
"OP_VERIFY",
|
|
793
|
-
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
794
|
-
"1",
|
|
795
|
-
"OP_NUMEQUALVERIFY",
|
|
796
|
-
"<receiver>",
|
|
797
|
-
"OP_EQUAL"
|
|
798
|
-
]
|
|
799
|
-
},
|
|
800
|
-
leaves: [
|
|
801
|
-
{
|
|
802
|
-
name: "fulfill",
|
|
803
|
-
witness: [
|
|
804
|
-
{
|
|
805
|
-
name: "serverSig",
|
|
806
|
-
type: "signature",
|
|
807
|
-
encoding: "schnorr-64",
|
|
808
|
-
injected: true
|
|
809
|
-
},
|
|
810
|
-
{
|
|
811
|
-
name: "emulatorSig",
|
|
812
|
-
type: "signature",
|
|
813
|
-
encoding: "schnorr-64",
|
|
814
|
-
injected: true
|
|
815
|
-
}
|
|
816
|
-
],
|
|
817
|
-
asm: [
|
|
818
|
-
"<SERVER_KEY>",
|
|
819
|
-
"OP_CHECKSIGVERIFY",
|
|
820
|
-
"<EMULATOR_KEY:fulfill>",
|
|
821
|
-
"OP_CHECKSIG"
|
|
822
|
-
]
|
|
823
|
-
}
|
|
824
|
-
]
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
name: "cancel",
|
|
828
|
-
leaves: [
|
|
829
|
-
{
|
|
830
|
-
name: "cancel",
|
|
831
|
-
witness: [
|
|
832
|
-
{
|
|
833
|
-
name: "userSig",
|
|
834
|
-
type: "signature",
|
|
835
|
-
encoding: "schnorr-64"
|
|
836
|
-
},
|
|
837
|
-
{
|
|
838
|
-
name: "serverSig",
|
|
839
|
-
type: "signature",
|
|
840
|
-
encoding: "schnorr-64",
|
|
841
|
-
injected: true
|
|
842
|
-
}
|
|
843
|
-
],
|
|
844
|
-
asm: [
|
|
845
|
-
"<user>",
|
|
846
|
-
"OP_CHECKSIGVERIFY",
|
|
847
|
-
"<SERVER_KEY>",
|
|
848
|
-
"OP_CHECKSIG"
|
|
849
|
-
]
|
|
850
|
-
}
|
|
851
|
-
]
|
|
852
|
-
}
|
|
853
|
-
],
|
|
854
|
-
source: {
|
|
855
|
-
entry: "sats-swap.ark",
|
|
856
|
-
files: {
|
|
857
|
-
"sats-swap.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` sats.\n// Coordination of who funds it lives outside the contract.\ncontract SatsSwap(\n pubkey receiver,\n int amount,\n pubkey user\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].value >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
858
|
-
}
|
|
859
|
-
},
|
|
860
|
-
compiler: {
|
|
861
|
-
name: "arkadec",
|
|
862
|
-
version: "0.1.0-rc.1",
|
|
863
|
-
options: {
|
|
864
|
-
optimize: true
|
|
865
|
-
}
|
|
866
|
-
},
|
|
867
|
-
updatedAt: "2026-11-02T17:43:42.616824535+00:00",
|
|
868
|
-
fingerprint: "sha256:d7a60ab2178ede40a2e4867816689ea022641531cc662b562bebd7caa1ef96c4"
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
// src/contracts/sats-swap-v4.json
|
|
874
|
-
var sats_swap_v4_default;
|
|
875
|
-
var init_sats_swap_v4 = __esm({
|
|
876
|
-
"src/contracts/sats-swap-v4.json"() {
|
|
877
|
-
sats_swap_v4_default = {
|
|
656
|
+
// src/contracts/sats-swap-directed.json
|
|
657
|
+
var sats_swap_directed_default;
|
|
658
|
+
var init_sats_swap_directed = __esm({
|
|
659
|
+
"src/contracts/sats-swap-directed.json"() {
|
|
660
|
+
sats_swap_directed_default = {
|
|
878
661
|
formatVersion: 1,
|
|
879
662
|
contractName: "SatsSwap",
|
|
880
663
|
constructorInputs: [
|
|
@@ -976,9 +759,9 @@ var init_sats_swap_v4 = __esm({
|
|
|
976
759
|
}
|
|
977
760
|
],
|
|
978
761
|
source: {
|
|
979
|
-
entry: "sats-swap-
|
|
762
|
+
entry: "sats-swap-directed.ark",
|
|
980
763
|
files: {
|
|
981
|
-
"sats-swap-
|
|
764
|
+
"sats-swap-directed.ark": "pragma arkade ^0.1.0;\n\n// The output at this input's index pays `receiver` at least `amount` sats,\n// and only `taker` can make that spend.\ncontract SatsSwap(\n pubkey receiver,\n int amount,\n pubkey user,\n pubkey taker\n) {\n function fulfill() {\n int i = this.activeInputIndex;\n require(tx.outputs[i].value >= amount);\n let paid = tx.outputs[i].script;\n require(paid.version == 1);\n require(paid.program == receiver);\n }\n\n function fulfill(signature takerSig, signature serverSig, signature emulatorSig) tapscript {\n require(checkMultisig([taker, server, emulator], [takerSig, serverSig, emulatorSig], 3));\n }\n\n function cancel(signature userSig, signature serverSig) tapscript {\n require(checkMultisig([user, server], [userSig, serverSig], 2));\n }\n}\n"
|
|
982
765
|
}
|
|
983
766
|
},
|
|
984
767
|
compiler: {
|
|
@@ -1080,7 +863,7 @@ var init_swap_want_btc_program_v1 = __esm({
|
|
|
1080
863
|
});
|
|
1081
864
|
|
|
1082
865
|
// src/rfq-contract.ts
|
|
1083
|
-
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2,
|
|
866
|
+
var RFQ_CONTRACT_VERSIONS_KEY, RFQ_CONTRACT_VERSION_KEY, RFQ_CONTRACT_VERSION_UNSUPPORTED, ASSET_SWAP_V2, ASSET_SWAP_DIRECTED, ASSET_SWAP_BASELINE;
|
|
1084
867
|
var init_rfq_contract = __esm({
|
|
1085
868
|
"src/rfq-contract.ts"() {
|
|
1086
869
|
"use strict";
|
|
@@ -1088,60 +871,41 @@ var init_rfq_contract = __esm({
|
|
|
1088
871
|
RFQ_CONTRACT_VERSION_KEY = "contract_version";
|
|
1089
872
|
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
1090
873
|
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
1091
|
-
|
|
1092
|
-
ASSET_SWAP_V4 = "asset-swap-v4";
|
|
874
|
+
ASSET_SWAP_DIRECTED = "asset-swap-directed";
|
|
1093
875
|
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
1094
876
|
}
|
|
1095
877
|
});
|
|
1096
878
|
|
|
1097
879
|
// src/program.ts
|
|
1098
|
-
var import_sdk3, swapPrograms,
|
|
880
|
+
var import_sdk3, swapPrograms, directedSwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, ASSET_SWAP_DERIVABLE_VERSIONS, assetSwapContractVersion;
|
|
1099
881
|
var init_program = __esm({
|
|
1100
882
|
"src/program.ts"() {
|
|
1101
883
|
"use strict";
|
|
1102
884
|
import_sdk3 = require("@arkade-os/sdk");
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
init_sats_swap();
|
|
1106
|
-
init_sats_swap_v4();
|
|
885
|
+
init_asset_swap_directed();
|
|
886
|
+
init_sats_swap_directed();
|
|
1107
887
|
init_swap_want_asset_program_v1();
|
|
1108
888
|
init_swap_want_btc_program_v1();
|
|
1109
889
|
init_rfq_contract();
|
|
1110
890
|
init_rfq_contract();
|
|
1111
891
|
swapPrograms = {
|
|
1112
|
-
wantAsset: import_sdk3.arkade.programFromArtifact(asset_swap_default),
|
|
1113
|
-
wantBtc: import_sdk3.arkade.programFromArtifact(sats_swap_default)
|
|
1114
|
-
};
|
|
1115
|
-
legacySwapPrograms = {
|
|
1116
892
|
wantAsset: import_sdk3.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
1117
893
|
wantBtc: import_sdk3.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
1118
894
|
};
|
|
1119
895
|
directedSwapPrograms = {
|
|
1120
|
-
wantAsset: import_sdk3.arkade.programFromArtifact(
|
|
1121
|
-
wantBtc: import_sdk3.arkade.programFromArtifact(
|
|
896
|
+
wantAsset: import_sdk3.arkade.programFromArtifact(asset_swap_directed_default),
|
|
897
|
+
wantBtc: import_sdk3.arkade.programFromArtifact(sats_swap_directed_default)
|
|
1122
898
|
};
|
|
1123
899
|
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
1124
900
|
user,
|
|
1125
901
|
server,
|
|
1126
902
|
...exitDelay && { exitDelay }
|
|
1127
903
|
});
|
|
1128
|
-
refuseTaker = (version, { taker }) => {
|
|
1129
|
-
if (taker !== void 0) throw new Error(`${version} binds no taker key`);
|
|
1130
|
-
};
|
|
1131
|
-
v3Args = (inputs) => ({
|
|
1132
|
-
receiver: inputs.receiver,
|
|
1133
|
-
amount: inputs.amount,
|
|
1134
|
-
...inputs.asset && {
|
|
1135
|
-
assetTxid: inputs.asset.txid,
|
|
1136
|
-
assetGroupIndex: inputs.asset.groupIndex
|
|
1137
|
-
},
|
|
1138
|
-
...sharedArgs(inputs)
|
|
1139
|
-
});
|
|
1140
904
|
ASSET_SWAP_CONTRACTS = {
|
|
1141
905
|
[ASSET_SWAP_V2]: {
|
|
1142
|
-
programs:
|
|
906
|
+
programs: swapPrograms,
|
|
1143
907
|
args: (inputs) => {
|
|
1144
|
-
|
|
908
|
+
if (inputs.taker !== void 0) throw new Error(`${ASSET_SWAP_V2} binds no taker key`);
|
|
1145
909
|
return {
|
|
1146
910
|
makerWP: inputs.receiver,
|
|
1147
911
|
wantAmount: inputs.amount,
|
|
@@ -1153,23 +917,26 @@ var init_program = __esm({
|
|
|
1153
917
|
};
|
|
1154
918
|
}
|
|
1155
919
|
},
|
|
1156
|
-
[
|
|
1157
|
-
programs: swapPrograms,
|
|
1158
|
-
args: (inputs) => {
|
|
1159
|
-
refuseTaker(ASSET_SWAP_V3, inputs);
|
|
1160
|
-
return v3Args(inputs);
|
|
1161
|
-
}
|
|
1162
|
-
},
|
|
1163
|
-
[ASSET_SWAP_V4]: {
|
|
920
|
+
[ASSET_SWAP_DIRECTED]: {
|
|
1164
921
|
programs: directedSwapPrograms,
|
|
1165
922
|
args: (inputs) => {
|
|
1166
|
-
if (inputs.taker === void 0)
|
|
1167
|
-
|
|
923
|
+
if (inputs.taker === void 0)
|
|
924
|
+
throw new Error(`${ASSET_SWAP_DIRECTED} needs a taker key`);
|
|
925
|
+
return {
|
|
926
|
+
receiver: inputs.receiver,
|
|
927
|
+
amount: inputs.amount,
|
|
928
|
+
...inputs.asset && {
|
|
929
|
+
assetTxid: inputs.asset.txid,
|
|
930
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
931
|
+
},
|
|
932
|
+
...sharedArgs(inputs),
|
|
933
|
+
taker: inputs.taker
|
|
934
|
+
};
|
|
1168
935
|
}
|
|
1169
936
|
}
|
|
1170
937
|
};
|
|
1171
|
-
ASSET_SWAP_CONTRACT_VERSIONS = [
|
|
1172
|
-
ASSET_SWAP_DERIVABLE_VERSIONS = [
|
|
938
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_DIRECTED];
|
|
939
|
+
ASSET_SWAP_DERIVABLE_VERSIONS = [ASSET_SWAP_DIRECTED, ASSET_SWAP_V2];
|
|
1173
940
|
assetSwapContractVersion = (id) => {
|
|
1174
941
|
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
1175
942
|
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
@@ -1452,19 +1219,16 @@ function swapProgramBinding(offer, operatorPubkey, contractVersion) {
|
|
|
1452
1219
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
1453
1220
|
}
|
|
1454
1221
|
const directed = offer.taker !== void 0;
|
|
1455
|
-
const version = contractVersion ?? (directed ?
|
|
1222
|
+
const version = contractVersion ?? (directed ? ASSET_SWAP_DIRECTED : ASSET_SWAP_BASELINE);
|
|
1456
1223
|
const expected = offer.swapPkScript;
|
|
1457
1224
|
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, version);
|
|
1458
|
-
const
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
if (pkOf(binding) === funded) return binding;
|
|
1463
|
-
}
|
|
1464
|
-
return bindSwapProgram(offer, operatorPubkey, directed ? ASSET_SWAP_V4 : version);
|
|
1225
|
+
const candidate = directed ? ASSET_SWAP_DIRECTED : ASSET_SWAP_BASELINE;
|
|
1226
|
+
const binding = bindSwapProgram(offer, operatorPubkey, candidate);
|
|
1227
|
+
if (pkOf(binding) === import_base5.hex.encode(expected)) return binding;
|
|
1228
|
+
return bindSwapProgram(offer, operatorPubkey, directed ? ASSET_SWAP_DIRECTED : version);
|
|
1465
1229
|
}
|
|
1466
1230
|
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1467
|
-
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1231
|
+
const { programs, args } = ASSET_SWAP_CONTRACTS[assetSwapContractVersion(contractVersion)];
|
|
1468
1232
|
const user = offer.makerPublicKey;
|
|
1469
1233
|
const assetId = offer.wantAsset;
|
|
1470
1234
|
return {
|
|
@@ -2956,7 +2720,7 @@ async function requestArkadeSwap(wallet, transport, params) {
|
|
|
2956
2720
|
if (quote.pair !== pair) {
|
|
2957
2721
|
throw new Error(`solver quoted ${JSON.stringify(quote.pair)}, not the requested ${pair}`);
|
|
2958
2722
|
}
|
|
2959
|
-
const taker = contractVersion ===
|
|
2723
|
+
const taker = contractVersion === ASSET_SWAP_DIRECTED ? (await Promise.resolve().then(() => (init_verify(), verify_exports))).verifyTaker({
|
|
2960
2724
|
attested: transport.attestedResponder,
|
|
2961
2725
|
solverPubkey: quote.solver_pubkey
|
|
2962
2726
|
}) : void 0;
|
|
@@ -3326,6 +3090,7 @@ var init_rfq = __esm({
|
|
|
3326
3090
|
"src/rfq.ts"() {
|
|
3327
3091
|
"use strict";
|
|
3328
3092
|
import_base7 = require("@scure/base");
|
|
3093
|
+
init_transportErrors();
|
|
3329
3094
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
3330
3095
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
3331
3096
|
import_sdk7 = require("@arkade-os/sdk");
|
|
@@ -3670,10 +3435,10 @@ var init_rfq = __esm({
|
|
|
3670
3435
|
});
|
|
3671
3436
|
}
|
|
3672
3437
|
if (p?.type !== "rfq_quote" || p.rfq_id !== rfqId) {
|
|
3673
|
-
throw new
|
|
3438
|
+
throw new SolverResponseInvalid(`unexpected reply: ${p?.type ?? "no payload"}`);
|
|
3674
3439
|
}
|
|
3675
3440
|
if (requestedPair !== void 0 && p.pair !== requestedPair) {
|
|
3676
|
-
throw new
|
|
3441
|
+
throw new SolverResponseInvalid(
|
|
3677
3442
|
`solver quoted ${JSON.stringify(p.pair)}, not the requested ${requestedPair}`
|
|
3678
3443
|
);
|
|
3679
3444
|
}
|
|
@@ -3697,11 +3462,13 @@ var init_rfq = __esm({
|
|
|
3697
3462
|
}
|
|
3698
3463
|
const selected = quote[RFQ_CONTRACT_VERSION_KEY];
|
|
3699
3464
|
if (sent !== request && selected !== void 0) {
|
|
3700
|
-
throw new
|
|
3465
|
+
throw new SolverResponseInvalid(
|
|
3466
|
+
`solver chose contract version ${selected}, but none was advertised`
|
|
3467
|
+
);
|
|
3701
3468
|
}
|
|
3702
3469
|
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
3703
3470
|
if (!advertised.includes(version)) {
|
|
3704
|
-
throw new
|
|
3471
|
+
throw new SolverResponseInvalid(
|
|
3705
3472
|
selected === void 0 ? `solver negotiated no contract version; advertised ${advertised.join(", ")}` : `solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
3706
3473
|
);
|
|
3707
3474
|
}
|
|
@@ -4236,33 +4003,246 @@ var init_nostrPool = __esm({
|
|
|
4236
4003
|
}
|
|
4237
4004
|
});
|
|
4238
4005
|
|
|
4006
|
+
// src/openRfq.ts
|
|
4007
|
+
var RFQ_BROADCAST_KIND, idPattern, pairPattern, hexKey, positiveAtomic, positiveSeconds, openRfqPayload, parseOpenRfqBid, rankOpenRfqBids;
|
|
4008
|
+
var init_openRfq = __esm({
|
|
4009
|
+
"src/openRfq.ts"() {
|
|
4010
|
+
"use strict";
|
|
4011
|
+
RFQ_BROADCAST_KIND = 24860;
|
|
4012
|
+
idPattern = /^[a-f0-9]{64}$/;
|
|
4013
|
+
pairPattern = /^[a-zA-Z0-9:/._%-]{1,256}->[a-zA-Z0-9:/._%-]{1,256}$/;
|
|
4014
|
+
hexKey = /^[a-f0-9]{64}$/;
|
|
4015
|
+
positiveAtomic = (value) => typeof value === "string" && /^[1-9][0-9]{0,127}$/.test(value) ? BigInt(value) : void 0;
|
|
4016
|
+
positiveSeconds = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
4017
|
+
openRfqPayload = (request) => {
|
|
4018
|
+
if (!idPattern.test(request.openId) || !pairPattern.test(request.pair) || request.amountSide !== "from" && request.amountSide !== "to" || typeof request.amount !== "bigint" || positiveAtomic(request.amount.toString()) === void 0 || !positiveSeconds(request.bidsUntil))
|
|
4019
|
+
throw new Error("invalid open RFQ request");
|
|
4020
|
+
return {
|
|
4021
|
+
v: 1,
|
|
4022
|
+
type: "rfq_open",
|
|
4023
|
+
open_id: request.openId,
|
|
4024
|
+
pair: request.pair,
|
|
4025
|
+
amount_side: request.amountSide,
|
|
4026
|
+
amount: request.amount.toString(),
|
|
4027
|
+
bids_until: request.bidsUntil
|
|
4028
|
+
};
|
|
4029
|
+
};
|
|
4030
|
+
parseOpenRfqBid = (payload, solverPubkey, eventId) => {
|
|
4031
|
+
if (!payload || typeof payload !== "object" || !hexKey.test(solverPubkey) || !hexKey.test(eventId))
|
|
4032
|
+
return null;
|
|
4033
|
+
const value = payload;
|
|
4034
|
+
const fromAmount = positiveAtomic(value.from_amount);
|
|
4035
|
+
const toAmount2 = positiveAtomic(value.to_amount);
|
|
4036
|
+
if (value.v !== 1 || value.type !== "rfq_bid" || typeof value.open_id !== "string" || !idPattern.test(value.open_id) || typeof value.pair !== "string" || !pairPattern.test(value.pair) || value.amount_side !== "from" && value.amount_side !== "to" || fromAmount === void 0 || toAmount2 === void 0 || !positiveSeconds(value.valid_until) || !value.card || typeof value.card !== "object" || Array.isArray(value.card))
|
|
4037
|
+
return null;
|
|
4038
|
+
return {
|
|
4039
|
+
id: eventId,
|
|
4040
|
+
solverPubkey,
|
|
4041
|
+
openId: value.open_id,
|
|
4042
|
+
pair: value.pair,
|
|
4043
|
+
amountSide: value.amount_side,
|
|
4044
|
+
fromAmount,
|
|
4045
|
+
toAmount: toAmount2,
|
|
4046
|
+
validUntil: value.valid_until,
|
|
4047
|
+
card: value.card
|
|
4048
|
+
};
|
|
4049
|
+
};
|
|
4050
|
+
rankOpenRfqBids = (bids, amountSide) => [...bids].sort((left, right) => {
|
|
4051
|
+
const difference = amountSide === "from" ? right.toAmount - left.toAmount : left.fromAmount - right.fromAmount;
|
|
4052
|
+
return difference < 0n ? -1 : difference > 0n ? 1 : left.solverPubkey.localeCompare(right.solverPubkey) || left.id.localeCompare(right.id);
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
});
|
|
4056
|
+
|
|
4057
|
+
// src/openRfqTransport.ts
|
|
4058
|
+
var import_nostr_tools2, MAX_BIDS, MAX_AUTHENTICATED_REPLY_DECRYPTIONS, MAX_EVENT_CONTENT, MAX_WINDOW_MS, CLOCK_SKEW_SECONDS, collectOpenRfqBids;
|
|
4059
|
+
var init_openRfqTransport = __esm({
|
|
4060
|
+
"src/openRfqTransport.ts"() {
|
|
4061
|
+
"use strict";
|
|
4062
|
+
import_nostr_tools2 = require("nostr-tools");
|
|
4063
|
+
init_nostr();
|
|
4064
|
+
init_nostrPool();
|
|
4065
|
+
init_openRfq();
|
|
4066
|
+
init_transportErrors();
|
|
4067
|
+
MAX_BIDS = 64;
|
|
4068
|
+
MAX_AUTHENTICATED_REPLY_DECRYPTIONS = 256;
|
|
4069
|
+
MAX_EVENT_CONTENT = 1e5;
|
|
4070
|
+
MAX_WINDOW_MS = 3e4;
|
|
4071
|
+
CLOCK_SKEW_SECONDS = 30;
|
|
4072
|
+
collectOpenRfqBids = (request, options) => {
|
|
4073
|
+
const payload = openRfqPayload(request);
|
|
4074
|
+
const windowMs = options.windowMs ?? 3e3;
|
|
4075
|
+
if (!Number.isSafeInteger(windowMs) || windowMs < 0 || windowMs > MAX_WINDOW_MS)
|
|
4076
|
+
throw new Error("windowMs must be an integer between 0 and 30000");
|
|
4077
|
+
const started = Date.now();
|
|
4078
|
+
const now = Math.floor(started / 1e3);
|
|
4079
|
+
const duration = Math.min(windowMs, request.bidsUntil * 1e3 - started);
|
|
4080
|
+
if (duration < 0 || request.bidsUntil > now + 31) throw new Error("invalid open RFQ deadline");
|
|
4081
|
+
const relays = [...new Set(options.relays)];
|
|
4082
|
+
if (!relays.length || relays.length > 16)
|
|
4083
|
+
throw new Error("open RFQ requires between 1 and 16 relays");
|
|
4084
|
+
for (const relay of relays) {
|
|
4085
|
+
const url = new URL(relay);
|
|
4086
|
+
if (!/^wss?:$/.test(url.protocol) || url.username || url.password || url.hash)
|
|
4087
|
+
throw new Error("invalid open RFQ relay");
|
|
4088
|
+
}
|
|
4089
|
+
options.signal?.throwIfAborted();
|
|
4090
|
+
const secretKey = new Uint8Array(options.secretKey);
|
|
4091
|
+
const clientPubkey = (0, import_nostr_tools2.getPublicKey)(secretKey);
|
|
4092
|
+
const event = (0, import_nostr_tools2.finalizeEvent)(
|
|
4093
|
+
{
|
|
4094
|
+
kind: RFQ_BROADCAST_KIND,
|
|
4095
|
+
created_at: now,
|
|
4096
|
+
tags: [["t", request.pair]],
|
|
4097
|
+
content: JSON.stringify(payload)
|
|
4098
|
+
},
|
|
4099
|
+
secretKey
|
|
4100
|
+
);
|
|
4101
|
+
const pool = options.pool ?? sharedNostrPool();
|
|
4102
|
+
return new Promise((resolve, reject) => {
|
|
4103
|
+
const bids = /* @__PURE__ */ new Map();
|
|
4104
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4105
|
+
let closed = false;
|
|
4106
|
+
let accepted = false;
|
|
4107
|
+
let subscription;
|
|
4108
|
+
const noRelay = () => new SolverUnavailable("no relay accepted the open RFQ");
|
|
4109
|
+
const finish = (error) => {
|
|
4110
|
+
if (closed) return;
|
|
4111
|
+
closed = true;
|
|
4112
|
+
clearTimeout(timer);
|
|
4113
|
+
options.signal?.removeEventListener("abort", abort);
|
|
4114
|
+
try {
|
|
4115
|
+
subscription?.close();
|
|
4116
|
+
} catch {
|
|
4117
|
+
}
|
|
4118
|
+
secretKey.fill(0);
|
|
4119
|
+
if (error !== void 0) reject(error);
|
|
4120
|
+
else resolve(rankOpenRfqBids([...bids.values()], request.amountSide));
|
|
4121
|
+
};
|
|
4122
|
+
const abort = () => finish(options.signal?.reason ?? new Error("open RFQ aborted"));
|
|
4123
|
+
const timer = setTimeout(() => finish(accepted ? void 0 : noRelay()), duration);
|
|
4124
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
4125
|
+
try {
|
|
4126
|
+
subscription = pool.subscribeMany(
|
|
4127
|
+
relays,
|
|
4128
|
+
{
|
|
4129
|
+
kinds: [RFQ_DIRECTED_KIND],
|
|
4130
|
+
"#p": [clientPubkey],
|
|
4131
|
+
"#e": [event.id],
|
|
4132
|
+
since: now - CLOCK_SKEW_SECONDS
|
|
4133
|
+
},
|
|
4134
|
+
{
|
|
4135
|
+
onevent(reply) {
|
|
4136
|
+
const current = Math.floor(Date.now() / 1e3);
|
|
4137
|
+
if (closed || !reply || typeof reply.content !== "string" || typeof reply.id !== "string" || !/^[a-f0-9]{64}$/.test(reply.id) || typeof reply.pubkey !== "string" || !/^[a-f0-9]{64}$/.test(reply.pubkey) || typeof reply.sig !== "string" || !/^[a-f0-9]{128}$/.test(reply.sig) || !Array.isArray(reply.tags) || reply.tags.length > 32 || !reply.tags.every(
|
|
4138
|
+
(tag) => Array.isArray(tag) && tag.length <= 8 && tag.every(
|
|
4139
|
+
(value) => typeof value === "string" && value.length <= 1024
|
|
4140
|
+
)
|
|
4141
|
+
) || Date.now() >= started + duration || reply.kind !== RFQ_DIRECTED_KIND || reply.content.length > MAX_EVENT_CONTENT || !Number.isSafeInteger(reply.created_at) || reply.created_at < event.created_at - CLOCK_SKEW_SECONDS || reply.created_at > current + CLOCK_SKEW_SECONDS || reply.created_at >= request.bidsUntil || seen.has(reply.id) || seen.size >= MAX_AUTHENTICATED_REPLY_DECRYPTIONS)
|
|
4142
|
+
return;
|
|
4143
|
+
const recipients = reply.tags.filter((tag) => tag[0] === "p");
|
|
4144
|
+
const references = reply.tags.filter((tag) => tag[0] === "e");
|
|
4145
|
+
if (recipients.length !== 1 || recipients[0]?.[1] !== clientPubkey || references.length !== 1 || references[0]?.[1] !== event.id)
|
|
4146
|
+
return;
|
|
4147
|
+
try {
|
|
4148
|
+
if (!(0, import_nostr_tools2.verifyEvent)(reply)) return;
|
|
4149
|
+
seen.add(reply.id);
|
|
4150
|
+
const key = import_nostr_tools2.nip44.v2.utils.getConversationKey(secretKey, reply.pubkey);
|
|
4151
|
+
const bid = parseOpenRfqBid(
|
|
4152
|
+
JSON.parse(import_nostr_tools2.nip44.v2.decrypt(reply.content, key)),
|
|
4153
|
+
reply.pubkey,
|
|
4154
|
+
reply.id
|
|
4155
|
+
);
|
|
4156
|
+
if (!bid || bid.openId !== request.openId || bid.pair !== request.pair || bid.amountSide !== request.amountSide || bid.validUntil <= current || bid.validUntil <= request.bidsUntil || (request.amountSide === "from" ? bid.fromAmount : bid.toAmount) !== request.amount)
|
|
4157
|
+
return;
|
|
4158
|
+
const previous = bids.get(bid.solverPubkey);
|
|
4159
|
+
if (previous) {
|
|
4160
|
+
const improved = request.amountSide === "from" ? bid.toAmount > previous.toAmount : bid.fromAmount < previous.fromAmount;
|
|
4161
|
+
if (!improved) return;
|
|
4162
|
+
} else if (bids.size >= MAX_BIDS) {
|
|
4163
|
+
const worst = rankOpenRfqBids(
|
|
4164
|
+
[...bids.values()],
|
|
4165
|
+
request.amountSide
|
|
4166
|
+
).at(-1);
|
|
4167
|
+
if (rankOpenRfqBids([worst, bid], request.amountSide)[0] !== bid)
|
|
4168
|
+
return;
|
|
4169
|
+
bids.delete(worst.solverPubkey);
|
|
4170
|
+
}
|
|
4171
|
+
bids.set(bid.solverPubkey, bid);
|
|
4172
|
+
accepted = true;
|
|
4173
|
+
options.onBids?.(
|
|
4174
|
+
rankOpenRfqBids([...bids.values()], request.amountSide)
|
|
4175
|
+
);
|
|
4176
|
+
} catch {
|
|
4177
|
+
}
|
|
4178
|
+
},
|
|
4179
|
+
onclose(reasons) {
|
|
4180
|
+
finish(new RelayUnavailable(reasons.map(String)));
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
);
|
|
4184
|
+
if (closed) subscription.close();
|
|
4185
|
+
else {
|
|
4186
|
+
const publications = pool.publish(relays, event);
|
|
4187
|
+
if (!publications.length) finish(noRelay());
|
|
4188
|
+
void Promise.allSettled(publications).then((results) => {
|
|
4189
|
+
accepted ||= results.some(
|
|
4190
|
+
(result) => result.status === "fulfilled" && !String(result.value).startsWith("connection failure")
|
|
4191
|
+
);
|
|
4192
|
+
if (!accepted) finish(noRelay());
|
|
4193
|
+
});
|
|
4194
|
+
for (const publication of publications)
|
|
4195
|
+
void publication.then(
|
|
4196
|
+
(result) => {
|
|
4197
|
+
if (!String(result).startsWith("connection failure")) accepted = true;
|
|
4198
|
+
},
|
|
4199
|
+
() => {
|
|
4200
|
+
}
|
|
4201
|
+
);
|
|
4202
|
+
}
|
|
4203
|
+
} catch (error) {
|
|
4204
|
+
finish(error);
|
|
4205
|
+
}
|
|
4206
|
+
});
|
|
4207
|
+
};
|
|
4208
|
+
}
|
|
4209
|
+
});
|
|
4210
|
+
|
|
4239
4211
|
// src/nostr.ts
|
|
4240
4212
|
var nostr_exports = {};
|
|
4241
4213
|
__export(nostr_exports, {
|
|
4214
|
+
RFQ_BROADCAST_KIND: () => RFQ_BROADCAST_KIND,
|
|
4242
4215
|
RFQ_DIRECTED_KIND: () => RFQ_DIRECTED_KIND,
|
|
4243
4216
|
RelayUnavailable: () => RelayUnavailable,
|
|
4244
4217
|
TransportClosed: () => TransportClosed,
|
|
4245
4218
|
closeSharedNostrPool: () => closeSharedNostrPool,
|
|
4219
|
+
collectOpenRfqBids: () => collectOpenRfqBids,
|
|
4246
4220
|
createNostrPool: () => createNostrPool,
|
|
4247
4221
|
nostrCardFetcher: () => nostrCardFetcher,
|
|
4248
4222
|
nostrRfqTransport: () => nostrRfqTransport,
|
|
4223
|
+
openRfqPayload: () => openRfqPayload,
|
|
4224
|
+
parseOpenRfqBid: () => parseOpenRfqBid,
|
|
4225
|
+
rankOpenRfqBids: () => rankOpenRfqBids,
|
|
4249
4226
|
sharedNostrPool: () => sharedNostrPool
|
|
4250
4227
|
});
|
|
4251
|
-
var import_solver_discovery4, import_sdk18,
|
|
4228
|
+
var import_solver_discovery4, import_sdk18, import_nostr_tools3, RFQ_DIRECTED_KIND, DEFAULT_TIMEOUT_MS, CONNECTION_FAILURE, CARD_FETCH_TIMEOUT_MS, RelayUnavailable, TransportClosed, closeReasons, nostrRfqTransport, isNewer, nostrCardFetcher;
|
|
4252
4229
|
var init_nostr = __esm({
|
|
4253
4230
|
"src/nostr.ts"() {
|
|
4254
4231
|
"use strict";
|
|
4255
4232
|
import_solver_discovery4 = require("@arkade-os/solver-discovery");
|
|
4256
4233
|
init_rfq();
|
|
4257
4234
|
init_nostrPool();
|
|
4235
|
+
init_transportErrors();
|
|
4258
4236
|
import_sdk18 = require("@arkade-os/sdk");
|
|
4259
|
-
|
|
4237
|
+
import_nostr_tools3 = require("nostr-tools");
|
|
4260
4238
|
init_nostrPool();
|
|
4239
|
+
init_openRfqTransport();
|
|
4240
|
+
init_openRfq();
|
|
4261
4241
|
RFQ_DIRECTED_KIND = 24859;
|
|
4262
4242
|
DEFAULT_TIMEOUT_MS = 3e4;
|
|
4263
4243
|
CONNECTION_FAILURE = "connection failure";
|
|
4264
4244
|
CARD_FETCH_TIMEOUT_MS = 5e3;
|
|
4265
|
-
RelayUnavailable = class extends
|
|
4245
|
+
RelayUnavailable = class extends SolverUnavailable {
|
|
4266
4246
|
reasons;
|
|
4267
4247
|
constructor(reasons) {
|
|
4268
4248
|
super(`lost every relay connection: ${reasons.join("; ") || "connection closed"}`);
|
|
@@ -4285,11 +4265,11 @@ var init_nostr = __esm({
|
|
|
4285
4265
|
(0, import_sdk18.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
4286
4266
|
const relays = options.relays;
|
|
4287
4267
|
const solverPubkey = options.solverPubkey;
|
|
4288
|
-
const secretKey = options.secretKey ?? (0,
|
|
4289
|
-
const pubkey = (0,
|
|
4268
|
+
const secretKey = options.secretKey ?? (0, import_nostr_tools3.generateSecretKey)();
|
|
4269
|
+
const pubkey = (0, import_nostr_tools3.getPublicKey)(secretKey);
|
|
4290
4270
|
const pool = options.pool ?? sharedNostrPool();
|
|
4291
4271
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
4292
|
-
const conversationKey =
|
|
4272
|
+
const conversationKey = import_nostr_tools3.nip44.v2.utils.getConversationKey(secretKey, solverPubkey);
|
|
4293
4273
|
let closed = false;
|
|
4294
4274
|
let lost;
|
|
4295
4275
|
const waiters = /* @__PURE__ */ new Map();
|
|
@@ -4298,10 +4278,10 @@ var init_nostr = __esm({
|
|
|
4298
4278
|
{ kinds: [RFQ_DIRECTED_KIND], "#p": [pubkey], authors: [solverPubkey] },
|
|
4299
4279
|
{
|
|
4300
4280
|
onevent(event) {
|
|
4301
|
-
if (event.pubkey !== solverPubkey || !(0,
|
|
4281
|
+
if (event.pubkey !== solverPubkey || !(0, import_nostr_tools3.verifyEvent)(event)) return;
|
|
4302
4282
|
let payload;
|
|
4303
4283
|
try {
|
|
4304
|
-
payload = JSON.parse(
|
|
4284
|
+
payload = JSON.parse(import_nostr_tools3.nip44.v2.decrypt(event.content, conversationKey));
|
|
4305
4285
|
} catch {
|
|
4306
4286
|
return;
|
|
4307
4287
|
}
|
|
@@ -4320,12 +4300,12 @@ var init_nostr = __esm({
|
|
|
4320
4300
|
}
|
|
4321
4301
|
);
|
|
4322
4302
|
const send = async (payload) => {
|
|
4323
|
-
const event = (0,
|
|
4303
|
+
const event = (0, import_nostr_tools3.finalizeEvent)(
|
|
4324
4304
|
{
|
|
4325
4305
|
kind: RFQ_DIRECTED_KIND,
|
|
4326
4306
|
created_at: Math.floor(Date.now() / 1e3),
|
|
4327
4307
|
tags: [["p", solverPubkey]],
|
|
4328
|
-
content:
|
|
4308
|
+
content: import_nostr_tools3.nip44.v2.encrypt(JSON.stringify(payload), conversationKey)
|
|
4329
4309
|
},
|
|
4330
4310
|
secretKey
|
|
4331
4311
|
);
|
|
@@ -4336,13 +4316,14 @@ var init_nostr = __esm({
|
|
|
4336
4316
|
const accepted = results.some(
|
|
4337
4317
|
(r) => r.status === "fulfilled" && !String(r.value).startsWith(CONNECTION_FAILURE)
|
|
4338
4318
|
);
|
|
4339
|
-
if (!accepted)
|
|
4319
|
+
if (!accepted)
|
|
4320
|
+
throw new SolverUnavailable(`no relay accepted the RFQ message: ${reasons.join("; ")}`);
|
|
4340
4321
|
};
|
|
4341
4322
|
const awaitReply = (rfqId) => {
|
|
4342
4323
|
const reply = new Promise((resolve, reject) => {
|
|
4343
4324
|
const timer = setTimeout(() => {
|
|
4344
4325
|
waiters.delete(rfqId);
|
|
4345
|
-
reject(new
|
|
4326
|
+
reject(new SolverUnavailable(`no solver reply within ${timeoutMs}ms`));
|
|
4346
4327
|
}, timeoutMs);
|
|
4347
4328
|
waiters.set(rfqId, {
|
|
4348
4329
|
resolve: (payload) => {
|
|
@@ -4428,7 +4409,7 @@ var init_nostr = __esm({
|
|
|
4428
4409
|
onevent(event) {
|
|
4429
4410
|
if (event.kind !== import_solver_discovery4.SOLVER_CARD_KIND || !asked.has(event.pubkey))
|
|
4430
4411
|
return;
|
|
4431
|
-
if (!(0,
|
|
4412
|
+
if (!(0, import_nostr_tools3.verifyEvent)(event)) return;
|
|
4432
4413
|
if (event.tags.find((tag) => tag[0] === "d")?.[1] !== network)
|
|
4433
4414
|
return;
|
|
4434
4415
|
if (isNewer(event, latest.get(event.pubkey)))
|
|
@@ -4480,9 +4461,8 @@ __export(protocol_exports, {
|
|
|
4480
4461
|
ASSET_SWAP_BASELINE: () => ASSET_SWAP_BASELINE,
|
|
4481
4462
|
ASSET_SWAP_CONTRACT_VERSIONS: () => ASSET_SWAP_CONTRACT_VERSIONS,
|
|
4482
4463
|
ASSET_SWAP_DERIVABLE_VERSIONS: () => ASSET_SWAP_DERIVABLE_VERSIONS,
|
|
4464
|
+
ASSET_SWAP_DIRECTED: () => ASSET_SWAP_DIRECTED,
|
|
4483
4465
|
ASSET_SWAP_V2: () => ASSET_SWAP_V2,
|
|
4484
|
-
ASSET_SWAP_V3: () => ASSET_SWAP_V3,
|
|
4485
|
-
ASSET_SWAP_V4: () => ASSET_SWAP_V4,
|
|
4486
4466
|
AddressMismatch: () => AddressMismatch,
|
|
4487
4467
|
BTC_ASSET_ID: () => BTC_ASSET_ID,
|
|
4488
4468
|
CROSS_ASSET_RAIL: () => CROSS_ASSET_RAIL,
|
|
@@ -7983,9 +7963,8 @@ async function watchOfferSwaps({
|
|
|
7983
7963
|
ASSET_SWAP_BASELINE,
|
|
7984
7964
|
ASSET_SWAP_CONTRACT_VERSIONS,
|
|
7985
7965
|
ASSET_SWAP_DERIVABLE_VERSIONS,
|
|
7966
|
+
ASSET_SWAP_DIRECTED,
|
|
7986
7967
|
ASSET_SWAP_V2,
|
|
7987
|
-
ASSET_SWAP_V3,
|
|
7988
|
-
ASSET_SWAP_V4,
|
|
7989
7968
|
AddressMismatch,
|
|
7990
7969
|
BTC_ASSET_ID,
|
|
7991
7970
|
CROSS_ASSET_RAIL,
|