@gearbox-protocol/sdk 15.1.0-next.1 → 15.1.0-next.10

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 (444) hide show
  1. package/dist/cjs/abi/iExpirable.js +15 -0
  2. package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  3. package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  4. package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  5. package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
  6. package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  7. package/dist/cjs/dev/AccountOpener.js +0 -1
  8. package/dist/cjs/dev/compareOpportunities.js +218 -0
  9. package/dist/cjs/model/charts.js +147 -0
  10. package/dist/cjs/model/charts.schema.js +240 -0
  11. package/dist/cjs/model/index.js +35 -22
  12. package/dist/cjs/model/liquidations.schema.js +1 -1
  13. package/dist/cjs/model/notices.schema.js +25 -0
  14. package/dist/cjs/model/opportunities.schema.js +1 -1
  15. package/dist/cjs/model/positions.schema.js +48 -2
  16. package/dist/cjs/new-sdk/AbstractNamespace.js +34 -4
  17. package/dist/cjs/new-sdk/GearboxSDK.js +72 -3
  18. package/dist/cjs/new-sdk/execute/ExecuteApi.js +95 -0
  19. package/dist/cjs/new-sdk/execute/index.js +3 -0
  20. package/dist/cjs/new-sdk/index.js +7 -0
  21. package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  22. package/dist/cjs/new-sdk/positions/PositionsNamespace.js +3 -6
  23. package/dist/cjs/new-sdk/simulate/SimulateApi.js +361 -0
  24. package/dist/cjs/new-sdk/simulate/index.js +4 -0
  25. package/dist/cjs/new-sdk/utils/index.js +0 -1
  26. package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
  27. package/dist/cjs/offchain/GearboxAPI.js +7 -0
  28. package/dist/cjs/offchain/index.js +3 -0
  29. package/dist/cjs/offchain/notices/OffchainNotices.js +27 -0
  30. package/dist/cjs/offchain/notices/index.js +3 -0
  31. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
  32. package/dist/cjs/offchain/positions/OffchainPositions.js +12 -12
  33. package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
  34. package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
  35. package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
  36. package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
  37. package/dist/cjs/preview/preview/previewOperation.js +1 -1
  38. package/dist/cjs/sdk/MultichainSDK.js +3 -4
  39. package/dist/cjs/sdk/OnchainSDK.js +42 -13
  40. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -8
  41. package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  42. package/dist/cjs/sdk/accounts/index.js +5 -2
  43. package/dist/cjs/sdk/accounts/intents/guards.js +114 -0
  44. package/dist/cjs/sdk/accounts/intents/index.js +216 -358
  45. package/dist/cjs/sdk/accounts/intents/math.js +56 -0
  46. package/dist/cjs/sdk/accounts/intents/open-strategy.js +133 -0
  47. package/dist/cjs/sdk/accounts/intents/operations.js +165 -0
  48. package/dist/cjs/sdk/accounts/intents/plan.js +373 -0
  49. package/dist/cjs/sdk/accounts/intents/realize.js +301 -0
  50. package/dist/cjs/sdk/accounts/intents/testing/delayed.js +50 -0
  51. package/dist/cjs/sdk/accounts/intents/testing/market.js +166 -0
  52. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +194 -35
  53. package/dist/cjs/sdk/accounts/intents/tests/add-collateral.fixtures.js +123 -0
  54. package/dist/cjs/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +254 -0
  55. package/dist/cjs/sdk/accounts/intents/tests/deposit.fixtures.js +324 -0
  56. package/dist/cjs/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +242 -0
  57. package/dist/cjs/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +383 -0
  58. package/dist/cjs/sdk/accounts/intents/tests/open-strategy.fixtures.js +133 -0
  59. package/dist/cjs/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +131 -0
  60. package/dist/cjs/sdk/accounts/intents/tests/withdraw.fixtures.js +426 -0
  61. package/dist/cjs/sdk/accounts/intents/types.js +16 -0
  62. package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
  63. package/dist/cjs/sdk/accounts/intents/utils/credit-account-slice.js +45 -0
  64. package/dist/cjs/sdk/accounts/intents/utils/index.js +17 -8
  65. package/dist/cjs/sdk/accounts/intents/utils/ledger.js +94 -0
  66. package/dist/cjs/sdk/accounts/intents/utils/pick-token.js +72 -0
  67. package/dist/cjs/sdk/accounts/intents/utils/quotas-for-update.js +27 -0
  68. package/dist/cjs/sdk/accounts/intents/utils/router-path.js +86 -0
  69. package/dist/cjs/sdk/accounts/intents/view.js +38 -0
  70. package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
  71. package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  72. package/dist/cjs/sdk/base/BaseContract.js +1 -1
  73. package/dist/cjs/sdk/base/TokensMeta.js +78 -27
  74. package/dist/cjs/sdk/index.js +30 -7
  75. package/dist/cjs/sdk/market/MarketRegister.js +16 -7
  76. package/dist/cjs/sdk/market/ZapperRegister.js +56 -25
  77. package/dist/cjs/sdk/market/credit/CreditManagerV310Contract.js +1 -12
  78. package/dist/cjs/sdk/market/credit/CreditSuite.js +28 -9
  79. package/dist/cjs/sdk/market/credit/index.js +3 -0
  80. package/dist/cjs/sdk/market/credit/isStrategyCollateral.js +50 -0
  81. package/dist/cjs/sdk/market/index.js +17 -0
  82. package/dist/cjs/sdk/market/math.js +57 -44
  83. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  84. package/dist/cjs/sdk/market/pool/PoolV310Contract.js +15 -1
  85. package/dist/cjs/sdk/market/rwa/RWARegistry.js +22 -0
  86. package/dist/cjs/sdk/opportunities/index.js +0 -13
  87. package/dist/cjs/sdk/options.js +1 -5
  88. package/dist/cjs/sdk/pools/PoolService.js +132 -3
  89. package/dist/cjs/sdk/pools/index.js +2 -0
  90. package/dist/cjs/sdk/positions/PositionsService.js +213 -1
  91. package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
  92. package/dist/cjs/sdk/positions/calcHealthFactor.js +52 -0
  93. package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
  94. package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
  95. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +19 -0
  96. package/dist/cjs/sdk/positions/index.js +12 -1
  97. package/dist/cjs/sdk/positions/types.js +31 -0
  98. package/dist/cjs/sdk/utils/abi-decode.js +2 -2
  99. package/dist/cjs/sdk/utils/viem/executeMulticallBatches.js +32 -0
  100. package/dist/cjs/sdk/utils/viem/index.js +2 -0
  101. package/dist/esm/abi/iExpirable.js +14 -0
  102. package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
  103. package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
  104. package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
  105. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +8 -5
  106. package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
  107. package/dist/esm/dev/AccountOpener.js +1 -2
  108. package/dist/esm/dev/compareOpportunities.js +216 -0
  109. package/dist/esm/dev/withdrawalUtils.js +1 -1
  110. package/dist/esm/model/charts.js +140 -0
  111. package/dist/esm/model/charts.schema.js +226 -0
  112. package/dist/esm/model/index.js +9 -7
  113. package/dist/esm/model/liquidations.schema.js +1 -1
  114. package/dist/esm/model/notices.schema.js +23 -0
  115. package/dist/esm/model/opportunities.schema.js +1 -1
  116. package/dist/esm/model/positions.schema.js +46 -4
  117. package/dist/esm/new-sdk/AbstractNamespace.js +34 -4
  118. package/dist/esm/new-sdk/GearboxSDK.js +72 -4
  119. package/dist/esm/new-sdk/execute/ExecuteApi.js +94 -0
  120. package/dist/esm/new-sdk/execute/index.js +2 -0
  121. package/dist/esm/new-sdk/index.js +6 -2
  122. package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +29 -6
  123. package/dist/esm/new-sdk/positions/PositionsNamespace.js +3 -6
  124. package/dist/esm/new-sdk/simulate/SimulateApi.js +360 -0
  125. package/dist/esm/new-sdk/simulate/index.js +3 -0
  126. package/dist/esm/new-sdk/utils/index.js +0 -1
  127. package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
  128. package/dist/esm/offchain/GearboxAPI.js +7 -0
  129. package/dist/esm/offchain/index.js +3 -1
  130. package/dist/esm/offchain/notices/OffchainNotices.js +26 -0
  131. package/dist/esm/offchain/notices/index.js +2 -0
  132. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
  133. package/dist/esm/offchain/positions/OffchainPositions.js +12 -12
  134. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  135. package/dist/esm/preview/preview/CreditAccountState.js +14 -1
  136. package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
  137. package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
  138. package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
  139. package/dist/esm/preview/preview/previewOperation.js +1 -1
  140. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  141. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  142. package/dist/esm/sdk/MultichainSDK.js +3 -4
  143. package/dist/esm/sdk/OnchainSDK.js +42 -13
  144. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +4 -10
  145. package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
  146. package/dist/esm/sdk/accounts/index.js +3 -2
  147. package/dist/esm/sdk/accounts/intents/guards.js +108 -0
  148. package/dist/esm/sdk/accounts/intents/index.js +214 -358
  149. package/dist/esm/sdk/accounts/intents/math.js +51 -0
  150. package/dist/esm/sdk/accounts/intents/open-strategy.js +132 -0
  151. package/dist/esm/sdk/accounts/intents/operations.js +153 -0
  152. package/dist/esm/sdk/accounts/intents/plan.js +361 -0
  153. package/dist/esm/sdk/accounts/intents/realize.js +300 -0
  154. package/dist/esm/sdk/accounts/intents/testing/delayed.js +38 -0
  155. package/dist/esm/sdk/accounts/intents/testing/market.js +148 -0
  156. package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +194 -35
  157. package/dist/esm/sdk/accounts/intents/tests/add-collateral.fixtures.js +110 -0
  158. package/dist/esm/sdk/accounts/intents/tests/adjust-leverage.fixtures.js +234 -0
  159. package/dist/esm/sdk/accounts/intents/tests/deposit.fixtures.js +302 -0
  160. package/dist/esm/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.js +220 -0
  161. package/dist/esm/sdk/accounts/intents/tests/finish-withdraw.fixtures.js +355 -0
  162. package/dist/esm/sdk/accounts/intents/tests/open-strategy.fixtures.js +119 -0
  163. package/dist/esm/sdk/accounts/intents/tests/withdraw-asset.fixtures.js +117 -0
  164. package/dist/esm/sdk/accounts/intents/tests/withdraw.fixtures.js +402 -0
  165. package/dist/esm/sdk/accounts/intents/types.js +16 -1
  166. package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
  167. package/dist/esm/sdk/accounts/intents/utils/credit-account-slice.js +43 -0
  168. package/dist/esm/sdk/accounts/intents/utils/index.js +9 -7
  169. package/dist/esm/sdk/accounts/intents/utils/ledger.js +93 -0
  170. package/dist/esm/sdk/accounts/intents/utils/pick-token.js +68 -0
  171. package/dist/esm/sdk/accounts/intents/utils/quotas-for-update.js +27 -1
  172. package/dist/esm/sdk/accounts/intents/utils/router-path.js +85 -0
  173. package/dist/esm/sdk/accounts/intents/view.js +37 -0
  174. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
  175. package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +29 -18
  176. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  177. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  178. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  179. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  180. package/dist/esm/sdk/base/BaseContract.js +1 -1
  181. package/dist/esm/sdk/base/TokensMeta.js +80 -29
  182. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  183. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  184. package/dist/esm/sdk/index.js +13 -4
  185. package/dist/esm/sdk/market/MarketRegister.js +16 -7
  186. package/dist/esm/sdk/market/ZapperRegister.js +56 -25
  187. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  188. package/dist/esm/sdk/market/credit/CreditManagerV310Contract.js +2 -13
  189. package/dist/esm/sdk/market/credit/CreditSuite.js +29 -10
  190. package/dist/esm/sdk/market/credit/index.js +2 -1
  191. package/dist/esm/sdk/market/credit/isStrategyCollateral.js +48 -0
  192. package/dist/esm/sdk/market/index.js +3 -1
  193. package/dist/esm/sdk/market/math.js +52 -40
  194. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
  195. package/dist/esm/sdk/market/pool/PoolV310Contract.js +17 -3
  196. package/dist/esm/sdk/market/rwa/RWARegistry.js +22 -0
  197. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  198. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  199. package/dist/esm/sdk/opportunities/index.js +1 -2
  200. package/dist/esm/sdk/options.js +1 -5
  201. package/dist/esm/sdk/pools/PoolService.js +133 -6
  202. package/dist/esm/sdk/pools/index.js +2 -2
  203. package/dist/esm/sdk/positions/PositionsService.js +213 -1
  204. package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
  205. package/dist/esm/sdk/positions/calcHealthFactor.js +51 -0
  206. package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
  207. package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
  208. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +18 -0
  209. package/dist/esm/sdk/positions/index.js +7 -2
  210. package/dist/esm/sdk/positions/types.js +31 -1
  211. package/dist/esm/sdk/utils/abi-decode.js +2 -2
  212. package/dist/esm/sdk/utils/viem/executeMulticallBatches.js +31 -0
  213. package/dist/esm/sdk/utils/viem/index.js +2 -1
  214. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  215. package/dist/types/abi/iExpirable.d.ts +14 -0
  216. package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
  217. package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
  218. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
  219. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +6 -1
  220. package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
  221. package/dist/types/dev/compareOpportunities.d.ts +153 -0
  222. package/dist/types/model/charts.d.ts +349 -0
  223. package/dist/types/model/charts.schema.d.ts +364 -0
  224. package/dist/types/model/index.d.ts +8 -6
  225. package/dist/types/model/notices.d.ts +29 -0
  226. package/dist/types/model/notices.schema.d.ts +23 -0
  227. package/dist/types/model/opportunities.d.ts +9 -9
  228. package/dist/types/model/positions.d.ts +133 -7
  229. package/dist/types/model/positions.schema.d.ts +128 -1
  230. package/dist/types/new-sdk/AbstractNamespace.d.ts +15 -2
  231. package/dist/types/new-sdk/GearboxSDK.d.ts +14 -2
  232. package/dist/types/new-sdk/execute/ExecuteApi.d.ts +108 -0
  233. package/dist/types/new-sdk/execute/index.d.ts +2 -0
  234. package/dist/types/new-sdk/index.d.ts +8 -4
  235. package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +19 -7
  236. package/dist/types/new-sdk/opportunities/types.d.ts +30 -9
  237. package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
  238. package/dist/types/new-sdk/positions/types.d.ts +9 -9
  239. package/dist/types/new-sdk/simulate/SimulateApi.d.ts +90 -0
  240. package/dist/types/new-sdk/simulate/index.d.ts +3 -0
  241. package/dist/types/new-sdk/simulate/types.d.ts +508 -0
  242. package/dist/types/new-sdk/types.d.ts +35 -1
  243. package/dist/types/new-sdk/utils/index.d.ts +1 -2
  244. package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
  245. package/dist/types/offchain/GearboxAPI.d.ts +6 -0
  246. package/dist/types/offchain/index.d.ts +4 -2
  247. package/dist/types/offchain/notices/OffchainNotices.d.ts +19 -0
  248. package/dist/types/offchain/notices/index.d.ts +2 -0
  249. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
  250. package/dist/types/offchain/positions/OffchainPositions.d.ts +8 -6
  251. package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
  252. package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
  253. package/dist/types/preview/preview/types.d.ts +4 -2
  254. package/dist/types/sdk/MultichainSDK.d.ts +0 -5
  255. package/dist/types/sdk/OnchainSDK.d.ts +1 -5
  256. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
  257. package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
  258. package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
  259. package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
  260. package/dist/types/sdk/accounts/index.d.ts +7 -5
  261. package/dist/types/sdk/accounts/intents/guards.d.ts +72 -0
  262. package/dist/types/sdk/accounts/intents/index.d.ts +130 -15
  263. package/dist/types/sdk/accounts/intents/math.d.ts +46 -0
  264. package/dist/types/sdk/accounts/intents/open-strategy.d.ts +64 -0
  265. package/dist/types/sdk/accounts/intents/operations.d.ts +215 -0
  266. package/dist/types/sdk/accounts/intents/plan.d.ts +189 -0
  267. package/dist/types/sdk/accounts/intents/realize.d.ts +35 -0
  268. package/dist/types/sdk/accounts/intents/testing/delayed.d.ts +50 -0
  269. package/dist/types/sdk/accounts/intents/testing/expect.d.ts +17 -21
  270. package/dist/types/sdk/accounts/intents/testing/market.d.ts +91 -0
  271. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +64 -16
  272. package/dist/types/sdk/accounts/intents/tests/add-collateral.fixtures.d.ts +45 -0
  273. package/dist/types/sdk/accounts/intents/tests/adjust-leverage.fixtures.d.ts +56 -0
  274. package/dist/types/sdk/accounts/intents/tests/deposit.fixtures.d.ts +64 -0
  275. package/dist/types/sdk/accounts/intents/tests/finish-decrease-leverage.fixtures.d.ts +107 -0
  276. package/dist/types/sdk/accounts/intents/tests/finish-withdraw.fixtures.d.ts +136 -0
  277. package/dist/types/sdk/accounts/intents/tests/open-strategy.fixtures.d.ts +56 -0
  278. package/dist/types/sdk/accounts/intents/tests/withdraw-asset.fixtures.d.ts +60 -0
  279. package/dist/types/sdk/accounts/intents/tests/withdraw.fixtures.d.ts +79 -0
  280. package/dist/types/sdk/accounts/intents/types.d.ts +369 -43
  281. package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
  282. package/dist/types/sdk/accounts/intents/utils/assemble-operation-calls.d.ts +1 -1
  283. package/dist/types/sdk/accounts/intents/utils/credit-account-slice.d.ts +29 -0
  284. package/dist/types/sdk/accounts/intents/utils/index.d.ts +7 -5
  285. package/dist/types/sdk/accounts/intents/utils/ledger.d.ts +41 -0
  286. package/dist/types/sdk/accounts/intents/utils/pick-token.d.ts +55 -0
  287. package/dist/types/sdk/accounts/intents/utils/quotas-for-update.d.ts +15 -4
  288. package/dist/types/sdk/accounts/intents/utils/router-path.d.ts +70 -0
  289. package/dist/types/sdk/accounts/intents/view.d.ts +15 -0
  290. package/dist/types/sdk/accounts/types.d.ts +17 -14
  291. package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +6 -0
  292. package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +18 -0
  293. package/dist/types/sdk/base/TokensMeta.d.ts +44 -1
  294. package/dist/types/sdk/base/index.d.ts +2 -2
  295. package/dist/types/sdk/base/token-types.d.ts +12 -1
  296. package/dist/types/sdk/index.d.ts +28 -19
  297. package/dist/types/sdk/market/MarketRegister.d.ts +7 -3
  298. package/dist/types/sdk/market/ZapperRegister.d.ts +20 -2
  299. package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +0 -4
  300. package/dist/types/sdk/market/credit/CreditSuite.d.ts +6 -3
  301. package/dist/types/sdk/market/credit/index.d.ts +2 -1
  302. package/dist/types/sdk/market/credit/isStrategyCollateral.d.ts +74 -0
  303. package/dist/types/sdk/market/credit/types.d.ts +2 -9
  304. package/dist/types/sdk/market/index.d.ts +4 -2
  305. package/dist/types/sdk/market/math.d.ts +44 -34
  306. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +6 -2
  307. package/dist/types/sdk/market/oracle/types.d.ts +10 -2
  308. package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +5 -0
  309. package/dist/types/sdk/market/pool/types.d.ts +5 -0
  310. package/dist/types/sdk/market/rwa/RWARegistry.d.ts +13 -0
  311. package/dist/types/sdk/market/types.d.ts +5 -1
  312. package/dist/types/sdk/opportunities/index.d.ts +1 -2
  313. package/dist/types/sdk/options.d.ts +0 -1
  314. package/dist/types/sdk/pools/PoolService.d.ts +32 -2
  315. package/dist/types/sdk/pools/index.d.ts +3 -3
  316. package/dist/types/sdk/pools/types.d.ts +109 -4
  317. package/dist/types/sdk/positions/PositionsService.d.ts +33 -2
  318. package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
  319. package/dist/types/sdk/positions/calcHealthFactor.d.ts +55 -0
  320. package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
  321. package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
  322. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +16 -0
  323. package/dist/types/sdk/positions/index.d.ts +7 -2
  324. package/dist/types/sdk/positions/types.d.ts +58 -1
  325. package/dist/types/sdk/types/state.d.ts +6 -0
  326. package/dist/types/sdk/utils/viem/executeMulticallBatches.d.ts +39 -0
  327. package/dist/types/sdk/utils/viem/index.d.ts +3 -2
  328. package/package.json +2 -1
  329. package/dist/cjs/model/history.js +0 -53
  330. package/dist/cjs/model/history.schema.js +0 -128
  331. package/dist/cjs/sdk/accounts/intents/intents/index.js +0 -14
  332. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -121
  333. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -15
  334. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -108
  335. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.js +0 -51
  336. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -130
  337. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -83
  338. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -117
  339. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -15
  340. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -95
  341. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -15
  342. package/dist/cjs/sdk/accounts/intents/intents/resume/index.js +0 -13
  343. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -138
  344. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -161
  345. package/dist/cjs/sdk/accounts/intents/operations/add-collateral/index.js +0 -17
  346. package/dist/cjs/sdk/accounts/intents/operations/claim-delayed/index.js +0 -54
  347. package/dist/cjs/sdk/accounts/intents/operations/close-credit-account/index.js +0 -26
  348. package/dist/cjs/sdk/accounts/intents/operations/decrease-debt/index.js +0 -12
  349. package/dist/cjs/sdk/accounts/intents/operations/increase-debt/index.js +0 -12
  350. package/dist/cjs/sdk/accounts/intents/operations/index.js +0 -27
  351. package/dist/cjs/sdk/accounts/intents/operations/quota-update/index.js +0 -22
  352. package/dist/cjs/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -22
  353. package/dist/cjs/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -18
  354. package/dist/cjs/sdk/accounts/intents/operations/swap/index.js +0 -18
  355. package/dist/cjs/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -27
  356. package/dist/cjs/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -43
  357. package/dist/cjs/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -27
  358. package/dist/cjs/sdk/accounts/intents/quoters/close.js +0 -58
  359. package/dist/cjs/sdk/accounts/intents/quoters/index.js +0 -7
  360. package/dist/cjs/sdk/accounts/intents/quoters/swap.js +0 -79
  361. package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
  362. package/dist/cjs/sdk/accounts/intents/testing/resume.js +0 -172
  363. package/dist/cjs/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -39
  364. package/dist/cjs/sdk/accounts/intents/utils/simulate-assets.js +0 -69
  365. package/dist/cjs/sdk/accounts/intents/utils/with-quota-update.js +0 -13
  366. package/dist/esm/model/history.js +0 -49
  367. package/dist/esm/model/history.schema.js +0 -116
  368. package/dist/esm/sdk/accounts/intents/intents/index.js +0 -8
  369. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +0 -107
  370. package/dist/esm/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.js +0 -14
  371. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.fixtures.js +0 -94
  372. package/dist/esm/sdk/accounts/intents/intents/resume/close/close.js +0 -50
  373. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +0 -114
  374. package/dist/esm/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.js +0 -82
  375. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +0 -110
  376. package/dist/esm/sdk/accounts/intents/intents/resume/deposit/deposit.js +0 -14
  377. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +0 -88
  378. package/dist/esm/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.js +0 -14
  379. package/dist/esm/sdk/accounts/intents/intents/resume/index.js +0 -7
  380. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +0 -121
  381. package/dist/esm/sdk/accounts/intents/intents/resume/withdraw/withdraw.js +0 -160
  382. package/dist/esm/sdk/accounts/intents/operations/add-collateral/index.js +0 -16
  383. package/dist/esm/sdk/accounts/intents/operations/claim-delayed/index.js +0 -52
  384. package/dist/esm/sdk/accounts/intents/operations/close-credit-account/index.js +0 -25
  385. package/dist/esm/sdk/accounts/intents/operations/decrease-debt/index.js +0 -11
  386. package/dist/esm/sdk/accounts/intents/operations/increase-debt/index.js +0 -11
  387. package/dist/esm/sdk/accounts/intents/operations/index.js +0 -14
  388. package/dist/esm/sdk/accounts/intents/operations/quota-update/index.js +0 -21
  389. package/dist/esm/sdk/accounts/intents/operations/repay-credit-account/index.js +0 -21
  390. package/dist/esm/sdk/accounts/intents/operations/start-delayed-withdrawal/index.js +0 -17
  391. package/dist/esm/sdk/accounts/intents/operations/swap/index.js +0 -17
  392. package/dist/esm/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.js +0 -26
  393. package/dist/esm/sdk/accounts/intents/operations/withdraw-collateral/index.js +0 -42
  394. package/dist/esm/sdk/accounts/intents/operations/wrap-rwa-collateral/index.js +0 -26
  395. package/dist/esm/sdk/accounts/intents/quoters/close.js +0 -56
  396. package/dist/esm/sdk/accounts/intents/quoters/index.js +0 -3
  397. package/dist/esm/sdk/accounts/intents/quoters/swap.js +0 -77
  398. package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
  399. package/dist/esm/sdk/accounts/intents/testing/resume.js +0 -157
  400. package/dist/esm/sdk/accounts/intents/utils/simulate-adjust-state.js +0 -38
  401. package/dist/esm/sdk/accounts/intents/utils/simulate-assets.js +0 -68
  402. package/dist/esm/sdk/accounts/intents/utils/with-quota-update.js +0 -12
  403. package/dist/types/model/history.d.ts +0 -153
  404. package/dist/types/model/history.schema.d.ts +0 -95
  405. package/dist/types/new-sdk/utils/history.d.ts +0 -18
  406. package/dist/types/sdk/accounts/intents/intents/index.d.ts +0 -8
  407. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.d.ts +0 -13
  408. package/dist/types/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.d.ts +0 -38
  409. package/dist/types/sdk/accounts/intents/intents/resume/close/close.d.ts +0 -26
  410. package/dist/types/sdk/accounts/intents/intents/resume/close/close.fixtures.d.ts +0 -63
  411. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.d.ts +0 -26
  412. package/dist/types/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.d.ts +0 -86
  413. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.d.ts +0 -13
  414. package/dist/types/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.d.ts +0 -48
  415. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.d.ts +0 -13
  416. package/dist/types/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.d.ts +0 -46
  417. package/dist/types/sdk/accounts/intents/intents/resume/index.d.ts +0 -7
  418. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.d.ts +0 -33
  419. package/dist/types/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.d.ts +0 -68
  420. package/dist/types/sdk/accounts/intents/operations/add-collateral/index.d.ts +0 -23
  421. package/dist/types/sdk/accounts/intents/operations/claim-delayed/index.d.ts +0 -55
  422. package/dist/types/sdk/accounts/intents/operations/close-credit-account/index.d.ts +0 -22
  423. package/dist/types/sdk/accounts/intents/operations/decrease-debt/index.d.ts +0 -18
  424. package/dist/types/sdk/accounts/intents/operations/increase-debt/index.d.ts +0 -18
  425. package/dist/types/sdk/accounts/intents/operations/index.d.ts +0 -14
  426. package/dist/types/sdk/accounts/intents/operations/quota-update/index.d.ts +0 -24
  427. package/dist/types/sdk/accounts/intents/operations/repay-credit-account/index.d.ts +0 -31
  428. package/dist/types/sdk/accounts/intents/operations/start-delayed-withdrawal/index.d.ts +0 -23
  429. package/dist/types/sdk/accounts/intents/operations/swap/index.d.ts +0 -28
  430. package/dist/types/sdk/accounts/intents/operations/types.d.ts +0 -21
  431. package/dist/types/sdk/accounts/intents/operations/unwrap-rwa-collateral/index.d.ts +0 -30
  432. package/dist/types/sdk/accounts/intents/operations/withdraw-collateral/index.d.ts +0 -36
  433. package/dist/types/sdk/accounts/intents/operations/wrap-rwa-collateral/index.d.ts +0 -30
  434. package/dist/types/sdk/accounts/intents/quoters/close.d.ts +0 -43
  435. package/dist/types/sdk/accounts/intents/quoters/index.d.ts +0 -3
  436. package/dist/types/sdk/accounts/intents/quoters/swap.d.ts +0 -43
  437. package/dist/types/sdk/accounts/intents/testing/resume.d.ts +0 -84
  438. package/dist/types/sdk/accounts/intents/utils/simulate-adjust-state.d.ts +0 -19
  439. package/dist/types/sdk/accounts/intents/utils/simulate-assets.d.ts +0 -21
  440. package/dist/types/sdk/accounts/intents/utils/with-quota-update.d.ts +0 -16
  441. /package/dist/cjs/{new-sdk/utils/history.js → model/notices.js} +0 -0
  442. /package/dist/cjs/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
  443. /package/dist/esm/{new-sdk/utils/history.js → model/notices.js} +0 -0
  444. /package/dist/esm/{sdk/accounts/intents/operations → new-sdk/simulate}/types.js +0 -0
