@mento-protocol/mento-sdk 3.2.3 → 3.2.4

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 (396) hide show
  1. package/dist/cache/routes.d.ts +13 -0
  2. package/dist/cache/routes.js +14089 -0
  3. package/dist/cache/tokens.d.ts +68 -0
  4. package/dist/cache/tokens.js +460 -0
  5. package/dist/core/abis/activePool.d.ts +2 -0
  6. package/dist/core/abis/activePool.js +14 -0
  7. package/dist/core/abis/addressesRegistry.d.ts +2 -0
  8. package/dist/core/abis/addressesRegistry.js +26 -0
  9. package/dist/core/abis/bipoolmanager.d.ts +34 -0
  10. package/dist/core/abis/bipoolmanager.js +72 -0
  11. package/dist/core/abis/borrowerOperations.d.ts +9 -0
  12. package/dist/core/abis/borrowerOperations.js +89 -0
  13. package/dist/core/abis/breakerbox.d.ts +13 -0
  14. package/dist/core/abis/breakerbox.js +8 -0
  15. package/dist/core/abis/broker.d.ts +2 -0
  16. package/dist/core/abis/broker.js +9 -0
  17. package/dist/core/abis/erc20.d.ts +9 -0
  18. package/dist/core/abis/erc20.js +21 -0
  19. package/dist/core/abis/fpmm.d.ts +270 -0
  20. package/dist/core/abis/fpmm.js +49 -0
  21. package/dist/core/abis/fpmmFactory.d.ts +85 -0
  22. package/dist/core/abis/fpmmFactory.js +26 -0
  23. package/dist/core/abis/hintHelpers.d.ts +2 -0
  24. package/dist/core/abis/hintHelpers.js +14 -0
  25. package/dist/core/abis/index.d.ts +22 -0
  26. package/dist/core/abis/index.js +38 -0
  27. package/dist/core/abis/liquidityStrategy.d.ts +132 -0
  28. package/dist/core/abis/liquidityStrategy.js +10 -0
  29. package/dist/core/abis/multiTroveGetter.d.ts +8 -0
  30. package/dist/core/abis/multiTroveGetter.js +15 -0
  31. package/dist/core/abis/priceFeed.d.ts +7 -0
  32. package/dist/core/abis/priceFeed.js +16 -0
  33. package/dist/core/abis/pricingmodule.d.ts +2 -0
  34. package/dist/core/abis/pricingmodule.js +6 -0
  35. package/dist/core/abis/reserve.d.ts +3 -0
  36. package/dist/core/abis/reserve.js +18 -0
  37. package/dist/core/abis/router.d.ts +521 -0
  38. package/dist/core/abis/router.js +45 -0
  39. package/dist/core/abis/sortedTroves.d.ts +2 -0
  40. package/dist/core/abis/sortedTroves.js +15 -0
  41. package/dist/core/abis/systemParams.d.ts +2 -0
  42. package/dist/core/abis/systemParams.js +14 -0
  43. package/dist/core/abis/troveManager.d.ts +2 -0
  44. package/dist/core/abis/troveManager.js +27 -0
  45. package/dist/core/abis/troveNFT.d.ts +2 -0
  46. package/dist/core/abis/troveNFT.js +9 -0
  47. package/dist/core/abis/virtualPool.d.ts +50 -0
  48. package/dist/core/abis/virtualPool.js +11 -0
  49. package/dist/core/abis/virtualPoolFactory.d.ts +59 -0
  50. package/dist/core/abis/virtualPoolFactory.js +17 -0
  51. package/dist/core/constants/addresses.d.ts +18 -0
  52. package/dist/core/constants/addresses.js +113 -0
  53. package/dist/core/constants/borrowConstants.d.ts +10 -0
  54. package/dist/core/constants/borrowConstants.js +16 -0
  55. package/dist/core/constants/borrowRegistries.d.ts +7 -0
  56. package/dist/core/constants/borrowRegistries.js +30 -0
  57. package/dist/core/constants/chainId.d.ts +7 -0
  58. package/dist/{cjs/enums → core/constants}/chainId.js +4 -1
  59. package/dist/core/constants/contractNames.d.ts +21 -0
  60. package/dist/core/constants/contractNames.js +24 -0
  61. package/dist/core/constants/index.d.ts +6 -0
  62. package/dist/core/constants/index.js +22 -0
  63. package/dist/core/errors/base.d.ts +8 -0
  64. package/dist/core/errors/base.js +17 -0
  65. package/dist/core/errors/index.d.ts +4 -0
  66. package/dist/{cjs/constants → core/errors}/index.js +4 -4
  67. package/dist/core/errors/oracle.d.ts +9 -0
  68. package/dist/core/errors/oracle.js +15 -0
  69. package/dist/core/errors/router.d.ts +14 -0
  70. package/dist/core/errors/router.js +24 -0
  71. package/dist/core/types/borrow.d.ts +87 -0
  72. package/dist/{cjs/interfaces/tradingLimitsConfig.js → core/types/borrow.js} +1 -0
  73. package/dist/core/types/contractAddresses.d.ts +42 -0
  74. package/dist/{cjs → core}/types/contractAddresses.js +1 -0
  75. package/dist/core/types/index.d.ts +10 -0
  76. package/dist/core/types/index.js +26 -0
  77. package/dist/core/types/liquidity.d.ts +194 -0
  78. package/dist/core/types/liquidity.js +3 -0
  79. package/dist/core/types/pool.d.ts +208 -0
  80. package/dist/core/types/pool.js +14 -0
  81. package/dist/core/types/provider.d.ts +45 -0
  82. package/dist/{cjs/interfaces/tradingLimitsState.js → core/types/provider.js} +1 -0
  83. package/dist/core/types/route.d.ts +62 -0
  84. package/dist/{cjs/interfaces/IChainClient.js → core/types/route.js} +1 -0
  85. package/dist/core/types/token.d.ts +21 -0
  86. package/dist/{cjs/interfaces/tradingLimit.js → core/types/token.js} +1 -0
  87. package/dist/core/types/tradingLimits.d.ts +91 -0
  88. package/dist/core/types/tradingLimits.js +3 -0
  89. package/dist/core/types/tradingMode.d.ts +24 -0
  90. package/dist/core/types/tradingMode.js +31 -0
  91. package/dist/core/types/transaction.d.ts +45 -0
  92. package/dist/core/types/transaction.js +3 -0
  93. package/dist/esm/cache/routes.js +14084 -0
  94. package/dist/esm/cache/tokens.js +452 -0
  95. package/dist/esm/core/abis/activePool.js +10 -0
  96. package/dist/esm/core/abis/addressesRegistry.js +22 -0
  97. package/dist/esm/core/abis/bipoolmanager.js +68 -0
  98. package/dist/esm/core/abis/borrowerOperations.js +85 -0
  99. package/dist/esm/core/abis/breakerbox.js +4 -0
  100. package/dist/esm/core/abis/broker.js +5 -0
  101. package/dist/esm/core/abis/erc20.js +17 -0
  102. package/dist/esm/core/abis/fpmm.js +45 -0
  103. package/dist/esm/core/abis/fpmmFactory.js +22 -0
  104. package/dist/esm/core/abis/hintHelpers.js +10 -0
  105. package/dist/esm/core/abis/index.js +21 -0
  106. package/dist/esm/core/abis/liquidityStrategy.js +6 -0
  107. package/dist/esm/core/abis/multiTroveGetter.js +11 -0
  108. package/dist/esm/core/abis/priceFeed.js +12 -0
  109. package/dist/esm/core/abis/pricingmodule.js +2 -0
  110. package/dist/esm/core/abis/reserve.js +14 -0
  111. package/dist/esm/core/abis/router.js +41 -0
  112. package/dist/esm/core/abis/sortedTroves.js +11 -0
  113. package/dist/esm/core/abis/systemParams.js +10 -0
  114. package/dist/esm/core/abis/troveManager.js +23 -0
  115. package/dist/esm/core/abis/troveNFT.js +5 -0
  116. package/dist/esm/core/abis/virtualPool.js +7 -0
  117. package/dist/esm/core/abis/virtualPoolFactory.js +13 -0
  118. package/dist/esm/core/constants/addresses.js +107 -0
  119. package/dist/esm/core/constants/borrowConstants.js +12 -0
  120. package/dist/esm/core/constants/borrowRegistries.js +25 -0
  121. package/dist/esm/{enums → core/constants}/chainId.js +2 -0
  122. package/dist/esm/core/constants/contractNames.js +20 -0
  123. package/dist/esm/core/constants/index.js +5 -0
  124. package/dist/esm/core/errors/base.js +12 -0
  125. package/dist/esm/core/errors/index.js +3 -0
  126. package/dist/esm/core/errors/oracle.js +10 -0
  127. package/dist/esm/core/errors/router.js +18 -0
  128. package/dist/esm/core/types/index.js +9 -0
  129. package/dist/esm/core/types/pool.js +10 -0
  130. package/dist/esm/core/types/tradingLimits.js +1 -0
  131. package/dist/esm/core/types/tradingMode.js +26 -0
  132. package/dist/esm/core/types/transaction.js +1 -0
  133. package/dist/esm/index.js +138 -6
  134. package/dist/esm/package.json +1 -0
  135. package/dist/esm/services/borrow/BorrowService.js +455 -0
  136. package/dist/esm/services/borrow/borrowHelpers.js +3 -0
  137. package/dist/esm/services/borrow/borrowMath.js +127 -0
  138. package/dist/esm/services/borrow/index.js +3 -0
  139. package/dist/esm/services/borrow/internal/borrowApprovalService.js +48 -0
  140. package/dist/esm/services/borrow/internal/borrowContextStore.js +35 -0
  141. package/dist/esm/services/borrow/internal/borrowErc20.js +38 -0
  142. package/dist/esm/services/borrow/internal/borrowHints.js +27 -0
  143. package/dist/esm/services/borrow/internal/borrowPositionParser.js +82 -0
  144. package/dist/esm/services/borrow/internal/borrowReadService.js +271 -0
  145. package/dist/esm/services/borrow/internal/borrowRegistryReader.js +108 -0
  146. package/dist/esm/services/borrow/internal/borrowTransactionService.js +271 -0
  147. package/dist/esm/services/borrow/internal/borrowTypes.js +1 -0
  148. package/dist/esm/services/borrow/internal/borrowValidation.js +89 -0
  149. package/dist/esm/services/index.js +8 -0
  150. package/dist/esm/services/liquidity/LiquidityService.js +163 -0
  151. package/dist/esm/services/liquidity/basicLiquidity.js +162 -0
  152. package/dist/esm/services/liquidity/index.js +1 -0
  153. package/dist/esm/services/liquidity/liquidityHelpers.js +95 -0
  154. package/dist/esm/services/liquidity/rebalance.js +59 -0
  155. package/dist/esm/services/liquidity/zapHelpers.js +120 -0
  156. package/dist/esm/services/liquidity/zapIn.js +112 -0
  157. package/dist/esm/services/liquidity/zapOut.js +248 -0
  158. package/dist/esm/services/pools/PoolService.js +204 -0
  159. package/dist/esm/services/pools/index.js +1 -0
  160. package/dist/esm/services/pools/poolDetails.js +209 -0
  161. package/dist/esm/services/pools/poolDiscovery.js +112 -0
  162. package/dist/esm/services/pools/rebalancePreview.js +181 -0
  163. package/dist/esm/services/quotes/QuoteService.js +85 -0
  164. package/dist/esm/services/quotes/index.js +1 -0
  165. package/dist/esm/services/routes/RouteService.js +268 -0
  166. package/dist/esm/services/routes/index.js +1 -0
  167. package/dist/esm/services/swap/SwapService.js +247 -0
  168. package/dist/esm/services/swap/index.js +1 -0
  169. package/dist/esm/services/tokens/index.js +1 -0
  170. package/dist/esm/services/tokens/tokenService.js +285 -0
  171. package/dist/esm/services/trading/TradingLimitsService.js +154 -0
  172. package/dist/esm/services/trading/TradingService.js +196 -0
  173. package/dist/esm/services/trading/index.js +2 -0
  174. package/dist/esm/utils/chainConfig.js +118 -0
  175. package/dist/esm/utils/costUtils.js +56 -0
  176. package/dist/esm/utils/deadline.js +22 -0
  177. package/dist/esm/utils/index.js +9 -0
  178. package/dist/esm/utils/multicall.js +47 -0
  179. package/dist/esm/utils/pathEncoder.js +69 -0
  180. package/dist/esm/utils/rateFeed.js +23 -0
  181. package/dist/esm/utils/retry.js +24 -0
  182. package/dist/esm/{routeUtils.js → utils/routeUtils.js} +115 -116
  183. package/dist/esm/utils/routes.js +2 -0
  184. package/dist/esm/utils/sortUtils.js +33 -0
  185. package/dist/esm/utils/tokens.js +2 -0
  186. package/dist/esm/utils/tradingLimits.js +163 -0
  187. package/dist/esm/utils/validation.js +30 -0
  188. package/dist/index.d.ts +101 -0
  189. package/dist/index.js +158 -0
  190. package/dist/services/borrow/BorrowService.d.ts +381 -0
  191. package/dist/services/borrow/BorrowService.js +460 -0
  192. package/dist/services/borrow/borrowHelpers.d.ts +4 -0
  193. package/dist/services/borrow/borrowHelpers.js +13 -0
  194. package/dist/services/borrow/borrowMath.d.ts +21 -0
  195. package/dist/services/borrow/borrowMath.js +137 -0
  196. package/dist/services/borrow/index.d.ts +4 -0
  197. package/dist/{cjs/interfaces → services/borrow}/index.js +4 -4
  198. package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
  199. package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
  200. package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
  201. package/dist/services/borrow/internal/borrowContextStore.js +40 -0
  202. package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
  203. package/dist/services/borrow/internal/borrowErc20.js +43 -0
  204. package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
  205. package/dist/services/borrow/internal/borrowHints.js +31 -0
  206. package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
  207. package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
  208. package/dist/services/borrow/internal/borrowReadService.d.ts +31 -0
  209. package/dist/services/borrow/internal/borrowReadService.js +276 -0
  210. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
  211. package/dist/services/borrow/internal/borrowRegistryReader.js +113 -0
  212. package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
  213. package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
  214. package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
  215. package/dist/services/borrow/internal/borrowTypes.js +3 -0
  216. package/dist/services/borrow/internal/borrowValidation.d.ts +14 -0
  217. package/dist/services/borrow/internal/borrowValidation.js +104 -0
  218. package/dist/services/index.d.ts +9 -0
  219. package/dist/{cjs → services}/index.js +9 -7
  220. package/dist/services/liquidity/LiquidityService.d.ts +139 -0
  221. package/dist/services/liquidity/LiquidityService.js +168 -0
  222. package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
  223. package/dist/services/liquidity/basicLiquidity.js +172 -0
  224. package/dist/services/liquidity/index.d.ts +2 -0
  225. package/dist/{cjs/types → services/liquidity}/index.js +2 -2
  226. package/dist/services/liquidity/liquidityHelpers.d.ts +19 -0
  227. package/dist/services/liquidity/liquidityHelpers.js +104 -0
  228. package/dist/services/liquidity/rebalance.d.ts +6 -0
  229. package/dist/services/liquidity/rebalance.js +64 -0
  230. package/dist/services/liquidity/zapHelpers.d.ts +66 -0
  231. package/dist/services/liquidity/zapHelpers.js +129 -0
  232. package/dist/services/liquidity/zapIn.d.ts +18 -0
  233. package/dist/services/liquidity/zapIn.js +119 -0
  234. package/dist/services/liquidity/zapOut.d.ts +9 -0
  235. package/dist/services/liquidity/zapOut.js +255 -0
  236. package/dist/services/pools/PoolService.d.ts +69 -0
  237. package/dist/services/pools/PoolService.js +209 -0
  238. package/dist/services/pools/index.d.ts +2 -0
  239. package/dist/{cjs/enums → services/pools}/index.js +2 -3
  240. package/dist/services/pools/poolDetails.d.ts +13 -0
  241. package/dist/services/pools/poolDetails.js +216 -0
  242. package/dist/services/pools/poolDiscovery.d.ts +12 -0
  243. package/dist/services/pools/poolDiscovery.js +117 -0
  244. package/dist/services/pools/rebalancePreview.d.ts +5 -0
  245. package/dist/services/pools/rebalancePreview.js +186 -0
  246. package/dist/services/quotes/QuoteService.d.ts +51 -0
  247. package/dist/services/quotes/QuoteService.js +91 -0
  248. package/dist/services/quotes/index.d.ts +2 -0
  249. package/dist/services/quotes/index.js +18 -0
  250. package/dist/services/routes/RouteService.d.ts +117 -0
  251. package/dist/services/routes/RouteService.js +306 -0
  252. package/dist/services/routes/index.d.ts +2 -0
  253. package/dist/services/routes/index.js +18 -0
  254. package/dist/services/swap/SwapService.d.ts +198 -0
  255. package/dist/services/swap/SwapService.js +252 -0
  256. package/dist/services/swap/index.d.ts +2 -0
  257. package/dist/services/swap/index.js +18 -0
  258. package/dist/services/tokens/index.d.ts +2 -0
  259. package/dist/services/tokens/index.js +18 -0
  260. package/dist/services/tokens/tokenService.d.ts +55 -0
  261. package/dist/services/tokens/tokenService.js +290 -0
  262. package/dist/services/trading/TradingLimitsService.d.ts +38 -0
  263. package/dist/services/trading/TradingLimitsService.js +159 -0
  264. package/dist/services/trading/TradingService.d.ts +113 -0
  265. package/dist/services/trading/TradingService.js +201 -0
  266. package/dist/services/trading/index.d.ts +3 -0
  267. package/dist/services/trading/index.js +19 -0
  268. package/dist/utils/chainConfig.d.ts +16 -0
  269. package/dist/utils/chainConfig.js +123 -0
  270. package/dist/utils/costUtils.d.ts +12 -0
  271. package/dist/utils/costUtils.js +60 -0
  272. package/dist/utils/deadline.d.ts +21 -0
  273. package/dist/utils/deadline.js +26 -0
  274. package/dist/utils/index.d.ts +10 -0
  275. package/dist/utils/index.js +26 -0
  276. package/dist/utils/multicall.d.ts +30 -0
  277. package/dist/utils/multicall.js +52 -0
  278. package/dist/utils/pathEncoder.d.ts +34 -0
  279. package/dist/utils/pathEncoder.js +73 -0
  280. package/dist/utils/rateFeed.d.ts +18 -0
  281. package/dist/utils/rateFeed.js +27 -0
  282. package/dist/utils/retry.d.ts +12 -0
  283. package/dist/utils/retry.js +28 -0
  284. package/dist/{esm → utils}/routeUtils.d.ts +84 -93
  285. package/dist/{cjs → utils}/routeUtils.js +123 -124
  286. package/dist/utils/routes.d.ts +3 -0
  287. package/dist/utils/routes.js +8 -0
  288. package/dist/utils/sortUtils.d.ts +24 -0
  289. package/dist/utils/sortUtils.js +39 -0
  290. package/dist/utils/tokens.d.ts +2 -0
  291. package/dist/utils/tokens.js +13 -0
  292. package/dist/utils/tradingLimits.d.ts +41 -0
  293. package/dist/utils/tradingLimits.js +171 -0
  294. package/dist/utils/validation.d.ts +19 -0
  295. package/dist/utils/validation.js +34 -0
  296. package/package.json +1 -1
  297. package/dist/cjs/ChainClient.d.ts +0 -9
  298. package/dist/cjs/ChainClient.js +0 -58
  299. package/dist/cjs/TestChainClient.d.ts +0 -7
  300. package/dist/cjs/TestChainClient.js +0 -41
  301. package/dist/cjs/constants/addresses.d.ts +0 -4
  302. package/dist/cjs/constants/addresses.js +0 -59
  303. package/dist/cjs/constants/currencies.d.ts +0 -5
  304. package/dist/cjs/constants/currencies.js +0 -29
  305. package/dist/cjs/constants/index.d.ts +0 -4
  306. package/dist/cjs/constants/tokens.11142220.d.ts +0 -2
  307. package/dist/cjs/constants/tokens.11142220.js +0 -128
  308. package/dist/cjs/constants/tokens.42220.d.ts +0 -2
  309. package/dist/cjs/constants/tokens.42220.js +0 -128
  310. package/dist/cjs/constants/tokens.d.ts +0 -65
  311. package/dist/cjs/constants/tokens.js +0 -170
  312. package/dist/cjs/constants/tradablePairs.11142220.d.ts +0 -2
  313. package/dist/cjs/constants/tradablePairs.11142220.js +0 -7391
  314. package/dist/cjs/constants/tradablePairs.42220.d.ts +0 -2
  315. package/dist/cjs/constants/tradablePairs.42220.js +0 -7391
  316. package/dist/cjs/constants/tradablePairs.d.ts +0 -16
  317. package/dist/cjs/constants/tradablePairs.js +0 -53
  318. package/dist/cjs/enums/chainId.d.ts +0 -4
  319. package/dist/cjs/enums/index.d.ts +0 -3
  320. package/dist/cjs/enums/proposalState.d.ts +0 -10
  321. package/dist/cjs/enums/proposalState.js +0 -14
  322. package/dist/cjs/enums/tradingMode.d.ts +0 -17
  323. package/dist/cjs/enums/tradingMode.js +0 -21
  324. package/dist/cjs/governance.d.ts +0 -62
  325. package/dist/cjs/governance.js +0 -151
  326. package/dist/cjs/index.d.ts +0 -7
  327. package/dist/cjs/interfaces/IChainClient.d.ts +0 -6
  328. package/dist/cjs/interfaces/index.d.ts +0 -4
  329. package/dist/cjs/interfaces/tradingLimit.d.ts +0 -7
  330. package/dist/cjs/interfaces/tradingLimitsConfig.d.ts +0 -10
  331. package/dist/cjs/interfaces/tradingLimitsState.d.ts +0 -9
  332. package/dist/cjs/limits.d.ts +0 -33
  333. package/dist/cjs/limits.js +0 -130
  334. package/dist/cjs/mento.d.ts +0 -287
  335. package/dist/cjs/mento.js +0 -699
  336. package/dist/cjs/routeUtils.d.ts +0 -304
  337. package/dist/cjs/types/contractAddressMap.d.ts +0 -4
  338. package/dist/cjs/types/contractAddressMap.js +0 -2
  339. package/dist/cjs/types/contractAddresses.d.ts +0 -23
  340. package/dist/cjs/types/index.d.ts +0 -2
  341. package/dist/cjs/utils.d.ts +0 -80
  342. package/dist/cjs/utils.js +0 -177
  343. package/dist/esm/ChainClient.d.ts +0 -9
  344. package/dist/esm/ChainClient.js +0 -54
  345. package/dist/esm/TestChainClient.d.ts +0 -7
  346. package/dist/esm/TestChainClient.js +0 -37
  347. package/dist/esm/constants/addresses.d.ts +0 -4
  348. package/dist/esm/constants/addresses.js +0 -55
  349. package/dist/esm/constants/currencies.d.ts +0 -5
  350. package/dist/esm/constants/currencies.js +0 -26
  351. package/dist/esm/constants/index.d.ts +0 -4
  352. package/dist/esm/constants/index.js +0 -4
  353. package/dist/esm/constants/tokens.11142220.d.ts +0 -2
  354. package/dist/esm/constants/tokens.11142220.js +0 -125
  355. package/dist/esm/constants/tokens.42220.d.ts +0 -2
  356. package/dist/esm/constants/tokens.42220.js +0 -125
  357. package/dist/esm/constants/tokens.d.ts +0 -65
  358. package/dist/esm/constants/tokens.js +0 -142
  359. package/dist/esm/constants/tradablePairs.11142220.d.ts +0 -2
  360. package/dist/esm/constants/tradablePairs.11142220.js +0 -7388
  361. package/dist/esm/constants/tradablePairs.42220.d.ts +0 -2
  362. package/dist/esm/constants/tradablePairs.42220.js +0 -7388
  363. package/dist/esm/constants/tradablePairs.d.ts +0 -16
  364. package/dist/esm/constants/tradablePairs.js +0 -26
  365. package/dist/esm/enums/chainId.d.ts +0 -4
  366. package/dist/esm/enums/index.d.ts +0 -3
  367. package/dist/esm/enums/index.js +0 -3
  368. package/dist/esm/enums/proposalState.d.ts +0 -10
  369. package/dist/esm/enums/proposalState.js +0 -11
  370. package/dist/esm/enums/tradingMode.d.ts +0 -17
  371. package/dist/esm/enums/tradingMode.js +0 -18
  372. package/dist/esm/governance.d.ts +0 -62
  373. package/dist/esm/governance.js +0 -147
  374. package/dist/esm/index.d.ts +0 -7
  375. package/dist/esm/interfaces/IChainClient.d.ts +0 -6
  376. package/dist/esm/interfaces/index.d.ts +0 -4
  377. package/dist/esm/interfaces/index.js +0 -4
  378. package/dist/esm/interfaces/tradingLimit.d.ts +0 -7
  379. package/dist/esm/interfaces/tradingLimitsConfig.d.ts +0 -10
  380. package/dist/esm/interfaces/tradingLimitsState.d.ts +0 -9
  381. package/dist/esm/limits.d.ts +0 -33
  382. package/dist/esm/limits.js +0 -123
  383. package/dist/esm/mento.d.ts +0 -287
  384. package/dist/esm/mento.js +0 -671
  385. package/dist/esm/types/contractAddressMap.d.ts +0 -4
  386. package/dist/esm/types/contractAddresses.d.ts +0 -23
  387. package/dist/esm/types/index.d.ts +0 -2
  388. package/dist/esm/types/index.js +0 -2
  389. package/dist/esm/utils.d.ts +0 -80
  390. package/dist/esm/utils.js +0 -162
  391. /package/dist/esm/{interfaces/IChainClient.js → core/types/borrow.js} +0 -0
  392. /package/dist/esm/{types → core/types}/contractAddresses.js +0 -0
  393. /package/dist/esm/{interfaces/tradingLimit.js → core/types/liquidity.js} +0 -0
  394. /package/dist/esm/{interfaces/tradingLimitsConfig.js → core/types/provider.js} +0 -0
  395. /package/dist/esm/{interfaces/tradingLimitsState.js → core/types/route.js} +0 -0
  396. /package/dist/esm/{types/contractAddressMap.js → core/types/token.js} +0 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRebalanceParamsInternal = buildRebalanceParamsInternal;
