@wardenswap/bestrate-sdk-beta 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,847 @@
1
+ import { Event, EventFilter, BytesLike, BaseContract, Signer, Overrides, ContractTransaction, BigNumberish, CallOverrides, BigNumber, PopulatedTransaction, utils, ethers } from 'ethers';
2
+ import { FunctionFragment, Result } from '@ethersproject/abi';
3
+ import { Listener, Provider } from '@ethersproject/providers';
4
+
5
+ declare enum BESTRATE_NETWORK {
6
+ bsc = "bsc",
7
+ arbitrum = "arbitrum",
8
+ polygon = "polygon",
9
+ ethereum = "ethereum",
10
+ avalanche = "avalanche",
11
+ optimism = "optimism"
12
+ }
13
+ type TokenInfo = {
14
+ address: string;
15
+ decimals: number;
16
+ };
17
+
18
+ interface LinearVariableGasUsed {
19
+ constant: bigint;
20
+ multiplier: bigint;
21
+ }
22
+ interface L2CalldataGasUsed {
23
+ perRoute: bigint;
24
+ perPath: bigint;
25
+ initialSingle: bigint;
26
+ initialSplit: bigint;
27
+ ethWeth: bigint;
28
+ wethEth: bigint;
29
+ }
30
+
31
+ declare const GAS_TOKEN_DECIMALS = 18;
32
+ interface GasFeeDisplay {
33
+ usd: string;
34
+ dest: string;
35
+ unit: string;
36
+ }
37
+ interface GasPriceTokenChains {
38
+ l1: GasPriceTokens;
39
+ l2?: GasPriceTokens;
40
+ }
41
+ type GasPriceTokens = {
42
+ dest: {
43
+ fee: bigint;
44
+ decimals: number;
45
+ };
46
+ usd: bigint;
47
+ };
48
+ interface GasPriceTokensArbitrary {
49
+ [token: string]: {
50
+ fee: bigint;
51
+ decimals: number;
52
+ };
53
+ }
54
+ interface GasUsedUnit {
55
+ variable: LinearVariableGasUsed;
56
+ pathVariable: bigint;
57
+ initial: bigint;
58
+ }
59
+ interface GasOptions {
60
+ price: GasPriceTokenChains;
61
+ execution: GasUsedUnit;
62
+ l2Calldata?: L2CalldataGasUsed;
63
+ }
64
+ declare function zeroGasOptions(): GasOptions;
65
+
66
+ interface TypedEvent<TArgsArray extends Array<any> = any, TArgsObject = any> extends Event {
67
+ args: TArgsArray & TArgsObject;
68
+ }
69
+ interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {
70
+ }
71
+ interface TypedListener<TEvent extends TypedEvent> {
72
+ (...listenerArg: [...__TypechainArgsArray<TEvent>, TEvent]): void;
73
+ }
74
+ type __TypechainArgsArray<T> = T extends TypedEvent<infer U> ? U : never;
75
+ interface OnEvent<TRes> {
76
+ <TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>, listener: TypedListener<TEvent>): TRes;
77
+ (eventName: string, listener: Listener): TRes;
78
+ }
79
+
80
+ interface Multicall2Interface extends utils.Interface {
81
+ functions: {
82
+ "aggregate((address,bytes)[])": FunctionFragment;
83
+ "blockAndAggregate((address,bytes)[])": FunctionFragment;
84
+ "getBlockHash(uint256)": FunctionFragment;
85
+ "getBlockNumber()": FunctionFragment;
86
+ "getCurrentBlockCoinbase()": FunctionFragment;
87
+ "getCurrentBlockDifficulty()": FunctionFragment;
88
+ "getCurrentBlockGasLimit()": FunctionFragment;
89
+ "getCurrentBlockTimestamp()": FunctionFragment;
90
+ "getEthBalance(address)": FunctionFragment;
91
+ "getLastBlockHash()": FunctionFragment;
92
+ "tryAggregate(bool,(address,bytes)[])": FunctionFragment;
93
+ "tryBlockAndAggregate(bool,(address,bytes)[])": FunctionFragment;
94
+ };
95
+ getFunction(nameOrSignatureOrTopic: "aggregate" | "blockAndAggregate" | "getBlockHash" | "getBlockNumber" | "getCurrentBlockCoinbase" | "getCurrentBlockDifficulty" | "getCurrentBlockGasLimit" | "getCurrentBlockTimestamp" | "getEthBalance" | "getLastBlockHash" | "tryAggregate" | "tryBlockAndAggregate"): FunctionFragment;
96
+ encodeFunctionData(functionFragment: "aggregate", values: [Multicall2.CallStruct[]]): string;
97
+ encodeFunctionData(functionFragment: "blockAndAggregate", values: [Multicall2.CallStruct[]]): string;
98
+ encodeFunctionData(functionFragment: "getBlockHash", values: [BigNumberish]): string;
99
+ encodeFunctionData(functionFragment: "getBlockNumber", values?: undefined): string;
100
+ encodeFunctionData(functionFragment: "getCurrentBlockCoinbase", values?: undefined): string;
101
+ encodeFunctionData(functionFragment: "getCurrentBlockDifficulty", values?: undefined): string;
102
+ encodeFunctionData(functionFragment: "getCurrentBlockGasLimit", values?: undefined): string;
103
+ encodeFunctionData(functionFragment: "getCurrentBlockTimestamp", values?: undefined): string;
104
+ encodeFunctionData(functionFragment: "getEthBalance", values: [string]): string;
105
+ encodeFunctionData(functionFragment: "getLastBlockHash", values?: undefined): string;
106
+ encodeFunctionData(functionFragment: "tryAggregate", values: [boolean, Multicall2.CallStruct[]]): string;
107
+ encodeFunctionData(functionFragment: "tryBlockAndAggregate", values: [boolean, Multicall2.CallStruct[]]): string;
108
+ decodeFunctionResult(functionFragment: "aggregate", data: BytesLike): Result;
109
+ decodeFunctionResult(functionFragment: "blockAndAggregate", data: BytesLike): Result;
110
+ decodeFunctionResult(functionFragment: "getBlockHash", data: BytesLike): Result;
111
+ decodeFunctionResult(functionFragment: "getBlockNumber", data: BytesLike): Result;
112
+ decodeFunctionResult(functionFragment: "getCurrentBlockCoinbase", data: BytesLike): Result;
113
+ decodeFunctionResult(functionFragment: "getCurrentBlockDifficulty", data: BytesLike): Result;
114
+ decodeFunctionResult(functionFragment: "getCurrentBlockGasLimit", data: BytesLike): Result;
115
+ decodeFunctionResult(functionFragment: "getCurrentBlockTimestamp", data: BytesLike): Result;
116
+ decodeFunctionResult(functionFragment: "getEthBalance", data: BytesLike): Result;
117
+ decodeFunctionResult(functionFragment: "getLastBlockHash", data: BytesLike): Result;
118
+ decodeFunctionResult(functionFragment: "tryAggregate", data: BytesLike): Result;
119
+ decodeFunctionResult(functionFragment: "tryBlockAndAggregate", data: BytesLike): Result;
120
+ events: {};
121
+ }
122
+ declare namespace Multicall2 {
123
+ type CallStruct = {
124
+ target: string;
125
+ callData: BytesLike;
126
+ };
127
+ type CallStructOutput = [string, string] & {
128
+ target: string;
129
+ callData: string;
130
+ };
131
+ type ResultStruct = {
132
+ success: boolean;
133
+ returnData: BytesLike;
134
+ };
135
+ type ResultStructOutput = [boolean, string] & {
136
+ success: boolean;
137
+ returnData: string;
138
+ };
139
+ }
140
+ interface Multicall2 extends BaseContract {
141
+ connect(signerOrProvider: Signer | Provider | string): this;
142
+ attach(addressOrName: string): this;
143
+ deployed(): Promise<this>;
144
+ interface: Multicall2Interface;
145
+ queryFilter<TEvent extends TypedEvent>(event: TypedEventFilter<TEvent>, fromBlockOrBlockhash?: string | number | undefined, toBlock?: string | number | undefined): Promise<Array<TEvent>>;
146
+ listeners<TEvent extends TypedEvent>(eventFilter?: TypedEventFilter<TEvent>): Array<TypedListener<TEvent>>;
147
+ listeners(eventName?: string): Array<Listener>;
148
+ removeAllListeners<TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>): this;
149
+ removeAllListeners(eventName?: string): this;
150
+ off: OnEvent<this>;
151
+ on: OnEvent<this>;
152
+ once: OnEvent<this>;
153
+ removeListener: OnEvent<this>;
154
+ functions: {
155
+ aggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
156
+ from?: string;
157
+ }): Promise<ContractTransaction>;
158
+ blockAndAggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
159
+ from?: string;
160
+ }): Promise<ContractTransaction>;
161
+ getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise<[string] & {
162
+ blockHash: string;
163
+ }>;
164
+ getBlockNumber(overrides?: CallOverrides): Promise<[BigNumber] & {
165
+ blockNumber: BigNumber;
166
+ }>;
167
+ getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<[string] & {
168
+ coinbase: string;
169
+ }>;
170
+ getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<[BigNumber] & {
171
+ difficulty: BigNumber;
172
+ }>;
173
+ getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<[BigNumber] & {
174
+ gaslimit: BigNumber;
175
+ }>;
176
+ getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<[BigNumber] & {
177
+ timestamp: BigNumber;
178
+ }>;
179
+ getEthBalance(addr: string, overrides?: CallOverrides): Promise<[BigNumber] & {
180
+ balance: BigNumber;
181
+ }>;
182
+ getLastBlockHash(overrides?: CallOverrides): Promise<[string] & {
183
+ blockHash: string;
184
+ }>;
185
+ tryAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
186
+ from?: string;
187
+ }): Promise<ContractTransaction>;
188
+ tryBlockAndAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
189
+ from?: string;
190
+ }): Promise<ContractTransaction>;
191
+ };
192
+ aggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
193
+ from?: string;
194
+ }): Promise<ContractTransaction>;
195
+ blockAndAggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
196
+ from?: string;
197
+ }): Promise<ContractTransaction>;
198
+ getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise<string>;
199
+ getBlockNumber(overrides?: CallOverrides): Promise<BigNumber>;
200
+ getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<string>;
201
+ getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<BigNumber>;
202
+ getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<BigNumber>;
203
+ getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<BigNumber>;
204
+ getEthBalance(addr: string, overrides?: CallOverrides): Promise<BigNumber>;
205
+ getLastBlockHash(overrides?: CallOverrides): Promise<string>;
206
+ tryAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
207
+ from?: string;
208
+ }): Promise<ContractTransaction>;
209
+ tryBlockAndAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
210
+ from?: string;
211
+ }): Promise<ContractTransaction>;
212
+ callStatic: {
213
+ aggregate(calls: Multicall2.CallStruct[], overrides?: CallOverrides): Promise<[
214
+ BigNumber,
215
+ string[]
216
+ ] & {
217
+ blockNumber: BigNumber;
218
+ returnData: string[];
219
+ }>;
220
+ blockAndAggregate(calls: Multicall2.CallStruct[], overrides?: CallOverrides): Promise<[
221
+ BigNumber,
222
+ string,
223
+ Multicall2.ResultStructOutput[]
224
+ ] & {
225
+ blockNumber: BigNumber;
226
+ blockHash: string;
227
+ returnData: Multicall2.ResultStructOutput[];
228
+ }>;
229
+ getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise<string>;
230
+ getBlockNumber(overrides?: CallOverrides): Promise<BigNumber>;
231
+ getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<string>;
232
+ getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<BigNumber>;
233
+ getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<BigNumber>;
234
+ getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<BigNumber>;
235
+ getEthBalance(addr: string, overrides?: CallOverrides): Promise<BigNumber>;
236
+ getLastBlockHash(overrides?: CallOverrides): Promise<string>;
237
+ tryAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: CallOverrides): Promise<Multicall2.ResultStructOutput[]>;
238
+ tryBlockAndAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: CallOverrides): Promise<[
239
+ BigNumber,
240
+ string,
241
+ Multicall2.ResultStructOutput[]
242
+ ] & {
243
+ blockNumber: BigNumber;
244
+ blockHash: string;
245
+ returnData: Multicall2.ResultStructOutput[];
246
+ }>;
247
+ };
248
+ filters: {};
249
+ estimateGas: {
250
+ aggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
251
+ from?: string;
252
+ }): Promise<BigNumber>;
253
+ blockAndAggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
254
+ from?: string;
255
+ }): Promise<BigNumber>;
256
+ getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise<BigNumber>;
257
+ getBlockNumber(overrides?: CallOverrides): Promise<BigNumber>;
258
+ getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<BigNumber>;
259
+ getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<BigNumber>;
260
+ getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<BigNumber>;
261
+ getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<BigNumber>;
262
+ getEthBalance(addr: string, overrides?: CallOverrides): Promise<BigNumber>;
263
+ getLastBlockHash(overrides?: CallOverrides): Promise<BigNumber>;
264
+ tryAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
265
+ from?: string;
266
+ }): Promise<BigNumber>;
267
+ tryBlockAndAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
268
+ from?: string;
269
+ }): Promise<BigNumber>;
270
+ };
271
+ populateTransaction: {
272
+ aggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
273
+ from?: string;
274
+ }): Promise<PopulatedTransaction>;
275
+ blockAndAggregate(calls: Multicall2.CallStruct[], overrides?: Overrides & {
276
+ from?: string;
277
+ }): Promise<PopulatedTransaction>;
278
+ getBlockHash(blockNumber: BigNumberish, overrides?: CallOverrides): Promise<PopulatedTransaction>;
279
+ getBlockNumber(overrides?: CallOverrides): Promise<PopulatedTransaction>;
280
+ getCurrentBlockCoinbase(overrides?: CallOverrides): Promise<PopulatedTransaction>;
281
+ getCurrentBlockDifficulty(overrides?: CallOverrides): Promise<PopulatedTransaction>;
282
+ getCurrentBlockGasLimit(overrides?: CallOverrides): Promise<PopulatedTransaction>;
283
+ getCurrentBlockTimestamp(overrides?: CallOverrides): Promise<PopulatedTransaction>;
284
+ getEthBalance(addr: string, overrides?: CallOverrides): Promise<PopulatedTransaction>;
285
+ getLastBlockHash(overrides?: CallOverrides): Promise<PopulatedTransaction>;
286
+ tryAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
287
+ from?: string;
288
+ }): Promise<PopulatedTransaction>;
289
+ tryBlockAndAggregate(requireSuccess: boolean, calls: Multicall2.CallStruct[], overrides?: Overrides & {
290
+ from?: string;
291
+ }): Promise<PopulatedTransaction>;
292
+ };
293
+ }
294
+
295
+ declare enum DexModel {
296
+ UniswapV2 = 0,
297
+ UniswapV3 = 1,
298
+ DMM = 2,
299
+ CurvePlain = 3,
300
+ CurveMeta = 4,
301
+ CurvePlainSol = 5,
302
+ Iron = 6,
303
+ Synapse = 7,
304
+ CurveMetaSol = 8,
305
+ CurveCrypto = 9,
306
+ CurveLendingA = 10,
307
+ CurveLendingCryptoZap = 11,
308
+ CurveLendingCryptoTwoZap = 12,
309
+ PolyDex = 13,
310
+ FireBirdWeighted = 14,
311
+ BalancerWeighted = 15,
312
+ BalancerStable = 16,
313
+ BalancerMetaStable = 17,
314
+ BalancerBoostedStable = 18,
315
+ BalancerLinear = 19,
316
+ BalancerLiquidityBootstrapping = 20,
317
+ Biswap = 21,
318
+ DodoV1 = 22,
319
+ DodoV2 = 23,
320
+ Mdex = 24,
321
+ Mars = 25,
322
+ Smoothy = 26,
323
+ Shibaswap = 27,
324
+ GmxDex = 28,
325
+ Solidly = 29,
326
+ Synthetix = 30,
327
+ Unknown = 31
328
+ }
329
+ interface UniswapV2BasedModelInfo {
330
+ model: DexModel.UniswapV2 | DexModel.Mdex | DexModel.Biswap | DexModel.Mars | DexModel.Shibaswap;
331
+ pairBytecodeHash: string;
332
+ factory: string;
333
+ fee: bigint;
334
+ feePrecision: bigint;
335
+ }
336
+ interface UniswapV3ModelInfo extends Omit<UniswapV2BasedModelInfo, 'model' | 'feePrecision'> {
337
+ model: DexModel.UniswapV3;
338
+ maxInitializedTicks: number;
339
+ tickQuerier: string;
340
+ depositAddress: string;
341
+ gasPerInitializedTick: bigint;
342
+ gasPerTick: bigint;
343
+ }
344
+ interface PolyDexModelInfo extends Omit<UniswapV2BasedModelInfo, 'model'> {
345
+ model: DexModel.PolyDex | DexModel.FireBirdWeighted;
346
+ weight: number;
347
+ }
348
+ interface CurvePlainModelInfo {
349
+ model: DexModel.CurvePlain | DexModel.CurvePlainSol | DexModel.Iron | DexModel.Synapse;
350
+ poolContract: string;
351
+ lpToken: string;
352
+ tokens: string[];
353
+ rates: bigint[];
354
+ lendingPrecision: bigint;
355
+ precision: bigint;
356
+ precisionMul: bigint[];
357
+ feeDenominator: bigint;
358
+ isUnderlying: boolean;
359
+ aPrecision?: bigint;
360
+ balancesArgs?: string;
361
+ }
362
+ interface CurveLendingModelInfo {
363
+ model: DexModel.CurveLendingA;
364
+ poolContract: string;
365
+ lpToken: string;
366
+ tokens: string[];
367
+ precision: bigint;
368
+ precisionMul: bigint[];
369
+ feeDenominator: bigint;
370
+ aPrecision: bigint;
371
+ }
372
+ interface CurveMetaModelInfo extends Omit<CurvePlainModelInfo, 'isUnderlying' | 'lendingPrecision' | 'model'> {
373
+ model: DexModel.CurveMeta | DexModel.CurveMetaSol;
374
+ multicall: string;
375
+ baseCacheExpires: bigint;
376
+ basePoolRouteId: string;
377
+ isCacheExists: boolean;
378
+ }
379
+ interface CurveCryptoModelInfo {
380
+ model: DexModel.CurveCrypto;
381
+ tokens: string[];
382
+ precision: bigint;
383
+ precisions: bigint[];
384
+ feeDenominator: bigint;
385
+ noiseFee: bigint;
386
+ minA: bigint;
387
+ maxA: bigint;
388
+ isAPrecise: boolean;
389
+ minGamma: bigint;
390
+ maxGamma: bigint;
391
+ aMultiplier: bigint;
392
+ poolContract: string;
393
+ lpToken: string;
394
+ }
395
+ interface CurveCryptoZapModelInfo {
396
+ model: DexModel.CurveLendingCryptoZap;
397
+ basePoolId: string;
398
+ poolId: string;
399
+ tokens: string[];
400
+ nStablecoins: number;
401
+ poolContract: string;
402
+ }
403
+ interface CurveCryptoTwoZapModelInfo extends Omit<CurveCryptoZapModelInfo, 'model'> {
404
+ model: DexModel.CurveLendingCryptoTwoZap;
405
+ nCoins: number;
406
+ }
407
+ interface DMMModelInfo {
408
+ model: DexModel.DMM;
409
+ pools: {
410
+ [token0: string]: {
411
+ [token1: string]: string;
412
+ };
413
+ };
414
+ }
415
+ interface BalancerWeightedModelInfo extends Omit<BalancerStableModelInfo, 'model' | 'aPrecision'> {
416
+ model: DexModel.BalancerWeighted | DexModel.BalancerLiquidityBootstrapping;
417
+ weights: bigint[];
418
+ }
419
+ interface BalancerStableModelInfo {
420
+ model: DexModel.BalancerStable;
421
+ tokens: string[];
422
+ scalingFactors: bigint[];
423
+ vaultContract: string;
424
+ poolId: string;
425
+ aPrecision: bigint;
426
+ depositAddress: string;
427
+ }
428
+ interface BalancerBoostedStableModelInfo extends Omit<BalancerStableModelInfo, 'model'> {
429
+ model: DexModel.BalancerBoostedStable;
430
+ bptIndex: number;
431
+ linearPoolIds: string[];
432
+ }
433
+ interface BalancerLinearModelInfo {
434
+ model: DexModel.BalancerLinear;
435
+ tokens: string[];
436
+ scalingFactors: bigint[];
437
+ vaultContract: string;
438
+ poolId: string;
439
+ mainIndex: number;
440
+ wrappedIndex: number;
441
+ wrappedToken: string;
442
+ bptIndex: number;
443
+ depositAddress: string;
444
+ }
445
+ interface BalancerMetaStableModelInfo extends Omit<BalancerStableModelInfo, 'model'> {
446
+ model: DexModel.BalancerMetaStable;
447
+ rateProviders: string[];
448
+ multicall: string;
449
+ }
450
+ interface DodoV2ModelInfo {
451
+ model: DexModel.DodoV2 | DexModel.DodoV1;
452
+ factoryContract: string;
453
+ pools: {
454
+ [baseToken: string]: {
455
+ [quoteToken: string]: string;
456
+ };
457
+ };
458
+ }
459
+ interface SmoothyModelInfo {
460
+ model: DexModel.Smoothy;
461
+ poolContract: string;
462
+ expectedImplAddress: string;
463
+ expectedTokens: {
464
+ [addr: string]: number;
465
+ };
466
+ }
467
+ interface GmxDexModelInfo {
468
+ model: DexModel.GmxDex;
469
+ vaultContract: string;
470
+ pricePrecision: bigint;
471
+ debtTokenContract: string;
472
+ }
473
+ interface SolidlyModelInfo {
474
+ model: DexModel.Solidly;
475
+ factoryContract: string;
476
+ isStable: boolean;
477
+ pairBytecodeHash: string;
478
+ }
479
+ interface SynthetixModelInfo {
480
+ model: DexModel.Synthetix;
481
+ tokens: {
482
+ [address: string]: string;
483
+ };
484
+ sUsdContract: string;
485
+ exchangeRatesContract: string;
486
+ exchangerContract: string;
487
+ synthetixContract: string;
488
+ flexibleStorageContract: string;
489
+ PRECISION_UNIT: bigint;
490
+ }
491
+ interface RouteInfo {
492
+ id: string;
493
+ address: string;
494
+ name: string;
495
+ }
496
+ type RouteInfoModel = RouteInfo & {
497
+ gas: bigint;
498
+ isTradingAllowed: boolean;
499
+ } & (UniswapV2BasedModelInfo | UniswapV3ModelInfo | CurvePlainModelInfo | CurveMetaModelInfo | CurveCryptoModelInfo | CurveCryptoZapModelInfo | CurveCryptoTwoZapModelInfo | CurveLendingModelInfo | DodoV2ModelInfo | SmoothyModelInfo | DMMModelInfo | BalancerWeightedModelInfo | BalancerStableModelInfo | BalancerMetaStableModelInfo | BalancerBoostedStableModelInfo | BalancerLinearModelInfo | PolyDexModelInfo | GmxDexModelInfo | SolidlyModelInfo | SynthetixModelInfo | {
500
+ model: DexModel.Unknown;
501
+ });
502
+
503
+ type DexRoute = RouteInfoModel[];
504
+
505
+ interface MulticallBatchOption {
506
+ maxCallsPerBatch: number;
507
+ }
508
+
509
+ interface AmountOut {
510
+ amount: bigint;
511
+ gas: bigint;
512
+ }
513
+ interface IAmountOutCalculatorModel {
514
+ /**
515
+ * get a list of pair that can be traded via the model
516
+ */
517
+ getTradablePairs(): [string, string][];
518
+ /**
519
+ * Get Warden's trading route address
520
+ */
521
+ getTradingRouteIndex(): number;
522
+ /**
523
+ * Get pool address for the model
524
+ */
525
+ getPoolAddress(): string;
526
+ /**
527
+ * TODO: Let model return list of visited path for given token pair
528
+ * pool
529
+ *
530
+ * getVisitedPaths(src: string, dest: string): [poolAddress, Set<string>()][]
531
+ * For 1 model:
532
+ * Uniswap: [[0xpool1, new Set<string>([0xtoken1, 0xtoken2])]]
533
+ * CurveMetaPool: [
534
+ * [0xmetaPool, new Set<string>([0xmetaToken])]
535
+ * [0xbasePool, new Set<string>([0xbaseToken])]
536
+ * ]
537
+ * GMX: [
538
+ * [0xgmxVault, new Set<string>([0xtoken1, token2])]
539
+ * ]
540
+ *
541
+ * Or, if swap a token on pool affects other tokens in the same pool, then return only list of pool tokens
542
+ */
543
+ /**
544
+ * Get deposit address
545
+ */
546
+ getDepositAddress(): string;
547
+ /**
548
+ * generate Multicall calls for getting current state of source
549
+ * @param tokens list of src/dest token addresses
550
+ */
551
+ getfetchingCurrentStateCalls(): Multicall2.CallStruct[];
552
+ /**
553
+ * Apply outputs received from Multicall
554
+ * @param outputs multicall's outputs
555
+ */
556
+ applyCurrentStateFromCalls(outputs: Multicall2.ResultStructOutput[]): void;
557
+ /**
558
+ * Calculate output amount based on trade direction and input amount
559
+ * @param src source token address
560
+ * @param dest destination token address
561
+ * @param amountIn amountIn
562
+ */
563
+ getAmountOut(src: string, dest: string, amountIn: bigint): AmountOut;
564
+ }
565
+
566
+ interface AmountOutResult {
567
+ amountOut: AmountOut;
568
+ routeIndex: number;
569
+ poolAddress: string;
570
+ }
571
+ interface TradingPath {
572
+ routeIndexes: number[];
573
+ tokens: string[];
574
+ pools: string[];
575
+ amountOut: bigint;
576
+ gas: bigint;
577
+ }
578
+ interface DexManagerOptions {
579
+ multicall: MulticallBatchOption;
580
+ maxCandidatePaths: number;
581
+ }
582
+ declare class DexManager {
583
+ private readonly DEX_ROUTES;
584
+ private readonly CORRESPONDENT_TOKENS;
585
+ private multicall;
586
+ private opt;
587
+ readonly corrTokenDecimals: {
588
+ [token: string]: number;
589
+ };
590
+ private models;
591
+ private indexedModels;
592
+ private DEX_ROUTES_ID_IDX;
593
+ private DEX_ROUTES_ADDRESS_IDX;
594
+ private corrTokens;
595
+ private amountOutCache;
596
+ constructor(DEX_ROUTES: DexRoute, CORRESPONDENT_TOKENS: TokenInfo[], multicall: Multicall2, opt: DexManagerOptions);
597
+ private updateIndexedModel;
598
+ private isModelIndexed;
599
+ private isModelTradingAllowed;
600
+ getModel<T extends IAmountOutCalculatorModel>(src: string, dest: string, routeIdx: number): T | undefined;
601
+ private getTradableModels;
602
+ getDepositAddress(src: string, dest: string, routeAddress: string): string;
603
+ generateAllTokenPairs(src: string, dest: string): [string, string][];
604
+ unregisterAll(): void;
605
+ registerSingle(pair: [string, string], routeIdx: number): void;
606
+ register(src: string, dest: string): void;
607
+ getRouteInfo(routeIdx: number): RouteInfo;
608
+ fetchAllReserves(): Promise<number>;
609
+ private tryGetAmountOut;
610
+ getMaxAmountOutWithCache(src: string, dest: string, amountIn: bigint, visitedRoutes?: Set<string>, gasPrice?: GasPriceTokensArbitrary): AmountOutResult;
611
+ getAmountOutByPath(src: string, dest: string, amountIn: bigint, routeIndexes: number[], tokens: string[]): AmountOut;
612
+ protected getPathCombinationRecursively(depth: number, tokens: string[], dest: string, visitedTokens: string[], amountIn: bigint, paths: TradingPath[], topNPaths: number, dexSelectorFunc: (src: string, dest: string, amountIn: bigint, visitedPools: Set<string>) => AmountOutResult): void;
613
+ getAllRoutesSingle(src: string, dest: string, amountIn: bigint, gasPrices?: GasPriceTokensArbitrary): TradingPath[];
614
+ getTokenPriceRoutes(usd: string, usdDecimal: number, additionalTokens: string[]): {
615
+ [token: string]: TradingPath[];
616
+ };
617
+ getCandidatePaths(topNPaths: number, src: string, dest: string, amountIn: bigint, gasPrices?: GasPriceTokensArbitrary): TradingPath[];
618
+ getAllRoutesSplit(src: string, dest: string, amountIn: bigint, gasPrice?: GasPriceTokensArbitrary): {
619
+ paths: TradingPath[];
620
+ amountOuts: bigint[][];
621
+ gas: bigint[][];
622
+ };
623
+ }
624
+
625
+ interface WardenBestRateOption {
626
+ /** Maximum number of function calls per single multicall call, lower the number may improve latency but in exchange of higher network traffic */
627
+ maxCallsPerFetch?: number;
628
+ /** Maximum number of candidate paths for split trading, lower the number may improve performance */
629
+ maxCandidatePathsCount?: number;
630
+ }
631
+ interface GetQuoteOption {
632
+ /** A flag indicating whether spliting trade should be enabled */
633
+ enableSplit?: boolean;
634
+ /** L2 Gas price for L2 chains e.g. Optimism, Arbitrum */
635
+ gasPriceL2?: ethers.BigNumberish;
636
+ }
637
+ type PathResult = {
638
+ routes: RouteInfo[];
639
+ tokens: string[];
640
+ };
641
+ type QuoteResult = {
642
+ type: 'split';
643
+ paths: PathResult[];
644
+ depositAddresses: string[];
645
+ volumns: number[];
646
+ amountOut: string;
647
+ gasFees: GasFeeDisplay;
648
+ blockNumber: number;
649
+ routerAddress: string;
650
+ swapAddress: string;
651
+ } | {
652
+ type: 'strategies';
653
+ path: PathResult;
654
+ depositAddress: string;
655
+ amountOut: string;
656
+ gasFees: GasFeeDisplay;
657
+ blockNumber: number;
658
+ routerAddress: string;
659
+ swapAddress: string;
660
+ } | {
661
+ type: 'ethToWeth' | 'wethToEth';
662
+ routerAddress: string;
663
+ amountOut: string;
664
+ gasFees: GasFeeDisplay;
665
+ };
666
+ /**
667
+ * Warden Best Rate for getting quote and swapping.
668
+ */
669
+ declare class WardenBestRate {
670
+ private provider;
671
+ private multicall2;
672
+ private network;
673
+ private options;
674
+ /**
675
+ * Create new instance of WardenBestRate
676
+ *
677
+ * @param provider ethersjs' Provider instance
678
+ * @param networkName Chain name (supported by WardenSwap)
679
+ * @param options Options
680
+ */
681
+ constructor(provider: ethers.providers.Provider, networkName: `${BESTRATE_NETWORK}`, options?: WardenBestRateOption);
682
+ private getTradeType;
683
+ /**
684
+ * Get deposit addresses indicating the first hop to be used for starting the trade.
685
+ * This information is required by Wardenswap contract
686
+ * @param srcDestRouteTuples tuples of src, dest, and routeAddress
687
+ * @returns a list of deposit addresses with the same order as the input
688
+ */
689
+ getDepositAddresses(srcDestRouteTuples: {
690
+ src: string;
691
+ dest: string;
692
+ routeAddress: string;
693
+ }[], dexManager?: DexManager): string[];
694
+ private _fetch;
695
+ private _quoteETHWETH;
696
+ private sendTx;
697
+ /**
698
+ * Set Allowance of a token to be spendable by WardenSwap contract
699
+ * @param signer ethers' Signer
700
+ * @param src Token to be approved
701
+ * @param allowedAmount Allowed amount to be spendable by WardenSwap contract
702
+ * @param overrides ethers' overrides
703
+ * @returns ethers' contract transaction (no wait)
704
+ */
705
+ approve(signer: Signer, src: string, allowedAmount?: ethers.BigNumberish, overrides?: ethers.PayableOverrides): Promise<ethers.ContractTransaction | null>;
706
+ /**
707
+ * Send a swap transaction to WardenSwap based on given quote
708
+ * @param signer ethers' Signer
709
+ * @param src Source token
710
+ * @param dest Destination token
711
+ * @param amountIn Amount of source token
712
+ * @param minDestAmount Minimum amount of destination token
713
+ * @param quoteResult Best rate quote got from `getQuote` method
714
+ * @param partnerId Warden's partner ID
715
+ * @param metaData MetaWarden ID
716
+ * @param receiver Wallet to receive destination token, default to tx sender
717
+ * @param overrides ethers' transaction overrides
718
+ * @returns ethers' contract transaction (no wait)
719
+ */
720
+ swap(signer: Signer, src: string, dest: string, amountIn: ethers.BigNumberish, minDestAmount: ethers.BigNumberish, quoteResult: QuoteResult, partnerId?: ethers.BigNumberish, metaData?: ethers.BigNumberish, receiver?: string, overrides?: ethers.PayableOverrides): Promise<ethers.ContractTransaction>;
721
+ /**
722
+ * Get the best rate of a token pair with given amount
723
+ * @param src Address of src asset
724
+ * @param dest Address of dest asset
725
+ * @param amountIn Amount of src asset to be traded
726
+ * @param gasPrice Amount of gas price per unit in native currency (18 decimals)
727
+ * e.g. BSC = BNB, Polygon = MATIC, Ethereum = ETH. For L2 chains,
728
+ * this is Ethereum (L1) gas price.
729
+ * @param opts Options for getting quote
730
+ * @returns Trading routes which provide the best rate
731
+ */
732
+ getQuote(src: string, dest: string, amountIn: ethers.BigNumberish, gasPrice: ethers.BigNumberish, opts?: GetQuoteOption): Promise<QuoteResult>;
733
+ }
734
+
735
+ /**
736
+ * A class for calldata compression to be used with WardenSwap on L2 chains
737
+ */
738
+ declare class WardenPayloadCompressor {
739
+ private networkName;
740
+ private provider;
741
+ private multicallOptions?;
742
+ private multicall;
743
+ private addressTableContract;
744
+ private readonly MAX_UINT24;
745
+ private readonly MAX_UINT32;
746
+ private readonly MAX_UINT64;
747
+ private readonly MAX_UINT80;
748
+ private readonly MAX_UINT96;
749
+ private readonly MAX_UINT112;
750
+ /**
751
+ * Create new instance of WardenPayloadCompressor
752
+ * @param networkName Chain name (supported by WardenSwap)
753
+ * @param provider ethersjs' Provider
754
+ * @param multicallOptions Multicall options
755
+ */
756
+ constructor(networkName: `${BESTRATE_NETWORK}`, provider: ethers.providers.Provider, multicallOptions?: MulticallBatchOption);
757
+ private fetchAddressIndex;
758
+ private encodeAddress;
759
+ private encodeAmount;
760
+ private encodePathResult;
761
+ private addPathResultAddressesToArray;
762
+ private createAddressIndexMap;
763
+ /**
764
+ * Compress swap data for L2 chains
765
+ * @param paths Path result(s) gathered from `getQuote`
766
+ * @param volumes Splitting ratio of source token amount range from 1-100
767
+ * @param addressIdxMap Address-index map gathered from ArbAddressTable contract
768
+ * @returns A hexadecimal string representing compressed swap data
769
+ */
770
+ encodeSwapDataL2(paths: PathResult | PathResult[], volumes: number[], addressIdxMap?: {
771
+ [address: string]: ethers.BigNumber | null;
772
+ }): Promise<string>;
773
+ /**
774
+ * Encode swap data for L1 chains
775
+ * @param paths Path result(s) gathered from `getQuote`
776
+ * @returns A hexadecimal string representing encoded swap data
777
+ */
778
+ encodeSwapData(paths: PathResult | PathResult[]): string;
779
+ /**
780
+ * Compress calldata for L2 chains
781
+ * @param src Source Token
782
+ * @param dest Destination Token
783
+ * @param amountIn Amount of source token
784
+ * @param minDestAmount Minimum amount of destination token required
785
+ * @param partnerId Warden's partner ID
786
+ * @param metaData MetaWarden data
787
+ * @param swapAddress Warden swap contract
788
+ * @param receiver Receiver wallet
789
+ * @param paths Path result(s) gathered from `getQuote`
790
+ * @param volumes Splitting ratio of source token amount range from 1-100
791
+ * @returns Serialized data to be used with swap functions with compression feature
792
+ */
793
+ compress(src: string, dest: string, amountIn: ethers.BigNumberish, minDestAmount: ethers.BigNumberish, partnerId: ethers.BigNumberish, metaData: ethers.BigNumberish, swapAddress: string, receiver: string, paths: PathResult | PathResult[], volumes: number[]): Promise<string>;
794
+ }
795
+
796
+ declare function initProvider(url: string, user?: string, password?: string): ethers.providers.JsonRpcProvider;
797
+
798
+ declare enum LogLevel {
799
+ DEBUG = 8,
800
+ LOG = 4,
801
+ WARN = 2,
802
+ ERROR = 1,
803
+ SILENT = 0
804
+ }
805
+ interface LoggerService {
806
+ level: LogLevel;
807
+ /**
808
+ * Write a 'log' level log.
809
+ */
810
+ log(message: any, ...optionalParams: any[]): any;
811
+ /**
812
+ * Write an 'error' level log.
813
+ */
814
+ error(message: any, ...optionalParams: any[]): any;
815
+ /**
816
+ * Write a 'warn' level log.
817
+ */
818
+ warn(message: any, ...optionalParams: any[]): any;
819
+ /**
820
+ * Write a 'debug' level log.
821
+ */
822
+ debug?(message: any, ...optionalParams: any[]): any;
823
+ /**
824
+ * Write a 'table' in 'debug' log level
825
+ * @param tabularData
826
+ * @param properties
827
+ */
828
+ table(tabularData?: any, properties?: string[]): void;
829
+ /**
830
+ * Set log levels.
831
+ * @param levels log levels
832
+ */
833
+ setLogLevels?(levels: LogLevel[]): any;
834
+ }
835
+ declare class Logger implements LoggerService {
836
+ level: LogLevel;
837
+ constructor(level: LogLevel);
838
+ static overrideLogger(logger: LoggerService): void;
839
+ log(message: any, ...optionalParams: any[]): void;
840
+ error(message: any, ...optionalParams: any[]): void;
841
+ warn(message: any, ...optionalParams: any[]): void;
842
+ debug(message: any, ...optionalParams: any[]): void;
843
+ table(tabularData?: any, properties?: string[]): void;
844
+ }
845
+ declare let log: LoggerService;
846
+
847
+ export { BESTRATE_NETWORK, GAS_TOKEN_DECIMALS, LogLevel, Logger, type LoggerService, type QuoteResult, WardenBestRate, WardenPayloadCompressor, initProvider, log, zeroGasOptions };