@glacislabs/stablegenie-zerodelta 3.3.0 → 3.4.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.
- package/dist/{chunk-QKGRMRS4.js → chunk-Q3YSX4D5.js} +205 -75
- package/dist/{chunk-OOURZ5DL.js → chunk-TYQF2L5C.js} +386 -46
- package/dist/core/index.cjs +409 -45
- package/dist/core/index.d.cts +85 -6
- package/dist/core/index.d.ts +85 -6
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +594 -120
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/{mount-DNvmtX0y.d.cts → mount-BT2NejVt.d.ts} +46 -6
- package/dist/{mount-jxrT-DMe.d.ts → mount-D8NmWtqV.d.cts} +46 -6
- package/dist/mount.cjs +580 -120
- package/dist/mount.d.cts +2 -2
- package/dist/mount.d.ts +2 -2
- package/dist/mount.js +2 -2
- package/dist/standalone.global.js +14 -9
- package/dist/verify-34voZYj1.d.cts +631 -0
- package/dist/verify-34voZYj1.d.ts +631 -0
- package/package.json +1 -1
- package/dist/verify-7lk90Ado.d.cts +0 -367
- package/dist/verify-7lk90Ado.d.ts +0 -367
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
type Hex = `0x${string}`;
|
|
2
|
+
type Address = `0x${string}`;
|
|
3
|
+
interface Chain {
|
|
4
|
+
chainId: number;
|
|
5
|
+
name?: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
/** Gas-token symbol ("ETH", "S", …). Used only to label a native-balance shortfall. */
|
|
8
|
+
nativeCurrency?: string;
|
|
9
|
+
escrowContract?: string;
|
|
10
|
+
rpcUrl?: string;
|
|
11
|
+
rpcUrls?: string[];
|
|
12
|
+
publicRpcUrl?: string;
|
|
13
|
+
rpc?: string;
|
|
14
|
+
rpcEndpoint?: string;
|
|
15
|
+
isEnabled?: boolean;
|
|
16
|
+
/** Chains the escrow SETTLES on. Only these can host the swap itself; every other chain is
|
|
17
|
+
* reachable as a bridge destination only. Supplied by `GET /chains`. */
|
|
18
|
+
isExecutionChain?: boolean;
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface Token {
|
|
22
|
+
symbol: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
chainId: number;
|
|
25
|
+
address: string;
|
|
26
|
+
decimals: number;
|
|
27
|
+
logoUrl?: string;
|
|
28
|
+
bridge?: string;
|
|
29
|
+
/** Versioned bridge family ("CCTPV2", "LayerZeroV2OFT", …). Paired with `bridge` it decides
|
|
30
|
+
* whether the settlement contracts can execute this deployment's destination leg. */
|
|
31
|
+
standard?: string;
|
|
32
|
+
isEnabled?: boolean;
|
|
33
|
+
/** Set by the gateway on the exact deployments a chained (two-leg) order can terminate in.
|
|
34
|
+
* Deliberately per-token, not per-chain. */
|
|
35
|
+
isChainedDestination?: boolean;
|
|
36
|
+
[k: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
interface Route {
|
|
39
|
+
tokenId?: string;
|
|
40
|
+
tokenName?: string;
|
|
41
|
+
fromChainId: number;
|
|
42
|
+
toChainId: number;
|
|
43
|
+
/** Token address at each end of the lane. A lane is identified by BOTH ends: the same symbol can
|
|
44
|
+
* be bridgeable from one chain and not another, and only the pair says which. */
|
|
45
|
+
fromAddress?: string;
|
|
46
|
+
toAddress?: string;
|
|
47
|
+
bridge?: string;
|
|
48
|
+
standard?: string;
|
|
49
|
+
isEnabled?: boolean;
|
|
50
|
+
[k: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
interface OrderRequest {
|
|
53
|
+
owner?: string;
|
|
54
|
+
bidToken?: string;
|
|
55
|
+
bidTokenAmount?: string | number;
|
|
56
|
+
askToken?: string;
|
|
57
|
+
askTokenAmount?: string | number;
|
|
58
|
+
destinationReceiver?: string;
|
|
59
|
+
destinationChainId?: string | number;
|
|
60
|
+
/** Chain the escrow executes the order on. Mandatory on-chain; the gateway always issues it. */
|
|
61
|
+
executionChainId?: string | number;
|
|
62
|
+
deadline?: string | number;
|
|
63
|
+
}
|
|
64
|
+
interface NormalizedOrder {
|
|
65
|
+
owner: string;
|
|
66
|
+
bidToken: string;
|
|
67
|
+
bidTokenAmount: string;
|
|
68
|
+
askToken: string;
|
|
69
|
+
askTokenAmount: string;
|
|
70
|
+
destinationReceiver: string;
|
|
71
|
+
destinationChainId: string;
|
|
72
|
+
executionChainId: string;
|
|
73
|
+
deadline: string;
|
|
74
|
+
}
|
|
75
|
+
interface Quote {
|
|
76
|
+
fromChainId: number;
|
|
77
|
+
toChainId: number;
|
|
78
|
+
fromToken: string;
|
|
79
|
+
toToken: string;
|
|
80
|
+
fromAmount?: string;
|
|
81
|
+
toAmount?: string;
|
|
82
|
+
finalAmount?: string;
|
|
83
|
+
bridge?: string;
|
|
84
|
+
feeBps?: number;
|
|
85
|
+
estimatedDuration?: number;
|
|
86
|
+
gasCostSource?: string;
|
|
87
|
+
gasCostDest?: string;
|
|
88
|
+
escrowAddress?: string;
|
|
89
|
+
/** Escrow on the execution chain. Informational: approve/submitOrder go to the SOURCE-chain
|
|
90
|
+
* escrow, which is what checkEscrow binds. */
|
|
91
|
+
executionEscrowAddress?: string;
|
|
92
|
+
executionChainId?: number | string;
|
|
93
|
+
/** Every leg of the order, first to last. A plain swap is one leg; a chained (RWA) quote is
|
|
94
|
+
* two or more, all encoded into one submitOrder call. */
|
|
95
|
+
orderRequests?: OrderRequest[] | null;
|
|
96
|
+
/** Legacy single-leg shape, accepted for backward compatibility. */
|
|
97
|
+
orderRequest?: OrderRequest | null;
|
|
98
|
+
[k: string]: unknown;
|
|
99
|
+
}
|
|
100
|
+
interface PayOption {
|
|
101
|
+
symbol: string;
|
|
102
|
+
symbolKey: string;
|
|
103
|
+
name: string;
|
|
104
|
+
chainId: number;
|
|
105
|
+
chainName: string;
|
|
106
|
+
address: string;
|
|
107
|
+
decimals: number;
|
|
108
|
+
logoUrl?: string;
|
|
109
|
+
bridge?: string;
|
|
110
|
+
sameChain?: boolean;
|
|
111
|
+
direct: boolean;
|
|
112
|
+
}
|
|
113
|
+
interface SolveResult {
|
|
114
|
+
directTransfer: boolean;
|
|
115
|
+
quote: Quote;
|
|
116
|
+
youPayRaw: string;
|
|
117
|
+
recipientReceivesRaw: string;
|
|
118
|
+
targetRaw: string;
|
|
119
|
+
overageBps: number;
|
|
120
|
+
meetsTarget: boolean;
|
|
121
|
+
iterations: number;
|
|
122
|
+
}
|
|
123
|
+
type PlannedTxKind = "transfer" | "approve" | "submitOrder";
|
|
124
|
+
interface PlannedTx {
|
|
125
|
+
id: string;
|
|
126
|
+
kind: PlannedTxKind;
|
|
127
|
+
label: string;
|
|
128
|
+
chainId: number;
|
|
129
|
+
to: string;
|
|
130
|
+
data: string;
|
|
131
|
+
value: string;
|
|
132
|
+
token?: string;
|
|
133
|
+
spender?: string;
|
|
134
|
+
escrow?: string;
|
|
135
|
+
amountRaw?: string;
|
|
136
|
+
mock?: boolean;
|
|
137
|
+
}
|
|
138
|
+
interface RouteResult {
|
|
139
|
+
id: string;
|
|
140
|
+
recommended: boolean;
|
|
141
|
+
state: "DIRECT" | "ROUTE" | "SHORT";
|
|
142
|
+
source: {
|
|
143
|
+
asset: string;
|
|
144
|
+
chainId: number;
|
|
145
|
+
chainName: string;
|
|
146
|
+
tokenAddress?: string;
|
|
147
|
+
decimals?: number;
|
|
148
|
+
amount: string;
|
|
149
|
+
payAmount: string;
|
|
150
|
+
};
|
|
151
|
+
receive: {
|
|
152
|
+
asset: string;
|
|
153
|
+
chainId: number;
|
|
154
|
+
chainName: string;
|
|
155
|
+
tokenAddress?: string;
|
|
156
|
+
decimals?: number;
|
|
157
|
+
amount: string;
|
|
158
|
+
};
|
|
159
|
+
routeLabel: string;
|
|
160
|
+
deltaLabel: string;
|
|
161
|
+
transactions: PlannedTx[];
|
|
162
|
+
quote: {
|
|
163
|
+
bridge?: string;
|
|
164
|
+
feeBps?: number;
|
|
165
|
+
estimatedDuration?: number;
|
|
166
|
+
gasCostSource?: string;
|
|
167
|
+
msgValue?: string;
|
|
168
|
+
deadline?: string;
|
|
169
|
+
iterations: number;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
interface Destination {
|
|
173
|
+
address: string;
|
|
174
|
+
chainId: number;
|
|
175
|
+
chainName?: string;
|
|
176
|
+
asset: string;
|
|
177
|
+
amount: string;
|
|
178
|
+
}
|
|
179
|
+
interface Plan {
|
|
180
|
+
mode: "zerodelta" | "swap" | "mock";
|
|
181
|
+
requestId: string;
|
|
182
|
+
expiresAt: string;
|
|
183
|
+
apiBase?: string;
|
|
184
|
+
routes: RouteResult[];
|
|
185
|
+
/** Wallet balances already read while choosing funding candidates. Payment UIs reuse these so
|
|
186
|
+
* route rendering does not trigger the same RPC scan a second time. */
|
|
187
|
+
fundingBalances?: Record<string, {
|
|
188
|
+
raw: string;
|
|
189
|
+
formatted: string;
|
|
190
|
+
}>;
|
|
191
|
+
/** Normalized account that `fundingBalances` belongs to. */
|
|
192
|
+
fundingAccount?: string;
|
|
193
|
+
destination: {
|
|
194
|
+
asset: string;
|
|
195
|
+
chainId: number;
|
|
196
|
+
chainName: string;
|
|
197
|
+
tokenAddress?: string;
|
|
198
|
+
decimals?: number;
|
|
199
|
+
amount: string;
|
|
200
|
+
address: string;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
interface SwapInput {
|
|
204
|
+
fromChainId: number | string;
|
|
205
|
+
toChainId: number | string;
|
|
206
|
+
fromToken: string;
|
|
207
|
+
toToken: string;
|
|
208
|
+
amountIn: string;
|
|
209
|
+
recipient?: string;
|
|
210
|
+
}
|
|
211
|
+
interface TxHistoryEntry {
|
|
212
|
+
kind?: "payment" | "swap";
|
|
213
|
+
hash?: string;
|
|
214
|
+
/** The on-chain KIND of the recorded hash. History records only the SETTLING tx (transfer /
|
|
215
|
+
* submitOrder), never the allowance `approve` — this discriminator lets the UI defend that. */
|
|
216
|
+
txKind?: PlannedTxKind;
|
|
217
|
+
chainId?: number;
|
|
218
|
+
chainName?: string;
|
|
219
|
+
fromAsset?: string;
|
|
220
|
+
toAsset?: string;
|
|
221
|
+
payAmount?: string;
|
|
222
|
+
receiveAmount?: string;
|
|
223
|
+
/** The signer (payer) — history is scoped per connected wallet. */
|
|
224
|
+
account?: string;
|
|
225
|
+
recipient?: string;
|
|
226
|
+
settlement?: "direct" | "escrow";
|
|
227
|
+
status?: "confirmed" | "unconfirmed" | "error" | "submitted";
|
|
228
|
+
}
|
|
229
|
+
/** A display-safe, sanitized history entry (no keys/calldata/secrets). */
|
|
230
|
+
interface SanitizedTxEntry {
|
|
231
|
+
kind: "payment" | "swap";
|
|
232
|
+
hash: string;
|
|
233
|
+
/** On-chain tx kind of `hash`. Always the settling tx (never `approve`) when set by the engine;
|
|
234
|
+
* optional for backward-compatibility with entries persisted before this field existed. */
|
|
235
|
+
txKind?: PlannedTxKind;
|
|
236
|
+
chainId: number | null;
|
|
237
|
+
chainName: string;
|
|
238
|
+
fromAsset: string;
|
|
239
|
+
toAsset: string;
|
|
240
|
+
payAmount: string;
|
|
241
|
+
receiveAmount: string;
|
|
242
|
+
/** Normalized signer address, or "" when unknown. */
|
|
243
|
+
account: string;
|
|
244
|
+
recipient: string;
|
|
245
|
+
settlement: "direct" | "escrow";
|
|
246
|
+
status: "confirmed" | "unconfirmed" | "error" | "submitted";
|
|
247
|
+
at: string;
|
|
248
|
+
}
|
|
249
|
+
/** Config injected into the engine by the host application. */
|
|
250
|
+
interface EngineConfig {
|
|
251
|
+
/** Request base. Default: {@link DEFAULT_WIDGET_API_BASE} (same-origin keyless proxy). */
|
|
252
|
+
apiBase?: string;
|
|
253
|
+
/** Optional viewer key. Attached as x-api-key ONLY when canAttachApiKey passes — i.e. a
|
|
254
|
+
* same-origin (relative) `apiBase`, or an absolute one matching {@link trustedApiOrigin}.
|
|
255
|
+
* Not needed against the keyless proxy, which injects the key server-side. */
|
|
256
|
+
apiKey?: string;
|
|
257
|
+
getApiKey?: () => string | Promise<string>;
|
|
258
|
+
/** Absolute origin that may receive `apiKey` when `apiBase` is absolute (e.g.
|
|
259
|
+
* `https://pay.example.com`). Omit and no absolute origin is trusted — same-origin only.
|
|
260
|
+
*
|
|
261
|
+
* There is no built-in default on purpose: the correct trusted origin is whichever proxy YOU
|
|
262
|
+
* deploy, so only this integration can know it. Set it to an origin you control — it is the
|
|
263
|
+
* sole destination permitted to receive the key. */
|
|
264
|
+
trustedApiOrigin?: string;
|
|
265
|
+
/** Injectable fetch (tests / SSR). Defaults to global fetch. */
|
|
266
|
+
fetchImpl?: typeof fetch;
|
|
267
|
+
/** Per-chain RPC overrides for settlement verification / balances. */
|
|
268
|
+
rpcOverrides?: Record<number, string>;
|
|
269
|
+
/** Called with a display-safe history entry after a submit (optional persistence). */
|
|
270
|
+
onTransaction?: (entry: SanitizedTxEntry) => void;
|
|
271
|
+
}
|
|
272
|
+
type FetchQuoteFn = (body: Record<string, unknown>, retries?: number) => Promise<Quote>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Which product a catalogue is being built for.
|
|
276
|
+
*
|
|
277
|
+
* The ZeroDelta dapp runs two over one gateway, and they differ in more than a token list:
|
|
278
|
+
*
|
|
279
|
+
* stable stable ⇄ stable. Both legs must execute through CCTP V2 or LayerZero V2 OFT, so the
|
|
280
|
+
* route projection is filtered to those families and a token is admitted only when a
|
|
281
|
+
* published lane touches it.
|
|
282
|
+
* rwa stable ⇄ real-world asset, EXACTLY ONE LEG OF EACH. The vault shares publish no route
|
|
283
|
+
* rows at all — they are delivered by a CHAINED two-leg order and marked
|
|
284
|
+
* `isChainedDestination` on the destination deployment — so requiring a lane here would
|
|
285
|
+
* empty the picker of every asset the product exists to trade.
|
|
286
|
+
*/
|
|
287
|
+
type ExchangeProduct = "stable" | "rwa";
|
|
288
|
+
/** The asset class of a symbol, or null when this build does not price it at all. */
|
|
289
|
+
declare function assetClassOf(symbol: string | undefined | null): "stable" | "rwa" | null;
|
|
290
|
+
/** The asset universe of a product, before any host narrowing. */
|
|
291
|
+
declare function productAssets(product: ExchangeProduct): ReadonlySet<string>;
|
|
292
|
+
/**
|
|
293
|
+
* The other side of an RWA pair.
|
|
294
|
+
*
|
|
295
|
+
* Exactly one leg of an RWA order is the real-world asset: picking a vault share on one side leaves
|
|
296
|
+
* only stables on the other, and the reverse. Without this the form would offer stable→stable and
|
|
297
|
+
* share→share pairs the gateway refuses, on a surface whose entire purpose is the RWA.
|
|
298
|
+
*
|
|
299
|
+
* With nothing selected yet the RWA side is offered, because that is the choice the user came to
|
|
300
|
+
* make; the stable side then narrows to match.
|
|
301
|
+
*/
|
|
302
|
+
declare function counterpartTokens(tokens: readonly Token[], selected: Pick<Token, "symbol"> | null | undefined): Token[];
|
|
303
|
+
/** `chainId:address` — the identity of ONE token deployment. */
|
|
304
|
+
declare function tokenKey(chainId: number | string, address: string): string;
|
|
305
|
+
/** One lane, keyed by BOTH ends. See {@link laneKeys} for why the source end matters. */
|
|
306
|
+
declare function laneKey(fromChainId: number | string, fromAddress: string, toChainId: number | string, toAddress: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* The only bridge/standard pairs whose adapters can execute the destination leg of a
|
|
309
|
+
* stable-to-stable order.
|
|
310
|
+
*
|
|
311
|
+
* Both fields are matched so a stale or malformed registry row cannot be promoted merely because it
|
|
312
|
+
* says "LayerZero". The versioned standard is required: an ambiguous "OFT" must not admit a
|
|
313
|
+
* LayerZero V1 asset such as DAI, which the escrow owns no adapter for.
|
|
314
|
+
*/
|
|
315
|
+
declare function isExecutableBridge(descriptor: {
|
|
316
|
+
bridge?: string;
|
|
317
|
+
standard?: string;
|
|
318
|
+
} | null | undefined): boolean;
|
|
319
|
+
/**
|
|
320
|
+
* A token whose config declares `bridge: "None"` is one the escrow owns no adapter for (Chainlink
|
|
321
|
+
* CCT, Wormhole NTT, the M0 Portal, LayerZero V1). The gateway emits no route rows for those.
|
|
322
|
+
*
|
|
323
|
+
* The test needs a POSITIVE answer: an absent `bridge` means we do not know, and "do not know" must
|
|
324
|
+
* not demote a token the route projection has already proved bridgeable.
|
|
325
|
+
*/
|
|
326
|
+
declare function isKnownUnbridgeable(bridge: string | undefined): boolean;
|
|
327
|
+
/** Enabled lanes whose bridge family the settlement contracts can actually execute. */
|
|
328
|
+
declare function executableRoutes(routes: readonly Route[]): Route[];
|
|
329
|
+
/** Deployments a token can be bridged OUT of — the bid side. */
|
|
330
|
+
declare function sourceKeys(routes: readonly Route[]): Set<string>;
|
|
331
|
+
/**
|
|
332
|
+
* Deployments a token can be bridged IN to — the ask side.
|
|
333
|
+
*
|
|
334
|
+
* Deliberately a separate projection from the source keys: a lane can be destination-only, so
|
|
335
|
+
* inferring one direction from the other would either hide a valid destination or offer a source the
|
|
336
|
+
* escrow refuses.
|
|
337
|
+
*/
|
|
338
|
+
declare function destinationKeys(routes: readonly Route[]): Set<string>;
|
|
339
|
+
/**
|
|
340
|
+
* Lanes keyed by both ends, for the one case where the source matters.
|
|
341
|
+
*
|
|
342
|
+
* {@link destinationKeys} collapses every route to where it ENDS, which is right for a swap: the
|
|
343
|
+
* order goes source → execution chain → destination, and the source only has to reach the execution
|
|
344
|
+
* chain. It is wrong for a SAME-SYMBOL pair, which the escrow short-circuits onto the direct path,
|
|
345
|
+
* where `bridgeDirect` runs on the SOURCE adapter and needs a real source→destination peer. "Some
|
|
346
|
+
* route ends at USDe on Base" is true from Ethereum and false from Optimism, and the collapsed set
|
|
347
|
+
* cannot tell those apart.
|
|
348
|
+
*/
|
|
349
|
+
declare function laneKeys(routes: readonly Route[]): Set<string>;
|
|
350
|
+
/** Chains the escrow settles on, from `GET /chains`. */
|
|
351
|
+
declare function executionChainIds(chains: readonly Chain[]): Set<number>;
|
|
352
|
+
/** Symbols deliverable on an execution chain — what makes "you can still receive this on Ethereum" a
|
|
353
|
+
* true statement rather than a guess. */
|
|
354
|
+
declare function hubDeliverableSymbols(tokens: readonly Token[], execution: ReadonlySet<number>): Set<string>;
|
|
355
|
+
/** A measured refusal, as {@link destinationAvailability} consumes it. */
|
|
356
|
+
interface BrokenLane {
|
|
357
|
+
/** Human label, e.g. `AUSD@8453 -> PYUSD@98866`. */
|
|
358
|
+
route: string;
|
|
359
|
+
/** The gateway's own error code, e.g. `QUOTE_UNAVAILABLE`. */
|
|
360
|
+
code: string;
|
|
361
|
+
/** The gateway's own message, verbatim. */
|
|
362
|
+
message: string;
|
|
363
|
+
kind?: string;
|
|
364
|
+
}
|
|
365
|
+
interface CatalogueContext {
|
|
366
|
+
/** From {@link sourceKeys}. */
|
|
367
|
+
source: ReadonlySet<string>;
|
|
368
|
+
/** From {@link destinationKeys}. */
|
|
369
|
+
destination: ReadonlySet<string>;
|
|
370
|
+
/** From {@link laneKeys}. Optional: without it the same-symbol direct-peer check is skipped. */
|
|
371
|
+
lanes?: ReadonlySet<string>;
|
|
372
|
+
/** From {@link executionChainIds}. */
|
|
373
|
+
execution: ReadonlySet<number>;
|
|
374
|
+
/** Chains a payment may be SENT FROM — `SUPPORTED_CHAIN_IDS` ∩ the enabled registry chains. */
|
|
375
|
+
sourceChains: ReadonlySet<number>;
|
|
376
|
+
/** From {@link hubDeliverableSymbols}. */
|
|
377
|
+
hubSymbols: ReadonlySet<string>;
|
|
378
|
+
/**
|
|
379
|
+
* Lanes the gateway's background prober has MEASURED refusing, keyed by {@link laneKey}. Absent
|
|
380
|
+
* means EMPTY — a health response that has not arrived, or a gateway in observe mode, demotes
|
|
381
|
+
* nothing.
|
|
382
|
+
*
|
|
383
|
+
* This is the one input that is not an inference. Everything else here reasons about what SHOULD
|
|
384
|
+
* work; this says what was actually tried and did not.
|
|
385
|
+
*/
|
|
386
|
+
brokenLanes?: ReadonlyMap<string, BrokenLane>;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Can this deployment fund a payment?
|
|
390
|
+
*
|
|
391
|
+
* A published route can add a payout-only chain to the destination catalogue, but it cannot make
|
|
392
|
+
* that chain safe to transact on: a source must also be a chain this widget pins an escrow and a
|
|
393
|
+
* bundled RPC for, because that is where `approve`, `submitOrder` and settlement verification run.
|
|
394
|
+
*/
|
|
395
|
+
declare function isSourceToken(token: Token, ctx: Pick<CatalogueContext, "source" | "execution" | "sourceChains">): boolean;
|
|
396
|
+
/**
|
|
397
|
+
* `available` — we can deliver this token on this chain.
|
|
398
|
+
* `hub-only` — the asset exists here but we cannot deliver it here; it IS deliverable on an
|
|
399
|
+
* execution chain.
|
|
400
|
+
* `unreachable` — we cannot deliver it anywhere the form can currently reach.
|
|
401
|
+
*/
|
|
402
|
+
type Availability = "available" | "hub-only" | "unreachable";
|
|
403
|
+
/**
|
|
404
|
+
* The measured refusal for this exact (source, destination) pair, if there is one.
|
|
405
|
+
*
|
|
406
|
+
* ⚠️ Deliberately keyed on BOTH ends. Most measured failures are lane gaps rather than a dead
|
|
407
|
+
* destination — a token that refuses from one source quotes fine from three others — so suppressing
|
|
408
|
+
* the destination alone would remove working routes to fix one broken one.
|
|
409
|
+
*/
|
|
410
|
+
declare function brokenLaneFor(token: Pick<Token, "chainId" | "address">, source: Pick<Token, "chainId" | "address"> | undefined, brokenLanes: ReadonlyMap<string, BrokenLane> | undefined): BrokenLane | undefined;
|
|
411
|
+
/**
|
|
412
|
+
* Whether an ask token can actually be delivered on its own chain.
|
|
413
|
+
*
|
|
414
|
+
* Without this the picker lists every enabled token and lets the gateway reject the pair, which
|
|
415
|
+
* surfaces as an unexplained 422 — that reads as the product being broken rather than the asset
|
|
416
|
+
* being undeliverable there.
|
|
417
|
+
*/
|
|
418
|
+
declare function destinationAvailability(token: Token, ctx: CatalogueContext, source?: Pick<Token, "symbol" | "chainId" | "address"> | null): Availability;
|
|
419
|
+
/**
|
|
420
|
+
* Can anything at all be delivered when paying WITH this token?
|
|
421
|
+
*
|
|
422
|
+
* {@link isSourceToken} only asks whether a token can LEAVE its chain, never whether there is
|
|
423
|
+
* anywhere to land — so a deployment whose every destination is refused stayed fully selectable: the
|
|
424
|
+
* picker offered it, the user chose it, and the destination list then came back empty with no
|
|
425
|
+
* explanation.
|
|
426
|
+
*
|
|
427
|
+
* `hub-only` does not count: that destination cannot be delivered as asked, and offering the source
|
|
428
|
+
* on the strength of it reproduces the same dead end one step later.
|
|
429
|
+
*
|
|
430
|
+
* ⚠️ Answers `true` whenever it cannot know — an empty catalogue must read as "has destinations".
|
|
431
|
+
*/
|
|
432
|
+
declare function hasReachableDestination(source: Token, catalogue: readonly Token[], ctx: CatalogueContext): boolean;
|
|
433
|
+
interface CatalogueInput {
|
|
434
|
+
chains: readonly Chain[];
|
|
435
|
+
tokens: readonly Token[];
|
|
436
|
+
routes: readonly Route[];
|
|
437
|
+
/** Which product this catalogue is for. Defaults to `"stable"`. */
|
|
438
|
+
product?: ExchangeProduct;
|
|
439
|
+
/** A host narrowing, INTERSECTED with the product's own universe. Omit for the whole product. */
|
|
440
|
+
allowedAssets?: ReadonlySet<string>;
|
|
441
|
+
/** Chains a payment may be SENT FROM — `SUPPORTED_CHAIN_IDS`. */
|
|
442
|
+
supportedChainIds: ReadonlySet<number>;
|
|
443
|
+
/** Measured refusals; omit or pass an empty map to suppress nothing. */
|
|
444
|
+
brokenLanes?: ReadonlyMap<string, BrokenLane>;
|
|
445
|
+
}
|
|
446
|
+
interface Catalogue extends CatalogueContext {
|
|
447
|
+
/** The product this catalogue was built for. */
|
|
448
|
+
product: ExchangeProduct;
|
|
449
|
+
/** Every deployment the widget may show, either side. */
|
|
450
|
+
tokens: Token[];
|
|
451
|
+
/** Deployments that can fund a payment, and that have somewhere to land. */
|
|
452
|
+
sources: Token[];
|
|
453
|
+
/** Chain ids that appear anywhere in the catalogue — sources plus payout-only destinations. */
|
|
454
|
+
chainIds: Set<number>;
|
|
455
|
+
/** Registry chains, plus a synthesised row per payout-only destination chain. */
|
|
456
|
+
chains: Chain[];
|
|
457
|
+
/**
|
|
458
|
+
* True once the registry has told us enough to give a verdict. While false the UI must claim
|
|
459
|
+
* nothing: every "unreachable" would be a confident negative derived from absent data.
|
|
460
|
+
*
|
|
461
|
+
* Requires a NON-EMPTY result, not merely two responses. A payload that arrives without the fields
|
|
462
|
+
* these rules read — `standard` on a token, addresses on a route — projects to an empty catalogue,
|
|
463
|
+
* and treating that as "ready" turns a thin response into "this product supports nothing": the pay
|
|
464
|
+
* flow refuses to build a plan at all rather than letting the gateway answer. An empty projection
|
|
465
|
+
* is something we failed to learn, not something we learned.
|
|
466
|
+
*/
|
|
467
|
+
ready: boolean;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Build the selectable catalogue from the live registry.
|
|
471
|
+
*
|
|
472
|
+
* Mirrors the dapp's Swap page: sources are bounded by the escrow chains, destinations are not —
|
|
473
|
+
* receiving does not require a wallet, an RPC, or an escrow on the far chain, only a published
|
|
474
|
+
* route. That asymmetry is why the dapp offers ~31 destination chains against 9 sources, and it is
|
|
475
|
+
* the single biggest reason the widget's catalogue used to be a fraction of the dapp's.
|
|
476
|
+
*/
|
|
477
|
+
declare function buildCatalogue(input: CatalogueInput): Catalogue;
|
|
478
|
+
|
|
479
|
+
/** One lane as the gateway reports it. Permissive on purpose — this is untrusted API data and the
|
|
480
|
+
* projection below reads only what it needs. */
|
|
481
|
+
interface RouteHealthLane {
|
|
482
|
+
laneKey?: string;
|
|
483
|
+
route?: string;
|
|
484
|
+
status?: string;
|
|
485
|
+
kind?: string;
|
|
486
|
+
code?: string;
|
|
487
|
+
message?: string;
|
|
488
|
+
[k: string]: unknown;
|
|
489
|
+
}
|
|
490
|
+
interface RouteHealth {
|
|
491
|
+
/** `enforce` = the operator has armed suppression. `observe` = data for dashboards only. */
|
|
492
|
+
mode?: string;
|
|
493
|
+
scope?: string;
|
|
494
|
+
summary?: {
|
|
495
|
+
healthy?: number;
|
|
496
|
+
degraded?: number;
|
|
497
|
+
broken?: number;
|
|
498
|
+
unknown?: number;
|
|
499
|
+
total?: number;
|
|
500
|
+
};
|
|
501
|
+
measuredAt?: string;
|
|
502
|
+
lastSweepAt?: string;
|
|
503
|
+
lanes?: RouteHealthLane[];
|
|
504
|
+
[k: string]: unknown;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* The lanes the picker must stop offering, keyed by `laneKey`.
|
|
508
|
+
*
|
|
509
|
+
* Empty — claim nothing — unless ALL of these hold:
|
|
510
|
+
*
|
|
511
|
+
* - the response arrived;
|
|
512
|
+
* - the gateway says `mode: "enforce"`. In observe mode the data exists for operators, and acting
|
|
513
|
+
* on it would defeat the shadow-period rollout the mode flag exists to provide;
|
|
514
|
+
* - the lane's status is `broken`. DEGRADED lanes stay SELECTABLE — the measured answer there is
|
|
515
|
+
* "it works, but mind the size", and removing it would take a working route away.
|
|
516
|
+
*/
|
|
517
|
+
declare function suppressedLanes(health: RouteHealth | undefined | null): ReadonlyMap<string, BrokenLane>;
|
|
518
|
+
/** A one-line reason a pair is hidden, for the picker row and the refusal panel. Never the raw
|
|
519
|
+
* gateway message: that text is untrusted and can carry infrastructure detail. */
|
|
520
|
+
declare function brokenLaneReason(lane: BrokenLane | undefined): string;
|
|
521
|
+
|
|
522
|
+
interface ResolvedConfig {
|
|
523
|
+
apiBase: string;
|
|
524
|
+
getApiKey: () => Promise<string>;
|
|
525
|
+
fetchImpl: typeof fetch;
|
|
526
|
+
rpcOverrides: Record<number, string>;
|
|
527
|
+
onTransaction?: EngineConfig["onTransaction"];
|
|
528
|
+
}
|
|
529
|
+
declare function parseAllowedApiBase(value: unknown): string | null;
|
|
530
|
+
/** Resolve the request base. A relative base (e.g. `/api/widget/v1`) is same-origin and allowed as
|
|
531
|
+
* is; an absolute base must pass parseAllowedApiBase; anything invalid falls back to the default. */
|
|
532
|
+
declare function resolveApiBase(value?: string): string;
|
|
533
|
+
/**
|
|
534
|
+
* Only attach the viewer key to a same-origin (relative) base, or to an origin the INTEGRATOR has
|
|
535
|
+
* explicitly declared trusted via `EngineConfig.trustedApiOrigin`.
|
|
536
|
+
*
|
|
537
|
+
* There is deliberately no hardcoded default origin. The API is normally reached through a
|
|
538
|
+
* server-side proxy that injects the key (`/api/widget/v1`), and that proxy origin differs per
|
|
539
|
+
* integrator deployment — so there is no single correct value to bake in. Shipping a fixed hostname
|
|
540
|
+
* here would make one unrelated origin the sole permitted key destination for everyone, and silently
|
|
541
|
+
* disable the key for every integrator not using it.
|
|
542
|
+
*
|
|
543
|
+
* Default is therefore same-origin only: fail closed, and let a host opt in to an absolute origin
|
|
544
|
+
* it controls.
|
|
545
|
+
*/
|
|
546
|
+
declare function canAttachApiKey(apiBase: string, trustedOrigin?: string): boolean;
|
|
547
|
+
declare function resolveConfig(config?: EngineConfig): ResolvedConfig;
|
|
548
|
+
|
|
549
|
+
interface ApiError extends Error {
|
|
550
|
+
code?: string;
|
|
551
|
+
status?: number;
|
|
552
|
+
reasons?: string[];
|
|
553
|
+
fieldErrors?: Array<{
|
|
554
|
+
message?: string;
|
|
555
|
+
}>;
|
|
556
|
+
blocked?: boolean;
|
|
557
|
+
blockedCategory?: string;
|
|
558
|
+
blockedReason?: string;
|
|
559
|
+
}
|
|
560
|
+
declare function apiError(message: string, props?: Partial<ApiError>): ApiError;
|
|
561
|
+
interface QuoteBlock {
|
|
562
|
+
blocked: true;
|
|
563
|
+
category: string;
|
|
564
|
+
reason: string;
|
|
565
|
+
message: string;
|
|
566
|
+
}
|
|
567
|
+
declare function classifyQuoteError(error: any): QuoteBlock | null;
|
|
568
|
+
interface ApiClient {
|
|
569
|
+
apiRequest: <T = any>(path: string, init?: RequestInit & {
|
|
570
|
+
timeoutMs?: number;
|
|
571
|
+
}) => Promise<T>;
|
|
572
|
+
fetchChains: () => Promise<Chain[]>;
|
|
573
|
+
fetchTokens: () => Promise<Token[]>;
|
|
574
|
+
fetchRoutes: () => Promise<Route[]>;
|
|
575
|
+
/** Measured lane health. NEVER rejects — see the implementation. */
|
|
576
|
+
fetchRouteHealth: () => Promise<RouteHealth | null>;
|
|
577
|
+
fetchQuote: (body: Record<string, unknown>, retries?: number) => Promise<Quote>;
|
|
578
|
+
apiBase: string;
|
|
579
|
+
}
|
|
580
|
+
/** Build an API client bound to a resolved config. The 60s resource cache is per-instance. */
|
|
581
|
+
declare function createApiClient(cfg: ResolvedConfig): ApiClient;
|
|
582
|
+
|
|
583
|
+
declare function registryRpc(chain: Chain | null): string;
|
|
584
|
+
interface TxPlan {
|
|
585
|
+
from?: string;
|
|
586
|
+
to?: string;
|
|
587
|
+
data?: string;
|
|
588
|
+
value?: string;
|
|
589
|
+
minNonce?: number;
|
|
590
|
+
}
|
|
591
|
+
declare function txMatchesPlan(tx: any, plan: TxPlan): boolean;
|
|
592
|
+
interface VerifyResult {
|
|
593
|
+
/** `confirmed` means MINED WITH A SUCCESS RECEIPT — never merely broadcast. `reverted` is a real
|
|
594
|
+
* on-chain failure (receipt status 0x0). `unconfirmed` means we could not establish either, and
|
|
595
|
+
* must NOT be presented to the payer as a completed payment. */
|
|
596
|
+
status: "confirmed" | "mismatch" | "reverted" | "unconfirmed";
|
|
597
|
+
reason?: string;
|
|
598
|
+
}
|
|
599
|
+
/** One ERC-20 balance to read: the token, its chain, and its decimals (for display formatting). */
|
|
600
|
+
interface BalanceTarget {
|
|
601
|
+
chainId: number;
|
|
602
|
+
tokenAddress: string;
|
|
603
|
+
decimals: number;
|
|
604
|
+
}
|
|
605
|
+
/** A read balance. `raw` is the base-unit integer as a decimal string; `formatted` is display-safe. */
|
|
606
|
+
interface BalanceEntry {
|
|
607
|
+
raw: string;
|
|
608
|
+
formatted: string;
|
|
609
|
+
}
|
|
610
|
+
interface Verifier {
|
|
611
|
+
payerNonceBaseline: (chainId: number, account: string) => Promise<number | null>;
|
|
612
|
+
verifySubmittedTx: (args: {
|
|
613
|
+
chainId: number;
|
|
614
|
+
hash: string;
|
|
615
|
+
from?: string;
|
|
616
|
+
to?: string;
|
|
617
|
+
data?: string;
|
|
618
|
+
value?: string;
|
|
619
|
+
minNonce?: number;
|
|
620
|
+
}) => Promise<VerifyResult>;
|
|
621
|
+
/** Read the payer's ERC-20 balance for each target, keyed `${chainId}:${tokenAddress.toLowerCase()}`.
|
|
622
|
+
* Read-only, off the same public-RPC path as settlement verification. Fail-open: a target whose
|
|
623
|
+
* RPC read fails is simply omitted from the result (never throws, never blocks a route). */
|
|
624
|
+
readBalances: (account: string, targets: BalanceTarget[]) => Promise<Record<string, BalanceEntry>>;
|
|
625
|
+
/** Payer's native (gas-token) balance in wei on `chainId`, or null when it cannot be read.
|
|
626
|
+
* Fail-open by contract: callers must treat null as "unknown", never as "zero". */
|
|
627
|
+
readNativeBalance: (chainId: number, account: string) => Promise<bigint | null>;
|
|
628
|
+
}
|
|
629
|
+
declare function createVerifier(api: ApiClient, fetchImpl: typeof fetch, rpcOverrides?: Record<number, string>): Verifier;
|
|
630
|
+
|
|
631
|
+
export { isExecutableBridge as $, type Availability as A, type BrokenLane as B, type Catalogue as C, type Destination as D, type EngineConfig as E, type FetchQuoteFn as F, apiError as G, type Hex as H, brokenLaneFor as I, buildCatalogue as J, canAttachApiKey as K, classifyQuoteError as L, createApiClient 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, createVerifier as U, type VerifyResult as V, destinationKeys as W, executableRoutes as X, executionChainIds as Y, hasReachableDestination as Z, hubDeliverableSymbols as _, type Chain as a, isKnownUnbridgeable as a0, isSourceToken as a1, laneKey as a2, laneKeys as a3, parseAllowedApiBase as a4, productAssets as a5, registryRpc as a6, resolveApiBase as a7, resolveConfig as a8, sourceKeys as a9, suppressedLanes as aa, tokenKey as ab, txMatchesPlan as ac, type ExchangeProduct as b, type RouteResult as c, type TxHistoryEntry as d, assetClassOf as e, brokenLaneReason as f, counterpartTokens as g, destinationAvailability as h, type PayOption as i, type SolveResult as j, type BalanceTarget as k, type BalanceEntry as l, type ApiClient as m, type SwapInput as n, type PlannedTx as o, type Verifier as p, type Address as q, type ApiError as r, type CatalogueContext as s, type CatalogueInput as t, type PlannedTxKind as u, type QuoteBlock as v, type ResolvedConfig as w, type RouteHealth as x, type RouteHealthLane as y, type TxPlan as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glacislabs/stablegenie-zerodelta",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Lightweight embeddable ZeroDelta payment + swap widget (exact-receive Pay and exact-in Swap). Wallet always owns the final signature.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|