@mento-protocol/mento-sdk 3.0.0-beta.2 → 3.0.0-beta.21

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 (327) hide show
  1. package/README.md +34 -0
  2. package/dist/cache/routes.d.ts +13 -0
  3. package/dist/cache/routes.d.ts.map +1 -0
  4. package/dist/cache/routes.js +130 -0
  5. package/dist/cache/routes.js.map +1 -0
  6. package/dist/cache/tokens.d.ts +67 -0
  7. package/dist/cache/tokens.d.ts.map +1 -0
  8. package/dist/cache/tokens.js +379 -0
  9. package/dist/cache/tokens.js.map +1 -0
  10. package/dist/core/abis/activePool.d.ts +2 -0
  11. package/dist/core/abis/activePool.d.ts.map +1 -0
  12. package/dist/core/abis/activePool.js +14 -0
  13. package/dist/core/abis/activePool.js.map +1 -0
  14. package/dist/core/abis/addressesRegistry.d.ts +2 -0
  15. package/dist/core/abis/addressesRegistry.d.ts.map +1 -0
  16. package/dist/core/abis/addressesRegistry.js +26 -0
  17. package/dist/core/abis/addressesRegistry.js.map +1 -0
  18. package/dist/core/abis/borrowerOperations.d.ts +9 -0
  19. package/dist/core/abis/borrowerOperations.d.ts.map +1 -0
  20. package/dist/core/abis/borrowerOperations.js +89 -0
  21. package/dist/core/abis/borrowerOperations.js.map +1 -0
  22. package/dist/core/abis/breakerbox.d.ts +13 -0
  23. package/dist/core/abis/breakerbox.d.ts.map +1 -0
  24. package/dist/core/abis/breakerbox.js +8 -0
  25. package/dist/core/abis/breakerbox.js.map +1 -0
  26. package/dist/core/abis/erc20.d.ts +7 -0
  27. package/dist/core/abis/erc20.d.ts.map +1 -1
  28. package/dist/core/abis/erc20.js +7 -0
  29. package/dist/core/abis/erc20.js.map +1 -1
  30. package/dist/core/abis/fpmm.d.ts +128 -0
  31. package/dist/core/abis/fpmm.d.ts.map +1 -1
  32. package/dist/core/abis/fpmm.js +10 -0
  33. package/dist/core/abis/fpmm.js.map +1 -1
  34. package/dist/core/abis/hintHelpers.d.ts +2 -0
  35. package/dist/core/abis/hintHelpers.d.ts.map +1 -0
  36. package/dist/core/abis/hintHelpers.js +14 -0
  37. package/dist/core/abis/hintHelpers.js.map +1 -0
  38. package/dist/core/abis/index.d.ts +12 -0
  39. package/dist/core/abis/index.d.ts.map +1 -1
  40. package/dist/core/abis/index.js +12 -0
  41. package/dist/core/abis/index.js.map +1 -1
  42. package/dist/core/abis/multiTroveGetter.d.ts +8 -0
  43. package/dist/core/abis/multiTroveGetter.d.ts.map +1 -0
  44. package/dist/core/abis/multiTroveGetter.js +15 -0
  45. package/dist/core/abis/multiTroveGetter.js.map +1 -0
  46. package/dist/core/abis/priceFeed.d.ts +7 -0
  47. package/dist/core/abis/priceFeed.d.ts.map +1 -0
  48. package/dist/core/abis/priceFeed.js +16 -0
  49. package/dist/core/abis/priceFeed.js.map +1 -0
  50. package/dist/core/abis/router.d.ts +436 -1
  51. package/dist/core/abis/router.d.ts.map +1 -1
  52. package/dist/core/abis/router.js +13 -0
  53. package/dist/core/abis/router.js.map +1 -1
  54. package/dist/core/abis/sortedTroves.d.ts +2 -0
  55. package/dist/core/abis/sortedTroves.d.ts.map +1 -0
  56. package/dist/core/abis/sortedTroves.js +15 -0
  57. package/dist/core/abis/sortedTroves.js.map +1 -0
  58. package/dist/core/abis/systemParams.d.ts +2 -0
  59. package/dist/core/abis/systemParams.d.ts.map +1 -0
  60. package/dist/core/abis/systemParams.js +14 -0
  61. package/dist/core/abis/systemParams.js.map +1 -0
  62. package/dist/core/abis/troveManager.d.ts +2 -0
  63. package/dist/core/abis/troveManager.d.ts.map +1 -0
  64. package/dist/core/abis/troveManager.js +27 -0
  65. package/dist/core/abis/troveManager.js.map +1 -0
  66. package/dist/core/abis/troveNFT.d.ts +2 -0
  67. package/dist/core/abis/troveNFT.d.ts.map +1 -0
  68. package/dist/core/abis/troveNFT.js +9 -0
  69. package/dist/core/abis/troveNFT.js.map +1 -0
  70. package/dist/core/abis/virtualPool.d.ts +40 -0
  71. package/dist/core/abis/virtualPool.d.ts.map +1 -1
  72. package/dist/core/abis/virtualPool.js +6 -1
  73. package/dist/core/abis/virtualPool.js.map +1 -1
  74. package/dist/core/abis/virtualPoolFactory.d.ts +8 -0
  75. package/dist/core/abis/virtualPoolFactory.d.ts.map +1 -1
  76. package/dist/core/abis/virtualPoolFactory.js +1 -0
  77. package/dist/core/abis/virtualPoolFactory.js.map +1 -1
  78. package/dist/core/constants/aaveConfig.js +2 -2
  79. package/dist/core/constants/addresses.d.ts.map +1 -1
  80. package/dist/core/constants/addresses.js +9 -4
  81. package/dist/core/constants/addresses.js.map +1 -1
  82. package/dist/core/constants/borrowConstants.d.ts +10 -0
  83. package/dist/core/constants/borrowConstants.d.ts.map +1 -0
  84. package/dist/core/constants/borrowConstants.js +16 -0
  85. package/dist/core/constants/borrowConstants.js.map +1 -0
  86. package/dist/core/constants/borrowRegistries.d.ts +7 -0
  87. package/dist/core/constants/borrowRegistries.d.ts.map +1 -0
  88. package/dist/core/constants/borrowRegistries.js +31 -0
  89. package/dist/core/constants/borrowRegistries.js.map +1 -0
  90. package/dist/core/constants/index.d.ts +2 -0
  91. package/dist/core/constants/index.d.ts.map +1 -1
  92. package/dist/core/constants/index.js +2 -0
  93. package/dist/core/constants/index.js.map +1 -1
  94. package/dist/core/errors/index.d.ts +1 -0
  95. package/dist/core/errors/index.d.ts.map +1 -1
  96. package/dist/core/errors/index.js +1 -0
  97. package/dist/core/errors/index.js.map +1 -1
  98. package/dist/core/errors/oracle.d.ts +9 -0
  99. package/dist/core/errors/oracle.d.ts.map +1 -0
  100. package/dist/core/errors/oracle.js +15 -0
  101. package/dist/core/errors/oracle.js.map +1 -0
  102. package/dist/core/errors/router.d.ts +6 -0
  103. package/dist/core/errors/router.d.ts.map +1 -1
  104. package/dist/core/errors/router.js +11 -1
  105. package/dist/core/errors/router.js.map +1 -1
  106. package/dist/core/types/borrow.d.ts +87 -0
  107. package/dist/core/types/borrow.d.ts.map +1 -0
  108. package/dist/core/types/borrow.js +3 -0
  109. package/dist/core/types/borrow.js.map +1 -0
  110. package/dist/core/types/contractAddresses.d.ts +2 -0
  111. package/dist/core/types/contractAddresses.d.ts.map +1 -1
  112. package/dist/core/types/index.d.ts +5 -1
  113. package/dist/core/types/index.d.ts.map +1 -1
  114. package/dist/core/types/index.js +5 -1
  115. package/dist/core/types/index.js.map +1 -1
  116. package/dist/core/types/liquidity.d.ts +117 -0
  117. package/dist/core/types/liquidity.d.ts.map +1 -0
  118. package/dist/core/types/liquidity.js +3 -0
  119. package/dist/core/types/liquidity.js.map +1 -0
  120. package/dist/core/types/pool.d.ts +110 -0
  121. package/dist/core/types/pool.d.ts.map +1 -1
  122. package/dist/core/types/provider.d.ts.map +1 -1
  123. package/dist/core/types/provider.js +0 -1
  124. package/dist/core/types/provider.js.map +1 -1
  125. package/dist/core/types/route.d.ts +3 -3
  126. package/dist/core/types/route.d.ts.map +1 -1
  127. package/dist/core/types/token.d.ts +13 -3
  128. package/dist/core/types/token.d.ts.map +1 -1
  129. package/dist/core/types/tradingLimits.d.ts +91 -0
  130. package/dist/core/types/tradingLimits.d.ts.map +1 -0
  131. package/dist/core/types/tradingLimits.js +3 -0
  132. package/dist/core/types/tradingLimits.js.map +1 -0
  133. package/dist/core/types/tradingMode.d.ts +24 -0
  134. package/dist/core/types/tradingMode.d.ts.map +1 -0
  135. package/dist/core/types/tradingMode.js +31 -0
  136. package/dist/core/types/tradingMode.js.map +1 -0
  137. package/dist/core/types/transaction.d.ts +45 -0
  138. package/dist/core/types/transaction.d.ts.map +1 -0
  139. package/dist/core/types/transaction.js +3 -0
  140. package/dist/core/types/transaction.js.map +1 -0
  141. package/dist/index.d.ts +34 -8
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js +47 -10
  144. package/dist/index.js.map +1 -1
  145. package/dist/services/borrow/BorrowService.d.ts +54 -0
  146. package/dist/services/borrow/BorrowService.d.ts.map +1 -0
  147. package/dist/services/borrow/BorrowService.js +129 -0
  148. package/dist/services/borrow/BorrowService.js.map +1 -0
  149. package/dist/services/borrow/borrowHelpers.d.ts +4 -0
  150. package/dist/services/borrow/borrowHelpers.d.ts.map +1 -0
  151. package/dist/services/borrow/borrowHelpers.js +13 -0
  152. package/dist/services/borrow/borrowHelpers.js.map +1 -0
  153. package/dist/services/borrow/borrowMath.d.ts +13 -0
  154. package/dist/services/borrow/borrowMath.d.ts.map +1 -0
  155. package/dist/services/borrow/borrowMath.js +129 -0
  156. package/dist/services/borrow/borrowMath.js.map +1 -0
  157. package/dist/services/borrow/index.d.ts +2 -0
  158. package/dist/services/borrow/index.d.ts.map +1 -0
  159. package/dist/services/borrow/index.js +18 -0
  160. package/dist/services/borrow/index.js.map +1 -0
  161. package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
  162. package/dist/services/borrow/internal/borrowApprovalService.d.ts.map +1 -0
  163. package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
  164. package/dist/services/borrow/internal/borrowApprovalService.js.map +1 -0
  165. package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
  166. package/dist/services/borrow/internal/borrowContextStore.d.ts.map +1 -0
  167. package/dist/services/borrow/internal/borrowContextStore.js +40 -0
  168. package/dist/services/borrow/internal/borrowContextStore.js.map +1 -0
  169. package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
  170. package/dist/services/borrow/internal/borrowErc20.d.ts.map +1 -0
  171. package/dist/services/borrow/internal/borrowErc20.js +43 -0
  172. package/dist/services/borrow/internal/borrowErc20.js.map +1 -0
  173. package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
  174. package/dist/services/borrow/internal/borrowHints.d.ts.map +1 -0
  175. package/dist/services/borrow/internal/borrowHints.js +31 -0
  176. package/dist/services/borrow/internal/borrowHints.js.map +1 -0
  177. package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
  178. package/dist/services/borrow/internal/borrowPositionParser.d.ts.map +1 -0
  179. package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
  180. package/dist/services/borrow/internal/borrowPositionParser.js.map +1 -0
  181. package/dist/services/borrow/internal/borrowReadService.d.ts +28 -0
  182. package/dist/services/borrow/internal/borrowReadService.d.ts.map +1 -0
  183. package/dist/services/borrow/internal/borrowReadService.js +218 -0
  184. package/dist/services/borrow/internal/borrowReadService.js.map +1 -0
  185. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
  186. package/dist/services/borrow/internal/borrowRegistryReader.d.ts.map +1 -0
  187. package/dist/services/borrow/internal/borrowRegistryReader.js +96 -0
  188. package/dist/services/borrow/internal/borrowRegistryReader.js.map +1 -0
  189. package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
  190. package/dist/services/borrow/internal/borrowTransactionService.d.ts.map +1 -0
  191. package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
  192. package/dist/services/borrow/internal/borrowTransactionService.js.map +1 -0
  193. package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
  194. package/dist/services/borrow/internal/borrowTypes.d.ts.map +1 -0
  195. package/dist/services/borrow/internal/borrowTypes.js +3 -0
  196. package/dist/services/borrow/internal/borrowTypes.js.map +1 -0
  197. package/dist/services/borrow/internal/borrowValidation.d.ts +13 -0
  198. package/dist/services/borrow/internal/borrowValidation.d.ts.map +1 -0
  199. package/dist/services/borrow/internal/borrowValidation.js +96 -0
  200. package/dist/services/borrow/internal/borrowValidation.js.map +1 -0
  201. package/dist/services/index.d.ts +2 -0
  202. package/dist/services/index.d.ts.map +1 -1
  203. package/dist/services/index.js +2 -0
  204. package/dist/services/index.js.map +1 -1
  205. package/dist/services/liquidity/LiquidityService.d.ts +154 -0
  206. package/dist/services/liquidity/LiquidityService.d.ts.map +1 -0
  207. package/dist/services/liquidity/LiquidityService.js +184 -0
  208. package/dist/services/liquidity/LiquidityService.js.map +1 -0
  209. package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
  210. package/dist/services/liquidity/basicLiquidity.d.ts.map +1 -0
  211. package/dist/services/liquidity/basicLiquidity.js +172 -0
  212. package/dist/services/liquidity/basicLiquidity.js.map +1 -0
  213. package/dist/services/liquidity/index.d.ts +2 -0
  214. package/dist/services/liquidity/index.d.ts.map +1 -0
  215. package/dist/services/liquidity/index.js +18 -0
  216. package/dist/services/liquidity/index.js.map +1 -0
  217. package/dist/services/liquidity/liquidityHelpers.d.ts +13 -0
  218. package/dist/services/liquidity/liquidityHelpers.d.ts.map +1 -0
  219. package/dist/services/liquidity/liquidityHelpers.js +74 -0
  220. package/dist/services/liquidity/liquidityHelpers.js.map +1 -0
  221. package/dist/services/liquidity/zapHelpers.d.ts +66 -0
  222. package/dist/services/liquidity/zapHelpers.d.ts.map +1 -0
  223. package/dist/services/liquidity/zapHelpers.js +133 -0
  224. package/dist/services/liquidity/zapHelpers.js.map +1 -0
  225. package/dist/services/liquidity/zapIn.d.ts +17 -0
  226. package/dist/services/liquidity/zapIn.d.ts.map +1 -0
  227. package/dist/services/liquidity/zapIn.js +125 -0
  228. package/dist/services/liquidity/zapIn.js.map +1 -0
  229. package/dist/services/liquidity/zapOut.d.ts +17 -0
  230. package/dist/services/liquidity/zapOut.d.ts.map +1 -0
  231. package/dist/services/liquidity/zapOut.js +242 -0
  232. package/dist/services/liquidity/zapOut.js.map +1 -0
  233. package/dist/services/pools/PoolService.d.ts +35 -10
  234. package/dist/services/pools/PoolService.d.ts.map +1 -1
  235. package/dist/services/pools/PoolService.js +61 -109
  236. package/dist/services/pools/PoolService.js.map +1 -1
  237. package/dist/services/pools/poolDetails.d.ts +11 -0
  238. package/dist/services/pools/poolDetails.d.ts.map +1 -0
  239. package/dist/services/pools/poolDetails.js +145 -0
  240. package/dist/services/pools/poolDetails.js.map +1 -0
  241. package/dist/services/pools/poolDiscovery.d.ts +12 -0
  242. package/dist/services/pools/poolDiscovery.d.ts.map +1 -0
  243. package/dist/services/pools/poolDiscovery.js +114 -0
  244. package/dist/services/pools/poolDiscovery.js.map +1 -0
  245. package/dist/services/quotes/QuoteService.d.ts +21 -12
  246. package/dist/services/quotes/QuoteService.d.ts.map +1 -1
  247. package/dist/services/quotes/QuoteService.js +41 -17
  248. package/dist/services/quotes/QuoteService.js.map +1 -1
  249. package/dist/services/routes/RouteService.d.ts +3 -3
  250. package/dist/services/routes/RouteService.d.ts.map +1 -1
  251. package/dist/services/routes/RouteService.js +3 -5
  252. package/dist/services/routes/RouteService.js.map +1 -1
  253. package/dist/services/swap/SwapService.d.ts +23 -19
  254. package/dist/services/swap/SwapService.d.ts.map +1 -1
  255. package/dist/services/swap/SwapService.js +36 -15
  256. package/dist/services/swap/SwapService.js.map +1 -1
  257. package/dist/services/tokens/supplyAdjustmentService.d.ts +0 -4
  258. package/dist/services/tokens/supplyAdjustmentService.d.ts.map +1 -1
  259. package/dist/services/tokens/supplyAdjustmentService.js +3 -8
  260. package/dist/services/tokens/supplyAdjustmentService.js.map +1 -1
  261. package/dist/services/tokens/tokenService.d.ts.map +1 -1
  262. package/dist/services/tokens/tokenService.js +2 -2
  263. package/dist/services/tokens/tokenService.js.map +1 -1
  264. package/dist/services/trading/TradingLimitsService.d.ts +38 -0
  265. package/dist/services/trading/TradingLimitsService.d.ts.map +1 -0
  266. package/dist/services/trading/TradingLimitsService.js +157 -0
  267. package/dist/services/trading/TradingLimitsService.js.map +1 -0
  268. package/dist/services/trading/TradingService.d.ts +110 -0
  269. package/dist/services/trading/TradingService.d.ts.map +1 -0
  270. package/dist/services/trading/TradingService.js +162 -0
  271. package/dist/services/trading/TradingService.js.map +1 -0
  272. package/dist/services/trading/index.d.ts +3 -0
  273. package/dist/services/trading/index.d.ts.map +1 -0
  274. package/dist/services/trading/index.js +19 -0
  275. package/dist/services/trading/index.js.map +1 -0
  276. package/dist/utils/costUtils.js +4 -4
  277. package/dist/utils/costUtils.js.map +1 -1
  278. package/dist/utils/deadline.d.ts +21 -0
  279. package/dist/utils/deadline.d.ts.map +1 -0
  280. package/dist/utils/deadline.js +26 -0
  281. package/dist/utils/deadline.js.map +1 -0
  282. package/dist/utils/index.d.ts +3 -0
  283. package/dist/utils/index.d.ts.map +1 -1
  284. package/dist/utils/index.js +3 -0
  285. package/dist/utils/index.js.map +1 -1
  286. package/dist/utils/pathEncoder.d.ts +8 -2
  287. package/dist/utils/pathEncoder.d.ts.map +1 -1
  288. package/dist/utils/pathEncoder.js +19 -3
  289. package/dist/utils/pathEncoder.js.map +1 -1
  290. package/dist/utils/rateFeed.d.ts +18 -0
  291. package/dist/utils/rateFeed.d.ts.map +1 -0
  292. package/dist/utils/rateFeed.js +27 -0
  293. package/dist/utils/rateFeed.js.map +1 -0
  294. package/dist/utils/routeUtils.d.ts +53 -53
  295. package/dist/utils/routeUtils.d.ts.map +1 -1
  296. package/dist/utils/routeUtils.js +41 -41
  297. package/dist/utils/routeUtils.js.map +1 -1
  298. package/dist/utils/routes.d.ts +2 -8
  299. package/dist/utils/routes.d.ts.map +1 -1
  300. package/dist/utils/routes.js +5 -46
  301. package/dist/utils/routes.js.map +1 -1
  302. package/dist/utils/tokens.d.ts +1 -77
  303. package/dist/utils/tokens.d.ts.map +1 -1
  304. package/dist/utils/tokens.js +10 -178
  305. package/dist/utils/tokens.js.map +1 -1
  306. package/dist/utils/tradingLimits.d.ts +41 -0
  307. package/dist/utils/tradingLimits.d.ts.map +1 -0
  308. package/dist/utils/tradingLimits.js +171 -0
  309. package/dist/utils/tradingLimits.js.map +1 -0
  310. package/dist/utils/validation.d.ts +19 -0
  311. package/dist/utils/validation.d.ts.map +1 -0
  312. package/dist/utils/validation.js +34 -0
  313. package/dist/utils/validation.js.map +1 -0
  314. package/package.json +3 -1
  315. package/dist/cache/routes.11142220.js +0 -1
  316. package/dist/cache/routes.42220.d.ts +0 -3
  317. package/dist/cache/routes.42220.d.ts.map +0 -1
  318. package/dist/cache/routes.42220.js +0 -112
  319. package/dist/cache/routes.42220.js.map +0 -1
  320. package/dist/cache/tokens.11142220.d.ts +0 -3
  321. package/dist/cache/tokens.11142220.d.ts.map +0 -1
  322. package/dist/cache/tokens.11142220.js +0 -129
  323. package/dist/cache/tokens.11142220.js.map +0 -1
  324. package/dist/cache/tokens.42220.d.ts +0 -3
  325. package/dist/cache/tokens.42220.d.ts.map +0 -1
  326. package/dist/cache/tokens.42220.js +0 -129
  327. package/dist/cache/tokens.42220.js.map +0 -1