@@ -1,9 +1,21 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
3
+ require("../constants/math.js");
4
+ require("../constants/index.js");
5
+ require("../utils/index.js");
2
6
  const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
3
7
  require("../base/index.js");
8
+ const require_sdk_market_math = require("../market/math.js");
9
+ const require_sdk_market_credit_dominantCollateral = require("../market/credit/dominantCollateral.js");
4
10
  const require_model_filters = require("../../model/filters.js");
5
11
  const require_model_positions = require("../../model/positions.js");
6
12
  require("../../model/index.js");
13
+ require("../market/index.js");
14
+ const require_sdk_positions_calcBorrowRate = require("./calcBorrowRate.js");
15
+ const require_sdk_positions_calcHealthFactor = require("./calcHealthFactor.js");
16
+ const require_sdk_positions_calcLiquidationPrice = require("./calcLiquidationPrice.js");
17
+ const require_sdk_positions_calcTimeToLiquidationMs = require("./calcTimeToLiquidationMs.js");
18
+ const require_sdk_positions_types = require("./types.js");
7
19
  //#region src/sdk/positions/PositionsService.ts
8
20
  /**
9
21
  * The `positions` read model of one chain: everything a wallet holds in the
@@ -28,7 +40,7 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
28
40
  wallet,
29
41
  blockNumber
30
42
  }) : Promise.resolve([]),
31
- wanted("strategy") ? this.sdk.accounts.listPositions({
43
+ wanted("strategy") ? this.listStrategyPositions({
32
44
  owner: wallet,
33
45
  includeZeroDebt: !require_model_filters.isFilterSet(isZeroDebt) || isZeroDebt,
34
46
  blockNumber
@@ -44,6 +56,206 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
44
56
  ...liquidation
45
57
  ].filter((row) => require_model_positions.matchesPositionFilter(row, filter));
46
58
  }
59
+ /**
60
+ * Describes all credit accounts of a wallet as strategy positions.
61
+ *
62
+ * @param props - {@link ListStrategyPositionsProps}
63
+ **/
64
+ async listStrategyPositions(props) {
65
+ const { owner, includeZeroDebt, blockNumber } = props;
66
+ const describable = (await this.sdk.accounts.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber)).filter((ca) => {
67
+ if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
68
+ return ca.success;
69
+ });
70
+ const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
71
+ return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
72
+ }
73
+ /**
74
+ * Health factor of an account state, in basis points (`10000` = 1.0).
75
+ **/
76
+ healthFactor(snapshot, options) {
77
+ const data = this.#marketData(snapshot);
78
+ return require_sdk_positions_calcHealthFactor.calcHealthFactor({
79
+ snapshot,
80
+ underlying: data.underlying,
81
+ decimals: data.decimals,
82
+ prices: data.prices,
83
+ reservePrices: data.reservePrices,
84
+ safePrices: options?.safePrices,
85
+ liquidationThresholds: data.liquidationThresholds,
86
+ activeQuotas: data.activeQuotas
87
+ });
88
+ }
89
+ /**
90
+ * Cost of an account state's debt, broken down into the pool's base rate
91
+ * and per-token quota rates.
92
+ **/
93
+ borrowRate(snapshot) {
94
+ const data = this.#marketData(snapshot);
95
+ return require_sdk_positions_calcBorrowRate.calcBorrowRate({
96
+ snapshot,
97
+ baseInterestRate: data.baseInterestRate,
98
+ feeInterest: data.feeInterest,
99
+ quotaRates: data.quotaRates
100
+ });
101
+ }
102
+ /**
103
+ * Estimated milliseconds until the account's health factor decays to
104
+ * `10000` under its current borrow rate, or `null` when the debt carries
105
+ * no rate (or the account is already liquidatable).
106
+ **/
107
+ timeToLiquidation(snapshot) {
108
+ const data = this.#marketData(snapshot);
109
+ return require_sdk_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs(require_sdk_positions_calcHealthFactor.calcHealthFactor({
110
+ snapshot,
111
+ underlying: data.underlying,
112
+ decimals: data.decimals,
113
+ prices: data.prices,
114
+ liquidationThresholds: data.liquidationThresholds,
115
+ activeQuotas: data.activeQuotas
116
+ }), BigInt(require_sdk_positions_calcBorrowRate.calcBorrowRate({
117
+ snapshot,
118
+ baseInterestRate: data.baseInterestRate,
119
+ feeInterest: data.feeInterest,
120
+ quotaRates: data.quotaRates
121
+ }).totalOnDebt));
122
+ }
123
+ /**
124
+ * Price of the single non-underlying collateral at which the account
125
+ * becomes liquidatable, or `null` when the account holds zero or several
126
+ * non-underlying assets.
127
+ **/
128
+ liquidationPrice(snapshot) {
129
+ const data = this.#marketData(snapshot);
130
+ return require_sdk_positions_calcLiquidationPrice.calcLiquidationPrice({
131
+ snapshot,
132
+ underlying: data.underlying,
133
+ decimals: data.decimals,
134
+ liquidationThresholds: data.liquidationThresholds
135
+ });
136
+ }
137
+ /**
138
+ * Builds one strategy position from an account snapshot.
139
+ *
140
+ * @param withdrawals - Delayed withdrawals of the account, keyed by the
141
+ * phantom token that represents them on it.
142
+ **/
143
+ #toStrategyPosition(ca, withdrawals) {
144
+ const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
145
+ const { market } = suite;
146
+ const { priceOracle } = market;
147
+ const { pool } = market.pool;
148
+ const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
149
+ const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
150
+ const collateral = require_sdk_market_credit_dominantCollateral.dominantCollateral(ca, market);
151
+ const snapshot = require_sdk_positions_types.accountSnapshotFromCreditAccountData(ca);
152
+ const borrowRate = this.borrowRate(snapshot);
153
+ const timeToLiquidation = this.timeToLiquidation(snapshot);
154
+ const liquidationPrice = this.liquidationPrice(snapshot);
155
+ return {
156
+ kind: "strategy",
157
+ chainId: this.sdk.chainId,
158
+ creditManager: ca.creditManager,
159
+ creditAccount: ca.creditAccount,
160
+ name: collateral ? suite.strategyName(collateral) : token.symbol,
161
+ targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
162
+ leverage: require_sdk_market_math.calcPositionLeverage(ca.totalValue, totalDebtValue),
163
+ borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
164
+ totalDebt: {
165
+ token,
166
+ value: totalDebtValue,
167
+ valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
168
+ },
169
+ totalValue: {
170
+ token,
171
+ value: ca.totalValue,
172
+ valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
173
+ },
174
+ healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
175
+ borrowRate,
176
+ timeToLiquidation,
177
+ liquidationPrice,
178
+ collaterals: ca.tokens.flatMap((t) => {
179
+ if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
180
+ return [{
181
+ collateral: priceOracle.toTokenAmount(t.token, t.balance),
182
+ quota: priceOracle.toTokenAmount(market.underlying, t.quota),
183
+ withdrawals: withdrawals.get(t.token) ?? []
184
+ }];
185
+ })
186
+ };
187
+ }
188
+ /**
189
+ * Delayed withdrawals of one account, keyed by the phantom token that
190
+ * represents them on it, so that each collateral row can pick up its own.
191
+ **/
192
+ async #accountWithdrawals(ca, blockNumber) {
193
+ const compressor = this.sdk.withdrawalCompressor;
194
+ const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
195
+ const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
196
+ if (!compressor || !holdsPhantomToken) return byPhantomToken;
197
+ const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
198
+ const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
199
+ const add = (w, outputs, claimableAt) => {
200
+ const assets = outputs.map((o) => ({
201
+ isDelayed: true,
202
+ ...priceOracle.toTokenAmount(o.token, o.amount),
203
+ redeemer: w.redeemer,
204
+ claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
205
+ }));
206
+ byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
207
+ };
208
+ for (const w of claimable) add(w, w.outputs);
209
+ for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
210
+ return byPhantomToken;
211
+ }
212
+ /**
213
+ * Collects decimals, prices and thresholds for the snapshot's tokens plus
214
+ * the market underlying, even when the account holds no underlying balance.
215
+ **/
216
+ #marketData(snapshot) {
217
+ const market = this.sdk.marketRegister.findByCreditManager(snapshot.creditManager);
218
+ const cm = this.sdk.marketRegister.findCreditManager(snapshot.creditManager).creditManager;
219
+ const { priceOracle } = market;
220
+ const underlying = market.pool.underlying;
221
+ const { pqk, pool } = market.pool;
222
+ const tokens = [underlying];
223
+ for (const a of snapshot.assets) tokens.push(a.token);
224
+ for (const q of snapshot.quotas) tokens.push(q.token);
225
+ const decimals = {};
226
+ const prices = {};
227
+ const reservePrices = {};
228
+ const liquidationThresholds = {};
229
+ const activeQuotas = {};
230
+ const quotaRates = {};
231
+ for (const token of tokens) {
232
+ const meta = this.sdk.tokensMeta.get(token);
233
+ if (meta) decimals[token] = meta.decimals;
234
+ try {
235
+ prices[token] = priceOracle.mainPrice(token);
236
+ } catch {}
237
+ try {
238
+ reservePrices[token] = priceOracle.reservePrice(token);
239
+ } catch {}
240
+ const lt = cm.liquidationThresholds.get(token);
241
+ if (lt !== void 0) liquidationThresholds[token] = lt;
242
+ if (pqk.hasActiveQuota(token)) {
243
+ activeQuotas[token] = true;
244
+ quotaRates[token] = pqk.quotaRate(token);
245
+ }
246
+ }
247
+ return {
248
+ underlying,
249
+ decimals,
250
+ prices,
251
+ reservePrices,
252
+ liquidationThresholds,
253
+ activeQuotas,
254
+ quotaRates,
255
+ baseInterestRate: pool.baseInterestRate,
256
+ feeInterest: cm.feeInterest
257
+ };
258
+ }
47
259
  };
