@paraswap/dex-lib 2.42.24 → 2.42.25-wombat.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 (255) hide show
  1. package/.vscode/launch.json +39 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/wombat/asset.json +769 -0
  5. package/build/abi/wombat/bmw.json +1247 -0
  6. package/build/abi/wombat/pool.json +1364 -0
  7. package/build/config.js +1 -1
  8. package/build/config.js.map +1 -1
  9. package/build/dex/index.js +2 -0
  10. package/build/dex/index.js.map +1 -1
  11. package/build/dex/{woo-fi → wombat}/config.d.ts +1 -1
  12. package/build/dex/wombat/config.js +77 -0
  13. package/build/dex/wombat/config.js.map +1 -0
  14. package/build/dex/wombat/types.d.ts +33 -0
  15. package/build/dex/{woo-fi → wombat}/types.js.map +1 -1
  16. package/build/dex/wombat/utils.d.ts +9 -0
  17. package/build/dex/wombat/utils.js +66 -0
  18. package/build/dex/wombat/utils.js.map +1 -0
  19. package/build/dex/wombat/wombat-bmw.d.ts +40 -0
  20. package/build/dex/wombat/wombat-bmw.js +147 -0
  21. package/build/dex/wombat/wombat-bmw.js.map +1 -0
  22. package/build/dex/wombat/wombat-pool.d.ts +22 -0
  23. package/build/dex/wombat/wombat-pool.js +161 -0
  24. package/build/dex/wombat/wombat-pool.js.map +1 -0
  25. package/build/dex/wombat/wombat-quoter.d.ts +16 -0
  26. package/build/dex/wombat/wombat-quoter.js +176 -0
  27. package/build/dex/wombat/wombat-quoter.js.map +1 -0
  28. package/build/dex/wombat/wombat.d.ts +55 -0
  29. package/build/dex/wombat/wombat.js +290 -0
  30. package/build/dex/wombat/wombat.js.map +1 -0
  31. package/package.json +1 -1
  32. package/src/abi/wombat/asset.json +769 -0
  33. package/src/abi/wombat/bmw.json +1247 -0
  34. package/{build/abi/wBETH.json → src/abi/wombat/pool.json} +574 -737
  35. package/src/config.ts +1 -2
  36. package/src/dex/index.ts +2 -0
  37. package/src/dex/wombat/config.ts +77 -0
  38. package/src/dex/wombat/types.ts +55 -0
  39. package/src/dex/wombat/utils.ts +62 -0
  40. package/src/dex/wombat/wombat-bmw.ts +209 -0
  41. package/src/dex/wombat/wombat-e2e.test.ts +264 -0
  42. package/src/dex/wombat/wombat-integration.test.ts +258 -0
  43. package/src/dex/wombat/wombat-pool.ts +231 -0
  44. package/src/dex/wombat/wombat-quoter.ts +269 -0
  45. package/src/dex/wombat/wombat.ts +426 -0
  46. package/tests/constants-e2e.ts +19 -4
  47. package/tests/utils-e2e.ts +2 -1
  48. package/.idea/aws.xml +0 -17
  49. package/.idea/codeStyles/Project.xml +0 -19
  50. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  51. package/.idea/misc.xml +0 -6
  52. package/.idea/modules.xml +0 -8
  53. package/.idea/paraswap-dex-lib.iml +0 -9
  54. package/.idea/prettier.xml +0 -7
  55. package/.idea/vcs.xml +0 -6
  56. package/build/abi/AugustusV6.abi.json +0 -395
  57. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  58. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  59. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  60. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  61. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  62. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  63. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  64. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  65. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  66. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  67. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  68. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  69. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  70. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  71. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  72. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  73. package/build/dex/algebra/algebra-pool.d.ts +0 -114
  74. package/build/dex/algebra/algebra-pool.js +0 -448
  75. package/build/dex/algebra/algebra-pool.js.map +0 -1
  76. package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
  77. package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
  78. package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
  79. package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
  80. package/build/dex/balancer-v2/LinearMath.js +0 -285
  81. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  82. package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
  83. package/build/dex/balancer-v2/LinearPool.js +0 -444
  84. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  85. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
  86. package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
  87. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  88. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  89. package/build/dex/balancer-v2/StableMath.js +0 -272
  90. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  91. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
  92. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
  93. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  94. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.d.ts +0 -33
  95. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js +0 -128
  96. package/build/dex/balancer-v2/pools/gyro/Gyro3Pool.js.map +0 -1
  97. package/build/dex/balancer-v2/pools/gyro/GyroEPool.d.ts +0 -34
  98. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js +0 -151
  99. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +0 -1
  100. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  101. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  102. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  103. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  104. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  105. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  106. package/build/dex/lighter-v1/abi/erc20.json +0 -222
  107. package/build/dex/lighter-v1/abi/factory.json +0 -291
  108. package/build/dex/lighter-v1/abi/order_book.json +0 -594
  109. package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
  110. package/build/dex/lighter-v1/abi/router.json +0 -488
  111. package/build/dex/lighter-v1/config.d.ts +0 -4
  112. package/build/dex/lighter-v1/config.js +0 -17
  113. package/build/dex/lighter-v1/config.js.map +0 -1
  114. package/build/dex/lighter-v1/constants.d.ts +0 -2
  115. package/build/dex/lighter-v1/constants.js +0 -13
  116. package/build/dex/lighter-v1/constants.js.map +0 -1
  117. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
  118. package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
  119. package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
  120. package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
  121. package/build/dex/lighter-v1/lighter-v1.js +0 -331
  122. package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
  123. package/build/dex/lighter-v1/types.d.ts +0 -40
  124. package/build/dex/lighter-v1/types.js.map +0 -1
  125. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  126. package/build/dex/pancakeswap-v3/types.js +0 -3
  127. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  128. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  129. package/build/dex/quickswap/camelot-v3.js +0 -19
  130. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  131. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  132. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  133. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  134. package/build/dex/quickswap-v3.d.ts +0 -21
  135. package/build/dex/quickswap-v3.js +0 -40
  136. package/build/dex/quickswap-v3.js.map +0 -1
  137. package/build/dex/ramses-v2/config.d.ts +0 -4
  138. package/build/dex/ramses-v2/config.js +0 -28
  139. package/build/dex/ramses-v2/config.js.map +0 -1
  140. package/build/dex/ramses-v2/constants.d.ts +0 -28
  141. package/build/dex/ramses-v2/constants.js +0 -35
  142. package/build/dex/ramses-v2/constants.js.map +0 -1
  143. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  144. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  145. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  146. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  147. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  148. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  149. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  150. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  151. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  152. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  153. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  154. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  155. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  156. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  157. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  158. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  159. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  160. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  161. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  162. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  163. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  164. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  165. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  166. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  167. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  168. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  169. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  170. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  171. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  172. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  173. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  174. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  175. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  176. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  177. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  178. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  179. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  180. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  181. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  182. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  183. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  184. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  185. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  186. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  187. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  188. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  189. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  190. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  191. package/build/dex/ramses-v2/types.d.ts +0 -154
  192. package/build/dex/ramses-v2/types.js +0 -9
  193. package/build/dex/ramses-v2/types.js.map +0 -1
  194. package/build/dex/ramses-v2/utils.d.ts +0 -6
  195. package/build/dex/ramses-v2/utils.js +0 -71
  196. package/build/dex/ramses-v2/utils.js.map +0 -1
  197. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  198. package/build/dex/solidly/forks-override/fvm.js +0 -42
  199. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  200. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  201. package/build/dex/sushiswap-v3/config.js +0 -132
  202. package/build/dex/sushiswap-v3/config.js.map +0 -1
  203. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  204. package/build/dex/sushiswap-v3/constants.js +0 -32
  205. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  206. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  207. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  208. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  209. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  210. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  211. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  212. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  213. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  214. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  215. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  216. package/build/dex/sushiswap-v3/token.js +0 -23
  217. package/build/dex/sushiswap-v3/token.js.map +0 -1
  218. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  219. package/build/dex/sushiswap-v3/types.js +0 -18
  220. package/build/dex/sushiswap-v3/types.js.map +0 -1
  221. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  222. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  223. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  224. package/build/dex/woo-fi/config.js +0 -141
  225. package/build/dex/woo-fi/config.js.map +0 -1
  226. package/build/dex/woo-fi/constants.d.ts +0 -5
  227. package/build/dex/woo-fi/constants.js +0 -20
  228. package/build/dex/woo-fi/constants.js.map +0 -1
  229. package/build/dex/woo-fi/types.d.ts +0 -48
  230. package/build/dex/woo-fi/types.js +0 -3
  231. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  232. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  233. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  234. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  235. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  236. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  237. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  238. package/build/dex/woo-fi/woo-fi.js +0 -480
  239. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  240. package/build/executor/Executor01BytecodeBuilder.d.ts +0 -77
  241. package/build/executor/Executor01BytecodeBuilder.js +0 -359
  242. package/build/executor/Executor01BytecodeBuilder.js.map +0 -1
  243. package/build/executor/Executor02BytecodeBuilder.d.ts +0 -12
  244. package/build/executor/Executor02BytecodeBuilder.js +0 -14
  245. package/build/executor/Executor02BytecodeBuilder.js.map +0 -1
  246. package/build/executor/ExecutorDetector.d.ts +0 -28
  247. package/build/executor/ExecutorDetector.js +0 -89
  248. package/build/executor/ExecutorDetector.js.map +0 -1
  249. package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
  250. package/build/executor/IExecutorBytecodeBuilder.js +0 -3
  251. package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
  252. package/build/generic-swap-transaction-builder.d.ts +0 -39
  253. package/build/generic-swap-transaction-builder.js +0 -156
  254. package/build/generic-swap-transaction-builder.js.map +0 -1
  255. /package/build/dex/{lighter-v1 → wombat}/types.js +0 -0