@@ -1,5 +1,12 @@
1
- import { Pool } from '../../core/types';
1
+ import { Pool, PoolDetails } from '../../core/types';
2
2
  import { PublicClient } from 'viem';
3
+ /**
4
+ * Result of pool discovery including any warnings from failed factories
5
+ */
6
+ export interface PoolDiscoveryResult {
7
+ pools: Pool[];
8
+ warnings: string[];
9
+ }
3
10
  /**
4
11
  * Service for discovering liquidity pools in the Mento protocol.
5
12
  * Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
@@ -8,13 +15,19 @@ export declare class PoolService {
8
15
  private publicClient;
9
16
  private chainId;
10
17
  private poolsCache;
18
+ private discoveryWarnings;
11
19
  constructor(publicClient: PublicClient, chainId: number);
20
+ /**
21
+ * Returns any warnings from the last pool discovery operation.
22
+ * Useful for debugging when some factories fail but others succeed.
23
+ */
24
+ getDiscoveryWarnings(): string[];
12
25
  /**
13
26
  * Fetches all pools available in the protocol from both FPMM and Virtual pool factories
14
27
  * Results are cached in memory for the service instance lifetime
15
28
  *
16
29
  * @returns Array of all pools available in the protocol
17
- * @throws {Error} If RPC call fails or pools are unavailable
30
+ * @throws {Error} If no pools can be discovered from any factory
18
31
  *
19
32
  * @example
20
33
  * ```typescript
@@ -24,14 +37,26 @@ export declare class PoolService {
24
37
  */
