@mento-protocol/mento-sdk 3.2.2 → 3.2.3

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 (397) hide show
  1. package/dist/cjs/ChainClient.d.ts +9 -0
  2. package/dist/cjs/ChainClient.js +58 -0
  3. package/dist/cjs/TestChainClient.d.ts +7 -0
  4. package/dist/cjs/TestChainClient.js +41 -0
  5. package/dist/cjs/constants/addresses.d.ts +4 -0
  6. package/dist/cjs/constants/addresses.js +59 -0
  7. package/dist/cjs/constants/currencies.d.ts +5 -0
  8. package/dist/cjs/constants/currencies.js +29 -0
  9. package/dist/cjs/constants/index.d.ts +4 -0
  10. package/dist/{services/borrow → cjs/constants}/index.js +4 -4
  11. package/dist/cjs/constants/tokens.11142220.d.ts +2 -0
  12. package/dist/cjs/constants/tokens.11142220.js +128 -0
  13. package/dist/cjs/constants/tokens.42220.d.ts +2 -0
  14. package/dist/cjs/constants/tokens.42220.js +128 -0
  15. package/dist/cjs/constants/tokens.d.ts +65 -0
  16. package/dist/cjs/constants/tokens.js +170 -0
  17. package/dist/cjs/constants/tradablePairs.11142220.d.ts +2 -0
  18. package/dist/cjs/constants/tradablePairs.11142220.js +7391 -0
  19. package/dist/cjs/constants/tradablePairs.42220.d.ts +2 -0
  20. package/dist/cjs/constants/tradablePairs.42220.js +7391 -0
  21. package/dist/cjs/constants/tradablePairs.d.ts +16 -0
  22. package/dist/cjs/constants/tradablePairs.js +53 -0
  23. package/dist/cjs/enums/chainId.d.ts +4 -0
  24. package/dist/{core/constants → cjs/enums}/chainId.js +1 -4
  25. package/dist/cjs/enums/index.d.ts +3 -0
  26. package/dist/{services/liquidity → cjs/enums}/index.js +3 -2
  27. package/dist/cjs/enums/proposalState.d.ts +10 -0
  28. package/dist/cjs/enums/proposalState.js +14 -0
  29. package/dist/cjs/enums/tradingMode.d.ts +17 -0
  30. package/dist/cjs/enums/tradingMode.js +21 -0
  31. package/dist/cjs/governance.d.ts +62 -0
  32. package/dist/cjs/governance.js +151 -0
  33. package/dist/cjs/index.d.ts +7 -0
  34. package/dist/{core/constants → cjs}/index.js +7 -6
  35. package/dist/cjs/interfaces/IChainClient.d.ts +6 -0
  36. package/dist/{core/types/route.js → cjs/interfaces/IChainClient.js} +0 -1
  37. package/dist/cjs/interfaces/index.d.ts +4 -0
  38. package/dist/{core/errors → cjs/interfaces}/index.js +4 -4
  39. package/dist/cjs/interfaces/tradingLimit.d.ts +7 -0
  40. package/dist/{core/types/token.js → cjs/interfaces/tradingLimit.js} +0 -1
  41. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +10 -0
  42. package/dist/{core/types/borrow.js → cjs/interfaces/tradingLimitsConfig.js} +0 -1
  43. package/dist/cjs/interfaces/tradingLimitsState.d.ts +9 -0
  44. package/dist/{core/types/provider.js → cjs/interfaces/tradingLimitsState.js} +0 -1
  45. package/dist/cjs/limits.d.ts +33 -0
  46. package/dist/cjs/limits.js +130 -0
  47. package/dist/cjs/mento.d.ts +287 -0
  48. package/dist/cjs/mento.js +699 -0
  49. package/dist/{utils → cjs}/routeUtils.d.ts +93 -84
  50. package/dist/{utils → cjs}/routeUtils.js +124 -123
  51. package/dist/cjs/types/contractAddressMap.d.ts +4 -0
  52. package/dist/cjs/types/contractAddressMap.js +2 -0
  53. package/dist/cjs/types/contractAddresses.d.ts +23 -0
  54. package/dist/cjs/types/contractAddresses.js +2 -0
  55. package/dist/cjs/types/index.d.ts +2 -0
  56. package/dist/{services/pools → cjs/types}/index.js +2 -2
  57. package/dist/cjs/utils.d.ts +80 -0
  58. package/dist/cjs/utils.js +177 -0
  59. package/dist/esm/ChainClient.d.ts +9 -0
  60. package/dist/esm/ChainClient.js +54 -0
  61. package/dist/esm/TestChainClient.d.ts +7 -0
  62. package/dist/esm/TestChainClient.js +37 -0
  63. package/dist/esm/constants/addresses.d.ts +4 -0
  64. package/dist/esm/constants/addresses.js +55 -0
  65. package/dist/esm/constants/currencies.d.ts +5 -0
  66. package/dist/esm/constants/currencies.js +26 -0
  67. package/dist/esm/constants/index.d.ts +4 -0
  68. package/dist/esm/constants/index.js +4 -0
  69. package/dist/esm/constants/tokens.11142220.d.ts +2 -0
  70. package/dist/esm/constants/tokens.11142220.js +125 -0
  71. package/dist/esm/constants/tokens.42220.d.ts +2 -0
  72. package/dist/esm/constants/tokens.42220.js +125 -0
  73. package/dist/esm/constants/tokens.d.ts +65 -0
  74. package/dist/esm/constants/tokens.js +142 -0
  75. package/dist/esm/constants/tradablePairs.11142220.d.ts +2 -0
  76. package/dist/esm/constants/tradablePairs.11142220.js +7388 -0
  77. package/dist/esm/constants/tradablePairs.42220.d.ts +2 -0
  78. package/dist/esm/constants/tradablePairs.42220.js +7388 -0
  79. package/dist/esm/constants/tradablePairs.d.ts +16 -0
  80. package/dist/esm/constants/tradablePairs.js +26 -0
  81. package/dist/esm/enums/chainId.d.ts +4 -0
  82. package/dist/esm/{core/constants → enums}/chainId.js +0 -2
  83. package/dist/esm/enums/index.d.ts +3 -0
  84. package/dist/esm/enums/index.js +3 -0
  85. package/dist/esm/enums/proposalState.d.ts +10 -0
  86. package/dist/esm/enums/proposalState.js +11 -0
  87. package/dist/esm/enums/tradingMode.d.ts +17 -0
  88. package/dist/esm/enums/tradingMode.js +18 -0
  89. package/dist/esm/governance.d.ts +62 -0
  90. package/dist/esm/governance.js +147 -0
  91. package/dist/esm/index.d.ts +7 -0
  92. package/dist/esm/index.js +6 -138
  93. package/dist/esm/interfaces/IChainClient.d.ts +6 -0
  94. package/dist/esm/interfaces/index.d.ts +4 -0
  95. package/dist/esm/interfaces/index.js +4 -0
  96. package/dist/esm/interfaces/tradingLimit.d.ts +7 -0
  97. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +10 -0
  98. package/dist/esm/interfaces/tradingLimitsState.d.ts +9 -0
  99. package/dist/esm/limits.d.ts +33 -0
  100. package/dist/esm/limits.js +123 -0
  101. package/dist/esm/mento.d.ts +287 -0
  102. package/dist/esm/mento.js +671 -0
  103. package/dist/esm/routeUtils.d.ts +304 -0
  104. package/dist/esm/{utils/routeUtils.js → routeUtils.js} +116 -115
  105. package/dist/esm/types/contractAddressMap.d.ts +4 -0
  106. package/dist/esm/types/contractAddresses.d.ts +23 -0
  107. package/dist/esm/types/index.d.ts +2 -0
  108. package/dist/esm/types/index.js +2 -0
  109. package/dist/esm/utils.d.ts +80 -0
  110. package/dist/esm/utils.js +162 -0
  111. package/package.json +1 -1
  112. package/dist/cache/routes.d.ts +0 -13
  113. package/dist/cache/routes.js +0 -13733
  114. package/dist/cache/tokens.d.ts +0 -68
  115. package/dist/cache/tokens.js +0 -446
  116. package/dist/core/abis/activePool.d.ts +0 -2
  117. package/dist/core/abis/activePool.js +0 -14
  118. package/dist/core/abis/addressesRegistry.d.ts +0 -2
  119. package/dist/core/abis/addressesRegistry.js +0 -26
  120. package/dist/core/abis/bipoolmanager.d.ts +0 -34
  121. package/dist/core/abis/bipoolmanager.js +0 -72
  122. package/dist/core/abis/borrowerOperations.d.ts +0 -9
  123. package/dist/core/abis/borrowerOperations.js +0 -89
  124. package/dist/core/abis/breakerbox.d.ts +0 -13
  125. package/dist/core/abis/breakerbox.js +0 -8
  126. package/dist/core/abis/broker.d.ts +0 -2
  127. package/dist/core/abis/broker.js +0 -9
  128. package/dist/core/abis/erc20.d.ts +0 -9
  129. package/dist/core/abis/erc20.js +0 -21
  130. package/dist/core/abis/fpmm.d.ts +0 -270
  131. package/dist/core/abis/fpmm.js +0 -49
  132. package/dist/core/abis/fpmmFactory.d.ts +0 -85
  133. package/dist/core/abis/fpmmFactory.js +0 -26
  134. package/dist/core/abis/hintHelpers.d.ts +0 -2
  135. package/dist/core/abis/hintHelpers.js +0 -14
  136. package/dist/core/abis/index.d.ts +0 -22
  137. package/dist/core/abis/index.js +0 -38
  138. package/dist/core/abis/liquidityStrategy.d.ts +0 -132
  139. package/dist/core/abis/liquidityStrategy.js +0 -10
  140. package/dist/core/abis/multiTroveGetter.d.ts +0 -8
  141. package/dist/core/abis/multiTroveGetter.js +0 -15
  142. package/dist/core/abis/priceFeed.d.ts +0 -7
  143. package/dist/core/abis/priceFeed.js +0 -16
  144. package/dist/core/abis/pricingmodule.d.ts +0 -2
  145. package/dist/core/abis/pricingmodule.js +0 -6
  146. package/dist/core/abis/reserve.d.ts +0 -3
  147. package/dist/core/abis/reserve.js +0 -18
  148. package/dist/core/abis/router.d.ts +0 -521
  149. package/dist/core/abis/router.js +0 -45
  150. package/dist/core/abis/sortedTroves.d.ts +0 -2
  151. package/dist/core/abis/sortedTroves.js +0 -15
  152. package/dist/core/abis/systemParams.d.ts +0 -2
  153. package/dist/core/abis/systemParams.js +0 -14
  154. package/dist/core/abis/troveManager.d.ts +0 -2
  155. package/dist/core/abis/troveManager.js +0 -27
  156. package/dist/core/abis/troveNFT.d.ts +0 -2
  157. package/dist/core/abis/troveNFT.js +0 -9
  158. package/dist/core/abis/virtualPool.d.ts +0 -50
  159. package/dist/core/abis/virtualPool.js +0 -11
  160. package/dist/core/abis/virtualPoolFactory.d.ts +0 -59
  161. package/dist/core/abis/virtualPoolFactory.js +0 -17
  162. package/dist/core/constants/addresses.d.ts +0 -18
  163. package/dist/core/constants/addresses.js +0 -113
  164. package/dist/core/constants/borrowConstants.d.ts +0 -10
  165. package/dist/core/constants/borrowConstants.js +0 -16
  166. package/dist/core/constants/borrowRegistries.d.ts +0 -7
  167. package/dist/core/constants/borrowRegistries.js +0 -30
  168. package/dist/core/constants/chainId.d.ts +0 -7
  169. package/dist/core/constants/contractNames.d.ts +0 -21
  170. package/dist/core/constants/contractNames.js +0 -24
  171. package/dist/core/constants/index.d.ts +0 -6
  172. package/dist/core/errors/base.d.ts +0 -8
  173. package/dist/core/errors/base.js +0 -17
  174. package/dist/core/errors/index.d.ts +0 -4
  175. package/dist/core/errors/oracle.d.ts +0 -9
  176. package/dist/core/errors/oracle.js +0 -15
  177. package/dist/core/errors/router.d.ts +0 -14
  178. package/dist/core/errors/router.js +0 -24
  179. package/dist/core/types/borrow.d.ts +0 -87
  180. package/dist/core/types/contractAddresses.d.ts +0 -42
  181. package/dist/core/types/contractAddresses.js +0 -3
  182. package/dist/core/types/index.d.ts +0 -10
  183. package/dist/core/types/index.js +0 -26
  184. package/dist/core/types/liquidity.d.ts +0 -194
  185. package/dist/core/types/liquidity.js +0 -3
  186. package/dist/core/types/pool.d.ts +0 -208
  187. package/dist/core/types/pool.js +0 -14
  188. package/dist/core/types/provider.d.ts +0 -45
  189. package/dist/core/types/route.d.ts +0 -62
  190. package/dist/core/types/token.d.ts +0 -21
  191. package/dist/core/types/tradingLimits.d.ts +0 -91
  192. package/dist/core/types/tradingLimits.js +0 -3
  193. package/dist/core/types/tradingMode.d.ts +0 -24
  194. package/dist/core/types/tradingMode.js +0 -31
  195. package/dist/core/types/transaction.d.ts +0 -45
  196. package/dist/core/types/transaction.js +0 -3
  197. package/dist/esm/cache/routes.js +0 -13728
  198. package/dist/esm/cache/tokens.js +0 -438
  199. package/dist/esm/core/abis/activePool.js +0 -10
  200. package/dist/esm/core/abis/addressesRegistry.js +0 -22
  201. package/dist/esm/core/abis/bipoolmanager.js +0 -68
  202. package/dist/esm/core/abis/borrowerOperations.js +0 -85
  203. package/dist/esm/core/abis/breakerbox.js +0 -4
  204. package/dist/esm/core/abis/broker.js +0 -5
  205. package/dist/esm/core/abis/erc20.js +0 -17
  206. package/dist/esm/core/abis/fpmm.js +0 -45
  207. package/dist/esm/core/abis/fpmmFactory.js +0 -22
  208. package/dist/esm/core/abis/hintHelpers.js +0 -10
  209. package/dist/esm/core/abis/index.js +0 -21
  210. package/dist/esm/core/abis/liquidityStrategy.js +0 -6
  211. package/dist/esm/core/abis/multiTroveGetter.js +0 -11
  212. package/dist/esm/core/abis/priceFeed.js +0 -12
  213. package/dist/esm/core/abis/pricingmodule.js +0 -2
  214. package/dist/esm/core/abis/reserve.js +0 -14
  215. package/dist/esm/core/abis/router.js +0 -41
  216. package/dist/esm/core/abis/sortedTroves.js +0 -11
  217. package/dist/esm/core/abis/systemParams.js +0 -10
  218. package/dist/esm/core/abis/troveManager.js +0 -23
  219. package/dist/esm/core/abis/troveNFT.js +0 -5
  220. package/dist/esm/core/abis/virtualPool.js +0 -7
  221. package/dist/esm/core/abis/virtualPoolFactory.js +0 -13
  222. package/dist/esm/core/constants/addresses.js +0 -107
  223. package/dist/esm/core/constants/borrowConstants.js +0 -12
  224. package/dist/esm/core/constants/borrowRegistries.js +0 -25
  225. package/dist/esm/core/constants/contractNames.js +0 -20
  226. package/dist/esm/core/constants/index.js +0 -5
  227. package/dist/esm/core/errors/base.js +0 -12
  228. package/dist/esm/core/errors/index.js +0 -3
  229. package/dist/esm/core/errors/oracle.js +0 -10
  230. package/dist/esm/core/errors/router.js +0 -18
  231. package/dist/esm/core/types/index.js +0 -9
  232. package/dist/esm/core/types/pool.js +0 -10
  233. package/dist/esm/core/types/tradingLimits.js +0 -1
  234. package/dist/esm/core/types/tradingMode.js +0 -26
  235. package/dist/esm/core/types/transaction.js +0 -1
  236. package/dist/esm/package.json +0 -1
  237. package/dist/esm/services/borrow/BorrowService.js +0 -455
  238. package/dist/esm/services/borrow/borrowHelpers.js +0 -3
  239. package/dist/esm/services/borrow/borrowMath.js +0 -127
  240. package/dist/esm/services/borrow/index.js +0 -3
  241. package/dist/esm/services/borrow/internal/borrowApprovalService.js +0 -48
  242. package/dist/esm/services/borrow/internal/borrowContextStore.js +0 -35
  243. package/dist/esm/services/borrow/internal/borrowErc20.js +0 -38
  244. package/dist/esm/services/borrow/internal/borrowHints.js +0 -27
  245. package/dist/esm/services/borrow/internal/borrowPositionParser.js +0 -82
  246. package/dist/esm/services/borrow/internal/borrowReadService.js +0 -271
  247. package/dist/esm/services/borrow/internal/borrowRegistryReader.js +0 -108
  248. package/dist/esm/services/borrow/internal/borrowTransactionService.js +0 -271
  249. package/dist/esm/services/borrow/internal/borrowTypes.js +0 -1
  250. package/dist/esm/services/borrow/internal/borrowValidation.js +0 -89
  251. package/dist/esm/services/index.js +0 -8
  252. package/dist/esm/services/liquidity/LiquidityService.js +0 -163
  253. package/dist/esm/services/liquidity/basicLiquidity.js +0 -162
  254. package/dist/esm/services/liquidity/index.js +0 -1
  255. package/dist/esm/services/liquidity/liquidityHelpers.js +0 -95
  256. package/dist/esm/services/liquidity/rebalance.js +0 -59
  257. package/dist/esm/services/liquidity/zapHelpers.js +0 -120
  258. package/dist/esm/services/liquidity/zapIn.js +0 -112
  259. package/dist/esm/services/liquidity/zapOut.js +0 -248
  260. package/dist/esm/services/pools/PoolService.js +0 -204
  261. package/dist/esm/services/pools/index.js +0 -1
  262. package/dist/esm/services/pools/poolDetails.js +0 -209
  263. package/dist/esm/services/pools/poolDiscovery.js +0 -112
  264. package/dist/esm/services/pools/rebalancePreview.js +0 -181
  265. package/dist/esm/services/quotes/QuoteService.js +0 -85
  266. package/dist/esm/services/quotes/index.js +0 -1
  267. package/dist/esm/services/routes/RouteService.js +0 -268
  268. package/dist/esm/services/routes/index.js +0 -1
  269. package/dist/esm/services/swap/SwapService.js +0 -247
  270. package/dist/esm/services/swap/index.js +0 -1
  271. package/dist/esm/services/tokens/index.js +0 -1
  272. package/dist/esm/services/tokens/tokenService.js +0 -285
  273. package/dist/esm/services/trading/TradingLimitsService.js +0 -154
  274. package/dist/esm/services/trading/TradingService.js +0 -196
  275. package/dist/esm/services/trading/index.js +0 -2
  276. package/dist/esm/utils/chainConfig.js +0 -118
  277. package/dist/esm/utils/costUtils.js +0 -56
  278. package/dist/esm/utils/deadline.js +0 -22
  279. package/dist/esm/utils/index.js +0 -9
  280. package/dist/esm/utils/multicall.js +0 -47
  281. package/dist/esm/utils/pathEncoder.js +0 -69
  282. package/dist/esm/utils/rateFeed.js +0 -23
  283. package/dist/esm/utils/retry.js +0 -24
  284. package/dist/esm/utils/routes.js +0 -2
  285. package/dist/esm/utils/sortUtils.js +0 -33
  286. package/dist/esm/utils/tokens.js +0 -2
  287. package/dist/esm/utils/tradingLimits.js +0 -163
  288. package/dist/esm/utils/validation.js +0 -30
  289. package/dist/index.d.ts +0 -101
  290. package/dist/index.js +0 -158
  291. package/dist/services/borrow/BorrowService.d.ts +0 -381
  292. package/dist/services/borrow/BorrowService.js +0 -460
  293. package/dist/services/borrow/borrowHelpers.d.ts +0 -4
  294. package/dist/services/borrow/borrowHelpers.js +0 -13
  295. package/dist/services/borrow/borrowMath.d.ts +0 -21
  296. package/dist/services/borrow/borrowMath.js +0 -137
  297. package/dist/services/borrow/index.d.ts +0 -4
  298. package/dist/services/borrow/internal/borrowApprovalService.d.ts +0 -14
  299. package/dist/services/borrow/internal/borrowApprovalService.js +0 -53
  300. package/dist/services/borrow/internal/borrowContextStore.d.ts +0 -11
  301. package/dist/services/borrow/internal/borrowContextStore.js +0 -40
  302. package/dist/services/borrow/internal/borrowErc20.d.ts +0 -5
  303. package/dist/services/borrow/internal/borrowErc20.js +0 -43
  304. package/dist/services/borrow/internal/borrowHints.d.ts +0 -7
  305. package/dist/services/borrow/internal/borrowHints.js +0 -31
  306. package/dist/services/borrow/internal/borrowPositionParser.d.ts +0 -4
  307. package/dist/services/borrow/internal/borrowPositionParser.js +0 -87
  308. package/dist/services/borrow/internal/borrowReadService.d.ts +0 -31
  309. package/dist/services/borrow/internal/borrowReadService.js +0 -276
  310. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +0 -5
  311. package/dist/services/borrow/internal/borrowRegistryReader.js +0 -113
  312. package/dist/services/borrow/internal/borrowTransactionService.d.ts +0 -23
  313. package/dist/services/borrow/internal/borrowTransactionService.js +0 -276
  314. package/dist/services/borrow/internal/borrowTypes.d.ts +0 -15
  315. package/dist/services/borrow/internal/borrowTypes.js +0 -3
  316. package/dist/services/borrow/internal/borrowValidation.d.ts +0 -14
  317. package/dist/services/borrow/internal/borrowValidation.js +0 -104
  318. package/dist/services/index.d.ts +0 -9
  319. package/dist/services/index.js +0 -25
  320. package/dist/services/liquidity/LiquidityService.d.ts +0 -139
  321. package/dist/services/liquidity/LiquidityService.js +0 -168
  322. package/dist/services/liquidity/basicLiquidity.d.ts +0 -11
  323. package/dist/services/liquidity/basicLiquidity.js +0 -172
  324. package/dist/services/liquidity/index.d.ts +0 -2
  325. package/dist/services/liquidity/liquidityHelpers.d.ts +0 -19
  326. package/dist/services/liquidity/liquidityHelpers.js +0 -104
  327. package/dist/services/liquidity/rebalance.d.ts +0 -6
  328. package/dist/services/liquidity/rebalance.js +0 -64
  329. package/dist/services/liquidity/zapHelpers.d.ts +0 -66
  330. package/dist/services/liquidity/zapHelpers.js +0 -129
  331. package/dist/services/liquidity/zapIn.d.ts +0 -18
  332. package/dist/services/liquidity/zapIn.js +0 -119
  333. package/dist/services/liquidity/zapOut.d.ts +0 -9
  334. package/dist/services/liquidity/zapOut.js +0 -255
  335. package/dist/services/pools/PoolService.d.ts +0 -69
  336. package/dist/services/pools/PoolService.js +0 -209
  337. package/dist/services/pools/index.d.ts +0 -2
  338. package/dist/services/pools/poolDetails.d.ts +0 -13
  339. package/dist/services/pools/poolDetails.js +0 -216
  340. package/dist/services/pools/poolDiscovery.d.ts +0 -12
  341. package/dist/services/pools/poolDiscovery.js +0 -117
  342. package/dist/services/pools/rebalancePreview.d.ts +0 -5
  343. package/dist/services/pools/rebalancePreview.js +0 -186
  344. package/dist/services/quotes/QuoteService.d.ts +0 -51
  345. package/dist/services/quotes/QuoteService.js +0 -91
  346. package/dist/services/quotes/index.d.ts +0 -2
  347. package/dist/services/quotes/index.js +0 -18
  348. package/dist/services/routes/RouteService.d.ts +0 -117
  349. package/dist/services/routes/RouteService.js +0 -306
  350. package/dist/services/routes/index.d.ts +0 -2
  351. package/dist/services/routes/index.js +0 -18
  352. package/dist/services/swap/SwapService.d.ts +0 -198
  353. package/dist/services/swap/SwapService.js +0 -252
  354. package/dist/services/swap/index.d.ts +0 -2
  355. package/dist/services/swap/index.js +0 -18
  356. package/dist/services/tokens/index.d.ts +0 -2
  357. package/dist/services/tokens/index.js +0 -18
  358. package/dist/services/tokens/tokenService.d.ts +0 -55
  359. package/dist/services/tokens/tokenService.js +0 -290
  360. package/dist/services/trading/TradingLimitsService.d.ts +0 -38
  361. package/dist/services/trading/TradingLimitsService.js +0 -159
  362. package/dist/services/trading/TradingService.d.ts +0 -113
  363. package/dist/services/trading/TradingService.js +0 -201
  364. package/dist/services/trading/index.d.ts +0 -3
  365. package/dist/services/trading/index.js +0 -19
  366. package/dist/utils/chainConfig.d.ts +0 -16
  367. package/dist/utils/chainConfig.js +0 -123
  368. package/dist/utils/costUtils.d.ts +0 -12
  369. package/dist/utils/costUtils.js +0 -60
  370. package/dist/utils/deadline.d.ts +0 -21
  371. package/dist/utils/deadline.js +0 -26
  372. package/dist/utils/index.d.ts +0 -10
  373. package/dist/utils/index.js +0 -26
  374. package/dist/utils/multicall.d.ts +0 -30
  375. package/dist/utils/multicall.js +0 -52
  376. package/dist/utils/pathEncoder.d.ts +0 -34
  377. package/dist/utils/pathEncoder.js +0 -73
  378. package/dist/utils/rateFeed.d.ts +0 -18
  379. package/dist/utils/rateFeed.js +0 -27
  380. package/dist/utils/retry.d.ts +0 -12
  381. package/dist/utils/retry.js +0 -28
  382. package/dist/utils/routes.d.ts +0 -3
  383. package/dist/utils/routes.js +0 -8
  384. package/dist/utils/sortUtils.d.ts +0 -24
  385. package/dist/utils/sortUtils.js +0 -39
  386. package/dist/utils/tokens.d.ts +0 -2
  387. package/dist/utils/tokens.js +0 -13
  388. package/dist/utils/tradingLimits.d.ts +0 -41
  389. package/dist/utils/tradingLimits.js +0 -171
  390. package/dist/utils/validation.d.ts +0 -19
  391. package/dist/utils/validation.js +0 -34
  392. /package/dist/esm/{core/types/borrow.js → interfaces/IChainClient.js} +0 -0
  393. /package/dist/esm/{core/types/contractAddresses.js → interfaces/tradingLimit.js} +0 -0
  394. /package/dist/esm/{core/types/liquidity.js → interfaces/tradingLimitsConfig.js} +0 -0
  395. /package/dist/esm/{core/types/provider.js → interfaces/tradingLimitsState.js} +0 -0
  396. /package/dist/esm/{core/types/route.js → types/contractAddressMap.js} +0 -0
  397. /package/dist/esm/{core/types/token.js → types/contractAddresses.js} +0 -0
