@paraswap/dex-lib 2.46.2-remove-univ3-poolconfigs.2 → 2.47.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 (222) hide show
  1. package/build/abi/algebra/AlgebraPool.abi.json +724 -724
  2. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +191 -191
  3. package/build/abi/wombat/pool.json +1289 -0
  4. package/build/constants.d.ts +0 -1
  5. package/build/constants.js +1 -2
  6. package/build/constants.js.map +1 -1
  7. package/build/dex/algebra/algebra-pool.d.ts +37 -105
  8. package/build/dex/algebra/algebra-pool.js +322 -434
  9. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +4 -0
  10. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -1
  11. package/build/dex/uniswap-v2/config.js +36 -0
  12. package/build/dex/uniswap-v2/config.js.map +1 -1
  13. package/build/dex/uniswap-v2/rebase-tokens.json +7 -0
  14. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +0 -5
  15. package/build/dex/uniswap-v3/uniswap-v3-pool.js +0 -7
  16. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  17. package/build/dex/uniswap-v3/uniswap-v3.js +6 -14
  18. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  19. package/build/stateful-event-subscriber.d.ts +0 -1
  20. package/build/stateful-event-subscriber.js +1 -11
  21. package/build/stateful-event-subscriber.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/constants.ts +0 -2
  24. package/src/dex/uniswap-v2/config.ts +42 -0
  25. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +44 -55
  26. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +0 -8
  27. package/src/dex/uniswap-v3/uniswap-v3.ts +11 -18
  28. package/src/stateful-event-subscriber.ts +1 -16
  29. package/.idea/aws.xml +0 -17
  30. package/.idea/codeStyles/Project.xml +0 -19
  31. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  32. package/.idea/misc.xml +0 -6
  33. package/.idea/modules.xml +0 -8
  34. package/.idea/paraswap-dex-lib.iml +0 -9
  35. package/.idea/prettier.xml +0 -7
  36. package/.idea/vcs.xml +0 -6
  37. package/build/abi/AugustusV6.abi.json +0 -395
  38. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  39. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  40. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  41. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  42. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  43. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  44. package/build/abi/wBETH.json +0 -1527
  45. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  46. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  47. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  48. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  49. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  50. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  51. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  52. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  53. package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
  54. package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
  55. package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
  56. package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
  57. package/build/dex/balancer-v2/LinearMath.js +0 -285
  58. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  59. package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
  60. package/build/dex/balancer-v2/LinearPool.js +0 -444
  61. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  62. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
  63. package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
  64. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  65. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  66. package/build/dex/balancer-v2/StableMath.js +0 -272
  67. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  68. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
  69. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
  70. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  71. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  72. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  73. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  74. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  75. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  76. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  77. package/build/dex/lighter-v1/abi/erc20.json +0 -222
  78. package/build/dex/lighter-v1/abi/factory.json +0 -291
  79. package/build/dex/lighter-v1/abi/order_book.json +0 -594
  80. package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
  81. package/build/dex/lighter-v1/abi/router.json +0 -488
  82. package/build/dex/lighter-v1/config.d.ts +0 -4
  83. package/build/dex/lighter-v1/config.js +0 -17
  84. package/build/dex/lighter-v1/config.js.map +0 -1
  85. package/build/dex/lighter-v1/constants.d.ts +0 -2
  86. package/build/dex/lighter-v1/constants.js +0 -13
  87. package/build/dex/lighter-v1/constants.js.map +0 -1
  88. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
  89. package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
  90. package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
  91. package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
  92. package/build/dex/lighter-v1/lighter-v1.js +0 -331
  93. package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
  94. package/build/dex/lighter-v1/types.d.ts +0 -40
  95. package/build/dex/lighter-v1/types.js +0 -3
  96. package/build/dex/lighter-v1/types.js.map +0 -1
  97. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  98. package/build/dex/pancakeswap-v3/types.js +0 -3
  99. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  100. package/build/dex/quickswap-v3.d.ts +0 -21
  101. package/build/dex/quickswap-v3.js +0 -40
  102. package/build/dex/quickswap-v3.js.map +0 -1
  103. package/build/dex/ramses-v2/config.d.ts +0 -4
  104. package/build/dex/ramses-v2/config.js +0 -28
  105. package/build/dex/ramses-v2/config.js.map +0 -1
  106. package/build/dex/ramses-v2/constants.d.ts +0 -28
  107. package/build/dex/ramses-v2/constants.js +0 -35
  108. package/build/dex/ramses-v2/constants.js.map +0 -1
  109. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  110. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  111. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  112. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  113. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  114. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  115. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  116. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  117. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  118. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  119. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  120. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  121. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  122. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  123. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  124. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  125. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  126. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  127. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  128. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  129. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  130. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  131. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  132. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  133. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  134. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  135. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  136. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  137. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  138. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  139. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  140. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  141. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  142. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  143. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  144. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  145. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  146. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  147. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  148. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  149. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  150. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  151. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  152. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  153. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  154. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  155. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  156. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  157. package/build/dex/ramses-v2/types.d.ts +0 -154
  158. package/build/dex/ramses-v2/types.js +0 -9
  159. package/build/dex/ramses-v2/types.js.map +0 -1
  160. package/build/dex/ramses-v2/utils.d.ts +0 -6
  161. package/build/dex/ramses-v2/utils.js +0 -71
  162. package/build/dex/ramses-v2/utils.js.map +0 -1
  163. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  164. package/build/dex/solidly/forks-override/fvm.js +0 -42
  165. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  166. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  167. package/build/dex/sushiswap-v3/config.js +0 -132
  168. package/build/dex/sushiswap-v3/config.js.map +0 -1
  169. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  170. package/build/dex/sushiswap-v3/constants.js +0 -32
  171. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  172. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  173. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  174. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  175. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  176. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  177. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  178. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  179. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  180. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  181. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  182. package/build/dex/sushiswap-v3/token.js +0 -23
  183. package/build/dex/sushiswap-v3/token.js.map +0 -1
  184. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  185. package/build/dex/sushiswap-v3/types.js +0 -18
  186. package/build/dex/sushiswap-v3/types.js.map +0 -1
  187. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  188. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  189. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  190. package/build/dex/woo-fi/config.d.ts +0 -4
  191. package/build/dex/woo-fi/config.js +0 -141
  192. package/build/dex/woo-fi/config.js.map +0 -1
  193. package/build/dex/woo-fi/constants.d.ts +0 -5
  194. package/build/dex/woo-fi/constants.js +0 -20
  195. package/build/dex/woo-fi/constants.js.map +0 -1
  196. package/build/dex/woo-fi/types.d.ts +0 -48
  197. package/build/dex/woo-fi/types.js +0 -3
  198. package/build/dex/woo-fi/types.js.map +0 -1
  199. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  200. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  201. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  202. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  203. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  204. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  205. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  206. package/build/dex/woo-fi/woo-fi.js +0 -480
  207. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  208. package/build/executor/Executor01BytecodeBuilder.d.ts +0 -77
  209. package/build/executor/Executor01BytecodeBuilder.js +0 -359
  210. package/build/executor/Executor01BytecodeBuilder.js.map +0 -1
  211. package/build/executor/Executor02BytecodeBuilder.d.ts +0 -12
  212. package/build/executor/Executor02BytecodeBuilder.js +0 -14
  213. package/build/executor/Executor02BytecodeBuilder.js.map +0 -1
  214. package/build/executor/ExecutorDetector.d.ts +0 -28
  215. package/build/executor/ExecutorDetector.js +0 -89
  216. package/build/executor/ExecutorDetector.js.map +0 -1
  217. package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
  218. package/build/executor/IExecutorBytecodeBuilder.js +0 -3
  219. package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
  220. package/build/generic-swap-transaction-builder.d.ts +0 -39
  221. package/build/generic-swap-transaction-builder.js +0 -156
  222. package/build/generic-swap-transaction-builder.js.map +0 -1
