@paraswap/dex-lib 2.45.0 → 2.45.1-core.2.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 (210) 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/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/AugustusV6.abi.json +395 -0
  10. package/build/abi/algebra/AlgebraPool.abi.json +724 -724
  11. package/build/abi/curve-v1/StableSwapFRXETH.json +889 -0
  12. package/build/abi/curve-v1/StableSwapWBETH.json +1223 -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/uniswap-v3/UniswapV3Quoter.abi.json +191 -191
  16. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  17. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  18. package/build/abi/wBETH.json +1527 -0
  19. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  20. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  21. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  22. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  23. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  24. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  25. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  26. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  27. package/build/dex/algebra/algebra-pool.d.ts +105 -37
  28. package/build/dex/algebra/algebra-pool.js +434 -322
  29. package/build/dex/balancer-v2/Gyro3Pool.d.ts +43 -0
  30. package/build/dex/balancer-v2/Gyro3Pool.js +160 -0
  31. package/build/dex/balancer-v2/Gyro3Pool.js.map +1 -0
  32. package/build/dex/balancer-v2/LinearMath.d.ts +88 -0
  33. package/build/dex/balancer-v2/LinearMath.js +285 -0
  34. package/build/dex/balancer-v2/LinearMath.js.map +1 -0
  35. package/build/dex/balancer-v2/LinearPool.d.ts +81 -0
  36. package/build/dex/balancer-v2/LinearPool.js +444 -0
  37. package/build/dex/balancer-v2/LinearPool.js.map +1 -0
  38. package/build/dex/balancer-v2/PhantomStablePool.d.ts +90 -0
  39. package/build/dex/balancer-v2/PhantomStablePool.js +418 -0
  40. package/build/dex/balancer-v2/PhantomStablePool.js.map +1 -0
  41. package/build/dex/balancer-v2/StableMath.d.ts +9 -0
  42. package/build/dex/balancer-v2/StableMath.js +272 -0
  43. package/build/dex/balancer-v2/StableMath.js.map +1 -0
  44. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +140 -0
  45. package/build/dex/balancer-v2/balancer-v2-pool.js +647 -0
  46. package/build/dex/balancer-v2/balancer-v2-pool.js.map +1 -0
  47. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +33 -0
  48. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +128 -0
  49. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +1 -0
  50. package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +34 -0
  51. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +151 -0
  52. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -0
  53. package/build/dex/curve-v1/pools/frxETHpool.d.ts +7 -0
  54. package/build/dex/curve-v1/pools/frxETHpool.js +27 -0
  55. package/build/dex/curve-v1/pools/frxETHpool.js.map +1 -0
  56. package/build/dex/curve-v1/pools/wbETHpool.d.ts +29 -0
  57. package/build/dex/curve-v1/pools/wbETHpool.js +408 -0
  58. package/build/dex/curve-v1/pools/wbETHpool.js.map +1 -0
  59. package/build/dex/lighter-v1/abi/erc20.json +222 -0
  60. package/build/dex/lighter-v1/abi/factory.json +291 -0
  61. package/build/dex/lighter-v1/abi/order_book.json +594 -0
  62. package/build/dex/lighter-v1/abi/order_book_helper.json +176 -0
  63. package/build/dex/lighter-v1/abi/router.json +488 -0
  64. package/build/dex/lighter-v1/config.d.ts +4 -0
  65. package/build/dex/lighter-v1/config.js +17 -0
  66. package/build/dex/lighter-v1/config.js.map +1 -0
  67. package/build/dex/lighter-v1/constants.d.ts +2 -0
  68. package/build/dex/lighter-v1/constants.js +13 -0
  69. package/build/dex/lighter-v1/constants.js.map +1 -0
  70. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +57 -0
  71. package/build/dex/lighter-v1/lighter-v1-pool.js +310 -0
  72. package/build/dex/lighter-v1/lighter-v1-pool.js.map +1 -0
  73. package/build/dex/lighter-v1/lighter-v1.d.ts +45 -0
  74. package/build/dex/lighter-v1/lighter-v1.js +331 -0
  75. package/build/dex/lighter-v1/lighter-v1.js.map +1 -0
  76. package/build/dex/lighter-v1/types.d.ts +40 -0
  77. package/build/dex/lighter-v1/types.js +3 -0
  78. package/build/dex/lighter-v1/types.js.map +1 -0
  79. package/build/dex/pancakeswap-v3/types.d.ts +14 -0
  80. package/build/dex/pancakeswap-v3/types.js +3 -0
  81. package/build/dex/pancakeswap-v3/types.js.map +1 -0
  82. package/build/dex/quickswap-v3.d.ts +21 -0
  83. package/build/dex/quickswap-v3.js +40 -0
  84. package/build/dex/quickswap-v3.js.map +1 -0
  85. package/build/dex/ramses-v2/config.d.ts +4 -0
  86. package/build/dex/ramses-v2/config.js +28 -0
  87. package/build/dex/ramses-v2/config.js.map +1 -0
  88. package/build/dex/ramses-v2/constants.d.ts +28 -0
  89. package/build/dex/ramses-v2/constants.js +35 -0
  90. package/build/dex/ramses-v2/constants.js.map +1 -0
  91. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +4 -0
  92. package/build/dex/ramses-v2/contract-math/BitMath.js +93 -0
  93. package/build/dex/ramses-v2/contract-math/BitMath.js.map +1 -0
  94. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +3 -0
  95. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +8 -0
  96. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +1 -0
  97. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +4 -0
  98. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +9 -0
  99. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +1 -0
  100. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +4 -0
  101. package/build/dex/ramses-v2/contract-math/FullMath.js +19 -0
  102. package/build/dex/ramses-v2/contract-math/FullMath.js.map +1 -0
  103. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +3 -0
  104. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +22 -0
  105. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +1 -0
  106. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +10 -0
  107. package/build/dex/ramses-v2/contract-math/Oracle.js +133 -0
  108. package/build/dex/ramses-v2/contract-math/Oracle.js.map +1 -0
  109. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +10 -0
  110. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +91 -0
  111. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +1 -0
  112. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +8 -0
  113. package/build/dex/ramses-v2/contract-math/SwapMath.js +70 -0
  114. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +1 -0
  115. package/build/dex/ramses-v2/contract-math/Tick.d.ts +7 -0
  116. package/build/dex/ramses-v2/contract-math/Tick.js +45 -0
  117. package/build/dex/ramses-v2/contract-math/Tick.js.map +1 -0
  118. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +8 -0
  119. package/build/dex/ramses-v2/contract-math/TickBitMap.js +87 -0
  120. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +1 -0
  121. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +8 -0
  122. package/build/dex/ramses-v2/contract-math/TickMath.js +162 -0
  123. package/build/dex/ramses-v2/contract-math/TickMath.js.map +1 -0
  124. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +3 -0
  125. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +10 -0
  126. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +1 -0
  127. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +18 -0
  128. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +392 -0
  129. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +1 -0
  130. package/build/dex/ramses-v2/contract-math/utils.d.ts +3 -0
  131. package/build/dex/ramses-v2/contract-math/utils.js +16 -0
  132. package/build/dex/ramses-v2/contract-math/utils.js.map +1 -0
  133. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +42 -0
  134. package/build/dex/ramses-v2/ramses-v2-pool.js +307 -0
  135. package/build/dex/ramses-v2/ramses-v2-pool.js.map +1 -0
  136. package/build/dex/ramses-v2/ramses-v2.d.ts +61 -0
  137. package/build/dex/ramses-v2/ramses-v2.js +690 -0
  138. package/build/dex/ramses-v2/ramses-v2.js.map +1 -0
  139. package/build/dex/ramses-v2/types.d.ts +154 -0
  140. package/build/dex/ramses-v2/types.js +9 -0
  141. package/build/dex/ramses-v2/types.js.map +1 -0
  142. package/build/dex/ramses-v2/utils.d.ts +6 -0
  143. package/build/dex/ramses-v2/utils.js +71 -0
  144. package/build/dex/ramses-v2/utils.js.map +1 -0
  145. package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
  146. package/build/dex/solidly/forks-override/fvm.js +42 -0
  147. package/build/dex/solidly/forks-override/fvm.js.map +1 -0
  148. package/build/dex/sushiswap-v3/config.d.ts +4 -0
  149. package/build/dex/sushiswap-v3/config.js +132 -0
  150. package/build/dex/sushiswap-v3/config.js.map +1 -0
  151. package/build/dex/sushiswap-v3/constants.d.ts +4 -0
  152. package/build/dex/sushiswap-v3/constants.js +32 -0
  153. package/build/dex/sushiswap-v3/constants.js.map +1 -0
  154. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +56 -0
  155. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +598 -0
  156. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +1 -0
  157. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +1 -0
  158. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +6 -0
  159. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +1 -0
  160. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +21 -0
  161. package/build/dex/sushiswap-v3/sushiswap-v3.js +58 -0
  162. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +1 -0
  163. package/build/dex/sushiswap-v3/token.d.ts +6 -0
  164. package/build/dex/sushiswap-v3/token.js +23 -0
  165. package/build/dex/sushiswap-v3/token.js.map +1 -0
  166. package/build/dex/sushiswap-v3/types.d.ts +15 -0
  167. package/build/dex/sushiswap-v3/types.js +18 -0
  168. package/build/dex/sushiswap-v3/types.js.map +1 -0
  169. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
  170. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
  171. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  172. package/build/dex/woo-fi/config.d.ts +4 -0
  173. package/build/dex/woo-fi/config.js +141 -0
  174. package/build/dex/woo-fi/config.js.map +1 -0
  175. package/build/dex/woo-fi/constants.d.ts +5 -0
  176. package/build/dex/woo-fi/constants.js +20 -0
  177. package/build/dex/woo-fi/constants.js.map +1 -0
  178. package/build/dex/woo-fi/types.d.ts +48 -0
  179. package/build/dex/woo-fi/types.js +3 -0
  180. package/build/dex/woo-fi/types.js.map +1 -0
  181. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  182. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  183. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  184. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  185. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  186. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  187. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  188. package/build/dex/woo-fi/woo-fi.js +480 -0
  189. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  190. package/build/executor/Executor01BytecodeBuilder.d.ts +77 -0
  191. package/build/executor/Executor01BytecodeBuilder.js +359 -0
  192. package/build/executor/Executor01BytecodeBuilder.js.map +1 -0
  193. package/build/executor/Executor02BytecodeBuilder.d.ts +12 -0
  194. package/build/executor/Executor02BytecodeBuilder.js +14 -0
  195. package/build/executor/Executor02BytecodeBuilder.js.map +1 -0
  196. package/build/executor/ExecutorDetector.d.ts +28 -0
  197. package/build/executor/ExecutorDetector.js +89 -0
  198. package/build/executor/ExecutorDetector.js.map +1 -0
  199. package/build/executor/IExecutorBytecodeBuilder.d.ts +6 -0
  200. package/build/executor/IExecutorBytecodeBuilder.js +3 -0
  201. package/build/executor/IExecutorBytecodeBuilder.js.map +1 -0
  202. package/build/generic-swap-transaction-builder.d.ts +39 -0
  203. package/build/generic-swap-transaction-builder.js +156 -0
  204. package/build/generic-swap-transaction-builder.js.map +1 -0
  205. package/build/implementations/local-paraswap-sdk.js +2 -0
  206. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  207. package/package.json +2 -2
  208. package/src/implementations/local-paraswap-sdk.ts +2 -0
  209. package/build/abi/wombat/pool.json +0 -1289
  210. package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
@@ -1,336 +1,448 @@
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 });
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 });
6
8
  exports.AlgebraEventPool = void 0;
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");
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');
22
26
  class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
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);
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);
46
66
  }
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;
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);
65
79
  }
66
- processLog(state, log, blockHeader) {
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);
67
90
  try {
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
- }
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;
93
124
  }
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];
125
+ }
126
+ } catch (e) {
127
+ (0, utils_1.catchParseLogError)(e, this.logger);
134
128
  }
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];
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);
183
269
  }
184
- async _fetchInitStateMultiStrategies(blockNumber) {
185
- try {
186
- return await this._fetchPoolStateSingleStep(blockNumber);
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;
187
340
  }
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);
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;
194
352
  }
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;
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;
274
361
  }
362
+ }
363
+ return pool;
275
364
  }
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
- }
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
+ }
334
446
  }
335
447
  exports.AlgebraEventPool = AlgebraEventPool;
336
- //# sourceMappingURL=algebra-pool.js.map
448
+ //# sourceMappingURL=algebra-pool.js.map