@paraswap/dex-lib 2.42.11 → 2.42.13

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 (228) hide show
  1. package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +1276 -0
  2. package/build/abi/kyberswap-elastic/IFactory.json +550 -0
  3. package/build/abi/kyberswap-elastic/IPool.json +1042 -0
  4. package/build/abi/kyberswap-elastic/IQuoterV2.json +226 -0
  5. package/build/abi/kyberswap-elastic/IRouter.json +239 -0
  6. package/build/abi/kyberswap-elastic/TicksFeesReader.json +142 -0
  7. package/build/abi/wombat/asset.json +769 -0
  8. package/build/abi/wombat/bmw.json +1247 -0
  9. package/build/abi/wombat/pool.json +1364 -0
  10. package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +26 -0
  11. package/build/dex/baseswap-v3/baseswap-v3-factory.js +44 -0
  12. package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +1 -0
  13. package/build/dex/{algebra/algebra-pool.d.ts → baseswap-v3/baseswap-v3-pool.d.ts} +16 -16
  14. package/build/dex/{algebra/algebra-pool.js → baseswap-v3/baseswap-v3-pool.js} +137 -161
  15. package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +1 -0
  16. package/build/dex/baseswap-v3/baseswap-v3.d.ts +71 -0
  17. package/build/dex/baseswap-v3/baseswap-v3.js +752 -0
  18. package/build/dex/baseswap-v3/baseswap-v3.js.map +1 -0
  19. package/build/dex/baseswap-v3/config.d.ts +9 -0
  20. package/build/dex/baseswap-v3/config.js +48 -0
  21. package/build/dex/baseswap-v3/config.js.map +1 -0
  22. package/build/dex/baseswap-v3/constants.d.ts +28 -0
  23. package/build/dex/baseswap-v3/constants.js +35 -0
  24. package/build/dex/baseswap-v3/constants.js.map +1 -0
  25. package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +4 -0
  26. package/build/dex/baseswap-v3/contract-math/BitMath.js +93 -0
  27. package/build/dex/baseswap-v3/contract-math/BitMath.js.map +1 -0
  28. package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +3 -0
  29. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +8 -0
  30. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +1 -0
  31. package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +4 -0
  32. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +9 -0
  33. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +1 -0
  34. package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +4 -0
  35. package/build/dex/baseswap-v3/contract-math/FullMath.js +19 -0
  36. package/build/dex/baseswap-v3/contract-math/FullMath.js.map +1 -0
  37. package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +3 -0
  38. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +22 -0
  39. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +1 -0
  40. package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +10 -0
  41. package/build/dex/baseswap-v3/contract-math/Oracle.js +133 -0
  42. package/build/dex/baseswap-v3/contract-math/Oracle.js.map +1 -0
  43. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
  44. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +91 -0
  45. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
  46. package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +8 -0
  47. package/build/dex/baseswap-v3/contract-math/SwapMath.js +70 -0
  48. package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +1 -0
  49. package/build/dex/baseswap-v3/contract-math/Tick.d.ts +7 -0
  50. package/build/dex/baseswap-v3/contract-math/Tick.js +45 -0
  51. package/build/dex/baseswap-v3/contract-math/Tick.js.map +1 -0
  52. package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +7 -0
  53. package/build/dex/baseswap-v3/contract-math/TickBitMap.js +84 -0
  54. package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +1 -0
  55. package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +8 -0
  56. package/build/dex/baseswap-v3/contract-math/TickMath.js +162 -0
  57. package/build/dex/baseswap-v3/contract-math/TickMath.js.map +1 -0
  58. package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +3 -0
  59. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +10 -0
  60. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +1 -0
  61. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +37 -0
  62. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +393 -0
  63. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +1 -0
  64. package/build/dex/baseswap-v3/contract-math/utils.d.ts +7 -0
  65. package/build/dex/baseswap-v3/contract-math/utils.js +42 -0
  66. package/build/dex/baseswap-v3/contract-math/utils.js.map +1 -0
  67. package/build/dex/baseswap-v3/types.d.ts +164 -0
  68. package/build/dex/baseswap-v3/types.js +9 -0
  69. package/build/dex/baseswap-v3/types.js.map +1 -0
  70. package/build/dex/baseswap-v3/utils.d.ts +6 -0
  71. package/build/dex/baseswap-v3/utils.js +65 -0
  72. package/build/dex/baseswap-v3/utils.js.map +1 -0
  73. package/build/dex/dexalot/dexalot.d.ts +3 -2
  74. package/build/dex/dexalot/dexalot.js +33 -19
  75. package/build/dex/dexalot/dexalot.js.map +1 -1
  76. package/build/dex/hello/config.d.ts +4 -0
  77. package/build/dex/hello/config.js +15 -0
  78. package/build/dex/hello/config.js.map +1 -0
  79. package/build/dex/hello/hello-pool.d.ts +39 -0
  80. package/build/dex/hello/hello-pool.js +64 -0
  81. package/build/dex/hello/hello-pool.js.map +1 -0
  82. package/build/dex/hello/hello.d.ts +37 -0
  83. package/build/dex/hello/hello.js +126 -0
  84. package/build/dex/hello/hello.js.map +1 -0
  85. package/build/dex/hello/types.d.ts +6 -0
  86. package/build/dex/hello/types.js +3 -0
  87. package/build/dex/hello/types.js.map +1 -0
  88. package/build/dex/kyberswap-elastic/config.d.ts +4 -0
  89. package/build/dex/kyberswap-elastic/config.js +80 -0
  90. package/build/dex/kyberswap-elastic/config.js.map +1 -0
  91. package/build/dex/kyberswap-elastic/constants.d.ts +17 -0
  92. package/build/dex/kyberswap-elastic/constants.js +42 -0
  93. package/build/dex/kyberswap-elastic/constants.js.map +1 -0
  94. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +4 -0
  95. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +9 -0
  96. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +1 -0
  97. package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +5 -0
  98. package/build/dex/kyberswap-elastic/contract-math/FullMath.js +22 -0
  99. package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +1 -0
  100. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +3 -0
  101. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +12 -0
  102. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +1 -0
  103. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +3 -0
  104. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +22 -0
  105. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +1 -0
  106. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +5 -0
  107. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +25 -0
  108. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +1 -0
  109. package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +4 -0
  110. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +27 -0
  111. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +1 -0
  112. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +3 -0
  113. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +14 -0
  114. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +1 -0
  115. package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +8 -0
  116. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +30 -0
  117. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +1 -0
  118. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +10 -0
  119. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +91 -0
  120. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +1 -0
  121. package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +13 -0
  122. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +188 -0
  123. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +1 -0
  124. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +6 -0
  125. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +41 -0
  126. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +1 -0
  127. package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +9 -0
  128. package/build/dex/kyberswap-elastic/contract-math/TickMath.js +165 -0
  129. package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +1 -0
  130. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +3 -0
  131. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +10 -0
  132. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +1 -0
  133. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +28 -0
  134. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +502 -0
  135. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +1 -0
  136. package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +3 -0
  137. package/build/dex/kyberswap-elastic/contract-math/utils.js +16 -0
  138. package/build/dex/kyberswap-elastic/contract-math/utils.js.map +1 -0
  139. package/build/dex/kyberswap-elastic/errors.d.ts +2 -0
  140. package/build/dex/kyberswap-elastic/errors.js +6 -0
  141. package/build/dex/kyberswap-elastic/errors.js.map +1 -0
  142. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +80 -0
  143. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +458 -0
  144. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +1 -0
  145. package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +53 -0
  146. package/build/dex/kyberswap-elastic/kyberswap-elastic.js +610 -0
  147. package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +1 -0
  148. package/build/dex/kyberswap-elastic/types.d.ts +134 -0
  149. package/build/dex/kyberswap-elastic/types.js +9 -0
  150. package/build/dex/kyberswap-elastic/types.js.map +1 -0
  151. package/build/dex/kyberswap-elastic/utils/decoders.d.ts +9 -0
  152. package/build/dex/kyberswap-elastic/utils/decoders.js +78 -0
  153. package/build/dex/kyberswap-elastic/utils/decoders.js.map +1 -0
  154. package/build/dex/morphex/config.d.ts +11 -0
  155. package/build/dex/morphex/config.js +43 -0
  156. package/build/dex/morphex/config.js.map +1 -0
  157. package/build/dex/morphex/morphex.d.ts +25 -0
  158. package/build/dex/morphex/morphex.js +19 -0
  159. package/build/dex/morphex/morphex.js.map +1 -0
  160. package/build/dex/my-test-dex/config.d.ts +4 -0
  161. package/build/dex/my-test-dex/config.js +15 -0
  162. package/build/dex/my-test-dex/config.js.map +1 -0
  163. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  164. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  165. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  166. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  167. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  168. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  169. package/build/dex/my-test-dex/types.d.ts +6 -0
  170. package/build/dex/my-test-dex/types.js +3 -0
  171. package/build/dex/my-test-dex/types.js.map +1 -0
  172. package/build/dex/solidly/forks-override/fvm.d.ts +20 -0
  173. package/build/dex/solidly/forks-override/fvm.js +42 -0
  174. package/build/dex/solidly/forks-override/fvm.js.map +1 -0
  175. package/build/dex/swaap-v2/constants.d.ts +7 -3
  176. package/build/dex/swaap-v2/constants.js +8 -4
  177. package/build/dex/swaap-v2/constants.js.map +1 -1
  178. package/build/dex/swaap-v2/rate-fetcher.d.ts +2 -1
  179. package/build/dex/swaap-v2/rate-fetcher.js +25 -0
  180. package/build/dex/swaap-v2/rate-fetcher.js.map +1 -1
  181. package/build/dex/swaap-v2/swaap-v2.d.ts +4 -2
  182. package/build/dex/swaap-v2/swaap-v2.js +57 -20
  183. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  184. package/build/dex/swaap-v2/types.d.ts +8 -0
  185. package/build/dex/swaap-v2/utils.d.ts +3 -3
  186. package/build/dex/swaap-v2/utils.js +6 -8
  187. package/build/dex/swaap-v2/utils.js.map +1 -1
  188. package/build/dex/swaap-v2/validators.d.ts +1 -0
  189. package/build/dex/swaap-v2/validators.js +6 -1
  190. package/build/dex/swaap-v2/validators.js.map +1 -1
  191. package/build/dex/wombat/config.d.ts +5 -0
  192. package/build/dex/wombat/config.js +50 -0
  193. package/build/dex/wombat/config.js.map +1 -0
  194. package/build/dex/wombat/types.d.ts +33 -0
  195. package/build/dex/wombat/types.js +3 -0
  196. package/build/dex/wombat/types.js.map +1 -0
  197. package/build/dex/wombat/utils.d.ts +9 -0
  198. package/build/dex/wombat/utils.js +66 -0
  199. package/build/dex/wombat/utils.js.map +1 -0
  200. package/build/dex/wombat/wombat-bmw.d.ts +40 -0
  201. package/build/dex/wombat/wombat-bmw.js +145 -0
  202. package/build/dex/wombat/wombat-bmw.js.map +1 -0
  203. package/build/dex/wombat/wombat-pool.d.ts +22 -0
  204. package/build/dex/wombat/wombat-pool.js +161 -0
  205. package/build/dex/wombat/wombat-pool.js.map +1 -0
  206. package/build/dex/wombat/wombat-quoter.d.ts +16 -0
  207. package/build/dex/wombat/wombat-quoter.js +176 -0
  208. package/build/dex/wombat/wombat-quoter.js.map +1 -0
  209. package/build/dex/wombat/wombat.d.ts +55 -0
  210. package/build/dex/wombat/wombat.js +292 -0
  211. package/build/dex/wombat/wombat.js.map +1 -0
  212. package/package.json +1 -1
  213. package/src/dex/dexalot/dexalot.ts +48 -22
  214. package/src/dex/swaap-v2/constants.ts +11 -3
  215. package/src/dex/swaap-v2/rate-fetcher.ts +51 -1
  216. package/src/dex/swaap-v2/swaap-v2.ts +97 -43
  217. package/src/dex/swaap-v2/types.ts +10 -0
  218. package/src/dex/swaap-v2/utils.ts +9 -16
  219. package/src/dex/swaap-v2/validators.ts +6 -0
  220. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  221. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  222. package/build/dex/algebra/algebra-pool.js.map +0 -1
  223. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  224. package/build/dex/quickswap/camelot-v3.js +0 -19
  225. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  226. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  227. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  228. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
