@mento-protocol/mento-sdk 3.2.3 → 3.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +222 -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 +115 -0
  265. package/dist/services/trading/TradingService.js +227 -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,460 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BorrowService = void 0;
4
+ const borrowApprovalService_1 = require("./internal/borrowApprovalService");
5
+ const borrowContextStore_1 = require("./internal/borrowContextStore");
6
+ const borrowReadService_1 = require("./internal/borrowReadService");
7
+ const borrowTransactionService_1 = require("./internal/borrowTransactionService");
8
+ /**
9
+ * Service for managing borrowing positions (troves) in the Mento protocol.
10
+ * Provides methods to open, adjust, and close troves, manage collateral and debt,
11
+ * handle interest rates and batch managers, and query position data.
12
+ *
13
+ * All `build*` methods return `CallParams` ({ to, data, value }) that can be
14
+ * executed with any wallet client. The `debtTokenSymbol` parameter (e.g., 'GBPm')
15
+ * identifies which borrowing deployment to interact with.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const mento = await Mento.create(ChainId.CELO)
20
+ *
21
+ * const ownerIndex = await mento.borrow.findNextAvailableOwnerIndex('GBPm', '0x...', '0x...')
22
+ *
23
+ * // Open a trove
24
+ * const tx = await mento.borrow.buildOpenTroveTransaction('GBPm', {
25
+ * owner: '0x...', ownerIndex,
26
+ * collAmount: parseUnits('10', 18),
27
+ * boldAmount: parseUnits('1000', 18),
28
+ * annualInterestRate: parseUnits('0.05', 18),
29
+ * maxUpfrontFee: parseUnits('100', 18),
30
+ * })
31
+ * await walletClient.sendTransaction(tx)
32
+ * ```
33
+ */
34
+ class BorrowService {
35
+ constructor(publicClient, chainId) {
36
+ this.contextStore = new borrowContextStore_1.BorrowContextStore(publicClient, chainId);
37
+ this.txService = new borrowTransactionService_1.BorrowTransactionService(publicClient);
38
+ this.approvalService = new borrowApprovalService_1.BorrowApprovalService(publicClient);
39
+ this.readService = new borrowReadService_1.BorrowReadService(publicClient);
40
+ }
41
+ /**
42
+ * Builds a transaction to open a new trove (borrowing position).
43
+ * Requires prior collateral approval via `buildCollateralApprovalParams`.
44
+ *
45
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
46
+ * @param params - Trove opening parameters including collateral, debt amount, and interest rate
47
+ * @returns Transaction parameters ready to send
48
+ */
49
+ buildOpenTroveTransaction(debtTokenSymbol, params) {
50
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildOpenTroveTransaction(ctx, params));
51
+ }
52
+ /**
53
+ * Builds a transaction to adjust an existing trove's collateral and/or debt.
54
+ *
55
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
56
+ * @param params - Adjustment parameters specifying collateral/debt changes
57
+ * @returns Transaction parameters ready to send
58
+ */
59
+ buildAdjustTroveTransaction(debtTokenSymbol, params) {
60
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildAdjustTroveTransaction(ctx, params));
61
+ }
62
+ /**
63
+ * Builds a transaction to adjust a zombie trove. Zombie troves are still-open troves whose
64
+ * debt fell below the branch minimum debt, typically after a redemption.
65
+ *
66
+ * Use this when `getTroveData()` or `getUserTroves()` returns `status === 'zombie'`.
67
+ * Same parameters as `buildAdjustTroveTransaction`.
68
+ *
69
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
70
+ * @param params - Adjustment parameters specifying collateral/debt changes
71
+ * @returns Transaction parameters ready to send
72
+ */
73
+ buildAdjustZombieTroveTransaction(debtTokenSymbol, params) {
74
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildAdjustZombieTroveTransaction(ctx, params));
75
+ }
76
+ /**
77
+ * Builds a transaction to close a trove, repaying all debt and reclaiming collateral.
78
+ *
79
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
80
+ * @param troveId - The NFT token ID identifying the trove
81
+ * @returns Transaction parameters ready to send
82
+ */
83
+ buildCloseTroveTransaction(debtTokenSymbol, troveId) {
84
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildCloseTroveTransaction(ctx, troveId));
85
+ }
86
+ /**
87
+ * Builds a transaction to add collateral to an existing trove.
88
+ * Requires prior collateral approval via `buildCollateralApprovalParams`.
89
+ *
90
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
91
+ * @param troveId - The NFT token ID identifying the trove
92
+ * @param amount - Amount of collateral to add (in wei)
93
+ * @returns Transaction parameters ready to send
94
+ */
95
+ buildAddCollTransaction(debtTokenSymbol, troveId, amount) {
96
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildAddCollTransaction(ctx, troveId, amount));
97
+ }
98
+ /**
99
+ * Builds a transaction to withdraw collateral from an existing trove.
100
+ *
101
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
102
+ * @param troveId - The NFT token ID identifying the trove
103
+ * @param amount - Amount of collateral to withdraw (in wei)
104
+ * @returns Transaction parameters ready to send
105
+ */
106
+ buildWithdrawCollTransaction(debtTokenSymbol, troveId, amount) {
107
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildWithdrawCollTransaction(ctx, troveId, amount));
108
+ }
109
+ /**
110
+ * Builds a transaction to borrow additional debt against an existing trove.
111
+ *
112
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
113
+ * @param troveId - The NFT token ID identifying the trove
114
+ * @param amount - Additional debt amount to borrow (in wei)
115
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
116
+ * @returns Transaction parameters ready to send
117
+ */
118
+ buildBorrowMoreTransaction(debtTokenSymbol, troveId, amount, maxFee) {
119
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildBorrowMoreTransaction(ctx, troveId, amount, maxFee));
120
+ }
121
+ /**
122
+ * Builds a transaction to repay debt on an existing trove.
123
+ *
124
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
125
+ * @param troveId - The NFT token ID identifying the trove
126
+ * @param amount - Amount of debt to repay (in wei)
127
+ * @returns Transaction parameters ready to send
128
+ */
129
+ buildRepayDebtTransaction(debtTokenSymbol, troveId, amount) {
130
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildRepayDebtTransaction(ctx, troveId, amount));
131
+ }
132
+ /**
133
+ * Builds a transaction to change the annual interest rate on a trove.
134
+ *
135
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
136
+ * @param troveId - The NFT token ID identifying the trove
137
+ * @param newRate - New annual interest rate (18-decimal fixed-point, e.g., parseUnits('0.05', 18) for 5%)
138
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
139
+ * @returns Transaction parameters ready to send
140
+ */
141
+ buildAdjustInterestRateTransaction(debtTokenSymbol, troveId, newRate, maxFee) {
142
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildAdjustInterestRateTransaction(ctx, troveId, newRate, maxFee));
143
+ }
144
+ /**
145
+ * Builds a transaction to claim collateral surplus after a liquidation.
146
+ * This is for collateral held in the surplus pool after `closedByLiquidation`.
147
+ * Zombie troves with remaining collateral should usually be closed or adjusted instead.
148
+ *
149
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
150
+ * @returns Transaction parameters ready to send
151
+ */
152
+ buildClaimCollateralTransaction(debtTokenSymbol) {
153
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildClaimCollateralTransaction(ctx));
154
+ }
155
+ /**
156
+ * Builds a transaction to delegate interest rate management to a batch manager.
157
+ *
158
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
159
+ * @param troveId - The NFT token ID identifying the trove
160
+ * @param manager - Address of the batch manager contract
161
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
162
+ * @returns Transaction parameters ready to send
163
+ */
164
+ buildSetBatchManagerTransaction(debtTokenSymbol, troveId, manager, maxFee) {
165
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildSetBatchManagerTransaction(ctx, troveId, manager, maxFee));
166
+ }
167
+ /**
168
+ * Builds a transaction to remove a trove from a batch manager, setting a new individual rate.
169
+ *
170
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
171
+ * @param troveId - The NFT token ID identifying the trove
172
+ * @param newRate - New individual annual interest rate (18-decimal fixed-point)
173
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
174
+ * @returns Transaction parameters ready to send
175
+ */
176
+ buildRemoveFromBatchTransaction(debtTokenSymbol, troveId, newRate, maxFee) {
177
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildRemoveFromBatchTransaction(ctx, troveId, newRate, maxFee));
178
+ }
179
+ /**
180
+ * Builds a transaction to switch a trove to a different batch manager.
181
+ *
182
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
183
+ * @param troveId - The NFT token ID identifying the trove
184
+ * @param newManager - Address of the new batch manager contract
185
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
186
+ * @returns Transaction parameters ready to send
187
+ */
188
+ buildSwitchBatchManagerTransaction(debtTokenSymbol, troveId, newManager, maxFee) {
189
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildSwitchBatchManagerTransaction(ctx, troveId, newManager, maxFee));
190
+ }
191
+ /**
192
+ * Builds a transaction to delegate interest rate management to another address
193
+ * with bounded rate constraints.
194
+ *
195
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
196
+ * @param troveId - The NFT token ID identifying the trove
197
+ * @param delegate - Address to delegate interest rate management to
198
+ * @param minRate - Minimum allowed annual interest rate (18-decimal fixed-point)
199
+ * @param maxRate - Maximum allowed annual interest rate (18-decimal fixed-point)
200
+ * @param newRate - Initial annual interest rate to set (18-decimal fixed-point)
201
+ * @param maxFee - Maximum upfront fee the borrower is willing to pay (in wei)
202
+ * @param minChangePeriod - Minimum time between rate changes (in seconds)
203
+ * @returns Transaction parameters ready to send
204
+ */
205
+ buildSetInterestDelegateTransaction(debtTokenSymbol, troveId, delegate, minRate, maxRate, newRate, maxFee, minChangePeriod) {
206
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildSetInterestDelegateTransaction(ctx, troveId, delegate, minRate, maxRate, newRate, maxFee, minChangePeriod));
207
+ }
208
+ /**
209
+ * Builds a transaction to remove the interest rate delegate from a trove.
210
+ *
211
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
212
+ * @param troveId - The NFT token ID identifying the trove
213
+ * @returns Transaction parameters ready to send
214
+ */
215
+ buildRemoveInterestDelegateTransaction(debtTokenSymbol, troveId) {
216
+ return this.withContext(debtTokenSymbol, (ctx) => this.txService.buildRemoveInterestDelegateTransaction(ctx, troveId));
217
+ }
218
+ /**
219
+ * Builds approval params to allow BorrowerOperations to spend collateral tokens.
220
+ * Must be executed before `buildOpenTroveTransaction` or `buildAddCollTransaction`.
221
+ *
222
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
223
+ * @param amount - Amount of collateral to approve (in wei)
224
+ * @returns Transaction parameters for the ERC-20 approve call
225
+ */
226
+ buildCollateralApprovalParams(debtTokenSymbol, amount) {
227
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.buildCollateralApprovalParams(ctx, amount));
228
+ }
229
+ /**
230
+ * Builds approval params for the debt token (e.g., for repayment or closing).
231
+ *
232
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
233
+ * @param spender - Address to approve as spender
234
+ * @param amount - Amount of debt tokens to approve (in wei)
235
+ * @returns Transaction parameters for the ERC-20 approve call
236
+ */
237
+ buildDebtApprovalParams(debtTokenSymbol, spender, amount) {
238
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.buildDebtApprovalParams(ctx, spender, amount));
239
+ }
240
+ /**
241
+ * Builds approval params for the gas compensation token (required when opening a trove).
242
+ *
243
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
244
+ * @param amount - Amount to approve (in wei). If omitted, approves the gas compensation amount.
245
+ * @returns Transaction parameters for the ERC-20 approve call
246
+ */
247
+ buildGasCompensationApprovalParams(debtTokenSymbol, amount) {
248
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.buildGasCompensationApprovalParams(ctx, amount));
249
+ }
250
+ /**
251
+ * Gets the current collateral token allowance for BorrowerOperations.
252
+ *
253
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
254
+ * @param owner - Address to check allowance for
255
+ * @returns Current allowance in wei
256
+ */
257
+ getCollateralAllowance(debtTokenSymbol, owner) {
258
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.getCollateralAllowance(ctx, owner));
259
+ }
260
+ /**
261
+ * Gets the current debt token allowance for a specific spender.
262
+ *
263
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
264
+ * @param owner - Address to check allowance for
265
+ * @param spender - Address of the approved spender
266
+ * @returns Current allowance in wei
267
+ */
268
+ getDebtAllowance(debtTokenSymbol, owner, spender) {
269
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.getDebtAllowance(ctx, owner, spender));
270
+ }
271
+ /**
272
+ * Gets the current gas compensation token allowance.
273
+ *
274
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
275
+ * @param owner - Address to check allowance for
276
+ * @returns Current allowance in wei
277
+ */
278
+ getGasTokenAllowance(debtTokenSymbol, owner) {
279
+ return this.withContext(debtTokenSymbol, (ctx) => this.approvalService.getGasTokenAllowance(ctx, owner));
280
+ }
281
+ /**
282
+ * Fetches on-chain data for a specific trove.
283
+ * The returned position reflects the trove's current lifecycle status, including
284
+ * zombie troves that may still hold collateral even when their debt is zero.
285
+ *
286
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
287
+ * @param troveId - The NFT token ID identifying the trove
288
+ * @returns Trove position data including collateral, debt, interest rate, and status
289
+ */
290
+ getTroveData(debtTokenSymbol, troveId) {
291
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getTroveData(ctx, troveId));
292
+ }
293
+ /**
294
+ * Fetches troves currently owned by an address via the Trove NFT.
295
+ * This includes zombie troves that have been removed from `SortedTroves` but are still owned
296
+ * by the address. Closed or liquidated troves are not returned once their Trove NFT is burned
297
+ * or transferred away.
298
+ *
299
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
300
+ * @param owner - Address to query troves for
301
+ * @returns Array of trove positions currently owned by the address
302
+ */
303
+ getUserTroves(debtTokenSymbol, owner) {
304
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getUserTroves(ctx, owner));
305
+ }
306
+ /**
307
+ * Gets the current collateral token price from the price feed.
308
+ *
309
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
310
+ * @returns Collateral price in 18-decimal fixed-point format
311
+ */
312
+ getCollateralPrice(debtTokenSymbol) {
313
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getCollateralPrice(ctx));
314
+ }
315
+ /**
316
+ * Gets the system parameters for a borrowing deployment.
317
+ * Returns MCR, CCR, SCR, BCR, minimum debt, gas compensation, and minimum interest rate.
318
+ *
319
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
320
+ * @returns System parameters (all values in 18-decimal fixed-point)
321
+ */
322
+ getSystemParams(debtTokenSymbol) {
323
+ return this.withContext(debtTokenSymbol, (ctx) => ({ ...ctx.systemParams }));
324
+ }
325
+ /**
326
+ * Checks whether the borrowing system has been shut down (e.g., during a crisis).
327
+ *
328
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
329
+ * @returns true if the system is shut down, false otherwise
330
+ */
331
+ isSystemShutDown(debtTokenSymbol) {
332
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.isSystemShutDown(ctx));
333
+ }
334
+ /**
335
+ * Gets aggregate collateral and debt statistics for the borrowing branch.
336
+ *
337
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
338
+ * @returns Total collateral and total debt across all troves (in wei)
339
+ */
340
+ getBranchStats(debtTokenSymbol) {
341
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getBranchStats(ctx));
342
+ }
343
+ /**
344
+ * Gets the distribution of debt across interest rate brackets.
345
+ *
346
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
347
+ * @returns Array of brackets, each with a rate and total debt at that rate
348
+ */
349
+ getInterestRateBrackets(debtTokenSymbol) {
350
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getInterestRateBrackets(ctx));
351
+ }
352
+ /**
353
+ * Gets the weighted average interest rate across all active troves.
354
+ *
355
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
356
+ * @returns Average annual interest rate in 18-decimal fixed-point
357
+ */
358
+ getAverageInterestRate(debtTokenSymbol) {
359
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getAverageInterestRate(ctx));
360
+ }
361
+ /**
362
+ * Gets information about a batch manager's configuration.
363
+ *
364
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
365
+ * @param address - Address of the batch manager
366
+ * @returns Batch manager config (min/max rate, min change period), or null if not a valid manager
367
+ */
368
+ getBatchManagerInfo(debtTokenSymbol, address) {
369
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getBatchManagerInfo(ctx, address));
370
+ }
371
+ /**
372
+ * Estimates the upfront fee for opening a new trove.
373
+ *
374
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
375
+ * @param amount - Debt amount to borrow (in wei)
376
+ * @param rate - Annual interest rate (18-decimal fixed-point)
377
+ * @returns Estimated upfront fee in wei
378
+ */
379
+ predictOpenTroveUpfrontFee(debtTokenSymbol, amount, rate) {
380
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.predictOpenTroveUpfrontFee(ctx, amount, rate));
381
+ }
382
+ /**
383
+ * Estimates the upfront fee for increasing debt on an existing trove.
384
+ *
385
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
386
+ * @param troveId - The NFT token ID identifying the trove
387
+ * @param debtIncrease - Amount of additional debt (in wei)
388
+ * @returns Estimated upfront fee in wei
389
+ */
390
+ predictAdjustUpfrontFee(debtTokenSymbol, troveId, debtIncrease) {
391
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.predictAdjustUpfrontFee(ctx, troveId, debtIncrease));
392
+ }
393
+ /**
394
+ * Estimates the upfront fee for changing a trove's interest rate.
395
+ *
396
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
397
+ * @param troveId - The NFT token ID identifying the trove
398
+ * @param newRate - New annual interest rate (18-decimal fixed-point)
399
+ * @returns Estimated upfront fee in wei
400
+ */
401
+ predictAdjustInterestRateUpfrontFee(debtTokenSymbol, troveId, newRate) {
402
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.predictAdjustInterestRateUpfrontFee(ctx, troveId, newRate));
403
+ }
404
+ /**
405
+ * Estimates the upfront fee for joining a batch manager.
406
+ *
407
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
408
+ * @param troveId - The NFT token ID identifying the trove
409
+ * @param batchAddress - Address of the batch manager to join
410
+ * @returns Estimated upfront fee in wei
411
+ */
412
+ predictJoinBatchUpfrontFee(debtTokenSymbol, troveId, batchAddress) {
413
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.predictJoinBatchUpfrontFee(ctx, troveId, batchAddress));
414
+ }
415
+ /**
416
+ * Gets the current number of troves owned by an address via the Trove NFT.
417
+ *
418
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
419
+ * @param owner - Address of the trove owner
420
+ * @returns The number of troves currently owned by the address
421
+ */
422
+ getOwnedTroveCount(debtTokenSymbol, owner) {
423
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getOwnedTroveCount(ctx, owner));
424
+ }
425
+ /**
426
+ * Finds the first safe owner index for opening a trove with the given transaction sender.
427
+ *
428
+ * The `opener` must be the address that will call BorrowerOperations on-chain.
429
+ * For smart accounts, pass the smart account address rather than the controlling EOA.
430
+ *
431
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
432
+ * @param owner - Address that will own the trove NFT
433
+ * @param opener - Address that will submit the open-trove transaction on-chain
434
+ * @returns The first owner index that does not already map to an existing trove
435
+ */
436
+ findNextAvailableOwnerIndex(debtTokenSymbol, owner, opener) {
437
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.findNextAvailableOwnerIndex(ctx, owner, opener));
438
+ }
439
+ /**
440
+ * Gets the current number of troves owned by an address via the Trove NFT.
441
+ *
442
+ * @deprecated Use `findNextAvailableOwnerIndex` when preparing an open-trove transaction.
443
+ *
444
+ * @param debtTokenSymbol - The debt token symbol (e.g., 'GBPm')
445
+ * @param owner - Address of the trove owner
446
+ * @returns The number of troves currently owned by the address
447
+ */
448
+ getNextOwnerIndex(debtTokenSymbol, owner) {
449
+ return this.withContext(debtTokenSymbol, (ctx) => this.readService.getOwnedTroveCount(ctx, owner));
450
+ }
451
+ async withContext(debtTokenSymbol, callback) {
452
+ const ctx = await this.ensureInitialized(debtTokenSymbol);
453
+ return callback(ctx);
454
+ }
455
+ ensureInitialized(debtTokenSymbol) {
456
+ return this.contextStore.ensureInitialized(debtTokenSymbol);
457
+ }
458
+ }
459
+ exports.BorrowService = BorrowService;
460
+ //# sourceMappingURL=BorrowService.js.map
@@ -0,0 +1,4 @@
1
+ export { resolveAddressesFromRegistry, readSystemParams, } from './internal/borrowRegistryReader';
2
+ export { buildErc20ApprovalParams as buildCollateralApprovalParams, readErc20Allowance as getCollateralAllowance, } from './internal/borrowErc20';
3
+ export { mapTroveStatus, parseBorrowPosition } from './internal/borrowPositionParser';
4
+ //# sourceMappingURL=borrowHelpers.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseBorrowPosition = exports.mapTroveStatus = exports.getCollateralAllowance = exports.buildCollateralApprovalParams = exports.readSystemParams = exports.resolveAddressesFromRegistry = void 0;
4
+ var borrowRegistryReader_1 = require("./internal/borrowRegistryReader");
5
+ Object.defineProperty(exports, "resolveAddressesFromRegistry", { enumerable: true, get: function () { return borrowRegistryReader_1.resolveAddressesFromRegistry; } });
6
+ Object.defineProperty(exports, "readSystemParams", { enumerable: true, get: function () { return borrowRegistryReader_1.readSystemParams; } });
7
+ var borrowErc20_1 = require("./internal/borrowErc20");
8
+ Object.defineProperty(exports, "buildCollateralApprovalParams", { enumerable: true, get: function () { return borrowErc20_1.buildErc20ApprovalParams; } });
9
+ Object.defineProperty(exports, "getCollateralAllowance", { enumerable: true, get: function () { return borrowErc20_1.readErc20Allowance; } });
10
+ var borrowPositionParser_1 = require("./internal/borrowPositionParser");
11
+ Object.defineProperty(exports, "mapTroveStatus", { enumerable: true, get: function () { return borrowPositionParser_1.mapTroveStatus; } });
12
+ Object.defineProperty(exports, "parseBorrowPosition", { enumerable: true, get: function () { return borrowPositionParser_1.parseBorrowPosition; } });
13
+ //# sourceMappingURL=borrowHelpers.js.map
@@ -0,0 +1,21 @@
1
+ import type { LoanDetails, RiskLevel } from '../../core/types';
2
+ export declare function getLtv(collateral: bigint, debt: bigint, collPrice: bigint): bigint | null;
3
+ export declare function getLiquidationPrice(collateral: bigint, debt: bigint, mcr: bigint): bigint | null;
4
+ export declare function getLiquidationRisk(ltv: bigint, maxLtv: bigint): RiskLevel;
5
+ export declare function getRedemptionRisk(debtInFront: bigint, totalDebt: bigint): RiskLevel | null;
6
+ export declare function calculateMaxDebt(collateralUsd: bigint, maxLtv: bigint): bigint;
7
+ export declare function calculateDebtSuggestions(maxDebt: bigint, minDebt: bigint): {
8
+ amount: bigint;
9
+ ltv: bigint;
10
+ risk: RiskLevel;
11
+ }[];
12
+ /**
13
+ * Computes collateralization metrics from the supplied collateral, debt, price, and MCR.
14
+ *
15
+ * This helper is lifecycle-agnostic: it does not inspect trove status. For example, a zombie
16
+ * trove with `debt === 0` may still hold collateral on-chain, but this function only reports
17
+ * the math implied by the inputs. Combine its output with `BorrowPosition.status` when building
18
+ * UI for open, zombie, closed, or liquidated troves.
19
+ */
20
+ export declare function getLoanDetails(collateral: bigint | null, debt: bigint | null, interestRate: bigint | null, collPrice: bigint | null, mcr: bigint): LoanDetails;
21
+ //# sourceMappingURL=borrowMath.d.ts.map
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLtv = getLtv;
4
+ exports.getLiquidationPrice = getLiquidationPrice;
5
+ exports.getLiquidationRisk = getLiquidationRisk;
6
+ exports.getRedemptionRisk = getRedemptionRisk;
7
+ exports.calculateMaxDebt = calculateMaxDebt;
8
+ exports.calculateDebtSuggestions = calculateDebtSuggestions;
9
+ exports.getLoanDetails = getLoanDetails;
10
+ const constants_1 = require("../../core/constants");
11
+ const DECIMAL_PRECISION = 10n ** 18n;
12
+ const THOUSAND = 1000n;
13
+ const NORMALIZED_MAX_LTV = DECIMAL_PRECISION;
14
+ const DEBT_SUGGESTION_RATIOS = [300n, 600n, 800n];
15
+ function getLtv(collateral, debt, collPrice) {
16
+ const collateralUsd = (collateral * collPrice) / DECIMAL_PRECISION;
17
+ if (collateralUsd === 0n)
18
+ return null;
19
+ return (debt * DECIMAL_PRECISION) / collateralUsd;
20
+ }
21
+ function getLiquidationPrice(collateral, debt, mcr) {
22
+ if (collateral <= 0n || debt <= 0n)
23
+ return null;
24
+ if (mcr <= DECIMAL_PRECISION)
25
+ return null;
26
+ // liquidationPrice = (debt * mcr) / collateral
27
+ return (debt * mcr) / collateral;
28
+ }
29
+ function getLiquidationRisk(ltv, maxLtv) {
30
+ if (maxLtv <= 0n)
31
+ return 'low';
32
+ // Compare using cross-multiplication to avoid floor-division drift.
33
+ if (ltv * THOUSAND > maxLtv * constants_1.LTV_RISK_HIGH)
34
+ return 'high';
35
+ if (ltv * THOUSAND > maxLtv * constants_1.LTV_RISK_MEDIUM)
36
+ return 'medium';
37
+ return 'low';
38
+ }
39
+ function getRedemptionRisk(debtInFront, totalDebt) {
40
+ if (totalDebt === 0n)
41
+ return null;
42
+ // Compare using cross-multiplication to avoid floor-division drift.
43
+ if (debtInFront * THOUSAND > totalDebt * constants_1.REDEMPTION_RISK_LOW)
44
+ return 'low';
45
+ if (debtInFront * THOUSAND > totalDebt * constants_1.REDEMPTION_RISK_MEDIUM)
46
+ return 'medium';
47
+ return 'high';
48
+ }
49
+ function calculateMaxDebt(collateralUsd, maxLtv) {
50
+ return (collateralUsd * maxLtv) / DECIMAL_PRECISION;
51
+ }
52
+ function calculateDebtSuggestions(maxDebt, minDebt) {
53
+ if (maxDebt <= 0n)
54
+ return [];
55
+ const suggestions = [];
56
+ for (let i = 0; i < DEBT_SUGGESTION_RATIOS.length; i++) {
57
+ let amount = (maxDebt * DEBT_SUGGESTION_RATIOS[i]) / THOUSAND;
58
+ // Mirror frontend behavior:
59
+ // - First suggestion is clamped up to minDebt.
60
+ // - Later suggestions below minDebt are omitted.
61
+ if (amount < minDebt) {
62
+ if (i === 0) {
63
+ amount = minDebt;
64
+ }
65
+ else {
66
+ continue;
67
+ }
68
+ }
69
+ // ltv relative to maxLtv (normalized to 1e18 where 1e18 === maxLtv)
70
+ const ltv = (amount * DECIMAL_PRECISION) / maxDebt;
71
+ // Hide suggestions that exceed maxLtv.
72
+ if (ltv > NORMALIZED_MAX_LTV) {
73
+ continue;
74
+ }
75
+ suggestions.push({
76
+ amount,
77
+ ltv,
78
+ risk: getLiquidationRisk(ltv, NORMALIZED_MAX_LTV),
79
+ });
80
+ }
81
+ return suggestions;
82
+ }
83
+ /**
84
+ * Computes collateralization metrics from the supplied collateral, debt, price, and MCR.
85
+ *
86
+ * This helper is lifecycle-agnostic: it does not inspect trove status. For example, a zombie
87
+ * trove with `debt === 0` may still hold collateral on-chain, but this function only reports
88
+ * the math implied by the inputs. Combine its output with `BorrowPosition.status` when building
89
+ * UI for open, zombie, closed, or liquidated troves.
90
+ */
91
+ function getLoanDetails(collateral, debt, interestRate, collPrice, mcr) {
92
+ // maxLtv = 1 / MCR (MCR is e.g. 1.1e18 meaning 110%)
93
+ const maxLtv = (DECIMAL_PRECISION * DECIMAL_PRECISION) / mcr;
94
+ // maxLtvAllowed = maxLtv * MAX_LTV_ALLOWED_RATIO / 1000
95
+ const maxLtvAllowed = (maxLtv * constants_1.MAX_LTV_ALLOWED_RATIO) / THOUSAND;
96
+ const collateralUsd = collateral !== null && collPrice !== null
97
+ ? (collateral * collPrice) / DECIMAL_PRECISION
98
+ : null;
99
+ const ltv = debt !== null && collateralUsd !== null && collateralUsd > 0n
100
+ ? (debt * DECIMAL_PRECISION) / collateralUsd
101
+ : collateral !== null && collateral < 0n
102
+ ? DECIMAL_PRECISION
103
+ : null;
104
+ const status = ltv === null
105
+ ? null
106
+ : collateral !== null && (collateral < 0n || ltv > DECIMAL_PRECISION)
107
+ ? 'underwater'
108
+ : ltv > maxLtv
109
+ ? 'liquidatable'
110
+ : ltv > maxLtvAllowed
111
+ ? 'at-risk'
112
+ : 'healthy';
113
+ const maxDebt = collateralUsd !== null ? calculateMaxDebt(collateralUsd, maxLtv) : null;
114
+ const maxDebtAllowed = collateralUsd !== null && collateralUsd > 0n
115
+ ? (collateralUsd * maxLtvAllowed) / DECIMAL_PRECISION
116
+ : null;
117
+ const liquidationRisk = ltv !== null ? getLiquidationRisk(ltv, maxLtv) : null;
118
+ const liquidationPrice = collateral !== null && debt !== null && collateral > 0n
119
+ ? getLiquidationPrice(collateral, debt, mcr)
120
+ : null;
121
+ return {
122
+ collateral,
123
+ collateralUsd,
124
+ collPrice,
125
+ debt,
126
+ interestRate,
127
+ ltv,
128
+ maxLtv,
129
+ maxLtvAllowed,
130
+ liquidationPrice,
131
+ liquidationRisk,
132
+ maxDebt,
133
+ maxDebtAllowed,
134
+ status,
135
+ };
136
+ }
137
+ //# sourceMappingURL=borrowMath.js.map
@@ -0,0 +1,4 @@
1
+ export * from './BorrowService';
2
+ export * from './borrowHelpers';
3
+ export * from './borrowMath';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./tradingLimit"), exports);
18
- __exportStar(require("./tradingLimitsConfig"), exports);
19
- __exportStar(require("./tradingLimitsState"), exports);
20
- __exportStar(require("./IChainClient"), exports);
17
+ __exportStar(require("./BorrowService"), exports);
18
+ __exportStar(require("./borrowHelpers"), exports);
19
+ __exportStar(require("./borrowMath"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ import { PublicClient } from 'viem';
2
+ import { CallParams } from '../../../core/types';
3
+ import { DeploymentContext } from './borrowTypes';
4
+ export declare class BorrowApprovalService {
5
+ private publicClient;
6
+ constructor(publicClient: PublicClient);
7
+ buildCollateralApprovalParams(ctx: DeploymentContext, amount: bigint): CallParams;
8
+ buildDebtApprovalParams(ctx: DeploymentContext, spender: string, amount: bigint): CallParams;
9
+ buildGasCompensationApprovalParams(ctx: DeploymentContext, amount?: bigint): CallParams;
10
+ getCollateralAllowance(ctx: DeploymentContext, owner: string): Promise<bigint>;
11
+ getDebtAllowance(ctx: DeploymentContext, owner: string, spender: string): Promise<bigint>;
12
+ getGasTokenAllowance(ctx: DeploymentContext, owner: string): Promise<bigint>;
13
+ }
14
+ //# sourceMappingURL=borrowApprovalService.d.ts.map