@morpho-org/morpho-sdk 5.9.0 → 6.0.0-next.1

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 (243) hide show
  1. package/MIGRATION-v5-to-v6.md +404 -0
  2. package/README.md +127 -69
  3. package/lib/cjs/abis.d.ts +210 -0
  4. package/lib/cjs/abis.js +142 -2
  5. package/lib/cjs/actions/blue/borrow.d.ts +62 -61
  6. package/lib/cjs/actions/blue/borrow.js +48 -80
  7. package/lib/cjs/actions/blue/common.d.ts +86 -0
  8. package/lib/cjs/actions/blue/common.js +205 -0
  9. package/lib/cjs/actions/blue/refinance.d.ts +72 -112
  10. package/lib/cjs/actions/blue/refinance.js +97 -199
  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 -90
  20. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
  21. package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
  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/bundles/common.d.ts +200 -0
  26. package/lib/cjs/actions/bundles/common.js +469 -0
  27. package/lib/cjs/actions/bundles/index.d.ts +3 -0
  28. package/lib/cjs/actions/bundles/index.js +23 -0
  29. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  30. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
  31. package/lib/cjs/actions/index.d.ts +2 -1
  32. package/lib/cjs/actions/index.js +1 -0
  33. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  34. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  35. package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
  36. package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
  37. package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
  38. package/lib/cjs/actions/midnight/takeLend.js +2 -2
  39. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  40. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
  41. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  42. package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
  43. package/lib/cjs/actions/requirements/blue/index.d.ts +1 -0
  44. package/lib/cjs/actions/requirements/blue/index.js +1 -0
  45. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  46. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
  47. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  48. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +8 -2
  49. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  50. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -6
  51. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  52. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +123 -0
  53. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  54. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  55. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  56. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  57. package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  58. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +6 -4
  59. package/lib/cjs/actions/requirements/getRequirementsApproval.js +6 -4
  60. package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  61. package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
  62. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  63. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +18 -66
  64. package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
  65. package/lib/cjs/actions/vaultV1/deposit.js +110 -109
  66. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
  67. package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
  68. package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
  69. package/lib/cjs/actions/vaultV1/redeem.js +56 -33
  70. package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
  71. package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
  72. package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
  73. package/lib/cjs/actions/vaultV2/deposit.js +111 -109
  74. package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
  75. package/lib/cjs/actions/vaultV2/redeem.js +56 -34
  76. package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
  77. package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
  78. package/lib/cjs/bundler/actions.d.ts +4 -4
  79. package/lib/cjs/bundler/actions.js +4 -4
  80. package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
  81. package/lib/cjs/client/morphoViemExtension.js +2 -1
  82. package/lib/cjs/entities/blue/blue.d.ts +806 -374
  83. package/lib/cjs/entities/blue/blue.js +449 -696
  84. package/lib/cjs/entities/index.d.ts +2 -0
  85. package/lib/cjs/entities/index.js +15 -0
  86. package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
  87. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  88. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +203 -0
  89. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  90. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
  91. package/lib/cjs/entities/requirements/index.d.ts +1 -0
  92. package/lib/cjs/entities/requirements/index.js +17 -0
  93. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +348 -98
  94. package/lib/cjs/entities/vaultV1/vaultV1.js +322 -120
  95. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +221 -68
  96. package/lib/cjs/entities/vaultV2/vaultV2.js +219 -77
  97. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
  98. package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
  99. package/lib/cjs/helpers/index.d.ts +2 -1
  100. package/lib/cjs/helpers/index.js +5 -1
  101. package/lib/cjs/helpers/referralFee.d.ts +21 -0
  102. package/lib/cjs/helpers/referralFee.js +35 -0
  103. package/lib/cjs/helpers/slippage.d.ts +90 -1
  104. package/lib/cjs/helpers/slippage.js +123 -0
  105. package/lib/cjs/helpers/validate.d.ts +16 -23
  106. package/lib/cjs/helpers/validate.js +41 -48
  107. package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
  108. package/lib/cjs/helpers/validateRequirementSpender.js +3 -0
  109. package/lib/cjs/index.d.ts +1 -0
  110. package/lib/cjs/index.js +1 -0
  111. package/lib/cjs/types/action.d.ts +303 -210
  112. package/lib/cjs/types/action.js +29 -2
  113. package/lib/cjs/types/client.d.ts +9 -0
  114. package/lib/cjs/types/error.d.ts +193 -18
  115. package/lib/cjs/types/error.js +267 -24
  116. package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
  117. package/lib/esm/abis.d.ts +210 -0
  118. package/lib/esm/abis.js +140 -0
  119. package/lib/esm/actions/blue/borrow.d.ts +62 -61
  120. package/lib/esm/actions/blue/borrow.js +48 -80
  121. package/lib/esm/actions/blue/common.d.ts +86 -0
  122. package/lib/esm/actions/blue/common.js +193 -0
  123. package/lib/esm/actions/blue/refinance.d.ts +72 -112
  124. package/lib/esm/actions/blue/refinance.js +98 -200
  125. package/lib/esm/actions/blue/repay.d.ts +72 -68
  126. package/lib/esm/actions/blue/repay.js +56 -118
  127. package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
  128. package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
  129. package/lib/esm/actions/blue/supply.d.ts +62 -45
  130. package/lib/esm/actions/blue/supply.js +94 -70
  131. package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
  132. package/lib/esm/actions/blue/supplyCollateral.js +52 -69
  133. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
  134. package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
  135. package/lib/esm/actions/blue/withdraw.d.ts +68 -79
  136. package/lib/esm/actions/blue/withdraw.js +100 -96
  137. package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
  138. package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
  139. package/lib/esm/actions/bundles/common.d.ts +200 -0
  140. package/lib/esm/actions/bundles/common.js +457 -0
  141. package/lib/esm/actions/bundles/index.d.ts +3 -0
  142. package/lib/esm/actions/bundles/index.js +2 -0
  143. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
  144. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
  145. package/lib/esm/actions/index.d.ts +2 -1
  146. package/lib/esm/actions/index.js +1 -0
  147. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
  148. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
  149. package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
  150. package/lib/esm/actions/midnight/takeBorrow.js +2 -2
  151. package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
  152. package/lib/esm/actions/midnight/takeLend.js +2 -2
  153. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
  154. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
  155. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
  156. package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
  157. package/lib/esm/actions/requirements/blue/index.d.ts +1 -0
  158. package/lib/esm/actions/requirements/blue/index.js +1 -0
  159. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
  160. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
  161. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
  162. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -3
  163. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
  164. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -7
  165. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +61 -0
  166. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +119 -0
  167. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +4 -4
  168. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -5
  169. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  170. package/lib/esm/actions/requirements/encode/index.js +1 -0
  171. package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
  172. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +6 -4
  173. package/lib/esm/actions/requirements/getRequirementsApproval.js +6 -4
  174. package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
  175. package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
  176. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +22 -30
  177. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +19 -67
  178. package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
  179. package/lib/esm/actions/vaultV1/deposit.js +112 -111
  180. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
  181. package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
  182. package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
  183. package/lib/esm/actions/vaultV1/redeem.js +56 -33
  184. package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
  185. package/lib/esm/actions/vaultV1/withdraw.js +86 -34
  186. package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
  187. package/lib/esm/actions/vaultV2/deposit.js +113 -111
  188. package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
  189. package/lib/esm/actions/vaultV2/redeem.js +56 -34
  190. package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
  191. package/lib/esm/actions/vaultV2/withdraw.js +86 -35
  192. package/lib/esm/bundler/actions.d.ts +4 -4
  193. package/lib/esm/bundler/actions.js +4 -4
  194. package/lib/esm/client/morphoViemExtension.d.ts +2 -1
  195. package/lib/esm/client/morphoViemExtension.js +2 -1
  196. package/lib/esm/entities/blue/blue.d.ts +806 -374
  197. package/lib/esm/entities/blue/blue.js +455 -702
  198. package/lib/esm/entities/index.d.ts +2 -0
  199. package/lib/esm/entities/index.js +1 -0
  200. package/lib/esm/entities/midnight/midnight.d.ts +2 -2
  201. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +87 -0
  202. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +199 -0
  203. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
  204. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
  205. package/lib/esm/entities/requirements/index.d.ts +1 -0
  206. package/lib/esm/entities/requirements/index.js +1 -0
  207. package/lib/esm/entities/vaultV1/vaultV1.d.ts +348 -98
  208. package/lib/esm/entities/vaultV1/vaultV1.js +326 -124
  209. package/lib/esm/entities/vaultV2/vaultV2.d.ts +221 -68
  210. package/lib/esm/entities/vaultV2/vaultV2.js +222 -80
  211. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
  212. package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
  213. package/lib/esm/helpers/index.d.ts +2 -1
  214. package/lib/esm/helpers/index.js +2 -1
  215. package/lib/esm/helpers/referralFee.d.ts +21 -0
  216. package/lib/esm/helpers/referralFee.js +31 -0
  217. package/lib/esm/helpers/slippage.d.ts +90 -1
  218. package/lib/esm/helpers/slippage.js +122 -2
  219. package/lib/esm/helpers/validate.d.ts +16 -23
  220. package/lib/esm/helpers/validate.js +40 -48
  221. package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
  222. package/lib/esm/helpers/validateRequirementSpender.js +3 -0
  223. package/lib/esm/index.d.ts +1 -0
  224. package/lib/esm/index.js +1 -0
  225. package/lib/esm/types/action.d.ts +303 -210
  226. package/lib/esm/types/action.js +28 -2
  227. package/lib/esm/types/client.d.ts +9 -0
  228. package/lib/esm/types/error.d.ts +193 -18
  229. package/lib/esm/types/error.js +252 -21
  230. package/lib/esm/types/sharedLiquidity.d.ts +0 -7
  231. package/package.json +6 -5
  232. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
  233. package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
  234. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
  235. package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
  236. package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
  237. package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
  238. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
  239. package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
  240. package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
  241. package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
  242. package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
  243. package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  > 📖 **Full documentation → [docs.morpho.org/developers/sdks/morpho-sdk](https://docs.morpho.org/developers/sdks/morpho-sdk/)**
9
9
 
10
- Build transactions for Morpho's **VaultV1** (MetaMorpho), **VaultV2**, **Blue**, and **Midnight** fixed-rate markets on every chain where Morpho is deployed. Custom deployments can be added with `registerCustomAddresses` from `@morpho-org/morpho-sdk/addresses`.
10
+ Build transactions for Morpho's **VaultV1** (MetaMorpho), **VaultV2**, **Blue**, and **Midnight** fixed-rate markets on chains with the required protocol and periphery deployments. Custom deployments can be added with `registerCustomAddresses` from `@morpho-org/morpho-sdk/addresses`.
11
11
 
12
12
  ## Installation
13
13
 
@@ -15,42 +15,44 @@ 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 vault
19
+ deposit or Blue 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. Common vault writes call VaultBundlesV1, Blue writes call
24
+ BlueBundlesV1, and the remaining rows identify their destination.
21
25
 
22
26
  | Entity | Actions | Route |
23
27
  | --- | --- | --- |
24
- | **VaultV1** (MetaMorpho) | `deposit`, `migrateToV2` | Bundler |
25
- | | `withdraw`, `redeem` | Direct call |
28
+ | **VaultV1** (MetaMorpho) | `deposit`, `withdraw`, `redeem`, `migrateToV2` | VaultBundlesV1 |
26
29
  | | `inKindRedeem` | VaultExitBundlesV1 |
27
- | **VaultV2** | `deposit` | Bundler |
28
- | | `withdraw`, `redeem` | Direct call |
30
+ | **VaultV2** | `deposit`, `withdraw`, `redeem` | VaultBundlesV1 |
29
31
  | | `forceWithdraw`, `forceRedeem` | Vault multicall |
30
32
  | | `inKindRedeem` | VaultExitBundlesV1 |
31
- | **Blue** | `supply`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdraw`, `repayWithdrawCollateral`, `refinance` | Bundler |
32
- | | `withdrawCollateral` | Direct call |
33
+ | **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
33
34
  | **Midnight** | `takeLend`, `takeBorrow`, `supplyCollateralTakeBorrow`, `repayWithdrawCollateral` | Midnight Bundles |
34
35
  | | `makeLend`, `makeBorrow` | Midnight mempool |
35
36
  | | `supplyCollateral`, `redeem`, `cancelOffer` | Direct call |
36
37
 
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`.
38
+ `VaultExitBundlesV1`, `VaultBundlesV1`, and `BlueBundlesV1` are registered on Ethereum, Base,
39
+ Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo, and
40
+ Robinhood Chain. Custom deployments can still be configured with `registerCustomAddresses`.
40
41
 
41
42
  ## How it works
42
43
 
43
- Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. Vault
44
- `inKindRedeem` uses this shape so callers can await `getRequirements()` to check live Blue liquidity
45
- and share authorization before invoking `buildTx()`. Calling `buildTx()` directly skips those
46
- RPC-backed pre-flight checks. Other direct calls — vault `withdraw` / `redeem`, `forceWithdraw` /
47
- `forceRedeem`, and Blue `withdrawCollateral` — have no prerequisites and return only `{ buildTx }`.
44
+ Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. All Blue
45
+ writes use this lazy shape while still encoding one direct BlueBundlesV1 call. Vault deposits and
46
+ exits use the same shape for token or exact share authorization. Vault `inKindRedeem` additionally
47
+ checks live Blue liquidity. Calling `buildTx()` directly skips RPC-backed pre-flight checks.
48
+ `forceWithdraw` and `forceRedeem` remain direct Vault V2 multicalls without prerequisites.
48
49
 
49
50
  - **`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
51
  - **`buildTx(signatures?)`** — synchronous; the final, deep-frozen viem transaction. Pass any signatures collected from the requirements.
51
52
 
52
53
  ```typescript
53
- const { buildTx, getRequirements } = await vault.deposit({ amount, userAddress });
54
+ const vaultData = await vault.getData();
55
+ const { buildTx, getRequirements } = vault.deposit({ amount, userAddress, vaultData });
54
56
 
55
57
  const requirements = await getRequirements();
56
58
  // Send each approval tx and collect each signature, then:
@@ -59,9 +61,12 @@ const tx = buildTx([permitSignature]);
59
61
 
60
62
  Enable off-chain approvals (permit / Permit2) with `morphoViemExtension({ supportSignature: true })`.
61
63
 
62
- ### `userAddress` must be the signer
64
+ ### `userAddress` is the eventual submitter
63
65
 
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).
66
+ `userAddress` must be the account that eventually signs and sends the transaction. A connected
67
+ builder account may prepare a direct bundles call for a different submitter; signature helpers
68
+ enforce the expected identity at `sign()`. VaultBundlesV1 and BlueBundlesV1 always operate on
69
+ `msg.sender`.
65
70
 