@@ -0,0 +1,26 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { IDexHelper } from '../../dex-helper/idex-helper';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { Address, Log, Logger } from '../../types';
6
+ import { LogDescription } from 'ethers/lib/utils';
7
+ import { FactoryState } from './types';
8
+ export declare type OnPoolCreatedCallback = ({ token0, token1, fee, }: {
9
+ token0: string;
10
+ token1: string;
11
+ fee: bigint;
12
+ }) => Promise<void>;
13
+ export declare class BaseswapV3Factory extends StatefulEventSubscriber<FactoryState> {
14
+ readonly dexHelper: IDexHelper;
15
+ protected readonly factoryAddress: Address;
16
+ protected readonly onPoolCreated: OnPoolCreatedCallback;
17
+ handlers: {
18
+ [event: string]: (event: any) => Promise<void>;
19
+ };
20
+ logDecoder: (log: Log) => any;
21
+ readonly factoryIface: Interface;
22
+ constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, logger: Logger, onPoolCreated: OnPoolCreatedCallback, mapKey?: string);
23
+ generateState(): FactoryState;
24
+ protected processLog(_: DeepReadonly<FactoryState>, log: Readonly<Log>): Promise<FactoryState>;
25
+ handleNewPool(event: LogDescription): Promise<void>;
26
+ }
@@ -0,0 +1,44 @@
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 });
6
+ exports.BaseswapV3Factory = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const UniswapV3Factory_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3Factory.abi.json"));
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ /*
11
+ * "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
12
+ * State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
13
+ */
14
+ class BaseswapV3Factory extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
+ constructor(dexHelper, parentName, factoryAddress, logger, onPoolCreated, mapKey = '') {
16
+ super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
17
+ this.dexHelper = dexHelper;
18
+ this.factoryAddress = factoryAddress;
19
+ this.onPoolCreated = onPoolCreated;
20
+ this.handlers = {};
21
+ this.factoryIface = new abi_1.Interface(UniswapV3Factory_abi_json_1.default);
22
+ this.addressesSubscribed = [factoryAddress];
23
+ this.logDecoder = (log) => this.factoryIface.parseLog(log);
24
+ this.handlers['PoolCreated'] = this.handleNewPool.bind(this);
25
+ }
26
+ generateState() {
27
+ return {};
28
+ }
29
+ async processLog(_, log) {
30
+ const event = this.logDecoder(log);
31
+ if (event.name in this.handlers) {
32
+ await this.handlers[event.name](event);
33
+ }
34
+ return {};
35
+ }
36
+ async handleNewPool(event) {
37
+ const token0 = event.args.token0.toLowerCase();
38
+ const token1 = event.args.token1.toLowerCase();
39
+ const fee = event.args.fee;
40
+ await this.onPoolCreated({ token0, token1, fee });
41
+ }
42
+ }
43
+ exports.BaseswapV3Factory = BaseswapV3Factory;
44
+ //# sourceMappingURL=baseswap-v3-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseswap-v3-factory.js","sourceRoot":"","sources":["../../../src/dex/baseswap-v3/baseswap-v3-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAE/C,+GAAwE;AAExE,+EAA0E;AAe1E;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,mDAAqC;IAS1E,YACW,SAAqB,EAC9B,UAAkB,EACC,cAAuB,EAC1C,MAAc,EACK,aAAoC,EACvD,SAAiB,EAAE;QAEnB,KAAK,CAAC,UAAU,EAAE,GAAG,UAAU,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAPnE,cAAS,GAAT,SAAS,CAAY;QAEX,mBAAc,GAAd,cAAc,CAAS;QAEvB,kBAAa,GAAb,aAAa,CAAuB;QAbzD,aAAQ,GAEJ,EAAE,CAAC;QAIS,iBAAY,GAAG,IAAI,eAAS,CAAC,mCAAU,CAAC,CAAC;QAYvD,IAAI,CAAC,mBAAmB,GAAG,CAAC,cAAc,CAAC,CAAC;QAE5C,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEhE,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC;IAED,aAAa;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,CAA6B,EAC7B,GAAkB;QAElB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;SACxC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAqB;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;QAE3B,MAAM,IAAI,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACpD,CAAC;CACF;AAjDD,8CAiDC"}
@@ -1,46 +1,46 @@
1
+ import { Contract } from 'web3-eth-contract';
1
2
  import { Interface } from '@ethersproject/abi';
