@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
@@ -58,9 +58,8 @@ function validateBlueSupplyPlanAction(action, path) {
58
58
  * @throws {NonPositiveInputError} when `expiresAt`, `assets` or the deadline is not positive.
59
59
  * @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
60
60
  * @throws {NegativeInputError} when `referralFee.bps` is negative.
61
- * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
61
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 1,000 or `assets` exceeds uint256.
62
62
  * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
63
- * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
64
63
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
65
64
  * @throws {MarketIdMismatchError} When the snapshot describes another market.
66
65
  * @throws {BlueSnapshotChainMismatchError} When the snapshot describes another chain.
@@ -40,7 +40,7 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
40
40
  * @param params.marketData - Caller-fetched snapshot of the selected market and chain.
41
41
  * @param params.collateralAssets - Positive gross collateral amount in token base units.
42
42
  * @param params.funding.type - `"erc20"` (default) or `"native"` for wNative collateral.
43
- * @param params.referralFee.bps - Optional fee in integer basis points, below 10,000.
43
+ * @param params.referralFee.bps - Optional fee in integer basis points, at most 1,000.
44
44
  * @param params.referralFee.recipient - Non-zero recipient required for a positive fee.
45
45
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
46
46
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
@@ -55,10 +55,9 @@ export interface BlueSupplyCollateralPlanParams extends IntentParams, ReferenceT
55
55
  * @throws {NonPositiveInputError} when the collateral amount or expiry is zero.
56
56
  * @throws {ExpiredDeadlineError} when expiry is at or before the reference time.
57
57
  * @throws {NegativeInputError} when the collateral amount or fee basis points are negative.
58
- * @throws {InputExceedsMaxError} when collateral exceeds uint256 or fee basis points exceed 10,000.
58
+ * @throws {InputExceedsMaxError} when collateral exceeds uint256 or `referralFee.bps` exceeds 1,000.
59
59
  * @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
60
60
  * @throws {InvalidTransactionPlanError} when `calldataOrigin` exceeds 1 MiB.
61
- * @throws {ReferralFeePctExceededError} when the referral fee is 100%.
62
61
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
63
62
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain with no wNative.
64
63
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets non-wNative collateral.
@@ -29,7 +29,7 @@ const actionId = "blueSupplyCollateral";
29
29
  * @param params.marketData - Caller-fetched snapshot of the selected market and chain.
30
30
  * @param params.collateralAssets - Positive gross collateral amount in token base units.
31
31
  * @param params.funding.type - `"erc20"` (default) or `"native"` for wNative collateral.
32
- * @param params.referralFee.bps - Optional fee in integer basis points, below 10,000.
32
+ * @param params.referralFee.bps - Optional fee in integer basis points, at most 1,000.
33
33
  * @param params.referralFee.recipient - Non-zero recipient required for a positive fee.
34
34
  * @param params.supportSignature - Prefer an ERC-2612 permit where available; defaults to false.
35
35
  * @param params.now - Reference Unix timestamp in seconds; defaults to the device clock.
@@ -44,10 +44,9 @@ const actionId = "blueSupplyCollateral";
44
44
  * @throws {NonPositiveInputError} when the collateral amount or expiry is zero.
45
45
  * @throws {ExpiredDeadlineError} when expiry is at or before the reference time.
46
46
  * @throws {NegativeInputError} when the collateral amount or fee basis points are negative.
47
- * @throws {InputExceedsMaxError} when collateral exceeds uint256 or fee basis points exceed 10,000.
47
+ * @throws {InputExceedsMaxError} when collateral exceeds uint256 or `referralFee.bps` exceeds 1,000.
48
48
  * @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
49
49
  * @throws {InvalidTransactionPlanError} when `calldataOrigin` exceeds 1 MiB.
50
- * @throws {ReferralFeePctExceededError} when the referral fee is 100%.
51
50
  * @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
52
51
  * @throws {ChainWNativeMissingError} when native funding is requested on a chain with no wNative.
53
52
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets non-wNative collateral.
@@ -22,15 +22,20 @@ export interface BlueSupplyCollateralBorrowPlanParams extends IntentParams, Refe
22
22
  readonly borrowAssets: bigint;
23
23
  readonly funding?: Funding;
24
24
  readonly reallocations?: Iterable<VaultV2BlueReallocation>;
25
+ /** 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. */
26
+ readonly maxPenalty?: bigint;
25
27
  }
