@mento-protocol/mento-sdk 3.2.7-beta.0 → 3.2.7

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 (302) hide show
  1. package/package.json +1 -1
  2. package/dist/cache/routes.d.ts +0 -13
  3. package/dist/cache/routes.js +0 -14649
  4. package/dist/cache/tokens.d.ts +0 -68
  5. package/dist/cache/tokens.js +0 -488
  6. package/dist/core/abis/activePool.d.ts +0 -2
  7. package/dist/core/abis/activePool.js +0 -14
  8. package/dist/core/abis/addressesRegistry.d.ts +0 -2
  9. package/dist/core/abis/addressesRegistry.js +0 -26
  10. package/dist/core/abis/bipoolmanager.d.ts +0 -34
  11. package/dist/core/abis/bipoolmanager.js +0 -72
  12. package/dist/core/abis/borrowerOperations.d.ts +0 -9
  13. package/dist/core/abis/borrowerOperations.js +0 -89
  14. package/dist/core/abis/breakerbox.d.ts +0 -13
  15. package/dist/core/abis/breakerbox.js +0 -8
  16. package/dist/core/abis/broker.d.ts +0 -2
  17. package/dist/core/abis/broker.js +0 -9
  18. package/dist/core/abis/erc20.d.ts +0 -9
  19. package/dist/core/abis/erc20.js +0 -21
  20. package/dist/core/abis/fpmm.d.ts +0 -270
  21. package/dist/core/abis/fpmm.js +0 -49
  22. package/dist/core/abis/fpmmFactory.d.ts +0 -85
  23. package/dist/core/abis/fpmmFactory.js +0 -26
  24. package/dist/core/abis/hintHelpers.d.ts +0 -2
  25. package/dist/core/abis/hintHelpers.js +0 -14
  26. package/dist/core/abis/index.d.ts +0 -22
  27. package/dist/core/abis/index.js +0 -38
  28. package/dist/core/abis/liquidityStrategy.d.ts +0 -132
  29. package/dist/core/abis/liquidityStrategy.js +0 -10
  30. package/dist/core/abis/multiTroveGetter.d.ts +0 -8
  31. package/dist/core/abis/multiTroveGetter.js +0 -15
  32. package/dist/core/abis/priceFeed.d.ts +0 -7
  33. package/dist/core/abis/priceFeed.js +0 -16
  34. package/dist/core/abis/pricingmodule.d.ts +0 -2
  35. package/dist/core/abis/pricingmodule.js +0 -6
  36. package/dist/core/abis/reserve.d.ts +0 -3
  37. package/dist/core/abis/reserve.js +0 -18
  38. package/dist/core/abis/router.d.ts +0 -521
  39. package/dist/core/abis/router.js +0 -45
  40. package/dist/core/abis/sortedTroves.d.ts +0 -2
  41. package/dist/core/abis/sortedTroves.js +0 -15
  42. package/dist/core/abis/systemParams.d.ts +0 -2
  43. package/dist/core/abis/systemParams.js +0 -14
  44. package/dist/core/abis/troveManager.d.ts +0 -2
  45. package/dist/core/abis/troveManager.js +0 -27
  46. package/dist/core/abis/troveNFT.d.ts +0 -2
  47. package/dist/core/abis/troveNFT.js +0 -9
  48. package/dist/core/abis/virtualPool.d.ts +0 -50
  49. package/dist/core/abis/virtualPool.js +0 -11
  50. package/dist/core/abis/virtualPoolFactory.d.ts +0 -59
  51. package/dist/core/abis/virtualPoolFactory.js +0 -17
  52. package/dist/core/constants/addresses.d.ts +0 -18
  53. package/dist/core/constants/addresses.js +0 -113
  54. package/dist/core/constants/borrowConstants.d.ts +0 -10
  55. package/dist/core/constants/borrowConstants.js +0 -16
  56. package/dist/core/constants/borrowRegistries.d.ts +0 -7
  57. package/dist/core/constants/borrowRegistries.js +0 -34
  58. package/dist/core/constants/chainId.d.ts +0 -7
  59. package/dist/core/constants/chainId.js +0 -11
  60. package/dist/core/constants/contractNames.d.ts +0 -21
  61. package/dist/core/constants/contractNames.js +0 -24
  62. package/dist/core/constants/index.d.ts +0 -6
  63. package/dist/core/constants/index.js +0 -22
  64. package/dist/core/errors/base.d.ts +0 -8
  65. package/dist/core/errors/base.js +0 -17
  66. package/dist/core/errors/index.d.ts +0 -4
  67. package/dist/core/errors/index.js +0 -20
  68. package/dist/core/errors/oracle.d.ts +0 -9
  69. package/dist/core/errors/oracle.js +0 -15
  70. package/dist/core/errors/router.d.ts +0 -14
  71. package/dist/core/errors/router.js +0 -24
  72. package/dist/core/types/borrow.d.ts +0 -87
  73. package/dist/core/types/borrow.js +0 -3
  74. package/dist/core/types/contractAddresses.d.ts +0 -42
  75. package/dist/core/types/contractAddresses.js +0 -3
  76. package/dist/core/types/index.d.ts +0 -10
  77. package/dist/core/types/index.js +0 -26
  78. package/dist/core/types/liquidity.d.ts +0 -194
  79. package/dist/core/types/liquidity.js +0 -3
  80. package/dist/core/types/pool.d.ts +0 -208
  81. package/dist/core/types/pool.js +0 -14
  82. package/dist/core/types/provider.d.ts +0 -45
  83. package/dist/core/types/provider.js +0 -3
  84. package/dist/core/types/route.d.ts +0 -62
  85. package/dist/core/types/route.js +0 -3
  86. package/dist/core/types/token.d.ts +0 -21
  87. package/dist/core/types/token.js +0 -3
  88. package/dist/core/types/tradingLimits.d.ts +0 -91
  89. package/dist/core/types/tradingLimits.js +0 -3
  90. package/dist/core/types/tradingMode.d.ts +0 -24
  91. package/dist/core/types/tradingMode.js +0 -31
  92. package/dist/core/types/transaction.d.ts +0 -45
  93. package/dist/core/types/transaction.js +0 -3
  94. package/dist/esm/cache/routes.js +0 -14644
  95. package/dist/esm/cache/tokens.js +0 -480
  96. package/dist/esm/core/abis/activePool.js +0 -10
  97. package/dist/esm/core/abis/addressesRegistry.js +0 -22
  98. package/dist/esm/core/abis/bipoolmanager.js +0 -68
  99. package/dist/esm/core/abis/borrowerOperations.js +0 -85
  100. package/dist/esm/core/abis/breakerbox.js +0 -4
  101. package/dist/esm/core/abis/broker.js +0 -5
  102. package/dist/esm/core/abis/erc20.js +0 -17
  103. package/dist/esm/core/abis/fpmm.js +0 -45
  104. package/dist/esm/core/abis/fpmmFactory.js +0 -22
  105. package/dist/esm/core/abis/hintHelpers.js +0 -10
  106. package/dist/esm/core/abis/index.js +0 -21
  107. package/dist/esm/core/abis/liquidityStrategy.js +0 -6
  108. package/dist/esm/core/abis/multiTroveGetter.js +0 -11
  109. package/dist/esm/core/abis/priceFeed.js +0 -12
  110. package/dist/esm/core/abis/pricingmodule.js +0 -2
  111. package/dist/esm/core/abis/reserve.js +0 -14
  112. package/dist/esm/core/abis/router.js +0 -41
  113. package/dist/esm/core/abis/sortedTroves.js +0 -11
  114. package/dist/esm/core/abis/systemParams.js +0 -10
  115. package/dist/esm/core/abis/troveManager.js +0 -23
  116. package/dist/esm/core/abis/troveNFT.js +0 -5
  117. package/dist/esm/core/abis/virtualPool.js +0 -7
  118. package/dist/esm/core/abis/virtualPoolFactory.js +0 -13
  119. package/dist/esm/core/constants/addresses.js +0 -107
  120. package/dist/esm/core/constants/borrowConstants.js +0 -12
  121. package/dist/esm/core/constants/borrowRegistries.js +0 -29
  122. package/dist/esm/core/constants/chainId.js +0 -7
  123. package/dist/esm/core/constants/contractNames.js +0 -20
  124. package/dist/esm/core/constants/index.js +0 -5
  125. package/dist/esm/core/errors/base.js +0 -12
  126. package/dist/esm/core/errors/index.js +0 -3
  127. package/dist/esm/core/errors/oracle.js +0 -10
  128. package/dist/esm/core/errors/router.js +0 -18
  129. package/dist/esm/core/types/borrow.js +0 -1
  130. package/dist/esm/core/types/contractAddresses.js +0 -1
  131. package/dist/esm/core/types/index.js +0 -9
  132. package/dist/esm/core/types/liquidity.js +0 -1
  133. package/dist/esm/core/types/pool.js +0 -10
  134. package/dist/esm/core/types/provider.js +0 -1
  135. package/dist/esm/core/types/route.js +0 -1
  136. package/dist/esm/core/types/token.js +0 -1
  137. package/dist/esm/core/types/tradingLimits.js +0 -1
  138. package/dist/esm/core/types/tradingMode.js +0 -26
  139. package/dist/esm/core/types/transaction.js +0 -1
  140. package/dist/esm/index.js +0 -139
  141. package/dist/esm/package.json +0 -1
  142. package/dist/esm/services/borrow/BorrowService.js +0 -455
  143. package/dist/esm/services/borrow/borrowHelpers.js +0 -3
  144. package/dist/esm/services/borrow/borrowMath.js +0 -127
  145. package/dist/esm/services/borrow/index.js +0 -3
  146. package/dist/esm/services/borrow/internal/borrowApprovalService.js +0 -48
  147. package/dist/esm/services/borrow/internal/borrowContextStore.js +0 -35
  148. package/dist/esm/services/borrow/internal/borrowErc20.js +0 -38
  149. package/dist/esm/services/borrow/internal/borrowHints.js +0 -27
  150. package/dist/esm/services/borrow/internal/borrowPositionParser.js +0 -82
  151. package/dist/esm/services/borrow/internal/borrowReadService.js +0 -271
  152. package/dist/esm/services/borrow/internal/borrowRegistryReader.js +0 -108
  153. package/dist/esm/services/borrow/internal/borrowTransactionService.js +0 -271
  154. package/dist/esm/services/borrow/internal/borrowTypes.js +0 -1
  155. package/dist/esm/services/borrow/internal/borrowValidation.js +0 -89
  156. package/dist/esm/services/index.js +0 -8
  157. package/dist/esm/services/liquidity/LiquidityService.js +0 -163
  158. package/dist/esm/services/liquidity/basicLiquidity.js +0 -162
  159. package/dist/esm/services/liquidity/index.js +0 -1
  160. package/dist/esm/services/liquidity/liquidityHelpers.js +0 -95
  161. package/dist/esm/services/liquidity/rebalance.js +0 -59
  162. package/dist/esm/services/liquidity/zapHelpers.js +0 -181
  163. package/dist/esm/services/liquidity/zapIn.js +0 -131
  164. package/dist/esm/services/liquidity/zapOut.js +0 -248
  165. package/dist/esm/services/pools/PoolService.js +0 -204
  166. package/dist/esm/services/pools/index.js +0 -1
  167. package/dist/esm/services/pools/poolDetails.js +0 -209
  168. package/dist/esm/services/pools/poolDiscovery.js +0 -112
  169. package/dist/esm/services/pools/rebalancePreview.js +0 -181
  170. package/dist/esm/services/quotes/QuoteService.js +0 -85
  171. package/dist/esm/services/quotes/index.js +0 -1
  172. package/dist/esm/services/routes/RouteService.js +0 -268
  173. package/dist/esm/services/routes/index.js +0 -1
  174. package/dist/esm/services/swap/SwapService.js +0 -247
  175. package/dist/esm/services/swap/index.js +0 -1
  176. package/dist/esm/services/tokens/index.js +0 -1
  177. package/dist/esm/services/tokens/tokenService.js +0 -285
  178. package/dist/esm/services/trading/TradingLimitsService.js +0 -154
  179. package/dist/esm/services/trading/TradingService.js +0 -222
  180. package/dist/esm/services/trading/index.js +0 -2
  181. package/dist/esm/utils/chainConfig.js +0 -118
  182. package/dist/esm/utils/costUtils.js +0 -56
  183. package/dist/esm/utils/deadline.js +0 -22
  184. package/dist/esm/utils/index.js +0 -9
  185. package/dist/esm/utils/multicall.js +0 -47
  186. package/dist/esm/utils/pathEncoder.js +0 -69
  187. package/dist/esm/utils/rateFeed.js +0 -23
  188. package/dist/esm/utils/retry.js +0 -24
  189. package/dist/esm/utils/routeUtils.js +0 -361
  190. package/dist/esm/utils/routes.js +0 -2
  191. package/dist/esm/utils/sortUtils.js +0 -33
  192. package/dist/esm/utils/tokens.js +0 -2
  193. package/dist/esm/utils/tradingLimits.js +0 -163
  194. package/dist/esm/utils/validation.js +0 -30
  195. package/dist/index.d.ts +0 -101
  196. package/dist/index.js +0 -158
  197. package/dist/services/borrow/BorrowService.d.ts +0 -381
  198. package/dist/services/borrow/BorrowService.js +0 -460
  199. package/dist/services/borrow/borrowHelpers.d.ts +0 -4
  200. package/dist/services/borrow/borrowHelpers.js +0 -13
  201. package/dist/services/borrow/borrowMath.d.ts +0 -21
  202. package/dist/services/borrow/borrowMath.js +0 -137
  203. package/dist/services/borrow/index.d.ts +0 -4
  204. package/dist/services/borrow/index.js +0 -20
  205. package/dist/services/borrow/internal/borrowApprovalService.d.ts +0 -14
  206. package/dist/services/borrow/internal/borrowApprovalService.js +0 -53
  207. package/dist/services/borrow/internal/borrowContextStore.d.ts +0 -11
  208. package/dist/services/borrow/internal/borrowContextStore.js +0 -40
  209. package/dist/services/borrow/internal/borrowErc20.d.ts +0 -5
  210. package/dist/services/borrow/internal/borrowErc20.js +0 -43
  211. package/dist/services/borrow/internal/borrowHints.d.ts +0 -7
  212. package/dist/services/borrow/internal/borrowHints.js +0 -31
  213. package/dist/services/borrow/internal/borrowPositionParser.d.ts +0 -4
  214. package/dist/services/borrow/internal/borrowPositionParser.js +0 -87
  215. package/dist/services/borrow/internal/borrowReadService.d.ts +0 -31
  216. package/dist/services/borrow/internal/borrowReadService.js +0 -276
  217. package/dist/services/borrow/internal/borrowRegistryReader.d.ts +0 -5
  218. package/dist/services/borrow/internal/borrowRegistryReader.js +0 -113
  219. package/dist/services/borrow/internal/borrowTransactionService.d.ts +0 -23
  220. package/dist/services/borrow/internal/borrowTransactionService.js +0 -276
  221. package/dist/services/borrow/internal/borrowTypes.d.ts +0 -15
  222. package/dist/services/borrow/internal/borrowTypes.js +0 -3
  223. package/dist/services/borrow/internal/borrowValidation.d.ts +0 -14
  224. package/dist/services/borrow/internal/borrowValidation.js +0 -104
  225. package/dist/services/index.d.ts +0 -9
  226. package/dist/services/index.js +0 -25
  227. package/dist/services/liquidity/LiquidityService.d.ts +0 -139
  228. package/dist/services/liquidity/LiquidityService.js +0 -168
  229. package/dist/services/liquidity/basicLiquidity.d.ts +0 -11
  230. package/dist/services/liquidity/basicLiquidity.js +0 -172
  231. package/dist/services/liquidity/index.d.ts +0 -2
  232. package/dist/services/liquidity/index.js +0 -18
  233. package/dist/services/liquidity/liquidityHelpers.d.ts +0 -19
  234. package/dist/services/liquidity/liquidityHelpers.js +0 -104
  235. package/dist/services/liquidity/rebalance.d.ts +0 -6
  236. package/dist/services/liquidity/rebalance.js +0 -64
  237. package/dist/services/liquidity/zapHelpers.d.ts +0 -100
  238. package/dist/services/liquidity/zapHelpers.js +0 -192
  239. package/dist/services/liquidity/zapIn.d.ts +0 -18
  240. package/dist/services/liquidity/zapIn.js +0 -138
  241. package/dist/services/liquidity/zapOut.d.ts +0 -9
  242. package/dist/services/liquidity/zapOut.js +0 -255
  243. package/dist/services/pools/PoolService.d.ts +0 -69
  244. package/dist/services/pools/PoolService.js +0 -209
  245. package/dist/services/pools/index.d.ts +0 -2
  246. package/dist/services/pools/index.js +0 -18
  247. package/dist/services/pools/poolDetails.d.ts +0 -13
  248. package/dist/services/pools/poolDetails.js +0 -216
  249. package/dist/services/pools/poolDiscovery.d.ts +0 -12
  250. package/dist/services/pools/poolDiscovery.js +0 -117
  251. package/dist/services/pools/rebalancePreview.d.ts +0 -5
  252. package/dist/services/pools/rebalancePreview.js +0 -186
  253. package/dist/services/quotes/QuoteService.d.ts +0 -51
  254. package/dist/services/quotes/QuoteService.js +0 -91
  255. package/dist/services/quotes/index.d.ts +0 -2
  256. package/dist/services/quotes/index.js +0 -18
  257. package/dist/services/routes/RouteService.d.ts +0 -117
  258. package/dist/services/routes/RouteService.js +0 -306
  259. package/dist/services/routes/index.d.ts +0 -2
  260. package/dist/services/routes/index.js +0 -18
  261. package/dist/services/swap/SwapService.d.ts +0 -198
  262. package/dist/services/swap/SwapService.js +0 -252
  263. package/dist/services/swap/index.d.ts +0 -2
  264. package/dist/services/swap/index.js +0 -18
  265. package/dist/services/tokens/index.d.ts +0 -2
  266. package/dist/services/tokens/index.js +0 -18
  267. package/dist/services/tokens/tokenService.d.ts +0 -55
  268. package/dist/services/tokens/tokenService.js +0 -290
  269. package/dist/services/trading/TradingLimitsService.d.ts +0 -38
  270. package/dist/services/trading/TradingLimitsService.js +0 -159
  271. package/dist/services/trading/TradingService.d.ts +0 -115
  272. package/dist/services/trading/TradingService.js +0 -227
  273. package/dist/services/trading/index.d.ts +0 -3
  274. package/dist/services/trading/index.js +0 -19
  275. package/dist/utils/chainConfig.d.ts +0 -16
  276. package/dist/utils/chainConfig.js +0 -123
  277. package/dist/utils/costUtils.d.ts +0 -12
  278. package/dist/utils/costUtils.js +0 -60
  279. package/dist/utils/deadline.d.ts +0 -21
  280. package/dist/utils/deadline.js +0 -26
  281. package/dist/utils/index.d.ts +0 -10
  282. package/dist/utils/index.js +0 -26
  283. package/dist/utils/multicall.d.ts +0 -30
  284. package/dist/utils/multicall.js +0 -52
  285. package/dist/utils/pathEncoder.d.ts +0 -34
  286. package/dist/utils/pathEncoder.js +0 -73
  287. package/dist/utils/rateFeed.d.ts +0 -18
  288. package/dist/utils/rateFeed.js +0 -27
  289. package/dist/utils/retry.d.ts +0 -12
  290. package/dist/utils/retry.js +0 -28
  291. package/dist/utils/routeUtils.d.ts +0 -295
  292. package/dist/utils/routeUtils.js +0 -371
  293. package/dist/utils/routes.d.ts +0 -3
  294. package/dist/utils/routes.js +0 -8
  295. package/dist/utils/sortUtils.d.ts +0 -24
  296. package/dist/utils/sortUtils.js +0 -39
  297. package/dist/utils/tokens.d.ts +0 -2
  298. package/dist/utils/tokens.js +0 -13
  299. package/dist/utils/tradingLimits.d.ts +0 -41
  300. package/dist/utils/tradingLimits.js +0 -171
  301. package/dist/utils/validation.d.ts +0 -19
  302. package/dist/utils/validation.js +0 -34
