@morpho-org/morpho-sdk 5.8.0 → 6.0.0-next.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 (167) hide show
  1. package/MIGRATION-v5-to-v6.md +201 -0
  2. package/README.md +62 -40
  3. package/lib/cjs/abis.d.ts +543 -0
  4. package/lib/cjs/abis.js +738 -0
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -58
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +99 -0
  8. package/lib/cjs/actions/blue/common.js +318 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -107
  10. package/lib/cjs/actions/blue/refinance.js +97 -197
  11. package/lib/cjs/actions/blue/repay.d.ts +72 -68
  12. package/lib/cjs/actions/blue/repay.js +56 -118
  13. package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  14. package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
  15. package/lib/cjs/actions/blue/supply.d.ts +62 -45
  16. package/lib/cjs/actions/blue/supply.js +94 -70
  17. package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
  18. package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
  19. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -86
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -119
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -78
  22. package/lib/cjs/actions/blue/withdraw.js +101 -97
  23. package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
  24. package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
  25. package/lib/cjs/actions/index.d.ts +1 -1
  26. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  27. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  28. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  29. package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
  30. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  31. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  32. package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
  33. package/lib/cjs/actions/requirements/blue/index.js +2 -0
  34. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  35. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  36. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  37. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
  38. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  39. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
  40. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  41. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
  42. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  43. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  44. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  45. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
  46. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
  47. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  48. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  49. package/lib/cjs/blue/types.d.ts +3 -1
  50. package/lib/cjs/blue/utils.d.ts +3 -1
  51. package/lib/cjs/blue/utils.js +1 -0
  52. package/lib/cjs/bundler/actions.d.ts +6 -4
  53. package/lib/cjs/bundler/actions.js +6 -4
  54. package/lib/cjs/bundler/types.d.ts +10 -1
  55. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  56. package/lib/cjs/client/morphoViemExtension.js +2 -1
  57. package/lib/cjs/entities/blue/blue.d.ts +817 -360
  58. package/lib/cjs/entities/blue/blue.js +455 -698
  59. package/lib/cjs/entities/index.d.ts +1 -0
  60. package/lib/cjs/entities/vaultV1/vaultV1.js +4 -12
  61. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +18 -3
  62. package/lib/cjs/entities/vaultV1ReallocationData.js +11 -1
  63. package/lib/cjs/entities/vaultV2/vaultV2.js +6 -18
  64. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +7 -10
  65. package/lib/cjs/helpers/computeVaultV1Reallocations.js +7 -10
  66. package/lib/cjs/helpers/validate.d.ts +16 -23
  67. package/lib/cjs/helpers/validate.js +32 -48
  68. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  69. package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
  70. package/lib/cjs/types/action.d.ts +146 -162
  71. package/lib/cjs/types/action.js +29 -2
  72. package/lib/cjs/types/client.d.ts +9 -0
  73. package/lib/cjs/types/error.d.ts +173 -18
  74. package/lib/cjs/types/error.js +230 -25
  75. package/lib/cjs/types/sharedLiquidity.d.ts +20 -4
  76. package/lib/cjs/types.d.ts +3 -1
  77. package/lib/cjs/utils.d.ts +3 -1
  78. package/lib/cjs/utils.js +1 -0
  79. package/lib/esm/abis.d.ts +543 -0
  80. package/lib/esm/abis.js +737 -0
  81. package/lib/esm/actions/blue/borrow.d.ts +62 -58
  82. package/lib/esm/actions/blue/borrow.js +48 -80
  83. package/lib/esm/actions/blue/common.d.ts +99 -0
  84. package/lib/esm/actions/blue/common.js +306 -0
  85. package/lib/esm/actions/blue/refinance.d.ts +72 -107
  86. package/lib/esm/actions/blue/refinance.js +98 -198
  87. package/lib/esm/actions/blue/repay.d.ts +72 -68
  88. package/lib/esm/actions/blue/repay.js +56 -118
  89. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  90. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  91. package/lib/esm/actions/blue/supply.d.ts +62 -45
  92. package/lib/esm/actions/blue/supply.js +94 -70
  93. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  94. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  95. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -86
  96. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -120
  97. package/lib/esm/actions/blue/withdraw.d.ts +68 -78
  98. package/lib/esm/actions/blue/withdraw.js +100 -96
  99. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  100. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  101. package/lib/esm/actions/index.d.ts +1 -1
  102. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  103. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  104. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
  105. package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
  106. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  107. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  108. package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
  109. package/lib/esm/actions/requirements/blue/index.js +2 -0
  110. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  111. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  112. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  113. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
  114. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  115. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
  116. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
  117. package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
  118. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  119. package/lib/esm/actions/requirements/encode/index.js +1 -0
  120. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  121. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
  122. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
  123. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  124. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  125. package/lib/esm/blue/types.d.ts +3 -1
  126. package/lib/esm/blue/utils.d.ts +3 -1
  127. package/lib/esm/blue/utils.js +3 -1
  128. package/lib/esm/bundler/actions.d.ts +6 -4
  129. package/lib/esm/bundler/actions.js +6 -4
  130. package/lib/esm/bundler/types.d.ts +10 -1
  131. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  132. package/lib/esm/client/morphoViemExtension.js +2 -1
  133. package/lib/esm/entities/blue/blue.d.ts +817 -360
  134. package/lib/esm/entities/blue/blue.js +461 -704
  135. package/lib/esm/entities/index.d.ts +1 -0
  136. package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
  137. package/lib/esm/entities/vaultV1ReallocationData.d.ts +18 -3
  138. package/lib/esm/entities/vaultV1ReallocationData.js +13 -2
  139. package/lib/esm/entities/vaultV2/vaultV2.js +7 -19
  140. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +7 -10
  141. package/lib/esm/helpers/computeVaultV1Reallocations.js +7 -10
  142. package/lib/esm/helpers/validate.d.ts +16 -23
  143. package/lib/esm/helpers/validate.js +32 -48
  144. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  145. package/lib/esm/helpers/validateRequirementSpender.js +2 -0
  146. package/lib/esm/types/action.d.ts +146 -162
  147. package/lib/esm/types/action.js +28 -2
  148. package/lib/esm/types/client.d.ts +9 -0
  149. package/lib/esm/types/error.d.ts +173 -18
  150. package/lib/esm/types/error.js +216 -21
  151. package/lib/esm/types/sharedLiquidity.d.ts +20 -4
  152. package/lib/esm/types.d.ts +3 -1
  153. package/lib/esm/utils.d.ts +3 -1
  154. package/lib/esm/utils.js +3 -1
  155. package/package.json +7 -6
  156. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  157. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  158. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  159. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  160. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  161. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  162. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  163. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  164. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  165. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  166. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  167. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
