@glacislabs/stablegenie-zerodelta 3.3.0 → 4.0.0

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.
@@ -0,0 +1,855 @@
1
+ /** The engine's decision on the wallet pair. `ALLOW` still permits `flaggedCategories`. */
2
+ type ComplianceDecision = "ALLOW" | "DENY" | "REVIEW" | "REMEDIATE";
3
+ /**
4
+ * The compliance object the gateway attaches to a quote (domain.Compliance in
5
+ * zd-bebop-lite `api/internal/domain/quote.go`).
6
+ *
7
+ * ⚠️ `riskCategories` / `flaggedCategories` / `blockingCategories` / `reasons` are
8
+ * DISCLOSURE-GATED upstream: the gateway withholds them unless its reason-disclosure mode is
9
+ * "all", because naming a sanctions category back to the subject can amount to tipping off. Their
10
+ * absence therefore means "not disclosed to this key", NEVER "none found" — no surface may render
11
+ * an empty list as an all-clear.
12
+ */
13
+ interface Compliance {
14
+ status?: "SCREENED" | "UNSCREENED" | string;
15
+ decision?: ComplianceDecision | string;
16
+ screenedWallets?: string[];
17
+ sourceJurisdiction?: string;
18
+ appliedPolicyIds?: string[];
19
+ appliedPolicyNames?: string[];
20
+ appliedLegislation?: string[];
21
+ riskCategories?: string[];
22
+ flaggedCategories?: string[];
23
+ blockingCategories?: string[];
24
+ reasons?: string[];
25
+ policyVersion?: string;
26
+ checkId?: string;
27
+ expiresAt?: string;
28
+ }
29
+ /** One screening source's contribution. The vendor is never named — reason about `tier`. */
30
+ interface ScreenProvider {
31
+ providerId?: string;
32
+ tier?: string;
33
+ categories?: string[];
34
+ riskScore?: number;
35
+ }
36
+ /** A standalone /screen/wallet verdict — the direct-settlement path's gate. */
37
+ interface WalletScreen {
38
+ address: string;
39
+ network?: string;
40
+ riskScore?: number;
41
+ riskCategories?: string[];
42
+ blocked: boolean;
43
+ blockingCategories?: string[];
44
+ flaggedCategories?: string[];
45
+ providers?: ScreenProvider[];
46
+ checkedAt?: string;
47
+ }
48
+ type ComplianceTone = "ok" | "warn" | "blocked" | "neutral";
49
+ /** THE copy for a DENY, in one place — shared by the chip and the panel headline. */
50
+ declare const COMPLIANCE_DENY_LABEL = "Compliance check failed";
51
+ interface ComplianceView {
52
+ tone: ComplianceTone;
53
+ /** Short line for the chip. */
54
+ label: string;
55
+ /** Headline for the detail panel. */
56
+ headline: string;
57
+ /** True only for an explicit DENY — never inferred from an absence. */
58
+ blocked: boolean;
59
+ /** REVIEW / REMEDIATE: allowed to proceed, but the payer should know. */
60
+ needsAction: boolean;
61
+ /** The engine actually screened wallets for this payment. */
62
+ screened: boolean;
63
+ }
64
+ /**
65
+ * What the decision means, in the words a payer can act on.
66
+ *
67
+ * The four-way split exists because an ABSENT decision and a FAILED one are different facts and
68
+ * used to be rendered the same. A gateway with no compliance gate configured returns no
69
+ * `compliance` object at all; calling that "checks failed" is alarmist and calling it "checks
70
+ * passed" is a lie. It is stated as absent.
71
+ */
72
+ declare function complianceView(compliance: Compliance | null | undefined, hasQuote?: boolean): ComplianceView;
73
+ /** Display name of one engine risk category. */
74
+ declare function categoryLabel(code: string): string;
75
+ /** The bare reason "head" — everything before the first ':', bundle prefix removed. */
76
+ declare function complianceReasonHead(raw: string): string;
77
+ /**
78
+ * A machine reason code as a sentence a payer can act on.
79
+ *
80
+ * Unknown heads degrade to a lightly cleaned form of the raw code rather than being dropped: a
81
+ * blocked payer with a blank reason is the worst outcome this function can produce.
82
+ */
83
+ declare function humanizeComplianceReason(raw: string): string;
84
+ type ComplianceCheckId = "location" | "screening" | "risk" | "asset" | "limits";
85
+ interface ComplianceCheck {
86
+ id: ComplianceCheckId;
87
+ label: string;
88
+ ok: boolean;
89
+ /** Raw engine reason codes attributed to this control. Humanize for display. */
90
+ reasons: string[];
91
+ /** Evidence sub-line, e.g. "2 wallets screened" or the single screened address. */
92
+ note?: string;
93
+ }
94
+ /** The row order the panel renders. */
95
+ declare const COMPLIANCE_CHECK_ORDER: readonly ComplianceCheckId[];
96
+ /**
97
+ * The DISTINCT wallets the engine screened, in the order it listed them.
98
+ *
99
+ * The engine reports the order's owner and its destination receiver, so a payment that settles
100
+ * back to the sender arrives as the SAME address twice — counting the array would print "2 wallets
101
+ * screened" for a payment with one party in it. Folding is family-dependent: hex compares
102
+ * case-insensitively (EIP-55 casing is a checksum, not an identity), anything else — a base58
103
+ * Solana key — compares EXACTLY, because lowercasing base58 merges genuinely different wallets.
104
+ */
105
+ declare function distinctScreenedWallets(compliance: Compliance | null | undefined): string[];
106
+ /**
107
+ * The 5-control checklist, derived from evidence only.
108
+ *
109
+ * Returns `[]` when no decision was issued (`tone === "neutral"`). That is the non-negotiable
110
+ * part: five green ticks for a verdict nobody issued is exactly the failure this module exists to
111
+ * prevent, and an unconfigured gate is not a set of passed checks — the caller renders the
112
+ * headline alone in that case.
113
+ *
114
+ * ► Documented reading of an ambiguous case. When a decision IS issued, a control that no reason
115
+ * names is reported as passed: the engine accumulates `reasons` as a plural SET (the list of
116
+ * causes, not the first cause), so an unnamed control is one that ran without firing. The one
117
+ * place we refuse to infer is `screening`, asserted from the status field alone.
118
+ */
119
+ declare function complianceChecks(compliance: Compliance | null | undefined, cv?: ComplianceView): ComplianceCheck[];
120
+ /** Reasons the checklist did not claim, so a reason is never silently dropped. */
121
+ declare function unattributedComplianceReasons(compliance: Compliance | null | undefined, cv?: ComplianceView): string[];
122
+ /**
123
+ * How many controls this decision actually evidences.
124
+ *
125
+ * Nothing on the payload carries a control count, so a literal number would be fabricated in the
126
+ * one panel a payer reads as reassurance. What we CAN count is the checklist controls we are
127
+ * willing to assert plus every named overlay the decision reports it applied. Deduped
128
+ * case-insensitively so an overlay listed twice is not counted twice.
129
+ */
130
+ declare function complianceControlsEvaluated(compliance: Compliance | null | undefined, cv?: ComplianceView): number;
131
+ /** The summary sentence the chip and the panel share, so they cannot word the same fact differently. */
132
+ declare function complianceControlsLine(compliance: Compliance | null | undefined, cv?: ComplianceView): string;
133
+ /**
134
+ * Synthesize the quote-shaped compliance object for a DIRECT settlement, from the standalone
135
+ * wallet screens of the two parties.
136
+ *
137
+ * A direct transfer never touches /quote — it is a plain ERC-20 `transfer` from payer to merchant
138
+ * — so the gateway's own pre-quote gate cannot run on it and the payment would otherwise settle
139
+ * with NO screening whatsoever. `plan.ts` screens both parties explicitly and passes the verdicts
140
+ * here so the panel states the truth about what ran.
141
+ *
142
+ * ⚠️ It reports `decision: "ALLOW"` ONLY when every screen came back not-blocked, and the caller
143
+ * must have already refused to build the route otherwise. Note what this decision is NOT: a
144
+ * standalone wallet screen answers "is this address on a list", so `location`, `asset` and
145
+ * `limits` were NOT evaluated — the jurisdiction/corridor/amount controls live in the quote gate,
146
+ * which a direct transfer never reaches. Those rows are reported as not-evaluated rather than
147
+ * passed, because claiming a control ran when it did not is the one failure mode this whole module
148
+ * is built to avoid.
149
+ */
150
+ declare function directComplianceFromScreens(screens: WalletScreen[]): Compliance;
151
+ /**
152
+ * The controls a DIRECT settlement can evidence.
153
+ *
154
+ * `complianceChecks` reports an unnamed control as passed, which is the right reading for a quote
155
+ * decision (the engine ran every control and named the ones that fired) and the WRONG one here:
156
+ * a wallet screen evaluated neither jurisdiction, nor the asset pair, nor the amount. This narrows
157
+ * the list to the two rows a screen genuinely evidences rather than printing five green ticks for
158
+ * three controls that never ran.
159
+ */
160
+ declare const DIRECT_CHECK_IDS: readonly ComplianceCheckId[];
161
+ /** The sub-line explaining what a direct settlement did NOT evaluate. Stated, never omitted. */
162
+ declare const DIRECT_SCOPE_NOTE = "Direct settlement moves your funds straight to the recipient, so wallet screening applies. Jurisdiction, corridor and amount policy are evaluated on routed payments.";
163
+ declare const BLOCK_LABEL_DEFAULT = "flagged by compliance screening";
164
+ /**
165
+ * The phrase for a block, from whichever categories the engine disclosed.
166
+ *
167
+ * An empty list is the NORMAL case, not an error: categories are disclosure-gated upstream and are
168
+ * withheld from most keys precisely because naming a sanctions hit back to its subject can amount
169
+ * to tipping off. The generic default is therefore the designed outcome, never a fallback that
170
+ * signals something went wrong.
171
+ */
172
+ declare function blockLabelFor(categories: readonly string[]): string;
173
+ /**
174
+ * Short tag for a reason code — "Restricted country" where `humanizeComplianceReason` returns
175
+ * "Your region (CU) isn't supported." Same head grammar, different register: this is for the
176
+ * compact sub-line, the humanizer wherever there is room for a sentence.
177
+ */
178
+ declare function complianceReasonTag(raw: string): string;
179
+ /** The tag for a decision — the first reason that has one. Empty when there is nothing to say. */
180
+ declare function complianceTagOf(compliance: Compliance | null | undefined): string;
181
+ /** `always-blocked` is the floor; `blocked` and `flagged` are the two settings a tunable may hold. */
182
+ type ScreeningOutcome = "always-blocked" | "blocked" | "flagged";
183
+ /**
184
+ * The four NON-WEAKENABLE categories. The engine answers 422 `MATRIX_NOT_WEAKENABLE` to any policy
185
+ * that tries to soften one, so "always blocked" is a guarantee of the engine rather than a property
186
+ * of whichever policy happens to be active — which is why this half is derived, not transcribed.
187
+ */
188
+ declare const FLOOR_CATEGORIES: readonly string[];
189
+ /** Categories a policy MAY tune between BLOCK and FLAG. */
190
+ declare const TUNABLE_CATEGORIES: readonly string[];
191
+ /** The outcome one category carries, or `null` when this build cannot say — dropped, never guessed. */
192
+ declare function screeningOutcomeOf(category: string): ScreeningOutcome | null;
193
+ interface ScreeningBucket {
194
+ outcome: ScreeningOutcome;
195
+ /** The card heading. */
196
+ title: string;
197
+ /** One line saying what the outcome does to an order. */
198
+ detail: string;
199
+ categories: readonly string[];
200
+ }
201
+ /** The three groups, in escalating-permissiveness order. Mirrors the dApp's `SCREENING_BUCKETS`. */
202
+ declare const SCREENING_BUCKETS: readonly ScreeningBucket[];
203
+
204
+ type Hex = `0x${string}`;
205
+ type Address = `0x${string}`;
206
+ interface Chain {
207
+ chainId: number;
208
+ name?: string;
209
+ displayName?: string;
210
+ /** Gas-token symbol ("ETH", "S", …). Used only to label a native-balance shortfall. */
211
+ nativeCurrency?: string;
212
+ escrowContract?: string;
213
+ rpcUrl?: string;
214
+ rpcUrls?: string[];
215
+ publicRpcUrl?: string;
216
+ rpc?: string;
217
+ rpcEndpoint?: string;
218
+ isEnabled?: boolean;
219
+ /** Chains the escrow SETTLES on. Only these can host the swap itself; every other chain is
220
+ * reachable as a bridge destination only. Supplied by `GET /chains`. */
221
+ isExecutionChain?: boolean;
222
+ [k: string]: unknown;
223
+ }
224
+ interface Token {
225
+ symbol: string;
226
+ name?: string;
227
+ chainId: number;
228
+ address: string;
229
+ decimals: number;
230
+ logoUrl?: string;
231
+ bridge?: string;
232
+ /** Versioned bridge family ("CCTPV2", "LayerZeroV2OFT", …). Paired with `bridge` it decides
233
+ * whether the settlement contracts can execute this deployment's destination leg. */
234
+ standard?: string;
235
+ isEnabled?: boolean;
236
+ /** Set by the gateway on the exact deployments a chained (two-leg) order can terminate in.
237
+ * Deliberately per-token, not per-chain. */
238
+ isChainedDestination?: boolean;
239
+ [k: string]: unknown;
240
+ }
241
+ interface Route {
242
+ tokenId?: string;
243
+ tokenName?: string;
244
+ fromChainId: number;
245
+ toChainId: number;
246
+ /** Token address at each end of the lane. A lane is identified by BOTH ends: the same symbol can
247
+ * be bridgeable from one chain and not another, and only the pair says which. */
248
+ fromAddress?: string;
249
+ toAddress?: string;
250
+ bridge?: string;
251
+ standard?: string;
252
+ isEnabled?: boolean;
253
+ [k: string]: unknown;
254
+ }
255
+ interface OrderRequest {
256
+ owner?: string;
257
+ bidToken?: string;
258
+ bidTokenAmount?: string | number;
259
+ askToken?: string;
260
+ askTokenAmount?: string | number;
261
+ destinationReceiver?: string;
262
+ destinationChainId?: string | number;
263
+ /** Chain the escrow executes the order on. Mandatory on-chain; the gateway always issues it. */
264
+ executionChainId?: string | number;
265
+ deadline?: string | number;
266
+ }
267
+ interface NormalizedOrder {
268
+ owner: string;
269
+ bidToken: string;
270
+ bidTokenAmount: string;
271
+ askToken: string;
272
+ askTokenAmount: string;
273
+ destinationReceiver: string;
274
+ destinationChainId: string;
275
+ executionChainId: string;
276
+ deadline: string;
277
+ }
278
+ interface Quote {
279
+ fromChainId: number;
280
+ toChainId: number;
281
+ fromToken: string;
282
+ toToken: string;
283
+ fromAmount?: string;
284
+ toAmount?: string;
285
+ finalAmount?: string;
286
+ bridge?: string;
287
+ feeBps?: number;
288
+ estimatedDuration?: number;
289
+ gasCostSource?: string;
290
+ gasCostDest?: string;
291
+ /** The gateway's compliance decision for this quote's wallet pair. Absent = gate not configured. */
292
+ compliance?: Compliance;
293
+ escrowAddress?: string;
294
+ /** Escrow on the execution chain. Informational: approve/submitOrder go to the SOURCE-chain
295
+ * escrow, which is what checkEscrow binds. */
296
+ executionEscrowAddress?: string;
297
+ executionChainId?: number | string;
298
+ /** Every leg of the order, first to last. A plain swap is one leg; a chained (RWA) quote is
299
+ * two or more, all encoded into one submitOrder call. */
300
+ orderRequests?: OrderRequest[] | null;
301
+ /** Legacy single-leg shape, accepted for backward compatibility. */
302
+ orderRequest?: OrderRequest | null;
303
+ [k: string]: unknown;
304
+ }
305
+ interface PayOption {
306
+ symbol: string;
307
+ symbolKey: string;
308
+ name: string;
309
+ chainId: number;
310
+ chainName: string;
311
+ address: string;
312
+ decimals: number;
313
+ logoUrl?: string;
314
+ bridge?: string;
315
+ sameChain?: boolean;
316
+ direct: boolean;
317
+ }
318
+ interface SolveResult {
319
+ directTransfer: boolean;
320
+ quote: Quote;
321
+ youPayRaw: string;
322
+ recipientReceivesRaw: string;
323
+ targetRaw: string;
324
+ overageBps: number;
325
+ meetsTarget: boolean;
326
+ iterations: number;
327
+ }
328
+ type PlannedTxKind = "transfer" | "approve" | "submitOrder";
329
+ interface PlannedTx {
330
+ id: string;
331
+ kind: PlannedTxKind;
332
+ label: string;
333
+ chainId: number;
334
+ to: string;
335
+ data: string;
336
+ value: string;
337
+ token?: string;
338
+ spender?: string;
339
+ escrow?: string;
340
+ amountRaw?: string;
341
+ mock?: boolean;
342
+ }
343
+ interface RouteResult {
344
+ id: string;
345
+ recommended: boolean;
346
+ state: "DIRECT" | "ROUTE" | "SHORT";
347
+ source: {
348
+ asset: string;
349
+ chainId: number;
350
+ chainName: string;
351
+ tokenAddress?: string;
352
+ decimals?: number;
353
+ amount: string;
354
+ payAmount: string;
355
+ };
356
+ receive: {
357
+ asset: string;
358
+ chainId: number;
359
+ chainName: string;
360
+ tokenAddress?: string;
361
+ decimals?: number;
362
+ amount: string;
363
+ };
364
+ routeLabel: string;
365
+ deltaLabel: string;
366
+ transactions: PlannedTx[];
367
+ quote: {
368
+ bridge?: string;
369
+ feeBps?: number;
370
+ estimatedDuration?: number;
371
+ gasCostSource?: string;
372
+ msgValue?: string;
373
+ deadline?: string;
374
+ iterations: number;
375
+ /**
376
+ * The gateway's compliance decision for THIS route's wallet pair.
377
+ *
378
+ * ⚠️ This projection used to drop it, which is why the widget could not say anything about a
379
+ * control that had already run: the payer saw a price and no evidence. It is carried verbatim
380
+ * — the panel derives, it never invents (see core/compliance.ts).
381
+ *
382
+ * Absent when the gateway has no compliance gate configured. Absent is NOT "passed": the view
383
+ * renders that case as "no decision returned" rather than as green ticks.
384
+ */
385
+ compliance?: Compliance;
386
+ };
387
+ }
388
+ interface Destination {
389
+ address: string;
390
+ chainId: number;
391
+ chainName?: string;
392
+ asset: string;
393
+ amount: string;
394
+ }
395
+ interface Plan {
396
+ mode: "zerodelta" | "swap" | "mock";
397
+ requestId: string;
398
+ expiresAt: string;
399
+ apiBase?: string;
400
+ routes: RouteResult[];
401
+ /** Wallet balances already read while choosing funding candidates. Payment UIs reuse these so
402
+ * route rendering does not trigger the same RPC scan a second time. */
403
+ fundingBalances?: Record<string, {
404
+ raw: string;
405
+ formatted: string;
406
+ }>;
407
+ /** Normalized account that `fundingBalances` belongs to. */
408
+ fundingAccount?: string;
409
+ destination: {
410
+ asset: string;
411
+ chainId: number;
412
+ chainName: string;
413
+ tokenAddress?: string;
414
+ decimals?: number;
415
+ amount: string;
416
+ address: string;
417
+ };
418
+ }
419
+ interface SwapInput {
420
+ fromChainId: number | string;
421
+ toChainId: number | string;
422
+ fromToken: string;
423
+ toToken: string;
424
+ amountIn: string;
425
+ recipient?: string;
426
+ }
427
+ interface TxHistoryEntry {
428
+ kind?: "payment" | "swap";
429
+ hash?: string;
430
+ /** The on-chain KIND of the recorded hash. History records only the SETTLING tx (transfer /
431
+ * submitOrder), never the allowance `approve` — this discriminator lets the UI defend that. */
432
+ txKind?: PlannedTxKind;
433
+ chainId?: number;
434
+ chainName?: string;
435
+ fromAsset?: string;
436
+ toAsset?: string;
437
+ payAmount?: string;
438
+ receiveAmount?: string;
439
+ /** The signer (payer) — history is scoped per connected wallet. */
440
+ account?: string;
441
+ recipient?: string;
442
+ settlement?: "direct" | "escrow";
443
+ status?: "confirmed" | "unconfirmed" | "error" | "submitted";
444
+ }
445
+ /** A display-safe, sanitized history entry (no keys/calldata/secrets). */
446
+ interface SanitizedTxEntry {
447
+ kind: "payment" | "swap";
448
+ hash: string;
449
+ /** On-chain tx kind of `hash`. Always the settling tx (never `approve`) when set by the engine;
450
+ * optional for backward-compatibility with entries persisted before this field existed. */
451
+ txKind?: PlannedTxKind;
452
+ chainId: number | null;
453
+ chainName: string;
454
+ fromAsset: string;
455
+ toAsset: string;
456
+ payAmount: string;
457
+ receiveAmount: string;
458
+ /** Normalized signer address, or "" when unknown. */
459
+ account: string;
460
+ recipient: string;
461
+ settlement: "direct" | "escrow";
462
+ status: "confirmed" | "unconfirmed" | "error" | "submitted";
463
+ at: string;
464
+ }
465
+ /** Config injected into the engine by the host application. */
466
+ interface EngineConfig {
467
+ /** Request base. Default: {@link DEFAULT_WIDGET_API_BASE} (same-origin keyless proxy). */
468
+ apiBase?: string;
469
+ /** Optional viewer key. Attached as x-api-key ONLY when canAttachApiKey passes — i.e. a
470
+ * same-origin (relative) `apiBase`, or an absolute one matching {@link trustedApiOrigin}.
471
+ * Not needed against the keyless proxy, which injects the key server-side. */
472
+ apiKey?: string;
473
+ getApiKey?: () => string | Promise<string>;
474
+ /** Absolute origin that may receive `apiKey` when `apiBase` is absolute (e.g.
475
+ * `https://pay.example.com`). Omit and no absolute origin is trusted — same-origin only.
476
+ *
477
+ * There is no built-in default on purpose: the correct trusted origin is whichever proxy YOU
478
+ * deploy, so only this integration can know it. Set it to an origin you control — it is the
479
+ * sole destination permitted to receive the key. */
480
+ trustedApiOrigin?: string;
481
+ /** Injectable fetch (tests / SSR). Defaults to global fetch. */
482
+ fetchImpl?: typeof fetch;
483
+ /** Per-chain RPC overrides for settlement verification / balances. */
484
+ rpcOverrides?: Record<number, string>;
485
+ /** Called with a display-safe history entry after a submit (optional persistence). */
486
+ onTransaction?: (entry: SanitizedTxEntry) => void;
487
+ }
488
+ type FetchQuoteFn = (body: Record<string, unknown>, retries?: number) => Promise<Quote>;
489
+
490
+ /**
491
+ * Which product a catalogue is being built for.
492
+ *
493
+ * The ZeroDelta dapp runs two over one gateway, and they differ in more than a token list:
494
+ *
495
+ * stable stable ⇄ stable. Both legs must execute through CCTP V2 or LayerZero V2 OFT, so the
496
+ * route projection is filtered to those families and a token is admitted only when a
497
+ * published lane touches it.
498
+ * rwa stable ⇄ real-world asset, EXACTLY ONE LEG OF EACH. The vault shares publish no route
499
+ * rows at all — they are delivered by a CHAINED two-leg order and marked
500
+ * `isChainedDestination` on the destination deployment — so requiring a lane here would
501
+ * empty the picker of every asset the product exists to trade.
502
+ */
503
+ type ExchangeProduct = "stable" | "rwa";
504
+ /** The asset class of a symbol, or null when this build does not price it at all. */
505
+ declare function assetClassOf(symbol: string | undefined | null): "stable" | "rwa" | null;
506
+ /** The asset universe of a product, before any host narrowing. */
507
+ declare function productAssets(product: ExchangeProduct): ReadonlySet<string>;
508
+ /**
509
+ * The other side of an RWA pair.
510
+ *
511
+ * Exactly one leg of an RWA order is the real-world asset: picking a vault share on one side leaves
512
+ * only stables on the other, and the reverse. Without this the form would offer stable→stable and
513
+ * share→share pairs the gateway refuses, on a surface whose entire purpose is the RWA.
514
+ *
515
+ * With nothing selected yet the RWA side is offered, because that is the choice the user came to
516
+ * make; the stable side then narrows to match.
517
+ */
518
+ declare function counterpartTokens(tokens: readonly Token[], selected: Pick<Token, "symbol"> | null | undefined): Token[];
519
+ /** `chainId:address` — the identity of ONE token deployment. */
520
+ declare function tokenKey(chainId: number | string, address: string): string;
521
+ /** One lane, keyed by BOTH ends. See {@link laneKeys} for why the source end matters. */
522
+ declare function laneKey(fromChainId: number | string, fromAddress: string, toChainId: number | string, toAddress: string): string;
523
+ /**
524
+ * The only bridge/standard pairs whose adapters can execute the destination leg of a
525
+ * stable-to-stable order.
526
+ *
527
+ * Both fields are matched so a stale or malformed registry row cannot be promoted merely because it
528
+ * says "LayerZero". The versioned standard is required: an ambiguous "OFT" must not admit a
529
+ * LayerZero V1 asset such as DAI, which the escrow owns no adapter for.
530
+ */
531
+ declare function isExecutableBridge(descriptor: {
532
+ bridge?: string;
533
+ standard?: string;
534
+ } | null | undefined): boolean;
535
+ /**
536
+ * A token whose config declares `bridge: "None"` is one the escrow owns no adapter for (Chainlink
537
+ * CCT, Wormhole NTT, the M0 Portal, LayerZero V1). The gateway emits no route rows for those.
538
+ *
539
+ * The test needs a POSITIVE answer: an absent `bridge` means we do not know, and "do not know" must
540
+ * not demote a token the route projection has already proved bridgeable.
541
+ */
542
+ declare function isKnownUnbridgeable(bridge: string | undefined): boolean;
543
+ /** Enabled lanes whose bridge family the settlement contracts can actually execute. */
544
+ declare function executableRoutes(routes: readonly Route[]): Route[];
545
+ /** Deployments a token can be bridged OUT of — the bid side. */
546
+ declare function sourceKeys(routes: readonly Route[]): Set<string>;
547
+ /**
548
+ * Deployments a token can be bridged IN to — the ask side.
549
+ *
550
+ * Deliberately a separate projection from the source keys: a lane can be destination-only, so
551
+ * inferring one direction from the other would either hide a valid destination or offer a source the
552
+ * escrow refuses.
553
+ */
554
+ declare function destinationKeys(routes: readonly Route[]): Set<string>;
555
+ /**
556
+ * Lanes keyed by both ends, for the one case where the source matters.
557
+ *
558
+ * {@link destinationKeys} collapses every route to where it ENDS, which is right for a swap: the
559
+ * order goes source → execution chain → destination, and the source only has to reach the execution
560
+ * chain. It is wrong for a SAME-SYMBOL pair, which the escrow short-circuits onto the direct path,
561
+ * where `bridgeDirect` runs on the SOURCE adapter and needs a real source→destination peer. "Some
562
+ * route ends at USDe on Base" is true from Ethereum and false from Optimism, and the collapsed set
563
+ * cannot tell those apart.
564
+ */
565
+ declare function laneKeys(routes: readonly Route[]): Set<string>;
566
+ /** Chains the escrow settles on, from `GET /chains`. */
567
+ declare function executionChainIds(chains: readonly Chain[]): Set<number>;
568
+ /** Symbols deliverable on an execution chain — what makes "you can still receive this on Ethereum" a
569
+ * true statement rather than a guess. */
570
+ declare function hubDeliverableSymbols(tokens: readonly Token[], execution: ReadonlySet<number>): Set<string>;
571
+ /** A measured refusal, as {@link destinationAvailability} consumes it. */
572
+ interface BrokenLane {
573
+ /** Human label, e.g. `AUSD@8453 -> PYUSD@98866`. */
574
+ route: string;
575
+ /** The gateway's own error code, e.g. `QUOTE_UNAVAILABLE`. */
576
+ code: string;
577
+ /** The gateway's own message, verbatim. */
578
+ message: string;
579
+ kind?: string;
580
+ }
581
+ interface CatalogueContext {
582
+ /** From {@link sourceKeys}. */
583
+ source: ReadonlySet<string>;
584
+ /** From {@link destinationKeys}. */
585
+ destination: ReadonlySet<string>;
586
+ /** From {@link laneKeys}. Optional: without it the same-symbol direct-peer check is skipped. */
587
+ lanes?: ReadonlySet<string>;
588
+ /** From {@link executionChainIds}. */
589
+ execution: ReadonlySet<number>;
590
+ /** Chains a payment may be SENT FROM — `SUPPORTED_CHAIN_IDS` ∩ the enabled registry chains. */
591
+ sourceChains: ReadonlySet<number>;
592
+ /** From {@link hubDeliverableSymbols}. */
593
+ hubSymbols: ReadonlySet<string>;
594
+ /**
595
+ * Lanes the gateway's background prober has MEASURED refusing, keyed by {@link laneKey}. Absent
596
+ * means EMPTY — a health response that has not arrived, or a gateway in observe mode, demotes
597
+ * nothing.
598
+ *
599
+ * This is the one input that is not an inference. Everything else here reasons about what SHOULD
600
+ * work; this says what was actually tried and did not.
601
+ */
602
+ brokenLanes?: ReadonlyMap<string, BrokenLane>;
603
+ }
604
+ /**
605
+ * Can this deployment fund a payment?
606
+ *
607
+ * A published route can add a payout-only chain to the destination catalogue, but it cannot make
608
+ * that chain safe to transact on: a source must also be a chain this widget pins an escrow and a
609
+ * bundled RPC for, because that is where `approve`, `submitOrder` and settlement verification run.
610
+ */
611
+ declare function isSourceToken(token: Token, ctx: Pick<CatalogueContext, "source" | "execution" | "sourceChains">): boolean;
612
+ /**
613
+ * `available` — we can deliver this token on this chain.
614
+ * `hub-only` — the asset exists here but we cannot deliver it here; it IS deliverable on an
615
+ * execution chain.
616
+ * `unreachable` — we cannot deliver it anywhere the form can currently reach.
617
+ */
618
+ type Availability = "available" | "hub-only" | "unreachable";
619
+ /**
620
+ * The measured refusal for this exact (source, destination) pair, if there is one.
621
+ *
622
+ * ⚠️ Deliberately keyed on BOTH ends. Most measured failures are lane gaps rather than a dead
623
+ * destination — a token that refuses from one source quotes fine from three others — so suppressing
624
+ * the destination alone would remove working routes to fix one broken one.
625
+ */
626
+ declare function brokenLaneFor(token: Pick<Token, "chainId" | "address">, source: Pick<Token, "chainId" | "address"> | undefined, brokenLanes: ReadonlyMap<string, BrokenLane> | undefined): BrokenLane | undefined;
627
+ /**
628
+ * Whether an ask token can actually be delivered on its own chain.
629
+ *
630
+ * Without this the picker lists every enabled token and lets the gateway reject the pair, which
631
+ * surfaces as an unexplained 422 — that reads as the product being broken rather than the asset
632
+ * being undeliverable there.
633
+ */
634
+ declare function destinationAvailability(token: Token, ctx: CatalogueContext, source?: Pick<Token, "symbol" | "chainId" | "address"> | null): Availability;
635
+ /**
636
+ * Can anything at all be delivered when paying WITH this token?
637
+ *
638
+ * {@link isSourceToken} only asks whether a token can LEAVE its chain, never whether there is
639
+ * anywhere to land — so a deployment whose every destination is refused stayed fully selectable: the
640
+ * picker offered it, the user chose it, and the destination list then came back empty with no
641
+ * explanation.
642
+ *
643
+ * `hub-only` does not count: that destination cannot be delivered as asked, and offering the source
644
+ * on the strength of it reproduces the same dead end one step later.
645
+ *
646
+ * ⚠️ Answers `true` whenever it cannot know — an empty catalogue must read as "has destinations".
647
+ */
648
+ declare function hasReachableDestination(source: Token, catalogue: readonly Token[], ctx: CatalogueContext): boolean;
649
+ interface CatalogueInput {
650
+ chains: readonly Chain[];
651
+ tokens: readonly Token[];
652
+ routes: readonly Route[];
653
+ /** Which product this catalogue is for. Defaults to `"stable"`. */
654
+ product?: ExchangeProduct;
655
+ /** A host narrowing, INTERSECTED with the product's own universe. Omit for the whole product. */
656
+ allowedAssets?: ReadonlySet<string>;
657
+ /** Chains a payment may be SENT FROM — `SUPPORTED_CHAIN_IDS`. */
658
+ supportedChainIds: ReadonlySet<number>;
659
+ /** Measured refusals; omit or pass an empty map to suppress nothing. */
660
+ brokenLanes?: ReadonlyMap<string, BrokenLane>;
661
+ }
662
+ interface Catalogue extends CatalogueContext {
663
+ /** The product this catalogue was built for. */
664
+ product: ExchangeProduct;
665
+ /** Every deployment the widget may show, either side. */
666
+ tokens: Token[];
667
+ /** Deployments that can fund a payment, and that have somewhere to land. */
668
+ sources: Token[];
669
+ /** Chain ids that appear anywhere in the catalogue — sources plus payout-only destinations. */
670
+ chainIds: Set<number>;
671
+ /** Registry chains, plus a synthesised row per payout-only destination chain. */
672
+ chains: Chain[];
673
+ /**
674
+ * True once the registry has told us enough to give a verdict. While false the UI must claim
675
+ * nothing: every "unreachable" would be a confident negative derived from absent data.
676
+ *
677
+ * Requires a NON-EMPTY result, not merely two responses. A payload that arrives without the fields
678
+ * these rules read — `standard` on a token, addresses on a route — projects to an empty catalogue,
679
+ * and treating that as "ready" turns a thin response into "this product supports nothing": the pay
680
+ * flow refuses to build a plan at all rather than letting the gateway answer. An empty projection
681
+ * is something we failed to learn, not something we learned.
682
+ */
683
+ ready: boolean;
684
+ }
685
+ /**
686
+ * Build the selectable catalogue from the live registry.
687
+ *
688
+ * Mirrors the dapp's Swap page: sources are bounded by the escrow chains, destinations are not —
689
+ * receiving does not require a wallet, an RPC, or an escrow on the far chain, only a published
690
+ * route. That asymmetry is why the dapp offers ~31 destination chains against 9 sources, and it is
691
+ * the single biggest reason the widget's catalogue used to be a fraction of the dapp's.
692
+ */
693
+ declare function buildCatalogue(input: CatalogueInput): Catalogue;
694
+
695
+ /** One lane as the gateway reports it. Permissive on purpose — this is untrusted API data and the
696
+ * projection below reads only what it needs. */
697
+ interface RouteHealthLane {
698
+ laneKey?: string;
699
+ route?: string;
700
+ status?: string;
701
+ kind?: string;
702
+ code?: string;
703
+ message?: string;
704
+ [k: string]: unknown;
705
+ }
706
+ interface RouteHealth {
707
+ /** `enforce` = the operator has armed suppression. `observe` = data for dashboards only. */
708
+ mode?: string;
709
+ scope?: string;
710
+ summary?: {
711
+ healthy?: number;
712
+ degraded?: number;
713
+ broken?: number;
714
+ unknown?: number;
715
+ total?: number;
716
+ };
717
+ measuredAt?: string;
718
+ lastSweepAt?: string;
719
+ lanes?: RouteHealthLane[];
720
+ [k: string]: unknown;
721
+ }
722
+ /**
723
+ * The lanes the picker must stop offering, keyed by `laneKey`.
724
+ *
725
+ * Empty — claim nothing — unless ALL of these hold:
726
+ *
727
+ * - the response arrived;
728
+ * - the gateway says `mode: "enforce"`. In observe mode the data exists for operators, and acting
729
+ * on it would defeat the shadow-period rollout the mode flag exists to provide;
730
+ * - the lane's status is `broken`. DEGRADED lanes stay SELECTABLE — the measured answer there is
731
+ * "it works, but mind the size", and removing it would take a working route away.
732
+ */
733
+ declare function suppressedLanes(health: RouteHealth | undefined | null): ReadonlyMap<string, BrokenLane>;
734
+ /** A one-line reason a pair is hidden, for the picker row and the refusal panel. Never the raw
735
+ * gateway message: that text is untrusted and can carry infrastructure detail. */
736
+ declare function brokenLaneReason(lane: BrokenLane | undefined): string;
737
+
738
+ interface ResolvedConfig {
739
+ apiBase: string;
740
+ getApiKey: () => Promise<string>;
741
+ fetchImpl: typeof fetch;
742
+ rpcOverrides: Record<number, string>;
743
+ onTransaction?: EngineConfig["onTransaction"];
744
+ }
745
+ declare function parseAllowedApiBase(value: unknown): string | null;
746
+ /** Resolve the request base. A relative base (e.g. `/api/widget/v1`) is same-origin and allowed as
747
+ * is; an absolute base must pass parseAllowedApiBase; anything invalid falls back to the default. */
748
+ declare function resolveApiBase(value?: string): string;
749
+ /**
750
+ * Only attach the viewer key to a same-origin (relative) base, or to an origin the INTEGRATOR has
751
+ * explicitly declared trusted via `EngineConfig.trustedApiOrigin`.
752
+ *
753
+ * There is deliberately no hardcoded default origin. The API is normally reached through a
754
+ * server-side proxy that injects the key (`/api/widget/v1`), and that proxy origin differs per
755
+ * integrator deployment — so there is no single correct value to bake in. Shipping a fixed hostname
756
+ * here would make one unrelated origin the sole permitted key destination for everyone, and silently
757
+ * disable the key for every integrator not using it.
758
+ *
759
+ * Default is therefore same-origin only: fail closed, and let a host opt in to an absolute origin
760
+ * it controls.
761
+ */
762
+ declare function canAttachApiKey(apiBase: string, trustedOrigin?: string): boolean;
763
+ declare function resolveConfig(config?: EngineConfig): ResolvedConfig;
764
+
765
+ interface ApiError extends Error {
766
+ code?: string;
767
+ status?: number;
768
+ reasons?: string[];
769
+ fieldErrors?: Array<{
770
+ message?: string;
771
+ }>;
772
+ blocked?: boolean;
773
+ blockedCategory?: string;
774
+ blockedReason?: string;
775
+ }
776
+ declare function apiError(message: string, props?: Partial<ApiError>): ApiError;
777
+ interface QuoteBlock {
778
+ blocked: true;
779
+ category: string;
780
+ reason: string;
781
+ message: string;
782
+ }
783
+ declare function classifyQuoteError(error: any): QuoteBlock | null;
784
+ interface ApiClient {
785
+ apiRequest: <T = any>(path: string, init?: RequestInit & {
786
+ timeoutMs?: number;
787
+ }) => Promise<T>;
788
+ fetchChains: () => Promise<Chain[]>;
789
+ fetchTokens: () => Promise<Token[]>;
790
+ fetchRoutes: () => Promise<Route[]>;
791
+ /** Measured lane health. NEVER rejects — see the implementation. */
792
+ fetchRouteHealth: () => Promise<RouteHealth | null>;
793
+ fetchQuote: (body: Record<string, unknown>, retries?: number) => Promise<Quote>;
794
+ /**
795
+ * Standalone KYW screen of ONE address — the direct-settlement gate.
796
+ *
797
+ * ⚠️ Rejects rather than resolving to a benign verdict. The caller MUST fail closed: a screen
798
+ * that could not complete is not a clean wallet, and this is the only control standing between a
799
+ * direct ERC-20 transfer and a sanctioned counterparty.
800
+ */
801
+ screenWallet: (address: string, chainId?: number) => Promise<WalletScreen>;
802
+ apiBase: string;
803
+ }
804
+ /** Build an API client bound to a resolved config. The 60s resource cache is per-instance. */
805
+ declare function createApiClient(cfg: ResolvedConfig): ApiClient;
806
+
807
+ declare function registryRpc(chain: Chain | null): string;
808
+ interface TxPlan {
809
+ from?: string;
810
+ to?: string;
811
+ data?: string;
812
+ value?: string;
813
+ minNonce?: number;
814
+ }
815
+ declare function txMatchesPlan(tx: any, plan: TxPlan): boolean;
816
+ interface VerifyResult {
817
+ /** `confirmed` means MINED WITH A SUCCESS RECEIPT — never merely broadcast. `reverted` is a real
818
+ * on-chain failure (receipt status 0x0). `unconfirmed` means we could not establish either, and
819
+ * must NOT be presented to the payer as a completed payment. */
820
+ status: "confirmed" | "mismatch" | "reverted" | "unconfirmed";
821
+ reason?: string;
822
+ }
823
+ /** One ERC-20 balance to read: the token, its chain, and its decimals (for display formatting). */
824
+ interface BalanceTarget {
825
+ chainId: number;
826
+ tokenAddress: string;
827
+ decimals: number;
828
+ }
829
+ /** A read balance. `raw` is the base-unit integer as a decimal string; `formatted` is display-safe. */
830
+ interface BalanceEntry {
831
+ raw: string;
832
+ formatted: string;
833
+ }
834
+ interface Verifier {
835
+ payerNonceBaseline: (chainId: number, account: string) => Promise<number | null>;
836
+ verifySubmittedTx: (args: {
837
+ chainId: number;
838
+ hash: string;
839
+ from?: string;
840
+ to?: string;
841
+ data?: string;
842
+ value?: string;
843
+ minNonce?: number;
844
+ }) => Promise<VerifyResult>;
845
+ /** Read the payer's ERC-20 balance for each target, keyed `${chainId}:${tokenAddress.toLowerCase()}`.
846
+ * Read-only, off the same public-RPC path as settlement verification. Fail-open: a target whose
847
+ * RPC read fails is simply omitted from the result (never throws, never blocks a route). */
848
+ readBalances: (account: string, targets: BalanceTarget[]) => Promise<Record<string, BalanceEntry>>;
849
+ /** Payer's native (gas-token) balance in wei on `chainId`, or null when it cannot be read.
850
+ * Fail-open by contract: callers must treat null as "unknown", never as "zero". */
851
+ readNativeBalance: (chainId: number, account: string) => Promise<bigint | null>;
852
+ }
853
+ declare function createVerifier(api: ApiClient, fetchImpl: typeof fetch, rpcOverrides?: Record<number, string>): Verifier;
854
+
855
+ export { type QuoteBlock as $, type Availability as A, type BrokenLane as B, type Compliance as C, BLOCK_LABEL_DEFAULT as D, type EngineConfig as E, type FetchQuoteFn as F, COMPLIANCE_CHECK_ORDER as G, COMPLIANCE_DENY_LABEL as H, type CatalogueContext as I, type CatalogueInput as J, type ComplianceCheckId as K, type ComplianceDecision as L, DIRECT_CHECK_IDS as M, type NormalizedOrder as N, type OrderRequest as O, type Plan as P, type Quote as Q, type Route as R, type SanitizedTxEntry as S, type Token as T, DIRECT_SCOPE_NOTE as U, type VerifyResult as V, type WalletScreen as W, type Destination as X, FLOOR_CATEGORIES as Y, type Hex as Z, type PlannedTxKind as _, type Catalogue as a, type ResolvedConfig as a0, type RouteHealth as a1, type RouteHealthLane as a2, SCREENING_BUCKETS as a3, type ScreenProvider as a4, type ScreeningBucket as a5, type ScreeningOutcome as a6, TUNABLE_CATEGORIES as a7, type TxPlan as a8, apiError as a9, registryRpc as aA, resolveApiBase as aB, resolveConfig as aC, screeningOutcomeOf as aD, sourceKeys as aE, suppressedLanes as aF, tokenKey as aG, txMatchesPlan as aH, unattributedComplianceReasons as aI, blockLabelFor as aa, brokenLaneFor as ab, buildCatalogue as ac, canAttachApiKey as ad, categoryLabel as ae, classifyQuoteError as af, complianceControlsEvaluated as ag, complianceReasonHead as ah, complianceReasonTag as ai, complianceTagOf as aj, createApiClient as ak, createVerifier as al, destinationKeys as am, directComplianceFromScreens as an, distinctScreenedWallets as ao, executableRoutes as ap, executionChainIds as aq, hasReachableDestination as ar, hubDeliverableSymbols as as, isExecutableBridge as at, isKnownUnbridgeable as au, isSourceToken as av, laneKey as aw, laneKeys as ax, parseAllowedApiBase as ay, productAssets as az, type Chain as b, type ComplianceCheck as c, type ComplianceTone as d, type ComplianceView as e, type ExchangeProduct as f, type RouteResult as g, type TxHistoryEntry as h, assetClassOf as i, brokenLaneReason as j, complianceChecks as k, complianceControlsLine as l, complianceView as m, counterpartTokens as n, destinationAvailability as o, humanizeComplianceReason as p, type PayOption as q, type SolveResult as r, type BalanceTarget as s, type BalanceEntry as t, type ApiClient as u, type SwapInput as v, type PlannedTx as w, type Verifier as x, type Address as y, type ApiError as z };