@paraswap/dex-lib 2.16.7 → 2.16.8-pancakeswapv3.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 (150) hide show
  1. package/build/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +781 -0
  2. package/build/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +1039 -0
  3. package/build/abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json +285 -0
  4. package/build/abi/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  5. package/build/dex/index.js +1 -1
  6. package/build/dex/index.js.map +1 -1
  7. package/build/dex/{test-dex → pancakeswap-v3}/config.d.ts +2 -2
  8. package/build/dex/pancakeswap-v3/config.js +62 -0
  9. package/build/dex/pancakeswap-v3/config.js.map +1 -0
  10. package/build/dex/pancakeswap-v3/constants.d.ts +23 -0
  11. package/build/dex/pancakeswap-v3/constants.js +29 -0
  12. package/build/dex/pancakeswap-v3/constants.js.map +1 -0
  13. package/build/dex/pancakeswap-v3/contract-math/BitMath.d.ts +4 -0
  14. package/build/dex/pancakeswap-v3/contract-math/BitMath.js +93 -0
  15. package/build/dex/pancakeswap-v3/contract-math/BitMath.js.map +1 -0
  16. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.d.ts +3 -0
  17. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js +8 -0
  18. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js.map +1 -0
  19. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.d.ts +4 -0
  20. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js +9 -0
  21. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js.map +1 -0
  22. package/build/dex/pancakeswap-v3/contract-math/FullMath.d.ts +4 -0
  23. package/build/dex/pancakeswap-v3/contract-math/FullMath.js +19 -0
  24. package/build/dex/pancakeswap-v3/contract-math/FullMath.js.map +1 -0
  25. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.d.ts +3 -0
  26. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js +22 -0
  27. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js.map +1 -0
  28. package/build/dex/pancakeswap-v3/contract-math/Oracle.d.ts +10 -0
  29. package/build/dex/pancakeswap-v3/contract-math/Oracle.js +133 -0
  30. package/build/dex/pancakeswap-v3/contract-math/Oracle.js.map +1 -0
  31. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
  32. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js +91 -0
  33. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
  34. package/build/dex/pancakeswap-v3/contract-math/SwapMath.d.ts +8 -0
  35. package/build/dex/pancakeswap-v3/contract-math/SwapMath.js +70 -0
  36. package/build/dex/pancakeswap-v3/contract-math/SwapMath.js.map +1 -0
  37. package/build/dex/pancakeswap-v3/contract-math/Tick.d.ts +7 -0
  38. package/build/dex/pancakeswap-v3/contract-math/Tick.js +45 -0
  39. package/build/dex/pancakeswap-v3/contract-math/Tick.js.map +1 -0
  40. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.d.ts +8 -0
  41. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js +87 -0
  42. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js.map +1 -0
  43. package/build/dex/pancakeswap-v3/contract-math/TickMath.d.ts +8 -0
  44. package/build/dex/pancakeswap-v3/contract-math/TickMath.js +162 -0
  45. package/build/dex/pancakeswap-v3/contract-math/TickMath.js.map +1 -0
  46. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.d.ts +3 -0
  47. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js +10 -0
  48. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js.map +1 -0
  49. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.d.ts +18 -0
  50. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js +407 -0
  51. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js.map +1 -0
  52. package/build/dex/pancakeswap-v3/contract-math/utils.d.ts +3 -0
  53. package/build/dex/pancakeswap-v3/contract-math/utils.js +16 -0
  54. package/build/dex/pancakeswap-v3/contract-math/utils.js.map +1 -0
  55. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +45 -0
  56. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +340 -0
  57. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -0
  58. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +55 -0
  59. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +605 -0
  60. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  61. package/build/dex/pancakeswap-v3/types.d.ts +137 -0
  62. package/build/dex/pancakeswap-v3/types.js +9 -0
  63. package/build/dex/pancakeswap-v3/types.js.map +1 -0
  64. package/build/dex/pancakeswap-v3/utils.d.ts +6 -0
  65. package/build/dex/pancakeswap-v3/utils.js +65 -0
  66. package/build/dex/pancakeswap-v3/utils.js.map +1 -0
  67. package/build/dex/uniswap-v3/config.js +0 -28
  68. package/build/dex/uniswap-v3/config.js.map +1 -1
  69. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +1 -2
  70. package/build/dex/uniswap-v3/uniswap-v3-pool.js +2 -3
  71. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  72. package/build/dex/uniswap-v3/uniswap-v3.js +1 -1
  73. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  74. package/package.json +1 -1
  75. package/src/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +781 -0
  76. package/src/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +1039 -0
  77. package/src/dex/index.ts +1 -1
  78. package/src/dex/pancakeswap-v3/config.ts +68 -0
  79. package/src/dex/pancakeswap-v3/constants.ts +35 -0
  80. package/src/dex/pancakeswap-v3/contract-math/BitMath.ts +90 -0
  81. package/src/dex/pancakeswap-v3/contract-math/FixedPoint128.ts +3 -0
  82. package/src/dex/pancakeswap-v3/contract-math/FixedPoint96.ts +4 -0
  83. package/src/dex/pancakeswap-v3/contract-math/FullMath.ts +30 -0
  84. package/src/dex/pancakeswap-v3/contract-math/LiquidityMath.ts +17 -0
  85. package/src/dex/pancakeswap-v3/contract-math/Oracle.ts +226 -0
  86. package/src/dex/pancakeswap-v3/contract-math/SqrtPriceMath.ts +226 -0
  87. package/src/dex/pancakeswap-v3/contract-math/SwapMath.ts +139 -0
  88. package/src/dex/pancakeswap-v3/contract-math/Tick.ts +82 -0
  89. package/src/dex/pancakeswap-v3/contract-math/TickBitMap.ts +128 -0
  90. package/src/dex/pancakeswap-v3/contract-math/TickMath.ts +211 -0
  91. package/src/dex/pancakeswap-v3/contract-math/UnsafeMath.ts +5 -0
  92. package/src/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.ts +691 -0
  93. package/src/dex/pancakeswap-v3/contract-math/utils.ts +11 -0
  94. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +168 -0
  95. package/src/dex/pancakeswap-v3/pancakeswap-v3-events.test.ts +124 -0
  96. package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +338 -0
  97. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +554 -0
  98. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1000 -0
  99. package/src/dex/uniswap-v3/config.ts +0 -32
  100. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +0 -156
  101. package/src/dex/uniswap-v3/uniswap-v3-events.test.ts +4 -0
  102. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +1 -2
  103. package/src/dex/uniswap-v3/uniswap-v3.ts +0 -1
  104. package/build/abi/DirectSwap.json +0 -970
  105. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  106. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  107. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  108. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  109. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  110. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  111. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  112. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  113. package/build/dex/quickswap-v3.d.ts +0 -21
  114. package/build/dex/quickswap-v3.js +0 -40
  115. package/build/dex/quickswap-v3.js.map +0 -1
  116. package/build/dex/test-dex/config.js +0 -15
  117. package/build/dex/test-dex/config.js.map +0 -1
  118. package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
  119. package/build/dex/test-dex/test-dex-pool.js +0 -63
  120. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  121. package/build/dex/test-dex/test-dex.d.ts +0 -37
  122. package/build/dex/test-dex/test-dex.js +0 -126
  123. package/build/dex/test-dex/test-dex.js.map +0 -1
  124. package/build/dex/test-dex/types.d.ts +0 -6
  125. package/build/dex/test-dex/types.js +0 -3
  126. package/build/dex/test-dex/types.js.map +0 -1
  127. package/build/dex/woo-fi/config.d.ts +0 -4
  128. package/build/dex/woo-fi/config.js +0 -141
  129. package/build/dex/woo-fi/config.js.map +0 -1
  130. package/build/dex/woo-fi/constants.d.ts +0 -5
  131. package/build/dex/woo-fi/constants.js +0 -20
  132. package/build/dex/woo-fi/constants.js.map +0 -1
  133. package/build/dex/woo-fi/types.d.ts +0 -48
  134. package/build/dex/woo-fi/types.js +0 -3
  135. package/build/dex/woo-fi/types.js.map +0 -1
  136. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  137. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  138. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  139. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  140. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  141. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  142. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  143. package/build/dex/woo-fi/woo-fi.js +0 -480
  144. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  145. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  146. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  147. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
  148. package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +0 -28
  149. /package/src/abi/{uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json → pancakeswap-v3/PancakeswapV3Quoter.abi.json} +0 -0
  150. /package/src/abi/{uniswap-v3/pancakeswap-v3 → pancakeswap-v3}/PancakeswapV3Router.abi.json +0 -0
