@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
@@ -18,9 +18,11 @@ export interface BlueBorrowParams {
18
18
  readonly maxLtv: bigint;
19
19
  /** Optional validated Vault V2 BluePublicAllocator reallocations. */
20
20
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
21
+ /** Maximum WAD-scaled penalty rate per reallocation, defaulting to zero; it does not bound total proceeds lost. */
22
+ readonly maxPenalty?: bigint;
21
23
  /** Final call deadline in Unix seconds. */
22
24
  readonly deadline: bigint;
23
- /** Optional WAD-scaled referral fee, strictly below 100%. */
25
+ /** Optional WAD-scaled referral fee, at most 10%. */
24
26
  readonly referralFeePct?: bigint;
25
27
  /** Recipient required when `referralFeePct` is positive. */
26
28
  readonly referralFeeRecipient?: Address;
@@ -43,8 +45,9 @@ export interface BlueBorrowParams {
43
45
  * @param params.args.borrowAssets - Gross loan assets borrowed.
44
46
  * @param params.args.maxLtv - Maximum post-operation LTV.
45
47
  * @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
48
+ * @param params.args.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.
46
49
  * @param params.args.deadline - Final call deadline in Unix seconds.
47
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
50
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
48
51
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
49
52
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
50
53
  * @param params.metadata - Optional transaction metadata.
@@ -52,10 +55,15 @@ export interface BlueBorrowParams {
52
55
  * combined BlueBundlesV1 entrypoint with a zero collateral leg.
53
56
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
54
57
  * `id` that does not hash from its tuple fields.
58
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
55
59
  * @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
60
+ * Also thrown when maxPenalty is negative.
56
61
  * @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
57
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
62
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its bound.
63
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
58
64
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
65
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
66
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
59
67
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
60
68
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
61
69
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -11,6 +11,7 @@ export const parseBlueBorrow = (params) => ({
11
11
  borrowAssets: params.args.borrowAssets,
12
12
  maxLtv: params.args.maxLtv,
13
13
  reallocations: params.args.reallocations,
14
+ maxPenalty: params.args.maxPenalty,
14
15
  deadline: params.args.deadline,
15
16
  referralFeePct: params.args.referralFeePct,
16
17
  referralFeeRecipient: params.args.referralFeeRecipient,
@@ -12,8 +12,9 @@ import { buildBlueBorrow, parseBlueBorrow } from "./borrow.internal.js";
12
12
  * @param params.args.borrowAssets - Gross loan assets borrowed.
13
13
  * @param params.args.maxLtv - Maximum post-operation LTV.
14
14
  * @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
15
+ * @param params.args.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.
15
16
  * @param params.args.deadline - Final call deadline in Unix seconds.
16
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
17
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
17
18
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
18
19
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
19
20
  * @param params.metadata - Optional transaction metadata.
@@ -21,10 +22,15 @@ import { buildBlueBorrow, parseBlueBorrow } from "./borrow.internal.js";
21
22
  * combined BlueBundlesV1 entrypoint with a zero collateral leg.
22
23
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
23
24
  * `id` that does not hash from its tuple fields.
25
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
24
26
  * @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
27
+ * Also thrown when maxPenalty is negative.
25
28
  * @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
26
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
29
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its bound.
30
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
27
31
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
32
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
33
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
28
34
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
29
35
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
30
36
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -70,7 +70,10 @@ export declare const getBlueBundlesV1SignedAuthorization: (params: {
70
70
  authorizationSignature?: AuthorizationRequirementSignature;
71
71
  }) => BlueBundlesV1SignedAuthorization;
72
72
  /** Parses an ordered reallocation plan and its aggregate penalty once. @internal */
73
- export declare const parseBlueAllocations: (reallocations: readonly VaultV2BlueReallocation[], targetMarketParams: BlueMarket) => {
73
+ export declare const parseBlueAllocations: (reallocations: readonly VaultV2BlueReallocation[], { marketParams: targetMarketParams, maxPenalty, }: {
74
+ readonly marketParams: BlueMarket;
75
+ readonly maxPenalty?: bigint;
76
+ }) => {
74
77
  readonly publicAllocations: readonly {
75
78
  readonly vault: Address;
76
79
  readonly adapter: Address;
@@ -86,13 +86,27 @@ export const getBlueBundlesV1SignedAuthorization = (params) => {
86
86
  };
87
87
  };
88
88
  /** Parses an ordered reallocation plan and its aggregate penalty once. @internal */
89
- export const parseBlueAllocations = (reallocations, targetMarketParams) => {
89
+ export const parseBlueAllocations = (reallocations, { marketParams: targetMarketParams, maxPenalty, }) => {
90
+ // Snapshot each Vault V2 entry so validation, accounting and encoding read the same values.
91
+ const snapshots = reallocations.map((reallocation) => {
92
+ if (reallocation === null ||
93
+ typeof reallocation !== "object" ||
94
+ "withdrawals" in reallocation ||
95
+ "fee" in reallocation) {
96
+ return reallocation;
97
+ }
98
+ const { vault, from, to, assets, penalty } = reallocation;
99
+ return { vault, from, to, assets, penalty };
100
+ });
90
101
  // Reject malformed plans before constructing allocation calls.
91
- validateVaultV2BlueReallocations(reallocations, targetMarketParams.id);
102
+ validateVaultV2BlueReallocations(snapshots, {
103
+ targetMarketId: targetMarketParams.id,
104
+ maxPenalty,
105
+ });
92
106
  // Hoisted out of the map: idle sources all reference the same synthetic idle market, whose
93
107
  // construction eagerly hashes the market id — computing it once per call instead of per entry.
94
108
  const idleMarketParams = parseBlueMarket(MarketParams.idle(targetMarketParams.loanToken));
95
- const publicAllocations = reallocations.map((reallocation) => {
109
+ const publicAllocations = snapshots.map((reallocation) => {
96
110
  if (reallocation.from.type === "market" &&
97
111
  !isAddressEqual(reallocation.from.marketParams.loanToken, targetMarketParams.loanToken)) {
98
112
  throw new ReallocationLoanTokenMismatchError(targetMarketParams.loanToken, reallocation.from.marketParams.loanToken);
@@ -21,9 +21,11 @@ export interface BlueRefinanceParams {
21
21
  readonly maxLtv: bigint;
22
22
  /** Optional Vault V2 reallocations into the destination market. */
23
23
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
24
+ /** Maximum WAD-scaled penalty rate per reallocation, defaulting to zero; it does not bound the total penalty added to destination debt. */
25
+ readonly maxPenalty?: bigint;
24
26
  /** Final call deadline in Unix seconds. */
25
27
  readonly deadline: bigint;
26
- /** Optional WAD-scaled referral fee, strictly below 100%. */
28
+ /** Optional WAD-scaled referral fee, at most 10%. */
27
29
  readonly referralFeePct?: bigint;
28
30
  /** Recipient required when `referralFeePct` is positive. */
29
31
  readonly referralFeeRecipient?: Address;
@@ -49,8 +51,9 @@ export interface BlueRefinanceParams {
49
51
  * BlueBundlesV1 always migrates `msg.sender`.
50
52
  * @param params.args.maxLtv - Maximum destination LTV.
51
53
  * @param params.args.reallocations - Vault V2 reallocations into the destination.
54
+ * @param params.args.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.
52
55
  * @param params.args.deadline - Final call deadline in Unix seconds.
53
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
56
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
54
57
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
55
58
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
56
59
  * @param params.metadata - Optional transaction metadata.
@@ -59,11 +62,16 @@ export interface BlueRefinanceParams {
59
62
  * @throws {MarketIdMismatchError} when the migration source, destination, or a reallocation
60
63
  * source market has an `id` that does not hash from its tuple fields.
61
64
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
65
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
62
66
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
63
67
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
68
+ * Also thrown when maxPenalty is negative.
64
69
  * @throws {NonPositiveInputError} when the deadline or a reallocation amount is not positive.
65
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
70
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
71
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
66
72
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
73
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
74
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
67
75
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
68
76
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
69
77
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -29,7 +29,10 @@ export const parseBlueRefinance = (params) => {
29
29
  ...common,
30
30
  authorizationSignature: params.args.authorizationSignature,
31
31
  });
32
- const allocations = parseBlueAllocations([...(params.args.reallocations ?? [])], markets.destinationMarketParams);
32
+ const allocations = parseBlueAllocations([...(params.args.reallocations ?? [])], {
33
+ marketParams: markets.destinationMarketParams,
34
+ maxPenalty: params.args.maxPenalty,
35
+ });
33
36
  const fields = {
34
37
  ...parsedMarkets,
35
38
  ...normalized,
@@ -16,8 +16,9 @@ import { parseBlueRefinance } from "./refinance.internal.js";
16
16
  * BlueBundlesV1 always migrates `msg.sender`.
17
17
  * @param params.args.maxLtv - Maximum destination LTV.
18
18
  * @param params.args.reallocations - Vault V2 reallocations into the destination.
19
+ * @param params.args.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.
19
20
  * @param params.args.deadline - Final call deadline in Unix seconds.
20
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
21
22
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
22
23
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
23
24
  * @param params.metadata - Optional transaction metadata.
@@ -26,11 +27,16 @@ import { parseBlueRefinance } from "./refinance.internal.js";
26
27
  * @throws {MarketIdMismatchError} when the migration source, destination, or a reallocation
27
28
  * source market has an `id` that does not hash from its tuple fields.
28
29
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
30
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
29
31
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
30
32
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
33
+ * Also thrown when maxPenalty is negative.
31
34
  * @throws {NonPositiveInputError} when the deadline or a reallocation amount is not positive.
32
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
35
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
36
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
33
37
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
38
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
39
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
34
40
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
35
41
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
36
42
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -7,12 +7,13 @@ export declare function validateBlueRefinanceSource({ sourceMarketParams, destin
7
7
  }): void;
8
8
  /** @internal Requires distinct markets with identical loan and collateral tokens. */
9
9
  export declare function validateBlueRefinanceMarkets(sourceMarketParams: Pick<MarketParams, "id" | "loanToken" | "collateralToken">, destinationMarketParams: Pick<MarketParams, "id" | "loanToken" | "collateralToken">): void;
10
- /** @internal Checks the migration quote, including destination debt from allocator penalties and fees. */
11
- export declare function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, }: {
10
+ /** @internal Checks deadline-projected migration health, including destination debt from allocator penalties and fees. */
11
+ export declare function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, deadline, }: {
12
12
  readonly destinationMarketParams: Pick<MarketParams, "id" | "lltv">;
13
13
  readonly sourcePosition: Readonly<AccrualPosition>;
14
14
  readonly destinationPosition: Readonly<AccrualPosition>;
15
15
  readonly penaltyAssets: bigint;
16
16
  readonly referralFeePct: bigint;
17
17
  readonly now: bigint;
18
+ readonly deadline?: bigint;
18
19
  }): void;
@@ -1,6 +1,6 @@
1
1
  import { MathLib, } from "@morpho-org/blue-sdk";
2
- import { Time } from "@morpho-org/morpho-ts";
3
2
  import { isAddressEqual } from "viem";
3
+ import { getBlueBundlesV1QuoteTimestamp } from "../../helpers/getBlueBundlesV1QuoteTimestamp.js";
4
4
  import { validatePositionHealth } from "../../helpers/validate.js";
5
5
  import { NonPositiveInputError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
6
6
  import { getBlueBundlesV1ReferralFeeAssets } from "./common.js";
@@ -22,11 +22,15 @@ export function validateBlueRefinanceMarkets(sourceMarketParams, destinationMark
22
22
  throw new RefinanceTokenMismatchError(sourceMarketParams.id, destinationMarketParams.id);
23
23
  }
24
24
  }
25
- /** @internal Checks the migration quote, including destination debt from allocator penalties and fees. */
26
- export function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, }) {
27
- const accrualTimestamp = MathLib.max(now, sourcePosition.market.lastUpdate, destinationPosition.market.lastUpdate) + Time.s.from.h(2n);
28
- const source = sourcePosition.accrueInterest(accrualTimestamp);
29
- const destination = destinationPosition.accrueInterest(accrualTimestamp);
25
+ /** @internal Checks deadline-projected migration health, including destination debt from allocator penalties and fees. */
26
+ export function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, deadline, }) {
27
+ const quoteTimestamp = getBlueBundlesV1QuoteTimestamp({
28
+ lastUpdate: MathLib.max(sourcePosition.market.lastUpdate, destinationPosition.market.lastUpdate),
29
+ now,
30
+ deadline,
31
+ });
32
+ const source = sourcePosition.accrueInterest(quoteTimestamp);
33
+ const destination = destinationPosition.accrueInterest(quoteTimestamp);
30
34
  const feeAssets = getBlueBundlesV1ReferralFeeAssets(source.borrowAssets, referralFeePct);
31
35
  // Health is checked before authorizing or encoding the migration; the contract rechecks maxLtv.
32
36
  validatePositionHealth({
@@ -22,7 +22,7 @@ export interface BlueRepayParams {
22
22
  readonly nativeAmount?: bigint;
23
23
  /** Final call deadline in Unix seconds. */
24
24
  readonly deadline: bigint;
25
- /** Optional WAD-scaled referral fee, strictly below 100%. */
25
+ /** Optional WAD-scaled referral fee, at most 10%. */
26
26
  readonly referralFeePct?: bigint;
27
27
  /** Recipient required when `referralFeePct` is positive. */
28
28
  readonly referralFeeRecipient?: Address;
@@ -47,7 +47,7 @@ export interface BlueRepayParams {
47
47
  * @param params.args.maxRepayAssets - Gross repayment and fee funding cap.
48
48
  * @param params.args.nativeAmount - Exclusive native repay funding.
49
49
  * @param params.args.deadline - Final call deadline in Unix seconds.
50
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
50
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
51
51
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
52
52
  * @param params.args.requirementSignature - Optional loan-token signature.
53
53
  * @param params.metadata - Optional transaction metadata.
@@ -67,8 +67,9 @@ export interface BlueRepayParams {
67
67
  * @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
68
68
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
69
69
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
70
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
71
70
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
71
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
72
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
72
73
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
73
74
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
74
75
  * @example
@@ -14,7 +14,7 @@ import { buildBlueRepay, parseBlueRepay } from "./repay.internal.js";
14
14
  * @param params.args.maxRepayAssets - Gross repayment and fee funding cap.
15
15
  * @param params.args.nativeAmount - Exclusive native repay funding.
16
16
  * @param params.args.deadline - Final call deadline in Unix seconds.
17
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
17
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
18
18
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
19
19
  * @param params.args.requirementSignature - Optional loan-token signature.
20
20
  * @param params.metadata - Optional transaction metadata.
@@ -34,8 +34,9 @@ import { buildBlueRepay, parseBlueRepay } from "./repay.internal.js";
34
34
  * @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
35
35
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
36
36
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
37
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
38
37
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
38
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
39
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
39
40
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
40
41
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
41
42
  * @example
@@ -26,7 +26,7 @@ export interface BlueRepayWithdrawCollateralParams {
26
26
  readonly nativeAmount?: bigint;
27
27
  /** Final call deadline in Unix seconds. */
28
28
  readonly deadline: bigint;
29
- /** Optional WAD-scaled referral fee, strictly below 100%. */
29
+ /** Optional WAD-scaled referral fee, at most 10%. */
30
30
  readonly referralFeePct?: bigint;
31
31
  /** Recipient required when `referralFeePct` is positive. */
32
32
  readonly referralFeeRecipient?: Address;
@@ -56,7 +56,7 @@ export interface BlueRepayWithdrawCollateralParams {
56
56
  * @param params.args.maxLtv - Maximum post-operation LTV.
57
57
  * @param params.args.nativeAmount - Exclusive native repay funding.
58
58
  * @param params.args.deadline - Final call deadline in Unix seconds.
59
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
59
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
60
60
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
61
61
  * @param params.args.requirementSignature - Optional loan-token signature.
62
62
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -68,8 +68,9 @@ export interface BlueRepayWithdrawCollateralParams {
68
68
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
69
69
  * @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
70
70
  * @throws {MaxRepayAssetsBelowRepayAssetsError} when exact-asset funding cannot cover the repayment and referral fee.
71
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
72
71
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
72
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
73
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
73
74
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
74
75
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
75
76
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -18,7 +18,7 @@ import { parseBlueRepayWithdrawCollateral } from "./repayWithdrawCollateral.inte
18
18
  * @param params.args.maxLtv - Maximum post-operation LTV.
19
19
  * @param params.args.nativeAmount - Exclusive native repay funding.
20
20
  * @param params.args.deadline - Final call deadline in Unix seconds.
21
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
21
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
22
22
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
23
23
  * @param params.args.requirementSignature - Optional loan-token signature.
24
24
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -30,8 +30,9 @@ import { parseBlueRepayWithdrawCollateral } from "./repayWithdrawCollateral.inte
30
30
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
31
31
  * @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
32
32
  * @throws {MaxRepayAssetsBelowRepayAssetsError} when exact-asset funding cannot cover the repayment and referral fee.
33
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
34
33
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
34
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
35
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
35
36
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
36
37
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
37
38
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -18,7 +18,7 @@ export interface BlueSupplyParams {
18
18
  readonly nativeAmount?: bigint;
19
19
  /** Final call deadline in Unix seconds. */
20
20
  readonly deadline: bigint;
21
- /** Optional WAD-scaled referral fee, strictly below 100%. */
21
+ /** Optional WAD-scaled referral fee, at most 10%. */
22
22
  readonly referralFeePct?: bigint;
23
23
  /** Recipient required when `referralFeePct` is positive. */
24
24
  readonly referralFeeRecipient?: Address;
@@ -41,7 +41,7 @@ export interface BlueSupplyParams {
41
41
  * @param params.args.assets - Gross loan-token funding amount.
42
42
  * @param params.args.nativeAmount - Exclusive native funding; must equal `assets`.
43
43
  * @param params.args.deadline - Final call deadline in Unix seconds.
44
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
44
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
45
45
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
46
46
  * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer result.
47
47
  * @param params.metadata - Optional transaction metadata.
@@ -50,8 +50,10 @@ export interface BlueSupplyParams {
50
50
  * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
51
51
  * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
52
52
  * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
53
- * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
53
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint256`.
54
54
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
55
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
56
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
55
57
  * @throws {NativeFundingAmountMismatchError} when native funding does not equal `assets`.
56
58
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
57
59
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -12,7 +12,7 @@ import { encodeBlueSupply, parseBlueSupply } from "./supply.internal.js";
12
12
  * @param params.args.assets - Gross loan-token funding amount.
13
13
  * @param params.args.nativeAmount - Exclusive native funding; must equal `assets`.
14
14
  * @param params.args.deadline - Final call deadline in Unix seconds.
15
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
15
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
16
16
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
17
17
  * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer result.
18
18
  * @param params.metadata - Optional transaction metadata.
@@ -21,8 +21,10 @@ import { encodeBlueSupply, parseBlueSupply } from "./supply.internal.js";
21
21
  * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
22
22
  * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
23
23
  * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
24
- * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
24
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint256`.
25
25
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
26
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
27
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
26
28
  * @throws {NativeFundingAmountMismatchError} when native funding does not equal `assets`.
27
29
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
28
30
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
@@ -18,7 +18,7 @@ export interface BlueSupplyCollateralParams {
18
18
  readonly nativeAmount?: bigint;
19
19
  /** Final call deadline in Unix seconds. */
20
20
  readonly deadline: bigint;
21
- /** Optional WAD-scaled referral fee, strictly below 100%. */
21
+ /** Optional WAD-scaled referral fee, at most 10%. */
22
22
  readonly referralFeePct?: bigint;
23
23
  /** Recipient required when `referralFeePct` is positive. */
24
24
  readonly referralFeeRecipient?: Address;
@@ -41,7 +41,7 @@ export interface BlueSupplyCollateralParams {
41
41
  * @param params.args.collateralAssets - Gross collateral assets supplied.
42
42
  * @param params.args.nativeAmount - Exclusive native collateral funding.
43
43
  * @param params.args.deadline - Final call deadline in Unix seconds.
44
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
44
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
45
45
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
46
46
  * @param params.args.requirementSignature - Optional collateral-token signature.
47
47
  * @param params.metadata - Optional transaction metadata.
@@ -59,8 +59,9 @@ export interface BlueSupplyCollateralParams {
59
59
  * @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
60
60
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
61
61
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
62
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
63
62
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
63
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
64
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
64
65
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
65
66
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
66
67
  * @example
@@ -12,7 +12,7 @@ import { buildBlueSupplyCollateral, parseBlueSupplyCollateral, } from "./supplyC
12
12
  * @param params.args.collateralAssets - Gross collateral assets supplied.
13
13
  * @param params.args.nativeAmount - Exclusive native collateral funding.
14
14
  * @param params.args.deadline - Final call deadline in Unix seconds.
15
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
15
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
16
16
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
17
17
  * @param params.args.requirementSignature - Optional collateral-token signature.
18
18
  * @param params.metadata - Optional transaction metadata.
@@ -30,8 +30,9 @@ import { buildBlueSupplyCollateral, parseBlueSupplyCollateral, } from "./supplyC
30
30
  * @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
31
31
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
32
32
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
33
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
34
33
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
34
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
35
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
35
36
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
36
37
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
37
38
  * @example
@@ -22,9 +22,11 @@ export interface BlueSupplyCollateralBorrowParams {
22
22
  readonly nativeAmount?: bigint;
23
23
  /** Optional validated Vault V2 BluePublicAllocator reallocations. */
24
24
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
25
+ /** Maximum WAD-scaled penalty rate per reallocation, defaulting to zero; it does not bound total proceeds lost. */
26
+ readonly maxPenalty?: bigint;
25
27
  /** Final call deadline in Unix seconds. */
26
28
  readonly deadline: bigint;
27
- /** Optional WAD-scaled referral fee, strictly below 100%. */
29
+ /** Optional WAD-scaled referral fee, at most 10%. */
28
30
  readonly referralFeePct?: bigint;
29
31
  /** Recipient required when `referralFeePct` is positive. */
30
32
  readonly referralFeeRecipient?: Address;
@@ -51,8 +53,9 @@ export interface BlueSupplyCollateralBorrowParams {
51
53
  * @param params.args.maxLtv - Maximum post-operation LTV.
52
54
  * @param params.args.nativeAmount - Exclusive native collateral funding.
53
55
  * @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
56
+ * @param params.args.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.
54
57
  * @param params.args.deadline - Final call deadline in Unix seconds.
55
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
58
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
56
59
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
57
60
  * @param params.args.requirementSignature - Optional collateral token signature.
58
61
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -61,12 +64,17 @@ export interface BlueSupplyCollateralBorrowParams {
61
64
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
62
65
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
63
66
  * `id` that does not hash from its tuple fields.
67
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
64
68
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
69
+ * Also thrown when maxPenalty is negative.
65
70
  * @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
66
71
  * or a reallocation amount is not positive.
67
72
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
68
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
73
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
74
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
69
75
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
76
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
77
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
70
78
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
71
79
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
72
80
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -39,10 +39,12 @@ export declare const parseBlueSupplyCollateralBorrowMode: (params: {
39
39
  readonly collateralAssets: bigint;
40
40
  readonly borrowAssets: bigint;
41
41
  readonly reallocations: readonly VaultV2BlueReallocation[];
42
+ readonly maxPenalty?: bigint;
42
43
  }) => {
43
44
  readonly collateralAssets: bigint;
44
45
  readonly borrowAssets: bigint;
45
46
  readonly reallocations: readonly VaultV2BlueReallocation[];
47
+ readonly maxPenalty?: bigint;
46
48
  };
47
49
  /** Parses allocations and their input-only borrow penalty bound. @internal */
48
50
  export declare const parseBlueSupplyCollateralBorrowAllocations: (marketParams: ReturnType<typeof parseBlueMarket>, mode: ReturnType<typeof parseBlueSupplyCollateralBorrowMode>) => {
@@ -17,6 +17,7 @@ export const parseBlueSupplyCollateralBorrow = (params) => {
17
17
  const mode = parseBlueSupplyCollateralBorrowMode({
18
18
  ...amounts,
19
19
  reallocations: [...(params.args.reallocations ?? [])],
20
+ maxPenalty: params.args.maxPenalty,
20
21
  });
21
22
  // Reject signatures for inactive legs before continuing.
22
23
  validateBlueSupplyCollateralBorrowSignatureLegs(amounts, params.args);
@@ -66,7 +67,10 @@ export const parseBlueSupplyCollateralBorrowMode = (params) => {
66
67
  };
67
68
  /** Parses allocations and their input-only borrow penalty bound. @internal */
68
69
  export const parseBlueSupplyCollateralBorrowAllocations = (marketParams, mode) => {
69
- const allocations = parseBlueAllocations([...mode.reallocations], marketParams);
70
+ const allocations = parseBlueAllocations([...mode.reallocations], {
71
+ marketParams,
72
+ maxPenalty: mode.maxPenalty,
73
+ });
70
74
  if (allocations.penaltyAssets > mode.borrowAssets) {
71
75
  throw new InputExceedsMaxError({
72
76
  field: "reallocationPenaltyAssets",
@@ -15,8 +15,9 @@ import { parseBlueSupplyCollateralBorrow } from "./supplyCollateralBorrow.intern
15
15
  * @param params.args.maxLtv - Maximum post-operation LTV.
16
16
  * @param params.args.nativeAmount - Exclusive native collateral funding.
17
17
  * @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
18
+ * @param params.args.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.
18
19
  * @param params.args.deadline - Final call deadline in Unix seconds.
19
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
20
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
20
21
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
21
22
  * @param params.args.requirementSignature - Optional collateral token signature.
22
23
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -25,12 +26,17 @@ import { parseBlueSupplyCollateralBorrow } from "./supplyCollateralBorrow.intern
25
26
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
26
27
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
27
28
  * `id` that does not hash from its tuple fields.
29
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
28
30
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
31
+ * Also thrown when maxPenalty is negative.
29
32
  * @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
30
33
  * or a reallocation amount is not positive.
31
34
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
32
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
35
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
36
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
33
37
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
38
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
39
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
34
40
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
35
41
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
36
42
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -18,9 +18,11 @@ export interface BlueWithdrawParams {
18
18
  readonly withdrawShares: bigint;
19
19
  /** Optional validated Vault V2 BluePublicAllocator reallocations. */
20
20
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
21
+ /** Maximum WAD-scaled penalty rate per reallocation, defaulting to zero; it does not bound total proceeds lost. */
22
+ readonly maxPenalty?: bigint;
21
23
  /** Final call deadline in Unix seconds. */
22
24
  readonly deadline: bigint;
23
- /** Optional WAD-scaled referral fee, strictly below 100%. */
25
+ /** Optional WAD-scaled referral fee, at most 10%. */
24
26
  readonly referralFeePct?: bigint;
25
27
  /** Recipient required when `referralFeePct` is positive. */
26
28
  readonly referralFeeRecipient?: Address;
@@ -44,8 +46,9 @@ export interface BlueWithdrawParams {
44
46
  * @param params.args.withdrawAssets - Exact assets withdrawn, exclusive with shares.
45
47
  * @param params.args.withdrawShares - Exact shares burned, exclusive with assets.
46
48
  * @param params.args.reallocations - Vault V2 reallocations executed before withdrawal.
49
+ * @param params.args.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.
47
50
  * @param params.args.deadline - Final call deadline in Unix seconds.
48
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
51
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
49
52
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
50
53
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
51
54
  * @param params.metadata - Optional transaction metadata.
@@ -53,12 +56,17 @@ export interface BlueWithdrawParams {
53
56
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
54
57
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
55
58
  * `id` that does not hash from its tuple fields.
59
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
56
60
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
61
+ * Also thrown when maxPenalty is negative.
57
62
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
58
63
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
59
64
  * reallocation amount is provided.
60
- * @throws {InputExceedsMaxError} when a withdraw amount, fee, reallocation amount, or penalty exceeds its ABI bound.
65
+ * @throws {InputExceedsMaxError} when a withdraw amount, reallocation amount, or penalty exceeds its ABI bound.
66
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
61
67
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
68
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
69
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
62
70
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
63
71
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
64
72
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.