@paraswap/dex-lib 2.36.0 → 2.36.2-cache-invalidation

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 (250) hide show
  1. package/build/abi/api3-proxy.json +7 -0
  2. package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  3. package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
  4. package/build/dex/algebra/algebra-factory.d.ts +25 -0
  5. package/build/dex/algebra/algebra-factory.js +43 -0
  6. package/build/dex/algebra/algebra-factory.js.map +1 -0
  7. package/build/dex/algebra/algebra.d.ts +3 -0
  8. package/build/dex/algebra/algebra.js +27 -5
  9. package/build/dex/algebra/algebra.js.map +1 -1
  10. package/build/dex/algebra/config.js +0 -1
  11. package/build/dex/algebra/config.js.map +1 -1
  12. package/build/dex/algebra/types.d.ts +1 -1
  13. package/build/dex/balancer-v2/config.js +1 -1
  14. package/build/dex/curve-v1/config.js +40 -38
  15. package/build/dex/curve-v1/config.js.map +1 -1
  16. package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
  17. package/build/dex/hello/config.js +15 -0
  18. package/build/dex/hello/config.js.map +1 -0
  19. package/build/dex/hello/hello-pool.d.ts +39 -0
  20. package/build/dex/hello/hello-pool.js +64 -0
  21. package/build/dex/hello/hello-pool.js.map +1 -0
  22. package/build/dex/hello/hello.d.ts +37 -0
  23. package/build/dex/hello/hello.js +126 -0
  24. package/build/dex/hello/hello.js.map +1 -0
  25. package/build/dex/hello/types.d.ts +6 -0
  26. package/build/dex/{woo-fi → hello}/types.js.map +1 -1
  27. package/build/dex/{ramses-v2 → my-test-dex}/config.d.ts +1 -1
  28. package/build/dex/my-test-dex/config.js +15 -0
  29. package/build/dex/my-test-dex/config.js.map +1 -0
  30. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  31. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  32. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  33. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  34. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  35. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  36. package/build/dex/my-test-dex/types.d.ts +6 -0
  37. package/build/dex/{pancakeswap-v3 → my-test-dex}/types.js.map +1 -1
  38. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
  39. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
  40. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
  41. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
  42. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
  43. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  44. package/build/dex/quick-perps/pool.js +21 -6
  45. package/build/dex/quick-perps/pool.js.map +1 -1
  46. package/build/dex/quick-perps/quick-perps.js +34 -28
  47. package/build/dex/quick-perps/quick-perps.js.map +1 -1
  48. package/build/dex/solidly/config.js +1 -1
  49. package/build/dex/solidly/forks-override/aerodrome.js.map +1 -1
  50. package/build/dex/uniswap-v3/config.js.map +1 -1
  51. package/build/dex/uniswap-v3/types.d.ts +1 -0
  52. package/build/dex/uniswap-v3/types.js.map +1 -1
  53. package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
  54. package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
  55. package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
  56. package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
  57. package/build/dex/uniswap-v3/uniswap-v3.js +26 -2
  58. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  59. package/build/dex-helper/dummy-dex-helper.js +3 -0
  60. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  61. package/build/dex-helper/icache.d.ts +1 -0
  62. package/build/lib/api3-feed.d.ts +4 -0
  63. package/build/lib/api3-feed.js +18 -0
  64. package/build/lib/api3-feed.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/abi/api3-proxy.json +7 -0
  67. package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  68. package/src/dex/algebra/algebra-factory.ts +70 -0
  69. package/src/dex/algebra/algebra.ts +47 -6
  70. package/src/dex/algebra/config.ts +0 -1
  71. package/src/dex/algebra/types.ts +2 -1
  72. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +6 -8
  73. package/src/dex/balancer-v2/config.ts +1 -1
  74. package/src/dex/curve-v1/config.ts +40 -38
  75. package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +1 -7
  76. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +1 -7
  77. package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
  78. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
  79. package/src/dex/quick-perps/pool.ts +42 -7
  80. package/src/dex/quick-perps/quick-perps-events.test.ts +0 -1
  81. package/src/dex/quick-perps/quick-perps.ts +45 -35
  82. package/src/dex/solidly/config.ts +1 -1
  83. package/src/dex/solidly/forks-override/aerodrome.ts +1 -5
  84. package/src/dex/uniswap-v3/config.ts +1 -2
  85. package/src/dex/uniswap-v3/types.ts +2 -0
  86. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +1 -7
  87. package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
  88. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +0 -2
  89. package/src/dex/uniswap-v3/uniswap-v3.ts +47 -2
  90. package/src/dex-helper/dummy-dex-helper.ts +4 -0
  91. package/src/dex-helper/icache.ts +2 -0
  92. package/src/lib/api3-feed.ts +35 -0
  93. package/.idea/aws.xml +0 -17
  94. package/.idea/codeStyles/Project.xml +0 -19
  95. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  96. package/.idea/misc.xml +0 -6
  97. package/.idea/modules.xml +0 -8
  98. package/.idea/paraswap-dex-lib.iml +0 -9
  99. package/.idea/vcs.xml +0 -6
  100. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  101. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  102. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  103. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  104. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  105. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  106. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  107. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  108. package/build/abi/wBETH.json +0 -1527
  109. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  110. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  111. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  112. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  113. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  114. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  115. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  116. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  117. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  118. package/build/dex/algebra/algebra-pool.js +0 -336
  119. package/build/dex/algebra/algebra-pool.js.map +0 -1
  120. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  121. package/build/dex/balancer-v2/LinearMath.js +0 -179
  122. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  123. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  124. package/build/dex/balancer-v2/LinearPool.js +0 -324
  125. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  126. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  127. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  128. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  129. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  130. package/build/dex/balancer-v2/StableMath.js +0 -272
  131. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  132. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  133. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  134. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  135. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  136. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  137. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  138. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  139. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  140. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  141. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  142. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  143. package/build/dex/quickswap/camelot-v3.js +0 -19
  144. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  145. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  146. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  147. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  148. package/build/dex/quickswap-v3.d.ts +0 -21
  149. package/build/dex/quickswap-v3.js +0 -40
  150. package/build/dex/quickswap-v3.js.map +0 -1
  151. package/build/dex/ramses-v2/config.js +0 -28
  152. package/build/dex/ramses-v2/config.js.map +0 -1
  153. package/build/dex/ramses-v2/constants.d.ts +0 -28
  154. package/build/dex/ramses-v2/constants.js +0 -35
  155. package/build/dex/ramses-v2/constants.js.map +0 -1
  156. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  157. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  158. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  159. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  160. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  161. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  162. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  163. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  164. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  165. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  166. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  167. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  168. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  169. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  170. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  171. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  172. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  173. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  174. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  175. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  176. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  177. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  178. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  179. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  180. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  181. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  182. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  183. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  184. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  185. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  186. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  187. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  188. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  189. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  190. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  191. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  192. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  193. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  194. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  195. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  196. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  197. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  198. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  199. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  200. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  201. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  202. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  203. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  204. package/build/dex/ramses-v2/types.d.ts +0 -154
  205. package/build/dex/ramses-v2/types.js +0 -9
  206. package/build/dex/ramses-v2/types.js.map +0 -1
  207. package/build/dex/ramses-v2/utils.d.ts +0 -6
  208. package/build/dex/ramses-v2/utils.js +0 -71
  209. package/build/dex/ramses-v2/utils.js.map +0 -1
  210. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  211. package/build/dex/sushiswap-v3/config.js +0 -132
  212. package/build/dex/sushiswap-v3/config.js.map +0 -1
  213. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  214. package/build/dex/sushiswap-v3/constants.js +0 -32
  215. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  216. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  217. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  218. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  219. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  220. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  221. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  222. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  223. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  224. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  225. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  226. package/build/dex/sushiswap-v3/token.js +0 -23
  227. package/build/dex/sushiswap-v3/token.js.map +0 -1
  228. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  229. package/build/dex/sushiswap-v3/types.js +0 -18
  230. package/build/dex/sushiswap-v3/types.js.map +0 -1
  231. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  232. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  233. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  234. package/build/dex/woo-fi/config.js +0 -141
  235. package/build/dex/woo-fi/config.js.map +0 -1
  236. package/build/dex/woo-fi/constants.d.ts +0 -5
  237. package/build/dex/woo-fi/constants.js +0 -20
  238. package/build/dex/woo-fi/constants.js.map +0 -1
  239. package/build/dex/woo-fi/types.d.ts +0 -48
  240. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  241. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  242. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  243. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  244. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  245. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  246. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  247. package/build/dex/woo-fi/woo-fi.js +0 -480
  248. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  249. /package/build/dex/{pancakeswap-v3 → hello}/types.js +0 -0
  250. /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
