@paraswap/dex-lib 2.16.8-pancakeswapv3.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  9. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  10. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  11. package/build/config.js +4 -4
  12. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  13. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  14. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  15. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  16. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  17. package/build/dex/balancer-v2/balancer-v2.d.ts +14 -19
  18. package/build/dex/balancer-v2/balancer-v2.js +27 -22
  19. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  20. package/build/dex/balancer-v2/config.d.ts +2 -7
  21. package/build/dex/balancer-v2/config.js +20 -30
  22. package/build/dex/balancer-v2/config.js.map +1 -1
  23. package/build/dex/balancer-v2/pools/balancer-v2-pool.d.ts +25 -0
  24. package/build/dex/balancer-v2/pools/balancer-v2-pool.js +107 -0
  25. package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
  26. package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +20 -0
  27. package/build/dex/balancer-v2/pools/linear/LinearMath.js +179 -0
  28. package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -0
  29. package/build/dex/balancer-v2/pools/linear/LinearPool.d.ts +50 -0
  30. package/build/dex/balancer-v2/pools/linear/LinearPool.js +458 -0
  31. package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -0
  32. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.d.ts +10 -0
  33. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js +314 -0
  34. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -0
  35. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.d.ts +50 -0
  36. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js +367 -0
  37. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -0
  38. package/build/dex/balancer-v2/pools/stable/StableMath.d.ts +7 -0
  39. package/build/dex/balancer-v2/pools/stable/StableMath.js +111 -0
  40. package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -0
  41. package/build/dex/balancer-v2/pools/stable/StablePool.d.ts +30 -0
  42. package/build/dex/balancer-v2/pools/stable/StablePool.js +129 -0
  43. package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -0
  44. package/build/dex/balancer-v2/pools/weighted/WeightedMath.d.ts +6 -0
  45. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js +61 -0
  46. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js.map +1 -0
  47. package/build/dex/balancer-v2/pools/weighted/WeightedPool.d.ts +30 -0
  48. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js +112 -0
  49. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -0
  50. package/build/dex/balancer-v2/types.d.ts +1 -0
  51. package/build/dex/balancer-v2/types.js.map +1 -1
  52. package/build/dex/balancer-v2/utils.d.ts +3 -2
  53. package/build/dex/balancer-v2/utils.js +6 -4
  54. package/build/dex/balancer-v2/utils.js.map +1 -1
  55. package/build/dex/index.js +1 -1
  56. package/build/dex/index.js.map +1 -1
  57. package/build/dex/quickswap-v3.d.ts +21 -0
  58. package/build/dex/quickswap-v3.js +40 -0
  59. package/build/dex/quickswap-v3.js.map +1 -0
  60. package/build/dex/uniswap-v3/config.js +28 -0
  61. package/build/dex/uniswap-v3/config.js.map +1 -1
  62. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -1
  63. package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -2
  64. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  65. package/build/dex/uniswap-v3/uniswap-v3.js +1 -1
  66. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  67. package/build/dex/{pancakeswap-v3 → woo-fi}/config.d.ts +2 -2
  68. package/build/dex/woo-fi/config.js +141 -0
  69. package/build/dex/woo-fi/config.js.map +1 -0
  70. package/build/dex/woo-fi/constants.d.ts +5 -0
  71. package/build/dex/woo-fi/constants.js +20 -0
  72. package/build/dex/woo-fi/constants.js.map +1 -0
  73. package/build/dex/woo-fi/types.d.ts +48 -0
  74. package/build/dex/woo-fi/types.js +3 -0
  75. package/build/dex/woo-fi/types.js.map +1 -0
  76. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  77. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  78. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  79. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  80. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  81. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  82. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  83. package/build/dex/woo-fi/woo-fi.js +480 -0
  84. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  85. package/package.json +1 -1
  86. package/src/config.ts +4 -4
  87. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +538 -225
  88. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +305 -122
  89. package/src/dex/balancer-v2/balancer-v2.ts +60 -56
  90. package/src/dex/balancer-v2/config.ts +23 -35
  91. package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +274 -0
  92. package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +11 -10
  93. package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -6
  94. package/src/dex/balancer-v2/{StableMath.ts → pools/phantom-stable/PhantomStableMath.ts} +101 -21
  95. package/src/dex/balancer-v2/{PhantomStablePool.ts → pools/phantom-stable/PhantomStablePool.ts} +167 -12
  96. package/src/dex/balancer-v2/pools/stable/StableMath.ts +204 -0
  97. package/src/dex/balancer-v2/pools/stable/StablePool.ts +221 -0
  98. package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +84 -0
  99. package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +189 -0
  100. package/src/dex/balancer-v2/types.ts +1 -0
  101. package/src/dex/balancer-v2/utils.ts +7 -1
  102. package/src/dex/index.ts +1 -1
  103. package/src/dex/uniswap-v3/config.ts +32 -0
  104. package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +28 -0
  105. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +156 -0
  106. package/src/dex/uniswap-v3/uniswap-v3-events.test.ts +0 -4
  107. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +2 -1
  108. package/src/dex/uniswap-v3/uniswap-v3.ts +1 -0
  109. package/tests/constants-e2e.ts +33 -8
  110. package/build/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +0 -781
  111. package/build/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +0 -1039
  112. package/build/abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json +0 -285
  113. package/build/abi/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  114. package/build/dex/pancakeswap-v3/config.js +0 -62
  115. package/build/dex/pancakeswap-v3/config.js.map +0 -1
  116. package/build/dex/pancakeswap-v3/constants.d.ts +0 -23
  117. package/build/dex/pancakeswap-v3/constants.js +0 -29
  118. package/build/dex/pancakeswap-v3/constants.js.map +0 -1
  119. package/build/dex/pancakeswap-v3/contract-math/BitMath.d.ts +0 -4
  120. package/build/dex/pancakeswap-v3/contract-math/BitMath.js +0 -93
  121. package/build/dex/pancakeswap-v3/contract-math/BitMath.js.map +0 -1
  122. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.d.ts +0 -3
  123. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js +0 -8
  124. package/build/dex/pancakeswap-v3/contract-math/FixedPoint128.js.map +0 -1
  125. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.d.ts +0 -4
  126. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js +0 -9
  127. package/build/dex/pancakeswap-v3/contract-math/FixedPoint96.js.map +0 -1
  128. package/build/dex/pancakeswap-v3/contract-math/FullMath.d.ts +0 -4
  129. package/build/dex/pancakeswap-v3/contract-math/FullMath.js +0 -19
  130. package/build/dex/pancakeswap-v3/contract-math/FullMath.js.map +0 -1
  131. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.d.ts +0 -3
  132. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js +0 -22
  133. package/build/dex/pancakeswap-v3/contract-math/LiquidityMath.js.map +0 -1
  134. package/build/dex/pancakeswap-v3/contract-math/Oracle.d.ts +0 -10
  135. package/build/dex/pancakeswap-v3/contract-math/Oracle.js +0 -133
  136. package/build/dex/pancakeswap-v3/contract-math/Oracle.js.map +0 -1
  137. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.d.ts +0 -10
  138. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js +0 -91
  139. package/build/dex/pancakeswap-v3/contract-math/SqrtPriceMath.js.map +0 -1
  140. package/build/dex/pancakeswap-v3/contract-math/SwapMath.d.ts +0 -8
  141. package/build/dex/pancakeswap-v3/contract-math/SwapMath.js +0 -70
  142. package/build/dex/pancakeswap-v3/contract-math/SwapMath.js.map +0 -1
  143. package/build/dex/pancakeswap-v3/contract-math/Tick.d.ts +0 -7
  144. package/build/dex/pancakeswap-v3/contract-math/Tick.js +0 -45
  145. package/build/dex/pancakeswap-v3/contract-math/Tick.js.map +0 -1
  146. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.d.ts +0 -8
  147. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js +0 -87
  148. package/build/dex/pancakeswap-v3/contract-math/TickBitMap.js.map +0 -1
  149. package/build/dex/pancakeswap-v3/contract-math/TickMath.d.ts +0 -8
  150. package/build/dex/pancakeswap-v3/contract-math/TickMath.js +0 -162
  151. package/build/dex/pancakeswap-v3/contract-math/TickMath.js.map +0 -1
  152. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.d.ts +0 -3
  153. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js +0 -10
  154. package/build/dex/pancakeswap-v3/contract-math/UnsafeMath.js.map +0 -1
  155. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.d.ts +0 -18
  156. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js +0 -407
  157. package/build/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.js.map +0 -1
  158. package/build/dex/pancakeswap-v3/contract-math/utils.d.ts +0 -3
  159. package/build/dex/pancakeswap-v3/contract-math/utils.js +0 -16
  160. package/build/dex/pancakeswap-v3/contract-math/utils.js.map +0 -1
  161. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +0 -45
  162. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +0 -340
  163. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +0 -1
  164. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +0 -55
  165. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +0 -605
  166. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  167. package/build/dex/pancakeswap-v3/types.d.ts +0 -137
  168. package/build/dex/pancakeswap-v3/types.js +0 -9
  169. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  170. package/build/dex/pancakeswap-v3/utils.d.ts +0 -6
  171. package/build/dex/pancakeswap-v3/utils.js +0 -65
  172. package/build/dex/pancakeswap-v3/utils.js.map +0 -1
  173. package/src/abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json +0 -781
  174. package/src/abi/pancakeswap-v3/PancakeswapV3Pool.abi.json +0 -1039
  175. package/src/dex/balancer-v2/balancer-v2-pool.ts +0 -744
  176. package/src/dex/pancakeswap-v3/config.ts +0 -68
  177. package/src/dex/pancakeswap-v3/constants.ts +0 -35
  178. package/src/dex/pancakeswap-v3/contract-math/BitMath.ts +0 -90
  179. package/src/dex/pancakeswap-v3/contract-math/FixedPoint128.ts +0 -3
  180. package/src/dex/pancakeswap-v3/contract-math/FixedPoint96.ts +0 -4
  181. package/src/dex/pancakeswap-v3/contract-math/FullMath.ts +0 -30
  182. package/src/dex/pancakeswap-v3/contract-math/LiquidityMath.ts +0 -17
  183. package/src/dex/pancakeswap-v3/contract-math/Oracle.ts +0 -226
  184. package/src/dex/pancakeswap-v3/contract-math/SqrtPriceMath.ts +0 -226
  185. package/src/dex/pancakeswap-v3/contract-math/SwapMath.ts +0 -139
  186. package/src/dex/pancakeswap-v3/contract-math/Tick.ts +0 -82
  187. package/src/dex/pancakeswap-v3/contract-math/TickBitMap.ts +0 -128
  188. package/src/dex/pancakeswap-v3/contract-math/TickMath.ts +0 -211
  189. package/src/dex/pancakeswap-v3/contract-math/UnsafeMath.ts +0 -5
  190. package/src/dex/pancakeswap-v3/contract-math/pancakeswap-v3-math.ts +0 -691
  191. package/src/dex/pancakeswap-v3/contract-math/utils.ts +0 -11
  192. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +0 -168
  193. package/src/dex/pancakeswap-v3/pancakeswap-v3-events.test.ts +0 -124
  194. package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +0 -338
  195. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +0 -554
  196. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +0 -1000
  197. /package/src/abi/{pancakeswap-v3/PancakeswapV3Quoter.abi.json → uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json} +0 -0
  198. /package/src/abi/{pancakeswap-v3 → uniswap-v3/pancakeswap-v3}/PancakeswapV3Router.abi.json +0 -0