66
71
  ## Usage
67
72
 
@@ -94,32 +99,75 @@ Create an entity — every factory takes a chain ID as its last argument:
94
99
 
95
100
  ### Vault deposit / withdraw
96
101
 
97
- Deposit routes through the bundler and may require an approval or permit:
102
+ Deposit calls VaultBundlesV1 and may require an approval or permit. ERC-20 approvals and ERC-2612
103
+ permits authorize VaultBundlesV1. Permit2 SignatureTransfer also names VaultBundlesV1 as spender,
104
+ while the ERC-20 approval prerequisite targets canonical Permit2.
98
105
 
99
106
  ```typescript
100
107
  const vault = client.morpho.vaultV2("0xVault...", 1);
101
-
102
- const { buildTx, getRequirements } = await vault.deposit({
108
+ const vaultData = await vault.getData();
109
+ const { buildTx, getRequirements } = vault.deposit({
103
110
  amount: 1000000000000000000n,
104
111
  userAddress: "0xUser...",
112
+ vaultData,
105
113
  });
106
114
  const requirements = await getRequirements();
107
115
  const tx = buildTx([permitSignature]);
108
116
  ```
109
117
 
110
- Withdraw is a direct vault call with no requirements:
118
+ Withdraw is a VaultBundlesV1 call that burns the caller's shares, so it needs the exact share
119
+ allowance returned by `getRequirements()`:
111
120
 
