@paraswap/dex-lib 2.37.8-dexalot → 2.38.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.
Files changed (196) hide show
  1. package/build/config.js +2 -4
  2. package/build/config.js.map +1 -1
  3. package/build/dex/gmx/config.js +1 -1
  4. package/build/dex/idex.d.ts +1 -1
  5. package/build/dex/index.js +0 -2
  6. package/build/dex/index.js.map +1 -1
  7. package/build/dex/uniswap-v2/config.js +22 -0
  8. package/build/dex/uniswap-v2/config.js.map +1 -1
  9. package/build/types.d.ts +0 -1
  10. package/package.json +1 -1
  11. package/src/config.ts +2 -5
  12. package/src/dex/gmx/config.ts +1 -1
  13. package/src/dex/idex.ts +0 -2
  14. package/src/dex/index.ts +0 -2
  15. package/src/dex/uniswap-v2/config.ts +23 -0
  16. package/src/types.ts +0 -1
  17. package/tests/constants-e2e.ts +2 -2
  18. package/.idea/aws.xml +0 -17
  19. package/.idea/codeStyles/Project.xml +0 -19
  20. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  21. package/.idea/misc.xml +0 -6
  22. package/.idea/modules.xml +0 -8
  23. package/.idea/paraswap-dex-lib.iml +0 -9
  24. package/.idea/vcs.xml +0 -6
  25. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  26. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  27. package/build/abi/dexalot/DexalotMainnetRFQ.json +0 -952
  28. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  29. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  30. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  31. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  32. package/build/abi/wBETH.json +0 -1527
  33. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  34. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  35. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  36. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  37. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  38. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  39. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  40. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  41. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  42. package/build/dex/balancer-v2/LinearMath.js +0 -179
  43. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  44. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  45. package/build/dex/balancer-v2/LinearPool.js +0 -324
  46. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  47. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  48. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  49. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  50. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  51. package/build/dex/balancer-v2/StableMath.js +0 -272
  52. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  53. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  54. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  55. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  56. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  57. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  58. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  59. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  60. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  61. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  62. package/build/dex/dexalot/config.d.ts +0 -4
  63. package/build/dex/dexalot/config.js +0 -18
  64. package/build/dex/dexalot/config.js.map +0 -1
  65. package/build/dex/dexalot/constants.d.ts +0 -15
  66. package/build/dex/dexalot/constants.js +0 -22
  67. package/build/dex/dexalot/constants.js.map +0 -1
  68. package/build/dex/dexalot/dexalot.d.ts +0 -69
  69. package/build/dex/dexalot/dexalot.js +0 -642
  70. package/build/dex/dexalot/dexalot.js.map +0 -1
  71. package/build/dex/dexalot/rate-fetcher.d.ts +0 -28
  72. package/build/dex/dexalot/rate-fetcher.js +0 -100
  73. package/build/dex/dexalot/rate-fetcher.js.map +0 -1
  74. package/build/dex/dexalot/types.d.ts +0 -114
  75. package/build/dex/dexalot/types.js +0 -12
  76. package/build/dex/dexalot/types.js.map +0 -1
  77. package/build/dex/dexalot/validators.d.ts +0 -5
  78. package/build/dex/dexalot/validators.js +0 -45
  79. package/build/dex/dexalot/validators.js.map +0 -1
  80. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  81. package/build/dex/pancakeswap-v3/types.js +0 -3
  82. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  83. package/build/dex/quickswap-v3.d.ts +0 -21
  84. package/build/dex/quickswap-v3.js +0 -40
  85. package/build/dex/quickswap-v3.js.map +0 -1
  86. package/build/dex/ramses-v2/config.d.ts +0 -4
  87. package/build/dex/ramses-v2/config.js +0 -28
  88. package/build/dex/ramses-v2/config.js.map +0 -1
  89. package/build/dex/ramses-v2/constants.d.ts +0 -28
  90. package/build/dex/ramses-v2/constants.js +0 -35
  91. package/build/dex/ramses-v2/constants.js.map +0 -1
  92. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  93. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  94. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  95. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  96. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  97. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  98. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  99. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  100. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  101. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  102. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  103. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  104. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  105. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  106. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  107. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  108. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  109. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  110. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  111. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  112. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  113. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  114. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  115. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  116. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  117. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  118. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  119. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  120. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  121. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  122. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  123. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  124. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  125. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  126. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  127. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  128. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  129. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  130. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  131. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  132. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  133. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  134. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  135. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  136. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  137. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  138. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  139. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  140. package/build/dex/ramses-v2/types.d.ts +0 -154
  141. package/build/dex/ramses-v2/types.js +0 -9
  142. package/build/dex/ramses-v2/types.js.map +0 -1
  143. package/build/dex/ramses-v2/utils.d.ts +0 -6
  144. package/build/dex/ramses-v2/utils.js +0 -71
  145. package/build/dex/ramses-v2/utils.js.map +0 -1
  146. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  147. package/build/dex/sushiswap-v3/config.js +0 -132
  148. package/build/dex/sushiswap-v3/config.js.map +0 -1
  149. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  150. package/build/dex/sushiswap-v3/constants.js +0 -32
  151. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  152. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  153. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  154. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  155. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  156. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  157. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  158. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  159. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  160. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  161. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  162. package/build/dex/sushiswap-v3/token.js +0 -23
  163. package/build/dex/sushiswap-v3/token.js.map +0 -1
  164. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  165. package/build/dex/sushiswap-v3/types.js +0 -18
  166. package/build/dex/sushiswap-v3/types.js.map +0 -1
  167. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  168. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  169. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  170. package/build/dex/woo-fi/config.d.ts +0 -4
  171. package/build/dex/woo-fi/config.js +0 -141
  172. package/build/dex/woo-fi/config.js.map +0 -1
  173. package/build/dex/woo-fi/constants.d.ts +0 -5
  174. package/build/dex/woo-fi/constants.js +0 -20
  175. package/build/dex/woo-fi/constants.js.map +0 -1
  176. package/build/dex/woo-fi/types.d.ts +0 -48
  177. package/build/dex/woo-fi/types.js +0 -3
  178. package/build/dex/woo-fi/types.js.map +0 -1
  179. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  180. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  181. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  182. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  183. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  184. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  185. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  186. package/build/dex/woo-fi/woo-fi.js +0 -480
  187. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  188. package/src/abi/dexalot/DexalotMainnetRFQ.json +0 -952
  189. package/src/dex/dexalot/config.ts +0 -18
  190. package/src/dex/dexalot/constants.ts +0 -29
  191. package/src/dex/dexalot/dexalot-e2e.test.ts +0 -192
  192. package/src/dex/dexalot/dexalot-integration.test.ts +0 -188
  193. package/src/dex/dexalot/dexalot.ts +0 -998
  194. package/src/dex/dexalot/rate-fetcher.ts +0 -197
  195. package/src/dex/dexalot/types.ts +0 -131
  196. package/src/dex/dexalot/validators.ts +0 -46