@@ -53,6 +53,8 @@ export type PoolState = {
53
53
  balance1: bigint;
54
54
  };
55
55
 
56
+ export type FactoryState = Record<string, never>;
57
+
56
58
  export type UniswapV3Data = {
57
59
  path: {
58
60
  tokenIn: Address;
@@ -429,13 +429,7 @@ describe('UniswapV3 E2E', () => {
429
429
  ContractMethod.megaSwap,
430
430
  ],
431
431
  ],
432
- [
433
- SwapSide.BUY,
434
- [
435
- ContractMethod.simpleBuy,
436
- ContractMethod.buy
437
- ],
438
- ],
432
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
439
433
  ]);
440
434
 
441
435
  sideToContractMethods.forEach((contractMethods, side) =>
@@ -0,0 +1,73 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import FactoryABI from '../../abi/uniswap-v3/UniswapV3Factory.abi.json';
4
+ import { IDexHelper } from '../../dex-helper/idex-helper';
5
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
+ import { Address, Log, Logger } from '../../types';
7
+ import { LogDescription } from 'ethers/lib/utils';
8
+ import { FactoryState } from './types';
9
+
10
+ export type OnPoolCreatedCallback = ({
11
+ token0,
12
+ token1,
13
+ fee,
14
+ }: {
15
+ token0: string;
16
+ token1: string;
17
+ fee: bigint;
18
+ }) => Promise<void>;
19
+
20
+ /*
21
+ * "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
22
+ * 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)
23
+ */
24
+ export class UniswapV3Factory extends StatefulEventSubscriber<FactoryState> {
25
+ handlers: {
26
+ [event: string]: (event: any) => Promise<void>;
27
+ } = {};
28
+
29
+ logDecoder: (log: Log) => any;
30
+
31
+ public readonly factoryIface = new Interface(FactoryABI);
32
+
33
+ constructor(
34
+ readonly dexHelper: IDexHelper,
35
+ parentName: string,
36
+ protected readonly factoryAddress: Address,
37
+ logger: Logger,
38
+ protected readonly onPoolCreated: OnPoolCreatedCallback,
39
+ mapKey: string = '',
40
+ ) {
41
+ super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
42
+
43
+ this.addressesSubscribed = [factoryAddress];
44
+
45
+ this.logDecoder = (log: Log) => this.factoryIface.parseLog(log);
46
+
47
+ this.handlers['PoolCreated'] = this.handleNewPool.bind(this);
48
+ }
49
+
50
+ generateState(): FactoryState {
51
+ return {};
52
+ }
53
+
54
+ protected async processLog(
55
+ _: DeepReadonly<FactoryState>,
56
+ log: Readonly<Log>,
57
+ ): Promise<FactoryState> {
58
+ const event = this.logDecoder(log);
59
+ if (event.name in this.handlers) {
60
+ await this.handlers[event.name](event);
61
+ }
62
+
63
+ return {};
64
+ }
65
+
66
+ async handleNewPool(event: LogDescription) {
67
+ const token0 = event.args.token0;
68
+ const token1 = event.args.token1;
69
+ const fee = event.args.fee;
70
+
71
+ await this.onPoolCreated({ token0, token1, fee });
72
+ }
73
+ }
@@ -1099,6 +1099,4 @@ describe('SushiSwapV3', () => {
1099
1099
  checkPoolsLiquidity(poolLiquidity, TokenB.address, dexKey);
1100
1100
  });
1101
1101
  });