26
28
  /**
27
29
  * Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
28
- * are validated before reads; the position is quoted through max(now, lastUpdate) + two hours,
29
- * matching the stable entity handle. The SDK never signs. Native funding is exclusive and
30
+ * are validated before reads; health uses the expiry floored at max(now, lastUpdate).
31
+ * Expiries more than 365 days out retain the legacy +2h projection, like the entity handle.
32
+ * The SDK never signs. Native funding is exclusive and
30
33
  * only supports the chain's wrapped native collateral token. Reallocation penalties reduce proceeds.
31
34
  * @param client - Viem client used for prerequisite and registered-contract reads.
32
35
  * @param params - Intent, amounts and caller-fetched market/position snapshots.
36
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
33
37
  * @returns A data-only plan with approvals, authorization and the combined operation.
38
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
34
39
  * @throws {ZeroAccountError} when the account is zero.
35
40
  * @throws {NonIntegerInputError} when expiry or referral basis points are not safe integers.
36
41
  * @throws {ExpiredDeadlineError} when expiry is not later than the reference timestamp.
@@ -41,9 +46,10 @@ export interface BlueSupplyCollateralBorrowPlanParams extends IntentParams, Refe
41
46
  * @throws {MissingAccrualPositionError} when a borrow has no position snapshot.
42
47
  * @throws {MissingMarketPriceError} when the position snapshot has no usable oracle price.
43
48
  * @throws {BorrowExceedsSafeLtvError} when the quoted debt exceeds the buffered LLTV bound.
44
- * @throws {NegativeInputError} when an amount or referral fee is negative.
49
+ * @throws {NegativeInputError} when an amount, maxPenalty or referral fee is negative.
45
50
  * @throws {NonPositiveInputError} when both legs are zero, or a reallocation amount is not positive.
46
51
  * @throws {InputExceedsMaxError} when an amount exceeds its ABI bound or aggregate penalties exceed borrowing.
52
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
47
53
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
48
54
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
49
55
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation has an invalid shape.
@@ -51,7 +57,7 @@ export interface BlueSupplyCollateralBorrowPlanParams extends IntentParams, Refe
51
57
  * @throws {InconsistentReallocationPenaltyError} when one vault has conflicting penalties.
52
58
  * @throws {ReallocationWithdrawalOnTargetMarketError} when the source equals the target market.
53
59
  * @throws {ReallocationLoanTokenMismatchError} when a source has another loan token.
54
- * @throws {ReferralFeePctExceededError} when the referral fee reaches 100%.
60
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 1,000.
55
61
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
56
62
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
57
63
  * @throws {ChainWNativeMissingError} when native funding has no registered wrapped native token.
@@ -9,6 +9,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
9
9
  const viem_1 = require("viem");
10
10
  const supplyCollateralBorrow_js_1 = require("../../actions/blue/supplyCollateralBorrow.js");
11
11
  const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
12
+ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundlesV1QuoteTimestamp.js");
12
13
  const index_js_1 = require("../../helpers/index.js");
13
14
  const parse_js_1 = require("../../helpers/parse.js");
14
15
  const index_js_2 = require("../../types/index.js");
@@ -19,12 +20,15 @@ const authorization_js_1 = require("./authorization.js");
19
20
  const prepare_js_1 = require("./prepare.js");
20
21
  /**
21
22
  * Prepares collateral funding and Morpho authorization for one BlueBundlesV1 call. Snapshots
22
- * are validated before reads; the position is quoted through max(now, lastUpdate) + two hours,
23
- * matching the stable entity handle. The SDK never signs. Native funding is exclusive and
23
+ * are validated before reads; health uses the expiry floored at max(now, lastUpdate).
24
+ * Expiries more than 365 days out retain the legacy +2h projection, like the entity handle.
25
+ * The SDK never signs. Native funding is exclusive and
24
26
  * only supports the chain's wrapped native collateral token. Reallocation penalties reduce proceeds.
25
27
  * @param client - Viem client used for prerequisite and registered-contract reads.
26
28
  * @param params - Intent, amounts and caller-fetched market/position snapshots.
29
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
27
30
  * @returns A data-only plan with approvals, authorization and the combined operation.
31
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
28
32
  * @throws {ZeroAccountError} when the account is zero.
29
33
  * @throws {NonIntegerInputError} when expiry or referral basis points are not safe integers.
30
34
  * @throws {ExpiredDeadlineError} when expiry is not later than the reference timestamp.
@@ -35,9 +39,10 @@ const prepare_js_1 = require("./prepare.js");
35
39
  * @throws {MissingAccrualPositionError} when a borrow has no position snapshot.
36
40
  * @throws {MissingMarketPriceError} when the position snapshot has no usable oracle price.
37
41
  * @throws {BorrowExceedsSafeLtvError} when the quoted debt exceeds the buffered LLTV bound.
38
- * @throws {NegativeInputError} when an amount or referral fee is negative.
42
+ * @throws {NegativeInputError} when an amount, maxPenalty or referral fee is negative.
39
43
  * @throws {NonPositiveInputError} when both legs are zero, or a reallocation amount is not positive.
40
44
  * @throws {InputExceedsMaxError} when an amount exceeds its ABI bound or aggregate penalties exceed borrowing.
45
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
41
46
  * @throws {ReallocationsRequireBorrowError} when reallocations accompany no borrow.
42
47
  * @throws {InvalidReallocationAddressError} when a vault or adapter address is malformed.
43
48
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation has an invalid shape.
@@ -45,7 +50,7 @@ const prepare_js_1 = require("./prepare.js");
45
50
  * @throws {InconsistentReallocationPenaltyError} when one vault has conflicting penalties.
46
51
  * @throws {ReallocationWithdrawalOnTargetMarketError} when the source equals the target market.
47
52
  * @throws {ReallocationLoanTokenMismatchError} when a source has another loan token.
48
- * @throws {ReferralFeePctExceededError} when the referral fee reaches 100%.
53
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 1,000.
49
54
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
50
55
  * @throws {NativeAmountOnNonWNativeAssetError} when native funding targets another token.
51
56
  * @throws {ChainWNativeMissingError} when native funding has no registered wrapped native token.
@@ -87,6 +92,7 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
87
92
  const preparedParams = captureSupplyBorrowIntent(params);
88
93
  const { chainId, account, marketId, marketData, positionData, now } = preparedParams;
89
94
  const { collateralAssets, borrowAssets } = params;
95
+ const { maxPenalty } = params;
90
96
  const id = "blueSupplyCollateralBorrow";
91
97
  let label = "Supply collateral and borrow on Blue";
92
98
  if (borrowAssets === 0n) {
@@ -112,6 +118,7 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
112
118
  maxLtv,
113
119
  nativeAmount,
114
120
  reallocations,
121
+ maxPenalty,
115
122
  ...intent,
116
123
  },
117
124
  });
@@ -121,7 +128,11 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
121
128
  throw new index_js_2.MissingAccrualPositionError(marketId);
122
129
  }
123
130
  (0, index_js_1.validatePositionHealth)({
124
- positionData: position.accrueInterest(blue_sdk_1.MathLib.max(now, position.market.lastUpdate) + morpho_ts_1.Time.s.from.h(2n)),
131
+ positionData: position.accrueInterest((0, getBlueBundlesV1QuoteTimestamp_js_1.getBlueBundlesV1QuoteTimestamp)({
132
+ lastUpdate: position.market.lastUpdate,
133
+ now,
134
+ deadline: intent.deadline,
135
+ })),
125
136
  additionalCollateral: collateralAssets,
126
137
  borrowAmount: borrowAssets,
127
138
  marketId,
@@ -174,6 +185,7 @@ async function prepareBlueSupplyCollateralBorrow(client, params) {
174
185
  borrowAssets,
175
186
  maxLtv,
176
187
  nativeAssets: nativeAmount,
188
+ ...(maxPenalty !== undefined && { maxPenalty }),
177
189
  reallocations: reallocations.map((entry) => ({
178
190
  ...entry,
179
191
  from: entry.from.type === "market"
@@ -321,7 +333,12 @@ function validateSupplyCollateralBorrowPlanAction(action, path) {
321
333
  reallocations: "array",
322
334
  },
323
335
  });
324
- for (const key of ["nativeAssets", "referralFeePct", "authorizationNonce"]) {
336
+ for (const key of [
337
+ "nativeAssets",
338
+ "referralFeePct",
339
+ "authorizationNonce",
340
+ "maxPenalty",
341
+ ]) {
325
342
  if (inputs[key] !== undefined) {
326
343
  (0, validation_js_1.validatePlanField)(inputs[key], {
327
344
  path: `${path}.inputs.${key}`,
@@ -33,6 +33,8 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
33
33
  /** Caller-fetched position used to validate the available supply balance. */
