@gearbox-protocol/sdk 17.0.0-next.4 → 17.0.0

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 (364) hide show
  1. package/dist/cjs/dev/abi.js +14 -15
  2. package/dist/cjs/dev/claimFromFaucet.js +4 -8
  3. package/dist/cjs/dev/createAnvilClient.js +35 -17
  4. package/dist/cjs/dev/index.js +7 -2
  5. package/dist/cjs/dev/kycUtils.js +66 -58
  6. package/dist/cjs/dev/midasUtils.js +113 -16
  7. package/dist/cjs/dev/securitizeUtils.js +82 -42
  8. package/dist/cjs/dev/withdrawalUtils.js +3 -6
  9. package/dist/cjs/model/errors/index.js +2 -0
  10. package/dist/cjs/model/errors/operation-errors.js +19 -1
  11. package/dist/cjs/model/index.js +4 -2
  12. package/dist/cjs/model/rwa.js +4 -4
  13. package/dist/cjs/model/rwa.schema.js +4 -4
  14. package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
  15. package/dist/cjs/onchain/OnchainSDK.js +3 -3
  16. package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +2 -17
  17. package/dist/cjs/onchain/accounts/intents/borrow.js +140 -0
  18. package/dist/cjs/onchain/accounts/intents/collateral-valuation.js +41 -0
  19. package/dist/cjs/onchain/accounts/intents/guards.js +15 -3
  20. package/dist/cjs/onchain/accounts/intents/index.js +107 -20
  21. package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -12
  22. package/dist/cjs/onchain/accounts/intents/maxBorrow.js +89 -0
  23. package/dist/cjs/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  24. package/dist/cjs/onchain/accounts/intents/open-strategy.js +8 -46
  25. package/dist/cjs/onchain/accounts/intents/operations.js +0 -1
  26. package/dist/cjs/onchain/accounts/intents/realize.js +61 -4
  27. package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
  28. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  29. package/dist/cjs/onchain/accounts/intents/utils/common.js +19 -0
  30. package/dist/cjs/onchain/accounts/intents/utils/credit-account-slice.js +21 -0
  31. package/dist/cjs/onchain/accounts/intents/utils/index.js +2 -0
  32. package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +12 -9
  33. package/dist/cjs/onchain/accounts/intents/utils/router-path.js +4 -5
  34. package/dist/cjs/onchain/accounts/intents/withdraw-limits.js +97 -0
  35. package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  36. package/dist/cjs/onchain/constants/address-provider.js +0 -2
  37. package/dist/cjs/onchain/constants/index.js +0 -1
  38. package/dist/cjs/onchain/core/createAddressProvider.js +2 -5
  39. package/dist/cjs/onchain/index.js +60 -43
  40. package/dist/cjs/onchain/market/adapters/abi/conctructorAbi.js +2 -2
  41. package/dist/cjs/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
  42. package/dist/cjs/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +49 -5
  43. package/dist/cjs/onchain/market/credit/CreditSuite.js +26 -9
  44. package/dist/cjs/onchain/market/index.js +50 -38
  45. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +3 -3
  46. package/dist/cjs/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  47. package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +127 -0
  48. package/dist/cjs/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  49. package/dist/cjs/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  50. package/dist/cjs/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  51. package/dist/cjs/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  52. package/dist/cjs/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  53. package/dist/cjs/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  54. package/dist/cjs/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  55. package/dist/cjs/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  56. package/dist/cjs/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  57. package/dist/cjs/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  58. package/dist/cjs/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  59. package/dist/cjs/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  60. package/dist/cjs/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  61. package/dist/cjs/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  62. package/dist/cjs/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  63. package/dist/cjs/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  64. package/dist/cjs/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  65. package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +35 -0
  66. package/dist/cjs/onchain/market/pricefeeds/index.js +51 -39
  67. package/dist/cjs/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +189 -0
  68. package/dist/cjs/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  69. package/dist/cjs/onchain/market/pricefeeds/updates/index.js +8 -0
  70. package/dist/cjs/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  71. package/dist/cjs/onchain/market/pricefeeds/updates/updatableDependencies.js +14 -0
  72. package/dist/cjs/onchain/market/rwa/RWARegistry.js +4 -7
  73. package/dist/cjs/onchain/market/rwa/index.js +1 -0
  74. package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  75. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +56 -12
  76. package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  77. package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  78. package/dist/cjs/onchain/opportunities/OpportunitiesService.js +16 -4
  79. package/dist/cjs/onchain/positions/calcHealthFactor.js +3 -3
  80. package/dist/cjs/onchain/preview/index.js +2 -0
  81. package/dist/cjs/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  82. package/dist/cjs/onchain/preview/preview/index.js +2 -0
  83. package/dist/cjs/onchain/preview/preview/midasGreenlistsAccount.js +17 -0
  84. package/dist/cjs/onchain/preview/preview/previewOpenStrategyPosition.js +13 -16
  85. package/dist/cjs/onchain/preview/preview/previewOperation.js +19 -11
  86. package/dist/cjs/onchain/preview/preview/replayMulticall.js +4 -3
  87. package/dist/cjs/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  88. package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +11 -9
  89. package/dist/cjs/onchain/validation/bundles/{checkDraw.js → checkIncreaseDebt.js} +10 -10
  90. package/dist/cjs/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
  91. package/dist/cjs/onchain/validation/bundles/checkMidasAccountGreenlist.js +44 -0
  92. package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  93. package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +18 -8
  94. package/dist/cjs/onchain/validation/bundles/index.js +6 -4
  95. package/dist/cjs/onchain/validation/checkOperation.js +0 -1
  96. package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +1 -1
  97. package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  98. package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
  99. package/dist/cjs/onchain/validation/checks/index.js +2 -0
  100. package/dist/cjs/onchain/validation/index.js +8 -4
  101. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
  102. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
  103. package/dist/cjs/sdk/execute/ExecuteApi.js +67 -7
  104. package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  105. package/dist/cjs/sdk/prepare/PrepareApi.js +89 -14
  106. package/dist/esm/dev/abi.js +14 -15
  107. package/dist/esm/dev/claimFromFaucet.js +4 -8
  108. package/dist/esm/dev/createAnvilClient.js +36 -19
  109. package/dist/esm/dev/index.js +4 -4
  110. package/dist/esm/dev/kycUtils.js +66 -59
  111. package/dist/esm/dev/midasUtils.js +112 -18
  112. package/dist/esm/dev/securitizeUtils.js +84 -44
  113. package/dist/esm/dev/withdrawalUtils.js +3 -6
  114. package/dist/esm/model/errors/index.js +2 -2
  115. package/dist/esm/model/errors/operation-errors.js +18 -2
  116. package/dist/esm/model/index.js +4 -4
  117. package/dist/esm/model/rwa.js +4 -4
  118. package/dist/esm/model/rwa.schema.js +5 -5
  119. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
  120. package/dist/esm/onchain/OnchainSDK.js +3 -3
  121. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -17
  122. package/dist/esm/onchain/accounts/intents/borrow.js +138 -0
  123. package/dist/esm/onchain/accounts/intents/collateral-valuation.js +40 -0
  124. package/dist/esm/onchain/accounts/intents/guards.js +15 -3
  125. package/dist/esm/onchain/accounts/intents/index.js +107 -20
  126. package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
  127. package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
  128. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  129. package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -46
  130. package/dist/esm/onchain/accounts/intents/operations.js +0 -1
  131. package/dist/esm/onchain/accounts/intents/realize.js +61 -4
  132. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  133. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  134. package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
  135. package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
  136. package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
  137. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +12 -9
  138. package/dist/esm/onchain/accounts/intents/utils/router-path.js +4 -5
  139. package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
  140. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  141. package/dist/esm/onchain/constants/address-provider.js +1 -2
  142. package/dist/esm/onchain/constants/index.js +2 -2
  143. package/dist/esm/onchain/core/createAddressProvider.js +2 -5
  144. package/dist/esm/onchain/index.js +32 -24
  145. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +2 -2
  146. package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
  147. package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +50 -6
  148. package/dist/esm/onchain/market/credit/CreditSuite.js +26 -9
  149. package/dist/esm/onchain/market/index.js +26 -21
  150. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  151. package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  152. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
  153. package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  154. package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  155. package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  156. package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  157. package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  158. package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  159. package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  160. package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  161. package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  162. package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  163. package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  164. package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  165. package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  166. package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  167. package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  168. package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  169. package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  170. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
  171. package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
  172. package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
  173. package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  174. package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
  175. package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  176. package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
  177. package/dist/esm/onchain/market/rwa/RWARegistry.js +4 -8
  178. package/dist/esm/onchain/market/rwa/index.js +2 -2
  179. package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  180. package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
  181. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  182. package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  183. package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
  184. package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
  185. package/dist/esm/onchain/preview/index.js +2 -1
  186. package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  187. package/dist/esm/onchain/preview/preview/index.js +2 -1
  188. package/dist/esm/onchain/preview/preview/midasGreenlistsAccount.js +16 -0
  189. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +14 -17
  190. package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
  191. package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
  192. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  193. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +11 -9
  194. package/dist/esm/onchain/validation/bundles/checkIncreaseDebt.js +27 -0
  195. package/dist/esm/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
  196. package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +43 -0
  197. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  198. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +18 -8
  199. package/dist/esm/onchain/validation/bundles/index.js +4 -3
  200. package/dist/esm/onchain/validation/checkOperation.js +0 -1
  201. package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +1 -1
  202. package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  203. package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
  204. package/dist/esm/onchain/validation/checks/index.js +2 -1
  205. package/dist/esm/onchain/validation/index.js +5 -3
  206. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  207. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
  208. package/dist/esm/sdk/execute/ExecuteApi.js +67 -7
  209. package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  210. package/dist/esm/sdk/prepare/PrepareApi.js +94 -19
  211. package/dist/types/dev/abi.d.ts +13 -15
  212. package/dist/types/dev/claimFromFaucet.d.ts +0 -1
  213. package/dist/types/dev/createAnvilClient.d.ts +10 -3
  214. package/dist/types/dev/index.d.ts +4 -4
  215. package/dist/types/dev/kycUtils.d.ts +15 -24
  216. package/dist/types/dev/midasUtils.d.ts +35 -4
  217. package/dist/types/dev/securitizeUtils.d.ts +3 -9
  218. package/dist/types/model/errors/index.d.ts +2 -2
  219. package/dist/types/model/errors/operation-errors.d.ts +62 -7
  220. package/dist/types/model/index.d.ts +5 -5
  221. package/dist/types/model/opportunities.d.ts +6 -7
  222. package/dist/types/model/previews.d.ts +25 -19
  223. package/dist/types/model/rwa.d.ts +47 -27
  224. package/dist/types/model/rwa.schema.d.ts +3 -3
  225. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
  226. package/dist/types/offchain/opportunities/types.d.ts +1 -4
  227. package/dist/types/onchain/OnchainSDK.d.ts +2 -2
  228. package/dist/types/onchain/accounts/index.d.ts +5 -4
  229. package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
  230. package/dist/types/onchain/accounts/intents/collateral-valuation.d.ts +42 -0
  231. package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
  232. package/dist/types/onchain/accounts/intents/index.d.ts +103 -15
  233. package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
  234. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
  235. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
  236. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
  237. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  238. package/dist/types/onchain/accounts/intents/types.d.ts +51 -6
  239. package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
  240. package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
  241. package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
  242. package/dist/types/onchain/accounts/intents/utils/price-impact.d.ts +4 -1
  243. package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +2 -5
  244. package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
  245. package/dist/types/onchain/accounts/types.d.ts +4 -2
  246. package/dist/types/onchain/constants/address-provider.d.ts +1 -2
  247. package/dist/types/onchain/constants/index.d.ts +2 -2
  248. package/dist/types/onchain/index.d.ts +40 -31
  249. package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +6 -0
  250. package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +20 -4
  251. package/dist/types/onchain/market/adapters/types.d.ts +8 -0
  252. package/dist/types/onchain/market/credit/CreditSuite.d.ts +13 -3
  253. package/dist/types/onchain/market/index.d.ts +29 -24
  254. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
  255. package/dist/types/onchain/market/oracle/types.d.ts +2 -1
  256. package/dist/types/onchain/market/pool/types.d.ts +1 -1
  257. package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
  258. package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
  259. package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
  260. package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
  261. package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
  262. package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
  263. package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
  264. package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
  265. package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
  266. package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
  267. package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
  268. package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
  269. package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
  270. package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
  271. package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
  272. package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
  273. package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
  274. package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
  275. package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
  276. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
  277. package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
  278. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
  279. package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
  280. package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
  281. package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
  282. package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
  283. package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
  284. package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
  285. package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
  286. package/dist/types/onchain/market/rwa/RWARegistry.d.ts +2 -1
  287. package/dist/types/onchain/market/rwa/index.d.ts +3 -3
  288. package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
  289. package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
  290. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
  291. package/dist/types/onchain/market/rwa/types.d.ts +39 -37
  292. package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
  293. package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
  294. package/dist/types/onchain/opportunities/types.d.ts +6 -1
  295. package/dist/types/onchain/preview/index.d.ts +2 -1
  296. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  297. package/dist/types/onchain/preview/preview/midasGreenlistsAccount.d.ts +13 -0
  298. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
  299. package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
  300. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +5 -4
  301. package/dist/types/onchain/validation/bundles/{checkDraw.d.ts → checkIncreaseDebt.d.ts} +7 -7
  302. package/dist/types/onchain/validation/bundles/{checkQuotasAsked.d.ts → checkIncreaseQuota.d.ts} +3 -3
  303. package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +22 -0
  304. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
  305. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +9 -7
  306. package/dist/types/onchain/validation/bundles/index.d.ts +5 -4
  307. package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +1 -1
  308. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +2 -2
  309. package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +1 -1
  310. package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
  311. package/dist/types/onchain/validation/checks/index.d.ts +2 -1
  312. package/dist/types/onchain/validation/index.d.ts +6 -4
  313. package/dist/types/onchain/validation/raise.d.ts +2 -2
  314. package/dist/types/sdk/execute/index.d.ts +2 -2
  315. package/dist/types/sdk/execute/types.d.ts +48 -6
  316. package/dist/types/sdk/index.d.ts +5 -4
  317. package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
  318. package/dist/types/sdk/opportunities/types.d.ts +9 -3
  319. package/dist/types/sdk/prepare/PrepareApi.d.ts +16 -4
  320. package/dist/types/sdk/prepare/index.d.ts +4 -3
  321. package/dist/types/sdk/prepare/types.d.ts +200 -66
  322. package/package.json +1 -1
  323. package/dist/cjs/onchain/accounts/utils/midasUtils.js +0 -70
  324. package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
  325. package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -61
  326. package/dist/cjs/plugins/degen-distributors/index.js +0 -4
  327. package/dist/cjs/plugins/degen-distributors/package.json +0 -1
  328. package/dist/cjs/plugins/degen-distributors/types.js +0 -1
  329. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -114
  330. package/dist/cjs/plugins/delayed-withdrawal/index.js +0 -4
  331. package/dist/cjs/plugins/delayed-withdrawal/package.json +0 -1
  332. package/dist/cjs/plugins/delayed-withdrawal/types.js +0 -1
  333. package/dist/esm/onchain/accounts/utils/midasUtils.js +0 -69
  334. package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
  335. package/dist/esm/onchain/validation/bundles/checkDraw.js +0 -27
  336. package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -60
  337. package/dist/esm/plugins/degen-distributors/index.js +0 -3
  338. package/dist/esm/plugins/degen-distributors/package.json +0 -1
  339. package/dist/esm/plugins/degen-distributors/types.js +0 -1
  340. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -113
  341. package/dist/esm/plugins/delayed-withdrawal/index.js +0 -3
  342. package/dist/esm/plugins/delayed-withdrawal/package.json +0 -1
  343. package/dist/esm/plugins/delayed-withdrawal/types.js +0 -1
  344. package/dist/types/onchain/accounts/utils/midasUtils.d.ts +0 -38
  345. package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
  346. package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
  347. package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
  348. package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
  349. package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
  350. package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
  351. package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
  352. package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
  353. package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
  354. package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
  355. package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
  356. package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
  357. package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
  358. package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
  359. package/dist/types/plugins/degen-distributors/DegenDistributorsPlugin.d.ts +0 -25
  360. package/dist/types/plugins/degen-distributors/index.d.ts +0 -3
  361. package/dist/types/plugins/degen-distributors/types.d.ts +0 -8
  362. package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +0 -25
  363. package/dist/types/plugins/delayed-withdrawal/index.d.ts +0 -3
  364. package/dist/types/plugins/delayed-withdrawal/types.d.ts +0 -10