@@ -0,0 +1,201 @@
1
+ # Migrating `@morpho-org/morpho-sdk` from v5 to v6
2
+
3
+ Version 6 keeps the Blue entity at `client.morpho.blue(marketParams, chainId)` and preserves its
4
+ write-method names while routing them through five direct BlueBundlesV1 entrypoints. Blue reads and
5
+ versioned reallocation-data helpers remain on the same entity. There is no parallel BlueBundlesV1
6
+ extension or automatic fallback to the v5 route.
7
+
8
+ > **Chain availability.** The direct BlueBundlesV1 route requires the `bundles.blueBundlesV1`
9
+ > deployment on the target chain. On a registered chain without it (the previous Bundler3-routed
10
+ > flows covered more chains), **every** Blue write — `supply`, `supplyCollateral`, `borrow`,
11
+ > `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `withdraw`, and
12
+ > `refinance` — throws `UnknownAddressError` synchronously at handle creation (via
13
+ > `validateWriteCommon`). Confirm coverage before upgrading, for example
14
+ > `getChainAddresses(chainId).bundles?.blueBundlesV1 != null`.
15
+
16
+ ## Update Blue methods
17
+
18
+ | Stable method | v5 input | v6 input |
19
+ | --- | --- | --- |
20
+ | `supply` | `amount`/`nativeAmount`, `marketData`, `slippageTolerance` | Rename gross `amount` to `assets`; remove `marketData` and slippage; add required `deadline` plus optional `referralFeePct` and `referralFeeRecipient`. ERC-20 and native funding are now exclusive. |
21
+ | `withdraw` | `assets` or `shares`, optional `receiver`, `slippageTolerance`, mixed-version `reallocations` | Keep `assets`/`shares`; remove `receiver` and slippage; use only `VaultV2BlueReallocation`; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
22
+ | `supplyCollateral` | `amount` plus optional additive `nativeAmount` | Rename `amount` to `collateralAssets`; make native and ERC-20 funding exclusive; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
23
+ | `borrow` | `amount`, `slippageTolerance`, mixed-version `reallocations` | Rename `amount` to `borrowAssets`; remove slippage; use only `VaultV2BlueReallocation`; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
24
+ | `supplyCollateralBorrow` | `amount`, `borrowAmount`, required `positionData`, `slippageTolerance`, mixed-version `reallocations` | Rename the legs to `collateralAssets` and `borrowAssets`; `positionData` is required only when borrowing; use exclusive native funding and V2-only reallocations; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
25
+ | `repay` | `amount` or `shares`, optional additive `nativeAmount`, `slippageTolerance` | Rename the modes to `repayAssets` or `repayShares`; use `maxUint256` shares for a full close; remove slippage; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. Native funding must cover the full derived cap. |
26
+ | `withdrawCollateral` | `amount` | Rename `amount` to `collateralAssets`; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
27
+ | `repayWithdrawCollateral` | `amount` or `shares`, `withdrawAmount`, optional additive `nativeAmount`, `slippageTolerance` | Rename the repay modes to `repayAssets`/`repayShares` and `withdrawAmount` to `collateralAssets`; remove slippage; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. |
28
+ | `refinance` | `target`, `collateralAmount`, `borrowAssets`/`borrowShares`, `slippageTolerance`, `targetReallocations` | Rename `target` to `destination`; remove partial-leg amounts and share-price inputs; rename V2-only `targetReallocations` to `reallocations`; add `deadline`, `referralFeePct`, and `referralFeeRecipient`. The full live position always moves. |
29
+
30
+ The two combined methods require at least one non-zero leg. See the dedicated **Blue refinance**
31
+ section below for that method's larger shape change.
32
+
33
+ ## Update pure action builder inputs and metadata
34
+
35
+ Direct action consumers keep the root-barrel builder and parameter-type names, but must replace
36
+ their `args` objects as follows. `metadata` is unchanged.
37
+
38
+ | Stable builder / params | v6 `args` fields |
39
+ | --- | --- |
40
+ | `blueSupply` / `BlueSupplyParams` | `userAddress`, `assets`, optional `nativeAmount`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `requirementSignature`. |
41
+ | `blueWithdraw` / `BlueWithdrawParams` | `userAddress`, `withdrawAssets`, `withdrawShares`, optional V2 `reallocations`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `authorizationSignature`. |
42
+ | `blueSupplyCollateral` / `BlueSupplyCollateralParams` | `userAddress`, `collateralAssets`, optional `nativeAmount`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `requirementSignature`. |
43
+ | `blueBorrow` / `BlueBorrowParams` | `userAddress`, `borrowAssets`, `maxLtv`, optional V2 `reallocations`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `authorizationSignature`. |
44
+ | `blueSupplyCollateralBorrow` / `BlueSupplyCollateralBorrowParams` | `userAddress`, `collateralAssets`, `borrowAssets`, `maxLtv`, optional `nativeAmount`/V2 `reallocations`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, `requirementSignature`, and `authorizationSignature`. |
45
+ | `blueRepay` / `BlueRepayParams` | `userAddress`, `repayAssets`, `repayShares`, `maxRepayAssets`, optional `nativeAmount`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `requirementSignature`. |
46
+ | `blueWithdrawCollateral` / `BlueWithdrawCollateralParams` | `userAddress`, `collateralAssets`, `maxLtv`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `authorizationSignature`. |
47
+ | `blueRepayWithdrawCollateral` / `BlueRepayWithdrawCollateralParams` | `userAddress`, `repayAssets`, `repayShares`, `maxRepayAssets`, `collateralAssets`, `maxLtv`, optional `nativeAmount`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, `requirementSignature`, and `authorizationSignature`. |
48
+ | `blueRefinance` / `BlueRefinanceParams` | `userAddress`, `maxLtv`, optional V2 `reallocations`, required `deadline`, optional `referralFeePct`, `referralFeeRecipient`, and `authorizationSignature`; replace `source`/`target` with `market: { chainId, sourceMarketParams, destinationMarketParams }`. |
49
+
50
+ The transaction metadata exports and discriminator strings stay stable; their argument fields change
51
+ as below. The table lists only the delta: unchanged fields are retained and omitted. In particular
52
+ every Blue action keeps its `market` (`Hex` market id) field, so a strict decoder must keep matching
53
+ it alongside the added fields.
54
+
55
+ | Stable action type / discriminator | Removed v5 `action.args` fields | Changed / added v6 `action.args` fields |
56
+ | --- | --- | --- |
57
+ | `BlueSupplyAction` / `"blueSupply"` | `amount`, `maxSharePrice` | `assets`, `onBehalf`, optional `nativeAmount`, `referralFeePct`, `referralFeeRecipient`, `deadline`. |
58
+ | `BlueWithdrawAction` / `"blueWithdraw"` | `assets`, `shares`, `receiver`, `minSharePrice`, `reallocationFee` | `withdrawAssets`, `withdrawShares`, `onBehalf`, `reallocations`, `reallocationPenaltyAssets`, `referralFeePct`, `referralFeeRecipient`, `deadline`. |
59
+ | `BlueSupplyCollateralAction`, `BlueBorrowAction`, `BlueSupplyCollateralBorrowAction` | `amount`, `collateralAmount`, `borrowAmount`, `receiver`, `minSharePrice`, `reallocationFee` | All three use the combined shape: `collateralAssets`, `borrowAssets`, `maxLtv`, `onBehalf`, optional `nativeAmount`, `reallocations`, `reallocationPenaltyAssets`, `referralFeePct`, `referralFeeRecipient`, `deadline`; an inactive simple-method leg is zero. |
60
+ | `BlueRepayAction`, `BlueWithdrawCollateralAction`, `BlueRepayWithdrawCollateralAction` | `amount`, `shares`, `transferAmount`, `withdrawAmount`, `receiver`, `maxSharePrice` | All three use the combined shape: `repayAssets`, `repayShares`, `maxRepayAssets`, `collateralAssets`, `maxLtv`, `onBehalf`, optional `nativeAmount`, `referralFeePct`, `referralFeeRecipient`, `deadline`; inactive simple-method legs are zero. |
61
+ | `BlueRefinanceAction` / `"blueRefinance"` | `targetMarket`, `collateralAmount`, `borrowAssets`, `borrowShares`, borrow/repay share-price bounds, `user`, `reallocationFee` | `sourceMarket`, `destinationMarket`, `maxLtv`, `onBehalf`, `reallocations`, `reallocationPenaltyAssets`, `referralFeePct`, `referralFeeRecipient`, `deadline`. |
62
+
63
+ `RepayAmountArgs` and `RepayActionAmountArgs` are removed. Use the mutually exclusive
64
+ `repayAssets` / `repayShares` fields on the replacement method or builder instead.
65
+
66
+ ## Update write inputs
67
+
68
+ - Remove Blue `slippageTolerance`, `minSharePrice`, and `maxSharePrice` inputs. BlueBundlesV1 does
69
+ not expose the Bundler3 share-price checks. Vault deposit slippage protection is unchanged.
70
+ - Remove Blue `receiver`, `to`, and arbitrary `onBehalf` overrides. BlueBundlesV1 operates on the
71
+ transaction sender and sends proceeds and refunds back to that sender; `userAddress` must be the
72
+ eventual sender used to resolve requirements and position snapshots.
73
+ - Replace PublicAllocator V1 or mixed-version reallocation write inputs with Vault V2
74
+ `VaultV2BlueReallocation` inputs. All Vault V1 reallocation planning, data, input, validation,
75
+ and explicit low-level Bundler3-composition surfaces remain available only as deprecated
76
+ compatibility surfaces and will be removed in the next major; the high-level Blue writes do not
77
+ accept their outputs.
78
+ - Provide the BlueBundlesV1 execution deadline and any optional referral-fee configuration through
79
+ the new typed method inputs. Share-mode repayment deadlines are limited to two hours so the SDK's
80
+ derived `maxRepayAssets` remains sufficient through execution.
81
+ - Treat `supply` assets as gross funding: referral fees reduce assets supplied. Allocator penalties
82
+ and referral fees similarly affect proceeds or destination debt on the other operations.
83
+ - For native funding, the funded token must be the chain's wNative. Native and ERC-20 funding are
84
+ not additive on the direct BlueBundlesV1 call.
85
+
86
+ Borrow, collateral-withdraw, and migration legs retain the SDK's buffered LLTV validation. Pure
87
+ collateral supply and pure repay intentionally disable the onchain LTV cap so they can improve an
88
+ already-unhealthy position.
89
+
90
+ ## Update requirements and transaction handling
91
+
92
+ The lazy workflow is unchanged: await `getRequirements()`, satisfy approval transactions, collect
93
+ signatures, then pass the signatures to synchronous `buildTx(signatures)`.
94
+
95
+ The destinations are different:
96
+
97
+ - Classic ERC-20 approvals and ERC-2612 permits now authorize BlueBundlesV1.
98
+ - Permit2 keeps its ERC-20 approval on canonical Permit2, but the SignatureTransfer payload names
99
+ BlueBundlesV1 as spender. Explicit Permit2 nonces are now required — see the subsection below.
100
+ - Morpho authorization now grants BlueBundlesV1 operator rights instead of GeneralAdapter1.
101
+ - Without signature support, saturated full-repay requirements use the token's reusable maximum
102
+ allowance so a later bounded debt quote remains covered; BlueBundlesV1 still refunds unused
103
+ transaction funding.
104
+ - The built transaction's `to` is BlueBundlesV1, not Bundler3, and calldata contains one fixed
105
+ BlueBundlesV1 entrypoint rather than a `BundlerAction[]` multicall.
106
+
107
+ Update simulations and analytics for the v6 action-field changes. Do not assert
108
+ Bundler3/GeneralAdapter1 destinations or inspect Bundler3 sub-actions for these
109
+ high-level writes.
110
+
111
+ ### Permit2 SignatureTransfer requires an explicit nonce
112
+
113
+ SignatureTransfer consumes an owner-global unordered nonce rather than an allowance, so the SDK no
114
+ longer allocates one implicitly. For a client with `supportSignature: true`, the default supply
115
+ requirement path selects Permit2 and `supply(...).getRequirements()` now throws
116
+ `MissingPermit2TransferFromNonceError` when no nonce is supplied. Pass an unused nonce explicitly:
117
+
118
+ ```ts
119
+ const requirements = await market
120
+ .supply({ userAddress, assets, deadline })
121
+ .getRequirements({ permit2Nonce });
122
+ ```
123
+
124
+ Allocate any `uint256` whose Permit2 `nonceBitmap` bit is still unset for `userAddress` (each nonce
125
+ is single-use; a consumed one throws `Permit2TransferFromNonceAlreadyUsedError`). To skip Permit2
126
+ for ERC-2612 tokens, pass `getRequirements({ useSimplePermit: true })`, which prefers a one-signature
127
+ ERC-2612 permit and needs no nonce.
128
+
129
+ ## Blue refinance
130
+
131
+ The `refinance` entity method and the `blueRefinance` pure builder keep their names but now call
132
+ BlueBundlesV1's full-position migration entrypoint. Both drop partial and collateral-only migration:
133
+ the full live source debt and collateral always move, the source and destination markets must use the
134
+ same loan and collateral tokens and must not be the same market, and Morpho authorization targets
135
+ BlueBundlesV1.
136
+
137
+ `userAddress` must be the account that sends the transaction and, when used, signs the Morpho
138
+ authorization. BlueBundlesV1 migration calldata carries no owner field and always migrates
139
+ `msg.sender`; a supplied authorization signature is likewise bound to that sender. Unlike the v5
140
+ Bundler3 route (where `args.user` was encoded as `onBehalf` in every leg), a relayer can no longer
141
+ migrate a third party's position. Builders cannot enforce that `userAddress` matches the sender; a
142
+ mismatch does not itself revert, and BlueBundlesV1 still migrates `msg.sender`. The SDK uses
143
+ `userAddress` only to validate snapshots, build the authorization requirement, and populate action
144
+ metadata.
145
+
146
+ `market.refinance(...)` (entity method):
147
+
148
+ - Rename `target` to `destination`.
149
+ - Remove `collateralAmount`, `borrowAssets`, `borrowShares`, slippage, and share-price bounds.
150
+ - Rename V2-only `targetReallocations` to `reallocations`.
151
+ - Add `deadline` and optional referral-fee fields.
152
+ - Pass source and destination position snapshots.
153
+
154
+ `blueRefinance(...)` (pure builder):
155
+
156
+ - Replace the top-level `{ source: { chainId, marketParams }, target: { marketParams } }` shape with
157
+ `{ market: { chainId, sourceMarketParams, destinationMarketParams } }`.
158
+ - Rename `args.user` to `args.userAddress` and supply `args.maxLtv` (the buffered destination LTV).
159
+ - Remove `args.collateralAmount`, `args.borrowAssets`, `args.borrowShares`,
160
+ `args.minBorrowSharePrice`, and `args.maxRepaySharePrice`.
161
+ - Rename `args.targetReallocations` to `args.reallocations`.
162
+ - Add `args.deadline` and optional referral-fee fields.
163
+
164
+ The action metadata replaces `targetMarket`, partial-leg amounts, user, share-price bounds, and the
165
+ V1 fee with `destinationMarket`, `maxLtv`, `onBehalf`, a reallocation count and penalty total,
166
+ referral-fee fields, and `deadline`.
167
+
168
+ Stay on v5 if the product requires partial or collateral-only refinance behavior.
169
+
170
+ The partial-migration error classes `BorrowAmountAndSharesExclusiveError`,
171
+ `RefinanceExceedsCollateralError`, `RefinanceExceedsBorrowSharesError`,
172
+ `RefinanceExceedsBorrowAssetsError`, and `RefinanceSharesMissingBorrowAssetsError` are **deprecated,
173
+ not removed**: they stay exported through v6 (marked `@deprecated`) for consumers pattern-matching on
174
+ the v5 surface, are never thrown by the full-position route, and are removed in the next major. The
175
+ full-position route validates snapshot ownership and token/market compatibility, accounts for
176
+ reallocation penalties in destination debt, then checks the combined destination position against
177
+ the buffered LLTV (`BorrowExceedsSafeLtvError`); `RefinanceSameMarketError` and
178
+ `RefinanceTokenMismatchError` stay.
179
+
180
+ ## Removed action-output field: `reallocationFee`
181
+
182
+ `BlueBorrowAction`, `BlueWithdrawAction`, `BlueSupplyCollateralBorrowAction`, and
183
+ `BlueRefinanceAction` no longer expose `reallocationFee` in `action.args`. That field only ever
184
+ carried Vault V1 native PublicAllocator fees, which high-level writes no longer emit. Read
185
+ `reallocationPenaltyAssets` for the loan-token penalty donated by Vault V2 BluePublicAllocator
186
+ reallocations.
187
+
188
+ ## Removed type: `BlueReallocationPlan`
189
+
190
+ The `BlueReallocationPlan` union is removed. High-level Blue write inputs accept
191
+ `Iterable<VaultV2BlueReallocation>` directly; for explicit low-level Vault V1 composition, use
192
+ `VaultV1Reallocation[]`.
193
+
194
+ ## Upgrade checklist
195
+
196
+ - Update every Blue write call using the table above; method names remain stable.
197
+ - Remove Blue slippage and PublicAllocator V1 write inputs.
198
+ - Re-run approval and Morpho-authorization setup against the new spender/operator.
199
+ - Update transaction decoding, simulation fixtures, and action metadata fields; discriminator
200
+ names remain stable.
201
+ - Test native funding, full repay, and full-position migration paths used by the application.
package/README.md CHANGED
@@ -15,36 +15,40 @@ Build transactions for Morpho's **VaultV1** (MetaMorpho), **VaultV2**, **Blue**,
15
15
  pnpm add @morpho-org/morpho-sdk
16
16
  ```