4
+ exports.buildRebalanceTransactionInternal = buildRebalanceTransactionInternal;
5
+ const viem_1 = require("viem");
6
+ const abis_1 = require("../../core/abis");
7
+ const validation_1 = require("../../utils/validation");
8
+ const liquidityHelpers_1 = require("./liquidityHelpers");
9
+ function getRebalanceUnavailableError(poolAddress) {
10
+ return new Error(`Pool ${poolAddress} is not currently rebalanceable or does not have a supported liquidity strategy.`);
11
+ }
12
+ function assertRebalanceActionAmounts(poolAddress, amountRequired, amountTransferred) {
13
+ if (amountRequired <= 0n || amountTransferred <= 0n) {
14
+ throw new Error(`Rebalance action for pool ${poolAddress} has zero amounts and cannot be executed.`);
15
+ }
16
+ }
17
+ async function buildRebalanceParamsInternal(publicClient, chainId, poolService, poolAddress) {
18
+ (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
19
+ const preview = await poolService.getPoolRebalancePreview(poolAddress);
20
+ if (!preview) {
21
+ throw getRebalanceUnavailableError(poolAddress);
22
+ }
23
+ assertRebalanceActionAmounts(poolAddress, preview.amountRequired.amount, preview.amountTransferred.amount);
24
+ const data = (0, viem_1.encodeFunctionData)({
25
+ abi: abis_1.LIQUIDITY_STRATEGY_ABI,
26
+ functionName: 'rebalance',
27
+ args: [poolAddress],
28
+ });
29
+ return {
30
+ params: {
31
+ to: preview.strategyAddress,
32
+ data,
33
+ value: '0',
34
+ },
35
+ poolAddress,
36
+ strategyAddress: preview.strategyAddress,
37
+ inputToken: preview.inputToken,
38
+ outputToken: preview.outputToken,
39
+ amountRequired: preview.amountRequired.amount,
40
+ expectedAmountTransferred: preview.amountTransferred.amount,
41
+ expectedProtocolIncentive: preview.protocolIncentive.amount,
42
+ expectedLiquiditySourceIncentive: preview.liquiditySourceIncentive.amount,
43
+ approvalToken: preview.approvalToken,
44
+ approvalSpender: preview.approvalSpender,
45
+ approvalAmount: preview.approvalAmount,
46
+ direction: preview.direction,
47
+ };
48
+ }
49
+ async function buildRebalanceTransactionInternal(publicClient, chainId, poolService, poolAddress, owner) {
50
+ (0, validation_1.validateAddress)(owner, 'owner');
51
+ const rebalance = await buildRebalanceParamsInternal(publicClient, chainId, poolService, poolAddress);
52
+ const approvalToken = rebalance.approvalToken;
53
+ const approvalSpender = rebalance.approvalSpender;
54
+ const currentAllowance = await (0, liquidityHelpers_1.getAllowance)(publicClient, approvalToken, owner, chainId, approvalSpender);
55
+ const approval = currentAllowance < rebalance.approvalAmount
56
+ ? {
57
+ token: rebalance.approvalToken,
58
+ amount: rebalance.approvalAmount,
59
+ params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, approvalToken, rebalance.approvalAmount, approvalSpender),
60
+ }
61
+ : null;
62
+ return { approval, rebalance };
63
+ }
64
+ //# sourceMappingURL=rebalance.js.map
@@ -0,0 +1,66 @@
1
+ import { Address } from 'viem';
2
+ import { RouteService } from '../routes';
3
+ import { ZapParams } from '../../core/types';
4
+ import { RouterRoute } from '../../utils/pathEncoder';
5
+ /**
6
+ * Encodes the zapIn function call for the Router contract
7
+ */
8
+ export declare function encodeZapInCall(tokenIn: Address, amountInA: bigint, amountInB: bigint, zapParams: ZapParams, routesA: RouterRoute[], routesB: RouterRoute[], recipient: Address): string;
9
+ /**
10
+ * Encodes the zapOut function call for the Router contract
11
+ */
12
+ export declare function encodeZapOutCall(tokenOut: Address, liquidity: bigint, zapParams: ZapParams, routesA: RouterRoute[], routesB: RouterRoute[]): string;
13
+ /**
14
+ * Finds routes for zap in operations (from tokenIn to both pool tokens)
15
+ *
16
+ * @param routeService - Route service for finding swap paths
17
+ * @param tokenIn - Input token address
18
+ * @param token0 - Pool's token0 address
19
+ * @param token1 - Pool's token1 address
20
+ * @returns Routes from tokenIn to token0 and token1
21
+ */
22
+ export declare function findZapInRoutes(routeService: RouteService, tokenIn: string, token0: string, token1: string): Promise<{
23
+ routesA: RouterRoute[];
24
+ routesB: RouterRoute[];
25
+ }>;
26
+ /**
27
+ * Finds routes for zap out operations (from both pool tokens to tokenOut)
28
+ *
29
+ * @param routeService - Route service for finding swap paths
30
+ * @param token0 - Pool's token0 address
31
+ * @param token1 - Pool's token1 address
32
+ * @param tokenOut - Output token address
33
+ * @returns Routes from token0 and token1 to tokenOut
34
+ */
35
+ export declare function findZapOutRoutes(routeService: RouteService, token0: string, token1: string, tokenOut: string): Promise<{
36
+ routesA: RouterRoute[];
37
+ routesB: RouterRoute[];
38
+ }>;
39
+ /**
40
+ * Splits an amount into two parts based on a ratio
41
+ *
42
+ * @param amountIn - Total input amount
43
+ * @param splitRatio - Ratio for splitting (0-1, e.g., 0.5 for 50/50)
44
+ * @returns Split amounts for each part
45
+ */
46
+ export declare function splitAmount(amountIn: bigint, splitRatio: number): {
47
+ amountA: bigint;
48
+ amountB: bigint;
49
+ };
50
+ /**
51
+ * Estimates minimum LP tokens from zap in amounts.
52
+ *
53
+ * This is a conservative lower-bound estimate. The inputs are slippage-adjusted
54
+ * minimums, not expected amounts. Actual LP tokens minted on-chain may be higher
55
+ * because the router uses balanceOf(address(this)) after swaps, which can exceed
56
+ * the pre-calculated minimums.
57
+ *
58
+ * @param amountOutA - Minimum amount of token0 after swap (slippage-adjusted)
59
+ * @param amountOutB - Minimum amount of token1 after swap (slippage-adjusted)
60
+ * @param reserve0 - Current reserve of token0 in pool
61
+ * @param reserve1 - Current reserve of token1 in pool
62
+ * @param totalSupply - Total LP token supply
63
+ * @returns Conservative estimate of minimum LP tokens to be minted
64
+ */
65
+ export declare function estimateLiquidityFromZapIn(amountOutA: bigint, amountOutB: bigint, reserve0: bigint, reserve1: bigint, totalSupply: bigint): bigint;
66
+ //# sourceMappingURL=zapHelpers.d.ts.map
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeZapInCall = encodeZapInCall;
4
+ exports.encodeZapOutCall = encodeZapOutCall;
5
+ exports.findZapInRoutes = findZapInRoutes;
6
+ exports.findZapOutRoutes = findZapOutRoutes;
7
+ exports.splitAmount = splitAmount;
8
+ exports.estimateLiquidityFromZapIn = estimateLiquidityFromZapIn;
9
+ const viem_1 = require("viem");
10
+ const abis_1 = require("../../core/abis");
11
+ const pathEncoder_1 = require("../../utils/pathEncoder");
12
+ // ========== ENCODING FUNCTIONS ==========
13
+ /**
14
+ * Encodes the zapIn function call for the Router contract
15
+ */
16
+ function encodeZapInCall(tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient) {
17
+ return (0, viem_1.encodeFunctionData)({
18
+ abi: abis_1.ROUTER_ABI,
19
+ functionName: 'zapIn',
20
+ args: [tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient],
21
+ });
22
+ }
23
+ /**
24
+ * Encodes the zapOut function call for the Router contract
25
+ */
26
+ function encodeZapOutCall(tokenOut, liquidity, zapParams, routesA, routesB) {
27
+ return (0, viem_1.encodeFunctionData)({
28
+ abi: abis_1.ROUTER_ABI,
29
+ functionName: 'zapOut',
30
+ args: [tokenOut, liquidity, zapParams, routesA, routesB],
31
+ });
32
+ }
33
+ // ========== ROUTING FUNCTIONS ==========
34
+ /**
35
+ * Finds routes for zap in operations (from tokenIn to both pool tokens)
36
+ *
37
+ * @param routeService - Route service for finding swap paths
38
+ * @param tokenIn - Input token address
39
+ * @param token0 - Pool's token0 address
40
+ * @param token1 - Pool's token1 address
41
+ * @returns Routes from tokenIn to token0 and token1
42
+ */
43
+ async function findZapInRoutes(routeService, tokenIn, token0, token1) {
44
+ const [routeA, routeB] = await Promise.all([
45
+ tokenIn.toLowerCase() !== token0.toLowerCase()
46
+ ? routeService.findRoute(tokenIn, token0)
47
+ : Promise.resolve(null),
48
+ tokenIn.toLowerCase() !== token1.toLowerCase()
49
+ ? routeService.findRoute(tokenIn, token1)
50
+ : Promise.resolve(null),
51
+ ]);
52
+ const routesA = routeA ? (0, pathEncoder_1.encodeRoutePath)(routeA.path, tokenIn, token0) : [];
53
+ const routesB = routeB ? (0, pathEncoder_1.encodeRoutePath)(routeB.path, tokenIn, token1) : [];
54
+ return { routesA, routesB };
55
+ }
56
+ /**
57
+ * Finds routes for zap out operations (from both pool tokens to tokenOut)
58
+ *
59
+ * @param routeService - Route service for finding swap paths
60
+ * @param token0 - Pool's token0 address
61
+ * @param token1 - Pool's token1 address
62
+ * @param tokenOut - Output token address
63
+ * @returns Routes from token0 and token1 to tokenOut
64
+ */
65
+ async function findZapOutRoutes(routeService, token0, token1, tokenOut) {
66
+ const [routeA, routeB] = await Promise.all([
67
+ token0.toLowerCase() !== tokenOut.toLowerCase()
68
+ ? routeService.findRoute(token0, tokenOut)
69
+ : Promise.resolve(null),
70
+ token1.toLowerCase() !== tokenOut.toLowerCase()
71
+ ? routeService.findRoute(token1, tokenOut)
72
+ : Promise.resolve(null),
73
+ ]);
74
+ const routesA = routeA ? (0, pathEncoder_1.encodeRoutePath)(routeA.path, token0, tokenOut) : [];
75
+ const routesB = routeB ? (0, pathEncoder_1.encodeRoutePath)(routeB.path, token1, tokenOut) : [];
76
+ return { routesA, routesB };
77
+ }
78
+ // ========== CALCULATION FUNCTIONS ==========
79
+ /**
80
+ * Splits an amount into two parts based on a ratio
81
+ *
82
+ * @param amountIn - Total input amount
83
+ * @param splitRatio - Ratio for splitting (0-1, e.g., 0.5 for 50/50)
84
+ * @returns Split amounts for each part
85
+ */
86
+ function splitAmount(amountIn, splitRatio) {
87
+ if (splitRatio < 0 || splitRatio > 1) {
88
+ throw new Error('Split ratio must be between 0 and 1');
89
+ }
90
+ const amountA = (amountIn * BigInt(Math.floor(splitRatio * 10000))) / 10000n;
91
+ const amountB = amountIn - amountA;
92
+ return { amountA, amountB };
93
+ }
94
+ /**
95
+ * Estimates minimum LP tokens from zap in amounts.
96
+ *
97
+ * This is a conservative lower-bound estimate. The inputs are slippage-adjusted
98
+ * minimums, not expected amounts. Actual LP tokens minted on-chain may be higher
99
+ * because the router uses balanceOf(address(this)) after swaps, which can exceed
100
+ * the pre-calculated minimums.
101
+ *
102
+ * @param amountOutA - Minimum amount of token0 after swap (slippage-adjusted)
103
+ * @param amountOutB - Minimum amount of token1 after swap (slippage-adjusted)
104
+ * @param reserve0 - Current reserve of token0 in pool
105
+ * @param reserve1 - Current reserve of token1 in pool
106
+ * @param totalSupply - Total LP token supply
107
+ * @returns Conservative estimate of minimum LP tokens to be minted
108
+ */
109
+ function estimateLiquidityFromZapIn(amountOutA, amountOutB, reserve0, reserve1, totalSupply) {
110
+ if (totalSupply === 0n) {
111
+ // First liquidity provision - use geometric mean with BigInt sqrt
112
+ // to avoid precision loss from Number() conversion on 18-decimal values
113
+ const product = amountOutA * amountOutB;
114
+ if (product === 0n)
115
+ return 0n;
116
+ let x = product;
117
+ let y = (x + 1n) / 2n;
118
+ while (y < x) {
119
+ x = y;
120
+ y = (x + product / x) / 2n;
121
+ }
122
+ return x;
123
+ }
124
+ // Existing pool - calculate based on smaller ratio
125
+ const liquidityA = (amountOutA * totalSupply) / reserve0;
126
+ const liquidityB = (amountOutB * totalSupply) / reserve1;
127
+ return liquidityA < liquidityB ? liquidityA : liquidityB;
128
+ }
129
+ //# sourceMappingURL=zapHelpers.js.map
@@ -0,0 +1,18 @@
1
+ import { PublicClient } from 'viem';
2
+ import { PoolService } from '../pools';
3
+ import { RouteService } from '../routes';
4
+ import { LiquidityOptions, PreparedZapIn, ZapInQuote, ZapInDetails, ZapInTransaction } from '../../core/types';
5
+ /**
6
+ * Builds a complete zap in transaction including approval if needed
7
+ */
8
+ export declare function buildZapInTransactionInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, owner: string, options: LiquidityOptions): Promise<ZapInTransaction>;
9
+ /**
10
+ * Builds zap in transaction parameters without checking approval
11
+ */
12
+ export declare function buildZapInParamsInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, options: LiquidityOptions): Promise<ZapInDetails>;
13
+ /**
14
+ * Quotes a zap in operation (read-only)
15
+ */
16
+ export declare function quoteZapInInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, options: LiquidityOptions): Promise<ZapInQuote>;
17
+ export declare function prepareZapInInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenIn: string, amountIn: bigint, amountInSplit: number, recipient: string, owner: string | undefined, options: LiquidityOptions): Promise<PreparedZapIn>;
18
+ //# sourceMappingURL=zapIn.d.ts.map
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildZapInTransactionInternal = buildZapInTransactionInternal;
4
+ exports.buildZapInParamsInternal = buildZapInParamsInternal;
5
+ exports.quoteZapInInternal = quoteZapInInternal;
6
+ exports.prepareZapInInternal = prepareZapInInternal;
7
+ const abis_1 = require("../../core/abis");
8
+ const constants_1 = require("../../core/constants");
9
+ const validation_1 = require("../../utils/validation");
10
+ const liquidityHelpers_1 = require("./liquidityHelpers");
11
+ const zapHelpers_1 = require("./zapHelpers");
12
+ // ========== ZAP IN OPERATIONS ==========
13
+ /**
14
+ * Builds a complete zap in transaction including approval if needed
15
+ */
16
+ async function buildZapInTransactionInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options) {
17
+ const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options);
18
+ return {
19
+ approval: prepared.approval ?? null,
20
+ zapIn: prepared.details,
21
+ };
22
+ }
23
+ /**
24
+ * Builds zap in transaction parameters without checking approval
25
+ */
26
+ async function buildZapInParamsInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options) {
27
+ const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, undefined, options);
28
+ return prepared.details;
29
+ }
30
+ /**
31
+ * Quotes a zap in operation (read-only)
32
+ */
33
+ async function quoteZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, options) {
34
+ const prepared = await prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, tokenIn, undefined, options);
35
+ return prepared.quote;
36
+ }
37
+ async function prepareZapInInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, owner, options) {
38
+ if (owner) {
39
+ (0, validation_1.validateAddress)(owner, 'owner');
40
+ }
41
+ const [context, currentAllowance] = await Promise.all([
42
+ prepareZapInContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options),
43
+ owner ? (0, liquidityHelpers_1.getAllowance)(publicClient, tokenIn, owner, chainId) : Promise.resolve(null),
44
+ ]);
45
+ const approval = owner && currentAllowance !== null && currentAllowance < amountIn
46
+ ? { token: tokenIn, amount: amountIn, params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, tokenIn, amountIn) }
47
+ : owner
48
+ ? null
49
+ : undefined;
50
+ return {
51
+ routesA: context.routesA,
52
+ routesB: context.routesB,
53
+ quote: context.quote,
54
+ approval,
55
+ details: context.details,
56
+ };
57
+ }
58
+ async function prepareZapInContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenIn, amountIn, amountInSplit, recipient, options) {
59
+ (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
60
+ (0, validation_1.validateAddress)(tokenIn, 'tokenIn');
61
+ (0, validation_1.validateAddress)(recipient, 'recipient');
62
+ const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
63
+ const { amountA: amountInA, amountB: amountInB } = (0, zapHelpers_1.splitAmount)(amountIn, amountInSplit);
64
+ const [{ routesA, routesB }, poolSnapshot] = await Promise.all([
65
+ (0, zapHelpers_1.findZapInRoutes)(routeService, tokenIn, token0, token1),
66
+ (0, liquidityHelpers_1.getPoolSnapshot)(publicClient, poolAddress),
67
+ ]);
68
+ const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
69
+ const [amountOutMinA, amountOutMinB, amountAMin, amountBMin] = (await publicClient.readContract({
70
+ address: routerAddress,
71
+ abi: abis_1.ROUTER_ABI,
72
+ functionName: 'generateZapInParams',
73
+ args: [token0, token1, factoryAddr, amountInA, amountInB, routesA, routesB],
74
+ }));
75
+ const finalAmountAMin = (0, liquidityHelpers_1.calculateMinAmount)(amountAMin, options.slippageTolerance);
76
+ const finalAmountBMin = (0, liquidityHelpers_1.calculateMinAmount)(amountBMin, options.slippageTolerance);
77
+ const finalAmountOutMinA = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinA, options.slippageTolerance);
78
+ const finalAmountOutMinB = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinB, options.slippageTolerance);
79
+ const expectedLiquidity = (0, zapHelpers_1.estimateLiquidityFromZapIn)(finalAmountOutMinA, finalAmountOutMinB, poolSnapshot.reserve0, poolSnapshot.reserve1, poolSnapshot.totalSupply);
80
+ const quote = {
81
+ amountOutFromA: finalAmountOutMinA,
82
+ amountOutFromB: finalAmountOutMinB,
83
+ amountAMin: finalAmountAMin,
84
+ amountBMin: finalAmountBMin,
85
+ estimatedMinLiquidity: expectedLiquidity,
86
+ };
87
+ const zapParams = {
88
+ tokenA: token0,
89
+ tokenB: token1,
90
+ factory: factoryAddr,
91
+ amountAMin: finalAmountAMin,
92
+ amountBMin: finalAmountBMin,
93
+ amountOutMinA: finalAmountOutMinA,
94
+ amountOutMinB: finalAmountOutMinB,
95
+ };
96
+ const data = (0, zapHelpers_1.encodeZapInCall)(tokenIn, amountInA, amountInB, zapParams, routesA, routesB, recipient);
97
+ return {
98
+ routesA,
99
+ routesB,
100
+ quote,
101
+ details: {
102
+ params: {
103
+ to: routerAddress,
104
+ data,
105
+ value: '0',
106
+ },
107
+ poolAddress,
108
+ tokenIn,
109
+ amountIn,
110
+ amountInA,
111
+ amountInB,
112
+ routesA,
113
+ routesB,
114
+ zapParams,
115
+ estimatedMinLiquidity: expectedLiquidity,
116
+ },
117
+ };
118
+ }
119
+ //# sourceMappingURL=zapIn.js.map
@@ -0,0 +1,9 @@
1
+ import { PublicClient } from 'viem';
2
+ import { PoolService } from '../pools';
3
+ import { RouteService } from '../routes';
4
+ import { LiquidityOptions, PreparedZapOut, ZapOutQuote, ZapOutDetails, ZapOutTransaction } from '../../core/types';
5
+ export declare function buildZapOutTransactionInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, owner: string, options: LiquidityOptions): Promise<ZapOutTransaction>;
6
+ export declare function buildZapOutParamsInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, options: LiquidityOptions): Promise<ZapOutDetails>;
7
+ export declare function quoteZapOutInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, options: LiquidityOptions): Promise<ZapOutQuote>;
8
+ export declare function prepareZapOutInternal(publicClient: PublicClient, chainId: number, poolService: PoolService, routeService: RouteService, poolAddress: string, tokenOut: string, liquidity: bigint, recipient: string, owner: string | undefined, options: LiquidityOptions): Promise<PreparedZapOut>;
9
+ //# sourceMappingURL=zapOut.d.ts.map
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildZapOutTransactionInternal = buildZapOutTransactionInternal;
4
+ exports.buildZapOutParamsInternal = buildZapOutParamsInternal;
5
+ exports.quoteZapOutInternal = quoteZapOutInternal;
6
+ exports.prepareZapOutInternal = prepareZapOutInternal;
7
+ const abis_1 = require("../../core/abis");
8
+ const constants_1 = require("../../core/constants");
9
+ const errors_1 = require("../../core/errors");
10
+ const validation_1 = require("../../utils/validation");
11
+ const pathEncoder_1 = require("../../utils/pathEncoder");
12
+ const liquidityHelpers_1 = require("./liquidityHelpers");
13
+ const zapHelpers_1 = require("./zapHelpers");
14
+ const INSUFFICIENT_LIQUIDITY_SELECTOR = '0xbb55fd27';
15
+ const MAX_ROUTE_CANDIDATES_PER_LEG = 8;
16
+ const MAX_ROUTE_COMBINATIONS = 48;
17
+ const ROUTE_SIMULATION_BATCH_SIZE = 6;
18
+ async function buildZapOutTransactionInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
19
+ const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options);
20
+ return {
21
+ approval: prepared.approval ?? null,
22
+ zapOut: prepared.details,
23
+ };
24
+ }
25
+ async function buildZapOutParamsInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
26
+ const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, undefined, options);
27
+ return prepared.details;
28
+ }
29
+ async function quoteZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, options) {
30
+ const prepared = await prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, tokenOut, undefined, options);
31
+ return prepared.quote;
32
+ }
33
+ async function prepareZapOutInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, owner, options) {
34
+ if (owner) {
35
+ (0, validation_1.validateAddress)(owner, 'owner');
36
+ }
37
+ const [context, currentAllowance] = await Promise.all([
38
+ prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options),
39
+ owner ? (0, liquidityHelpers_1.getAllowance)(publicClient, poolAddress, owner, chainId) : Promise.resolve(null),
40
+ ]);
41
+ let details = context.details;
42
+ const approval = owner && currentAllowance !== null && currentAllowance < liquidity
43
+ ? { token: poolAddress, amount: liquidity, params: (0, liquidityHelpers_1.buildApprovalParams)(chainId, poolAddress, liquidity) }
44
+ : owner
45
+ ? null
46
+ : undefined;
47
+ if (owner && currentAllowance !== null && currentAllowance >= liquidity) {
48
+ const ownerAddr = owner;
49
+ const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
50
+ try {
51
+ await simulateZapOut(publicClient, ownerAddr, routerAddress, details.params.data);
52
+ }
53
+ catch (error) {
54
+ if (!isInsufficientLiquidityError(error)) {
55
+ throw error;
56
+ }
57
+ details = await findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, ownerAddr, options);
58
+ }
59
+ }
60
+ return {
61
+ routesA: details.routesA,
62
+ routesB: details.routesB,
63
+ quote: {
64
+ amountOutFromA: details.zapParams.amountOutMinA,
65
+ amountOutFromB: details.zapParams.amountOutMinB,
66
+ amountAMin: details.zapParams.amountAMin,
67
+ amountBMin: details.zapParams.amountBMin,
68
+ estimatedMinTokenOut: details.estimatedMinTokenOut,
69
+ },
70
+ approval,
71
+ details,
72
+ };
73
+ }
74
+ async function prepareZapOutContextInternal(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, recipient, options) {
75
+ (0, validation_1.validateAddress)(poolAddress, 'poolAddress');
76
+ (0, validation_1.validateAddress)(tokenOut, 'tokenOut');
77
+ (0, validation_1.validateAddress)(recipient, 'recipient');
78
+ const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
79
+ const { routesA, routesB } = await (0, zapHelpers_1.findZapOutRoutes)(routeService, token0, token1, tokenOut);
80
+ const details = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
81
+ return {
82
+ routesA,
83
+ routesB,
84
+ quote: {
85
+ amountOutFromA: details.zapParams.amountOutMinA,
86
+ amountOutFromB: details.zapParams.amountOutMinB,
87
+ amountAMin: details.zapParams.amountAMin,
88
+ amountBMin: details.zapParams.amountBMin,
89
+ estimatedMinTokenOut: details.estimatedMinTokenOut,
90
+ },
91
+ details,
92
+ };
93
+ }
94
+ async function buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options) {
95
+ const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
96
+ const [amountOutMinA, amountOutMinB, amountAMin, amountBMin] = (await publicClient.readContract({
97
+ address: routerAddress,
98
+ abi: abis_1.ROUTER_ABI,
99
+ functionName: 'generateZapOutParams',
100
+ args: [token0, token1, factoryAddr, liquidity, routesA, routesB],
101
+ }));
102
+ const finalAmountAMin = (0, liquidityHelpers_1.calculateMinAmount)(amountAMin, options.slippageTolerance);
103
+ const finalAmountBMin = (0, liquidityHelpers_1.calculateMinAmount)(amountBMin, options.slippageTolerance);
104
+ const finalAmountOutMinA = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinA, options.slippageTolerance);
105
+ const finalAmountOutMinB = (0, liquidityHelpers_1.calculateMinAmount)(amountOutMinB, options.slippageTolerance);
106
+ const zapParams = {
107
+ tokenA: token0,
108
+ tokenB: token1,
109
+ factory: factoryAddr,
110
+ amountAMin: finalAmountAMin,
111
+ amountBMin: finalAmountBMin,
112
+ amountOutMinA: finalAmountOutMinA,
113
+ amountOutMinB: finalAmountOutMinB,
114
+ };
115
+ const data = (0, zapHelpers_1.encodeZapOutCall)(tokenOut, liquidity, zapParams, routesA, routesB);
116
+ return {
117
+ params: {
118
+ to: routerAddress,
119
+ data,
120
+ value: '0',
121
+ },
122
+ poolAddress,
123
+ tokenOut,
124
+ liquidity,
125
+ routesA,
126
+ routesB,
127
+ zapParams,
128
+ estimatedMinTokenOut: finalAmountOutMinA + finalAmountOutMinB,
129
+ };
130
+ }
131
+ async function findViableZapOutDetails(publicClient, chainId, poolService, routeService, poolAddress, tokenOut, liquidity, owner, options) {
132
+ const { token0, token1, factoryAddr } = await (0, liquidityHelpers_1.getPoolInfo)(poolService, poolAddress);
133
+ const routerAddress = (0, constants_1.getContractAddress)(chainId, 'Router');
134
+ const allRoutes = await routeService.getRoutes({ cached: false, returnAllRoutes: true });
135
+ const [routesAOptions, routesBOptions] = await Promise.all([
136
+ getEncodedRouteCandidates(routeService, token0, tokenOut, poolAddress, allRoutes),
137
+ getEncodedRouteCandidates(routeService, token1, tokenOut, poolAddress, allRoutes),
138
+ ]);
139
+ const routeCombinations = [];
140
+ outer: for (const routesA of routesAOptions) {
141
+ for (const routesB of routesBOptions) {
142
+ routeCombinations.push({ routesA, routesB });
143
+ if (routeCombinations.length >= MAX_ROUTE_COMBINATIONS) {
144
+ break outer;
145
+ }
146
+ }
147
+ }
148
+ let best = null;
149
+ for (let index = 0; index < routeCombinations.length; index += ROUTE_SIMULATION_BATCH_SIZE) {
150
+ const batch = routeCombinations.slice(index, index + ROUTE_SIMULATION_BATCH_SIZE);
151
+ const candidates = await Promise.all(batch.map(async ({ routesA, routesB }) => {
152
+ try {
153
+ const candidate = await buildZapOutDetailsForRoutes(publicClient, chainId, poolAddress, tokenOut, liquidity, token0, token1, factoryAddr, routesA, routesB, options);
154
+ await simulateZapOut(publicClient, owner, routerAddress, candidate.params.data);
155
+ return candidate;
156
+ }
157
+ catch {
158
+ return null;
159
+ }
160
+ }));
161
+ for (const candidate of candidates) {
162
+ if (candidate && (!best || candidate.estimatedMinTokenOut > best.estimatedMinTokenOut)) {
163
+ best = candidate;
164
+ }
165
+ }
166
+ }
167
+ if (!best) {
168
+ throw new errors_1.ZapOutRouteNotViableError(poolAddress, tokenOut);
169
+ }
170
+ return best;
171
+ }
172
+ async function getEncodedRouteCandidates(routeService, tokenIn, tokenOut, sourcePoolAddress, allRoutes) {
173
+ if (tokenIn.toLowerCase() === tokenOut.toLowerCase()) {
174
+ return [[]];
175
+ }
176
+ const rawCandidates = [];
177
+ try {
178
+ rawCandidates.push(await routeService.findRoute(tokenIn, tokenOut));
179
+ }
180
+ catch {
181
+ // Continue; we'll try the broader route set next.
182
+ }
183
+ const pairCandidates = (allRoutes ?? await routeService.getRoutes({ cached: false, returnAllRoutes: true })).filter((route) => {
184
+ const a0 = route.tokens[0].address.toLowerCase();
185
+ const a1 = route.tokens[1].address.toLowerCase();
186
+ const t0 = tokenIn.toLowerCase();
187
+ const t1 = tokenOut.toLowerCase();
188
+ return (a0 === t0 && a1 === t1) || (a0 === t1 && a1 === t0);
189
+ });
190
+ rawCandidates.push(...pairCandidates);
191
+ if (rawCandidates.length === 0) {
192
+ throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
193
+ }
194
+ rawCandidates.sort((routeA, routeB) => {
195
+ const routeAUsesSourcePool = routeUsesPool(routeA, sourcePoolAddress) ? 1 : 0;
196
+ const routeBUsesSourcePool = routeUsesPool(routeB, sourcePoolAddress) ? 1 : 0;
197
+ if (routeAUsesSourcePool !== routeBUsesSourcePool)
198
+ return routeAUsesSourcePool - routeBUsesSourcePool;
199
+ if (routeA.path.length !== routeB.path.length)
200
+ return routeA.path.length - routeB.path.length;
201
+ return 0;
202
+ });
203
+ const encodedRoutes = [];
204
+ const seen = new Set();
205
+ for (const route of rawCandidates) {
206
+ try {
207
+ const encoded = (0, pathEncoder_1.encodeRoutePath)(route.path, tokenIn, tokenOut);
208
+ const key = JSON.stringify(encoded);
209
+ if (seen.has(key))
210
+ continue;
211
+ seen.add(key);
212
+ encodedRoutes.push(encoded);
213
+ if (encodedRoutes.length >= MAX_ROUTE_CANDIDATES_PER_LEG) {
214
+ break;
215
+ }
216
+ }
217
+ catch {
218
+ // Invalid path encoding for this direction; skip.
219
+ }
220
+ }
221
+ if (encodedRoutes.length === 0) {
222
+ throw new errors_1.RouteNotFoundError(tokenIn, tokenOut);
223
+ }
224
+ return encodedRoutes;
225
+ }
226
+ function routeUsesPool(route, poolAddress) {
227
+ const normalizedPool = poolAddress.toLowerCase();
228
+ return route.path.some((hop) => hop.poolAddr.toLowerCase() === normalizedPool);
229
+ }
230
+ async function simulateZapOut(publicClient, owner, routerAddress, data) {
231
+ await publicClient.call({
232
+ account: owner,
233
+ to: routerAddress,
234
+ data,
235
+ });
236
+ }
237
+ function isInsufficientLiquidityError(error) {
238
+ const message = extractErrorMessage(error).toLowerCase();
239
+ return (message.includes(INSUFFICIENT_LIQUIDITY_SELECTOR) ||
240
+ message.includes('insufficientliquidity'));
241
+ }
242
+ function extractErrorMessage(error) {
243
+ if (!(error instanceof Error)) {
244
+ return String(error);
245
+ }
246
+ const typed = error;
247
+ const parts = [
248
+ typed.message,
249
+ typed.shortMessage,
250
+ typed.details,
251
+ typed.cause instanceof Error ? typed.cause.message : undefined,
252
+ ].filter((part) => Boolean(part));
253
+ return parts.join(' | ');
254
+ }
255
+ //# sourceMappingURL=zapOut.js.map