@t402/smart-router 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +388 -0
- package/dist/chunk-BUGQ6VOQ.js +662 -0
- package/dist/chunk-BUGQ6VOQ.js.map +1 -0
- package/dist/chunk-KJJ2L6TF.js +742 -0
- package/dist/chunk-KJJ2L6TF.js.map +1 -0
- package/dist/chunk-PCDWVENA.js +450 -0
- package/dist/chunk-PCDWVENA.js.map +1 -0
- package/dist/chunk-QIZPPHGB.js +169 -0
- package/dist/chunk-QIZPPHGB.js.map +1 -0
- package/dist/chunk-XKFKUWJY.js +504 -0
- package/dist/chunk-XKFKUWJY.js.map +1 -0
- package/dist/execution/index.d.ts +679 -0
- package/dist/execution/index.js +31 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/gas-CNpJzuy5.d.ts +454 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/dist/liquidity/index.d.ts +418 -0
- package/dist/liquidity/index.js +24 -0
- package/dist/liquidity/index.js.map +1 -0
- package/dist/pricing/index.d.ts +74 -0
- package/dist/pricing/index.js +32 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/routing/index.d.ts +117 -0
- package/dist/routing/index.js +43 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/types-C0ey6WqI.d.ts +937 -0
- package/package.json +70 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { C as ChainId, P as ProtocolId, A as AssetId } from '../types-C0ey6WqI.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Liquidity pool type
|
|
6
|
+
*/
|
|
7
|
+
declare const PoolType: z.ZodEnum<["constant_product", "concentrated", "stable", "weighted", "hybrid"]>;
|
|
8
|
+
type PoolType = z.infer<typeof PoolType>;
|
|
9
|
+
/**
|
|
10
|
+
* Liquidity pool
|
|
11
|
+
*/
|
|
12
|
+
declare const LiquidityPool: z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
protocol: z.ZodString;
|
|
15
|
+
chain: z.ZodString;
|
|
16
|
+
type: z.ZodEnum<["constant_product", "concentrated", "stable", "weighted", "hybrid"]>;
|
|
17
|
+
tokens: z.ZodArray<z.ZodObject<{
|
|
18
|
+
asset: z.ZodString;
|
|
19
|
+
reserve: z.ZodString;
|
|
20
|
+
weight: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
asset: string;
|
|
23
|
+
reserve: string;
|
|
24
|
+
weight?: string | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
asset: string;
|
|
27
|
+
reserve: string;
|
|
28
|
+
weight?: string | undefined;
|
|
29
|
+
}>, "many">;
|
|
30
|
+
fee: z.ZodString;
|
|
31
|
+
tvl: z.ZodString;
|
|
32
|
+
tickSpacing: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
currentTick: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
sqrtPriceX96: z.ZodOptional<z.ZodString>;
|
|
35
|
+
address: z.ZodString;
|
|
36
|
+
createdAt: z.ZodNumber;
|
|
37
|
+
lastUpdated: z.ZodNumber;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
type: "constant_product" | "concentrated" | "stable" | "weighted" | "hybrid";
|
|
40
|
+
id: string;
|
|
41
|
+
chain: string;
|
|
42
|
+
protocol: string;
|
|
43
|
+
createdAt: number;
|
|
44
|
+
fee: string;
|
|
45
|
+
lastUpdated: number;
|
|
46
|
+
tokens: {
|
|
47
|
+
asset: string;
|
|
48
|
+
reserve: string;
|
|
49
|
+
weight?: string | undefined;
|
|
50
|
+
}[];
|
|
51
|
+
tvl: string;
|
|
52
|
+
address: string;
|
|
53
|
+
tickSpacing?: number | undefined;
|
|
54
|
+
currentTick?: number | undefined;
|
|
55
|
+
sqrtPriceX96?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
type: "constant_product" | "concentrated" | "stable" | "weighted" | "hybrid";
|
|
58
|
+
id: string;
|
|
59
|
+
chain: string;
|
|
60
|
+
protocol: string;
|
|
61
|
+
createdAt: number;
|
|
62
|
+
fee: string;
|
|
63
|
+
lastUpdated: number;
|
|
64
|
+
tokens: {
|
|
65
|
+
asset: string;
|
|
66
|
+
reserve: string;
|
|
67
|
+
weight?: string | undefined;
|
|
68
|
+
}[];
|
|
69
|
+
tvl: string;
|
|
70
|
+
address: string;
|
|
71
|
+
tickSpacing?: number | undefined;
|
|
72
|
+
currentTick?: number | undefined;
|
|
73
|
+
sqrtPriceX96?: string | undefined;
|
|
74
|
+
}>;
|
|
75
|
+
type LiquidityPool = z.infer<typeof LiquidityPool>;
|
|
76
|
+
/**
|
|
77
|
+
* Liquidity source (aggregated from multiple pools)
|
|
78
|
+
*/
|
|
79
|
+
declare const LiquiditySource: z.ZodObject<{
|
|
80
|
+
chain: z.ZodString;
|
|
81
|
+
inputAsset: z.ZodString;
|
|
82
|
+
outputAsset: z.ZodString;
|
|
83
|
+
totalLiquidity: z.ZodString;
|
|
84
|
+
bestPrice: z.ZodString;
|
|
85
|
+
averagePrice: z.ZodString;
|
|
86
|
+
pools: z.ZodArray<z.ZodObject<{
|
|
87
|
+
poolId: z.ZodString;
|
|
88
|
+
protocol: z.ZodString;
|
|
89
|
+
liquidity: z.ZodString;
|
|
90
|
+
price: z.ZodString;
|
|
91
|
+
maxAmountIn: z.ZodString;
|
|
92
|
+
maxAmountOut: z.ZodString;
|
|
93
|
+
priceImpact1Percent: z.ZodString;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
protocol: string;
|
|
96
|
+
price: string;
|
|
97
|
+
poolId: string;
|
|
98
|
+
liquidity: string;
|
|
99
|
+
maxAmountIn: string;
|
|
100
|
+
maxAmountOut: string;
|
|
101
|
+
priceImpact1Percent: string;
|
|
102
|
+
}, {
|
|
103
|
+
protocol: string;
|
|
104
|
+
price: string;
|
|
105
|
+
poolId: string;
|
|
106
|
+
liquidity: string;
|
|
107
|
+
maxAmountIn: string;
|
|
108
|
+
maxAmountOut: string;
|
|
109
|
+
priceImpact1Percent: string;
|
|
110
|
+
}>, "many">;
|
|
111
|
+
lastUpdated: z.ZodNumber;
|
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
|
113
|
+
chain: string;
|
|
114
|
+
inputAsset: string;
|
|
115
|
+
outputAsset: string;
|
|
116
|
+
lastUpdated: number;
|
|
117
|
+
totalLiquidity: string;
|
|
118
|
+
bestPrice: string;
|
|
119
|
+
averagePrice: string;
|
|
120
|
+
pools: {
|
|
121
|
+
protocol: string;
|
|
122
|
+
price: string;
|
|
123
|
+
poolId: string;
|
|
124
|
+
liquidity: string;
|
|
125
|
+
maxAmountIn: string;
|
|
126
|
+
maxAmountOut: string;
|
|
127
|
+
priceImpact1Percent: string;
|
|
128
|
+
}[];
|
|
129
|
+
}, {
|
|
130
|
+
chain: string;
|
|
131
|
+
inputAsset: string;
|
|
132
|
+
outputAsset: string;
|
|
133
|
+
lastUpdated: number;
|
|
134
|
+
totalLiquidity: string;
|
|
135
|
+
bestPrice: string;
|
|
136
|
+
averagePrice: string;
|
|
137
|
+
pools: {
|
|
138
|
+
protocol: string;
|
|
139
|
+
price: string;
|
|
140
|
+
poolId: string;
|
|
141
|
+
liquidity: string;
|
|
142
|
+
maxAmountIn: string;
|
|
143
|
+
maxAmountOut: string;
|
|
144
|
+
priceImpact1Percent: string;
|
|
145
|
+
}[];
|
|
146
|
+
}>;
|
|
147
|
+
type LiquiditySource = z.infer<typeof LiquiditySource>;
|
|
148
|
+
/**
|
|
149
|
+
* Cross-chain liquidity
|
|
150
|
+
*/
|
|
151
|
+
declare const CrossChainLiquidity: z.ZodObject<{
|
|
152
|
+
sourceChain: z.ZodString;
|
|
153
|
+
destinationChain: z.ZodString;
|
|
154
|
+
asset: z.ZodString;
|
|
155
|
+
bridges: z.ZodArray<z.ZodObject<{
|
|
156
|
+
bridge: z.ZodString;
|
|
157
|
+
liquidity: z.ZodString;
|
|
158
|
+
maxTransfer: z.ZodString;
|
|
159
|
+
minTransfer: z.ZodString;
|
|
160
|
+
fee: z.ZodString;
|
|
161
|
+
estimatedTime: z.ZodNumber;
|
|
162
|
+
available: z.ZodBoolean;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
bridge: string;
|
|
165
|
+
estimatedTime: number;
|
|
166
|
+
fee: string;
|
|
167
|
+
liquidity: string;
|
|
168
|
+
maxTransfer: string;
|
|
169
|
+
minTransfer: string;
|
|
170
|
+
available: boolean;
|
|
171
|
+
}, {
|
|
172
|
+
bridge: string;
|
|
173
|
+
estimatedTime: number;
|
|
174
|
+
fee: string;
|
|
175
|
+
liquidity: string;
|
|
176
|
+
maxTransfer: string;
|
|
177
|
+
minTransfer: string;
|
|
178
|
+
available: boolean;
|
|
179
|
+
}>, "many">;
|
|
180
|
+
totalLiquidity: z.ZodString;
|
|
181
|
+
bestBridge: z.ZodString;
|
|
182
|
+
lastUpdated: z.ZodNumber;
|
|
183
|
+
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
sourceChain: string;
|
|
185
|
+
destinationChain: string;
|
|
186
|
+
asset: string;
|
|
187
|
+
lastUpdated: number;
|
|
188
|
+
totalLiquidity: string;
|
|
189
|
+
bridges: {
|
|
190
|
+
bridge: string;
|
|
191
|
+
estimatedTime: number;
|
|
192
|
+
fee: string;
|
|
193
|
+
liquidity: string;
|
|
194
|
+
maxTransfer: string;
|
|
195
|
+
minTransfer: string;
|
|
196
|
+
available: boolean;
|
|
197
|
+
}[];
|
|
198
|
+
bestBridge: string;
|
|
199
|
+
}, {
|
|
200
|
+
sourceChain: string;
|
|
201
|
+
destinationChain: string;
|
|
202
|
+
asset: string;
|
|
203
|
+
lastUpdated: number;
|
|
204
|
+
totalLiquidity: string;
|
|
205
|
+
bridges: {
|
|
206
|
+
bridge: string;
|
|
207
|
+
estimatedTime: number;
|
|
208
|
+
fee: string;
|
|
209
|
+
liquidity: string;
|
|
210
|
+
maxTransfer: string;
|
|
211
|
+
minTransfer: string;
|
|
212
|
+
available: boolean;
|
|
213
|
+
}[];
|
|
214
|
+
bestBridge: string;
|
|
215
|
+
}>;
|
|
216
|
+
type CrossChainLiquidity = z.infer<typeof CrossChainLiquidity>;
|
|
217
|
+
/**
|
|
218
|
+
* Slippage calculation result
|
|
219
|
+
*/
|
|
220
|
+
declare const SlippageResult: z.ZodObject<{
|
|
221
|
+
inputAmount: z.ZodString;
|
|
222
|
+
outputAmount: z.ZodString;
|
|
223
|
+
priceImpact: z.ZodString;
|
|
224
|
+
effectivePrice: z.ZodString;
|
|
225
|
+
slippageTolerance: z.ZodString;
|
|
226
|
+
minOutputAmount: z.ZodString;
|
|
227
|
+
executionPath: z.ZodArray<z.ZodObject<{
|
|
228
|
+
poolId: z.ZodString;
|
|
229
|
+
amountIn: z.ZodString;
|
|
230
|
+
amountOut: z.ZodString;
|
|
231
|
+
priceImpact: z.ZodString;
|
|
232
|
+
}, "strip", z.ZodTypeAny, {
|
|
233
|
+
priceImpact: string;
|
|
234
|
+
poolId: string;
|
|
235
|
+
amountIn: string;
|
|
236
|
+
amountOut: string;
|
|
237
|
+
}, {
|
|
238
|
+
priceImpact: string;
|
|
239
|
+
poolId: string;
|
|
240
|
+
amountIn: string;
|
|
241
|
+
amountOut: string;
|
|
242
|
+
}>, "many">;
|
|
243
|
+
}, "strip", z.ZodTypeAny, {
|
|
244
|
+
inputAmount: string;
|
|
245
|
+
outputAmount: string;
|
|
246
|
+
minOutputAmount: string;
|
|
247
|
+
priceImpact: string;
|
|
248
|
+
effectivePrice: string;
|
|
249
|
+
slippageTolerance: string;
|
|
250
|
+
executionPath: {
|
|
251
|
+
priceImpact: string;
|
|
252
|
+
poolId: string;
|
|
253
|
+
amountIn: string;
|
|
254
|
+
amountOut: string;
|
|
255
|
+
}[];
|
|
256
|
+
}, {
|
|
257
|
+
inputAmount: string;
|
|
258
|
+
outputAmount: string;
|
|
259
|
+
minOutputAmount: string;
|
|
260
|
+
priceImpact: string;
|
|
261
|
+
effectivePrice: string;
|
|
262
|
+
slippageTolerance: string;
|
|
263
|
+
executionPath: {
|
|
264
|
+
priceImpact: string;
|
|
265
|
+
poolId: string;
|
|
266
|
+
amountIn: string;
|
|
267
|
+
amountOut: string;
|
|
268
|
+
}[];
|
|
269
|
+
}>;
|
|
270
|
+
type SlippageResult = z.infer<typeof SlippageResult>;
|
|
271
|
+
/**
|
|
272
|
+
* Liquidity depth at different price levels
|
|
273
|
+
*/
|
|
274
|
+
declare const LiquidityDepth: z.ZodObject<{
|
|
275
|
+
chain: z.ZodString;
|
|
276
|
+
inputAsset: z.ZodString;
|
|
277
|
+
outputAsset: z.ZodString;
|
|
278
|
+
currentPrice: z.ZodString;
|
|
279
|
+
depth: z.ZodArray<z.ZodObject<{
|
|
280
|
+
priceLevel: z.ZodString;
|
|
281
|
+
bidLiquidity: z.ZodString;
|
|
282
|
+
askLiquidity: z.ZodString;
|
|
283
|
+
}, "strip", z.ZodTypeAny, {
|
|
284
|
+
priceLevel: string;
|
|
285
|
+
bidLiquidity: string;
|
|
286
|
+
askLiquidity: string;
|
|
287
|
+
}, {
|
|
288
|
+
priceLevel: string;
|
|
289
|
+
bidLiquidity: string;
|
|
290
|
+
askLiquidity: string;
|
|
291
|
+
}>, "many">;
|
|
292
|
+
spread: z.ZodString;
|
|
293
|
+
lastUpdated: z.ZodNumber;
|
|
294
|
+
}, "strip", z.ZodTypeAny, {
|
|
295
|
+
chain: string;
|
|
296
|
+
inputAsset: string;
|
|
297
|
+
outputAsset: string;
|
|
298
|
+
currentPrice: string;
|
|
299
|
+
lastUpdated: number;
|
|
300
|
+
depth: {
|
|
301
|
+
priceLevel: string;
|
|
302
|
+
bidLiquidity: string;
|
|
303
|
+
askLiquidity: string;
|
|
304
|
+
}[];
|
|
305
|
+
spread: string;
|
|
306
|
+
}, {
|
|
307
|
+
chain: string;
|
|
308
|
+
inputAsset: string;
|
|
309
|
+
outputAsset: string;
|
|
310
|
+
currentPrice: string;
|
|
311
|
+
lastUpdated: number;
|
|
312
|
+
depth: {
|
|
313
|
+
priceLevel: string;
|
|
314
|
+
bidLiquidity: string;
|
|
315
|
+
askLiquidity: string;
|
|
316
|
+
}[];
|
|
317
|
+
spread: string;
|
|
318
|
+
}>;
|
|
319
|
+
type LiquidityDepth = z.infer<typeof LiquidityDepth>;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Liquidity provider interface
|
|
323
|
+
*/
|
|
324
|
+
interface ILiquidityProvider {
|
|
325
|
+
chain: ChainId;
|
|
326
|
+
protocol: ProtocolId;
|
|
327
|
+
getPools(inputAsset: AssetId, outputAsset?: AssetId): Promise<LiquidityPool[]>;
|
|
328
|
+
getPool(poolId: string): Promise<LiquidityPool | null>;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Bridge liquidity provider interface
|
|
332
|
+
*/
|
|
333
|
+
interface IBridgeProvider {
|
|
334
|
+
bridge: ProtocolId;
|
|
335
|
+
getLiquidity(sourceChain: ChainId, destinationChain: ChainId, asset: AssetId): Promise<CrossChainLiquidity['bridges'][0] | null>;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Aggregator configuration
|
|
339
|
+
*/
|
|
340
|
+
interface AggregatorConfig {
|
|
341
|
+
cacheTtl?: number;
|
|
342
|
+
maxPoolsPerSource?: number;
|
|
343
|
+
minLiquidity?: string;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Liquidity aggregator - combines liquidity from multiple sources
|
|
347
|
+
*/
|
|
348
|
+
declare class LiquidityAggregator {
|
|
349
|
+
private providers;
|
|
350
|
+
private bridgeProviders;
|
|
351
|
+
private poolCache;
|
|
352
|
+
private config;
|
|
353
|
+
constructor(config?: AggregatorConfig);
|
|
354
|
+
/**
|
|
355
|
+
* Register a liquidity provider
|
|
356
|
+
*/
|
|
357
|
+
registerProvider(provider: ILiquidityProvider): void;
|
|
358
|
+
/**
|
|
359
|
+
* Register a bridge provider
|
|
360
|
+
*/
|
|
361
|
+
registerBridgeProvider(provider: IBridgeProvider): void;
|
|
362
|
+
/**
|
|
363
|
+
* Get aggregated liquidity for a trading pair
|
|
364
|
+
*/
|
|
365
|
+
getLiquidity(chain: ChainId, inputAsset: AssetId, outputAsset: AssetId): Promise<LiquiditySource>;
|
|
366
|
+
/**
|
|
367
|
+
* Get cross-chain liquidity
|
|
368
|
+
*/
|
|
369
|
+
getCrossChainLiquidity(sourceChain: ChainId, destinationChain: ChainId, asset: AssetId): Promise<CrossChainLiquidity>;
|
|
370
|
+
/**
|
|
371
|
+
* Calculate slippage for a trade
|
|
372
|
+
*/
|
|
373
|
+
calculateSlippage(source: LiquiditySource, inputAmount: string, slippageTolerance: string): SlippageResult;
|
|
374
|
+
/**
|
|
375
|
+
* Get liquidity depth at different price levels
|
|
376
|
+
*/
|
|
377
|
+
getLiquidityDepth(chain: ChainId, inputAsset: AssetId, outputAsset: AssetId, levels?: number[]): Promise<LiquidityDepth>;
|
|
378
|
+
/**
|
|
379
|
+
* Find best route across multiple pools
|
|
380
|
+
*/
|
|
381
|
+
findBestRoute(source: LiquiditySource, inputAmount: string, maxPools?: number): {
|
|
382
|
+
pools: string[];
|
|
383
|
+
expectedOutput: string;
|
|
384
|
+
priceImpact: string;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Clear cache
|
|
388
|
+
*/
|
|
389
|
+
clearCache(): void;
|
|
390
|
+
private aggregatePools;
|
|
391
|
+
private calculatePoolPriceImpact;
|
|
392
|
+
private calculateTotalPriceImpact;
|
|
393
|
+
private calculateLiquidityAtLevel;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Mock liquidity provider for testing
|
|
397
|
+
*/
|
|
398
|
+
declare class MockLiquidityProvider implements ILiquidityProvider {
|
|
399
|
+
chain: ChainId;
|
|
400
|
+
protocol: ProtocolId;
|
|
401
|
+
private pools;
|
|
402
|
+
constructor(chain: ChainId, protocol: ProtocolId);
|
|
403
|
+
addPool(pool: LiquidityPool): void;
|
|
404
|
+
getPools(inputAsset: AssetId, outputAsset?: AssetId): Promise<LiquidityPool[]>;
|
|
405
|
+
getPool(poolId: string): Promise<LiquidityPool | null>;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Mock bridge provider for testing
|
|
409
|
+
*/
|
|
410
|
+
declare class MockBridgeProvider implements IBridgeProvider {
|
|
411
|
+
bridge: ProtocolId;
|
|
412
|
+
private liquidity;
|
|
413
|
+
constructor(bridge: ProtocolId);
|
|
414
|
+
setLiquidity(sourceChain: ChainId, destinationChain: ChainId, asset: AssetId, data: CrossChainLiquidity['bridges'][0]): void;
|
|
415
|
+
getLiquidity(sourceChain: ChainId, destinationChain: ChainId, asset: AssetId): Promise<CrossChainLiquidity['bridges'][0] | null>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export { type AggregatorConfig, CrossChainLiquidity, type IBridgeProvider, type ILiquidityProvider, LiquidityAggregator, LiquidityDepth, LiquidityPool, LiquiditySource, MockBridgeProvider, MockLiquidityProvider, PoolType, SlippageResult };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CrossChainLiquidity,
|
|
3
|
+
LiquidityAggregator,
|
|
4
|
+
LiquidityDepth,
|
|
5
|
+
LiquidityPool,
|
|
6
|
+
LiquiditySource,
|
|
7
|
+
MockBridgeProvider,
|
|
8
|
+
MockLiquidityProvider,
|
|
9
|
+
PoolType,
|
|
10
|
+
SlippageResult
|
|
11
|
+
} from "../chunk-PCDWVENA.js";
|
|
12
|
+
import "../chunk-QIZPPHGB.js";
|
|
13
|
+
export {
|
|
14
|
+
CrossChainLiquidity,
|
|
15
|
+
LiquidityAggregator,
|
|
16
|
+
LiquidityDepth,
|
|
17
|
+
LiquidityPool,
|
|
18
|
+
LiquiditySource,
|
|
19
|
+
MockBridgeProvider,
|
|
20
|
+
MockLiquidityProvider,
|
|
21
|
+
PoolType,
|
|
22
|
+
SlippageResult
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { c as GasOracle, F as FeeEstimateRequest, a as FeeEstimate, S as SwapQuote, B as BridgeQuote, P as ProtocolFees, T as TokenPrice } from '../gas-CNpJzuy5.js';
|
|
2
|
+
export { d as GasOracleConfig, G as GasPrice, I as IGasProvider, M as MockGasProvider, b as PricePrediction } from '../gas-CNpJzuy5.js';
|
|
3
|
+
import { C as ChainId, P as ProtocolId, A as AssetId } from '../types-C0ey6WqI.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fee estimator configuration
|
|
8
|
+
*/
|
|
9
|
+
interface FeeEstimatorConfig {
|
|
10
|
+
defaultSlippage?: string;
|
|
11
|
+
cacheTtl?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fee estimator for calculating total transaction costs
|
|
15
|
+
*/
|
|
16
|
+
declare class FeeEstimator {
|
|
17
|
+
private gasOracle;
|
|
18
|
+
private protocolFees;
|
|
19
|
+
private tokenPrices;
|
|
20
|
+
private config;
|
|
21
|
+
private readonly GAS_ESTIMATES;
|
|
22
|
+
constructor(gasOracle: GasOracle, config?: FeeEstimatorConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Estimate fees for an operation
|
|
25
|
+
*/
|
|
26
|
+
estimateFees(request: FeeEstimateRequest): Promise<FeeEstimate>;
|
|
27
|
+
/**
|
|
28
|
+
* Estimate total route fees
|
|
29
|
+
*/
|
|
30
|
+
estimateRouteFees(steps: Array<{
|
|
31
|
+
chain: ChainId;
|
|
32
|
+
operation: string;
|
|
33
|
+
protocol?: ProtocolId;
|
|
34
|
+
amount: string;
|
|
35
|
+
inputAsset: AssetId;
|
|
36
|
+
outputAsset?: AssetId;
|
|
37
|
+
}>, gasSpeed?: 'slow' | 'standard' | 'fast' | 'instant'): Promise<{
|
|
38
|
+
totalGasUsd: string;
|
|
39
|
+
totalProtocolFeesUsd: string;
|
|
40
|
+
totalFeesUsd: string;
|
|
41
|
+
stepEstimates: FeeEstimate[];
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Get a swap quote
|
|
45
|
+
*/
|
|
46
|
+
getSwapQuote(chain: ChainId, dex: ProtocolId, inputAsset: AssetId, outputAsset: AssetId, inputAmount: string, slippage?: string): Promise<SwapQuote>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a bridge quote
|
|
49
|
+
*/
|
|
50
|
+
getBridgeQuote(bridge: ProtocolId, sourceChain: ChainId, destinationChain: ChainId, sourceAsset: AssetId, destinationAsset: AssetId, inputAmount: string): Promise<BridgeQuote>;
|
|
51
|
+
/**
|
|
52
|
+
* Register protocol fee structure
|
|
53
|
+
*/
|
|
54
|
+
registerProtocolFees(fees: ProtocolFees): void;
|
|
55
|
+
/**
|
|
56
|
+
* Update token price
|
|
57
|
+
*/
|
|
58
|
+
updateTokenPrice(price: TokenPrice): void;
|
|
59
|
+
private getGasEstimate;
|
|
60
|
+
private calculateProtocolFee;
|
|
61
|
+
private getProtocolFeePercent;
|
|
62
|
+
private getTokenPrice;
|
|
63
|
+
private getBridgeEstimatedTime;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Calculate slippage-adjusted output
|
|
67
|
+
*/
|
|
68
|
+
declare function calculateMinOutput(amount: string, slippagePercent: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Calculate price impact from liquidity
|
|
71
|
+
*/
|
|
72
|
+
declare function calculatePriceImpact(amount: string, liquidity: string): string;
|
|
73
|
+
|
|
74
|
+
export { BridgeQuote, FeeEstimate, FeeEstimateRequest, FeeEstimator, type FeeEstimatorConfig, GasOracle, ProtocolFees, SwapQuote, TokenPrice, calculateMinOutput, calculatePriceImpact };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BridgeQuote,
|
|
3
|
+
FeeEstimate,
|
|
4
|
+
FeeEstimateRequest,
|
|
5
|
+
FeeEstimator,
|
|
6
|
+
GasOracle,
|
|
7
|
+
GasPrice,
|
|
8
|
+
MockGasProvider,
|
|
9
|
+
PricePrediction,
|
|
10
|
+
ProtocolFees,
|
|
11
|
+
SwapQuote,
|
|
12
|
+
TokenPrice,
|
|
13
|
+
calculateMinOutput,
|
|
14
|
+
calculatePriceImpact
|
|
15
|
+
} from "../chunk-BUGQ6VOQ.js";
|
|
16
|
+
import "../chunk-QIZPPHGB.js";
|
|
17
|
+
export {
|
|
18
|
+
BridgeQuote,
|
|
19
|
+
FeeEstimate,
|
|
20
|
+
FeeEstimateRequest,
|
|
21
|
+
FeeEstimator,
|
|
22
|
+
GasOracle,
|
|
23
|
+
GasPrice,
|
|
24
|
+
MockGasProvider,
|
|
25
|
+
PricePrediction,
|
|
26
|
+
ProtocolFees,
|
|
27
|
+
SwapQuote,
|
|
28
|
+
TokenPrice,
|
|
29
|
+
calculateMinOutput,
|
|
30
|
+
calculatePriceImpact
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { a as RouteRequest, c as Route, e as RouteValidation, G as GraphEdge, g as RoutingGraph, C as ChainId, A as AssetId, O as OptimizationStrategy } from '../types-C0ey6WqI.js';
|
|
2
|
+
export { f as GraphNode, P as ProtocolId, d as RouteComparison, b as RouteStep, R as RouteStepType } from '../types-C0ey6WqI.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Router configuration
|
|
7
|
+
*/
|
|
8
|
+
interface RouterConfig {
|
|
9
|
+
maxRoutes?: number;
|
|
10
|
+
cacheTtl?: number;
|
|
11
|
+
minConfidence?: number;
|
|
12
|
+
defaultSlippage?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Smart routing engine
|
|
16
|
+
*/
|
|
17
|
+
declare class RoutingEngine {
|
|
18
|
+
private graph;
|
|
19
|
+
private config;
|
|
20
|
+
private routeCache;
|
|
21
|
+
constructor(config?: RouterConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Find optimal routes for a payment
|
|
24
|
+
*/
|
|
25
|
+
findRoutes(request: RouteRequest): Promise<Route[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the best route for a payment
|
|
28
|
+
*/
|
|
29
|
+
getBestRoute(request: RouteRequest): Promise<Route | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Validate a route is still executable
|
|
32
|
+
*/
|
|
33
|
+
validateRoute(route: Route): Promise<RouteValidation>;
|
|
34
|
+
/**
|
|
35
|
+
* Update the routing graph with new data
|
|
36
|
+
*/
|
|
37
|
+
updateGraph(edges: GraphEdge[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Add an edge to the routing graph
|
|
40
|
+
*/
|
|
41
|
+
addEdge(edge: GraphEdge): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get the current routing graph
|
|
44
|
+
*/
|
|
45
|
+
getGraph(): RoutingGraph;
|
|
46
|
+
private validateRequest;
|
|
47
|
+
private findAllPaths;
|
|
48
|
+
private buildRoute;
|
|
49
|
+
private scoreRoute;
|
|
50
|
+
private calculateOutput;
|
|
51
|
+
private calculateProtocolFee;
|
|
52
|
+
private calculateBridgeFee;
|
|
53
|
+
private calculatePriceImpact;
|
|
54
|
+
private calculateExchangeRate;
|
|
55
|
+
private estimateGas;
|
|
56
|
+
private getProtocolContract;
|
|
57
|
+
private calculateConfidence;
|
|
58
|
+
private generateWarnings;
|
|
59
|
+
private findEdge;
|
|
60
|
+
private getCacheKey;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Routing error codes
|
|
64
|
+
*/
|
|
65
|
+
type RoutingErrorCode = 'INVALID_REQUEST' | 'NO_ROUTE' | 'NO_VALID_ROUTE' | 'INSUFFICIENT_LIQUIDITY' | 'ROUTE_EXPIRED';
|
|
66
|
+
/**
|
|
67
|
+
* Custom error for routing operations
|
|
68
|
+
*/
|
|
69
|
+
declare class RoutingError extends Error {
|
|
70
|
+
code: RoutingErrorCode;
|
|
71
|
+
constructor(message: string, code: RoutingErrorCode);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Cost function configuration
|
|
76
|
+
*/
|
|
77
|
+
interface CostConfig {
|
|
78
|
+
gasCostWeight: number;
|
|
79
|
+
feeWeight: number;
|
|
80
|
+
timeWeight: number;
|
|
81
|
+
slippageWeight: number;
|
|
82
|
+
hopPenalty: number;
|
|
83
|
+
bridgePenalty: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Default cost configurations for different strategies
|
|
87
|
+
*/
|
|
88
|
+
declare const COST_CONFIGS: Record<OptimizationStrategy, CostConfig>;
|
|
89
|
+
/**
|
|
90
|
+
* Calculate edge cost based on optimization strategy
|
|
91
|
+
*/
|
|
92
|
+
declare function calculateEdgeCost(edge: GraphEdge, config: CostConfig): number;
|
|
93
|
+
/**
|
|
94
|
+
* Dijkstra's algorithm for finding shortest path
|
|
95
|
+
*/
|
|
96
|
+
declare function dijkstra(edges: GraphEdge[], startChain: ChainId, startAsset: AssetId, endChain: ChainId, endAsset: AssetId, costConfig: CostConfig, maxHops?: number): GraphEdge[] | null;
|
|
97
|
+
/**
|
|
98
|
+
* A* algorithm with heuristic for faster path finding
|
|
99
|
+
*/
|
|
100
|
+
declare function astar(edges: GraphEdge[], startChain: ChainId, startAsset: AssetId, endChain: ChainId, endAsset: AssetId, costConfig: CostConfig, maxHops?: number): GraphEdge[] | null;
|
|
101
|
+
/**
|
|
102
|
+
* Find k-shortest paths using Yen's algorithm
|
|
103
|
+
*/
|
|
104
|
+
declare function kShortestPaths(edges: GraphEdge[], startChain: ChainId, startAsset: AssetId, endChain: ChainId, endAsset: AssetId, costConfig: CostConfig, k?: number, maxHops?: number): GraphEdge[][];
|
|
105
|
+
/**
|
|
106
|
+
* Multi-objective path finding (Pareto-optimal paths)
|
|
107
|
+
*/
|
|
108
|
+
declare function paretoOptimalPaths(edges: GraphEdge[], startChain: ChainId, startAsset: AssetId, endChain: ChainId, endAsset: AssetId, maxHops?: number): {
|
|
109
|
+
path: GraphEdge[];
|
|
110
|
+
metrics: {
|
|
111
|
+
cost: number;
|
|
112
|
+
time: number;
|
|
113
|
+
hops: number;
|
|
114
|
+
};
|
|
115
|
+
}[];
|
|
116
|
+
|
|
117
|
+
export { AssetId, COST_CONFIGS, ChainId, type CostConfig, GraphEdge, OptimizationStrategy, Route, RouteRequest, RouteValidation, type RouterConfig, RoutingEngine, RoutingError, type RoutingErrorCode, RoutingGraph, astar, calculateEdgeCost, dijkstra, kShortestPaths, paretoOptimalPaths };
|