25
38
  getPools(): Promise<Pool[]>;
26
39
  /**
27
- * Fetches all FPMM pools from the FPMM Factory
28
- */
29
- private fetchFPMMPools;
30
- /**
31
- * Fetches all Virtual pools by discovering them from BiPoolManager exchanges.
32
- * VirtualPoolFactory doesn't have an enumeration method,
33
- * so we have to derive pools from BiPoolManager.
40
+ * Fetches enriched on-chain details for a specific pool by address.
41
+ * Resolves the pool type from the discovery cache, then fetches
42
+ * pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
43
+ *
44
+ * @param poolAddr - The deployed pool contract address
45
+ * @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
46
+ * @throws {Error} If the pool address is not found in any known factory
47
+ * @throws {Error} If on-chain calls fail
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const details = await poolService.getPoolDetails('0x...')
52
+ * if (details.poolType === 'FPMM') {
53
+ * console.log(details.pricing.oraclePrice)
54
+ * console.log(details.rebalancing.inBand)
55
+ * } else {
56
+ * console.log(details.spreadPercent)
57
+ * }
58
+ * ```
34
59
  */
35
- private fetchVirtualPools;
60
+ getPoolDetails(poolAddr: string): Promise<PoolDetails>;
36
61
  }
37
62
  //# sourceMappingURL=PoolService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,kBAAkB,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAW,MAAM,MAAM,CAAA;AAK5C;;;GAGG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAF/D,OAAO,CAAC,UAAU,CAAsB;gBAEpB,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBjC;;OAEG;YACW,cAAc;IAkD5B;;;;OAIG;YACW,iBAAiB;CAmEhC"}
