@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,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_constants_math = require("../../constants/math.js");
2
3
  const require_model_errors_operation_errors = require("../../../model/errors/operation-errors.js");
3
4
  const require_model_errors_prepare_errors = require("../../../model/errors/prepare-errors.js");
4
5
  require("../../../model/index.js");
@@ -12,6 +13,7 @@ const require_onchain_accounts_intents_utils_price_impact = require("./utils/pri
12
13
  const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
13
14
  const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
14
15
  const require_onchain_accounts_intents_operations = require("./operations.js");
16
+ const require_onchain_accounts_intents_withdraw_limits = require("./withdraw-limits.js");
15
17
  //#region src/onchain/accounts/intents/realize.ts
16
18
  /**
17
19
  * Turns a plan into operations: the one place that talks to the router, knows
@@ -49,6 +51,7 @@ async function realize(steps, props) {
49
51
  * can revert.
50
52
  */
51
53
  const ledger = new require_onchain_accounts_intents_utils_ledger.OperationLedger(start);
54
+ const opening = ledger.snapshot();
52
55
  /**
53
56
  * The same walk with every routed leg counted at the amount the pathfinder
54
57
  * expects to return. Nothing is built from it: it is where the position
@@ -72,6 +75,26 @@ async function realize(steps, props) {
72
75
  let raised = 0n;
73
76
  /** The request, before the walk's end state can be attached to it. */
74
77
  let delayed;
78
+ /** Oracle value in the underlying of what routed legs and requests spend and return. */
79
+ const traded = {
80
+ spentUnd: 0n,
81
+ returnedUnd: 0n,
82
+ priced: true
83
+ };
84
+ const trade = (spent, returned) => {
85
+ const underlyingValue = (legs) => {
86
+ let sum = 0n;
87
+ for (const { token, amount } of legs) {
88
+ if (amount === 0n) continue;
89
+ const value = price(token, underlying, amount);
90
+ if (value <= 0n) traded.priced = false;
91
+ sum += value;
92
+ }
93
+ return sum;
94
+ };
95
+ traded.spentUnd += underlyingValue(spent);
96
+ traded.returnedUnd += underlyingValue(returned);
97
+ };
75
98
  /**
76
99
  * Set by a `clearQuotas` step, which settles the quotas mid-walk instead of
77
100
  * at the end — and settles them at none, whatever the balances turn out to be.
@@ -173,6 +196,13 @@ async function realize(steps, props) {
173
196
  ...swap,
174
197
  amountOut: leg.amount
175
198
  });
199
+ trade([{
200
+ token: step.from,
201
+ amount
202
+ }], [{
203
+ token: step.to,
204
+ amount: leg.amount
205
+ }]);
176
206
  raised = leg.minAmount;
177
207
  break;
178
208
  }
@@ -198,6 +228,13 @@ async function realize(steps, props) {
198
228
  })),
199
229
  amountOut: leg.amount
200
230
  });
231
+ trade(balances.map((a) => ({
232
+ token: a.token,
233
+ amount: a.balance
234
+ })), [{
235
+ token: underlying,
236
+ amount: leg.amount
237
+ }]);
201
238
  }
202
239
  }
203
240
  raised = ledger.balanceOf(underlying);
@@ -242,6 +279,13 @@ async function realize(steps, props) {
242
279
  amount: require_onchain_accounts_intents_utils_common.toTargetDecimals(queued.amount, queued.token, asset.underlying, sdk)
243
280
  } : void 0
244
281
  };
282
+ trade([{
283
+ token: preview.token,
284
+ amount: preview.amountIn
285
+ }], [...preview.outputs.filter((o) => !o.isDelayed).map((o) => ({
286
+ token: o.token,
287
+ amount: o.amount
288
+ })), ...delayed.claim ? [delayed.claim] : []]);
245
289
  raised = require_onchain_accounts_intents_operations.instantOutput(preview.outputs)?.amount ?? 0n;
246
290
  break;
247
291
  }
@@ -320,19 +364,32 @@ async function realize(steps, props) {
320
364
  totalValue: projected.totalValue
321
365
  };
322
366
  const projection = sdk.positions.projection(snapshot, { availableLiquidityChange: creditAccount.totalDebt - debt });
323
- require_onchain_accounts_intents_guards.assertCollateralised(sdk.positions.healthFactor({
367
+ const settled = {
324
368
  ...snapshot,
325
369
  assets,
326
370
  totalValue: floor.totalValue
327
- }, { safePrices: withdrawsCollateral }), withdrawsCollateral);
371
+ };
372
+ require_onchain_accounts_intents_guards.assertCollateralised(sdk.positions.healthFactor(settled, { safePrices: withdrawsCollateral }), withdrawsCollateral, () => ({
373
+ atMainPrices: sdk.positions.healthFactor(settled, { safePrices: false }),
374
+ withdrawable: require_onchain_validation_helpers_token.toTokenAmount(sdk, underlying, require_onchain_accounts_intents_withdraw_limits.withdrawLimits({
375
+ creditAccount,
376
+ sdk
377
+ }).safePartial)
378
+ }));
328
379
  const priceImpact = await require_onchain_accounts_intents_utils_price_impact.collectPriceImpact(probes, {
329
380
  totalValue: projected.totalValue,
330
- netValue: projected.totalValue - debt,
331
- toUnderlying: (from, amount) => price(from, underlying, amount)
381
+ netValue: opening.totalValue - opening.debt,
382
+ toUnderlying: (from, amount) => price(from, underlying, amount),
383
+ toUnderlyingAmount: market.toUnderlyingAmount
332
384
  });
385
+ const executionCost = traded.priced && traded.spentUnd > 0n ? {
386
+ amount: market.toUnderlyingAmount(traded.returnedUnd - traded.spentUnd),
387
+ rate: require_onchain_constants_math.PERCENTAGE_FACTOR_1KK * (traded.returnedUnd - traded.spentUnd) / traded.spentUnd
388
+ } : void 0;
333
389
  const state = {
334
390
  ...projection,
335
391
  priceImpact,
392
+ executionCost,
336
393
  currentPrice: sdk.positions.currentPrice(snapshot)
337
394
  };
338
395
  return {
@@ -8,8 +8,8 @@ const require_onchain_accounts_intents_utils_common = require("./utils/common.js
8
8
  const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
9
9
  const require_onchain_accounts_intents_plan = require("./plan.js");
10
10
  const require_onchain_accounts_intents_operations = require("./operations.js");
11
- const require_onchain_accounts_intents_realize = require("./realize.js");
12
11
  const require_onchain_accounts_intents_view = require("./view.js");
12
+ const require_onchain_accounts_intents_realize = require("./realize.js");
13
13
  //#region src/onchain/accounts/intents/tail.ts
14
14
  /**
15
15
  * The second half of a delayed intent: the claim, then whatever the intent
@@ -203,6 +203,7 @@ function buildMockSdk(args) {
203
203
  liquidationThresholds,
204
204
  collateralTokens,
205
205
  feeInterest: args.feeInterest ?? 0,
206
+ maxEnabledTokens: args.maxEnabledTokens ?? 4,
206
207
  maxLeverage: (collateral, targetHF) => require_onchain_market_math.calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0, targetHF)
207
208
  },
208
209
  creditFacade: {
@@ -3,6 +3,24 @@ const require_onchain_utils_AddressMap = require("../../../utils/AddressMap.js")
3
3
  //#region src/onchain/accounts/intents/utils/common.ts
4
4
  /** Case-insensitive address equality. */
5
5
  const eq = (a, b) => a.toLowerCase() === b.toLowerCase();
6
+ /**
7
+ * The suite and market behind a credit manager, or nothing where the register
8
+ * has no entry for it.
9
+ *
10
+ * For the reads a form calls on every keystroke, including before the SDK has
11
+ * finished attaching: a question the register cannot answer yet is not an
12
+ * error. Everything that prepares a transaction wants the throw instead.
13
+ */
14
+ function resolveCreditManager(sdk, creditManager) {
15
+ try {
16
+ return {
17
+ suite: sdk.marketRegister.findCreditManager(creditManager),
18
+ market: sdk.marketRegister.findByCreditManager(creditManager)
19
+ };
20
+ } catch {
21
+ return;
22
+ }
23
+ }
6
24
  function toTargetDecimals(fromAmount, fromToken, toToken, sdk) {
7
25
  const fromDecimals = sdk.tokensMeta.get(fromToken)?.decimals ?? 18;
8
26
  const toDecimals = sdk.tokensMeta.get(toToken)?.decimals ?? 18;
@@ -39,5 +57,6 @@ function toRouterCaSlice(creditAccount, expectedBalances = []) {
39
57
  }
40
58
  //#endregion
41
59
  exports.eq = eq;
60
+ exports.resolveCreditManager = resolveCreditManager;
42
61
  exports.toRouterCaSlice = toRouterCaSlice;
43
62
  exports.toTargetDecimals = toTargetDecimals;
@@ -27,6 +27,26 @@ function toCreditAccountSlice(ca) {
27
27
  };
28
28
  }
29
29
  /**
30
+ * The slice a flow that has no account yet quotes against.
31
+ *
32
+ * Nothing of it exists on chain until the transaction lands, and nothing has
33
+ * to: the pathfinder is asked about the credit manager, and every balance the
34
+ * flow reasons about is one the transaction itself puts there. The zero
35
+ * address stands in for the account so the shape is complete.
36
+ */
37
+ function unopenedAccountSlice(args) {
38
+ return {
39
+ creditAccount: "0x0000000000000000000000000000000000000000",
40
+ creditManager: args.creditManager.toLowerCase(),
41
+ creditFacade: args.creditFacade.toLowerCase(),
42
+ underlying: args.underlying.toLowerCase(),
43
+ enabledTokensMask: 0n,
44
+ totalDebtUSD: 0n,
45
+ totalDebt: 0n,
46
+ tokens: []
47
+ };
48
+ }
49
+ /**
30
50
  * Reads an account by address and narrows it to {@link CreditAccountSlice}.
31
51
  *
32
52
  * The shared read model's `StrategyPosition` carries neither `tokens` nor
@@ -43,3 +63,4 @@ async function fetchCreditAccountSlice(sdk, creditAccount) {
43
63
  //#endregion
44
64
  exports.fetchCreditAccountSlice = fetchCreditAccountSlice;
45
65
  exports.toCreditAccountSlice = toCreditAccountSlice;
66
+ exports.unopenedAccountSlice = unopenedAccountSlice;
@@ -26,7 +26,9 @@ exports.lossRate = require_onchain_accounts_intents_utils_price_impact.lossRate;
26
26
  exports.pickFattestNonPhantomToken = require_onchain_accounts_intents_utils_pick_token.pickFattestNonPhantomToken;
27
27
  exports.quotasAfterUpdate = require_onchain_accounts_intents_utils_quotas_for_update.quotasAfterUpdate;
28
28
  exports.rankAccountTokens = require_onchain_accounts_intents_utils_pick_token.rankAccountTokens;
29
+ exports.resolveCreditManager = require_onchain_accounts_intents_utils_common.resolveCreditManager;
29
30
  exports.startProbe = require_onchain_accounts_intents_utils_price_impact.startProbe;
30
31
  exports.toCreditAccountSlice = require_onchain_accounts_intents_utils_credit_account_slice.toCreditAccountSlice;
31
32
  exports.toRouterCaSlice = require_onchain_accounts_intents_utils_common.toRouterCaSlice;
32
33
  exports.toTargetDecimals = require_onchain_accounts_intents_utils_common.toTargetDecimals;
34
+ exports.unopenedAccountSlice = require_onchain_accounts_intents_utils_credit_account_slice.unopenedAccountSlice;
@@ -19,12 +19,12 @@ function probeBasket(balances, oracle) {
19
19
  if (usd > 0n) basketWad += usd * require_onchain_constants_math.WAD / require_onchain_constants_math.PRICE_DECIMALS;
20
20
  }
21
21
  if (basketWad <= 0n) return;
22
- const probeWad = PROBE_UNIT_USD_WAD;
23
22
  const scaled = balances.map((asset) => ({
24
23
  token: asset.token,
25
- balance: asset.balance * probeWad / basketWad
24
+ balance: asset.balance * PROBE_UNIT_USD_WAD / basketWad
26
25
  }));
27
- if (!scaled.some((a) => a.balance > 0n)) return;
26
+ const probeWad = scaled.reduce((sum, a) => sum + oracle.safeConvertToUSD(a.token, a.balance).value * require_onchain_constants_math.WAD / require_onchain_constants_math.PRICE_DECIMALS, 0n);
27
+ if (probeWad <= 0n) return;
28
28
  return {
29
29
  balances: scaled,
30
30
  basketWad,
@@ -86,12 +86,15 @@ async function collectPriceImpact(probes, ctx) {
86
86
  lossUnd += loss;
87
87
  }
88
88
  if (expectedUnd <= 0n) return;
89
- return lossRate({
90
- lossUnd,
91
- expectedUnd,
92
- totalValue: ctx.totalValue,
93
- netValue: ctx.netValue
94
- });
89
+ return {
90
+ ...lossRate({
91
+ lossUnd,
92
+ expectedUnd,
93
+ totalValue: ctx.totalValue,
94
+ netValue: ctx.netValue
95
+ }),
96
+ absolutePriceImpact: ctx.toUnderlyingAmount(-lossUnd)
97
+ };
95
98
  }
96
99
  //#endregion
97
100
  exports.collectPriceImpact = collectPriceImpact;
@@ -3,11 +3,8 @@ const require_onchain_accounts_intents_utils_common = require("./common.js");
3
3
  const require_onchain_accounts_intents_utils_price_impact = require("./price-impact.js");
4
4
  //#region src/onchain/accounts/intents/utils/router-path.ts
5
5
  /**
6
- * The engine's only door to the pathfinder.
7
- *
8
- * Deliberately not a quoter abstraction with an oracle-priced twin: paths are
9
- * always resolved on-chain, because a preview whose swap amounts came from
10
- * oracle prices could not produce the calldata that realises them.
6
+ * The engine's only door to the pathfinder, and the only quoter whose legs can
7
+ * be sent. {@link createOraclePaths} is the twin for a walk that only projects.
11
8
  */
12
9
  function createRouterPaths(args) {
13
10
  const { sdk, creditAccount, slippage } = args;
@@ -92,6 +89,7 @@ function createRouterPaths(args) {
92
89
  amount,
93
90
  keep
94
91
  });
92
+ if (leg.calls.length === 0) throw new Error("swap: missing router calls");
95
93
  return {
96
94
  ...leg,
97
95
  probe: probe && {
@@ -108,6 +106,7 @@ function createRouterPaths(args) {
108
106
  route: async (quoted) => (await quoteClose(quoted)).amount
109
107
  });
110
108
  const { amount, minAmount, calls } = await quoteClose(balances);
109
+ if (calls.length === 0 && minAmount > 0n) throw new Error("closeAll: missing router calls");
111
110
  const leg = {
112
111
  amount,
113
112
  minAmount,
@@ -0,0 +1,97 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
3
+ require("../../utils/index.js");
4
+ const require_onchain_validation_helpers_health_factor_limits = require("../../validation/helpers/health-factor-limits.js");
5
+ require("../../validation/index.js");
6
+ const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
7
+ const require_onchain_accounts_intents_math = require("./math.js");
8
+ const require_onchain_accounts_intents_collateral_valuation = require("./collateral-valuation.js");
9
+ const require_onchain_accounts_intents_view = require("./view.js");
10
+ //#region src/onchain/accounts/intents/withdraw-limits.ts
11
+ /**
12
+ * Every limit a `WITHDRAW` answers to, in underlying units.
13
+ *
14
+ * The one place they are assembled, so the figure a form is offered and the
15
+ * figure the collateral guard names when it turns a withdrawal down cannot
16
+ * drift apart: `CreditAccountOperationsService` reports this, and the guard
17
+ * quotes it back.
18
+ *
19
+ * @param props - Account slice, the SDK holding its market, and optionally the
20
+ * collateral the withdrawal would be funded from
21
+ * @returns The three limits, see {@link WithdrawCeilings}
22
+ **/
23
+ function withdrawLimits(props) {
24
+ const { creditAccount, sdk } = props;
25
+ const view = require_onchain_accounts_intents_view.accountView(creditAccount, sdk);
26
+ const partial = require_onchain_accounts_intents_math.maxProportionalWithdrawal(view, view.debtLimits);
27
+ const safe = maxSafeWithdrawal({
28
+ ...props,
29
+ targetHF: BigInt(require_onchain_validation_helpers_health_factor_limits.MIN_HEALTH_FACTOR_FACADE)
30
+ });
31
+ return {
32
+ partial,
33
+ safePartial: require_onchain_utils_bigint_math.BigIntMath.min(partial, safe),
34
+ exit: view.collateral > 0n ? view.collateral : 0n
35
+ };
36
+ }
37
+ /**
38
+ * Largest proportional withdrawal the safe-price collateral check still clears,
39
+ * in underlying units.
40
+ *
41
+ * A withdrawal hands funds over, so the facade weighs the account it leaves
42
+ * behind at safe prices rather than main ones — see {@link collateralValuation}.
43
+ * That is a second limit on top of the facade's `debtLimits`, and the two are
44
+ * independent: a caller wanting the amount a form may actually offer takes the
45
+ * lesser of this and `maxProportionalWithdrawal`.
46
+ *
47
+ * The arithmetic is the check solved for the amount. Taking `W` out at fixed
48
+ * leverage repays `dD = D·W/C`, so `W·TVL/C` of value is sold out of the source
49
+ * token; each dollar of that sale costs the check the source's threshold times
50
+ * its safe-to-main price ratio, while the repayment relieves `targetHF` per
51
+ * dollar of debt. Both terms are linear in `W`, which is why one division
52
+ * answers instead of a search — and why the answer is exact rather than a
53
+ * bound, as long as the plan really does fund itself from `sourceToken`.
54
+ *
55
+ * Two consequences worth stating, because they surprise:
56
+ *
57
+ * - An account whose collateral is entirely a token the reserve feed marks
58
+ * down cannot withdraw at all once it is under the threshold. A proportional
59
+ * withdrawal scales collateral and debt together, so it leaves the safe-price
60
+ * factor exactly where it found it — no amount climbs back over.
61
+ * - Leaving entirely is never refused for this reason: the exit settles the
62
+ * debt instead of shrinking it, and a check with no debt to divide by has
63
+ * nothing to refuse.
64
+ *
65
+ * @returns Amount in underlying units. The account's net value when safe prices
66
+ * do not limit the withdrawal at all, so the caller's `min` is a no-op; `0n`
67
+ * when the account already sits below `targetHF` at safe prices, and only the
68
+ * exit is left
69
+ **/
70
+ function maxSafeWithdrawal(props) {
71
+ const { creditAccount, sdk, targetHF } = props;
72
+ const view = require_onchain_accounts_intents_view.accountView(creditAccount, sdk);
73
+ if (view.collateral <= 0n) return 0n;
74
+ if (view.debt === 0n) return view.collateral;
75
+ const valuation = require_onchain_accounts_intents_collateral_valuation.collateralValuation(creditAccount, sdk);
76
+ const source = props.sourceToken ?? view.fattest();
77
+ const holding = source === void 0 ? void 0 : creditAccount.tokens.find((t) => require_onchain_accounts_intents_utils_common.eq(t.token, source));
78
+ if (!holding) return view.collateral;
79
+ let total = 0n;
80
+ for (const t of creditAccount.tokens) if (valuation.counts(t)) total += valuation.weigh(t);
81
+ const debtUsd = valuation.mainUsd(valuation.underlying, view.debt);
82
+ if (debtUsd === void 0 || debtUsd <= 0n) return view.collateral;
83
+ const slack = total - debtUsd * targetHF;
84
+ if (slack < 0n) return 0n;
85
+ const sourceMainUsd = valuation.mainUsd(holding.token, holding.balance);
86
+ if (sourceMainUsd === void 0 || sourceMainUsd <= 0n) return view.collateral;
87
+ const sourceRate = valuation.lt(holding.token) * valuation.checkedUsd(holding);
88
+ const tvlUsd = valuation.mainUsd(valuation.underlying, view.collateral + view.debt);
89
+ if (tvlUsd === void 0) return view.collateral;
90
+ const drain = sourceRate * tvlUsd - targetHF * debtUsd * sourceMainUsd;
91
+ if (drain <= 0n) return view.collateral;
92
+ const limit = view.collateral * slack * sourceMainUsd / drain;
93
+ return limit < view.collateral ? limit : view.collateral;
94
+ }
95
+ //#endregion
96
+ exports.maxSafeWithdrawal = maxSafeWithdrawal;
97
+ exports.withdrawLimits = withdrawLimits;
@@ -10,9 +10,9 @@ require("../../utils/index.js");
10
10
  const require_onchain_base_SDKConstruct = require("../../base/SDKConstruct.js");
11
11
  require("../../base/index.js");
12
12
  const require_onchain_market_math = require("../../market/math.js");
13
+ const require_onchain_market_rwa_midas_constants = require("../../market/rwa/midas/constants.js");
13
14
  const require_model_liquidations = require("../../../model/liquidations.js");
14
15
  require("../../../model/index.js");
15
- const require_onchain_market_rwa_midas_constants = require("../../market/rwa/midas/constants.js");
16
16
  const require_onchain_market_rwa_securitize_constants = require("../../market/rwa/securitize/constants.js");
17
17
  const require_onchain_market_credit_collateralUtils = require("../../market/credit/collateralUtils.js");
18
18
  const require_onchain_market_rwa_midas_MidasLiquidatorContract = require("../../market/rwa/midas/MidasLiquidatorContract.js");
@@ -33,7 +33,6 @@ const AP_WETH_GATEWAY = "WETH_GATEWAY";
33
33
  const AP_WETH_TOKEN = "WETH_TOKEN";
34
34
  const AP_ZAPPER_REGISTER = "ZAPPER_REGISTER";
35
35
  const AP_ZERO_PRICE_FEED = "ZERO_PRICE_FEED";
36
- const AP_RWA_COMPRESSOR = "GLOBAL::RWA_COMPRESSOR";
37
36
  const AP_REDEMPTION_LOGGER = "LOCAL::REDEMPTION_LOGGER";
38
37
  /**
39
38
  * Default address provider address for v3.1.0
@@ -69,7 +68,6 @@ exports.AP_PRICE_ORACLE = AP_PRICE_ORACLE;
69
68
  exports.AP_REDEMPTION_LOGGER = AP_REDEMPTION_LOGGER;
70
69
  exports.AP_REWARDS_COMPRESSOR = AP_REWARDS_COMPRESSOR;
71
70
  exports.AP_ROUTER = AP_ROUTER;
72
- exports.AP_RWA_COMPRESSOR = AP_RWA_COMPRESSOR;
73
71
  exports.AP_TOKEN_COMPRESSOR = AP_TOKEN_COMPRESSOR;
74
72
  exports.AP_TREASURY = AP_TREASURY;
75
73
  exports.AP_WETH_GATEWAY = AP_WETH_GATEWAY;
@@ -35,7 +35,6 @@ exports.AP_PRICE_ORACLE = require_onchain_constants_address_provider.AP_PRICE_OR
35
35
  exports.AP_REDEMPTION_LOGGER = require_onchain_constants_address_provider.AP_REDEMPTION_LOGGER;
36
36
  exports.AP_REWARDS_COMPRESSOR = require_onchain_constants_address_provider.AP_REWARDS_COMPRESSOR;
37
37
  exports.AP_ROUTER = require_onchain_constants_address_provider.AP_ROUTER;
38
- exports.AP_RWA_COMPRESSOR = require_onchain_constants_address_provider.AP_RWA_COMPRESSOR;
39
38
  exports.AP_TOKEN_COMPRESSOR = require_onchain_constants_address_provider.AP_TOKEN_COMPRESSOR;
40
39
  exports.AP_TREASURY = require_onchain_constants_address_provider.AP_TREASURY;
41
40
  exports.AP_WETH_GATEWAY = require_onchain_constants_address_provider.AP_WETH_GATEWAY;
@@ -1,15 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_abi_iVersion = require("../../abi/iVersion.js");
3
- const require_onchain_constants_address_provider = require("../constants/address-provider.js");
3
+ require("../constants/address-provider.js");
4
4
  const require_onchain_constants_versions = require("../constants/versions.js");
5
5
  require("../constants/index.js");
6
6
  const require_onchain_utils_hex = require("../utils/hex.js");
7
7
  const require_onchain_core_AddressProviderV310Contract = require("./AddressProviderV310Contract.js");
8
8
  //#region src/onchain/core/createAddressProvider.ts
9
- const OVERRIDE_ADDRESSES = { Mainnet: {
10
- [require_onchain_constants_address_provider.AP_PRICE_FEED_COMPRESSOR]: { 311: "0x1fA2637B9fab0CD14290A7EE908DDc9688a15120" },
11
- [require_onchain_constants_address_provider.AP_MARKET_COMPRESSOR]: { 311: "0x0C27F242f6e9F2A9AD3261bE6e439De3B948bcA2" }
12
- } };
9
+ const OVERRIDE_ADDRESSES = {};
13
10
  async function createAddressProvider(sdk, address) {
14
11
  let v;
15
12
  if (require_onchain_utils_hex.hexEq(address, "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38")) v = 310n;