@@ -1,448 +1,336 @@
1
- 'use strict';
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod };
6
- };
7
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
8
6
  exports.AlgebraEventPool = void 0;
9
- const lodash_1 = __importDefault(require('lodash'));
10
- const abi_1 = require('@ethersproject/abi');
11
- const ts_essentials_1 = require('ts-essentials');
12
- const utils_1 = require('../../utils');
13
- const stateful_event_subscriber_1 = require('../../stateful-event-subscriber');
14
- const ethers_1 = require('ethers');
15
- const AlgebraPool_abi_json_1 = __importDefault(
16
- require('../../abi/algebra/AlgebraPool.abi.json'),
17
- );
18
- const constants_1 = require('../uniswap-v3/constants');
19
- const decoders_1 = require('../../lib/decoders');
20
- const utils_2 = require('./utils');
21
- const AlgebraMath_1 = require('./lib/AlgebraMath');
22
- const TickBitMap_1 = require('../uniswap-v3/contract-math/TickBitMap');
23
- const utils_3 = require('../uniswap-v3/contract-math/utils');
24
- const Constants_1 = require('./lib/Constants');
25
- const constants_2 = require('../../constants');
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const abi_1 = require("@ethersproject/abi");
9
+ const ts_essentials_1 = require("ts-essentials");
10
+ const utils_1 = require("../../utils");
11
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
12
+ const ethers_1 = require("ethers");
13
+ const AlgebraPool_abi_json_1 = __importDefault(require("../../abi/algebra/AlgebraPool.abi.json"));
14
+ const constants_1 = require("../uniswap-v3/constants");
15
+ const decoders_1 = require("../../lib/decoders");
16
+ const utils_2 = require("./utils");
17
+ const AlgebraMath_1 = require("./lib/AlgebraMath");
18
+ const TickBitMap_1 = require("../uniswap-v3/contract-math/TickBitMap");
19
+ const utils_3 = require("../uniswap-v3/contract-math/utils");
20
+ const Constants_1 = require("./lib/Constants");
21
+ const constants_2 = require("../../constants");
26
22
  class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
