@morpho-org/morpho-sdk 10.1.0 → 10.3.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 (260) hide show
  1. package/README.md +126 -140
  2. package/lib/cjs/abis.d.ts +34 -0
  3. package/lib/cjs/abis.js +21 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +11 -3
  5. package/lib/cjs/actions/blue/borrow.internal.js +1 -0
  6. package/lib/cjs/actions/blue/borrow.js +8 -2
  7. package/lib/cjs/actions/blue/common.d.ts +4 -1
  8. package/lib/cjs/actions/blue/common.js +17 -3
  9. package/lib/cjs/actions/blue/refinance.d.ts +11 -3
  10. package/lib/cjs/actions/blue/refinance.internal.js +4 -1
  11. package/lib/cjs/actions/blue/refinance.js +8 -2
  12. package/lib/cjs/actions/blue/refinanceValidation.d.ts +3 -2
  13. package/lib/cjs/actions/blue/refinanceValidation.js +10 -6
  14. package/lib/cjs/actions/blue/repay.d.ts +4 -3
  15. package/lib/cjs/actions/blue/repay.js +3 -2
  16. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  17. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -2
  18. package/lib/cjs/actions/blue/supply.d.ts +5 -3
  19. package/lib/cjs/actions/blue/supply.js +4 -2
  20. package/lib/cjs/actions/blue/supplyCollateral.d.ts +4 -3
  21. package/lib/cjs/actions/blue/supplyCollateral.js +3 -2
  22. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  23. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  24. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  25. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +8 -2
  26. package/lib/cjs/actions/blue/withdraw.d.ts +11 -3
  27. package/lib/cjs/actions/blue/withdraw.internal.js +4 -1
  28. package/lib/cjs/actions/blue/withdraw.js +8 -2
  29. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
  30. package/lib/cjs/actions/blue/withdrawCollateral.js +3 -2
  31. package/lib/cjs/actions/bundles/common.d.ts +2 -8
  32. package/lib/cjs/actions/bundles/common.js +8 -20
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +0 -1
  34. package/lib/cjs/actions/midnight/takeBorrow.js +0 -1
  35. package/lib/cjs/actions/midnight/takeLend.js +0 -1
  36. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +0 -1
  37. package/lib/cjs/actions/midnight/takeWithdraw.js +0 -1
  38. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -1
  39. package/lib/cjs/actions/vaultV1/deposit.js +2 -1
  40. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +3 -2
  41. package/lib/cjs/actions/vaultV1/migrateToV2.js +2 -1
  42. package/lib/cjs/actions/vaultV1/redeem.d.ts +3 -2
  43. package/lib/cjs/actions/vaultV1/redeem.js +2 -1
  44. package/lib/cjs/actions/vaultV1/withdraw.d.ts +2 -1
  45. package/lib/cjs/actions/vaultV1/withdraw.js +2 -1
  46. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -1
  47. package/lib/cjs/actions/vaultV2/deposit.js +2 -1
  48. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +2 -1
  49. package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -1
  50. package/lib/cjs/actions/vaultV2/redeem.d.ts +3 -2
  51. package/lib/cjs/actions/vaultV2/redeem.js +2 -1
  52. package/lib/cjs/actions/vaultV2/withdraw.d.ts +2 -1
  53. package/lib/cjs/actions/vaultV2/withdraw.js +2 -1
  54. package/lib/cjs/constants.d.ts +1 -1
  55. package/lib/cjs/constants.js +2 -0
  56. package/lib/cjs/entities/blue/blue.d.ts +83 -20
  57. package/lib/cjs/entities/blue/blue.js +38 -12
  58. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  59. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
  60. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -6
  61. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -0
  62. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -7
  63. package/lib/cjs/entities/vaultV2/vaultV2.js +4 -0
  64. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -2
  65. package/lib/cjs/entities/vaultV2BlueReallocationData.js +19 -21
  66. package/lib/cjs/helpers/constant.d.ts +2 -0
  67. package/lib/cjs/helpers/constant.js +3 -1
  68. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  69. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
  70. package/lib/cjs/helpers/index.d.ts +1 -1
  71. package/lib/cjs/helpers/index.js +2 -1
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  73. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
  74. package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
  75. package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
  76. package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
  77. package/lib/cjs/helpers/reallocationPenalty.js +32 -0
  78. package/lib/cjs/helpers/referralFee.d.ts +2 -1
  79. package/lib/cjs/helpers/referralFee.js +5 -1
  80. package/lib/cjs/helpers/validate.d.ts +31 -4
  81. package/lib/cjs/helpers/validate.js +48 -9
  82. package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
  83. package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
  84. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  85. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
  86. package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
  87. package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
  88. package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
  89. package/lib/cjs/transactionPlan/blue/refinance.js +20 -3
  90. package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
  91. package/lib/cjs/transactionPlan/blue/repay.js +1 -2
  92. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  93. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  94. package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
  95. package/lib/cjs/transactionPlan/blue/supply.js +1 -2
  96. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  97. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
  98. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  99. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  100. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +15 -5
  101. package/lib/cjs/transactionPlan/blue/withdraw.js +25 -6
  102. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  103. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +11 -7
  104. package/lib/cjs/transactionPlan/deposit.js +4 -0
  105. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  106. package/lib/cjs/transactionPlan/intent.js +4 -2
  107. package/lib/cjs/transactionPlan/plan.d.ts +8 -4
  108. package/lib/cjs/transactionPlan/plan.js +8 -4
  109. package/lib/cjs/transactionPlan/types.d.ts +6 -0
  110. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +3 -3
  111. package/lib/cjs/transactionPlan/vaultv1/deposit.js +3 -3
  112. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  113. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
  114. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
  115. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
  116. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  117. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
  118. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
  119. package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
  120. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  121. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  122. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
  123. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
  124. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  125. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
  126. package/lib/cjs/types/error.d.ts +7 -6
  127. package/lib/cjs/types/error.js +10 -9
  128. package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
  129. package/lib/cjs/version.d.ts +1 -1
  130. package/lib/cjs/version.js +1 -1
  131. package/lib/esm/abis.d.ts +34 -0
  132. package/lib/esm/abis.js +20 -0
  133. package/lib/esm/actions/blue/borrow.d.ts +11 -3
  134. package/lib/esm/actions/blue/borrow.internal.js +1 -0
  135. package/lib/esm/actions/blue/borrow.js +8 -2
  136. package/lib/esm/actions/blue/common.d.ts +4 -1
  137. package/lib/esm/actions/blue/common.js +17 -3
  138. package/lib/esm/actions/blue/refinance.d.ts +11 -3
  139. package/lib/esm/actions/blue/refinance.internal.js +4 -1
  140. package/lib/esm/actions/blue/refinance.js +8 -2
  141. package/lib/esm/actions/blue/refinanceValidation.d.ts +3 -2
  142. package/lib/esm/actions/blue/refinanceValidation.js +10 -6
  143. package/lib/esm/actions/blue/repay.d.ts +4 -3
  144. package/lib/esm/actions/blue/repay.js +3 -2
  145. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -2
  147. package/lib/esm/actions/blue/supply.d.ts +5 -3
  148. package/lib/esm/actions/blue/supply.js +4 -2
  149. package/lib/esm/actions/blue/supplyCollateral.d.ts +4 -3
  150. package/lib/esm/actions/blue/supplyCollateral.js +3 -2
  151. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  152. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  153. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.js +8 -2
  155. package/lib/esm/actions/blue/withdraw.d.ts +11 -3
  156. package/lib/esm/actions/blue/withdraw.internal.js +4 -1
  157. package/lib/esm/actions/blue/withdraw.js +8 -2
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -2
  160. package/lib/esm/actions/bundles/common.d.ts +2 -8
  161. package/lib/esm/actions/bundles/common.js +4 -17
  162. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -2
  163. package/lib/esm/actions/midnight/takeBorrow.js +1 -2
  164. package/lib/esm/actions/midnight/takeLend.js +1 -2
  165. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -2
  166. package/lib/esm/actions/midnight/takeWithdraw.js +1 -2
  167. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -1
  168. package/lib/esm/actions/vaultV1/deposit.js +2 -1
  169. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +3 -2
  170. package/lib/esm/actions/vaultV1/migrateToV2.js +2 -1
  171. package/lib/esm/actions/vaultV1/redeem.d.ts +3 -2
  172. package/lib/esm/actions/vaultV1/redeem.js +2 -1
  173. package/lib/esm/actions/vaultV1/withdraw.d.ts +2 -1
  174. package/lib/esm/actions/vaultV1/withdraw.js +2 -1
  175. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -1
  176. package/lib/esm/actions/vaultV2/deposit.js +2 -1
  177. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +2 -1
  178. package/lib/esm/actions/vaultV2/forceWithdraw.js +2 -1
  179. package/lib/esm/actions/vaultV2/redeem.d.ts +3 -2
  180. package/lib/esm/actions/vaultV2/redeem.js +2 -1
  181. package/lib/esm/actions/vaultV2/withdraw.d.ts +2 -1
  182. package/lib/esm/actions/vaultV2/withdraw.js +2 -1
  183. package/lib/esm/constants.d.ts +1 -1
  184. package/lib/esm/constants.js +1 -1
  185. package/lib/esm/entities/blue/blue.d.ts +83 -20
  186. package/lib/esm/entities/blue/blue.js +38 -12
  187. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  188. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
  189. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -6
  190. package/lib/esm/entities/vaultV1/vaultV1.js +7 -1
  191. package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -7
  192. package/lib/esm/entities/vaultV2/vaultV2.js +5 -1
  193. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -2
  194. package/lib/esm/entities/vaultV2BlueReallocationData.js +17 -19
  195. package/lib/esm/helpers/constant.d.ts +2 -0
  196. package/lib/esm/helpers/constant.js +2 -0
  197. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  198. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
  199. package/lib/esm/helpers/index.d.ts +1 -1
  200. package/lib/esm/helpers/index.js +1 -1
  201. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  202. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
  203. package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
  204. package/lib/esm/helpers/quoteBlueRepay.js +21 -8
  205. package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
  206. package/lib/esm/helpers/reallocationPenalty.js +28 -0
  207. package/lib/esm/helpers/referralFee.d.ts +2 -1
  208. package/lib/esm/helpers/referralFee.js +5 -1
  209. package/lib/esm/helpers/validate.d.ts +31 -4
  210. package/lib/esm/helpers/validate.js +48 -11
  211. package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
  212. package/lib/esm/helpers/validateMidnightBounds.js +1 -2
  213. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  214. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
  215. package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
  216. package/lib/esm/transactionPlan/blue/borrow.js +27 -9
  217. package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
  218. package/lib/esm/transactionPlan/blue/refinance.js +20 -3
  219. package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
  220. package/lib/esm/transactionPlan/blue/repay.js +1 -2
  221. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  222. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  223. package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
  224. package/lib/esm/transactionPlan/blue/supply.js +1 -2
  225. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  226. package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
  227. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  228. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  229. package/lib/esm/transactionPlan/blue/withdraw.d.ts +15 -5
  230. package/lib/esm/transactionPlan/blue/withdraw.js +25 -6
  231. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  232. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +11 -7
  233. package/lib/esm/transactionPlan/deposit.js +5 -1
  234. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  235. package/lib/esm/transactionPlan/intent.js +4 -2
  236. package/lib/esm/transactionPlan/plan.d.ts +8 -4
  237. package/lib/esm/transactionPlan/plan.js +8 -4
  238. package/lib/esm/transactionPlan/types.d.ts +6 -0
  239. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +3 -3
  240. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -3
  241. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  242. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
  243. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
  244. package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
  245. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  246. package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
  247. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
  248. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
  249. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  250. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  251. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
  252. package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
  253. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  254. package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
  255. package/lib/esm/types/error.d.ts +7 -6
  256. package/lib/esm/types/error.js +11 -10
  257. package/lib/esm/types/sharedLiquidity.d.ts +7 -2
  258. package/lib/esm/version.d.ts +1 -1
  259. package/lib/esm/version.js +1 -1
  260. package/package.json +3 -3
