@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
@@ -10,7 +10,6 @@ const index_js_1 = require("../../actions/index.js");
10
10
  const index_js_2 = require("../../helpers/index.js");
11
11
  const index_js_3 = require("../../types/index.js");
12
12
  const index_js_4 = require("../requirements/index.js");
13
- const vaultV1ReallocationData_js_1 = require("../vaultV1ReallocationData.js");
14
13
  const vaultV2BlueReallocationData_js_1 = require("../vaultV2BlueReallocationData.js");
15
14
  class MorphoBlue {
16
15
  client;
@@ -81,7 +80,6 @@ class MorphoBlue {
81
80
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
82
81
  return (0, blue_sdk_viem_1.fetchMarket)(this.marketParams.id, this.client.viemClient, {
83
82
  ...parameters,
84
- chainId: this.chainId,
85
83
  deployless: this.client.options.supportDeployless,
86
84
  });
87
85
  }
@@ -90,7 +88,6 @@ class MorphoBlue {
90
88
  return (0, blue_sdk_viem_1.fetchAccrualPosition)(userAddress, this.marketParams.id, this.client.viemClient, {
91
89
  ...parameters,
92
90
  deployless: this.client.options.supportDeployless,
93
- chainId: this.chainId,
94
91
  });
95
92
  }
96
93
  /** {@inheritDoc BlueActions.supply} */
@@ -441,14 +438,7 @@ class MorphoBlue {
441
438
  ? this.getTokenRequirements({
442
439
  token: this.marketParams.loanToken,
443
440
  amount: maxRepayAssets,
444
- // A caller-requested reusable approval wins; a full repay otherwise defaults to
445
- // the token's reusable cap. Checksum the key so a differently-cased loan token
446
- // (common from subgraphs/APIs) resolves that cap instead of falling back to
447
- // maxUint256, which UNI/ONDO/COMP/FLUID reject.
448
- approvalAmount: requirementsParams?.approvalAmount ??
449
- (saturatedRepay
450
- ? (index_js_2.MAX_TOKEN_APPROVALS[this.chainId]?.[(0, viem_1.getAddress)(this.marketParams.loanToken)] ?? viem_1.maxUint256)
451
- : undefined),
441
+ approvalAmount: requirementsParams?.approvalAmount,
452
442
  userAddress,
453
443
  deadline,
454
444
  useSimplePermit: requirementsParams?.useSimplePermit,
@@ -662,120 +652,6 @@ class MorphoBlue {
662
652
  },
663
653
  };
664
654
  }
665
- /**
666
- * Fetches all on-chain inputs needed to compute public allocator reallocations.
667
- *
668
- * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
669
- * @param params.block.number - Block number used for every RPC read.
670
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
671
- * @returns Reallocation data ready for {@link getVaultV1Reallocations}.
672
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
673
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
674
- * {@link getVaultV2BlueReallocationData}.
675
- * @example
676
- * ```ts
677
- * import { markets, vaults } from "@morpho-org/morpho-test";
678
- * import { createPublicClient, http } from "viem";
679
- * import { mainnet } from "viem/chains";
680
- * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
681
- * import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
682
- *
683
- * const client = createPublicClient({ chain: mainnet, transport: http() })
684
- * .extend(morphoViemExtension());
685
- * const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
686
- * const block = await client.getBlock();
687
- * const data: VaultV1ReallocationData = await market.getVaultV1ReallocationData({
688
- * vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
689
- * block,
690
- * });
691
- * ```
692
- */
693
- async getVaultV1ReallocationData({ vaultAddresses, block, }) {
694
- (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
695
- const client = this.client.viemClient;
696
- const fetchParams = {
697
- blockNumber: block.number,
698
- chainId: this.chainId,
699
- deployless: this.client.options.supportDeployless,
700
- };
701
- const targetMarketId = this.marketParams.id;
702
- // Phase 1: Fetch the target market and all vaults at `block.number` in
703
- // parallel so every row of the resulting state comes from the same epoch
704
- // and the planner never trusts a caller-owned target-market snapshot.
705
- const [targetMarket, vaults] = await Promise.all([
706
- (0, blue_sdk_viem_1.fetchMarket)(targetMarketId, client, fetchParams),
707
- Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchVault)(addr, client, fetchParams))),
708
- ]);
709
- const allMarketIds = new Set([targetMarketId]);
710
- const vaultMarketPairs = [];
711
- for (const vault of vaults) {
712
- // Always include target market pair so its config/position is fetched
713
- // even when the target market is only in the vault's supplyQueue.
714
- vaultMarketPairs.push({ vault: vault.address, marketId: targetMarketId });
715
- for (const mid of vault.withdrawQueue) {
716
- allMarketIds.add(mid);
717
- if (mid !== targetMarketId) {
718
- vaultMarketPairs.push({ vault: vault.address, marketId: mid });
719
- }
720
- }
721
- }
722
- // Phase 2: Fetch all source markets, vault configs, and positions in parallel.
723
- const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
724
- const [markets, configs, positions] = await Promise.all([
725
- Promise.all(sourceMarketIds.map((mid) => (0, blue_sdk_viem_1.fetchMarket)(mid, client, fetchParams))),
726
- Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchVaultMarketConfig)(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
727
- Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchPosition)(vault, mid, client, fetchParams).then((position) => ({
728
- vault,
729
- mid,
730
- position,
731
- })))),
732
- ]);
733
- // Assemble records for VaultV1ReallocationData.
734
- const marketsRecord = {
735
- [targetMarketId]: targetMarket,
736
- };
737
- for (const m of markets) {
738
- marketsRecord[m.id] = m;
739
- }
740
- const vaultsRecord = {};
741
- for (const v of vaults) {
742
- vaultsRecord[v.address] = v;
743
- }
744
- const vaultMarketConfigsRecord = {};
745
- for (const { vault, mid, config } of configs) {
746
- (vaultMarketConfigsRecord[vault] ??= {})[mid] = config;
747
- }
748
- const positionsRecord = {};
749
- for (const { vault, mid, position } of positions) {
750
- (positionsRecord[vault] ??= {})[mid] = position;
751
- }
752
- return new vaultV1ReallocationData_js_1.VaultV1ReallocationData({
753
- chainId: this.chainId,
754
- markets: marketsRecord,
755
- vaults: vaultsRecord,
756
- vaultMarketConfigs: vaultMarketConfigsRecord,
757
- positions: positionsRecord,
758
- });
759
- }
760
- /**
761
- * Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
762
- *
763
- * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
764
- * @param params.block.number - Block number used for every RPC read.
765
- * @param params.block.timestamp - Timestamp corresponding to the fetched block.
766
- * @returns A `VaultV1ReallocationData` snapshot populated from one block.
767
- * @throws {ChainIdMismatchError} when the client chain does not match this market.
768
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
769
- * {@link getVaultV2BlueReallocationData}.
770
- * @example
771
- * ```ts
772
- * const data = await market.getReallocationData({ vaultAddresses, block });
773
- * // Equivalent to market.getVaultV1ReallocationData({ vaultAddresses, block }).
774
- * ```
775
- */
776
- getReallocationData(params) {
777
- return this.getVaultV1ReallocationData(params);
778
- }
779
655
  /**
780
656
  * Fetches Vault V2 BluePublicAllocator state for this target market.
781
657
  *
@@ -854,86 +730,6 @@ class MorphoBlue {
854
730
  ])),
855
731
  });
856
732
  }
857
- /**
858
- * Computes Vault V1 PublicAllocator reallocations for this market.
859
- *
860
- * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
861
- * or `{ operation, amount }` for a borrow or loan-asset withdraw.
862
- *
863
- * @param params - Reallocation computation parameters.
864
- * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
865
- * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
866
- * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
867
- * @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
868
- * @param params.options - Optional allocator and utilization options.
869
- * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
870
- * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
871
- * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
872
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
873
- * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
874
- * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
875
- * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
876
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
877
- * {@link getVaultV2BlueReallocations}.
878
- * @example
879
- * ```ts
880
- * const reallocations = market.getVaultV1Reallocations({
881
- * reallocationData,
882
- * operation: "borrow",
883
- * amount: 1_000_000n,
884
- * });
885
- * ```
886
- */
887
- getVaultV1Reallocations(params) {
888
- (0, index_js_2.validateChainId)(params.reallocationData.chainId, this.chainId);
889
- const marketId = this.marketParams.id;
890
- const options = { enabled: true, ...params.options };
891
- if (params.borrowAmount !== undefined) {
892
- return (0, index_js_2.computeVaultV1Reallocations)({
893
- reallocationData: params.reallocationData,
894
- marketId,
895
- operation: "borrow",
896
- amount: params.borrowAmount,
897
- options,
898
- });
899
- }
900
- return (0, index_js_2.computeVaultV1Reallocations)({
901
- reallocationData: params.reallocationData,
902
- marketId,
903
- operation: params.operation,
904
- amount: params.amount,
905
- options,
906
- });
907
- }
908
- /**
909
- * Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
910
- *
911
- * @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
912
- * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
913
- * @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
914
- * @param params.borrowAmount - Deprecated borrow amount alias.
915
- * @param params.options - Optional allocator and utilization options.
916
- * @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
917
- * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
918
- * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
919
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
920
- * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
921
- * @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
922
- * @throws {UnknownReallocationMarketError} when the target market is absent.
923
- * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
924
- * {@link getVaultV2BlueReallocations}.
925
- * @example
926
- * ```ts
927
- * const reallocations = market.getReallocations({
928
- * reallocationData,
929
- * operation: "borrow",
930
- * amount: 1_000_000n,
931
- * });
932
- * ```
933
- */
934
- getReallocations(params) {
935
- return this.getVaultV1Reallocations(params);
936
- }
937
733
  /**
938
734
  * Computes Vault V2 BluePublicAllocator reallocations for this market.
939
735
  *
@@ -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";
@@ -14,12 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.BlueUser = exports.Token = exports.PreLiquidationPosition = exports.BluePreLiquidationPosition = exports.PreLiquidationParams = exports.BluePreLiquidationParams = exports.Position = exports.BluePosition = exports.MarketParams = exports.BlueMarketParams = exports.Market = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = exports.BlueAccrualPosition = void 0;
18
- exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.VaultV1ReallocationData = exports.ReallocationData = void 0;
17
+ exports.VaultV2BlueReallocationData = exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.MorphoMidnight = exports.MorphoBlue = exports.MidnightTree = exports.MidnightPosition = exports.MidnightOffer = exports.MidnightMarketParams = exports.MidnightMarket = exports.MidnightGroup = exports.MidnightAccrualPosition = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2BluePublicAllocatorConfig = exports.VaultV2BlueMarketPublicAllocatorConfig = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.BlueUser = exports.Token = exports.BluePreLiquidationPosition = exports.BluePreLiquidationParams = exports.BluePosition = exports.BlueMarketParams = exports.BlueMarket = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.BlueAccrualPosition = void 0;
19
18
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
20
19
  Object.defineProperty(exports, "BlueAccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
21
- /** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
22
- Object.defineProperty(exports, "AccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
23
20
  Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
24
21
  Object.defineProperty(exports, "AccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2; } });
25
22
  Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter; } });
@@ -31,30 +28,18 @@ Object.defineProperty(exports, "Eip5267Domain", { enumerable: true, get: functio
31
28
  Object.defineProperty(exports, "ExchangeRateWrappedToken", { enumerable: true, get: function () { return blue_sdk_1.ExchangeRateWrappedToken; } });
32
29
  Object.defineProperty(exports, "Holding", { enumerable: true, get: function () { return blue_sdk_1.Holding; } });
33
30
  Object.defineProperty(exports, "BlueMarket", { enumerable: true, get: function () { return blue_sdk_1.Market; } });
34
- /** @deprecated Use `BlueMarket` or the raw Blue subpath. */
35
- Object.defineProperty(exports, "Market", { enumerable: true, get: function () { return blue_sdk_1.Market; } });
36
31
  Object.defineProperty(exports, "BlueMarketParams", { enumerable: true, get: function () { return blue_sdk_1.MarketParams; } });