112
121
  ```typescript
113
- const { buildTx } = vault.withdraw({
114
- amount: 500000000000000000n,
115
- userAddress: "0xUser...",
116
- });
117
- const tx = buildTx();
122
+ import { morphoViemExtension } from "@morpho-org/morpho-sdk";
123
+ import {
124
+ createPublicClient,
125
+ createWalletClient,
126
+ custom,
127
+ http,
128
+ type EIP1193Provider,
129
+ } from "viem";
130
+ import { mainnet } from "viem/chains";
131
+
132
+ async function withdrawUsdc(provider: EIP1193Provider, supportSignature = false) {
133
+ const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
134
+ morphoViemExtension({ supportSignature }),
135
+ );
136
+ const walletClient = createWalletClient({ chain: mainnet, transport: custom(provider) });
137
+ const [userAddress] = await walletClient.requestAddresses();
138
+ if (!userAddress) throw new Error("Connect a wallet account before withdrawing.");
139
+ const vault = client.morpho.vaultV2("0x04422053aDDbc9bB2759b248B574e3FCA76Bc145", mainnet.id);
140
+ const withdrawal = vault.withdraw({ amount: 500_000n, userAddress });
141
+ const requirements = await withdrawal.getRequirements();
142
+ const requirement = requirements[0];
143
+
144
+ if (requirement && "sign" in requirement) {
145
+ // With signature support enabled, sign the vault-share permit for this handle.
146
+ const signedPermit = await requirement.sign(walletClient, userAddress);
147
+ return walletClient.sendTransaction({
148
+ ...withdrawal.buildTx([signedPermit]),
149
+ account: userAddress,
150
+ });
151
+ }
152
+
153
+ for (const approval of requirements) {
154
+ if ("to" in approval) {
155
+ const hash = await walletClient.sendTransaction({ ...approval, account: userAddress });
156
+ const receipt = await client.waitForTransactionReceipt({ hash });
157
+ if (receipt.status !== "success") throw new Error("The share approval reverted.");
158
+ }
159
+ }
160
+ // Approval is confirmed, or the exact allowance was already in place.
161
+ return walletClient.sendTransaction({ ...withdrawal.buildTx(), account: userAddress });
162
+ }
163
+ // await withdrawUsdc(provider) returns the withdrawal transaction hash.
164
+ // Pass true as the second argument to use a signed share permit instead of an approval.
118
165
  ```
