@arkade-os/swap 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.cjs +653 -262
- package/dist/advanced.d.cts +9 -8
- package/dist/advanced.d.ts +9 -8
- package/dist/advanced.js +4 -3
- package/dist/{chunk-7BBQ74BG.js → chunk-552GDPBU.js} +484 -128
- package/dist/chunk-5QPJWOCN.js +16 -0
- package/dist/{chunk-QFM55KP2.js → chunk-FQNG4XMF.js} +9 -3
- package/dist/{chunk-SDPNWPGY.js → chunk-I7WEXXZX.js} +27 -16
- package/dist/index.cjs +669 -278
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +4 -3
- package/dist/{lockupContract-CKPFpIt9.d.ts → lockupContract-BUOsghl1.d.ts} +1 -1
- package/dist/{lockupContract-CpJXTjX_.d.cts → lockupContract-DguuT7NK.d.cts} +1 -1
- package/dist/nostr.cjs +290 -17
- package/dist/nostr.d.cts +2 -1
- package/dist/nostr.d.ts +2 -1
- package/dist/nostr.js +2 -1
- package/dist/{offer-Drw1k_jt.d.ts → offer-BhonWuKR.d.ts} +22 -17
- package/dist/{offer-Boxive2u.d.cts → offer-D_qHpWo2.d.cts} +22 -17
- package/dist/{offerFillPlan-BxNkWLtw.d.cts → offerFillPlan-Bp6-z6dS.d.cts} +3 -3
- package/dist/{offerFillPlan-D2N4s7Xe.d.ts → offerFillPlan-_AOLo6kh.d.ts} +3 -3
- package/dist/protocol.cjs +594 -198
- package/dist/protocol.d.cts +9 -8
- package/dist/protocol.d.ts +9 -8
- package/dist/protocol.js +14 -2
- package/dist/repositories/realm/index.d.cts +3 -2
- package/dist/repositories/realm/index.d.ts +3 -2
- package/dist/repositories/sqlite/index.d.cts +3 -2
- package/dist/repositories/sqlite/index.d.ts +3 -2
- package/dist/{repository-DFDNvcZ7.d.cts → repository--pfikw2R.d.cts} +1 -1
- package/dist/{repository-Dn1V17T2.d.ts → repository-CkKK0dGO.d.ts} +1 -1
- package/dist/{rfq-CP-P0PSL.d.ts → rfq-BRpo5uWU.d.cts} +14 -2
- package/dist/{rfq-CP-P0PSL.d.cts → rfq-IzhOCG02.d.ts} +14 -2
- package/dist/rfq-contract.cjs +45 -0
- package/dist/rfq-contract.d.cts +9 -0
- package/dist/rfq-contract.d.ts +9 -0
- package/dist/rfq-contract.js +16 -0
- package/dist/{watch-D-mc_wfD.d.ts → watch-DDNycuUa.d.ts} +1 -1
- package/dist/{watch-DFNMY2K-.d.cts → watch-pvTVFp6-.d.cts} +1 -1
- package/package.json +13 -3
package/dist/index.cjs
CHANGED
|
@@ -138,9 +138,9 @@ function onchainHtlcScript(params, network) {
|
|
|
138
138
|
if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
|
|
139
139
|
throw new Error("claimKey and refundKey must be 32-byte x-only keys");
|
|
140
140
|
}
|
|
141
|
-
if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
|
|
141
|
+
if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
|
|
142
142
|
throw new Error(
|
|
143
|
-
`refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
|
|
143
|
+
`refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
if (params.refundLocktime < LOCKTIME_THRESHOLD) {
|
|
@@ -229,15 +229,20 @@ async function claimOnchainFill(chain, input) {
|
|
|
229
229
|
}
|
|
230
230
|
async function classifyOnchainHtlc(chain, input) {
|
|
231
231
|
const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
232
|
+
const deep = (u) => u.confirmations >= input.minConfirmations;
|
|
233
|
+
const best = utxos.sort(
|
|
234
|
+
(a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
|
|
235
|
+
)[0];
|
|
236
|
+
const { funding } = input;
|
|
237
|
+
let spend = null;
|
|
238
|
+
if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
|
|
239
|
+
try {
|
|
240
|
+
spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (!best) throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (spend) {
|
|
241
246
|
const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
|
|
242
247
|
const txid = btc.Transaction.fromRaw(import_base.hex.decode(spend.txHex), {
|
|
243
248
|
allowUnknownInputs: true,
|
|
@@ -245,6 +250,7 @@ async function classifyOnchainHtlc(chain, input) {
|
|
|
245
250
|
}).id;
|
|
246
251
|
return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
|
|
247
252
|
}
|
|
253
|
+
if (!best) return { phase: "unfunded" };
|
|
248
254
|
if (best.confirmations < input.minConfirmations)
|
|
249
255
|
return { phase: "awaiting_confirmations", utxo: best };
|
|
250
256
|
const mtp = await chain.getMtp();
|
|
@@ -630,11 +636,248 @@ var init_lockupContract = __esm({
|
|
|
630
636
|
}
|
|
631
637
|
});
|
|
632
638
|
|
|
633
|
-
// src/swap
|
|
634
|
-
var
|
|
635
|
-
var
|
|
636
|
-
"src/swap
|
|
637
|
-
|
|
639
|
+
// src/contracts/asset-swap.json
|
|
640
|
+
var asset_swap_default;
|
|
641
|
+
var init_asset_swap = __esm({
|
|
642
|
+
"src/contracts/asset-swap.json"() {
|
|
643
|
+
asset_swap_default = {
|
|
644
|
+
formatVersion: 1,
|
|
645
|
+
contractName: "AssetSwap",
|
|
646
|
+
constructorInputs: [
|
|
647
|
+
{
|
|
648
|
+
name: "receiver",
|
|
649
|
+
type: "pubkey"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
name: "amount",
|
|
653
|
+
type: "int"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
name: "assetTxid",
|
|
657
|
+
type: "bytes32"
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
name: "assetGroupIndex",
|
|
661
|
+
type: "int"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
name: "user",
|
|
665
|
+
type: "pubkey"
|
|
666
|
+
}
|
|
667
|
+
],
|
|
668
|
+
functions: [
|
|
669
|
+
{
|
|
670
|
+
name: "fulfill",
|
|
671
|
+
arkade: {
|
|
672
|
+
inputs: [],
|
|
673
|
+
asm: [
|
|
674
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
675
|
+
"OP_DUP",
|
|
676
|
+
"<assetTxid>",
|
|
677
|
+
"<assetGroupIndex>",
|
|
678
|
+
"OP_INSPECTOUTASSETLOOKUP",
|
|
679
|
+
"OP_VERIFY",
|
|
680
|
+
"<amount>",
|
|
681
|
+
"OP_GREATERTHANOREQUAL",
|
|
682
|
+
"OP_VERIFY",
|
|
683
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
684
|
+
"1",
|
|
685
|
+
"OP_NUMEQUALVERIFY",
|
|
686
|
+
"<receiver>",
|
|
687
|
+
"OP_EQUAL"
|
|
688
|
+
]
|
|
689
|
+
},
|
|
690
|
+
leaves: [
|
|
691
|
+
{
|
|
692
|
+
name: "fulfill",
|
|
693
|
+
witness: [
|
|
694
|
+
{
|
|
695
|
+
name: "serverSig",
|
|
696
|
+
type: "signature",
|
|
697
|
+
encoding: "schnorr-64",
|
|
698
|
+
injected: true
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
name: "emulatorSig",
|
|
702
|
+
type: "signature",
|
|
703
|
+
encoding: "schnorr-64",
|
|
704
|
+
injected: true
|
|
705
|
+
}
|
|
706
|
+
],
|
|
707
|
+
asm: [
|
|
708
|
+
"<SERVER_KEY>",
|
|
709
|
+
"OP_CHECKSIGVERIFY",
|
|
710
|
+
"<EMULATOR_KEY:fulfill>",
|
|
711
|
+
"OP_CHECKSIG"
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
]
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
name: "cancel",
|
|
718
|
+
leaves: [
|
|
719
|
+
{
|
|
720
|
+
name: "cancel",
|
|
721
|
+
witness: [
|
|
722
|
+
{
|
|
723
|
+
name: "userSig",
|
|
724
|
+
type: "signature",
|
|
725
|
+
encoding: "schnorr-64"
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
name: "serverSig",
|
|
729
|
+
type: "signature",
|
|
730
|
+
encoding: "schnorr-64",
|
|
731
|
+
injected: true
|
|
732
|
+
}
|
|
733
|
+
],
|
|
734
|
+
asm: [
|
|
735
|
+
"<user>",
|
|
736
|
+
"OP_CHECKSIGVERIFY",
|
|
737
|
+
"<SERVER_KEY>",
|
|
738
|
+
"OP_CHECKSIG"
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
]
|
|
742
|
+
}
|
|
743
|
+
],
|
|
744
|
+
source: {
|
|
745
|
+
entry: "asset-swap.ark",
|
|
746
|
+
files: {
|
|
747
|
+
"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"
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
compiler: {
|
|
751
|
+
name: "arkadec",
|
|
752
|
+
version: "0.1.0-rc.1",
|
|
753
|
+
options: {
|
|
754
|
+
optimize: true
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
updatedAt: "2026-11-02T17:43:42.615113722+00:00",
|
|
758
|
+
fingerprint: "sha256:e2b80add6237f6c7e2c69a96ae46d55abe6de5f71c3718106f4d5b22ac9e6d0a"
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
// src/contracts/sats-swap.json
|
|
764
|
+
var sats_swap_default;
|
|
765
|
+
var init_sats_swap = __esm({
|
|
766
|
+
"src/contracts/sats-swap.json"() {
|
|
767
|
+
sats_swap_default = {
|
|
768
|
+
formatVersion: 1,
|
|
769
|
+
contractName: "SatsSwap",
|
|
770
|
+
constructorInputs: [
|
|
771
|
+
{
|
|
772
|
+
name: "receiver",
|
|
773
|
+
type: "pubkey"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
name: "amount",
|
|
777
|
+
type: "int"
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
name: "user",
|
|
781
|
+
type: "pubkey"
|
|
782
|
+
}
|
|
783
|
+
],
|
|
784
|
+
functions: [
|
|
785
|
+
{
|
|
786
|
+
name: "fulfill",
|
|
787
|
+
arkade: {
|
|
788
|
+
inputs: [],
|
|
789
|
+
asm: [
|
|
790
|
+
"OP_PUSHCURRENTINPUTINDEX",
|
|
791
|
+
"OP_DUP",
|
|
792
|
+
"OP_INSPECTOUTPUTVALUE",
|
|
793
|
+
"<amount>",
|
|
794
|
+
"OP_GREATERTHANOREQUAL",
|
|
795
|
+
"OP_VERIFY",
|
|
796
|
+
"OP_INSPECTOUTPUTSCRIPTPUBKEY",
|
|
797
|
+
"1",
|
|
798
|
+
"OP_NUMEQUALVERIFY",
|
|
799
|
+
"<receiver>",
|
|
800
|
+
"OP_EQUAL"
|
|
801
|
+
]
|
|
802
|
+
},
|
|
803
|
+
leaves: [
|
|
804
|
+
{
|
|
805
|
+
name: "fulfill",
|
|
806
|
+
witness: [
|
|
807
|
+
{
|
|
808
|
+
name: "serverSig",
|
|
809
|
+
type: "signature",
|
|
810
|
+
encoding: "schnorr-64",
|
|
811
|
+
injected: true
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
name: "emulatorSig",
|
|
815
|
+
type: "signature",
|
|
816
|
+
encoding: "schnorr-64",
|
|
817
|
+
injected: true
|
|
818
|
+
}
|
|
819
|
+
],
|
|
820
|
+
asm: [
|
|
821
|
+
"<SERVER_KEY>",
|
|
822
|
+
"OP_CHECKSIGVERIFY",
|
|
823
|
+
"<EMULATOR_KEY:fulfill>",
|
|
824
|
+
"OP_CHECKSIG"
|
|
825
|
+
]
|
|
826
|
+
}
|
|
827
|
+
]
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
name: "cancel",
|
|
831
|
+
leaves: [
|
|
832
|
+
{
|
|
833
|
+
name: "cancel",
|
|
834
|
+
witness: [
|
|
835
|
+
{
|
|
836
|
+
name: "userSig",
|
|
837
|
+
type: "signature",
|
|
838
|
+
encoding: "schnorr-64"
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
name: "serverSig",
|
|
842
|
+
type: "signature",
|
|
843
|
+
encoding: "schnorr-64",
|
|
844
|
+
injected: true
|
|
845
|
+
}
|
|
846
|
+
],
|
|
847
|
+
asm: [
|
|
848
|
+
"<user>",
|
|
849
|
+
"OP_CHECKSIGVERIFY",
|
|
850
|
+
"<SERVER_KEY>",
|
|
851
|
+
"OP_CHECKSIG"
|
|
852
|
+
]
|
|
853
|
+
}
|
|
854
|
+
]
|
|
855
|
+
}
|
|
856
|
+
],
|
|
857
|
+
source: {
|
|
858
|
+
entry: "sats-swap.ark",
|
|
859
|
+
files: {
|
|
860
|
+
"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"
|
|
861
|
+
}
|
|
862
|
+
},
|
|
863
|
+
compiler: {
|
|
864
|
+
name: "arkadec",
|
|
865
|
+
version: "0.1.0-rc.1",
|
|
866
|
+
options: {
|
|
867
|
+
optimize: true
|
|
868
|
+
}
|
|
869
|
+
},
|
|
870
|
+
updatedAt: "2026-11-02T17:43:42.616824535+00:00",
|
|
871
|
+
fingerprint: "sha256:d7a60ab2178ede40a2e4867816689ea022641531cc662b562bebd7caa1ef96c4"
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// src/legacy/swap-want-asset.program.v1.json
|
|
877
|
+
var swap_want_asset_program_v1_default;
|
|
878
|
+
var init_swap_want_asset_program_v1 = __esm({
|
|
879
|
+
"src/legacy/swap-want-asset.program.v1.json"() {
|
|
880
|
+
swap_want_asset_program_v1_default = {
|
|
638
881
|
version: 1,
|
|
639
882
|
name: "banco-btc-to-asset",
|
|
640
883
|
params: [
|
|
@@ -675,11 +918,11 @@ var init_swap_want_asset_program = __esm({
|
|
|
675
918
|
}
|
|
676
919
|
});
|
|
677
920
|
|
|
678
|
-
// src/swap-want-btc.program.json
|
|
679
|
-
var
|
|
680
|
-
var
|
|
681
|
-
"src/swap-want-btc.program.json"() {
|
|
682
|
-
|
|
921
|
+
// src/legacy/swap-want-btc.program.v1.json
|
|
922
|
+
var swap_want_btc_program_v1_default;
|
|
923
|
+
var init_swap_want_btc_program_v1 = __esm({
|
|
924
|
+
"src/legacy/swap-want-btc.program.v1.json"() {
|
|
925
|
+
swap_want_btc_program_v1_default = {
|
|
683
926
|
version: 1,
|
|
684
927
|
name: "banco-asset-to-btc",
|
|
685
928
|
params: [
|
|
@@ -715,6 +958,80 @@ var init_swap_want_btc_program = __esm({
|
|
|
715
958
|
}
|
|
716
959
|
});
|
|
717
960
|
|
|
961
|
+
// 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;
|
|
963
|
+
var init_rfq_contract = __esm({
|
|
964
|
+
"src/rfq-contract.ts"() {
|
|
965
|
+
"use strict";
|
|
966
|
+
RFQ_CONTRACT_VERSIONS_KEY = "contract_versions";
|
|
967
|
+
RFQ_CONTRACT_VERSION_KEY = "contract_version";
|
|
968
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED = "contract_version_unsupported";
|
|
969
|
+
ASSET_SWAP_V2 = "asset-swap-v2";
|
|
970
|
+
ASSET_SWAP_V3 = "asset-swap-v3";
|
|
971
|
+
ASSET_SWAP_BASELINE = ASSET_SWAP_V2;
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
// src/program.ts
|
|
976
|
+
var import_sdk4, swapPrograms, legacySwapPrograms, sharedArgs, ASSET_SWAP_CONTRACTS, ASSET_SWAP_CONTRACT_VERSIONS, assetSwapContractVersion;
|
|
977
|
+
var init_program = __esm({
|
|
978
|
+
"src/program.ts"() {
|
|
979
|
+
"use strict";
|
|
980
|
+
import_sdk4 = require("@arkade-os/sdk");
|
|
981
|
+
init_asset_swap();
|
|
982
|
+
init_sats_swap();
|
|
983
|
+
init_swap_want_asset_program_v1();
|
|
984
|
+
init_swap_want_btc_program_v1();
|
|
985
|
+
init_rfq_contract();
|
|
986
|
+
init_rfq_contract();
|
|
987
|
+
swapPrograms = {
|
|
988
|
+
wantAsset: import_sdk4.arkade.programFromArtifact(asset_swap_default),
|
|
989
|
+
wantBtc: import_sdk4.arkade.programFromArtifact(sats_swap_default)
|
|
990
|
+
};
|
|
991
|
+
legacySwapPrograms = {
|
|
992
|
+
wantAsset: import_sdk4.arkade.parseArtifact(swap_want_asset_program_v1_default),
|
|
993
|
+
wantBtc: import_sdk4.arkade.parseArtifact(swap_want_btc_program_v1_default)
|
|
994
|
+
};
|
|
995
|
+
sharedArgs = ({ user, server, exitDelay }) => ({
|
|
996
|
+
user,
|
|
997
|
+
server,
|
|
998
|
+
...exitDelay && { exitDelay }
|
|
999
|
+
});
|
|
1000
|
+
ASSET_SWAP_CONTRACTS = {
|
|
1001
|
+
[ASSET_SWAP_V2]: {
|
|
1002
|
+
programs: legacySwapPrograms,
|
|
1003
|
+
args: (inputs) => ({
|
|
1004
|
+
makerWP: inputs.receiver,
|
|
1005
|
+
wantAmount: inputs.amount,
|
|
1006
|
+
...inputs.asset && {
|
|
1007
|
+
wantAssetTxid: inputs.asset.txid,
|
|
1008
|
+
wantAssetGroupIndex: inputs.asset.groupIndex
|
|
1009
|
+
},
|
|
1010
|
+
...sharedArgs(inputs)
|
|
1011
|
+
})
|
|
1012
|
+
},
|
|
1013
|
+
[ASSET_SWAP_V3]: {
|
|
1014
|
+
programs: swapPrograms,
|
|
1015
|
+
args: (inputs) => ({
|
|
1016
|
+
receiver: inputs.receiver,
|
|
1017
|
+
amount: inputs.amount,
|
|
1018
|
+
...inputs.asset && {
|
|
1019
|
+
assetTxid: inputs.asset.txid,
|
|
1020
|
+
assetGroupIndex: inputs.asset.groupIndex
|
|
1021
|
+
},
|
|
1022
|
+
...sharedArgs(inputs)
|
|
1023
|
+
})
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
ASSET_SWAP_CONTRACT_VERSIONS = [ASSET_SWAP_V3, ASSET_SWAP_V2];
|
|
1027
|
+
assetSwapContractVersion = (id) => {
|
|
1028
|
+
if (id === void 0) return ASSET_SWAP_BASELINE;
|
|
1029
|
+
if (Object.hasOwn(ASSET_SWAP_CONTRACTS, id)) return id;
|
|
1030
|
+
throw new Error(`unknown contract version ${id}`);
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
|
|
718
1035
|
// src/rfqCorridor.ts
|
|
719
1036
|
var RfqCorridorRegistry, rfqCorridorHandlers;
|
|
720
1037
|
var init_rfqCorridor = __esm({
|
|
@@ -758,13 +1075,13 @@ var init_rfqCorridor = __esm({
|
|
|
758
1075
|
});
|
|
759
1076
|
|
|
760
1077
|
// src/store.ts
|
|
761
|
-
var import_base4, import_sha23,
|
|
1078
|
+
var import_base4, import_sha23, import_sdk5, BTC_ASSET_ID, byNewest, getAssetSwapsOrThrow, getAssetSwaps, saveSwapOrThrow, updateAssetSwap, updateAssetSwapBestEffort, swapSecretsToRecord, decodeHex32, PreimageNotRecoverableError, preimageForSwapRecord;
|
|
762
1079
|
var init_store = __esm({
|
|
763
1080
|
"src/store.ts"() {
|
|
764
1081
|
"use strict";
|
|
765
1082
|
import_base4 = require("@scure/base");
|
|
766
1083
|
import_sha23 = require("@noble/hashes/sha2.js");
|
|
767
|
-
|
|
1084
|
+
import_sdk5 = require("@arkade-os/sdk");
|
|
768
1085
|
init_repository();
|
|
769
1086
|
BTC_ASSET_ID = "btc";
|
|
770
1087
|
byNewest = (a, b) => b.createdAt - a.createdAt;
|
|
@@ -850,7 +1167,7 @@ var init_store = __esm({
|
|
|
850
1167
|
}
|
|
851
1168
|
let preimage;
|
|
852
1169
|
try {
|
|
853
|
-
preimage = await (0,
|
|
1170
|
+
preimage = await (0, import_sdk5.contractPreimage)(wallet, record.signingDescriptor, { stored, salt });
|
|
854
1171
|
} catch (cause) {
|
|
855
1172
|
throw new PreimageNotRecoverableError(
|
|
856
1173
|
"not-derivable",
|
|
@@ -975,37 +1292,60 @@ function withExitClosure(program, exit) {
|
|
|
975
1292
|
}
|
|
976
1293
|
};
|
|
977
1294
|
}
|
|
978
|
-
function swapProgramBinding(offer, operatorPubkey) {
|
|
1295
|
+
function swapProgramBinding(offer, operatorPubkey, contractVersion = ASSET_SWAP_BASELINE) {
|
|
979
1296
|
if (offer.makerPkScript.length !== FIELDS.makerPkScript.width) {
|
|
980
1297
|
throw new Error("makerPkScript is not a 34-byte taproot scriptPubKey");
|
|
981
1298
|
}
|
|
1299
|
+
const expected = offer.swapPkScript;
|
|
1300
|
+
if (!expected?.length) return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1301
|
+
const funded = import_base5.hex.encode(expected);
|
|
1302
|
+
const order = [
|
|
1303
|
+
ASSET_SWAP_BASELINE,
|
|
1304
|
+
...ASSET_SWAP_CONTRACT_VERSIONS.filter((v) => v !== ASSET_SWAP_BASELINE)
|
|
1305
|
+
];
|
|
1306
|
+
for (const version of order) {
|
|
1307
|
+
const binding = bindSwapProgram(offer, operatorPubkey, version);
|
|
1308
|
+
if (pkOf(binding) === funded) return binding;
|
|
1309
|
+
}
|
|
1310
|
+
return bindSwapProgram(offer, operatorPubkey, contractVersion);
|
|
1311
|
+
}
|
|
1312
|
+
function bindSwapProgram(offer, operatorPubkey, contractVersion) {
|
|
1313
|
+
const { programs, args } = ASSET_SWAP_CONTRACTS[contractVersion];
|
|
1314
|
+
const user = offer.makerPublicKey;
|
|
1315
|
+
const assetId = offer.wantAsset;
|
|
982
1316
|
return {
|
|
983
|
-
program: withExitClosure(
|
|
984
|
-
|
|
985
|
-
offer.
|
|
986
|
-
|
|
987
|
-
args: {
|
|
988
|
-
makerWP: offer.makerPkScript.subarray(2),
|
|
989
|
-
wantAmount: offer.wantAmount,
|
|
990
|
-
server: operatorPubkey,
|
|
991
|
-
user: offer.makerPublicKey,
|
|
1317
|
+
program: withExitClosure(assetId ? programs.wantAsset : programs.wantBtc, offer.exitDelay),
|
|
1318
|
+
args: args({
|
|
1319
|
+
receiver: offer.makerPkScript.subarray(2),
|
|
1320
|
+
amount: offer.wantAmount,
|
|
992
1321
|
// internal byte order
|
|
993
|
-
...
|
|
994
|
-
|
|
995
|
-
wantAssetGroupIndex: offer.wantAsset.groupIndex
|
|
1322
|
+
...assetId && {
|
|
1323
|
+
asset: { txid: assetId.txid.slice().reverse(), groupIndex: assetId.groupIndex }
|
|
996
1324
|
},
|
|
1325
|
+
user,
|
|
1326
|
+
server: operatorPubkey,
|
|
997
1327
|
...offer.exitDelay && { exitDelay: offer.exitDelay.value }
|
|
998
|
-
},
|
|
1328
|
+
}),
|
|
999
1329
|
keys: {
|
|
1000
1330
|
serverKey: operatorPubkey,
|
|
1001
|
-
userKey:
|
|
1331
|
+
userKey: user,
|
|
1002
1332
|
emulatorKey: offer.emulatorPubkey
|
|
1003
1333
|
}
|
|
1004
1334
|
};
|
|
1005
1335
|
}
|
|
1006
|
-
function
|
|
1007
|
-
|
|
1008
|
-
|
|
1336
|
+
function compileSwapBinding(binding) {
|
|
1337
|
+
let script = compiledBindings.get(binding);
|
|
1338
|
+
if (!script) {
|
|
1339
|
+
script = new import_sdk6.arkade.ArkadeProgramScript(binding.program, binding.args, binding.keys);
|
|
1340
|
+
compiledBindings.set(binding, script);
|
|
1341
|
+
}
|
|
1342
|
+
return script;
|
|
1343
|
+
}
|
|
1344
|
+
function pkOf(binding) {
|
|
1345
|
+
return import_base5.hex.encode(compileSwapBinding(binding).pkScript);
|
|
1346
|
+
}
|
|
1347
|
+
function offerContract(offer, operatorPubkey, contractVersion) {
|
|
1348
|
+
return compileSwapBinding(swapProgramBinding(offer, operatorPubkey, contractVersion));
|
|
1009
1349
|
}
|
|
1010
1350
|
function u64(name, value) {
|
|
1011
1351
|
if (value < BigInt(0) || value >> BigInt(64) > BigInt(0)) {
|
|
@@ -1121,8 +1461,8 @@ function decodeOffer(data) {
|
|
|
1121
1461
|
return {
|
|
1122
1462
|
swapPkScript: need("swapPkScript"),
|
|
1123
1463
|
wantAmount: readU64(amount),
|
|
1124
|
-
...fields.wantAsset && { wantAsset:
|
|
1125
|
-
...fields.offerAsset && { offerAsset:
|
|
1464
|
+
...fields.wantAsset && { wantAsset: import_sdk6.asset.AssetId.fromBytes(fields.wantAsset) },
|
|
1465
|
+
...fields.offerAsset && { offerAsset: import_sdk6.asset.AssetId.fromBytes(fields.offerAsset) },
|
|
1126
1466
|
makerPkScript: need("makerPkScript"),
|
|
1127
1467
|
makerPublicKey: need("makerPublicKey"),
|
|
1128
1468
|
emulatorPubkey: need("emulatorPubkey"),
|
|
@@ -1148,8 +1488,11 @@ async function registerOfferContract(wallet, info, binding, operatorPubkey, expe
|
|
|
1148
1488
|
});
|
|
1149
1489
|
}
|
|
1150
1490
|
function offerContractParams(client, binding, operatorPubkey, expectedPkScript) {
|
|
1151
|
-
const { program, args, keys } = swapProgramBinding(
|
|
1152
|
-
|
|
1491
|
+
const { program, args, keys } = swapProgramBinding(
|
|
1492
|
+
{ ...binding, swapPkScript: expectedPkScript },
|
|
1493
|
+
operatorPubkey
|
|
1494
|
+
);
|
|
1495
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, program, args, keys);
|
|
1153
1496
|
if (import_base5.hex.encode(contract.pkScript) !== import_base5.hex.encode(expectedPkScript)) {
|
|
1154
1497
|
throw new Error("derived covenant does not match the offer's swapPkScript");
|
|
1155
1498
|
}
|
|
@@ -1166,7 +1509,7 @@ async function restoreOfferCoverage(wallet, swaps) {
|
|
|
1166
1509
|
wallet.getArkadeInfo({ requireLive: true }),
|
|
1167
1510
|
wallet.getContractManager()
|
|
1168
1511
|
]);
|
|
1169
|
-
const operatorPubkey = import_base5.hex.decode((0,
|
|
1512
|
+
const operatorPubkey = import_base5.hex.decode((0, import_sdk6.toXOnlySignerHex)(info.signerPubkey));
|
|
1170
1513
|
const client = await derivingClient(wallet, info, contractManager);
|
|
1171
1514
|
const rows = await contractManager.getContracts({
|
|
1172
1515
|
script: live.map((swap) => swap.swapPkScript)
|
|
@@ -1189,7 +1532,7 @@ async function restoreOfferCoverage(wallet, swaps) {
|
|
|
1189
1532
|
params: offerContractParams(
|
|
1190
1533
|
client,
|
|
1191
1534
|
binding,
|
|
1192
|
-
stored ? import_base5.hex.decode((0,
|
|
1535
|
+
stored ? import_base5.hex.decode((0, import_sdk6.toXOnlySignerHex)(stored)) : operatorPubkey,
|
|
1193
1536
|
import_base5.hex.decode(swap.swapPkScript)
|
|
1194
1537
|
)
|
|
1195
1538
|
});
|
|
@@ -1233,7 +1576,7 @@ function resolveReceivePkScript(receiveAddress, walletPkScript, hrp, serverPubKe
|
|
|
1233
1576
|
if (receiveAddress === void 0) return walletPkScript;
|
|
1234
1577
|
let address;
|
|
1235
1578
|
try {
|
|
1236
|
-
address =
|
|
1579
|
+
address = import_sdk6.ArkAddress.decode(receiveAddress);
|
|
1237
1580
|
} catch (cause) {
|
|
1238
1581
|
throw new Error("receiveAddress is not a valid Arkade address", { cause });
|
|
1239
1582
|
}
|
|
@@ -1268,13 +1611,13 @@ async function deriveOffer(wallet, params) {
|
|
|
1268
1611
|
wallet.getAddress(),
|
|
1269
1612
|
wallet.identity.xOnlyPublicKey()
|
|
1270
1613
|
]);
|
|
1271
|
-
return { pkScript:
|
|
1614
|
+
return { pkScript: import_sdk6.ArkAddress.decode(address).pkScript, publicKey };
|
|
1272
1615
|
})()
|
|
1273
1616
|
]);
|
|
1274
|
-
const operatorPubKey = import_base5.hex.decode((0,
|
|
1275
|
-
const network = (0,
|
|
1617
|
+
const operatorPubKey = import_base5.hex.decode((0, import_sdk6.toXOnlySignerHex)(info.signerPubkey));
|
|
1618
|
+
const network = (0, import_sdk6.networkFromOperatorInfo)(info);
|
|
1276
1619
|
const emuKey = import_base5.hex.decode(
|
|
1277
|
-
(0,
|
|
1620
|
+
(0, import_sdk6.toXOnlySignerHex)((0, import_sdk6.resolveEmulatorPubkey)(network, params.emulatorPubkey))
|
|
1278
1621
|
);
|
|
1279
1622
|
const binding = Object.freeze({
|
|
1280
1623
|
wantAmount: params.wantAmount,
|
|
@@ -1291,7 +1634,7 @@ async function deriveOffer(wallet, params) {
|
|
|
1291
1634
|
// checked before registration below. @see assertExitDelay
|
|
1292
1635
|
exitDelay: params.noExit ? void 0 : params.exitDelay ? assertExitDelay(params.exitDelay) : serverExitDelay(info.unilateralExitDelay)
|
|
1293
1636
|
});
|
|
1294
|
-
const script = offerContract(binding, operatorPubKey);
|
|
1637
|
+
const script = offerContract(binding, operatorPubKey, params.contractVersion);
|
|
1295
1638
|
const offer = { ...binding, swapPkScript: script.pkScript };
|
|
1296
1639
|
const payload = encodeOffer(offer);
|
|
1297
1640
|
return Object.freeze({
|
|
@@ -1325,7 +1668,7 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1325
1668
|
wallet.getArkadeReader(),
|
|
1326
1669
|
wallet.getArkadeBroadcaster()
|
|
1327
1670
|
]);
|
|
1328
|
-
const client = await
|
|
1671
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1329
1672
|
arkade: { getInfo: async () => info, ...broadcaster },
|
|
1330
1673
|
indexer: reader,
|
|
1331
1674
|
identity: wallet.identity,
|
|
@@ -1335,21 +1678,22 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1335
1678
|
// no `network`: the row lookup is by script and the payout comes from wallet.getAddress()
|
|
1336
1679
|
oneShotSubmit: wallet.oneShotSubmit
|
|
1337
1680
|
});
|
|
1338
|
-
const operatorPubkey = swapAddress ?
|
|
1339
|
-
|
|
1681
|
+
const operatorPubkey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1682
|
+
let binding;
|
|
1340
1683
|
let rebuilt;
|
|
1341
1684
|
try {
|
|
1342
|
-
|
|
1685
|
+
binding = swapProgramBinding(offer, operatorPubkey);
|
|
1686
|
+
rebuilt = compileSwapBinding(binding);
|
|
1343
1687
|
} catch (cause) {
|
|
1344
1688
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript), { cause });
|
|
1345
1689
|
}
|
|
1346
1690
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1347
1691
|
throw new OfferCovenantMismatchError(import_base5.hex.encode(offer.swapPkScript));
|
|
1348
1692
|
}
|
|
1349
|
-
const contract = new
|
|
1693
|
+
const contract = new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1350
1694
|
const [vtxos, makerAddress] = await Promise.all([contract.getUtxos(), wallet.getAddress()]);
|
|
1351
1695
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
1352
|
-
const makerPkScript =
|
|
1696
|
+
const makerPkScript = import_sdk6.ArkAddress.decode(makerAddress).pkScript;
|
|
1353
1697
|
const cancel = contract.functions.cancel().from({ txid: vtxo.txid, vout: vtxo.vout, value: vtxo.value }).to(makerPkScript, BigInt(vtxo.value));
|
|
1354
1698
|
for (const a of vtxo.assets ?? []) {
|
|
1355
1699
|
cancel.withAsset({
|
|
@@ -1367,25 +1711,25 @@ async function prepareOfferCancel(wallet, offerHex, opts) {
|
|
|
1367
1711
|
async function connectFillContract(wallet, arkServerUrl, offer, opts = {}) {
|
|
1368
1712
|
const { swapAddress, emulator, emulatorPubkey } = opts;
|
|
1369
1713
|
const contractManager = await wallet.getContractManager();
|
|
1370
|
-
const client = await
|
|
1371
|
-
arkade: new
|
|
1372
|
-
indexer: new
|
|
1714
|
+
const client = await import_sdk6.arkade.Arkade.connect({
|
|
1715
|
+
arkade: new import_sdk6.RestOperatorProvider(arkServerUrl),
|
|
1716
|
+
indexer: new import_sdk6.RestIndexerProvider(arkServerUrl),
|
|
1373
1717
|
identity: wallet.identity,
|
|
1374
1718
|
contractManager,
|
|
1375
1719
|
...emulator !== void 0 ? {
|
|
1376
|
-
emulator: typeof emulator === "string" ? new
|
|
1720
|
+
emulator: typeof emulator === "string" ? new import_sdk6.RestEmulatorProvider(emulator) : emulator
|
|
1377
1721
|
} : {},
|
|
1378
1722
|
...emulatorPubkey ? { emulatorPubkey } : {}
|
|
1379
1723
|
});
|
|
1380
|
-
const serverKey = swapAddress ?
|
|
1381
|
-
const
|
|
1382
|
-
const rebuilt =
|
|
1724
|
+
const serverKey = swapAddress ? import_sdk6.ArkAddress.decode(swapAddress).serverPubKey : client.serverKey;
|
|
1725
|
+
const binding = swapProgramBinding(offer, serverKey);
|
|
1726
|
+
const rebuilt = compileSwapBinding(binding);
|
|
1383
1727
|
if (import_base5.hex.encode(rebuilt.pkScript) !== import_base5.hex.encode(offer.swapPkScript)) {
|
|
1384
1728
|
throw new Error(
|
|
1385
1729
|
"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"
|
|
1386
1730
|
);
|
|
1387
1731
|
}
|
|
1388
|
-
return new
|
|
1732
|
+
return new import_sdk6.arkade.ArkadeContract(client, binding.program, binding.args, binding.keys);
|
|
1389
1733
|
}
|
|
1390
1734
|
function resolveDeposit(vtxos, sel) {
|
|
1391
1735
|
const { fundingTxid, fundingOutpoint } = sel;
|
|
@@ -1674,7 +2018,7 @@ function assertScript(script, what) {
|
|
|
1674
2018
|
function assertAssetId(assetId, what) {
|
|
1675
2019
|
if (typeof assetId !== "string") throw new Error(`${what} must be an asset id string`);
|
|
1676
2020
|
try {
|
|
1677
|
-
return
|
|
2021
|
+
return import_sdk6.asset.AssetId.fromString(assetId).toString();
|
|
1678
2022
|
} catch {
|
|
1679
2023
|
throw new Error(`${what} is not a valid asset id`);
|
|
1680
2024
|
}
|
|
@@ -1696,22 +2040,18 @@ function assertFillCoin(coin, what) {
|
|
|
1696
2040
|
toAmount(coin.value, `${what}.value`, "sats", BigInt(1));
|
|
1697
2041
|
assertAssetEntries(coin.assets, what);
|
|
1698
2042
|
}
|
|
1699
|
-
var import_base5, import_utils2,
|
|
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;
|
|
1700
2044
|
var init_offer = __esm({
|
|
1701
2045
|
"src/offer.ts"() {
|
|
1702
2046
|
"use strict";
|
|
1703
2047
|
import_base5 = require("@scure/base");
|
|
1704
2048
|
import_utils2 = require("@scure/btc-signer/utils.js");
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
init_swap_want_btc_program();
|
|
2049
|
+
import_sdk6 = require("@arkade-os/sdk");
|
|
2050
|
+
init_program();
|
|
1708
2051
|
init_coverage();
|
|
1709
2052
|
init_rfqProfileParts();
|
|
1710
2053
|
init_store();
|
|
1711
|
-
|
|
1712
|
-
wantAsset: import_sdk5.arkade.parseArtifact(swap_want_asset_program_default),
|
|
1713
|
-
wantBtc: import_sdk5.arkade.parseArtifact(swap_want_btc_program_default)
|
|
1714
|
-
};
|
|
2054
|
+
compiledBindings = /* @__PURE__ */ new WeakMap();
|
|
1715
2055
|
OFFER_PACKET_TYPE = 3;
|
|
1716
2056
|
FIELDS = {
|
|
1717
2057
|
swapPkScript: { tag: 1, width: 34 },
|
|
@@ -1735,10 +2075,10 @@ var init_offer = __esm({
|
|
|
1735
2075
|
};
|
|
1736
2076
|
OFFER_CONTRACT_LABEL = "Arkade swap offer";
|
|
1737
2077
|
OFFER_CONTRACT_KIND = "asset-swap-offer";
|
|
1738
|
-
derivingClient = (wallet, info, contractManager) =>
|
|
2078
|
+
derivingClient = (wallet, info, contractManager) => import_sdk6.arkade.Arkade.connect({
|
|
1739
2079
|
arkade: { getInfo: async () => info },
|
|
1740
2080
|
identity: wallet.identity,
|
|
1741
|
-
network: (0,
|
|
2081
|
+
network: (0, import_sdk6.networkFromOperatorInfo)(info),
|
|
1742
2082
|
contractManager
|
|
1743
2083
|
});
|
|
1744
2084
|
NoSpendableDepositError = class extends Error {
|
|
@@ -1758,7 +2098,7 @@ var init_offer = __esm({
|
|
|
1758
2098
|
swapPkScript;
|
|
1759
2099
|
name = "OfferCovenantMismatchError";
|
|
1760
2100
|
};
|
|
1761
|
-
ASSET_CARRIER_SATS = BigInt(
|
|
2101
|
+
ASSET_CARRIER_SATS = BigInt(import_sdk6.ASSET_CARRIER_SATS);
|
|
1762
2102
|
amountOfAsset = (assets, assetId) => {
|
|
1763
2103
|
let total = BigInt(0);
|
|
1764
2104
|
for (const a of assets ?? []) {
|
|
@@ -1802,7 +2142,7 @@ function deriveLightningSend(input) {
|
|
|
1802
2142
|
throw new Error("lightning-send quote is missing profile.receiver_pk_script");
|
|
1803
2143
|
}
|
|
1804
2144
|
const contractParams = {
|
|
1805
|
-
solverPubkey: (0,
|
|
2145
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1806
2146
|
refundLocktime: quote.refund_locktime,
|
|
1807
2147
|
operatorPubkey: input.operatorPubkey,
|
|
1808
2148
|
paymentHash: input.paymentHash,
|
|
@@ -1848,7 +2188,7 @@ function deriveOnchainSend(input) {
|
|
|
1848
2188
|
"onchain-send"
|
|
1849
2189
|
);
|
|
1850
2190
|
const contractParams = {
|
|
1851
|
-
solverPubkey: (0,
|
|
2191
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(quote.solver_pubkey), "solver key"),
|
|
1852
2192
|
refundLocktime,
|
|
1853
2193
|
operatorPubkey: input.operatorPubkey,
|
|
1854
2194
|
paymentHash: input.paymentHash,
|
|
@@ -1857,7 +2197,7 @@ function deriveOnchainSend(input) {
|
|
|
1857
2197
|
emulatorPubkey: input.emulatorPubkey,
|
|
1858
2198
|
senderPubkey: input.senderPubkey,
|
|
1859
2199
|
receiverPkScript: solverHex(receiverPkScriptHex, "profile.receiver_pk_script"),
|
|
1860
|
-
refundPkScript:
|
|
2200
|
+
refundPkScript: import_sdk7.ArkAddress.decode(input.refundAddress).pkScript
|
|
1861
2201
|
};
|
|
1862
2202
|
const { script, address } = matchQuotedLockup(
|
|
1863
2203
|
quote,
|
|
@@ -1868,7 +2208,7 @@ function deriveOnchainSend(input) {
|
|
|
1868
2208
|
const htlcParams = {
|
|
1869
2209
|
paymentHash: input.paymentHash,
|
|
1870
2210
|
claimKey: input.payoutPubkey,
|
|
1871
|
-
refundKey: (0,
|
|
2211
|
+
refundKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(htlcPubkey), "solver L1 htlc key"),
|
|
1872
2212
|
refundLocktime: htlcLocktime
|
|
1873
2213
|
};
|
|
1874
2214
|
const htlc = onchainHtlcScript(htlcParams, input.l1Network);
|
|
@@ -1940,7 +2280,7 @@ function deriveOnchainReceive(input) {
|
|
|
1940
2280
|
).matched;
|
|
1941
2281
|
const htlcParams = {
|
|
1942
2282
|
paymentHash: input.paymentHash,
|
|
1943
|
-
claimKey: (0,
|
|
2283
|
+
claimKey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(claimPubkey), "solver L1 claim key"),
|
|
1944
2284
|
refundKey: input.refundPubkey,
|
|
1945
2285
|
refundLocktime: htlcLocktime
|
|
1946
2286
|
};
|
|
@@ -1957,21 +2297,23 @@ function deriveOnchainReceive(input) {
|
|
|
1957
2297
|
minConfirmations
|
|
1958
2298
|
};
|
|
1959
2299
|
}
|
|
1960
|
-
var import_base6, import_solver_discovery, import_legacy2,
|
|
2300
|
+
var import_base6, import_solver_discovery, import_legacy2, import_sdk7, import_sdk8, solverHex, quoteSats, quoteAmountSats, quoteExpectedSats, ARKADE_BTC, LIGHTNING_BTC, ONCHAIN_BTC, arkadeAssetLeg, rfqPair, LIGHTNING_SEND_PAIR, LIGHTNING_RECEIVE_PAIR, ONCHAIN_SEND_PAIR, ONCHAIN_RECEIVE_PAIR, RFQ_REFUSAL_ERROR_CODES, isRfqRefusalErrorCode, REFUSAL_FIELDS, REFUSAL_UNITS, safeInteger, safeRefusalDetail, refusalMessage, SwapRefusal, AddressMismatch, newRfqId, lightningSendRequest, arkadeSwapRequest, canonicalAssetAmount, normalizeHexBytes, normalizeMakerPkScript, normalizeMakerPublicKey, MIN_HEADROOM_SECONDS, assertFinite, MAX_PAIR_LENGTH, assertPairLength, verifyLockupAddress, LOCKUP_SHAPE_VARIANTS, matchQuotedLockup, assertFundable, expectQuote, requestVersionedQuote, pairOf, SEQUENCE_GRANULARITY_SECONDS, SOLO_REFUND_HEADROOM_SECONDS, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, seconds, suiteVhtlc, quotedSoloRefundDelay, offerTermsFromQuote, verifyOfferAddress, quoteCarrierSats, l1NetworkFromArk, onchainSendRequest, lightningReceiveRequest, onchainReceiveRequest, MIN_CLAIM_WINDOW_SECONDS, assertReceivable, matchReceiveLockup;
|
|
1961
2301
|
var init_rfq = __esm({
|
|
1962
2302
|
"src/rfq.ts"() {
|
|
1963
2303
|
"use strict";
|
|
1964
2304
|
import_base6 = require("@scure/base");
|
|
1965
2305
|
import_solver_discovery = require("@arkade-os/solver-discovery");
|
|
1966
2306
|
import_legacy2 = require("@noble/hashes/legacy.js");
|
|
1967
|
-
|
|
2307
|
+
import_sdk7 = require("@arkade-os/sdk");
|
|
1968
2308
|
init_onchainHtlc();
|
|
1969
2309
|
init_onchainHtlc();
|
|
1970
|
-
|
|
2310
|
+
import_sdk8 = require("@arkade-os/sdk");
|
|
1971
2311
|
init_claimAmountGate();
|
|
1972
2312
|
init_claimPacket();
|
|
1973
2313
|
init_lockupContract();
|
|
1974
2314
|
init_offer();
|
|
2315
|
+
init_program();
|
|
2316
|
+
init_rfq_contract();
|
|
1975
2317
|
solverHex = (value, field) => {
|
|
1976
2318
|
try {
|
|
1977
2319
|
return import_base6.hex.decode(value);
|
|
@@ -2008,6 +2350,7 @@ var init_rfq = __esm({
|
|
|
2008
2350
|
ONCHAIN_RECEIVE_PAIR = rfqPair(ONCHAIN_BTC, ARKADE_BTC);
|
|
2009
2351
|
RFQ_REFUSAL_ERROR_CODES = [
|
|
2010
2352
|
"amount_side_unsupported",
|
|
2353
|
+
RFQ_CONTRACT_VERSION_UNSUPPORTED,
|
|
2011
2354
|
"exact_out_unsupported",
|
|
2012
2355
|
"invalid_amount",
|
|
2013
2356
|
"invalid_payout_address",
|
|
@@ -2123,6 +2466,7 @@ var init_rfq = __esm({
|
|
|
2123
2466
|
pair,
|
|
2124
2467
|
amount_side: input.amountSide ?? "from",
|
|
2125
2468
|
amount: canonicalAssetAmount(input.amount),
|
|
2469
|
+
...input.contractVersions && input.contractVersions.length > 0 ? { [RFQ_CONTRACT_VERSIONS_KEY]: [...input.contractVersions] } : {},
|
|
2126
2470
|
// The solver's `.strict()` schema refuses any undeclared key as `unsupported_payload`.
|
|
2127
2471
|
profile: {
|
|
2128
2472
|
maker_pk_script: normalizeMakerPkScript(input.makerPkScript),
|
|
@@ -2310,6 +2654,34 @@ var init_rfq = __esm({
|
|
|
2310
2654
|
}
|
|
2311
2655
|
return payload;
|
|
2312
2656
|
};
|
|
2657
|
+
requestVersionedQuote = async (transport, request, advertised) => {
|
|
2658
|
+
if (advertised.length === 0) {
|
|
2659
|
+
throw new Error("contractVersions is empty: advertise at least one contract version");
|
|
2660
|
+
}
|
|
2661
|
+
let sent = request;
|
|
2662
|
+
let quote;
|
|
2663
|
+
try {
|
|
2664
|
+
quote = await transport.requestQuote(request);
|
|
2665
|
+
} catch (error) {
|
|
2666
|
+
if (!(error instanceof SwapRefusal) || error.reason !== "unsupported_payload" || error.errorCode !== void 0 || !advertised.includes(ASSET_SWAP_BASELINE)) {
|
|
2667
|
+
throw error;
|
|
2668
|
+
}
|
|
2669
|
+
const { [RFQ_CONTRACT_VERSIONS_KEY]: _, ...baseline } = request;
|
|
2670
|
+
sent = { ...baseline, rfq_id: newRfqId() };
|
|
2671
|
+
quote = await transport.requestQuote(sent);
|
|
2672
|
+
}
|
|
2673
|
+
const selected = quote[RFQ_CONTRACT_VERSION_KEY];
|
|
2674
|
+
if (sent !== request && selected !== void 0) {
|
|
2675
|
+
throw new Error(`solver chose contract version ${selected}, but none was advertised`);
|
|
2676
|
+
}
|
|
2677
|
+
const version = selected ?? ASSET_SWAP_BASELINE;
|
|
2678
|
+
if (!advertised.includes(version)) {
|
|
2679
|
+
throw new Error(
|
|
2680
|
+
`solver chose contract version ${version}, not one of ${advertised.join(", ")}`
|
|
2681
|
+
);
|
|
2682
|
+
}
|
|
2683
|
+
return { quote, rfqId: sent.rfq_id, contractVersion: assetSwapContractVersion(version) };
|
|
2684
|
+
};
|
|
2313
2685
|
pairOf = (payload) => typeof payload.pair === "string" ? payload.pair : void 0;
|
|
2314
2686
|
SEQUENCE_GRANULARITY_SECONDS = 512;
|
|
2315
2687
|
SOLO_REFUND_HEADROOM_SECONDS = 8 * SEQUENCE_GRANULARITY_SECONDS;
|
|
@@ -2332,7 +2704,7 @@ var init_rfq = __esm({
|
|
|
2332
2704
|
type: "seconds",
|
|
2333
2705
|
value: BigInt(value)
|
|
2334
2706
|
});
|
|
2335
|
-
suiteVhtlc = (params, roles) => new
|
|
2707
|
+
suiteVhtlc = (params, roles) => new import_sdk7.VHTLC.ScriptV2({
|
|
2336
2708
|
sender: roles.sender,
|
|
2337
2709
|
receiver: roles.receiver,
|
|
2338
2710
|
server: params.operatorPubkey,
|
|
@@ -2442,6 +2814,9 @@ var init_rfq = __esm({
|
|
|
2442
2814
|
if (input.now >= input.payDeadline) {
|
|
2443
2815
|
throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
|
|
2444
2816
|
}
|
|
2817
|
+
if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
|
|
2818
|
+
throw gateError("non_positive_amount", "quote carries a non-positive amount");
|
|
2819
|
+
}
|
|
2445
2820
|
if (input.quote.refund_locktime === void 0) {
|
|
2446
2821
|
throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
|
|
2447
2822
|
}
|
|
@@ -2461,7 +2836,7 @@ var init_rfq = __esm({
|
|
|
2461
2836
|
};
|
|
2462
2837
|
matchReceiveLockup = (input, refundLocktime, solverRefundPkScriptHex) => {
|
|
2463
2838
|
const contractParams = {
|
|
2464
|
-
solverPubkey: (0,
|
|
2839
|
+
solverPubkey: (0, import_sdk7.toXOnly)(import_base6.hex.decode(input.quote.solver_pubkey), "solver key"),
|
|
2465
2840
|
refundLocktime,
|
|
2466
2841
|
operatorPubkey: input.operatorPubkey,
|
|
2467
2842
|
paymentHash: input.paymentHash,
|
|
@@ -2469,7 +2844,7 @@ var init_rfq = __esm({
|
|
|
2469
2844
|
emulatorPubkey: input.emulatorPubkey,
|
|
2470
2845
|
solverRefundPkScript: solverHex(solverRefundPkScriptHex, "profile.solver_refund_pk_script"),
|
|
2471
2846
|
payoutPubkey: input.payoutPubkey,
|
|
2472
|
-
payoutPkScript:
|
|
2847
|
+
payoutPkScript: import_sdk7.ArkAddress.decode(input.payoutAddress).pkScript
|
|
2473
2848
|
};
|
|
2474
2849
|
const matched = matchQuotedLockup(
|
|
2475
2850
|
input.quote,
|
|
@@ -2631,14 +3006,14 @@ __export(nostr_exports, {
|
|
|
2631
3006
|
nostrRfqTransport: () => nostrRfqTransport,
|
|
2632
3007
|
sharedNostrPool: () => sharedNostrPool
|
|
2633
3008
|
});
|
|
2634
|
-
var import_solver_discovery2,
|
|
3009
|
+
var import_solver_discovery2, import_sdk16, import_nostr_tools2, RFQ_DIRECTED_KIND, DEFAULT_TIMEOUT_MS, CONNECTION_FAILURE, CARD_FETCH_TIMEOUT_MS, RelayUnavailable, TransportClosed, closeReasons, nostrRfqTransport, isNewer, nostrCardFetcher;
|
|
2635
3010
|
var init_nostr = __esm({
|
|
2636
3011
|
"src/nostr.ts"() {
|
|
2637
3012
|
"use strict";
|
|
2638
3013
|
import_solver_discovery2 = require("@arkade-os/solver-discovery");
|
|
2639
3014
|
init_rfq();
|
|
2640
3015
|
init_nostrPool();
|
|
2641
|
-
|
|
3016
|
+
import_sdk16 = require("@arkade-os/sdk");
|
|
2642
3017
|
import_nostr_tools2 = require("nostr-tools");
|
|
2643
3018
|
init_nostrPool();
|
|
2644
3019
|
RFQ_DIRECTED_KIND = 24859;
|
|
@@ -2665,7 +3040,7 @@ var init_nostr = __esm({
|
|
|
2665
3040
|
return url ? `${url}: ${reason ?? "closed"}` : reason ?? "closed";
|
|
2666
3041
|
});
|
|
2667
3042
|
nostrRfqTransport = (options) => {
|
|
2668
|
-
(0,
|
|
3043
|
+
(0, import_sdk16.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
2669
3044
|
const relays = options.relays;
|
|
2670
3045
|
const solverPubkey = options.solverPubkey;
|
|
2671
3046
|
const secretKey = options.secretKey ?? (0, import_nostr_tools2.generateSecretKey)();
|
|
@@ -2777,7 +3152,7 @@ var init_nostr = __esm({
|
|
|
2777
3152
|
};
|
|
2778
3153
|
isNewer = (event, held) => !held || event.created_at > held.created_at || event.created_at === held.created_at && event.id < held.id;
|
|
2779
3154
|
nostrCardFetcher = (options = {}) => {
|
|
2780
|
-
(0,
|
|
3155
|
+
(0, import_sdk16.assertTimerMs)("timeoutMs", options.timeoutMs);
|
|
2781
3156
|
if (options.timeoutMs === 0) throw new Error("timeoutMs must be positive");
|
|
2782
3157
|
const seen = /* @__PURE__ */ new Map();
|
|
2783
3158
|
const inflight = /* @__PURE__ */ new Map();
|
|
@@ -2947,13 +3322,13 @@ module.exports = __toCommonJS(index_exports);
|
|
|
2947
3322
|
|
|
2948
3323
|
// src/client/client.ts
|
|
2949
3324
|
var import_base23 = require("@scure/base");
|
|
2950
|
-
var
|
|
3325
|
+
var import_sdk38 = require("@arkade-os/sdk");
|
|
2951
3326
|
init_repository();
|
|
2952
3327
|
|
|
2953
3328
|
// src/refund.ts
|
|
2954
3329
|
var import_base7 = require("@scure/base");
|
|
2955
3330
|
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
2956
|
-
var
|
|
3331
|
+
var import_sdk9 = require("@arkade-os/sdk");
|
|
2957
3332
|
init_onchainHtlc();
|
|
2958
3333
|
init_rfq();
|
|
2959
3334
|
var walletOperator = (wallet) => {
|
|
@@ -2991,7 +3366,7 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
2991
3366
|
const out = [];
|
|
2992
3367
|
for (const vtxo of row?.vtxos ?? []) {
|
|
2993
3368
|
if (vtxo.isUnrolled) continue;
|
|
2994
|
-
if ((0,
|
|
3369
|
+
if ((0, import_sdk9.isVtxoSpent)(vtxo)) continue;
|
|
2995
3370
|
const key = `${vtxo.txid}:${vtxo.vout}`;
|
|
2996
3371
|
if (seen.has(key)) continue;
|
|
2997
3372
|
seen.add(key);
|
|
@@ -3007,17 +3382,17 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
3007
3382
|
}
|
|
3008
3383
|
var hashesTo = (candidate, paymentHash) => import_base7.hex.encode((0, import_sha24.sha256)(candidate)) === paymentHash;
|
|
3009
3384
|
var candidateWitnessItems = (tx, inputIndex) => [
|
|
3010
|
-
...(0,
|
|
3385
|
+
...(0, import_sdk9.getArkPsbtFields)(tx, inputIndex, import_sdk9.ConditionWitness).flat(),
|
|
3011
3386
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
3012
3387
|
];
|
|
3013
3388
|
var refundLeafScript = (tx, inputIndex) => {
|
|
3014
3389
|
const input = tx.getInput(inputIndex);
|
|
3015
3390
|
const witness = input.finalScriptWitness;
|
|
3016
3391
|
const leaves = input.tapLeafScript ?? [];
|
|
3017
|
-
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0,
|
|
3392
|
+
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? (0, import_sdk9.scriptFromTapLeafScript)(leaves[0]) : void 0;
|
|
3018
3393
|
if (!script) return void 0;
|
|
3019
3394
|
try {
|
|
3020
|
-
const { type } = (0,
|
|
3395
|
+
const { type } = (0, import_sdk9.decodeTapscript)(script);
|
|
3021
3396
|
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
|
|
3022
3397
|
} catch {
|
|
3023
3398
|
return void 0;
|
|
@@ -3027,7 +3402,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3027
3402
|
const { vtxos } = await indexer.getVtxos({ scripts: [import_base7.hex.encode(input.swapPkScript)] });
|
|
3028
3403
|
const all = vtxos ?? [];
|
|
3029
3404
|
if (all.length === 0) return { fate: "unknown" };
|
|
3030
|
-
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0,
|
|
3405
|
+
const exited = all.filter((vtxo) => vtxo.isUnrolled && !(0, import_sdk9.isVtxoSpent)(vtxo));
|
|
3031
3406
|
if (exited.length > 0) {
|
|
3032
3407
|
return {
|
|
3033
3408
|
fate: "exited",
|
|
@@ -3039,7 +3414,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3039
3414
|
let sweptLeft = false;
|
|
3040
3415
|
let live = false;
|
|
3041
3416
|
for (const vtxo of all) {
|
|
3042
|
-
if (!(0,
|
|
3417
|
+
if (!(0, import_sdk9.isVtxoSpent)(vtxo)) {
|
|
3043
3418
|
if (input.receiver && vtxo.isSwept) sweptLeft = true;
|
|
3044
3419
|
else live = true;
|
|
3045
3420
|
continue;
|
|
@@ -3066,7 +3441,7 @@ async function readLockupFate(indexer, input) {
|
|
|
3066
3441
|
for (const raw of txs) {
|
|
3067
3442
|
let tx;
|
|
3068
3443
|
try {
|
|
3069
|
-
tx =
|
|
3444
|
+
tx = import_sdk9.Transaction.fromPSBT(import_base7.base64.decode(raw));
|
|
3070
3445
|
} catch {
|
|
3071
3446
|
continue;
|
|
3072
3447
|
}
|
|
@@ -3116,10 +3491,10 @@ var assertNoneSwept = (vtxos, contract) => {
|
|
|
3116
3491
|
};
|
|
3117
3492
|
var operatorUnrollScript = async (operator, network) => {
|
|
3118
3493
|
const info = await operator.getInfo();
|
|
3119
|
-
return (0,
|
|
3494
|
+
return (0, import_sdk9.assertValidServerUnrollScript)(
|
|
3120
3495
|
info.checkpointTapscript,
|
|
3121
|
-
network ?? (0,
|
|
3122
|
-
(0,
|
|
3496
|
+
network ?? (0, import_sdk9.networkFromOperatorInfo)(info),
|
|
3497
|
+
(0, import_sdk9.toXOnly)(import_base7.hex.decode(info.forfeitPubkey), "forfeit key")
|
|
3123
3498
|
);
|
|
3124
3499
|
};
|
|
3125
3500
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
@@ -3139,7 +3514,7 @@ var lockupAssetOutputs = (vtxos) => {
|
|
|
3139
3514
|
address: "",
|
|
3140
3515
|
assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
|
|
3141
3516
|
};
|
|
3142
|
-
return [
|
|
3517
|
+
return [import_sdk9.Extension.create([(0, import_sdk9.createAssetPacket)(inputs, [receiver])]).txOut()];
|
|
3143
3518
|
};
|
|
3144
3519
|
var lockupInputs = (vtxos, contract, leaf) => {
|
|
3145
3520
|
const tapTree = contract.encode();
|
|
@@ -3164,7 +3539,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
3164
3539
|
const leaf = input.contract.refundWithoutReceiver();
|
|
3165
3540
|
const vtxos = boundedLockupSpend(input.vtxos);
|
|
3166
3541
|
const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
3167
|
-
const txid = await (0,
|
|
3542
|
+
const txid = await (0, import_sdk9.signAndSubmitOffchainTx)({
|
|
3168
3543
|
identity: input.sender,
|
|
3169
3544
|
provider: operator,
|
|
3170
3545
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
@@ -3182,7 +3557,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
3182
3557
|
var REFUND_MTP_LAG_SECONDS = 2 * 60 * 60;
|
|
3183
3558
|
|
|
3184
3559
|
// src/client/corridors/registry.ts
|
|
3185
|
-
var
|
|
3560
|
+
var import_sdk15 = require("@arkade-os/sdk");
|
|
3186
3561
|
|
|
3187
3562
|
// src/client/corridor.ts
|
|
3188
3563
|
var CORRIDORS = ["arkade", "lightning", "onchain"];
|
|
@@ -3379,7 +3754,7 @@ function isSwapError(e, name) {
|
|
|
3379
3754
|
}
|
|
3380
3755
|
|
|
3381
3756
|
// src/client/corridors/arkade.ts
|
|
3382
|
-
var
|
|
3757
|
+
var import_sdk10 = require("@arkade-os/sdk");
|
|
3383
3758
|
var ARKADE_DRIVE = {};
|
|
3384
3759
|
var messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
3385
3760
|
var arkadeCorridor = Object.assign(
|
|
@@ -3388,11 +3763,11 @@ var arkadeCorridor = Object.assign(
|
|
|
3388
3763
|
deps,
|
|
3389
3764
|
drive: ARKADE_DRIVE,
|
|
3390
3765
|
matches(raw) {
|
|
3391
|
-
const target = (0,
|
|
3766
|
+
const target = (0, import_sdk10.arkTarget)(raw);
|
|
3392
3767
|
if (target === void 0) return void 0;
|
|
3393
3768
|
try {
|
|
3394
|
-
const address =
|
|
3395
|
-
(0,
|
|
3769
|
+
const address = import_sdk10.ArkAddress.decode(target);
|
|
3770
|
+
(0, import_sdk10.assertRecipientArkadeAddress)(target, address, {
|
|
3396
3771
|
hrp: deps.network.hrp,
|
|
3397
3772
|
signerSet: deps.signerSet
|
|
3398
3773
|
});
|
|
@@ -3402,11 +3777,11 @@ var arkadeCorridor = Object.assign(
|
|
|
3402
3777
|
return { claimed: { kind: "address", address: target } };
|
|
3403
3778
|
}
|
|
3404
3779
|
}),
|
|
3405
|
-
{ target:
|
|
3780
|
+
{ target: import_sdk10.arkTarget }
|
|
3406
3781
|
);
|
|
3407
3782
|
|
|
3408
3783
|
// src/client/corridors/deps.ts
|
|
3409
|
-
var
|
|
3784
|
+
var import_sdk13 = require("@arkade-os/sdk");
|
|
3410
3785
|
|
|
3411
3786
|
// src/chainSource.ts
|
|
3412
3787
|
var btc2 = __toESM(require("@scure/btc-signer"), 1);
|
|
@@ -3465,7 +3840,7 @@ init_rfq();
|
|
|
3465
3840
|
var import_light_bolt11_decoder = __toESM(require("light-bolt11-decoder"), 1);
|
|
3466
3841
|
|
|
3467
3842
|
// src/client/corridors/lightning.ts
|
|
3468
|
-
var
|
|
3843
|
+
var import_sdk11 = require("@arkade-os/sdk");
|
|
3469
3844
|
var INVOICE_HRPS = [
|
|
3470
3845
|
["lnbcrt", ["regtest"]],
|
|
3471
3846
|
["lntbs", ["signet", "mutinynet"]],
|
|
@@ -3495,7 +3870,7 @@ var lightningCorridor = Object.assign(
|
|
|
3495
3870
|
deps,
|
|
3496
3871
|
drive: LIGHTNING_DRIVE,
|
|
3497
3872
|
matches(raw) {
|
|
3498
|
-
const invoice = (0,
|
|
3873
|
+
const invoice = (0, import_sdk11.invoiceTarget)(raw);
|
|
3499
3874
|
if (invoice === void 0) return void 0;
|
|
3500
3875
|
const networks2 = networksOfInvoiceHrp(invoice);
|
|
3501
3876
|
if (networks2 === void 0) {
|
|
@@ -3541,7 +3916,7 @@ var lightningCorridor = Object.assign(
|
|
|
3541
3916
|
};
|
|
3542
3917
|
}
|
|
3543
3918
|
}),
|
|
3544
|
-
{ target:
|
|
3919
|
+
{ target: import_sdk11.invoiceTarget }
|
|
3545
3920
|
);
|
|
3546
3921
|
|
|
3547
3922
|
// src/client/corridors/bolt11.ts
|
|
@@ -3572,7 +3947,7 @@ var decodeBolt11 = (invoice) => {
|
|
|
3572
3947
|
// src/client/corridors/chainSource.ts
|
|
3573
3948
|
var import_base9 = require("@scure/base");
|
|
3574
3949
|
var btc3 = __toESM(require("@scure/btc-signer"), 1);
|
|
3575
|
-
var
|
|
3950
|
+
var import_sdk12 = require("@arkade-os/sdk");
|
|
3576
3951
|
var addressOfScript = (script, network) => btc3.Address(network).encode(btc3.OutScript.decode(script));
|
|
3577
3952
|
var chainSourceOver = (backend, network) => {
|
|
3578
3953
|
const spenderFromVins = async (txid, vout, pkScript) => {
|
|
@@ -3639,7 +4014,7 @@ var esploraTip = async (esploraUrl, fetchImpl) => {
|
|
|
3639
4014
|
};
|
|
3640
4015
|
var esploraChainSource = (input) => chainSourceOver(
|
|
3641
4016
|
{
|
|
3642
|
-
provider: new
|
|
4017
|
+
provider: new import_sdk12.EsploraProvider(input.esploraUrl),
|
|
3643
4018
|
tip: () => esploraTip(input.esploraUrl, input.fetchImpl)
|
|
3644
4019
|
},
|
|
3645
4020
|
input.network
|
|
@@ -3665,10 +4040,10 @@ var refusedIfMalformed = (value, dep) => {
|
|
|
3665
4040
|
};
|
|
3666
4041
|
var emulatorPubkeyFor = (base) => {
|
|
3667
4042
|
if (base.emulatorPubkey !== void 0) {
|
|
3668
|
-
return (0,
|
|
4043
|
+
return (0, import_sdk13.resolveEmulatorPubkey)(base.network, base.emulatorPubkey);
|
|
3669
4044
|
}
|
|
3670
4045
|
try {
|
|
3671
|
-
return (0,
|
|
4046
|
+
return (0, import_sdk13.defaultEmulatorPubkey)(base.network);
|
|
3672
4047
|
} catch {
|
|
3673
4048
|
throw new MissingCorridorDep(
|
|
3674
4049
|
"arkade",
|
|
@@ -3719,7 +4094,7 @@ function resolveCorridorDeps(corridor, overrides, base) {
|
|
|
3719
4094
|
return {
|
|
3720
4095
|
networkName: base.networkName,
|
|
3721
4096
|
chain: chain && "provider" in chain ? chainSourceFrom(chain.provider, l1Network) : esploraChainSource({
|
|
3722
|
-
esploraUrl: chain?.esploraUrl ??
|
|
4097
|
+
esploraUrl: chain?.esploraUrl ?? import_sdk13.ESPLORA_URL[base.networkName],
|
|
3723
4098
|
network: L1_NETWORKS[l1Network],
|
|
3724
4099
|
fetchImpl: base.fetchImpl
|
|
3725
4100
|
}),
|
|
@@ -3749,8 +4124,8 @@ var resolveCorridorBase = async (input) => {
|
|
|
3749
4124
|
wallet: input.wallet,
|
|
3750
4125
|
operator: input.operator,
|
|
3751
4126
|
networkName,
|
|
3752
|
-
network: (0,
|
|
3753
|
-
signerSet: (0,
|
|
4127
|
+
network: (0, import_sdk13.getNetwork)(networkName),
|
|
4128
|
+
signerSet: (0, import_sdk13.signerSetFromInfo)(info),
|
|
3754
4129
|
emulatorPubkey: input.emulatorPubkey,
|
|
3755
4130
|
fetchImpl: input.fetchImpl,
|
|
3756
4131
|
repository: input.repository
|
|
@@ -3758,7 +4133,7 @@ var resolveCorridorBase = async (input) => {
|
|
|
3758
4133
|
};
|
|
3759
4134
|
|
|
3760
4135
|
// src/client/corridors/onchain.ts
|
|
3761
|
-
var
|
|
4136
|
+
var import_sdk14 = require("@arkade-os/sdk");
|
|
3762
4137
|
var btc4 = __toESM(require("@scure/btc-signer"), 1);
|
|
3763
4138
|
init_onchainHtlc();
|
|
3764
4139
|
init_rfq();
|
|
@@ -3788,14 +4163,14 @@ var onchainCorridor = Object.assign(
|
|
|
3788
4163
|
deps,
|
|
3789
4164
|
drive: ONCHAIN_DRIVE,
|
|
3790
4165
|
matches(raw) {
|
|
3791
|
-
const target = (0,
|
|
4166
|
+
const target = (0, import_sdk14.btcTarget)(raw);
|
|
3792
4167
|
if (target === void 0) return void 0;
|
|
3793
4168
|
try {
|
|
3794
4169
|
btc4.Address(L1_NETWORKS[l1]).decode(target);
|
|
3795
4170
|
} catch {
|
|
3796
4171
|
return { refused: `this is not a ${l1} address` };
|
|
3797
4172
|
}
|
|
3798
|
-
const amount =
|
|
4173
|
+
const amount = import_sdk14.BIP21.amountSats(raw);
|
|
3799
4174
|
return {
|
|
3800
4175
|
claimed: {
|
|
3801
4176
|
kind: "address",
|
|
@@ -3806,7 +4181,7 @@ var onchainCorridor = Object.assign(
|
|
|
3806
4181
|
}
|
|
3807
4182
|
};
|
|
3808
4183
|
},
|
|
3809
|
-
{ target:
|
|
4184
|
+
{ target: import_sdk14.btcTarget }
|
|
3810
4185
|
);
|
|
3811
4186
|
|
|
3812
4187
|
// src/client/corridors/registry.ts
|
|
@@ -3832,7 +4207,7 @@ var corridorSet = (base, overrides) => {
|
|
|
3832
4207
|
(corridor) => CORRIDOR_FACTORIES[corridor].target(raw) !== void 0
|
|
3833
4208
|
);
|
|
3834
4209
|
if (owners.length === 0) {
|
|
3835
|
-
if ((0,
|
|
4210
|
+
if ((0, import_sdk15.isLnurl)(raw)) return void 0;
|
|
3836
4211
|
throw new AmbiguousDestination(raw, "no corridor recognises this destination");
|
|
3837
4212
|
}
|
|
3838
4213
|
const claims = [];
|
|
@@ -3860,7 +4235,7 @@ var import_solver_discovery5 = require("@arkade-os/solver-discovery");
|
|
|
3860
4235
|
|
|
3861
4236
|
// src/markets.ts
|
|
3862
4237
|
var import_solver_discovery3 = require("@arkade-os/solver-discovery");
|
|
3863
|
-
var
|
|
4238
|
+
var import_sdk17 = require("@arkade-os/sdk");
|
|
3864
4239
|
|
|
3865
4240
|
// src/marketShape.ts
|
|
3866
4241
|
var MARKET_CORRIDORS = ["arkade", "bolt11", "bitcoin", "eip155"];
|
|
@@ -3902,7 +4277,7 @@ var marketPairLabel = (market) => `${sideLabel(market, "base")}/${sideLabel(mark
|
|
|
3902
4277
|
init_store();
|
|
3903
4278
|
var QUOTE_OPTIONS = { safetyBps: 0 };
|
|
3904
4279
|
var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
|
|
3905
|
-
(0,
|
|
4280
|
+
(0, import_sdk17.assertNonNegativeMs)("ttlMs", ttlMs);
|
|
3906
4281
|
const cache = /* @__PURE__ */ new Map();
|
|
3907
4282
|
const inflight = /* @__PURE__ */ new Map();
|
|
3908
4283
|
return async (input, init) => {
|
|
@@ -4013,7 +4388,7 @@ var import_solver_discovery4 = require("@arkade-os/solver-discovery");
|
|
|
4013
4388
|
init_store();
|
|
4014
4389
|
|
|
4015
4390
|
// src/client/assetId.ts
|
|
4016
|
-
var
|
|
4391
|
+
var import_sdk18 = require("@arkade-os/sdk");
|
|
4017
4392
|
var RAILS = ["arkade", "bitcoin", "bolt11", "eip155"];
|
|
4018
4393
|
var BITCOIN_RAILS = ["arkade", "bitcoin", "bolt11"];
|
|
4019
4394
|
var BTC_ASSET_PART = "slip44:0";
|
|
@@ -4042,7 +4417,7 @@ var CHAIN_REFERENCE = /^[-_a-z0-9]{1,32}$/;
|
|
|
4042
4417
|
var CHAIN_ID = /^(0|[1-9][0-9]*)$/;
|
|
4043
4418
|
var ASSET_REFERENCE = /^[-.%a-z0-9]{1,128}$/;
|
|
4044
4419
|
var isRail = (value) => RAILS.includes(value);
|
|
4045
|
-
var isNetworkRef = (value) => Object.hasOwn(
|
|
4420
|
+
var isNetworkRef = (value) => Object.hasOwn(import_sdk18.networks, value);
|
|
4046
4421
|
var parseAssetId = (value) => {
|
|
4047
4422
|
if (/[A-Z]/.test(value)) {
|
|
4048
4423
|
throw new AssetIdError(
|
|
@@ -4107,7 +4482,7 @@ var parseAssetId = (value) => {
|
|
|
4107
4482
|
}
|
|
4108
4483
|
if (namespace === ARKADE_ASSET_NAMESPACE) {
|
|
4109
4484
|
try {
|
|
4110
|
-
|
|
4485
|
+
import_sdk18.asset.AssetId.fromString(assetReference);
|
|
4111
4486
|
} catch (cause) {
|
|
4112
4487
|
throw new AssetIdError(
|
|
4113
4488
|
"invalid_asset_reference",
|
|
@@ -4163,7 +4538,7 @@ var isBtcAssetLenient = (id) => {
|
|
|
4163
4538
|
var arkadeAsset = (network, id) => `arkade:${network}/${ARKADE_ASSET_NAMESPACE}:${id.toString()}`;
|
|
4164
4539
|
var issuanceOf = (id) => {
|
|
4165
4540
|
const { assetNamespace, assetReference } = parseAssetId(id);
|
|
4166
|
-
return assetNamespace === ARKADE_ASSET_NAMESPACE ?
|
|
4541
|
+
return assetNamespace === ARKADE_ASSET_NAMESPACE ? import_sdk18.asset.AssetId.fromString(assetReference) : void 0;
|
|
4167
4542
|
};
|
|
4168
4543
|
|
|
4169
4544
|
// src/client/aliases.ts
|
|
@@ -4378,7 +4753,7 @@ var discoveryIndex = (input) => {
|
|
|
4378
4753
|
// src/client/accept.ts
|
|
4379
4754
|
var import_base12 = require("@scure/base");
|
|
4380
4755
|
var import_solver_discovery9 = require("@arkade-os/solver-discovery");
|
|
4381
|
-
var
|
|
4756
|
+
var import_sdk21 = require("@arkade-os/sdk");
|
|
4382
4757
|
init_offer();
|
|
4383
4758
|
init_coverage();
|
|
4384
4759
|
init_lockupContract();
|
|
@@ -4579,7 +4954,7 @@ init_rfqProfileParts();
|
|
|
4579
4954
|
init_store();
|
|
4580
4955
|
|
|
4581
4956
|
// src/client/assetPayment.ts
|
|
4582
|
-
var
|
|
4957
|
+
var import_sdk19 = require("@arkade-os/sdk");
|
|
4583
4958
|
var import_solver_discovery6 = require("@arkade-os/solver-discovery");
|
|
4584
4959
|
var DECIMAL = /^(0|[1-9][0-9]*)$/;
|
|
4585
4960
|
var MAX_SATS = 2100000000000000n;
|
|
@@ -4630,7 +5005,7 @@ function validateReceiverPaidQuoteShape(q) {
|
|
|
4630
5005
|
throw new Error("carrier receiver-paid quote needs an assetId");
|
|
4631
5006
|
}
|
|
4632
5007
|
try {
|
|
4633
|
-
|
|
5008
|
+
import_sdk19.asset.AssetId.fromString(q.assetId);
|
|
4634
5009
|
} catch {
|
|
4635
5010
|
throw new Error("carrier receiver-paid quote assetId is not a valid SDK asset id");
|
|
4636
5011
|
}
|
|
@@ -4869,7 +5244,7 @@ var assetPaymentOf = (stored, quoteExpiry) => {
|
|
|
4869
5244
|
};
|
|
4870
5245
|
|
|
4871
5246
|
// src/client/fundingNotSubmitted.ts
|
|
4872
|
-
var
|
|
5247
|
+
var import_sdk20 = require("@arkade-os/sdk");
|
|
4873
5248
|
var import_base11 = require("@scure/base");
|
|
4874
5249
|
init_coverage();
|
|
4875
5250
|
init_repository();
|
|
@@ -5087,7 +5462,7 @@ var retireUnsubmittedFunding = async (wallet, repository, record, contracts) =>
|
|
|
5087
5462
|
status: row.family === "offer" ? row.status : fundingWasNotSubmitted(row) ? "cancelled" : row.state === "settled" || row.state === "refunded" ? "fulfilled" : "pending"
|
|
5088
5463
|
}));
|
|
5089
5464
|
const legacy = (await collectRfqSwaps(repository)).map((row) => ({
|
|
5090
|
-
swapPkScript: import_base11.hex.encode(
|
|
5465
|
+
swapPkScript: import_base11.hex.encode(import_sdk20.ArkAddress.decode(row.lockupAddress).pkScript),
|
|
5091
5466
|
createdAt: row.createdAt * 1e3,
|
|
5092
5467
|
status: row.state === "settled" || row.state === "refunded" ? "fulfilled" : "pending"
|
|
5093
5468
|
}));
|
|
@@ -5433,15 +5808,15 @@ var acceptQuoteBody = async (input) => {
|
|
|
5433
5808
|
var registeredOfferRecord = async (input, preparation) => {
|
|
5434
5809
|
const { quote, wallet, corridors, now } = input;
|
|
5435
5810
|
const { plan } = preparation;
|
|
5436
|
-
const
|
|
5811
|
+
const arkade4 = corridors.get("arkade").deps;
|
|
5437
5812
|
const receiveIsBtc = plan.receive.asset.id === BTC_ASSET_ID;
|
|
5438
5813
|
const offer = await createOffer(
|
|
5439
5814
|
wallet,
|
|
5440
5815
|
{
|
|
5441
5816
|
// Keyed on the receive side: the covenant binds what the fill delivers.
|
|
5442
5817
|
wantAmount: plan.receive.atomic,
|
|
5443
|
-
...receiveIsBtc ? { offerAsset:
|
|
5444
|
-
emulatorPubkey:
|
|
5818
|
+
...receiveIsBtc ? { offerAsset: import_sdk21.asset.AssetId.fromString(plan.deposit.asset.id) } : { wantAsset: import_sdk21.asset.AssetId.fromString(plan.receive.asset.id) },
|
|
5819
|
+
emulatorPubkey: arkade4.emulatorPubkey
|
|
5445
5820
|
},
|
|
5446
5821
|
{ coverageId: quote.id }
|
|
5447
5822
|
);
|
|
@@ -5504,7 +5879,7 @@ var fundAndStamp = async (input, record, repository) => {
|
|
|
5504
5879
|
const txid = await fund({ ...input, ...bounds, validUntil }, record);
|
|
5505
5880
|
return stampFunding(repository, record, txid, input.now);
|
|
5506
5881
|
} catch (error) {
|
|
5507
|
-
if (input.firstFundingAttempt && validUntil !== void 0 && error instanceof
|
|
5882
|
+
if (input.firstFundingAttempt && validUntil !== void 0 && error instanceof import_sdk21.SendDeadlineExceededError) {
|
|
5508
5883
|
const stopped = {
|
|
5509
5884
|
...record,
|
|
5510
5885
|
...record.family === "offer" ? { status: "cancelled" } : { state: "failed" },
|
|
@@ -5573,7 +5948,7 @@ var reconcileFunding = async (input, record) => {
|
|
|
5573
5948
|
const script = record.family === "offer" ? record.swapPkScript : record.lockupPkScript;
|
|
5574
5949
|
const expected = BigInt(record.give.amount);
|
|
5575
5950
|
const reader = await input.wallet.getArkadeReader();
|
|
5576
|
-
const vtxos = await (0,
|
|
5951
|
+
const vtxos = await (0, import_sdk21.getAllNormalizedVtxos)(reader, [script]);
|
|
5577
5952
|
const deposit = vtxos.find((vtxo) => depositMatches(vtxo, record, expected));
|
|
5578
5953
|
return deposit?.txid;
|
|
5579
5954
|
};
|
|
@@ -5589,13 +5964,13 @@ var depositMatches = (vtxo, record, expected) => {
|
|
|
5589
5964
|
|
|
5590
5965
|
// src/client/cancel.ts
|
|
5591
5966
|
var import_base16 = require("@scure/base");
|
|
5592
|
-
var
|
|
5967
|
+
var import_sdk25 = require("@arkade-os/sdk");
|
|
5593
5968
|
init_coverage();
|
|
5594
5969
|
init_offer();
|
|
5595
5970
|
|
|
5596
5971
|
// src/restore.ts
|
|
5597
5972
|
var import_base13 = require("@scure/base");
|
|
5598
|
-
var
|
|
5973
|
+
var import_sdk22 = require("@arkade-os/sdk");
|
|
5599
5974
|
init_offer();
|
|
5600
5975
|
init_store();
|
|
5601
5976
|
var TXS_PER_REQUEST = 50;
|
|
@@ -5620,7 +5995,7 @@ async function fetchParsedTxs(indexer, txids) {
|
|
|
5620
5995
|
if (result.status !== "fulfilled") continue;
|
|
5621
5996
|
for (const psbt of result.value) {
|
|
5622
5997
|
try {
|
|
5623
|
-
const parsed =
|
|
5998
|
+
const parsed = import_sdk22.Transaction.fromPSBT(import_base13.base64.decode(psbt));
|
|
5624
5999
|
parsedByTxid.set(parsed.id, parsed);
|
|
5625
6000
|
} catch {
|
|
5626
6001
|
}
|
|
@@ -5649,7 +6024,7 @@ function classifySpend(offer, operatorPubkey, spendTx, deposit) {
|
|
|
5649
6024
|
if (!input.txid || input.index !== deposit.vout) continue;
|
|
5650
6025
|
if (import_base13.hex.encode(input.txid) !== deposit.txid) continue;
|
|
5651
6026
|
for (const leaf of input.tapLeafScript ?? []) {
|
|
5652
|
-
const spent = import_base13.hex.encode((0,
|
|
6027
|
+
const spent = import_base13.hex.encode((0, import_sdk22.scriptFromTapLeafScript)(leaf));
|
|
5653
6028
|
if (leaves.returned.some((back) => spent === import_base13.hex.encode(back))) return "cancelled";
|
|
5654
6029
|
if (leaves.fulfill && spent === import_base13.hex.encode(leaves.fulfill)) return "fulfilled";
|
|
5655
6030
|
}
|
|
@@ -5703,7 +6078,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
5703
6078
|
if (!fundingTx) continue;
|
|
5704
6079
|
fetchedTxids.push(txid);
|
|
5705
6080
|
try {
|
|
5706
|
-
const packet =
|
|
6081
|
+
const packet = import_sdk22.Extension.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
5707
6082
|
if (!packet) continue;
|
|
5708
6083
|
const payload = packet.serialize();
|
|
5709
6084
|
found.push({
|
|
@@ -5820,7 +6195,7 @@ init_repository();
|
|
|
5820
6195
|
init_repository();
|
|
5821
6196
|
|
|
5822
6197
|
// src/rfqRecord.ts
|
|
5823
|
-
var
|
|
6198
|
+
var import_sdk23 = require("@arkade-os/sdk");
|
|
5824
6199
|
var import_base14 = require("@scure/base");
|
|
5825
6200
|
|
|
5826
6201
|
// src/rfqSwapState.ts
|
|
@@ -5878,7 +6253,7 @@ function assertSameSwap(origin, swap) {
|
|
|
5878
6253
|
`rfq swap record is a ${origin.kind} origin paired with a ${swap.kind} swap`
|
|
5879
6254
|
);
|
|
5880
6255
|
}
|
|
5881
|
-
const funded = import_base14.hex.encode(
|
|
6256
|
+
const funded = import_base14.hex.encode(import_sdk23.ArkAddress.decode(origin.lockupAddress).pkScript);
|
|
5882
6257
|
const watched = import_base14.hex.encode(swap.lockupPkScript);
|
|
5883
6258
|
if (funded !== watched) {
|
|
5884
6259
|
throw new Error(
|
|
@@ -5925,8 +6300,8 @@ function rfqSwapOriginOf(record) {
|
|
|
5925
6300
|
};
|
|
5926
6301
|
}
|
|
5927
6302
|
function lockupScript(params, lockupAddress) {
|
|
5928
|
-
const script =
|
|
5929
|
-
const funded =
|
|
6303
|
+
const script = import_sdk23.VHTLCV2ContractHandler.createScript(params);
|
|
6304
|
+
const funded = import_sdk23.ArkAddress.decode(lockupAddress).pkScript;
|
|
5930
6305
|
if (import_base14.hex.encode(funded) !== import_base14.hex.encode(script.pkScript)) {
|
|
5931
6306
|
throw new Error(
|
|
5932
6307
|
`rfq swap covenant params derive ${import_base14.hex.encode(script.pkScript)}, but the record's lockup address holds ${import_base14.hex.encode(funded)} \u2014 these params are not this swap's`
|
|
@@ -5963,7 +6338,7 @@ function shouldRetainRfqSwap(record, now) {
|
|
|
5963
6338
|
|
|
5964
6339
|
// src/client/driveRecords.ts
|
|
5965
6340
|
init_store();
|
|
5966
|
-
var
|
|
6341
|
+
var import_sdk24 = require("@arkade-os/sdk");
|
|
5967
6342
|
var import_sha25 = require("@noble/hashes/sha2.js");
|
|
5968
6343
|
var import_base15 = require("@scure/base");
|
|
5969
6344
|
var splitRecords = (records) => {
|
|
@@ -6018,7 +6393,7 @@ var pageRfqRecords = (records, filter, page) => {
|
|
|
6018
6393
|
).sort(
|
|
6019
6394
|
(a, b) => a.updatedAt - b.updatedAt || (a.rfqId < b.rfqId ? -1 : a.rfqId > b.rfqId ? 1 : 0)
|
|
6020
6395
|
).slice(0, page.limit + 1);
|
|
6021
|
-
return (0,
|
|
6396
|
+
return (0, import_sdk24.pageResult)(rows, page.limit, (record) => ({
|
|
6022
6397
|
updatedAt: record.updatedAt,
|
|
6023
6398
|
rfqId: record.rfqId
|
|
6024
6399
|
}));
|
|
@@ -6044,7 +6419,7 @@ var corridorRecordStore = (repository, onRecord = () => {
|
|
|
6044
6419
|
index,
|
|
6045
6420
|
quoteIdOf: (rfqId) => byRfqId.get(rfqId),
|
|
6046
6421
|
async getRfqSwapsPage(filter, page) {
|
|
6047
|
-
(0,
|
|
6422
|
+
(0, import_sdk24.assertPageRequest)(page);
|
|
6048
6423
|
assertRfqSwapPageFilter(filter);
|
|
6049
6424
|
const { corridor } = splitRecords(await collectSwapRecords(repository));
|
|
6050
6425
|
for (const record of corridor) index(record);
|
|
@@ -6156,7 +6531,7 @@ var restoredOfferRecord = (swap, network, now) => {
|
|
|
6156
6531
|
now
|
|
6157
6532
|
);
|
|
6158
6533
|
};
|
|
6159
|
-
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network,
|
|
6534
|
+
var restoredAssetId = (network, id) => id === BTC_ASSET_ID ? btcOn("arkade", network) : arkadeAsset(network, import_sdk24.asset.AssetId.fromString(id));
|
|
6160
6535
|
var RESTORED_CORRIDORS = {
|
|
6161
6536
|
lightning_send: ["arkade", "lightning"],
|
|
6162
6537
|
lightning_receive: ["lightning", "arkade"],
|
|
@@ -6188,7 +6563,7 @@ var restoredCorridorRecord = (stored, network, refundLocktime) => {
|
|
|
6188
6563
|
kind: v1.kind,
|
|
6189
6564
|
rfqId: v1.rfqId,
|
|
6190
6565
|
lockupAddress: v1.lockupAddress,
|
|
6191
|
-
lockupPkScript: import_base15.hex.encode(
|
|
6566
|
+
lockupPkScript: import_base15.hex.encode(import_sdk24.ArkAddress.decode(v1.lockupAddress).pkScript),
|
|
6192
6567
|
lock: { hash },
|
|
6193
6568
|
refundLocktime,
|
|
6194
6569
|
profile: v1.profile,
|
|
@@ -6284,12 +6659,12 @@ var reconcileDepositSpend = async (record, indexer) => {
|
|
|
6284
6659
|
const { txs } = await indexer.getVirtualTxs(candidates);
|
|
6285
6660
|
const parsed = txs.map((psbt) => {
|
|
6286
6661
|
try {
|
|
6287
|
-
return
|
|
6662
|
+
return import_sdk25.Transaction.fromPSBT(import_base16.base64.decode(psbt));
|
|
6288
6663
|
} catch {
|
|
6289
6664
|
return void 0;
|
|
6290
6665
|
}
|
|
6291
6666
|
}).filter((tx) => tx !== void 0);
|
|
6292
|
-
const operatorPubkey =
|
|
6667
|
+
const operatorPubkey = import_sdk25.ArkAddress.decode(record.swapAddress).serverPubKey;
|
|
6293
6668
|
const kind = classifyDepositSpend(offer, operatorPubkey, parsed, {
|
|
6294
6669
|
txid: deposit.txid,
|
|
6295
6670
|
vout: deposit.vout
|
|
@@ -6328,12 +6703,12 @@ var retireOfferScripts = async (wallet, repository, record) => {
|
|
|
6328
6703
|
};
|
|
6329
6704
|
|
|
6330
6705
|
// src/client/drive.ts
|
|
6331
|
-
var
|
|
6706
|
+
var import_sdk32 = require("@arkade-os/sdk");
|
|
6332
6707
|
var import_base20 = require("@scure/base");
|
|
6333
6708
|
|
|
6334
6709
|
// src/claim.ts
|
|
6335
6710
|
var import_base17 = require("@scure/base");
|
|
6336
|
-
var
|
|
6711
|
+
var import_sdk26 = require("@arkade-os/sdk");
|
|
6337
6712
|
init_onchainHtlc();
|
|
6338
6713
|
var LockupAmountMismatchError = class extends Error {
|
|
6339
6714
|
name = "LockupAmountMismatchError";
|
|
@@ -6360,6 +6735,9 @@ async function pushClaim(operator, input) {
|
|
|
6360
6735
|
assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
|
|
6361
6736
|
if (!input.partiallyClaimed) {
|
|
6362
6737
|
assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
|
|
6738
|
+
if (input.expectedAmount <= 0) {
|
|
6739
|
+
throw gateError("invalid_gate_input", "expectedAmount is not positive");
|
|
6740
|
+
}
|
|
6363
6741
|
if (funded < input.expectedAmount) {
|
|
6364
6742
|
throw new LockupAmountMismatchError(input.expectedAmount, funded);
|
|
6365
6743
|
}
|
|
@@ -6369,8 +6747,8 @@ async function pushClaim(operator, input) {
|
|
|
6369
6747
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
6370
6748
|
const serverUnrollScript = await operatorUnrollScript(operator, input.network);
|
|
6371
6749
|
const leaf = input.contract.claim();
|
|
6372
|
-
const txid = await (0,
|
|
6373
|
-
identity: (0,
|
|
6750
|
+
const txid = await (0, import_sdk26.signAndSubmitOffchainTx)({
|
|
6751
|
+
identity: (0, import_sdk26.claimWithPreimageIdentity)(input.receiver, input.preimage),
|
|
6374
6752
|
provider: operator,
|
|
6375
6753
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
6376
6754
|
// One aggregate output: this leaf inspects nothing about the output set.
|
|
@@ -6391,7 +6769,7 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6391
6769
|
});
|
|
6392
6770
|
const byArkTx = /* @__PURE__ */ new Map();
|
|
6393
6771
|
for (const vtxo of vtxos ?? []) {
|
|
6394
|
-
if (!(0,
|
|
6772
|
+
if (!(0, import_sdk26.isVtxoSpent)(vtxo) || !vtxo.spentBy || !vtxo.arkTxId) continue;
|
|
6395
6773
|
byArkTx.set(vtxo.arkTxId, [...byArkTx.get(vtxo.arkTxId) ?? [], vtxo]);
|
|
6396
6774
|
}
|
|
6397
6775
|
if (byArkTx.size === 0) return [];
|
|
@@ -6401,9 +6779,9 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6401
6779
|
current,
|
|
6402
6780
|
...(deprecatedSigners ?? []).flatMap(
|
|
6403
6781
|
({ pubkey }) => pubkey ? [
|
|
6404
|
-
|
|
6782
|
+
import_sdk26.CSVMultisigTapscript.encode({
|
|
6405
6783
|
...current.params,
|
|
6406
|
-
pubkeys: [(0,
|
|
6784
|
+
pubkeys: [(0, import_sdk26.toXOnly)(import_base17.hex.decode(pubkey), "deprecated signer")]
|
|
6407
6785
|
})
|
|
6408
6786
|
] : []
|
|
6409
6787
|
)
|
|
@@ -6418,7 +6796,7 @@ async function findPendingClaims(operator, indexer, input) {
|
|
|
6418
6796
|
}));
|
|
6419
6797
|
const total = live.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
6420
6798
|
const checkpoints = unrollScripts.map(
|
|
6421
|
-
(unroll) => (0,
|
|
6799
|
+
(unroll) => (0, import_sdk26.buildOffchainTx)(
|
|
6422
6800
|
lockupInputs(live, input.contract, input.contract.claim()),
|
|
6423
6801
|
[{ script: input.contract.pkScript, amount: BigInt(total) }],
|
|
6424
6802
|
unroll
|
|
@@ -6434,14 +6812,14 @@ async function finalizePendingClaim(operator, indexer, input) {
|
|
|
6434
6812
|
const claims = await findPendingClaims(operator, indexer, input);
|
|
6435
6813
|
if (claims.length === 0) return [];
|
|
6436
6814
|
assertPreimageMatches(input.preimage, input.contract.options.preimageHash);
|
|
6437
|
-
const signer = (0,
|
|
6815
|
+
const signer = (0, import_sdk26.claimWithPreimageIdentity)(input.receiver, input.preimage);
|
|
6438
6816
|
const ours = import_base17.hex.encode(await input.receiver.xOnlyPublicKey());
|
|
6439
6817
|
const finalized = [];
|
|
6440
6818
|
for (const { arkTxid, checkpoints } of claims) {
|
|
6441
6819
|
const { txs } = await indexer.getVirtualTxs(checkpoints.map((checkpoint) => checkpoint.id));
|
|
6442
6820
|
const stored = new Map(
|
|
6443
6821
|
txs.map((raw) => {
|
|
6444
|
-
const tx =
|
|
6822
|
+
const tx = import_sdk26.Transaction.fromPSBT(import_base17.base64.decode(raw));
|
|
6445
6823
|
return [tx.id, tx];
|
|
6446
6824
|
})
|
|
6447
6825
|
);
|
|
@@ -6479,7 +6857,7 @@ init_onchainHtlc();
|
|
|
6479
6857
|
init_coverage();
|
|
6480
6858
|
|
|
6481
6859
|
// src/migrateOfferRows.ts
|
|
6482
|
-
var
|
|
6860
|
+
var import_sdk27 = require("@arkade-os/sdk");
|
|
6483
6861
|
|
|
6484
6862
|
// src/legacy/swap-want-asset.program.v0.json
|
|
6485
6863
|
var swap_want_asset_program_v0_default = {
|
|
@@ -6571,14 +6949,14 @@ function withExitV0(program, exit) {
|
|
|
6571
6949
|
}
|
|
6572
6950
|
var V0_TO_V1 = /* @__PURE__ */ new Map();
|
|
6573
6951
|
for (const [v0, v1] of [
|
|
6574
|
-
[swap_want_btc_program_v0_default,
|
|
6575
|
-
[swap_want_asset_program_v0_default,
|
|
6952
|
+
[swap_want_btc_program_v0_default, legacySwapPrograms.wantBtc],
|
|
6953
|
+
[swap_want_asset_program_v0_default, legacySwapPrograms.wantAsset]
|
|
6576
6954
|
]) {
|
|
6577
6955
|
for (const exit of [void 0, "blocks", "seconds"]) {
|
|
6578
6956
|
const timelock = exit && { type: exit, value: BigInt(0) };
|
|
6579
6957
|
V0_TO_V1.set(
|
|
6580
6958
|
JSON.stringify(withExitV0(v0, exit)),
|
|
6581
|
-
|
|
6959
|
+
import_sdk27.arkade.stringifyArtifact(withExitClosure(v1, timelock))
|
|
6582
6960
|
);
|
|
6583
6961
|
}
|
|
6584
6962
|
}
|
|
@@ -6617,7 +6995,7 @@ init_offer();
|
|
|
6617
6995
|
init_lockupContract();
|
|
6618
6996
|
|
|
6619
6997
|
// src/refundBlocked.ts
|
|
6620
|
-
var
|
|
6998
|
+
var import_sdk28 = require("@arkade-os/sdk");
|
|
6621
6999
|
var RefundNotLocallyPossibleError = class extends Error {
|
|
6622
7000
|
constructor(reason, message, options) {
|
|
6623
7001
|
super(message, options);
|
|
@@ -6634,16 +7012,16 @@ async function senderIdentityForSwapRecord(wallet, record) {
|
|
|
6634
7012
|
);
|
|
6635
7013
|
}
|
|
6636
7014
|
try {
|
|
6637
|
-
return await (0,
|
|
7015
|
+
return await (0, import_sdk28.contractSigner)(wallet, record.signingDescriptor);
|
|
6638
7016
|
} catch (cause) {
|
|
6639
|
-
if (cause instanceof
|
|
7017
|
+
if (cause instanceof import_sdk28.WalletCannotSignError) {
|
|
6640
7018
|
throw new RefundNotLocallyPossibleError(
|
|
6641
7019
|
"unsignable-wallet",
|
|
6642
7020
|
`this wallet holds ${record.signingDescriptor} but cannot sign with it; attach its signer`,
|
|
6643
7021
|
{ cause }
|
|
6644
7022
|
);
|
|
6645
7023
|
}
|
|
6646
|
-
if (cause instanceof
|
|
7024
|
+
if (cause instanceof import_sdk28.ForeignDescriptorError) {
|
|
6647
7025
|
throw new RefundNotLocallyPossibleError(
|
|
6648
7026
|
"foreign-descriptor",
|
|
6649
7027
|
`this wallet cannot derive ${record.signingDescriptor}; the swap was created on another wallet`,
|
|
@@ -6700,7 +7078,7 @@ init_repository();
|
|
|
6700
7078
|
|
|
6701
7079
|
// src/swapManager.ts
|
|
6702
7080
|
var import_base18 = require("@scure/base");
|
|
6703
|
-
var
|
|
7081
|
+
var import_sdk29 = require("@arkade-os/sdk");
|
|
6704
7082
|
init_onchainHtlc();
|
|
6705
7083
|
init_lockupContract();
|
|
6706
7084
|
init_repository();
|
|
@@ -6831,7 +7209,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
6831
7209
|
timer = null;
|
|
6832
7210
|
running = false;
|
|
6833
7211
|
constructor(deps, config = {}) {
|
|
6834
|
-
(0,
|
|
7212
|
+
(0, import_sdk29.assertTimerMs)("pollIntervalMs", config.pollIntervalMs);
|
|
6835
7213
|
this.deps = deps;
|
|
6836
7214
|
this.config = {
|
|
6837
7215
|
enableAutoActions: config.enableAutoActions ?? true,
|
|
@@ -7215,7 +7593,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7215
7593
|
});
|
|
7216
7594
|
return;
|
|
7217
7595
|
}
|
|
7218
|
-
if (!(0,
|
|
7596
|
+
if (!(0, import_sdk29.isContractVtxoEvent)(event)) return;
|
|
7219
7597
|
const swap = this.byLockupScript.get(event.contractScript);
|
|
7220
7598
|
if (!swap) return;
|
|
7221
7599
|
void this.pollSwap(swap).catch(() => {
|
|
@@ -7452,10 +7830,10 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7452
7830
|
return;
|
|
7453
7831
|
}
|
|
7454
7832
|
if (!partiallyClaimed) {
|
|
7455
|
-
if (!Number.
|
|
7833
|
+
if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
|
|
7456
7834
|
return this.block(
|
|
7457
7835
|
swap,
|
|
7458
|
-
`expectedAmount is not a
|
|
7836
|
+
`expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
|
|
7459
7837
|
);
|
|
7460
7838
|
}
|
|
7461
7839
|
const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
@@ -7485,8 +7863,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7485
7863
|
this.setState(swap, "claimed");
|
|
7486
7864
|
this.emitAction(swap, "claimLockup");
|
|
7487
7865
|
} catch (error) {
|
|
7488
|
-
const ark = (0,
|
|
7489
|
-
if ((0,
|
|
7866
|
+
const ark = (0, import_sdk29.isArkError)(error) ? error : (0, import_sdk29.maybeArkError)(error);
|
|
7867
|
+
if ((0, import_sdk29.isArkError)(ark, import_sdk29.ArkErrorName.VTXO_ALREADY_SPENT)) {
|
|
7490
7868
|
if (swap.claimFailure !== void 0) {
|
|
7491
7869
|
delete swap.claimFailure;
|
|
7492
7870
|
this.touch(swap);
|
|
@@ -7716,6 +8094,9 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7716
8094
|
utxo,
|
|
7717
8095
|
bump ? { bump } : void 0
|
|
7718
8096
|
);
|
|
8097
|
+
if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
|
|
8098
|
+
swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
|
|
8099
|
+
}
|
|
7719
8100
|
swap.claimTxid = txid;
|
|
7720
8101
|
swap.claimBroadcastAt = this.config.now();
|
|
7721
8102
|
delete swap.claimConfirmed;
|
|
@@ -7777,8 +8158,8 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
7777
8158
|
this.refundRefused.add(swap.rfqId);
|
|
7778
8159
|
return this.block(swap, error.message);
|
|
7779
8160
|
}
|
|
7780
|
-
const ark = (0,
|
|
7781
|
-
if ((0,
|
|
8161
|
+
const ark = (0, import_sdk29.isArkError)(error) ? error : (0, import_sdk29.maybeArkError)(error);
|
|
8162
|
+
if ((0, import_sdk29.isArkError)(ark, import_sdk29.ArkErrorName.VTXO_ALREADY_SPENT)) return;
|
|
7782
8163
|
this.emitFailed(swap, error);
|
|
7783
8164
|
if (now >= swap.refundLocktime + REFUND_MTP_LAG_SECONDS) {
|
|
7784
8165
|
swap.failure = errorMessage(error);
|
|
@@ -7971,7 +8352,7 @@ var outpointKey = (vtxo) => `${vtxo.txid}:${vtxo.vout}`;
|
|
|
7971
8352
|
|
|
7972
8353
|
// src/watch.ts
|
|
7973
8354
|
var import_base19 = require("@scure/base");
|
|
7974
|
-
var
|
|
8355
|
+
var import_sdk30 = require("@arkade-os/sdk");
|
|
7975
8356
|
init_coverage();
|
|
7976
8357
|
init_offer();
|
|
7977
8358
|
init_store();
|
|
@@ -8006,7 +8387,7 @@ async function watchOfferSwaps({
|
|
|
8006
8387
|
wallet.getAddress(),
|
|
8007
8388
|
wallet.getArkadeReader()
|
|
8008
8389
|
]);
|
|
8009
|
-
const operatorPubkey =
|
|
8390
|
+
const operatorPubkey = import_sdk30.ArkAddress.decode(address).serverPubKey;
|
|
8010
8391
|
let queue = Promise.resolve();
|
|
8011
8392
|
const enqueue = (task) => {
|
|
8012
8393
|
queue = queue.then(task).catch(() => {
|
|
@@ -8021,7 +8402,7 @@ async function watchOfferSwaps({
|
|
|
8021
8402
|
return classifyDepositSpend(
|
|
8022
8403
|
decodeOffer(import_base19.hex.decode(swap.offerHex)),
|
|
8023
8404
|
operatorPubkey,
|
|
8024
|
-
txs.map((psbt) =>
|
|
8405
|
+
txs.map((psbt) => import_sdk30.Transaction.fromPSBT(import_base19.base64.decode(psbt))),
|
|
8025
8406
|
{ txid: vtxo.txid, vout: vtxo.vout }
|
|
8026
8407
|
);
|
|
8027
8408
|
} catch {
|
|
@@ -8049,7 +8430,7 @@ async function watchOfferSwaps({
|
|
|
8049
8430
|
}
|
|
8050
8431
|
};
|
|
8051
8432
|
const unsubscribe = manager.onContractEvent((event) => {
|
|
8052
|
-
if (!(0,
|
|
8433
|
+
if (!(0, import_sdk30.isContractVtxoEvent)(event) || event.type !== "vtxo_spent") return;
|
|
8053
8434
|
enqueue(() => handleSpend(event));
|
|
8054
8435
|
});
|
|
8055
8436
|
return {
|
|
@@ -8059,7 +8440,7 @@ async function watchOfferSwaps({
|
|
|
8059
8440
|
}
|
|
8060
8441
|
|
|
8061
8442
|
// src/client/legacyRecords.ts
|
|
8062
|
-
var
|
|
8443
|
+
var import_sdk31 = require("@arkade-os/sdk");
|
|
8063
8444
|
init_repository();
|
|
8064
8445
|
var readLegacyRfqSwaps = async (repository, filter = {}) => {
|
|
8065
8446
|
try {
|
|
@@ -8076,7 +8457,7 @@ var withLegacyRfqSwaps = (bridge, repository, admits) => {
|
|
|
8076
8457
|
index: bridge.index,
|
|
8077
8458
|
quoteIdOf: bridge.quoteIdOf,
|
|
8078
8459
|
async getRfqSwapsPage(filter, page) {
|
|
8079
|
-
(0,
|
|
8460
|
+
(0, import_sdk31.assertPageRequest)(page);
|
|
8080
8461
|
assertRfqSwapPageFilter(filter);
|
|
8081
8462
|
const v2 = await collectRfqSwaps(bridge, filter);
|
|
8082
8463
|
const held = new Set(
|
|
@@ -8332,7 +8713,7 @@ var createSwapDrive = (config) => {
|
|
|
8332
8713
|
const secret = rfqClaimSecretOf(record);
|
|
8333
8714
|
if (!secret) throw new Error(`rfq swap ${swap.rfqId} carries no claim secret`);
|
|
8334
8715
|
const preimage = await preimageForSwapRecord(wallet, secret);
|
|
8335
|
-
const signer = await (0,
|
|
8716
|
+
const signer = await (0, import_sdk32.contractSigner)(wallet, await (0, import_sdk32.identityDescriptor)(wallet.identity));
|
|
8336
8717
|
const claimKey = record.profile.claimKey;
|
|
8337
8718
|
if (typeof claimKey === "string") {
|
|
8338
8719
|
const held = import_base20.hex.encode(await signer.xOnlyPublicKey());
|
|
@@ -8378,7 +8759,7 @@ var createSwapDrive = (config) => {
|
|
|
8378
8759
|
`rfq swap ${swap.rfqId} carries no refund descriptor; wire the onchain corridor's refund callback to take its L1 funding back`
|
|
8379
8760
|
);
|
|
8380
8761
|
}
|
|
8381
|
-
const signer = await (0,
|
|
8762
|
+
const signer = await (0, import_sdk32.contractSigner)(wallet, descriptor);
|
|
8382
8763
|
const held = import_base20.hex.encode(await signer.xOnlyPublicKey());
|
|
8383
8764
|
if (held !== record.profile.refundKey) {
|
|
8384
8765
|
throw new Error(
|
|
@@ -8418,7 +8799,7 @@ var createSwapDrive = (config) => {
|
|
|
8418
8799
|
}
|
|
8419
8800
|
};
|
|
8420
8801
|
const drivable = async (record) => !readsChain(record.kind) || await resolveOnchain();
|
|
8421
|
-
const pinnedNetwork = async () => (0,
|
|
8802
|
+
const pinnedNetwork = async () => (0, import_sdk32.getNetwork)(await config.network());
|
|
8422
8803
|
const claimSecretOf = async (swap) => {
|
|
8423
8804
|
const record = await corridorStore().getRfqSwap(swap.rfqId);
|
|
8424
8805
|
if (!record) throw new Error(`rfq swap ${swap.rfqId} has no stored record to claim from`);
|
|
@@ -8442,7 +8823,7 @@ var createSwapDrive = (config) => {
|
|
|
8442
8823
|
await track(
|
|
8443
8824
|
finalizePendingClaim(operator, indexer, {
|
|
8444
8825
|
contract: script,
|
|
8445
|
-
receiver: await (0,
|
|
8826
|
+
receiver: await (0, import_sdk32.contractSigner)(wallet, secret.signingDescriptor),
|
|
8446
8827
|
preimage: await preimageForSwapRecord(wallet, secret),
|
|
8447
8828
|
network: await pinnedNetwork()
|
|
8448
8829
|
})
|
|
@@ -8457,10 +8838,10 @@ var createSwapDrive = (config) => {
|
|
|
8457
8838
|
return track(
|
|
8458
8839
|
pushClaim(operator, {
|
|
8459
8840
|
contract: script,
|
|
8460
|
-
receiver: await (0,
|
|
8841
|
+
receiver: await (0, import_sdk32.contractSigner)(wallet, secret.signingDescriptor),
|
|
8461
8842
|
preimage: await preimageForSwapRecord(wallet, secret),
|
|
8462
8843
|
vtxos,
|
|
8463
|
-
destinationPkScript:
|
|
8844
|
+
destinationPkScript: import_sdk32.ArkAddress.decode(payoutAddress).pkScript,
|
|
8464
8845
|
// Passed through: `pushClaim`'s own value check decides whether `P` is published.
|
|
8465
8846
|
expectedAmount: swap.expectedAmount,
|
|
8466
8847
|
partiallyClaimed,
|
|
@@ -8531,7 +8912,7 @@ var createSwapDrive = (config) => {
|
|
|
8531
8912
|
config.network()
|
|
8532
8913
|
]);
|
|
8533
8914
|
const txs = history.map(toRestoreTx);
|
|
8534
|
-
const { hrp, serverPubKey: operatorPubkey } =
|
|
8915
|
+
const { hrp, serverPubKey: operatorPubkey } = import_sdk32.ArkAddress.decode(address);
|
|
8535
8916
|
const reopened = await legacyOfferDepositsToAdopt(store);
|
|
8536
8917
|
for (const txid of reopen) reopened.add(txid);
|
|
8537
8918
|
const cursor = reopened.size === 0 ? scanned : new Set([...scanned].filter((txid) => !reopened.has(txid)));
|
|
@@ -9504,13 +9885,13 @@ var verifyPlanLegs = (plan, legs, give) => {
|
|
|
9504
9885
|
|
|
9505
9886
|
// src/client/quoteRfq.ts
|
|
9506
9887
|
var import_base22 = require("@scure/base");
|
|
9507
|
-
var
|
|
9888
|
+
var import_sdk36 = require("@arkade-os/sdk");
|
|
9508
9889
|
var import_solver_discovery12 = require("@arkade-os/solver-discovery");
|
|
9509
9890
|
|
|
9510
9891
|
// src/jointGraph.ts
|
|
9511
9892
|
var import_base21 = require("@scure/base");
|
|
9512
9893
|
var import_sha26 = require("@noble/hashes/sha2.js");
|
|
9513
|
-
var
|
|
9894
|
+
var import_sdk33 = require("@arkade-os/sdk");
|
|
9514
9895
|
function digestJointGraph(plan, template) {
|
|
9515
9896
|
const parts = [];
|
|
9516
9897
|
const pushU32 = (value) => {
|
|
@@ -9572,7 +9953,7 @@ function verifyJointGraph(plan, template) {
|
|
|
9572
9953
|
}
|
|
9573
9954
|
}
|
|
9574
9955
|
function parseGraphTx(psbt) {
|
|
9575
|
-
return
|
|
9956
|
+
return import_sdk33.Transaction.fromPSBT(import_base21.base64.decode(psbt));
|
|
9576
9957
|
}
|
|
9577
9958
|
function deepFreeze(value) {
|
|
9578
9959
|
if (value !== null && typeof value === "object") {
|
|
@@ -9593,16 +9974,17 @@ function unsignedPsbtBytes(tx) {
|
|
|
9593
9974
|
init_claimAmountGate();
|
|
9594
9975
|
init_claimPacket();
|
|
9595
9976
|
init_offer();
|
|
9977
|
+
init_program();
|
|
9596
9978
|
init_store();
|
|
9597
9979
|
init_onchainHtlc();
|
|
9598
9980
|
init_onchainHtlc();
|
|
9599
9981
|
|
|
9600
9982
|
// src/payment/onchainSwap.ts
|
|
9601
|
-
var
|
|
9983
|
+
var import_sdk35 = require("@arkade-os/sdk");
|
|
9602
9984
|
init_onchainHtlc();
|
|
9603
9985
|
|
|
9604
9986
|
// src/payment/swapRail.ts
|
|
9605
|
-
var
|
|
9987
|
+
var import_sdk34 = require("@arkade-os/sdk");
|
|
9606
9988
|
|
|
9607
9989
|
// src/client/sats.ts
|
|
9608
9990
|
var satsOf = (value, field) => {
|
|
@@ -9699,7 +10081,7 @@ var resultOf = (railId, swap) => ({
|
|
|
9699
10081
|
// the tx that left THIS wallet, as on every other rail; later legs are the client's to report
|
|
9700
10082
|
...swap.fundingTxid === void 0 ? {} : { txid: swap.fundingTxid }
|
|
9701
10083
|
});
|
|
9702
|
-
var swapHandle = async (railId, client, quote) => (0,
|
|
10084
|
+
var swapHandle = async (railId, client, quote) => (0, import_sdk34.makeHandle)(railId, async (emit) => {
|
|
9703
10085
|
const accepted = await client.accept(quote);
|
|
9704
10086
|
return await new Promise((resolve, reject) => {
|
|
9705
10087
|
let finished = false;
|
|
@@ -9743,23 +10125,23 @@ function onchainSwapRail(client, deps) {
|
|
|
9743
10125
|
});
|
|
9744
10126
|
return {
|
|
9745
10127
|
id: ONCHAIN_SWAP_RAIL,
|
|
9746
|
-
match: (req) => (0,
|
|
10128
|
+
match: (req) => (0, import_sdk35.btcTarget)(req.raw) !== void 0,
|
|
9747
10129
|
available: async (req) => {
|
|
9748
|
-
if ((0,
|
|
9749
|
-
const address = (0,
|
|
10130
|
+
if ((0, import_sdk35.assetsOf)(req).length > 0) return false;
|
|
10131
|
+
const address = (0, import_sdk35.btcTarget)(req.raw);
|
|
9750
10132
|
if (address === void 0) return false;
|
|
9751
|
-
const amount = (0,
|
|
10133
|
+
const amount = (0, import_sdk35.tryResolveSendAmount)(req.raw, req.amount);
|
|
9752
10134
|
if (amount === void 0) return false;
|
|
9753
10135
|
if (BigInt(amount) < ONCHAIN_DUST_SATS) return false;
|
|
9754
10136
|
return railAvailable(client, inputFor2(address, amount));
|
|
9755
10137
|
},
|
|
9756
10138
|
quote: async (req) => {
|
|
9757
|
-
const address = (0,
|
|
10139
|
+
const address = (0, import_sdk35.btcTarget)(req.raw);
|
|
9758
10140
|
if (address === void 0) {
|
|
9759
10141
|
throw new Error(`${ONCHAIN_SWAP_RAIL}: the request carries no bitcoin address`);
|
|
9760
10142
|
}
|
|
9761
|
-
(0,
|
|
9762
|
-
const amount = (0,
|
|
10143
|
+
(0, import_sdk35.assertNoAssets)(ONCHAIN_SWAP_RAIL, req);
|
|
10144
|
+
const amount = (0, import_sdk35.resolveSendAmount)(ONCHAIN_SWAP_RAIL, req.raw, req.amount);
|
|
9763
10145
|
const quote = await client.quote(inputFor2(address, amount));
|
|
9764
10146
|
const payout = quote.take.amount - claimFee;
|
|
9765
10147
|
if (payout < ONCHAIN_DUST_SATS) {
|
|
@@ -9828,13 +10210,13 @@ var lockupOf = (derived) => ({
|
|
|
9828
10210
|
pkScript: derived.swapPkScript
|
|
9829
10211
|
});
|
|
9830
10212
|
var covenantInputs = (input) => {
|
|
9831
|
-
const network = (0,
|
|
9832
|
-
const
|
|
10213
|
+
const network = (0, import_sdk36.networkFromOperatorInfo)(input.info);
|
|
10214
|
+
const arkade4 = input.corridors.get("arkade").deps;
|
|
9833
10215
|
return {
|
|
9834
|
-
operatorPubkey: (0,
|
|
10216
|
+
operatorPubkey: (0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9835
10217
|
// The resolved per-network pin, never operator-reported: it lands in a covenant leaf
|
|
9836
10218
|
// that decides who can move the funds.
|
|
9837
|
-
emulatorPubkey: (0,
|
|
10219
|
+
emulatorPubkey: (0, import_sdk36.toXOnly)(import_base22.hex.decode(arkade4.emulatorPubkey), "emulator signer key"),
|
|
9838
10220
|
claimDelay: unilateralClaimDelay(Number(input.info.unilateralExitDelay)),
|
|
9839
10221
|
hrp: network.hrp
|
|
9840
10222
|
};
|
|
@@ -9892,14 +10274,13 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9892
10274
|
);
|
|
9893
10275
|
}
|
|
9894
10276
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
9895
|
-
const rfqId = newRfqId();
|
|
9896
10277
|
const maker = await makerPosition(input.wallet);
|
|
9897
10278
|
const receiveAddress = payment?.receiveAddress;
|
|
9898
10279
|
const receivePkScript = resolveReceivePkScript(
|
|
9899
10280
|
receiveAddress,
|
|
9900
10281
|
maker.pkScript,
|
|
9901
|
-
(0,
|
|
9902
|
-
(0,
|
|
10282
|
+
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp,
|
|
10283
|
+
(0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key")
|
|
9903
10284
|
);
|
|
9904
10285
|
const choice = payment?.carrier;
|
|
9905
10286
|
const carrierRequest = choice === void 0 ? void 0 : choice.mode === "purchase" ? { mode: "purchase" } : {
|
|
@@ -9917,20 +10298,29 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9917
10298
|
throw new Error("carrier quote expired before RFQ");
|
|
9918
10299
|
}
|
|
9919
10300
|
const request = arkadeSwapRequest({
|
|
9920
|
-
rfqId,
|
|
10301
|
+
rfqId: newRfqId(),
|
|
9921
10302
|
...sides,
|
|
9922
10303
|
amount: pinned.value,
|
|
9923
10304
|
amountSide: toRfqAmountSide(pinned.on),
|
|
9924
10305
|
makerPkScript: receivePkScript,
|
|
9925
|
-
makerPublicKey: maker.publicKey
|
|
9926
|
-
|
|
9927
|
-
const wire = await input.transport.requestQuote({
|
|
9928
|
-
...request,
|
|
9929
|
-
profile: {
|
|
9930
|
-
...request.profile,
|
|
9931
|
-
...carrierRequest === void 0 ? {} : { carrier: encodeCarrierRequest(carrierRequest) }
|
|
9932
|
-
}
|
|
10306
|
+
makerPublicKey: maker.publicKey,
|
|
10307
|
+
contractVersions: ASSET_SWAP_CONTRACT_VERSIONS
|
|
9933
10308
|
});
|
|
10309
|
+
const {
|
|
10310
|
+
quote: wire,
|
|
10311
|
+
rfqId,
|
|
10312
|
+
contractVersion
|
|
10313
|
+
} = await requestVersionedQuote(
|
|
10314
|
+
input.transport,
|
|
10315
|
+
{
|
|
10316
|
+
...request,
|
|
10317
|
+
profile: {
|
|
10318
|
+
...request.profile,
|
|
10319
|
+
...carrierRequest === void 0 ? {} : { carrier: encodeCarrierRequest(carrierRequest) }
|
|
10320
|
+
}
|
|
10321
|
+
},
|
|
10322
|
+
ASSET_SWAP_CONTRACT_VERSIONS
|
|
10323
|
+
);
|
|
9934
10324
|
verifyPair(wire.pair, pair);
|
|
9935
10325
|
const parsed = parseRfqQuote(wire);
|
|
9936
10326
|
verifyCrossAssetAmount({ pair, pinned, give: parsed.give, take: parsed.take });
|
|
@@ -9963,10 +10353,10 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9963
10353
|
) - 30;
|
|
9964
10354
|
if (input.now >= validUntil) throw new Error("asset payment terms lapsed before funding");
|
|
9965
10355
|
assetPayment = {
|
|
9966
|
-
receiveAddress: receiveAddress ?? new
|
|
9967
|
-
(0,
|
|
10356
|
+
receiveAddress: receiveAddress ?? new import_sdk36.ArkAddress(
|
|
10357
|
+
(0, import_sdk36.toXOnly)(import_base22.hex.decode(input.info.signerPubkey), "ark signer key"),
|
|
9968
10358
|
maker.pkScript.slice(2),
|
|
9969
|
-
(0,
|
|
10359
|
+
(0, import_sdk36.networkFromOperatorInfo)(input.info).hrp
|
|
9970
10360
|
).encode(),
|
|
9971
10361
|
validUntil,
|
|
9972
10362
|
...carrier === void 0 ? {} : { carrier },
|
|
@@ -9991,7 +10381,8 @@ var quoteArkadeAsset = async (input) => {
|
|
|
9991
10381
|
emulatorPubkey: input.corridors.get("arkade").deps.emulatorPubkey,
|
|
9992
10382
|
maker,
|
|
9993
10383
|
...receiveAddress === void 0 ? {} : { receiveAddress },
|
|
9994
|
-
info: input.info
|
|
10384
|
+
info: input.info,
|
|
10385
|
+
contractVersion
|
|
9995
10386
|
});
|
|
9996
10387
|
verifyingDerivation(() => verifyOfferAddress(wire, offer));
|
|
9997
10388
|
return {
|
|
@@ -10046,14 +10437,14 @@ var assetSidesOf = (legs) => {
|
|
|
10046
10437
|
{ give: "arkade", take: "arkade" }
|
|
10047
10438
|
);
|
|
10048
10439
|
}
|
|
10049
|
-
return giveIsBtc ? { wantAsset:
|
|
10440
|
+
return giveIsBtc ? { wantAsset: import_sdk36.asset.AssetId.fromString(legs.take.assetId) } : { offerAsset: import_sdk36.asset.AssetId.fromString(legs.give.assetId) };
|
|
10050
10441
|
};
|
|
10051
10442
|
var makerPosition = async (wallet) => {
|
|
10052
10443
|
const [address, publicKey] = await Promise.all([
|
|
10053
10444
|
wallet.getAddress(),
|
|
10054
10445
|
wallet.identity.xOnlyPublicKey()
|
|
10055
10446
|
]);
|
|
10056
|
-
return { pkScript:
|
|
10447
|
+
return { pkScript: import_sdk36.ArkAddress.decode(address).pkScript, publicKey };
|
|
10057
10448
|
};
|
|
10058
10449
|
var quoteLightningSend = async (input) => {
|
|
10059
10450
|
const invoice = input.endpoints.take.instrument;
|
|
@@ -10062,7 +10453,7 @@ var quoteLightningSend = async (input) => {
|
|
|
10062
10453
|
}
|
|
10063
10454
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
10064
10455
|
const rfqId = newRfqId();
|
|
10065
|
-
const secrets = await (0,
|
|
10456
|
+
const secrets = await (0, import_sdk36.provisionRefundKey)(input.wallet);
|
|
10066
10457
|
const wire = await input.transport.requestQuote(
|
|
10067
10458
|
lightningSendRequest({
|
|
10068
10459
|
rfqId,
|
|
@@ -10138,7 +10529,7 @@ var quoteLightningReceive = async (input) => {
|
|
|
10138
10529
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
10139
10530
|
const rfqId = newRfqId();
|
|
10140
10531
|
const [secrets, payoutAddress] = await Promise.all([
|
|
10141
|
-
(0,
|
|
10532
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10142
10533
|
input.wallet.getAddress()
|
|
10143
10534
|
]);
|
|
10144
10535
|
const paymentHash = import_base22.hex.encode(secrets.paymentHash);
|
|
@@ -10258,8 +10649,8 @@ var quoteOnchainSend = async (input) => {
|
|
|
10258
10649
|
}) : void 0;
|
|
10259
10650
|
const quoted = claimFee === void 0 ? pinned : { on: pinned.on, value: pinned.value + claimFee, source: pinned.source };
|
|
10260
10651
|
const [secrets, payoutKey] = await Promise.all([
|
|
10261
|
-
(0,
|
|
10262
|
-
(0,
|
|
10652
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10653
|
+
(0, import_sdk36.provisionRefundKey)(input.wallet)
|
|
10263
10654
|
]);
|
|
10264
10655
|
const paymentHash = import_base22.hex.encode(secrets.paymentHash);
|
|
10265
10656
|
const wire = await input.transport.requestQuote(
|
|
@@ -10367,8 +10758,8 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10367
10758
|
const rfqId = newRfqId();
|
|
10368
10759
|
const l1Network = l1NetworkFromArk(input.info.network);
|
|
10369
10760
|
const [secrets, refundKey, payoutAddress, boardingAddress] = await Promise.all([
|
|
10370
|
-
(0,
|
|
10371
|
-
(0,
|
|
10761
|
+
(0, import_sdk36.provisionClaimSecret)(input.wallet),
|
|
10762
|
+
(0, import_sdk36.provisionRefundKey)(input.wallet),
|
|
10372
10763
|
input.wallet.getAddress(),
|
|
10373
10764
|
input.wallet.getBoardingAddress()
|
|
10374
10765
|
]);
|
|
@@ -10478,7 +10869,7 @@ var quoteOnchainReceive = async (input) => {
|
|
|
10478
10869
|
};
|
|
10479
10870
|
|
|
10480
10871
|
// src/client/verbs.ts
|
|
10481
|
-
var
|
|
10872
|
+
var import_sdk37 = require("@arkade-os/sdk");
|
|
10482
10873
|
var enforceFeeCeiling = (quote, call, policy) => {
|
|
10483
10874
|
let ceiling;
|
|
10484
10875
|
for (const [source, limit] of [
|
|
@@ -10503,14 +10894,14 @@ var settle = async (deps, input, maxFee) => {
|
|
|
10503
10894
|
return deps.accept(quote);
|
|
10504
10895
|
};
|
|
10505
10896
|
var pay = async (deps, destination, options = {}) => {
|
|
10506
|
-
const
|
|
10507
|
-
if (
|
|
10508
|
-
const amount = (0,
|
|
10897
|
+
const arkade4 = (0, import_sdk37.arkTarget)(destination);
|
|
10898
|
+
if (arkade4 !== void 0) {
|
|
10899
|
+
const amount = (0, import_sdk37.resolveSendAmount)(
|
|
10509
10900
|
"ark",
|
|
10510
10901
|
destination,
|
|
10511
10902
|
options.amount === void 0 ? void 0 : satsOf(options.amount, "amount")
|
|
10512
10903
|
);
|
|
10513
|
-
return { kind: "payment", txid: await deps.wallet.send({ address:
|
|
10904
|
+
return { kind: "payment", txid: await deps.wallet.send({ address: arkade4, amount }) };
|
|
10514
10905
|
}
|
|
10515
10906
|
const swap = await settle(
|
|
10516
10907
|
deps,
|
|
@@ -10716,7 +11107,7 @@ var createSwapClient = (config) => {
|
|
|
10716
11107
|
}
|
|
10717
11108
|
},
|
|
10718
11109
|
accept: async (quote, options) => {
|
|
10719
|
-
const validUntil = (0,
|
|
11110
|
+
const validUntil = (0, import_sdk38.captureSendDeadline)(options?.validUntil);
|
|
10720
11111
|
ensureLive("accept");
|
|
10721
11112
|
const { corridors } = await resolved();
|
|
10722
11113
|
const drive2 = driving();
|
|
@@ -10831,7 +11222,7 @@ init_rfq();
|
|
|
10831
11222
|
init_repository();
|
|
10832
11223
|
|
|
10833
11224
|
// src/indexedDbRepository.ts
|
|
10834
|
-
var
|
|
11225
|
+
var import_sdk39 = require("@arkade-os/sdk");
|
|
10835
11226
|
init_repository();
|
|
10836
11227
|
var DEFAULT_DB_NAME = "arkade-intents";
|
|
10837
11228
|
var DB_VERSION = 5;
|
|
@@ -10874,7 +11265,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10874
11265
|
version = 5;
|
|
10875
11266
|
connection;
|
|
10876
11267
|
constructor(dbName = DEFAULT_DB_NAME) {
|
|
10877
|
-
this.connection = (0,
|
|
11268
|
+
this.connection = (0, import_sdk39.createManagedConnection)(dbName, DB_VERSION, initDatabase);
|
|
10878
11269
|
}
|
|
10879
11270
|
ensureDb() {
|
|
10880
11271
|
return this.connection.get();
|
|
@@ -10887,7 +11278,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10887
11278
|
* transaction, which `awaitTransaction` reports. */
|
|
10888
11279
|
async write(name, apply) {
|
|
10889
11280
|
const tx = (await this.ensureDb()).transaction([name], "readwrite");
|
|
10890
|
-
const done = (0,
|
|
11281
|
+
const done = (0, import_sdk39.awaitTransaction)(tx);
|
|
10891
11282
|
apply(tx.objectStore(name));
|
|
10892
11283
|
await done;
|
|
10893
11284
|
}
|
|
@@ -10905,10 +11296,10 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10905
11296
|
});
|
|
10906
11297
|
}
|
|
10907
11298
|
async getRfqSwap(rfqId) {
|
|
10908
|
-
return (0,
|
|
11299
|
+
return (0, import_sdk39.promisifyRequest)((await this.readStore(STORE_RFQ_SWAPS)).get(rfqId));
|
|
10909
11300
|
}
|
|
10910
11301
|
async getRfqSwapsPage(filter, page) {
|
|
10911
|
-
(0,
|
|
11302
|
+
(0, import_sdk39.assertPageRequest)(page);
|
|
10912
11303
|
assertRfqSwapPageFilter(filter);
|
|
10913
11304
|
const store = await this.readStore(STORE_RFQ_SWAPS);
|
|
10914
11305
|
const state = filter.state;
|
|
@@ -10925,7 +11316,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10925
11316
|
const cursor = request.result;
|
|
10926
11317
|
if (!cursor || state !== void 0 && cursor.key[0] !== state) {
|
|
10927
11318
|
resolve(
|
|
10928
|
-
(0,
|
|
11319
|
+
(0, import_sdk39.pageResult)(rows, page.limit, (row) => ({
|
|
10929
11320
|
updatedAt: row.updatedAt,
|
|
10930
11321
|
rfqId: row.rfqId
|
|
10931
11322
|
}))
|
|
@@ -10935,7 +11326,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10935
11326
|
rows.push(cursor.value);
|
|
10936
11327
|
if (rows.length > page.limit) {
|
|
10937
11328
|
resolve(
|
|
10938
|
-
(0,
|
|
11329
|
+
(0, import_sdk39.pageResult)(rows, page.limit, (row) => ({
|
|
10939
11330
|
updatedAt: row.updatedAt,
|
|
10940
11331
|
rfqId: row.rfqId
|
|
10941
11332
|
}))
|
|
@@ -10957,13 +11348,13 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10957
11348
|
});
|
|
10958
11349
|
}
|
|
10959
11350
|
async getSwapRecord(id) {
|
|
10960
|
-
return (0,
|
|
11351
|
+
return (0, import_sdk39.promisifyRequest)((await this.readStore(STORE_SWAP_RECORDS)).get(id));
|
|
10961
11352
|
}
|
|
10962
11353
|
async getSwapRecordsPage(page) {
|
|
10963
11354
|
return this.pageStore(STORE_SWAP_RECORDS, page);
|
|
10964
11355
|
}
|
|
10965
11356
|
async pageStore(name, page) {
|
|
10966
|
-
(0,
|
|
11357
|
+
(0, import_sdk39.assertPageRequest)(page);
|
|
10967
11358
|
const store = await this.readStore(name);
|
|
10968
11359
|
const range = page.after === void 0 ? void 0 : IDBKeyRange.lowerBound(page.after, true);
|
|
10969
11360
|
const request = store.openCursor(range);
|
|
@@ -10986,7 +11377,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10986
11377
|
});
|
|
10987
11378
|
}
|
|
10988
11379
|
resultOfPage(rows, limit) {
|
|
10989
|
-
const result = (0,
|
|
11380
|
+
const result = (0, import_sdk39.pageResult)(rows, limit, (row) => row.key);
|
|
10990
11381
|
return {
|
|
10991
11382
|
items: result.items.map((row) => row.value),
|
|
10992
11383
|
...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
|
|
@@ -10998,7 +11389,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
10998
11389
|
});
|
|
10999
11390
|
}
|
|
11000
11391
|
async getScannedTxids() {
|
|
11001
|
-
const keys = await (0,
|
|
11392
|
+
const keys = await (0, import_sdk39.promisifyRequest)((await this.readStore(STORE_SCANNED)).getAllKeys());
|
|
11002
11393
|
return new Set(keys);
|
|
11003
11394
|
}
|
|
11004
11395
|
async markTxidsScanned(txids) {
|
|
@@ -11008,7 +11399,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
11008
11399
|
}
|
|
11009
11400
|
async getCachedMarkets(network, registry) {
|
|
11010
11401
|
const store = await this.readStore(STORE_MARKETS);
|
|
11011
|
-
return (0,
|
|
11402
|
+
return (0, import_sdk39.promisifyRequest)(store.get(marketsCacheKey(network, registry)));
|
|
11012
11403
|
}
|
|
11013
11404
|
async saveCachedMarkets(network, registry, entry) {
|
|
11014
11405
|
await this.write(STORE_MARKETS, (store) => {
|
|
@@ -11021,7 +11412,7 @@ var IndexedDbAssetSwapRepository = class {
|
|
|
11021
11412
|
async clear() {
|
|
11022
11413
|
const stores = STORES.map(([name]) => name);
|
|
11023
11414
|
const tx = (await this.ensureDb()).transaction(stores, "readwrite");
|
|
11024
|
-
const done = (0,
|
|
11415
|
+
const done = (0, import_sdk39.awaitTransaction)(tx);
|
|
11025
11416
|
for (const name of stores) tx.objectStore(name).clear();
|
|
11026
11417
|
await done;
|
|
11027
11418
|
}
|
|
@@ -11035,7 +11426,7 @@ init_claimPacket();
|
|
|
11035
11426
|
init_lockupContract();
|
|
11036
11427
|
|
|
11037
11428
|
// src/payment/lightning.ts
|
|
11038
|
-
var
|
|
11429
|
+
var import_sdk40 = require("@arkade-os/sdk");
|
|
11039
11430
|
var LIGHTNING_RAIL = "lightning";
|
|
11040
11431
|
var inputFor = (invoice, amount) => ({
|
|
11041
11432
|
to: invoice,
|
|
@@ -11045,19 +11436,19 @@ function lightningRail(client) {
|
|
|
11045
11436
|
return {
|
|
11046
11437
|
id: LIGHTNING_RAIL,
|
|
11047
11438
|
// classification only, so `match` is not a second gate on top of `available`
|
|
11048
|
-
match: (req) => (0,
|
|
11439
|
+
match: (req) => (0, import_sdk40.invoiceTarget)(req.raw) !== void 0,
|
|
11049
11440
|
available: async (req) => {
|
|
11050
|
-
if ((0,
|
|
11051
|
-
const invoice = (0,
|
|
11441
|
+
if ((0, import_sdk40.assetsOf)(req).length > 0) return false;
|
|
11442
|
+
const invoice = (0, import_sdk40.invoiceTarget)(req.raw);
|
|
11052
11443
|
if (invoice === void 0) return false;
|
|
11053
11444
|
return railAvailable(client, inputFor(invoice, req.amount));
|
|
11054
11445
|
},
|
|
11055
11446
|
quote: async (req) => {
|
|
11056
|
-
const invoice = (0,
|
|
11447
|
+
const invoice = (0, import_sdk40.invoiceTarget)(req.raw);
|
|
11057
11448
|
if (invoice === void 0) {
|
|
11058
11449
|
throw new Error(`${LIGHTNING_RAIL}: the request carries no BOLT11 invoice`);
|
|
11059
11450
|
}
|
|
11060
|
-
(0,
|
|
11451
|
+
(0, import_sdk40.assertNoAssets)(LIGHTNING_RAIL, req);
|
|
11061
11452
|
const quote = await client.quote(inputFor(invoice, req.amount));
|
|
11062
11453
|
const amounts = receiverExact(LIGHTNING_RAIL, {
|
|
11063
11454
|
amount: quote.take.amount,
|
|
@@ -11075,7 +11466,7 @@ function lightningRail(client) {
|
|
|
11075
11466
|
}
|
|
11076
11467
|
|
|
11077
11468
|
// src/payment/router.ts
|
|
11078
|
-
var
|
|
11469
|
+
var import_sdk41 = require("@arkade-os/sdk");
|
|
11079
11470
|
var SWAP_ROUTER_PRIORITY = [
|
|
11080
11471
|
"ark",
|
|
11081
11472
|
LIGHTNING_RAIL,
|
|
@@ -11083,15 +11474,15 @@ var SWAP_ROUTER_PRIORITY = [
|
|
|
11083
11474
|
"onchain"
|
|
11084
11475
|
];
|
|
11085
11476
|
function createSwapPaymentRouter(wallet, client, config) {
|
|
11086
|
-
return new
|
|
11477
|
+
return new import_sdk41.PaymentRouter({
|
|
11087
11478
|
wallet,
|
|
11088
11479
|
prefs: { priority: [...SWAP_ROUTER_PRIORITY], ...config.prefs }
|
|
11089
|
-
}).use((0,
|
|
11480
|
+
}).use((0, import_sdk41.arkRail)()).use((0, import_sdk41.onchainRail)({ feeInfo: (0, import_sdk41.walletFeeSource)(wallet) })).use(lightningRail(client)).use(onchainSwapRail(client, config));
|
|
11090
11481
|
}
|
|
11091
11482
|
|
|
11092
11483
|
// src/offerFillPlan.ts
|
|
11093
11484
|
var import_base24 = require("@scure/base");
|
|
11094
|
-
var
|
|
11485
|
+
var import_sdk42 = require("@arkade-os/sdk");
|
|
11095
11486
|
init_offer();
|
|
11096
11487
|
var OFFER_FILL_TEMPLATE = "offer-fill/1";
|
|
11097
11488
|
var OFFER_FILL_OWNERS = [null, "solver", "sponsor"];
|
|
@@ -11109,7 +11500,7 @@ async function buildOfferFillPlan(wallet, arkServerUrl, offerHex, opts) {
|
|
|
11109
11500
|
const contract = await connectFillContract(wallet, arkServerUrl, offer, { swapAddress });
|
|
11110
11501
|
const vtxos = await contract.getUtxos();
|
|
11111
11502
|
const vtxo = resolveDeposit(vtxos, { fundingTxid, fundingOutpoint });
|
|
11112
|
-
const solverPayout = payoutScript ??
|
|
11503
|
+
const solverPayout = payoutScript ?? import_sdk42.ArkAddress.decode(await wallet.getAddress()).pkScript;
|
|
11113
11504
|
const sponsorLeg = sponsor !== void 0 ? normalizeSponsor(sponsor, assetCarrierSats) : void 0;
|
|
11114
11505
|
const fill = contract.functions.fulfill();
|
|
11115
11506
|
const layout = assembleOfferFill(fill, {
|
|
@@ -11176,14 +11567,14 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11176
11567
|
}
|
|
11177
11568
|
});
|
|
11178
11569
|
const ext = arkTx.getOutput(payments);
|
|
11179
|
-
if (!ext?.script || !
|
|
11570
|
+
if (!ext?.script || !import_sdk42.Extension.isExtension(ext.script)) {
|
|
11180
11571
|
throw new Error(`fill plan output ${payments} is not the extension packet`);
|
|
11181
11572
|
}
|
|
11182
11573
|
const anchor = arkTx.getOutput(payments + 1);
|
|
11183
|
-
if (!anchor?.script || import_base24.hex.encode(anchor.script) !== import_base24.hex.encode(
|
|
11574
|
+
if (!anchor?.script || import_base24.hex.encode(anchor.script) !== import_base24.hex.encode(import_sdk42.P2A.script) || anchor.amount !== import_sdk42.P2A.amount) {
|
|
11184
11575
|
throw new Error(`fill plan output ${payments + 1} is not the anchor`);
|
|
11185
11576
|
}
|
|
11186
|
-
const packet =
|
|
11577
|
+
const packet = import_sdk42.Extension.fromTx(arkTx).getAssetPacket();
|
|
11187
11578
|
for (const group of packet?.groups ?? []) {
|
|
11188
11579
|
if (group.assetId === null) throw new Error("fill plan carries an issuance group");
|
|
11189
11580
|
const assetId = group.assetId.toString();
|
|
@@ -11194,7 +11585,7 @@ function toJointGraph(arkTx, checkpoints, layout, wantedAssetId) {
|
|
|
11194
11585
|
}
|
|
11195
11586
|
for (const output of group.outputs) {
|
|
11196
11587
|
const hosted = arkTx.getOutput(output.vout);
|
|
11197
|
-
if (output.vout >= payments || !hosted?.script ||
|
|
11588
|
+
if (output.vout >= payments || !hosted?.script || import_sdk42.Extension.isExtension(hosted.script)) {
|
|
11198
11589
|
throw new Error(
|
|
11199
11590
|
`fill plan asset ${assetId} pays nonexistent output ${output.vout}`
|
|
11200
11591
|
);
|