@gearbox-protocol/sdk 17.0.0-next.3 → 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 (370) 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 +19 -7
  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 +33 -12
  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 +12 -10
  89. package/dist/cjs/onchain/validation/bundles/checkIncreaseDebt.js +28 -0
  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/checkSimulation.js +1 -1
  97. package/dist/cjs/onchain/validation/checks/checkBorrowLimit.js +1 -1
  98. package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +2 -5
  99. package/dist/cjs/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  100. package/dist/cjs/onchain/validation/checks/checkReservePriceLimited.js +30 -0
  101. package/dist/cjs/onchain/validation/checks/index.js +2 -0
  102. package/dist/cjs/onchain/validation/index.js +8 -4
  103. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
  104. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
  105. package/dist/cjs/sdk/execute/ExecuteApi.js +67 -7
  106. package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  107. package/dist/cjs/sdk/prepare/PrepareApi.js +89 -14
  108. package/dist/esm/dev/abi.js +14 -15
  109. package/dist/esm/dev/claimFromFaucet.js +4 -8
  110. package/dist/esm/dev/createAnvilClient.js +36 -19
  111. package/dist/esm/dev/index.js +4 -4
  112. package/dist/esm/dev/kycUtils.js +66 -59
  113. package/dist/esm/dev/midasUtils.js +112 -18
  114. package/dist/esm/dev/securitizeUtils.js +84 -44
  115. package/dist/esm/dev/withdrawalUtils.js +3 -6
  116. package/dist/esm/model/errors/index.js +2 -2
  117. package/dist/esm/model/errors/operation-errors.js +18 -2
  118. package/dist/esm/model/index.js +4 -4
  119. package/dist/esm/model/rwa.js +4 -4
  120. package/dist/esm/model/rwa.schema.js +5 -5
  121. package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
  122. package/dist/esm/onchain/OnchainSDK.js +3 -3
  123. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -17
  124. package/dist/esm/onchain/accounts/intents/borrow.js +138 -0
  125. package/dist/esm/onchain/accounts/intents/collateral-valuation.js +40 -0
  126. package/dist/esm/onchain/accounts/intents/guards.js +19 -7
  127. package/dist/esm/onchain/accounts/intents/index.js +107 -20
  128. package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -12
  129. package/dist/esm/onchain/accounts/intents/maxBorrow.js +87 -0
  130. package/dist/esm/onchain/accounts/intents/maxWithdrawCollateral.js +15 -41
  131. package/dist/esm/onchain/accounts/intents/open-strategy.js +8 -46
  132. package/dist/esm/onchain/accounts/intents/operations.js +0 -1
  133. package/dist/esm/onchain/accounts/intents/realize.js +61 -4
  134. package/dist/esm/onchain/accounts/intents/tail.js +1 -1
  135. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
  136. package/dist/esm/onchain/accounts/intents/utils/common.js +19 -1
  137. package/dist/esm/onchain/accounts/intents/utils/credit-account-slice.js +21 -1
  138. package/dist/esm/onchain/accounts/intents/utils/index.js +3 -3
  139. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +12 -9
  140. package/dist/esm/onchain/accounts/intents/utils/router-path.js +4 -5
  141. package/dist/esm/onchain/accounts/intents/withdraw-limits.js +95 -0
  142. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  143. package/dist/esm/onchain/constants/address-provider.js +1 -2
  144. package/dist/esm/onchain/constants/index.js +2 -2
  145. package/dist/esm/onchain/core/createAddressProvider.js +2 -5
  146. package/dist/esm/onchain/index.js +32 -24
  147. package/dist/esm/onchain/market/adapters/abi/conctructorAbi.js +2 -2
  148. package/dist/esm/onchain/market/adapters/contracts/AbstractAdapter.js +6 -0
  149. package/dist/esm/onchain/market/adapters/contracts/MidasGatewayAdapterContract.js +50 -6
  150. package/dist/esm/onchain/market/credit/CreditSuite.js +33 -12
  151. package/dist/esm/onchain/market/index.js +26 -21
  152. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  153. package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  154. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
  155. package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  156. package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  157. package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  158. package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  159. package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  160. package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  161. package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  162. package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  163. package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  164. package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  165. package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  166. package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  167. package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  168. package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  169. package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  170. package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  171. package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  172. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
  173. package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
  174. package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
  175. package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  176. package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
  177. package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  178. package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
  179. package/dist/esm/onchain/market/rwa/RWARegistry.js +4 -8
  180. package/dist/esm/onchain/market/rwa/index.js +2 -2
  181. package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
  182. package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
  183. package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
  184. package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
  185. package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
  186. package/dist/esm/onchain/positions/calcHealthFactor.js +3 -3
  187. package/dist/esm/onchain/preview/index.js +2 -1
  188. package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
  189. package/dist/esm/onchain/preview/preview/index.js +2 -1
  190. package/dist/esm/onchain/preview/preview/midasGreenlistsAccount.js +16 -0
  191. package/dist/esm/onchain/preview/preview/previewOpenStrategyPosition.js +14 -17
  192. package/dist/esm/onchain/preview/preview/previewOperation.js +19 -11
  193. package/dist/esm/onchain/preview/preview/replayMulticall.js +4 -3
  194. package/dist/esm/onchain/validation/bundles/checkCollateralFunding.js +3 -3
  195. package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +12 -10
  196. package/dist/esm/onchain/validation/bundles/checkIncreaseDebt.js +27 -0
  197. package/dist/esm/onchain/validation/bundles/{checkQuotasAsked.js → checkIncreaseQuota.js} +3 -3
  198. package/dist/esm/onchain/validation/bundles/checkMidasAccountGreenlist.js +43 -0
  199. package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
  200. package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +18 -8
  201. package/dist/esm/onchain/validation/bundles/index.js +4 -3
  202. package/dist/esm/onchain/validation/checkOperation.js +0 -1
  203. package/dist/esm/onchain/validation/checkSimulation.js +1 -1
  204. package/dist/esm/onchain/validation/checks/checkBorrowLimit.js +1 -1
  205. package/dist/esm/onchain/validation/checks/checkDebtLimits.js +2 -5
  206. package/dist/esm/onchain/validation/checks/checkPoolLiquidity.js +1 -1
  207. package/dist/esm/onchain/validation/checks/checkReservePriceLimited.js +29 -0
  208. package/dist/esm/onchain/validation/checks/index.js +2 -1
  209. package/dist/esm/onchain/validation/index.js +5 -3
  210. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  211. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
  212. package/dist/esm/sdk/execute/ExecuteApi.js +67 -7
  213. package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
  214. package/dist/esm/sdk/prepare/PrepareApi.js +94 -19
  215. package/dist/types/dev/abi.d.ts +13 -15
  216. package/dist/types/dev/claimFromFaucet.d.ts +0 -1
  217. package/dist/types/dev/createAnvilClient.d.ts +10 -3
  218. package/dist/types/dev/index.d.ts +4 -4
  219. package/dist/types/dev/kycUtils.d.ts +15 -24
  220. package/dist/types/dev/midasUtils.d.ts +35 -4
  221. package/dist/types/dev/securitizeUtils.d.ts +3 -9
  222. package/dist/types/model/errors/index.d.ts +2 -2
  223. package/dist/types/model/errors/operation-errors.d.ts +65 -11
  224. package/dist/types/model/index.d.ts +5 -5
  225. package/dist/types/model/opportunities.d.ts +6 -7
  226. package/dist/types/model/previews.d.ts +25 -19
  227. package/dist/types/model/rwa.d.ts +47 -27
  228. package/dist/types/model/rwa.schema.d.ts +3 -3
  229. package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
  230. package/dist/types/offchain/opportunities/types.d.ts +1 -4
  231. package/dist/types/onchain/OnchainSDK.d.ts +2 -2
  232. package/dist/types/onchain/accounts/index.d.ts +5 -4
  233. package/dist/types/onchain/accounts/intents/borrow.d.ts +141 -0
  234. package/dist/types/onchain/accounts/intents/collateral-valuation.d.ts +42 -0
  235. package/dist/types/onchain/accounts/intents/guards.d.ts +18 -2
  236. package/dist/types/onchain/accounts/intents/index.d.ts +103 -15
  237. package/dist/types/onchain/accounts/intents/maxBorrow.d.ts +54 -0
  238. package/dist/types/onchain/accounts/intents/maxWithdrawCollateral.d.ts +3 -8
  239. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -17
  240. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +2 -0
  241. package/dist/types/onchain/accounts/intents/tests/open-strategy.fixtures.d.ts +2 -2
  242. package/dist/types/onchain/accounts/intents/types.d.ts +51 -6
  243. package/dist/types/onchain/accounts/intents/utils/common.d.ts +15 -1
  244. package/dist/types/onchain/accounts/intents/utils/credit-account-slice.d.ts +14 -1
  245. package/dist/types/onchain/accounts/intents/utils/index.d.ts +3 -3
  246. package/dist/types/onchain/accounts/intents/utils/price-impact.d.ts +4 -1
  247. package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +2 -5
  248. package/dist/types/onchain/accounts/intents/withdraw-limits.d.ts +80 -0
  249. package/dist/types/onchain/accounts/types.d.ts +4 -2
  250. package/dist/types/onchain/constants/address-provider.d.ts +1 -2
  251. package/dist/types/onchain/constants/index.d.ts +2 -2
  252. package/dist/types/onchain/index.d.ts +40 -31
  253. package/dist/types/onchain/market/adapters/contracts/AbstractAdapter.d.ts +6 -0
  254. package/dist/types/onchain/market/adapters/contracts/MidasGatewayAdapterContract.d.ts +20 -4
  255. package/dist/types/onchain/market/adapters/types.d.ts +8 -0
  256. package/dist/types/onchain/market/credit/CreditSuite.d.ts +13 -3
  257. package/dist/types/onchain/market/credit/types.d.ts +2 -2
  258. package/dist/types/onchain/market/index.d.ts +29 -24
  259. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
  260. package/dist/types/onchain/market/oracle/types.d.ts +2 -1
  261. package/dist/types/onchain/market/pool/types.d.ts +1 -1
  262. package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
  263. package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
  264. package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
  265. package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
  266. package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
  267. package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
  268. package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
  269. package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
  270. package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
  271. package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
  272. package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
  273. package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
  274. package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
  275. package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
  276. package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
  277. package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
  278. package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
  279. package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
  280. package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
  281. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
  282. package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
  283. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
  284. package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
  285. package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
  286. package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
  287. package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
  288. package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
  289. package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
  290. package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
  291. package/dist/types/onchain/market/rwa/RWARegistry.d.ts +2 -1
  292. package/dist/types/onchain/market/rwa/index.d.ts +3 -3
  293. package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
  294. package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
  295. package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
  296. package/dist/types/onchain/market/rwa/types.d.ts +39 -37
  297. package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
  298. package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
  299. package/dist/types/onchain/opportunities/types.d.ts +6 -1
  300. package/dist/types/onchain/preview/index.d.ts +2 -1
  301. package/dist/types/onchain/preview/preview/index.d.ts +2 -1
  302. package/dist/types/onchain/preview/preview/midasGreenlistsAccount.d.ts +13 -0
  303. package/dist/types/onchain/preview/preview/previewOpenStrategyPosition.d.ts +5 -3
  304. package/dist/types/onchain/preview/preview/replayMulticall.d.ts +8 -7
  305. package/dist/types/onchain/validation/bundles/checkCreditOperation.d.ts +5 -4
  306. package/dist/types/onchain/validation/bundles/{checkDraw.d.ts → checkIncreaseDebt.d.ts} +7 -7
  307. package/dist/types/onchain/validation/bundles/{checkQuotasAsked.d.ts → checkIncreaseQuota.d.ts} +3 -3
  308. package/dist/types/onchain/validation/bundles/checkMidasAccountGreenlist.d.ts +22 -0
  309. package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
  310. package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +9 -7
  311. package/dist/types/onchain/validation/bundles/index.d.ts +5 -4
  312. package/dist/types/onchain/validation/checks/checkBorrowLimit.d.ts +1 -1
  313. package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +3 -3
  314. package/dist/types/onchain/validation/checks/checkPoolLiquidity.d.ts +1 -1
  315. package/dist/types/onchain/validation/checks/checkReservePriceLimited.d.ts +31 -0
  316. package/dist/types/onchain/validation/checks/index.d.ts +2 -1
  317. package/dist/types/onchain/validation/index.d.ts +6 -4
  318. package/dist/types/onchain/validation/raise.d.ts +2 -2
  319. package/dist/types/sdk/execute/index.d.ts +2 -2
  320. package/dist/types/sdk/execute/types.d.ts +48 -6
  321. package/dist/types/sdk/index.d.ts +5 -4
  322. package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
  323. package/dist/types/sdk/opportunities/types.d.ts +9 -3
  324. package/dist/types/sdk/prepare/PrepareApi.d.ts +16 -4
  325. package/dist/types/sdk/prepare/index.d.ts +4 -3
  326. package/dist/types/sdk/prepare/types.d.ts +200 -66
  327. package/package.json +1 -1
  328. package/dist/cjs/onchain/accounts/utils/midasUtils.js +0 -70
  329. package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
  330. package/dist/cjs/onchain/validation/bundles/checkDraw.js +0 -28
  331. package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -61
  332. package/dist/cjs/plugins/degen-distributors/index.js +0 -4
  333. package/dist/cjs/plugins/degen-distributors/package.json +0 -1
  334. package/dist/cjs/plugins/degen-distributors/types.js +0 -1
  335. package/dist/cjs/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -114
  336. package/dist/cjs/plugins/delayed-withdrawal/index.js +0 -4
  337. package/dist/cjs/plugins/delayed-withdrawal/package.json +0 -1
  338. package/dist/cjs/plugins/delayed-withdrawal/types.js +0 -1
  339. package/dist/esm/onchain/accounts/utils/midasUtils.js +0 -69
  340. package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
  341. package/dist/esm/onchain/validation/bundles/checkDraw.js +0 -27
  342. package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +0 -60
  343. package/dist/esm/plugins/degen-distributors/index.js +0 -3
  344. package/dist/esm/plugins/degen-distributors/package.json +0 -1
  345. package/dist/esm/plugins/degen-distributors/types.js +0 -1
  346. package/dist/esm/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.js +0 -113
  347. package/dist/esm/plugins/delayed-withdrawal/index.js +0 -3
  348. package/dist/esm/plugins/delayed-withdrawal/package.json +0 -1
  349. package/dist/esm/plugins/delayed-withdrawal/types.js +0 -1
  350. package/dist/types/onchain/accounts/utils/midasUtils.d.ts +0 -38
  351. package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
  352. package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
  353. package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
  354. package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
  355. package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
  356. package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
  357. package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
  358. package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
  359. package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
  360. package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
  361. package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
  362. package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
  363. package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
  364. package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
  365. package/dist/types/plugins/degen-distributors/DegenDistributorsPlugin.d.ts +0 -25
  366. package/dist/types/plugins/degen-distributors/index.d.ts +0 -3
  367. package/dist/types/plugins/degen-distributors/types.d.ts +0 -8
  368. package/dist/types/plugins/delayed-withdrawal/DelayedWithdrawalPlugin.d.ts +0 -25
  369. package/dist/types/plugins/delayed-withdrawal/index.d.ts +0 -3
  370. package/dist/types/plugins/delayed-withdrawal/types.d.ts +0 -10
