@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.4

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 (277) hide show
  1. package/MIGRATION-v5-to-v6.md +88 -32
  2. package/README.md +9 -7
  3. package/lib/cjs/abis.d.ts +7 -2844
  4. package/lib/cjs/abis.js +3 -1951
  5. package/lib/cjs/actions/blue/borrow.d.ts +3 -2
  6. package/lib/cjs/actions/blue/borrow.js +3 -2
  7. package/lib/cjs/actions/blue/common.js +1 -9
  8. package/lib/cjs/actions/blue/refinance.d.ts +2 -2
  9. package/lib/cjs/actions/blue/refinance.js +2 -2
  10. package/lib/cjs/actions/blue/repay.d.ts +1 -1
  11. package/lib/cjs/actions/blue/repay.js +1 -1
  12. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
  14. package/lib/cjs/actions/blue/supply.d.ts +2 -2
  15. package/lib/cjs/actions/blue/supply.js +2 -2
  16. package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
  18. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
  20. package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
  21. package/lib/cjs/actions/blue/withdraw.js +3 -3
  22. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
  23. package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
  24. package/lib/cjs/actions/bundles/common.d.ts +6 -2
  25. package/lib/cjs/actions/bundles/common.js +31 -5
  26. package/lib/cjs/actions/index.d.ts +0 -1
  27. package/lib/cjs/actions/index.js +0 -1
  28. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
  29. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
  30. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  31. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  32. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  33. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
  34. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  35. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
  36. package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
  37. package/lib/cjs/actions/requirements/encode/index.js +0 -1
  38. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
  39. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
  40. package/lib/cjs/actions/requirements/index.d.ts +0 -1
  41. package/lib/cjs/actions/requirements/index.js +0 -1
  42. package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
  43. package/lib/cjs/actions/vaultV1/deposit.js +1 -2
  44. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +7 -5
  45. package/lib/cjs/actions/vaultV1/inKindRedeem.js +11 -7
  46. package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
  47. package/lib/cjs/actions/vaultV2/deposit.js +1 -2
  48. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  49. package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
  50. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +7 -5
  51. package/lib/cjs/actions/vaultV2/inKindRedeem.js +11 -7
  52. package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
  53. package/lib/cjs/augment.d.ts +0 -1
  54. package/lib/cjs/augment.js +0 -1
  55. package/lib/cjs/blue/abis.d.ts +5 -5
  56. package/lib/cjs/blue/abis.js +3 -7
  57. package/lib/cjs/blue/entities.d.ts +10 -8
  58. package/lib/cjs/blue/entities.js +3 -3
  59. package/lib/cjs/blue/errors.d.ts +4 -2
  60. package/lib/cjs/blue/errors.js +3 -1
  61. package/lib/cjs/blue/fetch.d.ts +5 -3
  62. package/lib/cjs/blue/fetch.js +3 -3
  63. package/lib/cjs/blue/types.d.ts +2 -4
  64. package/lib/cjs/blue/utils.d.ts +6 -4
  65. package/lib/cjs/blue/utils.js +3 -3
  66. package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
  67. package/lib/cjs/client/morphoViemExtension.js +1 -1
  68. package/lib/cjs/constants.d.ts +3 -37
  69. package/lib/cjs/constants.js +1 -39
  70. package/lib/cjs/entities/blue/blue.d.ts +30 -265
  71. package/lib/cjs/entities/blue/blue.js +1 -205
  72. package/lib/cjs/entities/index.d.ts +11 -66
  73. package/lib/cjs/entities/index.js +3 -21
  74. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  75. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  76. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +13 -5
  77. package/lib/cjs/entities/vaultV1/vaultV1.js +16 -10
  78. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -19
  79. package/lib/cjs/entities/vaultV2/vaultV2.js +57 -26
  80. package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
  81. package/lib/cjs/errors.d.ts +5 -47
  82. package/lib/cjs/errors.js +4 -46
  83. package/lib/cjs/fetch.d.ts +5 -17
  84. package/lib/cjs/fetch.js +3 -17
  85. package/lib/cjs/helpers/constant.d.ts +0 -2
  86. package/lib/cjs/helpers/constant.js +0 -2
  87. package/lib/cjs/helpers/index.d.ts +2 -3
  88. package/lib/cjs/helpers/index.js +1 -9
  89. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +11 -5
  90. package/lib/cjs/helpers/slippage.d.ts +1 -103
  91. package/lib/cjs/helpers/slippage.js +0 -150
  92. package/lib/cjs/helpers/utilization.d.ts +12 -10
  93. package/lib/cjs/helpers/utilization.js +27 -12
  94. package/lib/cjs/helpers/validate.d.ts +1 -24
  95. package/lib/cjs/helpers/validate.js +2 -49
  96. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  97. package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
  98. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  99. package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  100. package/lib/cjs/midnight/errors.d.ts +1 -1
  101. package/lib/cjs/midnight/errors.js +2 -1
  102. package/lib/cjs/types/action.d.ts +17 -65
  103. package/lib/cjs/types/action.js +11 -4
  104. package/lib/cjs/types/error.d.ts +50 -381
  105. package/lib/cjs/types/error.js +64 -395
  106. package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
  107. package/lib/cjs/types.d.ts +2 -18
  108. package/lib/cjs/utils.d.ts +10 -35
  109. package/lib/cjs/utils.js +4 -36
  110. package/lib/esm/abis.d.ts +7 -2844
  111. package/lib/esm/abis.js +7 -1950
  112. package/lib/esm/actions/blue/borrow.d.ts +3 -2
  113. package/lib/esm/actions/blue/borrow.js +3 -2
  114. package/lib/esm/actions/blue/common.js +1 -9
  115. package/lib/esm/actions/blue/refinance.d.ts +2 -2
  116. package/lib/esm/actions/blue/refinance.js +2 -2
  117. package/lib/esm/actions/blue/repay.d.ts +1 -1
  118. package/lib/esm/actions/blue/repay.js +1 -1
  119. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
  120. package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
  121. package/lib/esm/actions/blue/supply.d.ts +2 -2
  122. package/lib/esm/actions/blue/supply.js +2 -2
  123. package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
  124. package/lib/esm/actions/blue/supplyCollateral.js +2 -2
  125. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
  126. package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
  127. package/lib/esm/actions/blue/withdraw.d.ts +3 -3
  128. package/lib/esm/actions/blue/withdraw.js +3 -3
  129. package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
  130. package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
  131. package/lib/esm/actions/bundles/common.d.ts +6 -2
  132. package/lib/esm/actions/bundles/common.js +32 -6
  133. package/lib/esm/actions/index.d.ts +0 -1
  134. package/lib/esm/actions/index.js +0 -1
  135. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
  136. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
  137. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
  138. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
  139. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
  140. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
  141. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
  142. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
  143. package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
  144. package/lib/esm/actions/requirements/encode/index.js +0 -1
  145. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
  146. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
  147. package/lib/esm/actions/requirements/index.d.ts +0 -1
  148. package/lib/esm/actions/requirements/index.js +0 -1
  149. package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
  150. package/lib/esm/actions/vaultV1/deposit.js +1 -2
  151. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +7 -5
  152. package/lib/esm/actions/vaultV1/inKindRedeem.js +11 -7
  153. package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
  154. package/lib/esm/actions/vaultV2/deposit.js +1 -2
  155. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  156. package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
  157. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +7 -5
  158. package/lib/esm/actions/vaultV2/inKindRedeem.js +11 -7
  159. package/lib/esm/augment/AccrualPosition.d.ts +1 -0
  160. package/lib/esm/augment.d.ts +0 -1
  161. package/lib/esm/augment.js +0 -1
  162. package/lib/esm/blue/abis.d.ts +5 -5
  163. package/lib/esm/blue/abis.js +5 -5
  164. package/lib/esm/blue/entities.d.ts +10 -8
  165. package/lib/esm/blue/entities.js +5 -3
  166. package/lib/esm/blue/errors.d.ts +4 -2
  167. package/lib/esm/blue/errors.js +4 -2
  168. package/lib/esm/blue/fetch.d.ts +5 -3
  169. package/lib/esm/blue/fetch.js +5 -3
  170. package/lib/esm/blue/types.d.ts +2 -4
  171. package/lib/esm/blue/utils.d.ts +6 -4
  172. package/lib/esm/blue/utils.js +6 -4
  173. package/lib/esm/client/morphoViemExtension.d.ts +1 -1
  174. package/lib/esm/client/morphoViemExtension.js +1 -1
  175. package/lib/esm/constants.d.ts +3 -37
  176. package/lib/esm/constants.js +3 -37
  177. package/lib/esm/entities/blue/blue.d.ts +30 -265
  178. package/lib/esm/entities/blue/blue.js +4 -208
  179. package/lib/esm/entities/index.d.ts +11 -66
  180. package/lib/esm/entities/index.js +5 -18
  181. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
  182. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
  183. package/lib/esm/entities/vaultV1/vaultV1.d.ts +13 -5
  184. package/lib/esm/entities/vaultV1/vaultV1.js +19 -13
  185. package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -19
  186. package/lib/esm/entities/vaultV2/vaultV2.js +61 -30
  187. package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
  188. package/lib/esm/errors.d.ts +5 -47
  189. package/lib/esm/errors.js +5 -47
  190. package/lib/esm/fetch.d.ts +5 -17
  191. package/lib/esm/fetch.js +5 -17
  192. package/lib/esm/helpers/constant.d.ts +0 -2
  193. package/lib/esm/helpers/constant.js +0 -2
  194. package/lib/esm/helpers/index.d.ts +2 -3
  195. package/lib/esm/helpers/index.js +2 -3
  196. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +11 -5
  197. package/lib/esm/helpers/slippage.d.ts +1 -103
  198. package/lib/esm/helpers/slippage.js +1 -147
  199. package/lib/esm/helpers/utilization.d.ts +12 -10
  200. package/lib/esm/helpers/utilization.js +26 -11
  201. package/lib/esm/helpers/validate.d.ts +1 -24
  202. package/lib/esm/helpers/validate.js +2 -48
  203. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  204. package/lib/esm/helpers/validateRequirementSpender.js +1 -3
  205. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
  206. package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
  207. package/lib/esm/midnight/errors.d.ts +1 -1
  208. package/lib/esm/midnight/errors.js +1 -1
  209. package/lib/esm/types/action.d.ts +17 -65
  210. package/lib/esm/types/action.js +12 -5
  211. package/lib/esm/types/error.d.ts +50 -381
  212. package/lib/esm/types/error.js +58 -377
  213. package/lib/esm/types/sharedLiquidity.d.ts +1 -117
  214. package/lib/esm/types.d.ts +2 -18
  215. package/lib/esm/utils.d.ts +10 -35
  216. package/lib/esm/utils.js +9 -34
  217. package/package.json +6 -17
  218. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  219. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
  220. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  221. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
  222. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  223. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
  224. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  225. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
  226. package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
  227. package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
  228. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  229. package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
  230. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  231. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
  232. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  233. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
  234. package/lib/cjs/actions/signatures/index.d.ts +0 -3
  235. package/lib/cjs/actions/signatures/index.js +0 -19
  236. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  237. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
  238. package/lib/cjs/bundler/actions.d.ts +0 -797
  239. package/lib/cjs/bundler/actions.js +0 -1371
  240. package/lib/cjs/bundler/index.d.ts +0 -2
  241. package/lib/cjs/bundler/index.js +0 -18
  242. package/lib/cjs/bundler/types.d.ts +0 -235
  243. package/lib/cjs/bundler/types.js +0 -2
  244. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
  245. package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
  246. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
  247. package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
  248. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
  249. package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
  250. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
  251. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
  252. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
  253. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
  254. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
  255. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
  256. package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
  257. package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
  258. package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
  259. package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
  260. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
  261. package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
  262. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
  263. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
  264. package/lib/esm/actions/signatures/index.d.ts +0 -3
  265. package/lib/esm/actions/signatures/index.js +0 -3
  266. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
  267. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
  268. package/lib/esm/bundler/actions.d.ts +0 -797
  269. package/lib/esm/bundler/actions.js +0 -1368
  270. package/lib/esm/bundler/index.d.ts +0 -2
  271. package/lib/esm/bundler/index.js +0 -2
  272. package/lib/esm/bundler/types.d.ts +0 -235
  273. package/lib/esm/bundler/types.js +0 -1
  274. package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
  275. package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
  276. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
  277. package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
