@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
@@ -4,53 +4,84 @@ import { VERSION_RANGE_310 } from "../constants/versions.js";
4
4
  import "../constants/index.js";
5
5
  import { hexEq } from "../utils/hex.js";
6
6
  import "../utils/index.js";
7
+ import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
7
8
  import { SDKConstruct } from "../base/SDKConstruct.js";
8
9
  import "../base/index.js";
9
10
  import { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
11
+ import "../utils/viem/index.js";
10
12
  import { createZapper } from "./zapper/createZapper.js";
11
13
  import "./zapper/index.js";
12
14
  //#region src/sdk/market/ZapperRegister.ts
13
15
  var ZapperRegister = class extends SDKConstruct {
14
16
  /**
15
17
  * Mapping pool.address -> Zapper[]
16
- * Needs to be loaded explicitly using loadZappers method
18
+ * Loaded during SDK attach, or restored by hydration
17
19
  */
18
20
  #zappers;
19
21
  /**
20
- * Load zappers for all pools using periphery compressor, adds hardcoded zappers
21
- */
22
- async loadZappers(force) {
23
- if (!force && this.#zappers) return;
24
- const [pcAddr] = this.sdk.addressProvider.mustGetLatest(AP_PERIPHERY_COMPRESSOR, VERSION_RANGE_310);
22
+ * @internal
23
+ *
24
+ * Returns the multicall batch that loads zappers of all pools from the
25
+ * periphery compressor. Used by the SDK to warm this cache together with
26
+ * other loaders in a single multicall.
27
+ *
28
+ * Returns an empty batch when zappers are already loaded and `force` is not set.
29
+ *
30
+ * @param force - reload zappers even when they are already loaded
31
+ **/
32
+ getLoadZappersMulticall(force) {
33
+ if (!force && this.#zappers) return {
34
+ contracts: [],
35
+ onResults: () => {}
36
+ };
37
+ this.#zappers = new AddressMap(void 0, "zappers");
38
+ const compressor = this.sdk.addressProvider.getLatest(AP_PERIPHERY_COMPRESSOR, VERSION_RANGE_310);
39
+ if (!compressor) {
40
+ this.logger?.warn("no periphery compressor on this chain, skipping zappers");
41
+ return {
42
+ contracts: [],
43
+ onResults: () => {}
44
+ };
45
+ }
46
+ const [pcAddr] = compressor;
25
47
  this.logger?.debug(`loading zappers with periphery compressor ${pcAddr}`);
26
48
  const markets = this.sdk.marketRegister.markets;
27
- const resp = await this.client.multicall({
49
+ return {
28
50
  contracts: markets.map((m) => ({
29
51
  abi: peripheryCompressorAbi,
30
52
  address: pcAddr,
31
53
  functionName: "getZappers",
32
54
  args: [m.configurator.address, m.pool.pool.address]
33
55
  })),
34
- allowFailure: true,
35
- batchSize: 0
36
- });
37
- this.#zappers = new AddressMap(void 0, "zappers");
38
- for (let i = 0; i < resp.length; i++) {
39
- const { status, result, error } = resp[i];
40
- const marketConfigurator = markets[i].configurator.address;
41
- const pool = markets[i].pool.pool.address;
42
- if (status === "success") for (const z of result) this.#addZapper({
43
- ...z,
44
- pool,
45
- type: "base"
46
- });
47
- else this.logger?.error(`failed to load zapper for market configurator ${this.labelAddress(marketConfigurator)} and pool ${this.labelAddress(pool)}: ${error}`);
48
- }
56
+ onResults: (resps) => {
57
+ for (let i = 0; i < resps.length; i++) {
58
+ const { status, result, error } = resps[i];
59
+ const marketConfigurator = markets[i].configurator.address;
60
+ const pool = markets[i].pool.pool.address;
61
+ if (status === "success") for (const z of result) this.#addZapper({
62
+ ...z,
63
+ pool,
64
+ type: "base"
65
+ });
66
+ else this.logger?.error(`failed to load zapper for market configurator ${this.labelAddress(marketConfigurator)} and pool ${this.labelAddress(pool)}: ${error}`);
67
+ }
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * Load zappers for all pools using periphery compressor, adds hardcoded zappers
73
+ *
74
+ * Zappers loaded during SDK attach or restored by hydration are kept unless
75
+ * `force` is set, so calling this after either is a no-op.
76
+ */
77
+ async loadZappers(force) {
78
+ await executeMulticallBatches(this.client, [this.getLoadZappersMulticall(force)]);
49
79
  }
50
80
  /**
51
81
  * Serializable snapshot of all loaded zappers, suitable for hydration.
52
- * Returns `undefined` when zappers were never loaded (i.e. `loadZappers` was
53
- * not called), so the not-loaded state round-trips cleanly.
82
+ * Returns `undefined` when zappers were never loaded (i.e. the SDK was
83
+ * attached without market configurators), so the not-loaded state round-trips
84
+ * cleanly.
54
85
  **/
55
86
  get zappersState() {
56
87
  if (!this.#zappers) return;
@@ -102,7 +133,7 @@ var ZapperRegister = class extends SDKConstruct {
102
133
  }
103
134
  }
104
135
  get zappers() {
105
- if (!this.#zappers) throw new Error("zappers not loaded, call loadZappers first");
136
+ if (!this.#zappers) throw new Error("zappers are not loaded, check if the sdk was properly attached or hydrated");
106
137
  return this.#zappers;
107
138
  }
108
139
  poolZappers(pool) {
@@ -1,7 +1,7 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/BaseContract.js";
3
4
  import "../../base/index.js";
4
- import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -8,8 +8,7 @@ import { BaseContract } from "../../base/BaseContract.js";
8
8
  import "../../base/index.js";
9
9
  import { createAdapter } from "../adapters/createAdapter.js";
10
10
  import "../adapters/index.js";
11
- import { maxLeverage } from "../math.js";
12
- import { isAddressEqual } from "viem";
11
+ import { calcMaxLeverage } from "../math.js";
13
12
  //#region src/sdk/market/credit/CreditManagerV310Contract.ts
14
13
  const abi = iCreditManagerV310Abi;
15
14
  var CreditManagerV310Contract = class extends BaseContract {
@@ -64,20 +63,10 @@ var CreditManagerV310Contract = class extends BaseContract {
64
63
  return this.liquidationThresholds.keys();
65
64
  }
66
65
  /**
67
- * {@inheritDoc ICreditManagerContract.leverageableCollaterals}
68
- */
69
- get leverageableCollaterals() {
70
- return this.collateralTokens.filter((token) => {
71
- if (isAddressEqual(token, this.underlying)) return false;
72
- const lt = this.liquidationThresholds.get(token);
73
- return !!lt && lt > 0 && lt < Number(10000n);
74
- });
75
- }
76
- /**
77
66
  * {@inheritDoc ICreditManagerContract.maxLeverage}
78
67
  */
79
68
  maxLeverage(collateral) {
80
- return maxLeverage(this.liquidationThresholds.mustGet(collateral));
69
+ return calcMaxLeverage(this.liquidationThresholds.mustGet(collateral));
81
70
  }
82
71
  /**
83
72
  * {@inheritDoc ICreditManagerContract.liquidationPremium}
@@ -6,11 +6,12 @@ import "../../constants/index.js";
6
6
  import "../../utils/index.js";
7
7
  import { SDKConstruct } from "../../base/SDKConstruct.js";
8
8
  import "../../base/index.js";
9
- import { additionalBorrowApyBps, borrowApyBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount } from "../math.js";
9
+ import { calcAdditionalBorrowApy, calcBorrowApy, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount } from "../math.js";
10
10
  import createCreditConfigurator from "./createCreditConfigurator.js";
11
11
  import createCreditFacade from "./createCreditFacade.js";
12
12
  import createCreditManager from "./createCreditManager.js";
13
13
  import { mustGetDominantCollateral } from "./dominantCollateral.js";
14
+ import { isStrategyCollateral } from "./isStrategyCollateral.js";
14
15
  //#region src/sdk/market/credit/CreditSuite.ts
15
16
  /**
16
17
  * SDK aggregate for one credit-manager branch inside a market.
@@ -170,13 +171,31 @@ var CreditSuite = class extends SDKConstruct {
170
171
  return this.creditFacade.isPaused || this.market.pool.isPaused;
171
172
  }
172
173
  /**
173
- * Collateral tokens a leveraged position can be built around in this suite:
174
- * the ones the credit manager can lever up, narrowed to those the market
175
- * still accepts quota for.
174
+ * Collateral tokens a leveraged position can be built around in this suite,
175
+ * see {@link isStrategyCollateral} for the per-token criteria.
176
+ *
177
+ * A suite where no debt can be drawn at all ({@link maxBorrowAmount} is `0`,
178
+ * e.g. its debt limit is exhausted or zeroed out) offers no strategies,
179
+ * whatever its collaterals are.
176
180
  */
177
181
  get strategyCollaterals() {
178
- const { pqk } = this.market.pool;
179
- return this.creditManager.leverageableCollaterals.filter((token) => pqk.hasActiveQuota(token));
182
+ if (this.maxBorrowAmount === 0n) return [];
183
+ const { pqk, unwrappedUnderlying } = this.market.pool;
184
+ const { mainPrices } = this.market.priceOracle;
185
+ const { tokensMeta, creditManager } = this;
186
+ return creditManager.collateralTokens.filter((token) => {
187
+ const meta = tokensMeta.mustGet(token);
188
+ return isStrategyCollateral({
189
+ token,
190
+ underlying: creditManager.underlying,
191
+ unwrappedUnderlying,
192
+ liquidationThreshold: creditManager.liquidationThresholds.mustGet(token),
193
+ contractType: meta.contractType,
194
+ isExpired: meta.isExpired,
195
+ mainPrice: mainPrices.get(token)?.price,
196
+ hasActiveQuota: pqk.hasActiveQuota(token)
197
+ });
198
+ });
180
199
  }
181
200
  /**
182
201
  * Largest debt a single new position can take on right now: the tightest of
@@ -220,16 +239,16 @@ var CreditSuite = class extends SDKConstruct {
220
239
  curator: market.curator,
221
240
  underlyingToken: market.underlyingToken,
222
241
  totalBorrow: oracle.toAmount(pool.underlying, borrowed),
223
- collateralTokens: market.collateralTokens,
242
+ collateralTokens: this.strategyCollaterals.map((t) => this.tokensMeta.mustGetToken(t)),
224
243
  paused: this.isPaused,
225
244
  rwa: market.rwa,
226
- sunset: isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
245
+ sunset: market.sunset || isSunsetStrategy(cm.address, collateral, this.sdk.networkType),
227
246
  liquidationThreshold,
228
247
  liquidationPremium: cm.liquidationPremium,
229
248
  liquidationFee: cm.feeLiquidation,
230
249
  expirationDate: this.expirationDate,
231
- borrowApy: borrowApyBps(pool.baseInterestRate, cm.feeInterest),
232
- additionalBorrowApy: additionalBorrowApyBps(market.pool.pqk.quotaRate(collateral), maxLeverage),
250
+ borrowApy: calcBorrowApy(pool.baseInterestRate, cm.feeInterest),
251
+ additionalBorrowApy: calcAdditionalBorrowApy(market.pool.pqk.quotaRate(collateral), cm.feeInterest, maxLeverage),
233
252
  maxBorrowAmount: oracle.toAmount(pool.underlying, this.maxBorrowAmount),
234
253
  maxLeverage
235
254
  };
@@ -3,7 +3,8 @@ import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./Cred
3
3
  import { CreditFacadeV310Contract } from "./CreditFacadeV310Contract.js";
4
4
  import { CreditManagerV310Contract } from "./CreditManagerV310Contract.js";
5
5
  import { dominantCollateral, mustGetDominantCollateral } from "./dominantCollateral.js";
6
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./isStrategyCollateral.js";
6
7
  import { CreditSuite } from "./CreditSuite.js";
7
8
  import { expectedBalanceDeltas } from "./expectedBalanceDeltas.js";
8
9
  import "./types.js";
9
- export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, mustGetDominantCollateral };
10
+ export { CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, NON_STRATEGY_PHANTOM_TOKEN_TYPES, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, isStrategyCollateral, mustGetDominantCollateral };
@@ -0,0 +1,48 @@
1
+ import "../../constants/math.js";
2
+ import "../../constants/index.js";
3
+ import { isAddressEqual } from "viem";
4
+ //#region src/sdk/market/credit/isStrategyCollateral.ts
5
+ /**
6
+ * Withdrawal and redemption phantom tokens that can never be acquired as a
7
+ * strategy target. Other `PHANTOM_TOKEN::*` types (Convex, Infrared, staking
8
+ * rewards) can.
9
+ */
10
+ const NON_STRATEGY_PHANTOM_TOKEN_TYPES = [
11
+ "PHANTOM_TOKEN::INFINIFI_UNWIND",
12
+ "PHANTOM_TOKEN::MELLOW_WITHDRAWAL",
13
+ "PHANTOM_TOKEN::MIDAS_REDEMPTION",
14
+ "PHANTOM_TOKEN::SECURITIZE_RD",
15
+ "PHANTOM_TOKEN::UPSHIFT_WITHDRAW"
16
+ ];
17
+ const NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET = new Set(NON_STRATEGY_PHANTOM_TOKEN_TYPES);
18
+ const RWA_UNDERLYING_PREFIX = "RWA_UNDERLYING::";
19
+ /**
20
+ * Whether a collateral token can be the target of a leveraged strategy.
21
+ *
22
+ * A token qualifies when it
23
+ *
24
+ * - has a liquidation threshold above `0` and below `100%`, and is not the
25
+ * suite's underlying — borrowing an asset against itself is not a position,
26
+ * and an LT of `0` or at least `100%` would mean unbounded leverage;
27
+ * - is not the token the market's underlying wraps, which for an RWA market
28
+ * is the same exposure as the underlying itself (also rejected when
29
+ * `contractType` starts with `"RWA_UNDERLYING::"`);
30
+ * - is not a withdrawal or redemption phantom token listed in
31
+ * {@link NON_STRATEGY_PHANTOM_TOKEN_TYPES} — those only ever appear as the
32
+ * intermediate step of a withdrawal and cannot be acquired;
33
+ * - is not an expired token, e.g. a matured Pendle PT;
34
+ * - has a non-zero main price in the market's oracle — a zero or missing
35
+ * answer (e.g. a failed or zero price feed) means the position cannot be
36
+ * valued;
37
+ * - the market still accepts quota for.
38
+ */
39
+ function isStrategyCollateral({ token, underlying, unwrappedUnderlying, liquidationThreshold, contractType, isExpired, mainPrice, hasActiveQuota }) {
40
+ if (isAddressEqual(token, underlying) || isAddressEqual(token, unwrappedUnderlying)) return false;
41
+ if (liquidationThreshold <= 0 || liquidationThreshold >= Number(10000n)) return false;
42
+ if (contractType && (NON_STRATEGY_PHANTOM_TOKEN_TYPE_SET.has(contractType) || contractType.startsWith(RWA_UNDERLYING_PREFIX))) return false;
43
+ if (isExpired) return false;
44
+ if (!mainPrice) return false;
45
+ return hasActiveQuota;
46
+ }
47
+ //#endregion
48
+ export { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral };
@@ -4,8 +4,10 @@ import "./adapters/index.js";
4
4
  import { CreditConfiguratorV310Contract } from "./credit/CreditConfiguratorV310Contract.js";
5
5
  import { CreditFacadeV310BaseContract, creditFacadeV310Abi as abi } from "./credit/CreditFacadeV310BaseContract.js";
6
6
  import { CreditFacadeV310Contract } from "./credit/CreditFacadeV310Contract.js";
7
+ import { MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber } from "./math.js";
7
8
  import { CreditManagerV310Contract } from "./credit/CreditManagerV310Contract.js";
8
9
  import { dominantCollateral, mustGetDominantCollateral } from "./credit/dominantCollateral.js";
10
+ import { NON_STRATEGY_PHANTOM_TOKEN_TYPES, isStrategyCollateral } from "./credit/isStrategyCollateral.js";
9
11
  import { CreditSuite } from "./credit/CreditSuite.js";
10
12
  import { expectedBalanceDeltas } from "./credit/expectedBalanceDeltas.js";
11
13
  import "./credit/index.js";
@@ -59,4 +61,4 @@ import { RWARegistry } from "./rwa/RWARegistry.js";
59
61
  import { RWA_FACTORY_TYPES, isRWAFactory } from "./rwa/types.js";
60
62
  import "./rwa/index.js";
61
63
  import "./types.js";
62
- export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, LinearInterestRateModelContract, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeRWAFactory, UnsupportedZapperFunctionError, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, fetchRedstonePayloads, getRawPriceUpdates, isLPPriceFeed, isRWAFactory, isUpdatablePriceFeed, mustGetDominantCollateral };
64
+ export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CreditConfiguratorV310Contract, CreditFacadeV310BaseContract, CreditFacadeV310Contract, CreditManagerV310Contract, CreditSuite, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, GaugeContract, IERC20ZapperContract, IETHZapperContract, LinearInterestRateModelContract, MAX_LEVERAGE_BUFFER_BPS, MarketRegister, MarketSuite, MellowLRTPriceFeedContract, MidasLiquidatorContract, NON_STRATEGY_PHANTOM_TOKEN_TYPES, PARTIAL_LIQUIDATION_BUFFER_BPS, PHANTOM_TOKEN_MIDAS_REDEMPTION, PHANTOM_TOKEN_SECURITIZE_REDEMPTION, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PlaceholderAdapterContract, PoolSuite, PoolV310Contract, PriceFeedRef, PriceFeedRegister, PriceOracleV310Contract, PythPriceFeed, RWARegistry, RWA_FACTORY_SECURITIZE, RWA_FACTORY_TYPES, RWA_LIQUIDATOR_MIDAS, RWA_LIQUIDATOR_SECURITIZE, RedstonePriceFeedContract, SECURITIZE_REGISTER_VAULT_TYPES, SecuritizeLiquidatorContract, SecuritizeRWAFactory, UnsupportedZapperFunctionError, WstETHPriceFeedContract, YearnPriceFeedContract, ZapperContract, ZeroPriceFeedContract, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, createAdapter, createPriceOracle, createZapper, abi as creditFacadeV310Abi, dominantCollateral, expectedBalanceDeltas, fetchRedstonePayloads, getRawPriceUpdates, healthFactorBps, isLPPriceFeed, isRWAFactory, isStrategyCollateral, isUpdatablePriceFeed, minSeizedAmount, mustGetDominantCollateral, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
@@ -15,7 +15,8 @@ const FULL = Number(PERCENTAGE_FACTOR);
15
15
  *
16
16
  * @example
17
17
  * ```ts
18
- * rayToBps(50_000_000_000_000_000_000_000_000n) // 500, i.e. 5%
18
+ * // ray: 5% (0.05 × 10²⁷)
19
+ * rayToBps(50_000_000_000_000_000_000_000_000n) // 500 bps = 5%
19
20
  * ```
20
21
  **/
21
22
  function rayToBps(ray) {
@@ -26,6 +27,7 @@ function rayToBps(ray) {
26
27
  *
27
28
  * @example
28
29
  * ```ts
30
+ * // usd: $1500.50 in 8-decimal fixed point
29
31
  * usdToNumber(150_050_000_000n) // 1500.5
30
32
  * ```
31
33
  **/
@@ -38,56 +40,66 @@ function usdToNumber(usd) {
38
40
  *
39
41
  * @example
40
42
  * ```ts
41
- * utilizationBps(750n, 1000n) // 7500, i.e. 75%
43
+ * // borrowed: 750, total: 1000
44
+ * calcUtilization(750n, 1000n) // 750 / 1000 = 7500 bps = 75%
42
45
  * ```
43
46
  **/
44
- function utilizationBps(borrowed, total) {
47
+ function calcUtilization(borrowed, total) {
45
48
  if (total <= 0n || borrowed <= 0n) return 0;
46
49
  const utilization = Number(borrowed * PERCENTAGE_FACTOR / total);
47
50
  return Math.min(utilization, FULL);
48
51
  }
49
52
  /**
50
- * Annual cost of debt for a credit manager, in basis points: the pool's base
51
- * rate plus the protocol's cut of the accrued interest.
53
+ * Annual cost of debt for a credit manager, in basis points:
54
+ * `baseInterestRate × (1 + feeInterest)` — the pool's base rate plus the
55
+ * protocol's cut of the accrued interest.
52
56
  *
53
57
  * @param baseInterestRate - Pool base rate in ray.
54
58
  * @param feeInterest - Credit manager interest fee in basis points.
55
59
  *
56
60
  * @example
57
61
  * ```ts
58
- * // 5% base rate, 50% interest fee
59
- * borrowApyBps(50_000_000_000_000_000_000_000_000n, 5000) // 750, i.e. 7.5%
62
+ * // baseInterestRate: 5% in ray, feeInterest: 5000 bps = 50%
63
+ * calcBorrowApy(50_000_000_000_000_000_000_000_000n, 5000) // 5% × 1.5 = 750 bps = 7.5%
60
64
  * ```
61
65
  **/
62
- function borrowApyBps(baseInterestRate, feeInterest) {
66
+ function calcBorrowApy(baseInterestRate, feeInterest) {
63
67
  return rayToBps(baseInterestRate * (PERCENTAGE_FACTOR + BigInt(feeInterest)) / PERCENTAGE_FACTOR);
64
68
  }
65
69
  /**
66
- * Highest leverage a liquidation threshold allows: `1 / (1 - lt)`.
67
- *
68
- * A threshold of 100% or more would allow unbounded leverage; such tokens are
69
- * not strategies and are filtered out before this is called, so the guard here
70
- * only exists to keep the function total.
70
+ * 5% safety margin subtracted from 100% in {@link calcMaxLeverage}, so a
71
+ * maxed position opens with HF slightly above 1.
72
+ **/
73
+ const MAX_LEVERAGE_BUFFER_BPS = 500;
74
+ /**
75
+ * Highest total-value leverage a liquidation threshold allows:
76
+ * `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
77
+ * `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
78
+ * equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
79
+ * keeps the maxed position slightly away from that boundary.
71
80
  *
72
81
  * @example
73
82
  * ```ts
74
- * maxLeverage(9000) // 10
75
- * maxLeverage(8000) // 5
83
+ * // liquidationThreshold: 9000 bps = 90%
84
+ * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
76
85
  * ```
77
86
  **/
78
- function maxLeverage(liquidationThreshold) {
79
- const equity = FULL - liquidationThreshold;
80
- return equity > 0 ? FULL / equity : Number.POSITIVE_INFINITY;
87
+ function calcMaxLeverage(liquidationThreshold) {
88
+ if (liquidationThreshold >= FULL) return 0;
89
+ const leverage = (FULL - 500) / (FULL - liquidationThreshold);
90
+ return Math.max(leverage, 1);
81
91
  }
82
92
  /**
83
93
  * Converts a credit account's health factor from the 18-decimal fixed point the
84
94
  * contracts store to basis points.
85
95
  *
86
- * An account with no debt return MAX_UINT256 from contract, here we return 0
96
+ * Accounts with no debt store `MAX_UINT256` on-chain; for those this
97
+ * returns `0`.
87
98
  *
88
99
  * @example
89
100
  * ```ts
90
- * healthFactorBps(1_250_000_000_000_000_000n) // 12500, i.e. 1.25
101
+ * // healthFactor: 1.25 in 18-decimal fixed point
102
+ * healthFactorBps(1_250_000_000_000_000_000n) // 12500 bps = 1.25
91
103
  * ```
92
104
  **/
93
105
  function healthFactorBps(healthFactor) {
@@ -95,39 +107,39 @@ function healthFactorBps(healthFactor) {
95
107
  return Number(healthFactor * PERCENTAGE_FACTOR / WAD);
96
108
  }
97
109
  /**
98
- * Leverage of an open position: `totalDebt / equity`, where equity is what is
99
- * left of the position's value once its debt is repaid.
100
- *
101
- * Returns `0` for a position that carries no debt and for one that is
102
- * underwater, where there is no equity to lever.
110
+ * Total-value leverage of an open position:
111
+ * `totalValue / (totalValue − totalDebt)`. `1` when unleveraged, `0` when
112
+ * underwater.
103
113
  *
104
- * @param totalDebt - Debt principal plus accrued interest and fees.
105
- * @param totalValue - Total value of the position, in the same token.
114
+ * @param totalValue - Total value of the position.
115
+ * @param totalDebt - Debt principal plus accrued interest and fees, same token.
106
116
  *
107
117
  * @example
108
118
  * ```ts
109
- * positionLeverage(800n, 1000n) // 4, i.e. 4x debt per unit of equity
119
+ * // totalValue: 100k, totalDebt: 80k → equity: 100k − 80k = 20k
120
+ * calcPositionLeverage(100_000n, 80_000n) // 100k / 20k = 5x
110
121
  * ```
111
122
  **/
112
- function positionLeverage(totalDebt, totalValue) {
123
+ function calcPositionLeverage(totalValue, totalDebt) {
113
124
  const equity = totalValue - totalDebt;
114
- if (equity <= 0n || totalDebt <= 0n) return 0;
115
- return Number(totalDebt) / Number(equity);
125
+ if (totalValue <= 0n || equity <= 0n) return 0;
126
+ if (totalDebt <= 0n) return 1;
127
+ return Number(totalValue) / Number(equity);
116
128
  }
117
129
  /**
118
- * Annual quota cost scaled to the debt a maximally leveraged position carries,
119
- * in basis points. Every unit of own capital carries `maxLeverage - 1` units of
120
- * debt, and the quota is paid on the whole quoted position.
130
+ * Annual quota cost on equity, in basis points:
131
+ * `quotaRate × (1 + feeInterest) × leverage`. Quota accrues on the whole
132
+ * quoted position, and the DAO takes `feeInterest` of it as with base interest.
121
133
  *
122
134
  * @example
123
135
  * ```ts
124
- * // 2.5% quota rate at 5x leverage
125
- * additionalBorrowApyBps(250, 5) // 1000, i.e. 10%
136
+ * // quotaRate: 200 bps = 2%, feeInterest: 2500 bps = 25%, leverage: 9.5x
137
+ * calcAdditionalBorrowApy(200, 2500, 9.5) // 2% × 1.25 × 9.5 = 2375 bps = 23.75%
126
138
  * ```
127
139
  **/
128
- function additionalBorrowApyBps(quotaRate, leverage) {
129
- if (!Number.isFinite(leverage)) return 0;
130
- return Math.round(quotaRate * Math.max(leverage - 1, 0));
140
+ function calcAdditionalBorrowApy(quotaRate, feeInterest, leverage) {
141
+ if (!Number.isFinite(leverage) || leverage <= 0) return 0;
142
+ return Math.round(quotaRate * (1 + feeInterest / FULL) * leverage);
131
143
  }
132
144
  /**
133
145
  * {@link PERCENTAGE_FACTOR} less a 0.1% safety buffer.
@@ -185,4 +197,4 @@ function optimalHFForPartialLiquidation(borrowRate) {
185
197
  return PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
186
198
  }
187
199
  //#endregion
188
- export { PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, healthFactorBps, maxLeverage, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, positionLeverage, rayToBps, usdToNumber, utilizationBps };
200
+ export { MAX_LEVERAGE_BUFFER_BPS, PARTIAL_LIQUIDATION_BUFFER_BPS, calcAdditionalBorrowApy, calcBorrowApy, calcMaxLeverage, calcPositionLeverage, calcUtilization, healthFactorBps, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, rayToBps, usdToNumber };
@@ -132,17 +132,24 @@ var PriceOracleBaseContract = class extends BaseContract {
132
132
  return amount * 10n ** BigInt(this.tokensMeta.decimals(to)) / price;
133
133
  }
134
134
  /**
135
- * {@inheritDoc IPriceOracleContract.safeUsdValue}
135
+ * {@inheritDoc IPriceOracleContract.safeConvertToUSD}
136
136
  **/
137
- safeUsdValue(token, amount) {
137
+ safeConvertToUSD(token, amount) {
138
138
  try {
139
- return usdToNumber(this.convertToUSD(token, amount));
139
+ return this.convertToUSD(token, amount);
140
140
  } catch (e) {
141
141
  this.logger?.debug(`cannot price ${this.labelAddress(token)}: ${e}`);
142
142
  return null;
143
143
  }
144
144
  }
145
145
  /**
146
+ * {@inheritDoc IPriceOracleContract.safeUsdValue}
147
+ **/
148
+ safeUsdValue(token, amount) {
149
+ const usd = this.safeConvertToUSD(token, amount);
150
+ return usd === null ? null : usdToNumber(usd);
151
+ }
152
+ /**
146
153
  * {@inheritDoc IPriceOracleContract.toAmount}
147
154
  **/
148
155
  toAmount = (token, value) => {
@@ -1,3 +1,4 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../utils/AddressMap.js";
3
4
  import { RAY } from "../../constants/math.js";
@@ -6,8 +7,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
6
7
  import "../../utils/index.js";
7
8
  import { BaseContract } from "../../base/BaseContract.js";
8
9
  import "../../base/index.js";
9
- import { iPausableAbi } from "../../../abi/iPausable.js";
10
- import { utilizationBps } from "../math.js";
10
+ import { calcUtilization } from "../math.js";
11
11
  //#region src/sdk/market/pool/PoolV310Contract.ts
12
12
  const abi = [...iPoolV310Abi, ...iPausableAbi];
13
13
  var PoolV310Contract = class extends BaseContract {
@@ -50,7 +50,7 @@ var PoolV310Contract = class extends BaseContract {
50
50
  * {@inheritDoc IPoolContract.utilization}
51
51
  */
52
52
  get utilization() {
53
- return utilizationBps(this.borrowed, this.expectedLiquidity);
53
+ return calcUtilization(this.borrowed, this.expectedLiquidity);
54
54
  }
55
55
  /**
56
56
  * {@inheritDoc IPoolContract.unwrappedUnderlying}
@@ -136,6 +136,20 @@ var PoolV310Contract = class extends BaseContract {
136
136
  ]
137
137
  });
138
138
  }
139
+ /**
140
+ * Burns as many of the owner's shares as it takes to send `assets` of the
141
+ * underlying to the receiver.
142
+ */
143
+ withdraw(assets, receiver, owner) {
144
+ return this.createRawTx({
145
+ functionName: "withdraw",
146
+ args: [
147
+ assets,
148
+ receiver,
149
+ owner
150
+ ]
151
+ });
152
+ }
139
153
  stringifyFunctionParams(params) {
140
154
  switch (params.functionName) {
141
155
  case "deposit": {
@@ -24,6 +24,11 @@ var RWARegistry = class extends SDKConstruct {
24
24
  #state;
25
25
  #factories = new AddressMap();
26
26
  /**
27
+ * Factories requested during attach; `undefined` when the registry was
28
+ * hydrated instead, in which case the request was never made on this instance.
29
+ **/
30
+ #requestedFactories;
31
+ /**
27
32
  * @internal
28
33
  *
29
34
  * Returns delegated multicalls for loading all RWA underlying tokens from the on-chain RWA compressor.
@@ -33,6 +38,7 @@ var RWARegistry = class extends SDKConstruct {
33
38
  * @param rwaFactories - RWA factory contracts to query.
34
39
  */
35
40
  getLoadMulticalls(configurators, rwaFactories = []) {
41
+ this.#requestedFactories = rwaFactories;
36
42
  if (!rwaFactories.length) return [];
37
43
  const [rwaCompressorAddress] = this.sdk.addressProvider.mustGetLatest(AP_RWA_COMPRESSOR, VERSION_RANGE_310);
38
44
  return [{
@@ -46,6 +52,22 @@ var RWARegistry = class extends SDKConstruct {
46
52
  }];
47
53
  }
48
54
  /**
55
+ * @internal
56
+ *
57
+ * Returns delegated multicalls that refresh the RWA state. Unlike the other
58
+ * warmed caches, RWA data carries values that change between blocks (e.g. the
59
+ * deposit allowance and claimable amount of an on-demand liquidity provider),
60
+ * so it is refreshed on every SDK sync.
61
+ *
62
+ * Factories are the ones requested during attach; after hydration the chain
63
+ * defaults are used, since the snapshot does not carry the requested list.
64
+ * An attach that explicitly requested no factories stays disabled.
65
+ **/
66
+ getSyncMulticalls() {
67
+ const factories = this.#requestedFactories ?? this.sdk.chain.rwaFactories;
68
+ return this.getLoadMulticalls([...this.sdk.marketRegister.marketFilter.configurators], factories);
69
+ }
70
+ /**
49
71
  * Fetches decoded investor data from the on-chain RWA compressor.
50
72
  *
51
73
  * Each factory produces its own investor data (e.g. registered tokens,
@@ -1,5 +1,5 @@
1
- import { ZapperContract } from "./ZapperContract.js";
2
1
  import { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
+ import { ZapperContract } from "./ZapperContract.js";
3
3
  //#region src/sdk/market/zapper/IETHZapperContract.ts
4
4
  const abi = iethZapperAbi;
5
5
  var IETHZapperContract = class extends ZapperContract {
@@ -1,6 +1,6 @@
1
+ import { iZapperAbi } from "../../../abi/iZapper.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
- import { iZapperAbi } from "../../../abi/iZapper.js";
4
4
  import { UnsupportedZapperFunctionError } from "./errors.js";
5
5
  //#region src/sdk/market/zapper/ZapperContract.ts
6
6
  /**
@@ -1,4 +1,3 @@
1
- import { PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, healthFactorBps, maxLeverage, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, positionLeverage, rayToBps, usdToNumber, utilizationBps } from "../market/math.js";
2
1
  import { MultichainOpportunitiesService } from "./MultichainOpportunitiesService.js";
3
2
  import { OpportunitiesService } from "./OpportunitiesService.js";
4
- export { MultichainOpportunitiesService, OpportunitiesService, PARTIAL_LIQUIDATION_BUFFER_BPS, additionalBorrowApyBps, borrowApyBps, healthFactorBps, maxLeverage, minSeizedAmount, optimalHFForPartialLiquidation, optimalRepaidAmount, positionLeverage, rayToBps, usdToNumber, utilizationBps };
3
+ export { MultichainOpportunitiesService, OpportunitiesService };
@@ -60,11 +60,7 @@ const attachOptionsSchema = z.object({
60
60
  /**
61
61
  * Options for Redstone price-feed updates.
62
62
  **/
63
- redstone: RedstoneOptions.optional(),
64
- /**
65
- * When `true`, automatically load zappers during attach.
66
- **/
67
- loadZappers: z.boolean().optional()
63
+ redstone: RedstoneOptions.optional()
68
64
  });
69
65
  //#endregion
70
66
  export { attachOptionsSchema, onchainSDKOptionsSchema };