@morpho-org/morpho-sdk 10.1.0 → 10.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/README.md +126 -140
  2. package/lib/cjs/abis.d.ts +34 -0
  3. package/lib/cjs/abis.js +21 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +11 -3
  5. package/lib/cjs/actions/blue/borrow.internal.js +1 -0
  6. package/lib/cjs/actions/blue/borrow.js +8 -2
  7. package/lib/cjs/actions/blue/common.d.ts +4 -1
  8. package/lib/cjs/actions/blue/common.js +17 -3
  9. package/lib/cjs/actions/blue/refinance.d.ts +11 -3
  10. package/lib/cjs/actions/blue/refinance.internal.js +4 -1
  11. package/lib/cjs/actions/blue/refinance.js +8 -2
  12. package/lib/cjs/actions/blue/refinanceValidation.d.ts +3 -2
  13. package/lib/cjs/actions/blue/refinanceValidation.js +10 -6
  14. package/lib/cjs/actions/blue/repay.d.ts +4 -3
  15. package/lib/cjs/actions/blue/repay.js +3 -2
  16. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  17. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -2
  18. package/lib/cjs/actions/blue/supply.d.ts +5 -3
  19. package/lib/cjs/actions/blue/supply.js +4 -2
  20. package/lib/cjs/actions/blue/supplyCollateral.d.ts +4 -3
  21. package/lib/cjs/actions/blue/supplyCollateral.js +3 -2
  22. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  23. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  24. package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  25. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +8 -2
  26. package/lib/cjs/actions/blue/withdraw.d.ts +11 -3
  27. package/lib/cjs/actions/blue/withdraw.internal.js +4 -1
  28. package/lib/cjs/actions/blue/withdraw.js +8 -2
  29. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
  30. package/lib/cjs/actions/blue/withdrawCollateral.js +3 -2
  31. package/lib/cjs/actions/bundles/common.d.ts +2 -8
  32. package/lib/cjs/actions/bundles/common.js +8 -20
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +0 -1
  34. package/lib/cjs/actions/midnight/takeBorrow.js +0 -1
  35. package/lib/cjs/actions/midnight/takeLend.js +0 -1
  36. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +0 -1
  37. package/lib/cjs/actions/midnight/takeWithdraw.js +0 -1
  38. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -1
  39. package/lib/cjs/actions/vaultV1/deposit.js +2 -1
  40. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +3 -2
  41. package/lib/cjs/actions/vaultV1/migrateToV2.js +2 -1
  42. package/lib/cjs/actions/vaultV1/redeem.d.ts +3 -2
  43. package/lib/cjs/actions/vaultV1/redeem.js +2 -1
  44. package/lib/cjs/actions/vaultV1/withdraw.d.ts +2 -1
  45. package/lib/cjs/actions/vaultV1/withdraw.js +2 -1
  46. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -1
  47. package/lib/cjs/actions/vaultV2/deposit.js +2 -1
  48. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +2 -1
  49. package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -1
  50. package/lib/cjs/actions/vaultV2/redeem.d.ts +3 -2
  51. package/lib/cjs/actions/vaultV2/redeem.js +2 -1
  52. package/lib/cjs/actions/vaultV2/withdraw.d.ts +2 -1
  53. package/lib/cjs/actions/vaultV2/withdraw.js +2 -1
  54. package/lib/cjs/constants.d.ts +1 -1
  55. package/lib/cjs/constants.js +2 -0
  56. package/lib/cjs/entities/blue/blue.d.ts +83 -20
  57. package/lib/cjs/entities/blue/blue.js +38 -12
  58. package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  59. package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
  60. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -6
  61. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -0
  62. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -7
  63. package/lib/cjs/entities/vaultV2/vaultV2.js +4 -0
  64. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -2
  65. package/lib/cjs/entities/vaultV2BlueReallocationData.js +19 -21
  66. package/lib/cjs/helpers/constant.d.ts +2 -0
  67. package/lib/cjs/helpers/constant.js +3 -1
  68. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  69. package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
  70. package/lib/cjs/helpers/index.d.ts +1 -1
  71. package/lib/cjs/helpers/index.js +2 -1
  72. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  73. package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
  74. package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
  75. package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
  76. package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
  77. package/lib/cjs/helpers/reallocationPenalty.js +32 -0
  78. package/lib/cjs/helpers/referralFee.d.ts +2 -1
  79. package/lib/cjs/helpers/referralFee.js +5 -1
  80. package/lib/cjs/helpers/validate.d.ts +31 -4
  81. package/lib/cjs/helpers/validate.js +48 -9
  82. package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
  83. package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
  84. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  85. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
  86. package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
  87. package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
  88. package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
  89. package/lib/cjs/transactionPlan/blue/refinance.js +20 -3
  90. package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
  91. package/lib/cjs/transactionPlan/blue/repay.js +1 -2
  92. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  93. package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  94. package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
  95. package/lib/cjs/transactionPlan/blue/supply.js +1 -2
  96. package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  97. package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
  98. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  99. package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  100. package/lib/cjs/transactionPlan/blue/withdraw.d.ts +15 -5
  101. package/lib/cjs/transactionPlan/blue/withdraw.js +25 -6
  102. package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  103. package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +11 -7
  104. package/lib/cjs/transactionPlan/deposit.js +4 -0
  105. package/lib/cjs/transactionPlan/intent.d.ts +1 -1
  106. package/lib/cjs/transactionPlan/intent.js +4 -2
  107. package/lib/cjs/transactionPlan/plan.d.ts +8 -4
  108. package/lib/cjs/transactionPlan/plan.js +8 -4
  109. package/lib/cjs/transactionPlan/types.d.ts +6 -0
  110. package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +3 -3
  111. package/lib/cjs/transactionPlan/vaultv1/deposit.js +3 -3
  112. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  113. package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
  114. package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
  115. package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
  116. package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  117. package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
  118. package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
  119. package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
  120. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  121. package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  122. package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
  123. package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
  124. package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  125. package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
  126. package/lib/cjs/types/error.d.ts +7 -6
  127. package/lib/cjs/types/error.js +10 -9
  128. package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
  129. package/lib/cjs/version.d.ts +1 -1
  130. package/lib/cjs/version.js +1 -1
  131. package/lib/esm/abis.d.ts +34 -0
  132. package/lib/esm/abis.js +20 -0
  133. package/lib/esm/actions/blue/borrow.d.ts +11 -3
  134. package/lib/esm/actions/blue/borrow.internal.js +1 -0
  135. package/lib/esm/actions/blue/borrow.js +8 -2
  136. package/lib/esm/actions/blue/common.d.ts +4 -1
  137. package/lib/esm/actions/blue/common.js +17 -3
  138. package/lib/esm/actions/blue/refinance.d.ts +11 -3
  139. package/lib/esm/actions/blue/refinance.internal.js +4 -1
  140. package/lib/esm/actions/blue/refinance.js +8 -2
  141. package/lib/esm/actions/blue/refinanceValidation.d.ts +3 -2
  142. package/lib/esm/actions/blue/refinanceValidation.js +10 -6
  143. package/lib/esm/actions/blue/repay.d.ts +4 -3
  144. package/lib/esm/actions/blue/repay.js +3 -2
  145. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +4 -3
  146. package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -2
  147. package/lib/esm/actions/blue/supply.d.ts +5 -3
  148. package/lib/esm/actions/blue/supply.js +4 -2
  149. package/lib/esm/actions/blue/supplyCollateral.d.ts +4 -3
  150. package/lib/esm/actions/blue/supplyCollateral.js +3 -2
  151. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +11 -3
  152. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
  153. package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +5 -1
  154. package/lib/esm/actions/blue/supplyCollateralBorrow.js +8 -2
  155. package/lib/esm/actions/blue/withdraw.d.ts +11 -3
  156. package/lib/esm/actions/blue/withdraw.internal.js +4 -1
  157. package/lib/esm/actions/blue/withdraw.js +8 -2
  158. package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
  159. package/lib/esm/actions/blue/withdrawCollateral.js +3 -2
  160. package/lib/esm/actions/bundles/common.d.ts +2 -8
  161. package/lib/esm/actions/bundles/common.js +4 -17
  162. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -2
  163. package/lib/esm/actions/midnight/takeBorrow.js +1 -2
  164. package/lib/esm/actions/midnight/takeLend.js +1 -2
  165. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -2
  166. package/lib/esm/actions/midnight/takeWithdraw.js +1 -2
  167. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -1
  168. package/lib/esm/actions/vaultV1/deposit.js +2 -1
  169. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +3 -2
  170. package/lib/esm/actions/vaultV1/migrateToV2.js +2 -1
  171. package/lib/esm/actions/vaultV1/redeem.d.ts +3 -2
  172. package/lib/esm/actions/vaultV1/redeem.js +2 -1
  173. package/lib/esm/actions/vaultV1/withdraw.d.ts +2 -1
  174. package/lib/esm/actions/vaultV1/withdraw.js +2 -1
  175. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -1
  176. package/lib/esm/actions/vaultV2/deposit.js +2 -1
  177. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +2 -1
  178. package/lib/esm/actions/vaultV2/forceWithdraw.js +2 -1
  179. package/lib/esm/actions/vaultV2/redeem.d.ts +3 -2
  180. package/lib/esm/actions/vaultV2/redeem.js +2 -1
  181. package/lib/esm/actions/vaultV2/withdraw.d.ts +2 -1
  182. package/lib/esm/actions/vaultV2/withdraw.js +2 -1
  183. package/lib/esm/constants.d.ts +1 -1
  184. package/lib/esm/constants.js +1 -1
  185. package/lib/esm/entities/blue/blue.d.ts +83 -20
  186. package/lib/esm/entities/blue/blue.js +38 -12
  187. package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
  188. package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
  189. package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -6
  190. package/lib/esm/entities/vaultV1/vaultV1.js +7 -1
  191. package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -7
  192. package/lib/esm/entities/vaultV2/vaultV2.js +5 -1
  193. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -2
  194. package/lib/esm/entities/vaultV2BlueReallocationData.js +17 -19
  195. package/lib/esm/helpers/constant.d.ts +2 -0
  196. package/lib/esm/helpers/constant.js +2 -0
  197. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
  198. package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
  199. package/lib/esm/helpers/index.d.ts +1 -1
  200. package/lib/esm/helpers/index.js +1 -1
  201. package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
  202. package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
  203. package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
  204. package/lib/esm/helpers/quoteBlueRepay.js +21 -8
  205. package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
  206. package/lib/esm/helpers/reallocationPenalty.js +28 -0
  207. package/lib/esm/helpers/referralFee.d.ts +2 -1
  208. package/lib/esm/helpers/referralFee.js +5 -1
  209. package/lib/esm/helpers/validate.d.ts +31 -4
  210. package/lib/esm/helpers/validate.js +48 -11
  211. package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
  212. package/lib/esm/helpers/validateMidnightBounds.js +1 -2
  213. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
  214. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
  215. package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
  216. package/lib/esm/transactionPlan/blue/borrow.js +27 -9
  217. package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
  218. package/lib/esm/transactionPlan/blue/refinance.js +20 -3
  219. package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
  220. package/lib/esm/transactionPlan/blue/repay.js +1 -2
  221. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
  222. package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
  223. package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
  224. package/lib/esm/transactionPlan/blue/supply.js +1 -2
  225. package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
  226. package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
  227. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
  228. package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
  229. package/lib/esm/transactionPlan/blue/withdraw.d.ts +15 -5
  230. package/lib/esm/transactionPlan/blue/withdraw.js +25 -6
  231. package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
  232. package/lib/esm/transactionPlan/blue/withdrawCollateral.js +11 -7
  233. package/lib/esm/transactionPlan/deposit.js +5 -1
  234. package/lib/esm/transactionPlan/intent.d.ts +1 -1
  235. package/lib/esm/transactionPlan/intent.js +4 -2
  236. package/lib/esm/transactionPlan/plan.d.ts +8 -4
  237. package/lib/esm/transactionPlan/plan.js +8 -4
  238. package/lib/esm/transactionPlan/types.d.ts +6 -0
  239. package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +3 -3
  240. package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -3
  241. package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
  242. package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
  243. package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
  244. package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
  245. package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
  246. package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
  247. package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
  248. package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
  249. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
  250. package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
  251. package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
  252. package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
  253. package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
  254. package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
  255. package/lib/esm/types/error.d.ts +7 -6
  256. package/lib/esm/types/error.js +11 -10
  257. package/lib/esm/types/sharedLiquidity.d.ts +7 -2
  258. package/lib/esm/version.d.ts +1 -1
  259. package/lib/esm/version.js +1 -1
  260. package/package.json +3 -3