27
- constructor(
28
- dexHelper,
29
- parentName,
30
- stateMultiContract,
31
- erc20Interface,
32
- factoryAddress,
33
- token0,
34
- token1,
35
- logger,
36
- mapKey = '',
37
- poolInitCodeHash,
38
- poolDeployer,
39
- ) {
40
- super(parentName, `${token0}_${token1}`, dexHelper, logger, true, mapKey);
41
- this.dexHelper = dexHelper;
42
- this.stateMultiContract = stateMultiContract;
43
- this.erc20Interface = erc20Interface;
44
- this.factoryAddress = factoryAddress;
45
- this.poolInitCodeHash = poolInitCodeHash;
46
- this.poolDeployer = poolDeployer;
47
- this.handlers = {};
48
- this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
49
- this.initFailed = false;
50
- this.initRetryAttemptCount = 0;
51
- this.token0 = token0.toLowerCase();
52
- this.token1 = token1.toLowerCase();
53
- this.logDecoder = log => this.poolIface.parseLog(log);
54
- this.addressesSubscribed = new Array(1);
55
- this.handlers['Fee'] = this.handleNewFee.bind(this);
56
- this.handlers['Swap'] = this.handleSwapEvent.bind(this);
57
- this.handlers['Mint'] = this.handleMintEvent.bind(this);
58
- this.handlers['Burn'] = this.handleBurnEvent.bind(this);
59
- this.handlers['Flash'] = this.handleFlashEvent.bind(this);
60
- this.handlers['Collect'] = this.handleCollectEvent.bind(this);
61
- this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
62
- }
63
- get poolAddress() {
64
- if (this._poolAddress === undefined) {
65
- this._poolAddress = this._computePoolAddress(this.token0, this.token1);
23
+ constructor(dexHelper, parentName, stateMultiContract, erc20Interface, factoryAddress, token0, token1, logger, mapKey = '', poolInitCodeHash, poolDeployer) {
24
+ super(parentName, `${token0}_${token1}`, dexHelper, logger, true, mapKey);
25
+ this.dexHelper = dexHelper;
26
+ this.stateMultiContract = stateMultiContract;
27
+ this.erc20Interface = erc20Interface;
28
+ this.factoryAddress = factoryAddress;
29
+ this.poolInitCodeHash = poolInitCodeHash;
30
+ this.poolDeployer = poolDeployer;
31
+ this.handlers = {};
32
+ this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
33
+ this.initFailed = false;
34
+ this.initRetryAttemptCount = 0;
35
+ this.token0 = token0.toLowerCase();
36
+ this.token1 = token1.toLowerCase();
37
+ this.logDecoder = (log) => this.poolIface.parseLog(log);
38
+ this.addressesSubscribed = new Array(1);
39
+ this.handlers['Fee'] = this.handleNewFee.bind(this);
40
+ this.handlers['Swap'] = this.handleSwapEvent.bind(this);
41
+ this.handlers['Mint'] = this.handleMintEvent.bind(this);
42
+ this.handlers['Burn'] = this.handleBurnEvent.bind(this);
43
+ this.handlers['Flash'] = this.handleFlashEvent.bind(this);
44
+ this.handlers['Collect'] = this.handleCollectEvent.bind(this);
45
+ this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
66
46
  }
67
- return this._poolAddress;
68
- }
69
- set poolAddress(address) {
70
- this._poolAddress = address.toLowerCase();
71
- }
72
- async initialize(blockNumber, options) {
73
- await super.initialize(blockNumber, options);
74
- }
75
- async processBlockLogs(state, logs, blockHeader) {
76
- const newState = await super.processBlockLogs(state, logs, blockHeader);
77
- if (newState && !newState.isValid) {
78
- return await this.generateState(blockHeader.number);
47
+ get poolAddress() {
48
+ if (this._poolAddress === undefined) {
49
+ this._poolAddress = this._computePoolAddress(this.token0, this.token1);
50
+ }
51
+ return this._poolAddress;
52
+ }
53
+ set poolAddress(address) {
54
+ this._poolAddress = address.toLowerCase();
55
+ }
56
+ async initialize(blockNumber, options) {
57
+ await super.initialize(blockNumber, options);
58
+ }
59
+ async processBlockLogs(state, logs, blockHeader) {
60
+ const newState = await super.processBlockLogs(state, logs, blockHeader);
61
+ if (newState && !newState.isValid) {
62
+ return await this.generateState(blockHeader.number);
63
+ }
64
+ return newState;
79
65
  }
80
- return newState;
81
- }
82
- processLog(state, log, blockHeader) {
83
- try {
84
- const event = this.logDecoder(log);
85
- if (event.name in this.handlers) {
86
- // Because we have observations in array which is mutable by nature, there is a
87
- // ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
88
- // And there is no good workaround, so turn off the type checker for this line
89
- const _state = lodash_1.default.cloneDeep(state);
66
+ processLog(state, log, blockHeader) {
90
67
  try {
91
- const newState = this.handlers[event.name](
92
- event,
93
- _state,
94
- log,
95
- blockHeader,
96
- );
97
- return newState;
98
- } catch (e) {
99
- if (
100
- e instanceof Error &&
101
- e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)
102
- ) {
103
- this.logger.warn(
104
- `${this.parentName}: Pool ${this.poolAddress} on ${
105
- this.dexHelper.config.data.network
106
- } is out of TickBitmap requested range. Re-query the state. ${JSON.stringify(
107
- event,
108
- )}`,
109
- e,
110
- );
111
- } else {
112
- this.logger.error(
113
- `${this.parentName}: Pool ${this.poolAddress}, ` +
114
- `network=${this.dexHelper.config.data.network}: Unexpected ` +
115
- `error while handling event on blockNumber=${blockHeader.number}, ` +
116
- `blockHash=${blockHeader.hash} and parentHash=${
117
- blockHeader.parentHash
118
- } for QuickSwapV3, ${JSON.stringify(event)}`,
119
- e,
120
- );
121
- }
122
- _state.isValid = false;
123
- return _state;
68
+ const event = this.logDecoder(log);
69
+ if (event.name in this.handlers) {
70
+ // Because we have observations in array which is mutable by nature, there is a
71
+ // ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
72
+ // And there is no good workaround, so turn off the type checker for this line
73
+ const _state = lodash_1.default.cloneDeep(state);
74
+ try {
75
+ const newState = this.handlers[event.name](event, _state, log, blockHeader);
76
+ return newState;
77
+ }
78
+ catch (e) {
79
+ if (e instanceof Error &&
80
+ e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)) {
81
+ this.logger.warn(`${this.parentName}: Pool ${this.poolAddress} on ${this.dexHelper.config.data.network} is out of TickBitmap requested range. Re-query the state. ${JSON.stringify(event)}`, e);
82
+ }
83
+ else {
84
+ this.logger.error(`${this.parentName}: Pool ${this.poolAddress}, ` +
85
+ `network=${this.dexHelper.config.data.network}: Unexpected ` +
86
+ `error while handling event on blockNumber=${blockHeader.number}, ` +
87
+ `blockHash=${blockHeader.hash} and parentHash=${blockHeader.parentHash} for QuickSwapV3, ${JSON.stringify(event)}`, e);
88
+ }
89
+ _state.isValid = false;
90
+ return _state;
91
+ }
92
+ }
124
93
  }
125
- }
126
- } catch (e) {
127
- (0, utils_1.catchParseLogError)(e, this.logger);
94
+ catch (e) {
95
+ (0, utils_1.catchParseLogError)(e, this.logger);
96
+ }
97
+ return null; // ignore unrecognized event
98
+ }
99
+ getBitmapRangeToRequest() {
100
+ return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
101
+ }
102
+ async _fetchPoolStateSingleStep(blockNumber) {
103
+ const callData = [
104
+ {
105
+ target: this.token0,
106
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
107
+ this.poolAddress,
108
+ ]),
109
+ decodeFunction: decoders_1.uint256ToBigInt,
110
+ },
111
+ {
112
+ target: this.token1,
113
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
114
+ this.poolAddress,
115
+ ]),
116
+ decodeFunction: decoders_1.uint256ToBigInt,
117
+ },
118
+ {
119
+ target: this.stateMultiContract.options.address,
120
+ callData: this.stateMultiContract.methods
121
+ .getFullStateWithRelativeBitmaps(this.factoryAddress, this.token0, this.token1, this.getBitmapRangeToRequest(), this.getBitmapRangeToRequest())
122
+ .encodeABI(),
123
+ decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
124
+ },
125
+ ];
126
+ const [resBalance0, resBalance1, resState] = await this.dexHelper.multiWrapper.tryAggregate(false, callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
127
+ (0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
128
+ const [balance0, balance1, _state] = [
129
+ resBalance0.returnData,
130
+ resBalance1.returnData,
131
+ resState.returnData,
132
+ ];
133
+ return [balance0, balance1, _state];
128
134
  }
129
- return null; // ignore unrecognized event
130
- }
131
- getBitmapRangeToRequest() {
132
- return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
133
- }
134
- async _fetchPoolStateSingleStep(blockNumber) {
135
- const callData = [
136
- {
137
- target: this.token0,
138
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
139
- this.poolAddress,
140
- ]),
141
- decodeFunction: decoders_1.uint256ToBigInt,
142
- },
143
- {
144
- target: this.token1,
145
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
146
- this.poolAddress,
147
- ]),
148
- decodeFunction: decoders_1.uint256ToBigInt,
149
- },
150
- {
151
- target: this.stateMultiContract.options.address,
152
- callData: this.stateMultiContract.methods
153
- .getFullStateWithRelativeBitmaps(
154
- this.factoryAddress,
155
- this.token0,
156
- this.token1,
157
- this.getBitmapRangeToRequest(),
158
- this.getBitmapRangeToRequest(),
159
- )
160
- .encodeABI(),
161
- decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
162
- },
163
- ];
164
- const [resBalance0, resBalance1, resState] =
165
- await this.dexHelper.multiWrapper.tryAggregate(
166
- false,
167
- callData,
168
- blockNumber,
169
- this.dexHelper.multiWrapper.defaultBatchSize,
170
- false,
171
- );
172
- (0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
173
- const [balance0, balance1, _state] = [
174
- resBalance0.returnData,
175
- resBalance1.returnData,
176
- resState.returnData,
177
- ];
178
- return [balance0, balance1, _state];
179
- }
180
- async _fetchPoolStateMultiStep(blockNumber) {
181
- const balancesAndGlobalStateCalldata = [
182
- {
183
- target: this.token0,
184
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
185
- this.poolAddress,
186
- ]),
187
- decodeFunction: decoders_1.uint256ToBigInt,
188
- },
189
- {
190
- target: this.token1,
191
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
192
- this.poolAddress,
193
- ]),
194
- decodeFunction: decoders_1.uint256ToBigInt,
195
- },
196
- {
197
- target: this.stateMultiContract.options.address,
198
- callData: this.stateMultiContract.methods
199
- .getFullStateWithoutTicks(
200
- this.factoryAddress,
201
- this.token0,
202
- this.token1,
203
- 0,
204
- 0,
205
- )
206
- .encodeABI(),
207
- decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
208
- },
209
- ];
210
- const [resBalance0, resBalance1, stateWithoutTicksAndTickBitmap] =
211
- await this.dexHelper.multiWrapper.tryAggregate(
212
- false,
213
- balancesAndGlobalStateCalldata,
214
- blockNumber,
215
- this.dexHelper.multiWrapper.defaultBatchSize,
216
- false,
217
- );
218
- (0, ts_essentials_1.assert)(
219
- stateWithoutTicksAndTickBitmap.success,
220
- 'Pool does not exist',
221
- );
222
- const [balance0, balance1, _stateWithoutTicksAndTickBitmap] = [
223
- resBalance0.returnData,
224
- resBalance1.returnData,
225
- stateWithoutTicksAndTickBitmap.returnData,
226
- ];
227
- const {
228
- globalState: { tick },
229
- } = _stateWithoutTicksAndTickBitmap;
230
- const currentBitmapIndex = (0, utils_1.int16)(
231
- (BigInt(tick) / Constants_1.Constants.TICK_SPACING) >> 8n,
232
- );
233
- const buffer = this.getBitmapRangeToRequest();
234
- const startBitMapIndex = currentBitmapIndex - buffer;
235
- const endBitMapIndex = currentBitmapIndex + buffer;
236
- const allBitMapIndices = Array.from(
237
- { length: 2 * Number(buffer) + 1 },
238
- () => startBitMapIndex + endBitMapIndex,
239
- );
240
- const ticksAndBitMaps = await Promise.all(
241
- allBitMapIndices.map(relativeTick => {
242
- return this.stateMultiContract.methods
243
- .getAdditionalBitmapWithTicks(
244
- this.factoryAddress,
245
- this.token0,
246
- this.token1,
247
- relativeTick,
248
- relativeTick,
249
- )
250
- .call();
251
- }),
252
- );
253
- const _state = {
254
- ..._stateWithoutTicksAndTickBitmap,
255
- tickBitmap: ticksAndBitMaps.flatMap(v => v[0]),
256
- ticks: ticksAndBitMaps.flatMap(v => v[1]),
257
- };
258
- return [balance0, balance1, _state];
259
- }
260
- async _fetchInitStateMultiStrategies(blockNumber) {
261
- try {
262
- return await this._fetchPoolStateSingleStep(blockNumber);
263
- } catch (e) {
264
- if (e instanceof Error && e.message.includes('Pool does not exist'))
265
- throw e;
266
- if (this.dexHelper.config.data.network != constants_2.Network.ZKEVM)
267
- throw e;
268
- return this._fetchPoolStateMultiStep(blockNumber);
135
+ async _fetchPoolStateMultiStep(blockNumber) {
136
+ const balancesAndGlobalStateCalldata = [
137
+ {
138
+ target: this.token0,
139
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
140
+ this.poolAddress,
141
+ ]),
142
+ decodeFunction: decoders_1.uint256ToBigInt,
143
+ },
144
+ {
145
+ target: this.token1,
146
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
147
+ this.poolAddress,
148
+ ]),
149
+ decodeFunction: decoders_1.uint256ToBigInt,
150
+ },
151
+ {
152
+ target: this.stateMultiContract.options.address,
153
+ callData: this.stateMultiContract.methods
154
+ .getFullStateWithoutTicks(this.factoryAddress, this.token0, this.token1, 0, 0)
155
+ .encodeABI(),
156
+ decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
157
+ },
158
+ ];
159
+ const [resBalance0, resBalance1, stateWithoutTicksAndTickBitmap] = await this.dexHelper.multiWrapper.tryAggregate(false, balancesAndGlobalStateCalldata, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
160
+ (0, ts_essentials_1.assert)(stateWithoutTicksAndTickBitmap.success, 'Pool does not exist');
161
+ const [balance0, balance1, _stateWithoutTicksAndTickBitmap] = [
162
+ resBalance0.returnData,
163
+ resBalance1.returnData,
164
+ stateWithoutTicksAndTickBitmap.returnData,
165
+ ];
166
+ const { globalState: { tick }, } = _stateWithoutTicksAndTickBitmap;
167
+ const currentBitmapIndex = (0, utils_1.int16)((BigInt(tick) / Constants_1.Constants.TICK_SPACING) >> 8n);
168
+ const buffer = this.getBitmapRangeToRequest();
169
+ const startBitMapIndex = currentBitmapIndex - buffer;
170
+ const endBitMapIndex = currentBitmapIndex + buffer;
171
+ const allBitMapIndices = Array.from({ length: 2 * Number(buffer) + 1 }, () => startBitMapIndex + endBitMapIndex);
172
+ const ticksAndBitMaps = await Promise.all(allBitMapIndices.map(relativeTick => {
173
+ return this.stateMultiContract.methods
174
+ .getAdditionalBitmapWithTicks(this.factoryAddress, this.token0, this.token1, relativeTick, relativeTick)
175
+ .call();
176
+ }));
177
+ const _state = {
178
+ ..._stateWithoutTicksAndTickBitmap,
179
+ tickBitmap: ticksAndBitMaps.flatMap(v => v[0]),
180
+ ticks: ticksAndBitMaps.flatMap(v => v[1]),
181
+ };
182
+ return [balance0, balance1, _state];
269
183
  }
