@morpho-org/morpho-sdk 10.1.0 → 10.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/lib/cjs/actions/blue/borrow.d.ts +11 -3
  2. package/lib/cjs/actions/blue/borrow.internal.js +1 -0
  3. package/lib/cjs/actions/blue/borrow.js +8 -2
  4. package/lib/cjs/actions/blue/common.d.ts +4 -1
  5. package/lib/cjs/actions/blue/common.js +17 -3
  6. package/lib/cjs/actions/blue/refinance.d.ts +11 -3
  7. package/lib/cjs/actions/blue/refinance.internal.js +4 -1
  8. package/lib/cjs/actions/blue/refinance.js +8 -2
  9. package/lib/cjs/actions/blue/refinanceValidation.d.ts +3 -2
  10. package/lib/cjs/actions/blue/refinanceValidation.js +10 -6
  11. package/lib/cjs/actions/blue/repay.d.ts +4 -3
  12. package/lib/cjs/actions/blue/repay.js +3 -2
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -2
  15. package/lib/cjs/actions/blue/supply.d.ts +5 -3
  16. package/lib/cjs/actions/blue/supply.js +4 -2
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +4 -3
  18. package/lib/cjs/actions/blue/supplyCollateral.js +3 -2
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  21. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  22. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +8 -2
  23. package/lib/cjs/actions/blue/withdraw.d.ts +11 -3
  24. package/lib/cjs/actions/blue/withdraw.internal.js +4 -1
  25. package/lib/cjs/actions/blue/withdraw.js +8 -2
  26. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
  27. package/lib/cjs/actions/blue/withdrawCollateral.js +3 -2
  28. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +0 -1
  29. package/lib/cjs/actions/midnight/takeBorrow.js +0 -1
  30. package/lib/cjs/actions/midnight/takeLend.js +0 -1
  31. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +0 -1
  32. package/lib/cjs/actions/midnight/takeWithdraw.js +0 -1
  33. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -1
  34. package/lib/cjs/actions/vaultV1/deposit.js +2 -1
  35. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +3 -2
  36. package/lib/cjs/actions/vaultV1/migrateToV2.js +2 -1
  37. package/lib/cjs/actions/vaultV1/redeem.d.ts +3 -2
  38. package/lib/cjs/actions/vaultV1/redeem.js +2 -1
  39. package/lib/cjs/actions/vaultV1/withdraw.d.ts +2 -1
  40. package/lib/cjs/actions/vaultV1/withdraw.js +2 -1
  41. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -1
  42. package/lib/cjs/actions/vaultV2/deposit.js +2 -1
  43. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +2 -1
  44. package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -1
  45. package/lib/cjs/actions/vaultV2/redeem.d.ts +3 -2
  46. package/lib/cjs/actions/vaultV2/redeem.js +2 -1
  47. package/lib/cjs/actions/vaultV2/withdraw.d.ts +2 -1
  48. package/lib/cjs/actions/vaultV2/withdraw.js +2 -1
  49. package/lib/cjs/constants.d.ts +1 -1
  50. package/lib/cjs/constants.js +2 -0
  51. package/lib/cjs/entities/blue/blue.d.ts +83 -20
  52. package/lib/cjs/entities/blue/blue.js +38 -12
  53. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  54. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
  55. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -6
  56. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -0
  57. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -7
  58. package/lib/cjs/entities/vaultV2/vaultV2.js +4 -0
  59. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -2
  60. package/lib/cjs/entities/vaultV2BlueReallocationData.js +19 -21
  61. package/lib/cjs/helpers/constant.d.ts +2 -0
  62. package/lib/cjs/helpers/constant.js +3 -1
  63. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  64. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
  65. package/lib/cjs/helpers/index.d.ts +1 -1
  66. package/lib/cjs/helpers/index.js +2 -1
  67. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  68. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
  69. package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
  70. package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
  71. package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
  72. package/lib/cjs/helpers/reallocationPenalty.js +32 -0
  73. package/lib/cjs/helpers/referralFee.d.ts +2 -1
  74. package/lib/cjs/helpers/referralFee.js +5 -1
  75. package/lib/cjs/helpers/validate.d.ts +31 -4
  76. package/lib/cjs/helpers/validate.js +48 -9
  77. package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
  78. package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
  79. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  80. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
  81. package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
  82. package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
  83. package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
  84. package/lib/cjs/transactionPlan/blue/refinance.js +20 -3
  85. package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
  86. package/lib/cjs/transactionPlan/blue/repay.js +1 -2
  87. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  88. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  89. package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
  90. package/lib/cjs/transactionPlan/blue/supply.js +1 -2
  91. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  92. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
  93. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  94. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  95. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +15 -5
  96. package/lib/cjs/transactionPlan/blue/withdraw.js +25 -6
  97. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  98. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +11 -7
  99. package/lib/cjs/transactionPlan/deposit.js +4 -0
  100. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  101. package/lib/cjs/transactionPlan/intent.js +4 -2
  102. package/lib/cjs/transactionPlan/plan.d.ts +8 -4
  103. package/lib/cjs/transactionPlan/plan.js +8 -4
  104. package/lib/cjs/transactionPlan/types.d.ts +6 -0
  105. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +3 -3
  106. package/lib/cjs/transactionPlan/vaultv1/deposit.js +3 -3
  107. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  108. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
  109. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
  110. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
  111. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  112. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
  113. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
  114. package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
  115. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  116. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  117. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
  118. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
  119. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  120. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
  121. package/lib/cjs/types/error.d.ts +7 -6
  122. package/lib/cjs/types/error.js +10 -9
  123. package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
  124. package/lib/cjs/version.d.ts +1 -1
  125. package/lib/cjs/version.js +1 -1
  126. package/lib/esm/actions/blue/borrow.d.ts +11 -3
  127. package/lib/esm/actions/blue/borrow.internal.js +1 -0
  128. package/lib/esm/actions/blue/borrow.js +8 -2
  129. package/lib/esm/actions/blue/common.d.ts +4 -1
  130. package/lib/esm/actions/blue/common.js +17 -3
  131. package/lib/esm/actions/blue/refinance.d.ts +11 -3
  132. package/lib/esm/actions/blue/refinance.internal.js +4 -1
  133. package/lib/esm/actions/blue/refinance.js +8 -2
  134. package/lib/esm/actions/blue/refinanceValidation.d.ts +3 -2
  135. package/lib/esm/actions/blue/refinanceValidation.js +10 -6
  136. package/lib/esm/actions/blue/repay.d.ts +4 -3
  137. package/lib/esm/actions/blue/repay.js +3 -2
  138. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  139. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -2
  140. package/lib/esm/actions/blue/supply.d.ts +5 -3
  141. package/lib/esm/actions/blue/supply.js +4 -2
  142. package/lib/esm/actions/blue/supplyCollateral.d.ts +4 -3
  143. package/lib/esm/actions/blue/supplyCollateral.js +3 -2
  144. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  145. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  146. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  147. package/lib/esm/actions/blue/supplyCollateralBorrow.js +8 -2
  148. package/lib/esm/actions/blue/withdraw.d.ts +11 -3
  149. package/lib/esm/actions/blue/withdraw.internal.js +4 -1
  150. package/lib/esm/actions/blue/withdraw.js +8 -2
  151. package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
  152. package/lib/esm/actions/blue/withdrawCollateral.js +3 -2
  153. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -2
  154. package/lib/esm/actions/midnight/takeBorrow.js +1 -2
  155. package/lib/esm/actions/midnight/takeLend.js +1 -2
  156. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -2
  157. package/lib/esm/actions/midnight/takeWithdraw.js +1 -2
  158. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -1
  159. package/lib/esm/actions/vaultV1/deposit.js +2 -1
  160. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +3 -2
  161. package/lib/esm/actions/vaultV1/migrateToV2.js +2 -1
  162. package/lib/esm/actions/vaultV1/redeem.d.ts +3 -2
  163. package/lib/esm/actions/vaultV1/redeem.js +2 -1
  164. package/lib/esm/actions/vaultV1/withdraw.d.ts +2 -1
  165. package/lib/esm/actions/vaultV1/withdraw.js +2 -1
  166. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -1
  167. package/lib/esm/actions/vaultV2/deposit.js +2 -1
  168. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +2 -1
  169. package/lib/esm/actions/vaultV2/forceWithdraw.js +2 -1
  170. package/lib/esm/actions/vaultV2/redeem.d.ts +3 -2
  171. package/lib/esm/actions/vaultV2/redeem.js +2 -1
  172. package/lib/esm/actions/vaultV2/withdraw.d.ts +2 -1
  173. package/lib/esm/actions/vaultV2/withdraw.js +2 -1
  174. package/lib/esm/constants.d.ts +1 -1
  175. package/lib/esm/constants.js +1 -1
  176. package/lib/esm/entities/blue/blue.d.ts +83 -20
  177. package/lib/esm/entities/blue/blue.js +38 -12
  178. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  179. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
  180. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -6
  181. package/lib/esm/entities/vaultV1/vaultV1.js +7 -1
  182. package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -7
  183. package/lib/esm/entities/vaultV2/vaultV2.js +5 -1
  184. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -2
  185. package/lib/esm/entities/vaultV2BlueReallocationData.js +17 -19
  186. package/lib/esm/helpers/constant.d.ts +2 -0
  187. package/lib/esm/helpers/constant.js +2 -0
  188. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  189. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
  190. package/lib/esm/helpers/index.d.ts +1 -1
  191. package/lib/esm/helpers/index.js +1 -1
  192. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  193. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
  194. package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
  195. package/lib/esm/helpers/quoteBlueRepay.js +21 -8
  196. package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
  197. package/lib/esm/helpers/reallocationPenalty.js +28 -0
  198. package/lib/esm/helpers/referralFee.d.ts +2 -1
  199. package/lib/esm/helpers/referralFee.js +5 -1
  200. package/lib/esm/helpers/validate.d.ts +31 -4
  201. package/lib/esm/helpers/validate.js +48 -11
  202. package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
  203. package/lib/esm/helpers/validateMidnightBounds.js +1 -2
  204. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  205. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
  206. package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
  207. package/lib/esm/transactionPlan/blue/borrow.js +27 -9
  208. package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
  209. package/lib/esm/transactionPlan/blue/refinance.js +20 -3
  210. package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
  211. package/lib/esm/transactionPlan/blue/repay.js +1 -2
  212. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  213. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  214. package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
  215. package/lib/esm/transactionPlan/blue/supply.js +1 -2
  216. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  217. package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
  218. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  219. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  220. package/lib/esm/transactionPlan/blue/withdraw.d.ts +15 -5
  221. package/lib/esm/transactionPlan/blue/withdraw.js +25 -6
  222. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  223. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +11 -7
  224. package/lib/esm/transactionPlan/deposit.js +5 -1
  225. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  226. package/lib/esm/transactionPlan/intent.js +4 -2
  227. package/lib/esm/transactionPlan/plan.d.ts +8 -4
  228. package/lib/esm/transactionPlan/plan.js +8 -4
  229. package/lib/esm/transactionPlan/types.d.ts +6 -0
  230. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +3 -3
  231. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -3
  232. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  233. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
  234. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
  235. package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
  236. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  237. package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
  238. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
  239. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
  240. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  241. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  242. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
  243. package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
  244. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  245. package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
  246. package/lib/esm/types/error.d.ts +7 -6
  247. package/lib/esm/types/error.js +11 -10
  248. package/lib/esm/types/sharedLiquidity.d.ts +7 -2
  249. package/lib/esm/version.d.ts +1 -1
  250. package/lib/esm/version.js +1 -1
  251. package/package.json +3 -3