@@ -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.
@@ -55,7 +55,10 @@ const parseBlueWithdraw = (params) => {
55
55
  ...common,
56
56
  authorizationSignature: params.args.authorizationSignature,
57
57
  });
58
- const allocations = (0, exports.parseBlueWithdrawPenalty)((0, common_js_1.parseBlueAllocations)([...(params.args.reallocations ?? [])], marketParams), mode);
58
+ const allocations = (0, exports.parseBlueWithdrawPenalty)((0, common_js_1.parseBlueAllocations)([...(params.args.reallocations ?? [])], {
59
+ marketParams,
60
+ maxPenalty: params.args.maxPenalty,
61
+ }), mode);
59
62
  const fields = {
60
63
  ...normalized,
61
64
  chainId: common.chainId,
@@ -17,8 +17,9 @@ const withdraw_internal_js_1 = require("./withdraw.internal.js");
17
17
  * @param params.args.withdrawAssets - Exact assets withdrawn, exclusive with shares.
18
18
  * @param params.args.withdrawShares - Exact shares burned, exclusive with assets.
19
19
  * @param params.args.reallocations - Vault V2 reallocations executed before withdrawal.
20
+ * @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.
20
21
  * @param params.args.deadline - Final call deadline in Unix seconds.
21
- * @param params.args.referralFeePct - Optional WAD-scaled fee below 100%.
22
+ * @param params.args.referralFeePct - Optional WAD-scaled fee at most 10%.
22
23
  * @param params.args.referralFeeRecipient - Recipient required for a positive fee.
23
24
  * @param params.args.authorizationSignature - Optional Blue authorization signature.
24
25
  * @param params.metadata - Optional transaction metadata.
@@ -26,12 +27,17 @@ const withdraw_internal_js_1 = require("./withdraw.internal.js");
26
27
  * BlueBundlesV1 and whose `action` records the normalized withdrawal inputs.
27
28
  * @throws {MarketIdMismatchError} when the target market or a reallocation source market has an
28
29
  * `id` that does not hash from its tuple fields.
30
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
29
31
  * @throws {NegativeInputError} when an amount, fee, or reallocation penalty is negative.
32
+ * Also thrown when maxPenalty is negative.
30
33
  * @throws {MutuallyExclusiveWithdrawAmountsError} when assets and shares are both nonzero.
31
34
  * @throws {NonPositiveInputError} when neither mode, no valid deadline, or a non-positive
32
35
  * reallocation amount is provided.
33
- * @throws {InputExceedsMaxError} when a withdraw amount, fee, reallocation amount, or penalty exceeds its ABI bound.
36
+ * @throws {InputExceedsMaxError} when a withdraw amount, reallocation amount, or penalty exceeds its ABI bound.
37
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
34
38
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
39
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
40
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
35
41
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
36
42
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not a valid Vault V2 reallocation.
37
43
  * @throws {InvalidReallocationSourceTypeError} when a reallocation source is malformed.
@@ -18,7 +18,7 @@ export interface BlueWithdrawCollateralParams {
18
18
  readonly maxLtv: 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 BlueWithdrawCollateralParams {
41
41
  * @param params.args.collateralAssets - Collateral assets withdrawn.
42
42
  * @param params.args.maxLtv - Maximum post-operation LTV.
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.authorizationSignature - Optional Blue authorization signature.
47
47
  * @param params.metadata - Optional transaction metadata.
@@ -50,8 +50,9 @@ export interface BlueWithdrawCollateralParams {
50
50
  * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
51
51
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
52
52
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
53
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
54
53
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
54
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
55
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
55
56
  * @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
56
57
  * @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
57
58
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
@@ -15,7 +15,7 @@ const withdrawCollateral_internal_js_1 = require("./withdrawCollateral.internal.
15
15
  * @param params.args.collateralAssets - Collateral assets withdrawn.
16
16
  * @param params.args.maxLtv - Maximum post-operation LTV.
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.authorizationSignature - Optional Blue authorization signature.
21
21
  * @param params.metadata - Optional transaction metadata.
@@ -24,8 +24,9 @@ const withdrawCollateral_internal_js_1 = require("./withdrawCollateral.internal.
24
24
  * @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
25
25
  * @throws {NegativeInputError} when collateral, LTV, or fee is negative.
26
26
  * @throws {NonPositiveInputError} when collateral or deadline is not positive.
27
- * @throws {InputExceedsMaxError} when the referral fee is at least WAD.
28
27
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no recipient.
28
+ * @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
29
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
29
30
  * @throws {DepositOwnerMismatchError} when the signed authorization owner differs from `userAddress`.
30
31
  * @throws {BundlesRequirementSignatureMismatchError} when authorization cannot be bound safely.
31
32
  * @throws {UnsupportedChainIdError} when the chain is absent from the registry.
@@ -1,13 +1,7 @@
1
1
  import { type Address, type Hex } from "viem";
2
+ import { BundlesPermitKind } from "../../abis.js";
2
3
  import { type BaseAction, type BundlesFundingArgs, type BundlesTokenRequirementSignature, type Erc2612RequirementSignature, type Metadata, type PermitRequirementSignature, type RequirementSignature, type TokenRequirementSignature, type Transaction } from "../../types/index.js";
3
- /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
4
- export declare const BundlesPermitKind: {
5
- readonly None: 0;
6
- readonly ERC2612: 1;
7
- readonly Permit2: 2;
8
- };
9
- /** A numeric permit kind consumed by `TokenLib.pullToken`. */
10
- export type BundlesPermitKind = (typeof BundlesPermitKind)[keyof typeof BundlesPermitKind];
4
+ export { BundlesPermitKind } from "../../abis.js";
11
5
  /** ABI-ready token permit consumed by fixed bundles deposit and funding entrypoints. */
12
6
  export interface BundlesTokenPermit {
13
7
  /** TokenLib permit dispatch kind. */
@@ -4,18 +4,15 @@ exports.finalizeVaultBundlesV1Transaction = exports.getBundlesReferralFeeAssets
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
6
  const viem_1 = require("viem");
7
+ const abis_js_1 = require("../../abis.js");
7
8
  const index_js_1 = require("../../helpers/index.js");
8
9
  const parse_js_1 = require("../../helpers/parse.js");
9
10
  const validate_js_1 = require("../../helpers/validate.js");
10
11
  const index_js_2 = require("../../types/index.js");
11
- /** Numeric permit kinds consumed by `TokenLib.pullToken`. */
12
- exports.BundlesPermitKind = {
13
- None: 0,
14
- ERC2612: 1,
15
- Permit2: 2,
16
- };
12
+ var abis_js_2 = require("../../abis.js");
13
+ Object.defineProperty(exports, "BundlesPermitKind", { enumerable: true, get: function () { return abis_js_2.BundlesPermitKind; } });
17
14
  const EMPTY_TOKEN_PERMIT = {
18
- kind: exports.BundlesPermitKind.None,
15
+ kind: abis_js_1.BundlesPermitKind.None,
19
16
  data: "0x",
20
17
  };
21
18
  /**
@@ -147,12 +144,8 @@ const getBundlesTokenPermit = (params) => {
147
144
  }
148
145
  if (requirementSignature.action.type === "permit2SignatureTransfer") {
149
146
  return {
150
- kind: exports.BundlesPermitKind.Permit2,
151
- data: (0, viem_1.encodeAbiParameters)([
152
- { type: "uint256", name: "nonce" },
153
- { type: "uint256", name: "deadline" },
154
- { type: "bytes", name: "signature" },
155
- ], [
147
+ kind: abis_js_1.BundlesPermitKind.Permit2,
148
+ data: (0, viem_1.encodeAbiParameters)(abis_js_1.bundlesPermitParameters[abis_js_1.BundlesPermitKind.Permit2], [
156
149
  requirementSignature.args.nonce,
157
150
  requirementSignature.args.deadline,
158
151
  requirementSignature.args.signature,
@@ -175,13 +168,8 @@ const getBundlesTokenPermit = (params) => {
175
168
  throw cause;
176
169
  }
177
170
  return {
178
- kind: exports.BundlesPermitKind.ERC2612,
179
- data: (0, viem_1.encodeAbiParameters)([
180
- { type: "uint256", name: "deadline" },
181
- { type: "uint8", name: "v" },
182
- { type: "bytes32", name: "r" },
183
- { type: "bytes32", name: "s" },
184
- ], [
171
+ kind: abis_js_1.BundlesPermitKind.ERC2612,
172
+ data: (0, viem_1.encodeAbiParameters)(abis_js_1.bundlesPermitParameters[abis_js_1.BundlesPermitKind.ERC2612], [
185
173
  requirementSignature.args.deadline,
186
174
  signature.v,
187
175
  signature.r,
@@ -160,7 +160,6 @@ const parseMidnightSupplyCollateralTakeBorrow = (params) => {
160
160
  (0, validateMidnightAccount_js_1.validateMidnightAddress)("referralFeeRecipient", params.referralFeeRecipient);
161
161
  }
162
162
  const { referralFeePct, referralFeeRecipient } = (0, parse_js_1.parseReferralFee)(params);
163
- (0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(referralFeePct);
164
163
  (0, validateMidnightTakeFeasibility_js_1.validateMidnightSellTargetBounds)({ target, referralFeePct });
165
164
  if (referralFeePct > 0n) {
166
165
  // Rejects fee recipients that would strand the fee in a contract.