2
3
  import { DeepReadonly } from 'ts-essentials';
3
- import { Address, BlockHeader, Log, Logger } from '../../types';
4
+ import { Log, Logger, BlockHeader, Address } from '../../types';
4
5
  import { InitializeStateOptions, StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
6
  import { IDexHelper } from '../../dex-helper/idex-helper';
6
- import { PoolState } from './types';
7
- import { Contract } from 'web3-eth-contract';
8
- import { DecodedStateMultiCallResultWithRelativeBitmaps } from './types';
9
- export declare class AlgebraEventPool extends StatefulEventSubscriber<PoolState> {
7
+ import { PoolState, DecodedStateMultiCallResultWithRelativeBitmaps, DecodeStateMultiCallFunc } from './types';
8
+ import { MultiCallParams } from '../../lib/multi-wrapper';
9
+ export declare class BaseswapV3EventPool extends StatefulEventSubscriber<PoolState> {
10
10
  readonly dexHelper: IDexHelper;
11
11
  readonly stateMultiContract: Contract;
12
+ readonly decodeStateMultiCallResultWithRelativeBitmaps: DecodeStateMultiCallFunc | undefined;
12
13
  readonly erc20Interface: Interface;
13
14
  protected readonly factoryAddress: Address;
15
+ feeCode: bigint;
14
16
  readonly poolInitCodeHash: string;
15
- readonly poolDeployer: string;
16
17
  handlers: {
17
- [event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>, blockHeader: BlockHeader) => DeepReadonly<PoolState> | null;
18
+ [event: string]: (event: any, pool: PoolState, log: Log, blockHeader: Readonly<BlockHeader>) => PoolState;
18
19
  };
19
20
  logDecoder: (log: Log) => any;
20
- addressesSubscribed: string[];
21
- private _poolAddress?;
22
21
  readonly token0: Address;
23
22
  readonly token1: Address;
23
+ private _poolAddress?;
24
+ protected _stateRequestCallData?: MultiCallParams<bigint | DecodedStateMultiCallResultWithRelativeBitmaps>[];
24
25
  readonly poolIface: Interface;
25
26
  initFailed: boolean;
26
27
  initRetryAttemptCount: number;
27
- constructor(dexHelper: IDexHelper, parentName: string, stateMultiContract: Contract, erc20Interface: Interface, factoryAddress: Address, token0: Address, token1: Address, logger: Logger, mapKey: string | undefined, poolInitCodeHash: string, poolDeployer: string);
28
+ feeCodeAsString: string;
29
+ constructor(dexHelper: IDexHelper, parentName: string, stateMultiContract: Contract, decodeStateMultiCallResultWithRelativeBitmaps: DecodeStateMultiCallFunc | undefined, erc20Interface: Interface, factoryAddress: Address, feeCode: bigint, token0: Address, token1: Address, logger: Logger, mapKey: string | undefined, poolInitCodeHash: string);
28
30
  get poolAddress(): Address;
29
31
  set poolAddress(address: Address);
30
32
  initialize(blockNumber: number, options?: InitializeStateOptions<PoolState>): Promise<void>;
31
33
  protected processBlockLogs(state: DeepReadonly<PoolState>, logs: Readonly<Log>[], blockHeader: Readonly<BlockHeader>): Promise<DeepReadonly<PoolState> | null>;
32
34
  protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PoolState> | null;
35
+ protected _getStateRequestCallData(): MultiCallParams<bigint | DecodedStateMultiCallResultWithRelativeBitmaps>[];
33
36
  getBitmapRangeToRequest(): bigint;
34
- private _fetchPoolStateSingleStep;
35
- private _fetchPoolStateMultiStep;
36
- _fetchInitStateMultiStrategies(blockNumber: number): Promise<[bigint, bigint, DecodedStateMultiCallResultWithRelativeBitmaps]>;
37
37
  generateState(blockNumber: number): Promise<Readonly<PoolState>>;
38
38
  handleSwapEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
39
- handleMintEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
40
39
  handleBurnEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
41
- handleNewFee(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
40
+ handleMintEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
41
+ handleSetFeeProtocolEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
42
42
  handleCollectEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
43
43
  handleFlashEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
44
- handleCommunityFee(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
44
+ handleIncreaseObservationCardinalityNextEvent(event: any, pool: PoolState, log: Log, blockHeader: BlockHeader): PoolState;
45
45
  private _computePoolAddress;
46
46
  }
@@ -3,50 +3,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AlgebraEventPool = void 0;
6
+ exports.BaseswapV3EventPool = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const abi_1 = require("@ethersproject/abi");
9
+ const ethers_1 = require("ethers");
9
10
  const ts_essentials_1 = require("ts-essentials");
10
- const utils_1 = require("../../utils");
11
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");
12
+ const UniswapV3Pool_abi_json_1 = __importDefault(require("../../abi/uniswap-v3/UniswapV3Pool.abi.json"));
13
+ const utils_1 = require("../../utils");
14
+ const uniswap_v3_math_1 = require("./contract-math/uniswap-v3-math");
15
+ const constants_1 = require("./constants");
16
+ const TickBitMap_1 = require("./contract-math/TickBitMap");
15
17
  const decoders_1 = require("../../lib/decoders");
16
18
  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");
22
- 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);
19
+ const utils_3 = require("./contract-math/utils");
20
+ class BaseswapV3EventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
21
+ constructor(dexHelper, parentName, stateMultiContract, decodeStateMultiCallResultWithRelativeBitmaps, erc20Interface, factoryAddress, feeCode, token0, token1, logger, mapKey = '', poolInitCodeHash) {
22
+ super(parentName, `${token0}_${token1}_${feeCode}`, dexHelper, logger, true, mapKey);
25
23
  this.dexHelper = dexHelper;
26
24
  this.stateMultiContract = stateMultiContract;
25
+ this.decodeStateMultiCallResultWithRelativeBitmaps = decodeStateMultiCallResultWithRelativeBitmaps;
27
26
  this.erc20Interface = erc20Interface;
28
27
  this.factoryAddress = factoryAddress;
28
+ this.feeCode = feeCode;
29
29
  this.poolInitCodeHash = poolInitCodeHash;
30
- this.poolDeployer = poolDeployer;
31
30
  this.handlers = {};
32
- this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
31
+ this.poolIface = new abi_1.Interface(UniswapV3Pool_abi_json_1.default);
33
32
  this.initFailed = false;
34
33
  this.initRetryAttemptCount = 0;
34
+ this.feeCodeAsString = feeCode.toString();
35
35
  this.token0 = token0.toLowerCase();
36
36
  this.token1 = token1.toLowerCase();
37
37
  this.logDecoder = (log) => this.poolIface.parseLog(log);
38
38
  this.addressesSubscribed = new Array(1);
39
- this.handlers['Fee'] = this.handleNewFee.bind(this);
39
+ // Add handlers
40
40
  this.handlers['Swap'] = this.handleSwapEvent.bind(this);
41
- this.handlers['Mint'] = this.handleMintEvent.bind(this);
42
41
  this.handlers['Burn'] = this.handleBurnEvent.bind(this);
43
- this.handlers['Flash'] = this.handleFlashEvent.bind(this);
42
+ this.handlers['Mint'] = this.handleMintEvent.bind(this);
43
+ this.handlers['SetFeeProtocol'] = this.handleSetFeeProtocolEvent.bind(this);
44
+ this.handlers['IncreaseObservationCardinalityNext'] =
45
+ this.handleIncreaseObservationCardinalityNextEvent.bind(this);
46
+ // Wen need them to keep balance of the pool up to date
44
47
  this.handlers['Collect'] = this.handleCollectEvent.bind(this);
45
- this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
48
+ // Almost the same as Collect, but for pool owners
49
+ this.handlers['CollectProtocol'] = this.handleCollectEvent.bind(this);
50
+ this.handlers['Flash'] = this.handleFlashEvent.bind(this);
46
51
  }
47
52
  get poolAddress() {
48
53
  if (this._poolAddress === undefined) {
49
- this._poolAddress = this._computePoolAddress(this.token0, this.token1);
54
+ this._poolAddress = this._computePoolAddress(this.token0, this.token1, this.feeCode);
50
55
  }
51
56
  return this._poolAddress;
52
57
  }
@@ -66,14 +71,19 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
66
71
  processLog(state, log, blockHeader) {
67
72
  try {
68
73
  const event = this.logDecoder(log);
74
+ const uniswapV3EventLoggingSampleRate = this.dexHelper.config.data.uniswapV3EventLoggingSampleRate;
75
+ if (!this.dexHelper.config.isSlave &&
76
+ uniswapV3EventLoggingSampleRate &&
77
+ (0, utils_1.isSampled)(uniswapV3EventLoggingSampleRate)) {
78
+ this.logger.info(`event=${event.name} - block=${blockHeader.number}. Log sampled at rate ${uniswapV3EventLoggingSampleRate * 100}%`);
79
+ }
69
80
  if (event.name in this.handlers) {
70
81
  // Because we have observations in array which is mutable by nature, there is a
71
82
  // ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
72
83
  // And there is no good workaround, so turn off the type checker for this line
73
84
  const _state = lodash_1.default.cloneDeep(state);
74
85
  try {
75
- const newState = this.handlers[event.name](event, _state, log, blockHeader);
76
- return newState;
86
+ return this.handlers[event.name](event, _state, log, blockHeader);
77
87
  }
78
88
  catch (e) {
79
89
  if (e instanceof Error &&
@@ -84,7 +94,7 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
84
94
  this.logger.error(`${this.parentName}: Pool ${this.poolAddress}, ` +
85
95
  `network=${this.dexHelper.config.data.network}: Unexpected ` +
86
96
  `error while handling event on blockNumber=${blockHeader.number}, ` +
87
- `blockHash=${blockHeader.hash} and parentHash=${blockHeader.parentHash} for QuickSwapV3, ${JSON.stringify(event)}`, e);
97
+ `blockHash=${blockHeader.hash} and parentHash=${blockHeader.parentHash} for UniswapV3, ${JSON.stringify(event)}`, e);
88
98
  }
89
99
  _state.isValid = false;
90
100
  return _state;
@@ -96,135 +106,99 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
96
106
  }
97
107
  return null; // ignore unrecognized event
98
108
  }
109
+ _getStateRequestCallData() {
110
+ if (!this._stateRequestCallData) {
111
+ const callData = [
112
+ {
113
+ target: this.token0,
114
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
115
+ this.poolAddress,
116
+ ]),
117
+ decodeFunction: decoders_1.uint256ToBigInt,
118
+ },
119
+ {
120
+ target: this.token1,
121
+ callData: this.erc20Interface.encodeFunctionData('balanceOf', [
122
+ this.poolAddress,
123
+ ]),
124
+ decodeFunction: decoders_1.uint256ToBigInt,
125
+ },
126
+ {
127
+ target: this.stateMultiContract.options.address,
128
+ callData: this.stateMultiContract.methods
129
+ .getFullStateWithRelativeBitmaps(this.factoryAddress, this.token0, this.token1, this.feeCode, this.getBitmapRangeToRequest(), this.getBitmapRangeToRequest())
130
+ .encodeABI(),
131
+ decodeFunction: this.decodeStateMultiCallResultWithRelativeBitmaps !== undefined
132
+ ? this.decodeStateMultiCallResultWithRelativeBitmaps
133
+ : utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
134
+ },
135
+ ];
136
+ this._stateRequestCallData = callData;
137
+ }
138
+ return this._stateRequestCallData;
139
+ }
99
140
  getBitmapRangeToRequest() {
100
141
  return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
101
142
  }
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
- ];
143
+ async generateState(blockNumber) {
144
+ const callData = this._getStateRequestCallData();
126
145
  const [resBalance0, resBalance1, resState] = await this.dexHelper.multiWrapper.tryAggregate(false, callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
146
+ // Quite ugly solution, but this is the one that fits to current flow.
147
+ // I think UniswapV3 callbacks subscriptions are complexified for no reason.
148
+ // Need to be revisited later
127
149
  (0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
128
150
  const [balance0, balance1, _state] = [
129
151
  resBalance0.returnData,
130
152
  resBalance1.returnData,
131
153
  resState.returnData,
132
154
  ];
133
- return [balance0, balance1, _state];
134
- }
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];
183
- }
184
- async _fetchInitStateMultiStrategies(blockNumber) {
185
- try {
186
- return await this._fetchPoolStateSingleStep(blockNumber);
187
- }
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);
194
- }
195
- }
196
- async generateState(blockNumber) {
197
- const [balance0, balance1, _state] = await this._fetchInitStateMultiStrategies(blockNumber);
198
155
  const tickBitmap = {};
199
156
  const ticks = {};
200
157
  (0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
201
158
  (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),
159
+ const observations = {
160
+ [_state.slot0.observationIndex]: {
161
+ blockTimestamp: (0, utils_1.bigIntify)(_state.observation.blockTimestamp),
162
+ tickCumulative: (0, utils_1.bigIntify)(_state.observation.tickCumulative),
163
+ secondsPerLiquidityCumulativeX128: (0, utils_1.bigIntify)(_state.observation.secondsPerLiquidityCumulativeX128),
164
+ initialized: _state.observation.initialized,
165
+ },
208
166
  };
209
- const currentTick = globalState.tick;
210
- const startTickBitmap = TickBitMap_1.TickBitMap.position(BigInt(currentTick) / Constants_1.Constants.TICK_SPACING)[0];
167
+ const currentTick = (0, utils_1.bigIntify)(_state.slot0.tick);
168
+ const tickSpacing = (0, utils_1.bigIntify)(_state.tickSpacing);
169
+ const startTickBitmap = TickBitMap_1.TickBitMap.position(currentTick / tickSpacing)[0];
170
+ const requestedRange = this.getBitmapRangeToRequest();
211
171
  return {
212
172
  pool: _state.pool,
213
173
  blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
214
- globalState,
174
+ slot0: {
175
+ sqrtPriceX96: (0, utils_1.bigIntify)(_state.slot0.sqrtPriceX96),
176
+ tick: currentTick,
177
+ observationIndex: +_state.slot0.observationIndex,
178
+ observationCardinality: +_state.slot0.observationCardinality,
179
+ observationCardinalityNext: +_state.slot0.observationCardinalityNext,
180
+ feeProtocol: (0, utils_1.bigIntify)(_state.slot0.feeProtocol),
181
+ },
215
182
  liquidity: (0, utils_1.bigIntify)(_state.liquidity),
216
- tickSpacing: Constants_1.Constants.TICK_SPACING,
217
- maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
183
+ fee: this.feeCode,
184
+ tickSpacing,
185
+ maxLiquidityPerTick: (0, utils_1.bigIntify)(_state.maxLiquidityPerTick),
218
186
  tickBitmap,
219
187
  ticks,
220
- startTickBitmap,
188
+ observations,
221
189
  isValid: true,
190
+ startTickBitmap,
191
+ lowestKnownTick: (BigInt.asIntN(24, startTickBitmap - requestedRange) << 8n) *
192
+ tickSpacing,
193
+ highestKnownTick: ((BigInt.asIntN(24, startTickBitmap + requestedRange) << 8n) +
194
+ BigInt.asIntN(24, 255n)) *
195
+ tickSpacing,
222
196
  balance0,
223
197
  balance1,
224
198
  };
225
199
  }
226
200
  handleSwapEvent(event, pool, log, blockHeader) {
227
- const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
201
+ const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.sqrtPriceX96);
228
202
  const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
229
203
  const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
230
204
  const newTick = (0, utils_1.bigIntify)(event.args.tick);
@@ -238,7 +212,7 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
238
212
  }