119
166
 
120
- For wNative vaults, pass `nativeAmount` instead of `amount` to deposit native ETH (wrapped automatically).
167
+ For wNative vaults, pass `nativeAmount` instead of `amount`. The transaction sends that amount as
168
+ `tx.value` to VaultBundlesV1, which wraps it internally; native deposits require no token permit.
121
169
 
122
- ### Blue: supply collateral & borrow
170
+ ### Blue: BlueBundlesV1 writes
123
171
 
124
172
  ```typescript
125
173
  const market = client.morpho.blue(
@@ -133,18 +181,15 @@ const market = client.morpho.blue(
133
181
  1,
134
182
  );
135
183
 
136
- const positionData = await market.getPositionData("0xUser...");
137
-
138
184
  const { buildTx, getRequirements } = market.supplyCollateralBorrow({
139
- amount: 1000000000000000000n, // collateral
140
- borrowAmount: 500000000000000000n, // loan asset
141
185
  userAddress: "0xUser...",
142
- positionData,
186
+ collateralAssets: 1_000_000n,
187
+ borrowAssets: 0n,
188
+ deadline: 1_900_000_000n,
143
189
  });
144
190
 
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.
191
+ // Satisfy each BlueBundlesV1 approval or signature requirement, then pass every
192
+ // collected signature to buildTx.
148
193
  const signatures = [];
149
194
  for (const requirement of await getRequirements()) {
150
195
  if (isRequirementSignature(requirement)) {
@@ -157,7 +202,15 @@ for (const requirement of await getRequirements()) {
157
202
  const tx = buildTx(signatures);
158
203
  ```