34
34
  readonly positionData: BluePositionSnapshot;
35
35
  readonly reallocations?: readonly VaultV2BlueReallocation[];
36
+ /** 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. */
37
+ readonly maxPenalty?: bigint;
36
38
  readonly now?: bigint;
37
39
  };
38
40
  /**
@@ -50,6 +52,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
50
52
  * @param params.assets - Exact positive gross loan assets withdrawn in base units; exclusive with `shares`.
51
53
  * @param params.shares - Exact positive supply shares burned; exclusive with `assets`, with no full-close sentinel or minimum-proceeds guarantee.
52
54
  * @param params.reallocations - Optional ordered Vault V2 BluePublicAllocator inputs; defaults to an empty list. Penalties reduce withdrawal proceeds.
55
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
53
56
  * @param params.reallocations[].vault - Vault whose liquidity the allocator moves.
54
57
  * @param params.reallocations[].from.type - Source discriminator: `market` or `idle`.
55
58
  * @param params.reallocations[].from.adapter - Source adapter, required only for a `market` source.
@@ -61,7 +64,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
61
64
  * @param params.reallocations[].to.adapter - Target adapter supplying the enclosing withdrawal market.
62
65
  * @param params.reallocations[].assets - Positive reallocated assets in loan-token base units, bounded by uint128.
63
66
  * @param params.reallocations[].penalty - Vault-configured WAD-scaled penalty, bounded by uint64 and applied with upward rounding per allocation.
64
- * @param params.referralFee.bps - Optional integer referral fee in basis points of gross proceeds after allocator penalties; defaults to zero and must be below 10,000.
67
+ * @param params.referralFee.bps - Optional integer referral fee in basis points of gross proceeds after allocator penalties; defaults to zero and must be at most 1,000.
65
68
  * @param params.referralFee.recipient - Optional fee recipient; required and non-zero when `referralFee.bps` is positive.
66
69
  * @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
67
70
  * @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
@@ -69,6 +72,7 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
69
72
  * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to every built transaction; omitted by default.
70
73
  * @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
71
74
  * @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
75
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
72
76
  * @throws {ChainIdMismatchError} when the client declares or its transport serves another chain.
73
77
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the registry.
74
78
  * @throws {UnknownAddressError} when Blue or BlueBundlesV1 is not registered on `chainId`.
@@ -79,8 +83,9 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
79
83
  * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
80
84
  * @throws {NonPositiveInputError} when expiry, the selected withdrawal amount, or a reallocation amount is not positive.
81
85
  * @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
82
- * @throws {NegativeInputError} when the referral fee, a withdrawal amount, or a reallocation penalty is negative.
83
- * @throws {InputExceedsMaxError} when referral basis points exceed 10,000, an encoded amount or penalty exceeds its ABI bound, or aggregate allocator penalties exceed withdrawn assets (the snapshot's downward-rounded asset quote in shares mode).
86
+ * @throws {NegativeInputError} when the referral fee, a withdrawal amount, maxPenalty, or a reallocation penalty is negative.
87
+ * @throws {InputExceedsMaxError} when referral basis points exceed 1,000, an encoded amount or penalty exceeds its ABI bound, or aggregate allocator penalties exceed withdrawn assets (the snapshot's downward-rounded asset quote in shares mode).
88
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
84
89
  * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
85
90
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not an object or has a legacy Vault V1 shape.
86
91
  * @throws {InvalidReallocationAddressError} when a reallocation vault or adapter address is malformed.
@@ -88,7 +93,6 @@ export type BlueWithdrawPlanParams = IntentParams & AssetsOrSharesArgs & {
88
93
  * @throws {InconsistentReallocationPenaltyError} when allocations from one vault specify different penalties.
89
94
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation source is the withdrawal market.
90
95
  * @throws {MutuallyExclusiveWithdrawAmountsError} when both withdrawal modes are nonzero.
91
- * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
92
96
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
93
97
  * @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
94
98
  * @throws {MissingAccrualPositionError} when the required position snapshot is missing.
@@ -128,7 +132,13 @@ export declare function validateBlueWithdrawAuthorizationRequest(request: Extrac
128
132
  }>, action: Extract<Action, {
129
133
  type: "blueWithdraw";
130
134
  }>): void;
131
- /** @internal Encodes the self-contained withdrawal recipe and its inline authorization, if requested. */
135
+ /**
136
+ * @internal Encodes the self-contained withdrawal recipe and its inline authorization, if requested.
137
+ * @param action - Withdrawal recipe with optional WAD-scaled maxPenalty in [0, WAD], defaulting to zero.
138
+ * @param requests - Available authorization signatures.
139
+ * @throws {NegativeInputError} when maxPenalty is negative.
140
+ * @throws {InputExceedsMaxError} when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
141
+ */
132
142
  export declare function buildBlueWithdraw(action: Extract<Action, {
133
143
  type: "blueWithdraw";
134
144
  }>, requests?: readonly SignatureRequest[]): Readonly<import("../../index.js").Transaction<import("../../index.js").BlueWithdrawAction>>;