239
213
  else {
240
214
  const zeroForOne = amount0 > 0n;
241
- const [, , , , , communityFee] = AlgebraMath_1.AlgebraMath._calculateSwapAndLock(pool, zeroForOne, newSqrtPriceX96, newTick, newLiquidity);
215
+ uniswap_v3_math_1.uniswapV3Math.swapFromEvent(pool, newSqrtPriceX96, newTick, newLiquidity, zeroForOne);
242
216
  if (zeroForOne) {
243
217
  if (amount1 < 0n) {
244
218
  pool.balance1 -= BigInt.asUintN(256, -amount1);
@@ -261,42 +235,47 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
261
235
  }
262
236
  pool.balance1 += BigInt.asUintN(256, amount1);
263
237
  }
264
- if (communityFee > 0n) {
265
- // _payCommunityFee
266
- if (zeroForOne) {
267
- pool.balance0 -= communityFee;
268
- }
269
- else {
270
- pool.balance1 -= communityFee;
271
- }
272
- }
273
238
  return pool;
274
239
  }
275
240
  }
241
+ handleBurnEvent(event, pool, log, blockHeader) {
242
+ const amount = (0, utils_1.bigIntify)(event.args.amount);
243
+ const tickLower = (0, utils_1.bigIntify)(event.args.tickLower);
244
+ const tickUpper = (0, utils_1.bigIntify)(event.args.tickUpper);
245
+ pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
246
+ uniswap_v3_math_1.uniswapV3Math._modifyPosition(pool, {
247
+ tickLower,
248
+ tickUpper,
249
+ liquidityDelta: -BigInt.asIntN(128, BigInt.asIntN(256, amount)),
250
+ });
251
+ // From this transaction I conclude that there is no balance change from
252
+ // Burn event: https://dashboard.tenderly.co/tx/mainnet/0xfccf5341147ac3ad0e66452273d12dfc3219e81f8fb369a6cdecfb24b9b9d078/logs
253
+ // And it aligns with UniswapV3 doc:
254
+ // https://github.com/Uniswap/v3-core/blob/05c10bf6d547d6121622ac51c457f93775e1df09/contracts/interfaces/pool/IUniswapV3PoolActions.sol#L59
255
+ // It just updates positions and tokensOwed which may be requested calling collect
256
+ // So, we don't need to update pool.balances0 and pool.balances1 here
257
+ return pool;
258
+ }
276
259
  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);