17
17
 
18
+ Upgrading from v5? Read the [v5 → v6 migration guide](./MIGRATION-v5-to-v6.md) before updating Blue
19
+ write integrations.
20
+
18
21
  ## Actions
19
22
 
20
- Each entity exposes a set of actions. Bundled actions route through bundler3 (via `GeneralAdapter1`); the rest are direct contract calls.
23
+ Each entity exposes a set of actions. Vault deposits route through Bundler3 via `GeneralAdapter1`;
24
+ Blue writes call BlueBundlesV1 directly; the remaining rows identify their direct destination.
21
25
 
22
26
  | Entity | Actions | Route |
23
27
  | --- | --- | --- |
24
- | **VaultV1** (MetaMorpho) | `deposit`, `migrateToV2` | Bundler |
28
+ | **VaultV1** (MetaMorpho) | `deposit`, `migrateToV2` | Bundler3 → GeneralAdapter1 |
25
29
  | | `withdraw`, `redeem` | Direct call |
26
30
  | | `inKindRedeem` | VaultExitBundlesV1 |
27
- | **VaultV2** | `deposit` | Bundler |
31
+ | **VaultV2** | `deposit` | Bundler3 → GeneralAdapter1 |
28
32
  | | `withdraw`, `redeem` | Direct call |
