@paraswap/dex-lib 3.7.0 → 3.7.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 (304) hide show
  1. package/build/abi/Uncompressor.json +250 -0
  2. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  3. package/build/dex/aave-v1/aave-v1.js +0 -23
  4. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  5. package/build/dex/balancer-v2/balancer-v2.js +41 -19
  6. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  7. package/build/dex/compound.js +1 -1
  8. package/build/dex/compound.js.map +1 -1
  9. package/build/dex/etherfi/etherfi.d.ts +26 -0
  10. package/build/dex/etherfi/etherfi.js +96 -0
  11. package/build/dex/etherfi/etherfi.js.map +1 -0
  12. package/build/dex/platypus/platypus.d.ts +1 -2
  13. package/build/dex/platypus/platypus.js +0 -45
  14. package/build/dex/platypus/platypus.js.map +1 -1
  15. package/build/dex/sdai/config.d.ts +11 -0
  16. package/build/dex/sdai/config.js +21 -0
  17. package/build/dex/sdai/config.js.map +1 -0
  18. package/build/dex/sdai/constants.d.ts +2 -0
  19. package/build/dex/sdai/constants.js +6 -0
  20. package/build/dex/sdai/constants.js.map +1 -0
  21. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  22. package/build/dex/sdai/scripts/validate-state.js +102 -0
  23. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  24. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  25. package/build/dex/sdai/sdai-pool.js +85 -0
  26. package/build/dex/sdai/sdai-pool.js.map +1 -0
  27. package/build/dex/sdai/sdai.d.ts +51 -0
  28. package/build/dex/sdai/sdai.js +172 -0
  29. package/build/dex/sdai/sdai.js.map +1 -0
  30. package/build/dex/sdai/types.d.ts +21 -0
  31. package/build/dex/sdai/types.js +11 -0
  32. package/build/dex/sdai/types.js.map +1 -0
  33. package/build/dex/sdai/utils.d.ts +4 -0
  34. package/build/dex/sdai/utils.js +39 -0
  35. package/build/dex/sdai/utils.js.map +1 -0
  36. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  37. package/build/dex/swaap-v1/swaap-v1.js +0 -14
  38. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  39. package/build/executor/compressor/Compressor.d.ts +23 -0
  40. package/build/executor/compressor/Compressor.js +144 -0
  41. package/build/executor/compressor/Compressor.js.map +1 -0
  42. package/build/executor/compressor/compress.d.ts +17 -0
  43. package/build/executor/compressor/compress.js +187 -0
  44. package/build/executor/compressor/compress.js.map +1 -0
  45. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  46. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  47. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  48. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  49. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  50. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  51. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  52. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  53. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  54. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  55. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  56. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  57. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  58. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  59. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  60. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  61. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  62. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  63. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  64. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  65. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  66. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  67. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  68. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  69. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  70. package/build/executor/compressor/fetchSaved.js +17 -0
  71. package/build/executor/compressor/fetchSaved.js.map +1 -0
  72. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  73. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  74. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  75. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  76. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  77. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  78. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  79. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  80. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  81. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  82. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  83. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  84. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  85. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  86. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  87. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  88. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  89. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  90. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  91. package/build/executor/compressor/utils/intToByte.js +10 -0
  92. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  93. package/package.json +1 -1
  94. package/src/dex/balancer-v2/balancer-v2.ts +41 -19
  95. package/tests/utils-e2e.ts +114 -116
  96. package/.idea/aws.xml +0 -17
  97. package/.idea/codeStyles/Project.xml +0 -19
  98. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  99. package/.idea/misc.xml +0 -6
  100. package/.idea/modules.xml +0 -8
  101. package/.idea/paraswap-dex-lib.iml +0 -9
  102. package/.idea/prettier.xml +0 -7
  103. package/.idea/vcs.xml +0 -6
  104. package/build/abi/AugustusV6.abi.json +0 -395
  105. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  106. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  107. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  108. package/build/abi/integral/relayer.json +0 -1148
  109. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  110. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  111. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  112. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  113. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  114. package/build/abi/wBETH.json +0 -1527
  115. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  116. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  117. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  118. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  119. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  120. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  121. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  122. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  123. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  124. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  125. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  126. package/build/dex/algebra/algebra-pool.d.ts +0 -114
  127. package/build/dex/algebra/algebra-pool.js +0 -448
  128. package/build/dex/algebra/algebra-pool.js.map +0 -1
  129. package/build/dex/balancer-v2/Gyro3Pool.d.ts +0 -43
  130. package/build/dex/balancer-v2/Gyro3Pool.js +0 -160
  131. package/build/dex/balancer-v2/Gyro3Pool.js.map +0 -1
  132. package/build/dex/balancer-v2/LinearMath.d.ts +0 -88
  133. package/build/dex/balancer-v2/LinearMath.js +0 -285
  134. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  135. package/build/dex/balancer-v2/LinearPool.d.ts +0 -81
  136. package/build/dex/balancer-v2/LinearPool.js +0 -444
  137. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  138. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -90
  139. package/build/dex/balancer-v2/PhantomStablePool.js +0 -418
  140. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  141. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  142. package/build/dex/balancer-v2/StableMath.js +0 -272
  143. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  144. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -140
  145. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -647
  146. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  147. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  148. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  149. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  150. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  151. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  152. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  153. package/build/dex/integral/config.d.ts +0 -4
  154. package/build/dex/integral/config.js +0 -18
  155. package/build/dex/integral/config.js.map +0 -1
  156. package/build/dex/integral/integral-pool.d.ts +0 -39
  157. package/build/dex/integral/integral-pool.js +0 -67
  158. package/build/dex/integral/integral-pool.js.map +0 -1
  159. package/build/dex/integral/integral.d.ts +0 -48
  160. package/build/dex/integral/integral.js +0 -402
  161. package/build/dex/integral/integral.js.map +0 -1
  162. package/build/dex/integral/types.d.ts +0 -25
  163. package/build/dex/integral/types.js +0 -9
  164. package/build/dex/integral/types.js.map +0 -1
  165. package/build/dex/lighter-v1/abi/erc20.json +0 -222
  166. package/build/dex/lighter-v1/abi/factory.json +0 -291
  167. package/build/dex/lighter-v1/abi/order_book.json +0 -594
  168. package/build/dex/lighter-v1/abi/order_book_helper.json +0 -176
  169. package/build/dex/lighter-v1/abi/router.json +0 -488
  170. package/build/dex/lighter-v1/config.d.ts +0 -4
  171. package/build/dex/lighter-v1/config.js +0 -17
  172. package/build/dex/lighter-v1/config.js.map +0 -1
  173. package/build/dex/lighter-v1/constants.d.ts +0 -2
  174. package/build/dex/lighter-v1/constants.js +0 -13
  175. package/build/dex/lighter-v1/constants.js.map +0 -1
  176. package/build/dex/lighter-v1/lighter-v1-pool.d.ts +0 -57
  177. package/build/dex/lighter-v1/lighter-v1-pool.js +0 -310
  178. package/build/dex/lighter-v1/lighter-v1-pool.js.map +0 -1
  179. package/build/dex/lighter-v1/lighter-v1.d.ts +0 -45
  180. package/build/dex/lighter-v1/lighter-v1.js +0 -331
  181. package/build/dex/lighter-v1/lighter-v1.js.map +0 -1
  182. package/build/dex/lighter-v1/types.d.ts +0 -40
  183. package/build/dex/lighter-v1/types.js +0 -3
  184. package/build/dex/lighter-v1/types.js.map +0 -1
  185. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  186. package/build/dex/pancakeswap-v3/types.js +0 -3
  187. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  188. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  189. package/build/dex/quickswap/camelot-v3.js +0 -19
  190. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  191. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  192. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  193. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  194. package/build/dex/quickswap-v3.d.ts +0 -21
  195. package/build/dex/quickswap-v3.js +0 -40
  196. package/build/dex/quickswap-v3.js.map +0 -1
  197. package/build/dex/ramses-v2/config.d.ts +0 -4
  198. package/build/dex/ramses-v2/config.js +0 -28
  199. package/build/dex/ramses-v2/config.js.map +0 -1
  200. package/build/dex/ramses-v2/constants.d.ts +0 -28
  201. package/build/dex/ramses-v2/constants.js +0 -35
  202. package/build/dex/ramses-v2/constants.js.map +0 -1
  203. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  204. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  205. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  206. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  207. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  208. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  209. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  210. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  211. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  212. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  213. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  214. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  215. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  216. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  217. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  218. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  219. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  220. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  221. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  222. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  223. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  224. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  225. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  226. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  227. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  228. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  229. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  230. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  231. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  232. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  233. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  234. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  235. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  236. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  237. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  238. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  239. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  240. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  241. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  242. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  243. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  244. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  245. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  246. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  247. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  248. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  249. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  250. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  251. package/build/dex/ramses-v2/types.d.ts +0 -154
  252. package/build/dex/ramses-v2/types.js +0 -9
  253. package/build/dex/ramses-v2/types.js.map +0 -1
  254. package/build/dex/ramses-v2/utils.d.ts +0 -6
  255. package/build/dex/ramses-v2/utils.js +0 -71
  256. package/build/dex/ramses-v2/utils.js.map +0 -1
  257. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  258. package/build/dex/solidly/forks-override/fvm.js +0 -42
  259. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  260. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  261. package/build/dex/sushiswap-v3/config.js +0 -132
  262. package/build/dex/sushiswap-v3/config.js.map +0 -1
  263. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  264. package/build/dex/sushiswap-v3/constants.js +0 -32
  265. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  266. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  267. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  268. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  269. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  270. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  271. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  272. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  273. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  274. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  275. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  276. package/build/dex/sushiswap-v3/token.js +0 -23
  277. package/build/dex/sushiswap-v3/token.js.map +0 -1
  278. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  279. package/build/dex/sushiswap-v3/types.js +0 -18
  280. package/build/dex/sushiswap-v3/types.js.map +0 -1
  281. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  282. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  283. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  284. package/build/dex/woo-fi/config.d.ts +0 -4
  285. package/build/dex/woo-fi/config.js +0 -141
  286. package/build/dex/woo-fi/config.js.map +0 -1
  287. package/build/dex/woo-fi/constants.d.ts +0 -5
  288. package/build/dex/woo-fi/constants.js +0 -20
  289. package/build/dex/woo-fi/constants.js.map +0 -1
  290. package/build/dex/woo-fi/types.d.ts +0 -48
  291. package/build/dex/woo-fi/types.js +0 -3
  292. package/build/dex/woo-fi/types.js.map +0 -1
  293. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  294. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  295. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  296. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  297. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  298. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  299. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  300. package/build/dex/woo-fi/woo-fi.js +0 -480
  301. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  302. package/build/executor/IExecutorBytecodeBuilder.d.ts +0 -6
  303. package/build/executor/IExecutorBytecodeBuilder.js +0 -3
  304. package/build/executor/IExecutorBytecodeBuilder.js.map +0 -1