260
+ const amount = (0, utils_1.bigIntify)(event.args.amount);
261
+ const tickLower = (0, utils_1.bigIntify)(event.args.tickLower);
262
+ const tickUpper = (0, utils_1.bigIntify)(event.args.tickUpper);
280
263
  const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
281
264
  const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
282
265
  pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
283
- AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(pool, bottomTick, topTick, liquidityActual);
266
+ uniswap_v3_math_1.uniswapV3Math._modifyPosition(pool, {
267
+ tickLower,
268
+ tickUpper,
269
+ liquidityDelta: amount,
270
+ });
284
271
  pool.balance0 += amount0;
285
272
  pool.balance1 += amount1;
286
273
  return pool;
287
274
  }
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;
275
+ handleSetFeeProtocolEvent(event, pool, log, blockHeader) {
276
+ const feeProtocol0 = (0, utils_1.bigIntify)(event.args.feeProtocol0New);
277
+ const feeProtocol1 = (0, utils_1.bigIntify)(event.args.feeProtocol1New);
278
+ pool.slot0.feeProtocol = feeProtocol0 + (feeProtocol1 << 4n);
300
279
  pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
301
280
  return pool;
302
281
  }
@@ -316,21 +295,18 @@ class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscrib
316
295
  pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
317
296
  return pool;