@@ -0,0 +1,141 @@
1
+ import { TokenAmount } from "../../../model/primitives.js";
2
+ import "../../../model/index.js";
3
+ import { Asset } from "../../base/types.js";
4
+ import { MultiCall } from "../../types/transactions.js";
5
+ import { OnchainSDK } from "../../OnchainSDK.js";
6
+ import { CreditAccountSlice, OperationState } from "./types.js";
7
+ import "../../index.js";
8
+ import { Address } from "viem";
9
+ //#region src/onchain/accounts/intents/borrow.d.ts
10
+ /**
11
+ * Taking a loan against collateral, in one transaction that opens the account.
12
+ *
13
+ * The plainest thing a credit account can do, and the one shape of it the
14
+ * leveraged flows cannot express: the borrowed funds do not stay on the
15
+ * account to be traded, they go to the wallet. What is left behind is the
16
+ * collateral and the debt it backs.
17
+ */
18
+ interface BorrowProps {
19
+ sdk: OnchainSDK;
20
+ /** Credit manager to open the account in. */
21
+ creditManager: Address;
22
+ /** Token the wallet puts up, in the manager's collateral list. */
23
+ collateralToken: Address;
24
+ /** Amount of {@link collateralToken}, in its own units. */
25
+ collateralAmount: bigint;
26
+ /**
27
+ * Token the loan is paid out in. The market underlying needs no trade;
28
+ * anything else is bought with the borrowed underlying on the way out.
29
+ *
30
+ * On an RWA market the underlying is a compliance wrapper that cannot leave
31
+ * the account, so the payout there is the asset behind it — USDC rather than
32
+ * dcUSDC — and the wrapper itself is refused.
33
+ */
34
+ borrowToken: Address;
35
+ /** Amount of {@link borrowToken} the wallet asks for, in its own units. */
36
+ borrowAmount: bigint;
37
+ /** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
38
+ slippage: number | undefined;
39
+ /** Extra quota headroom in PERCENTAGE_FORMAT. */
40
+ quotaReserve: number | undefined;
41
+ /**
42
+ * Existing credit account to draw the loan on, instead of opening one.
43
+ *
44
+ * Must carry no debt and no quotas, as a reused opening must. Borrowing on
45
+ * an account that already owes is what the `ADJUST_LEVERAGE` intent is for.
46
+ **/
47
+ creditAccount?: CreditAccountSlice;
48
+ }
49
+ /**
50
+ * Where a borrow leaves the wallet and the account it opens.
51
+ *
52
+ * A whole {@link OperationState}, holdings included: unlike an opening, a
53
+ * borrow has no second branch of balances to choose between — the collateral
54
+ * is the only thing left on the account and its amount is known exactly.
55
+ * Slippage lands on the payout instead, which is why that one is reported
56
+ * twice.
57
+ *
58
+ * Being that state rather than merely resembling it is what lets a borrow
59
+ * result go straight to `checkSimulation`, which weighs whatever the engine
60
+ * projected: the market, the debt, the quotas and the two factors, all of
61
+ * which a borrow reports where an operation on an existing account does.
62
+ */
63
+ interface BorrowState extends OperationState {
64
+ /** What the wallet puts up, as it will sit on the account. */
65
+ collateral: TokenAmount;
66
+ /**
67
+ * What the wallet is expected to receive, in the token it asked for. Equal
68
+ * to the debt when that token is the market underlying, and to the debt
69
+ * rescaled where an RWA payout unwraps it one for one; in neither case is
70
+ * anything traded.
71
+ */
72
+ borrowed: TokenAmount;
73
+ /**
74
+ * The floor under {@link borrowed} once slippage is allowed for — what the
75
+ * transaction is signed against. Equal to `borrowed` when nothing is traded.
76
+ */
77
+ minBorrowed: TokenAmount;
78
+ /**
79
+ * Router slippage the payout leg was quoted at, in PERCENTAGE_FORMAT
80
+ * (100% = 10_000). The SDK's own default where the caller named none.
81
+ */
82
+ slippage: number;
83
+ /**
84
+ * Quota to buy for the collateral; feeds `openCA.averageQuota` and
85
+ * `openCA.minQuota` alike, both branches being the same here.
86
+ *
87
+ * Transport for the transaction rather than something to display, like
88
+ * {@link calls} below.
89
+ */
90
+ quotaIncrease: Asset[];
91
+ /**
92
+ * The leg that turns the borrowed underlying into the payout: a router path
93
+ * where it is bought, the vault redemption where an RWA market unwraps it,
94
+ * empty where the payout is the underlying itself. Feeds `openCA.calls`,
95
+ * which places it before the withdrawal.
96
+ */
97
+ calls: MultiCall[];
98
+ /**
99
+ * The account this loan was simulated against and must be executed on, when
100
+ * it reuses one; `undefined` for a borrow that opens its own.
101
+ *
102
+ * Carried here rather than asked of the caller again at `buildTx`, so the
103
+ * transaction cannot be built against an account the numbers were not
104
+ * computed for.
105
+ **/
106
+ creditAccount?: Address;
107
+ }
108
+ /**
109
+ * Builds the state a borrow would leave behind.
110
+ *
111
+ * The debt is named rather than derived: a borrow asks for an amount, where an
112
+ * opening asks for a leverage and lets the collateral decide. Everything the
113
+ * loan pays out leaves the account, so the collateral alone backs it — which
114
+ * is what makes the health factor here a straight function of the two amounts.
115
+ *
116
+ * Produces no operation list, as opening never does: the caller hands the
117
+ * numbers and the calls to `sdk.accounts.openCA`, with `withdrawToken` set to
118
+ * the payout.
119
+ */
120
+ declare function buildBorrowState(props: BorrowProps): Promise<BorrowState>;
121
+ /** Inputs of {@link borrowCollateralQuota}. */
122
+ interface BorrowCollateralQuotaProps {
123
+ sdk: OnchainSDK;
124
+ creditManager: Address;
125
+ /** Collateral the fresh account will hold. */
126
+ assets: Asset[];
127
+ /** Extra quota headroom in PERCENTAGE_FORMAT. */
128
+ quotaReserve: number | undefined;
129
+ }
130
+ /**
131
+ * Quota a borrow buys for its collateral on an account that holds none yet.
132
+ *
133
+ * Shared with `maxBorrow`, because a quota short of the collateral's weighted
134
+ * value is what caps the loan: the two have to read the same number or the
135
+ * ceiling one offers is one the other refuses.
136
+ *
137
+ * @param props - {@link BorrowCollateralQuotaProps}
138
+ **/
139
+ declare function borrowCollateralQuota({ sdk, creditManager, assets, quotaReserve }: BorrowCollateralQuotaProps): Asset[];
140
+ //#endregion
141
+ export { BorrowCollateralQuotaProps, BorrowProps, BorrowState, borrowCollateralQuota, buildBorrowState };
@@ -0,0 +1,42 @@
1
+ import { OnchainSDK } from "../../OnchainSDK.js";
2
+ import { CreditAccountSlice } from "./types.js";
3
+ import "../../index.js";
4
+ import { Address } from "viem";
5
+ //#region src/onchain/accounts/intents/collateral-valuation.d.ts
6
+ /** One balance on the account, as the slice carries it. */
7
+ type Holding = CreditAccountSlice["tokens"][number];
8
+ /**
9
+ * The collateral check's own valuation of an account, as a handful of lookups.
10
+ *
11
+ * Shared by everything that solves that check for an amount, so the rules it
12
+ * encodes are written once: a holding backed by a quota counts the lesser of the
13
+ * quota and its threshold-weighted value, an unquoted one its weighted value
14
+ * alone, and dust or a disabled balance nothing at all. Collateral is valued at
15
+ * the protocol safe price — `min` of the two feeds, 0 where there is no reserve
16
+ * — the way the facade values a call that hands funds over; the underlying is
17
+ * exempt and stays on the main feed, as `CreditManagerV3._safeConvertToUSD`
18
+ * does.
19
+ *
20
+ * Every figure is carried in USD × `PERCENTAGE_FACTOR`, the units the check
21
+ * compares in, so a threshold never has to be divided back out.
22
+ */
23
+ interface CollateralValuation {
24
+ /** Market underlying, the one token safe pricing does not touch. */
25
+ underlying: Address;
26
+ /** Whether the holding is weighed at all. */
27
+ counts(holding: Holding): boolean;
28
+ /** What the holding backs, in USD × `PERCENTAGE_FACTOR`. */
29
+ weigh(holding: Holding): bigint;
30
+ /** What the holding's quota backs, in the same units; 0 on a closed market. */
31
+ quotaValue(holding: Holding): bigint;
32
+ /** USD at the main feed; `undefined` when the token has no price at all. */
33
+ mainUsd(token: Address, amount: bigint): bigint | undefined;
34
+ /** USD the check counts the holding at, before its threshold. */
35
+ checkedUsd(holding: Holding): bigint;
36
+ /** Liquidation threshold in basis points; 0 for a token the manager refuses. */
37
+ lt(token: Address): bigint;
38
+ }
39
+ /** {@inheritDoc CollateralValuation} */
40
+ declare function collateralValuation(creditAccount: CreditAccountSlice, sdk: OnchainSDK): CollateralValuation;
41
+ //#endregion
42
+ export { CollateralValuation, Holding, collateralValuation };
@@ -1,3 +1,5 @@
1
+ import { Bps, TokenAmount } from "../../../model/primitives.js";
2
+ import "../../../model/index.js";
1
3
  import { Asset } from "../../base/types.js";
