@blazephoenix/sdk 0.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/LICENSE +21 -0
- package/README.md +184 -0
- package/dist/index.cjs +564 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +805 -0
- package/dist/index.d.ts +805 -0
- package/dist/index.js +540 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
1
|
+
type Address = `0x${string}`;
|
|
2
|
+
type Hex = `0x${string}`;
|
|
3
|
+
/** Chain selector: id (1, 8453, 10, 42161) or name ("base", "eth", …). */
|
|
4
|
+
type ChainRef = number | string;
|
|
5
|
+
/** Token selector: 0x-address, ETH / WETH / USDC / BZPX, or (single-quote
|
|
6
|
+
* endpoint only) ANY traded symbol — the API resolves unknown tickers to the
|
|
7
|
+
* deepest-liquidity token on that chain and echoes the resolution back in
|
|
8
|
+
* `resolved`. Pass 0x addresses when you need precision; the batch endpoint
|
|
9
|
+
* takes addresses/built-in symbols only. */
|
|
10
|
+
type TokenRef = string;
|
|
11
|
+
interface QuoteRequest {
|
|
12
|
+
chain: ChainRef;
|
|
13
|
+
tokenIn: TokenRef;
|
|
14
|
+
tokenOut: TokenRef;
|
|
15
|
+
/** Input amount in the token's base units (wei-style). */
|
|
16
|
+
amountIn: bigint | string;
|
|
17
|
+
/** When set, the response includes ready-to-send `tx` calldata. */
|
|
18
|
+
recipient?: Address;
|
|
19
|
+
/** 0–5000. Default: the protocol's own execution floor (effectiveMinOut). */
|
|
20
|
+
slippageBps?: number;
|
|
21
|
+
/** 10–3600 seconds. Default 120. */
|
|
22
|
+
deadlineSec?: number;
|
|
23
|
+
/** Execution-grade re-quote (previewPlanExact) — slower, sharper. */
|
|
24
|
+
exact?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface QuoteLeg {
|
|
27
|
+
pool: Address;
|
|
28
|
+
hooks: Address;
|
|
29
|
+
kind: number;
|
|
30
|
+
fee: number;
|
|
31
|
+
tickSpacing: number;
|
|
32
|
+
zeroForOne: boolean;
|
|
33
|
+
stable: boolean;
|
|
34
|
+
amountIn: string;
|
|
35
|
+
expectedOut: string;
|
|
36
|
+
auxId: Hex;
|
|
37
|
+
}
|
|
38
|
+
interface QuoteHop {
|
|
39
|
+
tokenIn: Address;
|
|
40
|
+
tokenOut: Address;
|
|
41
|
+
amountIn: string;
|
|
42
|
+
expectedOut: string;
|
|
43
|
+
legs: QuoteLeg[];
|
|
44
|
+
}
|
|
45
|
+
interface QuoteRoute {
|
|
46
|
+
hops: QuoteHop[];
|
|
47
|
+
totalOut: string;
|
|
48
|
+
singleOut: string;
|
|
49
|
+
singleOutFloor: string;
|
|
50
|
+
expectedImpactBps: string;
|
|
51
|
+
confidenceWad: string;
|
|
52
|
+
estGas: string;
|
|
53
|
+
hasSurplus: boolean;
|
|
54
|
+
isV4Bundle: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface QuoteSummary {
|
|
57
|
+
grossOut: string;
|
|
58
|
+
protocolFee: string;
|
|
59
|
+
netOut: string;
|
|
60
|
+
ironFloor: string;
|
|
61
|
+
effectiveMinOut: string;
|
|
62
|
+
impactBps: number;
|
|
63
|
+
estGas: string;
|
|
64
|
+
hops: number;
|
|
65
|
+
legs: number;
|
|
66
|
+
canExecute: boolean;
|
|
67
|
+
hasSurplus: boolean;
|
|
68
|
+
feeBps: number;
|
|
69
|
+
}
|
|
70
|
+
interface QuoteTx {
|
|
71
|
+
to: Address;
|
|
72
|
+
data: Hex;
|
|
73
|
+
value: '0';
|
|
74
|
+
}
|
|
75
|
+
interface QuoteResponse {
|
|
76
|
+
ok: true;
|
|
77
|
+
mode: 'preview' | 'exact';
|
|
78
|
+
chainId: number;
|
|
79
|
+
tokenIn: Address;
|
|
80
|
+
tokenOut: Address;
|
|
81
|
+
amountIn: string;
|
|
82
|
+
/** Net output after the protocol fee — the number to compare across venues. */
|
|
83
|
+
amountOut: string;
|
|
84
|
+
quote?: QuoteSummary;
|
|
85
|
+
route: QuoteRoute;
|
|
86
|
+
tx?: QuoteTx;
|
|
87
|
+
wrapRequired: boolean;
|
|
88
|
+
unwrapAfter?: boolean;
|
|
89
|
+
/** Present when a symbol was resolved server-side: per side
|
|
90
|
+
* { symbol, address, name?, liquidityUsd }. Always check it when quoting
|
|
91
|
+
* by ticker — it tells you exactly which token you got. */
|
|
92
|
+
resolved?: Record<string, {
|
|
93
|
+
symbol: string;
|
|
94
|
+
address: Address;
|
|
95
|
+
name?: string;
|
|
96
|
+
liquidityUsd: number;
|
|
97
|
+
}>;
|
|
98
|
+
resolvedNote?: string;
|
|
99
|
+
executeWith?: {
|
|
100
|
+
router: Address;
|
|
101
|
+
function: string;
|
|
102
|
+
note: string;
|
|
103
|
+
};
|
|
104
|
+
meta: {
|
|
105
|
+
quotedAt: number;
|
|
106
|
+
latencyMs: number;
|
|
107
|
+
rpcTried: number;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface ApiErrorBody {
|
|
111
|
+
ok: false;
|
|
112
|
+
code: string;
|
|
113
|
+
error: string;
|
|
114
|
+
chainId?: number;
|
|
115
|
+
}
|
|
116
|
+
type BatchResult = QuoteResponse | ApiErrorBody;
|
|
117
|
+
interface BatchResponse {
|
|
118
|
+
ok: true;
|
|
119
|
+
count: number;
|
|
120
|
+
results: BatchResult[];
|
|
121
|
+
}
|
|
122
|
+
interface ManifestChain {
|
|
123
|
+
chainId: number;
|
|
124
|
+
name: string;
|
|
125
|
+
live: boolean;
|
|
126
|
+
explorer: string;
|
|
127
|
+
contracts: {
|
|
128
|
+
hub: Address;
|
|
129
|
+
solver: Address;
|
|
130
|
+
router: Address;
|
|
131
|
+
quoter: Address;
|
|
132
|
+
staking: Address;
|
|
133
|
+
};
|
|
134
|
+
weth: Address;
|
|
135
|
+
usdc: Address;
|
|
136
|
+
bzpx?: Address;
|
|
137
|
+
}
|
|
138
|
+
interface ManifestResponse {
|
|
139
|
+
ok: true;
|
|
140
|
+
name: string;
|
|
141
|
+
version: string;
|
|
142
|
+
url: string;
|
|
143
|
+
docs: string;
|
|
144
|
+
quoteApi: string;
|
|
145
|
+
token: {
|
|
146
|
+
symbol: string;
|
|
147
|
+
chain: string;
|
|
148
|
+
address: Address;
|
|
149
|
+
basescan: string;
|
|
150
|
+
totalSupply: string;
|
|
151
|
+
};
|
|
152
|
+
feeBps: number;
|
|
153
|
+
chains: ManifestChain[];
|
|
154
|
+
events: Record<string, {
|
|
155
|
+
signature: string;
|
|
156
|
+
topic0: Hex;
|
|
157
|
+
}>;
|
|
158
|
+
contact: string;
|
|
159
|
+
}
|
|
160
|
+
interface HealthResponse {
|
|
161
|
+
ok: true;
|
|
162
|
+
service: string;
|
|
163
|
+
version: string;
|
|
164
|
+
now: number;
|
|
165
|
+
chains: {
|
|
166
|
+
chainId: number;
|
|
167
|
+
name: string;
|
|
168
|
+
live: boolean;
|
|
169
|
+
}[];
|
|
170
|
+
}
|
|
171
|
+
/** A decoded on-chain fill (Router `Swap` event). */
|
|
172
|
+
interface Fill {
|
|
173
|
+
txHash: Hex;
|
|
174
|
+
blockNumber: bigint;
|
|
175
|
+
user: Address;
|
|
176
|
+
tokenIn: Address;
|
|
177
|
+
tokenOut: Address;
|
|
178
|
+
amountIn: bigint;
|
|
179
|
+
amountOut: bigint;
|
|
180
|
+
legs: bigint;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
declare class BlazeApiError extends Error {
|
|
184
|
+
readonly code: string;
|
|
185
|
+
readonly status: number;
|
|
186
|
+
constructor(code: string, message: string, status: number);
|
|
187
|
+
}
|
|
188
|
+
interface ClientOptions {
|
|
189
|
+
/** Override the API origin (e.g. a mirror). Default: https://blazephoenix.xyz */
|
|
190
|
+
baseUrl?: string;
|
|
191
|
+
/** Custom fetch (tests, proxies). Default: globalThis.fetch. */
|
|
192
|
+
fetchFn?: typeof fetch;
|
|
193
|
+
/** Per-request timeout in ms. Default 15000. */
|
|
194
|
+
timeoutMs?: number;
|
|
195
|
+
/** Extra attempts on transient failures (network, 429, 502-504), honouring
|
|
196
|
+
* the server's retry-after. Default 2. Set 0 to disable. */
|
|
197
|
+
retries?: number;
|
|
198
|
+
/** Micro-cache for PREVIEW quotes (no recipient, no exact) — absorbs hot
|
|
199
|
+
* loops without serving stale execution data. Default 1000ms; 0 disables. */
|
|
200
|
+
cacheTtlMs?: number;
|
|
201
|
+
}
|
|
202
|
+
declare class BlazePhoenix {
|
|
203
|
+
private readonly base;
|
|
204
|
+
private readonly fetchFn;
|
|
205
|
+
private readonly timeoutMs;
|
|
206
|
+
private readonly retries;
|
|
207
|
+
private readonly cacheTtlMs;
|
|
208
|
+
constructor(opts?: ClientOptions);
|
|
209
|
+
/** Build the GET /api/quote URL for a request (useful for logging/debugging). */
|
|
210
|
+
quoteUrl(req: QuoteRequest): string;
|
|
211
|
+
private call;
|
|
212
|
+
/** One quote — previewPlan computed on-chain. Throws BlazeApiError on failure.
|
|
213
|
+
* Identical concurrent calls share one request; preview quotes ride a tiny
|
|
214
|
+
* micro-cache (cacheTtlMs) so hot loops never hammer the wire. */
|
|
215
|
+
quote(req: QuoteRequest): Promise<QuoteResponse>;
|
|
216
|
+
/** Up to 10 quotes in one round-trip (screeners / arb loops).
|
|
217
|
+
* Per-item failures come back inline — the batch itself only throws on
|
|
218
|
+
* transport/validation errors. Identical concurrent batches coalesce. */
|
|
219
|
+
quoteBatch(reqs: QuoteRequest[]): Promise<BatchResponse>;
|
|
220
|
+
/** Service health + per-chain live flags. Zero upstream cost server-side —
|
|
221
|
+
* poll it from your monitor as often as you like. */
|
|
222
|
+
health(): Promise<HealthResponse>;
|
|
223
|
+
/** Machine-readable protocol manifest — near-static, cached for 1h. */
|
|
224
|
+
manifest(): Promise<ManifestResponse>;
|
|
225
|
+
}
|
|
226
|
+
interface PollOptions {
|
|
227
|
+
/** Tick interval in ms (min 500, default 4000). */
|
|
228
|
+
intervalMs?: number;
|
|
229
|
+
onError?: (e: unknown) => void;
|
|
230
|
+
}
|
|
231
|
+
/** Poll a pair and get called back with each fresh quote — the heartbeat of a
|
|
232
|
+
* price bot in one line. Overlap-safe (a slow tick is skipped, not stacked).
|
|
233
|
+
* Returns a stop function. */
|
|
234
|
+
declare function pollQuote(client: BlazePhoenix, req: QuoteRequest, onQuote: (q: QuoteResponse) => void, opts?: PollOptions): () => void;
|
|
235
|
+
/** The ready-to-broadcast transaction from a quote (requires `recipient` in the
|
|
236
|
+
* request and an ERC-20 input). Throws with a precise reason otherwise. */
|
|
237
|
+
declare function buildSwapTx(q: QuoteResponse): QuoteTx;
|
|
238
|
+
interface DeepLinkOptions {
|
|
239
|
+
chain?: number | string;
|
|
240
|
+
tokenIn?: string;
|
|
241
|
+
tokenOut?: string;
|
|
242
|
+
/** Human units for the pay field (e.g. "0.5"). */
|
|
243
|
+
amount?: string;
|
|
244
|
+
tab?: 'home' | 'swap' | 'staking' | 'airdrop' | 'api';
|
|
245
|
+
baseUrl?: string;
|
|
246
|
+
}
|
|
247
|
+
/** A shareable link that opens the site pre-filled — bot buttons, referral posts. */
|
|
248
|
+
declare function deepLink(opts?: DeepLinkOptions): string;
|
|
249
|
+
|
|
250
|
+
/** Coalesce concurrent identical work — leader runs, followers share. */
|
|
251
|
+
declare function singleflight<T>(key: string, fn: () => Promise<T>): Promise<T>;
|
|
252
|
+
interface RetryOptions {
|
|
253
|
+
/** Extra attempts after the first (default 2). */
|
|
254
|
+
retries?: number;
|
|
255
|
+
/** Base backoff in ms; grows ×3 per attempt with jitter (default 250). */
|
|
256
|
+
backoffMs?: number;
|
|
257
|
+
timeoutMs?: number;
|
|
258
|
+
}
|
|
259
|
+
/** fetch with timeout + polite retries. Returns the final Response (which may
|
|
260
|
+
* still be an error status — non-transient statuses are never retried). */
|
|
261
|
+
declare function resilientFetch(fetchFn: typeof fetch, url: string, init: RequestInit | undefined, opts?: RetryOptions): Promise<Response>;
|
|
262
|
+
|
|
263
|
+
declare const API_BASE = "https://blazephoenix.xyz";
|
|
264
|
+
type SupportedChainId = 1 | 8453 | 10 | 42161;
|
|
265
|
+
interface ChainInfo {
|
|
266
|
+
chainId: SupportedChainId;
|
|
267
|
+
name: string;
|
|
268
|
+
explorer: string;
|
|
269
|
+
weth: `0x${string}`;
|
|
270
|
+
usdc: `0x${string}`;
|
|
271
|
+
bzpx?: `0x${string}`;
|
|
272
|
+
contracts: {
|
|
273
|
+
hub: `0x${string}`;
|
|
274
|
+
solver: `0x${string}`;
|
|
275
|
+
router: `0x${string}`;
|
|
276
|
+
quoter: `0x${string}`;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
declare const CHAINS: Record<SupportedChainId, ChainInfo>;
|
|
280
|
+
/** Accepts a chain id (number or numeric string) or a human alias. */
|
|
281
|
+
declare function resolveChain(chain: number | string): SupportedChainId;
|
|
282
|
+
/** Public, KEYLESS RPC endpoints per chain — community infrastructure, no
|
|
283
|
+
* providers, no keys (enforced by tests). They make the on-chain module work
|
|
284
|
+
* with ZERO configuration; production integrations should still bring their
|
|
285
|
+
* own `rpcUrl` for guaranteed throughput. */
|
|
286
|
+
declare const PUBLIC_RPCS: Record<SupportedChainId, string[]>;
|
|
287
|
+
/** Protocol fee (bps) applied to quoted output; execution surplus is fee-exempt. */
|
|
288
|
+
declare const FEE_BPS = 28;
|
|
289
|
+
/** Router event topic0 hashes (one `Swap` per fill — index everything with them).
|
|
290
|
+
* Verified against the ABIs by `npm test` (viem toEventSelector). */
|
|
291
|
+
declare const SWAP_TOPIC0: "0xd6d34547c69c5ee3d2667625c188acf1006abb93e0ee7cf03925c67cf7760413";
|
|
292
|
+
declare const SURPLUS_TOPIC0: "0x1a3afef0f067eb51a6bfec6ab3625a4408dd8c3571b72836483e68feb70d1026";
|
|
293
|
+
|
|
294
|
+
declare const QUOTER_ABI: readonly [{
|
|
295
|
+
readonly type: "function";
|
|
296
|
+
readonly name: "previewPlan";
|
|
297
|
+
readonly stateMutability: "view";
|
|
298
|
+
readonly inputs: readonly [{
|
|
299
|
+
readonly name: "tIn";
|
|
300
|
+
readonly type: "address";
|
|
301
|
+
}, {
|
|
302
|
+
readonly name: "tOut";
|
|
303
|
+
readonly type: "address";
|
|
304
|
+
}, {
|
|
305
|
+
readonly name: "amountIn";
|
|
306
|
+
readonly type: "uint256";
|
|
307
|
+
}];
|
|
308
|
+
readonly outputs: readonly [{
|
|
309
|
+
readonly name: "pv";
|
|
310
|
+
readonly type: "tuple";
|
|
311
|
+
readonly components: readonly [{
|
|
312
|
+
readonly name: "route";
|
|
313
|
+
readonly type: "tuple";
|
|
314
|
+
readonly components: readonly [{
|
|
315
|
+
readonly name: "hops";
|
|
316
|
+
readonly type: "tuple[]";
|
|
317
|
+
readonly components: readonly [{
|
|
318
|
+
readonly name: "tokenIn";
|
|
319
|
+
readonly type: "address";
|
|
320
|
+
}, {
|
|
321
|
+
readonly name: "tokenOut";
|
|
322
|
+
readonly type: "address";
|
|
323
|
+
}, {
|
|
324
|
+
readonly name: "amountIn";
|
|
325
|
+
readonly type: "uint256";
|
|
326
|
+
}, {
|
|
327
|
+
readonly name: "expectedOut";
|
|
328
|
+
readonly type: "uint256";
|
|
329
|
+
}, {
|
|
330
|
+
readonly name: "legs";
|
|
331
|
+
readonly type: "tuple[]";
|
|
332
|
+
readonly components: readonly [{
|
|
333
|
+
readonly name: "pool";
|
|
334
|
+
readonly type: "address";
|
|
335
|
+
}, {
|
|
336
|
+
readonly name: "hooks";
|
|
337
|
+
readonly type: "address";
|
|
338
|
+
}, {
|
|
339
|
+
readonly name: "kind";
|
|
340
|
+
readonly type: "uint8";
|
|
341
|
+
}, {
|
|
342
|
+
readonly name: "fee";
|
|
343
|
+
readonly type: "uint24";
|
|
344
|
+
}, {
|
|
345
|
+
readonly name: "tickSpacing";
|
|
346
|
+
readonly type: "int24";
|
|
347
|
+
}, {
|
|
348
|
+
readonly name: "zeroForOne";
|
|
349
|
+
readonly type: "bool";
|
|
350
|
+
}, {
|
|
351
|
+
readonly name: "stable";
|
|
352
|
+
readonly type: "bool";
|
|
353
|
+
}, {
|
|
354
|
+
readonly name: "amountIn";
|
|
355
|
+
readonly type: "uint256";
|
|
356
|
+
}, {
|
|
357
|
+
readonly name: "expectedOut";
|
|
358
|
+
readonly type: "uint256";
|
|
359
|
+
}, {
|
|
360
|
+
readonly name: "auxId";
|
|
361
|
+
readonly type: "bytes32";
|
|
362
|
+
}];
|
|
363
|
+
}];
|
|
364
|
+
}, {
|
|
365
|
+
readonly name: "totalOut";
|
|
366
|
+
readonly type: "uint256";
|
|
367
|
+
}, {
|
|
368
|
+
readonly name: "singleOut";
|
|
369
|
+
readonly type: "uint256";
|
|
370
|
+
}, {
|
|
371
|
+
readonly name: "singleOutFloor";
|
|
372
|
+
readonly type: "uint256";
|
|
373
|
+
}, {
|
|
374
|
+
readonly name: "expectedImpactBps";
|
|
375
|
+
readonly type: "uint256";
|
|
376
|
+
}, {
|
|
377
|
+
readonly name: "confidenceWad";
|
|
378
|
+
readonly type: "uint256";
|
|
379
|
+
}, {
|
|
380
|
+
readonly name: "estGas";
|
|
381
|
+
readonly type: "uint256";
|
|
382
|
+
}, {
|
|
383
|
+
readonly name: "hasSurplus";
|
|
384
|
+
readonly type: "bool";
|
|
385
|
+
}, {
|
|
386
|
+
readonly name: "isV4Bundle";
|
|
387
|
+
readonly type: "bool";
|
|
388
|
+
}];
|
|
389
|
+
}, {
|
|
390
|
+
readonly name: "grossOut";
|
|
391
|
+
readonly type: "uint256";
|
|
392
|
+
}, {
|
|
393
|
+
readonly name: "protocolFee";
|
|
394
|
+
readonly type: "uint256";
|
|
395
|
+
}, {
|
|
396
|
+
readonly name: "safetyBuffer";
|
|
397
|
+
readonly type: "uint256";
|
|
398
|
+
}, {
|
|
399
|
+
readonly name: "netOut";
|
|
400
|
+
readonly type: "uint256";
|
|
401
|
+
}, {
|
|
402
|
+
readonly name: "ironFloor";
|
|
403
|
+
readonly type: "uint256";
|
|
404
|
+
}, {
|
|
405
|
+
readonly name: "userMinOut";
|
|
406
|
+
readonly type: "uint256";
|
|
407
|
+
}, {
|
|
408
|
+
readonly name: "effectiveMinOut";
|
|
409
|
+
readonly type: "uint256";
|
|
410
|
+
}, {
|
|
411
|
+
readonly name: "estGas";
|
|
412
|
+
readonly type: "uint256";
|
|
413
|
+
}, {
|
|
414
|
+
readonly name: "hops";
|
|
415
|
+
readonly type: "uint256";
|
|
416
|
+
}, {
|
|
417
|
+
readonly name: "legs";
|
|
418
|
+
readonly type: "uint256";
|
|
419
|
+
}, {
|
|
420
|
+
readonly name: "topology";
|
|
421
|
+
readonly type: "uint8";
|
|
422
|
+
}, {
|
|
423
|
+
readonly name: "bridgeUsed";
|
|
424
|
+
readonly type: "address";
|
|
425
|
+
}, {
|
|
426
|
+
readonly name: "canExecute";
|
|
427
|
+
readonly type: "bool";
|
|
428
|
+
}];
|
|
429
|
+
}, {
|
|
430
|
+
readonly name: "fallbackRoute";
|
|
431
|
+
readonly type: "tuple";
|
|
432
|
+
readonly components: readonly [{
|
|
433
|
+
readonly name: "hops";
|
|
434
|
+
readonly type: "tuple[]";
|
|
435
|
+
readonly components: readonly [{
|
|
436
|
+
readonly name: "tokenIn";
|
|
437
|
+
readonly type: "address";
|
|
438
|
+
}, {
|
|
439
|
+
readonly name: "tokenOut";
|
|
440
|
+
readonly type: "address";
|
|
441
|
+
}, {
|
|
442
|
+
readonly name: "amountIn";
|
|
443
|
+
readonly type: "uint256";
|
|
444
|
+
}, {
|
|
445
|
+
readonly name: "expectedOut";
|
|
446
|
+
readonly type: "uint256";
|
|
447
|
+
}, {
|
|
448
|
+
readonly name: "legs";
|
|
449
|
+
readonly type: "tuple[]";
|
|
450
|
+
readonly components: readonly [{
|
|
451
|
+
readonly name: "pool";
|
|
452
|
+
readonly type: "address";
|
|
453
|
+
}, {
|
|
454
|
+
readonly name: "hooks";
|
|
455
|
+
readonly type: "address";
|
|
456
|
+
}, {
|
|
457
|
+
readonly name: "kind";
|
|
458
|
+
readonly type: "uint8";
|
|
459
|
+
}, {
|
|
460
|
+
readonly name: "fee";
|
|
461
|
+
readonly type: "uint24";
|
|
462
|
+
}, {
|
|
463
|
+
readonly name: "tickSpacing";
|
|
464
|
+
readonly type: "int24";
|
|
465
|
+
}, {
|
|
466
|
+
readonly name: "zeroForOne";
|
|
467
|
+
readonly type: "bool";
|
|
468
|
+
}, {
|
|
469
|
+
readonly name: "stable";
|
|
470
|
+
readonly type: "bool";
|
|
471
|
+
}, {
|
|
472
|
+
readonly name: "amountIn";
|
|
473
|
+
readonly type: "uint256";
|
|
474
|
+
}, {
|
|
475
|
+
readonly name: "expectedOut";
|
|
476
|
+
readonly type: "uint256";
|
|
477
|
+
}, {
|
|
478
|
+
readonly name: "auxId";
|
|
479
|
+
readonly type: "bytes32";
|
|
480
|
+
}];
|
|
481
|
+
}];
|
|
482
|
+
}, {
|
|
483
|
+
readonly name: "totalOut";
|
|
484
|
+
readonly type: "uint256";
|
|
485
|
+
}, {
|
|
486
|
+
readonly name: "singleOut";
|
|
487
|
+
readonly type: "uint256";
|
|
488
|
+
}, {
|
|
489
|
+
readonly name: "singleOutFloor";
|
|
490
|
+
readonly type: "uint256";
|
|
491
|
+
}, {
|
|
492
|
+
readonly name: "expectedImpactBps";
|
|
493
|
+
readonly type: "uint256";
|
|
494
|
+
}, {
|
|
495
|
+
readonly name: "confidenceWad";
|
|
496
|
+
readonly type: "uint256";
|
|
497
|
+
}, {
|
|
498
|
+
readonly name: "estGas";
|
|
499
|
+
readonly type: "uint256";
|
|
500
|
+
}, {
|
|
501
|
+
readonly name: "hasSurplus";
|
|
502
|
+
readonly type: "bool";
|
|
503
|
+
}, {
|
|
504
|
+
readonly name: "isV4Bundle";
|
|
505
|
+
readonly type: "bool";
|
|
506
|
+
}];
|
|
507
|
+
}, {
|
|
508
|
+
readonly name: "hasFallback";
|
|
509
|
+
readonly type: "bool";
|
|
510
|
+
}];
|
|
511
|
+
}, {
|
|
512
|
+
readonly type: "function";
|
|
513
|
+
readonly name: "previewPlanExact";
|
|
514
|
+
readonly stateMutability: "view";
|
|
515
|
+
readonly inputs: readonly [{
|
|
516
|
+
readonly name: "tIn";
|
|
517
|
+
readonly type: "address";
|
|
518
|
+
}, {
|
|
519
|
+
readonly name: "tOut";
|
|
520
|
+
readonly type: "address";
|
|
521
|
+
}, {
|
|
522
|
+
readonly name: "amountIn";
|
|
523
|
+
readonly type: "uint256";
|
|
524
|
+
}];
|
|
525
|
+
readonly outputs: readonly [{
|
|
526
|
+
readonly name: "route";
|
|
527
|
+
readonly type: "tuple";
|
|
528
|
+
readonly components: readonly [{
|
|
529
|
+
readonly name: "hops";
|
|
530
|
+
readonly type: "tuple[]";
|
|
531
|
+
readonly components: readonly [{
|
|
532
|
+
readonly name: "tokenIn";
|
|
533
|
+
readonly type: "address";
|
|
534
|
+
}, {
|
|
535
|
+
readonly name: "tokenOut";
|
|
536
|
+
readonly type: "address";
|
|
537
|
+
}, {
|
|
538
|
+
readonly name: "amountIn";
|
|
539
|
+
readonly type: "uint256";
|
|
540
|
+
}, {
|
|
541
|
+
readonly name: "expectedOut";
|
|
542
|
+
readonly type: "uint256";
|
|
543
|
+
}, {
|
|
544
|
+
readonly name: "legs";
|
|
545
|
+
readonly type: "tuple[]";
|
|
546
|
+
readonly components: readonly [{
|
|
547
|
+
readonly name: "pool";
|
|
548
|
+
readonly type: "address";
|
|
549
|
+
}, {
|
|
550
|
+
readonly name: "hooks";
|
|
551
|
+
readonly type: "address";
|
|
552
|
+
}, {
|
|
553
|
+
readonly name: "kind";
|
|
554
|
+
readonly type: "uint8";
|
|
555
|
+
}, {
|
|
556
|
+
readonly name: "fee";
|
|
557
|
+
readonly type: "uint24";
|
|
558
|
+
}, {
|
|
559
|
+
readonly name: "tickSpacing";
|
|
560
|
+
readonly type: "int24";
|
|
561
|
+
}, {
|
|
562
|
+
readonly name: "zeroForOne";
|
|
563
|
+
readonly type: "bool";
|
|
564
|
+
}, {
|
|
565
|
+
readonly name: "stable";
|
|
566
|
+
readonly type: "bool";
|
|
567
|
+
}, {
|
|
568
|
+
readonly name: "amountIn";
|
|
569
|
+
readonly type: "uint256";
|
|
570
|
+
}, {
|
|
571
|
+
readonly name: "expectedOut";
|
|
572
|
+
readonly type: "uint256";
|
|
573
|
+
}, {
|
|
574
|
+
readonly name: "auxId";
|
|
575
|
+
readonly type: "bytes32";
|
|
576
|
+
}];
|
|
577
|
+
}];
|
|
578
|
+
}, {
|
|
579
|
+
readonly name: "totalOut";
|
|
580
|
+
readonly type: "uint256";
|
|
581
|
+
}, {
|
|
582
|
+
readonly name: "singleOut";
|
|
583
|
+
readonly type: "uint256";
|
|
584
|
+
}, {
|
|
585
|
+
readonly name: "singleOutFloor";
|
|
586
|
+
readonly type: "uint256";
|
|
587
|
+
}, {
|
|
588
|
+
readonly name: "expectedImpactBps";
|
|
589
|
+
readonly type: "uint256";
|
|
590
|
+
}, {
|
|
591
|
+
readonly name: "confidenceWad";
|
|
592
|
+
readonly type: "uint256";
|
|
593
|
+
}, {
|
|
594
|
+
readonly name: "estGas";
|
|
595
|
+
readonly type: "uint256";
|
|
596
|
+
}, {
|
|
597
|
+
readonly name: "hasSurplus";
|
|
598
|
+
readonly type: "bool";
|
|
599
|
+
}, {
|
|
600
|
+
readonly name: "isV4Bundle";
|
|
601
|
+
readonly type: "bool";
|
|
602
|
+
}];
|
|
603
|
+
}, {
|
|
604
|
+
readonly name: "exactOut";
|
|
605
|
+
readonly type: "uint256";
|
|
606
|
+
}];
|
|
607
|
+
}];
|
|
608
|
+
declare const ROUTER_ABI: readonly [{
|
|
609
|
+
readonly type: "function";
|
|
610
|
+
readonly name: "swapExactIn";
|
|
611
|
+
readonly stateMutability: "nonpayable";
|
|
612
|
+
readonly inputs: readonly [{
|
|
613
|
+
readonly name: "route";
|
|
614
|
+
readonly type: "tuple";
|
|
615
|
+
readonly components: readonly [{
|
|
616
|
+
readonly name: "hops";
|
|
617
|
+
readonly type: "tuple[]";
|
|
618
|
+
readonly components: readonly [{
|
|
619
|
+
readonly name: "tokenIn";
|
|
620
|
+
readonly type: "address";
|
|
621
|
+
}, {
|
|
622
|
+
readonly name: "tokenOut";
|
|
623
|
+
readonly type: "address";
|
|
624
|
+
}, {
|
|
625
|
+
readonly name: "amountIn";
|
|
626
|
+
readonly type: "uint256";
|
|
627
|
+
}, {
|
|
628
|
+
readonly name: "expectedOut";
|
|
629
|
+
readonly type: "uint256";
|
|
630
|
+
}, {
|
|
631
|
+
readonly name: "legs";
|
|
632
|
+
readonly type: "tuple[]";
|
|
633
|
+
readonly components: readonly [{
|
|
634
|
+
readonly name: "pool";
|
|
635
|
+
readonly type: "address";
|
|
636
|
+
}, {
|
|
637
|
+
readonly name: "hooks";
|
|
638
|
+
readonly type: "address";
|
|
639
|
+
}, {
|
|
640
|
+
readonly name: "kind";
|
|
641
|
+
readonly type: "uint8";
|
|
642
|
+
}, {
|
|
643
|
+
readonly name: "fee";
|
|
644
|
+
readonly type: "uint24";
|
|
645
|
+
}, {
|
|
646
|
+
readonly name: "tickSpacing";
|
|
647
|
+
readonly type: "int24";
|
|
648
|
+
}, {
|
|
649
|
+
readonly name: "zeroForOne";
|
|
650
|
+
readonly type: "bool";
|
|
651
|
+
}, {
|
|
652
|
+
readonly name: "stable";
|
|
653
|
+
readonly type: "bool";
|
|
654
|
+
}, {
|
|
655
|
+
readonly name: "amountIn";
|
|
656
|
+
readonly type: "uint256";
|
|
657
|
+
}, {
|
|
658
|
+
readonly name: "expectedOut";
|
|
659
|
+
readonly type: "uint256";
|
|
660
|
+
}, {
|
|
661
|
+
readonly name: "auxId";
|
|
662
|
+
readonly type: "bytes32";
|
|
663
|
+
}];
|
|
664
|
+
}];
|
|
665
|
+
}, {
|
|
666
|
+
readonly name: "totalOut";
|
|
667
|
+
readonly type: "uint256";
|
|
668
|
+
}, {
|
|
669
|
+
readonly name: "singleOut";
|
|
670
|
+
readonly type: "uint256";
|
|
671
|
+
}, {
|
|
672
|
+
readonly name: "singleOutFloor";
|
|
673
|
+
readonly type: "uint256";
|
|
674
|
+
}, {
|
|
675
|
+
readonly name: "expectedImpactBps";
|
|
676
|
+
readonly type: "uint256";
|
|
677
|
+
}, {
|
|
678
|
+
readonly name: "confidenceWad";
|
|
679
|
+
readonly type: "uint256";
|
|
680
|
+
}, {
|
|
681
|
+
readonly name: "estGas";
|
|
682
|
+
readonly type: "uint256";
|
|
683
|
+
}, {
|
|
684
|
+
readonly name: "hasSurplus";
|
|
685
|
+
readonly type: "bool";
|
|
686
|
+
}, {
|
|
687
|
+
readonly name: "isV4Bundle";
|
|
688
|
+
readonly type: "bool";
|
|
689
|
+
}];
|
|
690
|
+
}, {
|
|
691
|
+
readonly name: "amountIn";
|
|
692
|
+
readonly type: "uint256";
|
|
693
|
+
}, {
|
|
694
|
+
readonly name: "userMinOut";
|
|
695
|
+
readonly type: "uint256";
|
|
696
|
+
}, {
|
|
697
|
+
readonly name: "recipient";
|
|
698
|
+
readonly type: "address";
|
|
699
|
+
}, {
|
|
700
|
+
readonly name: "deadline";
|
|
701
|
+
readonly type: "uint256";
|
|
702
|
+
}];
|
|
703
|
+
readonly outputs: readonly [{
|
|
704
|
+
readonly name: "amountOut";
|
|
705
|
+
readonly type: "uint256";
|
|
706
|
+
}];
|
|
707
|
+
}, {
|
|
708
|
+
readonly type: "event";
|
|
709
|
+
readonly name: "Swap";
|
|
710
|
+
readonly inputs: readonly [{
|
|
711
|
+
readonly name: "user";
|
|
712
|
+
readonly type: "address";
|
|
713
|
+
readonly indexed: true;
|
|
714
|
+
}, {
|
|
715
|
+
readonly name: "tokenIn";
|
|
716
|
+
readonly type: "address";
|
|
717
|
+
readonly indexed: true;
|
|
718
|
+
}, {
|
|
719
|
+
readonly name: "tokenOut";
|
|
720
|
+
readonly type: "address";
|
|
721
|
+
readonly indexed: true;
|
|
722
|
+
}, {
|
|
723
|
+
readonly name: "amountIn";
|
|
724
|
+
readonly type: "uint256";
|
|
725
|
+
readonly indexed: false;
|
|
726
|
+
}, {
|
|
727
|
+
readonly name: "amountOut";
|
|
728
|
+
readonly type: "uint256";
|
|
729
|
+
readonly indexed: false;
|
|
730
|
+
}, {
|
|
731
|
+
readonly name: "legs";
|
|
732
|
+
readonly type: "uint256";
|
|
733
|
+
readonly indexed: false;
|
|
734
|
+
}];
|
|
735
|
+
}, {
|
|
736
|
+
readonly type: "event";
|
|
737
|
+
readonly name: "Surplus";
|
|
738
|
+
readonly inputs: readonly [{
|
|
739
|
+
readonly name: "token";
|
|
740
|
+
readonly type: "address";
|
|
741
|
+
readonly indexed: true;
|
|
742
|
+
}, {
|
|
743
|
+
readonly name: "amount";
|
|
744
|
+
readonly type: "uint256";
|
|
745
|
+
readonly indexed: false;
|
|
746
|
+
}];
|
|
747
|
+
}];
|
|
748
|
+
|
|
749
|
+
/** Unlimited allowance (2^256 − 1). Prefer EXACT amounts — pass the amount you
|
|
750
|
+
* are about to swap; use MAX_UINT256 only when you consciously want one
|
|
751
|
+
* approval forever (bots with their own key management). */
|
|
752
|
+
declare const MAX_UINT256: bigint;
|
|
753
|
+
interface ApproveOptions {
|
|
754
|
+
/** ERC-20 token to approve (the swap's tokenIn). */
|
|
755
|
+
token: Address;
|
|
756
|
+
/** Chain id or name — picks the Router as the default spender. */
|
|
757
|
+
chain: ChainRef;
|
|
758
|
+
/** Allowance in base units. Be exact; MAX_UINT256 opts into unlimited. */
|
|
759
|
+
amount: bigint;
|
|
760
|
+
/** Override the spender (defaults to the BlazePhoenix Router). */
|
|
761
|
+
spender?: Address;
|
|
762
|
+
}
|
|
763
|
+
/** Ready-to-send `approve` transaction for the Router (or a custom spender).
|
|
764
|
+
* Send it once per token before the first swap; then swap freely. */
|
|
765
|
+
declare function buildApproveTx(opts: ApproveOptions): QuoteTx;
|
|
766
|
+
/** "1.5" + 18 decimals → 1500000000000000000n. Pure string math — no floats,
|
|
767
|
+
* no precision loss. Rejects more fractional digits than the token carries. */
|
|
768
|
+
declare function toBaseUnits(amount: string, decimals: number): bigint;
|
|
769
|
+
/** 1500000000000000000n + 18 decimals → "1.5" (trailing zeros trimmed).
|
|
770
|
+
* `maxDp` optionally truncates the fractional part for display. */
|
|
771
|
+
declare function fromBaseUnits(v: bigint | string, decimals: number, maxDp?: number): string;
|
|
772
|
+
|
|
773
|
+
interface OnChainOptions {
|
|
774
|
+
chain: number | string;
|
|
775
|
+
/** Your RPC endpoint. OPTIONAL since v0.4.0 — omitted, the SDK falls back
|
|
776
|
+
* across public keyless endpoints (fine for dev/bots; bring your own node
|
|
777
|
+
* for production throughput). The SDK still ships no providers and no keys. */
|
|
778
|
+
rpcUrl?: string;
|
|
779
|
+
}
|
|
780
|
+
/** previewPlan straight from the chain — the exact numbers the API serves. */
|
|
781
|
+
declare function quoteOnChain(opts: OnChainOptions & {
|
|
782
|
+
tokenIn: Address;
|
|
783
|
+
tokenOut: Address;
|
|
784
|
+
amountIn: bigint;
|
|
785
|
+
}): Promise<{
|
|
786
|
+
preview: Record<string, unknown>;
|
|
787
|
+
hasFallback: boolean;
|
|
788
|
+
chainId: SupportedChainId;
|
|
789
|
+
}>;
|
|
790
|
+
interface WatchFillsOptions extends OnChainOptions {
|
|
791
|
+
onFill: (fill: Fill) => void;
|
|
792
|
+
/** Poll interval in ms (default 4000). */
|
|
793
|
+
pollMs?: number;
|
|
794
|
+
}
|
|
795
|
+
/** Stream every BlazePhoenix fill on a chain (one Router `Swap` event per
|
|
796
|
+
* swap). Returns an unwatch function. */
|
|
797
|
+
declare function watchFills(opts: WatchFillsOptions): Promise<() => void>;
|
|
798
|
+
/** Historic fills over a block range (for indexing / the quoted-vs-executed
|
|
799
|
+
* verification pattern documented at https://blazephoenix.xyz/?tab=api). */
|
|
800
|
+
declare function getFills(opts: OnChainOptions & {
|
|
801
|
+
fromBlock: bigint;
|
|
802
|
+
toBlock: bigint;
|
|
803
|
+
}): Promise<Fill[]>;
|
|
804
|
+
|
|
805
|
+
export { API_BASE, type Address, type ApiErrorBody, type ApproveOptions, type BatchResponse, type BatchResult, BlazeApiError, BlazePhoenix, CHAINS, type ChainInfo, type ChainRef, type ClientOptions, type DeepLinkOptions, FEE_BPS, type Fill, type Hex, MAX_UINT256, type ManifestChain, type ManifestResponse, type OnChainOptions, PUBLIC_RPCS, type PollOptions, QUOTER_ABI, type QuoteHop, type QuoteLeg, type QuoteRequest, type QuoteResponse, type QuoteRoute, type QuoteSummary, type QuoteTx, ROUTER_ABI, type RetryOptions, SURPLUS_TOPIC0, SWAP_TOPIC0, type SupportedChainId, type TokenRef, type WatchFillsOptions, buildApproveTx, buildSwapTx, deepLink, fromBaseUnits, getFills, pollQuote, quoteOnChain, resilientFetch, resolveChain, singleflight, toBaseUnits, watchFills };
|