@arkade-os/swap 0.1.0-rc.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -252
- package/dist/advanced.cjs +6613 -3224
- package/dist/advanced.d.cts +328 -283
- package/dist/advanced.d.ts +328 -283
- package/dist/advanced.js +347 -34
- package/dist/chunk-A3SHHRX4.js +104 -0
- package/dist/chunk-FMRAV77W.js +3065 -0
- package/dist/chunk-T4FHBWZI.js +3459 -0
- package/dist/{chunk-NS3K6BZG.js → chunk-YHESEL4I.js} +1792 -636
- package/dist/index.cjs +6901 -3901
- package/dist/index.d.cts +71 -243
- package/dist/index.d.ts +71 -243
- package/dist/index.js +131 -167
- package/dist/lockupContract-CIXkJPxV.d.ts +148 -0
- package/dist/lockupContract-CkhWMKCo.d.cts +148 -0
- package/dist/node/index.cjs +61 -10
- package/dist/node/index.d.cts +307 -635
- package/dist/node/index.d.ts +307 -635
- package/dist/node/index.js +65 -10
- package/dist/nostr.cjs +427 -49
- package/dist/nostr.d.cts +59 -70
- package/dist/nostr.d.ts +59 -70
- package/dist/nostr.js +268 -36
- package/dist/offer-BPD2ortO.d.ts +269 -0
- package/dist/offer-Diff5Flc.d.cts +269 -0
- package/dist/offerFillPlan-B-5ae_gQ.d.cts +1671 -0
- package/dist/offerFillPlan-CJzneX6F.d.ts +1671 -0
- package/dist/protocol.cjs +5717 -4275
- package/dist/protocol.d.cts +258 -328
- package/dist/protocol.d.ts +258 -328
- package/dist/protocol.js +200 -224
- package/dist/repositories/realm/index.cjs +55 -11
- package/dist/repositories/realm/index.d.cts +18 -30
- package/dist/repositories/realm/index.d.ts +18 -30
- package/dist/repositories/realm/index.js +49 -12
- package/dist/repositories/sqlite/index.cjs +61 -10
- package/dist/repositories/sqlite/index.d.cts +7 -6
- package/dist/repositories/sqlite/index.d.ts +7 -6
- package/dist/repositories/sqlite/index.js +57 -11
- package/dist/repository-BBVRh9ez.d.ts +2357 -0
- package/dist/repository-C4pvymhs.d.cts +2357 -0
- package/dist/{rfq-BO6o7NwS.d.ts → rfq-C0tHOvn6.d.cts} +323 -444
- package/dist/{rfq-BO6o7NwS.d.cts → rfq-C0tHOvn6.d.ts} +323 -444
- package/dist/watch-7BiRa4oB.d.ts +74 -0
- package/dist/watch-Bxq-lx_6.d.cts +74 -0
- package/package.json +10 -10
- package/dist/chunk-JFKGMPMH.js +0 -3456
- package/dist/chunk-LLG7RD2T.js +0 -1499
- package/dist/chunk-U7VWWTL6.js +0 -66
- package/dist/errors-CNISbN0M.d.ts +0 -2218
- package/dist/errors-DwNhIP0N.d.cts +0 -2218
- package/dist/lockupContract-C8-Mcg69.d.ts +0 -664
- package/dist/lockupContract-mIt4syse.d.cts +0 -664
- package/dist/repository-CGPLbjBe.d.ts +0 -3489
- package/dist/repository-DSGGq0ct.d.cts +0 -3489
- package/dist/watch-DWyVqyEN.d.cts +0 -96
- package/dist/watch-DmvHNX6T.d.ts +0 -96
package/dist/advanced.d.cts
CHANGED
|
@@ -1,52 +1,159 @@
|
|
|
1
|
-
import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './
|
|
2
|
-
export { e as AcceptConflict, f as AcceptInput, g as
|
|
3
|
-
import { DiscoveredMarket } from '@arkade-os/solver-discovery';
|
|
4
|
-
import { N as NetworkRef,
|
|
5
|
-
export {
|
|
6
|
-
import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-
|
|
7
|
-
export { S as SwapRefusal } from './rfq-
|
|
1
|
+
import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './offerFillPlan-B-5ae_gQ.cjs';
|
|
2
|
+
export { e as AcceptConflict, f as AcceptInput, g as AcceptOptions, h as AmbiguousDestination, i as AmountEncodingUnsupported, j as AmountMismatch, k as AssetRfqPreparation, l as AttestingRfqTransport, B as BuildOfferFillPlanOpts, m as CORRIDOR_FACTORIES, n as CancelInput, o as CancelOutcome, p as ClaimedDestination, q as ClientDisposed, r as CorridorBase, s as CorridorClaim, t as CorridorCovenant, u as CorridorDeadline, v as CorridorDeps, w as CorridorDepsByCorridor, x as CorridorDrive, y as CorridorLockup, z as CorridorModule, E as CorridorOverrides, F as CorridorPass, G as CorridorRfqPreparation, H as DEFAULT_MAX_REFUND_WINDOW_SECONDS, I as DiscoveryConfig, J as DiscoveryIndexInput, K as DiscoverySnapshotUnavailable, N as DriveMode, P as DriveRefusal, Q as ExchangeOptions, R as FEED_TTL_MS, T as FeeCeiling, U as FeedFetch, V as FeedQuoteInput, W as FillSponsor, X as FillSponsorFare, Y as INDEXED_NETWORKS, Z as InconsistentRoute, _ as InsufficientFunds, $ as JointGraph, a0 as LockupOwner, a1 as Market, a2 as MarketLeg, a3 as MaxFeeExceeded, a4 as MissingCorridorDep, a5 as NotCancellable, a6 as OFFER_FILL_OWNERS, a7 as OFFER_FILL_TEMPLATE, a8 as ONCHAIN_CLAIM_FEE_RATE_SATVB, a9 as ObservationSeam, aa as OfferPreparation, ab as OnchainClaim, ac as OnchainRefund, ad as OperatorUnreachable, ae as ParsedRfqQuote, af as PayOptions, ag as PayResult, ah as QuoteCheck, ai as QuoteExpired, aj as QuotePreparation, ak as QuoteVerificationFailed, al as REGISTRY_URL, am as ReceiveArtifact, an as ReceiveOptions, ao as ReceiveRequest, ap as RecoveryResult, aq as RegisteredAsset, ar as RfqAuctionPolicy, as as RfqPreparation, at as RfqQuoteInput, au as RfqRendezvous, av as RfqTransportFactory, aw as RouteSide, ax as SWAP_ERROR_NAMES, ay as SwapClient, az as SwapClientConfig, aA as SwapDrive, aB as SwapDriveConfig, aC as SwapDriveRefusedError, aD as SwapError, aE as SwapErrorName, aF as SwapFilter, aG as UnsupportedRoute, aH as VerbDeps, aI as acceptQuote, aJ as attesting, aK as buildOfferFillPlan, aL as cancelSwap, aM as canonicalAssetId, aN as cardMarketOf, aO as chooseMarket, aP as conflictingFields, aQ as corridorSet, aR as createNostrTransportFactory, aS as createSwapClient, aT as createSwapDrive, aU as deepFreeze, aV as digestJointGraph, aW as discoveryIndex, aX as eligibleMarkets, aY as enforceFeeCeiling, aZ as exchange, a_ as feedFetch, a$ as feedSpread, b0 as isAddressable, b1 as isCardMarket, b2 as isIndexedNetwork, b3 as isSwapError, b4 as isUsableCard, b5 as liveArkadeInfo, b6 as marketBackendOf, b7 as marketKeyOf, b8 as marketOf, b9 as marketRefOf, ba as nostrTransportFactory, bb as parseRfqQuote, bc as pay, bd as quoteFromFeed, be as quoteViaRfq, bf as readableRecord, bg as receive, bh as resolveCorridorBase, bi as resolveCorridorDeps, bj as rfqLeg, bk as rfqPairFor, bl as swapRecordOf, bm as toDiscoveryLeg, bn as unsignedPsbtBytes, bo as usableMarkets, bp as verifyJointGraph, bq as verifyOfferFillPlan, br as verifyPlanLegs, bs as withCanonicalAmount } from './offerFillPlan-B-5ae_gQ.cjs';
|
|
3
|
+
import { DiscoveredMarket, Side } from '@arkade-os/solver-discovery';
|
|
4
|
+
import { N as NetworkRef, A as AssetId, C as Corridor, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, c as AssetSwapStatus, S as SwapRecord, O as OfferSwapRecord, d as AssetSwapRepository, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, h as AssetSwap, L as LockupSpendIndexer, i as RouteResolution, j as ResolvedEndpoint, P as PinnedAmount, I as Instrument, k as Route, l as QuoteInput, m as Pubkey } from './repository-C4pvymhs.cjs';
|
|
5
|
+
export { n as ACTIVITY_TOKEN, o as ARKADE_ASSET_NAMESPACE, p as Amount, q as AmountFormatError, r as AmountOn, s as AmountRefusal, t as ArkadeCarrierChoice, u as Artifact, v as AssetIdError, w as AssetIdRefusal, x as AssetNamespace, y as AssetOn, z as AssetPart, B as AssetPaymentInput, D as AssetPaymentTerms, E as AssetRef, F as AssetScale, G as AssetSwapId, H as AtomicDecimal, J as AuctionMarketRef, K as AuctionProvenance, M as BITCOIN_RAILS, T as BTC_ASSET_PART, U as BitcoinRail, V as CORRIDORS, W as CORRIDOR_PASS, X as CardMarketRef, Y as CorridorId, Z as CorridorKind, _ as DepositArtifact, $ as DisplayDecimal, a0 as Endpoint, a1 as Ep, a2 as Hex, a3 as LOCKUP_OWNER, a4 as MarketBackend, a5 as MarketRef, a6 as OFFER_SWAP_ID_PREFIX, a7 as Outcome, a8 as ParsedAssetId, a9 as Quote, aa as QuoteLeg, ab as RAILS, ac as RFQ_SWAP_ID_PREFIX, ad as RailOf, ae as RankedBid, af as RawState, ag as ReceiverPaidCarrierQuote, ah as RecordedArtifact, ai as RecordedAssetPayment, aj as RecordedEndpoint, ak as RecordedInstrument, al as RecordedLeg, am as RestoredMarketRef, an as RfqAmountSide, ao as SnapshotRef, ap as Swap, aq as SwapFamily, ar as SwapRecordCommon, as as SwapUpdate, at as TaxiIdentity, au as Unsubscribe, av as VerifiedCarrierTerms, aw as arkadeAsset, ax as artifactOf, ay as assetPartOf, az as assetSwapIdOf, aA as bitcoinNetworkOf, aB as btcAssetPart, aC as btcOn, aD as corridorOfRail, aE as corridorOutcome, aF as decodeRfqAmount, aG as encodeRfqAmount, aH as familyOfSwapId, aI as formatAssetId, aJ as fromAtomicDecimal, aK as fromRfqAmountSide, aL as fundingWasNotSubmitted, aM as fundsFromWallet, aN as instrumentOf, aO as isAssetId, aP as isAtomicDecimal, aQ as isBtcAsset, aR as isBtcAssetLenient, aS as isNetworkRef, aT as issuanceOf, aU as legOf, aV as offerOutcome, aW as parseAssetId, aX as quoteIdOfSwapId, aY as railOf, aZ as railOfCorridor, a_ as readsChain, a$ as recordArtifact, b0 as recordEndpoint, b1 as recordInstrument, b2 as recordLeg, b3 as recordOutcome, b4 as sameAsset, b5 as swapOf, b6 as toAtomicDecimal, b7 as toRfqAmountSide, b8 as toSafeNumber } from './repository-C4pvymhs.cjs';
|
|
6
|
+
import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-C0tHOvn6.cjs';
|
|
7
|
+
export { S as SwapRefusal } from './rfq-C0tHOvn6.cjs';
|
|
8
8
|
import * as btc from '@scure/btc-signer';
|
|
9
|
-
import { OnchainProvider, NetworkName, IWallet, VHTLC } from '@arkade-os/sdk';
|
|
10
|
-
import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-
|
|
9
|
+
import { OnchainProvider, NetworkName, PageRequest, PageResult, IWallet, VHTLC } from '@arkade-os/sdk';
|
|
10
|
+
import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-Bxq-lx_6.cjs';
|
|
11
|
+
import './offer-Diff5Flc.cjs';
|
|
12
|
+
import 'nostr-tools';
|
|
11
13
|
|
|
14
|
+
/** The EVM leg's namespace. Which chain is the quote's `evm_chain_id`, not the pair. */
|
|
15
|
+
declare const EVM_CHAIN = "ethereum";
|
|
16
|
+
/** `ethereum:<token>`, lowercased: the solver's pair regex is lowercase-only while its profile
|
|
17
|
+
* address fields accept a checksum, so normalising only one of them yields `unsupported_pair`. */
|
|
18
|
+
declare const evmTokenLeg: (tokenAddress: string) => string;
|
|
19
|
+
/** `arkade:BTC->ethereum:<token>`: the client locks sats, the solver pays tokens. */
|
|
20
|
+
declare const evmSendPair: (tokenAddress: string) => string;
|
|
21
|
+
/** `ethereum:<token>->arkade:BTC`: the client locks tokens, the solver pays sats. */
|
|
22
|
+
declare const evmReceivePair: (tokenAddress: string) => string;
|
|
23
|
+
declare const evmDirectionOf: (pair: string) => "send" | "receive" | null;
|
|
24
|
+
/** The lowercase ERC20 an EVM pair names, or `null`. */
|
|
25
|
+
declare const evmTokenOf: (pair: string) => string | null;
|
|
26
|
+
declare const evmAmountToWire: (units: bigint) => string;
|
|
27
|
+
/** Refuses a JSON number outright: by the time it is here the parser may already have rounded it. */
|
|
28
|
+
declare const evmAmountFromWire: (value: unknown, field: string) => bigint;
|
|
29
|
+
/** Exact-in only: `amount` is sats, and the solver's schema pins `amount_side: "from"`. */
|
|
30
|
+
declare const evmSendRequest: (input: {
|
|
31
|
+
rfqId: string;
|
|
32
|
+
tokenAddress: string;
|
|
33
|
+
/** `sha256(P)`, hex. */
|
|
34
|
+
paymentHash: string;
|
|
35
|
+
/** Where the client takes the tokens; sent as given, keeping any EIP-55 checksum. */
|
|
36
|
+
evmClaimAddress: string;
|
|
37
|
+
/** The client's Arkade address, where the covenant refund pays. */
|
|
38
|
+
refundAddress: string;
|
|
39
|
+
/** The client's x-only key for the covenant's refund leaves. */
|
|
40
|
+
senderPubkey: Uint8Array;
|
|
41
|
+
amountSats: number;
|
|
42
|
+
}) => Record<string, unknown>;
|
|
43
|
+
/** The token amount rides the profile as `evm_amount`; the envelope has no `amount`, and the
|
|
44
|
+
* solver's strict schema refuses one. No `claim_packet`: the client must be online to claim. */
|
|
45
|
+
declare const evmReceiveRequest: (input: {
|
|
46
|
+
rfqId: string;
|
|
47
|
+
tokenAddress: string;
|
|
48
|
+
paymentHash: string;
|
|
49
|
+
evmAmount: bigint;
|
|
50
|
+
/** The client's own lock deadline, as a block height. */
|
|
51
|
+
evmTimeoutBlock: number;
|
|
52
|
+
evmRefundAddress: string;
|
|
53
|
+
payoutAddress: string;
|
|
54
|
+
/** The covenant's `receiver` role. */
|
|
55
|
+
payoutPubkey: Uint8Array;
|
|
56
|
+
}) => Record<string, unknown>;
|
|
57
|
+
interface EvmQuoteProfileCommon {
|
|
58
|
+
payment_hash: string;
|
|
59
|
+
/** Compare-only: never fund it without deriving the covenant locally. */
|
|
60
|
+
lockup_address: string;
|
|
61
|
+
evm_contract_address: string;
|
|
62
|
+
evm_chain_id: number;
|
|
63
|
+
/** Wait for both: a rollup can bury a lock in seconds before its L1 batch finalizes. */
|
|
64
|
+
min_confirmations: number;
|
|
65
|
+
min_age_seconds: number;
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
}
|
|
68
|
+
interface EvmSendQuoteProfile extends EvmQuoteProfileCommon {
|
|
69
|
+
/** The solver's claim pkScript, needed to rebuild the covenant's merkle root. */
|
|
70
|
+
receiver_pk_script: string;
|
|
71
|
+
/** The solver's address, the refund role of its lock: the sixth swap-key field, and an
|
|
72
|
+
* explicit argument to `claim`. */
|
|
73
|
+
evm_refund_address: string;
|
|
74
|
+
/** A block height, unlike the unix-seconds `refund_locktime` beside it. */
|
|
75
|
+
evm_timeout_block: number;
|
|
76
|
+
}
|
|
77
|
+
interface EvmReceiveQuoteProfile extends EvmQuoteProfileCommon {
|
|
78
|
+
/** The solver's refund pkScript, needed to rebuild the covenant's merkle root. */
|
|
79
|
+
solver_refund_pk_script: string;
|
|
80
|
+
/** The `claimAddress` the client must lock to. */
|
|
81
|
+
evm_claim_address: string;
|
|
82
|
+
}
|
|
83
|
+
interface EvmSendQuote {
|
|
84
|
+
v: 1;
|
|
85
|
+
type: "rfq_quote";
|
|
86
|
+
rfq_id: string;
|
|
87
|
+
pair: string;
|
|
88
|
+
from_amount: number;
|
|
89
|
+
to_amount: string;
|
|
90
|
+
solver_pubkey: string;
|
|
91
|
+
valid_until: number;
|
|
92
|
+
refund_locktime: number;
|
|
93
|
+
profile: EvmSendQuoteProfile;
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
}
|
|
96
|
+
interface EvmReceiveQuote {
|
|
97
|
+
v: 1;
|
|
98
|
+
type: "rfq_quote";
|
|
99
|
+
rfq_id: string;
|
|
100
|
+
pair: string;
|
|
101
|
+
from_amount: string;
|
|
102
|
+
to_amount: number;
|
|
103
|
+
solver_pubkey: string;
|
|
104
|
+
valid_until: number;
|
|
105
|
+
refund_locktime: number;
|
|
106
|
+
profile: EvmReceiveQuoteProfile;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}
|
|
109
|
+
type EvmRfqQuote = EvmSendQuote | EvmReceiveQuote;
|
|
12
110
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* M1 declared {@link AssetAliasTable} and left it injected: the alias layer owns
|
|
16
|
-
* no network, and the table's only real source is the market index, which is
|
|
17
|
-
* this milestone's. So this is the inverse of `toDiscoveryLeg` -- a card's
|
|
18
|
-
* corridor and `AssetInfo` back up to the public id a caller may write, plus the
|
|
19
|
-
* ticker that id answers to.
|
|
20
|
-
*
|
|
21
|
-
* Tickers are display metadata on a card and identity nowhere, which is why the
|
|
22
|
-
* table carries both and `canonicalAssetId` refuses a ticker that names two
|
|
23
|
-
* assets rather than picking one. Rows are deduplicated by id and ticker, so a
|
|
24
|
-
* ticker listed by nine solvers for the same asset is one row and not an
|
|
25
|
-
* ambiguity.
|
|
111
|
+
* Checks a reply's shape and binds it to the request (rfq id, token, payment hash, chain, exact
|
|
112
|
+
* input). It does not make `lockup_address` safe to fund. Unknown fields are tolerated.
|
|
26
113
|
*/
|
|
114
|
+
declare const readEvmSendQuote: (payload: unknown, expected: {
|
|
115
|
+
tokenAddress: string;
|
|
116
|
+
rfqId: string;
|
|
117
|
+
paymentHash: string;
|
|
118
|
+
chainId: number;
|
|
119
|
+
amountSats: number;
|
|
120
|
+
}) => EvmSendQuote;
|
|
121
|
+
/** The receive-direction counterpart of {@link readEvmSendQuote}. */
|
|
122
|
+
declare const readEvmReceiveQuote: (payload: unknown, expected: {
|
|
123
|
+
tokenAddress: string;
|
|
124
|
+
rfqId: string;
|
|
125
|
+
paymentHash: string;
|
|
126
|
+
chainId: number;
|
|
127
|
+
evmAmount: bigint;
|
|
128
|
+
}) => EvmReceiveQuote;
|
|
129
|
+
/** The token leg of a quote, picked by its pair so the sats leg can never be read as tokens. */
|
|
130
|
+
declare const evmQuoteTokenAmount: (quote: EvmRfqQuote) => bigint;
|
|
131
|
+
/** The sats leg of a quote; see {@link evmQuoteTokenAmount}. */
|
|
132
|
+
declare const evmQuoteSats: (quote: EvmRfqQuote) => number;
|
|
27
133
|
|
|
28
134
|
/**
|
|
29
|
-
* The
|
|
135
|
+
* The alias table, filled from discovery: the inverse of `toDiscoveryLeg`, mapping a card's
|
|
136
|
+
* corridor and `AssetInfo` back to the public id a caller may write, plus its ticker.
|
|
30
137
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
138
|
+
* Tickers are display metadata, never identity, so `canonicalAssetId` refuses a ticker naming two
|
|
139
|
+
* assets. Rows dedupe by id and ticker, so nine solvers listing one asset is one row.
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The public id for one side of a card, or `undefined` when not expressible: an arkade-issued
|
|
144
|
+
* asset on lightning or L1, or an id that is neither BTC nor the identity form.
|
|
34
145
|
*/
|
|
35
146
|
declare const publicAssetId: (corridor: Corridor, assetId: string, network: NetworkRef) => AssetId | undefined;
|
|
147
|
+
/** The public id for one leg of a card: a CAIP-19 id as published, else the legacy id's conversion. */
|
|
148
|
+
declare const cardLegAssetId: (card: DiscoveredMarket, side: Side, network: NetworkRef) => AssetId | undefined;
|
|
36
149
|
/** Every asset the snapshot names, as caller-writable ids and their tickers. */
|
|
37
150
|
declare const aliasTableFrom: (markets: readonly DiscoveredMarket[], network: NetworkRef) => AssetAliasTable;
|
|
38
151
|
/**
|
|
39
152
|
* The table narrowed to one rail.
|
|
40
153
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* spec's own `exchange({ give: "BTC", ... })` unresolvable if the table were
|
|
45
|
-
* consulted whole. A ticker is therefore resolved on the leg's own rail: the
|
|
46
|
-
* leg's corridor is already fixed by the destination, by `via`, or by being the
|
|
47
|
-
* wallet's side, so the scope is a fact rather than a preference. Collisions
|
|
48
|
-
* WITHIN a rail — two arkade assets both called `USDT` — still refuse, which is
|
|
49
|
-
* the case the rule exists for.
|
|
154
|
+
* BTC has one id per rail (Q12), so a whole-table lookup of `"BTC"` would collide and refuse. The
|
|
155
|
+
* leg's rail is already fixed (by destination, `via`, or being the wallet's side), so resolving on
|
|
156
|
+
* it is a fact, not a preference. Collisions within a rail (two arkade `USDT`s) still refuse.
|
|
50
157
|
*/
|
|
51
158
|
declare const scopedToRail: (table: AssetAliasTable, rail: Rail) => AssetAliasTable;
|
|
52
159
|
|
|
@@ -55,9 +162,8 @@ declare const DEFAULT_INVOICE_EXPIRY_SECONDS = 3600;
|
|
|
55
162
|
/**
|
|
56
163
|
* Decode a BOLT11 invoice into the facts the corridor needs.
|
|
57
164
|
*
|
|
58
|
-
* Signature-blind, like the library:
|
|
59
|
-
*
|
|
60
|
-
* corridor will compare against is the one the payer would pay to.
|
|
165
|
+
* Signature-blind, like the library: it does not prove who issued the invoice, only that the
|
|
166
|
+
* payment hash compared downstream is the one the payer would pay to.
|
|
61
167
|
*
|
|
62
168
|
* @throws when the string is not a decodable BOLT11 invoice, or decodes without
|
|
63
169
|
* the timestamp or payment hash BOLT11 requires.
|
|
@@ -80,20 +186,13 @@ interface ChainSourceBackend {
|
|
|
80
186
|
* core's `Network` and `L1_NETWORKS`' entries both satisfy it directly. */
|
|
81
187
|
type AddressParams = typeof btc.NETWORK;
|
|
82
188
|
/**
|
|
83
|
-
* A {@link ChainSource} over an arbitrary L1 backend
|
|
84
|
-
*
|
|
85
|
-
* Separate from {@link esploraChainSource} so the adapter's logic — the
|
|
86
|
-
* confirmations arithmetic, the script-to-address encode, the missing-spender
|
|
87
|
-
* fallback — is exercisable without a server, and so a caller with its own
|
|
88
|
-
* `OnchainProvider` can reuse it.
|
|
189
|
+
* A {@link ChainSource} over an arbitrary L1 backend, so a caller with its own `OnchainProvider`
|
|
190
|
+
* can reuse the adapter logic, and tests can run it without a server.
|
|
89
191
|
*/
|
|
90
192
|
declare const chainSourceOver: (backend: ChainSourceBackend, network: AddressParams) => ChainSource;
|
|
91
193
|
/**
|
|
92
|
-
* Tip height and median-time-past off Esplora's `/blocks`.
|
|
93
|
-
*
|
|
94
|
-
* `/blocks` rather than `/blocks/tip`, for the reason core already records:
|
|
95
|
-
* the latter is not part of the Esplora spec — electrs serves it as an alias,
|
|
96
|
-
* a strict backend like mempool answers an empty array.
|
|
194
|
+
* Tip height and median-time-past off Esplora's `/blocks`. Not `/blocks/tip`: that is not in the
|
|
195
|
+
* Esplora spec (electrs aliases it, mempool answers an empty array).
|
|
97
196
|
*/
|
|
98
197
|
declare const esploraTip: (esploraUrl: string, fetchImpl?: typeof fetch) => Promise<L1Tip>;
|
|
99
198
|
/** The default: core's Esplora provider at `esploraUrl`, with the tip read off
|
|
@@ -113,44 +212,27 @@ declare const arkadeCorridor: CorridorFactory<ArkadeCorridorDeps>;
|
|
|
113
212
|
/**
|
|
114
213
|
* The lightning corridor: a BOLT11 invoice, on this wallet's network.
|
|
115
214
|
*
|
|
116
|
-
* Core
|
|
117
|
-
* and
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* The HRP-to-network table exists in neither package, so it is authored here.
|
|
122
|
-
* Two of its facts are worth stating because a test could otherwise claim more
|
|
123
|
-
* than the vocabulary can express: `lntbs` is signet AND mutinynet, which share
|
|
124
|
-
* an HRP exactly as they share `tark`, so a signet-versus-mutinynet rejection is
|
|
125
|
-
* not expressible; and `lnsb` (simnet) is admitted by core's regex — five
|
|
126
|
-
* prefixes, where §6 names four — and named by no `NetworkName`, so it is
|
|
127
|
-
* refused rather than mapped to a neighbour.
|
|
215
|
+
* Core's `isLightningInvoice` checks shape only (no checksum, no decode), so the network
|
|
216
|
+
* match and decode happen here. `lntbs` is both signet and mutinynet, so a
|
|
217
|
+
* signet-versus-mutinynet mismatch is not detectable; `lnsb` (simnet) passes core's regex
|
|
218
|
+
* but names no `NetworkName`, so it is refused rather than mapped to a neighbour.
|
|
128
219
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* headroom check needs `quote.refund_locktime` and no parse has a quote — and
|
|
132
|
-
* belong to the quote path.
|
|
220
|
+
* Gates owned here: HRP, invoice expiry, amountless refusal. Gates that need the quote
|
|
221
|
+
* (e.g. headroom vs `quote.refund_locktime`) belong to the quote path.
|
|
133
222
|
*/
|
|
134
223
|
|
|
135
224
|
/**
|
|
136
|
-
* Which networks an invoice HRP can belong to.
|
|
137
|
-
*
|
|
138
|
-
* An ordered list rather than a record, because the order is load-bearing:
|
|
139
|
-
* `lnbcrt` has to be tested before `lnbc` and `lntbs` before `lntb`, and a
|
|
140
|
-
* record would leave that to key-iteration order.
|
|
225
|
+
* Which networks an invoice HRP can belong to. Ordered, not a record: `lnbcrt` must be
|
|
226
|
+
* tested before `lnbc` and `lntbs` before `lntb`.
|
|
141
227
|
*/
|
|
142
228
|
declare const INVOICE_HRPS: readonly [readonly ["lnbcrt", readonly ["regtest"]], readonly ["lntbs", readonly ["signet", "mutinynet"]], readonly ["lnbc", readonly ["bitcoin"]], readonly ["lntb", readonly ["testnet"]]];
|
|
143
229
|
/** The networks `raw`'s HRP names, or `undefined` for one no network claims. */
|
|
144
230
|
declare const networksOfInvoiceHrp: (raw: string) => readonly NetworkName[] | undefined;
|
|
145
231
|
/**
|
|
146
|
-
* Both directions,
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* refund, since the solver claims the lockup with the preimage it learns by
|
|
151
|
-
* paying. On `lightning -> arkade` the solver funds it: every non-claim leaf is
|
|
152
|
-
* the solver's, the trader has no refund at all, and the deadline is a moment to
|
|
153
|
-
* have claimed BEFORE.
|
|
232
|
+
* Both directions, with ownership inverted. `arkade -> lightning`: the trader funds the
|
|
233
|
+
* lockup, so `refundLocktime` is a moment to refund AFTER (the solver claims with the
|
|
234
|
+
* preimage it learns by paying). `lightning -> arkade`: the solver funds it, the trader
|
|
235
|
+
* has no refund, and the deadline is a moment to have claimed BEFORE.
|
|
154
236
|
*/
|
|
155
237
|
declare const LIGHTNING_DRIVE: {
|
|
156
238
|
readonly give: {
|
|
@@ -175,20 +257,13 @@ declare const LIGHTNING_DRIVE: {
|
|
|
175
257
|
declare const lightningCorridor: CorridorFactory<LightningCorridorDeps>;
|
|
176
258
|
|
|
177
259
|
/**
|
|
178
|
-
*
|
|
260
|
+
* On `onchain -> arkade` the Arkade lockup is the solver's and the L1 HTLC's refund leaf the
|
|
261
|
+
* trader's own: the trader claims the lockup, or takes its L1 funding back after
|
|
262
|
+
* `htlc.refundLocktime`.
|
|
179
263
|
*
|
|
180
|
-
* `
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* deadline, a second observation seam AND a second action callback. Declaring
|
|
184
|
-
* the lockup half alone is what would produce a manager that silently lets the
|
|
185
|
-
* trader's L1 refund window pass.
|
|
186
|
-
*
|
|
187
|
-
* On `arkade -> onchain` the pass reads two covenants and they have different
|
|
188
|
-
* owners. The Arkade lockup is the trader's, and `refundLocktime` is the moment
|
|
189
|
-
* the money comes back. The L1 HTLC is the solver's on its refund leaf — the
|
|
190
|
-
* trader holds only the claim key — so reaching `htlc.refundLocktime` does not
|
|
191
|
-
* mean "refund the HTLC", it means the claim was missed.
|
|
264
|
+
* On `arkade -> onchain` the two covenants have different owners: the Arkade lockup is
|
|
265
|
+
* the trader's (`refundLocktime` = money comes back), but the L1 HTLC's refund leaf is
|
|
266
|
+
* the solver's, so reaching `htlc.refundLocktime` means the claim was missed.
|
|
192
267
|
*/
|
|
193
268
|
declare const ONCHAIN_DRIVE: {
|
|
194
269
|
readonly take: {
|
|
@@ -204,39 +279,38 @@ declare const ONCHAIN_DRIVE: {
|
|
|
204
279
|
readonly actions: readonly ["claimOnchain", "refundArkade"];
|
|
205
280
|
readonly seams: readonly ["indexer", "chain"];
|
|
206
281
|
};
|
|
282
|
+
readonly give: {
|
|
283
|
+
readonly lockups: readonly [{
|
|
284
|
+
readonly covenant: "arkade_lockup";
|
|
285
|
+
readonly owner: "solver";
|
|
286
|
+
readonly deadline: "refund_locktime";
|
|
287
|
+
}, {
|
|
288
|
+
readonly covenant: "onchain_htlc";
|
|
289
|
+
readonly owner: "trader";
|
|
290
|
+
readonly deadline: "htlc_refund_locktime";
|
|
291
|
+
}];
|
|
292
|
+
readonly actions: readonly ["claimLockup", "refundOnchain"];
|
|
293
|
+
readonly seams: readonly ["indexer", "chain"];
|
|
294
|
+
};
|
|
207
295
|
};
|
|
208
296
|
declare const onchainCorridor: CorridorFactory<OnchainCorridorDeps>;
|
|
209
297
|
|
|
210
298
|
/**
|
|
211
|
-
* The
|
|
212
|
-
*
|
|
213
|
-
* **The record bridge is the load-bearing one.** `RfqSwapManager` restores from
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* `restoreFromRepository` opens with `requireRepository`, so the unwired
|
|
227
|
-
* branch costs a hand-rolled restore rather than a storage-shape choice.
|
|
228
|
-
* - **It carries an `rfqId -> QuoteId` index**, because the manager keys every
|
|
229
|
-
* callback on `rfqId` while the v2 store keys on `QuoteId`. Without it
|
|
230
|
-
* `arkadeRefunder` misses its record and throws
|
|
231
|
-
* `RefundNotLocallyPossibleError` — the one refusal the manager reads as
|
|
232
|
-
* PERMANENT — leaving every v2 send leg blocked for its whole refund window
|
|
233
|
-
* with the lockup funded.
|
|
234
|
-
* - **`removeRfqSwap` is inert.** `restoreFromRepository` runs `dropRetired`
|
|
235
|
-
* before the rebuild, which would hard-delete v2 records under v1's
|
|
236
|
-
* thirty-day retention before `client.ready` resolves. v2 retention is M6's
|
|
237
|
-
* open question, and settling it here by side effect is not M5's to do. The
|
|
238
|
-
* manager still drops its in-memory copies, so an aged terminal record is not
|
|
239
|
-
* rebuilt; the record itself survives.
|
|
299
|
+
* The seams between the v2 record store and v1's drive machinery.
|
|
300
|
+
*
|
|
301
|
+
* **The record bridge is the load-bearing one.** `RfqSwapManager` restores from `getRfqSwapsPage()`,
|
|
302
|
+
* while `accept()` writes `saveSwapRecord` into a disjoint keyspace, so without this file the
|
|
303
|
+
* manager's restore returns nothing for every v2-accepted swap. {@link CorridorSwapRecord} carries
|
|
304
|
+
* every {@link RfqSwapRecord} field but the ignored display `amount`, which keeps the bridge cheap.
|
|
305
|
+
*
|
|
306
|
+
* - **The store is wired as the manager's `repository` dep**: `restoreFromRepository` opens with
|
|
307
|
+
* `requireRepository`, so leaving it unwired would mean a hand-rolled restore.
|
|
308
|
+
* - **It carries an `rfqId -> QuoteId` index**: manager callbacks key on `rfqId`. Without it
|
|
309
|
+
* `arkadeRefunder` misses its record and throws `RefundNotLocallyPossibleError` — which the
|
|
310
|
+
* manager reads as PERMANENT — blocking every v2 send leg for its refund window with funds locked.
|
|
311
|
+
* - **`removeRfqSwap` is inert**: `restoreFromRepository` runs `dropRetired` first, which would
|
|
312
|
+
* hard-delete v2 records under v1's thirty-day retention before `client.ready` resolves. v2
|
|
313
|
+
* retention is still undecided. The manager still drops its in-memory copy; the record survives.
|
|
240
314
|
*/
|
|
241
315
|
|
|
242
316
|
/** Every stored corridor record, and every offer record, in one read. */
|
|
@@ -244,25 +318,18 @@ declare const splitRecords: (records: readonly SwapRecord[]) => {
|
|
|
244
318
|
corridor: CorridorSwapRecord[];
|
|
245
319
|
offer: OfferSwapRecord[];
|
|
246
320
|
};
|
|
247
|
-
/**
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* Field for field, minus the display `amount` — `rebuildRfqSwap` reads none of
|
|
251
|
-
* it, and inventing one would put a number on the record that no request result
|
|
252
|
-
* produced.
|
|
253
|
-
*/
|
|
321
|
+
/** A v2 corridor record as the manager's own record type, minus the display `amount`
|
|
322
|
+
* (`rebuildRfqSwap` reads none, and inventing one would record a number no request produced). */
|
|
254
323
|
declare const rfqRecordOf: (record: CorridorSwapRecord) => RfqSwapRecord;
|
|
255
324
|
/**
|
|
256
|
-
* The manager's mutable half, written back onto the v2 record.
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* `claimFailure` when it becomes terminal, and a spread would only ever set
|
|
261
|
-
* these fields, never clear them — leaving a stale refusal reading as a live
|
|
262
|
-
* one. The origin half is carried through untouched, `fundingTxid` included:
|
|
263
|
-
* the manager never learns it, so it can only be the accept path's.
|
|
325
|
+
* The manager's mutable half, written back onto the v2 record. REPLACED, not merged (as
|
|
326
|
+
* `updateRfqSwapRecord` does): the manager clears `blockedReason`/`claimFailure`, and a spread could
|
|
327
|
+
* never clear them, leaving a stale refusal reading as live. The origin half, `fundingTxid`
|
|
328
|
+
* included, is carried through untouched — the manager never learns it.
|
|
264
329
|
*/
|
|
265
330
|
declare const withRfqState: (record: CorridorSwapRecord, state: RfqSwapRecord) => CorridorSwapRecord;
|
|
331
|
+
/** One keyset page over records already in memory, in the repository's `(updatedAt, rfqId)` order. */
|
|
332
|
+
declare const pageRfqRecords: (records: readonly RfqSwapRecord[], filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>) => PageResult<RfqSwapRecord, RfqSwapPageCursor>;
|
|
266
333
|
/** What a bridge or source hands back to the drive after a write. */
|
|
267
334
|
type RecordSink = (record: SwapRecord) => void;
|
|
268
335
|
interface CorridorRecordStore extends RfqSwapRecordStore {
|
|
@@ -273,36 +340,23 @@ interface CorridorRecordStore extends RfqSwapRecordStore {
|
|
|
273
340
|
quoteIdOf(rfqId: string): QuoteId | undefined;
|
|
274
341
|
}
|
|
275
342
|
/**
|
|
276
|
-
* The v2 record store, as the manager's `repository` dep.
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
* system of record, and the manager's own read-then-write per pass exists so a
|
|
280
|
-
* consumer's edit is not overwritten by a copy taken at boot. The index is the
|
|
281
|
-
* only thing held in memory, and it is a pure lookup — a miss costs one full
|
|
282
|
-
* scan and never a wrong answer.
|
|
343
|
+
* The v2 record store, as the manager's `repository` dep. Every read goes to the repository (the
|
|
344
|
+
* system of record), so a consumer's edit is never overwritten by a boot-time copy. Only the index
|
|
345
|
+
* is in memory; a miss costs one scan, never a wrong answer.
|
|
283
346
|
*/
|
|
284
347
|
declare const corridorRecordStore: (repository: AssetSwapRepository, onRecord?: RecordSink,
|
|
285
348
|
/**
|
|
286
|
-
* Which stored records the restore may hand to the manager.
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* TERMINALLY on its first pass without a `ChainSource` — a deliberate
|
|
292
|
-
* refusal to watch that corridor blind. Excluding the record here leaves it
|
|
293
|
-
* durable, undriven and reporting off itself, which is the honest answer to
|
|
294
|
-
* "this client cannot drive this swap".
|
|
295
|
-
*
|
|
296
|
-
* And a record in a terminal state, which the drive excludes: the manager
|
|
297
|
-
* would rebuild it only to file it in `finished`, so handing it over pays
|
|
298
|
-
* a covenant derivation and a contract row lookup per record for nothing.
|
|
299
|
-
* The record itself stays readable — it is still in the drive's registry
|
|
300
|
-
* and still answers off its own stored state.
|
|
349
|
+
* Which stored records the restore may hand to the manager. Two cases:
|
|
350
|
+
* - an `arkade -> onchain` record on a client whose chain source was refused — the manager would
|
|
351
|
+
* fail it TERMINALLY on its first pass; excluded, it stays durable, undriven and self-reporting;
|
|
352
|
+
* - a terminal record, which the manager would rebuild only to file as finished (a covenant
|
|
353
|
+
* derivation and row lookup for nothing). It stays readable in the drive's registry.
|
|
301
354
|
*/
|
|
302
355
|
admits?: (record: CorridorSwapRecord) => boolean) => CorridorRecordStore;
|
|
303
356
|
/** A v2 offer record as the watcher and coverage read one. */
|
|
304
357
|
declare const offerFactsOf: (record: OfferSwapRecord) => OfferSwapFacts & {
|
|
305
358
|
id: QuoteId;
|
|
359
|
+
coverageId: QuoteId;
|
|
306
360
|
};
|
|
307
361
|
/** The v2 offer half of the record store, as the watcher's source. */
|
|
308
362
|
declare const offerRecordSource: (repository: AssetSwapRepository, onRecord?: RecordSink, now?: () => number) => OfferSwapSource<OfferSwapFacts & {
|
|
@@ -310,42 +364,51 @@ declare const offerRecordSource: (repository: AssetSwapRepository, onRecord?: Re
|
|
|
310
364
|
}>;
|
|
311
365
|
/** One classified spend, written onto a v2 offer record. */
|
|
312
366
|
declare const applyOfferSpend: (record: OfferSwapRecord, changes: OfferSpendChanges, now: number) => OfferSwapRecord;
|
|
313
|
-
/**
|
|
314
|
-
|
|
367
|
+
/** What the restore scan learned about one deposit. */
|
|
368
|
+
interface DepositFate {
|
|
369
|
+
readonly status: AssetSwapStatus;
|
|
370
|
+
readonly spentTxid?: string;
|
|
371
|
+
/** Unix milliseconds, as `AssetSwap` carries it. */
|
|
372
|
+
readonly completedAt?: number;
|
|
373
|
+
}
|
|
374
|
+
/** A deposit's fate written onto its record. The spend too: the watcher only
|
|
375
|
+
* writes a spend it saw, and it sees nothing between two clients. */
|
|
376
|
+
declare const withDepositFate: (record: OfferSwapRecord, fate: DepositFate, now: number) => OfferSwapRecord;
|
|
377
|
+
/** Whether the fate says anything the record does not; the write it gates re-emits the swap. */
|
|
378
|
+
declare const fateMoved: (record: OfferSwapRecord, fate: DepositFate) => boolean;
|
|
315
379
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* is
|
|
380
|
+
* An offer record for a deposit the restore scan found and no record claims. Keyed on the funding
|
|
381
|
+
* txid so a re-scan updates rather than duplicates. The chain lacks the market, solver, spread and
|
|
382
|
+
* deadline, hence `market.kind: "restored"` and a zero fee.
|
|
383
|
+
*/
|
|
384
|
+
declare const restoredOfferRecord: (swap: AssetSwap, network: NetworkRef, now: number) => OfferSwapRecord;
|
|
385
|
+
/**
|
|
386
|
+
* A corridor record for a v1 `rfqSwaps` row. v1 kept one display `amount` and no quote, invoice or
|
|
387
|
+
* solver key, so both legs carry that amount, the fee is zero, Lightning legs stand in as
|
|
388
|
+
* `wallet`, and `market.kind` is `"restored"`. Throws when the row has no payment hash or its
|
|
389
|
+
* lockup address does not decode.
|
|
390
|
+
*/
|
|
391
|
+
declare const restoredCorridorRecord: (stored: RfqSwapRecord, network: NetworkRef, refundLocktime: number) => CorridorSwapRecord;
|
|
392
|
+
/**
|
|
393
|
+
* The wallet's own reader, as the manager's required observation seam. The reader reads NAMED
|
|
394
|
+
* foreign scripts and has no "own wallet" default, so a call with neither scripts nor outpoints is a
|
|
395
|
+
* caller bug. Built from the wallet (the client takes no server URL or provider); the drive still
|
|
396
|
+
* takes it as an input so unit tests can double it.
|
|
325
397
|
*/
|
|
326
398
|
declare const walletLockupIndexer: (wallet: IWallet) => LockupSpendIndexer;
|
|
327
399
|
|
|
328
400
|
/**
|
|
329
|
-
* Route resolution: the single place `to` is parsed, the corridor pair
|
|
330
|
-
*
|
|
331
|
-
* to happen before a solver is told anything.
|
|
401
|
+
* Route resolution: the single place `to` is parsed, the corridor pair decided, the
|
|
402
|
+
* amount pinned and the market chosen — everything before a solver is told anything.
|
|
332
403
|
*
|
|
333
|
-
* The order
|
|
334
|
-
*
|
|
335
|
-
* market
|
|
336
|
-
*
|
|
337
|
-
* `Route` variant — a pair outside the union is `UnsupportedRoute` here, before
|
|
338
|
-
* an RFQ round trip, an artifact or a record. Only then does the market index
|
|
339
|
-
* come in, and only then can a ticker be canonicalized, since the table a ticker
|
|
340
|
-
* resolves against is built out of the cards themselves.
|
|
341
|
-
*
|
|
342
|
-
* The amount is pinned last and before any network call: exactly one may be
|
|
343
|
-
* pinned, by the caller or by an invoice, and two is `AmountMismatch` — thrown
|
|
344
|
-
* with nothing disclosed, which is the whole reason it is thrown here.
|
|
404
|
+
* The order (§3.1) is load-bearing: `to` first (needs no market data); the pair selects
|
|
405
|
+
* the `Route` variant, refusing unsupported pairs before any round trip or record; only
|
|
406
|
+
* then the market index, since tickers resolve against the cards themselves. Exactly one
|
|
407
|
+
* amount may be pinned; two is `AmountMismatch`, thrown here so nothing is disclosed.
|
|
345
408
|
*/
|
|
346
409
|
|
|
347
|
-
/** The
|
|
348
|
-
declare const SUPPORTED_PAIRS: readonly ["arkade->arkade", "arkade->lightning", "lightning->arkade", "arkade->onchain"];
|
|
410
|
+
/** The five implemented corridor pairs, spelled as the route union spells them. */
|
|
411
|
+
declare const SUPPORTED_PAIRS: readonly ["arkade->arkade", "arkade->lightning", "lightning->arkade", "arkade->onchain", "onchain->arkade"];
|
|
349
412
|
type SupportedPair = (typeof SUPPORTED_PAIRS)[number];
|
|
350
413
|
interface ResolveDeps {
|
|
351
414
|
readonly corridors: CorridorSet;
|
|
@@ -354,12 +417,8 @@ interface ResolveDeps {
|
|
|
354
417
|
readonly discovery: DiscoveryIndex;
|
|
355
418
|
readonly policy?: SwapPolicy;
|
|
356
419
|
/**
|
|
357
|
-
* `resolve()` reads what is in hand; `quote()` may fetch.
|
|
358
|
-
*
|
|
359
|
-
* The one difference between the two paths, and the reason it is a flag
|
|
360
|
-
* rather than two functions: everything else about resolution — the parse,
|
|
361
|
-
* the pair, the pin, the veto — has to be identical, or the resolution a
|
|
362
|
-
* caller vetoed would not be the one they quoted.
|
|
420
|
+
* `resolve()` reads what is in hand; `quote()` may fetch. A flag, not two functions,
|
|
421
|
+
* so the resolution a caller vetoed is exactly the one they quote.
|
|
363
422
|
*/
|
|
364
423
|
readonly mode: "resolve" | "quote";
|
|
365
424
|
}
|
|
@@ -385,12 +444,9 @@ interface ResolvedRoute {
|
|
|
385
444
|
/**
|
|
386
445
|
* Assemble the closed `Route` from two fully-instrumented legs.
|
|
387
446
|
*
|
|
388
|
-
* The one cast
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* asset went through `toDiscoveryLeg`, which is what decided the corridor. The
|
|
392
|
-
* runtime re-check is cheap and turns a broken invariant into a throw at the
|
|
393
|
-
* boundary rather than a covenant built against the wrong rail.
|
|
447
|
+
* The quote path's one cast: the type checker cannot correlate `corridor` and `asset`,
|
|
448
|
+
* so the runtime re-check turns a broken invariant into a throw rather than a covenant
|
|
449
|
+
* built against the wrong rail.
|
|
394
450
|
*/
|
|
395
451
|
declare const assembleRoute: (give: ResolvedEndpoint & {
|
|
396
452
|
instrument: Instrument;
|
|
@@ -403,46 +459,25 @@ declare const resolveRoute: (input: QuoteInput, deps: ResolveDeps) => Promise<Re
|
|
|
403
459
|
declare const satsOf: (value: bigint, field: string) => number;
|
|
404
460
|
|
|
405
461
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* v1 spreads these checks across four request entrypoints and reaches the offer
|
|
409
|
-
* path with none of them: `expectQuote` compares type, id and pair;
|
|
410
|
-
* `verifyLockupAddress` compares the derived address; `assertFundable`,
|
|
411
|
-
* `verifyReceiveInvoice` and `assertReceivable` gate expiry, headroom and the
|
|
412
|
-
* claim window on some legs and not others; and the docs push the rest — plan
|
|
413
|
-
* validation, the rendezvous choice, the invoice decode — onto the caller. This
|
|
414
|
-
* module runs the whole set, once, on both backends, before any quote is
|
|
415
|
-
* returned, and every failure is one error class with the check named on it.
|
|
462
|
+
* Quote verification as one invariant: every check runs once, on both backends, before any quote
|
|
463
|
+
* is returned, and every failure is one error class naming the check.
|
|
416
464
|
*
|
|
417
|
-
* The gates themselves
|
|
418
|
-
* constants
|
|
419
|
-
* covenant's own timing, and re-implementing them here would be a second
|
|
420
|
-
* opinion where the whole point is that there is one. What this adds is the
|
|
421
|
-
* mapping: a gate's stable `reason` becomes a {@link QuoteCheck}, so a caller
|
|
422
|
-
* switches on the check rather than on a string the wire's own vocabulary
|
|
423
|
-
* leaked.
|
|
465
|
+
* The gates themselves stay `rfq.ts`'s (audited, and carrying the covenant-mirroring timing
|
|
466
|
+
* constants); this only maps a gate's stable `reason` to a {@link QuoteCheck}.
|
|
424
467
|
*
|
|
425
|
-
* Two failures deliberately
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
* the problem, and the remedy is a fresh quote rather than a different solver.
|
|
468
|
+
* Two failures are deliberately NOT verification failures: a solver declining is `SwapRefusal`,
|
|
469
|
+
* and an expired or expiring quote is `QuoteExpired` (the remedy is a fresh quote, not a
|
|
470
|
+
* different solver).
|
|
429
471
|
*/
|
|
430
472
|
|
|
431
473
|
/**
|
|
432
474
|
* The fifth check: who answered.
|
|
433
475
|
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* caller can turn off by handing in a different transport, and verification that
|
|
437
|
-
* configuration can disable is not an invariant. So the transport delivers the
|
|
438
|
-
* attestation and this runs it, in addressed mode only: published RFQ has N
|
|
439
|
-
* unknown responders and attributes each bid by its own signature instead.
|
|
476
|
+
* Run here, not left to the transport, so swapping in a different transport cannot disable it.
|
|
477
|
+
* Addressed mode only: published RFQ attributes each bid by its own signature.
|
|
440
478
|
*
|
|
441
|
-
* `pinnable` is the trust boundary
|
|
442
|
-
*
|
|
443
|
-
* unvalidated — so a snapshot read back out of local storage cannot supply it,
|
|
444
|
-
* and the check fails closed rather than pinning against content anyone with
|
|
445
|
-
* write access to the browser's storage could have chosen.
|
|
479
|
+
* `pinnable` is the trust boundary: a cached card's `discovery_pubkey` is unvalidated (anyone with
|
|
480
|
+
* write access to browser storage could choose it), so a cache-sourced key fails closed.
|
|
446
481
|
*/
|
|
447
482
|
declare const verifyResponder: (input: {
|
|
448
483
|
/** The key this transport proves every reply came from, if it proves one. */
|
|
@@ -453,24 +488,15 @@ declare const verifyResponder: (input: {
|
|
|
453
488
|
readonly pinnable: boolean;
|
|
454
489
|
}) => void;
|
|
455
490
|
/**
|
|
456
|
-
* The pair check, run here as well as in the transport
|
|
457
|
-
*
|
|
458
|
-
* `expectQuote` already compares it — this is not a gap being filled but the
|
|
459
|
-
* layer that OWNS the string doing its own comparison, so a transport that
|
|
460
|
-
* skips the check (or one a caller injected) cannot make the quote path skip it
|
|
461
|
-
* too. v1 documented this one as the caller's job, in bold.
|
|
491
|
+
* The pair check, run here as well as in the transport's `expectQuote`, so a transport that skips
|
|
492
|
+
* it (or one a caller injected) cannot make the quote path skip it too.
|
|
462
493
|
*/
|
|
463
494
|
declare const verifyPair: (quoted: unknown, requested: string) => void;
|
|
464
495
|
/**
|
|
465
|
-
* Derive the covenant, and fold every way that can fail into
|
|
496
|
+
* Derive the covenant, and fold every way that can fail into the `lockup_address` check.
|
|
466
497
|
*
|
|
467
|
-
* `AddressMismatch` is
|
|
468
|
-
*
|
|
469
|
-
* error would leave two classes for one condition across the v1/v2 seam. The
|
|
470
|
-
* other failures — a missing binding field, malformed hex from the solver — are
|
|
471
|
-
* the same check reached from further back: an address that cannot be derived
|
|
472
|
-
* cannot be compared, and both mean the same thing to a caller, which is do not
|
|
473
|
-
* fund this.
|
|
498
|
+
* `AddressMismatch` is that check under its v1 name; a missing binding field or malformed solver
|
|
499
|
+
* hex is the same check reached earlier. All mean "do not fund this".
|
|
474
500
|
*/
|
|
475
501
|
declare const verifyingDerivation: <T>(derive: () => T) => T;
|
|
476
502
|
/**
|
|
@@ -493,10 +519,8 @@ declare const verifySendWindow: (input: {
|
|
|
493
519
|
* The receive legs' window gate, measured from the pay deadline rather than
|
|
494
520
|
* from now.
|
|
495
521
|
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
* what can actually run out is the hold invoice. The window that matters is
|
|
499
|
-
* therefore the one left after a payer pays at the last possible moment.
|
|
522
|
+
* `refund_locktime` is the SOLVER's here, so BIP-113 lag extends the trader's claim window; what
|
|
523
|
+
* can run out is the hold invoice, so the window that matters is after a last-moment payment.
|
|
500
524
|
*/
|
|
501
525
|
declare const verifyReceiveWindow: (input: {
|
|
502
526
|
readonly quote: RfqQuote;
|
|
@@ -505,13 +529,8 @@ declare const verifyReceiveWindow: (input: {
|
|
|
505
529
|
readonly now: number;
|
|
506
530
|
}) => void;
|
|
507
531
|
/**
|
|
508
|
-
* The invoice check on a send:
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* Both halves matter. A quote whose `to_amount` is not the invoice's amount is
|
|
512
|
-
* not a quote for this invoice — the BOLT11 profile is exact-out and the
|
|
513
|
-
* invoice is the amount pin. A `from_amount` below it is a negative spread,
|
|
514
|
-
* which is not a quote at all.
|
|
532
|
+
* The invoice check on a send: `to_amount` must equal the invoice amount (BOLT11 is exact-out),
|
|
533
|
+
* and `from_amount` below it is a negative spread.
|
|
515
534
|
*/
|
|
516
535
|
declare const verifySendInvoice: (input: {
|
|
517
536
|
/** The amount the trader's own decode read off the invoice. */
|
|
@@ -523,15 +542,10 @@ declare const verifySendInvoice: (input: {
|
|
|
523
542
|
* The invoice check on a receive: bind the SOLVER's hold invoice to this swap's
|
|
524
543
|
* hash and to the quote.
|
|
525
544
|
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* reason: that gate compares the decoded amount against `quote.from_amount` as a
|
|
531
|
-
* JS number, and under the amount migration that field arrives as either a
|
|
532
|
-
* number or a string. A `!==` between a string and a number is always true, and
|
|
533
|
-
* a check that always fails is not safer than one that compares the decoded
|
|
534
|
-
* bigint — it just refuses every quote from a solver that already migrated.
|
|
545
|
+
* The one attack on this corridor with no on-chain trace: an invoice on another payment hash is
|
|
546
|
+
* paid to the solver in full and no lockup on `H` is ever funded. Not delegated to
|
|
547
|
+
* `verifyReceiveInvoice`, which compares against `quote.from_amount` as a JS number; mid amount
|
|
548
|
+
* migration that field may be a string, and `!==` would refuse every migrated solver.
|
|
535
549
|
*/
|
|
536
550
|
declare const verifyReceiveInvoiceFacts: (input: {
|
|
537
551
|
readonly invoice: string;
|
|
@@ -545,13 +559,8 @@ declare const verifyReceiveInvoiceFacts: (input: {
|
|
|
545
559
|
payDeadline: number;
|
|
546
560
|
};
|
|
547
561
|
/**
|
|
548
|
-
* The policy floor on a quote's remaining life
|
|
549
|
-
*
|
|
550
|
-
* One layer above the wire's own refusal of a quote already past `valid_until`:
|
|
551
|
-
* that one says the terms are dead, this one says they will be before the caller
|
|
552
|
-
* can use them. Only the caller knows how long their flow takes between seeing
|
|
553
|
-
* terms and accepting them, so the floor is theirs to set — and with none set,
|
|
554
|
-
* only expiry itself refuses.
|
|
562
|
+
* The policy floor on a quote's remaining life: refuses terms that will expire before the caller
|
|
563
|
+
* can use them. With no floor set, only expiry itself refuses.
|
|
555
564
|
*/
|
|
556
565
|
declare const verifyQuoteTtl: (input: {
|
|
557
566
|
readonly quoteId: QuoteId;
|
|
@@ -560,18 +569,21 @@ declare const verifyQuoteTtl: (input: {
|
|
|
560
569
|
readonly floorSeconds?: number;
|
|
561
570
|
}) => void;
|
|
562
571
|
/**
|
|
563
|
-
* The
|
|
564
|
-
*
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
572
|
+
* The policy ceiling on how long a send's funds stay locked: a solver that never pays could
|
|
573
|
+
* otherwise hold them for as long as it quotes.
|
|
574
|
+
*/
|
|
575
|
+
declare const verifyRefundWindow: (input: {
|
|
576
|
+
readonly refundLocktime: number;
|
|
577
|
+
/** A send's solo-refund CSV delay. */
|
|
578
|
+
readonly refundWithoutReceiverDelay?: number;
|
|
579
|
+
readonly now: number;
|
|
580
|
+
readonly maxSeconds?: number;
|
|
581
|
+
}) => void;
|
|
582
|
+
/**
|
|
583
|
+
* The quote answers the request that was made: the pinned side must not be repriced.
|
|
569
584
|
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* quoted, which on the wire is the pair plus the pinned side. The closed
|
|
573
|
-
* {@link QuoteCheck} union gains no member for it, and the strings say exactly
|
|
574
|
-
* what disagreed.
|
|
585
|
+
* Reported as the `pair` check, since the trade's identity on the wire is the pair plus the pinned
|
|
586
|
+
* side; {@link QuoteCheck} gains no member for it.
|
|
575
587
|
*/
|
|
576
588
|
declare const verifyQuotedAmount: (input: {
|
|
577
589
|
readonly pair: string;
|
|
@@ -582,6 +594,35 @@ declare const verifyQuotedAmount: (input: {
|
|
|
582
594
|
readonly give: bigint;
|
|
583
595
|
readonly take: bigint;
|
|
584
596
|
}) => void;
|
|
597
|
+
/**
|
|
598
|
+
* The quote answers the request, on a pair whose two legs carry **different
|
|
599
|
+
* assets**.
|
|
600
|
+
*
|
|
601
|
+
* Everything {@link verifyQuotedAmount} establishes except the one check that
|
|
602
|
+
* does not survive the change of asset: `take > give` is a mispricing when both
|
|
603
|
+
* legs are BTC and is the normal shape of a trade when they are not — 10_000
|
|
604
|
+
* sats for 1_000 cents reads one way round, and the reverse trade reads the
|
|
605
|
+
* other. Comparing them would refuse a correct quote on one direction of every
|
|
606
|
+
* asset market, which is why this is a separate function rather than a flag.
|
|
607
|
+
*
|
|
608
|
+
* What replaces it is positivity on both legs: a zero payout is not a trade,
|
|
609
|
+
* and it is the only cross-asset statement about the two numbers that means
|
|
610
|
+
* anything without a price.
|
|
611
|
+
*/
|
|
612
|
+
declare const verifyCrossAssetAmount: (input: {
|
|
613
|
+
readonly pair: string;
|
|
614
|
+
readonly pinned: {
|
|
615
|
+
on: "give" | "take";
|
|
616
|
+
value: bigint;
|
|
617
|
+
};
|
|
618
|
+
readonly give: bigint;
|
|
619
|
+
readonly take: bigint;
|
|
620
|
+
}) => void;
|
|
621
|
+
/**
|
|
622
|
+
* The solver's carrier for an asset deposit, well-formed. Reported as the `pair` check, like the
|
|
623
|
+
* amounts: it is sats the trader funds on top of the quoted give leg.
|
|
624
|
+
*/
|
|
625
|
+
declare const verifiedCarrierSats: (quote: RfqQuote) => bigint;
|
|
585
626
|
|
|
586
627
|
/**
|
|
587
628
|
* `retryable` is the point of the type: a 400 says the packet does not bind to
|
|
@@ -602,7 +643,7 @@ interface CovclaimdInfo {
|
|
|
602
643
|
/** Compressed hex — feeds `requestLightningReceive`'s `emulatorPubkey`. */
|
|
603
644
|
emulatorPubkey: string;
|
|
604
645
|
}
|
|
605
|
-
/** The
|
|
646
|
+
/** The fields `POST /v1/reveal` takes. */
|
|
606
647
|
interface RevealParams {
|
|
607
648
|
/** The funded lockup's Arkade address, bech32m. */
|
|
608
649
|
swapAddress: string;
|
|
@@ -610,6 +651,8 @@ interface RevealParams {
|
|
|
610
651
|
ciphertext: string;
|
|
611
652
|
/** The covenant's `enforcePayTo` ArkadeScript, base64. */
|
|
612
653
|
arkadeScript: string;
|
|
654
|
+
/** The `minAmount` {@link ciphertext} was sealed with, in sats; omit for an unbound one. */
|
|
655
|
+
minAmount?: bigint;
|
|
613
656
|
/** The lockup's serialized taptree, hex. */
|
|
614
657
|
taptree: string;
|
|
615
658
|
}
|
|
@@ -650,8 +693,10 @@ declare function revealClaimPacket(client: CovclaimdClient, input: {
|
|
|
650
693
|
address: string;
|
|
651
694
|
/** `P`, 32 bytes, from the swap's `secrets`. */
|
|
652
695
|
preimage: Uint8Array;
|
|
696
|
+
/** Sats the lockup must carry, e.g. the record's `expectedAmount`. */
|
|
697
|
+
minAmount: bigint;
|
|
653
698
|
}): Promise<{
|
|
654
699
|
ciphertext: string;
|
|
655
700
|
}>;
|
|
656
701
|
|
|
657
|
-
export { type AddressParams, ArkadeCorridorDeps, AssetAliasTable, AssetId, type ChainSourceBackend, Corridor, CorridorFactory, type CorridorRecordStore, CorridorSet, CorridorSwapRecord, type CovclaimdClient, type CovclaimdInfo, CovclaimdRevealError, DEFAULT_INVOICE_EXPIRY_SECONDS, DiscoveryIndex, DiscoveryLeg, DiscoverySnapshot, INVOICE_HRPS, Instrument, type L1Tip, LIGHTNING_DRIVE, LightningCorridorDeps, MarketCandidate, NetworkRef, ONCHAIN_DRIVE, OfferSwapRecord, OnchainCorridorDeps, PinnedAmount, Pubkey, QuoteId, QuoteInput, Rail, type RecordSink, type ResolveDeps, ResolvedEndpoint, type ResolvedRoute, type RevealParams, Route, RouteResolution, SwapPolicy, SwapRecord, aliasTableFrom, applyOfferSpend, arkadeCorridor, assembleRoute, chainSourceOver, corridorRecordStore, covclaimdClient, decodeBolt11, esploraChainSource, esploraTip, lightningCorridor, networksOfInvoiceHrp, offerFactsOf, offerRecordSource, onchainCorridor, publicAssetId, resolveRoute, revealClaimPacket, revealFieldsFromScript, rfqRecordOf, satsOf, scopedToRail, splitRecords, verifyPair, verifyQuoteTtl, verifyQuotedAmount, verifyReceiveInvoiceFacts, verifyReceiveWindow, verifyResponder, verifySendInvoice, verifySendWindow, verifyingDerivation, walletLockupIndexer,
|
|
702
|
+
export { type AddressParams, ArkadeCorridorDeps, AssetAliasTable, AssetId, type ChainSourceBackend, Corridor, CorridorFactory, type CorridorRecordStore, CorridorSet, CorridorSwapRecord, type CovclaimdClient, type CovclaimdInfo, CovclaimdRevealError, DEFAULT_INVOICE_EXPIRY_SECONDS, type DepositFate, DiscoveryIndex, DiscoveryLeg, DiscoverySnapshot, EVM_CHAIN, type EvmReceiveQuote, type EvmReceiveQuoteProfile, type EvmRfqQuote, type EvmSendQuote, type EvmSendQuoteProfile, INVOICE_HRPS, Instrument, type L1Tip, LIGHTNING_DRIVE, LightningCorridorDeps, MarketCandidate, NetworkRef, ONCHAIN_DRIVE, OfferSwapRecord, OnchainCorridorDeps, PinnedAmount, Pubkey, QuoteId, QuoteInput, Rail, type RecordSink, type ResolveDeps, ResolvedEndpoint, type ResolvedRoute, type RevealParams, Route, RouteResolution, SwapPolicy, SwapRecord, aliasTableFrom, applyOfferSpend, arkadeCorridor, assembleRoute, cardLegAssetId, chainSourceOver, corridorRecordStore, covclaimdClient, decodeBolt11, esploraChainSource, esploraTip, evmAmountFromWire, evmAmountToWire, evmDirectionOf, evmQuoteSats, evmQuoteTokenAmount, evmReceivePair, evmReceiveRequest, evmSendPair, evmSendRequest, evmTokenLeg, evmTokenOf, fateMoved, lightningCorridor, networksOfInvoiceHrp, offerFactsOf, offerRecordSource, onchainCorridor, pageRfqRecords, publicAssetId, readEvmReceiveQuote, readEvmSendQuote, resolveRoute, restoredCorridorRecord, restoredOfferRecord, revealClaimPacket, revealFieldsFromScript, rfqRecordOf, satsOf, scopedToRail, splitRecords, verifiedCarrierSats, verifyCrossAssetAmount, verifyPair, verifyQuoteTtl, verifyQuotedAmount, verifyReceiveInvoiceFacts, verifyReceiveWindow, verifyRefundWindow, verifyResponder, verifySendInvoice, verifySendWindow, verifyingDerivation, walletLockupIndexer, withDepositFate, withRfqState };
|