270
- }
271
- async generateState(blockNumber) {
272
- const [balance0, balance1, _state] =
273
- await this._fetchInitStateMultiStrategies(blockNumber);
274
- const tickBitmap = {};
275
- const ticks = {};
276
- (0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
277
- (0, utils_3._reduceTicks)(ticks, _state.ticks);
278
- const globalState = {
279
- communityFeeToken0: (0, utils_1.bigIntify)(
280
- _state.globalState.communityFeeToken0,
281
- ),
282
- communityFeeToken1: (0, utils_1.bigIntify)(
283
- _state.globalState.communityFeeToken1,
284
- ),
285
- fee: (0, utils_1.bigIntify)(_state.globalState.fee),
286
- price: (0, utils_1.bigIntify)(_state.globalState.price),
287
- tick: (0, utils_1.bigIntify)(_state.globalState.tick),
288
- };
289
- const currentTick = globalState.tick;
290
- const startTickBitmap = TickBitMap_1.TickBitMap.position(
291
- BigInt(currentTick) / Constants_1.Constants.TICK_SPACING,
292
- )[0];
293
- return {
294
- pool: _state.pool,
295
- blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
296
- globalState,
297
- liquidity: (0, utils_1.bigIntify)(_state.liquidity),
298
- tickSpacing: Constants_1.Constants.TICK_SPACING,
299
- maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
300
- tickBitmap,
301
- ticks,
302
- startTickBitmap,
303
- isValid: true,
304
- balance0,
305
- balance1,
306
- };
307
- }
308
- handleSwapEvent(event, pool, log, blockHeader) {
309
- const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
310
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
311
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
312
- const newTick = (0, utils_1.bigIntify)(event.args.tick);
313
- const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
314
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
315
- if (amount0 <= 0n && amount1 <= 0n) {
316
- this.logger.error(
317
- `${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
318
- `${this.poolAddress} and ${blockHeader.number}. Check why it happened`,
319
- );
320
- pool.isValid = false;
321
- return pool;
322
- } else {
323
- const zeroForOne = amount0 > 0n;
324
- const [, , , , , communityFee] =
325
- AlgebraMath_1.AlgebraMath._calculateSwapAndLock(
326
- pool,
327
- zeroForOne,
328
- newSqrtPriceX96,
329
- newTick,
330
- newLiquidity,
331
- );
332
- if (zeroForOne) {
333
- if (amount1 < 0n) {
334
- pool.balance1 -= BigInt.asUintN(256, -amount1);
335
- } else {
336
- this.logger.error(
337
- `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`,
338
- );
339
- pool.isValid = false;
184
+ async _fetchInitStateMultiStrategies(blockNumber) {
185
+ try {
186
+ return await this._fetchPoolStateSingleStep(blockNumber);
340
187
  }
341
- // This is not correct fully, because pool may get more tokens then it needs, but
342
- // it is not accounted in internal state, it should be good enough
343
- pool.balance0 += BigInt.asUintN(256, amount0);
344
- } else {
345
- if (amount0 < 0n) {
346
- pool.balance0 -= BigInt.asUintN(256, -amount0);
347
- } else {
348
- this.logger.error(
349
- `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`,
350
- );
351
- pool.isValid = false;
188
+ catch (e) {
189
+ if (e instanceof Error && e.message.includes('Pool does not exist'))
190
+ throw e;
191
+ if (this.dexHelper.config.data.network != constants_2.Network.ZKEVM)
192
+ throw e;
193
+ return this._fetchPoolStateMultiStep(blockNumber);
352
194
  }
353
- pool.balance1 += BigInt.asUintN(256, amount1);
354
- }
355
- if (communityFee > 0n) {
356
- // _payCommunityFee
357
- if (zeroForOne) {
358
- pool.balance0 -= communityFee;
359
- } else {
360
- pool.balance1 -= communityFee;
195
+ }
196
+ async generateState(blockNumber) {
197
+ const [balance0, balance1, _state] = await this._fetchInitStateMultiStrategies(blockNumber);
198
+ const tickBitmap = {};
199
+ const ticks = {};
200
+ (0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
201
+ (0, utils_3._reduceTicks)(ticks, _state.ticks);
202
+ const globalState = {
203
+ communityFeeToken0: (0, utils_1.bigIntify)(_state.globalState.communityFeeToken0),
204
+ communityFeeToken1: (0, utils_1.bigIntify)(_state.globalState.communityFeeToken1),
205
+ fee: (0, utils_1.bigIntify)(_state.globalState.fee),
206
+ price: (0, utils_1.bigIntify)(_state.globalState.price),
207
+ tick: (0, utils_1.bigIntify)(_state.globalState.tick),
208
+ };
209
+ const currentTick = globalState.tick;
210
+ const startTickBitmap = TickBitMap_1.TickBitMap.position(BigInt(currentTick) / Constants_1.Constants.TICK_SPACING)[0];
211
+ return {
212
+ pool: _state.pool,
213
+ blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
214
+ globalState,
215
+ liquidity: (0, utils_1.bigIntify)(_state.liquidity),
216
+ tickSpacing: Constants_1.Constants.TICK_SPACING,
217
+ maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
218
+ tickBitmap,
219
+ ticks,
220
+ startTickBitmap,
221
+ isValid: true,
222
+ balance0,
223
+ balance1,
224
+ };
225
+ }
226
+ handleSwapEvent(event, pool, log, blockHeader) {
227
+ const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
228
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
229
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
230
+ const newTick = (0, utils_1.bigIntify)(event.args.tick);
231
+ const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
232
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
233
+ if (amount0 <= 0n && amount1 <= 0n) {
234
+ this.logger.error(`${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
235
+ `${this.poolAddress} and ${blockHeader.number}. Check why it happened`);
236
+ pool.isValid = false;
237
+ return pool;
238
+ }
239
+ else {
240
+ const zeroForOne = amount0 > 0n;
241
+ const [, , , , , communityFee] = AlgebraMath_1.AlgebraMath._calculateSwapAndLock(pool, zeroForOne, newSqrtPriceX96, newTick, newLiquidity);
242
+ if (zeroForOne) {
243
+ if (amount1 < 0n) {
244
+ pool.balance1 -= BigInt.asUintN(256, -amount1);
245
+ }
246
+ else {
247
+ this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`);
248
+ pool.isValid = false;
249
+ }
250
+ // This is not correct fully, because pool may get more tokens then it needs, but
251
+ // it is not accounted in internal state, it should be good enough
252
+ pool.balance0 += BigInt.asUintN(256, amount0);
253
+ }
254
+ else {
255
+ if (amount0 < 0n) {
256
+ pool.balance0 -= BigInt.asUintN(256, -amount0);
257
+ }
258
+ else {
259
+ this.logger.error(`In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`);
260
+ pool.isValid = false;
261
+ }
262
+ pool.balance1 += BigInt.asUintN(256, amount1);
263
+ }
264
+ if (communityFee > 0n) {
265
+ // _payCommunityFee
266
+ if (zeroForOne) {
267
+ pool.balance0 -= communityFee;
268
+ }
269
+ else {
270
+ pool.balance1 -= communityFee;
271
+ }
272
+ }
273
+ return pool;
361
274
  }
362
- }
363
- return pool;
364
275
  }
365
- }
366
- handleMintEvent(event, pool, log, blockHeader) {
367
- const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
368
- const topTick = (0, utils_1.bigIntify)(event.args.topTick);
369
- const liquidityActual = (0, utils_1.bigIntify)(event.args.liquidityAmount);
370
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
371
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
372
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
373
- AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
374
- pool,
375
- bottomTick,
376
- topTick,
377
- liquidityActual,
378
- );
379
- pool.balance0 += amount0;
380
- pool.balance1 += amount1;
381
- return pool;
382
- }
383
- handleBurnEvent(event, pool, log, blockHeader) {
384
- const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
385
- const topTick = (0, utils_1.bigIntify)(event.args.topTick);
386
- const amount = (0, utils_1.bigIntify)(event.args.liquidityAmount);
387
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
388
- AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
389
- pool,
390
- bottomTick,
391
- topTick,
392
- -BigInt.asIntN(128, BigInt.asIntN(256, amount)),
393
- );
394
- // no balance change
395
- return pool;
396
- }
397
- handleNewFee(event, pool, log, blockHeader) {
398
- const fee = (0, utils_1.bigIntify)(event.args.fee);
399
- pool.globalState.fee = fee;
400
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
401
- return pool;
402
- }
403
- handleCollectEvent(event, pool, log, blockHeader) {
404
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
405
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
406
- pool.balance0 -= amount0;
407
- pool.balance1 -= amount1;
408
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
409
- return pool;
410
- }
411
- handleFlashEvent(event, pool, log, blockHeader) {
412
- const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
413
- const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
414
- pool.balance0 += paid0;
415
- pool.balance1 += paid1;
416
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
417
- return pool;
418
- }
419
- handleCommunityFee(event, pool, log, blockHeader) {
420
- const communityFeeToken0 = (0, utils_1.bigIntify)(
421
- event.ags.communityFee0New,
422
- );
423
- const communityFeeToken1 = (0, utils_1.bigIntify)(
424
- event.ags.communityFee1New,
425
- );
426
- pool.globalState.communityFeeToken0 = communityFeeToken0;
427
- pool.globalState.communityFeeToken1 = communityFeeToken1;
428
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
429
- return pool;
430
- }
431
- _computePoolAddress(token0, token1) {
432
- // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
433
- if (token0 > token1) [token0, token1] = [token1, token0];
434
- const encodedKey = ethers_1.ethers.utils.keccak256(
435
- ethers_1.ethers.utils.defaultAbiCoder.encode(
436
- ['address', 'address'],
437
- [token0, token1],
438
- ),
439
- );
440
- return ethers_1.ethers.utils.getCreate2Address(
441
- this.poolDeployer,
442
- encodedKey,
443
- this.poolInitCodeHash,
444
- );
445
- }
276
+ handleMintEvent(event, pool, log, blockHeader) {
277
+ const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
278
+ const topTick = (0, utils_1.bigIntify)(event.args.topTick);
279
+ const liquidityActual = (0, utils_1.bigIntify)(event.args.liquidityAmount);
280
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
281
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
282
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
283
+ AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(pool, bottomTick, topTick, liquidityActual);
284
+ pool.balance0 += amount0;
285
+ pool.balance1 += amount1;
286
+ return pool;
287
+ }
288
+ handleBurnEvent(event, pool, log, blockHeader) {
289
+ const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
290
+ const topTick = (0, utils_1.bigIntify)(event.args.topTick);
291
+ const amount = (0, utils_1.bigIntify)(event.args.liquidityAmount);
292
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
293
+ AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(pool, bottomTick, topTick, -BigInt.asIntN(128, BigInt.asIntN(256, amount)));
294
+ // no balance change
295
+ return pool;
296
+ }
297
+ handleNewFee(event, pool, log, blockHeader) {
298
+ const fee = (0, utils_1.bigIntify)(event.args.fee);
299
+ pool.globalState.fee = fee;
300
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
301
+ return pool;
302
+ }
303
+ handleCollectEvent(event, pool, log, blockHeader) {
304
+ const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
305
+ const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
306
+ pool.balance0 -= amount0;
307
+ pool.balance1 -= amount1;
308
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
309
+ return pool;
310
+ }
311
+ handleFlashEvent(event, pool, log, blockHeader) {
312
+ const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
313
+ const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
314
+ pool.balance0 += paid0;
315
+ pool.balance1 += paid1;
316
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
317
+ return pool;
318
+ }
319
+ handleCommunityFee(event, pool, log, blockHeader) {
320
+ const communityFeeToken0 = (0, utils_1.bigIntify)(event.ags.communityFee0New);
321
+ const communityFeeToken1 = (0, utils_1.bigIntify)(event.ags.communityFee1New);
322
+ pool.globalState.communityFeeToken0 = communityFeeToken0;
323
+ pool.globalState.communityFeeToken1 = communityFeeToken1;
324
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
325
+ return pool;
326
+ }
327
+ _computePoolAddress(token0, token1) {
328
+ // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
329
+ if (token0 > token1)
330
+ [token0, token1] = [token1, token0];
331
+ const encodedKey = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'address'], [token0, token1]));
332
+ return ethers_1.ethers.utils.getCreate2Address(this.poolDeployer, encodedKey, this.poolInitCodeHash);
333
+ }
446
334
  }
447
335
  exports.AlgebraEventPool = AlgebraEventPool;
448
- //# sourceMappingURL=algebra-pool.js.map
336
+ //# sourceMappingURL=algebra-pool.js.map