@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
package/src/config.ts CHANGED
@@ -308,9 +308,8 @@ const baseConfigs: { [network: number]: BaseConfig } = {
308
308
  hashFlowAuthToken: process.env.API_KEY_HASHFLOW_AUTH_TOKEN || '',
309
309
  hashFlowDisabledMMs:
310
310
  process.env[`HASHFLOW_DISABLED_MMS_10`]?.split(',') || [],
311
-
312
311
  adapterAddresses: {
313
- OptimismAdapter01: '0x654dE10890f8B2C5bF54E50Af169a7E93165C416',
312
+ OptimismAdapter01: '0x5dcf544b0c9689fa67dcb713fd2656d217e25a59',
314
313
  OptimismBuyAdapter: '0xA10c9a84E72d9DfF424Fe2284B6460784bed407E',
315
314
  },
316
315
  uniswapV2ExchangeRouterAddress:
package/src/dex/index.ts CHANGED
@@ -38,6 +38,7 @@ import { Excalibur } from './uniswap-v2/excalibur';
38
38
  import { MakerPsm } from './maker-psm/maker-psm';
39
39
  import { KyberDmm } from './kyberdmm/kyberdmm';
40
40
  import { Platypus } from './platypus/platypus';
41
+ import { Wombat } from './wombat/wombat';
41
42
  import { GMX } from './gmx/gmx';
42
43
  import { WooFiV2 } from './woo-fi-v2/woo-fi-v2';
43
44
  import { ParaSwapLimitOrders } from './paraswap-limit-orders/paraswap-limit-orders';
@@ -157,6 +158,7 @@ const Dexes = [
157
158
  SwaapV2,
158
159
  QuickPerps,
159
160
  NomiswapV2,
161
+ Wombat,
160
162
  ];
161
163
 
162
164
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -0,0 +1,77 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap, AdapterMappings } from '../../types';
3
+ import { Network, SwapSide } from '../../constants';
4
+
5
+ export const WombatConfig: DexConfigMap<DexParams> = {
6
+ Wombat: {
7
+ [Network.BSC]: {
8
+ bmwAddress: '0x489833311676B566f888119c29bd997Dc6C95830',
9
+ },
10
+ [Network.ARBITRUM]: {
11
+ bmwAddress: '0x62A83C6791A3d7950D823BB71a38e47252b6b6F4',
12
+ },
13
+ [Network.MAINNET]: {
14
+ bmwAddress: '0xC9bFC3eFeFe4CF96877009F75a61F5c1937e5d1a',
15
+ },
16
+ [Network.AVALANCHE]: {
17
+ bmwAddress: '0x6521a549834F5E6d253CD2e5F4fbe4048f86cd7b',
18
+ },
19
+ [Network.BASE]: {
20
+ bmwAddress: '0x6521a549834F5E6d253CD2e5F4fbe4048f86cd7b',
21
+ },
22
+ [Network.OPTIMISM]: {
23
+ bmwAddress: '0x25C9dd8a3774EF7C918cd28ff59cF9e29504C914',
24
+ },
25
+ },
26
+ };
27
+
28
+ export const Adapters: Record<number, AdapterMappings> = {
29
+ [Network.BSC]: {
30
+ [SwapSide.SELL]: [
31
+ {
32
+ name: 'BscAdapter02',
33
+ index: 7,
34
+ },
35
+ ],
36
+ },
37
+ [Network.ARBITRUM]: {
38
+ [SwapSide.SELL]: [
39
+ {
40
+ name: 'ArbitrumAdapter02',
41
+ index: 8,
42
+ },
43
+ ],
44
+ },
45
+ [Network.MAINNET]: {
46
+ [SwapSide.SELL]: [
47
+ {
48
+ name: 'Adapter03',
49
+ index: 15,
50
+ },
51
+ ],
52
+ },
53
+ [Network.AVALANCHE]: {
54
+ [SwapSide.SELL]: [
55
+ {
56
+ name: 'AvalancheAdapter02',
57
+ index: 7,
58
+ },
59
+ ],
60
+ },
61
+ [Network.BASE]: {
62
+ [SwapSide.SELL]: [
63
+ {
64
+ name: 'BaseAdapter01',
65
+ index: 7,
66
+ },
67
+ ],
68
+ },
69
+ [Network.OPTIMISM]: {
70
+ [SwapSide.SELL]: [
71
+ {
72
+ name: 'OptimismAdapter01',
73
+ index: 12,
74
+ },
75
+ ],
76
+ },
77
+ };
@@ -0,0 +1,55 @@
1
+ import { Address } from '../../types';
2
+
3
+ // State-related types
4
+
5
+ export type BmwState = {
6
+ pools: Address[];
7
+ };
8
+
9
+ export type PoolState = {
10
+ // poolState is the state of event
11
+ // subscriber. This should be the minimum
12
+ // set of parameters required to compute
13
+ // pool prices.
14
+ params: PoolParams;
15
+ underlyingAddresses: Address[];
16
+ asset: { [underlyingAddress: string]: AssetState };
17
+ };
18
+
19
+ export type AssetState = {
20
+ address: Address;
21
+ paused: boolean;
22
+ cash: bigint;
23
+ liability: bigint;
24
+ underlyingTokenDecimals: number;
25
+ relativePrice?: bigint;
26
+ };
27
+
28
+ export type PoolParams = {
29
+ paused: boolean;
30
+ ampFactor: bigint;
31
+ haircutRate: bigint;
32
+ startCovRatio: bigint;
33
+ endCovRatio: bigint;
34
+ };
35
+
36
+ export type WombatData = {
37
+ // TODO: WombatData is the dex data that is
38
+ // returned by the API that can be used for
39
+ // tx building. The data structure should be minimal.
40
+ // Complete me!
41
+ exchange: Address;
42
+ };
43
+
44
+ export type DexParams = {
45
+ // DexParams is set of parameters that can be used to initiate a DEX fork.
46
+ bmwAddress: Address;
47
+ // routerAddress?: Address;
48
+ };
49
+
50
+ export type MulticallResultOutputs =
51
+ | boolean
52
+ | bigint
53
+ | Address
54
+ | number
55
+ | undefined;
@@ -0,0 +1,62 @@
1
+ import { BI_POWS } from '../../bigint-constants';
2
+ import { MultiResult } from '../../lib/multi-wrapper';
3
+ import { BytesLike } from 'ethers/lib/utils';
4
+ import { generalDecoder } from '../../lib/decoders';
5
+
6
+ export const WAD = BI_POWS[18];
7
+
8
+ export function wmul(x: bigint, y: bigint): bigint {
9
+ return (x * y + WAD / 2n) / WAD;
10
+ }
11
+
12
+ export function wdiv(x: bigint, y: bigint): bigint {
13
+ return (x * WAD + y / 2n) / y;
14
+ }
15
+
16
+ // Convert x to WAD (18 decimals) from d decimals.
17
+ export function toWad(x: bigint, d: bigint): bigint {
18
+ if (d < 18n) {
19
+ return x * 10n ** (18n - d);
20
+ } else if (d > 18n) {
21
+ return x / 10n ** (d - 18n);
22
+ }
23
+ return x;
24
+ }
25
+ // Convert x from WAD (18 decimals) to d decimals.
26
+ export function fromWad(x: bigint, d: bigint): bigint {
27
+ if (d < 18n) {
28
+ return x / 10n ** (18n - d);
29
+ } else if (d > 18n) {
30
+ return x * 10n ** (d - 18n);
31
+ }
32
+ return x;
33
+ }
34
+
35
+ // Babylonian Method with initial guess (typecast as int)
36
+ export function sqrt(y: bigint, guess: bigint): bigint {
37
+ let z = 0n;
38
+ if (y > 3) {
39
+ if (guess > 0 && guess <= y) {
40
+ z = guess;
41
+ } else if (guess < 0 && -guess <= y) {
42
+ z = -guess;
43
+ } else {
44
+ z = y;
45
+ }
46
+ let x = (y / z + z) / 2n;
47
+ while (x != z) {
48
+ z = x;
49
+ x = (y / x + x) / 2n;
50
+ }
51
+ } else if (y != 0n) {
52
+ z = 1n;
53
+ }
54
+
55
+ return z;
56
+ }
57
+
58
+ export const uint120ToBigInt = (
59
+ result: MultiResult<BytesLike> | BytesLike,
60
+ ): bigint => {
61
+ return generalDecoder(result, ['uint120'], 0n, value => value[0].toBigInt());
62
+ };
@@ -0,0 +1,209 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { BytesLike } from 'ethers';
3
+ import { LogDescription } from 'ethers/lib/utils';
4
+ import { Contract } from 'web3-eth-contract';
5
+ import { DeepReadonly } from 'ts-essentials';
6
+ import { Address, Log, Logger, MultiCallInput } from '../../types';
7
+ import { catchParseLogError } from '../../utils';
8
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
9
+ import { IDexHelper } from '../../dex-helper';
10
+ import { BmwState } from './types';
11
+ import BmwABI from '../../abi/wombat/bmw.json';
12
+ import AssetABI from '../../abi/wombat/asset.json';
13
+ import PoolABI from '../../abi/wombat/pool.json';
14
+
15
+ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
16
+ static readonly bmwInterface = new Interface(BmwABI);
17
+ static readonly assetInterface = new Interface(AssetABI);
18
+ static readonly poolInterface = new Interface(PoolABI);
19
+
20
+ private readonly logDecoder: (log: Log) => any;
21
+ private bmwContract: Contract;
22
+ private handlers: {
23
+ [event: string]: (
24
+ event: any,
25
+ state: DeepReadonly<BmwState>,
26
+ log: Readonly<Log>,
27
+ ) => Promise<DeepReadonly<BmwState> | null>;
28
+ } = {};
29
+
30
+ constructor(
31
+ dexKey: string,
32
+ name: string,
33
+ protected network: number,
34
+ protected dexHelper: IDexHelper,
35
+ logger: Logger,
36
+ protected bmwAddress: Address,
37
+ protected onAssetAdded: (
38
+ pool: Address,
39
+ asset2TokenMap: Map<Address, Address>,
40
+ blockNumber: number,
41
+ ) => Promise<void>,
42
+ ) {
43
+ super(
44
+ `${dexKey} ${name}`,
45
+ `${dexKey}-${network} ${name}`,
46
+ dexHelper,
47
+ logger,
48
+ );
49
+
50
+ this.logDecoder = (log: Log) => WombatBmw.bmwInterface.parseLog(log);
51
+ this.addressesSubscribed = [this.bmwAddress];
52
+ this.bmwContract = new this.dexHelper.web3Provider.eth.Contract(
53
+ BmwABI as any,
54
+ this.bmwAddress,
55
+ );
56
+
57
+ // users-actions handlers
58
+ this.handlers['Add'] = this.handleAdd.bind(this);
59
+ }
60
+
61
+ /**
62
+ * The function is called every time any of the subscribed
63
+ * addresses release log. The function accepts the current
64
+ * state, updates the state according to the log, and returns
65
+ * the updated state.
66
+ * @param state - Current state of event subscriber
67
+ * @param log - Log released by one of the subscribed addresses
68
+ * @returns Updates state of the event subscriber after the log
69
+ */
70
+ protected async processLog(
71
+ state: DeepReadonly<BmwState>,
72
+ log: Readonly<Log>,
73
+ ): Promise<DeepReadonly<BmwState> | null> {
74
+ try {
75
+ const event = this.logDecoder(log);
76
+ if (event.name in this.handlers) {
77
+ return await this.handlers[event.name](event, state, log);
78
+ }
79
+ } catch (e) {
80
+ catchParseLogError(e, this.logger);
81
+ }
82
+
83
+ return null;
84
+ }
85
+
86
+ /**
87
+ * The function generates state using on-chain calls. This
88
+ * function is called to regenerate state if the event based
89
+ * system fails to fetch events and the local state is no
90
+ * more correct.
91
+ * should be generated
92
+ * @returns state of the event subscriber at blocknumber
93
+ */
94
+ async generateState(blockNumber: number): Promise<DeepReadonly<BmwState>> {
95
+ const bmwState: BmwState = { pools: [] };
96
+ let inputs: MultiCallInput[] = [];
97
+
98
+ const poolLength = await this.bmwContract.methods
99
+ .poolLength()
100
+ .call({}, blockNumber);
101
+ for (let i = 0; i < poolLength; i++) {
102
+ inputs.push({
103
+ target: this.bmwAddress,
104
+ callData: WombatBmw.bmwInterface.encodeFunctionData('poolInfo', [i]),
105
+ });
106
+ }
107
+ let returnData = (
108
+ await this.dexHelper.multiContract.methods
109
+ .aggregate(inputs)
110
+ .call({}, blockNumber)
111
+ ).returnData;
112
+
113
+ const lpTokens = returnData.map((data: BytesLike) =>
114
+ WombatBmw.bmwInterface
115
+ .decodeFunctionResult('poolInfo', data)[0]
116
+ .toLowerCase(),
117
+ );
118
+
119
+ inputs = [];
120
+ for (const lpToken of lpTokens) {
121
+ inputs.push({
122
+ target: lpToken,
123
+ callData:
124
+ WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
125
+ });
126
+ inputs.push({
127
+ target: lpToken,
128
+ callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
129
+ });
130
+ }
131
+
132
+ returnData = (
133
+ await this.dexHelper.multiContract.methods
134
+ .aggregate(inputs)
135
+ .call({}, blockNumber)
136
+ ).returnData;
137
+
138
+ const pool2AssetInfo = new Map<Address, Map<Address, Address>>();
139
+ let i = 0;
140
+ for (const lpToken of lpTokens) {
141
+ const underlyingToken = WombatBmw.assetInterface
142
+ .decodeFunctionResult('underlyingToken', returnData[i++])[0]
143
+ .toLowerCase();
144
+ const pool = WombatBmw.assetInterface
145
+ .decodeFunctionResult('pool', returnData[i++])[0]
146
+ .toLowerCase();
147
+
148
+ if (!pool2AssetInfo.has(pool)) {
149
+ pool2AssetInfo.set(pool, new Map<Address, Address>());
150
+ }
151
+ pool2AssetInfo.get(pool)!.set(lpToken, underlyingToken);
152
+ }
153
+
154
+ const promises: Promise<void>[] = [];
155
+ pool2AssetInfo.forEach((asset2TokenMap, pool) => {
156
+ bmwState.pools.push(pool);
157
+ promises.push(this.onAssetAdded(pool, asset2TokenMap, blockNumber));
158
+ });
159
+ await Promise.all(promises);
160
+
161
+ return bmwState;
162
+ }
163
+
164
+ async handleAdd(
165
+ event: LogDescription,
166
+ state: DeepReadonly<BmwState>,
167
+ log: Readonly<Log>,
168
+ ): Promise<DeepReadonly<BmwState> | null> {
169
+ const lpToken = event.args.lpToken.toString().toLowerCase();
170
+ let multiCallInputs: MultiCallInput[] = [];
171
+
172
+ multiCallInputs.push({
173
+ target: lpToken,
174
+ callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
175
+ });
176
+ multiCallInputs.push({
177
+ target: lpToken,
178
+ callData: WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
179
+ });
180
+
181
+ const returnData = (
182
+ await this.dexHelper.multiContract.methods
183
+ .aggregate(multiCallInputs)
184
+ .call({}, log.blockNumber)
185
+ ).returnData;
186
+
187
+ const pool = WombatBmw.assetInterface
188
+ .decodeFunctionResult('pool', returnData[0])[0]
189
+ .toLowerCase();
190
+ const underlyingToken = WombatBmw.assetInterface
191
+ .decodeFunctionResult('underlyingToken', returnData[1])[0]
192
+ .toLowerCase();
193
+
194
+ await this.onAssetAdded(
195
+ pool,
196
+ new Map<Address, Address>().set(lpToken, underlyingToken),
197
+ log.blockNumber,
198
+ );
199
+ if (!state.pools.includes(pool)) {
200
+ return {
201
+ pools: [...state.pools, pool],
202
+ };
203
+ } else {
204
+ return {
205
+ pools: state.pools,
206
+ };
207
+ }
208
+ }
209
+ }
@@ -0,0 +1,264 @@
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
+ type Pairs = { name: string; sellAmount: string; buyAmount: string }[][];
15
+
16
+ function testForNetwork(
17
+ network: Network,
18
+ dexKey: string,
19
+ pairs: Pairs,
20
+ slippage?: number | undefined,
21
+ ) {
22
+ const provider = new StaticJsonRpcProvider(
23
+ generateConfig(network).privateHttpProvider,
24
+ network,
25
+ );
26
+ const tokens = Tokens[network];
27
+ const holders = Holders[network];
28
+
29
+ const sideToContractMethods = new Map([
30
+ [
31
+ SwapSide.SELL,
32
+ [
33
+ ContractMethod.simpleSwap,
34
+ ContractMethod.multiSwap,
35
+ ContractMethod.megaSwap,
36
+ ],
37
+ ],
38
+ [SwapSide.BUY, [ContractMethod.simpleBuy /* ContractMethod.buy */]],
39
+ ]);
40
+
41
+ sideToContractMethods.forEach((contractMethods, side) =>
42
+ describe(`${side}`, () => {
43
+ contractMethods.forEach((contractMethod: ContractMethod) => {
44
+ pairs.forEach(pair => {
45
+ describe(`${contractMethod}`, () => {
46
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
47
+ await testE2E(
48
+ tokens[pair[0].name],
49
+ tokens[pair[1].name],
50
+ holders[pair[0].name],
51
+ side === SwapSide.SELL ? pair[0].sellAmount : pair[0].buyAmount,
52
+ side,
53
+ dexKey,
54
+ contractMethod,
55
+ network,
56
+ provider,
57
+ undefined,
58
+ undefined,
59
+ undefined,
60
+ slippage,
61
+ );
62
+ });
63
+
64
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
65
+ await testE2E(
66
+ tokens[pair[1].name],
67
+ tokens[pair[0].name],
68
+ holders[pair[1].name],
69
+ side === SwapSide.SELL ? pair[1].sellAmount : pair[1].buyAmount,
70
+ side,
71
+ dexKey,
72
+ contractMethod,
73
+ network,
74
+ provider,
75
+ undefined,
76
+ undefined,
77
+ undefined,
78
+ slippage,
79
+ );
80
+ });
81
+ });
82
+ });
83
+ });
84
+ }),
85
+ );
86
+ }
87
+
88
+ describe('Wombat E2E', () => {
89
+ const dexKey = 'Wombat';
90
+
91
+ describe('BSC', () => {
92
+ const network = Network.BSC;
93
+
94
+ const pairs: Pairs = [
95
+ [
96
+ {
97
+ name: 'USDC',
98
+ sellAmount: '1000000000',
99
+ buyAmount: '1000000000',
100
+ },
101
+ {
102
+ name: 'USDT',
103
+ sellAmount: '1000000000',
104
+ buyAmount: '1000000000',
105
+ },
106
+ ],
107
+ [
108
+ {
109
+ name: 'BNB',
110
+ sellAmount: '1000000000000000000',
111
+ buyAmount: '1000000000000000000',
112
+ },
113
+ {
114
+ name: 'BNBx',
115
+ sellAmount: '1000000000000000000',
116
+ buyAmount: '1000000000000000000',
117
+ },
118
+ ],
119
+ ];
120
+
121
+ testForNetwork(network, dexKey, pairs);
122
+ });
123
+
124
+ describe('Arbitrum', () => {
125
+ const network = Network.ARBITRUM;
126
+
127
+ const pairs: Pairs = [
128
+ [
129
+ {
130
+ name: 'USDC',
131
+ sellAmount: '100000000',
132
+ buyAmount: '100000000',
133
+ },
134
+ {
135
+ name: 'USDT',
136
+ sellAmount: '100000000',
137
+ buyAmount: '100000000',
138
+ },
139
+ ],
140
+ [
141
+ {
142
+ name: 'ETH',
143
+ sellAmount: '10000000000000000',
144
+ buyAmount: '10000000000000000',
145
+ },
146
+ {
147
+ name: 'wstETH',
148
+ sellAmount: '10000000000000000',
149
+ buyAmount: '10000000000000000',
150
+ },
151
+ ],
152
+ ];
153
+
154
+ testForNetwork(network, dexKey, pairs);
155
+ });
156
+
157
+ describe('Ethereum', () => {
158
+ const network = Network.MAINNET;
159
+
160
+ const pairs: Pairs = [
161
+ [
162
+ {
163
+ name: 'USDC',
164
+ sellAmount: '100000000',
165
+ buyAmount: '100000000',
166
+ },
167
+ {
168
+ name: 'USDT',
169
+ sellAmount: '100000000',
170
+ buyAmount: '100000000',
171
+ },
172
+ ],
173
+ [
174
+ {
175
+ name: 'ETH',
176
+ sellAmount: '1000000000000000000',
177
+ buyAmount: '1000000000000000000',
178
+ },
179
+ {
180
+ name: 'wstETH',
181
+ sellAmount: '1000000000000000000',
182
+ buyAmount: '1000000000000000000',
183
+ },
184
+ ],
185
+ ];
186
+
187
+ testForNetwork(network, dexKey, pairs);
188
+ });
189
+
190
+ describe('Avalanche', () => {
191
+ const network = Network.AVALANCHE;
192
+
193
+ const pairs: Pairs = [
194
+ [
195
+ {
196
+ name: 'USDC',
197
+ sellAmount: '10000000',
198
+ buyAmount: '10000000',
199
+ },
200
+ {
201
+ name: 'USDT',
202
+ sellAmount: '10000000',
203
+ buyAmount: '10000000',
204
+ },
205
+ ],
206
+ [
207
+ {
208
+ name: 'AVAX',
209
+ sellAmount: '100000000000000000000',
210
+ buyAmount: '100000000000000000000',
211
+ },
212
+ {
213
+ name: 'sAVAX',
214
+ sellAmount: '100000000000000000000',
215
+ buyAmount: '100000000000000000000',
216
+ },
217
+ ],
218
+ ];
219
+
220
+ testForNetwork(network, dexKey, pairs);
221
+ });
222
+
223
+ describe('Base', () => {
224
+ const network = Network.BASE;
225
+
226
+ const pairs: Pairs = [
227
+ [
228
+ {
229
+ name: 'USDC',
230
+ sellAmount: '100000000',
231
+ buyAmount: '100000000',
232
+ },
233
+ {
234
+ name: 'USDbC',
235
+ sellAmount: '100000000',
236
+ buyAmount: '100000000',
237
+ },
238
+ ],
239
+ ];
240
+
241
+ testForNetwork(network, dexKey, pairs);
242
+ });
243
+
244
+ describe('Optimism', () => {
245
+ const network = Network.OPTIMISM;
246
+
247
+ const pairs: Pairs = [
248
+ [
249
+ {
250
+ name: 'USDC',
251
+ sellAmount: '100000000',
252
+ buyAmount: '100000000',
253
+ },
254
+ {
255
+ name: 'USDT',
256
+ sellAmount: '100000000',
257
+ buyAmount: '100000000',
258
+ },
259
+ ],
260
+ ];
261
+
262
+ testForNetwork(network, dexKey, pairs);
263
+ });
264
+ });