@@ -1,168 +0,0 @@
1
- import dotenv from 'dotenv';
2
- dotenv.config();
3
-
4
- import { testE2E } from '../../../tests/utils-e2e';
5
- import {
6
- Tokens,
7
- Holders,
8
- NativeTokenSymbols,
9
- } from '../../../tests/constants-e2e';
10
- import { Network, ContractMethod, SwapSide } from '../../constants';
11
- import { StaticJsonRpcProvider } from '@ethersproject/providers';
12
- import { generateConfig } from '../../config';
13
-
14
- describe('PancakeswapV3 E2E', () => {
15
- const dexKey = 'PancakeswapV3';
16
-
17
- describe('PancakeswapV3 MAINNET', () => {
18
- const network = Network.MAINNET;
19
- const tokens = Tokens[network];
20
- const holders = Holders[network];
21
- const provider = new StaticJsonRpcProvider(
22
- generateConfig(network).privateHttpProvider,
23
- network,
24
- );
25
-
26
- const tokenASymbol: string = 'USDT';
27
- const tokenBSymbol: string = 'USDC';
28
- const nativeTokenSymbol = NativeTokenSymbols[network];
29
-
30
- const tokenAAmount: string = '100000000';
31
- const tokenBAmount: string = '100000000';
32
- const nativeTokenAmount = '1000000000000000000';
33
-
34
- const sideToContractMethods = new Map([
35
- [
36
- SwapSide.SELL,
37
- [
38
- ContractMethod.simpleSwap,
39
- ContractMethod.multiSwap,
40
- ContractMethod.megaSwap,
41
- ],
42
- ],
43
- [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
44
- ]);
45
-
46
- sideToContractMethods.forEach((contractMethods, side) =>
47
- contractMethods.forEach((contractMethod: ContractMethod) => {
48
- describe(`${contractMethod}`, () => {
49
- it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
50
- await testE2E(
51
- tokens[nativeTokenSymbol],
52
- tokens[tokenASymbol],
53
- holders[nativeTokenSymbol],
54
- side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
55
- side,
56
- dexKey,
57
- contractMethod,
58
- network,
59
- provider,
60
- );
61
- });
62
- it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
63
- await testE2E(
64
- tokens[tokenASymbol],
65
- tokens[nativeTokenSymbol],
66
- holders[tokenASymbol],
67
- side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
68
- side,
69
- dexKey,
70
- contractMethod,
71
- network,
72
- provider,
73
- );
74
- });
75
- it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${tokenBSymbol}`, async () => {
76
- await testE2E(
77
- tokens[tokenASymbol],
78
- tokens[tokenBSymbol],
79
- holders[tokenASymbol],
80
- side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
81
- side,
82
- dexKey,
83
- contractMethod,
84
- network,
85
- provider,
86
- );
87
- });
88
- });
89
- }),
90
- );
91
- });
92
-
93
- describe('PancakeswapV3 BSC', () => {
94
- const network = Network.BSC;
95
- const tokens = Tokens[network];
96
- const holders = Holders[network];
97
- const provider = new StaticJsonRpcProvider(
98
- generateConfig(network).privateHttpProvider,
99
- network,
100
- );
101
-
102
- const tokenASymbol: string = 'BUSD';
103
- const tokenBSymbol: string = 'WBNB';
104
- const nativeTokenSymbol = NativeTokenSymbols[network];
105
-
106
- const tokenAAmount: string = '100000000000000000000';
107
- const tokenBAmount: string = '1000000000000000000';
108
- const nativeTokenAmount = '1000000000000000000';
109
-
110
- const sideToContractMethods = new Map([
111
- [
112
- SwapSide.SELL,
113
- [
114
- ContractMethod.simpleSwap,
115
- ContractMethod.multiSwap,
116
- ContractMethod.megaSwap,
117
- ],
118
- ],
119
- [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
120
- ]);
121
-
122
- sideToContractMethods.forEach((contractMethods, side) =>
123
- contractMethods.forEach((contractMethod: ContractMethod) => {
124
- describe(`${contractMethod}`, () => {
125
- it(`${network} ${side} ${contractMethod} ${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
126
- await testE2E(
127
- tokens[nativeTokenSymbol],
128
- tokens[tokenASymbol],
129
- holders[nativeTokenSymbol],
130
- side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
131
- side,
132
- dexKey,
133
- contractMethod,
134
- network,
135
- provider,
136
- );
137
- });
138
- it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
139
- await testE2E(
140
- tokens[tokenASymbol],
141
- tokens[nativeTokenSymbol],
142
- holders[tokenASymbol],
143
- side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
144
- side,
145
- dexKey,
146
- contractMethod,
147
- network,
148
- provider,
149
- );
150
- });
151
- it(`${network} ${side} ${contractMethod} ${tokenASymbol} -> ${tokenBSymbol}`, async () => {
152
- await testE2E(
153
- tokens[tokenASymbol],
154
- tokens[tokenBSymbol],
155
- holders[tokenASymbol],
156
- side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
157
- side,
158
- dexKey,
159
- contractMethod,
160
- network,
161
- provider,
162
- );
163
- });
164
- });
165
- }),
166
- );
167
- });
168
- });
@@ -1,124 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { PancakeswapV3Config } from './config';
6
- import { Network } from '../../constants';
7
- import { DummyDexHelper } from '../../dex-helper/index';
8
- import { testEventSubscriber } from '../../../tests/utils-events';
9
- import { Interface } from '@ethersproject/abi';
10
- import ERC20ABI from '../../abi/erc20.json';
11
- import StateMulticallABI from '../../abi/pancakeswap-v3/PancakeV3StateMulticall.abi.json';
12
- import { AbiItem } from 'web3-utils';
13
- import { PancakeSwapV3EventPool } from './pancakeswap-v3-pool';
14
- import { PoolState } from '../uniswap-v3/types';
15
-
16
- jest.setTimeout(300 * 1000);
17
- const dexKey = 'PancakeswapV3';
18
- const network = Network.MAINNET;
19
- const config = PancakeswapV3Config[dexKey][network];
20
-
21
- async function fetchPoolStateFromContract(
22
- pancakeswapV3Pool: PancakeSwapV3EventPool,
23
- blockNumber: number,
24
- poolAddress: string,
25
- ): Promise<PoolState | undefined> {
26
- const message = `PancakeswapV3: ${poolAddress} blockNumber ${blockNumber}`;
27
- console.log(`Fetching state ${message}`);
28
- // Be careful to not request state prior to contract deployment
29
- // Otherwise need to use manual state sourcing from multicall
30
- // We had that mechanism, but removed it with this commit
31
- // You can restore it, but better just to find block after state multicall
32
- // deployment
33
- const state = await pancakeswapV3Pool.generateState(blockNumber);
34
-
35
- console.log(`Done ${message}`);
36
-
37
- return state;
38
- }
39
-
40
- describe('PancakeswapV3 Event', function () {
41
- const poolAddress = '0x04c8577958CcC170EB3d2CCa76F9d51bc6E42D8f';
42
- const poolFeeCode = 100n;
43
- const token0 = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
44
- const token1 = '0xdAC17F958D2ee523a2206206994597C13D831ec7';
45
-
46
- const blockNumbers: { [eventName: string]: number[] } = {
47
- ['Swap']: [
48
- 17030597, 17031935, 17032362, 17035931, 17038708, 17039103, 17039688,
49
- 17039812, 17046030, 17046317, 17046694, 17047063, 17047219, 17056731,
50
- 17057640, 17057862, 17057892, 17057955, 17063052, 17063127, 17063524,
51
- 17091869, 17093155, 17093506, 17146325, 17146863, 17147474, 17147830,
52
- 17154952, 17159976, 17160283, 17160720, 17233700, 17234168, 17234407,
53
- 17234433, 17242498, 17242712, 17243089, 17276770, 17277552, 17277733,
54
- 17320467,
55
- ],
56
- ['Burn']: [
57
- 17030970, 17031054, 17031107, 17031773, 17031838, 17033280, 17036092,
58
- 17042331, 17042392, 17043224, 17097388, 17098794, 17099011, 17118506,
59
- 17121704, 17143519, 17163847, 17207834, 17213897, 17249508, 17251725,
60
- ],
61
- ['Mint']: [
62
- 17030284, 17031045, 17033298, 17033315, 17036173, 17042433, 17043299,
63
- 17044836, 17044855, 17046316, 17047699, 17047732, 17050119, 17071407,
64
- 17074384, 17090265, 17092669, 17093251, 17094015, 17121836, 17147932,
65
- 17163857, 17172266, 17185894, 17194153, 17199371, 17249453,
66
- ],
67
- ['SetFeeProtocol']: [],
68
- ['IncreaseObservationCardinalityNext']: [],
69
- ['Collect']: [
70
- 17117306, 17118506, 17121704, 17143519, 17147612, 17160005, 17163847,
71
- 17192312, 17201868, 17205784, 17207834, 17213120, 17213897, 17241053,
72
- 17249508, 17251725,
73
- ],
74
- ['Flash']: [],
75
- };
76
-
77
- describe('PancakeswapV3EventPool', function () {
78
- Object.keys(blockNumbers).forEach((event: string) => {
79
- blockNumbers[event].forEach((blockNumber: number) => {
80
- it(`${event}:${blockNumber} - should return correct state`, async function () {
81
- const dexHelper = new DummyDexHelper(network);
82
-
83
- const logger = dexHelper.getLogger(dexKey);
84
-
85
- const pancakeswapV3Pool = new PancakeSwapV3EventPool(
86
- dexHelper,
87
- dexKey,
88
- new dexHelper.web3Provider.eth.Contract(
89
- StateMulticallABI as AbiItem[],
90
- config.stateMulticall,
91
- ),
92
- new Interface(ERC20ABI),
93
- config.factory,
94
- poolFeeCode,
95
- token0,
96
- token1,
97
- logger,
98
- undefined,
99
- config.initHash,
100
- config.deployer,
101
- );
102
-
103
- // It is done in generateState. But here have to make it manually
104
- pancakeswapV3Pool.poolAddress = poolAddress.toLowerCase();
105
- pancakeswapV3Pool.addressesSubscribed[0] = poolAddress;
106
-
107
- await testEventSubscriber(
108
- pancakeswapV3Pool,
109
- pancakeswapV3Pool.addressesSubscribed,
110
- (_blockNumber: number) =>
111
- fetchPoolStateFromContract(
112
- pancakeswapV3Pool,
113
- _blockNumber,
114
- poolAddress,
115
- ),
116
- blockNumber,
117
- `${dexKey}_${poolAddress}`,
118
- dexHelper.provider,
119
- );
120
- });
121
- });
122
- });
123
- });
124
- });
@@ -1,338 +0,0 @@
1
- /* eslint-disable no-console */
2
- import dotenv from 'dotenv';
3
- dotenv.config();
4
-
5
- import { Interface, Result } from '@ethersproject/abi';
6
- import { DummyDexHelper } from '../../dex-helper/index';
7
- import { Network, SwapSide } from '../../constants';
8
- import { BI_POWS } from '../../bigint-constants';
9
- import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
10
- import { Tokens } from '../../../tests/constants-e2e';
11
- import PancakeswapV3QuoterABI from '../../abi/pancakeswap-v3/PancakeswapV3Quoter.abi.json';
12
- import { Address } from '@paraswap/core';
13
- import { PancakeswapV3 } from './pancakeswap-v3';
14
-
15
- const network = Network.MAINNET;
16
- const TokenASymbol = 'USDC';
17
- const TokenA = Tokens[network][TokenASymbol];
18
-
19
- const TokenBSymbol = 'USDT';
20
- const TokenB = Tokens[network][TokenBSymbol];
21
-
22
- const amounts = [
23
- 0n,
24
- 10_000n * BI_POWS[6],
25
- 20_000n * BI_POWS[6],
26
- 30_000n * BI_POWS[6],
27
- ];
28
-
29
- const amountsBuy = [0n, 1n * BI_POWS[6], 2n * BI_POWS[6], 3n * BI_POWS[6]];
30
-
31
- const dexHelper = new DummyDexHelper(network);
32
- const dexKey = 'PancakeswapV3';
33
-
34
- const quoterIface = new Interface(PancakeswapV3QuoterABI);
35
-
36
- function getReaderCalldata(
37
- exchangeAddress: string,
38
- readerIface: Interface,
39
- amounts: bigint[],
40
- funcName: string,
41
- tokenIn: Address,
42
- tokenOut: Address,
43
- fee: bigint,
44
- ) {
45
- return amounts.map(amount => ({
46
- target: exchangeAddress,
47
- callData: readerIface.encodeFunctionData(funcName, [
48
- [tokenIn, tokenOut, amount, fee, 0n],
49
- ]),
50
- }));
51
- }
52
-
53
- function decodeReaderResult(
54
- results: Result,
55
- readerIface: Interface,
56
- funcName: string,
57
- ) {
58
- return results.map(result => {
59
- const parsed = readerIface.decodeFunctionResult(funcName, result);
60
- return BigInt(parsed[0]._hex);
61
- });
62
- }
63
-
64
- async function checkOnChainPricing(
65
- pancakeswapV3: PancakeswapV3,
66
- funcName: string,
67
- blockNumber: number,
68
- prices: bigint[],
69
- tokenIn: Address,
70
- tokenOut: Address,
71
- fee: bigint,
72
- _amounts: bigint[],
73
- ) {
74
- // Quoter address
75
- const exchangeAddress = '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997';
76
- const readerIface = quoterIface;
77
-
78
- const sum = prices.reduce((acc, curr) => (acc += curr), 0n);
79
-
80
- if (sum === 0n) {
81
- console.log(
82
- `Prices were not calculated for tokenIn=${tokenIn}, tokenOut=${tokenOut}, fee=${fee.toString()}. Most likely price impact is too big for requested amount`,
83
- );
84
- return false;
85
- }
86
-
87
- const readerCallData = getReaderCalldata(
88
- exchangeAddress,
89
- readerIface,
90
- _amounts.slice(1),
91
- funcName,
92
- tokenIn,
93
- tokenOut,
94
- fee,
95
- );
96
-
97
- let readerResult;
98
- try {
99
- readerResult = (
100
- await dexHelper.multiContract.methods
101
- .aggregate(readerCallData)
102
- .call({}, blockNumber)
103
- ).returnData;
104
- } catch (e) {
105
- console.log(
106
- `Can not fetch on-chain pricing for fee ${fee}. It happens for low liquidity pools`,
107
- e,
108
- );
109
- return false;
110
- }
111
-
112
- const expectedPrices = [0n].concat(
113
- decodeReaderResult(readerResult, readerIface, funcName),
114
- );
115
-
116
- let firstZeroIndex = prices.slice(1).indexOf(0n);
117
-
118
- // we skipped first, so add +1 on result
119
- firstZeroIndex = firstZeroIndex === -1 ? prices.length : firstZeroIndex;
120
-
121
- // Compare only the ones for which we were able to calculate prices
122
- expect(prices.slice(0, firstZeroIndex)).toEqual(
123
- expectedPrices.slice(0, firstZeroIndex),
124
- );
125
- return true;
126
- }
127
-
128
- describe('PancakeswapV3', function () {
129
- let blockNumber: number;
130
- let pancakeswapV3: PancakeswapV3;
131
-
132
- beforeEach(async () => {
133
- blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
134
- pancakeswapV3 = new PancakeswapV3(network, dexKey, dexHelper);
135
- });
136
-
137
- it('getPoolIdentifiers and getPricesVolume SELL', async function () {
138
- const pools = await pancakeswapV3.getPoolIdentifiers(
139
- TokenA,
140
- TokenB,
141
- SwapSide.SELL,
142
- blockNumber,
143
- );
144
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
145
-
146
- expect(pools.length).toBeGreaterThan(0);
147
-
148
- const poolPrices = await pancakeswapV3.getPricesVolume(
149
- TokenA,
150
- TokenB,
151
- amounts,
152
- SwapSide.SELL,
153
- blockNumber,
154
- pools,
155
- );
156
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
157
-
158
- expect(poolPrices).not.toBeNull();
159
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
160
-
161
- let falseChecksCounter = 0;
162
- await Promise.all(
163
- poolPrices!.map(async price => {
164
- const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
165
- const res = await checkOnChainPricing(
166
- pancakeswapV3,
167
- 'quoteExactInputSingle',
168
- blockNumber,
169
- price.prices,
170
- TokenA.address,
171
- TokenB.address,
172
- fee,
173
- amounts,
174
- );
175
- if (res === false) falseChecksCounter++;
176
- }),
177
- );
178
-
179
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
180
- });
181
-
182
- it('getPoolIdentifiers and getPricesVolume BUY', async function () {
183
- const pools = await pancakeswapV3.getPoolIdentifiers(
184
- TokenA,
185
- TokenB,
186
- SwapSide.BUY,
187
- blockNumber,
188
- );
189
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
190
-
191
- expect(pools.length).toBeGreaterThan(0);
192
-
193
- const poolPrices = await pancakeswapV3.getPricesVolume(
194
- TokenA,
195
- TokenB,
196
- amountsBuy,
197
- SwapSide.BUY,
198
- blockNumber,
199
- pools,
200
- );
201
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
202
-
203
- expect(poolPrices).not.toBeNull();
204
- checkPoolPrices(poolPrices!, amountsBuy, SwapSide.BUY, dexKey);
205
-
206
- // Check if onchain pricing equals to calculated ones
207
- let falseChecksCounter = 0;
208
- await Promise.all(
209
- poolPrices!.map(async price => {
210
- const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
211
- const res = await checkOnChainPricing(
212
- pancakeswapV3,
213
- 'quoteExactOutputSingle',
214
- blockNumber,
215
- price.prices,
216
- TokenA.address,
217
- TokenB.address,
218
- fee,
219
- amountsBuy,
220
- );
221
- if (res === false) falseChecksCounter++;
222
- }),
223
- );
224
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
225
- });
226
-
227
- it('getPoolIdentifiers and getPricesVolume SELL stable pairs', async function () {
228
- const pools = await pancakeswapV3.getPoolIdentifiers(
229
- TokenA,
230
- TokenB,
231
- SwapSide.SELL,
232
- blockNumber,
233
- );
234
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
235
-
236
- expect(pools.length).toBeGreaterThan(0);
237
-
238
- const poolPrices = await pancakeswapV3.getPricesVolume(
239
- TokenA,
240
- TokenB,
241
- amounts,
242
- SwapSide.SELL,
243
- blockNumber,
244
- pools,
245
- );
246
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
247
-
248
- expect(poolPrices).not.toBeNull();
249
- checkPoolPrices(
250
- poolPrices!.filter(pp => pp.unit !== 0n),
251
- amounts,
252
- SwapSide.SELL,
253
- dexKey,
254
- );
255
-
256
- // Check if onchain pricing equals to calculated ones
257
- let falseChecksCounter = 0;
258
- await Promise.all(
259
- poolPrices!.map(async price => {
260
- const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
261
- const res = await checkOnChainPricing(
262
- pancakeswapV3,
263
- 'quoteExactInputSingle',
264
- blockNumber,
265
- price.prices,
266
- TokenA.address,
267
- TokenB.address,
268
- fee,
269
- amounts,
270
- );
271
- if (res === false) falseChecksCounter++;
272
- }),
273
- );
274
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
275
- });
276
-
277
- it('getPoolIdentifiers and getPricesVolume BUY stable pairs', async function () {
278
- const pools = await pancakeswapV3.getPoolIdentifiers(
279
- TokenA,
280
- TokenB,
281
- SwapSide.BUY,
282
- blockNumber,
283
- );
284
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
285
-
286
- expect(pools.length).toBeGreaterThan(0);
287
-
288
- const poolPrices = await pancakeswapV3.getPricesVolume(
289
- TokenA,
290
- TokenB,
291
- amountsBuy,
292
- SwapSide.BUY,
293
- blockNumber,
294
- pools,
295
- );
296
- console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
297
-
298
- expect(poolPrices).not.toBeNull();
299
- checkPoolPrices(
300
- poolPrices!.filter(pp => pp.unit !== 0n),
301
- amountsBuy,
302
- SwapSide.BUY,
303
- dexKey,
304
- );
305
-
306
- // Check if onchain pricing equals to calculated ones
307
- let falseChecksCounter = 0;
308
- await Promise.all(
309
- poolPrices!.map(async price => {
310
- const fee = pancakeswapV3.eventPools[price.poolIdentifier!]!.feeCode;
311
- const res = await checkOnChainPricing(
312
- pancakeswapV3,
313
- 'quoteExactOutputSingle',
314
- blockNumber,
315
- price.prices,
316
- TokenA.address,
317
- TokenB.address,
318
- fee,
319
- amountsBuy,
320
- );
321
- if (res === false) falseChecksCounter++;
322
- }),
323
- );
324
- expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
325
- });
326
-
327
- it('getTopPoolsForToken', async function () {
328
- const poolLiquidity = await pancakeswapV3.getTopPoolsForToken(
329
- Tokens[Network.MAINNET]['USDC'].address,
330
- 10,
331
- );
332
- console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
333
-
334
- if (!pancakeswapV3.hasConstantPriceLargeAmounts) {
335
- checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
336
- }
337
- });
338
- });