@@ -31,6 +31,7 @@ const prepare_js_1 = require("./prepare.js");
31
31
  * @param params.assets - Exact positive gross loan assets withdrawn in base units; exclusive with `shares`.
32
32
  * @param params.shares - Exact positive supply shares burned; exclusive with `assets`, with no full-close sentinel or minimum-proceeds guarantee.
33
33
  * @param params.reallocations - Optional ordered Vault V2 BluePublicAllocator inputs; defaults to an empty list. Penalties reduce withdrawal proceeds.
34
+ * @param params.maxPenalty - Maximum WAD-scaled penalty rate per reallocation in [0, WAD], defaulting to zero. Each rate applies to that reallocation's assets, so it does not bound total proceeds lost.
34
35
  * @param params.reallocations[].vault - Vault whose liquidity the allocator moves.
35
36
  * @param params.reallocations[].from.type - Source discriminator: `market` or `idle`.
36
37
  * @param params.reallocations[].from.adapter - Source adapter, required only for a `market` source.
@@ -42,7 +43,7 @@ const prepare_js_1 = require("./prepare.js");
42
43
  * @param params.reallocations[].to.adapter - Target adapter supplying the enclosing withdrawal market.
43
44
  * @param params.reallocations[].assets - Positive reallocated assets in loan-token base units, bounded by uint128.
44
45
  * @param params.reallocations[].penalty - Vault-configured WAD-scaled penalty, bounded by uint64 and applied with upward rounding per allocation.
45
- * @param params.referralFee.bps - Optional integer referral fee in basis points of gross proceeds after allocator penalties; defaults to zero and must be below 10,000.
46
+ * @param params.referralFee.bps - Optional integer referral fee in basis points of gross proceeds after allocator penalties; defaults to zero and must be at most 1,000.
46
47
  * @param params.referralFee.recipient - Optional fee recipient; required and non-zero when `referralFee.bps` is positive.
47
48
  * @param params.supportSignature - Optional Morpho authorization signature preference; defaults to `false`, selecting a direct authorization transaction when needed. Neither mode requests a token allowance or Permit2 signature.