@@ -1,13 +1,12 @@
1
1
  import { MathLib, } from "@morpho-org/blue-sdk";
2
- import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchPosition, fetchVault, fetchVaultMarketConfig, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
2
+ import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
3
3
  import { getChainAddress, Time } from "@morpho-org/morpho-ts";
4
- import { getAddress, isAddressEqual, maxUint256 } from "viem";
4
+ import { isAddressEqual, maxUint256 } from "viem";
5
5
  import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
6
6
  import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
7
- import { computeVaultV1Reallocations, DEFAULT_LLTV_BUFFER, MAX_TOKEN_APPROVALS, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
7
+ import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
8
8
  import { ExpiredDeadlineError, InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
9
9
  import { getBundlesTokenRequirements } from "../requirements/index.js";
10
- import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
11
10
  import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
12
11
  export class MorphoBlue {
13
12
  client;
@@ -78,7 +77,6 @@ export class MorphoBlue {
78
77
  validateChainId(this.client.viemClient.chain?.id, this.chainId);
79
78
  return fetchMarket(this.marketParams.id, this.client.viemClient, {
80
79
  ...parameters,
81
- chainId: this.chainId,
82
80
  deployless: this.client.options.supportDeployless,
83
81
  });
84
82
  }
@@ -87,7 +85,6 @@ export class MorphoBlue {
87
85
  return fetchAccrualPosition(userAddress, this.marketParams.id, this.client.viemClient, {
88
86
  ...parameters,
89
87
  deployless: this.client.options.supportDeployless,
90
- chainId: this.chainId,
91
88
  });
92
89
  }
93
90
  /** {@inheritDoc BlueActions.supply} */
@@ -438,14 +435,7 @@ export class MorphoBlue {
438
435
  ? this.getTokenRequirements({
439
436
  token: this.marketParams.loanToken,
440
437
  amount: maxRepayAssets,
441
- // A caller-requested reusable approval wins; a full repay otherwise defaults to
442
- // the token's reusable cap. Checksum the key so a differently-cased loan token
443
- // (common from subgraphs/APIs) resolves that cap instead of falling back to
444
- // maxUint256, which UNI/ONDO/COMP/FLUID reject.
445
- approvalAmount: requirementsParams?.approvalAmount ??
446
- (saturatedRepay
447
- ? (MAX_TOKEN_APPROVALS[this.chainId]?.[getAddress(this.marketParams.loanToken)] ?? maxUint256)
448
- : undefined),
438
+ approvalAmount: requirementsParams?.approvalAmount,
449
439
  userAddress,
450
440
  deadline,
451
441
  useSimplePermit: requirementsParams?.useSimplePermit,
@@ -659,120 +649,6 @@ export class MorphoBlue {
659
649
  },
660
650
  };
661
651
  }
662
- /**
663
- * Fetches all on-chain inputs needed to compute public allocator reallocations.
664
- *
665
- * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
666
- * @param params.block.number - Block number used for every RPC read.
667
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
668
- * @returns Reallocation data ready for {@link getVaultV1Reallocations}.
669
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
670
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
671
- * {@link getVaultV2BlueReallocationData}.
672
- * @example
673
- * ```ts
674
- * import { markets, vaults } from "@morpho-org/morpho-test";
675
- * import { createPublicClient, http } from "viem";
676
- * import { mainnet } from "viem/chains";
677
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
678
- * import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
679
- *
680
- * const client = createPublicClient({ chain: mainnet, transport: http() })
681
- * .extend(morphoViemExtension());
682
- * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
683
- * const block = await client.getBlock();
684
- * const data: VaultV1ReallocationData = await market.getVaultV1ReallocationData({
685
- * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
686
- * block,
687
- * });
688
- * ```
689
- */
690
- async getVaultV1ReallocationData({ vaultAddresses, block, }) {
691
- validateChainId(this.client.viemClient.chain?.id, this.chainId);
692
- const client = this.client.viemClient;
693
- const fetchParams = {
694
- blockNumber: block.number,
695
- chainId: this.chainId,
696
- deployless: this.client.options.supportDeployless,
697
- };
698
- const targetMarketId = this.marketParams.id;
699
- // Phase 1: Fetch the target market and all vaults at `block.number` in
700
- // parallel so every row of the resulting state comes from the same epoch
701
- // and the planner never trusts a caller-owned target-market snapshot.
702
- const [targetMarket, vaults] = await Promise.all([
703
- fetchMarket(targetMarketId, client, fetchParams),
704
- Promise.all(vaultAddresses.map((addr) => fetchVault(addr, client, fetchParams))),
705
- ]);
706
- const allMarketIds = new Set([targetMarketId]);
707
- const vaultMarketPairs = [];
708
- for (const vault of vaults) {
709
- // Always include target market pair so its config/position is fetched
710
- // even when the target market is only in the vault's supplyQueue.
711
- vaultMarketPairs.push({ vault: vault.address, marketId: targetMarketId });
712
- for (const mid of vault.withdrawQueue) {
713
- allMarketIds.add(mid);
714
- if (mid !== targetMarketId) {
715
- vaultMarketPairs.push({ vault: vault.address, marketId: mid });
716
- }
717
- }
718
- }
719
- // Phase 2: Fetch all source markets, vault configs, and positions in parallel.
720
- const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
721
- const [markets, configs, positions] = await Promise.all([
722
- Promise.all(sourceMarketIds.map((mid) => fetchMarket(mid, client, fetchParams))),
723
- Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchVaultMarketConfig(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
724
- Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchPosition(vault, mid, client, fetchParams).then((position) => ({
725
- vault,
726
- mid,
727
- position,
728
- })))),
729
- ]);
730
- // Assemble records for VaultV1ReallocationData.
731
- const marketsRecord = {
732
- [targetMarketId]: targetMarket,
733
- };
734
- for (const m of markets) {
735
- marketsRecord[m.id] = m;
736
- }
737
- const vaultsRecord = {};
738
- for (const v of vaults) {
739
- vaultsRecord[v.address] = v;
740
- }
741
- const vaultMarketConfigsRecord = {};
742
- for (const { vault, mid, config } of configs) {
743
- (vaultMarketConfigsRecord[vault] ??= {})[mid] = config;
744
- }
745
- const positionsRecord = {};
746
- for (const { vault, mid, position } of positions) {
747
- (positionsRecord[vault] ??= {})[mid] = position;
748
- }
749
- return new VaultV1ReallocationData({
750
- chainId: this.chainId,
751
- markets: marketsRecord,
752
- vaults: vaultsRecord,
753
- vaultMarketConfigs: vaultMarketConfigsRecord,
754
- positions: positionsRecord,
755
- });
756
- }
757
- /**
758
- * Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
759
- *
760
- * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
761
- * @param params.block.number - Block number used for every RPC read.
762
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
763
- * @returns A `VaultV1ReallocationData` snapshot populated from one block.
764
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
765
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
766
- * {@link getVaultV2BlueReallocationData}.
767
- * @example
768
- * ```ts
769
- * const data = await market.getReallocationData({ vaultAddresses, block });
770
- * // Equivalent to market.getVaultV1ReallocationData({ vaultAddresses, block }).
771
- * ```
772
- */
773
- getReallocationData(params) {
774
- return this.getVaultV1ReallocationData(params);
775
- }
776
652
  /**
777
653
  * Fetches Vault V2 BluePublicAllocator state for this target market.
778
654
  *
@@ -851,86 +727,6 @@ export class MorphoBlue {
851
727
  ])),
852
728
  });
853
729
  }
854
- /**
855
- * Computes Vault V1 PublicAllocator reallocations for this market.
856
- *
857
- * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
858
- * or `{ operation, amount }` for a borrow or loan-asset withdraw.
859
- *
860
- * @param params - Reallocation computation parameters.
861
- * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
862
- * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
863
- * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
864
- * @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
865
- * @param params.options - Optional allocator and utilization options.
866
- * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
867
- * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
868
- * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
869
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
870
- * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
871
- * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
872
- * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
873
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
874
- * {@link getVaultV2BlueReallocations}.
875
- * @example
876
- * ```ts
877
- * const reallocations = market.getVaultV1Reallocations({
878
- * reallocationData,
879
- * operation: "borrow",
880
- * amount: 1_000_000n,
881
- * });
882
- * ```
883
- */
884
- getVaultV1Reallocations(params) {
885
- validateChainId(params.reallocationData.chainId, this.chainId);
886
- const marketId = this.marketParams.id;
887
- const options = { enabled: true, ...params.options };
888
- if (params.borrowAmount !== undefined) {
889
- return computeVaultV1Reallocations({
890
- reallocationData: params.reallocationData,
891
- marketId,
892
- operation: "borrow",
893
- amount: params.borrowAmount,
894
- options,
895
- });
896
- }
897
- return computeVaultV1Reallocations({
898
- reallocationData: params.reallocationData,
899
- marketId,
900
- operation: params.operation,
901
- amount: params.amount,
902
- options,
903
- });
904
- }
905
- /**
906
- * Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
907
- *
908
- * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
909
- * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
910
- * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
911
- * @param params.borrowAmount - Deprecated borrow amount alias.
912
- * @param params.options - Optional allocator and utilization options.
913
- * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
914
- * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
915
- * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
916
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
917
- * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
918
- * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
919
- * @throws {UnknownReallocationMarketError} when the target market is absent.
920
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
921
- * {@link getVaultV2BlueReallocations}.
922
- * @example
923
- * ```ts
924
- * const reallocations = market.getReallocations({
925
- * reallocationData,
926
- * operation: "borrow",
927
- * amount: 1_000_000n,
928
- * });
929
- * ```
930
- */
931
- getReallocations(params) {
932
- return this.getVaultV1Reallocations(params);
933
- }
934
730
  /**
935
731
  * Computes Vault V2 BluePublicAllocator reallocations for this market.
936
732
  *
@@ -1,75 +1,20 @@
1
- export type { IAccrualPosition as IBlueAccrualPosition,
2
- /** @deprecated Use `IBlueAccrualPosition` or the raw Blue subpath. */
3
- IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket,
4
- /** @deprecated Use `IBlueMarket` or the raw Blue subpath. */
5
- IMarket, IMarketParams as IBlueMarketParams,
6
- /** @deprecated Use `IBlueMarketParams` or the raw Blue subpath. */
7
- IMarketParams, IPosition as IBluePosition,
8
- /** @deprecated Use `IBluePosition` or the raw Blue subpath. */
9
- IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
10
- /** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
11
- IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
12
- /** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
13
- IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
14
- /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BlueMarketPublicAllocatorConfig`. */
15
- IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType,
16
- /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BluePublicAllocatorConfig`. */
17
- VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
18
- export { AccrualPosition as BlueAccrualPosition,
19
- /** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
20
- AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
21
- /** @deprecated Use `BlueMarket` or the raw Blue subpath. */
22
- Market, MarketParams as BlueMarketParams,
23
- /** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
24
- MarketParams, Position as BluePosition,
25
- /** @deprecated Use `BluePosition` or the raw Blue subpath. */
26
- Position, PreLiquidationParams as BluePreLiquidationParams,
27
- /** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
28
- PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
29
- /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
30
- PreLiquidationPosition, Token, User as BlueUser,
31
- /** @deprecated Use `BlueUser` or the raw Blue subpath. */
32
- User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
33
- /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
34
- VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
1
+ export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
2
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
+ IPreLiquidationParams as IBluePreLiquidationParams,
4
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
+ IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
6
+ export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
7
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
8
+ PreLiquidationParams as BluePreLiquidationParams,
9
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
10
+ PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
35
11
  export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
36
12
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
37
13
  export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
38
14
  export { MorphoBlue } from "./blue/index.js";
39
- export type { GetOffersDataParams as MidnightGetOffersDataParams,
40
- /** @deprecated Use `MidnightGetOffersDataParams`. */
41
- GetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams,
42
- /** @deprecated Use `MidnightGetPositionDataParams`. */
43
- GetPositionDataParams, MakeLendParams as MidnightMakeLendParams,
44
- /** @deprecated Use `MidnightMakeLendParams`. */
45
- MakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput,
46
- /** @deprecated Use `MidnightMakeOffersOutput`. */
47
- MakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams,
48
- /** @deprecated Use `MidnightMakeOffersParams`. */
49
- MakeOffersParams, MarketActionParams as MidnightMarketActionParams,
50
- /** @deprecated Use `MidnightMarketActionParams`. */
51
- MarketActionParams, OffersData as MidnightOffersData,
52
- /** @deprecated Use `MidnightOffersData`. */
53
- OffersData, OfferValidationParams as MidnightOfferValidationParams,
54
- /** @deprecated Use `MidnightOfferValidationParams`. */
55
- OfferValidationParams, RedeemParams as MidnightRedeemParams,
56
- /** @deprecated Use `MidnightRedeemParams`. */
57
- RedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams,
58
- /** @deprecated Use `MidnightRepayWithdrawCollateralParams`. */
59
- RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams,
60
- /** @deprecated Use `MidnightSupplyCollateralMakeBorrowParams`. */
61
- SupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams,
62
- /** @deprecated Use `MidnightSupplyCollateralParams`. */
63
- SupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams,
64
- /** @deprecated Use `MidnightSupplyCollateralTakeBorrowParams`. */
65
- SupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams,
66
- /** @deprecated Use `MidnightTakeBorrowParams`. */
67
- TakeBorrowParams, TakeLendParams as MidnightTakeLendParams,
68
- /** @deprecated Use `MidnightTakeLendParams`. */
69
- TakeLendParams, } from "./midnight/index.js";
15
+ export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, } from "./midnight/index.js";
70
16
  export { type MidnightActionOutput, type MidnightActionSignatures, type MidnightActions, MorphoMidnight, } from "./midnight/index.js";
71
17
  export * from "./requirements/index.js";
72
18
  export { MorphoVaultV1 } from "./vaultV1/index.js";
73
- export { type InputReallocationData, type InputVaultV1ReallocationData, ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
74
19
  export { MorphoVaultV2 } from "./vaultV2/index.js";
75
20
  export { type InputVaultV2BlueReallocationData, VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
@@ -1,25 +1,12 @@
1
- export { AccrualPosition as BlueAccrualPosition,
2
- /** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
3
- AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
4
- /** @deprecated Use `BlueMarket` or the raw Blue subpath. */
5
- Market, MarketParams as BlueMarketParams,
6
- /** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
7
- MarketParams, Position as BluePosition,
8
- /** @deprecated Use `BluePosition` or the raw Blue subpath. */
9
- Position, PreLiquidationParams as BluePreLiquidationParams,
10
- /** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
11
- PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
12
- /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
13
- PreLiquidationPosition, Token, User as BlueUser,
14
- /** @deprecated Use `BlueUser` or the raw Blue subpath. */
15
- User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
16
- /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
17
- VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
1
+ export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
2
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
3
+ PreLiquidationParams as BluePreLiquidationParams,
4
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
5
+ PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
18
6
  export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
19
7
  export { MorphoBlue } from "./blue/index.js";
20
8
  export { MorphoMidnight, } from "./midnight/index.js";
21
9
  export * from "./requirements/index.js";
22
10
  export { MorphoVaultV1 } from "./vaultV1/index.js";
23
- export { ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
24
11
  export { MorphoVaultV2 } from "./vaultV2/index.js";
25
12
  export { VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
@@ -6,14 +6,17 @@ import { type ActionRequirement } from "../../types/index.js";
6
6
  *
7
7
  * The exit burns however many shares the vault prices at execution time, so the share allowance is
8
8
  * the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
9
- * satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
9
+ * satisfy the requirement: it is replaced by an onchain approval for exactly the computed cap. Only
10
+ * an insufficient allowance may be raised through an ERC-2612 permit, because VaultBundlesV1 skips a
11
+ * permit whose nonce was already consumed and the leftover allowance would then stay in force.
10
12
  *
11
13
  * @internal
12
14
  *
13
15
  * @param viemClient - Client used to read the current share allowance and permit nonce.
14
16
  * @param params - Vault snapshot, owner, exact allowance, and deadline values.
15
17
  * @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
16
- * permit or approval that sets it to exactly that cap.
18
+ * approval that sets it to exactly that cap, or one permit when the allowance is below the cap
19
+ * and signatures are supported.
17
20
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
18
21
  * @throws {viem.BaseError} when an allowance or nonce read fails.
19
22
  */
@@ -10,14 +10,17 @@ import { ExpiredDeadlineError, } from "../../types/index.js";
10
10
  *
11
11
  * The exit burns however many shares the vault prices at execution time, so the share allowance is
12
12
  * the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
13
- * satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
13
+ * satisfy the requirement: it is replaced by an onchain approval for exactly the computed cap. Only
14
+ * an insufficient allowance may be raised through an ERC-2612 permit, because VaultBundlesV1 skips a
15
+ * permit whose nonce was already consumed and the leftover allowance would then stay in force.
14
16
  *
15
17
  * @internal
16
18
  *
17
19
  * @param viemClient - Client used to read the current share allowance and permit nonce.
18
20
  * @param params - Vault snapshot, owner, exact allowance, and deadline values.
19
21
  * @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
20
- * permit or approval that sets it to exactly that cap.
22
+ * approval that sets it to exactly that cap, or one permit when the allowance is below the cap
23
+ * and signatures are supported.
21
24
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
22
25
  * @throws {viem.BaseError} when an allowance or nonce read fails.
23
26
  */
@@ -39,7 +42,9 @@ export const getVaultBundlesSharesRequirements = async (viemClient, params) => {
39
42
  // so only an exact match skips the approval or permit that resets it to the computed cap.
40
43
  if (allowance === params.requiredShareAllowance)
41
44
  return [];
42
- if (params.supportSignature) {
45
+ // An oversized allowance is only ever lowered onchain: `TokenLib.submitPermit` skips a permit
46
+ // whose nonce was already consumed, which would silently leave the stale cap in force.
47
+ if (allowance < params.requiredShareAllowance && params.supportSignature) {
43
48
  const nonce = await readContract(viemClient, {
44
49
  address: params.vaultData.address,
45
50
  abi: erc2612Abi,
@@ -36,6 +36,7 @@ export interface VaultV1Actions {
36
36
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
37
37
  * transaction builder.
38
38
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
39
+ * @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
39
40
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
40
41
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
41
42
  * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
@@ -111,9 +112,10 @@ export interface VaultV1Actions {
111
112
  * defaults to two hours from handle creation.
112
113
  * @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
113
114
  * which returns a deep-frozen `Transaction<VaultV1WithdrawAction>`. Requirements are empty
114
- * when the allowance equals the cap; otherwise they contain an exact approval or, with
115
- * signature support, an ERC-2612 request. The cap stays pinned to the first resolution while
116
- * each call re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
115
+ * when the allowance equals the cap; an oversized allowance is always reset with an exact
116
+ * onchain approval, and an insufficient one is raised by an approval or, with signature
117
+ * support, an ERC-2612 request. The cap stays pinned to the first resolution while each call
118
+ * re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
117
119
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
118
120
  * @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
119
121
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
@@ -240,6 +242,10 @@ export interface VaultV1Actions {
240
242
  * Snapshot state can drift before inclusion, so a later reallocation may still make the on-chain
241
243
  * loop under-cover even after pre-flight succeeds.
242
244
  *
245
+ * In-kind exits require an exact vault-share allowance for the computed cap. An ERC-2612 permit
246
+ * is emitted only to raise an insufficient allowance; an oversized allowance is always reset
247
+ * with an onchain approval before the exit.
248
+ *
243
249
  * @param params - In-kind redemption parameters.
244
250
  * @param params.amount - Asset-denominated amount to exit.
245
251
  * @param params.marketParamsList - Ordered vault markets consumed greedily by the contract;
@@ -266,7 +272,9 @@ export interface VaultV1Actions {
266
272
  * @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the flash loan.
267
273
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
268
274
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
269
- * @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
275
+ * @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
276
+ * the wrong asset, owner, or signature encoding, or names another spender, amount, or deadline
277
+ * than the prepared cap.
270
278
  * @example
271
279
  * ```ts
272
280
  * import { isRequirementSignature } from "@morpho-org/morpho-sdk";
@@ -329,8 +337,8 @@ export interface VaultV1Actions {
329
337
  * satisfied between calls stops being reported, while the derived source share cap stays
330
338
  * pinned to the supplied snapshot.
331
339
  * @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
332
- * @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
333
340
  * @throws {ChainIdMismatchError} when the connected client targets another chain.
341
+ * @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
334
342
  * @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
335
343
  * @throws {VaultAssetMismatchError} when the source and destination vault assets differ.
336
344
  * @throws {SameVaultMigrationError} when the source and destination vault addresses are equal.
@@ -1,13 +1,13 @@
1
- import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, getChainAddresses, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
1
+ import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
2
2
  import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
3
3
  import { getChainAddress, Time } from "@morpho-org/morpho-ts";
4
4
  import { erc20Abi, isAddressEqual } from "viem";
5
5
  import { multicall } from "viem/actions";
6
- import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
6
+ import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
7
7
  import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
8
8
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
9
9
  import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
10
- import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
10
+ import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
11
11
  import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
12
12
  import { getBundlesTokenRequirements } from "../requirements/index.js";
13
13
  export class MorphoVaultV1 {
@@ -27,7 +27,6 @@ export class MorphoVaultV1 {
27
27
  }
28
28
  return fetchAccrualVault(this.vault, this.client.viemClient, {
29
29
  ...parameters,
30
- chainId: this.chainId,
31
30
  deployless: this.client.options.supportDeployless,
32
31
  });
33
32
  }
@@ -185,9 +184,10 @@ export class MorphoVaultV1 {
185
184
  supportSignature: this.client.options.supportSignature,
186
185
  });
187
186
  const signatureRequirement = requirements.find(isRequirementSignature);
188
- if (signatureRequirement?.action.type === "permit") {
189
- expectedRequirement = signatureRequirement.action;
190
- }
187
+ expectedRequirement =
188
+ signatureRequirement?.action.type === "permit"
189
+ ? signatureRequirement.action
190
+ : undefined;
191
191
  return requirements;
192
192
  },
193
193
  buildTx: (signatures) => {
@@ -293,8 +293,7 @@ export class MorphoVaultV1 {
293
293
  if (deadline <= now)
294
294
  throw new ExpiredDeadlineError(deadline, now);
295
295
  const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
296
- const addresses = getChainAddresses(this.chainId);
297
- const blue = addresses.blue ?? addresses.morpho;
296
+ const blue = getChainAddress(this.chainId, "blue");
298
297
  let covered = 0n;
299
298
  const assignedByMarket = new Map();
300
299
  for (const marketParams of marketParamsListSnapshot) {
@@ -392,9 +391,14 @@ export class MorphoVaultV1 {
392
391
  required: amount,
393
392
  });
394
393
  }
395
- if (allowance >= requiredShareAllowance)
394
+ // In-kind withdrawals carry no onchain share cap, so the allowance itself is the cap. A
395
+ // larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
396
+ if (allowance === requiredShareAllowance)
396
397
  return [];
397
- if (this.client.options.supportSignature) {
398
+ // A lowering permit can be skipped after its nonce is consumed, so oversized allowances
399
+ // must be reset with an onchain approval.
400
+ if (allowance < requiredShareAllowance &&
401
+ this.client.options.supportSignature) {
398
402
  return [
399
403
  encodeVaultSharesPermit({
400
404
  vault: vaultData,
@@ -418,8 +422,10 @@ export class MorphoVaultV1 {
418
422
  ];
419
423
  },
420
424
  buildTx: (signatures) => {
421
- const { permit } = selectRequirementSignatures(signatures, {
422
- permit: true,
425
+ const permit = selectBundlesSharesPermitSignature(signatures, {
426
+ spender: vaultExitBundlesV1,
427
+ amount: requiredShareAllowance,
428
+ deadline,
423
429
  });
424
430
  return vaultV1InKindRedeem({
425
431
  vault: { chainId: this.chainId, address: this.vault },