@@ -1,998 +0,0 @@
1
- import {
2
- Token,
3
- Address,
4
- ExchangePrices,
5
- PoolPrices,
6
- AdapterExchangeParam,
7
- SimpleExchangeParam,
8
- PoolLiquidity,
9
- Logger,
10
- ExchangeTxInfo,
11
- OptimalSwapExchange,
12
- PreprocessTransactionOptions, TransferFeeParams,
13
- } from '../../types';
14
- import {
15
- SwapSide,
16
- Network,
17
- ETHER_ADDRESS,
18
- NULL_ADDRESS,
19
- } from '../../constants';
20
- import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
21
- import { getDexKeysWithNetwork, isAxiosError } from '../../utils';
22
- import { IDex } from '../idex';
23
- import { IDexHelper } from '../../dex-helper/idex-helper';
24
- import {
25
- ClobSide,
26
- DexalotData,
27
- PairData,
28
- PairDataMap,
29
- PriceDataMap,
30
- DexalotRfqError,
31
- DexalotAPIParameters,
32
- RFQResponse,
33
- RFQResponseError,
34
- TokenAddrDataMap,
35
- TokenDataMap,
36
- } from './types';
37
- import { SlippageCheckError, TooStrictSlippageCheckError } from '../generic-rfq/types';
38
- import { SimpleExchange } from '../simple-exchange';
39
- import { Adapters, DexalotConfig } from './config';
40
- import { RateFetcher } from './rate-fetcher';
41
- import mainnetRFQAbi from '../../abi/dexalot/DexalotMainnetRFQ.json';
42
- import { Interface } from 'ethers/lib/utils';
43
- import { assert } from 'ts-essentials';
44
- import {
45
- DEXALOT_API_URL,
46
- DEXALOT_API_PRICES_POLLING_INTERVAL_MS,
47
- DEXALOT_PRICES_CACHES_TTL_S,
48
- DEXALOT_GAS_COST,
49
- DEXALOT_PAIRS_CACHES_TTL_S,
50
- DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
51
- DEXALOT_TOKENS_CACHES_TTL_S,
52
- DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
53
- DEXALOT_RATE_LIMITED_TTL_S,
54
- DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION,
55
- DEXALOT_RESTRICTED_CACHE_KEY,
56
- DEXALOT_RESTRICT_TTL_S,
57
- DEXALOT_RATELIMIT_CACHE_VALUE,
58
- DEXALOT_BLACKLIST_CACHES_TTL_S,
59
- } from './constants';
60
- import { BI_MAX_UINT256 } from '../../bigint-constants';
61
- import { ethers } from 'ethers';
62
- import BigNumber from 'bignumber.js';
63
- import { Method } from '../../dex-helper/irequest-wrapper';
64
-
65
- export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
66
- readonly isStatePollingDex = true;
67
- readonly hasConstantPriceLargeAmounts = false;
68
- readonly needWrapNative = false;
69
- readonly isFeeOnTransferSupported = false;
70
- private rateFetcher: RateFetcher;
71
-
72
- private dexalotAuthToken: string;
73
-
74
- private pricesCacheKey: string;
75
- private pairsCacheKey: string;
76
- private tokensAddrCacheKey: string;
77
- private tokensCacheKey: string;
78
- private blacklistCacheKey: string;
79
- private tokensMap: TokenDataMap = {};
80
-
81
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
82
- getDexKeysWithNetwork(DexalotConfig);
83
-
84
- logger: Logger;
85
-
86
- constructor(
87
- readonly network: Network,
88
- readonly dexKey: string,
89
- readonly dexHelper: IDexHelper,
90
- protected adapters = Adapters[network] || {},
91
- readonly mainnetRFQAddress: string = DexalotConfig['Dexalot'][network]
92
- .mainnetRFQAddress,
93
- protected rfqInterface = new Interface(mainnetRFQAbi),
94
- ) {
95
- super(dexHelper, dexKey);
96
- this.logger = dexHelper.getLogger(dexKey);
97
-
98
- const authToken = dexHelper.config.data.dexalotAuthToken;
99
- assert(
100
- authToken !== undefined,
101
- 'Dexalot auth token is not specified with env variable',
102
- );
103
- this.dexalotAuthToken = authToken;
104
-
105
- this.pricesCacheKey = 'prices';
106
- this.pairsCacheKey = 'pairs';
107
- this.tokensAddrCacheKey = 'tokens_addr';
108
- this.tokensCacheKey = 'tokens';
109
- this.blacklistCacheKey = 'blacklist';
110
-
111
- this.rateFetcher = new RateFetcher(
112
- this.dexHelper,
113
- this.dexKey,
114
- this.network,
115
- this.logger,
116
- {
117
- rateConfig: {
118
- pairsIntervalMs: DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
119
- pricesIntervalMs: DEXALOT_API_PRICES_POLLING_INTERVAL_MS,
120
- blacklistIntervalMs: DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
121
- pairsReqParams: this.getAPIReqParams('api/rfq/pairs', 'GET'),
122
- pricesReqParams: this.getAPIReqParams('api/rfq/prices', 'GET'),
123
- blacklistReqParams: this.getAPIReqParams('api/rfq/blacklist', 'GET'),
124
- pairsCacheKey: this.pairsCacheKey,
125
- pairsCacheTTLSecs: DEXALOT_PAIRS_CACHES_TTL_S,
126
- pricesCacheKey: this.pricesCacheKey,
127
- pricesCacheTTLSecs: DEXALOT_PRICES_CACHES_TTL_S,
128
- tokensAddrCacheKey: this.tokensAddrCacheKey,
129
- tokensCacheKey: this.tokensCacheKey,
130
- tokensCacheTTLSecs: DEXALOT_TOKENS_CACHES_TTL_S,
131
- blacklistCacheKey: this.blacklistCacheKey,
132
- blacklistCacheTTLSecs: DEXALOT_BLACKLIST_CACHES_TTL_S,
133
- },
134
- },
135
- );
136
- }
137
-
138
- async initializePricing(blockNumber: number): Promise<void> {
139
- if (!this.dexHelper.config.isSlave) {
140
- this.rateFetcher.start();
141
- }
142
-
143
- return;
144
- }
145
-
146
- getAdapters(side: SwapSide): { name: string; index: number }[] | null {
147
- return this.adapters[side] ? this.adapters[side] : null;
148
- }
149
-
150
- getPairString(baseToken: Token, quoteToken: Token): string {
151
- return `${baseToken.symbol}/${quoteToken.symbol}`.toLowerCase();
152
- }
153
-
154
- async getPairData(
155
- srcToken: Token,
156
- destToken: Token,
157
- ): Promise<PairData | null> {
158
- const normalizedSrcToken = this.normalizeToken(srcToken);
159
- const normalizedDestToken = this.normalizeToken(destToken);
160
- if (normalizedSrcToken.address === normalizedDestToken.address) {
161
- return null;
162
- }
163
-
164
- const cachedTokens = (await this.getCachedTokens()) || {};
165
- if (
166
- !(normalizedSrcToken.address in cachedTokens) ||
167
- !(normalizedDestToken.address in cachedTokens)
168
- ) {
169
- return null;
170
- }
171
- normalizedSrcToken.symbol = cachedTokens[normalizedSrcToken.address].symbol;
172
- normalizedDestToken.symbol =
173
- cachedTokens[normalizedDestToken.address].symbol;
174
-
175
- const cachedPairs = (await this.getCachedPairs()) || {};
176
-
177
- const potentialPairs = [
178
- {
179
- identifier: this.getPairString(normalizedSrcToken, normalizedDestToken),
180
- isSrcBase: true,
181
- },
182
- {
183
- identifier: this.getPairString(normalizedDestToken, normalizedSrcToken),
184
- isSrcBase: false,
185
- },
186
- ];
187
-
188
- for (const pair of potentialPairs) {
189
- if (pair.identifier in cachedPairs) {
190
- const pairData = cachedPairs[pair.identifier];
191
- pairData.isSrcBase = pair.isSrcBase;
192
- return pairData;
193
- }
194
- }
195
- return null;
196
- }
197
-
198
- getIdentifier(srcAddress: Address, destAddress: Address) {
199
- const sortedAddresses =
200
- srcAddress < destAddress
201
- ? [srcAddress, destAddress]
202
- : [destAddress, srcAddress];
203
-
204
- return `${this.dexKey}_${sortedAddresses[0].toLowerCase()}_${sortedAddresses[1].toLowerCase()}`;
205
- }
206
-
207
- async getPoolIdentifiers(
208
- srcToken: Token,
209
- destToken: Token,
210
- side: SwapSide,
211
- blockNumber: number,
212
- ): Promise<string[]> {
213
- if (!srcToken || !destToken) {
214
- return [];
215
- }
216
- const pairData = await this.getPairData(srcToken, destToken);
217
- if (!pairData) {
218
- return [];
219
- }
220
-
221
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
222
-
223
- return [this.getIdentifier(
224
- tokensAddr[pairData.base.toLowerCase()],
225
- tokensAddr[pairData.quote.toLowerCase()],
226
- )];
227
- }
228
-
229
- async getCachedPairs(): Promise<PairDataMap | null> {
230
- const cachedPairs = await this.dexHelper.cache.get(
231
- this.dexKey,
232
- this.network,
233
- this.pairsCacheKey,
234
- );
235
-
236
- if (cachedPairs) {
237
- return JSON.parse(cachedPairs) as PairDataMap;
238
- }
239
-
240
- return null;
241
- }
242
-
243
- async getCachedPrices(): Promise<PriceDataMap | null> {
244
- const cachedPrices = await this.dexHelper.cache.get(
245
- this.dexKey,
246
- this.network,
247
- this.pricesCacheKey,
248
- );
249
-
250
- if (cachedPrices) {
251
- return JSON.parse(cachedPrices) as PriceDataMap;
252
- }
253
-
254
- return null;
255
- }
256
-
257
- async getCachedTokensAddr(): Promise<TokenAddrDataMap | null> {
258
- const cachedTokensAddr = await this.dexHelper.cache.get(
259
- this.dexKey,
260
- this.network,
261
- this.tokensAddrCacheKey,
262
- );
263
-
264
- if (cachedTokensAddr) {
265
- return JSON.parse(cachedTokensAddr) as TokenAddrDataMap;
266
- }
267
-
268
- return null;
269
- }
270
-
271
- async getCachedTokens(): Promise<TokenDataMap | null> {
272
- const cachedTokens = await this.dexHelper.cache.get(
273
- this.dexKey,
274
- this.network,
275
- this.tokensCacheKey,
276
- );
277
-
278
- if (cachedTokens) {
279
- return JSON.parse(cachedTokens) as TokenDataMap;
280
- }
281
-
282
- return null;
283
- }
284
-
285
- normalizeAddress(address: string): string {
286
- return address.toLowerCase() === ETHER_ADDRESS
287
- ? NULL_ADDRESS
288
- : address.toLowerCase();
289
- }
290
-
291
- denormalizeAddress(address: string): string {
292
- return address.toLowerCase() === NULL_ADDRESS
293
- ? ETHER_ADDRESS
294
- : address.toLowerCase();
295
- }
296
-
297
- // Dexalot protocol for native token expects 0x00000... instead of 0xeeeee...
298
- normalizeToken(token: Token): Token {
299
- return {
300
- address: this.normalizeAddress(token.address),
301
- decimals: token.decimals,
302
- };
303
- }
304
-
305
- denormalizeToken(token: Token): Token {
306
- return {
307
- address: this.denormalizeAddress(token.address),
308
- decimals: token.decimals,
309
- };
310
- }
311
-
312
- calculateOrderPrice(
313
- amounts: bigint[],
314
- orderbook: string[][],
315
- baseToken: Token,
316
- quoteToken: Token,
317
- side: ClobSide,
318
- ) {
319
- let result = [];
320
-
321
- for (let i = 0; i < amounts.length; i++) {
322
- let amt = amounts[i];
323
- if (amt === 0n) {
324
- result.push(amt);
325
- continue;
326
- }
327
-
328
- let left = 0,
329
- right = orderbook.length;
330
- let qty = BigInt(0);
331
-
332
- while (left < right) {
333
- let mid = Math.floor((left + right) / 2);
334
- qty = BigInt(
335
- ethers.utils
336
- .parseUnits(orderbook[mid][1], quoteToken.decimals)
337
- .toString(),
338
- );
339
- if (side === ClobSide.ASK) {
340
- const price = BigInt(
341
- ethers.utils
342
- .parseUnits(orderbook[mid][0], baseToken.decimals)
343
- .toString(),
344
- );
345
- qty =
346
- (qty * BigInt(10 ** (baseToken.decimals * 2))) /
347
- (price * BigInt(10 ** quoteToken.decimals));
348
- }
349
- if (qty <= amt) {
350
- left = mid + 1;
351
- } else {
352
- right = mid;
353
- }
354
- }
355
-
356
- let price,
357
- amount = BigInt(0);
358
- if (left === orderbook.length) {
359
- price = BigInt(
360
- ethers.utils
361
- .parseUnits(orderbook[left - 1][0], baseToken.decimals)
362
- .toString(),
363
- );
364
- amount = qty;
365
- } else if (amounts[i] === qty) {
366
- price = BigInt(
367
- ethers.utils
368
- .parseUnits(orderbook[left][0], baseToken.decimals)
369
- .toString(),
370
- );
371
- amount = amounts[i];
372
- } else {
373
- const lPrice = BigInt(
374
- ethers.utils
375
- .parseUnits(orderbook[left][0], baseToken.decimals)
376
- .toString(),
377
- );
378
- const rPrice = BigInt(
379
- ethers.utils
380
- .parseUnits(orderbook[left + 1][0], baseToken.decimals)
381
- .toString(),
382
- );
383
- const lQty = qty;
384
- let rQty = BigInt(
385
- ethers.utils
386
- .parseUnits(orderbook[left + 1][1], quoteToken.decimals)
387
- .toString(),
388
- );
389
- if (side === ClobSide.ASK) {
390
- rQty = (rQty * rPrice) / BigInt(10 ** quoteToken.decimals);
391
- }
392
- price = lPrice + ((rPrice - lPrice) * (amt - lQty)) / (rQty - lQty);
393
- amount = amounts[i];
394
- }
395
-
396
- if (side === ClobSide.BID) {
397
- result.push(
398
- (amount * BigInt(10 ** (baseToken.decimals * 2))) /
399
- (price * BigInt(10 ** quoteToken.decimals)),
400
- );
401
- } else {
402
- result.push(
403
- (price * amount * BigInt(10 ** quoteToken.decimals)) /
404
- BigInt(10 ** (baseToken.decimals * 2)),
405
- );
406
- }
407
- }
408
- return result;
409
- }
410
-
411
- async getPricesVolume(
412
- srcToken: Token,
413
- destToken: Token,
414
- amounts: bigint[],
415
- side: SwapSide,
416
- blockNumber: number,
417
- limitPools?: string[],
418
- transferFees?: TransferFeeParams,
419
- ): Promise<null | ExchangePrices<DexalotData>> {
420
- try {
421
- if (await this.isRestricted()) {
422
- return null;
423
- }
424
-
425
- const normalizedSrcToken = this.normalizeToken(srcToken);
426
- const normalizedDestToken = this.normalizeToken(destToken);
427
-
428
- this.tokensMap = (await this.getCachedTokens()) || {};
429
- if (normalizedSrcToken.address === normalizedDestToken.address) {
430
- return null;
431
- }
432
-
433
- const pools = limitPools
434
- ? limitPools.filter(
435
- p =>
436
- p ===
437
- this.getIdentifier(
438
- normalizedSrcToken.address,
439
- normalizedDestToken.address,
440
- ),
441
- )
442
- : await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
443
-
444
- if (pools.length === 0) {
445
- return null;
446
- }
447
-
448
- const pairData = await this.getPairData(
449
- normalizedSrcToken,
450
- normalizedDestToken,
451
- );
452
- if (!pairData) {
453
- return null;
454
- }
455
-
456
- const priceMap = await this.getCachedPrices();
457
- if (!priceMap) {
458
- return null;
459
- }
460
-
461
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
462
- const pairKey = `${pairData.base}/${pairData.quote}`.toLowerCase();
463
- if (
464
- !(pairKey in priceMap)
465
- || !pools.includes(this.getIdentifier(
466
- tokensAddr[pairData.base.toLowerCase()],
467
- tokensAddr[pairData.quote.toLowerCase()],
468
- ))
469
- ) {
470
- return null;
471
- }
472
-
473
- const priceData = priceMap[pairKey];
474
- const baseToken = pairData.isSrcBase
475
- ? normalizedSrcToken
476
- : normalizedDestToken;
477
- const quoteToken = pairData.isSrcBase
478
- ? normalizedDestToken
479
- : normalizedSrcToken;
480
-
481
- // convert from swap to clob side
482
- let orderbook = priceData.asks;
483
- let clobSide = ClobSide.BID;
484
- if (
485
- (side === SwapSide.SELL && pairData.isSrcBase) ||
486
- (side === SwapSide.BUY && !pairData.isSrcBase)
487
- ) {
488
- orderbook = priceData.bids;
489
- clobSide = ClobSide.ASK;
490
- }
491
- if (orderbook.length === 0) {
492
- throw new Error(`Empty orderbook for ${pairKey}`);
493
- }
494
-
495
- const prices = this.calculateOrderPrice(
496
- amounts,
497
- orderbook,
498
- baseToken,
499
- quoteToken,
500
- clobSide,
501
- );
502
- const outDecimals =
503
- clobSide === ClobSide.BID ? baseToken.decimals : quoteToken.decimals;
504
- const poolIdentifier = this.getIdentifier(pairData.base, pairData.quote);
505
-
506
- return [
507
- {
508
- prices,
509
- unit: BigInt(outDecimals),
510
- data: {},
511
- poolIdentifier: poolIdentifier,
512
- exchange: this.dexKey,
513
- gasCost: DEXALOT_GAS_COST,
514
- poolAddresses: [this.mainnetRFQAddress],
515
- },
516
- ];
517
- } catch (e: unknown) {
518
- this.logger.error(
519
- `Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${
520
- destToken.address || destToken.symbol
521
- }, ${side}:`,
522
- e,
523
- );
524
- return null;
525
- }
526
- }
527
-
528
- generateRFQError(errorStr: string, swapIdentifier: string) {
529
- const message = `${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}. ${errorStr}`;
530
- this.logger.warn(message);
531
- throw new DexalotRfqError(message);
532
- }
533
-
534
- async preProcessTransaction(
535
- optimalSwapExchange: OptimalSwapExchange<DexalotData>,
536
- srcToken: Token,
537
- destToken: Token,
538
- side: SwapSide,
539
- options: PreprocessTransactionOptions,
540
- ): Promise<[OptimalSwapExchange<DexalotData>, ExchangeTxInfo]> {
541
- if (await this.isBlacklisted(options.txOrigin)) {
542
- this.logger.warn(
543
- `${this.dexKey}-${this.network}: blacklisted TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`,
544
- );
545
- throw new Error(
546
- `${this.dexKey}-${
547
- this.network
548
- }: user=${options.txOrigin.toLowerCase()} is blacklisted`,
549
- );
550
- }
551
-
552
- if (BigInt(optimalSwapExchange.srcAmount) === 0n) {
553
- throw new Error('getFirmRate failed with srcAmount === 0');
554
- }
555
-
556
- const normalizedSrcToken = this.normalizeToken(srcToken);
557
- const normalizedDestToken = this.normalizeToken(destToken);
558
- const swapIdentifier = `${this.getIdentifier(
559
- normalizedSrcToken.address,
560
- normalizedDestToken.address,
561
- )}_${side}`;
562
-
563
- try {
564
- const makerToken = normalizedDestToken;
565
- const takerToken = normalizedSrcToken;
566
-
567
- const rfqParams = {
568
- makerAsset: ethers.utils.getAddress(makerToken.address),
569
- takerAsset: ethers.utils.getAddress(takerToken.address),
570
- makerAmount:
571
- side === SwapSide.BUY ? optimalSwapExchange.destAmount : undefined,
572
- takerAmount:
573
- side === SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
574
- userAddress: options.txOrigin,
575
- chainid: this.network,
576
- };
577
-
578
- const rfq: RFQResponse = await this.dexHelper.httpRequest.post(
579
- `${DEXALOT_API_URL}/api/rfq/firm`,
580
- rfqParams,
581
- undefined,
582
- { 'x-apikey': this.dexalotAuthToken },
583
- );
584
- if (!rfq) {
585
- this.generateRFQError(
586
- 'Missing quote data',
587
- `RFQ ${swapIdentifier} ${JSON.stringify(rfq)}`,
588
- );
589
- } else if (!rfq.signature) {
590
- this.generateRFQError('Missing signature', swapIdentifier);
591
- }
592
- rfq.order.signature = rfq.signature;
593
-
594
- const { order } = rfq;
595
-
596
- assert(
597
- order.makerAsset.toLowerCase() === makerToken.address,
598
- `QuoteData makerAsset=${order.makerAsset} is different from Paraswap makerAsset=${makerToken.address}`,
599
- );
600
- assert(
601
- order.takerAsset.toLowerCase() === takerToken.address,
602
- `QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`,
603
- );
604
- if (side === SwapSide.SELL) {
605
- assert(
606
- order.takerAmount === optimalSwapExchange.srcAmount,
607
- `QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`,
608
- );
609
- } else {
610
- assert(
611
- order.makerAmount === optimalSwapExchange.destAmount,
612
- `QuoteData makerAmount=${order.makerAmount} is different from Paraswap destAmount=${optimalSwapExchange.destAmount}`,
613
- );
614
- }
615
-
616
- const expiryAsBigInt = BigInt(order.expiry);
617
- const minDeadline = expiryAsBigInt > 0 ? expiryAsBigInt : BI_MAX_UINT256;
618
-
619
- const slippageFactor = options.slippageFactor;
620
- let isFailOnSlippage = false;
621
- let slippageErrorMessage = '';
622
-
623
- if (side === SwapSide.SELL) {
624
- if (
625
- BigInt(order.makerAmount) <
626
- BigInt(
627
- new BigNumber(optimalSwapExchange.destAmount.toString())
628
- .times(slippageFactor)
629
- .toFixed(0),
630
- )
631
- ) {
632
- isFailOnSlippage = true;
633
- const message = `${this.dexKey}-${this.network}: too much slippage on quote ${side} quoteTokenAmount ${order.makerAmount} / destAmount ${optimalSwapExchange.destAmount} < ${slippageFactor}`;
634
- slippageErrorMessage = message;
635
- this.logger.warn(message);
636
- }
637
- } else {
638
- if (
639
- BigInt(order.takerAmount) >
640
- BigInt(slippageFactor.times(optimalSwapExchange.srcAmount.toString()).toFixed(0))
641
- ) {
642
- isFailOnSlippage = true;
643
- const message = `${this.dexKey}-${
644
- this.network
645
- }: too much slippage on quote ${side} baseTokenAmount ${order.takerAmount} / srcAmount ${optimalSwapExchange.srcAmount} > ${slippageFactor.toFixed()}`;
646
- slippageErrorMessage = message;
647
- this.logger.warn(message);
648
- }
649
- }
650
-
651
- let isTooStrictSlippage = false;
652
- if (
653
- isFailOnSlippage &&
654
- side === SwapSide.SELL &&
655
- new BigNumber(1)
656
- .minus(slippageFactor)
657
- .lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
658
- ) {
659
- isTooStrictSlippage = true;
660
- } else if (
661
- isFailOnSlippage &&
662
- side === SwapSide.BUY &&
663
- slippageFactor
664
- .minus(1)
665
- .lt(DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)
666
- ) {
667
- isTooStrictSlippage = true;
668
- }
669
-
670
- if (isFailOnSlippage && isTooStrictSlippage) {
671
- throw new TooStrictSlippageCheckError(slippageErrorMessage);
672
- } else if (isFailOnSlippage && !isTooStrictSlippage) {
673
- throw new SlippageCheckError(slippageErrorMessage);
674
- }
675
-
676
- return [
677
- {
678
- ...optimalSwapExchange,
679
- data: {
680
- quoteData: order,
681
- },
682
- },
683
- { deadline: minDeadline },
684
- ];
685
- } catch (e) {
686
- if (isAxiosError(e) && e.response && e.response.data) {
687
- const errorData: RFQResponseError = e.response.data;
688
- if (errorData.ReasonCode === 'FQ-009') {
689
- this.logger.warn(
690
- `${this.dexKey}-${this.network}: Encountered rate limited user=${options.txOrigin}. Adding to local rate limit cache`,
691
- );
692
- await this.setRateLimited(options.txOrigin, errorData.RetryAfter);
693
- } else {
694
- await this.setBlacklist(options.txOrigin);
695
- this.logger.error(
696
- `${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}: ${errorData.Reason}`,
697
- );
698
- }
699
- } else {
700
- if(e instanceof TooStrictSlippageCheckError) {
701
- this.logger.warn(
702
- `${this.dexKey}-${this.network}: failed to build transaction on side ${side} with too strict slippage. Skipping restriction`,
703
- );
704
- } else {
705
- this.logger.warn(
706
- `${this.dexKey}-${this.network}: protocol is restricted`,
707
- );
708
- await this.restrict();
709
- }
710
- }
711
-
712
- throw e;
713
- }
714
- }
715
-
716
- getCalldataGasCost(poolPrices: PoolPrices<DexalotData>): number | number[] {
717
- return (
718
- CALLDATA_GAS_COST.DEX_OVERHEAD +
719
- // addresses: makerAsset, takerAsset, maker, taker
720
- CALLDATA_GAS_COST.ADDRESS * 4 +
721
- // uint256: expiry
722
- CALLDATA_GAS_COST.wordNonZeroBytes(16) +
723
- // uint256: nonceAndMeta, makerAmount, takerAmount
724
- CALLDATA_GAS_COST.AMOUNT * 3 +
725
- // bytes: _signature (65 bytes)
726
- CALLDATA_GAS_COST.FULL_WORD * 2 +
727
- CALLDATA_GAS_COST.OFFSET_SMALL
728
- );
729
- }
730
-
731
- getTokenFromAddress(address: Address): Token {
732
- return this.tokensMap[this.normalizeAddress(address)];
733
- }
734
-
735
- getAdapterParam(
736
- srcToken: string,
737
- destToken: string,
738
- srcAmount: string,
739
- destAmount: string,
740
- data: DexalotData,
741
- side: SwapSide,
742
- ): AdapterExchangeParam {
743
- const { quoteData } = data;
744
-
745
- assert(
746
- quoteData !== undefined,
747
- `${this.dexKey}-${this.network}: quoteData undefined`,
748
- );
749
-
750
- const params = [
751
- {
752
- nonceAndMeta: quoteData.nonceAndMeta,
753
- expiry: quoteData.expiry,
754
- makerAsset: quoteData.makerAsset,
755
- takerAsset: quoteData.takerAsset,
756
- maker: quoteData.maker,
757
- taker: quoteData.taker,
758
- makerAmount: quoteData.makerAmount,
759
- takerAmount: quoteData.takerAmount,
760
- },
761
- quoteData.signature,
762
- ];
763
-
764
- const payload = this.abiCoder.encodeParameter(
765
- {
766
- ParentStruct: {
767
- order: {
768
- nonceAndMeta: 'uint256',
769
- expiry: 'uint128',
770
- makerAsset: 'address',
771
- takerAsset: 'address',
772
- maker: 'address',
773
- taker: 'address',
774
- makerAmount: 'uint256',
775
- takerAmount: 'uint256',
776
- },
777
- signature: 'bytes',
778
- },
779
- },
780
- {
781
- order: params[0],
782
- signature: params[1],
783
- },
784
- );
785
-
786
- return {
787
- targetExchange: this.mainnetRFQAddress,
788
- payload,
789
- networkFee: '0',
790
- };
791
- }
792
-
793
- async restrict(ttl: number = DEXALOT_RESTRICT_TTL_S): Promise<boolean> {
794
- await this.dexHelper.cache.setex(
795
- this.dexKey,
796
- this.network,
797
- DEXALOT_RESTRICTED_CACHE_KEY,
798
- ttl,
799
- 'true',
800
- );
801
- return true;
802
- }
803
-
804
- async isRestricted(): Promise<boolean> {
805
- const result = await this.dexHelper.cache.get(
806
- this.dexKey,
807
- this.network,
808
- DEXALOT_RESTRICTED_CACHE_KEY,
809
- );
810
-
811
- return result === 'true';
812
- }
813
-
814
- async setBlacklist(txOrigin: Address, ttl: number = DEXALOT_BLACKLIST_CACHES_TTL_S,): Promise<boolean> {
815
- const cachedBlacklist = await this.dexHelper.cache.get(
816
- this.dexKey,
817
- this.network,
818
- this.blacklistCacheKey,
819
- );
820
-
821
- let blacklist: string[] = [];
822
- if (cachedBlacklist) {
823
- blacklist = JSON.parse(cachedBlacklist);
824
- }
825
-
826
- blacklist.push(txOrigin.toLowerCase());
827
-
828
- this.dexHelper.cache.setex(
829
- this.dexKey,
830
- this.network,
831
- this.blacklistCacheKey,
832
- ttl,
833
- JSON.stringify(blacklist),
834
- );
835
-
836
- return true;
837
- }
838
-
839
- async isBlacklisted(txOrigin: Address): Promise<boolean> {
840
- const cachedBlacklist = await this.dexHelper.cache.get(
841
- this.dexKey,
842
- this.network,
843
- this.blacklistCacheKey,
844
- );
845
-
846
- if (cachedBlacklist) {
847
- const blacklist = JSON.parse(cachedBlacklist) as string[];
848
- return blacklist.includes(txOrigin.toLowerCase());
849
- }
850
-
851
- // To not show pricing for rate limited users
852
- if(await this.isRateLimited(txOrigin)) {
853
- return true;
854
- }
855
-
856
- return false;
857
- }
858
-
859
- getRateLimitedKey(address: Address) {
860
- return `rate_limited_${address}`.toLowerCase();
861
- }
862
-
863
- async isRateLimited(txOrigin: Address): Promise<boolean> {
864
- const result = await this.dexHelper.cache.get(
865
- this.dexKey,
866
- this.network,
867
- this.getRateLimitedKey(txOrigin),
868
- );
869
- return result === DEXALOT_RATELIMIT_CACHE_VALUE;
870
- }
871
-
872
- async setRateLimited(txOrigin: Address, ttl = DEXALOT_RATE_LIMITED_TTL_S) {
873
- await this.dexHelper.cache.setex(
874
- this.dexKey,
875
- this.network,
876
- this.getRateLimitedKey(txOrigin),
877
- ttl,
878
- DEXALOT_RATELIMIT_CACHE_VALUE,
879
- );
880
- return true;
881
- }
882
-
883
- async getSimpleParam(
884
- srcToken: string,
885
- destToken: string,
886
- srcAmount: string,
887
- destAmount: string,
888
- data: DexalotData,
889
- side: SwapSide,
890
- ): Promise<SimpleExchangeParam> {
891
- const { quoteData } = data;
892
-
893
- assert(
894
- quoteData !== undefined,
895
- `${this.dexKey}-${this.network}: quoteData undefined`,
896
- );
897
-
898
- const swapFunction = 'simpleSwap';
899
- const swapFunctionParams = [
900
- [
901
- quoteData.nonceAndMeta,
902
- quoteData.expiry,
903
- quoteData.makerAsset,
904
- quoteData.takerAsset,
905
- quoteData.maker,
906
- quoteData.taker,
907
- quoteData.makerAmount,
908
- quoteData.takerAmount,
909
- ],
910
- quoteData.signature,
911
- ];
912
-
913
- const swapData = this.rfqInterface.encodeFunctionData(
914
- swapFunction,
915
- swapFunctionParams,
916
- );
917
-
918
- return this.buildSimpleParamWithoutWETHConversion(
919
- srcToken,
920
- srcAmount,
921
- destToken,
922
- destAmount,
923
- swapData,
924
- this.mainnetRFQAddress,
925
- );
926
- }
927
-
928
- async getTopPoolsForToken(
929
- tokenAddress: Address,
930
- limit: number,
931
- ): Promise<PoolLiquidity[]> {
932
- const normalizedTokenAddress = this.normalizeAddress(tokenAddress);
933
- const pairs = (await this.getCachedPairs()) || {};
934
- this.tokensMap = (await this.getCachedTokens()) || {};
935
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
936
- const token = this.getTokenFromAddress(normalizedTokenAddress);
937
- if (!token) {
938
- return [];
939
- }
940
-
941
- const tokenSymbol = token.symbol?.toLowerCase() || '';
942
-
943
- let pairsByLiquidity = [];
944
- for (const pairName of Object.keys(pairs)) {
945
- if (!pairName.includes(tokenSymbol)) {
946
- continue;
947
- }
948
-
949
- const tokensInPair = pairName.split('/');
950
- if (tokensInPair.length !== 2) {
951
- continue;
952
- }
953
-
954
- const [ baseToken, quoteToken ] = tokensInPair;
955
- const addr = tokensAddr[baseToken.toLowerCase()];
956
- let outputToken = this.getTokenFromAddress(addr);
957
- if (baseToken === tokenSymbol) {
958
- const addr = tokensAddr[quoteToken.toLowerCase()];
959
- outputToken = this.getTokenFromAddress(addr);
960
- }
961
-
962
- const denormalizedToken = this.denormalizeToken(outputToken);
963
-
964
- pairsByLiquidity.push({
965
- exchange: this.dexKey,
966
- address: this.mainnetRFQAddress,
967
- connectorTokens: [{
968
- address: denormalizedToken.address,
969
- decimals: denormalizedToken.decimals,
970
- }],
971
- liquidityUSD: pairs[pairName].liquidityUSD,
972
- });
973
- }
974
-
975
- pairsByLiquidity.sort(
976
- (a: PoolLiquidity, b: PoolLiquidity) => b.liquidityUSD - a.liquidityUSD,
977
- );
978
-
979
- return pairsByLiquidity.slice(0, limit);
980
- }
981
-
982
- getAPIReqParams(endpoint: string, method: Method): DexalotAPIParameters {
983
- return {
984
- url: `${DEXALOT_API_URL}/${endpoint}`,
985
- headers: { 'x-apikey': this.dexalotAuthToken },
986
- params: {
987
- chainid: this.network,
988
- },
989
- method: method,
990
- };
991
- }
992
-
993
- releaseResources(): void {
994
- if (this.rateFetcher) {
995
- this.rateFetcher.stop();
996
- }
997
- }
998
- }