@arkade-os/swap 0.1.0 → 0.1.2
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 +150 -33
- package/dist/advanced.d.cts +10 -8
- package/dist/advanced.d.ts +10 -8
- package/dist/advanced.js +7 -3
- package/dist/{chunk-WKJFXXSR.js → chunk-BLECLU5Q.js} +91 -14
- package/dist/{chunk-FMRAV77W.js → chunk-ICSREL7N.js} +14 -12
- package/dist/{chunk-HRMWBULL.js → chunk-J2PMAQP2.js} +70 -25
- package/dist/index.cjs +146 -33
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/{lockupContract-D7BNjksX.d.ts → lockupContract-CIXkJPxV.d.ts} +1 -1
- package/dist/{lockupContract-G-9CNRMq.d.cts → lockupContract-CkhWMKCo.d.cts} +1 -1
- package/dist/nostr.js +1 -1
- package/dist/{offer-DdB1M6FZ.d.ts → offer-BPD2ortO.d.ts} +1 -1
- package/dist/{offer-CcJfx5Fj.d.cts → offer-Diff5Flc.d.cts} +1 -1
- package/dist/{offerFillPlan-BII0PW92.d.cts → offerFillPlan-B-5ae_gQ.d.cts} +40 -11
- package/dist/{offerFillPlan-CNTLVD7j.d.ts → offerFillPlan-CJzneX6F.d.ts} +40 -11
- package/dist/protocol.cjs +99 -25
- package/dist/protocol.d.cts +6 -6
- package/dist/protocol.d.ts +6 -6
- package/dist/protocol.js +4 -4
- package/dist/repositories/realm/index.d.cts +1 -1
- package/dist/repositories/realm/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/{repository-DmPzpbd7.d.ts → repository-BBVRh9ez.d.ts} +17 -2
- package/dist/{repository-DqdLVrVv.d.cts → repository-C4pvymhs.d.cts} +17 -2
- package/dist/{watch-CmJQDtsy.d.ts → watch-7BiRa4oB.d.ts} +1 -1
- package/dist/{watch-BonYT9af.d.cts → watch-Bxq-lx_6.d.cts} +1 -1
- package/package.json +2 -2
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
rfqCorridorHandlers,
|
|
25
25
|
rfqSignerOf,
|
|
26
26
|
updateAssetSwapBestEffort
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-ICSREL7N.js";
|
|
28
28
|
import {
|
|
29
29
|
collectRfqSwaps
|
|
30
30
|
} from "./chunk-A3SHHRX4.js";
|
|
@@ -928,7 +928,9 @@ import {
|
|
|
928
928
|
assertSubmittedArkTxid,
|
|
929
929
|
assertValidServerUnrollScript,
|
|
930
930
|
buildOffchainTx,
|
|
931
|
+
createAssetPacket,
|
|
931
932
|
decodeTapscript,
|
|
933
|
+
Extension,
|
|
932
934
|
getArkPsbtFields,
|
|
933
935
|
isVtxoSpent,
|
|
934
936
|
matchServerCheckpoints,
|
|
@@ -991,7 +993,8 @@ async function findLockupVtxos(contracts, swapPkScript) {
|
|
|
991
993
|
txid: vtxo.txid,
|
|
992
994
|
vout: vtxo.vout,
|
|
993
995
|
value: Number(vtxo.value),
|
|
994
|
-
recoverable: vtxo.isSwept
|
|
996
|
+
recoverable: vtxo.isSwept,
|
|
997
|
+
...vtxo.assets?.length ? { assets: vtxo.assets } : {}
|
|
995
998
|
});
|
|
996
999
|
}
|
|
997
1000
|
return out;
|
|
@@ -1001,17 +1004,17 @@ var candidateWitnessItems = (tx, inputIndex) => [
|
|
|
1001
1004
|
...getArkPsbtFields(tx, inputIndex, ConditionWitness).flat(),
|
|
1002
1005
|
...tx.getInput(inputIndex).finalScriptWitness ?? []
|
|
1003
1006
|
];
|
|
1004
|
-
var
|
|
1007
|
+
var refundLeafScript = (tx, inputIndex) => {
|
|
1005
1008
|
const input = tx.getInput(inputIndex);
|
|
1006
1009
|
const witness = input.finalScriptWitness;
|
|
1007
1010
|
const leaves = input.tapLeafScript ?? [];
|
|
1008
1011
|
const script = witness && witness.length >= 2 ? witness[witness.length - 2] : leaves.length === 1 ? scriptFromTapLeafScript(leaves[0]) : void 0;
|
|
1009
|
-
if (!script) return
|
|
1012
|
+
if (!script) return void 0;
|
|
1010
1013
|
try {
|
|
1011
1014
|
const { type } = decodeTapscript(script);
|
|
1012
|
-
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig";
|
|
1015
|
+
return type === "multisig" || type === "csv-multisig" || type === "cltv-multisig" ? script : void 0;
|
|
1013
1016
|
} catch {
|
|
1014
|
-
return
|
|
1017
|
+
return void 0;
|
|
1015
1018
|
}
|
|
1016
1019
|
};
|
|
1017
1020
|
async function readLockupFate(indexer, input) {
|
|
@@ -1044,6 +1047,7 @@ async function readLockupFate(indexer, input) {
|
|
|
1044
1047
|
const spends = [...spentBy.values()];
|
|
1045
1048
|
const { txs } = await indexer.getVirtualTxs([...spentBy.keys()]);
|
|
1046
1049
|
const refunded = /* @__PURE__ */ new Set();
|
|
1050
|
+
const leafScripts = /* @__PURE__ */ new Set();
|
|
1047
1051
|
for (const raw of txs) {
|
|
1048
1052
|
let tx;
|
|
1049
1053
|
try {
|
|
@@ -1065,11 +1069,15 @@ async function readLockupFate(indexer, input) {
|
|
|
1065
1069
|
return { fate: "claimed", preimage: candidate, spends };
|
|
1066
1070
|
}
|
|
1067
1071
|
}
|
|
1068
|
-
|
|
1072
|
+
const leafScript = refundLeafScript(tx, i);
|
|
1073
|
+
if (leafScript) {
|
|
1074
|
+
refunded.add(`${vtxo.txid}:${vtxo.vout}`);
|
|
1075
|
+
leafScripts.add(hex2.encode(leafScript));
|
|
1076
|
+
}
|
|
1069
1077
|
}
|
|
1070
1078
|
}
|
|
1071
1079
|
if (sweptLeft) return { fate: "open" };
|
|
1072
|
-
return everySpendNamed && all.every((vtxo) => refunded.has(`${vtxo.txid}:${vtxo.vout}`)) ? { fate: "returned", spends } : { fate: "unknown" };
|
|
1080
|
+
return everySpendNamed && all.every((vtxo) => refunded.has(`${vtxo.txid}:${vtxo.vout}`)) ? { fate: "returned", spends, leafScripts: [...leafScripts] } : { fate: "unknown" };
|
|
1073
1081
|
}
|
|
1074
1082
|
var assertNoneSwept = (vtxos, contract) => {
|
|
1075
1083
|
const swept = vtxos.filter((vtxo) => vtxo.recoverable);
|
|
@@ -1090,6 +1098,23 @@ var operatorUnrollScript = async (operator, network) => {
|
|
|
1090
1098
|
};
|
|
1091
1099
|
var MAX_LOCKUP_SPEND_INPUTS = 16;
|
|
1092
1100
|
var boundedLockupSpend = (vtxos) => [...vtxos].sort((a, b) => b.value - a.value).slice(0, MAX_LOCKUP_SPEND_INPUTS);
|
|
1101
|
+
var lockupAssetOutputs = (vtxos) => {
|
|
1102
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
1103
|
+
const totals = /* @__PURE__ */ new Map();
|
|
1104
|
+
vtxos.forEach((vtxo, vin) => {
|
|
1105
|
+
if (!vtxo.assets?.length) return;
|
|
1106
|
+
inputs.set(vin, [...vtxo.assets]);
|
|
1107
|
+
for (const { assetId, amount } of vtxo.assets) {
|
|
1108
|
+
totals.set(assetId, (totals.get(assetId) ?? 0n) + amount);
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
if (inputs.size === 0) return [];
|
|
1112
|
+
const receiver = {
|
|
1113
|
+
address: "",
|
|
1114
|
+
assets: [...totals].map(([assetId, amount]) => ({ assetId, amount }))
|
|
1115
|
+
};
|
|
1116
|
+
return [Extension.create([createAssetPacket(inputs, [receiver])]).txOut()];
|
|
1117
|
+
};
|
|
1093
1118
|
var lockupInputs = (vtxos, contract, leaf) => {
|
|
1094
1119
|
const tapTree = contract.encode();
|
|
1095
1120
|
return vtxos.map((vtxo) => ({
|
|
@@ -1115,7 +1140,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
1115
1140
|
const amount = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
|
|
1116
1141
|
const { arkTx: tx, checkpoints } = buildOffchainTx(
|
|
1117
1142
|
lockupInputs(vtxos, input.contract, leaf),
|
|
1118
|
-
[{ script: refundPkScript, amount: BigInt(amount) }],
|
|
1143
|
+
[{ script: refundPkScript, amount: BigInt(amount) }, ...lockupAssetOutputs(vtxos)],
|
|
1119
1144
|
serverUnrollScript
|
|
1120
1145
|
);
|
|
1121
1146
|
const signedTx = await input.sender.sign(tx);
|
|
@@ -1170,8 +1195,7 @@ var chainSourceFrom = (provider, network) => {
|
|
|
1170
1195
|
}));
|
|
1171
1196
|
},
|
|
1172
1197
|
async getSpendingTx(txid, vout, pkScript) {
|
|
1173
|
-
const
|
|
1174
|
-
const outspend = outspends[vout];
|
|
1198
|
+
const outspend = provider.getTxOutspend ? await provider.getTxOutspend(txid, vout) : (await provider.getTxOutspends(txid))[vout];
|
|
1175
1199
|
if (!outspend?.spent) return null;
|
|
1176
1200
|
const spender = outspend.txid || await spenderFromHistory(txid, vout, pkScript);
|
|
1177
1201
|
if (!spender) return null;
|
|
@@ -1510,7 +1534,7 @@ var validatePlan = (plan, giveBalance, dust) => {
|
|
|
1510
1534
|
// src/restore.ts
|
|
1511
1535
|
import { base64 as base642, hex as hex4 } from "@scure/base";
|
|
1512
1536
|
import {
|
|
1513
|
-
Extension,
|
|
1537
|
+
Extension as Extension2,
|
|
1514
1538
|
Transaction as Transaction2,
|
|
1515
1539
|
scriptFromTapLeafScript as scriptFromTapLeafScript2
|
|
1516
1540
|
} from "@arkade-os/sdk";
|
|
@@ -1619,7 +1643,7 @@ async function restoreAssetSwaps(indexer, txs, existingIds, opts) {
|
|
|
1619
1643
|
if (!fundingTx) continue;
|
|
1620
1644
|
fetchedTxids.push(txid);
|
|
1621
1645
|
try {
|
|
1622
|
-
const packet =
|
|
1646
|
+
const packet = Extension2.fromTx(parsed).getPacketByType(OFFER_PACKET_TYPE);
|
|
1623
1647
|
if (!packet) continue;
|
|
1624
1648
|
const payload = packet.serialize();
|
|
1625
1649
|
found.push({
|
|
@@ -1738,6 +1762,8 @@ var RFQ_SWAP_ACTIVE_STATES = [
|
|
|
1738
1762
|
"needs_counterparty"
|
|
1739
1763
|
];
|
|
1740
1764
|
var isRfqSwapTerminal = (state) => RFQ_SWAP_TERMINAL_STATES.includes(state);
|
|
1765
|
+
var isRecheckableRefundedSend = (record) => record.kind === "lightning_send" && record.state === "refunded" && !record.refundTxid;
|
|
1766
|
+
var isRfqSwapRestorable = (record) => !isRfqSwapTerminal(record.state) || isRecheckableRefundedSend(record);
|
|
1741
1767
|
|
|
1742
1768
|
// src/rfqRecord.ts
|
|
1743
1769
|
import { ArkAddress, VHTLCV2ContractHandler } from "@arkade-os/sdk";
|
|
@@ -1910,7 +1936,10 @@ async function pushClaim(operator, input) {
|
|
|
1910
1936
|
provider: operator,
|
|
1911
1937
|
inputs: lockupInputs(vtxos, input.contract, leaf),
|
|
1912
1938
|
// One aggregate output: this leaf inspects nothing about the output set.
|
|
1913
|
-
outputs: [
|
|
1939
|
+
outputs: [
|
|
1940
|
+
{ script: input.destinationPkScript, amount: BigInt(locked) },
|
|
1941
|
+
...lockupAssetOutputs(vtxos)
|
|
1942
|
+
],
|
|
1914
1943
|
serverUnrollScript,
|
|
1915
1944
|
verifyServerSignatures: { serverPubkey: input.contract.options.server }
|
|
1916
1945
|
});
|
|
@@ -2217,6 +2246,46 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
2217
2246
|
}
|
|
2218
2247
|
return { restored, failed, pruned: [] };
|
|
2219
2248
|
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Re-read stored `refunded` Lightning sends with no refund txid, one at a time. A misread
|
|
2251
|
+
* could have ended a settled send this way: a `claimed` read settles the record, any other
|
|
2252
|
+
* answer, or a failure, leaves it untouched. Returns the swaps it settled in every sink; one
|
|
2253
|
+
* a sink refused stays monitored for the poll to retry. `stopped` is checked before each
|
|
2254
|
+
* record and before each write, so a caller can walk away mid-run.
|
|
2255
|
+
*/
|
|
2256
|
+
async recheckRefundedSends(options = {}) {
|
|
2257
|
+
const repository = this.requireRepository("recheckRefundedSends");
|
|
2258
|
+
const params = options.params ?? this.paramsFromContracts();
|
|
2259
|
+
const settled = [];
|
|
2260
|
+
for (const record of await collectRfqSwaps(repository, { state: "refunded" })) {
|
|
2261
|
+
if (options.stopped?.()) break;
|
|
2262
|
+
if (!isRecheckableRefundedSend(record) || this.monitored.has(record.rfqId)) continue;
|
|
2263
|
+
const removedAt = this.removed.get(record.rfqId);
|
|
2264
|
+
try {
|
|
2265
|
+
const swap = rebuildRfqSwap(record, await params(record));
|
|
2266
|
+
const fate = await readLockupFate(this.deps.indexer, {
|
|
2267
|
+
swapPkScript: swap.lockupPkScript,
|
|
2268
|
+
paymentHash: swap.paymentHash
|
|
2269
|
+
});
|
|
2270
|
+
if (options.stopped?.()) break;
|
|
2271
|
+
if (fate.fate !== "claimed") continue;
|
|
2272
|
+
if (this.monitored.has(record.rfqId)) continue;
|
|
2273
|
+
if (this.removed.get(record.rfqId) !== removedAt) continue;
|
|
2274
|
+
delete swap.lockupSpendTxids;
|
|
2275
|
+
this.stampLockupSpends(swap, fate.spends);
|
|
2276
|
+
this.stampSettlementPreimage(swap, fate.preimage);
|
|
2277
|
+
this.setState(swap, "settled");
|
|
2278
|
+
if (await this.save(swap)) {
|
|
2279
|
+
this.dirty.delete(swap.rfqId);
|
|
2280
|
+
settled.push(swap);
|
|
2281
|
+
} else {
|
|
2282
|
+
this.track(swap);
|
|
2283
|
+
}
|
|
2284
|
+
} catch {
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
return settled;
|
|
2288
|
+
}
|
|
2220
2289
|
/**
|
|
2221
2290
|
* Drop stored records that are terminal and past `RFQ_SWAP_RETENTION_SECONDS` (per
|
|
2222
2291
|
* `shouldRetainRfqSwap`), and return their ids. Explicit only: restore keeps history.
|
|
@@ -2583,6 +2652,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
2583
2652
|
* finalization and the per-swap lock belong to `pollSwap`.
|
|
2584
2653
|
*/
|
|
2585
2654
|
async runPass(swap) {
|
|
2655
|
+
if (isRfqSwapTerminal(swap.state)) return;
|
|
2586
2656
|
await this.ensureRegistered(swap);
|
|
2587
2657
|
let fate;
|
|
2588
2658
|
try {
|
|
@@ -2594,6 +2664,11 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
2594
2664
|
} catch {
|
|
2595
2665
|
fate = { fate: "unknown" };
|
|
2596
2666
|
}
|
|
2667
|
+
if ((swap.kind === "lightning_send" || swap.kind === "onchain_send") && fate.fate === "returned" && this.config.now() < swap.refundLocktime && !fate.leafScripts.every(
|
|
2668
|
+
(script) => script === swap.lockup?.script.nonInteractiveRefundScript
|
|
2669
|
+
)) {
|
|
2670
|
+
fate = { fate: "unknown" };
|
|
2671
|
+
}
|
|
2597
2672
|
if (swap.kind === "onchain_receive") return this.driveOnchainReceive(swap, fate);
|
|
2598
2673
|
if (fate.fate === "claimed" || fate.fate === "returned") {
|
|
2599
2674
|
this.stampLockupSpends(swap, fate.spends);
|
|
@@ -3360,6 +3435,8 @@ export {
|
|
|
3360
3435
|
classifyDepositSpend,
|
|
3361
3436
|
restoreAssetSwaps,
|
|
3362
3437
|
isRfqSwapTerminal,
|
|
3438
|
+
isRecheckableRefundedSend,
|
|
3439
|
+
isRfqSwapRestorable,
|
|
3363
3440
|
RFQ_SWAP_RETENTION_SECONDS,
|
|
3364
3441
|
normalizeRfqSwapRecord,
|
|
3365
3442
|
createRfqSwapRecord,
|
|
@@ -2260,10 +2260,12 @@ function deriveLightningSend(input) {
|
|
|
2260
2260
|
}
|
|
2261
2261
|
async function requestLightningSend(wallet, transport, params) {
|
|
2262
2262
|
const rfqId = params.rfqId ?? newRfqId();
|
|
2263
|
-
const secrets = await
|
|
2263
|
+
const [secrets, info] = await Promise.all([
|
|
2264
|
+
provisionRefundKey(wallet),
|
|
2265
|
+
wallet.getArkadeInfo({ requireLive: true })
|
|
2266
|
+
]);
|
|
2264
2267
|
const senderPubkey = secrets.pubkey;
|
|
2265
2268
|
const refundAddress = secrets.address;
|
|
2266
|
-
const info = await wallet.getArkadeInfo({ requireLive: true });
|
|
2267
2269
|
const quote = await transport.requestQuote(
|
|
2268
2270
|
lightningSendRequest({ rfqId, invoice: params.invoice.raw, refundAddress, senderPubkey })
|
|
2269
2271
|
);
|
|
@@ -2563,7 +2565,11 @@ function deriveOnchainSend(input) {
|
|
|
2563
2565
|
}
|
|
2564
2566
|
async function requestOnchainSend(wallet, transport, params) {
|
|
2565
2567
|
const rfqId = params.rfqId ?? newRfqId();
|
|
2566
|
-
const secrets = await
|
|
2568
|
+
const [secrets, info, refundAddress] = await Promise.all([
|
|
2569
|
+
provisionClaimSecret(wallet, { preimage: params.preimage }),
|
|
2570
|
+
wallet.getArkadeInfo({ requireLive: true }),
|
|
2571
|
+
wallet.getAddress()
|
|
2572
|
+
]);
|
|
2567
2573
|
if (secrets.mustPersistPreimage) {
|
|
2568
2574
|
console.warn(
|
|
2569
2575
|
"[swap] this swap's preimage cannot be re-derived from the seed and MUST be persisted with the record before funding"
|
|
@@ -2571,10 +2577,6 @@ async function requestOnchainSend(wallet, transport, params) {
|
|
|
2571
2577
|
}
|
|
2572
2578
|
const paymentHash = hex5.encode(secrets.paymentHash);
|
|
2573
2579
|
const senderPubkey = secrets.pubkey;
|
|
2574
|
-
const [info, refundAddress] = await Promise.all([
|
|
2575
|
-
wallet.getArkadeInfo({ requireLive: true }),
|
|
2576
|
-
wallet.getAddress()
|
|
2577
|
-
]);
|
|
2578
2580
|
const quote = await transport.requestQuote(
|
|
2579
2581
|
onchainSendRequest({
|
|
2580
2582
|
rfqId,
|
|
@@ -2751,7 +2753,11 @@ function deriveLightningReceive(input) {
|
|
|
2751
2753
|
};
|
|
2752
2754
|
}
|
|
2753
2755
|
var provisionReceive = async (wallet, params, persistBefore) => {
|
|
2754
|
-
const secrets = await
|
|
2756
|
+
const [secrets, info, payoutAddress] = await Promise.all([
|
|
2757
|
+
provisionClaimSecret(wallet),
|
|
2758
|
+
wallet.getArkadeInfo({ requireLive: true }),
|
|
2759
|
+
wallet.getAddress()
|
|
2760
|
+
]);
|
|
2755
2761
|
if (secrets.mustPersistPreimage) {
|
|
2756
2762
|
console.warn(
|
|
2757
2763
|
`[swap] this swap's preimage cannot be re-derived from the seed and MUST be persisted with the record before ${persistBefore}`
|
|
@@ -2760,10 +2766,6 @@ var provisionReceive = async (wallet, params, persistBefore) => {
|
|
|
2760
2766
|
const preimage = secrets.preimage;
|
|
2761
2767
|
const paymentHash = hex5.encode(secrets.paymentHash);
|
|
2762
2768
|
const payoutPubkey = secrets.pubkey;
|
|
2763
|
-
const [info, payoutAddress] = await Promise.all([
|
|
2764
|
-
wallet.getArkadeInfo({ requireLive: true }),
|
|
2765
|
-
wallet.getAddress()
|
|
2766
|
-
]);
|
|
2767
2769
|
const binds = bindsClaimAmount();
|
|
2768
2770
|
const claimPacket = params.covclaimdPubkey && (!binds || params.amountSide === "to") ? await sealClaimPacket({
|
|
2769
2771
|
preimage,
|
|
@@ -21,7 +21,9 @@ import {
|
|
|
21
21
|
fromAtomicDecimal,
|
|
22
22
|
fundingWasNotSubmitted,
|
|
23
23
|
fundsFromWallet,
|
|
24
|
+
isRecheckableRefundedSend,
|
|
24
25
|
isRfqConfigurationRefusal,
|
|
26
|
+
isRfqSwapRestorable,
|
|
25
27
|
isRfqSwapTerminal,
|
|
26
28
|
lightningCorridor,
|
|
27
29
|
makeCachedFeedFetch,
|
|
@@ -58,7 +60,7 @@ import {
|
|
|
58
60
|
undeliveredCarry,
|
|
59
61
|
walletOperator,
|
|
60
62
|
watchOfferSwaps
|
|
61
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-BLECLU5Q.js";
|
|
62
64
|
import {
|
|
63
65
|
ARKADE_BTC,
|
|
64
66
|
ASSET_CARRIER_SATS,
|
|
@@ -123,7 +125,7 @@ import {
|
|
|
123
125
|
unilateralClaimDelay,
|
|
124
126
|
verifyOfferAddress,
|
|
125
127
|
withExitClosure
|
|
126
|
-
} from "./chunk-
|
|
128
|
+
} from "./chunk-ICSREL7N.js";
|
|
127
129
|
import {
|
|
128
130
|
assertRfqSwapPageFilter,
|
|
129
131
|
collectAssetSwaps,
|
|
@@ -1009,14 +1011,22 @@ var publicAssetId = (corridor, assetId, network) => {
|
|
|
1009
1011
|
if (!ARKADE_ASSET_IDENTITY.test(assetId)) return void 0;
|
|
1010
1012
|
return `arkade:${network}/${ARKADE_ASSET_NAMESPACE}:${assetId}`;
|
|
1011
1013
|
};
|
|
1014
|
+
var cardLegAssetId = (card, side, network) => {
|
|
1015
|
+
const corridor = corridorOfRail(marketCorridor(card, side));
|
|
1016
|
+
if (corridor === void 0) return void 0;
|
|
1017
|
+
const canonical = marketAssetId(card, side);
|
|
1018
|
+
if (canonical !== void 0 && isAssetId(canonical)) return canonical;
|
|
1019
|
+
return publicAssetId(
|
|
1020
|
+
corridor,
|
|
1021
|
+
(side === "base" ? card.base_asset : card.quote_asset).id,
|
|
1022
|
+
network
|
|
1023
|
+
);
|
|
1024
|
+
};
|
|
1012
1025
|
var aliasTableFrom = (markets, network) => {
|
|
1013
1026
|
const rows = /* @__PURE__ */ new Map();
|
|
1014
1027
|
const add = (card, side) => {
|
|
1015
1028
|
const info = side === "base" ? card.base_asset : card.quote_asset;
|
|
1016
|
-
const
|
|
1017
|
-
if (corridor === void 0) return;
|
|
1018
|
-
const canonical = marketAssetId(card, side);
|
|
1019
|
-
const id = canonical !== void 0 && isAssetId(canonical) ? canonical : publicAssetId(corridor, info.id, network);
|
|
1029
|
+
const id = cardLegAssetId(card, side, network);
|
|
1020
1030
|
if (id === void 0 || typeof info.ticker !== "string" || info.ticker === "") return;
|
|
1021
1031
|
rows.set(`${id} ${info.ticker.toLowerCase()}`, { id, ticker: info.ticker });
|
|
1022
1032
|
};
|
|
@@ -1120,8 +1130,7 @@ var chainSourceOver = (backend, network) => {
|
|
|
1120
1130
|
}));
|
|
1121
1131
|
},
|
|
1122
1132
|
async getSpendingTx(txid, vout, pkScript) {
|
|
1123
|
-
const
|
|
1124
|
-
const outspend = outspends[vout];
|
|
1133
|
+
const outspend = backend.provider.getTxOutspend ? await backend.provider.getTxOutspend(txid, vout) : (await backend.provider.getTxOutspends(txid))[vout];
|
|
1125
1134
|
if (!outspend?.spent) return null;
|
|
1126
1135
|
const spender = outspend.txid || await spenderFromVins(txid, vout, pkScript);
|
|
1127
1136
|
if (!spender) return null;
|
|
@@ -2126,6 +2135,7 @@ var createSwapDrive = (config) => {
|
|
|
2126
2135
|
let readyPromise;
|
|
2127
2136
|
const inFlight = /* @__PURE__ */ new Set();
|
|
2128
2137
|
let queue = Promise.resolve();
|
|
2138
|
+
let recheck;
|
|
2129
2139
|
const track = (work) => {
|
|
2130
2140
|
inFlight.add(work);
|
|
2131
2141
|
void work.then(
|
|
@@ -2143,6 +2153,7 @@ var createSwapDrive = (config) => {
|
|
|
2143
2153
|
do {
|
|
2144
2154
|
await queue;
|
|
2145
2155
|
await Promise.allSettled([...inFlight]);
|
|
2156
|
+
if (!disposed) await recheck;
|
|
2146
2157
|
await watcher?.idle();
|
|
2147
2158
|
} while (inFlight.size > 0);
|
|
2148
2159
|
};
|
|
@@ -2165,12 +2176,12 @@ var createSwapDrive = (config) => {
|
|
|
2165
2176
|
storage(),
|
|
2166
2177
|
remember,
|
|
2167
2178
|
// Terminal records stay readable but are excluded from the manager's read, sparing
|
|
2168
|
-
// a rebuild per record just to file it `finished
|
|
2169
|
-
// `rfqId` (see `getRfqSwapsPage`).
|
|
2170
|
-
(r) => !undrivable.has(r.id) &&
|
|
2179
|
+
// a rebuild per record just to file it `finished`, except a refunded send restore
|
|
2180
|
+
// re-reads. The index still learns their `rfqId` (see `getRfqSwapsPage`).
|
|
2181
|
+
(r) => !undrivable.has(r.id) && isRfqSwapRestorable(r)
|
|
2171
2182
|
),
|
|
2172
2183
|
storage(),
|
|
2173
|
-
(r) => !undrivableLegacy.has(r.rfqId) &&
|
|
2184
|
+
(r) => !undrivableLegacy.has(r.rfqId) && isRfqSwapRestorable(r)
|
|
2174
2185
|
)
|
|
2175
2186
|
);
|
|
2176
2187
|
const effectiveState = (swap) => {
|
|
@@ -2619,8 +2630,9 @@ var createSwapDrive = (config) => {
|
|
|
2619
2630
|
}
|
|
2620
2631
|
}
|
|
2621
2632
|
const liveCorridor = corridor.filter((record) => !isRfqSwapTerminal(record.state));
|
|
2633
|
+
const recheckable = corridor.filter(isRecheckableRefundedSend);
|
|
2622
2634
|
const store = corridorStore();
|
|
2623
|
-
for (const record of liveCorridor) store.index(record);
|
|
2635
|
+
for (const record of [...liveCorridor, ...recheckable]) store.index(record);
|
|
2624
2636
|
const liveLegacy = await legacyLiveRfqSwaps(repository);
|
|
2625
2637
|
if (liveCorridor.length > 0 || liveLegacy.length > 0) {
|
|
2626
2638
|
try {
|
|
@@ -2667,6 +2679,17 @@ var createSwapDrive = (config) => {
|
|
|
2667
2679
|
}
|
|
2668
2680
|
}
|
|
2669
2681
|
emitAll();
|
|
2682
|
+
if (mode !== "readonly" && recheckable.length > 0) {
|
|
2683
|
+
recheck = (async () => {
|
|
2684
|
+
try {
|
|
2685
|
+
await contractsOf();
|
|
2686
|
+
managerDeps.repository = store;
|
|
2687
|
+
await manager.recheckRefundedSends({ stopped: () => disposed });
|
|
2688
|
+
} catch (error) {
|
|
2689
|
+
console.warn("[swap] the refunded send re-read did not complete", error);
|
|
2690
|
+
}
|
|
2691
|
+
})();
|
|
2692
|
+
}
|
|
2670
2693
|
};
|
|
2671
2694
|
const ready = () => readyPromise ??= restore();
|
|
2672
2695
|
const stop = async () => {
|
|
@@ -2841,7 +2864,8 @@ import {
|
|
|
2841
2864
|
isRfqMarket as isRfqMarket2,
|
|
2842
2865
|
marketCorridor as marketCorridor2,
|
|
2843
2866
|
marketLegKey,
|
|
2844
|
-
selectMarkets
|
|
2867
|
+
selectMarkets,
|
|
2868
|
+
sideLimits
|
|
2845
2869
|
} from "@arkade-os/solver-discovery";
|
|
2846
2870
|
var marketKeyOf = (card) => {
|
|
2847
2871
|
const base = marketLegKey(card, "base");
|
|
@@ -2915,6 +2939,18 @@ var cardMarketOf = (card, snapshot, key, backend) => ({
|
|
|
2915
2939
|
snapshot
|
|
2916
2940
|
});
|
|
2917
2941
|
var isCardMarket = (market) => market.kind === "card";
|
|
2942
|
+
var marketLegOf = (card, side, network) => {
|
|
2943
|
+
const asset5 = cardLegAssetId(card, side, network);
|
|
2944
|
+
return {
|
|
2945
|
+
...asset5 === void 0 ? {} : { asset: asset5 },
|
|
2946
|
+
decimals: (side === "base" ? card.base_asset : card.quote_asset).decimals,
|
|
2947
|
+
limits: sideLimits(card, side)
|
|
2948
|
+
};
|
|
2949
|
+
};
|
|
2950
|
+
var marketOf = (card, snapshot, network) => ({
|
|
2951
|
+
...cardMarketOf(card, snapshot, marketKeyOf(card), marketBackendOf(card)),
|
|
2952
|
+
legs: [marketLegOf(card, "base", network), marketLegOf(card, "quote", network)]
|
|
2953
|
+
});
|
|
2918
2954
|
|
|
2919
2955
|
// src/client/resolve.ts
|
|
2920
2956
|
var SUPPORTED_PAIRS = [
|
|
@@ -3883,7 +3919,7 @@ var assetSidesOf = (legs) => {
|
|
|
3883
3919
|
const giveIsBtc = legs.give.assetId === BTC_ASSET_ID;
|
|
3884
3920
|
const takeIsBtc = legs.take.assetId === BTC_ASSET_ID;
|
|
3885
3921
|
if (giveIsBtc && takeIsBtc) {
|
|
3886
|
-
throw new UnsupportedRoute("
|
|
3922
|
+
throw new UnsupportedRoute("give and take are both BTC, so the route swaps nothing", {
|
|
3887
3923
|
give: "arkade",
|
|
3888
3924
|
take: "arkade"
|
|
3889
3925
|
});
|
|
@@ -3985,9 +4021,11 @@ var quoteLightningReceive = async (input) => {
|
|
|
3985
4021
|
const pinned = pinnedFor(input);
|
|
3986
4022
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
3987
4023
|
const rfqId = newRfqId();
|
|
3988
|
-
const secrets = await
|
|
4024
|
+
const [secrets, payoutAddress] = await Promise.all([
|
|
4025
|
+
provisionClaimSecret(input.wallet),
|
|
4026
|
+
input.wallet.getAddress()
|
|
4027
|
+
]);
|
|
3989
4028
|
const paymentHash = hex8.encode(secrets.paymentHash);
|
|
3990
|
-
const payoutAddress = await input.wallet.getAddress();
|
|
3991
4029
|
const lightning = input.corridors.get("lightning").deps;
|
|
3992
4030
|
const sealTo = sealingKey(lightning);
|
|
3993
4031
|
const sealsAmount = pinned.on === "take" && input.legs.take.assetId === BTC_ASSET_ID;
|
|
@@ -4103,8 +4141,10 @@ var quoteOnchainSend = async (input) => {
|
|
|
4103
4141
|
claimVsize: onchain.claimVsize
|
|
4104
4142
|
}) : void 0;
|
|
4105
4143
|
const quoted = claimFee === void 0 ? pinned : { on: pinned.on, value: pinned.value + claimFee, source: pinned.source };
|
|
4106
|
-
const secrets = await
|
|
4107
|
-
|
|
4144
|
+
const [secrets, payoutKey] = await Promise.all([
|
|
4145
|
+
provisionClaimSecret(input.wallet),
|
|
4146
|
+
provisionRefundKey(input.wallet)
|
|
4147
|
+
]);
|
|
4108
4148
|
const paymentHash = hex8.encode(secrets.paymentHash);
|
|
4109
4149
|
const wire = await input.transport.requestQuote(
|
|
4110
4150
|
withCanonicalAmount(
|
|
@@ -4210,11 +4250,14 @@ var quoteOnchainReceive = async (input) => {
|
|
|
4210
4250
|
const pair = rfqPairFor(input.legs.give, input.legs.take);
|
|
4211
4251
|
const rfqId = newRfqId();
|
|
4212
4252
|
const l1Network = l1NetworkFromArk(input.info.network);
|
|
4213
|
-
const secrets = await
|
|
4214
|
-
|
|
4253
|
+
const [secrets, refundKey, payoutAddress, boardingAddress] = await Promise.all([
|
|
4254
|
+
provisionClaimSecret(input.wallet),
|
|
4255
|
+
provisionRefundKey(input.wallet),
|
|
4256
|
+
input.wallet.getAddress(),
|
|
4257
|
+
input.wallet.getBoardingAddress()
|
|
4258
|
+
]);
|
|
4215
4259
|
const paymentHash = hex8.encode(secrets.paymentHash);
|
|
4216
|
-
const
|
|
4217
|
-
const refundPkScript = l1ScriptForAddress(await input.wallet.getBoardingAddress(), l1Network);
|
|
4260
|
+
const refundPkScript = l1ScriptForAddress(boardingAddress, l1Network);
|
|
4218
4261
|
const wire = await input.transport.requestQuote(
|
|
4219
4262
|
withCanonicalAmount(
|
|
4220
4263
|
onchainReceiveRequest({
|
|
@@ -4611,10 +4654,10 @@ var createSwapClient = (config) => {
|
|
|
4611
4654
|
},
|
|
4612
4655
|
markets: async () => {
|
|
4613
4656
|
ensureLive("markets");
|
|
4614
|
-
const { discovery } = await resolved();
|
|
4657
|
+
const { base, discovery } = await resolved();
|
|
4615
4658
|
const snapshot = await discovery.load();
|
|
4616
4659
|
return usableMarkets(snapshot, config.policy).map(
|
|
4617
|
-
(card) =>
|
|
4660
|
+
(card) => marketOf(card, snapshot.ref, base.networkName)
|
|
4618
4661
|
);
|
|
4619
4662
|
},
|
|
4620
4663
|
pay: async (destination, options) => {
|
|
@@ -4865,6 +4908,7 @@ export {
|
|
|
4865
4908
|
railOfCorridor,
|
|
4866
4909
|
corridorOfRail,
|
|
4867
4910
|
publicAssetId,
|
|
4911
|
+
cardLegAssetId,
|
|
4868
4912
|
aliasTableFrom,
|
|
4869
4913
|
scopedToRail,
|
|
4870
4914
|
arkadeCorridor,
|
|
@@ -4908,6 +4952,7 @@ export {
|
|
|
4908
4952
|
marketRefOf,
|
|
4909
4953
|
cardMarketOf,
|
|
4910
4954
|
isCardMarket,
|
|
4955
|
+
marketOf,
|
|
4911
4956
|
assembleRoute,
|
|
4912
4957
|
resolveRoute,
|
|
4913
4958
|
DEFAULT_MAX_REFUND_WINDOW_SECONDS,
|