48
49
  * @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
@@ -50,6 +51,7 @@ const prepare_js_1 = require("./prepare.js");
50
51
  * @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to every built transaction; omitted by default.
51
52
  * @param params.deployless - Optional shared intent field; unused because withdrawal reads no token metadata.
52
53
  * @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with a withdrawal step. Direct Morpho authorization is a preceding step; signed authorization is consumed inline by the withdrawal. Attach signatures before building.
54
+ * @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
53
55
  * @throws {ChainIdMismatchError} when the client declares or its transport serves another chain.
54
56
  * @throws {UnsupportedChainIdError} when `chainId` is absent from the registry.
55
57
  * @throws {UnknownAddressError} when Blue or BlueBundlesV1 is not registered on `chainId`.
@@ -60,8 +62,9 @@ const prepare_js_1 = require("./prepare.js");
60
62
  * @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
61
63
  * @throws {NonPositiveInputError} when expiry, the selected withdrawal amount, or a reallocation amount is not positive.
62
64
  * @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
63
- * @throws {NegativeInputError} when the referral fee, a withdrawal amount, or a reallocation penalty is negative.
64
- * @throws {InputExceedsMaxError} when referral basis points exceed 10,000, an encoded amount or penalty exceeds its ABI bound, or aggregate allocator penalties exceed withdrawn assets (the snapshot's downward-rounded asset quote in shares mode).
65
+ * @throws {NegativeInputError} when the referral fee, a withdrawal amount, maxPenalty, or a reallocation penalty is negative.
66
+ * @throws {InputExceedsMaxError} when referral basis points exceed 1,000, an encoded amount or penalty exceeds its ABI bound, or aggregate allocator penalties exceed withdrawn assets (the snapshot's downward-rounded asset quote in shares mode).
67
+ * Also thrown when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
65
68
  * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
66
69
  * @throws {InvalidVaultV2BlueReallocationShapeError} when a reallocation entry is not an object or has a legacy Vault V1 shape.
67
70
  * @throws {InvalidReallocationAddressError} when a reallocation vault or adapter address is malformed.
@@ -69,7 +72,6 @@ const prepare_js_1 = require("./prepare.js");
69
72
  * @throws {InconsistentReallocationPenaltyError} when allocations from one vault specify different penalties.
70
73
  * @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation source is the withdrawal market.
71
74
  * @throws {MutuallyExclusiveWithdrawAmountsError} when both withdrawal modes are nonzero.
72
- * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
73
75
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
74
76
  * @throws {ReallocationLoanTokenMismatchError} when a source market uses another loan token.
75
77
  * @throws {MissingAccrualPositionError} when the required position snapshot is missing.
@@ -103,6 +105,7 @@ const prepare_js_1 = require("./prepare.js");
103
105
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
104
106
  */
105
107
  async function prepareBlueWithdraw(client, params) {
108
+ const { maxPenalty } = params;
106
109
  await (0, validateClientChainId_js_1.validateClientChainId)(client, params.chainId);
107
110
  const { positionData: snapshot } = params;
108
111
  if (snapshot == null) {
@@ -123,6 +126,7 @@ async function prepareBlueWithdraw(client, params) {
123
126
  withdrawAssets: "assets" in params ? (params.assets ?? 0n) : 0n,
124
127
  withdrawShares: "shares" in params ? (params.shares ?? 0n) : 0n,
125
128
  reallocations: params.reallocations ?? [],
129
+ ...(maxPenalty !== undefined && { maxPenalty }),
126
130
  deadline: intent.deadline,
127
131
  referralFeePct: intent.referralFeePct,
128
132
  referralFeeRecipient: intent.referralFeeRecipient ?? viem_1.zeroAddress,
@@ -208,7 +212,13 @@ function validateBlueWithdrawAuthorizationRequest(request, action) {
208
212
  deadline: action.inputs.deadline,
209
213
  });
210
214
  }
211
- /** @internal Encodes the self-contained withdrawal recipe and its inline authorization, if requested. */
215
+ /**
216
+ * @internal Encodes the self-contained withdrawal recipe and its inline authorization, if requested.
217
+ * @param action - Withdrawal recipe with optional WAD-scaled maxPenalty in [0, WAD], defaulting to zero.
218
+ * @param requests - Available authorization signatures.
219
+ * @throws {NegativeInputError} when maxPenalty is negative.
220
+ * @throws {InputExceedsMaxError} when maxPenalty exceeds WAD or a penalty exceeds maxPenalty (zero by default).
221
+ */
212
222
  function buildBlueWithdraw(action, requests = []) {
213
223
  const { chainId, account, marketParams, authorizationNonce: _authorizationNonce, ...args } = action.inputs;
214
224
  let authorizationSignature;
@@ -242,7 +252,10 @@ function buildBlueWithdraw(action, requests = []) {
242
252
  }
243
253
  const targetMarketParams = new blue_sdk_1.MarketParams(marketParams);
244
254
  // Reject malformed entries with typed errors before reading their source fields.
245
- (0, validate_js_1.validateVaultV2BlueReallocations)(args.reallocations, targetMarketParams.id);
255
+ (0, validate_js_1.validateVaultV2BlueReallocations)(args.reallocations, {
256
+ targetMarketId: targetMarketParams.id,
257
+ maxPenalty: args.maxPenalty,
258
+ });
246
259
  const reallocations = args.reallocations.map((entry) => ({
247
260
  ...entry,
248
261
  from: entry.from.type === "market"
@@ -265,6 +278,12 @@ function buildBlueWithdraw(action, requests = []) {
265
278
  /** @internal Validates stored withdrawal scalars and allocator input shapes. */
266
279
  function validateBlueWithdrawPlanAction(action, path) {
267
280
  const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
281
+ if (inputs.maxPenalty !== undefined) {
282
+ (0, validation_js_1.validatePlanField)(inputs.maxPenalty, {
283
+ path: `${path}.inputs.maxPenalty`,
284
+ type: "uint256 bigint",
285
+ });
286
+ }
268
287
  const roles = (0, validation_js_1.getPlanObject)(action.signatureRequestIds, `${path}.signatureRequestIds`);
269
288
  if (roles.morphoAuthorization !== undefined) {
270
289
  (0, validation_js_1.validatePlanField)(roles.morphoAuthorization, {
@@ -30,7 +30,8 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
30
30
  }
31
31
  /**
32
32
  * Prepares a BlueBundlesV1 collateral withdrawal with direct or inline signed Morpho authorization.
33
- * Health is checked with the same two-hour accrual horizon and LLTV buffer as the entity handle.
33
+ * Health uses the expiry floored at max(now, lastUpdate), with the entity's LLTV buffer.
34
+ * Expiries more than 365 days out retain the legacy +2h projection for unlimited sentinels.
34
35
  * No token allowance or Permit2 prerequisite is read or produced.
35
36
  * @param client - Viem client used for registered contract-code and Morpho authorization reads.
36
37
  * @param params - Intent and matching market and account position snapshots.
@@ -40,9 +41,9 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
40
41
  * @param params.marketData.chainId - Chain from which the market snapshot was fetched; must equal `chainId`.
41
42
  * @param params.marketData.market - Caller-fetched `Market` providing the market tuple and LLTV.
42
43
  * @param params.positionData.chainId - Chain from which the position snapshot was fetched; must equal `chainId`.
43
- * @param params.positionData.position - Caller-fetched `AccrualPosition` for `account` and `marketId`, used for the two-hour accrued health check.
44
+ * @param params.positionData.position - Caller-fetched `AccrualPosition` for `account` and `marketId`, used for the deadline-accrued health check.
44
45
  * @param params.collateralAssets - Positive collateral withdrawal in token base units, not exceeding the position's collateral.
45
- * @param params.referralFee.bps - Optional integer referral fee in basis points; defaults to zero and must be below 10,000.
46
+ * @param params.referralFee.bps - Optional integer referral fee in basis points; defaults to zero and must be at most 1,000.
46
47
  * @param params.referralFee.recipient - Non-zero fee recipient required when the optional fee is positive.
47
48
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
48
49
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
@@ -59,9 +60,8 @@ export interface BlueWithdrawCollateralPlanParams extends IntentParams, Referenc
59
60
  * @throws {NonPositiveInputError} when `expiresAt` or `collateralAssets` is not positive.
60
61
  * @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
61
62
  * @throws {NegativeInputError} when `referralFee.bps` is negative.
62
- * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `collateralAssets` exceeds uint256.
63
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 1,000 or `collateralAssets` exceeds uint256.
63
64
  * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
64
- * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
65
65
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
66
66
  * @throws {UnsupportedMarketIrmError} when projecting an indebted position requires an unsupported IRM without rate data.
67
67
  * @throws {WithdrawExceedsCollateralError} when `collateralAssets` exceeds the position's collateral.
@@ -9,6 +9,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
9
9
  const withdrawCollateral_js_1 = require("../../actions/blue/withdrawCollateral.js");
10
10
  const common_js_1 = require("../../actions/bundles/common.js");
11
11
  const constant_js_1 = require("../../helpers/constant.js");
12
+ const getBlueBundlesV1QuoteTimestamp_js_1 = require("../../helpers/getBlueBundlesV1QuoteTimestamp.js");
12
13
  const validate_js_1 = require("../../helpers/validate.js");
13
14
  const index_js_1 = require("../../types/index.js");
14
15
  const error_js_1 = require("../error.js");
@@ -17,7 +18,8 @@ const authorization_js_1 = require("./authorization.js");
17
18
  const prepare_js_1 = require("./prepare.js");
18
19
  /**
19
20
  * Prepares a BlueBundlesV1 collateral withdrawal with direct or inline signed Morpho authorization.
20
- * Health is checked with the same two-hour accrual horizon and LLTV buffer as the entity handle.
21
+ * Health uses the expiry floored at max(now, lastUpdate), with the entity's LLTV buffer.
22
+ * Expiries more than 365 days out retain the legacy +2h projection for unlimited sentinels.
21
23
  * No token allowance or Permit2 prerequisite is read or produced.
22
24
  * @param client - Viem client used for registered contract-code and Morpho authorization reads.
23
25
  * @param params - Intent and matching market and account position snapshots.
@@ -27,9 +29,9 @@ const prepare_js_1 = require("./prepare.js");
27
29
  * @param params.marketData.chainId - Chain from which the market snapshot was fetched; must equal `chainId`.
28
30
  * @param params.marketData.market - Caller-fetched `Market` providing the market tuple and LLTV.
29
31
  * @param params.positionData.chainId - Chain from which the position snapshot was fetched; must equal `chainId`.
30
- * @param params.positionData.position - Caller-fetched `AccrualPosition` for `account` and `marketId`, used for the two-hour accrued health check.
32
+ * @param params.positionData.position - Caller-fetched `AccrualPosition` for `account` and `marketId`, used for the deadline-accrued health check.
31
33
  * @param params.collateralAssets - Positive collateral withdrawal in token base units, not exceeding the position's collateral.
32
- * @param params.referralFee.bps - Optional integer referral fee in basis points; defaults to zero and must be below 10,000.
34
+ * @param params.referralFee.bps - Optional integer referral fee in basis points; defaults to zero and must be at most 1,000.
33
35
  * @param params.referralFee.recipient - Non-zero fee recipient required when the optional fee is positive.
34
36
  * @param params.supportSignature - Optional Morpho authorization signature preference, defaulting to `false`; otherwise prepares a direct authorization transaction when needed.
35
37
  * @param params.now - Optional reference timestamp in Unix seconds, normally the latest block timestamp; defaults to the device clock.
@@ -46,9 +48,8 @@ const prepare_js_1 = require("./prepare.js");
46
48
  * @throws {NonPositiveInputError} when `expiresAt` or `collateralAssets` is not positive.
47
49
  * @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
48
50
  * @throws {NegativeInputError} when `referralFee.bps` is negative.
49
- * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `collateralAssets` exceeds uint256.
51
+ * @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 1,000 or `collateralAssets` exceeds uint256.
50
52
  * @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
51
- * @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000.
52
53
  * @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
53
54
  * @throws {UnsupportedMarketIrmError} when projecting an indebted position requires an unsupported IRM without rate data.
54
55
  * @throws {WithdrawExceedsCollateralError} when `collateralAssets` exceeds the position's collateral.
@@ -113,8 +114,11 @@ async function prepareBlueWithdrawCollateral(client, params) {
113
114
  (0, validate_js_1.validatePositionHealthAfterWithdraw)({
114
115
  positionData: position.borrowShares === 0n
115
116
  ? new blue_sdk_1.AccrualPosition(position, position.market)
116
- : position.accrueInterest(blue_sdk_1.MathLib.max(now, position.market.lastUpdate) +
117
- morpho_ts_1.Time.s.from.h(2n)),
117
+ : position.accrueInterest((0, getBlueBundlesV1QuoteTimestamp_js_1.getBlueBundlesV1QuoteTimestamp)({
118
+ lastUpdate: position.market.lastUpdate,
119
+ now,
120
+ deadline: resolvedIntent.deadline,
121
+ })),
118
122
  withdrawAmount: collateralAssets,
119
123
  lltv,
120
124
  marketId,
@@ -36,6 +36,8 @@ function validateDepositPlanAction(action, path) {
36
36
  function resolveDepositInputs(params, now) {
37
37
  const { vault, chainId, assets } = params;
38
38
  const intent = (0, intent_js_1.resolveIntent)(params, now);
39
+ // Bound forward accrual for both vault deposit plan kinds.
40
+ (0, validate_js_1.validateVaultDepositDeadline)(intent.deadline, { now, field: "expiresAt" });
39
41
  const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
40
42
  (0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
41
43
  const native = (params.funding ?? { type: "erc20" }).type === "native";
@@ -68,6 +70,8 @@ async function prepareVaultDeposit(client, params) {
68
70
  const { chainId, account, assets } = params;
69
71
  const vault = params.vault.address;
70
72
  const now = params.now ?? morpho_ts_1.Time.timestamp();
73
+ // Reject a non-bigint clock before deriving the default expiry.
74
+ (0, validate_js_1.validateReferenceTime)(now);
71
75
  const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
72
76
  const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
73
77
  const tokenPermitRequestId = `${params.type}:tokenPermit`;
@@ -10,7 +10,7 @@ export type Funding = {
10
10
  };
11
11
  /**
12
12
  * @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
13
- * Referral fee in basis points of the gross amount, paid to `recipient`.
13
+ * Referral fee in basis points of the gross amount, paid to `recipient`. At most 1,000 bps (10%).
14
14
  */
15
15
  export interface ReferralFee {
16
16
  readonly bps: number;
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveIntent = resolveIntent;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
+ const constant_js_1 = require("../helpers/constant.js");
6
7
  const index_js_1 = require("../types/index.js");
7
8
  const error_js_1 = require("./error.js");
8
9
  const validation_js_1 = require("./validation.js");
9
10
  const BASIS_POINTS = 10000n;
10
11
  const WAD_PER_BASIS_POINT = morpho_ts_1.MathLib.WAD / BASIS_POINTS;
12
+ const MAX_REFERRAL_FEE_BPS = constant_js_1.MIDNIGHT_MAX_REFERRAL_FEE_PCT / WAD_PER_BASIS_POINT;
11
13
  function toSafeInteger(field, value) {
12
14
  if (!Number.isSafeInteger(value)) {
13
15
  throw new error_js_1.NonIntegerInputError(field, value);
@@ -37,11 +39,11 @@ function resolveIntent(params, now) {
37
39
  if (bps < 0n) {
38
40
  throw new index_js_1.NegativeInputError("referralFee.bps", bps);
39
41
  }
40
- if (bps > BASIS_POINTS) {
42
+ if (bps > MAX_REFERRAL_FEE_BPS) {
41
43
  throw new index_js_1.InputExceedsMaxError({
42
44
  field: "referralFee.bps",
43
45
  value: bps,
44
- max: BASIS_POINTS,
46
+ max: MAX_REFERRAL_FEE_BPS,
45
47
  });
46
48
  }
47
49
  const { calldataOrigin } = params;
@@ -70,6 +70,7 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
70
70
  * @param step - Recipe to encode; missing signatures on unrelated supported steps do not block it.
71
71
  * @returns A frozen `{ to, data, value, action }`, ready to simulate or submit. `data` ends with the plan's `calldataOrigin` when one was set.
72
72
  * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
73
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
73
74
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
74
75
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported.
75
76
  * @throws {UnsupportedTransactionPlanActionError} If any plan step or the selected step names an unsupported action type.
@@ -83,13 +84,14 @@ export declare function getPendingSignatureRequests(plan: TransactionPlan): read
83
84
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
84
85
  * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
85
86
  * @throws {ReferralFeePctExceededError} If the action's referral fee is at least WAD.
87
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
86
88
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
87
89
  * @throws {IncompleteTransactionPlanError} If a referenced signature request or its signature is missing.
88
90
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with the step's action or its encoding arguments.
89
91
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
90
92
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
91
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
92
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
93
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
94
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
93
95
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
94
96
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
95
97
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.
@@ -120,6 +122,7 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
120
122
  * @param plan - Plan whose referenced signature requests all carry a signature.
121
123
  * @returns Frozen SDK transactions in step order; discriminate on `action.type` for per-step handling.
122
124
  * @throws {InvalidTransactionPlanError} If the plan header, action context, IDs or deadlines are inconsistent.
125
+ * @throws {InvalidBigIntInputError} If a supplied Blue maxPenalty is not a bigint; uint256 schema validation is performed by parseTransactionPlan, not this builder.
123
126
  * @throws {InvalidSignatureError} If a stored signature has high s, cannot recover a public key or does not match the request owner.
124
127
  * @throws {UnsupportedTransactionPlanVersionError} If the plan version is unsupported, including empty plans.
125
128
  * @throws {UnsupportedTransactionPlanActionError} If any plan step names an unsupported action type, before reading requests.
@@ -133,13 +136,14 @@ export declare function buildTransaction(plan: TransactionPlan, step: Step): Rea
133
136
  * @throws {EmptyDeallocationsError} If a force-redeem step has no deallocations.
134
137
  * @throws {EmptyMarketParamsListError} If a Vault V1 in-kind redemption step has no markets.
135
138
  * @throws {ReferralFeePctExceededError} If an action's referral fee is at least WAD.
139
+ * @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
136
140
  * @throws {ReferralFeeRecipientMissingError} If a positive referral fee has no nonzero recipient.
137
141
  * @throws {IncompleteTransactionPlanError} If any step references a signature request or signature that is missing.
138
142
  * @throws {TransactionPlanSignatureMismatchError} If a referenced request disagrees with its action or encoding arguments.
139
143
  * @throws {BundlesPermitMismatchError} If a stored signature cannot be parsed or a signed permit's encoding arguments do not match the step.
140
144
  * @throws {MarketIdMismatchError} If a Blue market ID differs from its parameter tuple.
141
- * @throws {NegativeInputError} If a Blue amount, native value, LTV bound or referral fee is negative.
142
- * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, or withdrawal-only funding is nonzero.
145
+ * @throws {NegativeInputError} If a Blue amount, native value, LTV bound, maxPenalty or referral fee is negative.
146
+ * @throws {InputExceedsMaxError} If a Blue amount, bound or deadline exceeds uint256, maxPenalty exceeds WAD, a reallocation penalty exceeds maxPenalty (default zero, rejecting any positive penalty), or withdrawal-only funding is nonzero.
143
147
  * @throws {MutuallyExclusiveRepayAmountsError} If a Blue repayment specifies both nonzero assets and shares.
144
148
  * @throws {MaxRepayAssetsBelowRepayAssetsError} If exact-asset funding cannot cover repayment plus referral fees.
145
149
  * @throws {NativeFundingAmountMismatchError} If Blue native funding does not equal the full repayment cap.