@@ -1,8 +1,9 @@
1
1
  import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure } from "../../model/errors/prepare-errors.js";
2
2
  import "../../model/index.js";
3
+ import { ExecutionCost, OperationState, PathLossRate, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
4
+ import { BorrowState } from "../../onchain/accounts/intents/borrow.js";
3
5
  import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
4
- import { OperationState, PathLossRate, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
5
6
  import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
6
- import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
7
+ import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
7
8
  import { ChainOf, PrepareApi } from "./PrepareApi.js";
8
- export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareApi, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure };
9
+ export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareApi, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure };
@@ -1,6 +1,6 @@
1
1
  import { Bps, Timestamp, TokenAmount } from "../../model/primitives.js";
2
2
  import { Curator } from "../../model/curators.js";
3
- import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError } from "../../model/errors/operation-errors.js";
3
+ import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError, ReservePriceLimitedError } from "../../model/errors/operation-errors.js";
4
4
  import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
5
5
  import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
6
6
  import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
@@ -10,9 +10,10 @@ import "../../model/index.js";
10
10
  import { Asset } from "../../onchain/base/types.js";
11
11
  import { MultiCall } from "../../onchain/types/transactions.js";
12
12
  import { PoolSimulation } from "../../onchain/pools/types.js";