37
- /** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
38
- Object.defineProperty(exports, "MarketParams", { enumerable: true, get: function () { return blue_sdk_1.MarketParams; } });
39
32
  Object.defineProperty(exports, "BluePosition", { enumerable: true, get: function () { return blue_sdk_1.Position; } });
40
- /** @deprecated Use `BluePosition` or the raw Blue subpath. */
41
- Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return blue_sdk_1.Position; } });
33
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
42
34
  Object.defineProperty(exports, "BluePreLiquidationParams", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationParams; } });
43
- /** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
44
- Object.defineProperty(exports, "PreLiquidationParams", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationParams; } });
35
+ /** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
45
36
  Object.defineProperty(exports, "BluePreLiquidationPosition", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationPosition; } });
46
- /** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
47
- Object.defineProperty(exports, "PreLiquidationPosition", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationPosition; } });
48
37
  Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return blue_sdk_1.Token; } });
49
38
  Object.defineProperty(exports, "BlueUser", { enumerable: true, get: function () { return blue_sdk_1.User; } });
50
- /** @deprecated Use `BlueUser` or the raw Blue subpath. */
51
- Object.defineProperty(exports, "User", { enumerable: true, get: function () { return blue_sdk_1.User; } });
52
39
  Object.defineProperty(exports, "Vault", { enumerable: true, get: function () { return blue_sdk_1.Vault; } });