1102
-
1103
1102
  });
1104
-
@@ -64,6 +64,7 @@ import {
64
64
  DEFAULT_ID_ERC20_AS_STRING,
65
65
  } from '../../lib/tokens/types';
66
66
  import { OptimalSwapExchange } from '@paraswap/core';
67
+ import { OnPoolCreatedCallback, UniswapV3Factory } from './uniswap-v3-factory';
67
68
 
68
69
  type PoolPairsInfo = {
69
70
  token0: Address;
@@ -71,14 +72,15 @@ type PoolPairsInfo = {
71
72
  fee: string;
72
73
  };
73
74
 
74
- const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 60 * 60 * 24 * 1000; // 24 hours
75
- const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 30 * 60 * 1000; // Once in 30 minutes
75
+ const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
76
+ const UNISWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
76
77
  const UNISWAPV3_QUOTE_GASLIMIT = 200_000;
77
78
 
78
79
  export class UniswapV3
79
80
  extends SimpleExchange
80
81
  implements IDex<UniswapV3Data, UniswapV3Param>
81
82
  {
83
+ private readonly factory: UniswapV3Factory;
82
84
  readonly isFeeOnTransferSupported: boolean = false;
83
85
  readonly eventPools: Record<string, UniswapV3EventPool | null> = {};
84
86
 
@@ -138,6 +140,14 @@ export class UniswapV3
138
140
 
139
141
  this.notExistingPoolSetKey =
140
142
  `${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
143
+
144
+ this.factory = new UniswapV3Factory(
145
+ dexHelper,
146
+ dexKey,
147
+ this.config.factory,
148
+ this.logger,
149
+ this.onPoolCreatedDeleteFromNonExistingSet.bind(this),
150
+ );
141
151
  }
142
152
 
143
153
  get supportedFees() {
@@ -154,6 +164,9 @@ export class UniswapV3
154
164
  }
155
165
 
156
166
  async initializePricing(blockNumber: number) {
167
+ // Init listening to new pools creation
168
+ await this.factory.initialize(blockNumber);
169
+
157
170
  // This is only for testing, because cold pool fetching is goes out of
158
171
  // FETCH_POOL_INDENTIFIER_TIMEOUT range
159
172
  await Promise.all(
@@ -184,6 +197,38 @@ export class UniswapV3
184
197
  }
185
198
  }
186
199
 
200
+ /*
201
+ * When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
202
+ * Once the pool is created, it gets immediately flagged
203
+ */
204
+ onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback = async ({
205
+ token0,
206
+ token1,
207
+ fee,
208
+ }) => {
209
+ const logPrefix = '[UniswapV3.onPoolCreatedDeleteFromNonExistingSet]';
210
+ const [_token0, _token1] = this._sortTokens(token0, token1);
211
+ const poolKey = `${token0}_${token1}_${fee}`.toLowerCase();
212
+
213
+ // consider doing it only from master pool for less calls to distant cache
214
+
215
+ // delete entry locally to let local instance discover the pool
216
+ delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
217
+
218
+ try {
219
+ this.logger.info(
220
+ `${logPrefix} delete pool from not existing set: ${poolKey}`,
221
+ );
222
+ // delete pool record from set
223
+ await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
224
+ } catch (error) {
225
+ this.logger.error(
226
+ `${logPrefix} failed to delete pool from set: ${poolKey}`,
227
+ error,
228
+ );
229
+ }
230
+ };
231
+
187
232
  async getPool(
188
233
  srcAddress: Address,
189
234
  destAddress: Address,
@@ -115,6 +115,10 @@ class DummyCache implements ICache {
115
115
  return 0;
116
116
  }
117
117
 
118
+ async zrem(key: string, membersKeys: string[]): Promise<number> {
119
+ return 0;
120
+ }
121
+
118
122
  async zadd(key: string, bulkItemsToAdd: (number | string)[], option?: 'NX') {
119
123
  return 0;
120
124
  }
@@ -46,6 +46,8 @@ export interface ICache {
46
46
 
47
47
  zremrangebyscore(key: string, min: number, max: number): Promise<number>;
48
48
 
49
+ zrem(key: string, membersKeys: string[]): Promise<number>;
50
+
49
51
  zscore(setKey: string, key: string): Promise<string | null>;
50
52
 
51
53
  sismember(setKey: string, key: string): Promise<boolean>;
@@ -51,6 +51,14 @@ export class Api3FeedSubscriber<State> extends PartialEventSubscriber<
51
51
  };
52
52
  }
53
53
 
54
+ static getDapiNameHashMultiCallInput(proxy: Address): MultiCallInput {
55
+ return {
56
+ target: proxy,
57
+ callData:
58
+ Api3FeedSubscriber.proxyInterface.encodeFunctionData('dapiNameHash'),
59
+ };
60
+ }
61
+
54
62
  static getDataFeedId(proxy: Address): MultiCallInput {
55
63
  return {
56
64
  target: proxy,
@@ -59,6 +67,33 @@ export class Api3FeedSubscriber<State> extends PartialEventSubscriber<
59
67
  };
60
68
  }
61
69
 
70
+ static getFeedIdFromDapiNameHash(
71
+ api3Server: Address,
72
+ dapiNameHash: string,
73
+ ): MultiCallInput {
74
+ return {
75
+ target: api3Server,
76
+ callData: Api3FeedSubscriber.api3ServerV1Iface.encodeFunctionData(
77
+ 'dapiNameHashToDataFeedId',
78
+ [dapiNameHash],
79
+ ),
80
+ };
81
+ }
82
+
83
+ static decodeFeedIdFromDapiNameHash(multicallOutput: MultiCallOutput) {
84
+ return Api3FeedSubscriber.api3ServerV1Iface.decodeFunctionResult(
85
+ 'dapiNameHashToDataFeedId',
86
+ multicallOutput,
87
+ )[0];
88
+ }
89
+
90
+ static decodeDapiNameHash(multicallOutput: MultiCallOutput) {
91
+ return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
92
+ 'dapiNameHash',
93
+ multicallOutput,
94
+ )[0];
95
+ }
96
+
62
97
  static decodeDataFeedId(multicallOutput: MultiCallOutput) {
63
98
  return Api3FeedSubscriber.proxyInterface.decodeFunctionResult(
64
99
  'dataFeedId',
package/.idea/aws.xml DELETED
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="accountSettings">
4
- <option name="activeProfile" value="profile:default" />
5
- <option name="activeRegion" value="us-east-1" />
6
- <option name="recentlyUsedProfiles">
7
- <list>
8
- <option value="profile:default" />
9
- </list>
10
- </option>
11
- <option name="recentlyUsedRegions">
12
- <list>
13
- <option value="us-east-1" />
14
- </list>
15
- </option>
16
- </component>
17
- </project>
@@ -1,19 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <ScalaCodeStyleSettings>
4
- <option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
5
- </ScalaCodeStyleSettings>
6
- <TypeScriptCodeStyleSettings version="0">
7
- <option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACKETS" value="true" />
8
- <option name="USE_DOUBLE_QUOTES" value="false" />
9
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
10
- </TypeScriptCodeStyleSettings>
11
- <codeStyleSettings language="TypeScript">
12
- <indentOptions>
13
- <option name="INDENT_SIZE" value="2" />
14
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
15
- <option name="TAB_SIZE" value="2" />
16
- </indentOptions>
17
- </codeStyleSettings>
18
- </code_scheme>
19
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
4
- </state>
5
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/.idea/paraswap-dex-lib.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="JAVA_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="inheritedJdk" />
7
- <orderEntry type="sourceFolder" forTests="false" />
8
- </component>
9
- </module>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>