159
204
 
160
- The LLTV buffer guards against instant liquidation.
205
+ Set `borrowAssets` to a non-zero amount and provide `positionData` to combine collateral supply and
206
+ borrowing. That path may also require Morpho authorization for BlueBundlesV1. Optional
207
+ `reallocations` are Vault V2 only, and the LLTV buffer guards the resulting position against
208
+ instant liquidation. Blue writes do not accept `slippageTolerance`, `minSharePrice`, or
209
+ `maxSharePrice` because BlueBundlesV1 has no share-price-bound inputs.
210
+
211
+ > High-level Blue writes accept only `VaultV2BlueReallocation`. Vault V1 planning and explicit
212
+ > low-level Bundler3 composition remain available only as deprecated compatibility surfaces and
213
+ > will be removed in the next major.
161
214
 
162
215
  > All SDK surfaces for the Vault V1 shared-liquidity algorithm and its PublicAllocator Bundler3
163
216
  > composition are deprecated and will be removed in the next major. Use Vault V2
@@ -184,7 +237,9 @@ const requirements = await output.getRequirements();
184
237
  const tx = output.buildTx();
185
238
  ```
186
239
 
187
- 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.
240
+ See the [documentation](https://docs.morpho.org/developers/sdks/morpho-sdk/) for the full API:
241
+ native wrapping, Vault V2 BluePublicAllocator reallocations, borrow-position migration, vault V1 →
242
+ V2 migration, force withdraw/redeem, and Midnight maker flows.
188
243
 
189
244
  ## Architecture
190
245
 
@@ -205,11 +260,11 @@ graph LR
205
260
  MV1 --> V1IKR[vaultV1InKindRedeem]
206
261
  MV1 --> V1M[vaultV1MigrateToV2]
207
262
 
208
- V1D -->|nativeTransfer + wrapNative + erc4626Deposit| B1[Bundler3]
209
- V1W -->|direct call| MM[MetaMorpho]
210
- V1R -->|direct call| MM
263
+ V1D --> VBV1[VaultBundlesV1]
264
+ V1W --> VBV1
265
+ V1R --> VBV1
266
+ V1M --> VBV1
211
267
  V1IKR -->|direct call| VEB[VaultExitBundlesV1]
212
- V1M -->|erc20TransferFrom + erc4626Redeem + erc4626Deposit| B1
213
268
  end
214
269
 
215
270
  subgraph VaultV2 Flow
@@ -221,32 +276,37 @@ graph LR
221
276
  MV2 --> V2FW[vaultV2ForceWithdraw]
222
277
  MV2 --> V2FR[vaultV2ForceRedeem]
223
278
 
224
- V2D -->|nativeTransfer + wrapNative + erc4626Deposit| B2[Bundler3]
225
- V2W -->|direct call| V2C[VaultV2 Contract]
226
- V2R -->|direct call| V2C
279
+ V2D --> VBV1
280
+ V2W --> VBV1
281
+ V2R --> VBV1
227
282
  V2IKR -->|direct call| VEB
228
- V2FW -->|multicall| V2C
283
+ V2FW -->|multicall| V2C[VaultV2 Contract]
229
284
  V2FR -->|multicall| V2C
230
285
  end
231
286
 
232
287
  subgraph Blue Flow
233
288
  MM1[MorphoBlue]
234
- MM1 --> M1S[blueSupply]
235
- MM1 --> M1SC[blueSupplyCollateral]
236
- MM1 --> M1B[blueBorrow]
237
- MM1 --> M1SCB[blueSupplyCollateralBorrow]
238
- MM1 --> M1W[blueWithdraw]
239
- MM1 --> M1RF[blueRefinance]
240
-
241
- M1S -->|nativeWrap? + erc20TransferFrom + morphoSupply| B3[Bundler3]
242
- M1SC -->|erc20TransferFrom + morphoSupplyCollateral| B3
243
- M1B -->|allocator reallocation? + morphoBorrow| B3
244
- M1SCB -->|transfer + supplyCollateral + allocator reallocation? + borrow| B3
245
- M1W -->|allocator reallocation? + morphoWithdraw| B3
246
- M1RF -->|allocator reallocation? + supplyCollateral callback: borrow + repay + withdrawCollateral| B3
247
-
248
- B3 -.->|reallocateTo| PA1[PublicAllocator V1]
249
- B3 -.->|reallocate / allocateFromIdle| BPA[Blue Public Allocator]
289
+ MM1 --> M1S[supply]
290
+ MM1 --> M1SC[supplyCollateral]
291
+ MM1 --> M1B[borrow]
292
+ MM1 --> M1SCB[supplyCollateralBorrow]
293
+ MM1 --> M1R[repay]
294
+ MM1 --> M1WC[withdrawCollateral]
295
+ MM1 --> M1RW[repayWithdrawCollateral]
296
+ MM1 --> M1W[withdraw]
297
+ MM1 --> M1M[refinance]
298
+
299
+ M1S --> BBV1[BlueBundlesV1]
300
+ M1SC --> BBV1
301
+ M1B --> BBV1
302
+ M1SCB --> BBV1
303
+ M1R --> BBV1
304
+ M1WC --> BBV1
305
+ M1RW --> BBV1
306
+ M1W --> BBV1
307
+ M1M --> BBV1
308
+
309
+ BBV1 -.->|reallocate / allocateFromIdle| BPA[Blue Public Allocator]
250
310
  end
251
311
 
252
312
  subgraph Midnight Flow
@@ -269,13 +329,11 @@ graph LR
269
329
  MM1 -.->|approval / permit / authorization| REQ
270
330
  MN1 -.->|approval / authorization / root signature or ratification| REQ
271
331
 
272
- style B1 fill:#e8f5e9,stroke:#4caf50
273
- style B2 fill:#e8f5e9,stroke:#4caf50
274
- style B3 fill:#e8f5e9,stroke:#4caf50
275
- style MM fill:#fff3e0,stroke:#ff9800
332
+ style VBV1 fill:#e8f5e9,stroke:#4caf50
333
+ style BBV1 fill:#e8f5e9,stroke:#4caf50
334
+ style VEB fill:#fff3e0,stroke:#ff9800
276
335
  style V2C fill:#e3f2fd,stroke:#2196f3
277
336
  style REQ fill:#f3e5f5,stroke:#9c27b0
278
- style PA1 fill:#fff9c4,stroke:#f9a825
279
337
  style BPA fill:#fff9c4,stroke:#f9a825
280
338
  ```
