@steerprotocol/sdk 1.30.4 → 1.30.5

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 (355) hide show
  1. package/dist/cjs/const/amm/configs/ammConfig.js +33 -34
  2. package/dist/cjs/const/amm/configs/ammConfig.js.map +1 -1
  3. package/dist/cjs/const/amm/configs/protocols/index.js +0 -39
  4. package/dist/cjs/const/amm/configs/protocols/index.js.map +1 -1
  5. package/dist/cjs/const/stabilityVaults/index.js +1 -1
  6. package/dist/cjs/const/stabilityVaults/index.js.map +1 -1
  7. package/dist/esm/base/FeeManagerClient.js +26 -22
  8. package/dist/esm/base/FeeManagerClient.js.map +1 -1
  9. package/dist/esm/base/PoolClient.js +19 -15
  10. package/dist/esm/base/PoolClient.js.map +1 -1
  11. package/dist/esm/base/SmartRewardClient.js +10 -6
  12. package/dist/esm/base/SmartRewardClient.js.map +1 -1
  13. package/dist/esm/base/SmartRewards.js +11 -7
  14. package/dist/esm/base/SmartRewards.js.map +1 -1
  15. package/dist/esm/base/StakingClient.js +18 -14
  16. package/dist/esm/base/StakingClient.js.map +1 -1
  17. package/dist/esm/base/SubgraphClient.js +8 -4
  18. package/dist/esm/base/SubgraphClient.js.map +1 -1
  19. package/dist/esm/base/VaultClient.js +55 -37
  20. package/dist/esm/base/VaultClient.js.map +1 -1
  21. package/dist/esm/base/vault/deposit/index.js +42 -38
  22. package/dist/esm/base/vault/deposit/index.js.map +1 -1
  23. package/dist/esm/base/vault/deposit/types.js +2 -1
  24. package/dist/esm/base/vault/single-asset/calculateLimitPrice.js +39 -32
  25. package/dist/esm/base/vault/single-asset/calculateLimitPrice.js.map +1 -1
  26. package/dist/esm/base/vault/single-asset/calculateSwapAmount.js +8 -5
  27. package/dist/esm/base/vault/single-asset/calculateSwapAmount.js.map +1 -1
  28. package/dist/esm/base/vault/single-asset/estimateLpTokens.js +12 -7
  29. package/dist/esm/base/vault/single-asset/estimateLpTokens.js.map +1 -1
  30. package/dist/esm/base/vault/single-asset/index.js +32 -6
  31. package/dist/esm/base/vault/single-asset/index.js.map +1 -1
  32. package/dist/esm/base/vault/single-asset/simulateSwap.js +30 -24
  33. package/dist/esm/base/vault/single-asset/simulateSwap.js.map +1 -1
  34. package/dist/esm/base/vault/single-asset/singleAssetDeposit.js +33 -29
  35. package/dist/esm/base/vault/single-asset/singleAssetDeposit.js.map +1 -1
  36. package/dist/esm/base/vault/single-asset/types.js +5 -2
  37. package/dist/esm/base/vault/single-asset/types.js.map +1 -1
  38. package/dist/esm/base/vault/utils.js +16 -7
  39. package/dist/esm/base/vault/utils.js.map +1 -1
  40. package/dist/esm/base/vault/withdraw/index.js +10 -6
  41. package/dist/esm/base/vault/withdraw/index.js.map +1 -1
  42. package/dist/esm/base/vault/withdraw/types.js +2 -1
  43. package/dist/esm/client.js +15 -11
  44. package/dist/esm/client.js.map +1 -1
  45. package/dist/esm/const/abis/UniswapPool.js +4 -1
  46. package/dist/esm/const/abis/UniswapPool.js.map +1 -1
  47. package/dist/esm/const/abis/erc1155.js +4 -1
  48. package/dist/esm/const/abis/erc1155.js.map +1 -1
  49. package/dist/esm/const/abis/erc20.js +4 -1
  50. package/dist/esm/const/abis/erc20.js.map +1 -1
  51. package/dist/esm/const/abis/erc721.js +4 -1
  52. package/dist/esm/const/abis/erc721.js.map +1 -1
  53. package/dist/esm/const/abis/feeManager.js +4 -1
  54. package/dist/esm/const/abis/feeManager.js.map +1 -1
  55. package/dist/esm/const/abis/index.js +24 -8
  56. package/dist/esm/const/abis/index.js.map +1 -1
  57. package/dist/esm/const/abis/quoter.js +9 -6
  58. package/dist/esm/const/abis/quoter.js.map +1 -1
  59. package/dist/esm/const/abis/singleTokenDeposit.js +4 -1
  60. package/dist/esm/const/abis/singleTokenDeposit.js.map +1 -1
  61. package/dist/esm/const/abis/vaultFees.js +4 -1
  62. package/dist/esm/const/abis/vaultFees.js.map +1 -1
  63. package/dist/esm/const/amm/configs/ammConfig.js +98 -95
  64. package/dist/esm/const/amm/configs/ammConfig.js.map +1 -1
  65. package/dist/esm/const/amm/configs/protocols/aerodrome-v2.js +12 -8
  66. package/dist/esm/const/amm/configs/protocols/aerodrome-v2.js.map +1 -1
  67. package/dist/esm/const/amm/configs/protocols/aerodrome.js +12 -8
  68. package/dist/esm/const/amm/configs/protocols/aerodrome.js.map +1 -1
  69. package/dist/esm/const/amm/configs/protocols/arthswap.js +14 -10
  70. package/dist/esm/const/amm/configs/protocols/arthswap.js.map +1 -1
  71. package/dist/esm/const/amm/configs/protocols/baseswap.js +11 -7
  72. package/dist/esm/const/amm/configs/protocols/baseswap.js.map +1 -1
  73. package/dist/esm/const/amm/configs/protocols/basex.js +12 -8
  74. package/dist/esm/const/amm/configs/protocols/basex.js.map +1 -1
  75. package/dist/esm/const/amm/configs/protocols/beam.js +11 -7
  76. package/dist/esm/const/amm/configs/protocols/beam.js.map +1 -1
  77. package/dist/esm/const/amm/configs/protocols/beamswap.js +11 -7
  78. package/dist/esm/const/amm/configs/protocols/beamswap.js.map +1 -1
  79. package/dist/esm/const/amm/configs/protocols/blackhole.js +12 -8
  80. package/dist/esm/const/amm/configs/protocols/blackhole.js.map +1 -1
  81. package/dist/esm/const/amm/configs/protocols/camelot.js +17 -13
  82. package/dist/esm/const/amm/configs/protocols/camelot.js.map +1 -1
  83. package/dist/esm/const/amm/configs/protocols/crust.js +11 -7
  84. package/dist/esm/const/amm/configs/protocols/crust.js.map +1 -1
  85. package/dist/esm/const/amm/configs/protocols/cypher.js +13 -9
  86. package/dist/esm/const/amm/configs/protocols/cypher.js.map +1 -1
  87. package/dist/esm/const/amm/configs/protocols/dodo.js +11 -7
  88. package/dist/esm/const/amm/configs/protocols/dodo.js.map +1 -1
  89. package/dist/esm/const/amm/configs/protocols/dragonswap.js +11 -7
  90. package/dist/esm/const/amm/configs/protocols/dragonswap.js.map +1 -1
  91. package/dist/esm/const/amm/configs/protocols/eddy.js +11 -7
  92. package/dist/esm/const/amm/configs/protocols/eddy.js.map +1 -1
  93. package/dist/esm/const/amm/configs/protocols/equilibre.js +11 -7
  94. package/dist/esm/const/amm/configs/protocols/equilibre.js.map +1 -1
  95. package/dist/esm/const/amm/configs/protocols/fenix.js +11 -7
  96. package/dist/esm/const/amm/configs/protocols/fenix.js.map +1 -1
  97. package/dist/esm/const/amm/configs/protocols/forge.js +13 -9
  98. package/dist/esm/const/amm/configs/protocols/forge.js.map +1 -1
  99. package/dist/esm/const/amm/configs/protocols/fusionx.js +12 -8
  100. package/dist/esm/const/amm/configs/protocols/fusionx.js.map +1 -1
  101. package/dist/esm/const/amm/configs/protocols/glyph.js +13 -9
  102. package/dist/esm/const/amm/configs/protocols/glyph.js.map +1 -1
  103. package/dist/esm/const/amm/configs/protocols/henjin.js +11 -7
  104. package/dist/esm/const/amm/configs/protocols/henjin.js.map +1 -1
  105. package/dist/esm/const/amm/configs/protocols/hercules.js +11 -7
  106. package/dist/esm/const/amm/configs/protocols/hercules.js.map +1 -1
  107. package/dist/esm/const/amm/configs/protocols/horiza.js +13 -9
  108. package/dist/esm/const/amm/configs/protocols/horiza.js.map +1 -1
  109. package/dist/esm/const/amm/configs/protocols/index.js +56 -79
  110. package/dist/esm/const/amm/configs/protocols/index.js.map +1 -1
  111. package/dist/esm/const/amm/configs/protocols/katana.js +10 -6
  112. package/dist/esm/const/amm/configs/protocols/katana.js.map +1 -1
  113. package/dist/esm/const/amm/configs/protocols/katanaIntegral.js +10 -6
  114. package/dist/esm/const/amm/configs/protocols/katanaIntegral.js.map +1 -1
  115. package/dist/esm/const/amm/configs/protocols/kim.js +15 -11
  116. package/dist/esm/const/amm/configs/protocols/kim.js.map +1 -1
  117. package/dist/esm/const/amm/configs/protocols/kinetix.js +14 -10
  118. package/dist/esm/const/amm/configs/protocols/kinetix.js.map +1 -1
  119. package/dist/esm/const/amm/configs/protocols/kodiak.js +14 -10
  120. package/dist/esm/const/amm/configs/protocols/kodiak.js.map +1 -1
  121. package/dist/esm/const/amm/configs/protocols/kyo.js +12 -8
  122. package/dist/esm/const/amm/configs/protocols/kyo.js.map +1 -1
  123. package/dist/esm/const/amm/configs/protocols/linehub.js +11 -7
  124. package/dist/esm/const/amm/configs/protocols/linehub.js.map +1 -1
  125. package/dist/esm/const/amm/configs/protocols/lynex.js +13 -9
  126. package/dist/esm/const/amm/configs/protocols/lynex.js.map +1 -1
  127. package/dist/esm/const/amm/configs/protocols/machinex.js +13 -9
  128. package/dist/esm/const/amm/configs/protocols/machinex.js.map +1 -1
  129. package/dist/esm/const/amm/configs/protocols/maia.js +13 -9
  130. package/dist/esm/const/amm/configs/protocols/maia.js.map +1 -1
  131. package/dist/esm/const/amm/configs/protocols/metavault.js +16 -12
  132. package/dist/esm/const/amm/configs/protocols/metavault.js.map +1 -1
  133. package/dist/esm/const/amm/configs/protocols/nest.js +12 -8
  134. package/dist/esm/const/amm/configs/protocols/nest.js.map +1 -1
  135. package/dist/esm/const/amm/configs/protocols/novaswap.js +11 -7
  136. package/dist/esm/const/amm/configs/protocols/novaswap.js.map +1 -1
  137. package/dist/esm/const/amm/configs/protocols/ocelex.js +11 -7
  138. package/dist/esm/const/amm/configs/protocols/ocelex.js.map +1 -1
  139. package/dist/esm/const/amm/configs/protocols/pancakeswap.js +17 -13
  140. package/dist/esm/const/amm/configs/protocols/pancakeswap.js.map +1 -1
  141. package/dist/esm/const/amm/configs/protocols/poolshark.js +11 -7
  142. package/dist/esm/const/amm/configs/protocols/poolshark.js.map +1 -1
  143. package/dist/esm/const/amm/configs/protocols/quickswap-algebra.js +12 -8
  144. package/dist/esm/const/amm/configs/protocols/quickswap-algebra.js.map +1 -1
  145. package/dist/esm/const/amm/configs/protocols/quickswap-integral.js +17 -13
  146. package/dist/esm/const/amm/configs/protocols/quickswap-integral.js.map +1 -1
  147. package/dist/esm/const/amm/configs/protocols/quickswap-univ3.js +20 -16
  148. package/dist/esm/const/amm/configs/protocols/quickswap-univ3.js.map +1 -1
  149. package/dist/esm/const/amm/configs/protocols/quickswap.js +18 -14
  150. package/dist/esm/const/amm/configs/protocols/quickswap.js.map +1 -1
  151. package/dist/esm/const/amm/configs/protocols/retro.js +13 -9
  152. package/dist/esm/const/amm/configs/protocols/retro.js.map +1 -1
  153. package/dist/esm/const/amm/configs/protocols/sailor.js +11 -7
  154. package/dist/esm/const/amm/configs/protocols/sailor.js.map +1 -1
  155. package/dist/esm/const/amm/configs/protocols/shadow.js +13 -9
  156. package/dist/esm/const/amm/configs/protocols/shadow.js.map +1 -1
  157. package/dist/esm/const/amm/configs/protocols/silverswap.js +15 -11
  158. package/dist/esm/const/amm/configs/protocols/silverswap.js.map +1 -1
  159. package/dist/esm/const/amm/configs/protocols/spark-integral.js +12 -8
  160. package/dist/esm/const/amm/configs/protocols/spark-integral.js.map +1 -1
  161. package/dist/esm/const/amm/configs/protocols/spark.js +11 -7
  162. package/dist/esm/const/amm/configs/protocols/spark.js.map +1 -1
  163. package/dist/esm/const/amm/configs/protocols/spark32.js +11 -7
  164. package/dist/esm/const/amm/configs/protocols/spark32.js.map +1 -1
  165. package/dist/esm/const/amm/configs/protocols/spookyswap.js +11 -7
  166. package/dist/esm/const/amm/configs/protocols/spookyswap.js.map +1 -1
  167. package/dist/esm/const/amm/configs/protocols/stellaswap.js +13 -9
  168. package/dist/esm/const/amm/configs/protocols/stellaswap.js.map +1 -1
  169. package/dist/esm/const/amm/configs/protocols/supswap.js +11 -7
  170. package/dist/esm/const/amm/configs/protocols/supswap.js.map +1 -1
  171. package/dist/esm/const/amm/configs/protocols/sushi.js +73 -69
  172. package/dist/esm/const/amm/configs/protocols/sushi.js.map +1 -1
  173. package/dist/esm/const/amm/configs/protocols/swapmode.js +11 -7
  174. package/dist/esm/const/amm/configs/protocols/swapmode.js.map +1 -1
  175. package/dist/esm/const/amm/configs/protocols/swapsicle.js +11 -7
  176. package/dist/esm/const/amm/configs/protocols/swapsicle.js.map +1 -1
  177. package/dist/esm/const/amm/configs/protocols/thena.js +13 -9
  178. package/dist/esm/const/amm/configs/protocols/thena.js.map +1 -1
  179. package/dist/esm/const/amm/configs/protocols/thick.js +12 -8
  180. package/dist/esm/const/amm/configs/protocols/thick.js.map +1 -1
  181. package/dist/esm/const/amm/configs/protocols/thickv2.js +12 -8
  182. package/dist/esm/const/amm/configs/protocols/thickv2.js.map +1 -1
  183. package/dist/esm/const/amm/configs/protocols/thruster.js +12 -8
  184. package/dist/esm/const/amm/configs/protocols/thruster.js.map +1 -1
  185. package/dist/esm/const/amm/configs/protocols/uniswap.js +83 -79
  186. package/dist/esm/const/amm/configs/protocols/uniswap.js.map +1 -1
  187. package/dist/esm/const/amm/configs/protocols/wasabee.js +11 -7
  188. package/dist/esm/const/amm/configs/protocols/wasabee.js.map +1 -1
  189. package/dist/esm/const/amm/index.js +19 -3
  190. package/dist/esm/const/amm/index.js.map +1 -1
  191. package/dist/esm/const/amm/utils/beacon.js +76 -70
  192. package/dist/esm/const/amm/utils/beacon.js.map +1 -1
  193. package/dist/esm/const/amm/utils/contracts.js +26 -16
  194. package/dist/esm/const/amm/utils/contracts.js.map +1 -1
  195. package/dist/esm/const/amm/utils/index.js +46 -22
  196. package/dist/esm/const/amm/utils/index.js.map +1 -1
  197. package/dist/esm/const/amm/utils/protocol.js +24 -16
  198. package/dist/esm/const/amm/utils/protocol.js.map +1 -1
  199. package/dist/esm/const/api.js +7 -3
  200. package/dist/esm/const/api.js.map +1 -1
  201. package/dist/esm/const/capabilities.js +20 -15
  202. package/dist/esm/const/capabilities.js.map +1 -1
  203. package/dist/esm/const/chain.js +12 -9
  204. package/dist/esm/const/chain.js.map +1 -1
  205. package/dist/esm/const/deployments/abis.js +4 -1
  206. package/dist/esm/const/deployments/abis.js.map +1 -1
  207. package/dist/esm/const/deployments/apechain.js +4 -1
  208. package/dist/esm/const/deployments/apechain.js.map +1 -1
  209. package/dist/esm/const/deployments/arbitrum.js +4 -1
  210. package/dist/esm/const/deployments/arbitrum.js.map +1 -1
  211. package/dist/esm/const/deployments/arbitrumgoerli.js +4 -1
  212. package/dist/esm/const/deployments/arbitrumgoerli.js.map +1 -1
  213. package/dist/esm/const/deployments/astar.js +4 -1
  214. package/dist/esm/const/deployments/astar.js.map +1 -1
  215. package/dist/esm/const/deployments/astarzkevm.js +4 -1
  216. package/dist/esm/const/deployments/astarzkevm.js.map +1 -1
  217. package/dist/esm/const/deployments/avalanche.js +4 -1
  218. package/dist/esm/const/deployments/avalanche.js.map +1 -1
  219. package/dist/esm/const/deployments/bartiotest.js +4 -1
  220. package/dist/esm/const/deployments/bartiotest.js.map +1 -1
  221. package/dist/esm/const/deployments/base.js +4 -1
  222. package/dist/esm/const/deployments/base.js.map +1 -1
  223. package/dist/esm/const/deployments/bera.js +4 -1
  224. package/dist/esm/const/deployments/bera.js.map +1 -1
  225. package/dist/esm/const/deployments/berachainbartio.js +4 -1
  226. package/dist/esm/const/deployments/berachainbartio.js.map +1 -1
  227. package/dist/esm/const/deployments/blast.js +4 -1
  228. package/dist/esm/const/deployments/blast.js.map +1 -1
  229. package/dist/esm/const/deployments/bsc.js +4 -1
  230. package/dist/esm/const/deployments/bsc.js.map +1 -1
  231. package/dist/esm/const/deployments/celo.js +4 -1
  232. package/dist/esm/const/deployments/celo.js.map +1 -1
  233. package/dist/esm/const/deployments/core.js +4 -1
  234. package/dist/esm/const/deployments/core.js.map +1 -1
  235. package/dist/esm/const/deployments/eth.js +4 -1
  236. package/dist/esm/const/deployments/eth.js.map +1 -1
  237. package/dist/esm/const/deployments/evmos.js +4 -1
  238. package/dist/esm/const/deployments/evmos.js.map +1 -1
  239. package/dist/esm/const/deployments/fantom.js +4 -1
  240. package/dist/esm/const/deployments/fantom.js.map +1 -1
  241. package/dist/esm/const/deployments/filecoin.js +4 -1
  242. package/dist/esm/const/deployments/filecoin.js.map +1 -1
  243. package/dist/esm/const/deployments/flare.js +4 -1
  244. package/dist/esm/const/deployments/flare.js.map +1 -1
  245. package/dist/esm/const/deployments/goerli.js +4 -1
  246. package/dist/esm/const/deployments/goerli.js.map +1 -1
  247. package/dist/esm/const/deployments/hemi.js +4 -1
  248. package/dist/esm/const/deployments/hemi.js.map +1 -1
  249. package/dist/esm/const/deployments/hyperevm.js +4 -1
  250. package/dist/esm/const/deployments/hyperevm.js.map +1 -1
  251. package/dist/esm/const/deployments/index.js +99 -48
  252. package/dist/esm/const/deployments/index.js.map +1 -1
  253. package/dist/esm/const/deployments/katana.js +4 -1
  254. package/dist/esm/const/deployments/katana.js.map +1 -1
  255. package/dist/esm/const/deployments/kava.js +4 -1
  256. package/dist/esm/const/deployments/kava.js.map +1 -1
  257. package/dist/esm/const/deployments/linea.js +4 -1
  258. package/dist/esm/const/deployments/linea.js.map +1 -1
  259. package/dist/esm/const/deployments/localhost.js +4 -1
  260. package/dist/esm/const/deployments/localhost.js.map +1 -1
  261. package/dist/esm/const/deployments/manta.js +4 -1
  262. package/dist/esm/const/deployments/manta.js.map +1 -1
  263. package/dist/esm/const/deployments/mantle.js +4 -1
  264. package/dist/esm/const/deployments/mantle.js.map +1 -1
  265. package/dist/esm/const/deployments/metis.js +4 -1
  266. package/dist/esm/const/deployments/metis.js.map +1 -1
  267. package/dist/esm/const/deployments/mode.js +4 -1
  268. package/dist/esm/const/deployments/mode.js.map +1 -1
  269. package/dist/esm/const/deployments/moonbeam.js +4 -1
  270. package/dist/esm/const/deployments/moonbeam.js.map +1 -1
  271. package/dist/esm/const/deployments/mumbai.js +4 -1
  272. package/dist/esm/const/deployments/mumbai.js.map +1 -1
  273. package/dist/esm/const/deployments/nibiru.js +4 -1
  274. package/dist/esm/const/deployments/nibiru.js.map +1 -1
  275. package/dist/esm/const/deployments/okxtestnet.js +4 -1
  276. package/dist/esm/const/deployments/okxtestnet.js.map +1 -1
  277. package/dist/esm/const/deployments/optimism.js +4 -1
  278. package/dist/esm/const/deployments/optimism.js.map +1 -1
  279. package/dist/esm/const/deployments/optimismgoerli.js +4 -1
  280. package/dist/esm/const/deployments/optimismgoerli.js.map +1 -1
  281. package/dist/esm/const/deployments/peaq.js +4 -1
  282. package/dist/esm/const/deployments/peaq.js.map +1 -1
  283. package/dist/esm/const/deployments/polygon.js +4 -1
  284. package/dist/esm/const/deployments/polygon.js.map +1 -1
  285. package/dist/esm/const/deployments/polyzkevm.js +4 -1
  286. package/dist/esm/const/deployments/polyzkevm.js.map +1 -1
  287. package/dist/esm/const/deployments/pyzkevm.js +4 -1
  288. package/dist/esm/const/deployments/pyzkevm.js.map +1 -1
  289. package/dist/esm/const/deployments/ronin.js +4 -1
  290. package/dist/esm/const/deployments/ronin.js.map +1 -1
  291. package/dist/esm/const/deployments/rootstock.js +4 -1
  292. package/dist/esm/const/deployments/rootstock.js.map +1 -1
  293. package/dist/esm/const/deployments/saga.js +4 -1
  294. package/dist/esm/const/deployments/saga.js.map +1 -1
  295. package/dist/esm/const/deployments/scroll.js +4 -1
  296. package/dist/esm/const/deployments/scroll.js.map +1 -1
  297. package/dist/esm/const/deployments/sei.js +4 -1
  298. package/dist/esm/const/deployments/sei.js.map +1 -1
  299. package/dist/esm/const/deployments/soneium.js +4 -1
  300. package/dist/esm/const/deployments/soneium.js.map +1 -1
  301. package/dist/esm/const/deployments/sonic.js +4 -1
  302. package/dist/esm/const/deployments/sonic.js.map +1 -1
  303. package/dist/esm/const/deployments/taiko.js +4 -1
  304. package/dist/esm/const/deployments/taiko.js.map +1 -1
  305. package/dist/esm/const/deployments/tataratestnet.js +4 -1
  306. package/dist/esm/const/deployments/tataratestnet.js.map +1 -1
  307. package/dist/esm/const/deployments/telos.js +4 -1
  308. package/dist/esm/const/deployments/telos.js.map +1 -1
  309. package/dist/esm/const/deployments/thundercore.js +4 -1
  310. package/dist/esm/const/deployments/thundercore.js.map +1 -1
  311. package/dist/esm/const/deployments/uni.js +4 -1
  312. package/dist/esm/const/deployments/uni.js.map +1 -1
  313. package/dist/esm/const/deployments/xlayer.js +4 -1
  314. package/dist/esm/const/deployments/xlayer.js.map +1 -1
  315. package/dist/esm/const/deployments/zeta.js +4 -1
  316. package/dist/esm/const/deployments/zeta.js.map +1 -1
  317. package/dist/esm/const/deployments/zircuit.js +4 -1
  318. package/dist/esm/const/deployments/zircuit.js.map +1 -1
  319. package/dist/esm/const/deployments/zklinknova.js +4 -1
  320. package/dist/esm/const/deployments/zklinknova.js.map +1 -1
  321. package/dist/esm/const/index.js +28 -12
  322. package/dist/esm/const/index.js.map +1 -1
  323. package/dist/esm/const/network.js +232 -223
  324. package/dist/esm/const/network.js.map +1 -1
  325. package/dist/esm/const/protocol.js +97 -83
  326. package/dist/esm/const/protocol.js.map +1 -1
  327. package/dist/esm/const/quoter.js +53 -42
  328. package/dist/esm/const/quoter.js.map +1 -1
  329. package/dist/esm/const/stabilityVaults/index.js +17 -1
  330. package/dist/esm/const/stabilityVaults/index.js.map +1 -1
  331. package/dist/esm/const/stabilityVaults/stabilityVaultsConfig.js +15 -10
  332. package/dist/esm/const/stabilityVaults/stabilityVaultsConfig.js.map +1 -1
  333. package/dist/esm/const/subgraph.js +60 -56
  334. package/dist/esm/const/subgraph.js.map +1 -1
  335. package/dist/esm/const/thegraph.js +5 -1
  336. package/dist/esm/const/thegraph.js.map +1 -1
  337. package/dist/esm/index.js +31 -12
  338. package/dist/esm/index.js.map +1 -1
  339. package/dist/esm/scripts/processDeployments.js +15 -10
  340. package/dist/esm/scripts/processDeployments.js.map +1 -1
  341. package/dist/esm/types.js +2 -1
  342. package/dist/esm/utils/PoolQueryAdapter.js +44 -38
  343. package/dist/esm/utils/PoolQueryAdapter.js.map +1 -1
  344. package/dist/esm/utils/SubgraphVaultClient.js +10 -6
  345. package/dist/esm/utils/SubgraphVaultClient.js.map +1 -1
  346. package/dist/esm/utils/subgraph-types.js +2 -1
  347. package/dist/types/const/amm/configs/ammConfig.d.ts.map +1 -1
  348. package/dist/types/const/amm/configs/protocols/index.d.ts +0 -39
  349. package/dist/types/const/amm/configs/protocols/index.d.ts.map +1 -1
  350. package/dist/types/const/stabilityVaults/index.d.ts +1 -1
  351. package/dist/types/const/stabilityVaults/index.d.ts.map +1 -1
  352. package/package.json +1 -1
  353. package/src/const/amm/configs/ammConfig.ts +2 -3
  354. package/src/const/amm/configs/protocols/index.ts +1 -40
  355. package/src/const/stabilityVaults/index.ts +1 -1
