@paraswap/dex-lib 2.36.1 → 2.36.2-dexalot

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