@paraswap/dex-lib 3.6.1 → 3.6.2

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 (281) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/maverick-v2/MaverickV2Pool.json +1234 -0
  5. package/build/abi/maverick-v2/MaverickV2PoolLens.json +1232 -0
  6. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  7. package/build/abi/{integral/relayer.json → wombat/pool.json} +587 -446
  8. package/build/dex/maker-psm/maker-psm.js +1 -1
  9. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  10. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  11. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  12. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  13. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  14. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  15. package/build/dex/maverick-v2/config.d.ts +6 -0
  16. package/build/dex/maverick-v2/config.js +21 -0
  17. package/build/dex/maverick-v2/config.js.map +1 -0
  18. package/build/dex/maverick-v2/maverick-math/maverick-basic-math.d.ts +24 -0
  19. package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js +117 -0
  20. package/build/dex/maverick-v2/maverick-math/maverick-basic-math.js.map +1 -0
  21. package/build/dex/maverick-v2/maverick-math/maverick-bin-math.d.ts +17 -0
  22. package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js +114 -0
  23. package/build/dex/maverick-v2/maverick-math/maverick-bin-math.js.map +1 -0
  24. package/build/dex/maverick-v2/maverick-math/maverick-delta-math.d.ts +19 -0
  25. package/build/dex/maverick-v2/maverick-math/maverick-delta-math.js +20 -0
  26. package/build/dex/maverick-v2/maverick-math/maverick-delta-math.js.map +1 -0
  27. package/build/dex/maverick-v2/maverick-math/maverick-math.d.ts +5 -0
  28. package/build/dex/maverick-v2/maverick-math/maverick-math.js +33 -0
  29. package/build/dex/maverick-v2/maverick-math/maverick-math.js.map +1 -0
  30. package/build/dex/maverick-v2/maverick-math/maverick-pool-lib.d.ts +6 -0
  31. package/build/dex/maverick-v2/maverick-math/maverick-pool-lib.js +24 -0
  32. package/build/dex/maverick-v2/maverick-math/maverick-pool-lib.js.map +1 -0
  33. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.d.ts +37 -0
  34. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +440 -0
  35. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -0
  36. package/build/dex/maverick-v2/maverick-math/maverick-swap-math.d.ts +9 -0
  37. package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js +102 -0
  38. package/build/dex/maverick-v2/maverick-math/maverick-swap-math.js.map +1 -0
  39. package/build/dex/maverick-v2/maverick-math/maverick-tick-math.d.ts +8 -0
  40. package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js +109 -0
  41. package/build/dex/maverick-v2/maverick-math/maverick-tick-math.js.map +1 -0
  42. package/build/dex/maverick-v2/maverick-math/maverick-twa-math.d.ts +7 -0
  43. package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js +35 -0
  44. package/build/dex/maverick-v2/maverick-math/maverick-twa-math.js.map +1 -0
  45. package/build/dex/maverick-v2/maverick-v2-pool.d.ts +57 -0
  46. package/build/dex/maverick-v2/maverick-v2-pool.js +184 -0
  47. package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -0
  48. package/build/dex/maverick-v2/maverick-v2.d.ts +47 -0
  49. package/build/dex/maverick-v2/maverick-v2.js +294 -0
  50. package/build/dex/maverick-v2/maverick-v2.js.map +1 -0
  51. package/build/dex/maverick-v2/types.d.ts +144 -0
  52. package/build/dex/{woo-fi → maverick-v2}/types.js.map +1 -1
  53. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  54. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  55. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  56. package/build/dex/stable-pool.js +1 -8
  57. package/build/dex/stable-pool.js.map +1 -1
  58. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  59. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  60. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  61. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  62. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  63. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  64. package/package.json +1 -1
  65. package/src/dex/maker-psm/maker-psm.ts +2 -3
  66. package/src/dex/maker-psm/scripts/gem.abi.json +136 -0
  67. package/src/dex/maker-psm/scripts/validate-state.ts +221 -0
  68. package/src/dex/maker-psm/scripts/vat.abi.json +243 -0
  69. package/.idea/aws.xml +0 -17
  70. package/.idea/codeStyles/Project.xml +0 -19
  71. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  72. package/.idea/misc.xml +0 -6
  73. package/.idea/modules.xml +0 -8
  74. package/.idea/paraswap-dex-lib.iml +0 -9
  75. package/.idea/prettier.xml +0 -7
  76. package/.idea/vcs.xml +0 -6
  77. package/build/abi/AugustusV6.abi.json +0 -395
  78. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  79. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  80. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  81. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  82. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  83. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  84. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  85. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  86. package/build/abi/wBETH.json +0 -1527
  87. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  88. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  89. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  90. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  91. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  92. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  93. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  94. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  95. package/build/dex/algebra/algebra-pool.d.ts +0 -114
  96. package/build/dex/algebra/algebra-pool.js +0 -448
  97. package/build/dex/algebra/algebra-pool.js.map +0 -1
  98. package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
  99. package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
  100. package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
  101. package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
  102. package/build/dex/balancer-v2/LinearMath.js +0 -285
  103. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  104. package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
  105. package/build/dex/balancer-v2/LinearPool.js +0 -444
  106. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  107. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
  108. package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
  109. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  110. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  111. package/build/dex/balancer-v2/StableMath.js +0 -272
  112. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  113. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
  114. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
  115. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  116. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  117. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  118. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  119. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  120. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  121. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  122. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.d.ts +0 -4
  123. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +0 -80
  124. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +0 -1
  125. package/build/dex/curve-v1-stable-ng/config.d.ts +0 -5
  126. package/build/dex/curve-v1-stable-ng/config.js +0 -268
  127. package/build/dex/curve-v1-stable-ng/config.js.map +0 -1
  128. package/build/dex/curve-v1-stable-ng/curve-v1-stable-ng.d.ts +0 -18
  129. package/build/dex/curve-v1-stable-ng/curve-v1-stable-ng.js +0 -23
  130. package/build/dex/curve-v1-stable-ng/curve-v1-stable-ng.js.map +0 -1
  131. package/build/dex/integral/config.d.ts +0 -4
  132. package/build/dex/integral/config.js +0 -18
  133. package/build/dex/integral/config.js.map +0 -1
  134. package/build/dex/integral/integral-pool.d.ts +0 -39
  135. package/build/dex/integral/integral-pool.js +0 -67
  136. package/build/dex/integral/integral-pool.js.map +0 -1
  137. package/build/dex/integral/integral.d.ts +0 -48
  138. package/build/dex/integral/integral.js +0 -402
  139. package/build/dex/integral/integral.js.map +0 -1
  140. package/build/dex/integral/types.d.ts +0 -25
  141. package/build/dex/integral/types.js +0 -9
  142. package/build/dex/integral/types.js.map +0 -1
  143. package/build/dex/lighter-v1/abi/erc20.json +0 -222
  144. package/build/dex/lighter-v1/abi/factory.json +0 -291
  145. package/build/dex/lighter-v1/abi/order_book.json +0 -594
  146. package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
  147. package/build/dex/lighter-v1/abi/router.json +0 -488
  148. package/build/dex/lighter-v1/config.d.ts +0 -4
  149. package/build/dex/lighter-v1/config.js +0 -17
  150. package/build/dex/lighter-v1/config.js.map +0 -1
  151. package/build/dex/lighter-v1/constants.d.ts +0 -2
  152. package/build/dex/lighter-v1/constants.js +0 -13
  153. package/build/dex/lighter-v1/constants.js.map +0 -1
  154. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
  155. package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
  156. package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
  157. package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
  158. package/build/dex/lighter-v1/lighter-v1.js +0 -331
  159. package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
  160. package/build/dex/lighter-v1/types.d.ts +0 -40
  161. package/build/dex/lighter-v1/types.js.map +0 -1
  162. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  163. package/build/dex/pancakeswap-v3/types.js +0 -3
  164. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  165. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  166. package/build/dex/quickswap/camelot-v3.js +0 -19
  167. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  168. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  169. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  170. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  171. package/build/dex/quickswap-v3.d.ts +0 -21
  172. package/build/dex/quickswap-v3.js +0 -40
  173. package/build/dex/quickswap-v3.js.map +0 -1
  174. package/build/dex/ramses-v2/config.d.ts +0 -4
  175. package/build/dex/ramses-v2/config.js +0 -28
  176. package/build/dex/ramses-v2/config.js.map +0 -1
  177. package/build/dex/ramses-v2/constants.d.ts +0 -28
  178. package/build/dex/ramses-v2/constants.js +0 -35
  179. package/build/dex/ramses-v2/constants.js.map +0 -1
  180. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  181. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  182. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  183. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  184. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  185. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  186. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  187. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  188. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  189. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  190. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  191. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  192. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  193. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  194. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  195. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  196. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  197. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  198. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  199. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  200. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  201. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  202. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  203. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  204. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  205. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  206. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  207. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  208. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  209. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  210. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  211. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  212. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  213. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  214. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  215. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  216. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  217. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  218. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  219. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  220. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  221. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  222. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  223. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  224. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  225. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  226. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  227. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  228. package/build/dex/ramses-v2/types.d.ts +0 -154
  229. package/build/dex/ramses-v2/types.js +0 -9
  230. package/build/dex/ramses-v2/types.js.map +0 -1
  231. package/build/dex/ramses-v2/utils.d.ts +0 -6
  232. package/build/dex/ramses-v2/utils.js +0 -71
  233. package/build/dex/ramses-v2/utils.js.map +0 -1
  234. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  235. package/build/dex/solidly/forks-override/fvm.js +0 -42
  236. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  237. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  238. package/build/dex/sushiswap-v3/config.js +0 -132
  239. package/build/dex/sushiswap-v3/config.js.map +0 -1
  240. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  241. package/build/dex/sushiswap-v3/constants.js +0 -32
  242. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  243. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  244. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  245. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  246. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  247. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  248. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  249. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  250. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  251. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  252. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  253. package/build/dex/sushiswap-v3/token.js +0 -23
  254. package/build/dex/sushiswap-v3/token.js.map +0 -1
  255. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  256. package/build/dex/sushiswap-v3/types.js +0 -18
  257. package/build/dex/sushiswap-v3/types.js.map +0 -1
  258. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  259. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  260. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  261. package/build/dex/woo-fi/config.d.ts +0 -4
  262. package/build/dex/woo-fi/config.js +0 -141
  263. package/build/dex/woo-fi/config.js.map +0 -1
  264. package/build/dex/woo-fi/constants.d.ts +0 -5
  265. package/build/dex/woo-fi/constants.js +0 -20
  266. package/build/dex/woo-fi/constants.js.map +0 -1
  267. package/build/dex/woo-fi/types.d.ts +0 -48
  268. package/build/dex/woo-fi/types.js +0 -3
  269. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  270. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  271. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  272. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  273. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  274. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  275. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  276. package/build/dex/woo-fi/woo-fi.js +0 -480
  277. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  278. package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
  279. package/build/executor/IExecutorBytecodeBuilder.js +0 -3
  280. package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
  281. /package/build/dex/{lighter-v1 → maverick-v2}/types.js +0 -0
