@mento-protocol/mento-sdk 3.2.2-beta1 → 3.2.3

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