48
260
  //#endregion
49
261
  exports.PositionsService = PositionsService;
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
3
+ const require_sdk_constants_math = require("../constants/math.js");
4
+ const require_sdk_market_math = require("../market/math.js");
5
+ //#region src/sdk/positions/calcBorrowRate.ts
6
+ /**
7
+ * Cost of an account state's debt, broken down into the pool's base rate and
8
+ * per-token quota rates.
9
+ *
10
+ * The base rate is the market's current borrow APY (the pool's base rate plus
11
+ * the credit manager's interest fee) — the same value `borrowApy` reports on
12
+ * a position; it is not recomputed for the projected pool liquidity. Quota
13
+ * contributions are `quotaBalance * quotaRate` with the interest fee on top,
14
+ * normalized against the total value (`total`, `quotas`) and against the
15
+ * debt (`totalOnDebt`, the rate the debt itself grows at). Formulas are in
16
+ * parity with the frontend's `BorrowRateUtils`.
17
+ **/
18
+ function calcBorrowRate(props) {
19
+ const { snapshot, baseInterestRate, feeInterest, quotaRates } = props;
20
+ const { quotas, totalDebt, totalValue } = snapshot;
21
+ const rates = new require_sdk_utils_AddressMap.AddressMap(Object.entries(quotaRates));
22
+ const base = require_sdk_market_math.calcBorrowApy(baseInterestRate, feeInterest);
23
+ const fee = require_sdk_constants_math.PERCENTAGE_FACTOR + BigInt(feeInterest);
24
+ let quotaRateSum = 0n;
25
+ const perQuota = {};
26
+ for (const q of quotas) {
27
+ if (q.balance <= 10n) continue;
28
+ const rate = rates.get(q.token);
29
+ const rateBalance = rate === void 0 ? 0n : q.balance * BigInt(rate);
30
+ quotaRateSum += rateBalance;
31
+ const withFee = rateBalance * fee / require_sdk_constants_math.PERCENTAGE_FACTOR;
32
+ perQuota[q.token] = totalValue > 0n ? Number(withFee / totalValue) : 0;
33
+ }
34
+ const quotaRateSumWithFee = quotaRateSum * fee / require_sdk_constants_math.PERCENTAGE_FACTOR;
35
+ return {
36
+ total: totalValue > 0n ? Number(totalDebt * BigInt(base) / totalValue) + Number(quotaRateSumWithFee / totalValue) : 0,
37
+ totalOnDebt: totalDebt > 0n ? base + Number(quotaRateSumWithFee / totalDebt) : 0,
38
+ base,
39
+ quotas: perQuota
40
+ };
41
+ }
42
+ //#endregion
43
+ exports.calcBorrowRate = calcBorrowRate;
@@ -0,0 +1,52 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
3
+ const require_sdk_utils_bigint_math = require("../utils/bigint-math.js");
4
+ const require_sdk_constants_math = require("../constants/math.js");
5
+ let viem = require("viem");
6
+ //#region src/sdk/positions/calcHealthFactor.ts
7
+ /**
8
+ * Health factor of an account state, in basis points (`10000` = 1.0).
9
+ *
10
+ * Collateral is valued under liquidation thresholds, with quoted tokens
11
+ * capped by their quota, and compared against the debt's value. An account
12
+ * with no debt reports `65535` (`MAX_UINT16`), the contract's own sentinel
13
+ * scaled down. Formulas are in parity with the legacy `calcHealthFactor`.
14
+ * Tokens with no price in {@link CalcHealthFactorProps.prices} contribute
15
+ * nothing.
16
+ **/
17
+ function calcHealthFactor(props) {
18
+ const { snapshot, underlying, decimals, prices, reservePrices = {}, safePrices = false, liquidationThresholds, activeQuotas } = props;
19
+ if (snapshot.totalDebt === 0n) return Number(require_sdk_constants_math.MAX_UINT16);
20
+ const decimalsByToken = new require_sdk_utils_AddressMap.AddressMap(Object.entries(decimals));
21
+ const pricesByToken = new require_sdk_utils_AddressMap.AddressMap(Object.entries(prices));
22
+ const reservePricesByToken = new require_sdk_utils_AddressMap.AddressMap(Object.entries(reservePrices));
23
+ const lts = new require_sdk_utils_AddressMap.AddressMap(Object.entries(liquidationThresholds));
24
+ const active = new require_sdk_utils_AddressMap.AddressMap(Object.entries(activeQuotas));
25
+ const priceOf = (token, forCollateral) => {
26
+ const main = pricesByToken.get(token);
27
+ if (!safePrices || !forCollateral) return main;
28
+ const reserve = reservePricesByToken.get(token);
29
+ if (main !== void 0 && reserve !== void 0) return require_sdk_utils_bigint_math.BigIntMath.min(main, reserve);
30
+ return main ?? reserve;
31
+ };
32
+ const convertToUSD = (token, amount, forCollateral = false) => {
33
+ const price = priceOf(token, forCollateral);
34
+ if (price === void 0) return null;
35
+ const scale = 10n ** BigInt(decimalsByToken.get(token) ?? 18);
36
+ return amount * price / scale;
37
+ };
38
+ const assetMoney = snapshot.assets.reduce((acc, { token, balance }) => {
39
+ if (balance <= 10n) return acc;
40
+ const lt = BigInt(lts.get(token) ?? 0);
41
+ const tokenLtWeighted = (convertToUSD(token, balance, true) ?? 0n) * lt;
42
+ const quota = snapshot.quotas.find((q) => (0, viem.isAddressEqual)(q.token, token));
43
+ const quotaBalance = quota && (active.get(token) ?? false) ? quota.balance : 0n;
44
+ const quotaWeighted = (convertToUSD(underlying, quotaBalance) ?? 0n) * require_sdk_constants_math.PERCENTAGE_FACTOR;
45
+ return acc + (quota ? require_sdk_utils_bigint_math.BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
46
+ }, 0n);
47
+ const borrowedMoney = convertToUSD(underlying, snapshot.totalDebt) ?? 0n;
48
+ const hf = borrowedMoney > 0n ? assetMoney / borrowedMoney : 0n;
49
+ return Number(hf);
50
+ }
51
+ //#endregion
52
+ exports.calcHealthFactor = calcHealthFactor;
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../constants/math.js");
3
+ const require_sdk_positions_calcLiquidationPriceForTarget = require("./calcLiquidationPriceForTarget.js");
4
+ let viem = require("viem");
5
+ //#region src/sdk/positions/calcLiquidationPrice.ts
6
+ /**
7
+ * Liquidation price of an account state's target collateral, in the oracle's
8
+ * 8-decimal (`PRICE_DECIMALS`) fixed point.
9
+ *
10
+ * As the frontend does, a liquidation price only exists when the account
11
+ * holds exactly one non-dust non-underlying asset; otherwise `null`.
12
+ **/
13
+ function calcLiquidationPrice(props) {
14
+ const { snapshot, underlying } = props;
15
+ const targets = snapshot.assets.filter((a) => a.balance > 10n && !(0, viem.isAddressEqual)(a.token, underlying));
16
+ if (targets.length !== 1) return null;
17
+ return require_sdk_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget({
18
+ ...props,
19
+ targetToken: targets[0].token
20
+ });
21
+ }
22
+ //#endregion
23
+ exports.calcLiquidationPrice = calcLiquidationPrice;
@@ -0,0 +1,30 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_utils_AddressMap = require("../utils/AddressMap.js");
3
+ const require_sdk_constants_math = require("../constants/math.js");
4
+ let viem = require("viem");
5
+ //#region src/sdk/positions/calcLiquidationPriceForTarget.ts
6
+ /**
7
+ * Liquidation price of an explicitly named collateral token, in
8
+ * `PRICE_DECIMALS` fixed point; `0n` when the account holds none of it or the
9
+ * token has no liquidation threshold. Formula is in parity with the legacy
10
+ * `liquidationPrice`: the effective debt (debt less the underlying balance's
11
+ * contribution under its threshold) over the threshold-weighted target
12
+ * balance.
13
+ **/
14
+ function calcLiquidationPriceForTarget(props) {
15
+ const { snapshot, targetToken, underlying, decimals, liquidationThresholds } = props;
16
+ const decimalsByToken = new require_sdk_utils_AddressMap.AddressMap(Object.entries(decimals));
17
+ const lts = new require_sdk_utils_AddressMap.AddressMap(Object.entries(liquidationThresholds));
18
+ const underlyingDecimals = decimalsByToken.get(underlying) ?? 18;
19
+ const underlyingBalance = snapshot.assets.find((a) => (0, viem.isAddressEqual)(a.token, underlying))?.balance ?? 0n;
20
+ const ltUnderlying = BigInt(lts.get(underlying) ?? 0);
21
+ const effectiveDebt = (snapshot.totalDebt - underlyingBalance * ltUnderlying / require_sdk_constants_math.PERCENTAGE_FACTOR) * require_sdk_constants_math.WAD / 10n ** BigInt(underlyingDecimals);
22
+ const targetDecimals = decimalsByToken.get(targetToken) ?? 18;
23
+ const targetBalance = snapshot.assets.find((a) => (0, viem.isAddressEqual)(a.token, targetToken))?.balance ?? 0n;
24
+ const effectiveTargetBalance = targetBalance * require_sdk_constants_math.WAD / 10n ** BigInt(targetDecimals);
25
+ const lpLT = BigInt(lts.get(targetToken) ?? 0);
26
+ if (targetBalance <= 10n || lpLT <= 0n) return 0n;
27
+ return effectiveDebt * require_sdk_constants_math.PRICE_DECIMALS * require_sdk_constants_math.PERCENTAGE_FACTOR / (effectiveTargetBalance * lpLT);
28
+ }
29
+ //#endregion
30
+ exports.calcLiquidationPriceForTarget = calcLiquidationPriceForTarget;
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_constants_math = require("../constants/math.js");
3
+ //#region src/sdk/positions/calcTimeToLiquidationMs.ts
4
+ /**
5
+ * Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
6
+ * while the debt grows at `totalBorrowRateOnDebt`, in the same `Bps` scale
7
+ * (`10000` = 100%) as {@link BorrowRateBreakdown.totalOnDebt} reports it —
8
+ * not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` = 100%) scale the
9
+ * pre-rewrite frontend fed into its own `getTimeToLiquidation`.
10
+ *
11
+ * `null` when the account is already at or under the liquidation threshold,
12
+ * or when the debt carries no borrow rate at all.
13
+ **/
14
+ function calcTimeToLiquidationMs(healthFactorBps, totalBorrowRateOnDebt) {
15
+ if (BigInt(healthFactorBps) <= 10000n || totalBorrowRateOnDebt === 0n) return null;
16
+ return (BigInt(healthFactorBps) - require_sdk_constants_math.PERCENTAGE_FACTOR) * (BigInt(require_sdk_constants_math.SECONDS_PER_YEAR) * require_sdk_constants_math.PERCENTAGE_FACTOR / totalBorrowRateOnDebt) * 1000n / require_sdk_constants_math.PERCENTAGE_FACTOR;
17
+ }
18
+ //#endregion
19
+ exports.calcTimeToLiquidationMs = calcTimeToLiquidationMs;
@@ -1,6 +1,17 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sdk_positions_calcBorrowRate = require("./calcBorrowRate.js");
3
+ const require_sdk_positions_calcHealthFactor = require("./calcHealthFactor.js");
4
+ const require_sdk_positions_calcLiquidationPriceForTarget = require("./calcLiquidationPriceForTarget.js");
5
+ const require_sdk_positions_calcLiquidationPrice = require("./calcLiquidationPrice.js");
6
+ const require_sdk_positions_calcTimeToLiquidationMs = require("./calcTimeToLiquidationMs.js");
2
7
  const require_sdk_positions_MultichainPositionsService = require("./MultichainPositionsService.js");
8
+ const require_sdk_positions_types = require("./types.js");
3
9
  const require_sdk_positions_PositionsService = require("./PositionsService.js");
4
- require("./types.js");
5
10
  exports.MultichainPositionsService = require_sdk_positions_MultichainPositionsService.MultichainPositionsService;
6
11
  exports.PositionsService = require_sdk_positions_PositionsService.PositionsService;
12
+ exports.accountSnapshotFromCreditAccountData = require_sdk_positions_types.accountSnapshotFromCreditAccountData;
13
+ exports.calcBorrowRate = require_sdk_positions_calcBorrowRate.calcBorrowRate;
14
+ exports.calcHealthFactor = require_sdk_positions_calcHealthFactor.calcHealthFactor;
15
+ exports.calcLiquidationPrice = require_sdk_positions_calcLiquidationPrice.calcLiquidationPrice;
16
+ exports.calcLiquidationPriceForTarget = require_sdk_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget;
17
+ exports.calcTimeToLiquidationMs = require_sdk_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs;
@@ -1 +1,32 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../constants/math.js");
3
+ //#region src/sdk/positions/types.ts
4
+ /**
5
+ * Builds an {@link AccountSnapshot} from on-chain credit account data: the
6
+ * enabled, above-dust tokens become assets and quotas, and `totalDebt` is
7
+ * principal plus accrued interest and fees.
8
+ **/
9
+ function accountSnapshotFromCreditAccountData(ca) {
10
+ const assets = [];
11
+ const quotas = [];
12
+ for (const t of ca.tokens) {
13
+ if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
14
+ assets.push({
15
+ token: t.token,
16
+ balance: t.balance
17
+ });
18
+ quotas.push({
19
+ token: t.token,
20
+ balance: t.quota
21
+ });
22
+ }
23
+ return {
24
+ creditManager: ca.creditManager,
25
+ assets,
26
+ quotas,
27
+ totalDebt: ca.debt + ca.accruedInterest + ca.accruedFees,
28
+ totalValue: ca.totalValue
29
+ };
30
+ }
31
+ //#endregion
32
+ exports.accountSnapshotFromCreditAccountData = accountSnapshotFromCreditAccountData;
@@ -28,7 +28,7 @@ function functionArgsToMap(abi, functionName, args) {
28
28
  name: functionName,
29
29
  args
30
30
  });
