@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.
@@ -14,6 +14,7 @@ const parseBlueBorrow = (params) => ({
14
14
  borrowAssets: params.args.borrowAssets,
15
15
  maxLtv: params.args.maxLtv,
16
16
  reallocations: params.args.reallocations,
17
+ maxPenalty: params.args.maxPenalty,
17
18
  deadline: params.args.deadline,
18
19
  referralFeePct: params.args.referralFeePct,
19
20
  referralFeeRecipient: params.args.referralFeeRecipient,
@@ -15,8 +15,9 @@ const borrow_internal_js_1 = require("./borrow.internal.js");
15
15
  * @param params.args.borrowAssets - Gross loan assets borrowed.
16
16
  * @param params.args.maxLtv - Maximum post-operation LTV.
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 referral fee.
20
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
20
21
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
21
22
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
22
23
  * @param params.metadata - Optional transaction metadata.
@@ -24,10 +25,15 @@ const borrow_internal_js_1 = require("./borrow.internal.js");
24
25
  * combined BlueBundlesV1 entrypoint with a zero collateral leg.
25
26
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
26
27
  * `id` that does not hash from its tuple fields.
28
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
27
29
  * @throws {NegativeInputError} when an amount, LTV, fee, or reallocation penalty is negative.
30
+ * Also thrown when maxPenalty is negative.
28
31
  * @throws {NonPositiveInputError} when the borrow, deadline, or reallocation amount is not positive.
29
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its bound.
32
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its bound.
33
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
30
34
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
35
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
36
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
31
37
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
32
38
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
33
39
  * @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;
@@ -92,13 +92,27 @@ const getBlueBundlesV1SignedAuthorization = (params) => {
92
92
  };
93
93
  exports.getBlueBundlesV1SignedAuthorization = getBlueBundlesV1SignedAuthorization;
94
94
  /** Parses an ordered reallocation plan and its aggregate penalty once. @internal */
95
- const parseBlueAllocations = (reallocations, targetMarketParams) => {
95
+ const parseBlueAllocations = (reallocations, { marketParams: targetMarketParams, maxPenalty, }) => {
96
+ // Snapshot each Vault V2 entry so validation, accounting and encoding read the same values.
97
+ const snapshots = reallocations.map((reallocation) => {
98
+ if (reallocation === null ||
99
+ typeof reallocation !== "object" ||
100
+ "withdrawals" in reallocation ||
101
+ "fee" in reallocation) {
102
+ return reallocation;
103
+ }
104
+ const { vault, from, to, assets, penalty } = reallocation;
105
+ return { vault, from, to, assets, penalty };
106
+ });
96
107
  // Reject malformed plans before constructing allocation calls.
97
- (0, validate_js_1.validateVaultV2BlueReallocations)(reallocations, targetMarketParams.id);
108
+ (0, validate_js_1.validateVaultV2BlueReallocations)(snapshots, {
109
+ targetMarketId: targetMarketParams.id,
110
+ maxPenalty,
111
+ });
98
112
  // Hoisted out of the map: idle sources all reference the same synthetic idle market, whose
99
113
  // construction eagerly hashes the market id — computing it once per call instead of per entry.
100
114
  const idleMarketParams = (0, parse_js_1.parseBlueMarket)(blue_sdk_1.MarketParams.idle(targetMarketParams.loanToken));
101
- const publicAllocations = reallocations.map((reallocation) => {
115
+ const publicAllocations = snapshots.map((reallocation) => {
102
116
  if (reallocation.from.type === "market" &&
103
117
  !(0, viem_1.isAddressEqual)(reallocation.from.marketParams.loanToken, targetMarketParams.loanToken)) {
104
118
  throw new index_js_2.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.
@@ -33,7 +33,10 @@ const parseBlueRefinance = (params) => {
33
33
  ...common,
34
34
  authorizationSignature: params.args.authorizationSignature,
35
35
  });
36
- const allocations = (0, common_js_1.parseBlueAllocations)([...(params.args.reallocations ?? [])], markets.destinationMarketParams);
36
+ const allocations = (0, common_js_1.parseBlueAllocations)([...(params.args.reallocations ?? [])], {
37
+ marketParams: markets.destinationMarketParams,
38
+ maxPenalty: params.args.maxPenalty,
39
+ });
37
40
  const fields = {
38
41
  ...parsedMarkets,
39
42
  ...normalized,
@@ -19,8 +19,9 @@ const refinance_internal_js_1 = require("./refinance.internal.js");
19
19
  * BlueBundlesV1 always migrates `msg.sender`.
20
20
  * @param params.args.maxLtv - Maximum destination LTV.
21
21
  * @param params.args.reallocations - Vault V2 reallocations into the destination.
22
+ * @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.
22
23
  * @param params.args.deadline - Final call deadline in Unix seconds.
23
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
24
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
24
25
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
25
26
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
26
27
  * @param params.metadata - Optional transaction metadata.
@@ -29,11 +30,16 @@ const refinance_internal_js_1 = require("./refinance.internal.js");
29
30
  * @throws {MarketIdMismatchError} when the migration source, destination, or a reallocation
30
31
  * source market has an `id` that does not hash from its tuple fields.
31
32
  * @throws {RefinanceSameMarketError} when source and destination IDs match.
33
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
32
34
  * @throws {RefinanceTokenMismatchError} when their loan or collateral tokens differ.
33
35
  * @throws {NegativeInputError} when `maxLtv`, a referral fee, or a reallocation penalty is negative.
36
+ * Also thrown when maxPenalty is negative.
34
37
  * @throws {NonPositiveInputError} when the deadline or a reallocation amount is not positive.
35
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
38
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
39
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
36
40
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
41
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
42
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
37
43
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
38
44
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
39
45
  * @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;
@@ -4,8 +4,8 @@ exports.validateBlueRefinanceSource = validateBlueRefinanceSource;
4
4
  exports.validateBlueRefinanceMarkets = validateBlueRefinanceMarkets;
5
5
  exports.validateBlueRefinanceQuote = validateBlueRefinanceQuote;
6
6
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
7
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
8
7
  const viem_1 = require("viem");
8
+ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundlesV1QuoteTimestamp.js");
9
9
  const validate_js_1 = require("../../helpers/validate.js");
10
10
  const index_js_1 = require("../../types/index.js");
11
11
  const common_js_1 = require("./common.js");
@@ -27,11 +27,15 @@ function validateBlueRefinanceMarkets(sourceMarketParams, destinationMarketParam
27
27
  throw new index_js_1.RefinanceTokenMismatchError(sourceMarketParams.id, destinationMarketParams.id);
28
28
  }
29
29
  }
30
- /** @internal Checks the migration quote, including destination debt from allocator penalties and fees. */
31
- function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, }) {
32
- const accrualTimestamp = blue_sdk_1.MathLib.max(now, sourcePosition.market.lastUpdate, destinationPosition.market.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
33
- const source = sourcePosition.accrueInterest(accrualTimestamp);
34
- const destination = destinationPosition.accrueInterest(accrualTimestamp);
30
+ /** @internal Checks deadline-projected migration health, including destination debt from allocator penalties and fees. */
31
+ function validateBlueRefinanceQuote({ destinationMarketParams, sourcePosition, destinationPosition, penaltyAssets, referralFeePct, now, deadline, }) {
32
+ const quoteTimestamp = (0, getBlueBundlesV1QuoteTimestamp_js_1.getBlueBundlesV1QuoteTimestamp)({
33
+ lastUpdate: blue_sdk_1.MathLib.max(sourcePosition.market.lastUpdate, destinationPosition.market.lastUpdate),
34
+ now,
35
+ deadline,
36
+ });
37
+ const source = sourcePosition.accrueInterest(quoteTimestamp);
38
+ const destination = destinationPosition.accrueInterest(quoteTimestamp);
35
39
  const feeAssets = (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(source.borrowAssets, referralFeePct);
36
40
  // Health is checked before authorizing or encoding the migration; the contract rechecks maxLtv.
37
41
  (0, validate_js_1.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
@@ -17,7 +17,7 @@ const repay_internal_js_1 = require("./repay.internal.js");
17
17
  * @param params.args.maxRepayAssets - Gross repayment and fee funding cap.
18
18
  * @param params.args.nativeAmount - Exclusive native repay funding.
19
19
  * @param params.args.deadline - Final call deadline in Unix seconds.
20
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
20
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
21
21
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
22
22
  * @param params.args.requirementSignature - Optional loan-token signature.
23
23
  * @param params.metadata - Optional transaction metadata.
@@ -37,8 +37,9 @@ const repay_internal_js_1 = require("./repay.internal.js");
37
37
  * @throws {DepositAmountMismatchError} when the signed amount differs from `maxRepayAssets`.
38
38
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
39
39
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
40
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
41
40
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
41
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
42
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
42
43
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
43
44
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
44
45
  * @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.
@@ -21,7 +21,7 @@ const repayWithdrawCollateral_internal_js_1 = require("./repayWithdrawCollateral
21
21
  * @param params.args.maxLtv - Maximum post-operation LTV.
22
22
  * @param params.args.nativeAmount - Exclusive native repay funding.
23
23
  * @param params.args.deadline - Final call deadline in Unix seconds.
24
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
24
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
25
25
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
26
26
  * @param params.args.requirementSignature - Optional loan-token signature.
27
27
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -33,8 +33,9 @@ const repayWithdrawCollateral_internal_js_1 = require("./repayWithdrawCollateral
33
33
  * @throws {MutuallyExclusiveRepayAmountsError} when assets and shares are both nonzero.
34
34
  * @throws {NonPositiveInputError} when both operation legs are zero, repay funding is absent, or the deadline is invalid.
35
35
  * @throws {MaxRepayAssetsBelowRepayAssetsError} when exact-asset funding cannot cover the repayment and referral fee.
36
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
37
36
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
37
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
38
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
38
39
  * @throws {NativeFundingAmountMismatchError} when native funding is partial or mixed.
39
40
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
40
41
  * @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.
@@ -15,7 +15,7 @@ const supply_internal_js_1 = require("./supply.internal.js");
15
15
  * @param params.args.assets - Gross loan-token funding amount.
16
16
  * @param params.args.nativeAmount - Exclusive native funding; must equal `assets`.
17
17
  * @param params.args.deadline - Final call deadline in Unix seconds.
18
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
18
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
19
19
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
20
20
  * @param params.args.requirementSignature - Optional ERC-2612 or Permit2 SignatureTransfer result.
21
21
  * @param params.metadata - Optional transaction metadata.
@@ -24,8 +24,10 @@ const supply_internal_js_1 = require("./supply.internal.js");
24
24
  * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
25
25
  * @throws {NonPositiveInputError} when `assets` or `deadline` is not positive.
26
26
  * @throws {NegativeInputError} when `nativeAmount` or `referralFeePct` is negative.
27
- * @throws {InputExceedsMaxError} when `assets` exceeds `uint256` or `referralFeePct` is at least WAD.
27
+ * @throws {InputExceedsMaxError} when `assets` exceeds `uint256`.
28
28
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
29
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
30
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
29
31
  * @throws {NativeFundingAmountMismatchError} when native funding does not equal `assets`.
30
32
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
31
33
  * @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
@@ -15,7 +15,7 @@ const supplyCollateral_internal_js_1 = require("./supplyCollateral.internal.js")
15
15
  * @param params.args.collateralAssets - Gross collateral assets supplied.
16
16
  * @param params.args.nativeAmount - Exclusive native collateral funding.
17
17
  * @param params.args.deadline - Final call deadline in Unix seconds.
18
- * @param params.args.referralFeePct - Optional WAD-scaled referral fee.
18
+ * @param params.args.referralFeePct - Optional WAD-scaled referral fee, at most 10%.
19
19
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
20
20
  * @param params.args.requirementSignature - Optional collateral-token signature.
21
21
  * @param params.metadata - Optional transaction metadata.
@@ -33,8 +33,9 @@ const supplyCollateral_internal_js_1 = require("./supplyCollateral.internal.js")
33
33
  * @throws {DepositAmountMismatchError} when the signed amount differs from `collateralAssets`.
34
34
  * @throws {DepositSpenderMismatchError} when the signed spender is not BlueBundlesV1.
35
35
  * @throws {BundlesRequirementSignatureMismatchError} when a signature cannot be encoded safely.
36
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
37
36
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
37
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
38
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
38
39
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
39
40
  * @throws {UnknownAddressError} when BlueBundlesV1 is not registered.
40
41
  * @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>) => {
@@ -20,6 +20,7 @@ const parseBlueSupplyCollateralBorrow = (params) => {
20
20
  const mode = (0, exports.parseBlueSupplyCollateralBorrowMode)({
21
21
  ...amounts,
22
22
  reallocations: [...(params.args.reallocations ?? [])],
23
+ maxPenalty: params.args.maxPenalty,
23
24
  });
24
25
  // Reject signatures for inactive legs before continuing.
25
26
  (0, signatures_js_1.validateBlueSupplyCollateralBorrowSignatureLegs)(amounts, params.args);
@@ -71,7 +72,10 @@ const parseBlueSupplyCollateralBorrowMode = (params) => {
71
72
  exports.parseBlueSupplyCollateralBorrowMode = parseBlueSupplyCollateralBorrowMode;
72
73
  /** Parses allocations and their input-only borrow penalty bound. @internal */
73
74
  const parseBlueSupplyCollateralBorrowAllocations = (marketParams, mode) => {
74
- const allocations = (0, common_js_1.parseBlueAllocations)([...mode.reallocations], marketParams);
75
+ const allocations = (0, common_js_1.parseBlueAllocations)([...mode.reallocations], {
76
+ marketParams,
77
+ maxPenalty: mode.maxPenalty,
78
+ });
75
79
  if (allocations.penaltyAssets > mode.borrowAssets) {
76
80
  throw new index_js_1.InputExceedsMaxError({
77
81
  field: "reallocationPenaltyAssets",
@@ -18,8 +18,9 @@ const supplyCollateralBorrow_internal_js_1 = require("./supplyCollateralBorrow.i
18
18
  * @param params.args.maxLtv - Maximum post-operation LTV.
19
19
  * @param params.args.nativeAmount - Exclusive native collateral funding.
20
20
  * @param params.args.reallocations - Vault V2 reallocations executed before borrowing.
21
+ * @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.
21
22
  * @param params.args.deadline - Final call deadline in Unix seconds.
22
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
23
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
23
24
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
24
25
  * @param params.args.requirementSignature - Optional collateral token signature.
25
26
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
@@ -28,12 +29,17 @@ const supplyCollateralBorrow_internal_js_1 = require("./supplyCollateralBorrow.i
28
29
  * whose `to` address is BlueBundlesV1 and whose `action` records the normalized inputs.
29
30
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
30
31
  * `id` that does not hash from its tuple fields.
32
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
31
33
  * @throws {NegativeInputError} when an amount, `maxLtv`, native value, or fee is negative.
34
+ * Also thrown when maxPenalty is negative.
32
35
  * @throws {NonPositiveInputError} when both operation legs are zero, the deadline is not positive,
33
36
  * or a reallocation amount is not positive.
34
37
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
35
- * @throws {InputExceedsMaxError} when a fee, reallocation amount, or penalty exceeds its ABI bound.
38
+ * @throws {InputExceedsMaxError} when a reallocation amount or penalty exceeds its ABI bound.
39
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
36
40
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
41
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
42
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
37
43
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
38
44
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
39
45
  * @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.