@@ -1,248 +0,0 @@
1
- import { ROUTER_ABI } from '../../core/abis';
2
- import { getContractAddress } from '../../core/constants';
3
- import { RouteNotFoundError, ZapOutRouteNotViableError } from '../../core/errors';
4
- import { validateAddress } from '../../utils/validation';
5
- import { encodeRoutePath } from '../../utils/pathEncoder';
6
- import { buildApprovalParams, getAllowance, calculateMinAmount, getPoolInfo } from './liquidityHelpers';
7
- import { encodeZapOutCall, findZapOutRoutes } from './zapHelpers';
8
- const INSUFFICIENT_LIQUIDITY_SELECTOR = '0xbb55fd27';
9
- const MAX_ROUTE_CANDIDATES_PER_LEG = 8;
10
- const MAX_ROUTE_COMBINATIONS = 48;
11
- const ROUTE_SIMULATION_BATCH_SIZE = 6;
12
- export async function buildZapOutTransactionInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
13
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options);
14
- return {
15
- approval: prepared.approval ?? null,
16
- zapOut: prepared.details,
17
- };
18
- }
19
- export async function buildZapOutParamsInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
20
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, undefined, options);
21
- return prepared.details;
22
- }
23
- export async function quoteZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, options) {
24
- const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, tokenOut, undefined, options);
25
- return prepared.quote;
26
- }
27
- export async function prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
28
- if (owner) {
29
- validateAddress(owner, 'owner');
30
- }
31
- const [context, currentAllowance] = await Promise.all([
32
- prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options),
33
- owner ? getAllowance(publicClient, poolAddress, owner, chainId) : Promise.resolve(null),
34
- ]);
35
- let details = context.details;
36
- const approval = owner && currentAllowance !== null && currentAllowance < liquidity
37
- ? { token: poolAddress, amount: liquidity, params: buildApprovalParams(chainId, poolAddress, liquidity) }
38
- : owner
39
- ? null
40
- : undefined;
41
- if (owner && currentAllowance !== null && currentAllowance >= liquidity) {
42
- const ownerAddr = owner;
43
- const routerAddress = getContractAddress(chainId, 'Router');
44
- try {
45
- await simulateZapOut(publicClient, ownerAddr, routerAddress, details.params.data);
46
- }
47
- catch (error) {
48
- if (!isInsufficientLiquidityError(error)) {
49
- throw error;
50
- }
51
- details = await findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, ownerAddr, options);
52
- }
53
- }
54
- return {
55
- routesA: details.routesA,
56
- routesB: details.routesB,
57
- quote: {
58
- amountOutFromA: details.zapParams.amountOutMinA,
59
- amountOutFromB: details.zapParams.amountOutMinB,
60
- amountAMin: details.zapParams.amountAMin,
61
- amountBMin: details.zapParams.amountBMin,
62
- estimatedMinTokenOut: details.estimatedMinTokenOut,
63
- },
64
- approval,
65
- details,
66
- };
67
- }
68
- async function prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
69
- validateAddress(poolAddress, 'poolAddress');
70
- validateAddress(tokenOut, 'tokenOut');
71
- validateAddress(recipient, 'recipient');
72
- const { token0, token1, factoryAddr } = await getPoolInfo(poolService, poolAddress);
73
- const { routesA, routesB } = await findZapOutRoutes(routeService, token0, token1, tokenOut);
74
- const details = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
75
- return {
76
- routesA,
77
- routesB,
78
- quote: {
79
- amountOutFromA: details.zapParams.amountOutMinA,
80
- amountOutFromB: details.zapParams.amountOutMinB,
81
- amountAMin: details.zapParams.amountAMin,
82
- amountBMin: details.zapParams.amountBMin,
83
- estimatedMinTokenOut: details.estimatedMinTokenOut,
84
- },
85
- details,
86
- };
87
- }
88
- async function buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options) {
89
- const routerAddress = getContractAddress(chainId, 'Router');
90
- const [amountOutMinA, amountOutMinB, amountAMin, amountBMin] = (await publicClient.readContract({
91
- address: routerAddress,
92
- abi: ROUTER_ABI,
93
- functionName: 'generateZapOutParams',
94
- args: [token0, token1, factoryAddr, liquidity, routesA, routesB],
95
- }));
96
- const finalAmountAMin = calculateMinAmount(amountAMin, options.slippageTolerance);
97
- const finalAmountBMin = calculateMinAmount(amountBMin, options.slippageTolerance);
98
- const finalAmountOutMinA = calculateMinAmount(amountOutMinA, options.slippageTolerance);
99
- const finalAmountOutMinB = calculateMinAmount(amountOutMinB, options.slippageTolerance);
100
- const zapParams = {
101
- tokenA: token0,
102
- tokenB: token1,
103
- factory: factoryAddr,
104
- amountAMin: finalAmountAMin,
105
- amountBMin: finalAmountBMin,
106
- amountOutMinA: finalAmountOutMinA,
107
- amountOutMinB: finalAmountOutMinB,
108
- };
109
- const data = encodeZapOutCall(tokenOut, liquidity, zapParams, routesA, routesB);
110
- return {
111
- params: {
112
- to: routerAddress,
113
- data,
114
- value: '0',
115
- },
116
- poolAddress,
117
- tokenOut,
118
- liquidity,
119
- routesA,
120
- routesB,
121
- zapParams,
122
- estimatedMinTokenOut: finalAmountOutMinA + finalAmountOutMinB,
123
- };
124
- }
125
- async function findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, owner, options) {
126
- const { token0, token1, factoryAddr } = await getPoolInfo(poolService, poolAddress);
127
- const routerAddress = getContractAddress(chainId, 'Router');
128
- const allRoutes = await routeService.getRoutes({ cached: false, returnAllRoutes: true });
129
- const [routesAOptions, routesBOptions] = await Promise.all([
130
- getEncodedRouteCandidates(routeService, token0, tokenOut, poolAddress, allRoutes),
131
- getEncodedRouteCandidates(routeService, token1, tokenOut, poolAddress, allRoutes),
132
- ]);
133
- const routeCombinations = [];
134
- outer: for (const routesA of routesAOptions) {
135
- for (const routesB of routesBOptions) {
136
- routeCombinations.push({ routesA, routesB });
137
- if (routeCombinations.length >= MAX_ROUTE_COMBINATIONS) {
138
- break outer;
139
- }
140
- }
141
- }
142
- let best = null;
143
- for (let index = 0; index < routeCombinations.length; index += ROUTE_SIMULATION_BATCH_SIZE) {
144
- const batch = routeCombinations.slice(index, index + ROUTE_SIMULATION_BATCH_SIZE);
145
- const candidates = await Promise.all(batch.map(async ({ routesA, routesB }) => {
146
- try {
147
- const candidate = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
148
- await simulateZapOut(publicClient, owner, routerAddress, candidate.params.data);
149
- return candidate;
150
- }
151
- catch {
152
- return null;
153
- }
154
- }));
155
- for (const candidate of candidates) {
156
- if (candidate && (!best || candidate.estimatedMinTokenOut > best.estimatedMinTokenOut)) {
157
- best = candidate;
158
- }
159
- }
160
- }
161
- if (!best) {
162
- throw new ZapOutRouteNotViableError(poolAddress, tokenOut);
163
- }
164
- return best;
165
- }
166
- async function getEncodedRouteCandidates(routeService, tokenIn, tokenOut, sourcePoolAddress, allRoutes) {
167
- if (tokenIn.toLowerCase() === tokenOut.toLowerCase()) {
168
- return [[]];
169
- }
170
- const rawCandidates = [];
171
- try {
172
- rawCandidates.push(await routeService.findRoute(tokenIn, tokenOut));
173
- }
174
- catch {
175
- // Continue; we'll try the broader route set next.
176
- }
177
- const pairCandidates = (allRoutes ?? await routeService.getRoutes({ cached: false, returnAllRoutes: true })).filter((route) => {
178
- const a0 = route.tokens[0].address.toLowerCase();
179
- const a1 = route.tokens[1].address.toLowerCase();
180
- const t0 = tokenIn.toLowerCase();
181
- const t1 = tokenOut.toLowerCase();
182
- return (a0 === t0 && a1 === t1) || (a0 === t1 && a1 === t0);
183
- });
184
- rawCandidates.push(...pairCandidates);
185
- if (rawCandidates.length === 0) {
186
- throw new RouteNotFoundError(tokenIn, tokenOut);
187
- }
188
- rawCandidates.sort((routeA, routeB) => {
189
- const routeAUsesSourcePool = routeUsesPool(routeA, sourcePoolAddress) ? 1 : 0;
190
- const routeBUsesSourcePool = routeUsesPool(routeB, sourcePoolAddress) ? 1 : 0;
191
- if (routeAUsesSourcePool !== routeBUsesSourcePool)
192
- return routeAUsesSourcePool - routeBUsesSourcePool;
193
- if (routeA.path.length !== routeB.path.length)
194
- return routeA.path.length - routeB.path.length;
195
- return 0;
196
- });
197
- const encodedRoutes = [];
198
- const seen = new Set();
199
- for (const route of rawCandidates) {
200
- try {
201
- const encoded = encodeRoutePath(route.path, tokenIn, tokenOut);
202
- const key = JSON.stringify(encoded);
203
- if (seen.has(key))
204
- continue;
205
- seen.add(key);
206
- encodedRoutes.push(encoded);
207
- if (encodedRoutes.length >= MAX_ROUTE_CANDIDATES_PER_LEG) {
208
- break;
209
- }
210
- }
211
- catch {
212
- // Invalid path encoding for this direction; skip.
213
- }
214
- }
215
- if (encodedRoutes.length === 0) {
216
- throw new RouteNotFoundError(tokenIn, tokenOut);
217
- }
218
- return encodedRoutes;
219
- }
220
- function routeUsesPool(route, poolAddress) {
221
- const normalizedPool = poolAddress.toLowerCase();
222
- return route.path.some((hop) => hop.poolAddr.toLowerCase() === normalizedPool);
223
- }
224
- async function simulateZapOut(publicClient, owner, routerAddress, data) {
225
- await publicClient.call({
226
- account: owner,
227
- to: routerAddress,
228
- data,
229
- });
230
- }
231
- function isInsufficientLiquidityError(error) {
232
- const message = extractErrorMessage(error).toLowerCase();
233
- return (message.includes(INSUFFICIENT_LIQUIDITY_SELECTOR) ||
234
- message.includes('insufficientliquidity'));
235
- }
236
- function extractErrorMessage(error) {
237
- if (!(error instanceof Error)) {
238
- return String(error);
239
- }
240
- const typed = error;
241
- const parts = [
242
- typed.message,
243
- typed.shortMessage,
244
- typed.details,
245
- typed.cause instanceof Error ? typed.cause.message : undefined,
246
- ].filter((part) => Boolean(part));
247
- return parts.join(' | ');
248
- }
@@ -1,204 +0,0 @@
1
- import { PoolType } from '../../core/types';
2
- import { fetchFPMMPools, fetchVirtualPools } from './poolDiscovery';
3
- import { fetchFPMMPoolDetailsBatch, fetchVirtualPoolDetailsBatch, } from './poolDetails';
4
- import { fetchPoolRebalancePreview, fetchPoolRebalancePreviewBatch, } from './rebalancePreview';
5
- /**
6
- * Service for discovering liquidity pools in the Mento protocol.
7
- * Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
8
- */
9
- export class PoolService {
10
- constructor(publicClient, chainId) {
11
- this.publicClient = publicClient;
12
- this.chainId = chainId;
13
- this.poolsCache = null;
14
- this.discoveryWarnings = [];
15
- this.poolsPromise = null;
16
- this.poolDetailsCache = new Map();
17
- this.poolDetailPromises = new Map();
18
- }
19
- /**
20
- * Returns any warnings from the last pool discovery operation.
21
- * Useful for debugging when some factories fail but others succeed.
22
- */
23
- getDiscoveryWarnings() {
24
- return [...this.discoveryWarnings];
25
- }
26
- /**
27
- * Fetches all pools available in the protocol from both FPMM and Virtual pool factories
28
- * Results are cached in memory for the service instance lifetime
29
- *
30
- * @returns Array of all pools available in the protocol
31
- * @throws {Error} If no pools can be discovered from any factory
32
- *
33
- * @example
34
- * ```typescript
35
- * const pools = await poolService.getPools()
36
- * console.log(`Found ${pools.length} pools`)
37
- * ```
38
- */
39
- async getPools() {
40
- if (this.poolsCache) {
41
- return this.poolsCache;
42
- }
43
- if (this.poolsPromise) {
44
- return this.poolsPromise;
45
- }
46
- this.poolsPromise = this.loadPools();
47
- try {
48
- return await this.poolsPromise;
49
- }
50
- finally {
51
- this.poolsPromise = null;
52
- }
53
- }
54
- async loadPools() {
55
- const warnings = [];
56
- const settled = await Promise.allSettled([
57
- fetchFPMMPools(this.publicClient, this.chainId),
58
- fetchVirtualPools(this.publicClient, this.chainId),
59
- ]);
60
- const pools = [];
61
- const [fpmmResult, virtualResult] = settled;
62
- if (fpmmResult.status === 'fulfilled') {
63
- pools.push(...fpmmResult.value);
64
- }
65
- else {
66
- warnings.push(`Failed to fetch FPMM pools: ${fpmmResult.reason instanceof Error ? fpmmResult.reason.message : String(fpmmResult.reason)}`);
67
- }
68
- if (virtualResult.status === 'fulfilled') {
69
- pools.push(...virtualResult.value);
70
- }
71
- else {
72
- warnings.push(`Failed to fetch Virtual pools: ${virtualResult.reason instanceof Error ? virtualResult.reason.message : String(virtualResult.reason)}`);
73
- }
74
- this.discoveryWarnings = warnings;
75
- // Only throw if NO pools were discovered from any factory
76
- if (pools.length === 0) {
77
- throw new Error('Failed to discover any pools from any factory. ' +
78
- 'All pool factory queries failed. Check network connectivity and RPC endpoint.');
79
- }
80
- this.poolsCache = pools;
81
- return pools;
82
- }
83
- /**
84
- * Fetches enriched on-chain details for a specific pool by address.
85
- * Resolves the pool type from the discovery cache, then fetches
86
- * pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
87
- *
88
- * @param poolAddr - The deployed pool contract address
89
- * @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
90
- * @throws {Error} If the pool address is not found in any known factory
91
- * @throws {Error} If on-chain calls fail
92
- *
93
- * @example
94
- * ```typescript
95
- * const details = await poolService.getPoolDetails('0x...')
96
- * if (details.poolType === 'FPMM') {
97
- * console.log(details.pricing.oraclePrice)
98
- * console.log(details.rebalancing.inBand)
99
- * } else {
100
- * console.log(details.spreadPercent)
101
- * }
102
- * ```
103
- */
104
- async getPoolDetails(poolAddr) {
105
- const [details] = await this.getPoolDetailsBatch([poolAddr]);
106
- return details;
107
- }
108
- async getPoolRebalancePreview(poolAddr) {
109
- const details = await this.getPoolDetails(poolAddr);
110
- return fetchPoolRebalancePreview(this.publicClient, details);
111
- }
112
- async getPoolRebalancePreviewBatch(poolAddresses) {
113
- const details = await this.getPoolDetailsBatch(poolAddresses);
114
- return fetchPoolRebalancePreviewBatch(this.publicClient, details);
115
- }
116
- async getPoolDetailsBatch(poolAddresses) {
117
- const pools = await this.getPools();
118
- const targets = poolAddresses
119
- ? poolAddresses.map((poolAddress) => {
120
- const pool = pools.find((candidate) => candidate.poolAddr.toLowerCase() === poolAddress.toLowerCase());
121
- if (!pool) {
122
- throw new Error(`Pool not found: ${poolAddress}. Ensure the address is a valid pool discovered by getPools().`);
123
- }
124
- return pool;
125
- })
126
- : pools;
127
- const results = new Array(targets.length);
128
- const pendingResults = [];
129
- const missingTargets = [];
130
- for (const [index, pool] of targets.entries()) {
131
- const key = pool.poolAddr.toLowerCase();
132
- const cached = this.poolDetailsCache.get(key);
133
- if (cached) {
134
- results[index] = cached;
135
- continue;
136
- }
137
- const inFlight = this.poolDetailPromises.get(key);
138
- if (inFlight) {
139
- pendingResults.push(inFlight.then((detail) => {
140
- results[index] = detail;
141
- }));
142
- continue;
143
- }
144
- missingTargets.push({ pool, index, key });
145
- }
146
- if (missingTargets.length > 0) {
147
- const grouped = {
148
- fpmm: missingTargets.filter(({ pool }) => pool.poolType === PoolType.FPMM),
149
- virtual: missingTargets.filter(({ pool }) => pool.poolType !== PoolType.FPMM),
150
- };
151
- const createdPromises = new Map();
152
- const createdPendingResults = [];
153
- for (const target of missingTargets) {
154
- const deferred = createDeferred();
155
- this.poolDetailPromises.set(target.key, deferred.promise);
156
- createdPromises.set(target.key, deferred);
157
- const pendingResult = deferred.promise.then((detail) => {
158
- results[target.index] = detail;
159
- });
160
- pendingResults.push(pendingResult);
161
- createdPendingResults.push(pendingResult);
162
- }
163
- try {
164
- const [fpmmDetails, virtualDetails] = await Promise.all([
165
- fetchFPMMPoolDetailsBatch(this.publicClient, this.chainId, grouped.fpmm.map(({ pool }) => pool)),
166
- fetchVirtualPoolDetailsBatch(this.publicClient, grouped.virtual.map(({ pool }) => pool)),
167
- ]);
168
- for (const [groupIndex, detail] of fpmmDetails.entries()) {
169
- const target = grouped.fpmm[groupIndex];
170
- this.poolDetailsCache.set(target.key, detail);
171
- createdPromises.get(target.key)?.resolve(detail);
172
- }
173
- for (const [groupIndex, detail] of virtualDetails.entries()) {
174
- const target = grouped.virtual[groupIndex];
175
- this.poolDetailsCache.set(target.key, detail);
176
- createdPromises.get(target.key)?.resolve(detail);
177
- }
178
- }
179
- catch (error) {
180
- for (const target of missingTargets) {
181
- createdPromises.get(target.key)?.reject(error);
182
- }
183
- await Promise.allSettled(createdPendingResults);
184
- throw error;
185
- }
186
- finally {
187
- for (const target of missingTargets) {
188
- this.poolDetailPromises.delete(target.key);
189
- }
190
- }
191
- }
192
- await Promise.all(pendingResults);
193
- return results;
194
- }
195
- }
196
- function createDeferred() {
197
- let resolve;
198
- let reject;
199
- const promise = new Promise((resolvePromise, rejectPromise) => {
200
- resolve = resolvePromise;
201
- reject = rejectPromise;
202
- });
203
- return { promise, resolve, reject };
204
- }
@@ -1 +0,0 @@
1
- export * from "./PoolService";
@@ -1,209 +0,0 @@
1
- import { tryGetContractAddress } from '../../core/constants';
2
- import { FPMM_ABI, VIRTUAL_POOL_ABI } from '../../core/abis';
3
- import { getAddress } from 'viem';
4
- import { multicall } from '../../utils/multicall';
5
- const FPMM_FIXED_RESULT_COUNT = 8;
6
- const VIRTUAL_RESULT_COUNT = 3;
7
- /**
8
- * Fetches enriched details for an FPMM pool
9
- */
10
- export async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
11
- const [details] = await fetchFPMMPoolDetailsBatch(publicClient, chainId, [pool]);
12
- return details;
13
- }
14
- export async function fetchFPMMPoolDetailsBatch(publicClient, chainId, pools) {
15
- if (pools.length === 0) {
16
- return [];
17
- }
18
- const openLiquidityStrategy = getOpenLiquidityStrategy(chainId);
19
- const contracts = pools.flatMap((pool) => buildFPMMContracts(pool, openLiquidityStrategy));
20
- const results = await multicall(publicClient, contracts);
21
- const strategyCheckCount = openLiquidityStrategy ? 1 : 0;
22
- const perPoolResultCount = FPMM_FIXED_RESULT_COUNT + strategyCheckCount + 1;
23
- return pools.map((pool, index) => {
24
- const offset = index * perPoolResultCount;
25
- const poolResults = results.slice(offset, offset + perPoolResultCount);
26
- return parseFPMMPoolDetails(pool, openLiquidityStrategy, poolResults);
27
- });
28
- }
29
- function buildFPMMContracts(pool, openLiquidityStrategy) {
30
- const address = pool.poolAddr;
31
- return [
32
- { address, abi: FPMM_ABI, functionName: 'getReserves' },
33
- { address, abi: FPMM_ABI, functionName: 'decimals0' },
34
- { address, abi: FPMM_ABI, functionName: 'decimals1' },
35
- { address, abi: FPMM_ABI, functionName: 'lpFee' },
36
- { address, abi: FPMM_ABI, functionName: 'protocolFee' },
37
- { address, abi: FPMM_ABI, functionName: 'rebalanceIncentive' },
38
- { address, abi: FPMM_ABI, functionName: 'rebalanceThresholdAbove' },
39
- { address, abi: FPMM_ABI, functionName: 'rebalanceThresholdBelow' },
40
- ...(openLiquidityStrategy
41
- ? [{
42
- address,
43
- abi: FPMM_ABI,
44
- functionName: 'liquidityStrategy',
45
- args: [openLiquidityStrategy],
46
- }]
47
- : []),
48
- { address, abi: FPMM_ABI, functionName: 'getRebalancingState' },
49
- ];
50
- }
51
- function parseFPMMPoolDetails(pool, openLiquidityStrategy, results) {
52
- try {
53
- const reservesRes = results[0];
54
- const decimals0Res = results[1];
55
- const decimals1Res = results[2];
56
- const lpFeeRes = results[3];
57
- const protocolFeeRes = results[4];
58
- const rebalanceIncentiveRes = results[5];
59
- const thresholdAboveRes = results[6];
60
- const thresholdBelowRes = results[7];
61
- if (!reservesRes ||
62
- !decimals0Res ||
63
- !decimals1Res ||
64
- !lpFeeRes ||
65
- !protocolFeeRes ||
66
- !rebalanceIncentiveRes ||
67
- !thresholdAboveRes ||
68
- !thresholdBelowRes ||
69
- reservesRes.status === 'failure' ||
70
- decimals0Res.status === 'failure' ||
71
- decimals1Res.status === 'failure' ||
72
- lpFeeRes.status === 'failure' ||
73
- protocolFeeRes.status === 'failure' ||
74
- rebalanceIncentiveRes.status === 'failure' ||
75
- thresholdAboveRes.status === 'failure' ||
76
- thresholdBelowRes.status === 'failure') {
77
- throw new Error('One or more core pool reads failed');
78
- }
79
- const [reserve0, reserve1, blockTimestampLast] = reservesRes.result;
80
- const lpFeeBps = lpFeeRes.result;
81
- const protocolFeeBps = protocolFeeRes.result;
82
- const rebalanceIncentiveBps = rebalanceIncentiveRes.result;
83
- const thresholdAboveBps = thresholdAboveRes.result;
84
- const thresholdBelowBps = thresholdBelowRes.result;
85
- const strategyCheckCount = openLiquidityStrategy ? 1 : 0;
86
- const openStrategyResult = strategyCheckCount > 0 ? results[FPMM_FIXED_RESULT_COUNT] : null;
87
- const liquidityStrategy = openLiquidityStrategy &&
88
- openStrategyResult?.status === 'success' &&
89
- openStrategyResult.result === true
90
- ? openLiquidityStrategy
91
- : null;
92
- const rebalancingRes = results[FPMM_FIXED_RESULT_COUNT + strategyCheckCount];
93
- let pricing = null;
94
- let inBand = null;
95
- if (rebalancingRes?.status === 'success') {
96
- const [oraclePriceNum, oraclePriceDen, reservePriceNum, reservePriceDen, reservePriceAboveOraclePrice, rebalanceThreshold, priceDifference,] = rebalancingRes.result;
97
- pricing = {
98
- oraclePriceNum,
99
- oraclePriceDen,
100
- oraclePrice: Number(oraclePriceNum) / Number(oraclePriceDen),
101
- reservePriceNum,
102
- reservePriceDen,
103
- reservePrice: Number(reservePriceNum) / Number(reservePriceDen),
104
- priceDifferenceBps: priceDifference,
105
- priceDifferencePercent: Number(priceDifference) / 100,
106
- reservePriceAboveOraclePrice,
107
- };
108
- inBand = priceDifference < BigInt(rebalanceThreshold);
109
- }
110
- return {
111
- ...pool,
112
- poolType: 'FPMM',
113
- scalingFactor0: decimals0Res.result,
114
- scalingFactor1: decimals1Res.result,
115
- reserve0,
116
- reserve1,
117
- blockTimestampLast,
118
- pricing,
119
- fees: {
120
- lpFeeBps,
121
- lpFeePercent: Number(lpFeeBps) / 100,
122
- protocolFeeBps,
123
- protocolFeePercent: Number(protocolFeeBps) / 100,
124
- totalFeePercent: (Number(lpFeeBps) + Number(protocolFeeBps)) / 100,
125
- },
126
- rebalancing: {
127
- rebalanceIncentiveBps,
128
- rebalanceIncentivePercent: Number(rebalanceIncentiveBps) / 100,
129
- rebalanceThresholdAboveBps: thresholdAboveBps,
130
- rebalanceThresholdAbovePercent: Number(thresholdAboveBps) / 100,
131
- rebalanceThresholdBelowBps: thresholdBelowBps,
132
- rebalanceThresholdBelowPercent: Number(thresholdBelowBps) / 100,
133
- inBand,
134
- liquidityStrategy,
135
- },
136
- };
137
- }
138
- catch (error) {
139
- throw new Error(`Failed to fetch FPMM pool details for ${pool.poolAddr}: ${error.message}`);
140
- }
141
- }
142
- /**
143
- * Fetches enriched details for a Virtual pool
144
- */
145
- export async function fetchVirtualPoolDetails(publicClient, pool) {
146
- const [details] = await fetchVirtualPoolDetailsBatch(publicClient, [pool]);
147
- return details;
148
- }
149
- export async function fetchVirtualPoolDetailsBatch(publicClient, pools) {
150
- if (pools.length === 0) {
151
- return [];
152
- }
153
- const contracts = pools.flatMap((pool) => buildVirtualContracts(pool));
154
- const results = await multicall(publicClient, contracts);
155
- return pools.map((pool, index) => {
156
- const offset = index * VIRTUAL_RESULT_COUNT;
157
- const poolResults = results.slice(offset, offset + VIRTUAL_RESULT_COUNT);
158
- return parseVirtualPoolDetails(pool, poolResults);
159
- });
160
- }
161
- function buildVirtualContracts(pool) {
162
- const address = pool.poolAddr;
163
- return [
164
- { address, abi: VIRTUAL_POOL_ABI, functionName: 'getReserves' },
165
- { address, abi: VIRTUAL_POOL_ABI, functionName: 'protocolFee' },
166
- { address, abi: VIRTUAL_POOL_ABI, functionName: 'metadata' },
167
- ];
168
- }
169
- function parseVirtualPoolDetails(pool, results) {
170
- try {
171
- if (results.length !== VIRTUAL_RESULT_COUNT ||
172
- results[0].status === 'failure' ||
173
- results[1].status === 'failure' ||
174
- results[2].status === 'failure') {
175
- throw new Error('One or more virtual pool reads failed');
176
- }
177
- const [reserve0, reserve1, blockTimestampLast] = results[0].result;
178
- const [dec0, dec1] = results[2].result;
179
- const spreadBps = results[1].result;
180
- return {
181
- ...pool,
182
- poolType: 'Virtual',
183
- scalingFactor0: dec0,
184
- scalingFactor1: dec1,
185
- reserve0,
186
- reserve1,
187
- blockTimestampLast,
188
- spreadBps,
189
- spreadPercent: Number(spreadBps) / 100,
190
- };
191
- }
192
- catch (error) {
193
- throw new Error(`Failed to fetch Virtual pool details for ${pool.poolAddr}: ${error.message}`);
194
- }
195
- }
196
- /**
197
- * Returns the configured Open Liquidity Strategy for the given chain.
198
- */
199
- function getOpenLiquidityStrategy(chainId) {
200
- const strategyAddress = tryGetContractAddress(chainId, 'OpenLiquidityStrategy');
201
- if (!strategyAddress)
202
- return null;
203
- try {
204
- return getAddress(strategyAddress);
205
- }
206
- catch {
207
- return null;
208
- }
209
- }