318
297
  }
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;
298
+ handleIncreaseObservationCardinalityNextEvent(event, pool, log, blockHeader) {
299
+ pool.slot0.observationCardinalityNext = parseInt(event.args.observationCardinalityNextNew, 10);
324
300
  pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
325
301
  return pool;
326
302
  }
327
- _computePoolAddress(token0, token1) {
303
+ _computePoolAddress(token0, token1, fee) {
328
304
  // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
329
305
  if (token0 > token1)
330
306
  [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);
307
+ const encodedKey = ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(['address', 'address', 'uint24'], [token0, token1, BigInt.asUintN(24, fee)]));
308
+ return ethers_1.ethers.utils.getCreate2Address(this.factoryAddress, encodedKey, this.poolInitCodeHash);
333
309
  }
334
310
  }
335
- exports.AlgebraEventPool = AlgebraEventPool;
336
- //# sourceMappingURL=algebra-pool.js.map
311
+ exports.BaseswapV3EventPool = BaseswapV3EventPool;
312
+ //# sourceMappingURL=baseswap-v3-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseswap-v3-pool.js","sourceRoot":"","sources":["../../../src/dex/baseswap-v3/baseswap-v3-pool.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,4CAA+C;AAC/C,mCAAgC;AAChC,iDAAqD;AAErD,+EAGyC;AAOzC,yGAA2E;AAC3E,uCAAuE;AACvE,qEAAgE;AAEhE,2CAIqB;AACrB,2DAAwD;AACxD,iDAAqD;AACrD,mCAAwE;AACxE,iDAAwE;AAExE,MAAa,mBAAoB,SAAQ,mDAAkC;IA6BzE,YACW,SAAqB,EAC9B,UAAkB,EACT,kBAA4B,EAC5B,6CAEI,EACJ,cAAyB,EACf,cAAuB,EACnC,OAAe,EACtB,MAAe,EACf,MAAe,EACf,MAAc,EACd,SAAiB,EAAE,EACV,gBAAwB;QAEjC,KAAK,CACH,UAAU,EACV,GAAG,MAAM,IAAI,MAAM,IAAI,OAAO,EAAE,EAChC,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,CACP,CAAC;QAtBO,cAAS,GAAT,SAAS,CAAY;QAErB,uBAAkB,GAAlB,kBAAkB,CAAU;QAC5B,kDAA6C,GAA7C,6CAA6C,CAEzC;QACJ,mBAAc,GAAd,cAAc,CAAW;QACf,mBAAc,GAAd,cAAc,CAAS;QACnC,YAAO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