@@ -0,0 +1,1000 @@
1
+ import { defaultAbiCoder, Interface } from '@ethersproject/abi';
2
+ import _ from 'lodash';
3
+ import { pack } from '@ethersproject/solidity';
4
+ import {
5
+ Token,
6
+ Address,
7
+ ExchangePrices,
8
+ AdapterExchangeParam,
9
+ SimpleExchangeParam,
10
+ PoolLiquidity,
11
+ Logger,
12
+ NumberAsString,
13
+ PoolPrices,
14
+ } from '../../types';
15
+ import { SwapSide, Network, CACHE_PREFIX } from '../../constants';
16
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
17
+ import {
18
+ getBigIntPow,
19
+ getDexKeysWithNetwork,
20
+ interpolate,
21
+ isTruthy,
22
+ } from '../../utils';
23
+ import { IDex } from '../../dex/idex';
24
+ import { IDexHelper } from '../../dex-helper/idex-helper';
25
+ import {
26
+ DexParams,
27
+ OutputResult,
28
+ PoolState,
29
+ UniswapV3Data,
30
+ UniswapV3Functions,
31
+ UniswapV3Param,
32
+ } from '../uniswap-v3/types';
33
+ import {
34
+ getLocalDeadlineAsFriendlyPlaceholder,
35
+ SimpleExchange,
36
+ } from '../simple-exchange';
37
+ import { PancakeswapV3Config, Adapters } from './config';
38
+ import { PancakeSwapV3EventPool } from './pancakeswap-v3-pool';
39
+ import PancakeswapV3RouterABI from '../../abi/pancakeswap-v3/PancakeswapV3Router.abi.json';
40
+ import PancakeswapV3QuoterABI from '../../abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json';
41
+ import UniswapV3MultiABI from '../../abi/uniswap-v3/UniswapMulti.abi.json';
42
+ import PancakeswapV3StateMulticallABI from '../../abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json';
43
+ import {
44
+ PANCAKESWAPV3_EFFICIENCY_FACTOR,
45
+ PANCAKESWAP3_FUNCTION_CALL_GAS_COST,
46
+ PANCAKESWAPV3_TICK_GAS_COST,
47
+ } from './constants';
48
+ import { DeepReadonly } from 'ts-essentials';
49
+ import { pancakeswapV3Math } from './contract-math/pancakeswap-v3-math';
50
+ import { Contract } from 'web3-eth-contract';
51
+ import { AbiItem } from 'web3-utils';
52
+ import { BalanceRequest, getBalances } from '../../lib/tokens/balancer-fetcher';
53
+ import {
54
+ AssetType,
55
+ DEFAULT_ID_ERC20,
56
+ DEFAULT_ID_ERC20_AS_STRING,
57
+ } from '../../lib/tokens/types';
58
+
59
+ type PoolPairsInfo = {
60
+ token0: Address;
61
+ token1: Address;
62
+ fee: string;
63
+ };
64
+
65
+ const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 60 * 60 * 24 * 1000; // 24 hours
66
+ const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 30 * 60 * 1000; // Once in 30 minutes
67
+ const PANCAKESWAPV3_QUOTE_GASLIMIT = 200_000;
68
+
69
+ export class PancakeswapV3
70
+ extends SimpleExchange
71
+ implements IDex<UniswapV3Data, UniswapV3Param>
72
+ {
73
+ readonly isFeeOnTransferSupported: boolean = false;
74
+ readonly eventPools: Record<string, PancakeSwapV3EventPool | null> = {};
75
+
76
+ readonly hasConstantPriceLargeAmounts = false;
77
+ readonly needWrapNative = true;
78
+
79
+ intervalTask?: NodeJS.Timeout;
80
+
81
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
82
+ getDexKeysWithNetwork(_.pick(PancakeswapV3Config, ['PancakeswapV3']));
83
+
84
+ logger: Logger;
85
+
86
+ private uniswapMulti: Contract;
87
+ private stateMultiContract: Contract;
88
+
89
+ private notExistingPoolSetKey: string;
90
+
91
+ constructor(
92
+ protected network: Network,
93
+ dexKey: string,
94
+ protected dexHelper: IDexHelper,
95
+ protected adapters = Adapters[network] || {},
96
+ readonly routerIface = new Interface(PancakeswapV3RouterABI),
97
+ readonly quoterIface = new Interface(PancakeswapV3QuoterABI),
98
+ protected config = PancakeswapV3Config[dexKey][network], // protected poolsToPreload = PoolsToPreload[dexKey][network] || [],
99
+ ) {
100
+ super(dexHelper, dexKey);
101
+ this.logger = dexHelper.getLogger(dexKey + '-' + network);
102
+ this.uniswapMulti = new this.dexHelper.web3Provider.eth.Contract(
103
+ UniswapV3MultiABI as AbiItem[],
104
+ this.config.uniswapMulticall,
105
+ );
106
+ this.stateMultiContract = new this.dexHelper.web3Provider.eth.Contract(
107
+ PancakeswapV3StateMulticallABI as AbiItem[],
108
+ this.config.stateMulticall,
109
+ );
110
+
111
+ // To receive revert reasons
112
+ this.dexHelper.web3Provider.eth.handleRevert = false;
113
+
114
+ // Normalise once all config addresses and use across all scenarios
115
+ this.config = this._toLowerForAllConfigAddresses();
116
+
117
+ this.notExistingPoolSetKey =
118
+ `${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
119
+ }
120
+
121
+ get supportedFees() {
122
+ return this.config.supportedFees;
123
+ }
124
+
125
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
126
+ return this.adapters[side] ? this.adapters[side] : null;
127
+ }
128
+
129
+ getPoolIdentifier(srcAddress: Address, destAddress: Address, fee: bigint) {
130
+ const tokenAddresses = this._sortTokens(srcAddress, destAddress).join('_');
131
+ return `${this.dexKey}_${tokenAddresses}_${fee}`;
132
+ }
133
+
134
+ async initializePricing(blockNumber: number) {
135
+ if (!this.dexHelper.config.isSlave) {
136
+ const cleanExpiredNotExistingPoolsKeys = async () => {
137
+ const maxTimestamp =
138
+ Date.now() - PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS;
139
+ await this.dexHelper.cache.zremrangebyscore(
140
+ this.notExistingPoolSetKey,
141
+ 0,
142
+ maxTimestamp,
143
+ );
144
+ };
145
+
146
+ this.intervalTask = setInterval(
147
+ cleanExpiredNotExistingPoolsKeys.bind(this),
148
+ PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS,
149
+ );
150
+ }
151
+ }
152
+
153
+ async getPool(
154
+ srcAddress: Address,
155
+ destAddress: Address,
156
+ fee: bigint,
157
+ blockNumber: number,
158
+ ): Promise<PancakeSwapV3EventPool | null> {
159
+ let pool =
160
+ this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)];
161
+
162
+ if (pool === undefined) {
163
+ const [token0, token1] = this._sortTokens(srcAddress, destAddress);
164
+
165
+ const key = `${token0}_${token1}_${fee}`.toLowerCase();
166
+
167
+ const notExistingPoolScore = await this.dexHelper.cache.zscore(
168
+ this.notExistingPoolSetKey,
169
+ key,
170
+ );
171
+
172
+ const poolDoesNotExist = notExistingPoolScore !== null;
173
+
174
+ if (poolDoesNotExist) {
175
+ this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
176
+ null;
177
+ return null;
178
+ }
179
+
180
+ await this.dexHelper.cache.hset(
181
+ this.dexmapKey,
182
+ key,
183
+ JSON.stringify({
184
+ token0,
185
+ token1,
186
+ fee: fee.toString(),
187
+ }),
188
+ );
189
+
190
+ this.logger.trace(`starting to listen to new pool: ${key}`);
191
+ pool = new PancakeSwapV3EventPool(
192
+ this.dexHelper,
193
+ this.dexKey,
194
+ this.stateMultiContract,
195
+ this.erc20Interface,
196
+ this.config.factory,
197
+ fee,
198
+ token0,
199
+ token1,
200
+ this.logger,
201
+ this.cacheStateKey,
202
+ this.config.initHash,
203
+ this.config.deployer,
204
+ );
205
+
206
+ try {
207
+ await pool.initialize(blockNumber, {
208
+ initCallback: (state: DeepReadonly<PoolState>) => {
209
+ //really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
210
+ pool!.addressesSubscribed[0] = state.pool;
211
+ pool!.poolAddress = state.pool;
212
+ },
213
+ });
214
+ } catch (e) {
215
+ if (e instanceof Error && e.message.endsWith('Pool does not exist')) {
216
+ // no need to await we want the set to have the pool key but it's not blocking
217
+ this.dexHelper.cache.zadd(
218
+ this.notExistingPoolSetKey,
219
+ [Date.now(), key],
220
+ 'NX',
221
+ );
222
+
223
+ // Pool does not exist for this feeCode, so we can set it to null
224
+ // to prevent more requests for this pool
225
+ pool = null;
226
+ this.logger.trace(
227
+ `${this.dexHelper}: Pool: srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} not found`,
228
+ e,
229
+ );
230
+ } else {
231
+ // Unexpected Error. Break execution. Do not save the pool in this.eventPools
232
+ this.logger.error(
233
+ `${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool`,
234
+ e,
235
+ );
236
+ throw new Error('Cannot generate pool state');
237
+ }
238
+ }
239
+
240
+ if (pool !== null) {
241
+ const allEventPools = Object.values(this.eventPools);
242
+ this.logger.info(
243
+ `starting to listen to new non-null pool: ${key}. Already following ${allEventPools
244
+ // Not that I like this reduce, but since it is done only on initialization, expect this to be ok
245
+ .reduce(
246
+ (acc, curr) => (curr !== null ? ++acc : acc),
247
+ 0,
248
+ )} non-null pools or ${allEventPools.length} total pools`,
249
+ );
250
+ }
251
+
252
+ this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
253
+ pool;
254
+ }
255
+ return pool;
256
+ }
257
+
258
+ async addMasterPool(poolKey: string, blockNumber: number): Promise<boolean> {
259
+ const _pairs = await this.dexHelper.cache.hget(this.dexmapKey, poolKey);
260
+ if (!_pairs) {
261
+ this.logger.warn(
262
+ `did not find poolConfig in for key ${this.dexmapKey} ${poolKey}`,
263
+ );
264
+ return false;
265
+ }
266
+
267
+ const poolInfo: PoolPairsInfo = JSON.parse(_pairs);
268
+
269
+ const pool = await this.getPool(
270
+ poolInfo.token0,
271
+ poolInfo.token1,
272
+ BigInt(poolInfo.fee),
273
+ blockNumber,
274
+ );
275
+
276
+ if (!pool) {
277
+ return false;
278
+ }
279
+
280
+ return true;
281
+ }
282
+
283
+ async getPoolIdentifiers(
284
+ srcToken: Token,
285
+ destToken: Token,
286
+ side: SwapSide,
287
+ blockNumber: number,
288
+ ): Promise<string[]> {
289
+ const _srcToken = this.dexHelper.config.wrapETH(srcToken);
290
+ const _destToken = this.dexHelper.config.wrapETH(destToken);
291
+
292
+ const [_srcAddress, _destAddress] = this._getLoweredAddresses(
293
+ _srcToken,
294
+ _destToken,
295
+ );
296
+
297
+ if (_srcAddress === _destAddress) return [];
298
+
299
+ const pools = (
300
+ await Promise.all(
301
+ this.supportedFees.map(async fee =>
302
+ this.getPool(_srcAddress, _destAddress, fee, blockNumber),
303
+ ),
304
+ )
305
+ ).filter(pool => pool);
306
+
307
+ if (pools.length === 0) return [];
308
+
309
+ return pools.map(pool =>
310
+ this.getPoolIdentifier(_srcAddress, _destAddress, pool!.feeCode),
311
+ );
312
+ }
313
+
314
+ async getPricingFromRpc(
315
+ from: Token,
316
+ to: Token,
317
+ amounts: bigint[],
318
+ side: SwapSide,
319
+ pools: PancakeSwapV3EventPool[],
320
+ ): Promise<ExchangePrices<UniswapV3Data> | null> {
321
+ if (pools.length === 0) {
322
+ return null;
323
+ }
324
+ this.logger.warn(`fallback to rpc for ${pools.length} pool(s)`);
325
+
326
+ const requests = pools.map<BalanceRequest>(
327
+ pool => ({
328
+ owner: pool.poolAddress,
329
+ asset: side == SwapSide.SELL ? from.address : to.address,
330
+ assetType: AssetType.ERC20,
331
+ ids: [
332
+ {
333
+ id: DEFAULT_ID_ERC20,
334
+ spenders: [],
335
+ },
336
+ ],
337
+ }),
338
+ [],
339
+ );
340
+
341
+ const balances = await getBalances(this.dexHelper.multiWrapper, requests);
342
+
343
+ pools = pools.filter((pool, index) => {
344
+ const balance = balances[index].amounts[DEFAULT_ID_ERC20_AS_STRING];
345
+ if (balance >= amounts[amounts.length - 1]) {
346
+ return true;
347
+ }
348
+ this.logger.warn(
349
+ `[${this.network}][${pool.parentName}] have no balance ${pool.poolAddress} ${from.address} ${to.address}. (Balance: ${balance})`,
350
+ );
351
+ return false;
352
+ });
353
+
354
+ pools.forEach(pool => {
355
+ this.logger.warn(
356
+ `[${this.network}][${pool.parentName}] fallback to rpc for ${pool.name}`,
357
+ );
358
+ });
359
+
360
+ const unitVolume = getBigIntPow(
361
+ (side === SwapSide.SELL ? from : to).decimals,
362
+ );
363
+
364
+ const chunks = amounts.length - 1;
365
+
366
+ const _width = Math.floor(chunks / this.config.chunksCount);
367
+
368
+ const _amounts = [unitVolume].concat(
369
+ Array.from(Array(this.config.chunksCount).keys()).map(
370
+ i => amounts[(i + 1) * _width],
371
+ ),
372
+ );
373
+
374
+ const calldata = pools.map(pool =>
375
+ _amounts.map(_amount => ({
376
+ target: this.config.quoter,
377
+ gasLimit: PANCAKESWAPV3_QUOTE_GASLIMIT,
378
+ callData:
379
+ side === SwapSide.SELL
380
+ ? this.quoterIface.encodeFunctionData('quoteExactInputSingle', [
381
+ [
382
+ from.address,
383
+ to.address,
384
+ _amount.toString(),
385
+ pool.feeCodeAsString,
386
+ 0, //sqrtPriceLimitX96
387
+ ],
388
+ ])
389
+ : this.quoterIface.encodeFunctionData('quoteExactOutputSingle', [
390
+ [
391
+ from.address,
392
+ to.address,
393
+ _amount.toString(),
394
+ pool.feeCodeAsString,
395
+ 0, //sqrtPriceLimitX96
396
+ ],
397
+ ]),
398
+ })),
399
+ );
400
+
401
+ const data = await this.uniswapMulti.methods
402
+ .multicall(calldata.flat())
403
+ .call();
404
+
405
+ const decode = (j: number): bigint => {
406
+ if (!data.returnData[j].success) {
407
+ return 0n;
408
+ }
409
+ const decoded = defaultAbiCoder.decode(
410
+ ['uint256'],
411
+ data.returnData[j].returnData,
412
+ );
413
+ return BigInt(decoded[0].toString());
414
+ };
415
+
416
+ let i = 0;
417
+ const result = pools.map(pool => {
418
+ const _rates = _amounts.map(() => decode(i++));
419
+ const unit: bigint = _rates[0];
420
+
421
+ const prices = interpolate(
422
+ _amounts.slice(1),
423
+ _rates.slice(1),
424
+ amounts,
425
+ side,
426
+ );
427
+
428
+ return {
429
+ prices,
430
+ unit,
431
+ data: {
432
+ path: [
433
+ {
434
+ tokenIn: from.address,
435
+ tokenOut: to.address,
436
+ fee: pool.feeCodeAsString,
437
+ },
438
+ ],
439
+ },
440
+ poolIdentifier: this.getPoolIdentifier(
441
+ pool.token0,
442
+ pool.token1,
443
+ pool.feeCode,
444
+ ),
445
+ exchange: this.dexKey,
446
+ gasCost: prices.map(p => (p === 0n ? 0 : PANCAKESWAPV3_QUOTE_GASLIMIT)),
447
+ poolAddresses: [pool.poolAddress],
448
+ };
449
+ });
450
+
451
+ return result;
452
+ }
453
+
454
+ async getPricesVolume(
455
+ srcToken: Token,
456
+ destToken: Token,
457
+ amounts: bigint[],
458
+ side: SwapSide,
459
+ blockNumber: number,
460
+ limitPools?: string[],
461
+ ): Promise<null | ExchangePrices<UniswapV3Data>> {
462
+ try {
463
+ const _srcToken = this.dexHelper.config.wrapETH(srcToken);
464
+ const _destToken = this.dexHelper.config.wrapETH(destToken);
465
+
466
+ const [_srcAddress, _destAddress] = this._getLoweredAddresses(
467
+ _srcToken,
468
+ _destToken,
469
+ );
470
+
471
+ if (_srcAddress === _destAddress) return null;
472
+
473
+ let selectedPools: PancakeSwapV3EventPool[] = [];
474
+
475
+ if (!limitPools) {
476
+ selectedPools = (
477
+ await Promise.all(
478
+ this.supportedFees.map(async fee => {
479
+ const locallyFoundPool =
480
+ this.eventPools[
481
+ this.getPoolIdentifier(_srcAddress, _destAddress, fee)
482
+ ];
483
+ if (locallyFoundPool) return locallyFoundPool;
484
+
485
+ const newlyFetchedPool = await this.getPool(
486
+ _srcAddress,
487
+ _destAddress,
488
+ fee,
489
+ blockNumber,
490
+ );
491
+ return newlyFetchedPool;
492
+ }),
493
+ )
494
+ ).filter(isTruthy);
495
+ } else {
496
+ const pairIdentifierWithoutFee = this.getPoolIdentifier(
497
+ _srcAddress,
498
+ _destAddress,
499
+ 0n,
500
+ // Trim from 0 fee postfix, so it become comparable
501
+ ).slice(0, -1);
502
+
503
+ const poolIdentifiers = limitPools.filter(identifier =>
504
+ identifier.startsWith(pairIdentifierWithoutFee),
505
+ );
506
+
507
+ selectedPools = (
508
+ await Promise.all(
509
+ poolIdentifiers.map(async identifier => {
510
+ let locallyFoundPool = this.eventPools[identifier];
511
+ if (locallyFoundPool) return locallyFoundPool;
512
+
513
+ const [, srcAddress, destAddress, fee] = identifier.split('_');
514
+ const newlyFetchedPool = await this.getPool(
515
+ srcAddress,
516
+ destAddress,
517
+ BigInt(fee),
518
+ blockNumber,
519
+ );
520
+ return newlyFetchedPool;
521
+ }),
522
+ )
523
+ ).filter(isTruthy);
524
+ }
525
+
526
+ if (selectedPools.length === 0) return null;
527
+
528
+ const poolsToUse = selectedPools.reduce(
529
+ (acc, pool) => {
530
+ let state = pool.getState(blockNumber);
531
+ if (state === null) {
532
+ this.logger.trace(
533
+ `${this.dexKey}: State === null. Fallback to rpc ${pool.name}`,
534
+ );
535
+ acc.poolWithoutState.push(pool);
536
+ } else {
537
+ acc.poolWithState.push(pool);
538
+ }
539
+ return acc;
540
+ },
541
+ {
542
+ poolWithState: [] as PancakeSwapV3EventPool[],
543
+ poolWithoutState: [] as PancakeSwapV3EventPool[],
544
+ },
545
+ );
546
+
547
+ const rpcResultsPromise = this.getPricingFromRpc(
548
+ _srcToken,
549
+ _destToken,
550
+ amounts,
551
+ side,
552
+ poolsToUse.poolWithoutState,
553
+ );
554
+
555
+ const states = poolsToUse.poolWithState.map(
556
+ p => p.getState(blockNumber)!,
557
+ );
558
+
559
+ const unitAmount = getBigIntPow(
560
+ side == SwapSide.SELL ? _srcToken.decimals : _destToken.decimals,
561
+ );
562
+
563
+ const _amounts = [...amounts.slice(1)];
564
+
565
+ const [token0] = this._sortTokens(_srcAddress, _destAddress);
566
+
567
+ const zeroForOne = token0 === _srcAddress ? true : false;
568
+
569
+ const result = await Promise.all(
570
+ poolsToUse.poolWithState.map(async (pool, i) => {
571
+ const state = states[i];
572
+
573
+ if (state.liquidity <= 0n) {
574
+ this.logger.trace(`pool have 0 liquidity`);
575
+ return null;
576
+ }
577
+
578
+ const balanceDestToken =
579
+ _destAddress === pool.token0 ? state.balance0 : state.balance1;
580
+
581
+ const unitResult = this._getOutputs(
582
+ state,
583
+ [unitAmount],
584
+ zeroForOne,
585
+ side,
586
+ balanceDestToken,
587
+ );
588
+ const pricesResult = this._getOutputs(
589
+ state,
590
+ _amounts,
591
+ zeroForOne,
592
+ side,
593
+ balanceDestToken,
594
+ );
595
+
596
+ if (!unitResult || !pricesResult) {
597
+ this.logger.debug('Prices or unit is not calculated');
598
+ return null;
599
+ }
600
+
601
+ const prices = [0n, ...pricesResult.outputs];
602
+ const gasCost = [
603
+ 0,
604
+ ...pricesResult.outputs.map((p, index) => {
605
+ if (p == 0n) {
606
+ return 0;
607
+ } else {
608
+ return (
609
+ PANCAKESWAP3_FUNCTION_CALL_GAS_COST +
610
+ pricesResult.tickCounts[index] * PANCAKESWAPV3_TICK_GAS_COST
611
+ );
612
+ }
613
+ }),
614
+ ];
615
+ return {
616
+ unit: unitResult.outputs[0],
617
+ prices,
618
+ data: {
619
+ path: [
620
+ {
621
+ tokenIn: _srcAddress,
622
+ tokenOut: _destAddress,
623
+ fee: pool.feeCode.toString(),
624
+ },
625
+ ],
626
+ },
627
+ poolIdentifier: this.getPoolIdentifier(
628
+ pool.token0,
629
+ pool.token1,
630
+ pool.feeCode,
631
+ ),
632
+ exchange: this.dexKey,
633
+ gasCost: gasCost,
634
+ poolAddresses: [pool.poolAddress],
635
+ };
636
+ }),
637
+ );
638
+ const rpcResults = await rpcResultsPromise;
639
+
640
+ const notNullResult = result.filter(
641
+ res => res !== null,
642
+ ) as ExchangePrices<UniswapV3Data>;
643
+
644
+ if (rpcResults) {
645
+ rpcResults.forEach(r => {
646
+ if (r) {
647
+ notNullResult.push(r);
648
+ }
649
+ });
650
+ }
651
+
652
+ return notNullResult;
653
+ } catch (e) {
654
+ this.logger.error(
655
+ `Error_getPricesVolume ${srcToken.symbol || srcToken.address}, ${
656
+ destToken.symbol || destToken.address
657
+ }, ${side}:`,
658
+ e,
659
+ );
660
+ return null;
661
+ }
662
+ }
663
+
664
+ getAdapterParam(
665
+ srcToken: string,
666
+ destToken: string,
667
+ srcAmount: string,
668
+ destAmount: string,
669
+ data: UniswapV3Data,
670
+ side: SwapSide,
671
+ ): AdapterExchangeParam {
672
+ const { path: rawPath } = data;
673
+ const path = this._encodePath(rawPath, side);
674
+
675
+ const payload = this.abiCoder.encodeParameter(
676
+ {
677
+ ParentStruct: {
678
+ path: 'bytes',
679
+ deadline: 'uint256',
680
+ },
681
+ },
682
+ {
683
+ path,
684
+ deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
685
+ },
686
+ );
687
+
688
+ return {
689
+ targetExchange: this.config.router,
690
+ payload,
691
+ networkFee: '0',
692
+ };
693
+ }
694
+
695
+ getCalldataGasCost(poolPrices: PoolPrices<UniswapV3Data>): number | number[] {
696
+ const gasCost =
697
+ CALLDATA_GAS_COST.DEX_OVERHEAD +
698
+ CALLDATA_GAS_COST.LENGTH_SMALL +
699
+ // ParentStruct header
700
+ CALLDATA_GAS_COST.OFFSET_SMALL +
701
+ // ParentStruct -> path header
702
+ CALLDATA_GAS_COST.OFFSET_SMALL +
703
+ // ParentStruct -> deadline
704
+ CALLDATA_GAS_COST.TIMESTAMP +
705
+ // ParentStruct -> path (20+3+20 = 43 = 32+11 bytes)
706
+ CALLDATA_GAS_COST.LENGTH_SMALL +
707
+ CALLDATA_GAS_COST.FULL_WORD +
708
+ CALLDATA_GAS_COST.wordNonZeroBytes(11);
709
+ const arr = new Array(poolPrices.prices.length);
710
+ poolPrices.prices.forEach((p, index) => {
711
+ if (p == 0n) {
712
+ arr[index] = 0;
713
+ } else {
714
+ arr[index] = gasCost;
715
+ }
716
+ });
717
+ return arr;
718
+ }
719
+
720
+ async getSimpleParam(
721
+ srcToken: string,
722
+ destToken: string,
723
+ srcAmount: string,
724
+ destAmount: string,
725
+ data: UniswapV3Data,
726
+ side: SwapSide,
727
+ ): Promise<SimpleExchangeParam> {
728
+ const swapFunction =
729
+ side === SwapSide.SELL
730
+ ? UniswapV3Functions.exactInput
731
+ : UniswapV3Functions.exactOutput;
732
+
733
+ const path = this._encodePath(data.path, side);
734
+ const swapFunctionParams: UniswapV3Param =
735
+ side === SwapSide.SELL
736
+ ? {
737
+ recipient: this.augustusAddress,
738
+ deadline: getLocalDeadlineAsFriendlyPlaceholder(),
739
+ amountIn: srcAmount,
740
+ amountOutMinimum: destAmount,
741
+ path,
742
+ }
743
+ : {
744
+ recipient: this.augustusAddress,
745
+ deadline: getLocalDeadlineAsFriendlyPlaceholder(),
746
+ amountOut: destAmount,
747
+ amountInMaximum: srcAmount,
748
+ path,
749
+ };
750
+ const swapData = this.routerIface.encodeFunctionData(swapFunction, [
751
+ swapFunctionParams,
752
+ ]);
753
+
754
+ return this.buildSimpleParamWithoutWETHConversion(
755
+ srcToken,
756
+ srcAmount,
757
+ destToken,
758
+ destAmount,
759
+ swapData,
760
+ this.config.router,
761
+ );
762
+ }
763
+
764
+ async getTopPoolsForToken(
765
+ tokenAddress: Address,
766
+ limit: number,
767
+ ): Promise<PoolLiquidity[]> {
768
+ const _tokenAddress = tokenAddress.toLowerCase();
769
+
770
+ const res = await this._querySubgraph(
771
+ `query ($token: Bytes!, $count: Int) {
772
+ pools0: pools(first: $count, orderBy: totalValueLockedUSD, orderDirection: desc, where: {token0: $token}) {
773
+ id
774
+ token0 {
775
+ id
776
+ decimals
777
+ }
778
+ token1 {
779
+ id
780
+ decimals
781
+ }
782
+ totalValueLockedUSD
783
+ }
784
+ pools1: pools(first: $count, orderBy: totalValueLockedUSD, orderDirection: desc, where: {token1: $token}) {
785
+ id
786
+ token0 {
787
+ id
788
+ decimals
789
+ }
790
+ token1 {
791
+ id
792
+ decimals
793
+ }
794
+ totalValueLockedUSD
795
+ }
796
+ }`,
797
+ {
798
+ token: _tokenAddress,
799
+ count: limit,
800
+ },
801
+ );
802
+
803
+ if (!(res && res.pools0 && res.pools1)) {
804
+ this.logger.error(
805
+ `Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`,
806
+ );
807
+ return [];
808
+ }
809
+
810
+ const pools0 = _.map(res.pools0, pool => ({
811
+ exchange: this.dexKey,
812
+ address: pool.id.toLowerCase(),
813
+ connectorTokens: [
814
+ {
815
+ address: pool.token1.id.toLowerCase(),
816
+ decimals: parseInt(pool.token1.decimals),
817
+ },
818
+ ],
819
+ liquidityUSD:
820
+ parseFloat(pool.totalValueLockedUSD) * PANCAKESWAPV3_EFFICIENCY_FACTOR,
821
+ }));
822
+
823
+ const pools1 = _.map(res.pools1, pool => ({
824
+ exchange: this.dexKey,
825
+ address: pool.id.toLowerCase(),
826
+ connectorTokens: [
827
+ {
828
+ address: pool.token0.id.toLowerCase(),
829
+ decimals: parseInt(pool.token0.decimals),
830
+ },
831
+ ],
832
+ liquidityUSD:
833
+ parseFloat(pool.totalValueLockedUSD) * PANCAKESWAPV3_EFFICIENCY_FACTOR,
834
+ }));
835
+
836
+ const pools = _.slice(
837
+ _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
838
+ 0,
839
+ limit,
840
+ );
841
+ return pools;
842
+ }
843
+
844
+ private async _getPoolsFromIdentifiers(
845
+ poolIdentifiers: string[],
846
+ blockNumber: number,
847
+ ): Promise<PancakeSwapV3EventPool[]> {
848
+ const pools = await Promise.all(
849
+ poolIdentifiers.map(async identifier => {
850
+ const [, srcAddress, destAddress, fee] = identifier.split('_');
851
+ return this.getPool(srcAddress, destAddress, BigInt(fee), blockNumber);
852
+ }),
853
+ );
854
+ return pools.filter(pool => pool) as PancakeSwapV3EventPool[];
855
+ }
856
+
857
+ private _getLoweredAddresses(srcToken: Token, destToken: Token) {
858
+ return [srcToken.address.toLowerCase(), destToken.address.toLowerCase()];
859
+ }
860
+
861
+ private _sortTokens(srcAddress: Address, destAddress: Address) {
862
+ return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
863
+ }
864
+
865
+ private _toLowerForAllConfigAddresses() {
866
+ // If new config property will be added, the TS will throw compile error
867
+ const newConfig: DexParams = {
868
+ router: this.config.router.toLowerCase(),
869
+ quoter: this.config.quoter.toLowerCase(),
870
+ factory: this.config.factory.toLowerCase(),
871
+ supportedFees: this.config.supportedFees,
872
+ stateMulticall: this.config.stateMulticall.toLowerCase(),
873
+ chunksCount: this.config.chunksCount,
874
+ uniswapMulticall: this.config.uniswapMulticall,
875
+ deployer: this.config.deployer?.toLowerCase(),
876
+ initHash: this.config.initHash,
877
+ subgraphURL: this.config.subgraphURL,
878
+ };
879
+ return newConfig;
880
+ }
881
+
882
+ private _getOutputs(
883
+ state: DeepReadonly<PoolState>,
884
+ amounts: bigint[],
885
+ zeroForOne: boolean,
886
+ side: SwapSide,
887
+ destTokenBalance: bigint,
888
+ ): OutputResult | null {
889
+ try {
890
+ const outputsResult = pancakeswapV3Math.queryOutputs(
891
+ state,
892
+ amounts,
893
+ zeroForOne,
894
+ side,
895
+ );
896
+
897
+ if (side === SwapSide.SELL) {
898
+ if (outputsResult.outputs[0] > destTokenBalance) {
899
+ return null;
900
+ }
901
+
902
+ for (let i = 0; i < outputsResult.outputs.length; i++) {
903
+ if (outputsResult.outputs[i] > destTokenBalance) {
904
+ outputsResult.outputs[i] = 0n;
905
+ outputsResult.tickCounts[i] = 0;
906
+ }
907
+ }
908
+ } else {
909
+ if (amounts[0] > destTokenBalance) {
910
+ return null;
911
+ }
912
+
913
+ // This may be improved by first checking outputs and requesting outputs
914
+ // only for amounts that makes more sense, but I don't think this is really
915
+ // important now
916
+ for (let i = 0; i < amounts.length; i++) {
917
+ if (amounts[i] > destTokenBalance) {
918
+ outputsResult.outputs[i] = 0n;
919
+ outputsResult.tickCounts[i] = 0;
920
+ }
921
+ }
922
+ }
923
+
924
+ return outputsResult;
925
+ } catch (e) {
926
+ this.logger.debug(
927
+ `${this.dexKey}: received error in _getOutputs while calculating outputs`,
928
+ e,
929
+ );
930
+ return null;
931
+ }
932
+ }
933
+
934
+ private async _querySubgraph(
935
+ query: string,
936
+ variables: Object,
937
+ timeout = 30000,
938
+ ) {
939
+ try {
940
+ const res = await this.dexHelper.httpRequest.post(
941
+ this.config.subgraphURL,
942
+ { query, variables },
943
+ undefined,
944
+ { timeout: timeout },
945
+ );
946
+ return res.data;
947
+ } catch (e) {
948
+ this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
949
+ return {};
950
+ }
951
+ }
952
+
953
+ private _encodePath(
954
+ path: {
955
+ tokenIn: Address;
956
+ tokenOut: Address;
957
+ fee: NumberAsString;
958
+ }[],
959
+ side: SwapSide,
960
+ ): string {
961
+ if (path.length === 0) {
962
+ this.logger.error(
963
+ `${this.dexKey}: Received invalid path=${path} for side=${side} to encode`,
964
+ );
965
+ return '0x';
966
+ }
967
+
968
+ const { _path, types } = path.reduce(
969
+ (
970
+ { _path, types }: { _path: string[]; types: string[] },
971
+ curr,
972
+ index,
973
+ ): { _path: string[]; types: string[] } => {
974
+ if (index === 0) {
975
+ return {
976
+ types: ['address', 'uint24', 'address'],
977
+ _path: [curr.tokenIn, curr.fee, curr.tokenOut],
978
+ };
979
+ } else {
980
+ return {
981
+ types: [...types, 'uint24', 'address'],
982
+ _path: [..._path, curr.fee, curr.tokenOut],
983
+ };
984
+ }
985
+ },
986
+ { _path: [], types: [] },
987
+ );
988
+
989
+ return side === SwapSide.BUY
990
+ ? pack(types.reverse(), _path.reverse())
991
+ : pack(types, _path);
992
+ }
993
+
994
+ releaseResources() {
995
+ if (this.intervalTask !== undefined) {
996
+ clearInterval(this.intervalTask);
997
+ this.intervalTask = undefined;
998
+ }
999
+ }
1000
+ }