13
- import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
14
13
  import { AccountCalculatorOperation } from "../../onchain/accounts/intents/operations.js";
15
- import { ClaimRemainder, DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
14
+ import { ClaimRemainder, DelayedStart, ExecutionCost, OperationState, PathLossRate, ResumableIntent, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
15
+ import { BorrowState } from "../../onchain/accounts/intents/borrow.js";
16
+ import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
16
17
  import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
17
18
  import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
18
19
  import "../../onchain/index.js";
@@ -22,7 +23,7 @@ import { Address } from "viem";
22
23
  * What any operation on an existing account can answer with: the engine's
23
24
  * shared guards, the missing account, and a wrapped crash.
24
25
  **/
25
- type AccountFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
26
+ type AccountFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | ReservePriceLimitedError | InsufficientBalanceError | CreditAccountNotFoundError | UnexpectedFailureError;
26
27
  /** Same guards for the account-less open flow. */
27
28
  type OpenFlowError = CreditManagerPausedError | MarketExpiredError | ForbiddenTokenError | QuotaLimitReachedError | InsufficientCollateralError | InsufficientBalanceError | UnexpectedFailureError;
28
29
  /**
@@ -227,6 +228,41 @@ interface OpenStrategyResult {
227
228
  /** Unix seconds of {@link blockNumber}. */
228
229
  timestamp: Timestamp;
229
230
  }
231
+ /**
232
+ * What taking a loan against collateral comes to.
233
+ *
234
+ * Shaped like {@link OpenStrategyResult} — a borrow opens its account too, so
235
+ * there is no chain of steps to report — with the whole projection on the
236
+ * state rather than two branches of balances, see {@link BorrowState}.
237
+ **/
238
+ interface BorrowResult {
239
+ /**
240
+ * Everything the loan arrives at: the collateral and the debt it backs, the
241
+ * payout expected and its floor, the position metrics a screen shows beside
242
+ * them, and the router path `openCA` is handed.
243
+ **/
244
+ state: BorrowState;
245
+ /** Block of the chain state this result was computed from. */
246
+ blockNumber: number;
247
+ /** Unix seconds of {@link blockNumber}. */
248
+ timestamp: Timestamp;
249
+ }
250
+ /**
251
+ * What opening an account that holds nothing comes to: the block it was
252
+ * cleared at, and nothing else.
253
+ *
254
+ * The one prepared operation with no state to report. Every other result
255
+ * describes where the account lands, but this one lands it holding nothing and
256
+ * owing nothing — there is no collateral to value, no debt to weigh and no
257
+ * health factor to read. What the preparation is for is the refusal it can
258
+ * answer with instead: a market that takes no multicall.
259
+ **/
260
+ interface EmptyCreditAccountResult {
261
+ /** Block of the chain state this result was computed from. */
262
+ blockNumber: number;
263
+ /** Unix seconds of {@link blockNumber}. */
264
+ timestamp: Timestamp;
265
+ }
230
266
  /**
231
267
  * Shared knobs. Both default to the SDK's own defaults when omitted.
232
268
  **/
@@ -338,15 +374,7 @@ interface WithdrawCollateralParams extends PrepareOptions {
338
374
  /** Wallet receiving the tokens. */
339
375
  to: Address;
340
376
  }
341
- /**
342
- * Opening a position, in one of the two shapes an opening comes in.
343
- *
344
- * The union is the check: an empty opening names nothing to open with, so
345
- * collateral it meant to spend or an account it meant to reuse cannot be
346
- * silently dropped — those arguments do not typecheck against `empty: true`.
347
- **/
348
- type OpenStrategyParams = OpenStrategyFundedParams | OpenStrategyEmptyParams;
349
- interface OpenStrategyFundedParams extends PrepareOptions {
377
+ interface OpenStrategyParams extends PrepareOptions {
350
378
  /** Collateral coming from the wallet, in their own tokens. */
351
379
  collateral: Asset[];
352
380
  /**
@@ -363,43 +391,80 @@ interface OpenStrategyFundedParams extends PrepareOptions {
363
391
  /**
364
392
  * Existing credit account to open the position on, instead of creating one.
365
393
  *
366
- * Must belong to `strategy.creditManager` and carry no debt and no quotas —
367
- * an account pre-opened by an {@link OpenStrategyEmptyParams} opening.
368
- * The projection is identical either way; only the transaction differs, and
369
- * `execute.buildTx` reads which one to build off the result's own
370
- * `state.creditAccount`.
394
+ * Any account of `strategy.creditManager` that carries no debt and no
395
+ * quotas qualifies. The projection is identical either way; only the
396
+ * transaction differs, and `execute.buildTx` reads which one to build off
397
+ * the result's own `state.creditAccount`.
398
+ **/
399
+ creditAccount?: Address;
400
+ }
401
+ interface BorrowParams extends PrepareOptions {
402
+ /**
403
+ * Token the wallet puts up as collateral. Must be a collateral token of the
404
+ * market, and cannot be {@link borrowToken} — the payout is swept off the
405
+ * account, and a sweep takes the whole balance of the token it names.
406
+ **/
407
+ collateralToken: Address;
408
+ /** Amount of {@link collateralToken} that leaves the wallet. */
409
+ collateralAmount: bigint;
410
+ /**
411
+ * Token the wallet is paid the loan in. The market underlying is handed over
412
+ * as it is borrowed; anything else the router has a path to is bought with
413
+ * the borrowed underlying first, and then {@link BorrowResult} reports both
414
+ * what that trade is expected to return and its floor.
415
+ *
416
+ * An RWA market is paid in the asset its underlying wraps — `USDC`, not the
417
+ * `dcUSDC` the pool lends — because the wrapper cannot leave the account.
418
+ * The two convert one for one through the market's vault, so that payout is
419
+ * exact like the underlying's. Naming the wrapper is refused with
420
+ * `unsupportedCollateralToken`.
421
+ **/
422
+ borrowToken: Address;
423
+ /**
424
+ * Amount of {@link borrowToken} the wallet asks for. It is the debt exactly
425
+ * when `borrowToken` is the market underlying, and the same amount in the
426
+ * underlying's own decimals when it is the asset an RWA market unwraps into;
427
+ * otherwise the debt is what the oracle prices that much of it at, and what
428
+ * actually arrives is the router's answer.
429
+ **/
430
+ borrowAmount: bigint;
431
+ /**
432
+ * Existing credit account to draw the loan on, instead of opening one.
433
+ *
434
+ * Any account of `strategy.creditManager` that carries no debt and no
435
+ * quotas qualifies. Only the transaction differs; `execute.buildTx` reads
436
+ * which one to build off the result's own `state.creditAccount`.
437
+ *
438
+ * Balances already sitting on it are left where they are and are **not**
439
+ * counted towards the health factor, so the loan this allows is the one the
440
+ * named collateral alone carries. The exception is a balance in
441
+ * {@link borrowToken}: the payout sweep takes the whole balance of the token
442
+ * it names, so that one leaves with the loan.
371
443
  **/
372
444
  creditAccount?: Address;
373
- empty?: false;
374
445
  }
375
446
  /**
376
- * Opening an account that holds nothing: no collateral, no debt, no quotas, and
377
- * no route quoted. A wallet holds one so a position can be put on it later, by
378
- * an opening that names it as
379
- * {@link OpenStrategyFundedParams.creditAccount}.
380
- *
381
- * The market is the whole request. There is nothing else to say: with no
382
- * collateral the debt is zero at any leverage, and there is nothing to route
383
- * anywhere — so leverage and a target token are not merely ignored here, they
384
- * cannot be named.
447
+ * What a borrow form knows before it knows the amount: everything
448
+ * {@link BorrowParams} carries except the loan itself, which is the answer.
385
449
  **/
386
- interface OpenStrategyEmptyParams {
387
- empty: true;
388
- /**
389
- * The three an empty opening would otherwise have to drop, spelled out as
390
- * `never` rather than merely left out.
391
- *
392
- * A bare `{ empty: true }` is a structural type, and excess-property checking
393
- * only fires on a fresh object literal — so params built up in a variable, as
394
- * a form builds them, would pass on the extra members and have them silently
395
- * dropped. Naming them closes that: the shape is refused wherever it is
396
- * written, and `empty` typed as a plain `boolean` is refused by both branches.
397
- **/
398
- collateral?: never;
399
- leverage?: never;
400
- creditAccount?: never;
401
- targetToken?: never;
402
- leftoverBalances?: never;
450
+ interface MaxBorrowParams {
451
+ /** Token the wallet would put up, as in {@link BorrowParams}. */
452
+ collateralToken: Address;
453
+ /** Amount of {@link collateralToken} that would leave the wallet. */
454
+ collateralAmount: bigint;
455
+ /** Token the loan would be paid in; the ceiling comes back in its units. */
456
+ borrowToken: Address;
457
+ /**
458
+ * Health factor the loan should leave the account at, in basis points.
459
+ * Omitted, the SDK holds it to the threshold a form would.
460
+ **/
461
+ targetHF?: bigint;
462
+ /**
463
+ * Extra quota headroom in PERCENTAGE_FORMAT. Pass what the borrow itself
464
+ * will pass: a quota short of the collateral's weighted value is what caps
465
+ * the loan, so a different reserve here answers about a different loan.
466
+ **/
467
+ quotaReserve?: number;
403
468
  }
404
469
  interface LpParams {
405
470
  /**
@@ -472,11 +537,11 @@ interface FinalizeParams extends PrepareOptions {
472
537
  * throws: a chain that cannot be reached or a crash on the way arrives as
473
538
  * `unexpectedFailure` with the cause attached.
474
539
  *
475
- * The bare readers stay outside the envelope: the `max*` ceilings answer their
476
- * number and throw on an account or chain the SDK does not hold, and the two
477
- * synchronous readers ({@link leverageBand}, {@link withdrawableCollaterals})
478
- * weigh state already loaded and say "nothing available" with `undefined` or
479
- * an empty list.
540
+ * The bare readers stay outside the envelope. The ones that read an account
541
+ * answer their number and throw on an account or chain the SDK does not hold;
542
+ * the synchronous ones ({@link leverageBand}, {@link withdrawableCollaterals},
543
+ * {@link maxBorrow}) weigh state already loaded and say "nothing available"
544
+ * with `undefined`, an empty list or `0n`.
480
545
  **/
481
546
  interface IOpportunitiesPrepare {
482
547
  /**
@@ -503,10 +568,41 @@ interface IOpportunitiesPrepare {
503
568
  /**
504
569
  * Opening a leveraged position from wallet collateral.
505
570
  *
506
- * The one flow with no account yet, so the result carries no operation list —
571
+ * There is no account to walk yet, so the result carries no operation list —
507
572
  * it feeds `sdk.accounts.openCA` instead.
573
+ *
574
+ * `creditAccount` puts the position on an account the wallet already holds
575
+ * rather than creating one.
508
576
  **/
509
577
  openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
578
+ /**
579
+ * Handing a wallet an account that holds nothing: no collateral, no debt, no
580
+ * quotas and no route quoted. It exists so a wallet can hold an account
581
+ * ahead of having a use for one, and so the two flows that put something on
582
+ * an account have one to name as their `creditAccount`.
583
+ *
584
+ * The market is the whole request, and the only thing that can refuse it is
585
+ * the market itself: a facade that is paused or past its expiration takes no
586
+ * multicall, so an account cannot be opened there either.
587
+ **/
588
+ openEmptyCreditAccount(strategy: StrategyInput): Promise<SDKReturn<EmptyCreditAccountResult, CreditManagerPausedError | MarketExpiredError | UnexpectedFailureError>>;
589
+ /**
590
+ * Borrowing against collateral: one transaction opens an account, puts the
591
+ * collateral on it, draws the loan and pays it out to the wallet.
592
+ *
593
+ * The account is left holding the collateral and owing the debt, and nothing
594
+ * else — which is what tells this apart from {@link openNewStrategy}, where
595
+ * the borrowed funds stay on the account as part of the position. There is
596
+ * no leverage to name for the same reason: the loan is the amount asked for.
597
+ *
598
+ * The payout leaves the account, so the market weighs what is left at safe
599
+ * prices, and a loan the remaining collateral cannot carry there comes back
600
+ * as `insufficientCollateral` rather than reverting on arrival.
601
+ *
602
+ * `creditAccount` draws the loan on an account the wallet already holds
603
+ * instead of opening another, as {@link openNewStrategy} does.
604
+ **/
605
+ borrow(strategy: StrategyInput, params: BorrowParams): Promise<SDKReturn<BorrowResult, OpenFlowError | DebtOutOfRangeError | UnsupportedCollateralTokenError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
510
606
  /**
511
607
  * Growing a position: collateral in, debt drawn on top, both converted into
512
608
  * the position token.
@@ -541,26 +637,33 @@ interface IOpportunitiesPrepare {
541
637
  **/
542
638
  withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<SDKReturn<StrategyRoutesResult, (AccountFlowError | DebtOutOfRangeError | UnsupportedTokenPairError | NoDelayedRouteError | MultipleDelayedWithdrawalsError | WithdrawalInProgressError) & WithRouteErrors>>;
543
639
  /**
544
- * How much {@link withdrawStrategy} can take out, both ends of it, in
545
- * underlying units: `partial` is the largest withdrawal that keeps leverage
546
- * and leaves the debt at the credit manager's `minDebt`, `exit` is the net
547
- * value leaving entirely hands over.
548
- *
549
- * Two numbers rather than one because the range has a hole in it: between
550
- * them the flow refuses with `debtOutOfRange`, since the leftover loan would
551
- * sit below the floor. A form driving a slider off `partial` and a Max
552
- * button off `exit` describes what the account can actually do; a form using
553
- * either alone will misstate one of them — see {@link WithdrawCeilings},
554
- * which spells out how far apart they can be.
555
- *
556
- * Taking everything out needs neither figure: send `MAX_UINT256` to
640
+ * How much {@link withdrawStrategy} can take out, every end of it, in
641
+ * underlying units: `safePartial` is the largest partial withdrawal the flow
642
+ * accepts, `partial` the same figure before the safe-price collateral check
643
+ * has had its say, and `exit` the net value leaving entirely hands over.
644
+ *
645
+ * More than one number because the range has a hole in it: between the
646
+ * largest partial and `exit` the flow refuses with `debtOutOfRange`, since
647
+ * the leftover loan would sit below the floor. A form driving a slider off
648
+ * `safePartial` and a Max button off `exit` describes what the account can
649
+ * actually do; a form using either alone will misstate one of them — see
650
+ * {@link WithdrawCeilings}, which spells out how far apart they can be and
651
+ * why the two partial figures differ.
652
+ *
653
+ * `sourceToken` is the collateral the withdrawal would be funded from, the
654
+ * same argument {@link withdrawStrategy} takes. It matters because selling
655
+ * one collateral and selling another cost the safe-price check different
656
+ * amounts; omitted, both this and the flow itself reach for the account's
657
+ * largest non-phantom balance.
658
+ *
659
+ * Taking everything out needs none of the figures: send `MAX_UINT256` to
557
660
  * {@link withdrawStrategy} and the exit is what runs, named rather than
558
661
  * priced.
559
662
  *
560
663
  * A bare read: it answers its numbers, and throws on an account or a chain
561
664
  * the SDK does not hold.
562
665
  **/
563
- maxWithdraw(position: PositionInput): Promise<WithdrawCeilings>;
666
+ maxWithdraw(position: PositionInput, sourceToken?: Address): Promise<WithdrawCeilings>;
564
667
  /**
565
668
  * Paying debt down with funds from the wallet: collateral stays where it is,
566
669
  * so net value grows by what was repaid, leverage falls and the health factor
@@ -663,6 +766,37 @@ interface IOpportunitiesPrepare {
663
766
  * the SDK does not hold.
664
767
  **/
665
768
  maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<bigint>;
769
+ /**
770
+ * Largest loan {@link borrow} can draw against a given collateral while the
771
+ * account stays safely collateralised, in the payout token's units — the
772
+ * ceiling a borrow form should offer.
773
+ *
774
+ * The loan leaves the account, so the collateral alone backs the debt and
775
+ * the market weighs it at safe prices, under its liquidation threshold and
776
+ * capped by the quota the borrow buys for it. The answer is then held to
777
+ * what the market will actually lend: the pool's free liquidity, the
778
+ * manager's own allowance and the facade's `maxDebt`.
779
+ *
780
+ * `targetHF` names the health factor to land at, in basis points; omitted,
781
+ * the SDK holds it to the threshold a form would.
782
+ *
783
+ * Synchronous, like {@link leverageBand} and for the same reason: the
784
+ * account does not exist yet, so there is nothing to read and a form can ask
785
+ * on every keystroke.
786
+ *
787
+ * It is a ceiling and not a verdict: the facade's `minDebt` is a floor, and
788
+ * holding the answer to it would tell a form `0` for collateral that does
789
+ * carry a loan, only a smaller one than this market lends. So a Max offered
790
+ * from here can still be refused by {@link borrow} with `debtOutOfRange`,
791
+ * which names the floor the amount fell short of.
792
+ *
793
+ * `0n` where this market funds no loan of this shape at any size — a
794
+ * collateral worth nothing at safe prices, a payout token equal to the
795
+ * collateral, a market with nothing left to lend, or a manager the SDK does
796
+ * not hold. Not the same as "any amount works", and a caller must not offer
797
+ * a Max for it.
798
+ **/
799
+ maxBorrow(strategy: StrategyInput, params: MaxBorrowParams): bigint;
666
800
  /**
667
801
  * The tail of a delayed route: claim the matured withdrawal, then whatever the
668
802
  * operation that requested it still owes — repaying debt and paying the wallet
@@ -688,4 +822,4 @@ interface IOpportunitiesPrepare {
688
822
  finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<FinalizeResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
689
823
  }
690
824
  //#endregion
691
- export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError };
825
+ export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "17.0.0-next.3",
3
+ "version": "17.0.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,70 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_onchain_utils_AddressMap = require("../../utils/AddressMap.js");
3
- let viem = require("viem");
4
- //#region src/onchain/accounts/utils/midasUtils.ts
5
- const ADAPTER_MIDAS_GATEWAY = "ADAPTER::MIDAS_GATEWAY";
6
- const ADAPTER_MIDAS_ISSUANCE_VAULT = "ADAPTER::MIDAS_ISSUANCE_VAULT";
7
- /**
8
- * Permissionless gateways have no greenlist and reject `receiveGreenlist`,
9
- * see MidasMode in integrations-v3
10
- */
11
- const MIDAS_MODE_PERMISSIONLESS = 0;
12
- const iMidasGatewayAdapterExtAbi = (0, viem.parseAbi)(["function receiveGreenlist() external returns (bool)"]);
13
- const iMidasGatewayModeAbi = (0, viem.parseAbi)(["function mode() external view returns (uint8)"]);
14
- const receiveGreenlistCallData = (0, viem.encodeFunctionData)({
15
- abi: iMidasGatewayAdapterExtAbi,
16
- functionName: "receiveGreenlist"
17
- });
18
- /**
19
- * Prepends `MidasGatewayAdapter.receiveGreenlist()` to a credit facade
20
- * multicall that mints an mToken through a Midas issuance vault.
21
- *
22
- * Permissioned and restricted-interface mTokens can only be held by greenlisted
23
- * accounts, and a freshly opened credit account is never greenlisted, so the
24
- * mint reverts with `WMAC: hasnt role` unless the account asks the gateway for
25
- * the greenlist first. Greenlisting the borrower is not enough — the role is
26
- * checked on the token holder, which is the credit account.
27
- *
28
- * Returns `calls` unchanged when nothing has to be greenlisted: no issuance
29
- * vault is called, its mToken has no gateway adapter on this credit manager,
30
- * the gateway is permissionless, or the call is already there.
31
- */
32
- async function prependMidasReceiveGreenlist(props) {
33
- const { cm, client, calls, logger } = props;
34
- const adapters = Array.from(cm.creditManager.adapters.values());
35
- const gatewayByMToken = require_onchain_utils_AddressMap.AddressMap.fromMappedArray(adapters.filter((a) => a.contractType === ADAPTER_MIDAS_GATEWAY), (a) => a.mToken);
36
- const calledVaults = adapters.filter((a) => a.contractType === ADAPTER_MIDAS_ISSUANCE_VAULT).filter((vault) => calls.some((call) => (0, viem.isAddressEqual)(call.target, vault.address)));
37
- if (gatewayByMToken.size === 0 || calledVaults.length === 0) return calls;
38
- const gateways = new require_onchain_utils_AddressMap.AddressMap();
39
- for (const vault of calledVaults) {
40
- const gateway = gatewayByMToken.get(vault.mToken);
41
- if (!gateway) logger?.debug(`midas: no gateway adapter for mToken ${vault.mToken} minted by ${vault.address} on ${cm.name}, cannot greenlist the credit account`);
42
- else if (calls.some((call) => (0, viem.isAddressEqual)(call.target, gateway.address) && call.callData === receiveGreenlistCallData)) logger?.debug(`midas: gateway adapter ${gateway.address} already receives the greenlist`);
43
- else gateways.upsert(gateway.address, gateway);
44
- }
45
- if (gateways.size === 0) return calls;
46
- const uniqueGateways = gateways.values();
47
- const modes = await client.multicall({
48
- allowFailure: false,
49
- contracts: uniqueGateways.map(({ targetContract }) => ({
50
- address: targetContract,
51
- abi: iMidasGatewayModeAbi,
52
- functionName: "mode"
53
- }))
54
- });
55
- const prepended = [];
56
- for (const [i, gateway] of uniqueGateways.entries()) {
57
- if (modes[i] === MIDAS_MODE_PERMISSIONLESS) {
58
- logger?.debug(`midas: gateway ${gateway.targetContract} is permissionless, nothing to greenlist`);
59
- continue;
60
- }
61
- logger?.debug(`midas: greenlisting the credit account via gateway adapter ${gateway.address}`);
62
- prepended.push({
63
- target: gateway.address,
64
- callData: receiveGreenlistCallData
65
- });
66
- }
67
- return prepended.length > 0 ? [...prepended, ...calls] : calls;
68
- }
69
- //#endregion
70
- exports.prependMidasReceiveGreenlist = prependMidasReceiveGreenlist;