@paraswap/dex-lib 2.37.2-current-fee-ramses-v2.4 → 2.37.3

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 (254) hide show
  1. package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  2. package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
  3. package/build/dex/algebra/algebra-factory.d.ts +25 -0
  4. package/build/dex/algebra/algebra-factory.js +43 -0
  5. package/build/dex/algebra/algebra-factory.js.map +1 -0
  6. package/build/dex/algebra/algebra.d.ts +3 -0
  7. package/build/dex/algebra/algebra.js +27 -5
  8. package/build/dex/algebra/algebra.js.map +1 -1
  9. package/build/dex/algebra/config.js +0 -1
  10. package/build/dex/algebra/config.js.map +1 -1
  11. package/build/dex/algebra/types.d.ts +1 -1
  12. package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
  13. package/build/dex/hello/config.js +15 -0
  14. package/build/dex/hello/config.js.map +1 -0
  15. package/build/dex/hello/hello-pool.d.ts +39 -0
  16. package/build/dex/hello/hello-pool.js +64 -0
  17. package/build/dex/hello/hello-pool.js.map +1 -0
  18. package/build/dex/hello/hello.d.ts +37 -0
  19. package/build/dex/hello/hello.js +126 -0
  20. package/build/dex/hello/hello.js.map +1 -0
  21. package/build/dex/hello/types.d.ts +6 -0
  22. package/build/dex/{woo-fi → hello}/types.js.map +1 -1
  23. package/build/dex/index.js +7 -2
  24. package/build/dex/index.js.map +1 -1
  25. package/build/dex/{dexalot → my-test-dex}/config.d.ts +1 -1
  26. package/build/dex/my-test-dex/config.js +15 -0
  27. package/build/dex/my-test-dex/config.js.map +1 -0
  28. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  29. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  30. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  31. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  32. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  33. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  34. package/build/dex/my-test-dex/types.d.ts +6 -0
  35. package/build/dex/{pancakeswap-v3 → my-test-dex}/types.js.map +1 -1
  36. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
  37. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
  38. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
  39. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
  40. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
  41. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  42. package/build/dex/uniswap-v3/config.js +0 -2
  43. package/build/dex/uniswap-v3/config.js.map +1 -1
  44. package/build/dex/uniswap-v3/types.d.ts +1 -2
  45. package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
  46. package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
  47. package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
  48. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +5 -7
  49. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  50. package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
  51. package/build/dex/uniswap-v3/uniswap-v3.js +29 -9
  52. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  53. package/build/dex-helper/dummy-dex-helper.js +3 -0
  54. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  55. package/build/dex-helper/icache.d.ts +1 -0
  56. package/package.json +1 -1
  57. package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  58. package/src/dex/algebra/algebra-factory.ts +70 -0
  59. package/src/dex/algebra/algebra.ts +47 -6
  60. package/src/dex/algebra/config.ts +0 -1
  61. package/src/dex/algebra/types.ts +2 -1
  62. package/src/dex/index.ts +6 -3
  63. package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
  64. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
  65. package/src/dex/uniswap-v3/config.ts +0 -2
  66. package/src/dex/uniswap-v3/types.ts +2 -2
  67. package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
  68. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -6
  69. package/src/dex/uniswap-v3/uniswap-v3.ts +67 -27
  70. package/src/dex-helper/dummy-dex-helper.ts +4 -0
  71. package/src/dex-helper/icache.ts +2 -0
  72. package/.idea/aws.xml +0 -17
  73. package/.idea/codeStyles/Project.xml +0 -19
  74. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  75. package/.idea/misc.xml +0 -6
  76. package/.idea/modules.xml +0 -8
  77. package/.idea/paraswap-dex-lib.iml +0 -9
  78. package/.idea/vcs.xml +0 -6
  79. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  80. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  81. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  82. package/build/abi/dexalot/DexalotMainnetRFQ.json +0 -887
  83. package/build/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
  84. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  85. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  86. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  87. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  88. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  89. package/build/abi/wBETH.json +0 -1527
  90. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  91. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  92. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  93. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  94. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  95. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  96. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  97. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  98. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  99. package/build/dex/algebra/algebra-pool.js +0 -336
  100. package/build/dex/algebra/algebra-pool.js.map +0 -1
  101. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  102. package/build/dex/balancer-v2/LinearMath.js +0 -179
  103. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  104. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  105. package/build/dex/balancer-v2/LinearPool.js +0 -324
  106. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  107. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  108. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  109. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  110. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  111. package/build/dex/balancer-v2/StableMath.js +0 -272
  112. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  113. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  114. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  115. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  116. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  117. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  118. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  119. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  120. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  121. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  122. package/build/dex/dexalot/config.js +0 -18
  123. package/build/dex/dexalot/config.js.map +0 -1
  124. package/build/dex/dexalot/constants.d.ts +0 -15
  125. package/build/dex/dexalot/constants.js +0 -22
  126. package/build/dex/dexalot/constants.js.map +0 -1
  127. package/build/dex/dexalot/dexalot.d.ts +0 -69
  128. package/build/dex/dexalot/dexalot.js +0 -646
  129. package/build/dex/dexalot/dexalot.js.map +0 -1
  130. package/build/dex/dexalot/rate-fetcher.d.ts +0 -28
  131. package/build/dex/dexalot/rate-fetcher.js +0 -100
  132. package/build/dex/dexalot/rate-fetcher.js.map +0 -1
  133. package/build/dex/dexalot/types.d.ts +0 -114
  134. package/build/dex/dexalot/types.js +0 -12
  135. package/build/dex/dexalot/types.js.map +0 -1
  136. package/build/dex/dexalot/validators.d.ts +0 -5
  137. package/build/dex/dexalot/validators.js +0 -45
  138. package/build/dex/dexalot/validators.js.map +0 -1
  139. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  140. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  141. package/build/dex/quickswap/camelot-v3.js +0 -19
  142. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  143. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  144. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  145. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  146. package/build/dex/quickswap-v3.d.ts +0 -21
  147. package/build/dex/quickswap-v3.js +0 -40
  148. package/build/dex/quickswap-v3.js.map +0 -1
  149. package/build/dex/ramses-v2/config.d.ts +0 -4
  150. package/build/dex/ramses-v2/config.js +0 -28
  151. package/build/dex/ramses-v2/config.js.map +0 -1
  152. package/build/dex/ramses-v2/constants.d.ts +0 -28
  153. package/build/dex/ramses-v2/constants.js +0 -35
  154. package/build/dex/ramses-v2/constants.js.map +0 -1
  155. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  156. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  157. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  158. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  159. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  160. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  161. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  162. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  163. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  164. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  165. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  166. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  167. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  168. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  169. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  170. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  171. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  172. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  173. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  174. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  175. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  176. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  177. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  178. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  179. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  180. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  181. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  182. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  183. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  184. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  185. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  186. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  187. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  188. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  189. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  190. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  191. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  192. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  193. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  194. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  195. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  196. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  197. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  198. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  199. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  200. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  201. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  202. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  203. package/build/dex/ramses-v2/types.d.ts +0 -154
  204. package/build/dex/ramses-v2/types.js +0 -9
  205. package/build/dex/ramses-v2/types.js.map +0 -1
  206. package/build/dex/ramses-v2/utils.d.ts +0 -6
  207. package/build/dex/ramses-v2/utils.js +0 -71
  208. package/build/dex/ramses-v2/utils.js.map +0 -1
  209. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  210. package/build/dex/sushiswap-v3/config.js +0 -132
  211. package/build/dex/sushiswap-v3/config.js.map +0 -1
  212. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  213. package/build/dex/sushiswap-v3/constants.js +0 -32
  214. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  215. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  216. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  217. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  218. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  219. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  220. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  221. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  222. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  223. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  224. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  225. package/build/dex/sushiswap-v3/token.js +0 -23
  226. package/build/dex/sushiswap-v3/token.js.map +0 -1
  227. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  228. package/build/dex/sushiswap-v3/types.js +0 -18
  229. package/build/dex/sushiswap-v3/types.js.map +0 -1
  230. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  231. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  232. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  233. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.d.ts +0 -7
  234. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -87
  235. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +0 -1
  236. package/build/dex/woo-fi/config.js +0 -141
  237. package/build/dex/woo-fi/config.js.map +0 -1
  238. package/build/dex/woo-fi/constants.d.ts +0 -5
  239. package/build/dex/woo-fi/constants.js +0 -20
  240. package/build/dex/woo-fi/constants.js.map +0 -1
  241. package/build/dex/woo-fi/types.d.ts +0 -48
  242. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  243. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  244. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  245. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  246. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  247. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  248. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  249. package/build/dex/woo-fi/woo-fi.js +0 -480
  250. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  251. package/src/abi/ramses-v2/RamsesV2Pool.abi.json +0 -1580
  252. package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -104
  253. /package/build/dex/{pancakeswap-v3 → hello}/types.js +0 -0
  254. /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