29
33
  | | `forceWithdraw`, `forceRedeem` | Vault multicall |
30
34
  | | `inKindRedeem` | VaultExitBundlesV1 |
31
- | **Blue** | `supply`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdraw`, `repayWithdrawCollateral`, `refinance` | Bundler |
32
- | | `withdrawCollateral` | Direct call |
35
+ | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
33
36
  | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `repayWithdrawCollateral` | Midnight Bundles |
34
37
  | | `makeLend`, `makeBorrow` | Midnight mempool |
35
38
  | | `supplyCollateral`, `redeem`, `cancelOffer` | Direct call |
36
39
 
37
- `VaultExitBundlesV1` is registered on Ethereum, Base, Arbitrum, Optimism, Polygon, World Chain,
38
- Unichain, HyperEVM, Katana, Monad, Stable, Tempo, and Robinhood Chain. Custom deployments can still
39
- be configured with `registerCustomAddresses`.
40
+ `VaultExitBundlesV1`, `VaultBundlesV1`, and `BlueBundlesV1` are registered on Ethereum, Base,
41
+ Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo, and
42
+ Robinhood Chain. Custom deployments can still be configured with `registerCustomAddresses`.
40
43
 
41
44
  ## How it works
42
45
 
43
- Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. Vault
46
+ Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. All Blue
47
+ writes use this lazy shape while still encoding one direct BlueBundlesV1 call. Vault
44
48
  `inKindRedeem` uses this shape so callers can await `getRequirements()` to check live Blue liquidity
45
49
  and share authorization before invoking `buildTx()`. Calling `buildTx()` directly skips those
46
50
  RPC-backed pre-flight checks. Other direct calls — vault `withdraw` / `redeem`, `forceWithdraw` /
47
- `forceRedeem`, and Blue `withdrawCollateral` — have no prerequisites and return only `{ buildTx }`.
51
+ `forceRedeem` — have no prerequisites and return only `{ buildTx }`.
48
52
 
49
53
  - **`getRequirements()`** — async; the on-chain prerequisites to satisfy first: ERC-20 approvals, permit / Permit2 signatures, Morpho authorization, or (for Midnight) operator authorization and offer-root signatures.
50
54
  - **`buildTx(signatures?)`** — synchronous; the final, deep-frozen viem transaction. Pass any signatures collected from the requirements.
@@ -61,7 +65,10 @@ Enable off-chain approvals (permit / Permit2) with `morphoViemExtension({ suppor
61
65
 
62
66
  ### `userAddress` must be the signer
63
67
 
64
- `userAddress` must be the account that signs and sends the transaction. Builders don't enforce this, but the signature helpers do — `sign()` throws `AddressMismatchError` when the wallet's account differs. It matters most for `repayWithdrawCollateral`; see [BUNDLER3.md](./BUNDLER3.md#other-pitfalls).
68
+ `userAddress` must be the account that signs and sends the transaction. Builders don't enforce
69
+ this, but the signature helpers do — `sign()` throws `AddressMismatchError` when the wallet's
70
+ account differs. BlueBundlesV1 always operates on `msg.sender`, so a Blue transaction must be sent
71
+ by that same account.
65
72
 
66
73
  ## Usage
67
74
 
@@ -119,7 +126,7 @@ const tx = buildTx();
119
126
 
120
127
  For wNative vaults, pass `nativeAmount` instead of `amount` to deposit native ETH (wrapped automatically).
121
128
 
122
- ### Blue: supply collateral & borrow
129
+ ### Blue: BlueBundlesV1 writes
123
130
 
124
131
  ```typescript
125
132
  const market = client.morpho.blue(
@@ -133,18 +140,15 @@ const market = client.morpho.blue(
133
140
  1,
134
141
  );
135
142
 
136
- const positionData = await market.getPositionData("0xUser...");
137
-
138
143
  const { buildTx, getRequirements } = market.supplyCollateralBorrow({
139
- amount: 1000000000000000000n, // collateral
140
- borrowAmount: 500000000000000000n, // loan asset
141
144
  userAddress: "0xUser...",
142
- positionData,
145
+ collateralAssets: 1_000_000n,
146
+ borrowAssets: 0n,
147
+ deadline: 1_900_000_000n,
143
148
  });
144
149
 
145
- // This flow can return more than one requirement — a collateral approval/permit
146
- // and a one-time Morpho authorization for GeneralAdapter1. Satisfy each and pass
147
- // every collected signature to buildTx.
150
+ // Satisfy each BlueBundlesV1 approval or signature requirement, then pass every
151
+ // collected signature to buildTx.
148
152
  const signatures = [];
149
153
  for (const requirement of await getRequirements()) {
150
154
  if (isRequirementSignature(requirement)) {
@@ -157,7 +161,19 @@ for (const requirement of await getRequirements()) {
157
161
  const tx = buildTx(signatures);
158
162
  ```
159
163
 
160
- The LLTV buffer guards against instant liquidation.
164
+ Set `borrowAssets` to a non-zero amount and provide `positionData` to combine collateral supply and
165
+ borrowing. That path may also require Morpho authorization for BlueBundlesV1. Optional
166
+ `reallocations` are Vault V2 only, and the LLTV buffer guards the resulting position against
167
+ instant liquidation. Blue writes do not accept `slippageTolerance`, `minSharePrice`, or
168
+ `maxSharePrice` because BlueBundlesV1 has no share-price-bound inputs.
169
+
170
+ > High-level Blue writes accept only `VaultV2BlueReallocation`. Vault V1 planning and explicit
171
+ > low-level Bundler3 composition remain available only as deprecated compatibility surfaces and
172
+ > will be removed in the next major.
173
+
174
+ > All SDK surfaces for the Vault V1 shared-liquidity algorithm and its PublicAllocator Bundler3
175
+ > composition are deprecated and will be removed in the next major. Use Vault V2
176
+ > BluePublicAllocator reallocations.
161
177
 
162
178
  ### Midnight: take a fixed-rate offer
163
179
 
@@ -180,7 +196,9 @@ const requirements = await output.getRequirements();
180
196
  const tx = output.buildTx();
181
197
  ```
182
198
 
183
- See the [documentation](https://docs.morpho.org/developers/sdks/morpho-sdk/) for the full API: native wrapping, PublicAllocator reallocations, V1 → V2 migration, refinance, force withdraw/redeem, and Midnight maker flows.
199
+ See the [documentation](https://docs.morpho.org/developers/sdks/morpho-sdk/) for the full API:
200
+ native wrapping, Vault V2 BluePublicAllocator reallocations, borrow-position migration, vault V1 →
201
+ V2 migration, force withdraw/redeem, and Midnight maker flows.
184
202
 
185
203
  ## Architecture
186
204
 
@@ -227,22 +245,27 @@ graph LR
227
245
 
228
246
  subgraph Blue Flow
229
247
  MM1[MorphoBlue]
230
- MM1 --> M1S[blueSupply]
231
- MM1 --> M1SC[blueSupplyCollateral]
232
- MM1 --> M1B[blueBorrow]
233
- MM1 --> M1SCB[blueSupplyCollateralBorrow]
234
- MM1 --> M1W[blueWithdraw]
235
- MM1 --> M1RF[blueRefinance]
236
-
237
- M1S -->|nativeWrap? + erc20TransferFrom + morphoSupply| B3[Bundler3]
238
- M1SC -->|erc20TransferFrom + morphoSupplyCollateral| B3
239
- M1B -->|allocator reallocation? + morphoBorrow| B3
240
- M1SCB -->|transfer + supplyCollateral + allocator reallocation? + borrow| B3
241
- M1W -->|allocator reallocation? + morphoWithdraw| B3
242
- M1RF -->|allocator reallocation? + supplyCollateral callback: borrow + repay + withdrawCollateral| B3
243
-
244
- B3 -.->|reallocateTo| PA1[PublicAllocator V1]
245
- B3 -.->|reallocate / allocateFromIdle| BPA[Blue Public Allocator]
248
+ MM1 --> M1S[supply]
249
+ MM1 --> M1SC[supplyCollateral]
250
+ MM1 --> M1B[borrow]
251
+ MM1 --> M1SCB[supplyCollateralBorrow]
252
+ MM1 --> M1R[repay]
253
+ MM1 --> M1WC[withdrawCollateral]
254
+ MM1 --> M1RW[repayWithdrawCollateral]
255
+ MM1 --> M1W[withdraw]
256
+ MM1 --> M1M[refinance]
257
+
258
+ M1S --> BBV1[BlueBundlesV1]
259
+ M1SC --> BBV1
260
+ M1B --> BBV1
261
+ M1SCB --> BBV1
262
+ M1R --> BBV1
263
+ M1WC --> BBV1
264
+ M1RW --> BBV1
265
+ M1W --> BBV1
266
+ M1M --> BBV1
267
+
268
+ BBV1 -.->|reallocate / allocateFromIdle| BPA[Blue Public Allocator]
246
269
  end
247
270
 
248
271
  subgraph Midnight Flow
@@ -267,11 +290,10 @@ graph LR
267
290
 
268
291
  style B1 fill:#e8f5e9,stroke:#4caf50
269
292
  style B2 fill:#e8f5e9,stroke:#4caf50
270
- style B3 fill:#e8f5e9,stroke:#4caf50
293
+ style BBV1 fill:#e8f5e9,stroke:#4caf50
271
294
  style MM fill:#fff3e0,stroke:#ff9800
272
295
  style V2C fill:#e3f2fd,stroke:#2196f3
273
296
  style REQ fill:#f3e5f5,stroke:#9c27b0
274
- style PA1 fill:#fff9c4,stroke:#f9a825
275
297
  style BPA fill:#fff9c4,stroke:#f9a825
276
298
  ```
277
299