53
40
  Object.defineProperty(exports, "VaultConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultConfig; } });
54
41
  Object.defineProperty(exports, "VaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketAllocation; } });
55
42
  Object.defineProperty(exports, "VaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketConfig; } });
56
- /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
57
- Object.defineProperty(exports, "VaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketPublicAllocatorConfig; } });
58
43
  Object.defineProperty(exports, "VaultToken", { enumerable: true, get: function () { return blue_sdk_1.VaultToken; } });
59
44
  Object.defineProperty(exports, "VaultUser", { enumerable: true, get: function () { return blue_sdk_1.VaultUser; } });
60
45
  Object.defineProperty(exports, "VaultV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2; } });
@@ -80,9 +65,6 @@ Object.defineProperty(exports, "MorphoMidnight", { enumerable: true, get: functi
80
65
  __exportStar(require("./requirements/index.js"), exports);
81
66
  var index_js_3 = require("./vaultV1/index.js");
82
67
  Object.defineProperty(exports, "MorphoVaultV1", { enumerable: true, get: function () { return index_js_3.MorphoVaultV1; } });
83
- var vaultV1ReallocationData_js_1 = require("./vaultV1ReallocationData.js");
84
- Object.defineProperty(exports, "ReallocationData", { enumerable: true, get: function () { return vaultV1ReallocationData_js_1.ReallocationData; } });
85
- Object.defineProperty(exports, "VaultV1ReallocationData", { enumerable: true, get: function () { return vaultV1ReallocationData_js_1.VaultV1ReallocationData; } });
86
68
  var index_js_4 = require("./vaultV2/index.js");
87
69
  Object.defineProperty(exports, "MorphoVaultV2", { enumerable: true, get: function () { return index_js_4.MorphoVaultV2; } });
88
70
  var vaultV2BlueReallocationData_js_1 = require("./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
  */
@@ -13,14 +13,17 @@ const index_js_3 = require("../../types/index.js");
13
13
  *
14
14
  * The exit burns however many shares the vault prices at execution time, so the share allowance is
15
15
  * the only cap on that burn. A leftover allowance above `requiredShareAllowance` therefore does not
16
- * satisfy the requirement: it is replaced by an approval or permit for exactly the computed cap.
16
+ * satisfy the requirement: it is replaced by an onchain approval for exactly the computed cap. Only
17
+ * an insufficient allowance may be raised through an ERC-2612 permit, because VaultBundlesV1 skips a
18
+ * permit whose nonce was already consumed and the leftover allowance would then stay in force.
17
19
  *
18
20
  * @internal
19
21
  *
20
22
  * @param viemClient - Client used to read the current share allowance and permit nonce.
21
23
  * @param params - Vault snapshot, owner, exact allowance, and deadline values.
22
24
  * @returns No requirement when the allowance already equals `requiredShareAllowance`, otherwise one
23
- * permit or approval that sets it to exactly that cap.
25
+ * approval that sets it to exactly that cap, or one permit when the allowance is below the cap
26
+ * and signatures are supported.
24
27
  * @throws {ExpiredDeadlineError} when the bundles deadline has elapsed.
25
28
  * @throws {viem.BaseError} when an allowance or nonce read fails.
26
29
  */
@@ -42,7 +45,9 @@ const getVaultBundlesSharesRequirements = async (viemClient, params) => {
42
45
  // so only an exact match skips the approval or permit that resets it to the computed cap.
43
46
  if (allowance === params.requiredShareAllowance)
44
47
  return [];
45
- if (params.supportSignature) {
48
+ // An oversized allowance is only ever lowered onchain: `TokenLib.submitPermit` skips a permit
49
+ // whose nonce was already consumed, which would silently leave the stale cap in force.
50
+ if (allowance < params.requiredShareAllowance && params.supportSignature) {
46
51
  const nonce = await (0, actions_1.readContract)(viemClient, {
47
52
  address: params.vaultData.address,
48
53
  abi: blue_sdk_viem_1.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.
@@ -30,7 +30,6 @@ class MorphoVaultV1 {
30
30
  }
31
31
  return (0, blue_sdk_viem_1.fetchAccrualVault)(this.vault, this.client.viemClient, {
32
32
  ...parameters,
33
- chainId: this.chainId,
34
33
  deployless: this.client.options.supportDeployless,
35
34
  });
36
35
  }
@@ -188,9 +187,10 @@ class MorphoVaultV1 {
188
187
  supportSignature: this.client.options.supportSignature,
189
188
  });
190
189
  const signatureRequirement = requirements.find(index_js_3.isRequirementSignature);
191
- if (signatureRequirement?.action.type === "permit") {
192
- expectedRequirement = signatureRequirement.action;
193
- }
190
+ expectedRequirement =
191
+ signatureRequirement?.action.type === "permit"
192
+ ? signatureRequirement.action
193
+ : undefined;
194
194
  return requirements;
195
195
  },
196
196
  buildTx: (signatures) => {
@@ -296,8 +296,7 @@ class MorphoVaultV1 {
296
296
  if (deadline <= now)
297
297
  throw new index_js_3.ExpiredDeadlineError(deadline, now);
298
298
  const vaultExitBundlesV1 = (0, morpho_ts_1.getChainAddress)(this.chainId, "bundles.vaultExitBundlesV1");
299
- const addresses = (0, blue_sdk_1.getChainAddresses)(this.chainId);
300
- const blue = addresses.blue ?? addresses.morpho;
299
+ const blue = (0, morpho_ts_1.getChainAddress)(this.chainId, "blue");
301
300
  let covered = 0n;
302
301
  const assignedByMarket = new Map();
303
302
  for (const marketParams of marketParamsListSnapshot) {
@@ -395,9 +394,14 @@ class MorphoVaultV1 {
395
394
  required: amount,
396
395
  });
397
396
  }
398
- if (allowance >= requiredShareAllowance)
397
+ // In-kind withdrawals carry no onchain share cap, so the allowance itself is the cap. A
398
+ // larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
399
+ if (allowance === requiredShareAllowance)
399
400
  return [];
400
- if (this.client.options.supportSignature) {
401
+ // A lowering permit can be skipped after its nonce is consumed, so oversized allowances
402
+ // must be reset with an onchain approval.
403
+ if (allowance < requiredShareAllowance &&
404
+ this.client.options.supportSignature) {
401
405
  return [
402
406
  (0, index_js_1.encodeVaultSharesPermit)({
403
407
  vault: vaultData,
@@ -421,8 +425,10 @@ class MorphoVaultV1 {
421
425
  ];
422
426
  },
423
427
  buildTx: (signatures) => {
424
- const { permit } = (0, index_js_3.selectRequirementSignatures)(signatures, {
425
- permit: true,
428
+ const permit = (0, common_js_1.selectBundlesSharesPermitSignature)(signatures, {
429
+ spender: vaultExitBundlesV1,
430
+ amount: requiredShareAllowance,
431
+ deadline,
426
432
  });
427
433
  return (0, index_js_1.vaultV1InKindRedeem)({
428
434
  vault: { chainId: this.chainId, address: this.vault },