1
+ {"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAY,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAInC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;GAGG;AACH,qBAAa,WAAW;IAIV,OAAO,CAAC,YAAY;IAAgB,OAAO,CAAC,OAAO;IAH/D,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,iBAAiB,CAAe;gBAEpB,YAAY,EAAE,YAAY,EAAU,OAAO,EAAE,MAAM;IAEvE;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;;;;;;;;;;;OAYG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IA2CjC;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAc7D"}
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PoolService = void 0;
4
- const constants_1 = require("../../core/constants");
5
4
  const types_1 = require("../../core/types");
6
- const abis_1 = require("../../core/abis");
7
- const sortUtils_1 = require("../../utils/sortUtils");
8
- // TODO: Update to enrich pools with more data as needed. Use optional flag to include more data.
5
+ const poolDiscovery_1 = require("./poolDiscovery");
6
+ const poolDetails_1 = require("./poolDetails");
9
7
  /**
10
8
  * Service for discovering liquidity pools in the Mento protocol.
11
9
  * Aggregates pools from multiple factory contracts (FPMM and VirtualPool).
@@ -15,13 +13,21 @@ class PoolService {
15
13
  this.publicClient = publicClient;
16
14
  this.chainId = chainId;
17
15
  this.poolsCache = null;
16
+ this.discoveryWarnings = [];
17
+ }
18
+ /**
19
+ * Returns any warnings from the last pool discovery operation.
20
+ * Useful for debugging when some factories fail but others succeed.
21
+ */
22
+ getDiscoveryWarnings() {
23
+ return [...this.discoveryWarnings];
18
24
  }