@@ -3,7 +3,6 @@ import { NumberAsString } from '../../types';
3
3
  import { Address } from '../../types';
4
4
  import { AbiItem } from 'web3-utils';
5
5
  import { MultiResult } from '../../lib/multi-wrapper';
6
- import { UniswapV3EventPool } from './uniswap-v3-pool';
7
6
 
8
7
  export type OracleObservation = {
9
8
  blockTimestamp: bigint;
@@ -54,6 +53,8 @@ export type PoolState = {
54
53
  balance1: bigint;
55
54
  };
56
55
 
56
+ export type FactoryState = Record<string, never>;
57
+
57
58
  export type UniswapV3Data = {
58
59
  path: {
59
60
  tokenIn: Address;
@@ -80,7 +81,6 @@ export type DexParams = {
80
81
  subgraphURL: string;
81
82
  initHash: string;
82
83
  stateMultiCallAbi?: AbiItem[];
83
- eventPoolImplementation?: typeof UniswapV3EventPool;
84
84
  decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
85
85
  };
86
86
 
@@ -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
+ }
@@ -46,9 +46,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
46
46
 
47
47
  private _poolAddress?: Address;
48
48
 
49
- public currentFeeCodeAsString: string | undefined;
50
-
51
- protected _stateRequestCallData?: MultiCallParams<
49
+ private _stateRequestCallData?: MultiCallParams<
52
50
  bigint | DecodedStateMultiCallResultWithRelativeBitmaps
53
51
  >[];
54
52
 
@@ -57,7 +55,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
57
55
  public initFailed = false;
58
56
  public initRetryAttemptCount = 0;
59
57
 
60
- public feeCodeAsString;
58
+ public readonly feeCodeAsString;
61
59
 
62
60
  constructor(
63
61
  readonly dexHelper: IDexHelper,
@@ -68,7 +66,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
68
66
  | undefined,
69
67
  readonly erc20Interface: Interface,
70
68
  protected readonly factoryAddress: Address,
71
- public feeCode: bigint,
69
+ public readonly feeCode: bigint,
72
70
  token0: Address,
73
71
  token1: Address,
74
72
  logger: Logger,
@@ -201,7 +199,7 @@ export class UniswapV3EventPool extends StatefulEventSubscriber<PoolState> {
201
199
  return null; // ignore unrecognized event
202
200
  }
203
201
 
204
- protected _getStateRequestCallData() {
202
+ private _getStateRequestCallData() {
205
203
  if (!this._stateRequestCallData) {
206
204
  const callData: MultiCallParams<
207
205
  bigint | DecodedStateMultiCallResultWithRelativeBitmaps
@@ -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
 
@@ -139,6 +141,14 @@ export class UniswapV3
139
141
 
140
142
  this.notExistingPoolSetKey =
141
143
  `${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
144
+
145
+ this.factory = new UniswapV3Factory(
146
+ dexHelper,
147
+ dexKey,
148
+ this.config.factory,
149
+ this.logger,
150
+ this.onPoolCreatedDeleteFromNonExistingSet,
151
+ );
142
152
  }
143
153
 
144
154
  get supportedFees() {
@@ -155,6 +165,9 @@ export class UniswapV3
155
165
  }
156
166
 
157
167
  async initializePricing(blockNumber: number) {
168
+ // Init listening to new pools creation
169
+ await this.factory.initialize(blockNumber);
170
+
158
171
  // This is only for testing, because cold pool fetching is goes out of
159
172
  // FETCH_POOL_INDENTIFIER_TIMEOUT range
160
173
  await Promise.all(
@@ -185,6 +198,38 @@ export class UniswapV3
185
198
  }
186
199
  }
187
200
 
201
+ /*
202
+ * When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
203
+ * Once the pool is created, it gets immediately flagged
204
+ */
205
+ onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback = async ({
206
+ token0,
207
+ token1,
208
+ fee,
209
+ }) => {
210
+ const logPrefix = '[UniswapV3.onPoolCreatedDeleteFromNonExistingSet]';
211
+ const [_token0, _token1] = this._sortTokens(token0, token1);
212
+ const poolKey = `${token0}_${token1}_${fee}`.toLowerCase();
213
+
214
+ // consider doing it only from master pool for less calls to distant cache
215
+
216
+ // delete entry locally to let local instance discover the pool
217
+ delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
218
+
219
+ try {
220
+ this.logger.info(
221
+ `${logPrefix} delete pool from not existing set: ${poolKey}`,
222
+ );
223
+ // delete pool record from set
224
+ await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
225
+ } catch (error) {
226
+ this.logger.error(
227
+ `${logPrefix} failed to delete pool from set: ${poolKey}`,
228
+ error,
229
+ );
230
+ }
231
+ };
232
+
188
233
  async getPool(
189
234
  srcAddress: Address,
190
235
  destAddress: Address,
@@ -242,29 +287,25 @@ export class UniswapV3
242
287
  }
243
288
 
244
289
  this.logger.trace(`starting to listen to new pool: ${key}`);
245
- const poolImplementation =
246
- this.config.eventPoolImplementation !== undefined
247
- ? this.config.eventPoolImplementation
248
- : UniswapV3EventPool;
249
290
  pool =
250
291
  pool ||
251
- new poolImplementation(
252
- this.dexHelper,
253
- this.dexKey,
254
- this.stateMultiContract,
255
- this.config.decodeStateMultiCallResultWithRelativeBitmaps,
256
- this.erc20Interface,
257
- this.config.factory,
258
- fee,
259
- token0,
260
- token1,
261
- this.logger,
262
- this.cacheStateKey,
263
- this.config.initHash,
292
+ new UniswapV3EventPool(
293
+ this.dexHelper,
294
+ this.dexKey,
295
+ this.stateMultiContract,
296
+ this.config.decodeStateMultiCallResultWithRelativeBitmaps,
297
+ this.erc20Interface,
298
+ this.config.factory,
299
+ fee,
300
+ token0,
301
+ token1,
302
+ this.logger,
303
+ this.cacheStateKey,
304
+ this.config.initHash,
264
305
  );
265
306
 
266
307
  try {
267
- await pool!.initialize(blockNumber, {
308
+ await pool.initialize(blockNumber, {
268
309
  initCallback: (state: DeepReadonly<PoolState>) => {
269
310
  //really hacky, we need to push poolAddress so that we subscribeToLogs in StatefulEventSubscriber
270
311
  pool!.addressesSubscribed[0] = state.pool;
@@ -293,10 +334,10 @@ export class UniswapV3
293
334
  // on unknown error mark as failed and increase retryCount for retry init strategy
294
335
  // note: state would be null by default which allows to fallback
295
336
  this.logger.warn(
296
- `${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool!.initRetryAttemptCount}`,
337
+ `${this.dexKey}: Can not generate pool state for srcAddress=${srcAddress}, destAddress=${destAddress}, fee=${fee} pool fallback to rpc and retry every ${this.config.initRetryFrequency} times, initRetryAttemptCount=${pool.initRetryAttemptCount}`,
297
338
  e,
298
339
  );
299
- pool!.initFailed = true;
340
+ pool.initFailed = true;
300
341
  }
301
342
  }
302
343
 
@@ -313,8 +354,8 @@ export class UniswapV3
313
354
  }
314
355
 
315
356
  this.eventPools[this.getPoolIdentifier(srcAddress, destAddress, fee)] =
316
- pool!;
317
- return pool!;
357
+ pool;
358
+ return pool;
318
359
  }
319
360
 
320
361
  async addMasterPool(poolKey: string, blockNumber: number): Promise<boolean> {
@@ -495,7 +536,7 @@ export class UniswapV3
495
536
  {
496
537
  tokenIn: from.address,
497
538
  tokenOut: to.address,
498
- fee: pool.currentFeeCodeAsString ? pool.currentFeeCodeAsString : pool.feeCodeAsString,
539
+ fee: pool.feeCodeAsString,
499
540
  },
500
541
  ],
501
542
  exchange: pool.poolAddress,
@@ -689,7 +730,7 @@ export class UniswapV3
689
730
  {
690
731
  tokenIn: _srcAddress,
691
732
  tokenOut: _destAddress,
692
- fee: pool.currentFeeCodeAsString ? pool.currentFeeCodeAsString : pool.feeCode.toString(),
733
+ fee: pool.feeCode.toString(),
693
734
  },
694
735
  ],
695
736
  },
@@ -1070,7 +1111,6 @@ export class UniswapV3
1070
1111
  initHash: this.config.initHash,
1071
1112
  subgraphURL: this.config.subgraphURL,
1072
1113
  stateMultiCallAbi: this.config.stateMultiCallAbi,
1073
- eventPoolImplementation: this.config.eventPoolImplementation,
1074
1114
  decodeStateMultiCallResultWithRelativeBitmaps:
1075
1115
  this.config.decodeStateMultiCallResultWithRelativeBitmaps,
1076
1116
  };
@@ -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>;
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>