@@ -1,448 +0,0 @@
1
- 'use strict';
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod };
6
- };
7
- Object.defineProperty(exports, '__esModule', { value: true });
8
- exports.AlgebraEventPool = void 0;
9
- const lodash_1 = __importDefault(require('lodash'));
10
- const abi_1 = require('@ethersproject/abi');
11
- const ts_essentials_1 = require('ts-essentials');
12
- const utils_1 = require('../../utils');
13
- const stateful_event_subscriber_1 = require('../../stateful-event-subscriber');
14
- const ethers_1 = require('ethers');
15
- const AlgebraPool_abi_json_1 = __importDefault(
16
- require('../../abi/algebra/AlgebraPool.abi.json'),
17
- );
18
- const constants_1 = require('../uniswap-v3/constants');
19
- const decoders_1 = require('../../lib/decoders');
20
- const utils_2 = require('./utils');
21
- const AlgebraMath_1 = require('./lib/AlgebraMath');
22
- const TickBitMap_1 = require('../uniswap-v3/contract-math/TickBitMap');
23
- const utils_3 = require('../uniswap-v3/contract-math/utils');
24
- const Constants_1 = require('./lib/Constants');
25
- const constants_2 = require('../../constants');
26
- class AlgebraEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
27
- constructor(
28
- dexHelper,
29
- parentName,
30
- stateMultiContract,
31
- erc20Interface,
32
- factoryAddress,
33
- token0,
34
- token1,
35
- logger,
36
- mapKey = '',
37
- poolInitCodeHash,
38
- poolDeployer,
39
- ) {
40
- super(parentName, `${token0}_${token1}`, dexHelper, logger, true, mapKey);
41
- this.dexHelper = dexHelper;
42
- this.stateMultiContract = stateMultiContract;
43
- this.erc20Interface = erc20Interface;
44
- this.factoryAddress = factoryAddress;
45
- this.poolInitCodeHash = poolInitCodeHash;
46
- this.poolDeployer = poolDeployer;
47
- this.handlers = {};
48
- this.poolIface = new abi_1.Interface(AlgebraPool_abi_json_1.default);
49
- this.initFailed = false;
50
- this.initRetryAttemptCount = 0;
51
- this.token0 = token0.toLowerCase();
52
- this.token1 = token1.toLowerCase();
53
- this.logDecoder = log => this.poolIface.parseLog(log);
54
- this.addressesSubscribed = new Array(1);
55
- this.handlers['Fee'] = this.handleNewFee.bind(this);
56
- this.handlers['Swap'] = this.handleSwapEvent.bind(this);
57
- this.handlers['Mint'] = this.handleMintEvent.bind(this);
58
- this.handlers['Burn'] = this.handleBurnEvent.bind(this);
59
- this.handlers['Flash'] = this.handleFlashEvent.bind(this);
60
- this.handlers['Collect'] = this.handleCollectEvent.bind(this);
61
- this.handlers['CommunityFee'] = this.handleCommunityFee.bind(this);
62
- }
63
- get poolAddress() {
64
- if (this._poolAddress === undefined) {
65
- this._poolAddress = this._computePoolAddress(this.token0, this.token1);
66
- }
67
- return this._poolAddress;
68
- }
69
- set poolAddress(address) {
70
- this._poolAddress = address.toLowerCase();
71
- }
72
- async initialize(blockNumber, options) {
73
- await super.initialize(blockNumber, options);
74
- }
75
- async processBlockLogs(state, logs, blockHeader) {
76
- const newState = await super.processBlockLogs(state, logs, blockHeader);
77
- if (newState && !newState.isValid) {
78
- return await this.generateState(blockHeader.number);
79
- }
80
- return newState;
81
- }
82
- processLog(state, log, blockHeader) {
83
- try {
84
- const event = this.logDecoder(log);
85
- if (event.name in this.handlers) {
86
- // Because we have observations in array which is mutable by nature, there is a
87
- // ts compile error: https://stackoverflow.com/questions/53412934/disable-allowing-assigning-readonly-types-to-non-readonly-types
88
- // And there is no good workaround, so turn off the type checker for this line
89
- const _state = lodash_1.default.cloneDeep(state);
90
- try {
91
- const newState = this.handlers[event.name](
92
- event,
93
- _state,
94
- log,
95
- blockHeader,
96
- );
97
- return newState;
98
- } catch (e) {
99
- if (
100
- e instanceof Error &&
101
- e.message.endsWith(constants_1.OUT_OF_RANGE_ERROR_POSTFIX)
102
- ) {
103
- this.logger.warn(
104
- `${this.parentName}: Pool ${this.poolAddress} on ${
105
- this.dexHelper.config.data.network
106
- } is out of TickBitmap requested range. Re-query the state. ${JSON.stringify(
107
- event,
108
- )}`,
109
- e,
110
- );
111
- } else {
112
- this.logger.error(
113
- `${this.parentName}: Pool ${this.poolAddress}, ` +
114
- `network=${this.dexHelper.config.data.network}: Unexpected ` +
115
- `error while handling event on blockNumber=${blockHeader.number}, ` +
116
- `blockHash=${blockHeader.hash} and parentHash=${
117
- blockHeader.parentHash
118
- } for QuickSwapV3, ${JSON.stringify(event)}`,
119
- e,
120
- );
121
- }
122
- _state.isValid = false;
123
- return _state;
124
- }
125
- }
126
- } catch (e) {
127
- (0, utils_1.catchParseLogError)(e, this.logger);
128
- }
129
- return null; // ignore unrecognized event
130
- }
131
- getBitmapRangeToRequest() {
132
- return constants_1.TICK_BITMAP_TO_USE + constants_1.TICK_BITMAP_BUFFER;
133
- }
134
- async _fetchPoolStateSingleStep(blockNumber) {
135
- const callData = [
136
- {
137
- target: this.token0,
138
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
139
- this.poolAddress,
140
- ]),
141
- decodeFunction: decoders_1.uint256ToBigInt,
142
- },
143
- {
144
- target: this.token1,
145
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
146
- this.poolAddress,
147
- ]),
148
- decodeFunction: decoders_1.uint256ToBigInt,
149
- },
150
- {
151
- target: this.stateMultiContract.options.address,
152
- callData: this.stateMultiContract.methods
153
- .getFullStateWithRelativeBitmaps(
154
- this.factoryAddress,
155
- this.token0,
156
- this.token1,
157
- this.getBitmapRangeToRequest(),
158
- this.getBitmapRangeToRequest(),
159
- )
160
- .encodeABI(),
161
- decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
162
- },
163
- ];
164
- const [resBalance0, resBalance1, resState] =
165
- await this.dexHelper.multiWrapper.tryAggregate(
166
- false,
167
- callData,
168
- blockNumber,
169
- this.dexHelper.multiWrapper.defaultBatchSize,
170
- false,
171
- );
172
- (0, ts_essentials_1.assert)(resState.success, 'Pool does not exist');
173
- const [balance0, balance1, _state] = [
174
- resBalance0.returnData,
175
- resBalance1.returnData,
176
- resState.returnData,
177
- ];
178
- return [balance0, balance1, _state];
179
- }
180
- async _fetchPoolStateMultiStep(blockNumber) {
181
- const balancesAndGlobalStateCalldata = [
182
- {
183
- target: this.token0,
184
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
185
- this.poolAddress,
186
- ]),
187
- decodeFunction: decoders_1.uint256ToBigInt,
188
- },
189
- {
190
- target: this.token1,
191
- callData: this.erc20Interface.encodeFunctionData('balanceOf', [
192
- this.poolAddress,
193
- ]),
194
- decodeFunction: decoders_1.uint256ToBigInt,
195
- },
196
- {
197
- target: this.stateMultiContract.options.address,
198
- callData: this.stateMultiContract.methods
199
- .getFullStateWithoutTicks(
200
- this.factoryAddress,
201
- this.token0,
202
- this.token1,
203
- 0,
204
- 0,
205
- )
206
- .encodeABI(),
207
- decodeFunction: utils_2.decodeStateMultiCallResultWithRelativeBitmaps,
208
- },
209
- ];
210
- const [resBalance0, resBalance1, stateWithoutTicksAndTickBitmap] =
211
- await this.dexHelper.multiWrapper.tryAggregate(
212
- false,
213
- balancesAndGlobalStateCalldata,
214
- blockNumber,
215
- this.dexHelper.multiWrapper.defaultBatchSize,
216
- false,
217
- );
218
- (0, ts_essentials_1.assert)(
219
- stateWithoutTicksAndTickBitmap.success,
220
- 'Pool does not exist',
221
- );
222
- const [balance0, balance1, _stateWithoutTicksAndTickBitmap] = [
223
- resBalance0.returnData,
224
- resBalance1.returnData,
225
- stateWithoutTicksAndTickBitmap.returnData,
226
- ];
227
- const {
228
- globalState: { tick },
229
- } = _stateWithoutTicksAndTickBitmap;
230
- const currentBitmapIndex = (0, utils_1.int16)(
231
- (BigInt(tick) / Constants_1.Constants.TICK_SPACING) >> 8n,
232
- );
233
- const buffer = this.getBitmapRangeToRequest();
234
- const startBitMapIndex = currentBitmapIndex - buffer;
235
- const endBitMapIndex = currentBitmapIndex + buffer;
236
- const allBitMapIndices = Array.from(
237
- { length: 2 * Number(buffer) + 1 },
238
- () => startBitMapIndex + endBitMapIndex,
239
- );
240
- const ticksAndBitMaps = await Promise.all(
241
- allBitMapIndices.map(relativeTick => {
242
- return this.stateMultiContract.methods
243
- .getAdditionalBitmapWithTicks(
244
- this.factoryAddress,
245
- this.token0,
246
- this.token1,
247
- relativeTick,
248
- relativeTick,
249
- )
250
- .call();
251
- }),
252
- );
253
- const _state = {
254
- ..._stateWithoutTicksAndTickBitmap,
255
- tickBitmap: ticksAndBitMaps.flatMap(v => v[0]),
256
- ticks: ticksAndBitMaps.flatMap(v => v[1]),
257
- };
258
- return [balance0, balance1, _state];
259
- }
260
- async _fetchInitStateMultiStrategies(blockNumber) {
261
- try {
262
- return await this._fetchPoolStateSingleStep(blockNumber);
263
- } catch (e) {
264
- if (e instanceof Error && e.message.includes('Pool does not exist'))
265
- throw e;
266
- if (this.dexHelper.config.data.network != constants_2.Network.ZKEVM)
267
- throw e;
268
- return this._fetchPoolStateMultiStep(blockNumber);
269
- }
270
- }
271
- async generateState(blockNumber) {
272
- const [balance0, balance1, _state] =
273
- await this._fetchInitStateMultiStrategies(blockNumber);
274
- const tickBitmap = {};
275
- const ticks = {};
276
- (0, utils_3._reduceTickBitmap)(tickBitmap, _state.tickBitmap);
277
- (0, utils_3._reduceTicks)(ticks, _state.ticks);
278
- const globalState = {
279
- communityFeeToken0: (0, utils_1.bigIntify)(
280
- _state.globalState.communityFeeToken0,
281
- ),
282
- communityFeeToken1: (0, utils_1.bigIntify)(
283
- _state.globalState.communityFeeToken1,
284
- ),
285
- fee: (0, utils_1.bigIntify)(_state.globalState.fee),
286
- price: (0, utils_1.bigIntify)(_state.globalState.price),
287
- tick: (0, utils_1.bigIntify)(_state.globalState.tick),
288
- };
289
- const currentTick = globalState.tick;
290
- const startTickBitmap = TickBitMap_1.TickBitMap.position(
291
- BigInt(currentTick) / Constants_1.Constants.TICK_SPACING,
292
- )[0];
293
- return {
294
- pool: _state.pool,
295
- blockTimestamp: (0, utils_1.bigIntify)(_state.blockTimestamp),
296
- globalState,
297
- liquidity: (0, utils_1.bigIntify)(_state.liquidity),
298
- tickSpacing: Constants_1.Constants.TICK_SPACING,
299
- maxLiquidityPerTick: Constants_1.Constants.MAX_LIQUIDITY_PER_TICK,
300
- tickBitmap,
301
- ticks,
302
- startTickBitmap,
303
- isValid: true,
304
- balance0,
305
- balance1,
306
- };
307
- }
308
- handleSwapEvent(event, pool, log, blockHeader) {
309
- const newSqrtPriceX96 = (0, utils_1.bigIntify)(event.args.price);
310
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
311
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
312
- const newTick = (0, utils_1.bigIntify)(event.args.tick);
313
- const newLiquidity = (0, utils_1.bigIntify)(event.args.liquidity);
314
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
315
- if (amount0 <= 0n && amount1 <= 0n) {
316
- this.logger.error(
317
- `${this.parentName}: amount0 <= 0n && amount1 <= 0n for ` +
318
- `${this.poolAddress} and ${blockHeader.number}. Check why it happened`,
319
- );
320
- pool.isValid = false;
321
- return pool;
322
- } else {
323
- const zeroForOne = amount0 > 0n;
324
- const [, , , , , communityFee] =
325
- AlgebraMath_1.AlgebraMath._calculateSwapAndLock(
326
- pool,
327
- zeroForOne,
328
- newSqrtPriceX96,
329
- newTick,
330
- newLiquidity,
331
- );
332
- if (zeroForOne) {
333
- if (amount1 < 0n) {
334
- pool.balance1 -= BigInt.asUintN(256, -amount1);
335
- } else {
336
- this.logger.error(
337
- `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount1}`,
338
- );
339
- pool.isValid = false;
340
- }
341
- // This is not correct fully, because pool may get more tokens then it needs, but
342
- // it is not accounted in internal state, it should be good enough
343
- pool.balance0 += BigInt.asUintN(256, amount0);
344
- } else {
345
- if (amount0 < 0n) {
346
- pool.balance0 -= BigInt.asUintN(256, -amount0);
347
- } else {
348
- this.logger.error(
349
- `In swapEvent for pool ${pool.pool} received incorrect values ${zeroForOne} and ${amount0}`,
350
- );
351
- pool.isValid = false;
352
- }
353
- pool.balance1 += BigInt.asUintN(256, amount1);
354
- }
355
- if (communityFee > 0n) {
356
- // _payCommunityFee
357
- if (zeroForOne) {
358
- pool.balance0 -= communityFee;
359
- } else {
360
- pool.balance1 -= communityFee;
361
- }
362
- }
363
- return pool;
364
- }
365
- }
366
- handleMintEvent(event, pool, log, blockHeader) {
367
- const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
368
- const topTick = (0, utils_1.bigIntify)(event.args.topTick);
369
- const liquidityActual = (0, utils_1.bigIntify)(event.args.liquidityAmount);
370
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
371
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
372
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
373
- AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
374
- pool,
375
- bottomTick,
376
- topTick,
377
- liquidityActual,
378
- );
379
- pool.balance0 += amount0;
380
- pool.balance1 += amount1;
381
- return pool;
382
- }
383
- handleBurnEvent(event, pool, log, blockHeader) {
384
- const bottomTick = (0, utils_1.bigIntify)(event.args.bottomTick);
385
- const topTick = (0, utils_1.bigIntify)(event.args.topTick);
386
- const amount = (0, utils_1.bigIntify)(event.args.liquidityAmount);
387
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
388
- AlgebraMath_1.AlgebraMath._updatePositionTicksAndFees(
389
- pool,
390
- bottomTick,
391
- topTick,
392
- -BigInt.asIntN(128, BigInt.asIntN(256, amount)),
393
- );
394
- // no balance change
395
- return pool;
396
- }
397
- handleNewFee(event, pool, log, blockHeader) {
398
- const fee = (0, utils_1.bigIntify)(event.args.fee);
399
- pool.globalState.fee = fee;
400
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
401
- return pool;
402
- }
403
- handleCollectEvent(event, pool, log, blockHeader) {
404
- const amount0 = (0, utils_1.bigIntify)(event.args.amount0);
405
- const amount1 = (0, utils_1.bigIntify)(event.args.amount1);
406
- pool.balance0 -= amount0;
407
- pool.balance1 -= amount1;
408
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
409
- return pool;
410
- }
411
- handleFlashEvent(event, pool, log, blockHeader) {
412
- const paid0 = (0, utils_1.bigIntify)(event.args.paid0);
413
- const paid1 = (0, utils_1.bigIntify)(event.args.paid1);
414
- pool.balance0 += paid0;
415
- pool.balance1 += paid1;
416
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
417
- return pool;
418
- }
419
- handleCommunityFee(event, pool, log, blockHeader) {
420
- const communityFeeToken0 = (0, utils_1.bigIntify)(
421
- event.ags.communityFee0New,
422
- );
423
- const communityFeeToken1 = (0, utils_1.bigIntify)(
424
- event.ags.communityFee1New,
425
- );
426
- pool.globalState.communityFeeToken0 = communityFeeToken0;
427
- pool.globalState.communityFeeToken1 = communityFeeToken1;
428
- pool.blockTimestamp = (0, utils_1.bigIntify)(blockHeader.timestamp);
429
- return pool;
430
- }
431
- _computePoolAddress(token0, token1) {
432
- // https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/PoolAddress.sol
433
- if (token0 > token1) [token0, token1] = [token1, token0];
434
- const encodedKey = ethers_1.ethers.utils.keccak256(
435
- ethers_1.ethers.utils.defaultAbiCoder.encode(
436
- ['address', 'address'],
437
- [token0, token1],
438
- ),
439
- );
440
- return ethers_1.ethers.utils.getCreate2Address(
441
- this.poolDeployer,
442
- encodedKey,
443
- this.poolInitCodeHash,
444
- );
445
- }
446
- }
447
- exports.AlgebraEventPool = AlgebraEventPool;
448
- //# sourceMappingURL=algebra-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"algebra-pool.js","sourceRoot":"","sources":["../../../src/dex/algebra/algebra-pool.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,4CAA+C;AAC/C,iDAAqD;AAErD,uCAAmE;AACnE,+EAGyC;AAOzC,mCAAgC;AAEhC,kGAAgE;AAEhE,uDAIiC;AACjC,iDAAqD;AAErD,mCAAwE;AACxE,mDAAgD;AAChD,uEAAoE;AACpE,6DAG2C;AAC3C,+CAA4C;AAC5C,+CAA0C;AAE1C,MAAa,gBAAiB,SAAQ,mDAAkC;IAuBtE,YACW,SAAqB,EAC9B,UAAkB,EACT,kBAA4B,EAC5B,cAAyB,EACf,cAAuB,EAC1C,MAAe,EACf,MAAe,EACf,MAAc,EACd,SAAiB,EAAE,EACV,gBAAwB,EACxB,YAAoB;QAE7B,KAAK,CAAC,UAAU,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAZjE,cAAS,GAAT,SAAS,CAAY;QAErB,uBAAkB,GAAlB,kBAAkB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,CAAC;CACF;AA1hBD,4CA0hBC"}
@@ -1,43 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { BigNumber } from '@ethersproject/bignumber';
3
- import { BasePool } from './balancer-v2-pool';
4
- import { SwapSide } from '../../constants';
5
- import { callData, SubgraphPoolBase, PoolState } from './types';
6
- export declare type Gyro3PoolPairData = {
7
- balances: BigNumber[];
8
- indexIn: number;
9
- indexOut: number;
10
- swapFee: bigint;
11
- balanceTertiary: BigNumber;
12
- decimalsTertiary: number;
13
- scalingFactors: bigint[];
14
- root3Alpha: BigNumber;
15
- };
16
- export declare class Gyro3Pool extends BasePool {
17
- vaultAddress: string;
18
- vaultInterface: Interface;
19
- poolInterface: Interface;
20
- constructor(vaultAddress: string, vaultInterface: Interface);
21
- parsePoolPairData(
22
- pool: SubgraphPoolBase,
23
- poolState: PoolState,
24
- tokenIn: string,
25
- tokenOut: string,
26
- ): Gyro3PoolPairData;
27
- getSwapMaxAmount(poolPairData: Gyro3PoolPairData, side: SwapSide): bigint;
28
- getOnChainCalls(pool: SubgraphPoolBase): callData[];
29
- decodeOnChainCalls(
30
- pool: SubgraphPoolBase,
31
- data: {
32
- success: boolean;
33
- returnData: any;
34
- }[],
35
- startIndex: number,
36
- ): [
37
- {
38
- [address: string]: PoolState;
39
- },
40
- number,
41
- ];
42
- onSell(amounts: bigint[], poolPairData: Gyro3PoolPairData): bigint[];
43
- }
@@ -1,160 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.Gyro3Pool = void 0;
4
- const abi_1 = require('@ethersproject/abi');
5
- const bignumber_1 = require('@ethersproject/bignumber');
6
- const balancer_v2_pool_1 = require('./balancer-v2-pool');
7
- const constants_1 = require('../../constants');
8
- const utils_1 = require('./utils');
9
- const balancer_v2_math_1 = require('./balancer-v2-math');
10
- const sor_1 = require('@balancer-labs/sor');
11
- // Swap Limit factor
12
- const SWAP_LIMIT_FACTOR = BigInt('999999000000000000');
13
- class Gyro3Pool extends balancer_v2_pool_1.BasePool {
14
- constructor(vaultAddress, vaultInterface) {
15
- super();
16
- this.poolInterface = new abi_1.Interface([
17
- 'function getSwapFeePercentage() view returns (uint256)',
18
- ]);
19
- this.vaultAddress = vaultAddress;
20
- this.vaultInterface = vaultInterface;
21
- }
22
- parsePoolPairData(pool, poolState, tokenIn, tokenOut) {
23
- // All values should be normalised to 18 decimals. e.g. 1USDC = 1e18 not 1e6
24
- let indexIn = 0,
25
- indexOut = 0,
26
- indexTertiary = 0;
27
- const scalingFactors = [];
28
- const balances = pool.tokens.map((t, i) => {
29
- if (t.address.toLowerCase() === tokenIn.toLowerCase()) indexIn = i;
30
- else if (t.address.toLowerCase() === tokenOut.toLowerCase()) indexOut = i;
31
- else indexTertiary = i;
32
- const scalingFactor = (0, utils_1.getTokenScalingFactor)(t.decimals);
33
- scalingFactors.push(scalingFactor);
34
- return bignumber_1.BigNumber.from(
35
- this._upscale(
36
- BigInt(poolState.tokens[t.address.toLowerCase()].balance),
37
- scalingFactor,
38
- ),
39
- );
40
- });
41
- const balanceTertiary = balances[indexTertiary];
42
- const decimalsTertiary = pool.tokens[indexTertiary].decimals;
43
- const poolPairData = {
44
- balances,
45
- indexIn,
46
- indexOut,
47
- scalingFactors,
48
- swapFee: poolState.swapFee,
49
- balanceTertiary,
50
- decimalsTertiary,
51
- root3Alpha: (0, utils_1.safeParseFixed)(pool.root3Alpha, 18),
52
- };
53
- return poolPairData;
54
- }
55
- getSwapMaxAmount(poolPairData, side) {
56
- if (side === constants_1.SwapSide.SELL) {
57
- // Approximation - similar to traditional stable pools
58
- return this._downscaleDown(
59
- balancer_v2_math_1.MathSol.mulDownFixed(
60
- poolPairData.balances[poolPairData.indexOut].toBigInt(),
61
- SWAP_LIMIT_FACTOR,
62
- ),
63
- poolPairData.scalingFactors[poolPairData.indexIn],
64
- );
65
- } else {
66
- // Not currently supported
67
- return BigInt(0);
68
- }
69
- }
70
- /*
71
- Helper function to construct onchain multicall data for Pool.
72
- */
73
- getOnChainCalls(pool) {
74
- const poolCallData = [
75
- {
76
- target: this.vaultAddress,
77
- callData: this.vaultInterface.encodeFunctionData('getPoolTokens', [
78
- pool.id,
79
- ]),
80
- },
81
- {
82
- target: pool.address,
83
- callData: this.poolInterface.encodeFunctionData('getSwapFeePercentage'),
84
- },
85
- ];
86
- return poolCallData;
87
- }
88
- /*
89
- Helper function to decode multicall data for Pool.
90
- data must contain returnData
91
- startIndex is where to start in returnData. Allows this decode function to be called along with other pool types.
92
- */
93
- decodeOnChainCalls(pool, data, startIndex) {
94
- const pools = {};
95
- const poolTokens = (0, utils_1.decodeThrowError)(
96
- this.vaultInterface,
97
- 'getPoolTokens',
98
- data[startIndex++],
99
- pool.address,
100
- );
101
- const swapFee = (0, utils_1.decodeThrowError)(
102
- this.poolInterface,
103
- 'getSwapFeePercentage',
104
- data[startIndex++],
105
- pool.address,
106
- )[0];
107
- const poolState = {
108
- swapFee: BigInt(swapFee.toString()),
109
- orderedTokens: poolTokens.tokens,
110
- tokens: poolTokens.tokens.reduce((ptAcc, pt, j) => {
111
- const tokenState = {
112
- balance: BigInt(poolTokens.balances[j].toString()),
113
- };
114
- ptAcc[pt.toLowerCase()] = tokenState;
115
- return ptAcc;
116
- }, {}),
117
- };
118
- pools[pool.address] = poolState;
119
- return [pools, startIndex];
120
- }
121
- onSell(amounts, poolPairData) {
122
- try {
123
- const invariant = sor_1.Gyro3Maths._calculateInvariant(
124
- poolPairData.balances,
125
- poolPairData.root3Alpha,
126
- );
127
- const virtualOffsetInOut = balancer_v2_math_1.MathSol.mulDownFixed(
128
- invariant.toBigInt(),
129
- poolPairData.root3Alpha.toBigInt(),
130
- );
131
- const tokenAmountsInScaled = amounts.map(a =>
132
- this._upscale(a, poolPairData.scalingFactors[poolPairData.indexIn]),
133
- );
134
- const tokenAmountsInWithFee = tokenAmountsInScaled.map(a =>
135
- this._subtractSwapFeeAmount(a, poolPairData.swapFee),
136
- );
137
- const amountsOut = tokenAmountsInWithFee.map(amount => {
138
- try {
139
- const amountOut = sor_1.Gyro3Maths._calcOutGivenIn(
140
- poolPairData.balances[poolPairData.indexIn],
141
- poolPairData.balances[poolPairData.indexOut],
142
- bignumber_1.BigNumber.from(amount),
143
- bignumber_1.BigNumber.from(virtualOffsetInOut),
144
- ).toBigInt();
145
- return this._downscaleDown(
146
- amountOut,
147
- poolPairData.scalingFactors[poolPairData.indexOut],
148
- );
149
- } catch (error) {
150
- return BigInt(0);
151
- }
152
- });
153
- return amountsOut;
154
- } catch (error) {
155
- return [];
156
- }
157
- }
158
- }
159
- exports.Gyro3Pool = Gyro3Pool;
160
- //# sourceMappingURL=Gyro3Pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Gyro3Pool.js","sourceRoot":"","sources":["../../../src/dex/balancer-v2/Gyro3Pool.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,wDAAqD;AAErD,yDAA8C;AAC9C,+CAA2C;AAC3C,mCAIiB;AAEjB,yDAA6C;AAC7C,4CAAgD;AAGhD,oBAAoB;AACpB,MAAM,iBAAiB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAcvD,MAAa,SAAU,SAAQ,2BAAQ;IAOrC,YAAY,YAAoB,EAAE,cAAyB;QACzD,KAAK,EAAE,CAAC;QALV,kBAAa,GAAG,IAAI,eAAS,CAAC;YAC5B,wDAAwD;SACzD,CAAC,CAAC;QAID,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,iBAAiB,CACf,IAAsB,EACtB,SAAoB,EACpB,OAAe,EACf,QAAgB;QAEhB,4EAA4E;QAC5E,IAAI,OAAO,GAAG,CAAC,EACb,QAAQ,GAAG,CAAC,EACZ,aAAa,GAAG,CAAC,CAAC;QACpB,MAAM,cAAc,GAAa,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,E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