2
4
  import { MarketSuite } from "../../market/MarketSuite.js";
3
5
  import { CreditSuite } from "../../market/credit/CreditSuite.js";
@@ -74,11 +76,25 @@ declare function assertGrowthAllowed(args: {
74
76
  * whose reserve feed the SDK cannot read keeps its main price, so a plan can
75
77
  * still be refused on-chain after passing here.
76
78
  */
77
- declare function assertCollateralised(healthFactorBps: number, safePrices: boolean): void;
79
+ declare function assertCollateralised(healthFactorBps: number, safePrices: boolean, atSafePrices?: SafePriceEvidence): void;
80
+ /**
81
+ * What tells a reserve feed marking collateral down apart from a position that
82
+ * is simply too small, read only when the collateral check has already failed.
83
+ *
84
+ * A thunk because both halves are expensive: the account has to be valued a
85
+ * second time at the main feed, and the check solved for the amount that would
86
+ * still clear it.
87
+ */
88
+ type SafePriceEvidence = () => {
89
+ /** The plan's end state weighed at the main feed. */
90
+ atMainPrices: Bps;
91
+ /** What the account can still take out, in the market's underlying. */
92
+ withdrawable: TokenAmount;
93
+ };
78
94
  /**
79
95
  * A quota can only be raised as far as the market still has room for: past the
80
96
  * token's limit the keeper takes nothing more, whoever is asking.
81
97
  */
82
98
  declare function assertQuotaAvailable(sdk: OnchainSDK, market: MarketSuite, increases: readonly Asset[]): void;
83
99
  //#endregion
84
- export { assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaAvailable };
100
+ export { SafePriceEvidence, assertCanBorrow, assertCollateralised, assertGrowthAllowed, assertMarketOperable, assertQuotaAvailable };
@@ -2,9 +2,11 @@ import { SDKError } from "../../../model/result.js";
2
2
  import "../../../model/index.js";
3
3
  import { SDKConstruct } from "../../base/SDKConstruct.js";
4
4
  import { IntentValidationError } from "../../validation/raise.js";
5
- import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
6
5
  import { AccountCalculatorOperation } from "./operations.js";
7
- import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./types.js";
6
+ import { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, ExecutionCost, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent } from "./types.js";
7
+ import { BorrowProps, BorrowState } from "./borrow.js";
8
+ import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
9
+ import { MaxBorrowProps } from "./maxBorrow.js";
8
10
  import { OpenStrategyProps, OpenStrategyState } from "./open-strategy.js";
9
11
  import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
10
12
  import { isPhantomToken } from "./utils/pick-token.js";
@@ -21,6 +23,22 @@ type OpenStrategyPreviewResult = {
21
23
  ok: true;
22
24
  state: OpenStrategyState;
23
25
  } | SDKError<IntentValidationError>;
26
+ /**
27
+ * Borrow preview outcome, shaped like {@link OpenStrategyPreviewResult}: both
28
+ * open an account, so neither has an operation chain to report.
29
+ */
30
+ type BorrowPreviewResult = {
31
+ ok: true;
32
+ state: BorrowState;
33
+ } | SDKError<IntentValidationError>;
34
+ /**
35
+ * Empty-account preview outcome: the thinnest of the three, since an account
36
+ * that holds nothing has no state to project — only the market's own refusal
37
+ * to open one at all.
38
+ */
39
+ type EmptyAccountPreviewResult = {
40
+ ok: true;
41
+ } | SDKError<IntentValidationError>;
24
42
  /** An intent plus everything previewing it needs. */
25
43
  type StartProps = StartIntentProps & {
26
44
  intent: StartIntent;
@@ -45,21 +63,30 @@ declare class CreditAccountOperationsService extends SDKConstruct {
45
63
  startIntent(props: StartProps): Promise<IntentPreviewResult>;
46
64
  /**
47
65
  * Both ends of what a `WITHDRAW` can take out, in underlying: the largest
48
- * partial withdrawal that keeps leverage and stays inside the facade's
49
- * `debtLimits`, and the net value an exit hands over. They are reported together
50
- * because a withdraw form needs both — the range it may offer, and the one
51
- * amount past it that is allowed — and because the distance between them is
52
- * the account's own, not a constant a caller could assume.
66
+ * partial withdrawal that keeps leverage, and the net value an exit hands
67
+ * over. They are reported together because a withdraw form needs both — the
68
+ * range it may offer, and the one amount past it that is allowed — and
69
+ * because the distance between them is the account's own, not a constant a
70
+ * caller could assume.
53
71
  *
54
- * Takes no target health factor, unlike {@link maxWithdrawCollateral}: a
55
- * proportional withdrawal leaves the factor where it found it, and the
56
- * facade's `minDebt` is what bounds it.
72
+ * Two rules bound the partial end and both are reported: the facade's
73
+ * `debtLimits` as `partial`, and the safe-price collateral check on top of
74
+ * it as `safePartial`. The second is the one to offer — see
75
+ * {@link WithdrawCeilings}.
57
76
  *
58
- * @param props - Account slice and the SDK holding its market
59
- * @returns The two ceilings, see {@link WithdrawCeilings} for the gap between
60
- * them
77
+ * Takes no target health factor, unlike {@link maxWithdrawCollateral}. A
78
+ * proportional withdrawal leaves the factor where it found it, so there is
79
+ * no room to choose: what these answer to is the facade's own threshold,
80
+ * which is also what {@link startIntent} refuses against.
81
+ *
82
+ * @param props - Account slice, the SDK holding its market, and optionally
83
+ * the collateral the withdrawal would be funded from
84
+ * @returns The three limits, see {@link WithdrawCeilings} for the gap
85
+ * between them
61
86
  */
62
- maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk">): WithdrawCeilings;
87
+ maxWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk"> & {
88
+ sourceToken?: Address;
89
+ }): WithdrawCeilings;
63
90
  /**
64
91
  * Debt a `REPAY` would have to cover to settle the account, in underlying
65
92
  * units: principal plus the interest and fees accrued as of the read.
@@ -110,6 +137,30 @@ declare class CreditAccountOperationsService extends SDKConstruct {
110
137
  token: Address;
111
138
  targetHF?: bigint;
112
139
  }): bigint;
140
+ /**
141
+ * Largest loan a given collateral supports at `targetHF`, in the payout
142
+ * token's units — the ceiling a borrow form should offer.
143
+ *
144
+ * Reads no account, like {@link leverageBand}: the borrow opens one. The
145
+ * collateral is valued the way the transaction will be judged, at safe
146
+ * prices and under the quota the borrow buys, and the answer is then held to
147
+ * what the market will lend.
148
+ *
149
+ * A ceiling, not a verdict: the facade's `minDebt` is a floor and is not
150
+ * applied here, so collateral too small for this market still answers with
151
+ * what it carries and {@link borrowIntent} is the one that refuses the loan.
152
+ *
153
+ * The default is {@link MIN_HF_LIMITED}, the threshold a form holds an
154
+ * account to.
155
+ *
156
+ * @param props - The manager, the SDK holding its market, the collateral put
157
+ * up, the token to be paid in, and optionally the health factor to land at
158
+ * @returns Amount in the payout token's units; `0n` where no loan of this
159
+ * shape can be funded at any size
160
+ */
161
+ maxBorrow(props: Omit<MaxBorrowProps, "targetHF"> & {
162
+ targetHF?: bigint;
163
+ }): bigint;
113
164
  /**
114
165
  * Previews the same operation when its source only redeems through its
115
166
  * issuer: a Securitize dsToken, a Mellow share.
@@ -177,6 +228,21 @@ declare class CreditAccountOperationsService extends SDKConstruct {
177
228
  * beside it, so both halves of an operation are consumed the same way
178
229
  */
179
230
  finishIntent(props: FinishIntentProps): Promise<FinishIntentResult>;
231
+ /**
232
+ * Previews opening an account that holds nothing.
233
+ *
234
+ * Nothing is put up, drawn or routed, so there is no state to build and no
235
+ * guard to run beyond the market's own: a paused or expired facade takes no
236
+ * multicall, and an opening is a multicall like any other. Answers the same
237
+ * envelope its two neighbours do so a caller branches on `ok` throughout.
238
+ *
239
+ * @param props - The SDK holding the market, and the manager to open in
240
+ * @returns `{ ok: true }`, or `{ ok: false, error }` when the market takes
241
+ * no transaction right now
242
+ */
243
+ openEmptyAccountIntent(props: Pick<StartIntentProps, "sdk"> & {
244
+ creditManager: Address;
245
+ }): Promise<EmptyAccountPreviewResult>;
180
246
  /**
181
247
  * Previews opening a brand-new leveraged position.
182
248
  *
@@ -190,6 +256,28 @@ declare class CreditAccountOperationsService extends SDKConstruct {
190
256
  * leverage or the resulting debt is not viable
191
257
  */
192
258
  openStrategyIntent(props: OpenStrategyProps): Promise<OpenStrategyPreviewResult>;
259
+ /**
260
+ * Previews taking a loan against collateral, on an account this same
261
+ * transaction opens.
262
+ *
263
+ * Sits beside {@link openStrategyIntent} rather than under
264
+ * {@link startIntent} for the same reason: there is no account yet, and the
265
+ * output feeds `sdk.accounts.openCA`. What sets it apart from an opening is
266
+ * where the loan goes — out to the wallet rather than into a position — so
267
+ * the debt is named outright instead of following from a leverage, and the
268
+ * collateral is the only thing the account is left holding.
269
+ *
270
+ * `creditAccount` draws the loan on one the wallet already holds instead of
271
+ * opening another, as an opening takes one.
272
+ *
273
+ * @param props - Credit manager, the collateral the wallet puts up and the
274
+ * payout it asks for
275
+ * @returns Debt, the payout's two branches and the projection the account
276
+ * lands in, or `{ ok: false, error }` when the loan is not viable — a debt
277
+ * outside the facade's limits, collateral that cannot carry it, a payout the
278
+ * router has no path to
279
+ */
280
+ borrowIntent(props: BorrowProps): Promise<BorrowPreviewResult>;
193
281
  }
194
282
  //#endregion
195
- export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, type ClaimRemainder, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type FinishIntentResult, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteErrors, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
283
+ export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, BorrowPreviewResult, type BorrowProps, type BorrowState, type ClaimRemainder, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EmptyAccountPreviewResult, type ExecutionCost, type FinishIntentProps, type FinishIntentResult, type InstantRoute, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, OpenStrategyPreviewResult, type OpenStrategyProps, type OpenStrategyState, type OperationState, type PathLossRate, type RepayStrategyIntent, type ResumableIntent, type RouteErrors, type StartIntent, type WithdrawAssetIntent, type WithdrawCeilings, type WithdrawStrategyIntent, fetchCreditAccountSlice, isPhantomToken, toCreditAccountSlice };
@@ -0,0 +1,54 @@
1
+ import { OnchainSDK } from "../../OnchainSDK.js";
2
+ import "../../index.js";
3
+ import { Address } from "viem";
4
+ //#region src/onchain/accounts/intents/maxBorrow.d.ts
5
+ interface MaxBorrowProps {
6
+ sdk: OnchainSDK;
7
+ /** Credit manager the loan would be taken in. */
8
+ creditManager: Address;
9
+ /** Token the wallet puts up, in the manager's collateral list. */
10
+ collateralToken: Address;
11
+ /** Amount of {@link collateralToken}, in its own units. */
12
+ collateralAmount: bigint;
13
+ /** Token the loan is paid out in; the answer is in its units. */
14
+ borrowToken: Address;
15
+ /** Health factor the loan has to leave the account at, in basis points. */
16
+ targetHF: bigint;
17
+ /** Extra quota headroom in PERCENTAGE_FORMAT, as the borrow itself takes. */
18
+ quotaReserve: number | undefined;
19
+ }
20
+ /**
21
+ * Largest loan this collateral supports at `targetHF` — the ceiling a borrow
22
+ * form should offer, in the payout token's units.
23
+ *
24
+ * The inverse of a borrow rather than a search for one: the loan leaves the
25
+ * account entirely, so the collateral is the whole of what backs the debt, and
26
+ * the health factor is one division away from the amount. Solving it the other
27
+ * way round costs a division too, and no iteration.
28
+ *
29
+ * Collateral is valued the way the transaction will be judged — at safe
30
+ * prices, under its liquidation threshold, capped by the quota the borrow
31
+ * buys for it, all of which is {@link collateralValuation}'s business. The ceiling
32
+ * is then held to what the market will actually lend: the pool's free
33
+ * liquidity, the manager's own allowance and the facade's `maxDebt`, whichever
34
+ * binds first.
35
+ *
36
+ * The facade's `minDebt` is deliberately not applied. It is a floor, and a
37
+ * ceiling answered as `0n` because the collateral is too small for this market
38
+ * would tell a form nothing about what it is holding — the number a user needs
39
+ * to see is the one they are short of. Collateral that carries something
40
+ * therefore answers with it, whether or not the market would lend that little;
41
+ * a loan under the floor is refused by `borrow` itself, with `debtOutOfRange`
42
+ * naming both ends.
43
+ *
44
+ * Nothing is fetched or simulated — the account does not exist yet and every
45
+ * input is loaded market state, so a form can call this on each keystroke.
46
+ *
47
+ * @param props - {@link MaxBorrowProps}
48
+ * @returns Amount in the payout token's units; `0n` where no loan of this
49
+ * shape exists at any size — a collateral that backs nothing at safe prices, a
50
+ * market with nothing left to lend, and a manager the SDK does not hold yet
51
+ **/
52
+ declare function maxBorrow(props: MaxBorrowProps): bigint;
53
+ //#endregion
54
+ export { MaxBorrowProps, maxBorrow };
@@ -16,14 +16,9 @@ interface MaxWithdrawCollateralProps {
16
16
  * factor stays at or above `targetHF`.
17
17
  *
18
18
  * This is the collateral check solved for one balance, and it counts what that
19
- * check counts: a holding backed by a quota contributes the lesser of the
20
- * quota and its threshold-weighted value, an unquoted one — the underlying —
21
- * its weighted value alone, and dust or a disabled balance nothing at all.
22
- * Collateral is valued at the protocol safe price (`min` of the two feeds,
23
- * 0 when there is no reserve), the way the facade values a call that hands
24
- * funds over; the underlying is exempt and is valued at the main feed, as
25
- * `CreditManagerV3._safeConvertToUSD` does. The debt is valued at the main
26
- * feed, as the check does. Zero debt frees the whole balance.
19
+ * check counts — see {@link collateralValuation} for it, safe prices included.
20
+ * The debt is valued at the main feed, as the check does. Zero debt frees the
21
+ * whole balance.
27
22
  *
28
23
  * Rounding always favours the account, so the answer clears the check rather
29
24
  * than landing a wei short of it.
@@ -8,15 +8,8 @@ import { CreditAccountSlice, SimulationPrices } from "./types.js";
8
8
  import "../../index.js";
9
9
  import { Address } from "viem";
10
10
  //#region src/onchain/accounts/intents/open-strategy.d.ts
11
- /**
12
- * Opening an account and putting a position on it in one transaction.
13
- *
14
- * The union says which of the two openings this is: {@link OpenStrategyEmpty}
15
- * takes only the market, because an account holding nothing has nothing to
16
- * route, no leverage to reach and no target to reach it in.
17
- */
18
- type OpenStrategyProps = OpenStrategyFunded | OpenStrategyEmpty;
19
- interface OpenStrategyFunded {
11
+ /** Opening an account and putting a position on it in one transaction. */
12
+ interface OpenStrategyProps {
20
13
  sdk: OnchainSDK;
21
14
  /** Credit manager to open the account in. */
22
15
  creditManager: Address;
@@ -39,13 +32,6 @@ interface OpenStrategyFunded {
39
32
  * is what the `DEPOSIT` intent is for.
40
33
  **/
41
34
  creditAccount?: CreditAccountSlice;
42
- empty?: false;
43
- }
44
- /** Opening an account that holds nothing, for a position to land on later. */
45
- interface OpenStrategyEmpty {
46
- sdk: OnchainSDK;
47
- creditManager: Address;
48
- empty: true;
49
35
  }
50
36
  /**
51
37
  * Projected result of opening a brand-new leveraged position.
@@ -95,4 +81,4 @@ interface OpenStrategyState extends Omit<AccountProjection, "assets" | "quotas">
95
81
  */
96
82
  declare function buildOpenStrategyState(props: OpenStrategyProps): Promise<OpenStrategyState>;
97
83
  //#endregion
98
- export { OpenStrategyEmpty, OpenStrategyFunded, OpenStrategyProps, OpenStrategyState, buildOpenStrategyState };
84
+ export { OpenStrategyProps, OpenStrategyState, buildOpenStrategyState };
@@ -90,6 +90,8 @@ interface BuildMockSdkArgs {
90
90
  baseInterestRate?: bigint;
91
91
  /** Credit manager interest fee in Bps; feeds position metrics. */
92
92
  feeInterest?: number;
93
+ /** Quoted tokens the facade enables at once; feeds `checkQuotaCount`. */
94
+ maxEnabledTokens?: number;
93
95
  creditManager: Address;
94
96
  creditFacade: Address;
95
97
  /** Market underlying token (`market.pool.underlying`). */
@@ -1,6 +1,6 @@
1
1
  import { Asset } from "../../../base/types.js";
2
2
  import { OnchainSDK } from "../../../OnchainSDK.js";
3
- import { OpenStrategyFunded } from "../open-strategy.js";
3
+ import { OpenStrategyProps } from "../open-strategy.js";
4
4
  import "../../../index.js";
5
5
  import { MarketSdkExtras } from "../testing/market.js";
6
6
  import { Address } from "viem";
@@ -51,6 +51,6 @@ declare const case_underlying_1x: OpenStrategyCase;
51
51
  */
52
52
  declare const case_mixed_with_leftover: OpenStrategyCase;
53
53
  declare function buildOpenStrategySdk(extras?: MarketSdkExtras): OnchainSDK;
54
- declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK): OpenStrategyFunded;
54
+ declare function buildOpenStrategyProps(c: OpenStrategyCase, sdk: OnchainSDK): OpenStrategyProps;
55
55
  //#endregion
56
56
  export { COLLATERAL_ANY, HALF_UND, KEEP_ANY, LEVERAGE_1X, LEVERAGE_2X, LEVERAGE_3X, LT, MARGIN_UND, OpenStrategyCase, buildOpenStrategyProps, buildOpenStrategySdk, case_mixed_with_leftover, case_underlying_1x, case_underlying_3x, quotaFor };
@@ -31,6 +31,18 @@ interface PathLossRate {
31
31
  pathPriceImpact: bigint;
32
32
  netValuePriceImpact: bigint;
33
33
  totalValuePriceImpact: bigint;
34
+ absolutePriceImpact: TokenAmount;
35
+ }
36
+ /**
37
+ * What an operation gives up against the oracle: the value of everything its
38
+ * routed legs and redemption request return, the expected claim included, less
39
+ * the value of what they spend. Negative for a loss.
40
+ */
41
+ interface ExecutionCost {
42
+ /** `out − in` in the market underlying. */
43
+ amount: TokenAmount;
44
+ /** `(out − in) / in`, in `PERCENTAGE_FACTOR_1KK` (1_000_000 = 100%). */
45
+ rate: bigint;
34
46
  }
35
47
  /**
36
48
  * The two prices only a planned walk can quote, carried by every simulation
@@ -62,7 +74,18 @@ interface SimulationPrices {
62
74
  * {@link AccountProjection} vocabulary, plus the prices only a routed walk can
63
75
  * report.
64
76
  */
65
- interface OperationState extends AccountProjection, SimulationPrices {}
77
+ interface OperationState extends AccountProjection, SimulationPrices {
78
+ /**
79
+ * What the operation gives up against the oracle.
80
+ *
81
+ * `undefined` where nothing was traded, where a leg cannot be priced, and on
82
+ * a {@link BorrowState}, which does not measure it: the cost compares an
83
+ * account against itself before and after, and a borrow's payout goes to the
84
+ * wallet rather than staying to be compared. What its route cost is on that
85
+ * state as `borrowed` against `totalDebt`.
86
+ */
87
+ executionCost: ExecutionCost | undefined;
88
+ }
66
89
  /**
67
90
  * What planning an intent yields: the operation chain, the state it projects,
68
91
  * and the calldata that realises it — or the error that stopped the plan.
@@ -429,12 +452,34 @@ interface WithdrawStrategyIntent {
429
452
  */
430
453
  interface WithdrawCeilings {
431
454
  /**
432
- * Largest partial withdrawal {@link WithdrawStrategyIntent} accepts: the one
433
- * whose proportional repayment leaves the debt at `minDebt`. `0n` when the
434
- * debt already sits below the floor, and always at least one unit under
435
- * `exit` — the last unit closes the account rather than shrinking it.
455
+ * Largest partial withdrawal the facade's `debtLimits` accept: the one whose
456
+ * proportional repayment leaves the debt at `minDebt`. `0n` when the debt
457
+ * already sits below the floor, and always at least one unit under `exit` —
458
+ * the last unit closes the account rather than shrinking it.
459
+ *
460
+ * `debtLimits` are not the only rule a withdrawal answers to, so this is a
461
+ * limit rather than the limit: {@link safePartial} is the one to offer.
436
462
  */
437
463
  partial: bigint;
464
+ /**
465
+ * Largest partial withdrawal {@link WithdrawStrategyIntent} actually accepts
466
+ * — {@link partial} once the safe-price collateral check has had its say,
467
+ * and never above it.
468
+ *
469
+ * A withdrawal hands funds over, and the facade weighs what it leaves behind
470
+ * at safe prices: `min` of a token's two feeds, or nothing at all where
471
+ * governance registered no reserve feed. Collateral the reserve feed marks
472
+ * down therefore backs less than a projection at main prices suggests, and
473
+ * the withdrawal stops earlier than `debtLimits` alone would say. This is
474
+ * the figure a slider and a Max button belong on.
475
+ *
476
+ * `0n` on an account already under the threshold at safe prices. That is not
477
+ * a rounding artefact and a smaller request does not help: a proportional
478
+ * withdrawal leaves the safe-price factor exactly where it found it, so no
479
+ * amount clears a threshold the account is already under. Such a position
480
+ * can still leave — see {@link exit}, which the check never refuses.
481
+ */
482
+ safePartial: bigint;
438
483
  /**
439
484
  * What leaving hands over: the account's net value, which is also the amount
440
485
  * at which a withdrawal turns into an exit. `0n` on an account whose debt
@@ -470,4 +515,4 @@ type FinishIntentProps = StartIntentProps & {
470
515
  claimable: ClaimableWithdrawal;
471
516
  };
472
517
  //#endregion
473
- export { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, SimulationPrices, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent };
518
+ export { AddCollateralIntent, AdjustLeverageIntent, ClaimRemainder, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, ExecutionCost, FinishIntentProps, FinishIntentResult, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteErrors, SimulationPrices, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawCeilings, WithdrawStrategyIntent };
@@ -1,5 +1,7 @@
1
1
  import { Asset } from "../../../base/types.js";
2
2
  import { RouterCASlice } from "../../../router/types.js";
3
+ import { MarketSuite } from "../../../market/MarketSuite.js";
4
+ import { CreditSuite } from "../../../market/credit/CreditSuite.js";
3
5
  import { OnchainSDK } from "../../../OnchainSDK.js";
4
6
  import { CreditAccountSlice } from "../types.js";
5
7
  import "../../../index.js";
@@ -7,6 +9,18 @@ import { Address } from "viem";
7
9
  //#region src/onchain/accounts/intents/utils/common.d.ts
8
10
  /** Case-insensitive address equality. */
9
11
  declare const eq: (a: Address, b: Address) => boolean;
12
+ /**
13
+ * The suite and market behind a credit manager, or nothing where the register
14
+ * has no entry for it.
15
+ *
16
+ * For the reads a form calls on every keystroke, including before the SDK has
17
+ * finished attaching: a question the register cannot answer yet is not an
18
+ * error. Everything that prepares a transaction wants the throw instead.
19
+ */
20
+ declare function resolveCreditManager(sdk: OnchainSDK, creditManager: Address): {
21
+ suite: CreditSuite;
22
+ market: MarketSuite;
23
+ } | undefined;
10
24
  declare function toTargetDecimals(fromAmount: bigint, fromToken: Address, toToken: Address, sdk: OnchainSDK): bigint;
11
25
  /**
12
26
  * Router CA slice from the account slice. RouterV310 reads `ca.tokens` for
@@ -16,4 +30,4 @@ declare function toTargetDecimals(fromAmount: bigint, fromToken: Address, toToke
16
30
  */
17
31
  declare function toRouterCaSlice(creditAccount: CreditAccountSlice, expectedBalances?: Asset[]): RouterCASlice;
18
32
  //#endregion
19
- export { eq, toRouterCaSlice, toTargetDecimals };
33
+ export { eq, resolveCreditManager, toRouterCaSlice, toTargetDecimals };