@@ -1,15 +1,18 @@
1
- import { Rounding, Token } from '@uniswap/sdk-core';
2
- import { Pool as PoolV3 } from '@uniswap/v3-sdk';
3
- import { Decimal } from 'decimal.js';
4
- import { UniswapV3PoolABI } from '../../../const/abis/UniswapPool.js';
5
- import { abis } from '../../../const/deployments/abis.js';
6
- import { getContractAddressByChainIdAndContractName } from '../../../const/network.js';
7
- import { isAlgebraDirectionProtocol, isAlgebraIntegralProtocol, isAlgebraProtocol, isPoolSharkProtocol } from '../../../const/protocol.js';
8
- import { getGlobalState, getGlobalStateAlgebraIntegral, getGlobalStatePoolShark, getSlot0 } from '../utils.js';
9
- import { getProtocolTypeByBeacon } from "../../../const/index.js";
10
- const VAULT_ABI = abis.QuickSwapUniv3MultiPositionLiquidityManager;
11
- const PERIPHERY_ABI = abis.SteerPeriphery;
12
- export class VaultDepositClient {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultDepositClient = void 0;
4
+ const sdk_core_1 = require("@uniswap/sdk-core");
5
+ const v3_sdk_1 = require("@uniswap/v3-sdk");
6
+ const decimal_js_1 = require("decimal.js");
7
+ const UniswapPool_js_1 = require("../../../const/abis/UniswapPool.js");
8
+ const abis_js_1 = require("../../../const/deployments/abis.js");
9
+ const network_js_1 = require("../../../const/network.js");
10
+ const protocol_js_1 = require("../../../const/protocol.js");
11
+ const utils_js_1 = require("../utils.js");
12
+ const index_js_1 = require("../../../const/index.js");
13
+ const VAULT_ABI = abis_js_1.abis.QuickSwapUniv3MultiPositionLiquidityManager;
14
+ const PERIPHERY_ABI = abis_js_1.abis.SteerPeriphery;
15
+ class VaultDepositClient {
13
16
  constructor(publicClient, walletClient) {
14
17
  this.publicClient = publicClient;
15
18
  this.walletClient = walletClient;
@@ -32,7 +35,7 @@ export class VaultDepositClient {
32
35
  if (!params.chainId) {
33
36
  throw new Error('chainId is required when using Steer Periphery');
34
37
  }
35
- const steerPeripheryAddress = getContractAddressByChainIdAndContractName(params.chainId, 'SteerPeriphery');
38
+ const steerPeripheryAddress = (0, network_js_1.getContractAddressByChainIdAndContractName)(params.chainId, 'SteerPeriphery');
36
39
  if (!steerPeripheryAddress) {
37
40
  throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);
38
41
  }
@@ -102,7 +105,7 @@ export class VaultDepositClient {
102
105
  if (!params.chainId) {
103
106
  throw new Error('chainId is required when using Steer Periphery');
104
107
  }
105
- const steerPeripheryAddress = getContractAddressByChainIdAndContractName(params.chainId, 'SteerPeriphery');
108
+ const steerPeripheryAddress = (0, network_js_1.getContractAddressByChainIdAndContractName)(params.chainId, 'SteerPeriphery');
106
109
  if (!steerPeripheryAddress) {
107
110
  throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);
108
111
  }
@@ -227,7 +230,7 @@ export class VaultDepositClient {
227
230
  let vaultDetails;
228
231
  let isAlgebraVault = false;
229
232
  const chainId = await this.publicClient.getChainId();
230
- const steerPeripheryAddress = getContractAddressByChainIdAndContractName(chainId, 'SteerPeriphery');
233
+ const steerPeripheryAddress = (0, network_js_1.getContractAddressByChainIdAndContractName)(chainId, 'SteerPeriphery');
231
234
  if (!steerPeripheryAddress)
232
235
  throw new Error('SteerPeriphery address not found');
233
236
  try {
@@ -263,7 +266,7 @@ export class VaultDepositClient {
263
266
  if (!pool.data)
264
267
  throw new Error('Failed to retrieve pool for ratio calculation');
265
268
  // Determine the protocol
266
- const protocol = getProtocolTypeByBeacon(vaultDetails.vaultType);
269
+ const protocol = (0, index_js_1.getProtocolTypeByBeacon)(vaultDetails.vaultType);
267
270
  if (!protocol)
268
271
  throw new Error('Unsupported protocol type');
269
272
  console.log('Protocol detected:', protocol);
@@ -271,10 +274,10 @@ export class VaultDepositClient {
271
274
  const poolInstanceResponse = await this.getPoolInstance({
272
275
  vaultAddress,
273
276
  chain: { id: chainId },
274
- isAlgebraPool: isAlgebraProtocol(protocol),
275
- isPoolSharkPool: isPoolSharkProtocol(protocol),
276
- isAlgebraIntegralPool: isAlgebraIntegralProtocol(protocol),
277
- isAlgebraDirectionPool: isAlgebraDirectionProtocol(protocol),
277
+ isAlgebraPool: (0, protocol_js_1.isAlgebraProtocol)(protocol),
278
+ isPoolSharkPool: (0, protocol_js_1.isPoolSharkProtocol)(protocol),
279
+ isAlgebraIntegralPool: (0, protocol_js_1.isAlgebraIntegralProtocol)(protocol),
280
+ isAlgebraDirectionPool: (0, protocol_js_1.isAlgebraDirectionProtocol)(protocol),
278
281
  });
279
282
  if (!poolInstanceResponse.success || !poolInstanceResponse.data) {
280
283
  throw new Error('Failed to get pool instance for price calculation');
@@ -285,16 +288,16 @@ export class VaultDepositClient {
285
288
  ? poolInstance.priceOf(poolInstance.token0)
286
289
  : poolInstance.priceOf(poolInstance.token0).invert();
287
290
  // Convert price to string using Decimal for maximum precision
288
- ratio = price.toSignificant(undefined, undefined, Rounding.ROUND_DOWN);
291
+ ratio = price.toSignificant(undefined, undefined, sdk_core_1.Rounding.ROUND_DOWN);
289
292
  }
290
293
  // Case 2: Vault has liquidity
291
294
  else {
292
295
  // Convert bigint values to Decimal instances for precise calculation
293
296
  // Convert bigints to strings first to avoid type errors
294
- const token0Bal = new Decimal(token0Balance.toString());
295
- const token1Bal = new Decimal(token1Balance.toString());
296
- const token0Dec = new Decimal(10).pow(Number(token0Decimals));
297
- const token1Dec = new Decimal(10).pow(Number(token1Decimals));
297
+ const token0Bal = new decimal_js_1.Decimal(token0Balance.toString());
298
+ const token1Bal = new decimal_js_1.Decimal(token1Balance.toString());
299
+ const token0Dec = new decimal_js_1.Decimal(10).pow(Number(token0Decimals));
300
+ const token1Dec = new decimal_js_1.Decimal(10).pow(Number(token1Decimals));
298
301
  // Calculate adjusted balances
299
302
  const token0Adjusted = token0Bal.div(token0Dec);
300
303
  const token1Adjusted = token1Bal.div(token1Dec);
@@ -370,11 +373,11 @@ export class VaultDepositClient {
370
373
  // Handle different protocol types
371
374
  if (params.isAlgebraIntegralPool) {
372
375
  // For Algebra Integral pools
373
- slot0Response = await getGlobalStateAlgebraIntegral(this.publicClient, poolData.data.id, params.isAlgebraDirectionPool);
376
+ slot0Response = await (0, utils_js_1.getGlobalStateAlgebraIntegral)(this.publicClient, poolData.data.id, params.isAlgebraDirectionPool);
374
377
  }
375
378
  else if (params.isPoolSharkPool) {
376
379
  // For PoolShark pools
377
- const poolSharkResponse = await getGlobalStatePoolShark(this.publicClient, poolData.data.id);
380
+ const poolSharkResponse = await (0, utils_js_1.getGlobalStatePoolShark)(this.publicClient, poolData.data.id);
378
381
  if (poolSharkResponse.success && poolSharkResponse.data) {
379
382
  slot0Response = {
380
383
  success: true,
@@ -396,18 +399,18 @@ export class VaultDepositClient {
396
399
  }
397
400
  if (params.isAlgebraPool) {
398
401
  // For Algebra pools
399
- slot0Response = await getGlobalState(this.publicClient, poolData.data.id, params.isAlgebraDirectionPool);
402
+ slot0Response = await (0, utils_js_1.getGlobalState)(this.publicClient, poolData.data.id, params.isAlgebraDirectionPool);
400
403
  }
401
404
  else {
402
405
  // For standard Uniswap V3 pools
403
- slot0Response = await getSlot0(this.publicClient, poolData.data.id);
406
+ slot0Response = await (0, utils_js_1.getSlot0)(this.publicClient, poolData.data.id);
404
407
  }
405
408
  if (!slot0Response.success || !slot0Response.data) {
406
409
  throw new Error('Failed to read pool state');
407
410
  }
408
411
  const slot0 = slot0Response.data;
409
- const token0 = new Token(params.chain.id, poolData.data.token0.id, Number(poolData.data.token0.decimals), poolData.data.token0.symbol, poolData.data.token0.name);
410
- const token1 = new Token(params.chain.id, poolData.data.token1.id, Number(poolData.data.token1.decimals), poolData.data.token1.symbol, poolData.data.token1.name);
412
+ const token0 = new sdk_core_1.Token(params.chain.id, poolData.data.token0.id, Number(poolData.data.token0.decimals), poolData.data.token0.symbol, poolData.data.token0.name);
413
+ const token1 = new sdk_core_1.Token(params.chain.id, poolData.data.token1.id, Number(poolData.data.token1.decimals), poolData.data.token1.symbol, poolData.data.token1.name);
411
414
  // Get liquidity
412
415
  const liquidity = await this.getPoolLiquidity(poolData.data.id);
413
416
  if (!liquidity.success || !liquidity.data) {
@@ -430,7 +433,7 @@ export class VaultDepositClient {
430
433
  throw new Error('Failed to get pool price');
431
434
  }
432
435
  return {
433
- data: new PoolV3(token0, token1, poolData.data.feeTier, price.toString(), liquidity.data.toString(), slot0.tick),
436
+ data: new v3_sdk_1.Pool(token0, token1, poolData.data.feeTier, price.toString(), liquidity.data.toString(), slot0.tick),
434
437
  status: 200,
435
438
  success: true,
436
439
  };
@@ -453,7 +456,7 @@ export class VaultDepositClient {
453
456
  try {
454
457
  const liquidity = (await this.publicClient.readContract({
455
458
  address: poolAddress,
456
- abi: UniswapV3PoolABI,
459
+ abi: UniswapPool_js_1.UniswapV3PoolABI,
457
460
  functionName: 'liquidity',
458
461
  }));
459
462
  return {
@@ -490,9 +493,9 @@ export class VaultDepositClient {
490
493
  ? token1Decimals - token0Decimals
491
494
  : token0Decimals - token1Decimals;
492
495
  // Convert all values to Decimal for precise calculation
493
- const amountDecimal = new Decimal(amount.toString());
494
- const ratioDecimal = new Decimal(ratio);
495
- const adjustmentDecimal = new Decimal(10).pow(Number(decimalDiff));
496
+ const amountDecimal = new decimal_js_1.Decimal(amount.toString());
497
+ const ratioDecimal = new decimal_js_1.Decimal(ratio);
498
+ const adjustmentDecimal = new decimal_js_1.Decimal(10).pow(Number(decimalDiff));
496
499
  // Perform calculation using Decimal.js
497
500
  const result = amountDecimal.times(ratioDecimal).times(adjustmentDecimal);
498
501
  // Convert result back to bigint, rounding down to nearest integer
@@ -522,7 +525,7 @@ export class VaultDepositClient {
522
525
  // Try to get vault details, first attempt with regular vault
523
526
  let vaultDetails;
524
527
  const chainId = await this.publicClient.getChainId();
525
- const steerPeripheryAddress = getContractAddressByChainIdAndContractName(chainId, 'SteerPeriphery');
528
+ const steerPeripheryAddress = (0, network_js_1.getContractAddressByChainIdAndContractName)(chainId, 'SteerPeriphery');
526
529
  if (!steerPeripheryAddress)
527
530
  throw new Error('SteerPeriphery address not found');
528
531
  try {
@@ -550,7 +553,7 @@ export class VaultDepositClient {
550
553
  // Get tick spacing
551
554
  const tickSpacing = (await this.publicClient.readContract({
552
555
  address: pool.data,
553
- abi: UniswapV3PoolABI,
556
+ abi: UniswapPool_js_1.UniswapV3PoolABI,
554
557
  functionName: 'tickSpacing',
555
558
  }));
556
559
  const poolData = {
@@ -587,4 +590,5 @@ export class VaultDepositClient {
587
590
  }
588
591
  }
589
592
  }
593
+ exports.VaultDepositClient = VaultDepositClient;
590
594
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/base/vault/deposit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,0CAA0C,EAAE,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE3I,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE/G,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE,MAAM,SAAS,GAAG,IAAI,CAAC,2CAA2C,CAAC;AACnE,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC;AAE1C,MAAM,OAAO,kBAAkB;IAC7B,YACqB,YAA0B,EAC1B,YAA0B;Q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imal.js';\nimport { Address, Hash, PublicClient, WalletClient } from 'viem';\nimport { UniswapV3PoolABI } from '../../../const/abis/UniswapPool.js';\nimport { abis } from '../../../const/deployments/abis.js';\nimport { getContractAddressByChainIdAndContractName } from '../../../const/network.js';\nimport { isAlgebraDirectionProtocol, isAlgebraIntegralProtocol, isAlgebraProtocol, isPoolSharkProtocol } from '../../../const/protocol.js';\nimport { AlgebraVaultDetails, PoolData, SteerResponse, VaultDetails } from '../../../types.js';\nimport { getGlobalState, getGlobalStateAlgebraIntegral, getGlobalStatePoolShark, getSlot0 } from '../utils.js';\nimport { DepositRatioResponse, PoolInstanceParams, VaultDepositParams } from './types.js';\nimport { getProtocolTypeByBeacon } from \"../../../const/index.js\";\n\nconst VAULT_ABI = abis.QuickSwapUniv3MultiPositionLiquidityManager;\nconst PERIPHERY_ABI = abis.SteerPeriphery;\n\nexport class VaultDepositClient {\n constructor(\n protected readonly publicClient: PublicClient,\n protected readonly walletClient: WalletClient\n ) {}\n\n /**\n * Deposits tokens into a vault\n * @param params The deposit parameters\n */\n public async deposit(params: VaultDepositParams): Promise<SteerResponse<Hash>> {\n try {\n const account = await this.walletClient.getAddresses();\n if (!account[0]) throw new Error('No account found');\n\n // Calculate min amounts based on slippage\n const amount0Min =\n (params.amount0Desired * BigInt(Math.floor((1 - params.slippage) * 1000))) / 1000n;\n const amount1Min =\n (params.amount1Desired * BigInt(Math.floor((1 - params.slippage) * 1000))) / 1000n;\n\n let hash: Hash;\n\n // If using Steer Periphery\n if (params.isSteerPeriphery) {\n if (!params.chainId) {\n throw new Error('chainId is required when using Steer Periphery');\n }\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n params.chainId,\n 'SteerPeriphery'\n );\n\n if (!steerPeripheryAddress) {\n throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);\n }\n\n const { request } = await this.publicClient.simulateContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'deposit',\n args: [\n params.vaultAddress,\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ],\n account: account[0],\n });\n hash = await this.walletClient.writeContract(request);\n } else {\n // Regular vault deposit\n const { request } = await this.publicClient.simulateContract({\n address: params.vaultAddress,\n abi: VAULT_ABI,\n functionName: 'deposit',\n args: [\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ],\n account: account[0],\n });\n hash = await this.walletClient.writeContract(request);\n }\n\n return {\n data: hash,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Prepares the transaction data for depositing tokens into a vault without executing it\n * @param params The deposit parameters\n */\n public async prepareDepositTx(params: VaultDepositParams): Promise<\n SteerResponse<{\n address: Address;\n abi: {\n type: string;\n inputs: {\n name: string;\n internalType: string;\n type: string;\n }[];\n name: string;\n outputs: {\n internalType: string;\n name: string;\n type: string;\n }[];\n stateMutability: string;\n }[];\n functionName: string;\n args: readonly [Address, bigint, bigint, bigint, bigint, Address] | readonly [bigint, bigint, bigint, bigint, Address];\n }>\n > {\n try {\n const account = await this.walletClient.getAddresses();\n if (!params.to) {\n if (!account[0]) throw new Error('No account found');\n }\n\n const amount0Min = 0n;\n const amount1Min = 0n;\n\n // If using Steer Periphery\n if (params.isSteerPeriphery) {\n if (!params.chainId) {\n throw new Error('chainId is required when using Steer Periphery');\n }\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n params.chainId,\n 'SteerPeriphery'\n );\n\n if (!steerPeripheryAddress) {\n throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);\n }\n\n // Steer Periphery ABI and parameters\n return {\n data: {\n address: steerPeripheryAddress as Address,\n abi: [\n {\n type: 'function',\n inputs: [\n { name: 'vaultAddress', internalType: 'address', type: 'address' },\n { name: 'amount0Desired', internalType: 'uint256', type: 'uint256' },\n { name: 'amount1Desired', internalType: 'uint256', type: 'uint256' },\n { name: 'amount0Min', internalType: 'uint256', type: 'uint256' },\n { name: 'amount1Min', internalType: 'uint256', type: 'uint256' },\n { name: 'to', internalType: 'address', type: 'address' },\n ],\n name: 'deposit',\n outputs: [],\n stateMutability: 'nonpayable',\n },\n ],\n functionName: 'deposit',\n args: [\n params.vaultAddress,\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ] as const,\n },\n status: 200,\n success: true,\n };\n }\n\n // Regular vault deposit\n return {\n data: {\n address: params.vaultAddress,\n abi: [\n {\n inputs: [\n {\n internalType: 'uint256',\n name: 'amount0Desired',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Desired',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount0Min',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Min',\n type: 'uint256',\n },\n {\n internalType: 'address',\n name: 'to',\n type: 'address',\n },\n ],\n name: 'deposit',\n outputs: [\n {\n internalType: 'uint256',\n name: 'shares',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount0Used',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Used',\n type: 'uint256',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n ],\n functionName: 'deposit',\n args: [\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ] as const,\n },\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the deposit ratio for a vault\n * @param vaultAddress The vault address\n */\n public async getDepositRatio(\n vaultAddress: Address,\n zeroForOne: boolean\n ): Promise<SteerResponse<DepositRatioResponse>> {\n try {\n // Try to get vault details, first attempt with regular vault\n let vaultDetails: VaultDetails | AlgebraVaultDetails;\n let isAlgebraVault = false;\n\n const chainId = await this.publicClient.getChainId();\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n chainId,\n 'SteerPeriphery'\n );\n if (!steerPeripheryAddress) throw new Error('SteerPeriphery address not found');\n try {\n // First try regular vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'vaultDetailsByAddress',\n args: [vaultAddress],\n })) as VaultDetails;\n } catch (error) {\n // If regular vault fails, try Algebra vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'algebraVaultDetailsByAddress',\n args: [vaultAddress],\n })) as AlgebraVaultDetails;\n isAlgebraVault = true;\n }\n\n const token0Balance = vaultDetails.token0Balance;\n const token1Balance = vaultDetails.token1Balance;\n const token0Decimals = vaultDetails.token0Decimals;\n const token1Decimals = vaultDetails.token1Decimals;\n\n let ratio: string;\n\n // Case 1: No liquidity in the vault\n if (token0Balance === 0n && token1Balance === 0n) {\n // Get pool instance to calculate price\n const chainId = await this.publicClient.getChainId();\n\n // Get the pool address\n const pool = await this.getPool(vaultAddress);\n if (!pool.data) throw new Error('Failed to retrieve pool for ratio calculation');\n\n // Determine the protocol\n const protocol = getProtocolTypeByBeacon(vaultDetails.vaultType);\n if (!protocol) throw new Error('Unsupported protocol type');\n console.log('Protocol detected:', protocol);\n\n // Get pool instance with the correct protocol type\n const poolInstanceResponse = await this.getPoolInstance({\n vaultAddress,\n chain: { id: chainId },\n isAlgebraPool: isAlgebraProtocol(protocol),\n isPoolSharkPool: isPoolSharkProtocol(protocol),\n isAlgebraIntegralPool: isAlgebraIntegralProtocol(protocol),\n isAlgebraDirectionPool: isAlgebraDirectionProtocol(protocol),\n });\n\n if (!poolInstanceResponse.success || !poolInstanceResponse.data) {\n throw new Error('Failed to get pool instance for price calculation');\n }\n\n const poolInstance = poolInstanceResponse.data;\n // Get price based on zeroForOne\n const price = zeroForOne\n ? poolInstance.priceOf(poolInstance.token0)\n : poolInstance.priceOf(poolInstance.token0).invert();\n\n // Convert price to string using Decimal for maximum precision\n ratio = price.toSignificant(undefined, undefined, Rounding.ROUND_DOWN);\n }\n // Case 2: Vault has liquidity\n else {\n // Convert bigint values to Decimal instances for precise calculation\n // Convert bigints to strings first to avoid type errors\n const token0Bal = new Decimal(token0Balance.toString());\n const token1Bal = new Decimal(token1Balance.toString());\n const token0Dec = new Decimal(10).pow(Number(token0Decimals));\n const token1Dec = new Decimal(10).pow(Number(token1Decimals));\n\n // Calculate adjusted balances\n const token0Adjusted = token0Bal.div(token0Dec);\n const token1Adjusted = token1Bal.div(token1Dec);\n\n // Calculate ratio based on token balances\n // If zeroForOne is true: ratio = token1/token0\n // If zeroForOne is false: ratio = token0/token1\n ratio = zeroForOne\n ? token1Adjusted.div(token0Adjusted).toString() // token1/token0 ratio\n : token0Adjusted.div(token1Adjusted).toString(); // token0/token1 ratio\n }\n\n return {\n data: {\n ratio,\n token0Balance,\n token1Balance,\n token0Decimals,\n token1Decimals,\n vaultDetails,\n isAlgebraVault,\n },\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the pool address for a vault\n * @param vaultAddress The vault address\n */\n private async getPool(vaultAddress: Address): Promise<SteerResponse<Address>> {\n try {\n const pool = (await this.publicClient.readContract({\n address: vaultAddress,\n abi: VAULT_ABI,\n functionName: 'pool',\n })) as Address;\n\n return {\n data: pool,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets a pool instance for a vault\n * @param params The pool instance parameters\n */\n public async getPoolInstance(params: PoolInstanceParams): Promise<SteerResponse<PoolV3>> {\n console.log('Fetching pool instance...');\n\n try {\n const poolData = await this.preparePoolData(params.vaultAddress);\n console.log('Pool data fetched:', poolData);\n\n if (!poolData.success || !poolData.data) {\n throw new Error('Failed to fetch pool data');\n }\n\n let slot0Response;\n\n // Handle different protocol types\n if (params.isAlgebraIntegralPool) {\n // For Algebra Integral pools\n slot0Response = await getGlobalStateAlgebraIntegral(\n this.publicClient,\n poolData.data.id,\n params.isAlgebraDirectionPool\n );\n } else if (params.isPoolSharkPool) {\n // For PoolShark pools\n const poolSharkResponse = await getGlobalStatePoolShark(\n this.publicClient,\n poolData.data.id\n );\n if (poolSharkResponse.success && poolSharkResponse.data) {\n slot0Response = {\n success: true,\n status: 200,\n data: {\n sqrtPriceX96: poolSharkResponse.data.pool.price,\n tick: poolSharkResponse.data.pool.tickAtPrice,\n observationIndex: 0,\n observationCardinality: 0,\n observationCardinalityNext: 0,\n feeProtocol: 0,\n unlocked: poolSharkResponse.data.unlocked === 1,\n },\n };\n } else {\n slot0Response = poolSharkResponse;\n }\n }\n if (params.isAlgebraPool) {\n // For Algebra pools\n slot0Response = await getGlobalState(\n this.publicClient,\n poolData.data.id,\n params.isAlgebraDirectionPool\n );\n } else {\n // For standard Uniswap V3 pools\n slot0Response = await getSlot0(this.publicClient, poolData.data.id);\n }\n\n if (!slot0Response.success || !slot0Response.data) {\n throw new Error('Failed to read pool state');\n }\n\n const slot0 = slot0Response.data;\n\n const token0 = new Token(\n params.chain.id,\n poolData.data.token0.id,\n Number(poolData.data.token0.decimals),\n poolData.data.token0.symbol,\n poolData.data.token0.name\n );\n\n const token1 = new Token(\n params.chain.id,\n poolData.data.token1.id,\n Number(poolData.data.token1.decimals),\n poolData.data.token1.symbol,\n poolData.data.token1.name\n );\n\n // Get liquidity\n const liquidity = await this.getPoolLiquidity(poolData.data.id);\n if (!liquidity.success || !liquidity.data) {\n throw new Error('Failed to fetch pool liquidity');\n }\n\n let price: bigint | undefined;\n\n if (params.isAlgebraPool && !params.isAlgebraIntegralPool) {\n price = slot0Response?.data?.price;\n } else if (params.isAlgebraIntegralPool) {\n price = slot0Response?.data?.price;\n } else if (params.isPoolSharkPool) {\n price = (slot0Response?.data?.tick as unknown as { price: bigint })?.price;\n } else {\n price = slot0Response?.data?.sqrtPriceX96;\n }\n\n if (!price) {\n throw new Error('Failed to get pool price');\n }\n\n return {\n data: new PoolV3(\n token0,\n token1,\n poolData.data.feeTier,\n price.toString(),\n liquidity.data.toString(),\n slot0.tick\n ),\n status: 200,\n success: true,\n };\n } catch (error) {\n console.error('Error creating pool instance:', error);\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the pool liquidity\n * @param poolAddress The pool address\n */\n private async getPoolLiquidity(poolAddress: Address): Promise<SteerResponse<bigint>> {\n try {\n const liquidity = (await this.publicClient.readContract({\n address: poolAddress,\n abi: UniswapV3PoolABI,\n functionName: 'liquidity',\n })) as bigint;\n\n return {\n data: liquidity,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the corresponding token amount based on the provided token amount and ratio\n * @param vaultAddress The vault address\n * @param amount The amount of token to calculate the corresponding amount for\n * @param zeroForOne If true, calculates token1 amount for given token0, if false calculates token0 amount for given token1\n */\n public async getCorrespondingTokenAmount(\n vaultAddress: Address,\n amount: bigint,\n zeroForOne: boolean\n ): Promise<SteerResponse<bigint>> {\n try {\n // Get the deposit ratio for the vault\n const ratioResponse = await this.getDepositRatio(vaultAddress, zeroForOne);\n if (!ratioResponse.success || !ratioResponse.data) {\n throw new Error('Failed to get deposit ratio');\n }\n\n const { ratio, token0Decimals, token1Decimals } = ratioResponse.data;\n\n // Calculate the decimal adjustment based on token decimals\n const decimalDiff = zeroForOne\n ? token1Decimals - token0Decimals\n : token0Decimals - token1Decimals;\n\n // Convert all values to Decimal for precise calculation\n const amountDecimal = new Decimal(amount.toString());\n const ratioDecimal = new Decimal(ratio);\n const adjustmentDecimal = new Decimal(10).pow(Number(decimalDiff));\n\n // Perform calculation using Decimal.js\n const result = amountDecimal.times(ratioDecimal).times(adjustmentDecimal);\n\n // Convert result back to bigint, rounding down to nearest integer\n // Use toFixed(0) to avoid scientific notation which BigInt cannot parse\n const correspondingAmount = BigInt(result.floor().toFixed(0));\n\n return {\n data: correspondingAmount,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Prepares pool data from vault details\n * @param vaultAddress The vault address\n */\n private async preparePoolData(vaultAddress: Address): Promise<SteerResponse<PoolData>> {\n try {\n // Try to get vault details, first attempt with regular vault\n let vaultDetails: VaultDetails | AlgebraVaultDetails;\n\n const chainId = await this.publicClient.getChainId();\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n chainId,\n 'SteerPeriphery'\n );\n if (!steerPeripheryAddress) throw new Error('SteerPeriphery address not found');\n\n try {\n // First try regular vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'vaultDetailsByAddress',\n args: [vaultAddress],\n })) as VaultDetails;\n } catch (error) {\n // If regular vault fails, try Algebra vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'algebraVaultDetailsByAddress',\n args: [vaultAddress],\n })) as AlgebraVaultDetails;\n }\n\n // Get the pool contract to fetch tick spacing\n const pool = await this.getPool(vaultAddress);\n if (!pool.data) throw new Error('Failed to retrieve pool');\n\n // Get tick spacing\n const tickSpacing = (await this.publicClient.readContract({\n address: pool.data,\n abi: UniswapV3PoolABI,\n functionName: 'tickSpacing',\n })) as number;\n\n const poolData: PoolData = {\n id: pool.data,\n token0: {\n id: vaultDetails.token0,\n decimals: vaultDetails.token0Decimals.toString(),\n symbol: vaultDetails.token0Symbol,\n name: vaultDetails.token0Symbol,\n },\n token1: {\n id: vaultDetails.token1,\n decimals: vaultDetails.token1Decimals.toString(),\n symbol: vaultDetails.token1Symbol,\n name: vaultDetails.token1Symbol,\n },\n chainId: await this.publicClient.getChainId(),\n feeTier: 3000, // Fixed fee tier as specified\n tickSpacing,\n };\n\n return {\n data: poolData,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/base/vault/deposit/index.ts"],"names":[],"mappings":";;;AAAA,gDAAoD;AACpD,4CAAiD;AACjD,2CAAqC;AAErC,uEAAsE;AACtE,gEAA0D;AAC1D,0DAAuF;AACvF,4DAA2I;AAE3I,0CAA+G;AAE/G,sDAAkE;AAElE,MAAM,SAAS,GAAG,cAAI,CAAC,2CAA2C,CAAC;AACnE,MAAM,aAAa,GAAG,cAAI,CAAC,cAAc,CAAC;AAE1C,MAAa,kBAAkB;IAC7B,YACqB,YAA0B,EAC1B,YAA0B;QAD1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ;;;OAGG;IACI,KAAK,CAAC,OAAO,CAAC,MAA0B;QAC7C,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;YACvD,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAErD,0CAA0C;YAC1C,MAAM,UAAU,GACd,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;YACrF,MAAM,UAAU,GACd,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,G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AAQ,EAAE,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE;oBAChD,MAAM,EAAE,YAAY,CAAC,YAAY;oBACjC,IAAI,EAAE,YAAY,CAAC,YAAY;iBAChC;gBACD,OAAO,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE;gBAC7C,OAAO,EAAE,IAAI,EAAE,8BAA8B;gBAC7C,WAAW;aACZ,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,IAAI,EAAE,IAAI;gBACV,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB;aACzE,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAhrBD,gDAgrBC","sourcesContent":["import { Rounding, Token } from '@uniswap/sdk-core';\nimport { Pool as PoolV3 } from '@uniswap/v3-sdk';\nimport { Decimal } from 'decimal.js';\nimport { Address, Hash, PublicClient, WalletClient } from 'viem';\nimport { UniswapV3PoolABI } from '../../../const/abis/UniswapPool.js';\nimport { abis } from '../../../const/deployments/abis.js';\nimport { getContractAddressByChainIdAndContractName } from '../../../const/network.js';\nimport { isAlgebraDirectionProtocol, isAlgebraIntegralProtocol, isAlgebraProtocol, isPoolSharkProtocol } from '../../../const/protocol.js';\nimport { AlgebraVaultDetails, PoolData, SteerResponse, VaultDetails } from '../../../types.js';\nimport { getGlobalState, getGlobalStateAlgebraIntegral, getGlobalStatePoolShark, getSlot0 } from '../utils.js';\nimport { DepositRatioResponse, PoolInstanceParams, VaultDepositParams } from './types.js';\nimport { getProtocolTypeByBeacon } from \"../../../const/index.js\";\n\nconst VAULT_ABI = abis.QuickSwapUniv3MultiPositionLiquidityManager;\nconst PERIPHERY_ABI = abis.SteerPeriphery;\n\nexport class VaultDepositClient {\n constructor(\n protected readonly publicClient: PublicClient,\n protected readonly walletClient: WalletClient\n ) {}\n\n /**\n * Deposits tokens into a vault\n * @param params The deposit parameters\n */\n public async deposit(params: VaultDepositParams): Promise<SteerResponse<Hash>> {\n try {\n const account = await this.walletClient.getAddresses();\n if (!account[0]) throw new Error('No account found');\n\n // Calculate min amounts based on slippage\n const amount0Min =\n (params.amount0Desired * BigInt(Math.floor((1 - params.slippage) * 1000))) / 1000n;\n const amount1Min =\n (params.amount1Desired * BigInt(Math.floor((1 - params.slippage) * 1000))) / 1000n;\n\n let hash: Hash;\n\n // If using Steer Periphery\n if (params.isSteerPeriphery) {\n if (!params.chainId) {\n throw new Error('chainId is required when using Steer Periphery');\n }\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n params.chainId,\n 'SteerPeriphery'\n );\n\n if (!steerPeripheryAddress) {\n throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);\n }\n\n const { request } = await this.publicClient.simulateContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'deposit',\n args: [\n params.vaultAddress,\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ],\n account: account[0],\n });\n hash = await this.walletClient.writeContract(request);\n } else {\n // Regular vault deposit\n const { request } = await this.publicClient.simulateContract({\n address: params.vaultAddress,\n abi: VAULT_ABI,\n functionName: 'deposit',\n args: [\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ],\n account: account[0],\n });\n hash = await this.walletClient.writeContract(request);\n }\n\n return {\n data: hash,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Prepares the transaction data for depositing tokens into a vault without executing it\n * @param params The deposit parameters\n */\n public async prepareDepositTx(params: VaultDepositParams): Promise<\n SteerResponse<{\n address: Address;\n abi: {\n type: string;\n inputs: {\n name: string;\n internalType: string;\n type: string;\n }[];\n name: string;\n outputs: {\n internalType: string;\n name: string;\n type: string;\n }[];\n stateMutability: string;\n }[];\n functionName: string;\n args: readonly [Address, bigint, bigint, bigint, bigint, Address] | readonly [bigint, bigint, bigint, bigint, Address];\n }>\n > {\n try {\n const account = await this.walletClient.getAddresses();\n if (!params.to) {\n if (!account[0]) throw new Error('No account found');\n }\n\n const amount0Min = 0n;\n const amount1Min = 0n;\n\n // If using Steer Periphery\n if (params.isSteerPeriphery) {\n if (!params.chainId) {\n throw new Error('chainId is required when using Steer Periphery');\n }\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n params.chainId,\n 'SteerPeriphery'\n );\n\n if (!steerPeripheryAddress) {\n throw new Error(`SteerPeriphery address not found for chainId: ${params.chainId}`);\n }\n\n // Steer Periphery ABI and parameters\n return {\n data: {\n address: steerPeripheryAddress as Address,\n abi: [\n {\n type: 'function',\n inputs: [\n { name: 'vaultAddress', internalType: 'address', type: 'address' },\n { name: 'amount0Desired', internalType: 'uint256', type: 'uint256' },\n { name: 'amount1Desired', internalType: 'uint256', type: 'uint256' },\n { name: 'amount0Min', internalType: 'uint256', type: 'uint256' },\n { name: 'amount1Min', internalType: 'uint256', type: 'uint256' },\n { name: 'to', internalType: 'address', type: 'address' },\n ],\n name: 'deposit',\n outputs: [],\n stateMutability: 'nonpayable',\n },\n ],\n functionName: 'deposit',\n args: [\n params.vaultAddress,\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ] as const,\n },\n status: 200,\n success: true,\n };\n }\n\n // Regular vault deposit\n return {\n data: {\n address: params.vaultAddress,\n abi: [\n {\n inputs: [\n {\n internalType: 'uint256',\n name: 'amount0Desired',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Desired',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount0Min',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Min',\n type: 'uint256',\n },\n {\n internalType: 'address',\n name: 'to',\n type: 'address',\n },\n ],\n name: 'deposit',\n outputs: [\n {\n internalType: 'uint256',\n name: 'shares',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount0Used',\n type: 'uint256',\n },\n {\n internalType: 'uint256',\n name: 'amount1Used',\n type: 'uint256',\n },\n ],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n ],\n functionName: 'deposit',\n args: [\n params.amount0Desired,\n params.amount1Desired,\n amount0Min,\n amount1Min,\n params.to ?? account[0],\n ] as const,\n },\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the deposit ratio for a vault\n * @param vaultAddress The vault address\n */\n public async getDepositRatio(\n vaultAddress: Address,\n zeroForOne: boolean\n ): Promise<SteerResponse<DepositRatioResponse>> {\n try {\n // Try to get vault details, first attempt with regular vault\n let vaultDetails: VaultDetails | AlgebraVaultDetails;\n let isAlgebraVault = false;\n\n const chainId = await this.publicClient.getChainId();\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n chainId,\n 'SteerPeriphery'\n );\n if (!steerPeripheryAddress) throw new Error('SteerPeriphery address not found');\n try {\n // First try regular vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'vaultDetailsByAddress',\n args: [vaultAddress],\n })) as VaultDetails;\n } catch (error) {\n // If regular vault fails, try Algebra vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'algebraVaultDetailsByAddress',\n args: [vaultAddress],\n })) as AlgebraVaultDetails;\n isAlgebraVault = true;\n }\n\n const token0Balance = vaultDetails.token0Balance;\n const token1Balance = vaultDetails.token1Balance;\n const token0Decimals = vaultDetails.token0Decimals;\n const token1Decimals = vaultDetails.token1Decimals;\n\n let ratio: string;\n\n // Case 1: No liquidity in the vault\n if (token0Balance === 0n && token1Balance === 0n) {\n // Get pool instance to calculate price\n const chainId = await this.publicClient.getChainId();\n\n // Get the pool address\n const pool = await this.getPool(vaultAddress);\n if (!pool.data) throw new Error('Failed to retrieve pool for ratio calculation');\n\n // Determine the protocol\n const protocol = getProtocolTypeByBeacon(vaultDetails.vaultType);\n if (!protocol) throw new Error('Unsupported protocol type');\n console.log('Protocol detected:', protocol);\n\n // Get pool instance with the correct protocol type\n const poolInstanceResponse = await this.getPoolInstance({\n vaultAddress,\n chain: { id: chainId },\n isAlgebraPool: isAlgebraProtocol(protocol),\n isPoolSharkPool: isPoolSharkProtocol(protocol),\n isAlgebraIntegralPool: isAlgebraIntegralProtocol(protocol),\n isAlgebraDirectionPool: isAlgebraDirectionProtocol(protocol),\n });\n\n if (!poolInstanceResponse.success || !poolInstanceResponse.data) {\n throw new Error('Failed to get pool instance for price calculation');\n }\n\n const poolInstance = poolInstanceResponse.data;\n // Get price based on zeroForOne\n const price = zeroForOne\n ? poolInstance.priceOf(poolInstance.token0)\n : poolInstance.priceOf(poolInstance.token0).invert();\n\n // Convert price to string using Decimal for maximum precision\n ratio = price.toSignificant(undefined, undefined, Rounding.ROUND_DOWN);\n }\n // Case 2: Vault has liquidity\n else {\n // Convert bigint values to Decimal instances for precise calculation\n // Convert bigints to strings first to avoid type errors\n const token0Bal = new Decimal(token0Balance.toString());\n const token1Bal = new Decimal(token1Balance.toString());\n const token0Dec = new Decimal(10).pow(Number(token0Decimals));\n const token1Dec = new Decimal(10).pow(Number(token1Decimals));\n\n // Calculate adjusted balances\n const token0Adjusted = token0Bal.div(token0Dec);\n const token1Adjusted = token1Bal.div(token1Dec);\n\n // Calculate ratio based on token balances\n // If zeroForOne is true: ratio = token1/token0\n // If zeroForOne is false: ratio = token0/token1\n ratio = zeroForOne\n ? token1Adjusted.div(token0Adjusted).toString() // token1/token0 ratio\n : token0Adjusted.div(token1Adjusted).toString(); // token0/token1 ratio\n }\n\n return {\n data: {\n ratio,\n token0Balance,\n token1Balance,\n token0Decimals,\n token1Decimals,\n vaultDetails,\n isAlgebraVault,\n },\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the pool address for a vault\n * @param vaultAddress The vault address\n */\n private async getPool(vaultAddress: Address): Promise<SteerResponse<Address>> {\n try {\n const pool = (await this.publicClient.readContract({\n address: vaultAddress,\n abi: VAULT_ABI,\n functionName: 'pool',\n })) as Address;\n\n return {\n data: pool,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets a pool instance for a vault\n * @param params The pool instance parameters\n */\n public async getPoolInstance(params: PoolInstanceParams): Promise<SteerResponse<PoolV3>> {\n console.log('Fetching pool instance...');\n\n try {\n const poolData = await this.preparePoolData(params.vaultAddress);\n console.log('Pool data fetched:', poolData);\n\n if (!poolData.success || !poolData.data) {\n throw new Error('Failed to fetch pool data');\n }\n\n let slot0Response;\n\n // Handle different protocol types\n if (params.isAlgebraIntegralPool) {\n // For Algebra Integral pools\n slot0Response = await getGlobalStateAlgebraIntegral(\n this.publicClient,\n poolData.data.id,\n params.isAlgebraDirectionPool\n );\n } else if (params.isPoolSharkPool) {\n // For PoolShark pools\n const poolSharkResponse = await getGlobalStatePoolShark(\n this.publicClient,\n poolData.data.id\n );\n if (poolSharkResponse.success && poolSharkResponse.data) {\n slot0Response = {\n success: true,\n status: 200,\n data: {\n sqrtPriceX96: poolSharkResponse.data.pool.price,\n tick: poolSharkResponse.data.pool.tickAtPrice,\n observationIndex: 0,\n observationCardinality: 0,\n observationCardinalityNext: 0,\n feeProtocol: 0,\n unlocked: poolSharkResponse.data.unlocked === 1,\n },\n };\n } else {\n slot0Response = poolSharkResponse;\n }\n }\n if (params.isAlgebraPool) {\n // For Algebra pools\n slot0Response = await getGlobalState(\n this.publicClient,\n poolData.data.id,\n params.isAlgebraDirectionPool\n );\n } else {\n // For standard Uniswap V3 pools\n slot0Response = await getSlot0(this.publicClient, poolData.data.id);\n }\n\n if (!slot0Response.success || !slot0Response.data) {\n throw new Error('Failed to read pool state');\n }\n\n const slot0 = slot0Response.data;\n\n const token0 = new Token(\n params.chain.id,\n poolData.data.token0.id,\n Number(poolData.data.token0.decimals),\n poolData.data.token0.symbol,\n poolData.data.token0.name\n );\n\n const token1 = new Token(\n params.chain.id,\n poolData.data.token1.id,\n Number(poolData.data.token1.decimals),\n poolData.data.token1.symbol,\n poolData.data.token1.name\n );\n\n // Get liquidity\n const liquidity = await this.getPoolLiquidity(poolData.data.id);\n if (!liquidity.success || !liquidity.data) {\n throw new Error('Failed to fetch pool liquidity');\n }\n\n let price: bigint | undefined;\n\n if (params.isAlgebraPool && !params.isAlgebraIntegralPool) {\n price = slot0Response?.data?.price;\n } else if (params.isAlgebraIntegralPool) {\n price = slot0Response?.data?.price;\n } else if (params.isPoolSharkPool) {\n price = (slot0Response?.data?.tick as unknown as { price: bigint })?.price;\n } else {\n price = slot0Response?.data?.sqrtPriceX96;\n }\n\n if (!price) {\n throw new Error('Failed to get pool price');\n }\n\n return {\n data: new PoolV3(\n token0,\n token1,\n poolData.data.feeTier,\n price.toString(),\n liquidity.data.toString(),\n slot0.tick\n ),\n status: 200,\n success: true,\n };\n } catch (error) {\n console.error('Error creating pool instance:', error);\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the pool liquidity\n * @param poolAddress The pool address\n */\n private async getPoolLiquidity(poolAddress: Address): Promise<SteerResponse<bigint>> {\n try {\n const liquidity = (await this.publicClient.readContract({\n address: poolAddress,\n abi: UniswapV3PoolABI,\n functionName: 'liquidity',\n })) as bigint;\n\n return {\n data: liquidity,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Gets the corresponding token amount based on the provided token amount and ratio\n * @param vaultAddress The vault address\n * @param amount The amount of token to calculate the corresponding amount for\n * @param zeroForOne If true, calculates token1 amount for given token0, if false calculates token0 amount for given token1\n */\n public async getCorrespondingTokenAmount(\n vaultAddress: Address,\n amount: bigint,\n zeroForOne: boolean\n ): Promise<SteerResponse<bigint>> {\n try {\n // Get the deposit ratio for the vault\n const ratioResponse = await this.getDepositRatio(vaultAddress, zeroForOne);\n if (!ratioResponse.success || !ratioResponse.data) {\n throw new Error('Failed to get deposit ratio');\n }\n\n const { ratio, token0Decimals, token1Decimals } = ratioResponse.data;\n\n // Calculate the decimal adjustment based on token decimals\n const decimalDiff = zeroForOne\n ? token1Decimals - token0Decimals\n : token0Decimals - token1Decimals;\n\n // Convert all values to Decimal for precise calculation\n const amountDecimal = new Decimal(amount.toString());\n const ratioDecimal = new Decimal(ratio);\n const adjustmentDecimal = new Decimal(10).pow(Number(decimalDiff));\n\n // Perform calculation using Decimal.js\n const result = amountDecimal.times(ratioDecimal).times(adjustmentDecimal);\n\n // Convert result back to bigint, rounding down to nearest integer\n // Use toFixed(0) to avoid scientific notation which BigInt cannot parse\n const correspondingAmount = BigInt(result.floor().toFixed(0));\n\n return {\n data: correspondingAmount,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n\n /**\n * Prepares pool data from vault details\n * @param vaultAddress The vault address\n */\n private async preparePoolData(vaultAddress: Address): Promise<SteerResponse<PoolData>> {\n try {\n // Try to get vault details, first attempt with regular vault\n let vaultDetails: VaultDetails | AlgebraVaultDetails;\n\n const chainId = await this.publicClient.getChainId();\n\n const steerPeripheryAddress = getContractAddressByChainIdAndContractName(\n chainId,\n 'SteerPeriphery'\n );\n if (!steerPeripheryAddress) throw new Error('SteerPeriphery address not found');\n\n try {\n // First try regular vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'vaultDetailsByAddress',\n args: [vaultAddress],\n })) as VaultDetails;\n } catch (error) {\n // If regular vault fails, try Algebra vault\n vaultDetails = (await this.publicClient.readContract({\n address: steerPeripheryAddress as Address,\n abi: PERIPHERY_ABI,\n functionName: 'algebraVaultDetailsByAddress',\n args: [vaultAddress],\n })) as AlgebraVaultDetails;\n }\n\n // Get the pool contract to fetch tick spacing\n const pool = await this.getPool(vaultAddress);\n if (!pool.data) throw new Error('Failed to retrieve pool');\n\n // Get tick spacing\n const tickSpacing = (await this.publicClient.readContract({\n address: pool.data,\n abi: UniswapV3PoolABI,\n functionName: 'tickSpacing',\n })) as number;\n\n const poolData: PoolData = {\n id: pool.data,\n token0: {\n id: vaultDetails.token0,\n decimals: vaultDetails.token0Decimals.toString(),\n symbol: vaultDetails.token0Symbol,\n name: vaultDetails.token0Symbol,\n },\n token1: {\n id: vaultDetails.token1,\n decimals: vaultDetails.token1Decimals.toString(),\n symbol: vaultDetails.token1Symbol,\n name: vaultDetails.token1Symbol,\n },\n chainId: await this.publicClient.getChainId(),\n feeTier: 3000, // Fixed fee tier as specified\n tickSpacing,\n };\n\n return {\n data: poolData,\n status: 200,\n success: true,\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Unknown error occurred',\n };\n }\n }\n}\n"]}
@@ -1,2 +1,3 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
2
3
  //# sourceMappingURL=types.js.map
@@ -1,23 +1,30 @@
1
- import { Decimal } from 'decimal.js';
2
- import { erc20Abi } from '../../../const/abis/erc20.js';
3
- import { getPoolPrice, getPoolState, getPoolStateWithPrice } from '../utils.js';
4
- import { AMMType } from './types.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bigintToDecimal = bigintToDecimal;
4
+ exports.decimalToBigint = decimalToBigint;
5
+ exports.getQuoteFromSqrtRatioX96 = getQuoteFromSqrtRatioX96;
6
+ exports.calculateLimitPrice = calculateLimitPrice;
7
+ exports.getPoolSlot0 = getPoolSlot0;
8
+ const decimal_js_1 = require("decimal.js");
9
+ const erc20_js_1 = require("../../../const/abis/erc20.js");
10
+ const utils_js_1 = require("../utils.js");
11
+ const types_js_1 = require("./types.js");
5
12
  /**
6
13
  * Configure Decimal.js for high precision calculations
7
14
  */
8
- Decimal.config({
15
+ decimal_js_1.Decimal.config({
9
16
  precision: 50, // High precision for financial calculations
10
- rounding: Decimal.ROUND_DOWN // Conservative rounding for safety
17
+ rounding: decimal_js_1.Decimal.ROUND_DOWN // Conservative rounding for safety
11
18
  });
12
19
  /**
13
20
  * Constants matching the Solidity contract using Decimal.js
14
21
  */
15
- const BASIS_POINTS = new Decimal(10000);
16
- const Q96 = new Decimal(2).pow(96);
22
+ const BASIS_POINTS = new decimal_js_1.Decimal(10000);
23
+ const Q96 = new decimal_js_1.Decimal(2).pow(96);
17
24
  const Q192 = Q96.mul(Q96);
18
- const Q128 = new Decimal(2).pow(128);
19
- const Q64 = new Decimal(2).pow(64);
20
- const UINT128_MAX = new Decimal(2).pow(128).sub(1);
25
+ const Q128 = new decimal_js_1.Decimal(2).pow(128);
26
+ const Q64 = new decimal_js_1.Decimal(2).pow(64);
27
+ const UINT128_MAX = new decimal_js_1.Decimal(2).pow(128).sub(1);
21
28
  /**
22
29
  * High-precision multiplication and division using Decimal.js
23
30
  * Equivalent to Solidity's FullMath.mulDiv
@@ -30,20 +37,20 @@ function mulDiv(a, b, denominator) {
30
37
  */
31
38
  function sqrt(value) {
32
39
  if (value.isZero())
33
- return new Decimal(0);
40
+ return new decimal_js_1.Decimal(0);
34
41
  return value.sqrt();
35
42
  }
36
43
  /**
37
44
  * Convert BigInt to Decimal for calculations
38
45
  */
39
- export function bigintToDecimal(value) {
40
- return new Decimal(value.toString());
46
+ function bigintToDecimal(value) {
47
+ return new decimal_js_1.Decimal(value.toString());
41
48
  }
42
49
  /**
43
50
  * Convert Decimal back to BigInt for return values
44
51
  * Uses toFixed(0) to get full decimal representation without scientific notation
45
52
  */
46
- export function decimalToBigint(value) {
53
+ function decimalToBigint(value) {
47
54
  // Use toFixed(0) to get full integer representation without scientific notation
48
55
  const stringValue = value.floor().toFixed(0);
49
56
  return BigInt(stringValue);
@@ -57,7 +64,7 @@ export function decimalToBigint(value) {
57
64
  * @param quoteToken Address of quote token
58
65
  * @returns The quote amount as Decimal
59
66
  */
60
- export function getQuoteFromSqrtRatioX96(sqrtRatioX96, baseAmount, baseToken, quoteToken) {
67
+ function getQuoteFromSqrtRatioX96(sqrtRatioX96, baseAmount, baseToken, quoteToken) {
61
68
  // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself
62
69
  if (sqrtRatioX96.lte(UINT128_MAX)) {
63
70
  const ratioX192 = sqrtRatioX96.mul(sqrtRatioX96);
@@ -87,10 +94,10 @@ async function applySlippageProtection(sqrtPriceX96, slippageBP, zeroForOne, tok
87
94
  // Get current price: how much token1 per 1 unit of token0
88
95
  const decimals0 = await publicClient.readContract({
89
96
  address: token0,
90
- abi: erc20Abi,
97
+ abi: erc20_js_1.erc20Abi,
91
98
  functionName: 'decimals'
92
99
  });
93
- const baseAmount = new Decimal(10).pow(decimals0);
100
+ const baseAmount = new decimal_js_1.Decimal(10).pow(decimals0);
94
101
  const currentQuote = getQuoteFromSqrtRatioX96(sqrtPriceX96, baseAmount, token0, token1);
95
102
  let adjustedQuote;
96
103
  if (zeroForOne) {
@@ -144,22 +151,22 @@ async function applySlippageProtection(sqrtPriceX96, slippageBP, zeroForOne, tok
144
151
  * }
145
152
  * ```
146
153
  */
147
- export async function calculateLimitPrice(publicClient, params) {
154
+ async function calculateLimitPrice(publicClient, params) {
148
155
  try {
149
156
  // Get current pool state from slot0
150
- const slot0Data = await getPoolState(publicClient, {
157
+ const slot0Data = await (0, utils_js_1.getPoolState)(publicClient, {
151
158
  poolAddress: params.pool,
152
- isAlgebraPool: params.ammType === AMMType.Algebra,
153
- isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,
154
- isAlgebraDirectionPool: params.ammType === AMMType.AlgebraDirectional,
159
+ isAlgebraPool: params.ammType === types_js_1.AMMType.Algebra,
160
+ isAlgebraIntegralPool: params.ammType === types_js_1.AMMType.AlgebraIntegral,
161
+ isAlgebraDirectionPool: params.ammType === types_js_1.AMMType.AlgebraDirectional,
155
162
  isPoolSharkPool: false // PoolShark not defined in AMMType enum
156
163
  });
157
164
  if (!slot0Data.success || !slot0Data.data) {
158
165
  throw new Error(slot0Data.error || 'Failed to get pool state');
159
166
  }
160
- const sqrtPriceX96BigInt = getPoolPrice(slot0Data.data, {
161
- isAlgebraPool: params.ammType === AMMType.Algebra,
162
- isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,
167
+ const sqrtPriceX96BigInt = (0, utils_js_1.getPoolPrice)(slot0Data.data, {
168
+ isAlgebraPool: params.ammType === types_js_1.AMMType.Algebra,
169
+ isAlgebraIntegralPool: params.ammType === types_js_1.AMMType.AlgebraIntegral,
163
170
  isPoolSharkPool: false // PoolShark not defined in AMMType enum
164
171
  });
165
172
  if (!sqrtPriceX96BigInt) {
@@ -167,7 +174,7 @@ export async function calculateLimitPrice(publicClient, params) {
167
174
  }
168
175
  // Convert to Decimal for high-precision calculations
169
176
  const sqrtPriceX96 = bigintToDecimal(sqrtPriceX96BigInt);
170
- const slippageBP = new Decimal(params.slippageBP);
177
+ const slippageBP = new decimal_js_1.Decimal(params.slippageBP);
171
178
  // Apply slippage protection using high-precision arithmetic
172
179
  const limitSqrtPriceX96Decimal = await applySlippageProtection(sqrtPriceX96, slippageBP, params.zeroForOne, params.token0, params.token1, publicClient);
173
180
  return {
@@ -194,13 +201,13 @@ export async function calculateLimitPrice(publicClient, params) {
194
201
  * @param ammType - Type of AMM
195
202
  * @returns Promise resolving to the pool slot0 data
196
203
  */
197
- export async function getPoolSlot0(publicClient, poolAddress, ammType) {
204
+ async function getPoolSlot0(publicClient, poolAddress, ammType) {
198
205
  try {
199
- const poolState = await getPoolStateWithPrice(publicClient, {
206
+ const poolState = await (0, utils_js_1.getPoolStateWithPrice)(publicClient, {
200
207
  poolAddress,
201
- isAlgebraPool: ammType === AMMType.Algebra,
202
- isAlgebraIntegralPool: ammType === AMMType.AlgebraIntegral,
203
- isAlgebraDirectionPool: ammType === AMMType.AlgebraDirectional,
208
+ isAlgebraPool: ammType === types_js_1.AMMType.Algebra,
209
+ isAlgebraIntegralPool: ammType === types_js_1.AMMType.AlgebraIntegral,
210
+ isAlgebraDirectionPool: ammType === types_js_1.AMMType.AlgebraDirectional,
204
211
  isPoolSharkPool: false // PoolShark not defined in AMMType enum
205
212
  });
206
213
  if (!poolState.success || !poolState.data) {
@@ -1 +1 @@
1
- {"version":3,"file":"calculateLimitPrice.js","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/calculateLimitPrice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,SAAS,EAAE,EAAE,EAAE,4CAA4C;IAC3D,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,mCAAmC;CACjE,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;AACxC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACnC,MA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X,aAAa,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO;YAC1C,qBAAqB,EAAE,OAAO,KAAK,OAAO,CAAC,eAAe;YAC1D,sBAAsB,EAAE,OAAO,KAAK,OAAO,CAAC,kBAAkB;YAC9D,eAAe,EAAE,KAAK,CAAC,wCAAwC;SAChE,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,IAAI,0BAA0B,CAAC,CAAC;QACjE,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,KAAkB;YACvC,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B;SAChF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { Decimal } from 'decimal.js';\nimport type { PublicClient } from 'viem';\nimport { erc20Abi } from '../../../const/abis/erc20.js';\nimport { SteerResponse } from '../../../types.js';\nimport { getPoolPrice, getPoolState, getPoolStateWithPrice } from '../utils.js';\nimport type { CalculateLimitPriceParams, PoolSlot0 } from './types.js';\nimport { AMMType } from './types.js';\n\n/**\n * Configure Decimal.js for high precision calculations\n */\nDecimal.config({ \n precision: 50, // High precision for financial calculations\n rounding: Decimal.ROUND_DOWN // Conservative rounding for safety\n});\n\n/**\n * Constants matching the Solidity contract using Decimal.js\n */\nconst BASIS_POINTS = new Decimal(10000);\nconst Q96 = new Decimal(2).pow(96);\nconst Q192 = Q96.mul(Q96);\nconst Q128 = new Decimal(2).pow(128);\nconst Q64 = new Decimal(2).pow(64);\nconst UINT128_MAX = new Decimal(2).pow(128).sub(1);\n\n/**\n * High-precision multiplication and division using Decimal.js\n * Equivalent to Solidity's FullMath.mulDiv\n */\nfunction mulDiv(a: Decimal, b: Decimal, denominator: Decimal): Decimal {\n return a.mul(b).div(denominator);\n}\n\n/**\n * High-precision square root using Decimal.js\n */\nfunction sqrt(value: Decimal): Decimal {\n if (value.isZero()) return new Decimal(0);\n return value.sqrt();\n}\n\n/**\n * Convert BigInt to Decimal for calculations\n */\nexport function bigintToDecimal(value: bigint): Decimal {\n return new Decimal(value.toString());\n}\n\n/**\n * Convert Decimal back to BigInt for return values\n * Uses toFixed(0) to get full decimal representation without scientific notation\n */\nexport function decimalToBigint(value: Decimal): bigint {\n // Use toFixed(0) to get full integer representation without scientific notation\n const stringValue = value.floor().toFixed(0);\n return BigInt(stringValue);\n}\n\n/**\n * Get quote from sqrtRatioX96 using high-precision Decimal arithmetic\n * Equivalent to Solidity's getQuoteFromSqrtRatioX96\n * @param sqrtRatioX96 The sqrt ratio for which to compute the quote\n * @param baseAmount Amount of base token\n * @param baseToken Address of base token\n * @param quoteToken Address of quote token\n * @returns The quote amount as Decimal\n */\nexport function getQuoteFromSqrtRatioX96(\n sqrtRatioX96: Decimal,\n baseAmount: Decimal,\n baseToken: `0x${string}`,\n quoteToken: `0x${string}`\n): Decimal {\n // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself\n if (sqrtRatioX96.lte(UINT128_MAX)) {\n const ratioX192 = sqrtRatioX96.mul(sqrtRatioX96);\n return baseToken < quoteToken\n ? mulDiv(ratioX192, baseAmount, Q192)\n : mulDiv(Q192, baseAmount, ratioX192);\n } else {\n const ratioX128 = mulDiv(sqrtRatioX96, sqrtRatioX96, Q64);\n return baseToken < quoteToken\n ? mulDiv(ratioX128, baseAmount, Q128)\n : mulDiv(Q128, baseAmount, ratioX128);\n }\n}\n\n/**\n * Applies slippage protection to sqrtPriceX96 based on swap direction using high-precision arithmetic\n * Equivalent to Solidity's applySlippageProtection function\n * @param sqrtPriceX96 The current square root price\n * @param slippageBP Slippage protection in basis points (e.g., 300 = 3%)\n * @param zeroForOne True if swapping token0 for token1\n * @param token0 Address of token0\n * @param token1 Address of token1\n * @param publicClient Viem public client for reading token decimals\n * @returns The price limit with slippage protection as Decimal\n */\nasync function applySlippageProtection(\n sqrtPriceX96: Decimal,\n slippageBP: Decimal,\n zeroForOne: boolean,\n token0: `0x${string}`,\n token1: `0x${string}`,\n publicClient: PublicClient\n): Promise<Decimal> {\n // Get current price: how much token1 per 1 unit of token0\n const decimals0 = await publicClient.readContract({\n address: token0,\n abi: erc20Abi,\n functionName: 'decimals'\n }) as number;\n \n const baseAmount = new Decimal(10).pow(decimals0);\n \n const currentQuote = getQuoteFromSqrtRatioX96(\n sqrtPriceX96,\n baseAmount,\n token0,\n token1\n );\n \n let adjustedQuote: Decimal;\n \n if (zeroForOne) {\n // Swapping token0 for token1\n // We want to ensure we don't get less than expected token1\n // So we set a minimum acceptable rate (decrease the quote)\n adjustedQuote = mulDiv(currentQuote, BASIS_POINTS.sub(slippageBP), BASIS_POINTS);\n } else {\n // Swapping token1 for token0 \n // We want to ensure we don't pay more than expected token1\n // So we set a maximum acceptable rate (increase the quote)\n adjustedQuote = mulDiv(currentQuote, BASIS_POINTS.add(slippageBP), BASIS_POINTS);\n }\n \n if (adjustedQuote.isZero()) {\n throw new Error('AdjustedQuoteCalculationFailed');\n }\n \n // Convert adjusted quote back to sqrtPriceX96\n // This is the reverse of getQuoteFromSqrtRatioX96\n let adjustedRatioX192: Decimal;\n if (token0 < token1) {\n // ratioX192 = (adjustedQuote * 2^192) / baseAmount\n adjustedRatioX192 = mulDiv(adjustedQuote, Q192, baseAmount);\n } else {\n // ratioX192 = (baseAmount * 2^192) / adjustedQuote \n adjustedRatioX192 = mulDiv(baseAmount, Q192, adjustedQuote);\n }\n \n return sqrt(adjustedRatioX192);\n}\n\n/**\n * Calculates the sqrt price limit for slippage protection during swaps using high-precision arithmetic\n * \n * @param publicClient - Viem public client for blockchain reads\n * @param params - Parameters for limit price calculation\n * @returns Promise resolving to the calculated sqrt price limit\n * \n * @example\n * ```typescript\n * const result = await calculateLimitPrice(publicClient, {\n * pool: '0x...',\n * slippageBP: 500, // 5% slippage\n * zeroForOne: true,\n * ammType: AMMType.UniswapV3,\n * token0: '0x...',\n * token1: '0x...'\n * });\n * \n * if (result.success) {\n * console.log('Sqrt price limit:', result.data);\n * }\n * ```\n */\nexport async function calculateLimitPrice(\n publicClient: PublicClient,\n params: CalculateLimitPriceParams\n): Promise<SteerResponse<bigint>> {\n try {\n // Get current pool state from slot0\n const slot0Data = await getPoolState(\n publicClient,\n {\n poolAddress: params.pool,\n isAlgebraPool: params.ammType === AMMType.Algebra,\n isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,\n isAlgebraDirectionPool: params.ammType === AMMType.AlgebraDirectional,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n }\n );\n\n if (!slot0Data.success || !slot0Data.data) {\n throw new Error(slot0Data.error || 'Failed to get pool state');\n }\n\n const sqrtPriceX96BigInt = getPoolPrice(slot0Data.data, {\n isAlgebraPool: params.ammType === AMMType.Algebra,\n isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n });\n\n if (!sqrtPriceX96BigInt) {\n throw new Error('Failed to extract pool price');\n }\n \n // Convert to Decimal for high-precision calculations\n const sqrtPriceX96 = bigintToDecimal(sqrtPriceX96BigInt);\n const slippageBP = new Decimal(params.slippageBP);\n\n // Apply slippage protection using high-precision arithmetic\n const limitSqrtPriceX96Decimal = await applySlippageProtection(\n sqrtPriceX96,\n slippageBP,\n params.zeroForOne,\n params.token0,\n params.token1,\n publicClient\n );\n\n return {\n data: decimalToBigint(limitSqrtPriceX96Decimal),\n status: 200,\n success: true\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Failed to calculate limit price'\n };\n }\n}\n\n/**\n * Gets the current pool state from slot0\n * Currently supports UniswapV3 only\n * \n * @param publicClient - Viem public client for blockchain reads\n * @param poolAddress - Address of the pool\n * @param ammType - Type of AMM\n * @returns Promise resolving to the pool slot0 data\n */\nexport async function getPoolSlot0(\n publicClient: PublicClient,\n poolAddress: `0x${string}`,\n ammType: AMMType\n): Promise<SteerResponse<PoolSlot0>> {\n try {\n const poolState = await getPoolStateWithPrice(publicClient, {\n poolAddress,\n isAlgebraPool: ammType === AMMType.Algebra,\n isAlgebraIntegralPool: ammType === AMMType.AlgebraIntegral,\n isAlgebraDirectionPool: ammType === AMMType.AlgebraDirectional,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n });\n\n if (!poolState.success || !poolState.data) {\n throw new Error(poolState.error || 'Failed to get pool state');\n }\n\n return {\n data: poolState.data.state as PoolSlot0,\n status: 200,\n success: true\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Failed to get pool slot0 data'\n };\n }\n} "]}
1
+ {"version":3,"file":"calculateLimitPrice.js","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/calculateLimitPrice.ts"],"names":[],"mappings":";;AA6CA,0CAEC;AAMD,0CAIC;AAWD,4DAkBC;AA4FD,kDA0DC;AAWD,oCA+BC;AAtRD,2CAAqC;AAErC,2DAAwD;AAExD,0CAAgF;AAEhF,yCAAqC;AAErC;;GAEG;AACH,oBAAO,CAAC,MAAM,CAAC;IACb,SAAS,EAAE,EAAE,EAAE,4CAA4C;IAC3D,QAAQ,EAAE,oBAAO,CAAC,UAAU,CAAC,mCAAmC;CACjE,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,YAAY,GAAG,IAAI,oBAAO,CAAC,KAAK,CAAC,CAAC;AACxC,MAAM,GAAG,GAAG,IAAI,oBAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACnC,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAA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YAC1C,qBAAqB,EAAE,OAAO,KAAK,kBAAO,CAAC,eAAe;YAC1D,sBAAsB,EAAE,OAAO,KAAK,kBAAO,CAAC,kBAAkB;YAC9D,eAAe,EAAE,KAAK,CAAC,wCAAwC;SAChE,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,IAAI,0BAA0B,CAAC,CAAC;QACjE,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,KAAkB;YACvC,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B;SAChF,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { Decimal } from 'decimal.js';\nimport type { PublicClient } from 'viem';\nimport { erc20Abi } from '../../../const/abis/erc20.js';\nimport { SteerResponse } from '../../../types.js';\nimport { getPoolPrice, getPoolState, getPoolStateWithPrice } from '../utils.js';\nimport type { CalculateLimitPriceParams, PoolSlot0 } from './types.js';\nimport { AMMType } from './types.js';\n\n/**\n * Configure Decimal.js for high precision calculations\n */\nDecimal.config({ \n precision: 50, // High precision for financial calculations\n rounding: Decimal.ROUND_DOWN // Conservative rounding for safety\n});\n\n/**\n * Constants matching the Solidity contract using Decimal.js\n */\nconst BASIS_POINTS = new Decimal(10000);\nconst Q96 = new Decimal(2).pow(96);\nconst Q192 = Q96.mul(Q96);\nconst Q128 = new Decimal(2).pow(128);\nconst Q64 = new Decimal(2).pow(64);\nconst UINT128_MAX = new Decimal(2).pow(128).sub(1);\n\n/**\n * High-precision multiplication and division using Decimal.js\n * Equivalent to Solidity's FullMath.mulDiv\n */\nfunction mulDiv(a: Decimal, b: Decimal, denominator: Decimal): Decimal {\n return a.mul(b).div(denominator);\n}\n\n/**\n * High-precision square root using Decimal.js\n */\nfunction sqrt(value: Decimal): Decimal {\n if (value.isZero()) return new Decimal(0);\n return value.sqrt();\n}\n\n/**\n * Convert BigInt to Decimal for calculations\n */\nexport function bigintToDecimal(value: bigint): Decimal {\n return new Decimal(value.toString());\n}\n\n/**\n * Convert Decimal back to BigInt for return values\n * Uses toFixed(0) to get full decimal representation without scientific notation\n */\nexport function decimalToBigint(value: Decimal): bigint {\n // Use toFixed(0) to get full integer representation without scientific notation\n const stringValue = value.floor().toFixed(0);\n return BigInt(stringValue);\n}\n\n/**\n * Get quote from sqrtRatioX96 using high-precision Decimal arithmetic\n * Equivalent to Solidity's getQuoteFromSqrtRatioX96\n * @param sqrtRatioX96 The sqrt ratio for which to compute the quote\n * @param baseAmount Amount of base token\n * @param baseToken Address of base token\n * @param quoteToken Address of quote token\n * @returns The quote amount as Decimal\n */\nexport function getQuoteFromSqrtRatioX96(\n sqrtRatioX96: Decimal,\n baseAmount: Decimal,\n baseToken: `0x${string}`,\n quoteToken: `0x${string}`\n): Decimal {\n // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself\n if (sqrtRatioX96.lte(UINT128_MAX)) {\n const ratioX192 = sqrtRatioX96.mul(sqrtRatioX96);\n return baseToken < quoteToken\n ? mulDiv(ratioX192, baseAmount, Q192)\n : mulDiv(Q192, baseAmount, ratioX192);\n } else {\n const ratioX128 = mulDiv(sqrtRatioX96, sqrtRatioX96, Q64);\n return baseToken < quoteToken\n ? mulDiv(ratioX128, baseAmount, Q128)\n : mulDiv(Q128, baseAmount, ratioX128);\n }\n}\n\n/**\n * Applies slippage protection to sqrtPriceX96 based on swap direction using high-precision arithmetic\n * Equivalent to Solidity's applySlippageProtection function\n * @param sqrtPriceX96 The current square root price\n * @param slippageBP Slippage protection in basis points (e.g., 300 = 3%)\n * @param zeroForOne True if swapping token0 for token1\n * @param token0 Address of token0\n * @param token1 Address of token1\n * @param publicClient Viem public client for reading token decimals\n * @returns The price limit with slippage protection as Decimal\n */\nasync function applySlippageProtection(\n sqrtPriceX96: Decimal,\n slippageBP: Decimal,\n zeroForOne: boolean,\n token0: `0x${string}`,\n token1: `0x${string}`,\n publicClient: PublicClient\n): Promise<Decimal> {\n // Get current price: how much token1 per 1 unit of token0\n const decimals0 = await publicClient.readContract({\n address: token0,\n abi: erc20Abi,\n functionName: 'decimals'\n }) as number;\n \n const baseAmount = new Decimal(10).pow(decimals0);\n \n const currentQuote = getQuoteFromSqrtRatioX96(\n sqrtPriceX96,\n baseAmount,\n token0,\n token1\n );\n \n let adjustedQuote: Decimal;\n \n if (zeroForOne) {\n // Swapping token0 for token1\n // We want to ensure we don't get less than expected token1\n // So we set a minimum acceptable rate (decrease the quote)\n adjustedQuote = mulDiv(currentQuote, BASIS_POINTS.sub(slippageBP), BASIS_POINTS);\n } else {\n // Swapping token1 for token0 \n // We want to ensure we don't pay more than expected token1\n // So we set a maximum acceptable rate (increase the quote)\n adjustedQuote = mulDiv(currentQuote, BASIS_POINTS.add(slippageBP), BASIS_POINTS);\n }\n \n if (adjustedQuote.isZero()) {\n throw new Error('AdjustedQuoteCalculationFailed');\n }\n \n // Convert adjusted quote back to sqrtPriceX96\n // This is the reverse of getQuoteFromSqrtRatioX96\n let adjustedRatioX192: Decimal;\n if (token0 < token1) {\n // ratioX192 = (adjustedQuote * 2^192) / baseAmount\n adjustedRatioX192 = mulDiv(adjustedQuote, Q192, baseAmount);\n } else {\n // ratioX192 = (baseAmount * 2^192) / adjustedQuote \n adjustedRatioX192 = mulDiv(baseAmount, Q192, adjustedQuote);\n }\n \n return sqrt(adjustedRatioX192);\n}\n\n/**\n * Calculates the sqrt price limit for slippage protection during swaps using high-precision arithmetic\n * \n * @param publicClient - Viem public client for blockchain reads\n * @param params - Parameters for limit price calculation\n * @returns Promise resolving to the calculated sqrt price limit\n * \n * @example\n * ```typescript\n * const result = await calculateLimitPrice(publicClient, {\n * pool: '0x...',\n * slippageBP: 500, // 5% slippage\n * zeroForOne: true,\n * ammType: AMMType.UniswapV3,\n * token0: '0x...',\n * token1: '0x...'\n * });\n * \n * if (result.success) {\n * console.log('Sqrt price limit:', result.data);\n * }\n * ```\n */\nexport async function calculateLimitPrice(\n publicClient: PublicClient,\n params: CalculateLimitPriceParams\n): Promise<SteerResponse<bigint>> {\n try {\n // Get current pool state from slot0\n const slot0Data = await getPoolState(\n publicClient,\n {\n poolAddress: params.pool,\n isAlgebraPool: params.ammType === AMMType.Algebra,\n isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,\n isAlgebraDirectionPool: params.ammType === AMMType.AlgebraDirectional,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n }\n );\n\n if (!slot0Data.success || !slot0Data.data) {\n throw new Error(slot0Data.error || 'Failed to get pool state');\n }\n\n const sqrtPriceX96BigInt = getPoolPrice(slot0Data.data, {\n isAlgebraPool: params.ammType === AMMType.Algebra,\n isAlgebraIntegralPool: params.ammType === AMMType.AlgebraIntegral,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n });\n\n if (!sqrtPriceX96BigInt) {\n throw new Error('Failed to extract pool price');\n }\n \n // Convert to Decimal for high-precision calculations\n const sqrtPriceX96 = bigintToDecimal(sqrtPriceX96BigInt);\n const slippageBP = new Decimal(params.slippageBP);\n\n // Apply slippage protection using high-precision arithmetic\n const limitSqrtPriceX96Decimal = await applySlippageProtection(\n sqrtPriceX96,\n slippageBP,\n params.zeroForOne,\n params.token0,\n params.token1,\n publicClient\n );\n\n return {\n data: decimalToBigint(limitSqrtPriceX96Decimal),\n status: 200,\n success: true\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Failed to calculate limit price'\n };\n }\n}\n\n/**\n * Gets the current pool state from slot0\n * Currently supports UniswapV3 only\n * \n * @param publicClient - Viem public client for blockchain reads\n * @param poolAddress - Address of the pool\n * @param ammType - Type of AMM\n * @returns Promise resolving to the pool slot0 data\n */\nexport async function getPoolSlot0(\n publicClient: PublicClient,\n poolAddress: `0x${string}`,\n ammType: AMMType\n): Promise<SteerResponse<PoolSlot0>> {\n try {\n const poolState = await getPoolStateWithPrice(publicClient, {\n poolAddress,\n isAlgebraPool: ammType === AMMType.Algebra,\n isAlgebraIntegralPool: ammType === AMMType.AlgebraIntegral,\n isAlgebraDirectionPool: ammType === AMMType.AlgebraDirectional,\n isPoolSharkPool: false // PoolShark not defined in AMMType enum\n });\n\n if (!poolState.success || !poolState.data) {\n throw new Error(poolState.error || 'Failed to get pool state');\n }\n\n return {\n data: poolState.data.state as PoolSlot0,\n status: 200,\n success: true\n };\n } catch (error) {\n return {\n data: null,\n status: 500,\n success: false,\n error: error instanceof Error ? error.message : 'Failed to get pool slot0 data'\n };\n }\n} "]}