19
25
  /**
20
26
  * Fetches all pools available in the protocol from both FPMM and Virtual pool factories
21
27
  * Results are cached in memory for the service instance lifetime
22
28
  *
23
29
  * @returns Array of all pools available in the protocol
24
- * @throws {Error} If RPC call fails or pools are unavailable
30
+ * @throws {Error} If no pools can be discovered from any factory
25
31
  *
26
32
  * @example
27
33
  * ```typescript
@@ -37,120 +43,66 @@ class PoolService {
37
43
  // for dynamic factory discovery. For now we will use
38
44
  // the hardcoded factory addresses for the chain for v1.
39
45
  const pools = [];
40
- const fpmmPools = await this.fetchFPMMPools();
41
- pools.push(...fpmmPools);
42
- const virtualPools = await this.fetchVirtualPools();
43
- pools.push(...virtualPools);
44
- this.poolsCache = pools;
45
- return pools;
46
- }
47
- /**
48
- * Fetches all FPMM pools from the FPMM Factory
49
- */
50
- async fetchFPMMPools() {
51
- const fpmmFactoryAddress = (0, constants_1.getContractAddress)(this.chainId, 'FPMMFactory');
52
- if (!fpmmFactoryAddress) {
53
- console.warn('FPMM Factory address not found for this chain');
54
- return [];
46
+ const warnings = [];
47
+ try {
48
+ const fpmmPools = await (0, poolDiscovery_1.fetchFPMMPools)(this.publicClient, this.chainId);
49
+ pools.push(...fpmmPools);
50
+ }
51
+ catch (error) {
52
+ const message = `Failed to fetch FPMM pools: ${error instanceof Error ? error.message : String(error)}`;
53
+ console.warn(`[PoolService] ${message}`);
54
+ warnings.push(message);
55
55
  }
56
56
  try {
57
- // Get all deployed FPMM pool addresses
58
- const poolAddresses = (await this.publicClient.readContract({
59
- address: fpmmFactoryAddress,
60
- abi: abis_1.FPMM_FACTORY_ABI,
61
- functionName: 'deployedFPMMAddresses',
62
- }));
63
- if (poolAddresses.length === 0) {
64
- return [];
65
- }
66
- const poolDataPromises = poolAddresses.map(async (poolAddress) => {
67
- const [token0, token1] = await Promise.all([
68
- this.publicClient.readContract({
69
- address: poolAddress,
70
- abi: abis_1.FPMM_ABI,
71
- functionName: 'token0',
72
- }),
73
- this.publicClient.readContract({
74
- address: poolAddress,
75
- abi: abis_1.FPMM_ABI,
76
- functionName: 'token1',
77
- }),
78
- ]);
79
- return {
80
- factoryAddr: fpmmFactoryAddress,
81
- poolAddr: poolAddress,
82
- token0: token0,
83
- token1: token1,
84
- poolType: types_1.PoolType.FPMM,
85
- };
86
- });
87
- return await Promise.all(poolDataPromises);
57
+ const virtualPools = await (0, poolDiscovery_1.fetchVirtualPools)(this.publicClient, this.chainId);
58
+ pools.push(...virtualPools);
88
59
  }
89
60
  catch (error) {
90
- console.error('Failed to fetch FPMM pools:', error);
91
- throw new Error(`Failed to fetch FPMM pools: ${error.message}`);
61
+ const message = `Failed to fetch Virtual pools: ${error instanceof Error ? error.message : String(error)}`;
62
+ console.warn(`[PoolService] ${message}`);
63
+ warnings.push(message);
92
64
  }
65
+ this.discoveryWarnings = warnings;
66
+ // Only throw if NO pools were discovered from any factory
67
+ if (pools.length === 0) {
68
+ throw new Error('Failed to discover any pools from any factory. ' +
69
+ 'All pool factory queries failed. Check network connectivity and RPC endpoint.');
70
+ }
71
+ this.poolsCache = pools;
72
+ return pools;
93
73
  }
94
74
  /**
95
- * Fetches all Virtual pools by discovering them from BiPoolManager exchanges.
96
- * VirtualPoolFactory doesn't have an enumeration method,
97
- * so we have to derive pools from BiPoolManager.
75
+ * Fetches enriched on-chain details for a specific pool by address.
76
+ * Resolves the pool type from the discovery cache, then fetches
77
+ * pool-type-specific data (pricing, fees, rebalancing for FPMM; reserves and spread for Virtual).
78
+ *
79
+ * @param poolAddr - The deployed pool contract address
80
+ * @returns Enriched pool details (FPMMPoolDetails or VirtualPoolDetails)
81
+ * @throws {Error} If the pool address is not found in any known factory
82
+ * @throws {Error} If on-chain calls fail
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const details = await poolService.getPoolDetails('0x...')
87
+ * if (details.poolType === 'FPMM') {
88
+ * console.log(details.pricing.oraclePrice)
89
+ * console.log(details.rebalancing.inBand)
90
+ * } else {
91
+ * console.log(details.spreadPercent)
92
+ * }
93
+ * ```
98
94
  */
99
- async fetchVirtualPools() {
100
- const virtualPoolFactoryAddress = (0, constants_1.getContractAddress)(this.chainId, 'VirtualPoolFactory');
101
- const biPoolManagerAddress = (0, constants_1.getContractAddress)(this.chainId, 'BiPoolManager');
102
- if (!virtualPoolFactoryAddress || !biPoolManagerAddress) {
103
- console.warn('VirtualPoolFactory or BiPoolManager address not found for this chain');
104
- return [];
95
+ async getPoolDetails(poolAddr) {
96
+ const pools = await this.getPools();
97
+ const pool = pools.find((p) => p.poolAddr.toLowerCase() === poolAddr.toLowerCase());
98
+ if (!pool) {
99
+ throw new Error(`Pool not found: ${poolAddr}. ` + 'Ensure the address is a valid pool discovered by getPools().');
105
100
  }
106
- try {
107
- // TODO: When new virtual pool factory is deployed
108
- // we can simplify this by using VirtualPoolFactory.getAllPools() returns(address[])
109
- // Get all exchanges from BiPoolManager
110
- const exchangesData = (await this.publicClient.readContract({
111
- address: biPoolManagerAddress,
112
- abi: abis_1.BIPOOL_MANAGER_ABI,
113
- functionName: 'getExchanges',
114
- }));
115
- if (exchangesData.length === 0) {
116
- return [];
117
- }
118
- // For each exchange, check if a virtual pool exists, and if so, return the pool address.
119
- const poolPromises = exchangesData.map(async (exchange) => {
120
- if (exchange.assets.length !== 2) {
121
- console.warn(`Skipping invalid exchange ${exchange.exchangeId}: expected 2 assets`);
122
- return null;
123
- }
124
- const [token0, token1] = (0, sortUtils_1.sortTokenAddresses)(exchange.assets[0], exchange.assets[1]);
125
- const poolAddress = (await this.publicClient.readContract({
126
- address: virtualPoolFactoryAddress,
127
- abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
128
- functionName: 'getOrPrecomputeProxyAddress',
129
- args: [token0, token1],
130
- }));
131
- const isDeployed = (await this.publicClient.readContract({
132
- address: virtualPoolFactoryAddress,
133
- abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
134
- functionName: 'isPool',
135
- args: [poolAddress],
136
- }));
137
- if (!isDeployed) {
138
- return null;
139
- }
140
- return {
141
- factoryAddr: virtualPoolFactoryAddress,
142
- poolAddr: poolAddress,
143
- token0: token0,
144
- token1: token1,
145
- poolType: types_1.PoolType.Virtual,
146
- };
147
- });
148
- const results = await Promise.all(poolPromises);
149
- return results.filter((pool) => pool !== null);
101
+ if (pool.poolType === types_1.PoolType.FPMM) {
102
+ return (0, poolDetails_1.fetchFPMMPoolDetails)(this.publicClient, this.chainId, pool);
150
103
  }
151
- catch (error) {
152
- console.error('Failed to fetch Virtual pools:', error);
153
- throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
104
+ else {
105
+ return (0, poolDetails_1.fetchVirtualPoolDetails)(this.publicClient, pool);
154
106
  }
155
107
  }
156
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PoolService.js","sourceRoot":"","sources":["../../../src/services/pools/PoolService.ts"],"names":[],"mappings":";;;AAAA,oDAAkE;AAClE,4CAAiD;AACjD,0CAA0G;AAE1G,qDAA0D;AAE1D,iGAAiG;AAEjG;;;GAGG;AACH,MAAa,WAAW;IAGtB,YAAoB,YAA0B,EAAU,OAAe;QAAnD,iBAAY,GAAZ,YAAY,CAAc;QAAU,YAAO,GAAP,OAAO,CAAQ;QAF/D,eAAU,GAAkB,IAAI,CAAA;IAEkC,CAAC;IAE3E;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED,6DAA6D;QAC7D,2DAA2D;QAC3D,8DAA8D;QAC9D,MAAM,KAAK,GAAW,EAAE,CAAA;QAExB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;QAC7C,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAA;QAExB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAA;QACnD,KAAK,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAA;QAE3B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;QACvB,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,cAAc;QAC1B,MAAM,kBAAkB,GAAG,IAAA,8BAAkB,EAAC,IAAI,CAAC,OAAk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aAAM,CAAC;YACN,OAAO,IAAA,qCAAuB,EAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;QACzD,CAAC;IACH,CAAC;CACF;AAzGD,kCAyGC"}
@@ -0,0 +1,11 @@
1
+ import { Pool, FPMMPoolDetails, VirtualPoolDetails } from '../../core/types';
2
+ import { PublicClient } from 'viem';
3
+ /**
4
+ * Fetches enriched details for an FPMM pool
5
+ */
6
+ export declare function fetchFPMMPoolDetails(publicClient: PublicClient, chainId: number, pool: Pool): Promise<FPMMPoolDetails>;
7
+ /**
8
+ * Fetches enriched details for a Virtual pool
9
+ */
10
+ export declare function fetchVirtualPoolDetails(publicClient: PublicClient, pool: Pool): Promise<VirtualPoolDetails>;
11
+ //# sourceMappingURL=poolDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolDetails.d.ts","sourceRoot":"","sources":["../../../src/services/pools/poolDetails.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,eAAe,EAAe,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAEzF,OAAO,EAAE,YAAY,EAAW,MAAM,MAAM,CAAA;AAE5C;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,eAAe,CAAC,CAmH1B;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA4BjH"}
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchFPMMPoolDetails = fetchFPMMPoolDetails;
4
+ exports.fetchVirtualPoolDetails = fetchVirtualPoolDetails;
5
+ const constants_1 = require("../../core/constants");
6
+ const abis_1 = require("../../core/abis");
7
+ /**
8
+ * Fetches enriched details for an FPMM pool
9
+ */
10
+ async function fetchFPMMPoolDetails(publicClient, chainId, pool) {
11
+ const address = pool.poolAddr;
12
+ try {
13
+ // Known liquidity strategy addresses for this chain
14
+ const knownStrategies = getKnownLiquidityStrategies(chainId);
15
+ // Fetch core data
16
+ const [reservesResult, decimals0, decimals1, lpFee, protocolFee, rebalanceIncentive, rebalanceThresholdAbove, rebalanceThresholdBelow, ...strategyResults] = await Promise.all([
17
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'getReserves' }),
18
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'decimals0' }),
19
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'decimals1' }),
20
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'lpFee' }),
21
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'protocolFee' }),
22
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceIncentive' }),
23
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceThresholdAbove' }),
24
+ publicClient.readContract({ address, abi: abis_1.FPMM_ABI, functionName: 'rebalanceThresholdBelow' }),
25
+ ...knownStrategies.map((strategyAddr) => publicClient.readContract({
26
+ address,
27
+ abi: abis_1.FPMM_ABI,
28
+ functionName: 'liquidityStrategy',
29
+ args: [strategyAddr],
30
+ })),
31
+ ]);
32
+ const [reserve0, reserve1, blockTimestampLast] = reservesResult;
33
+ const lpFeeBps = lpFee;
34
+ const protocolFeeBps = protocolFee;
35
+ const rebalanceIncentiveBps = rebalanceIncentive;
36
+ const thresholdAboveBps = rebalanceThresholdAbove;
37
+ const thresholdBelowBps = rebalanceThresholdBelow;
38
+ // Find the active liquidity strategy (first match wins)
39
+ const activeIndex = strategyResults.findIndex((result) => result === true);
40
+ const liquidityStrategy = activeIndex >= 0 ? knownStrategies[activeIndex] : null;
41
+ // Fetch pricing separately — graceful degradation when FX market is closed
42
+ let pricing = null;
43
+ let inBand = null;
44
+ try {
45
+ const rebalancingStateResult = await publicClient.readContract({
46
+ address,
47
+ abi: abis_1.FPMM_ABI,
48
+ functionName: 'getRebalancingState',
49
+ });
50
+ const [oraclePriceNum, oraclePriceDen, reservePriceNum, reservePriceDen, reservePriceAboveOraclePrice, rebalanceThreshold, priceDifference,] = rebalancingStateResult;
51
+ pricing = {
52
+ oraclePriceNum,
53
+ oraclePriceDen,
54
+ oraclePrice: Number(oraclePriceNum) / Number(oraclePriceDen),
55
+ reservePriceNum,
56
+ reservePriceDen,
57
+ reservePrice: Number(reservePriceNum) / Number(reservePriceDen),
58
+ priceDifferenceBps: priceDifference,
59
+ priceDifferencePercent: Number(priceDifference) / 100,
60
+ reservePriceAboveOraclePrice,
61
+ };
62
+ inBand = priceDifference < BigInt(rebalanceThreshold);
63
+ }
64
+ catch {
65
+ // getRebalancingState() failed (likely FXMarketClosed) — pricing stays null
66
+ }
67
+ return {
68
+ ...pool,
69
+ poolType: 'FPMM',
70
+ scalingFactor0: decimals0,
71
+ scalingFactor1: decimals1,
72
+ reserve0,
73
+ reserve1,
74
+ blockTimestampLast,
75
+ pricing,
76
+ fees: {
77
+ lpFeeBps,
78
+ lpFeePercent: Number(lpFeeBps) / 100,
79
+ protocolFeeBps,
80
+ protocolFeePercent: Number(protocolFeeBps) / 100,
81
+ totalFeePercent: (Number(lpFeeBps) + Number(protocolFeeBps)) / 100,
82
+ },
83
+ rebalancing: {
84
+ rebalanceIncentiveBps,
85
+ rebalanceIncentivePercent: Number(rebalanceIncentiveBps) / 100,
86
+ rebalanceThresholdAboveBps: thresholdAboveBps,
87
+ rebalanceThresholdAbovePercent: Number(thresholdAboveBps) / 100,
88
+ rebalanceThresholdBelowBps: thresholdBelowBps,
89
+ rebalanceThresholdBelowPercent: Number(thresholdBelowBps) / 100,
90
+ inBand,
91
+ liquidityStrategy,
92
+ },
93
+ };
94
+ }
95
+ catch (error) {
96
+ throw new Error(`Failed to fetch FPMM pool details for ${pool.poolAddr}: ${error.message}`);
97
+ }
98
+ }
99
+ /**
100
+ * Fetches enriched details for a Virtual pool
101
+ */
102
+ async function fetchVirtualPoolDetails(publicClient, pool) {
103
+ const address = pool.poolAddr;
104
+ try {
105
+ const [reservesResult, protocolFee, metadataResult] = await Promise.all([
106
+ publicClient.readContract({ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'getReserves' }),
107
+ publicClient.readContract({ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'protocolFee' }),
108
+ publicClient.readContract({ address, abi: abis_1.VIRTUAL_POOL_ABI, functionName: 'metadata' }),
109
+ ]);
110
+ const [reserve0, reserve1, blockTimestampLast] = reservesResult;
111
+ const [dec0, dec1] = metadataResult;
112
+ const spreadBps = protocolFee;
113
+ return {
114
+ ...pool,
115
+ poolType: 'Virtual',
116
+ scalingFactor0: dec0,
117
+ scalingFactor1: dec1,
118
+ reserve0,
119
+ reserve1,
120
+ blockTimestampLast,
121
+ spreadBps,
122
+ spreadPercent: Number(spreadBps) / 100,
123
+ };
124
+ }
125
+ catch (error) {
126
+ throw new Error(`Failed to fetch Virtual pool details for ${pool.poolAddr}: ${error.message}`);
127
+ }
128
+ }
129
+ /**
130
+ * Returns the known liquidity strategy addresses for the given chain.
131
+ */
132
+ function getKnownLiquidityStrategies(chainId) {
133
+ const strategies = [];
134
+ const chainAddresses = constants_1.addresses[chainId];
135
+ if (!chainAddresses)
136
+ return strategies;
137
+ if (chainAddresses.ReserveLiquidityStrategy) {
138
+ strategies.push(chainAddresses.ReserveLiquidityStrategy);
139
+ }
140
+ if (chainAddresses.CDPLiquidityStrategy) {
141
+ strategies.push(chainAddresses.CDPLiquidityStrategy);
142
+ }
143
+ return strategies;
144
+ }
145
+ //# sourceMappingURL=poolDetails.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolDetails.js","sourceRoot":"","sources":["../../../src/services/pools/poolDetails.ts"],"names":[],"mappings":";;AAQA,oDAuHC;AAKD,0DA4BC;AAhKD,oDAAyD;AAEzD,0CAA4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qBAAS,CAAC,OAAkB,CAAC,CAAA;IACpD,IAAI,CAAC,cAAc;QAAE,OAAO,UAAU,CAAA;IAEtC,IAAI,cAAc,CAAC,wBAAwB,EAAE,CAAC;QAC5C,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAA;IAC1D,CAAC;IACD,IAAI,cAAc,CAAC,oBAAoB,EAAE,CAAC;QACxC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAA;IACtD,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Pool } from '../../core/types';
2
+ import { PublicClient } from 'viem';
3
+ /**
4
+ * Fetches all FPMM pools from the FPMM Factory
5
+ */
6
+ export declare function fetchFPMMPools(publicClient: PublicClient, chainId: number): Promise<Pool[]>;
7
+ /**
8
+ * Fetches all active Virtual pools from the VirtualPoolFactory,
9
+ * then resolves token pairs and exchange IDs from each pool and BiPoolManager.
10
+ */
11
+ export declare function fetchVirtualPools(publicClient: PublicClient, chainId: number): Promise<Pool[]>;
12
+ //# sourceMappingURL=poolDiscovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolDiscovery.d.ts","sourceRoot":"","sources":["../../../src/services/pools/poolDiscovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,kBAAkB,CAAA;AAQjD,OAAO,EAAE,YAAY,EAAW,MAAM,MAAM,CAAA;AAG5C;;GAEG;AACH,wBAAsB,cAAc,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CA8CjG;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CA8DpG"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchFPMMPools = fetchFPMMPools;
4
+ exports.fetchVirtualPools = fetchVirtualPools;
5
+ const constants_1 = require("../../core/constants");
6
+ const types_1 = require("../../core/types");
7
+ const abis_1 = require("../../core/abis");
8
+ const sortUtils_1 = require("../../utils/sortUtils");
9
+ /**
10
+ * Fetches all FPMM pools from the FPMM Factory
11
+ */
12
+ async function fetchFPMMPools(publicClient, chainId) {
13
+ const fpmmFactoryAddress = (0, constants_1.getContractAddress)(chainId, 'FPMMFactory');
14
+ if (!fpmmFactoryAddress) {
15
+ return [];
16
+ }
17
+ try {
18
+ // Get all deployed FPMM pool addresses
19
+ const poolAddresses = (await publicClient.readContract({
20
+ address: fpmmFactoryAddress,
21
+ abi: abis_1.FPMM_FACTORY_ABI,
22
+ functionName: 'deployedFPMMAddresses',
23
+ }));
24
+ if (poolAddresses.length === 0) {
25
+ return [];
26
+ }
27
+ const poolDataPromises = poolAddresses.map(async (poolAddress) => {
28
+ const [token0, token1] = await Promise.all([
29
+ publicClient.readContract({
30
+ address: poolAddress,
31
+ abi: abis_1.FPMM_ABI,
32
+ functionName: 'token0',
33
+ }),
34
+ publicClient.readContract({
35
+ address: poolAddress,
36
+ abi: abis_1.FPMM_ABI,
37
+ functionName: 'token1',
38
+ }),
39
+ ]);
40
+ return {
41
+ factoryAddr: fpmmFactoryAddress,
42
+ poolAddr: poolAddress,
43
+ token0: token0,
44
+ token1: token1,
45
+ poolType: types_1.PoolType.FPMM,
46
+ };
47
+ });
48
+ return await Promise.all(poolDataPromises);
49
+ }
50
+ catch (error) {
51
+ throw new Error(`Failed to fetch FPMM pools: ${error.message}`);
52
+ }
53
+ }
54
+ /**
55
+ * Fetches all active Virtual pools from the VirtualPoolFactory,
56
+ * then resolves token pairs and exchange IDs from each pool and BiPoolManager.
57
+ */
58
+ async function fetchVirtualPools(publicClient, chainId) {
59
+ const virtualPoolFactoryAddress = (0, constants_1.getContractAddress)(chainId, 'VirtualPoolFactory');
60
+ const biPoolManagerAddress = (0, constants_1.getContractAddress)(chainId, 'BiPoolManager');
61
+ if (!virtualPoolFactoryAddress || !biPoolManagerAddress) {
62
+ return [];
63
+ }
64
+ try {
65
+ // Fetch active pool addresses and all exchanges in parallel
66
+ const [poolAddresses, exchangesData] = await Promise.all([
67
+ publicClient.readContract({
68
+ address: virtualPoolFactoryAddress,
69
+ abi: abis_1.VIRTUAL_POOL_FACTORY_ABI,
70
+ functionName: 'getAllPools',
71
+ }),
72
+ publicClient.readContract({
73
+ address: biPoolManagerAddress,
74
+ abi: abis_1.BIPOOL_MANAGER_ABI,
75
+ functionName: 'getExchanges',
76
+ }),
77
+ ]);
78
+ if (poolAddresses.length === 0) {
79
+ return [];
80
+ }
81
+ // Build a lookup from sorted token pair to exchangeId
82
+ const tokenPairToExchangeId = new Map();
83
+ for (const exchange of exchangesData) {
84
+ if (exchange.assets.length === 2) {
85
+ const [t0, t1] = (0, sortUtils_1.sortTokenAddresses)(exchange.assets[0], exchange.assets[1]);
86
+ tokenPairToExchangeId.set(`${t0}:${t1}`, exchange.exchangeId);
87
+ }
88
+ }
89
+ // For each pool, read its token pair and match to an exchangeId
90
+ const poolPromises = poolAddresses.map(async (poolAddress) => {
91
+ const [token0, token1] = (await publicClient.readContract({
92
+ address: poolAddress,
93
+ abi: abis_1.VIRTUAL_POOL_ABI,
94
+ functionName: 'tokens',
95
+ }));
96
+ const [sorted0, sorted1] = (0, sortUtils_1.sortTokenAddresses)(token0, token1);
97
+ const exchangeId = tokenPairToExchangeId.get(`${sorted0}:${sorted1}`);
98
+ const pool = {
99
+ factoryAddr: virtualPoolFactoryAddress,
100
+ poolAddr: poolAddress,
101
+ token0: sorted0,
102
+ token1: sorted1,
103
+ poolType: types_1.PoolType.Virtual,
104
+ exchangeId,
105
+ };
106
+ return pool;
107
+ });
108
+ return await Promise.all(poolPromises);
109
+ }
110
+ catch (error) {
111
+ throw new Error(`Failed to fetch Virtual pools: ${error.message}`);
112
+ }
113
+ }
114
+ //# sourceMappingURL=poolDiscovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolDiscovery.js","sourceRoot":"","sources":["../../../src/services/pools/poolDiscovery.ts"],"names":[],"mappings":";;AAeA,wCA8CC;AAMD,8CA8DC;AAjID,oDAAkE;AAClE,4CAAiD;AACjD,0CAMwB;AAExB,qDAA0D;AAE1D;;GAEG;AACI,KAAK,UAAU,cAAc,CAAC,YAA0B,EAAE,OAAe;IAC9E,MAAM,kBAAkB,GAAG,IAAA,8BAAkB,EAAC,OAAkB,EAAE,aAAa,CAAC,CAAA;IAEhF,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,CAAC;QACH,uCAAuC;QACvC,MAAM,aAAa,GAAG,CAAC,MAAM,YAAY,CAAC,YAAY,CAAC;YACrD,OAAO,EAAE,kBAA6B;YACtC,GAAG,EAAE,uBAAgB;YACrB,YAAY,EAAE,uBAAuB;SACtC,CAAC,CAAc,CAAA;QAEhB,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,gBAAgB,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YAC/D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACzC,YAAY,CAAC,YAAY,CAAC;oBACxB,OAAO,EAAE,WAAW;oBACpB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,QAAQ;iBACvB,CAAqB;gBACtB,YAAY,CAAC,YAAY,CAAC;oBACxB,OAAO,EAAE,WAAW;oBACpB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,QAAQ;iBACvB,CAAqB;aACvB,CAAC,CAAA;YAEF,OAAO;gBACL,WAAW,EAAE,kBAAkB;gBAC/B,QAAQ,EAAE,WAAqB;gBAC/B,MAAM,EAAE,MAAgB;gBACxB,MA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