281
339
 
package/lib/cjs/abis.d.ts CHANGED
@@ -326,6 +326,216 @@ export declare const vaultExitBundlesV1Abi: readonly [{
326
326
  readonly outputs: readonly [];
327
327
  readonly stateMutability: "nonpayable";
328
328
  }];
329
+ /**
330
+ * Pinned ABI for the VaultBundlesV1 entrypoints used by Vault V1 and Vault V2 actions.
331
+ *
332
+ * Sourced from `morpho-org/bundles` commit
333
+ * `f27e7bcf744310303e24faa522b71d702e696686`.
334
+ */
335
+ export declare const vaultBundlesV1Abi: readonly [{
336
+ readonly type: "error";
337
+ readonly name: "AlreadyInitiated";
338
+ readonly inputs: readonly [];
339
+ }, {
340
+ readonly type: "error";
341
+ readonly name: "DeadlinePassed";
342
+ readonly inputs: readonly [];
343
+ }, {
344
+ readonly type: "error";
345
+ readonly name: "InconsistentAssets";
346
+ readonly inputs: readonly [];
347
+ }, {
348
+ readonly type: "error";
349
+ readonly name: "NotExactlyOneZero";
350
+ readonly inputs: readonly [];
351
+ }, {
352
+ readonly type: "error";
353
+ readonly name: "PctExceeded";
354
+ readonly inputs: readonly [];
355
+ }, {
356
+ readonly type: "error";
357
+ readonly name: "SlippageExceeded";
358
+ readonly inputs: readonly [];
359
+ }, {
360
+ readonly type: "function";
361
+ readonly name: "initiator";
362
+ readonly inputs: readonly [];
363
+ readonly outputs: readonly [{
364
+ readonly name: "";
365
+ readonly type: "address";
366
+ readonly internalType: "address";
367
+ }];
368
+ readonly stateMutability: "view";
369
+ }, {
370
+ readonly type: "function";
371
+ readonly name: "vaultBundlesV1Deposit";
372
+ readonly inputs: readonly [{
373
+ readonly name: "vault";
374
+ readonly type: "address";
375
+ readonly internalType: "address";
376
+ }, {
377
+ readonly name: "assets";
378
+ readonly type: "uint256";
379
+ readonly internalType: "uint256";
380
+ }, {
381
+ readonly name: "maxSharePriceE27";
382
+ readonly type: "uint256";
383
+ readonly internalType: "uint256";
384
+ }, {
385
+ readonly name: "assetPermit";
386
+ readonly type: "tuple";
387
+ readonly internalType: "struct TokenPermit";
388
+ readonly components: readonly [{
389
+ readonly name: "kind";
390
+ readonly type: "uint8";
391
+ readonly internalType: "enum PermitKind";
392
+ }, {
393
+ readonly name: "data";
394
+ readonly type: "bytes";
395
+ readonly internalType: "bytes";
396
+ }];
397
+ }, {
398
+ readonly name: "referralFeePct";
399
+ readonly type: "uint256";
400
+ readonly internalType: "uint256";
401
+ }, {
402
+ readonly name: "referralFeeRecipient";
403
+ readonly type: "address";
404
+ readonly internalType: "address";
405
+ }, {
406
+ readonly name: "deadline";
407
+ readonly type: "uint256";
408
+ readonly internalType: "uint256";
409
+ }];
410
+ readonly outputs: readonly [];
411
+ readonly stateMutability: "payable";
412
+ }, {
413
+ readonly type: "function";
414
+ readonly name: "vaultBundlesV1Withdraw";
415
+ readonly inputs: readonly [{
416
+ readonly name: "vault";
417
+ readonly type: "address";
418
+ readonly internalType: "address";
419
+ }, {
420
+ readonly name: "assets";
421
+ readonly type: "uint256";
422
+ readonly internalType: "uint256";
423
+ }, {
424
+ readonly name: "shares";
425
+ readonly type: "uint256";
426
+ readonly internalType: "uint256";
427
+ }, {
428
+ readonly name: "sharesPermit";
429
+ readonly type: "tuple";
430
+ readonly internalType: "struct Permit";
431
+ readonly components: readonly [{
432
+ readonly name: "value";
433
+ readonly type: "uint256";
434
+ readonly internalType: "uint256";
435
+ }, {
436
+ readonly name: "nonce";
437
+ readonly type: "uint256";
438
+ readonly internalType: "uint256";
439
+ }, {
440
+ readonly name: "deadline";
441
+ readonly type: "uint256";
442
+ readonly internalType: "uint256";
443
+ }, {
444
+ readonly name: "v";
445
+ readonly type: "uint8";
446
+ readonly internalType: "uint8";
447
+ }, {
448
+ readonly name: "r";
449
+ readonly type: "bytes32";
450
+ readonly internalType: "bytes32";
451
+ }, {
452
+ readonly name: "s";
453
+ readonly type: "bytes32";
454
+ readonly internalType: "bytes32";
455
+ }];
456
+ }, {
457
+ readonly name: "referralFeePct";
458
+ readonly type: "uint256";
459
+ readonly internalType: "uint256";
460
+ }, {
461
+ readonly name: "referralFeeRecipient";
462
+ readonly type: "address";
463
+ readonly internalType: "address";
464
+ }, {
465
+ readonly name: "deadline";
466
+ readonly type: "uint256";
467
+ readonly internalType: "uint256";
468
+ }];
469
+ readonly outputs: readonly [];
470
+ readonly stateMutability: "nonpayable";
471
+ }, {
472
+ readonly type: "function";
473
+ readonly name: "vaultBundlesV1Migrate";
474
+ readonly inputs: readonly [{
475
+ readonly name: "sourceVault";
476
+ readonly type: "address";
477
+ readonly internalType: "address";
478
+ }, {
479
+ readonly name: "destVault";
480
+ readonly type: "address";
481
+ readonly internalType: "address";
482
+ }, {
483
+ readonly name: "assetsWithdrawn";
484
+ readonly type: "uint256";
485
+ readonly internalType: "uint256";
486
+ }, {
487
+ readonly name: "sharesRedeemed";
488
+ readonly type: "uint256";
489
+ readonly internalType: "uint256";
490
+ }, {
491
+ readonly name: "destMaxSharePriceE27";
492
+ readonly type: "uint256";
493
+ readonly internalType: "uint256";
494
+ }, {
495
+ readonly name: "sharesPermit";
496
+ readonly type: "tuple";
497
+ readonly internalType: "struct Permit";
498
+ readonly components: readonly [{
499
+ readonly name: "value";
500
+ readonly type: "uint256";
501
+ readonly internalType: "uint256";
502
+ }, {
503
+ readonly name: "nonce";
504
+ readonly type: "uint256";
505
+ readonly internalType: "uint256";
506
+ }, {
507
+ readonly name: "deadline";
508
+ readonly type: "uint256";
509
+ readonly internalType: "uint256";
510
+ }, {
511
+ readonly name: "v";
512
+ readonly type: "uint8";
513
+ readonly internalType: "uint8";
514
+ }, {
515
+ readonly name: "r";
516
+ readonly type: "bytes32";
517
+ readonly internalType: "bytes32";
518
+ }, {
519
+ readonly name: "s";
520
+ readonly type: "bytes32";
521
+ readonly internalType: "bytes32";
522
+ }];
523
+ }, {
524
+ readonly name: "referralFeePct";
525
+ readonly type: "uint256";
526
+ readonly internalType: "uint256";
527
+ }, {
528
+ readonly name: "referralFeeRecipient";
529
+ readonly type: "address";
530
+ readonly internalType: "address";
531
+ }, {
532
+ readonly name: "deadline";
533
+ readonly type: "uint256";
534
+ readonly internalType: "uint256";
535
+ }];
536
+ readonly outputs: readonly [];
537
+ readonly stateMutability: "nonpayable";
538
+ }];
329
539
  /** ABI for the Bundler3 multicall contract. */
330
540
  export declare const bundler3Abi: readonly [{
331
541
  readonly type: "function";