@@ -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.
@@ -12,7 +12,7 @@ import { buildVaultV1Withdraw, } from "../../actions/vaultV1/withdraw.js";
12
12
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
13
13
  import { resolveTransactionMetadata } from "../../helpers/metadata.js";
14
14
  import { parseUint256 } from "../../helpers/parse.js";
15
- import { validateNativeVaultAsset } from "../../helpers/validate.js";
15
+ import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
16
16
  import { AmountAndSharesExclusiveError, ExpiredDeadlineError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
17
17
  import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
18
18
  import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
@@ -73,6 +73,8 @@ export class MorphoVaultV1 {
73
73
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
74
74
  }
75
75
  const createdAt = suppliedNow ?? Time.timestamp();
76
+ // Reject a non-bigint clock before deriving the default deadline.
77
+ validateReferenceTime(createdAt);
76
78
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
77
79
  if (deadline <= createdAt) {
78
80
  throw new ExpiredDeadlineError(deadline, createdAt);
@@ -89,6 +91,8 @@ export class MorphoVaultV1 {
89
91
  validateNativeVaultAsset(this.chainId, vaultAsset);
90
92
  }
91
93
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
94
+ // Bound forward accrual before deriving the deposit price protection.
95
+ validateVaultDepositDeadline(deadline, { now: createdAt });
92
96
  const maxSharePrice = computeVaultMaxSharePrice({
93
97
  vaultData,
94
98
  deadline,
@@ -417,6 +421,8 @@ export class MorphoVaultV1 {
417
421
  const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
418
422
  validateSlippageTolerance(slippageTolerance);
419
423
  const createdAt = suppliedNow ?? Time.timestamp();
424
+ // Reject a non-bigint clock before deriving the default deadline.
425
+ validateReferenceTime(createdAt);
420
426
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
421
427
  if (deadline <= createdAt) {
422
428
  throw new ExpiredDeadlineError(deadline, createdAt);
@@ -45,7 +45,7 @@ export interface VaultV2Actions {
45
45
  * only for a wNative vault.
46
46
  * @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
47
47
  * exceed 10%.
48
- * @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
48
+ * @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%, deducted before
49
49
  * the vault deposit.
50
50
  * @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
51
51
  * @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
@@ -56,16 +56,18 @@ export interface VaultV2Actions {
56
56
  * `getRequirements()` when the RPC reports another chain via `eth_chainId`.
57
57
  * @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
58
58
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
59
+ * @throws {InvalidBigIntInputError} when `now` is not a bigint.
59
60
  * @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
60
61
  * @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
61
62
  * @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
62
63
  * @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
63
64
  * @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
64
65
  * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
66
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
65
67
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
66
68
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
67
69
  * @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
68
- * @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
70
+ * @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or the deadline exceeds uint256.
69
71
  * @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
70
72
  * @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
71
73
  * @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
@@ -128,7 +130,7 @@ export interface VaultV2Actions {
128
130
  * @param params.slippageTolerance - Optional WAD-scaled tolerance used only to size the minimum
129
131
  * share allowance. It does not impose an on-chain share-burn bound.
130
132
  * Defaults to 0.03% and cannot exceed 10%.
131
- * @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
133
+ * @param params.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero;
132
134
  * rounded down and deducted from the gross withdrawn assets.
133
135
  * @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
134
136
  * @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
@@ -150,6 +152,7 @@ export interface VaultV2Actions {
150
152
  * @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
151
153
  * @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
152
154
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
155
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
153
156
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
154
157
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
155
158
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
@@ -204,7 +207,7 @@ export interface VaultV2Actions {
204
207
  * @param params - The redeem parameters.
205
208
  * @param params.shares - Exact vault shares to burn.
206
209
  * @param params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
207
- * @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
210
+ * @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be at most 10%.
208
211
  * @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
209
212
  * @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
210
213
  * @returns Lazy share-allowance requirements and a synchronous transaction builder.
@@ -216,6 +219,7 @@ export interface VaultV2Actions {
216
219
  * @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
217
220
  * @throws {NegativeInputError} when `referralFeePct` is negative.
218
221
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
222
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
219
223
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
220
224
  * @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
221
225
  * @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
@@ -410,7 +414,7 @@ export interface VaultV2Actions {
410
414
  * derived at `MAX_SLIPPAGE_TOLERANCE`. When that floor rounds down to zero (dust exits) it is
411
415
  * clamped to `1`, so any positive override is accepted.
412
416
  * @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
413
- * `referralFeeRecipient`. Defaults to `0n`.
417
+ * `referralFeeRecipient`, at most 10%. Defaults to `0n`.
414
418
  * @param params.referralFeeRecipient - Optional referral fee recipient, required when
415
419
  * `referralFeePct` is positive.
416
420
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
@@ -421,8 +425,9 @@ export interface VaultV2Actions {
421
425
  * `minSharePriceE27` is not positive.
422
426
  * @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
423
427
  * @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
424
- * `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
425
- * below WAD, or when `deadline` is more than one year after handle creation.
428
+ * `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `deadline` is more than one year after handle creation.
429
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
430
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
426
431
  * @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
427
432
  * requirement resolution.
428
433
  * @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
@@ -13,7 +13,7 @@ import { buildVaultV2Withdraw, } from "../../actions/vaultV2/withdraw.js";
13
13
  import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
14
14
  import { resolveTransactionMetadata } from "../../helpers/metadata.js";
15
15
  import { parseUint256 } from "../../helpers/parse.js";
16
- import { validateNativeVaultAsset } from "../../helpers/validate.js";
16
+ import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
17
17
  import { ExpiredDeadlineError, NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
18
18
  import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
19
19
  import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
@@ -74,6 +74,8 @@ export class MorphoVaultV2 {
74
74
  throw new VaultAddressMismatchError(this.vault, vaultData.address);
75
75
  }
76
76
  const createdAt = suppliedNow ?? Time.timestamp();
77
+ // Reject a non-bigint clock before deriving the default deadline.
78
+ validateReferenceTime(createdAt);
77
79
  const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
78
80
  if (deadline <= createdAt) {
79
81
  throw new ExpiredDeadlineError(deadline, createdAt);
@@ -90,6 +92,8 @@ export class MorphoVaultV2 {
90
92
  validateNativeVaultAsset(this.chainId, vaultAsset);
91
93
  }
92
94
  const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
95
+ // Bound forward accrual before deriving the deposit price protection.
96
+ validateVaultDepositDeadline(deadline, { now: createdAt });
93
97
  const maxSharePrice = computeVaultMaxSharePrice({
94
98
  vaultData,
95
99
  deadline,
@@ -402,8 +402,13 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
402
402
  * destination-market handle (for example,
403
403
  * `client.morpho.blue(destination.marketParams, chainId)`), not the source
404
404
  * handle. Pass the source position's `borrowAssets` accrued to
405
- * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
406
- * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
405
+ * the resolved plan expiry (or the required action deadline for entity
406
+ * `refinance`) as `operation.amount`. With
407
+ * `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
408
+ * `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
409
+ * resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
410
+ * `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
411
+ * compatibility. The optional `operation.referralFeePct` is WAD-scaled.
407
412
  * The planner includes the referral fee and its allocator-leg penalties in
408
413
  * destination debt, so penalized legs also cover their own penalty.
409
414
  * Refinance never uses vaults with a 100% penalty.
@@ -467,8 +472,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
467
472
  * @returns Flat action-ready reallocations and their post-simulation state.
468
473
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
469
474
  * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
475
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
470
476
  * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
471
477
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
478
+ * @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
472
479
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
473
480
  * @throws {UnknownReallocationMarketError} when a required market is absent.
474
481
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -538,6 +545,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
538
545
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
539
546
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
540
547
  * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
548
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
541
549
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
542
550
  * @throws {UnknownReallocationMarketError} when a required market is absent.
543
551
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -585,6 +593,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
585
593
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
586
594
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
587
595
  * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
596
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
588
597
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
589
598
  * @throws {UnknownReallocationMarketError} when a required market is absent.
590
599
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -2,8 +2,10 @@ import { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMark
2
2
  import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
3
3
  import { isAddressEqual } from "viem";
4
4
  import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1ReferralFeeAssets, } from "../actions/blue/common.js";
5
- import { DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, MAX_REALLOCATION_PENALTY, } from "../helpers/constant.js";
5
+ import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "../helpers/constant.js";
6
+ import { resolveMaxPenalty } from "../helpers/reallocationPenalty.js";
6
7
  import { resolveAllocatorCapHeadroom, resolveCapAccrualBuffer, resolveMaxWithdrawalUtilization, } from "../helpers/utilization.js";
8
+ import { validateMidnightReferralFeeCap } from "../helpers/validateMidnightBounds.js";
7
9
  import { InputExceedsMaxError, InsufficientSharedLiquidityError, NegativeInputError, NonPositiveInputError, ReallocationAdapterSupplySharesUnderflowError, ReallocationAllocationUnderflowError, ReallocationWithdrawExceedsMarketSupplyError, ReferralFeePctExceededError, UnknownReallocationActiveAdaptersError, UnknownReallocationAdapterError, UnknownReallocationAllocationError, UnknownReallocationMarketError, UnknownReallocationMarketPublicAllocatorConfigError, UnknownReallocationPublicAllocatorConfigError, UnknownReallocationVaultError, } from "../types/index.js";
8
10
  const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
9
11
  const createCapReserveState = (markets) => ({
@@ -63,20 +65,6 @@ const getAdapterIds = (cache, adapter, market) => {
63
65
  cache.set(key, ids);
64
66
  return ids;
65
67
  };
66
- const resolveMaxPenalty = (value) => {
67
- const penalty = value ?? DEFAULT_MAX_REALLOCATION_PENALTY;
68
- if (penalty < 0n) {
69
- throw new NegativeInputError("maxPenalty", penalty);
70
- }
71
- if (penalty > MAX_REALLOCATION_PENALTY) {
72
- throw new InputExceedsMaxError({
73
- field: "maxPenalty",
74
- value: penalty,
75
- max: MAX_REALLOCATION_PENALTY,
76
- });
77
- }
78
- return penalty;
79
- };
80
68
  const getCanonicalMarket = (markets, market) => (markets[market.id] ??= new Market({ ...market }));
81
69
  const clonePosition = (position, markets) => new AccrualPosition(position, getCanonicalMarket(markets, position.market));
82
70
  const cloneAccrualVault = (vault, markets) => new AccrualVault({
@@ -604,8 +592,13 @@ export class VaultV2BlueReallocationData {
604
592
  * destination-market handle (for example,
605
593
  * `client.morpho.blue(destination.marketParams, chainId)`), not the source
606
594
  * handle. Pass the source position's `borrowAssets` accrued to
607
- * `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
608
- * `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
595
+ * the resolved plan expiry (or the required action deadline for entity
596
+ * `refinance`) as `operation.amount`. With
597
+ * `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
598
+ * `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
599
+ * resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
600
+ * `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
601
+ * compatibility. The optional `operation.referralFeePct` is WAD-scaled.
609
602
  * The planner includes the referral fee and its allocator-leg penalties in
610
603
  * destination debt, so penalized legs also cover their own penalty.
611
604
  * Refinance never uses vaults with a 100% penalty.
@@ -669,8 +662,10 @@ export class VaultV2BlueReallocationData {
669
662
  * @returns Flat action-ready reallocations and their post-simulation state.
670
663
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
671
664
  * @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
665
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
672
666
  * @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
673
667
  * @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
668
+ * @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
674
669
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
675
670
  * @throws {UnknownReallocationMarketError} when a required market is absent.
676
671
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -940,6 +935,7 @@ export class VaultV2BlueReallocationData {
940
935
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
941
936
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
942
937
  * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
938
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
943
939
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
944
940
  * @throws {UnknownReallocationMarketError} when a required market is absent.
945
941
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1003,6 +999,7 @@ export class VaultV2BlueReallocationData {
1003
999
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
1004
1000
  * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1005
1001
  * @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
1002
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
1006
1003
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
1007
1004
  * @throws {UnknownReallocationMarketError} when a required market is absent.
1008
1005
  * @throws {UnknownReallocationVaultError} when configured vault state is absent.
@@ -1591,8 +1588,7 @@ function resolveVaultCandidateIdleState(params) {
1591
1588
  }
1592
1589
  const vault = data.getVault(vaultAddress);
1593
1590
  if (!isAddressEqual(publicAllocatorConfig.vault, vaultAddress) ||
1594
- publicAllocatorConfig.penalty >
1595
- (options.maxPenalty ?? DEFAULT_MAX_REALLOCATION_PENALTY)) {
1591
+ publicAllocatorConfig.penalty > resolveMaxPenalty(options.maxPenalty)) {
1596
1592
  return;
1597
1593
  }
1598
1594
  if (penalty != null && publicAllocatorConfig.penalty !== penalty) {
@@ -2464,6 +2460,8 @@ function resolveOperationFeeAssets(operation) {
2464
2460
  if (referralFeePct >= MathLib.WAD) {
2465
2461
  throw new ReferralFeePctExceededError(referralFeePct);
2466
2462
  }
2463
+ // Reject fees that the refinance bundle builder would reject.
2464
+ validateMidnightReferralFeeCap(referralFeePct);
2467
2465
  const feeAssets = operation.type === "refinance"
2468
2466
  ? getBlueBundlesV1ReferralFeeAssets(amount, referralFeePct)
2469
2467
  : 0n;
@@ -1,4 +1,6 @@
1
1
  import { type Address } from "viem";
2
+ /** Maximum forward accrual window for vault deposits and V1-to-V2 migration, in seconds. */
3
+ export declare const VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
2
4
  /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
3
5
  export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
4
6
  /**
@@ -1,6 +1,8 @@
1
1
  import { ChainId, MathLib } from "@morpho-org/blue-sdk";
2
2
  import { Time } from "@morpho-org/morpho-ts";
3
3
  import { maxUint96 } from "viem";
4
+ /** Maximum forward accrual window for vault deposits and V1-to-V2 migration, in seconds. */
5
+ export const VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
4
6
  /** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
5
7
  export const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
6
8
  /**
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @internal Projects health to realistic finite deadlines, never before now or the market snapshot.
3
+ * Deadlines more than 365 days out (maxUint256/maxUint48-style unlimited sentinels) use
4
+ * the legacy two-hour projection to avoid interest-accrual overflow.
5
+ */
6
+ export declare function getBlueBundlesV1QuoteTimestamp({ lastUpdate, now, deadline, }: {
7
+ readonly lastUpdate: bigint;
8
+ readonly now: bigint;
9
+ readonly deadline?: bigint;
10
+ }): bigint;
@@ -0,0 +1,15 @@
1
+ import { MathLib } from "@morpho-org/blue-sdk";
2
+ import { Time } from "@morpho-org/morpho-ts";
3
+ const MAX_BLUE_HEALTH_DEADLINE_HORIZON = Time.s.from.d(365n);
4
+ /**
5
+ * @internal Projects health to realistic finite deadlines, never before now or the market snapshot.
6
+ * Deadlines more than 365 days out (maxUint256/maxUint48-style unlimited sentinels) use
7
+ * the legacy two-hour projection to avoid interest-accrual overflow.
8
+ */
9
+ export function getBlueBundlesV1QuoteTimestamp({ lastUpdate, now, deadline, }) {
10
+ const minTimestamp = MathLib.max(now, lastUpdate);
11
+ return deadline === undefined ||
12
+ deadline > minTimestamp + MAX_BLUE_HEALTH_DEADLINE_HORIZON
13
+ ? minTimestamp + Time.s.from.h(2n)
14
+ : MathLib.max(minTimestamp, deadline);
15
+ }
@@ -1,5 +1,5 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
3
3
  export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
4
4
  export { addTransactionMetadata } from "./metadata.js";
5
5
  export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
@@ -1,5 +1,5 @@
1
1
  export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
2
- export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
2
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
3
3
  export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
4
4
  export { addTransactionMetadata } from "./metadata.js";
5
5
  export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
@@ -20,7 +20,7 @@ export interface PreviewVaultV2ForceWithdrawParams {
20
20
  * without `userAddress`.
21
21
  */
22
22
  readonly feeProjectionTimestamp?: bigint;
23
- /** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
23
+ /** Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`. */
24
24
  readonly referralFeePct?: bigint;
25
25
  /** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
26
26
  * enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
@@ -78,7 +78,7 @@ export interface VaultV2ForceWithdrawPreview {
78
78
  * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
79
79
  * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
80
80
  * keep the deadline itself within that horizon. Ignored without `userAddress`.
81
- * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
81
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
82
82
  * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
83
83
  * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
84
84
  * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
@@ -86,7 +86,7 @@ export interface VaultV2ForceWithdrawPreview {
86
86
  * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
87
87
  * `adapter` override that is not the vault's sole adapter, an adapter that is not a
88
88
  * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
89
- * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
89
+ * `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
90
90
  * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
91
91
  * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
92
92
  * exit whose realized share price rounds down to zero at the default slippage tolerance (which
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
2
2
  import { isAddressEqual, maxUint256, zeroAddress } from "viem";
3
+ import { MIDNIGHT_MAX_REFERRAL_FEE_PCT } from "./constant.js";
3
4
  import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
4
5
  /**
5
6
  * Previews what a Vault V2 force withdrawal delivers, without any RPC.
@@ -24,7 +25,7 @@ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdraw
24
25
  * `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
25
26
  * more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
26
27
  * keep the deadline itself within that horizon. Ignored without `userAddress`.
27
- * @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
28
+ * @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
28
29
  * @param params.referralFeeRecipient - Optional referral fee recipient. Required when
29
30
  * `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
30
31
  * When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
@@ -32,7 +33,7 @@ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdraw
32
33
  * @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
33
34
  * `adapter` override that is not the vault's sole adapter, an adapter that is not a
34
35
  * MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
35
- * `referralFeePct` outside `[0, WAD)`, a positive `referralFeePct` without a non-zero
36
+ * `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
36
37
  * `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
37
38
  * whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
38
39
  * exit whose realized share price rounds down to zero at the default slippage tolerance (which
@@ -59,9 +60,7 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
59
60
  if (requestedExitAssets <= 0n) {
60
61
  return undefined;
61
62
  }
62
- // Out of the range the action accepts, `netAssets` would quote a payout the contract can never
63
- // deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
64
- if (referralFeePct < 0n || referralFeePct >= MathLib.WAD) {
63
+ if (referralFeePct < 0n || referralFeePct > MIDNIGHT_MAX_REFERRAL_FEE_PCT) {
65
64
  return undefined;
66
65
  }
67
66
  if (referralFeePct > 0n &&
@@ -1,14 +1,18 @@
1
- import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
1
+ import { AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
2
2
  /** @internal Quotes repayment funding without projecting a position for health checks. */
3
3
  export declare function quoteBlueRepayFunding(params: Parameters<typeof quoteBlueRepay>[0]): bigint;
4
- /** @internal Quotes Blue repayment funding and the position used for withdrawal health checks. */
5
- export declare function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, }: {
4
+ /**
5
+ * @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
6
+ * Debt-free positions retain their snapshot without projecting market-wide interest.
7
+ */
8
+ export declare function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }: {
6
9
  readonly positionData: AccrualPosition;
7
10
  readonly marketId: MarketId;
8
11
  readonly repayAssets: bigint;
9
12
  readonly repayShares: bigint;
10
13
  readonly deadline: bigint;
11
14
  readonly now: bigint;
15
+ readonly healthTimestamp?: bigint;
12
16
  }): {
13
17
  simulatedRepayShares: bigint;
14
18
  accruedPosition: AccrualPosition;
@@ -1,4 +1,4 @@
1
- import { MathLib, } from "@morpho-org/blue-sdk";
1
+ import { AccrualPosition, MathLib } from "@morpho-org/blue-sdk";
2
2
  import { Time } from "@morpho-org/morpho-ts";
3
3
  import { maxUint256 } from "viem";
4
4
  import { InputExceedsMaxError } from "../types/error.js";
@@ -13,8 +13,11 @@ export function quoteBlueRepayFunding(params) {
13
13
  }
14
14
  return params.repayAssets;
15
15
  }
16
- /** @internal Quotes Blue repayment funding and the position used for withdrawal health checks. */
17
- export function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, }) {
16
+ /**
17
+ * @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
18
+ * Debt-free positions retain their snapshot without projecting market-wide interest.
19
+ */
20
+ export function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }) {
18
21
  const saturatedRepay = repayShares === maxUint256;
19
22
  const simulatedRepayShares = saturatedRepay
20
23
  ? positionData.borrowShares
@@ -33,10 +36,20 @@ export function quoteBlueRepay({ positionData, marketId, repayAssets, repayShare
33
36
  max: quoteHorizon,
34
37
  });
35
38
  }
36
- const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
37
- const accruedPosition = positionData.accrueInterest(accrualTimestamp);
38
- const expectedRepayAssets = repayAssets <= 0n && repayShares > 0n
39
- ? accruedPosition.market.toBorrowAssets(simulatedRepayShares, "Up")
40
- : repayAssets;
39
+ const accrualTimestamp = healthTimestamp ?? (repayShares > 0n ? deadline : quoteHorizon);
40
+ const accruedPosition = positionData.borrowShares === 0n
41
+ ? new AccrualPosition(positionData, positionData.market)
42
+ : positionData.accrueInterest(accrualTimestamp);
43
+ if (repayAssets > 0n || simulatedRepayShares <= 0n) {
44
+ return {
45
+ simulatedRepayShares,
46
+ accruedPosition,
47
+ expectedRepayAssets: repayAssets,
48
+ };
49
+ }
50
+ const fundingPosition = accrualTimestamp === deadline
51
+ ? accruedPosition
52
+ : positionData.accrueInterest(deadline);
53
+ const expectedRepayAssets = fundingPosition.market.toBorrowAssets(simulatedRepayShares, "Up");
41
54
  return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
42
55
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Resolves an omitted reallocation penalty bound and validates its runtime type and range.
3
+ * @param value - Optional WAD-scaled penalty bound.
4
+ * @returns A bigint in [0, WAD], defaulting only undefined to zero.
5
+ * @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
6
+ * @throws {NegativeInputError} when the bound is negative.
7
+ * @throws {InputExceedsMaxError} when the bound exceeds WAD.
8
+ * @internal
9
+ */
10
+ export declare const resolveMaxPenalty: (value: unknown) => bigint;
@@ -0,0 +1,28 @@
1
+ import { InputExceedsMaxError, InvalidBigIntInputError, NegativeInputError, } from "../types/error.js";
2
+ import { DEFAULT_MAX_REALLOCATION_PENALTY, MAX_REALLOCATION_PENALTY, } from "./constant.js";
3
+ /**
4
+ * Resolves an omitted reallocation penalty bound and validates its runtime type and range.
5
+ * @param value - Optional WAD-scaled penalty bound.
6
+ * @returns A bigint in [0, WAD], defaulting only undefined to zero.
7
+ * @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
8
+ * @throws {NegativeInputError} when the bound is negative.
9
+ * @throws {InputExceedsMaxError} when the bound exceeds WAD.
10
+ * @internal
11
+ */
12
+ export const resolveMaxPenalty = (value) => {
13
+ const penalty = value === undefined ? DEFAULT_MAX_REALLOCATION_PENALTY : value;
14
+ if (typeof penalty !== "bigint") {
15
+ throw new InvalidBigIntInputError("maxPenalty", penalty);
16
+ }
17
+ if (penalty < 0n) {
18
+ throw new NegativeInputError("maxPenalty", penalty);
19
+ }
20
+ if (penalty > MAX_REALLOCATION_PENALTY) {
21
+ throw new InputExceedsMaxError({
22
+ field: "maxPenalty",
23
+ value: penalty,
24
+ max: MAX_REALLOCATION_PENALTY,
25
+ });
26
+ }
27
+ return penalty;
28
+ };