31
- if (!abiItem || abiItem.type !== "function") throw new viem.AbiFunctionNotFoundError(functionName);
31
+ if (abiItem?.type !== "function") throw new viem.AbiFunctionNotFoundError(functionName);
32
32
  const namedArgs = {};
33
33
  if (Array.isArray(args)) args.forEach((value, i) => {
34
34
  const input = abiItem.inputs?.[i];
@@ -51,7 +51,7 @@ function functionArgsToRecord(abi, functionName, args) {
51
51
  name: functionName,
52
52
  args
53
53
  });
54
- if (!abiItem || abiItem.type !== "function") throw new viem.AbiFunctionNotFoundError(functionName);
54
+ if (abiItem?.type !== "function") throw new viem.AbiFunctionNotFoundError(functionName);
55
55
  const namedArgs = {};
56
56
  if (Array.isArray(args)) args.forEach((value, i) => {
57
57
  const key = (abiItem.inputs?.[i])?.name || `${i}`;
@@ -0,0 +1,32 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/sdk/utils/viem/executeMulticallBatches.ts
3
+ /**
4
+ * Executes the calls of several {@link MulticallBatch}es as a single multicall
5
+ * aggregate and dispatches each batch its own slice of the results.
6
+ *
7
+ * Failures are allowed per call: loaders in a batch decide themselves how to
8
+ * treat a reverted call (e.g. `contractType()` reverting on a plain ERC-20 is
9
+ * expected). Use {@link executeDelegatedMulticalls} instead when the calls need
10
+ * price updates applied first.
11
+ *
12
+ * @param client - Viem public client.
13
+ * @param batches - Batches to execute together, empty ones are allowed.
14
+ * @param opts - Block number forwarded to the multicall.
15
+ **/
16
+ async function executeMulticallBatches(client, batches, opts = {}) {
17
+ const contracts = batches.flatMap((b) => b.contracts);
18
+ if (!contracts.length) return;
19
+ const results = await client.multicall({
20
+ contracts,
21
+ allowFailure: true,
22
+ batchSize: 0,
23
+ blockNumber: opts.blockNumber
24
+ });
25
+ let offset = 0;
26
+ for (const batch of batches) {
27
+ batch.onResults(results.slice(offset, offset + batch.contracts.length));
28
+ offset += batch.contracts.length;
29
+ }
30
+ }
31
+ //#endregion
32
+ exports.executeMulticallBatches = executeMulticallBatches;
@@ -1,6 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_sdk_utils_viem_cast = require("./cast.js");
3
3
  const require_sdk_utils_viem_simulateCall = require("./simulateCall.js");
4
+ const require_sdk_utils_viem_executeMulticallBatches = require("./executeMulticallBatches.js");
4
5
  const require_sdk_utils_viem_simulateMulticall = require("./simulateMulticall.js");
5
6
  const require_sdk_utils_viem_simulateWithPriceUpdates = require("./simulateWithPriceUpdates.js");
6
7
  const require_sdk_utils_viem_executeDelegatedMulticalls = require("./executeDelegatedMulticalls.js");
@@ -10,6 +11,7 @@ exports.SimulateWithPriceUpdatesError = require_sdk_utils_viem_simulateWithPrice
10
11
  exports.SimulationError = require_sdk_utils_viem_simulateCall.SimulationError;
11
12
  exports.estimateRawTxGas = require_sdk_utils_viem_sendRawTx.estimateRawTxGas;
12
13
  exports.executeDelegatedMulticalls = require_sdk_utils_viem_executeDelegatedMulticalls.executeDelegatedMulticalls;
14
+ exports.executeMulticallBatches = require_sdk_utils_viem_executeMulticallBatches.executeMulticallBatches;
13
15
  exports.generateCastTraceCall = require_sdk_utils_viem_cast.generateCastTraceCall;
14
16
  exports.getCastTraceArgs = require_sdk_utils_viem_cast.getCastTraceArgs;
15
17
  exports.getSimulateWithPriceUpdatesError = require_sdk_utils_viem_simulateWithPriceUpdates.getSimulateWithPriceUpdatesError;
@@ -0,0 +1,14 @@
1
+ //#region src/abi/iExpirable.ts
2
+ const iExpirableAbi = [{
3
+ type: "function",
4
+ inputs: [],
5
+ name: "isExpired",
6
+ outputs: [{
7
+ name: "",
8
+ internalType: "bool",
9
+ type: "bool"
10
+ }],
11
+ stateMutability: "view"
12
+ }];
13
+ //#endregion
14
+ export { iExpirableAbi };
@@ -4,6 +4,8 @@ import { calcQuotaBorrowRate } from "../creditAccount/calc-quota-borrow-rate.js"
4
4
  /**
5
5
  * Under the hood sums up rates for all given quotas and then multiplies them by 1+feeInterest,
6
6
  * but it is expected that the ONLY quota will be passed
7
+ *
8
+ * @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
7
9
  */
8
10
  function getSingleQuotaBorrowRate(props) {
9
11
  const qr = calcQuotaBorrowRate(props);
@@ -1,9 +1,5 @@
1
- import { BigIntMath } from "../../../sdk/utils/bigint-math.js";
2
- import { PERCENTAGE_FACTOR, PRICE_DECIMALS } from "../../../sdk/constants/math.js";
3
- import "../../../sdk/index.js";
4
- import { PriceUtils } from "../price-math.js";
1
+ import { calcHealthFactor as calcHealthFactor$1 } from "../../../sdk/positions/calcHealthFactor.js";
5
2
  //#region src/common-utils/utils/creditAccount/calc-health-factor.ts
6
- const MAX_UINT16 = 65535;
7
3
  /**
8
4
  * Computes account health factor in percentage-factor units.
9
5
  *
@@ -14,25 +10,31 @@ const MAX_UINT16 = 65535;
14
10
  * @param props Credit account balances, quotas, prices, thresholds, and debt context.
15
11
  * @returns Health factor as a number in `PERCENTAGE_FACTOR` scale,
16
12
  * or `65535` when debt is zero.
13
+ *
14
+ * @deprecated Use `calcHealthFactor` from `sdk/positions` instead; this
15
+ * wrapper only maps the legacy props onto an `AccountSnapshot`.
17
16
  */
18
17
  function calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList }) {
19
- if (debt === 0n) return MAX_UINT16;
20
- const underlyingDecimals = tokensList[underlyingToken]?.decimals || 18;
21
- const underlyingPrice = prices[underlyingToken] || 0n;
22
- const assetMoney = assets.reduce((acc, { token: tokenAddress, balance: amount }) => {
23
- const tokenDecimals = tokensList[tokenAddress]?.decimals || 18;
24
- const lt = liquidationThresholds[tokenAddress] || 0n;
25
- const price = prices[tokenAddress] || 0n;
26
- const tokenLtMoney = PriceUtils.calcTotalPrice(price, amount, tokenDecimals) * lt / PERCENTAGE_FACTOR;
27
- const { isActive = false } = quotasInfo?.[tokenAddress] || {};
28
- const quota = quotas[tokenAddress];
29
- const quotaBalance = isActive ? quota?.balance || 0n : 0n;
30
- const quotaMoney = PriceUtils.calcTotalPrice(underlyingPrice, quotaBalance, underlyingDecimals);
31
- return acc + (quota ? BigIntMath.min(quotaMoney, tokenLtMoney) : tokenLtMoney);
32
- }, 0n);
33
- const borrowedMoney = PriceUtils.calcTotalPrice(underlyingPrice || PRICE_DECIMALS, debt, underlyingDecimals);
34
- const hfInPercent = borrowedMoney > 0n ? assetMoney * PERCENTAGE_FACTOR / borrowedMoney : 0n;
35
- return Number(hfInPercent);
18
+ const decimals = {};
19
+ for (const [token, meta] of Object.entries(tokensList)) decimals[token] = meta.decimals;
20
+ const lts = {};
21
+ for (const [token, lt] of Object.entries(liquidationThresholds)) lts[token] = Number(lt);
22
+ const activeQuotas = {};
23
+ for (const [token, info] of Object.entries(quotasInfo)) if (info?.isActive) activeQuotas[token] = true;
24
+ return calcHealthFactor$1({
25
+ snapshot: {
26
+ creditManager: underlyingToken,
27
+ assets,
28
+ quotas: Object.values(quotas),
29
+ totalDebt: debt,
30
+ totalValue: 0n
31
+ },
32
+ underlying: underlyingToken,
33
+ decimals,
34
+ prices,
35
+ liquidationThresholds: lts,
36
+ activeQuotas
37
+ });
36
38
  }
37
39
  //#endregion
38
40
  export { calcHealthFactor };
@@ -8,6 +8,8 @@
8
8
  *
9
9
  * @param props Quota balances and per-token quota rates.
10
10
  * @returns Sum of `balance * rate` terms in percentage-factor scale.
11
+ *
12
+ * @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
11
13
  */
12
14
  function calcQuotaBorrowRate({ quotas, quotaRates }) {
13
15
  return Object.values(quotas).reduce((acc, { token, balance }) => {
@@ -1,5 +1,4 @@
1
- import { PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../../../sdk/constants/math.js";
2
- import "../../../sdk/index.js";
1
+ import { calcTimeToLiquidationMs } from "../../../sdk/positions/calcTimeToLiquidationMs.js";
3
2
  //#region src/common-utils/utils/creditAccount/get-time-to-liquidation.ts
4
3
  /**
5
4
  * Estimates time remaining until health factor reaches liquidation level.
@@ -8,13 +7,17 @@ import "../../../sdk/index.js";
8
7
  * and returns a millisecond duration until `healthFactor` decays to `1.0`
9
8
  * (`PERCENTAGE_FACTOR` in internal scale).
10
9
  *
11
- * @param props Current health factor and `totalBorrowRate * debt` term.
10
+ * @param props Current health factor and `totalBorrowRate_debt`, both `Bps`
11
+ * (`10000` = 100%) — not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` =
12
+ * 100%) scale the pre-rewrite frontend fed this under the same name.
12
13
  * @returns Milliseconds to liquidation as `bigint`, or `null` when already at/under
13
14
  * liquidation threshold or when borrow-rate exposure is zero.
15
+ *
16
+ * @deprecated Use `calcTimeToLiquidationMs` from `sdk/positions` instead;
17
+ * this wrapper only forwards to the new implementation.
14
18
  */
15
19
  function getTimeToLiquidation({ healthFactor, totalBorrowRate_debt }) {
16
- if (healthFactor <= 10000n || totalBorrowRate_debt === 0n) return null;
17
- return (BigInt(healthFactor) - PERCENTAGE_FACTOR) * (BigInt(SECONDS_PER_YEAR) * PERCENTAGE_FACTOR * PERCENTAGE_DECIMALS / totalBorrowRate_debt) * 1000n / PERCENTAGE_FACTOR;
20
+ return calcTimeToLiquidationMs(healthFactor, totalBorrowRate_debt);
18
21
  }
19
22
  //#endregion
20
23
  export { getTimeToLiquidation };