@@ -1,272 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addFee = exports.subtractFee = exports._calcTokensOutGivenExactBptIn = exports._calcTokenOutGivenExactBptIn = exports._calcBptInGivenExactTokensOut = exports._calcBptOutGivenExactTokensIn = exports._calcInGivenOut = exports._calcOutGivenIn = exports._calculateInvariant = void 0;
4
- const bigint_constants_1 = require("../../bigint-constants");
5
- const balancer_v2_math_1 = require("./balancer-v2-math");
6
- const AMP_PRECISION = bigint_constants_1.BI_POWS[3];
7
- function _calculateInvariant(amp, balances, roundUp) {
8
- /**********************************************************************************************
9
- // invariant //
10
- // D = invariant D^(n+1) //
11
- // A = amplification coefficient A n^n S + D = A D n^n + ----------- //
12
- // S = sum of balances n^n P //
13
- // P = product of balances //
14
- // n = number of tokens //
15
- *********x************************************************************************************/
16
- // We support rounding up or down.
17
- let sum = 0n;
18
- const numTokens = balances.length;
19
- for (let i = 0; i < numTokens; i++) {
20
- sum = sum + balances[i];
21
- }
22
- if (sum == 0n) {
23
- return 0n;
24
- }
25
- let prevInvariant = 0n;
26
- let invariant = sum;
27
- const ampTimesTotal = amp * BigInt(numTokens);
28
- for (let i = 0; i < 255; i++) {
29
- let P_D = balances[0] * BigInt(numTokens);
30
- for (let j = 1; j < numTokens; j++) {
31
- P_D = balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(P_D, balances[j]), BigInt(numTokens)), invariant, roundUp);
32
- }
33
- prevInvariant = invariant;
34
- invariant = balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(BigInt(numTokens), invariant), invariant) +
35
- balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(ampTimesTotal, sum), P_D), AMP_PRECISION, roundUp), balancer_v2_math_1.MathSol.mul(BigInt(numTokens + 1), invariant) +
36
- // No need to use checked arithmetic for the amp precision, the amp is guaranteed to be at least 1
37
- balancer_v2_math_1.MathSol.div(balancer_v2_math_1.MathSol.mul(ampTimesTotal - AMP_PRECISION, P_D), AMP_PRECISION, !roundUp), roundUp);
38
- if (invariant > prevInvariant) {
39
- if (invariant - prevInvariant <= 1) {
40
- return invariant;
41
- }
42
- }
43
- else if (prevInvariant - invariant <= 1) {
44
- return invariant;
45
- }
46
- }
47
- throw new Error('Errors.STABLE_INVARIANT_DIDNT_CONVERGE');
48
- }
49
- exports._calculateInvariant = _calculateInvariant;
50
- // PairType = 'token->token'
51
- // SwapType = 'swapExactIn'
52
- function _calcOutGivenIn(amp, balances, tokenIndexIn, tokenIndexOut, amountIn, invariant) {
53
- balances = [...balances];
54
- // Given that we need to have a greater final balance out, the invariant needs to be rounded up
55
- if (!invariant)
56
- invariant = _calculateInvariant(amp, balances, true);
57
- const initBalance = balances[tokenIndexIn];
58
- balances[tokenIndexIn] = initBalance + amountIn;
59
- const finalBalanceOut = _getTokenBalanceGivenInvariantAndAllOtherBalances(amp, balances, invariant, tokenIndexOut);
60
- return balances[tokenIndexOut] - finalBalanceOut - 1n;
61
- }
62
- exports._calcOutGivenIn = _calcOutGivenIn;
63
- function _calcInGivenOut(amp, balances, tokenIndexIn, tokenIndexOut, amountOut, fee, invariant) {
64
- balances = [...balances];
65
- if (!invariant)
66
- invariant = _calculateInvariant(amp, balances, true);
67
- balances[tokenIndexOut] = balancer_v2_math_1.MathSol.sub(balances[tokenIndexOut], amountOut);
68
- const finalBalanceIn = _getTokenBalanceGivenInvariantAndAllOtherBalances(amp, balances, invariant, tokenIndexIn);
69
- let amountIn = balancer_v2_math_1.MathSol.add(balancer_v2_math_1.MathSol.sub(finalBalanceIn, balances[tokenIndexIn]), 1n);
70
- amountIn = addFee(amountIn, fee);
71
- return amountIn;
72
- }
73
- exports._calcInGivenOut = _calcInGivenOut;
74
- function _calcBptOutGivenExactTokensIn(amp, balances, amountsIn, bptTotalSupply, invariant) {
75
- if (!invariant)
76
- invariant = _calculateInvariant(amp, balances, true);
77
- // BPT out, so we round down overall.
78
- // First loop calculates the sum of all token balances, which will be used to calculate
79
- // the current weights of each token, relative to this sum
80
- let sumBalances = 0n;
81
- for (let i = 0; i < balances.length; i++) {
82
- sumBalances = sumBalances + balances[i];
83
- }
84
- // Calculate the weighted balance ratio without considering fees
85
- const balanceRatiosWithFee = new Array(amountsIn.length);
86
- // The weighted sum of token balance ratios with fee
87
- let invariantRatioWithFees = 0n;
88
- for (let i = 0; i < balances.length; i++) {
89
- const currentWeight = balancer_v2_math_1.MathSol.divDownFixed(balances[i], sumBalances);
90
- balanceRatiosWithFee[i] = balancer_v2_math_1.MathSol.divDownFixed(balances[i] + amountsIn[i], balances[i]);
91
- invariantRatioWithFees =
92
- invariantRatioWithFees +
93
- balancer_v2_math_1.MathSol.mulDownFixed(balanceRatiosWithFee[i], currentWeight);
94
- }
95
- // Second loop calculates new amounts in, taking into account the fee on the percentage excess
96
- const newBalances = new Array(balances.length);
97
- for (let i = 0; i < balances.length; i++) {
98
- let amountInWithoutFee;
99
- // Check if the balance ratio is greater than the ideal ratio to charge fees or not
100
- if (balanceRatiosWithFee[i] > invariantRatioWithFees) {
101
- const nonTaxableAmount = balancer_v2_math_1.MathSol.mulDownFixed(balances[i], invariantRatioWithFees - balancer_v2_math_1.MathSol.ONE);
102
- const taxableAmount = amountsIn[i] - nonTaxableAmount;
103
- // No need to use checked arithmetic for the swap fee, it is guaranteed to be lower than 50%
104
- // amountInWithoutFee =
105
- // nonTaxableAmount +
106
- // MathSol.mulDownFixed(
107
- // taxableAmount,
108
- // MathSol.ONE - swapFeePercentage
109
- // );
110
- amountInWithoutFee = nonTaxableAmount + taxableAmount;
111
- }
112
- else {
113
- amountInWithoutFee = amountsIn[i];
114
- }
115
- newBalances[i] = balances[i] + amountInWithoutFee;
116
- }
117
- // Get current and new invariants, taking swap fees into account
118
- const currentInvariant = _calculateInvariant(amp, balances, true);
119
- const newInvariant = _calculateInvariant(amp, newBalances, false);
120
- const invariantRatio = balancer_v2_math_1.MathSol.divDownFixed(newInvariant, currentInvariant);
121
- // If the invariant didn't increase for any reason, we simply don't mint BPT
122
- if (invariantRatio > balancer_v2_math_1.MathSol.ONE) {
123
- return balancer_v2_math_1.MathSol.mulDownFixed(bptTotalSupply, invariantRatio - balancer_v2_math_1.MathSol.ONE);
124
- }
125
- else {
126
- return 0n;
127
- }
128
- }
129
- exports._calcBptOutGivenExactTokensIn = _calcBptOutGivenExactTokensIn;
130
- /*
131
- Flow of calculations:
132
- amountsTokenOut -> amountsOutProportional ->
133
- amountOutPercentageExcess -> amountOutBeforeFee -> newInvariant -> amountBPTIn
134
- */
135
- function _calcBptInGivenExactTokensOut(amp, balances, amountsOut, bptTotalSupply, swapFeePercentage, invariant) {
136
- if (!invariant)
137
- invariant = _calculateInvariant(amp, balances, true);
138
- // BPT in, so we round up overall.
139
- // First loop calculates the sum of all token balances, which will be used to calculate
140
- // the current weights of each token relative to this sum
141
- let sumBalances = 0n;
142
- for (let i = 0; i < balances.length; i++) {
143
- sumBalances = sumBalances + balances[i];
144
- }
145
- // Calculate the weighted balance ratio without considering fees
146
- const balanceRatiosWithoutFee = new Array(amountsOut.length);
147
- let invariantRatioWithoutFees = 0n;
148
- for (let i = 0; i < balances.length; i++) {
149
- const currentWeight = balancer_v2_math_1.MathSol.divUpFixed(balances[i], sumBalances);
150
- balanceRatiosWithoutFee[i] = balancer_v2_math_1.MathSol.divUpFixed(balances[i] - amountsOut[i], balances[i]);
151
- invariantRatioWithoutFees =
152
- invariantRatioWithoutFees +
153
- balancer_v2_math_1.MathSol.mulUpFixed(balanceRatiosWithoutFee[i], currentWeight);
154
- }
155
- // Second loop calculates new amounts in, taking into account the fee on the percentage excess
156
- const newBalances = new Array(balances.length);
157
- for (let i = 0; i < balances.length; i++) {
158
- // Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it to
159
- // 'token out'. This results in slightly larger price impact.
160
- let amountOutWithFee;
161
- if (invariantRatioWithoutFees > balanceRatiosWithoutFee[i]) {
162
- const nonTaxableAmount = balancer_v2_math_1.MathSol.mulDownFixed(balances[i], balancer_v2_math_1.MathSol.complementFixed(invariantRatioWithoutFees));
163
- const taxableAmount = amountsOut[i] - nonTaxableAmount;
164
- // No need to use checked arithmetic for the swap fee, it is guaranteed to be lower than 50%
165
- amountOutWithFee =
166
- nonTaxableAmount +
167
- balancer_v2_math_1.MathSol.divUpFixed(taxableAmount, balancer_v2_math_1.MathSol.ONE - swapFeePercentage);
168
- }
169
- else {
170
- amountOutWithFee = amountsOut[i];
171
- }
172
- newBalances[i] = balances[i] - amountOutWithFee;
173
- }
174
- // Get current and new invariants, taking into account swap fees
175
- const currentInvariant = _calculateInvariant(amp, balances, true);
176
- const newInvariant = _calculateInvariant(amp, newBalances, false);
177
- const invariantRatio = balancer_v2_math_1.MathSol.divDownFixed(newInvariant, currentInvariant);
178
- // return amountBPTIn
179
- return balancer_v2_math_1.MathSol.mulUpFixed(bptTotalSupply, balancer_v2_math_1.MathSol.complementFixed(invariantRatio));
180
- }
181
- exports._calcBptInGivenExactTokensOut = _calcBptInGivenExactTokensOut;
182
- function _calcTokenOutGivenExactBptIn(amp, balances, tokenIndex, bptAmountIn, bptTotalSupply, invariant) {
183
- if (!invariant)
184
- invariant = _calculateInvariant(amp, balances, true);
185
- // Token out, so we round down overall.
186
- // Get the current and new invariants. Since we need a bigger new invariant, we round the current one up.
187
- const currentInvariant = _calculateInvariant(amp, balances, true);
188
- const newInvariant = balancer_v2_math_1.MathSol.mulUpFixed(balancer_v2_math_1.MathSol.divUpFixed(bptTotalSupply - bptAmountIn, bptTotalSupply), currentInvariant);
189
- // Calculate amount out without fee
190
- const newBalanceTokenIndex = _getTokenBalanceGivenInvariantAndAllOtherBalances(amp, balances, newInvariant, tokenIndex);
191
- const amountOutWithoutFee = balances[tokenIndex] - newBalanceTokenIndex;
192
- // First calculate the sum of all token balances, which will be used to calculate
193
- // the current weight of each token
194
- let sumBalances = 0n;
195
- for (let i = 0; i < balances.length; i++) {
196
- sumBalances = sumBalances + balances[i];
197
- }
198
- // We can now compute how much excess balance is being withdrawn as a result of the virtual swaps, which result
199
- // in swap fees.
200
- const currentWeight = balancer_v2_math_1.MathSol.divDownFixed(balances[tokenIndex], sumBalances);
201
- const taxablePercentage = balancer_v2_math_1.MathSol.complementFixed(currentWeight);
202
- // Swap fees are typically charged on 'token in', but there is no 'token in' here, so we apply it
203
- // to 'token out'. This results in slightly larger price impact. Fees are rounded up.
204
- const taxableAmount = balancer_v2_math_1.MathSol.mulUpFixed(amountOutWithoutFee, taxablePercentage);
205
- const nonTaxableAmount = amountOutWithoutFee - taxableAmount;
206
- // No need to use checked arithmetic for the swap fee, it is guaranteed to be lower than 50%
207
- return nonTaxableAmount + taxableAmount;
208
- }
209
- exports._calcTokenOutGivenExactBptIn = _calcTokenOutGivenExactBptIn;
210
- function _calcTokensOutGivenExactBptIn(balances, bptAmountIn, bptTotalSupply) {
211
- /**********************************************************************************************
212
- // exactBPTInForTokensOut //
213
- // (per token) //
214
- // aO = tokenAmountOut / bptIn \ //
215
- // b = tokenBalance a0 = b * | --------------------- | //
216
- // bptIn = bptAmountIn \ bptTotalSupply / //
217
- // bpt = bptTotalSupply //
218
- **********************************************************************************************/
219
- // Since we're computing an amount out, we round down overall. This means rounding down on both the
220
- // multiplication and division.
221
- const bptRatio = balancer_v2_math_1.MathSol.divDownFixed(bptAmountIn, bptTotalSupply);
222
- const amountsOut = new Array(balances.length);
223
- for (let i = 0; i < balances.length; i++) {
224
- amountsOut[i] = balancer_v2_math_1.MathSol.mulDownFixed(balances[i], bptRatio);
225
- }
226
- return amountsOut;
227
- }
228
- exports._calcTokensOutGivenExactBptIn = _calcTokensOutGivenExactBptIn;
229
- function _getTokenBalanceGivenInvariantAndAllOtherBalances(amp, balances, invariant, tokenIndex) {
230
- // Rounds result up overall
231
- const ampTimesTotal = amp * BigInt(balances.length);
232
- let sum = balances[0];
233
- let P_D = balances[0] * BigInt(balances.length);
234
- for (let j = 1; j < balances.length; j++) {
235
- P_D = balancer_v2_math_1.MathSol.divDown(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(P_D, balances[j]), BigInt(balances.length)), invariant);
236
- sum = sum + balances[j];
237
- }
238
- // No need to use safe math, based on the loop above `sum` is greater than or equal to `balances[tokenIndex]`
239
- sum = sum - balances[tokenIndex];
240
- const inv2 = balancer_v2_math_1.MathSol.mul(invariant, invariant);
241
- // We remove the balance fromm c by multiplying it
242
- const c = balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.divUp(inv2, balancer_v2_math_1.MathSol.mul(ampTimesTotal, P_D)), AMP_PRECISION), balances[tokenIndex]);
243
- const b = sum + balancer_v2_math_1.MathSol.mul(balancer_v2_math_1.MathSol.divDown(invariant, ampTimesTotal), AMP_PRECISION);
244
- // We iterate to find the balance
245
- let prevTokenBalance = 0n;
246
- // We multiply the first iteration outside the loop with the invariant to set the value of the
247
- // initial approximation.
248
- let tokenBalance = balancer_v2_math_1.MathSol.divUp(inv2 + c, invariant + b);
249
- for (let i = 0; i < 255; i++) {
250
- prevTokenBalance = tokenBalance;
251
- tokenBalance = balancer_v2_math_1.MathSol.divUp(balancer_v2_math_1.MathSol.mul(tokenBalance, tokenBalance) + c, balancer_v2_math_1.MathSol.mul(tokenBalance, 2n) + b - invariant);
252
- if (tokenBalance > prevTokenBalance) {
253
- if (tokenBalance - prevTokenBalance <= 1) {
254
- return tokenBalance;
255
- }
256
- }
257
- else if (prevTokenBalance - tokenBalance <= 1) {
258
- return tokenBalance;
259
- }
260
- }
261
- throw new Error('Errors.STABLE_GET_BALANCE_DIDNT_CONVERGE');
262
- }
263
- function subtractFee(amount, fee) {
264
- const feeAmount = balancer_v2_math_1.MathSol.mulUpFixed(amount, fee);
265
- return amount - feeAmount;
266
- }
267
- exports.subtractFee = subtractFee;
268
- function addFee(amount, fee) {
269
- return balancer_v2_math_1.MathSol.divUpFixed(amount, balancer_v2_math_1.MathSol.complementFixed(fee));
270
- }
271
- exports.addFee = addFee;
272
- //# sourceMappingURL=StableMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StableMath.js","sourceRoot":"","sources":["../../../src/dex/balancer-v2/StableMath.ts"],"names":[],"mappings":";;;AAAA,6DAAiD;AACjD,yDAA6C;AAE7C,MAAM,aAAa,GAAG,0BAAO,CAAC,CAAC,CAAC,CAAC;AAEjC,SAAgB,mBAAmB,CACjC,GAAW,EACX,QAAkB,EAClB,OAAgB;IAEhB;;;;;;;uGAOmG;IAEnG,kCAAkC;IAElC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE;QAClC,GAAG,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;KACzB;IACD,IAAI,GAAG,IAAI,EAAE,EAAE;QACb,OAAO,EAAE,CAAC;KACX;IAED,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,SAAS,GAAG,GAAG,CAAC;IACpB,MAAM,aAAa,GAAG,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAE9C,KAAK,IAAI,CAAC,GAAG,CAAC,E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S,GAAG,0BAAO,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,MAAM,GAAG,SAAS,CAAC;AAC5B,CAAC;AAHD,kCAGC;AAED,SAAgB,MAAM,CAAC,MAAc,EAAE,GAAW;IAChD,OAAO,0BAAO,CAAC,UAAU,CAAC,MAAM,EAAE,0BAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAFD,wBAEC"}
@@ -1,140 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { SwapSide } from '../../constants';
3
- import { callData, SubgraphPoolBase, PoolState } from './types';
4
- export declare class BasePool {
5
- _subtractSwapFeeAmount(amount: bigint, _swapFeePercentage: bigint): bigint;
6
- _upscaleArray(amounts: bigint[], scalingFactors: bigint[]): bigint[];
7
- _upscale(amount: bigint, scalingFactor: bigint): bigint;
8
- _downscaleDown(amount: bigint, scalingFactor: bigint): bigint;
9
- _nullifyIfMaxAmountExceeded(amountToTrade: bigint, swapMax: bigint): bigint;
10
- }
11
- declare type WeightedPoolPairData = {
12
- tokenInBalance: bigint;
13
- tokenOutBalance: bigint;
14
- tokenInScalingFactor: bigint;
15
- tokenOutScalingFactor: bigint;
16
- tokenInWeight: bigint;
17
- tokenOutWeight: bigint;
18
- swapFee: bigint;
19
- };
20
- declare type StablePoolPairData = {
21
- balances: bigint[];
22
- indexIn: number;
23
- indexOut: number;
24
- scalingFactors: bigint[];
25
- swapFee: bigint;
26
- amp: bigint;
27
- };
28
- declare abstract class BaseGeneralPool extends BasePool {
29
- onSell(amounts: bigint[], poolPairData: StablePoolPairData): bigint[];
30
- _swapGivenIn(
31
- tokenAmountsIn: bigint[],
32
- balances: bigint[],
33
- indexIn: number,
34
- indexOut: number,
35
- scalingFactors: bigint[],
36
- _swapFeePercentage: bigint,
37
- _amplificationParameter: bigint,
38
- ): bigint[];
39
- abstract _onSwapGivenIn(
40
- tokenAmountsIn: bigint[],
41
- balances: bigint[],
42
- indexIn: number,
43
- indexOut: number,
44
- _amplificationParameter: bigint,
45
- ): bigint[];
46
- }
47
- declare abstract class BaseMinimalSwapInfoPool extends BasePool {
48
- onSell(
49
- tokenAmountsIn: bigint[],
50
- poolPairData: WeightedPoolPairData,
51
- ): bigint[];
52
- abstract _onSwapGivenIn(
53
- tokenAmountsIn: bigint[],
54
- currentBalanceTokenIn: bigint,
55
- currentBalanceTokenOut: bigint,
56
- _weightIn: bigint,
57
- _weightOut: bigint,
58
- ): bigint[];
59
- }
60
- export declare class StablePool extends BaseGeneralPool {
61
- vaultAddress: string;
62
- vaultInterface: Interface;
63
- poolInterface: Interface;
64
- metaPoolInterface: Interface;
65
- constructor(vaultAddress: string, vaultInterface: Interface);
66
- _onSwapGivenIn(
67
- tokenAmountsIn: bigint[],
68
- balances: bigint[],
69
- indexIn: number,
70
- indexOut: number,
71
- _amplificationParameter: bigint,
72
- ): bigint[];
73
- parsePoolPairData(
74
- pool: SubgraphPoolBase,
75
- poolState: PoolState,
76
- tokenIn: string,
77
- tokenOut: string,
78
- ): StablePoolPairData;
79
- getOnChainCalls(pool: SubgraphPoolBase): callData[];
80
- decodeOnChainCalls(
81
- pool: SubgraphPoolBase,
82
- data: {
83
- success: boolean;
84
- returnData: any;
85
- }[],
86
- startIndex: number,
87
- ): [
88
- {
89
- [address: string]: PoolState;
90
- },
91
- number,
92
- ];
93
- getSwapMaxAmount(poolPairData: StablePoolPairData, side: SwapSide): bigint;
94
- }
95
- export declare class WeightedMath {
96
- static _MAX_IN_RATIO: bigint;
97
- static _MAX_OUT_RATIO: bigint;
98
- static _calcOutGivenIn(
99
- balanceIn: bigint,
100
- weightIn: bigint,
101
- balanceOut: bigint,
102
- weightOut: bigint,
103
- amountsIn: bigint[],
104
- ): bigint[];
105
- }
106
- export declare class WeightedPool extends BaseMinimalSwapInfoPool {
107
- vaultAddress: string;
108
- vaultInterface: Interface;
109
- poolInterface: Interface;
110
- constructor(vaultAddress: string, vaultInterface: Interface);
111
- _onSwapGivenIn(
112
- tokenAmountsIn: bigint[],
113
- currentBalanceTokenIn: bigint,
114
- currentBalanceTokenOut: bigint,
115
- _weightIn: bigint,
116
- _weightOut: bigint,
117
- ): bigint[];
118
- parsePoolPairData(
119
- pool: SubgraphPoolBase,
120
- poolState: PoolState,
121
- tokenIn: string,
122
- tokenOut: string,
123
- ): WeightedPoolPairData;
124
- getOnChainCalls(pool: SubgraphPoolBase): callData[];
125
- decodeOnChainCalls(
126
- pool: SubgraphPoolBase,
127
- data: {
128
- success: boolean;
129
- returnData: any;
130
- }[],
131
- startIndex: number,
132
- ): [
133
- {
134
- [address: string]: PoolState;
135
- },
136
- number,
137
- ];
138
- getSwapMaxAmount(poolPairData: WeightedPoolPairData, side: SwapSide): bigint;
139
- }
140
- export {};