@@ -1,14 +0,0 @@
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
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BorrowApprovalService = void 0;
4
- const viem_1 = require("viem");
5
- const abis_1 = require("../../../core/abis");
6
- const borrowErc20_1 = require("./borrowErc20");
7
- const borrowValidation_1 = require("./borrowValidation");
8
- const ZERO_VALUE = '0';
9
- class BorrowApprovalService {
10
- constructor(publicClient) {
11
- this.publicClient = publicClient;
12
- }
13
- buildCollateralApprovalParams(ctx, amount) {
14
- const approvalAmount = (0, borrowValidation_1.requireNonNegativeBigInt)(amount, 'amount');
15
- return (0, borrowErc20_1.buildErc20ApprovalParams)(ctx.addresses.collToken, ctx.addresses.borrowerOperations, approvalAmount);
16
- }
17
- buildDebtApprovalParams(ctx, spender, amount) {
18
- const spenderAddress = (0, borrowValidation_1.requireAddress)(spender, 'spender');
19
- const approvalAmount = (0, borrowValidation_1.requireNonNegativeBigInt)(amount, 'amount');
20
- const data = (0, viem_1.encodeFunctionData)({
21
- abi: abis_1.ERC20_ABI,
22
- functionName: 'approve',
23
- args: [spenderAddress, approvalAmount],
24
- });
25
- return { to: ctx.addresses.debtToken, data, value: ZERO_VALUE };
26
- }
27
- buildGasCompensationApprovalParams(ctx, amount) {
28
- const approvalAmount = amount === undefined
29
- ? ctx.systemParams.ethGasCompensation
30
- : (0, borrowValidation_1.requireNonNegativeBigInt)(amount, 'amount');
31
- return (0, borrowErc20_1.buildErc20ApprovalParams)(ctx.addresses.gasToken, ctx.addresses.borrowerOperations, approvalAmount);
32
- }
33
- async getCollateralAllowance(ctx, owner) {
34
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
35
- return (0, borrowErc20_1.readErc20Allowance)(this.publicClient, ctx.addresses.collToken, ownerAddress, ctx.addresses.borrowerOperations);
36
- }
37
- async getDebtAllowance(ctx, owner, spender) {
38
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
39
- const spenderAddress = (0, borrowValidation_1.requireAddress)(spender, 'spender');
40
- return (await this.publicClient.readContract({
41
- address: ctx.addresses.debtToken,
42
- abi: abis_1.ERC20_ABI,
43
- functionName: 'allowance',
44
- args: [ownerAddress, spenderAddress],
45
- }));
46
- }
47
- async getGasTokenAllowance(ctx, owner) {
48
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
49
- return (0, borrowErc20_1.readErc20Allowance)(this.publicClient, ctx.addresses.gasToken, ownerAddress, ctx.addresses.borrowerOperations);
50
- }
51
- }
52
- exports.BorrowApprovalService = BorrowApprovalService;
53
- //# sourceMappingURL=borrowApprovalService.js.map
@@ -1,11 +0,0 @@
1
- import { PublicClient } from 'viem';
2
- import { DeploymentContext } from './borrowTypes';
3
- export declare class BorrowContextStore {
4
- private publicClient;
5
- private chainId;
6
- private deployments;
7
- private initializing;
8
- constructor(publicClient: PublicClient, chainId: number);
9
- ensureInitialized(debtTokenSymbol: string): Promise<DeploymentContext>;
10
- }
11
- //# sourceMappingURL=borrowContextStore.d.ts.map
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BorrowContextStore = void 0;
4
- const constants_1 = require("../../../core/constants");
5
- const borrowRegistryReader_1 = require("./borrowRegistryReader");
6
- const borrowValidation_1 = require("./borrowValidation");
7
- class BorrowContextStore {
8
- constructor(publicClient, chainId) {
9
- this.publicClient = publicClient;
10
- this.chainId = chainId;
11
- this.deployments = new Map();
12
- this.initializing = new Map();
13
- }
14
- async ensureInitialized(debtTokenSymbol) {
15
- const symbol = (0, borrowValidation_1.requireDebtTokenSymbol)(debtTokenSymbol);
16
- const cached = this.deployments.get(symbol);
17
- if (cached)
18
- return cached;
19
- const inFlight = this.initializing.get(symbol);
20
- if (inFlight)
21
- return inFlight;
22
- const initPromise = (async () => {
23
- const registryAddress = (0, constants_1.getBorrowRegistry)(this.chainId, symbol);
24
- const addresses = await (0, borrowRegistryReader_1.resolveAddressesFromRegistry)(this.publicClient, registryAddress);
25
- const systemParams = await (0, borrowRegistryReader_1.readSystemParams)(this.publicClient, addresses.borrowerOperations);
26
- const ctx = { addresses, systemParams };
27
- this.deployments.set(symbol, ctx);
28
- return ctx;
29
- })();
30
- this.initializing.set(symbol, initPromise);
31
- try {
32
- return await initPromise;
33
- }
34
- finally {
35
- this.initializing.delete(symbol);
36
- }
37
- }
38
- }
39
- exports.BorrowContextStore = BorrowContextStore;
40
- //# sourceMappingURL=borrowContextStore.js.map
@@ -1,5 +0,0 @@
1
- import { Address, PublicClient } from 'viem';
2
- import { CallParams } from '../../../core/types';
3
- export declare function buildErc20ApprovalParams(token: Address, spender: Address, amount: bigint): CallParams;
4
- export declare function readErc20Allowance(publicClient: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
5
- //# sourceMappingURL=borrowErc20.d.ts.map
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildErc20ApprovalParams = buildErc20ApprovalParams;
4
- exports.readErc20Allowance = readErc20Allowance;
5
- const viem_1 = require("viem");
6
- const abis_1 = require("../../../core/abis");
7
- const validation_1 = require("../../../utils/validation");
8
- const ZERO_VALUE = '0';
9
- function requireBigInt(value, fieldName) {
10
- if (typeof value !== 'bigint') {
11
- throw new Error(`${fieldName} must be a bigint`);
12
- }
13
- if (value < 0n) {
14
- throw new Error(`${fieldName} cannot be negative`);
15
- }
16
- return value;
17
- }
18
- function buildErc20ApprovalParams(token, spender, amount) {
19
- (0, validation_1.validateAddress)(token, 'token');
20
- (0, validation_1.validateAddress)(spender, 'spender');
21
- if (amount < 0n) {
22
- throw new Error('Approval amount cannot be negative');
23
- }
24
- const data = (0, viem_1.encodeFunctionData)({
25
- abi: abis_1.ERC20_ABI,
26
- functionName: 'approve',
27
- args: [spender, amount],
28
- });
29
- return { to: token, data, value: ZERO_VALUE };
30
- }
31
- async function readErc20Allowance(publicClient, token, owner, spender) {
32
- (0, validation_1.validateAddress)(token, 'token');
33
- (0, validation_1.validateAddress)(owner, 'owner');
34
- (0, validation_1.validateAddress)(spender, 'spender');
35
- const allowanceRaw = await publicClient.readContract({
36
- address: token,
37
- abi: abis_1.ERC20_ABI,
38
- functionName: 'allowance',
39
- args: [owner, spender],
40
- });
41
- return requireBigInt(allowanceRaw, 'allowance');
42
- }
43
- //# sourceMappingURL=borrowErc20.js.map
@@ -1,7 +0,0 @@
1
- import { PublicClient } from 'viem';
2
- import { DeploymentContext } from './borrowTypes';
3
- export declare function getTroveOperationHints(publicClient: PublicClient, ctx: DeploymentContext, interestRate: bigint): Promise<{
4
- upper: bigint;
5
- lower: bigint;
6
- }>;
7
- //# sourceMappingURL=borrowHints.d.ts.map
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTroveOperationHints = getTroveOperationHints;
4
- const abis_1 = require("../../../core/abis");
5
- const constants_1 = require("../../../core/constants");
6
- const borrowValidation_1 = require("./borrowValidation");
7
- async function getTroveOperationHints(publicClient, ctx, interestRate) {
8
- const annualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(interestRate, 'interestRate');
9
- const troveCount = (await publicClient.readContract({
10
- address: ctx.addresses.sortedTroves,
11
- abi: abis_1.SORTED_TROVES_ABI,
12
- functionName: 'getSize',
13
- args: [],
14
- }));
15
- const sqrtCount = (0, borrowValidation_1.ceilSqrt)(troveCount);
16
- const numTrials = 10n * (sqrtCount > 0n ? sqrtCount : 1n);
17
- const [approxHint] = (await publicClient.readContract({
18
- address: ctx.addresses.hintHelpers,
19
- abi: abis_1.HINT_HELPERS_ABI,
20
- functionName: 'getApproxHint',
21
- args: [constants_1.COLL_INDEX, annualInterestRate, numTrials, 42n],
22
- }));
23
- const [upperHint, lowerHint] = (await publicClient.readContract({
24
- address: ctx.addresses.sortedTroves,
25
- abi: abis_1.SORTED_TROVES_ABI,
26
- functionName: 'findInsertPosition',
27
- args: [annualInterestRate, approxHint, approxHint],
28
- }));
29
- return { upper: upperHint, lower: lowerHint };
30
- }
31
- //# sourceMappingURL=borrowHints.js.map
@@ -1,4 +0,0 @@
1
- import { BorrowPosition, TroveStatus } from '../../../core/types';
2
- export declare function mapTroveStatus(statusNum: number): TroveStatus;
3
- export declare function parseBorrowPosition(troveId: string, latestData: unknown, trovesData: unknown): BorrowPosition;
4
- //# sourceMappingURL=borrowPositionParser.d.ts.map
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapTroveStatus = mapTroveStatus;
4
- exports.parseBorrowPosition = parseBorrowPosition;
5
- const viem_1 = require("viem");
6
- const validation_1 = require("../../../utils/validation");
7
- const MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
8
- function requireAddress(value, fieldName) {
9
- if (typeof value !== 'string') {
10
- throw new Error(`${fieldName} must be a string address`);
11
- }
12
- (0, validation_1.validateAddress)(value, fieldName);
13
- return value;
14
- }
15
- function requireBigInt(value, fieldName) {
16
- if (typeof value !== 'bigint') {
17
- throw new Error(`${fieldName} must be a bigint`);
18
- }
19
- if (value < 0n) {
20
- throw new Error(`${fieldName} cannot be negative`);
21
- }
22
- return value;
23
- }
24
- function requireNonNegativeInteger(value, fieldName) {
25
- if (typeof value === 'bigint') {
26
- if (value < 0n) {
27
- throw new Error(`${fieldName} cannot be negative`);
28
- }
29
- if (value > MAX_SAFE_INTEGER_BIGINT) {
30
- throw new Error(`${fieldName} exceeds Number.MAX_SAFE_INTEGER`);
31
- }
32
- return Number(value);
33
- }
34
- if (typeof value === 'number') {
35
- if (!Number.isSafeInteger(value)) {
36
- throw new Error(`${fieldName} must be a safe integer`);
37
- }
38
- if (value < 0) {
39
- throw new Error(`${fieldName} cannot be negative`);
40
- }
41
- return value;
42
- }
43
- throw new Error(`${fieldName} must be a number or bigint`);
44
- }
45
- function mapTroveStatus(statusNum) {
46
- if (!Number.isSafeInteger(statusNum) || statusNum < 0) {
47
- throw new Error(`Invalid trove status: ${statusNum}`);
48
- }
49
- switch (statusNum) {
50
- case 0:
51
- return 'nonExistent';
52
- case 1:
53
- return 'active';
54
- case 2:
55
- return 'closedByOwner';
56
- case 3:
57
- return 'closedByLiquidation';
58
- case 4:
59
- return 'zombie';
60
- default:
61
- throw new Error(`Unknown trove status: ${statusNum}`);
62
- }
63
- }
64
- function parseBorrowPosition(troveId, latestData, trovesData) {
65
- if (typeof troveId !== 'string' || troveId.length === 0) {
66
- throw new Error('troveId must be a non-empty string');
67
- }
68
- const latest = latestData;
69
- const trove = trovesData;
70
- const interestBatchManager = requireAddress(trove.interestBatchManager, 'trovesData.interestBatchManager');
71
- return {
72
- troveId,
73
- collateral: requireBigInt(latest.entireColl, 'latestData.entireColl'),
74
- debt: requireBigInt(latest.entireDebt, 'latestData.entireDebt'),
75
- annualInterestRate: requireBigInt(latest.annualInterestRate, 'latestData.annualInterestRate'),
76
- status: mapTroveStatus(requireNonNegativeInteger(trove.status, 'trovesData.status')),
77
- interestBatchManager: interestBatchManager.toLowerCase() === viem_1.zeroAddress ? null : interestBatchManager,
78
- lastDebtUpdateTime: requireNonNegativeInteger(trove.lastDebtUpdateTime, 'trovesData.lastDebtUpdateTime'),
79
- lastInterestRateAdjTime: requireNonNegativeInteger(latest.lastInterestRateAdjTime, 'latestData.lastInterestRateAdjTime'),
80
- redistBoldDebtGain: requireBigInt(latest.redistBoldDebtGain, 'latestData.redistBoldDebtGain'),
81
- redistCollGain: requireBigInt(latest.redistCollGain, 'latestData.redistCollGain'),
82
- accruedInterest: requireBigInt(latest.accruedInterest, 'latestData.accruedInterest'),
83
- recordedDebt: requireBigInt(latest.recordedDebt, 'latestData.recordedDebt'),
84
- accruedBatchManagementFee: requireBigInt(latest.accruedBatchManagementFee, 'latestData.accruedBatchManagementFee'),
85
- };
86
- }
87
- //# sourceMappingURL=borrowPositionParser.js.map
@@ -1,31 +0,0 @@
1
- import { PublicClient } from 'viem';
2
- import { BorrowPosition, InterestRateBracket } from '../../../core/types';
3
- import { DeploymentContext } from './borrowTypes';
4
- export declare class BorrowReadService {
5
- private publicClient;
6
- constructor(publicClient: PublicClient);
7
- getTroveData(ctx: DeploymentContext, troveId: string): Promise<BorrowPosition>;
8
- getUserTroves(ctx: DeploymentContext, owner: string): Promise<BorrowPosition[]>;
9
- getCollateralPrice(ctx: DeploymentContext): Promise<bigint>;
10
- isSystemShutDown(ctx: DeploymentContext): Promise<boolean>;
11
- getBranchStats(ctx: DeploymentContext): Promise<{
12
- totalColl: bigint;
13
- totalDebt: bigint;
14
- }>;
15
- getInterestRateBrackets(ctx: DeploymentContext): Promise<InterestRateBracket[]>;
16
- getAverageInterestRate(ctx: DeploymentContext): Promise<bigint>;
17
- getBatchManagerInfo(ctx: DeploymentContext, address: string): Promise<{
18
- minRate: bigint;
19
- maxRate: bigint;
20
- minChangePeriod: bigint;
21
- } | null>;
22
- predictOpenTroveUpfrontFee(ctx: DeploymentContext, amount: bigint, rate: bigint): Promise<bigint>;
23
- predictAdjustUpfrontFee(ctx: DeploymentContext, troveId: string, debtIncrease: bigint): Promise<bigint>;
24
- predictAdjustInterestRateUpfrontFee(ctx: DeploymentContext, troveId: string, newRate: bigint): Promise<bigint>;
25
- predictJoinBatchUpfrontFee(ctx: DeploymentContext, troveId: string, batchAddress: string): Promise<bigint>;
26
- getOwnedTroveCount(ctx: DeploymentContext, owner: string): Promise<number>;
27
- findNextAvailableOwnerIndex(ctx: DeploymentContext, owner: string, opener: string): Promise<number>;
28
- getNextOwnerIndex(ctx: DeploymentContext, owner: string): Promise<number>;
29
- private readContractsInChunks;
30
- }
31
- //# sourceMappingURL=borrowReadService.d.ts.map
@@ -1,276 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BorrowReadService = void 0;
4
- const abis_1 = require("../../../core/abis");
5
- const constants_1 = require("../../../core/constants");
6
- const multicall_1 = require("../../../utils/multicall");
7
- const borrowPositionParser_1 = require("./borrowPositionParser");
8
- const borrowValidation_1 = require("./borrowValidation");
9
- const TROVE_ID_BATCH_SIZE = 64;
10
- const TROVE_OWNER_BATCH_SIZE = 64;
11
- const TROVE_DETAIL_BATCH_SIZE = 64;
12
- const OWNER_INDEX_PROBE_BATCH_SIZE = 64;
13
- class BorrowReadService {
14
- constructor(publicClient) {
15
- this.publicClient = publicClient;
16
- }
17
- async getTroveData(ctx, troveId) {
18
- const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
19
- const [latestData, trovesData] = await this.readContractsInChunks([
20
- {
21
- address: ctx.addresses.troveManager,
22
- abi: abis_1.TROVE_MANAGER_ABI,
23
- functionName: 'getLatestTroveData',
24
- args: [parsedTroveId],
25
- },
26
- {
27
- address: ctx.addresses.troveManager,
28
- abi: abis_1.TROVE_MANAGER_ABI,
29
- functionName: 'Troves',
30
- args: [parsedTroveId],
31
- },
32
- ], 2);
33
- return (0, borrowPositionParser_1.parseBorrowPosition)((0, borrowValidation_1.formatTroveId)(parsedTroveId), latestData, trovesData);
34
- }
35
- async getUserTroves(ctx, owner) {
36
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
37
- const ownedTroveCount = await this.getOwnedTroveCount(ctx, ownerAddress);
38
- if (ownedTroveCount === 0) {
39
- return [];
40
- }
41
- const troveCount = (await this.publicClient.readContract({
42
- address: ctx.addresses.troveManager,
43
- abi: abis_1.TROVE_MANAGER_ABI,
44
- functionName: 'getTroveIdsCount',
45
- args: [],
46
- }));
47
- if (troveCount === 0n) {
48
- return [];
49
- }
50
- const troveIdContracts = [];
51
- for (let i = 0n; i < troveCount; i++) {
52
- troveIdContracts.push({
53
- address: ctx.addresses.troveManager,
54
- abi: abis_1.TROVE_MANAGER_ABI,
55
- functionName: 'getTroveFromTroveIdsArray',
56
- args: [i],
57
- });
58
- }
59
- const troveIds = (await this.readContractsInChunks(troveIdContracts, TROVE_ID_BATCH_SIZE)).map((troveId) => troveId);
60
- const ownerContracts = troveIds.map((troveId) => ({
61
- address: ctx.addresses.troveNFT,
62
- abi: abis_1.TROVE_NFT_ABI,
63
- functionName: 'ownerOf',
64
- args: [troveId],
65
- }));
66
- const troveOwners = await this.readContractsInChunks(ownerContracts, TROVE_OWNER_BATCH_SIZE);
67
- const matchedTroveIds = troveIds.filter((troveId, index) => troveOwners[index].toLowerCase() === ownerAddress.toLowerCase());
68
- if (matchedTroveIds.length === 0) {
69
- return [];
70
- }
71
- const troveDetailContracts = matchedTroveIds.flatMap((troveId) => ([
72
- {
73
- address: ctx.addresses.troveManager,
74
- abi: abis_1.TROVE_MANAGER_ABI,
75
- functionName: 'getLatestTroveData',
76
- args: [troveId],
77
- },
78
- {
79
- address: ctx.addresses.troveManager,
80
- abi: abis_1.TROVE_MANAGER_ABI,
81
- functionName: 'Troves',
82
- args: [troveId],
83
- },
84
- ]));
85
- const detailResults = await this.readContractsInChunks(troveDetailContracts, TROVE_DETAIL_BATCH_SIZE * 2);
86
- return matchedTroveIds.map((troveId, index) => {
87
- const offset = index * 2;
88
- return (0, borrowPositionParser_1.parseBorrowPosition)((0, borrowValidation_1.formatTroveId)(troveId), detailResults[offset], detailResults[offset + 1]);
89
- });
90
- }
91
- async getCollateralPrice(ctx) {
92
- return (await this.publicClient.readContract({
93
- address: ctx.addresses.priceFeed,
94
- abi: abis_1.PRICE_FEED_ABI,
95
- functionName: 'fetchPrice',
96
- args: [],
97
- }));
98
- }
99
- async isSystemShutDown(ctx) {
100
- return (await this.publicClient.readContract({
101
- address: ctx.addresses.borrowerOperations,
102
- abi: abis_1.BORROWER_OPERATIONS_ABI,
103
- functionName: 'hasBeenShutDown',
104
- args: [],
105
- }));
106
- }
107
- async getBranchStats(ctx) {
108
- const [totalColl, totalDebt] = await Promise.all([
109
- this.publicClient.readContract({
110
- address: ctx.addresses.borrowerOperations,
111
- abi: abis_1.BORROWER_OPERATIONS_ABI,
112
- functionName: 'getEntireBranchColl',
113
- args: [],
114
- }),
115
- this.publicClient.readContract({
116
- address: ctx.addresses.borrowerOperations,
117
- abi: abis_1.BORROWER_OPERATIONS_ABI,
118
- functionName: 'getEntireBranchDebt',
119
- args: [],
120
- }),
121
- ]);
122
- return { totalColl: totalColl, totalDebt: totalDebt };
123
- }
124
- async getInterestRateBrackets(ctx) {
125
- const result = (await this.publicClient.readContract({
126
- address: ctx.addresses.multiTroveGetter,
127
- abi: abis_1.MULTI_TROVE_GETTER_ABI,
128
- functionName: 'getDebtPerInterestRateAscending',
129
- args: [constants_1.COLL_INDEX, 0n, 500n],
130
- }));
131
- const entries = result[0] ?? [];
132
- const grouped = new Map();
133
- for (const item of entries) {
134
- const rate = (0, borrowValidation_1.requireNonNegativeBigInt)(item.interestRate, 'interestRate');
135
- const debt = (0, borrowValidation_1.requireNonNegativeBigInt)(item.debt, 'debt');
136
- const key = rate.toString();
137
- grouped.set(key, (grouped.get(key) ?? 0n) + debt);
138
- }
139
- return Array.from(grouped.entries())
140
- .map(([rate, totalDebt]) => ({
141
- rate: BigInt(rate),
142
- totalDebt,
143
- }))
144
- .sort((a, b) => (a.rate < b.rate ? -1 : a.rate > b.rate ? 1 : 0));
145
- }
146
- async getAverageInterestRate(ctx) {
147
- const brackets = await this.getInterestRateBrackets(ctx);
148
- if (brackets.length === 0)
149
- return 0n;
150
- let weightedRateSum = 0n;
151
- let totalDebt = 0n;
152
- for (const bracket of brackets) {
153
- weightedRateSum += bracket.rate * bracket.totalDebt;
154
- totalDebt += bracket.totalDebt;
155
- }
156
- return totalDebt === 0n ? 0n : weightedRateSum / totalDebt;
157
- }
158
- async getBatchManagerInfo(ctx, address) {
159
- const batchManagerAddress = (0, borrowValidation_1.requireAddress)(address, 'address');
160
- const exists = (await this.publicClient.readContract({
161
- address: ctx.addresses.borrowerOperations,
162
- abi: abis_1.BORROWER_OPERATIONS_ABI,
163
- functionName: 'checkBatchManagerExists',
164
- args: [batchManagerAddress],
165
- }));
166
- if (!exists)
167
- return null;
168
- const manager = (await this.publicClient.readContract({
169
- address: ctx.addresses.borrowerOperations,
170
- abi: abis_1.BORROWER_OPERATIONS_ABI,
171
- functionName: 'getInterestBatchManager',
172
- args: [batchManagerAddress],
173
- }));
174
- return {
175
- minRate: (0, borrowValidation_1.requireNonNegativeBigInt)(manager.minInterestRate, 'minInterestRate'),
176
- maxRate: (0, borrowValidation_1.requireNonNegativeBigInt)(manager.maxInterestRate, 'maxInterestRate'),
177
- minChangePeriod: (0, borrowValidation_1.requireNonNegativeBigInt)(manager.minInterestRateChangePeriod, 'minInterestRateChangePeriod'),
178
- };
179
- }
180
- async predictOpenTroveUpfrontFee(ctx, amount, rate) {
181
- const borrowedAmount = (0, borrowValidation_1.requireNonNegativeBigInt)(amount, 'amount');
182
- const annualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(rate, 'rate');
183
- return (await this.publicClient.readContract({
184
- address: ctx.addresses.hintHelpers,
185
- abi: abis_1.HINT_HELPERS_ABI,
186
- functionName: 'predictOpenTroveUpfrontFee',
187
- args: [constants_1.COLL_INDEX, borrowedAmount, annualInterestRate],
188
- }));
189
- }
190
- async predictAdjustUpfrontFee(ctx, troveId, debtIncrease) {
191
- const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
192
- const debtIncreaseAmount = (0, borrowValidation_1.requireNonNegativeBigInt)(debtIncrease, 'debtIncrease');
193
- return (await this.publicClient.readContract({
194
- address: ctx.addresses.hintHelpers,
195
- abi: abis_1.HINT_HELPERS_ABI,
196
- functionName: 'predictAdjustTroveUpfrontFee',
197
- args: [constants_1.COLL_INDEX, parsedTroveId, debtIncreaseAmount],
198
- }));
199
- }
200
- async predictAdjustInterestRateUpfrontFee(ctx, troveId, newRate) {
201
- const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
202
- const newAnnualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(newRate, 'newRate');
203
- return (await this.publicClient.readContract({
204
- address: ctx.addresses.hintHelpers,
205
- abi: abis_1.HINT_HELPERS_ABI,
206
- functionName: 'predictAdjustInterestRateUpfrontFee',
207
- args: [constants_1.COLL_INDEX, parsedTroveId, newAnnualInterestRate],
208
- }));
209
- }
210
- async predictJoinBatchUpfrontFee(ctx, troveId, batchAddress) {
211
- const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
212
- const managerAddress = (0, borrowValidation_1.requireAddress)(batchAddress, 'batchAddress');
213
- return (await this.publicClient.readContract({
214
- address: ctx.addresses.hintHelpers,
215
- abi: abis_1.HINT_HELPERS_ABI,
216
- functionName: 'predictJoinBatchInterestRateUpfrontFee',
217
- args: [constants_1.COLL_INDEX, parsedTroveId, managerAddress],
218
- }));
219
- }
220
- async getOwnedTroveCount(ctx, owner) {
221
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
222
- const ownerTroveCount = (await this.publicClient.readContract({
223
- address: ctx.addresses.troveNFT,
224
- abi: abis_1.TROVE_NFT_ABI,
225
- functionName: 'balanceOf',
226
- args: [ownerAddress],
227
- }));
228
- if (ownerTroveCount > borrowValidation_1.MAX_SAFE_INTEGER_BIGINT) {
229
- throw new Error('Owner trove count exceeds Number.MAX_SAFE_INTEGER');
230
- }
231
- return Number(ownerTroveCount);
232
- }
233
- async findNextAvailableOwnerIndex(ctx, owner, opener) {
234
- const ownerAddress = (0, borrowValidation_1.requireAddress)(owner, 'owner');
235
- const openerAddress = (0, borrowValidation_1.requireAddress)(opener, 'opener');
236
- let candidateIndex = await this.getOwnedTroveCount(ctx, ownerAddress);
237
- while (candidateIndex <= Number.MAX_SAFE_INTEGER) {
238
- const batchIndices = Array.from({ length: Math.min(OWNER_INDEX_PROBE_BATCH_SIZE, Number.MAX_SAFE_INTEGER - candidateIndex + 1) }, (_, offset) => candidateIndex + offset);
239
- const statusContracts = batchIndices.map((ownerIndex) => ({
240
- address: ctx.addresses.troveManager,
241
- abi: abis_1.TROVE_MANAGER_ABI,
242
- functionName: 'getTroveStatus',
243
- args: [(0, borrowValidation_1.deriveTroveId)(openerAddress, ownerAddress, ownerIndex)],
244
- }));
245
- const statuses = await this.readContractsInChunks(statusContracts, OWNER_INDEX_PROBE_BATCH_SIZE);
246
- const availableOffset = statuses.findIndex((status) => status === 0 || status === 0n);
247
- if (availableOffset !== -1) {
248
- return batchIndices[availableOffset];
249
- }
250
- candidateIndex += batchIndices.length;
251
- }
252
- throw new Error('Next available owner index exceeds Number.MAX_SAFE_INTEGER');
253
- }
254
- async getNextOwnerIndex(ctx, owner) {
255
- return this.getOwnedTroveCount(ctx, owner);
256
- }
257
- async readContractsInChunks(contracts, chunkSize) {
258
- if (contracts.length === 0) {
259
- return [];
260
- }
261
- const results = [];
262
- for (let index = 0; index < contracts.length; index += chunkSize) {
263
- const chunk = contracts.slice(index, index + chunkSize);
264
- const chunkResults = await (0, multicall_1.multicall)(this.publicClient, chunk, { allowFailure: false });
265
- for (const result of chunkResults) {
266
- if (result.status === 'failure') {
267
- throw result.error;
268
- }
269
- results.push(result.result);
270
- }
271
- }
272
- return results;
273
- }
274
- }
275
- exports.BorrowReadService = BorrowReadService;
276
- //# sourceMappingURL=borrowReadService.js.map
@@ -1,5 +0,0 @@
1
- import { Address, PublicClient } from 'viem';
2
- import { BorrowContractAddresses, SystemParams } from '../../../core/types';
3
- export declare function resolveAddressesFromRegistry(publicClient: PublicClient, registryAddress: string): Promise<BorrowContractAddresses>;
4
- export declare function readSystemParams(publicClient: PublicClient, borrowerOperations: Address): Promise<SystemParams>;
5
- //# sourceMappingURL=borrowRegistryReader.d.ts.map