@@ -0,0 +1,258 @@
1
+ import dotenv from 'dotenv';
2
+
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 { Wombat } from './wombat';
10
+ import {
11
+ checkPoolPrices,
12
+ checkPoolsLiquidity,
13
+ checkConstantPoolPrices,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+ import { Token } from '../../types';
17
+ import { Address } from '@paraswap/core';
18
+ import { WombatConfig } from './config';
19
+
20
+ function getReaderCalldata(
21
+ exchangeAddress: string,
22
+ readerIface: Interface,
23
+ side: SwapSide,
24
+ fromToken: Token,
25
+ toToken: Token,
26
+ amounts: bigint[],
27
+ funcName: string,
28
+ ) {
29
+ return amounts.map(amount => ({
30
+ target: exchangeAddress,
31
+ callData: readerIface.encodeFunctionData(
32
+ funcName,
33
+ side == SwapSide.SELL
34
+ ? [fromToken.address, toToken.address, amount]
35
+ : [toToken.address, fromToken.address, -amount],
36
+ ),
37
+ }));
38
+ }
39
+
40
+ function decodeReaderResult(
41
+ results: Result,
42
+ readerIface: Interface,
43
+ funcName: string,
44
+ ) {
45
+ return results.map(result => {
46
+ const parsed = readerIface.decodeFunctionResult(funcName, result);
47
+ return BigInt(parsed[0]._hex);
48
+ });
49
+ }
50
+
51
+ async function checkOnChainPricing(
52
+ wombat: Wombat,
53
+ pool: Address,
54
+ fromToken: Token,
55
+ toToken: Token,
56
+ side: SwapSide,
57
+ funcName: string,
58
+ blockNumber: number,
59
+ prices: bigint[],
60
+ amounts: bigint[],
61
+ ) {
62
+ const exchangeAddress = pool; // TODO: Put here the real exchange address
63
+
64
+ const readerIface = Wombat.poolInterface;
65
+
66
+ const readerCallData = getReaderCalldata(
67
+ exchangeAddress,
68
+ readerIface,
69
+ side,
70
+ fromToken,
71
+ toToken,
72
+ amounts.slice(1),
73
+ funcName,
74
+ );
75
+ const readerResult = (
76
+ await wombat.dexHelper.multiContract.methods
77
+ .aggregate(readerCallData)
78
+ .call({}, blockNumber)
79
+ ).returnData;
80
+
81
+ const expectedPrices = [0n].concat(
82
+ decodeReaderResult(readerResult, readerIface, funcName),
83
+ );
84
+
85
+ expect(prices).toEqual(expectedPrices);
86
+ }
87
+
88
+ async function testPricingOnNetwork(
89
+ wombat: Wombat,
90
+ network: Network,
91
+ dexKey: string,
92
+ blockNumber: number,
93
+ srcTokenSymbol: string,
94
+ destTokenSymbol: string,
95
+ side: SwapSide,
96
+ amounts: bigint[],
97
+ funcNameToCheck: string,
98
+ ) {
99
+ const networkTokens = Tokens[network];
100
+
101
+ const pools = await wombat.getPoolIdentifiers(
102
+ networkTokens[srcTokenSymbol],
103
+ networkTokens[destTokenSymbol],
104
+ side,
105
+ blockNumber,
106
+ );
107
+ console.log(
108
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
109
+ pools,
110
+ );
111
+
112
+ expect(pools.length).toBeGreaterThan(0);
113
+
114
+ const poolPrices = await wombat.getPricesVolume(
115
+ networkTokens[srcTokenSymbol],
116
+ networkTokens[destTokenSymbol],
117
+ amounts,
118
+ side,
119
+ blockNumber,
120
+ pools,
121
+ );
122
+ console.log(
123
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
124
+ poolPrices,
125
+ );
126
+
127
+ expect(poolPrices).not.toBeNull();
128
+ if (wombat.hasConstantPriceLargeAmounts) {
129
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
130
+ } else {
131
+ checkPoolPrices(poolPrices!, amounts, side, dexKey);
132
+ }
133
+
134
+ // Check if onchain pricing equals to calculated ones
135
+ await checkOnChainPricing(
136
+ wombat,
137
+ poolPrices![0].data.exchange,
138
+ networkTokens[srcTokenSymbol],
139
+ networkTokens[destTokenSymbol],
140
+ side,
141
+ funcNameToCheck,
142
+ blockNumber,
143
+ poolPrices![0].prices,
144
+ amounts,
145
+ );
146
+ }
147
+
148
+ describe('Wombat', function () {
149
+ const dexKey = 'Wombat';
150
+ let blockNumber: number;
151
+ let wombat: Wombat;
152
+
153
+ Object.keys(WombatConfig[dexKey]).forEach(key => {
154
+ describe(`network ${key}`, () => {
155
+ const network = Number(key) as Network;
156
+ const dexHelper = new DummyDexHelper(network);
157
+
158
+ const tokens = Tokens[network];
159
+
160
+ const srcTokenSymbol = 'USDC';
161
+ const destTokenSymbol = network == Network.BASE ? 'USDbC' : 'USDT';
162
+
163
+ let amountsForSell = [
164
+ 0n,
165
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
166
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
167
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
168
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
169
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
170
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
171
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
172
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
173
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
174
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
175
+ ];
176
+
177
+ let amountsForBuy = [
178
+ 0n,
179
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
180
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
181
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
182
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
183
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
184
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
185
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
186
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
187
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
188
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
189
+ ];
190
+
191
+ // OPTIMISM has very low liquidity currently, so we have to use very small amounts
192
+ // if (network === Network.OPTIMISM) {
193
+ // amountsForSell = amountsForSell.map(a => a / 100n);
194
+ // amountsForBuy = amountsForBuy.map(a => a / 100n);
195
+ // }
196
+
197
+ beforeAll(async () => {
198
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
199
+ wombat = new Wombat(network, dexKey, dexHelper);
200
+ });
201
+
202
+ it('getTopPoolsForToken', async function () {
203
+ // We have to check without calling initializePricing, because
204
+ // pool-tracker is not calling that function
205
+ if (wombat.updatePoolState) {
206
+ await wombat.updatePoolState();
207
+ }
208
+ const poolLiquidity = await wombat.getTopPoolsForToken(
209
+ tokens[srcTokenSymbol].address,
210
+ 10,
211
+ );
212
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
213
+
214
+ if (!wombat.hasConstantPriceLargeAmounts) {
215
+ checkPoolsLiquidity(
216
+ poolLiquidity,
217
+ Tokens[network][srcTokenSymbol].address,
218
+ dexKey,
219
+ );
220
+ }
221
+ });
222
+
223
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
224
+ if (wombat.initializePricing) {
225
+ await wombat.initializePricing(blockNumber);
226
+ }
227
+ await testPricingOnNetwork(
228
+ wombat,
229
+ network,
230
+ dexKey,
231
+ blockNumber,
232
+ srcTokenSymbol,
233
+ destTokenSymbol,
234
+ SwapSide.SELL,
235
+ amountsForSell,
236
+ 'quotePotentialSwap',
237
+ );
238
+ });
239
+
240
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
241
+ if (wombat.initializePricing) {
242
+ await wombat.initializePricing(blockNumber);
243
+ }
244
+ await testPricingOnNetwork(
245
+ wombat,
246
+ network,
247
+ dexKey,
248
+ blockNumber,
249
+ srcTokenSymbol,
250
+ destTokenSymbol,
251
+ SwapSide.BUY,
252
+ amountsForBuy,
253
+ 'quotePotentialSwap',
254
+ );
255
+ });
256
+ });
257
+ });
258
+ });
@@ -0,0 +1,231 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { Address } from '@paraswap/core';
3
+ import _ from 'lodash';
4
+
5
+ import { MultiCallParams, MultiResult } from '../../lib/multi-wrapper';
6
+ import { IDexHelper } from '../../dex-helper';
7
+ import { StatefulRpcPoller } from '../../lib/stateful-rpc-poller/stateful-rpc-poller';
8
+ import { StatePollingManager } from '../../lib/stateful-rpc-poller/state-polling-manager';
9
+ import { ObjWithUpdateInfo } from '../../lib/stateful-rpc-poller/types';
10
+ import { pollingManagerCbExtractor } from '../../lib/stateful-rpc-poller/utils';
11
+ import {
12
+ addressArrayDecode,
13
+ booleanDecode,
14
+ uint256ToBigInt,
15
+ uint8ToNumber,
16
+ } from '../../lib/decoders';
17
+ import PoolABI from '../../abi/wombat/pool.json';
18
+ import AssetABI from '../../abi/wombat/asset.json';
19
+ import { uint120ToBigInt } from './utils';
20
+ import { AssetState, MulticallResultOutputs, PoolState } from './types';
21
+
22
+ export class WombatPool extends StatefulRpcPoller<
23
+ PoolState,
24
+ MulticallResultOutputs
25
+ > {
26
+ static readonly poolInterface = new Interface(PoolABI);
27
+ static readonly assetInterface = new Interface(AssetABI);
28
+
29
+ constructor(
30
+ dexKey: string,
31
+ poolIdentifier: string,
32
+ dexHelper: IDexHelper,
33
+ protected poolAddress: Address,
34
+ protected asset2TokenMap: Map<Address, Address>,
35
+ ) {
36
+ const callbacks = pollingManagerCbExtractor(
37
+ StatePollingManager.getInstance(dexHelper),
38
+ );
39
+
40
+ super(dexKey, poolIdentifier, dexHelper, 0, 0, false, callbacks);
41
+ }
42
+
43
+ protected _getFetchStateMultiCalls(): MultiCallParams<MulticallResultOutputs>[] {
44
+ const params: MultiCallParams<MulticallResultOutputs>[] = [];
45
+
46
+ params.push({
47
+ target: this.poolAddress,
48
+ callData: WombatPool.poolInterface.encodeFunctionData('paused'),
49
+ decodeFunction: booleanDecode,
50
+ });
51
+ params.push({
52
+ target: this.poolAddress,
53
+ callData: WombatPool.poolInterface.encodeFunctionData('ampFactor'),
54
+ decodeFunction: uint256ToBigInt,
55
+ });
56
+ params.push({
57
+ target: this.poolAddress,
58
+ callData: WombatPool.poolInterface.encodeFunctionData('haircutRate'),
59
+ decodeFunction: uint256ToBigInt,
60
+ });
61
+ params.push({
62
+ target: this.poolAddress,
63
+ callData: WombatPool.poolInterface.encodeFunctionData('startCovRatio'),
64
+ decodeFunction: uint256ToBigInt,
65
+ });
66
+ params.push({
67
+ target: this.poolAddress,
68
+ callData: WombatPool.poolInterface.encodeFunctionData('endCovRatio'),
69
+ decodeFunction: uint256ToBigInt,
70
+ });
71
+ params.push({
72
+ target: this.poolAddress,
73
+ callData: WombatPool.poolInterface.encodeFunctionData('getTokens'),
74
+ decodeFunction: addressArrayDecode,
75
+ });
76
+
77
+ this.asset2TokenMap.forEach((token, asset) => {
78
+ params.push({
79
+ target: this.poolAddress,
80
+ callData: WombatPool.poolInterface.encodeFunctionData('isPaused', [
81
+ token,
82
+ ]),
83
+ decodeFunction: booleanDecode,
84
+ });
85
+ params.push({
86
+ target: asset,
87
+ callData: WombatPool.assetInterface.encodeFunctionData('cash'),
88
+ decodeFunction: uint120ToBigInt,
89
+ });
90
+ params.push({
91
+ target: asset,
92
+ callData: WombatPool.assetInterface.encodeFunctionData('liability'),
93
+ decodeFunction: uint120ToBigInt,
94
+ });
95
+ params.push({
96
+ target: asset,
97
+ callData: WombatPool.assetInterface.encodeFunctionData(
98
+ 'underlyingTokenDecimals',
99
+ ),
100
+ decodeFunction: uint8ToNumber,
101
+ });
102
+ params.push({
103
+ target: asset,
104
+ callData:
105
+ WombatPool.assetInterface.encodeFunctionData('getRelativePrice'),
106
+ decodeFunction: uint256ToBigInt,
107
+ });
108
+ });
109
+
110
+ return params;
111
+ }
112
+
113
+ protected _parseStateFromMultiResults(
114
+ multiOutputs: MulticallResultOutputs[],
115
+ ): PoolState {
116
+ const [
117
+ paused,
118
+ ampFactor,
119
+ haircutRate,
120
+ startCovRatio,
121
+ endCovRatio,
122
+ tokens,
123
+ ...remained
124
+ ] = multiOutputs as [
125
+ boolean,
126
+ bigint,
127
+ bigint,
128
+ bigint,
129
+ bigint,
130
+ Address[],
131
+ ...MulticallResultOutputs[],
132
+ ];
133
+
134
+ const assetTokenArray = Array.from(this.asset2TokenMap.entries());
135
+ const token2AssetStates = new Map<Address, AssetState>();
136
+ _.chunk(remained, 5).forEach((chunk, i) => {
137
+ const [paused, cash, liability, underlyingTokenDecimals, relativePrice] =
138
+ chunk as [boolean, bigint, bigint, number, bigint | undefined];
139
+
140
+ const [asset, token] = assetTokenArray[i];
141
+ token2AssetStates.set(token, {
142
+ address: asset,
143
+ paused,
144
+ cash,
145
+ liability,
146
+ underlyingTokenDecimals,
147
+ relativePrice,
148
+ });
149
+ });
150
+
151
+ const poolState: PoolState = {
152
+ params: {
153
+ paused,
154
+ ampFactor,
155
+ haircutRate,
156
+ startCovRatio,
157
+ endCovRatio,
158
+ },
159
+ underlyingAddresses: tokens,
160
+ asset: {},
161
+ };
162
+
163
+ const isMainPool =
164
+ Array.from(token2AssetStates.values()).filter(
165
+ assetState => assetState.relativePrice === undefined,
166
+ ).length > 0;
167
+ for (const token of poolState.underlyingAddresses) {
168
+ if (!token2AssetStates.has(token)) {
169
+ // this happens when asset has been added to pool but is not added to BMW yet
170
+ continue;
171
+ }
172
+ poolState.asset[token] = token2AssetStates.get(token)!;
173
+ if (isMainPool) {
174
+ poolState.asset[token].relativePrice = undefined;
175
+ }
176
+ }
177
+
178
+ return poolState;
179
+ }
180
+
181
+ public async fetchLatestStateFromRpc(): Promise<ObjWithUpdateInfo<PoolState> | null> {
182
+ const multiCalls = this.getFetchStateWithBlockInfoMultiCalls();
183
+ try {
184
+ const lastUpdatedAtMs = Date.now();
185
+ const aggregatedResults = (await this.dexHelper.multiWrapper.tryAggregate<
186
+ number | MulticallResultOutputs
187
+ >(
188
+ false,
189
+ multiCalls as MultiCallParams<MulticallResultOutputs | number>[],
190
+ )) as [MultiResult<number>, ...MultiResult<MulticallResultOutputs>[]];
191
+
192
+ return this.parseStateFromMultiResultsWithBlockInfo(
193
+ aggregatedResults,
194
+ lastUpdatedAtMs,
195
+ );
196
+ } catch (e) {
197
+ this._logMessageWithSuppression('ERROR_FETCHING_STATE_FROM_RPC', e);
198
+ }
199
+
200
+ return null;
201
+ }
202
+
203
+ public parseStateFromMultiResultsWithBlockInfo(
204
+ multiOutputs: [
205
+ MultiResult<number>,
206
+ ...MultiResult<MulticallResultOutputs>[],
207
+ ],
208
+ lastUpdatedAtMs: number,
209
+ ): ObjWithUpdateInfo<PoolState> {
210
+ const [blockNumber, ...outputsForAbstract] = multiOutputs.map((m, i) => {
211
+ return m.returnData;
212
+ }) as [number, ...MulticallResultOutputs[]];
213
+
214
+ return {
215
+ value: this._parseStateFromMultiResults(outputsForAbstract),
216
+ blockNumber,
217
+ lastUpdatedAtMs,
218
+ };
219
+ }
220
+
221
+ public addAssets(asset2TokenMap: Map<Address, Address>) {
222
+ for (const [asset, token] of asset2TokenMap) {
223
+ if (this.asset2TokenMap.has(asset)) {
224
+ continue;
225
+ }
226
+
227
+ this.asset2TokenMap.set(asset, token);
228
+ this._cachedMultiCallData = undefined;
229
+ }
230
+ }
231
+ }