@paraswap/dex-lib 3.4.2-balancer-v2-single-swap.0 → 3.4.2
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 +377 -377
- package/build/config.js +9 -5
- package/build/config.js.map +1 -1
- package/build/dex/algebra/algebra.js +25 -25
- package/build/dex/balancer-v1/balancer-v1.js +34 -34
- package/build/dex/balancer-v2/balancer-v2.d.ts +1 -1
- package/build/dex/balancer-v2/balancer-v2.js +65 -78
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/camelot/camelot.js +27 -27
- package/build/dex/kyberdmm/kyberdmm.js +27 -27
- package/build/dex/pancakeswap-v3/pancakeswap-v3.js +25 -25
- package/build/dex/solidly/solidly.js +27 -27
- package/build/dex/solidly-v3/solidly-v3.js +25 -25
- package/build/dex/swaap-v2/config.js +15 -0
- package/build/dex/swaap-v2/config.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +26 -26
- package/build/dex/uniswap-v3/uniswap-v3.js +25 -25
- package/funding.json +5 -5
- package/package.json +1 -1
- package/src/config.ts +500 -496
- package/src/constants.ts +67 -67
- package/src/dex/aave-v2/aave-v2.ts +409 -409
- package/src/dex/aave-v3/aave-v3.ts +320 -320
- package/src/dex/algebra/algebra.ts +1180 -1180
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +347 -347
- package/src/dex/augustus-rfq.ts +180 -180
- package/src/dex/bProtocol/bProtocol.ts +108 -108
- package/src/dex/balancer-v1/balancer-v1.ts +572 -572
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +1699 -1699
- package/src/dex/balancer-v2/balancer-v2.ts +1669 -1701
- package/src/dex/bancor/bancor.ts +128 -128
- package/src/dex/camelot/camelot.ts +873 -873
- package/src/dex/compound/compound.ts +107 -107
- package/src/dex/curve-v1/config.ts +1179 -1179
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +507 -507
- package/src/dex/curve-v1/curve-v1.ts +1315 -1315
- package/src/dex/curve-v1-factory/config.ts +1018 -1018
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +1288 -1288
- package/src/dex/curve-v2/curve-v2.ts +440 -440
- package/src/dex/dexalot/dexalot.ts +1100 -1100
- package/src/dex/dodo-v1/dodo-v1.ts +132 -132
- package/src/dex/dodo-v2.ts +266 -266
- package/src/dex/etherfi.ts +239 -239
- package/src/dex/generic-rfq/generic-rfq.ts +431 -431
- package/src/dex/gmx/gmx.ts +321 -321
- package/src/dex/hashflow/hashflow.ts +1135 -1135
- package/src/dex/idex.ts +254 -254
- package/src/dex/index.ts +357 -357
- package/src/dex/jarvis-v6/jarvis-v6.ts +509 -509
- package/src/dex/jarvis.ts +262 -262
- package/src/dex/kyberdmm/kyberdmm.ts +649 -649
- package/src/dex/lido/lido.ts +110 -110
- package/src/dex/maker-psm/maker-psm.ts +592 -592
- package/src/dex/maverick-v1/maverick-v1.ts +537 -537
- package/src/dex/nerve/config.ts +635 -635
- package/src/dex/nerve/nerve-e2e.test.ts +731 -731
- package/src/dex/nerve/nerve-events.test.ts +911 -911
- package/src/dex/nerve/nerve.ts +467 -467
- package/src/dex/onebit/onebit.ts +113 -113
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1150 -1150
- package/src/dex/paraswap-limit-orders/config.ts +60 -60
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +137 -137
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-integration.test.ts +328 -328
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +631 -631
- package/src/dex/polygon-migrator/polygon-migrator.ts +194 -194
- package/src/dex/quick-perps/quick-perps.ts +337 -337
- package/src/dex/quickswap/config.ts +16 -16
- package/src/dex/quickswap/quickswap-e2e.test.ts +384 -384
- package/src/dex/smoothy/smoothy.ts +110 -110
- package/src/dex/solidly/config.ts +225 -225
- package/src/dex/solidly/solidly-e2e.test.ts +1421 -1421
- package/src/dex/solidly/solidly-integration.test.ts +1753 -1753
- package/src/dex/solidly/solidly.ts +687 -687
- package/src/dex/solidly-v3/solidly-v3.ts +968 -968
- package/src/dex/spark/spark.ts +284 -284
- package/src/dex/stable-pool/stable-pool.ts +129 -129
- package/src/dex/swaap-v2/config.ts +15 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +233 -17
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +1 -1
- package/src/dex/swaap-v2/swaap-v2.ts +1056 -1056
- package/src/dex/swell/swell.ts +312 -312
- package/src/dex/synthetix/synthetix.ts +420 -420
- package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +180 -180
- package/src/dex/uniswap-v2/config.ts +637 -637
- package/src/dex/uniswap-v2/constants.ts +58 -58
- package/src/dex/uniswap-v2/uniswap-v2-e2e-avalanche.test.ts +1257 -1257
- package/src/dex/uniswap-v2/uniswap-v2-e2e-base.test.ts +42 -42
- package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +1295 -1295
- package/src/dex/uniswap-v2/uniswap-v2-e2e-mainnet.test.ts +1834 -1834
- package/src/dex/uniswap-v2/uniswap-v2-e2e-polygon.test.ts +871 -871
- package/src/dex/uniswap-v2/uniswap-v2.ts +1117 -1117
- package/src/dex/uniswap-v3/uniswap-v3.ts +1501 -1501
- package/src/dex/uniswap-v3.ts +242 -242
- package/src/dex/weth/config.ts +73 -73
- package/src/dex/weth/weth.ts +230 -230
- package/src/dex/wombat/wombat.ts +467 -467
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +529 -529
- package/src/dex/wsteth/wsteth.ts +304 -304
- package/src/dex/zerox/index.ts +328 -328
- package/src/executor/Executor01BytecodeBuilder.ts +474 -474
- package/src/executor/Executor02BytecodeBuilder.ts +1392 -1392
- package/src/executor/ExecutorBytecodeBuilder.ts +390 -390
- package/src/executor/ExecutorDetector.ts +131 -131
- package/src/executor/constants.ts +66 -66
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +1478 -1478
- package/src/executor/utils.ts +62 -62
- package/src/router/simpleswap.ts +366 -366
- package/src/types.ts +342 -342
- package/tests/constants-e2e.ts +1632 -1622
- package/tests/generate-new-limit-order.ts +107 -107
package/src/dex/idex.ts
CHANGED
|
@@ -1,254 +1,254 @@
|
|
|
1
|
-
import { AsyncOrSync } from 'ts-essentials';
|
|
2
|
-
import {
|
|
3
|
-
Address,
|
|
4
|
-
SimpleExchangeParam,
|
|
5
|
-
AdapterExchangeParam,
|
|
6
|
-
DexExchangeParam,
|
|
7
|
-
TxInfo,
|
|
8
|
-
NumberAsString,
|
|
9
|
-
Token,
|
|
10
|
-
ExchangePrices,
|
|
11
|
-
PoolPrices,
|
|
12
|
-
PoolLiquidity,
|
|
13
|
-
OptimalSwapExchange,
|
|
14
|
-
ExchangeTxInfo,
|
|
15
|
-
PreprocessTransactionOptions,
|
|
16
|
-
TransferFeeParams,
|
|
17
|
-
Config,
|
|
18
|
-
} from '../types';
|
|
19
|
-
import { SwapSide, Network } from '../constants';
|
|
20
|
-
import { IDexHelper } from '../dex-helper/idex-helper';
|
|
21
|
-
|
|
22
|
-
export type Context = {
|
|
23
|
-
isGlobalSrcToken: boolean;
|
|
24
|
-
isGlobalDestToken: boolean;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
|
|
28
|
-
needWrapNative: boolean;
|
|
29
|
-
needsSequentialPreprocessing?: boolean;
|
|
30
|
-
|
|
31
|
-
// Returns the ETH fee required to swap
|
|
32
|
-
// It is optional for a DEX to implement this
|
|
33
|
-
// This is a legacy function and will be removed soon
|
|
34
|
-
getNetworkFee?(
|
|
35
|
-
srcToken: Address,
|
|
36
|
-
destToken: Address,
|
|
37
|
-
srcAmount: NumberAsString,
|
|
38
|
-
destAmount: NumberAsString,
|
|
39
|
-
data: ExchangeData,
|
|
40
|
-
side: SwapSide,
|
|
41
|
-
): NumberAsString;
|
|
42
|
-
|
|
43
|
-
// If exists, called before getAdapterParam to use async calls and receive data if needed
|
|
44
|
-
preProcessTransaction?(
|
|
45
|
-
optimalSwapExchange: OptimalSwapExchange<ExchangeData>,
|
|
46
|
-
srcToken: Token,
|
|
47
|
-
destToken: Token,
|
|
48
|
-
side: SwapSide,
|
|
49
|
-
options: PreprocessTransactionOptions,
|
|
50
|
-
): AsyncOrSync<[OptimalSwapExchange<ExchangeData>, ExchangeTxInfo]>;
|
|
51
|
-
|
|
52
|
-
// This is helper a function to support testing if preProcessTransaction is implemented
|
|
53
|
-
getTokenFromAddress?(address: Address): Token;
|
|
54
|
-
|
|
55
|
-
// Encode params required by the exchange adapter
|
|
56
|
-
// V5: Used for multiSwap, buy & megaSwap
|
|
57
|
-
// V6: NOT used, pass a placeholder
|
|
58
|
-
getAdapterParam(
|
|
59
|
-
srcToken: Address,
|
|
60
|
-
destToken: Address,
|
|
61
|
-
srcAmount: NumberAsString,
|
|
62
|
-
destAmount: NumberAsString, // required for buy case
|
|
63
|
-
data: ExchangeData,
|
|
64
|
-
side: SwapSide,
|
|
65
|
-
): AdapterExchangeParam;
|
|
66
|
-
|
|
67
|
-
// Encode call data used by simpleSwap like routers
|
|
68
|
-
// V5: Used for simpleSwap & simpleBuy
|
|
69
|
-
// V6: NOT used, don't implement
|
|
70
|
-
getSimpleParam?(
|
|
71
|
-
srcToken: Address,
|
|
72
|
-
destToken: Address,
|
|
73
|
-
srcAmount: NumberAsString,
|
|
74
|
-
destAmount: NumberAsString,
|
|
75
|
-
data: ExchangeData,
|
|
76
|
-
side: SwapSide,
|
|
77
|
-
): AsyncOrSync<SimpleExchangeParam>;
|
|
78
|
-
|
|
79
|
-
getDexParam?(
|
|
80
|
-
srcToken: Address,
|
|
81
|
-
destToken: Address,
|
|
82
|
-
srcAmount: NumberAsString,
|
|
83
|
-
destAmount: NumberAsString,
|
|
84
|
-
recipient: Address,
|
|
85
|
-
data: ExchangeData,
|
|
86
|
-
side: SwapSide,
|
|
87
|
-
context: Context,
|
|
88
|
-
executorAddress: Address,
|
|
89
|
-
): AsyncOrSync<DexExchangeParam>;
|
|
90
|
-
|
|
91
|
-
// Returns params required by direct swap method.
|
|
92
|
-
// Only Dexes which have a direct method should implement this
|
|
93
|
-
// Used if there is a possibility for direct swap (Eg. UniswapV2,
|
|
94
|
-
// 0xV2/V4, etc)
|
|
95
|
-
getDirectParam?(
|
|
96
|
-
srcToken: Address,
|
|
97
|
-
destToken: Address,
|
|
98
|
-
srcAmount: NumberAsString,
|
|
99
|
-
destAmount: NumberAsString,
|
|
100
|
-
expectedAmount: NumberAsString,
|
|
101
|
-
data: ExchangeData,
|
|
102
|
-
side: SwapSide,
|
|
103
|
-
permit: string,
|
|
104
|
-
uuid: string,
|
|
105
|
-
feePercent: NumberAsString,
|
|
106
|
-
deadline: NumberAsString,
|
|
107
|
-
partner: string,
|
|
108
|
-
beneficiary: string,
|
|
109
|
-
contractMethod?: string,
|
|
110
|
-
): TxInfo<DirectParam>;
|
|
111
|
-
|
|
112
|
-
// Same as above but for V6
|
|
113
|
-
getDirectParamV6?(
|
|
114
|
-
srcToken: Address,
|
|
115
|
-
destToken: Address,
|
|
116
|
-
fromAmount: NumberAsString,
|
|
117
|
-
toAmount: NumberAsString,
|
|
118
|
-
quotedAmount: NumberAsString,
|
|
119
|
-
data: ExchangeData,
|
|
120
|
-
side: SwapSide,
|
|
121
|
-
permit: string,
|
|
122
|
-
uuid: string,
|
|
123
|
-
partnerAndFee: string,
|
|
124
|
-
beneficiary: string,
|
|
125
|
-
blockNumber: number,
|
|
126
|
-
contractMethod?: string,
|
|
127
|
-
): TxInfo<DirectParam>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export interface IDexPricing<ExchangeData> {
|
|
131
|
-
readonly dexKey: string;
|
|
132
|
-
// This is true if the the DEX is simply
|
|
133
|
-
// wrapping/ unwrapping like weth, lending pools, etc
|
|
134
|
-
// or has a pool where arbitrarily large amounts has
|
|
135
|
-
// constant price.
|
|
136
|
-
readonly hasConstantPriceLargeAmounts: boolean;
|
|
137
|
-
|
|
138
|
-
// Specify if current Dex integration can handle fee on transfer tokens
|
|
139
|
-
readonly isFeeOnTransferSupported: boolean;
|
|
140
|
-
|
|
141
|
-
readonly cacheStateKey: string;
|
|
142
|
-
|
|
143
|
-
// Used to determine if current dex is state polling type or not
|
|
144
|
-
// Set to true if there are many pools polling state and there is no
|
|
145
|
-
// event base support for this Dex
|
|
146
|
-
readonly isStatePollingDex?: boolean;
|
|
147
|
-
|
|
148
|
-
// Returns list of pool identifiers that can be used
|
|
149
|
-
// for a given swap. poolIdentifiers must be unique
|
|
150
|
-
// across DEXes. It is recommended to use
|
|
151
|
-
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
152
|
-
getPoolIdentifiers(
|
|
153
|
-
srcToken: Token,
|
|
154
|
-
destToken: Token,
|
|
155
|
-
side: SwapSide,
|
|
156
|
-
blockNumber: number,
|
|
157
|
-
): Promise<string[]>;
|
|
158
|
-
|
|
159
|
-
// Returns pool prices for amounts.
|
|
160
|
-
// If limitPools is defined only pools in limitPools
|
|
161
|
-
// should be used. If limitPools is undefined then
|
|
162
|
-
// any pools can be used.
|
|
163
|
-
getPricesVolume(
|
|
164
|
-
srcToken: Token,
|
|
165
|
-
destToken: Token,
|
|
166
|
-
amounts: bigint[],
|
|
167
|
-
side: SwapSide,
|
|
168
|
-
blockNumber: number,
|
|
169
|
-
// list of pool identifiers to use for pricing, if undefined use all pools
|
|
170
|
-
limitPools?: string[],
|
|
171
|
-
|
|
172
|
-
// I don't like putting this as new params, but in order to not change interface
|
|
173
|
-
// across all integrations, done it like this
|
|
174
|
-
transferFees?: TransferFeeParams,
|
|
175
|
-
isFirstSwap?: boolean,
|
|
176
|
-
): Promise<ExchangePrices<ExchangeData> | null>;
|
|
177
|
-
|
|
178
|
-
// Returns estimated gas cost for calldata for DEX when used in multiSwap.
|
|
179
|
-
// Output type/length corresponds to that of gasCost inside the poolPrices.
|
|
180
|
-
getCalldataGasCost(poolPrices: PoolPrices<ExchangeData>): number | number[];
|
|
181
|
-
|
|
182
|
-
// Initialize pricing is called once in the start of
|
|
183
|
-
// pricing service. It is intended to setup the integration
|
|
184
|
-
// for pricing requests. It is optional for a DEX to
|
|
185
|
-
// implement this function
|
|
186
|
-
initializePricing?(blockNumber: number): AsyncOrSync<void>;
|
|
187
|
-
|
|
188
|
-
// Returns the list of contract adapters (name and index)
|
|
189
|
-
// for a buy/sell. Return null if there are no adapters.
|
|
190
|
-
getAdapters(side: SwapSide): { name: string; index: number }[] | null;
|
|
191
|
-
|
|
192
|
-
// If you have any timers or other resources that are need to be released,
|
|
193
|
-
// you must put it here
|
|
194
|
-
releaseResources?(): AsyncOrSync<void>;
|
|
195
|
-
|
|
196
|
-
// Build an event based pool with all the info to create inside
|
|
197
|
-
// a cache key name poolKey
|
|
198
|
-
addMasterPool?(poolKey: string, blockNumber: number): AsyncOrSync<boolean>;
|
|
199
|
-
// return true if the userAddress is is blacklisted from the exchange
|
|
200
|
-
// useful for RFQ system
|
|
201
|
-
isBlacklisted?(userAddress?: Address): AsyncOrSync<boolean>;
|
|
202
|
-
|
|
203
|
-
// blacklist a specific userAddress from exchange
|
|
204
|
-
setBlacklist?(userAddress?: Address): AsyncOrSync<boolean>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export interface IDexPooltracker {
|
|
208
|
-
// This is called once before getTopPoolsForToken is
|
|
209
|
-
// called for multiple tokens. This can be helpful to
|
|
210
|
-
// update common state required for calculating
|
|
211
|
-
// getTopPoolsForToken. It is optional for a DEX
|
|
212
|
-
// to implement this
|
|
213
|
-
updatePoolState?(): AsyncOrSync<void>;
|
|
214
|
-
|
|
215
|
-
// Returns list of top pools based on liquidity. Max
|
|
216
|
-
// limit pools should be returned.
|
|
217
|
-
getTopPoolsForToken(
|
|
218
|
-
tokenAddress: Address,
|
|
219
|
-
limit: number,
|
|
220
|
-
): AsyncOrSync<PoolLiquidity[]>;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Combine IDexTxBuilder, IDexPricing & IDexPooltracker in
|
|
224
|
-
// a single interface
|
|
225
|
-
export interface IDex<
|
|
226
|
-
ExchangeData,
|
|
227
|
-
DirectParam = null,
|
|
228
|
-
OptimizedExchangeData = ExchangeData,
|
|
229
|
-
> extends IDexTxBuilder<OptimizedExchangeData, DirectParam>,
|
|
230
|
-
IDexPricing<ExchangeData>,
|
|
231
|
-
IDexPooltracker {}
|
|
232
|
-
|
|
233
|
-
// Defines the static objects of the IDex class
|
|
234
|
-
export interface DexConstructor<
|
|
235
|
-
ExchangeData,
|
|
236
|
-
DirectParam = null,
|
|
237
|
-
OptimizedExchangeData = ExchangeData,
|
|
238
|
-
> {
|
|
239
|
-
new (network: Network, dexKey: string, dexHelper: IDexHelper): IDex<
|
|
240
|
-
ExchangeData,
|
|
241
|
-
DirectParam,
|
|
242
|
-
OptimizedExchangeData
|
|
243
|
-
>;
|
|
244
|
-
|
|
245
|
-
// static dexKeysWithNetwork has the list of dex keys
|
|
246
|
-
// and networks they are supported. This is useful for using
|
|
247
|
-
// same DEX implementation for multiple forks supported
|
|
248
|
-
// in different set of networks.
|
|
249
|
-
dexKeysWithNetwork?: { key: string; networks: Network[] }[];
|
|
250
|
-
|
|
251
|
-
builderDexKeysWithNetwork?(dexHelper: Config): void;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export type IRouteOptimizer<T> = (formaterRate: T) => T;
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
2
|
+
import {
|
|
3
|
+
Address,
|
|
4
|
+
SimpleExchangeParam,
|
|
5
|
+
AdapterExchangeParam,
|
|
6
|
+
DexExchangeParam,
|
|
7
|
+
TxInfo,
|
|
8
|
+
NumberAsString,
|
|
9
|
+
Token,
|
|
10
|
+
ExchangePrices,
|
|
11
|
+
PoolPrices,
|
|
12
|
+
PoolLiquidity,
|
|
13
|
+
OptimalSwapExchange,
|
|
14
|
+
ExchangeTxInfo,
|
|
15
|
+
PreprocessTransactionOptions,
|
|
16
|
+
TransferFeeParams,
|
|
17
|
+
Config,
|
|
18
|
+
} from '../types';
|
|
19
|
+
import { SwapSide, Network } from '../constants';
|
|
20
|
+
import { IDexHelper } from '../dex-helper/idex-helper';
|
|
21
|
+
|
|
22
|
+
export type Context = {
|
|
23
|
+
isGlobalSrcToken: boolean;
|
|
24
|
+
isGlobalDestToken: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
|
|
28
|
+
needWrapNative: boolean;
|
|
29
|
+
needsSequentialPreprocessing?: boolean;
|
|
30
|
+
|
|
31
|
+
// Returns the ETH fee required to swap
|
|
32
|
+
// It is optional for a DEX to implement this
|
|
33
|
+
// This is a legacy function and will be removed soon
|
|
34
|
+
getNetworkFee?(
|
|
35
|
+
srcToken: Address,
|
|
36
|
+
destToken: Address,
|
|
37
|
+
srcAmount: NumberAsString,
|
|
38
|
+
destAmount: NumberAsString,
|
|
39
|
+
data: ExchangeData,
|
|
40
|
+
side: SwapSide,
|
|
41
|
+
): NumberAsString;
|
|
42
|
+
|
|
43
|
+
// If exists, called before getAdapterParam to use async calls and receive data if needed
|
|
44
|
+
preProcessTransaction?(
|
|
45
|
+
optimalSwapExchange: OptimalSwapExchange<ExchangeData>,
|
|
46
|
+
srcToken: Token,
|
|
47
|
+
destToken: Token,
|
|
48
|
+
side: SwapSide,
|
|
49
|
+
options: PreprocessTransactionOptions,
|
|
50
|
+
): AsyncOrSync<[OptimalSwapExchange<ExchangeData>, ExchangeTxInfo]>;
|
|
51
|
+
|
|
52
|
+
// This is helper a function to support testing if preProcessTransaction is implemented
|
|
53
|
+
getTokenFromAddress?(address: Address): Token;
|
|
54
|
+
|
|
55
|
+
// Encode params required by the exchange adapter
|
|
56
|
+
// V5: Used for multiSwap, buy & megaSwap
|
|
57
|
+
// V6: NOT used, pass a placeholder
|
|
58
|
+
getAdapterParam(
|
|
59
|
+
srcToken: Address,
|
|
60
|
+
destToken: Address,
|
|
61
|
+
srcAmount: NumberAsString,
|
|
62
|
+
destAmount: NumberAsString, // required for buy case
|
|
63
|
+
data: ExchangeData,
|
|
64
|
+
side: SwapSide,
|
|
65
|
+
): AdapterExchangeParam;
|
|
66
|
+
|
|
67
|
+
// Encode call data used by simpleSwap like routers
|
|
68
|
+
// V5: Used for simpleSwap & simpleBuy
|
|
69
|
+
// V6: NOT used, don't implement
|
|
70
|
+
getSimpleParam?(
|
|
71
|
+
srcToken: Address,
|
|
72
|
+
destToken: Address,
|
|
73
|
+
srcAmount: NumberAsString,
|
|
74
|
+
destAmount: NumberAsString,
|
|
75
|
+
data: ExchangeData,
|
|
76
|
+
side: SwapSide,
|
|
77
|
+
): AsyncOrSync<SimpleExchangeParam>;
|
|
78
|
+
|
|
79
|
+
getDexParam?(
|
|
80
|
+
srcToken: Address,
|
|
81
|
+
destToken: Address,
|
|
82
|
+
srcAmount: NumberAsString,
|
|
83
|
+
destAmount: NumberAsString,
|
|
84
|
+
recipient: Address,
|
|
85
|
+
data: ExchangeData,
|
|
86
|
+
side: SwapSide,
|
|
87
|
+
context: Context,
|
|
88
|
+
executorAddress: Address,
|
|
89
|
+
): AsyncOrSync<DexExchangeParam>;
|
|
90
|
+
|
|
91
|
+
// Returns params required by direct swap method.
|
|
92
|
+
// Only Dexes which have a direct method should implement this
|
|
93
|
+
// Used if there is a possibility for direct swap (Eg. UniswapV2,
|
|
94
|
+
// 0xV2/V4, etc)
|
|
95
|
+
getDirectParam?(
|
|
96
|
+
srcToken: Address,
|
|
97
|
+
destToken: Address,
|
|
98
|
+
srcAmount: NumberAsString,
|
|
99
|
+
destAmount: NumberAsString,
|
|
100
|
+
expectedAmount: NumberAsString,
|
|
101
|
+
data: ExchangeData,
|
|
102
|
+
side: SwapSide,
|
|
103
|
+
permit: string,
|
|
104
|
+
uuid: string,
|
|
105
|
+
feePercent: NumberAsString,
|
|
106
|
+
deadline: NumberAsString,
|
|
107
|
+
partner: string,
|
|
108
|
+
beneficiary: string,
|
|
109
|
+
contractMethod?: string,
|
|
110
|
+
): TxInfo<DirectParam>;
|
|
111
|
+
|
|
112
|
+
// Same as above but for V6
|
|
113
|
+
getDirectParamV6?(
|
|
114
|
+
srcToken: Address,
|
|
115
|
+
destToken: Address,
|
|
116
|
+
fromAmount: NumberAsString,
|
|
117
|
+
toAmount: NumberAsString,
|
|
118
|
+
quotedAmount: NumberAsString,
|
|
119
|
+
data: ExchangeData,
|
|
120
|
+
side: SwapSide,
|
|
121
|
+
permit: string,
|
|
122
|
+
uuid: string,
|
|
123
|
+
partnerAndFee: string,
|
|
124
|
+
beneficiary: string,
|
|
125
|
+
blockNumber: number,
|
|
126
|
+
contractMethod?: string,
|
|
127
|
+
): TxInfo<DirectParam>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface IDexPricing<ExchangeData> {
|
|
131
|
+
readonly dexKey: string;
|
|
132
|
+
// This is true if the the DEX is simply
|
|
133
|
+
// wrapping/ unwrapping like weth, lending pools, etc
|
|
134
|
+
// or has a pool where arbitrarily large amounts has
|
|
135
|
+
// constant price.
|
|
136
|
+
readonly hasConstantPriceLargeAmounts: boolean;
|
|
137
|
+
|
|
138
|
+
// Specify if current Dex integration can handle fee on transfer tokens
|
|
139
|
+
readonly isFeeOnTransferSupported: boolean;
|
|
140
|
+
|
|
141
|
+
readonly cacheStateKey: string;
|
|
142
|
+
|
|
143
|
+
// Used to determine if current dex is state polling type or not
|
|
144
|
+
// Set to true if there are many pools polling state and there is no
|
|
145
|
+
// event base support for this Dex
|
|
146
|
+
readonly isStatePollingDex?: boolean;
|
|
147
|
+
|
|
148
|
+
// Returns list of pool identifiers that can be used
|
|
149
|
+
// for a given swap. poolIdentifiers must be unique
|
|
150
|
+
// across DEXes. It is recommended to use
|
|
151
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
152
|
+
getPoolIdentifiers(
|
|
153
|
+
srcToken: Token,
|
|
154
|
+
destToken: Token,
|
|
155
|
+
side: SwapSide,
|
|
156
|
+
blockNumber: number,
|
|
157
|
+
): Promise<string[]>;
|
|
158
|
+
|
|
159
|
+
// Returns pool prices for amounts.
|
|
160
|
+
// If limitPools is defined only pools in limitPools
|
|
161
|
+
// should be used. If limitPools is undefined then
|
|
162
|
+
// any pools can be used.
|
|
163
|
+
getPricesVolume(
|
|
164
|
+
srcToken: Token,
|
|
165
|
+
destToken: Token,
|
|
166
|
+
amounts: bigint[],
|
|
167
|
+
side: SwapSide,
|
|
168
|
+
blockNumber: number,
|
|
169
|
+
// list of pool identifiers to use for pricing, if undefined use all pools
|
|
170
|
+
limitPools?: string[],
|
|
171
|
+
|
|
172
|
+
// I don't like putting this as new params, but in order to not change interface
|
|
173
|
+
// across all integrations, done it like this
|
|
174
|
+
transferFees?: TransferFeeParams,
|
|
175
|
+
isFirstSwap?: boolean,
|
|
176
|
+
): Promise<ExchangePrices<ExchangeData> | null>;
|
|
177
|
+
|
|
178
|
+
// Returns estimated gas cost for calldata for DEX when used in multiSwap.
|
|
179
|
+
// Output type/length corresponds to that of gasCost inside the poolPrices.
|
|
180
|
+
getCalldataGasCost(poolPrices: PoolPrices<ExchangeData>): number | number[];
|
|
181
|
+
|
|
182
|
+
// Initialize pricing is called once in the start of
|
|
183
|
+
// pricing service. It is intended to setup the integration
|
|
184
|
+
// for pricing requests. It is optional for a DEX to
|
|
185
|
+
// implement this function
|
|
186
|
+
initializePricing?(blockNumber: number): AsyncOrSync<void>;
|
|
187
|
+
|
|
188
|
+
// Returns the list of contract adapters (name and index)
|
|
189
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
190
|
+
getAdapters(side: SwapSide): { name: string; index: number }[] | null;
|
|
191
|
+
|
|
192
|
+
// If you have any timers or other resources that are need to be released,
|
|
193
|
+
// you must put it here
|
|
194
|
+
releaseResources?(): AsyncOrSync<void>;
|
|
195
|
+
|
|
196
|
+
// Build an event based pool with all the info to create inside
|
|
197
|
+
// a cache key name poolKey
|
|
198
|
+
addMasterPool?(poolKey: string, blockNumber: number): AsyncOrSync<boolean>;
|
|
199
|
+
// return true if the userAddress is is blacklisted from the exchange
|
|
200
|
+
// useful for RFQ system
|
|
201
|
+
isBlacklisted?(userAddress?: Address): AsyncOrSync<boolean>;
|
|
202
|
+
|
|
203
|
+
// blacklist a specific userAddress from exchange
|
|
204
|
+
setBlacklist?(userAddress?: Address): AsyncOrSync<boolean>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface IDexPooltracker {
|
|
208
|
+
// This is called once before getTopPoolsForToken is
|
|
209
|
+
// called for multiple tokens. This can be helpful to
|
|
210
|
+
// update common state required for calculating
|
|
211
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
212
|
+
// to implement this
|
|
213
|
+
updatePoolState?(): AsyncOrSync<void>;
|
|
214
|
+
|
|
215
|
+
// Returns list of top pools based on liquidity. Max
|
|
216
|
+
// limit pools should be returned.
|
|
217
|
+
getTopPoolsForToken(
|
|
218
|
+
tokenAddress: Address,
|
|
219
|
+
limit: number,
|
|
220
|
+
): AsyncOrSync<PoolLiquidity[]>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Combine IDexTxBuilder, IDexPricing & IDexPooltracker in
|
|
224
|
+
// a single interface
|
|
225
|
+
export interface IDex<
|
|
226
|
+
ExchangeData,
|
|
227
|
+
DirectParam = null,
|
|
228
|
+
OptimizedExchangeData = ExchangeData,
|
|
229
|
+
> extends IDexTxBuilder<OptimizedExchangeData, DirectParam>,
|
|
230
|
+
IDexPricing<ExchangeData>,
|
|
231
|
+
IDexPooltracker {}
|
|
232
|
+
|
|
233
|
+
// Defines the static objects of the IDex class
|
|
234
|
+
export interface DexConstructor<
|
|
235
|
+
ExchangeData,
|
|
236
|
+
DirectParam = null,
|
|
237
|
+
OptimizedExchangeData = ExchangeData,
|
|
238
|
+
> {
|
|
239
|
+
new (network: Network, dexKey: string, dexHelper: IDexHelper): IDex<
|
|
240
|
+
ExchangeData,
|
|
241
|
+
DirectParam,
|
|
242
|
+
OptimizedExchangeData
|
|
243
|
+
>;
|
|
244
|
+
|
|
245
|
+
// static dexKeysWithNetwork has the list of dex keys
|
|
246
|
+
// and networks they are supported. This is useful for using
|
|
247
|
+
// same DEX implementation for multiple forks supported
|
|
248
|
+
// in different set of networks.
|
|
249
|
+
dexKeysWithNetwork?: { key: string; networks: Network[] }[];
|
|
250
|
+
|
|
251
|
+
builderDexKeysWithNetwork?(dexHelper: Config): void;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type IRouteOptimizer<T> = (formaterRate: T) => T;
|