@@ -82,7 +82,7 @@ export interface BlueActions {
82
82
  * @param params.collateralAssets - Gross collateral assets supplied.
83
83
  * @param params.nativeAmount - Optional full native funding equal to `collateralAssets`.
84
84
  * @param params.deadline - Final call deadline in Unix seconds.
85
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
85
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
86
86
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
87
87
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
88
88
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
@@ -93,8 +93,9 @@ export interface BlueActions {
93
93
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
94
94
  * @throws {ChainWNativeMissingError} when native funding is requested without registered wNative.
95
95
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
96
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
97
96
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
97
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
98
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
98
99
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
99
100
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
100
101
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -156,7 +157,7 @@ export interface BlueActions {
156
157
  * @param params.assets - Gross loan-token assets funded before the referral fee.
157
158
  * @param params.nativeAmount - Optional full native funding; must equal `assets` and requires wNative.
158
159
  * @param params.deadline - Final call deadline in Unix seconds.
159
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
160
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
160
161
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
161
162
  * @returns Lazy prerequisite resolution and a synchronous deep-frozen transaction builder.
162
163
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
@@ -167,8 +168,10 @@ export interface BlueActions {
167
168
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
168
169
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
169
170
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
170
- * @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`, when the referral fee is at least WAD.
171
+ * @throws {InputExceedsMaxError} when `assets` or `deadline` exceeds `uint256`.
171
172
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
173
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
174
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
172
175
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
173
176
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when the route cannot consume a supplied signature.
174
177
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -245,10 +248,12 @@ export interface BlueActions {
245
248
  * @param params.assets - Exact assets withdrawn, exclusive with `shares`.
246
249
  * @param params.shares - Exact shares burned, exclusive with `assets`.
247
250
  * @param params.reallocations - Optional Vault V2 reallocations executed before withdrawal.
251
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
248
252
  * @param params.deadline - Final call deadline in Unix seconds.
249
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
253
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
250
254
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
251
255
  * @returns Lazy authorization resolution and a synchronous deep-frozen transaction builder.
256
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
252
257
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
253
258
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
254
259
  * @throws {ExpiredDeadlineError} when the deadline is stale.
@@ -257,12 +262,16 @@ export interface BlueActions {
257
262
  * reallocation source market's `id` does not hash from its tuple fields.
258
263
  * @throws {AccrualPositionUserMismatchError} when `positionData` belongs to another user.
259
264
  * @throws {NegativeInputError} when an amount, referral fee, or reallocation penalty is negative.
265
+ * Also thrown when maxPenalty is negative.
260
266
  * @throws {NonPositiveInputError} when no withdrawal mode or positive reallocation amount is provided.
261
267
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
262
268
  * @throws {WithdrawExceedsSupplyError} when assets exceed the supplied balance.
263
269
  * @throws {WithdrawSharesExceedSupplyError} when shares exceed the owned balance.
264
270
  * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
271
+ * Also thrown when maxPenalty exceeds WAD or a reallocation penalty exceeds maxPenalty.
265
272
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
273
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
274
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
266
275
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
267
276
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
268
277
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -311,6 +320,8 @@ export interface BlueActions {
311
320
  readonly userAddress: Address;
312
321
  readonly positionData: AccrualPosition;
313
322
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
323
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
324
+ readonly maxPenalty?: bigint;
314
325
  readonly deadline: bigint;
315
326
  readonly referralFeePct?: bigint;
316
327
  readonly referralFeeRecipient?: Address;
@@ -396,10 +407,12 @@ export interface BlueActions {
396
407
  * @param params.borrowAssets - Gross loan assets borrowed before penalties and referral fees.
397
408
  * @param params.positionData - Pre-fetched position used for the health check.
398
409
  * @param params.reallocations - Optional Vault V2 reallocations before borrowing.
410
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
399
411
  * @param params.deadline - Final call deadline in Unix seconds.
400
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
412
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
401
413
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
402
414
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
415
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
403
416
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
404
417
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
405
418
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
@@ -412,8 +425,12 @@ export interface BlueActions {
412
425
  * @throws {BorrowExceedsSafeLtvError} when the resulting position exceeds buffered LLTV.
413
426
  * @throws {NonPositiveInputError} when `borrowAssets` is not positive.
414
427
  * @throws {NegativeInputError} when the borrow, fee, or a reallocation value is negative.
428
+ * Also thrown when maxPenalty is negative.
415
429
  * @throws {InputExceedsMaxError} when a fee, penalty, or reallocation exceeds its bound.
430
+ * Also thrown when maxPenalty exceeds WAD or a reallocation penalty exceeds maxPenalty.
416
431
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
432
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
433
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
417
434
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
418
435
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
419
436
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -461,6 +478,8 @@ export interface BlueActions {
461
478
  readonly borrowAssets: bigint;
462
479
  readonly positionData: AccrualPosition;
463
480
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
481
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
482
+ readonly maxPenalty?: bigint;
464
483
  readonly deadline: bigint;
465
484
  readonly referralFeePct?: bigint;
466
485
  readonly referralFeeRecipient?: Address;
@@ -478,7 +497,7 @@ export interface BlueActions {
478
497
  * @param params.repayShares - Exact shares, or `maxUint256` for a full repay.
479
498
  * @param params.nativeAmount - Optional full native funding equal to the derived repayment cap.
480
499
  * @param params.deadline - Final call deadline in Unix seconds.
481
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
500
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
482
501
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
483
502
  * @returns Lazy token prerequisite resolution and a synchronous deep-frozen transaction.
484
503
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
@@ -496,6 +515,8 @@ export interface BlueActions {
496
515
  * @throws {InputExceedsMaxError} when a fee is out of bounds or a share quote deadline is too far away.
497
516
  * @throws {MaxRepayAssetsBelowRepayAssetsError} when a signed share cap no longer covers the fresh quote.
498
517
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
518
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
519
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
499
520
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
500
521
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
501
522
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -567,7 +588,7 @@ export interface BlueActions {
567
588
  * @param params.positionData - Pre-fetched position used for balance and health validation.
568
589
  * @param params.collateralAssets - Collateral assets withdrawn.
569
590
  * @param params.deadline - Final call deadline in Unix seconds.
570
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
591
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
571
592
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
572
593
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction.
573
594
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
@@ -582,8 +603,9 @@ export interface BlueActions {
582
603
  * @throws {WithdrawMakesPositionUnhealthyError} when the result exceeds buffered LLTV.
583
604
  * @throws {NonPositiveInputError} when `collateralAssets` is not positive.
584
605
  * @throws {NegativeInputError} when collateral or the referral fee is negative.
585
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
586
606
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
607
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
608
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
587
609
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple authorization signatures are supplied.
588
610
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a token signature is supplied.
589
611
  * @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
@@ -648,7 +670,7 @@ export interface BlueActions {
648
670
  * @param params.collateralAssets - Collateral withdrawn, or zero for pure repay.
649
671
  * @param params.nativeAmount - Optional full native funding; must equal derived `maxRepayAssets`.
650
672
  * @param params.deadline - Final call deadline in Unix seconds; share mode is limited to the two-hour funding quote horizon.
651
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
673
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
652
674
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
653
675
  * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
654
676
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
@@ -666,9 +688,11 @@ export interface BlueActions {
666
688
  * @throws {MissingMarketPriceError} when withdrawal health cannot be validated without an oracle price.
667
689
  * @throws {WithdrawMakesPositionUnhealthyError} when the post-repay withdrawal exceeds buffered LLTV.
668
690
  * @throws {ExpiredDeadlineError} when the deadline is stale.
669
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD or a share-mode deadline exceeds the funding quote horizon.
691
+ * @throws {InputExceedsMaxError} when a share-mode deadline exceeds the funding quote horizon.
670
692
  * @throws {MaxRepayAssetsBelowRepayAssetsError} from `buildTx()` when a previously signed share-mode cap no longer covers the fresh derived minimum.
671
693
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
694
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
695
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
672
696
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
673
697
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
674
698
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -751,10 +775,12 @@ export interface BlueActions {
751
775
  * @param params.positionData - Pre-fetched position; required when `borrowAssets` is positive.
752
776
  * @param params.nativeAmount - Optional full native collateral funding; must equal `collateralAssets`.
753
777
  * @param params.reallocations - Optional Vault V2 reallocations; valid only for a borrow.
778
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
754
779
  * @param params.deadline - Final call deadline in Unix seconds.
755
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
780
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
756
781
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
757
782
  * @returns Lazy funding/authorization resolution and a synchronous deep-frozen transaction builder.
783
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
758
784
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
759
785
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
760
786
  * @throws {UnsupportedBlueMarketIrmError} when positive debt requires an unsupported IRM projection.
@@ -767,12 +793,16 @@ export interface BlueActions {
767
793
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
768
794
  * @throws {ExpiredDeadlineError} when the deadline is stale.
769
795
  * @throws {NegativeInputError} when an amount, native funding, referral fee, or reallocation penalty is negative.
796
+ * Also thrown when maxPenalty is negative.
770
797
  * @throws {NonPositiveInputError} when both legs or a reallocation amount is not positive.
771
798
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
772
799
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
773
800
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
774
801
  * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
802
+ * Also thrown when maxPenalty exceeds WAD or a reallocation penalty exceeds maxPenalty.
775
803
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
804
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
805
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
776
806
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
777
807
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
778
808
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -828,6 +858,8 @@ export interface BlueActions {
828
858
  readonly positionData?: AccrualPosition;
829
859
  readonly nativeAmount?: bigint;
830
860
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
861
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
862
+ readonly maxPenalty?: bigint;
831
863
  readonly deadline: bigint;
832
864
  readonly referralFeePct?: bigint;
833
865
  readonly referralFeeRecipient?: Address;
@@ -848,10 +880,12 @@ export interface BlueActions {
848
880
  * @param params.destination.marketParams - Distinct destination market with matching tokens.
849
881
  * @param params.destination.positionData - User's pre-fetched destination position.
850
882
  * @param params.reallocations - Optional Vault V2 reallocations into the destination.
883
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound the total penalty added to destination debt.
851
884
  * @param params.deadline - Final call deadline in Unix seconds.
852
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%.
885
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%.
853
886
  * @param params.referralFeeRecipient - Recipient required for a positive fee.
854
887
  * @returns Lazy Blue authorization resolution and a synchronous deep-frozen transaction builder.
888
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
855
889
  * @throws {ChainIdMismatchError} when the client targets another chain, or from
856
890
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
857
891
  * @throws {UnsupportedBlueMarketIrmError} when positive source or destination debt requires an unsupported IRM projection.
@@ -862,12 +896,16 @@ export interface BlueActions {
862
896
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
863
897
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
864
898
  * @throws {NegativeInputError} when a referral fee or reallocation penalty is negative.
899
+ * Also thrown when maxPenalty is negative.
865
900
  * @throws {NonPositiveInputError} when the source has no borrow shares or a reallocation amount is not positive.
866
901
  * @throws {MissingMarketPriceError} when destination health cannot be validated without an oracle price.
867
902
  * @throws {BorrowExceedsSafeLtvError} when the complete destination exceeds buffered LLTV.
868
903
  * @throws {ExpiredDeadlineError} when the deadline is stale.
869
904
  * @throws {InputExceedsMaxError} when a fee or reallocation exceeds its ABI bound.
905
+ * Also thrown when maxPenalty exceeds WAD or a reallocation penalty exceeds maxPenalty.
870
906
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
907
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
908
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
871
909
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
872
910
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
873
911
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -927,6 +965,8 @@ export interface BlueActions {
927
965
  readonly positionData: AccrualPosition;
928
966
  };
929
967
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
968
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound the total penalty added to destination debt. */
969
+ readonly maxPenalty?: bigint;
930
970
  readonly deadline: bigint;
931
971
  readonly referralFeePct?: bigint;
932
972
  readonly referralFeeRecipient?: Address;
@@ -990,20 +1030,28 @@ export interface BlueActions {
990
1030
  * For `refinance`, compute the plan on the destination-market handle (for
991
1031
  * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
992
1032
  * source-market handle. Pass the source position's `borrowAssets` accrued to
993
- * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
994
- * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1033
+ * the resolved plan expiry (or the required action deadline for entity
1034
+ * `refinance`) as `operation.amount`. With
1035
+ * `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
1036
+ * `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
1037
+ * resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
1038
+ * `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
1039
+ * compatibility. The optional `operation.referralFeePct` is WAD-scaled.
995
1040
  * The planner includes the referral fee and its own planned allocator-leg
996
1041
  * penalties in destination debt. Refinance never uses vaults with a 100%
997
- * penalty.
1042
+ * penalty. When executing the returned reallocations, pass the same explicit
1043
+ * maxPenalty to borrow, supplyCollateralBorrow, withdraw, or refinance.
998
1044
  *
999
1045
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1000
1046
  * @param params.options - Optional allocator discovery controls and operation to support.
1001
1047
  * @returns Action-ready reallocations and their post-simulation state.
1048
+ * @throws {InvalidBigIntInputError} when options.maxPenalty is supplied but is not a bigint.
1002
1049
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1003
1050
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1004
1051
  * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
1005
1052
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
1006
1053
  * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1054
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
1007
1055
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1008
1056
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1009
1057
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1056,7 +1104,6 @@ export declare class MorphoBlue implements BlueActions {
1056
1104
  */
1057
1105
  private assertWriteTargets;
1058
1106
  private getMaxLtv;
1059
- private getBlueBundlesV1QuoteTimestamp;
1060
1107
  private getTokenRequirements;
1061
1108
  private getAuthorizationRequirements;
1062
1109
  getMarketData(parameters?: FetchParameters): Promise<Market>;
@@ -1089,6 +1136,8 @@ export declare class MorphoBlue implements BlueActions {
1089
1136
  readonly userAddress: Address;
1090
1137
  readonly positionData: AccrualPosition;
1091
1138
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1139
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
1140
+ readonly maxPenalty?: bigint;
1092
1141
  readonly deadline: bigint;
1093
1142
  readonly referralFeePct?: bigint;
1094
1143
  readonly referralFeeRecipient?: Address;
@@ -1123,6 +1172,8 @@ export declare class MorphoBlue implements BlueActions {
1123
1172
  readonly borrowAssets: bigint;
1124
1173
  readonly positionData: AccrualPosition;
1125
1174
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1175
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
1176
+ readonly maxPenalty?: bigint;
1126
1177
  readonly deadline: bigint;
1127
1178
  readonly referralFeePct?: bigint;
1128
1179
  readonly referralFeeRecipient?: Address;
@@ -1189,6 +1240,8 @@ export declare class MorphoBlue implements BlueActions {
1189
1240
  readonly positionData?: AccrualPosition;
1190
1241
  readonly nativeAmount?: bigint;
1191
1242
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1243
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost. */
1244
+ readonly maxPenalty?: bigint;
1192
1245
  readonly deadline: bigint;
1193
1246
  readonly referralFeePct?: bigint;
1194
1247
  readonly referralFeeRecipient?: Address;
@@ -1207,6 +1260,8 @@ export declare class MorphoBlue implements BlueActions {
1207
1260
  readonly positionData: AccrualPosition;
1208
1261
  };
1209
1262
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
1263
+ /** Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound the total penalty added to destination debt. */
1264
+ readonly maxPenalty?: bigint;
1210
1265
  readonly deadline: bigint;
1211
1266
  readonly referralFeePct?: bigint;
1212
1267
  readonly referralFeeRecipient?: Address;
@@ -1294,20 +1349,28 @@ export declare class MorphoBlue implements BlueActions {
1294
1349
  * For `refinance`, compute the plan on the destination-market handle (for
1295
1350
  * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
1296
1351
  * source-market handle. Pass the source position's `borrowAssets` accrued to
1297
- * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
1298
- * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1352
+ * the resolved plan expiry (or the required action deadline for entity
1353
+ * `refinance`) as `operation.amount`. With
1354
+ * `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
1355
+ * `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
1356
+ * resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
1357
+ * `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
1358
+ * compatibility. The optional `operation.referralFeePct` is WAD-scaled.
1299
1359
  * The planner includes the referral fee and its own planned allocator-leg
1300
1360
  * penalties in destination debt. Refinance never uses vaults with a 100%
1301
- * penalty.
1361
+ * penalty. When executing the returned reallocations, pass the same explicit
1362
+ * maxPenalty to borrow, supplyCollateralBorrow, withdraw, or refinance.
1302
1363
  *
1303
1364
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
1304
1365
  * @param params.options - Optional allocator discovery controls and operation to support.
1305
1366
  * @returns Action-ready reallocations and their post-simulation state.
1367
+ * @throws {InvalidBigIntInputError} when options.maxPenalty is supplied but is not a bigint.
1306
1368
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
1307
1369
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1308
1370
  * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
1309
1371
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
1310
1372
  * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1373
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
1311
1374
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
1312
1375
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1313
1376
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -17,6 +17,7 @@ const withdraw_internal_js_1 = require("../../actions/blue/withdraw.internal.js"
17
17
  const withdrawBuyCallback_internal_js_1 = require("../../actions/blue/withdrawBuyCallback.internal.js");
18
18
  const getBlueAuthorizationRequirement_js_1 = require("../../actions/requirements/blue/getBlueAuthorizationRequirement.js");
19
19
  const chainCheck_js_1 = require("../../actions/requirements/chainCheck.js");
20
+ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundlesV1QuoteTimestamp.js");
20
21
  const index_js_1 = require("../../helpers/index.js");
21
22
  const metadata_js_1 = require("../../helpers/metadata.js");
22
23
  const parse_js_1 = require("../../helpers/parse.js");
@@ -99,9 +100,6 @@ class MorphoBlue {
99
100
  getMaxLtv(marketParams = this.parsedMarket) {
100
101
  return blue_sdk_1.MathLib.zeroFloorSub(marketParams.lltv, index_js_1.DEFAULT_LLTV_BUFFER);
101
102
  }
102
- getBlueBundlesV1QuoteTimestamp(lastUpdate, now = morpho_ts_1.Time.timestamp()) {
103
- return blue_sdk_1.MathLib.max(now, lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
104
- }
105
103
  async getTokenRequirements(chainCheck, params) {
106
104
  // Reject expiry before continuing this call.
107
105
  this.validateDeadline(params.deadline, params.now);
@@ -253,7 +251,10 @@ class MorphoBlue {
253
251
  marketId: this.parsedMarket.id,
254
252
  });
255
253
  }
256
- const allocations = (0, withdraw_internal_js_1.parseBlueWithdrawPenalty)((0, common_js_1.parseBlueAllocations)([...(params.reallocations ?? [])], this.parsedMarket), mode);
254
+ const allocations = (0, withdraw_internal_js_1.parseBlueWithdrawPenalty)((0, common_js_1.parseBlueAllocations)([...(params.reallocations ?? [])], {
255
+ marketParams: this.parsedMarket,
256
+ maxPenalty: params.maxPenalty,
257
+ }), mode);
257
258
  const reallocationPenaltyAssets = allocations.penaltyAssets;
258
259
  const expectedWithdrawAssets = assets > 0n ? assets : positionData.market.toSupplyAssets(shares, "Down");
259
260
  if (shares > 0n && reallocationPenaltyAssets > expectedWithdrawAssets) {
@@ -449,7 +450,7 @@ class MorphoBlue {
449
450
  return this.borrowPrepared(this.parseBorrowParams(params));
450
451
  }
451
452
  parseBorrowParams(params) {
452
- const { userAddress, borrowAssets, positionData, reallocations, deadline, referralFeePct, referralFeeRecipient, } = params;
453
+ const { userAddress, borrowAssets, positionData, reallocations, maxPenalty, deadline, referralFeePct, referralFeeRecipient, } = params;
453
454
  const normalizedReallocations = [...(reallocations ?? [])];
454
455
  return {
455
456
  ...this.parseSupplyCollateralBorrowParams({
@@ -459,6 +460,7 @@ class MorphoBlue {
459
460
  borrowAssets,
460
461
  positionData,
461
462
  reallocations: normalizedReallocations,
463
+ maxPenalty,
462
464
  deadline,
463
465
  referralFeePct,
464
466
  referralFeeRecipient,
@@ -582,9 +584,16 @@ class MorphoBlue {
582
584
  repayShares,
583
585
  deadline,
584
586
  now: createdAt,
587
+ healthTimestamp: collateralAssets > 0n
588
+ ? (0, getBlueBundlesV1QuoteTimestamp_js_1.getBlueBundlesV1QuoteTimestamp)({
589
+ lastUpdate: positionData.market.lastUpdate,
590
+ now: createdAt,
591
+ deadline,
592
+ })
593
+ : undefined,
585
594
  });
586
- const referralFeeAssets = (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, referralFeePct);
587
- const maxRepayAssets = expectedRepayAssets + referralFeeAssets;
595
+ const maxRepayAssets = expectedRepayAssets +
596
+ (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(expectedRepayAssets, referralFeePct);
588
597
  const nativeValue = (0, parse_js_1.parseNativeFunding)({
589
598
  chainId: this.chainId,
590
599
  token: this.parsedMarket.loanToken,
@@ -689,6 +698,7 @@ class MorphoBlue {
689
698
  collateralAssets,
690
699
  borrowAssets,
691
700
  reallocations: [...(params.reallocations ?? [])],
701
+ maxPenalty: params.maxPenalty,
692
702
  });
693
703
  const allocations = (0, supplyCollateralBorrow_internal_js_1.parseBlueSupplyCollateralBorrowAllocations)(this.parsedMarket, mode);
694
704
  if (borrowAssets > 0n) {
@@ -703,7 +713,11 @@ class MorphoBlue {
703
713
  });
704
714
  // Reject resulting debt above the buffered LLTV.
705
715
  (0, index_js_1.validatePositionHealth)({
706
- positionData: positionData.accrueInterest(this.getBlueBundlesV1QuoteTimestamp(positionData.market.lastUpdate, createdAt)),
716
+ positionData: positionData.accrueInterest((0, getBlueBundlesV1QuoteTimestamp_js_1.getBlueBundlesV1QuoteTimestamp)({
717
+ lastUpdate: positionData.market.lastUpdate,
718
+ now: createdAt,
719
+ deadline: normalized.deadline,
720
+ })),
707
721
  additionalCollateral: collateralAssets,
708
722
  borrowAmount: borrowAssets,
709
723
  marketId: this.parsedMarket.id,
@@ -811,7 +825,10 @@ class MorphoBlue {
811
825
  expectedMarketId: destinationMarketParams.id,
812
826
  expectedUser: userAddress,
813
827
  });
814
- const allocations = (0, common_js_1.parseBlueAllocations)([...(params.reallocations ?? [])], markets.destinationMarketParams);
828
+ const allocations = (0, common_js_1.parseBlueAllocations)([...(params.reallocations ?? [])], {
829
+ marketParams: markets.destinationMarketParams,
830
+ maxPenalty: params.maxPenalty,
831
+ });
815
832
  (0, refinanceValidation_js_1.validateBlueRefinanceQuote)({
816
833
  destinationMarketParams,
817
834
  sourcePosition: positionData,
@@ -819,6 +836,7 @@ class MorphoBlue {
819
836
  penaltyAssets: allocations.penaltyAssets,
820
837
  referralFeePct,
821
838
  now: createdAt,
839
+ deadline: normalized.deadline,
822
840
  });
823
841
  const input = {
824
842
  ...markets,
@@ -981,20 +999,28 @@ class MorphoBlue {
981
999
  * For `refinance`, compute the plan on the destination-market handle (for
982
1000
  * example, `client.morpho.blue(destination.marketParams, chainId)`), not the
983
1001
  * source-market handle. Pass the source position's `borrowAssets` accrued to
984
- * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
985
- * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
1002
+ * the resolved plan expiry (or the required action deadline for entity
1003
+ * `refinance`) as `operation.amount`. With
1004
+ * `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
1005
+ * `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
1006
+ * resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
1007
+ * `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
1008
+ * compatibility. The optional `operation.referralFeePct` is WAD-scaled.
986
1009
  * The planner includes the referral fee and its own planned allocator-leg
987
1010
  * penalties in destination debt. Refinance never uses vaults with a 100%
988
- * penalty.
1011
+ * penalty. When executing the returned reallocations, pass the same explicit
1012
+ * maxPenalty to borrow, supplyCollateralBorrow, withdraw, or refinance.
989
1013
  *
990
1014
  * @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
991
1015
  * @param params.options - Optional allocator discovery controls and operation to support.
992
1016
  * @returns Action-ready reallocations and their post-simulation state.
1017
+ * @throws {InvalidBigIntInputError} when options.maxPenalty is supplied but is not a bigint.
993
1018
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
994
1019
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
995
1020
  * @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
996
1021
  * @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
997
1022
  * @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
1023
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
998
1024
  * @throws {NonPositiveInputError} when an enabled operation amount is not positive.
999
1025
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1000
1026
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -6,6 +6,8 @@ import type { VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
6
6
  * price bound uses assets net of the referral fee. Neither snapshot is mutated.
7
7
  * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
8
8
  * @returns The destination maximum share price and minimum source share allowance.
9
+ * @throws {InvalidBigIntInputError} when `now` is not a bigint.
10
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after preparation.
9
11
  */
10
12
  export declare function computeVaultV1MigrateToV2Quote(params: VaultV1MigrateToV2AmountArgs & {
11
13
  readonly sourceVault: AccrualVault;
@@ -4,15 +4,20 @@ exports.computeVaultV1MigrateToV2Quote = computeVaultV1MigrateToV2Quote;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const common_js_1 = require("../../actions/bundles/common.js");
6
6
  const slippage_js_1 = require("../../helpers/slippage.js");
7
+ const validate_js_1 = require("../../helpers/validate.js");
7
8
  /**
8
9
  * @internal Quotes a migration from validated snapshots and intent without reading chain state.
9
10
  * The source accrues interest and performance fees before a shares-mode conversion; the target
10
11
  * price bound uses assets net of the referral fee. Neither snapshot is mutated.
11
12
  * @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
12
13
  * @returns The destination maximum share price and minimum source share allowance.
14
+ * @throws {InvalidBigIntInputError} when `now` is not a bigint.
15
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after preparation.
13
16
  */
14
17
  function computeVaultV1MigrateToV2Quote(params) {
15
18
  const { sourceVault, targetVault, assets, shares, referralFeePct, slippageTolerance, deadline, now, } = params;
19
+ // Bound the destination's forward-accrued deposit price.
20
+ (0, validate_js_1.validateVaultDepositDeadline)(deadline, { now });
16
21
  const grossAssets = assets ??
17
22
  sourceVault
18
23
  .accrueInterest(sourceVault.allocations
@@ -40,7 +40,7 @@ export interface VaultV1Actions {
40
40
  * only for a wNative vault.
41
41
  * @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
42
42
  * exceed 10%.
43
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
43
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%, deducted before
44
44
  * the vault deposit.
45
45
  * @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
46
46
  * @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
@@ -51,16 +51,18 @@ export interface VaultV1Actions {
51
51
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
52
52
  * @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
53
53
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
54
+ * @throws {InvalidBigIntInputError} when `now` is not a bigint.
54
55
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
55
56
  * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
56
57
  * @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
57
58
  * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
58
59
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
59
60
  * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
61
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
60
62
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
61
63
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
62
64
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
63
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
65
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or the deadline exceeds uint256.
64
66
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
65
67
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
66
68
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -122,7 +124,7 @@ export interface VaultV1Actions {
122
124
  * @param params.slippageTolerance - Optional WAD-scaled tolerance used only to size the minimum
123
125
  * share allowance. It does not impose an on-chain share-burn bound.
124
126
  * Defaults to 0.03% and cannot exceed 10%.
125
- * @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
127
+ * @param params.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero;
126
128
  * rounded down and deducted from the gross withdrawn assets.
127
129
  * @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
128
130
  * @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
@@ -144,6 +146,7 @@ export interface VaultV1Actions {
144
146
  * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
145
147
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
146
148
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
149
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
147
150
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
148
151
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
149
152
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
@@ -201,7 +204,7 @@ export interface VaultV1Actions {
201
204
  * @param params.shares - Exact vault shares to burn.
202
205
  * @param params.userAddress - Account that signs and submits the transaction; VaultBundlesV1
203
206
  * burns and pays `msg.sender`.
204
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted from the
207
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%, deducted from the
205
208
  * redeemed assets.
206
209
  * @param params.referralFeeRecipient - Optional non-zero recipient required for a positive fee.
207
210
  * @param params.deadline - Optional execution and share-permit deadline in Unix seconds; defaults
@@ -214,6 +217,7 @@ export interface VaultV1Actions {
214
217
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
215
218
  * @throws {NegativeInputError} when `referralFeePct` is negative.
216
219
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
220
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
217
221
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
218
222
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
219
223
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
@@ -378,7 +382,7 @@ export interface VaultV1Actions {
378
382
  * @param params.slippageTolerance - Optional WAD-scaled tolerance used to size the minimum
379
383
  * assets-mode source share allowance and the destination `maxSharePrice`; it does not impose
380
384
  * an on-chain source share-burn bound. Defaults to 0.03% and cannot exceed 10%.
381
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted from the
385
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%, deducted from the
382
386
  * source-vault proceeds.
383
387
  * @param params.referralFeeRecipient - Optional non-zero recipient required for a positive fee.
384
388
  * @param params.deadline - Optional execution and share-permit deadline in Unix seconds; defaults
@@ -398,9 +402,11 @@ export interface VaultV1Actions {
398
402
  * @throws {NonPositiveInputError} when the selected amount or a computed share value is not positive.
399
403
  * @throws {NegativeInputError} when slippage tolerance or `referralFeePct` is negative.
400
404
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
405
+ * @throws {InvalidBigIntInputError} when `now` is not a bigint.
401
406
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
402
- * @throws {InputExceedsMaxError} when the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
407
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or the selected amount, `maxSharePriceVaultV2`, or `deadline` exceeds uint256.
403
408
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
409
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
404
410
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
405
411
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
406
412
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered.