@glacislabs/stablegenie-zerodelta 2.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,353 @@
1
+ import { a as Token, Q as Quote, N as NormalizedOrder, b as PayOption, R as RouteResult, C as Chain, c as Route, F as FetchQuoteFn, d as SolveResult, O as OrderRequest, A as ApiClient, P as Plan, e as SwapInput, f as PlannedTx, g as Verifier, T as TxHistoryEntry, S as SanitizedTxEntry, E as EngineConfig } from '../verify-CaO0OD4Z.js';
2
+ export { h as Address, i as ApiError, B as BalanceEntry, j as BalanceTarget, D as Destination, H as Hex, k as PlannedTxKind, l as QuoteBlock, m as ResolvedConfig, n as TxPlan, V as VerifyResult, o as apiError, p as canAttachApiKey, q as classifyQuoteError, r as createApiClient, s as createVerifier, t as parseAllowedApiBase, u as registryRpc, v as resolveApiBase, w as resolveConfig, x as txMatchesPlan } from '../verify-CaO0OD4Z.js';
3
+
4
+ /** Default request base for the widget: the same-origin keyless custody proxy (server injects the
5
+ * ZeroDelta key). A host may override to `/api/v1` + an apiKey for the demo-first fallback path. */
6
+ declare const DEFAULT_WIDGET_API_BASE = "/api/widget/v1";
7
+ declare const SUPPORTED_CHAIN_IDS: ReadonlySet<number>;
8
+ declare const SUPPORTED_ASSETS: ReadonlySet<string>;
9
+ declare const API_CACHE_TTL_MS = 60000;
10
+ declare const MAX_QUOTE_CANDIDATES = 8;
11
+ declare const QUOTE_BUFFER_BPS = 50;
12
+ declare const LZ_FEE_BUFFER_BPS = 1500n;
13
+ declare const SUBMIT_ORDER_SELECTOR = "0xbbd71141";
14
+ declare const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
15
+ declare const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
16
+ declare const ERC20_ALLOWANCE_SELECTOR = "0xdd62ed3e";
17
+ declare const ERC20_BALANCEOF_SELECTOR = "0x70a08231";
18
+ declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
19
+ declare const PREVIEW_OWNER = "0x1111111111111111111111111111111111111111";
20
+ declare const CANONICAL_DECIMALS: Record<string, number>;
21
+ declare const CANONICAL_ESCROW: Record<number, string>;
22
+ declare const MAX_LZ_MSG_VALUE_WEI: bigint;
23
+ declare const MAX_LZ_MSG_VALUE_WEI_BY_CHAIN: Record<number, bigint>;
24
+ /** Cap on the raw, pre-buffer native bridge fee for `chainId`. */
25
+ declare function maxNativeFeeWei(chainId: number): bigint;
26
+ declare const CANONICAL_INBOUND_BRIDGE: Record<string, "layerzero" | "cctp">;
27
+ declare const SAME_CLASS_STABLE: ReadonlySet<string>;
28
+ declare const MAX_SAME_CLASS_PAY_BPS = 30000n;
29
+ declare const BUNDLED_NATIVE_SYMBOL: Record<number, string>;
30
+ declare const BUNDLED_RPC: Record<number, string>;
31
+
32
+ declare function symbolKey(value: unknown): string;
33
+ declare function isAddress(value: unknown): boolean;
34
+ declare function normalizeAddress(value: unknown): string | null;
35
+ declare function assertAddress(value: unknown, label: string): string;
36
+ declare function resolveSwapReceiver(recipient: unknown, payer: unknown): string;
37
+
38
+ declare function assetDecimals(token: Partial<Token> | undefined | null): number;
39
+ declare function normalizeDecimalText(value: unknown): string;
40
+ declare function parseUnitsDecimal(amount: unknown, decimals: number): bigint;
41
+ declare function scaleDecimals(amount: bigint, fromDecimals: number, toDecimals: number): bigint;
42
+ declare function formatUnits(raw: string | bigint | number, decimals: number, maxDecimals?: number): string;
43
+ declare function finalOf(quote: Quote | undefined | null): bigint;
44
+
45
+ declare function strip0x(value: unknown): string;
46
+ declare function uintWord(value: bigint | number | string): string;
47
+ declare function addressWord(address: string): string;
48
+ declare function bytesPayload(value: string): string;
49
+ declare function encodeApprove(spender: string, amount: bigint | number | string): string;
50
+ declare function encodeTransfer(to: string, amount: bigint | number | string): string;
51
+ declare function encodeAllowance(owner: string, spender: string): string;
52
+ declare function encodeBalanceOf(account: string): string;
53
+ declare function encodeSubmitOrder(order: NormalizedOrder): string;
54
+ declare function toHexQuantity(value: bigint | number | string): string;
55
+
56
+ /**
57
+ * Resolve the escrow that will receive the approval and the submitOrder call.
58
+ *
59
+ * Three gates, all fail-closed:
60
+ * 1. the chain registry must supply a real escrow;
61
+ * 2. the quote must ALSO supply one, and the two must agree — an absent `quote.escrowAddress` used
62
+ * to skip the comparison entirely (`if (fromQuote && …)`), so omitting the field disabled the
63
+ * cross-check rather than failing it;
64
+ * 3. when an offline pin exists for the chain it overrides both, because gates 1 and 2 read from
65
+ * the same untrusted API and cannot detect a consistently-hostile backend.
66
+ */
67
+ declare function checkEscrow(chainId: number, quoteEscrow: unknown, chainsEscrow: unknown): string;
68
+ /** Label-based LayerZero sniff. Only a HINT: it is true-positive but not true-negative, because a
69
+ * cross-token quote with mixed legs reports `bridge: "auto"`. Never gate native value on this alone
70
+ * — use {@link requiresNativeBridgeFee}. Kept exported for labelling and as the unknown-asset
71
+ * fallback. */
72
+ declare function isLayerZeroRoute(quote: Quote | undefined | null, option?: Partial<PayOption>): boolean;
73
+ /**
74
+ * Whether this route's inbound leg charges a native bridge fee that must ride along as msg.value.
75
+ *
76
+ * Decided by the SOURCE asset's pinned bridge standard, never by the aggregate `quote.bridge` label:
77
+ * the escrow picks its inbound adapter from `bidToken`, so the bid asset alone determines whether
78
+ * a native fee is owed. Fail-closed for unsupported assets via the (weaker) label sniff.
79
+ */
80
+ declare function requiresNativeBridgeFee(quote: Quote | undefined | null, option?: Partial<PayOption>): boolean;
81
+ declare function applyLayerZeroBuffer(quote: Quote | undefined | null, option?: Partial<PayOption>): bigint;
82
+
83
+ /** Native wei the route's settling tx must carry as msg.value. 0 for CCTP and direct transfers. */
84
+ declare function routeNativeValue(route: RouteResult | null | undefined): bigint;
85
+ /** Gas-token symbol for a chain. Registry first (operator-fixable), then the bundled fallback. */
86
+ declare function nativeSymbol(chainId: number, chains?: Chain[]): string;
87
+ /** Render wei for humans without ever collapsing a real fee to a bare "0". */
88
+ declare function formatNative(wei: bigint): string;
89
+ interface NativeFeeCheck {
90
+ /** msg.value the settling tx needs, in wei. */
91
+ required: bigint;
92
+ /** Payer's native balance, or null when unknown (RPC failed / not read yet). */
93
+ balance: bigint | null;
94
+ /** True only when we KNOW the balance and it cannot cover `required`. */
95
+ short: boolean;
96
+ /** `required - balance`, or 0 when covered/unknown. */
97
+ shortfall: bigint;
98
+ }
99
+ /**
100
+ * Compare a route's native requirement against the payer's balance.
101
+ *
102
+ * Fail-OPEN on an unknown balance: a flaky RPC must never block a payment the wallet could have
103
+ * settled. The check is also deliberately one-sided — `balance >= required` does not guarantee the
104
+ * send succeeds, because gas is owed on top; it only rules out the case that is certainly doomed.
105
+ */
106
+ declare function checkNativeFee(route: RouteResult | null | undefined, balance: bigint | null): NativeFeeCheck;
107
+ /** Short CTA label for a shortfall, or null when nothing is short. */
108
+ declare function nativeFeeShortLabel(check: NativeFeeCheck, symbol: string): string | null;
109
+ /** Full sentence for the error panel / pre-sign refusal. */
110
+ declare function nativeFeeShortMessage(check: NativeFeeCheck, symbol: string, chainName: string): string;
111
+
112
+ declare function chainNameOf(chainId: number, chains: Chain[]): string;
113
+ declare function chainById(chains: Chain[], chainId: number): Chain | null;
114
+ declare function isDeliverable(symbol: string, chainId: number): boolean;
115
+ declare function chainSelectable(chain: Chain | null, chainId: number): boolean;
116
+ declare function tokenEnabled(token: Partial<Token> | undefined | null): boolean;
117
+ declare function findToken(tokens: Token[], chainId: number, symbol: string): Token | null;
118
+ interface BuildPayOptionsArgs {
119
+ invoiceAsset: string;
120
+ invoiceChainId: number;
121
+ tokens: Token[];
122
+ routes: Route[];
123
+ chains: Chain[];
124
+ walletChainId?: number;
125
+ }
126
+ declare function buildPayOptions({ invoiceAsset, invoiceChainId, tokens, routes, chains, walletChainId }: BuildPayOptionsArgs): PayOption[];
127
+
128
+ interface SolveArgs {
129
+ option: PayOption;
130
+ destination: {
131
+ amount?: string;
132
+ chainId: number | string;
133
+ address: string;
134
+ };
135
+ destinationToken: Token;
136
+ payer: string;
137
+ fetchQuote: FetchQuoteFn;
138
+ amountInRaw?: string | bigint;
139
+ }
140
+ declare function solveExactOut({ option, destination, destinationToken, payer, fetchQuote }: SolveArgs): Promise<SolveResult>;
141
+ declare function solveExactIn({ option, destination, destinationToken, payer, fetchQuote, amountInRaw }: SolveArgs): Promise<SolveResult>;
142
+
143
+ declare function normalizeOrderRequest(order: OrderRequest, payer: string, destination: {
144
+ address: string;
145
+ chainId: number | string;
146
+ }): NormalizedOrder;
147
+ interface AssertQuoteArgs {
148
+ quote: Quote;
149
+ order: NormalizedOrder;
150
+ option: PayOption;
151
+ destinationToken: Token;
152
+ destination: {
153
+ address: string;
154
+ chainId: number | string;
155
+ };
156
+ payer: string;
157
+ result: SolveResult;
158
+ }
159
+ declare function assertQuoteMatchesSelection({ quote, order, option, destinationToken, destination, payer, result }: AssertQuoteArgs): void;
160
+
161
+ interface BuildRouteArgs {
162
+ option: PayOption;
163
+ destination: {
164
+ address: string;
165
+ chainId: number | string;
166
+ amount?: string;
167
+ };
168
+ destinationToken: Token;
169
+ chains: Chain[];
170
+ payer: string;
171
+ fetchQuote: FetchQuoteFn;
172
+ solve?: typeof solveExactOut;
173
+ amountInRaw?: string | bigint;
174
+ }
175
+ declare function buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote, solve, amountInRaw }: BuildRouteArgs): Promise<RouteResult>;
176
+
177
+ interface PayRequest {
178
+ address: string;
179
+ chainId: number;
180
+ asset: string;
181
+ amount: string;
182
+ }
183
+ declare function validateDestination(destination: PayRequest): void;
184
+ declare function planErrorSummary(errors: unknown[]): string;
185
+ declare function fetchPaymentPlan(api: ApiClient, request: PayRequest, payer: string, wallet?: {
186
+ chainId?: number;
187
+ }): Promise<Plan>;
188
+
189
+ interface ValidatedSwap {
190
+ fromChainId: number;
191
+ toChainId: number;
192
+ fromToken: string;
193
+ toToken: string;
194
+ amountIn: string;
195
+ }
196
+ declare function validateSwap(swap?: Partial<SwapInput>): ValidatedSwap;
197
+ interface SwapPreview {
198
+ receive: string;
199
+ receiveRaw: string;
200
+ fromAmount: string;
201
+ fromToken: string;
202
+ toToken: string;
203
+ bridge: string;
204
+ feeBps: number;
205
+ estimatedDuration: number;
206
+ }
207
+ declare function quoteSwapPreview(api: ApiClient, swap: SwapInput, owner?: string): Promise<SwapPreview>;
208
+ declare function buildSwapPlan(api: ApiClient, swap: SwapInput, payer: string, wallet?: {
209
+ chainId?: number;
210
+ }): Promise<Plan>;
211
+
212
+ declare function isHexAddress(value: unknown): boolean;
213
+ declare function isHexData(value: unknown): boolean;
214
+ declare function isHexQuantity(value: unknown): boolean;
215
+ declare function planMsgValueHex(route: RouteResult | undefined | null): string | null;
216
+ /**
217
+ * Validate a single planned tx before signing.
218
+ * @param expectedRecipient the destination address the transfer must pay (the merchant/receiver).
219
+ */
220
+ declare function validatePlannedTransaction(tx: PlannedTx | undefined | null, route: RouteResult, expectedRecipient: string): boolean;
221
+ /** Whether an existing ERC-20 allowance already covers an approve tx (lets the flow skip it). */
222
+ declare function allowanceCovers(tx: PlannedTx, account: string, ethCall: (to: string, data: string) => Promise<string>): Promise<boolean>;
223
+
224
+ declare const STABLEGENIE_INTENT_VERSION = 1;
225
+ declare const STABLEGENIE_INTENT_TTL_MS: number;
226
+ declare const STABLEGENIE_SUPPORTED_CHAIN_IDS: readonly number[];
227
+ declare const STABLEGENIE_SUPPORTED_ASSETS: readonly string[];
228
+ declare const stableGenieIntentSchema: {
229
+ readonly type: "object";
230
+ readonly additionalProperties: false;
231
+ readonly required: readonly ["version", "product", "lane", "nonce", "createdAt", "expiresAt", "sourcePage", "destination"];
232
+ readonly properties: {
233
+ readonly version: {
234
+ readonly const: 1;
235
+ };
236
+ readonly product: {
237
+ readonly const: "stablegenie";
238
+ };
239
+ readonly lane: {
240
+ readonly enum: readonly ["CRYPTO_TO_CRYPTO"];
241
+ };
242
+ readonly status: {
243
+ readonly enum: readonly ["unsigned", "quoted", "submitted", "settled", "expired"];
244
+ };
245
+ readonly nonce: {
246
+ readonly type: "string";
247
+ readonly minLength: 16;
248
+ readonly maxLength: 128;
249
+ };
250
+ readonly createdAt: {
251
+ readonly type: "string";
252
+ readonly format: "date-time";
253
+ };
254
+ readonly expiresAt: {
255
+ readonly type: "string";
256
+ readonly format: "date-time";
257
+ };
258
+ readonly intentHash: {
259
+ readonly type: "string";
260
+ readonly pattern: "^0x[a-fA-F0-9]{64}$";
261
+ };
262
+ readonly sourcePage: {
263
+ readonly type: "object";
264
+ readonly additionalProperties: false;
265
+ readonly required: readonly ["origin", "url"];
266
+ readonly properties: {
267
+ readonly origin: {
268
+ readonly type: "string";
269
+ readonly pattern: "^https?://";
270
+ };
271
+ readonly url: {
272
+ readonly type: "string";
273
+ readonly pattern: "^https?://";
274
+ };
275
+ readonly title: {
276
+ readonly type: "string";
277
+ readonly maxLength: 256;
278
+ };
279
+ };
280
+ };
281
+ readonly destination: {
282
+ readonly type: "object";
283
+ readonly additionalProperties: false;
284
+ readonly required: readonly ["address", "chainId", "asset", "amount"];
285
+ readonly properties: {
286
+ readonly address: {
287
+ readonly type: "string";
288
+ readonly pattern: "^0x[a-fA-F0-9]{40}$";
289
+ };
290
+ readonly chainId: {
291
+ readonly type: "integer";
292
+ readonly enum: readonly number[];
293
+ };
294
+ readonly chainName: {
295
+ readonly type: "string";
296
+ readonly maxLength: 64;
297
+ };
298
+ readonly asset: {
299
+ readonly type: "string";
300
+ readonly enum: readonly string[];
301
+ };
302
+ readonly amount: {
303
+ readonly type: "string";
304
+ readonly pattern: "^(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$";
305
+ };
306
+ };
307
+ };
308
+ readonly detector: {
309
+ readonly type: "object";
310
+ readonly additionalProperties: false;
311
+ readonly properties: {
312
+ readonly confidence: {
313
+ readonly type: "number";
314
+ readonly minimum: 0;
315
+ readonly maximum: 1;
316
+ };
317
+ readonly evidence: {
318
+ readonly type: "object";
319
+ };
320
+ readonly elementText: {
321
+ readonly type: "string";
322
+ readonly maxLength: 500;
323
+ };
324
+ };
325
+ };
326
+ };
327
+ };
328
+
329
+ interface Engine {
330
+ api: ApiClient;
331
+ verifier: Verifier;
332
+ apiBase: string;
333
+ fetchChains: ApiClient["fetchChains"];
334
+ fetchTokens: ApiClient["fetchTokens"];
335
+ fetchRoutes: ApiClient["fetchRoutes"];
336
+ fetchQuote: ApiClient["fetchQuote"];
337
+ fetchPaymentPlan: (request: PayRequest, payer: string, wallet?: {
338
+ chainId?: number;
339
+ }) => Promise<Plan>;
340
+ quoteSwapPreview: (swap: SwapInput, owner?: string) => Promise<SwapPreview>;
341
+ buildSwapPlan: (swap: SwapInput, payer: string, wallet?: {
342
+ chainId?: number;
343
+ }) => Promise<Plan>;
344
+ payerNonceBaseline: Verifier["payerNonceBaseline"];
345
+ verifySubmittedTx: Verifier["verifySubmittedTx"];
346
+ readBalances: Verifier["readBalances"];
347
+ readNativeBalance: Verifier["readNativeBalance"];
348
+ recordTransaction: (entry: TxHistoryEntry) => SanitizedTxEntry;
349
+ }
350
+ /** Create an engine bound to a config. The 60s resource cache is per-engine. */
351
+ declare function createEngine(config?: EngineConfig): Engine;
352
+
353
+ export { API_CACHE_TTL_MS, ApiClient, type AssertQuoteArgs, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, type BuildPayOptionsArgs, type BuildRouteArgs, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, Chain, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, type Engine, EngineConfig, FetchQuoteFn, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, type NativeFeeCheck, NormalizedOrder, OrderRequest, PREVIEW_OWNER, PayOption, type PayRequest, Plan, PlannedTx, QUOTE_BUFFER_BPS, Quote, Route, RouteResult, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, SanitizedTxEntry, type SolveArgs, SolveResult, SwapInput, type SwapPreview, Token, TxHistoryEntry, type ValidatedSwap, Verifier, ZERO_ADDRESS, addressWord, allowanceCovers, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytesPayload, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, createEngine, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, requiresNativeBridgeFee, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
@@ -0,0 +1 @@
1
+ export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetDecimals, buildPayOptions, buildRoute, buildSwapPlan, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, createApiClient, createEngine, createVerifier, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, isAddress, isDeliverable, isHexAddress, isHexData, isHexQuantity, isLayerZeroRoute, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, stableGenieIntentSchema, strip0x, symbolKey, toHexQuantity, tokenEnabled, txMatchesPlan, uintWord, validateDestination, validatePlannedTransaction, validateSwap } from '../chunk-VL5MWEY2.js';