@morpho-org/morpho-sdk 5.3.1 → 5.3.3

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.
package/README.md CHANGED
@@ -31,6 +31,7 @@ pnpm add @morpho-org/morpho-sdk
31
31
  | **VaultV1** | `deposit` | Bundler (general adapter) | Same ERC-4626 inflation attack prevention as V2. Supports native token wrapping. |
32
32
  | | `withdraw` | Direct vault call | No attack surface |
33
33
  | | `redeem` | Direct vault call | No attack surface |
34
+ | | `migrateToV2` | Bundler (general adapter) | Atomic V1 → V2 migration: redeem V1 shares + deposit into V2 in one tx. Slippage-protected. |
34
35
  | **Blue** | `supply` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupply` with `maxSharePrice` (inflation guard). Supports native wrapping when `loanToken === wNative`. |
35
36
  | | `supplyCollateral` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupplyCollateral`. Supports native wrapping. |
36
37
  | | `borrow` | Bundler (general adapter) | `morphoBorrow` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
@@ -236,7 +237,13 @@ const tx = buildTx();
236
237
 
237
238
  #### Migrate to V2
238
239
 
239
- Atomically migrate a full position from a VaultV1 (MetaMorpho) vault into a VaultV2 vault. The bundler redeems the V1 shares and deposits the resulting assets into V2 in a single transaction. Both vaults must share the same underlying asset.
240
+ Atomically migrate a full position from a VaultV1 (MetaMorpho) vault into a VaultV2 vault. In a single bundler transaction, the user's V1 shares are pulled into `GeneralAdapter1`, redeemed for the underlying asset, and re-deposited into the V2 vault on the user's behalf. Guarantees:
241
+
242
+ - **Atomic** — redeem V1 + deposit V2 happen in one transaction; the user is never left holding loose assets between the two legs.
243
+ - **Slippage-protected on both legs** — the entity derives a `minSharePriceVaultV1` (V1 redeem floor) and a `maxSharePriceVaultV2` (V2 deposit ceiling, which doubles as the ERC-4626 inflation-attack guard) from live vault state plus your `slippageTolerance`.
244
+ - **Same-asset only** — both vaults must share the same underlying asset. A mismatch throws `VaultAssetMismatchError`; a `sourceVault` whose address doesn't match the entity throws `VaultAddressMismatchError`.
245
+
246
+ `sourceVault` / `targetVault` are the accrual snapshots returned by each entity's `getData()`.
240
247
 
241
248
  ```typescript
242
249
  const sourceVault = client.morpho.vaultV1("0xV1Vault...", 1);
@@ -246,11 +253,24 @@ const { buildTx, getRequirements } = sourceVault.migrateToV2({
246
253
  userAddress: "0xUser...",
247
254
  sourceVault: await sourceVault.getData(),
248
255
  targetVault: await targetVault.getData(),
249
- shares: 1000000000000000000n,
256
+ shares: 1000000000000000000n, // full V1 position, in V1 shares
257
+ slippageTolerance: 300000000000000n, // optional, WAD (0.03%); defaults to DEFAULT_SLIPPAGE_TOLERANCE, capped at 10%
250
258
  });
251
259
 
260
+ // GeneralAdapter1 must be allowed to pull the V1 shares. Because V1 shares
261
+ // implement EIP-2612, this is returned either as an ERC-20 approval tx or as a
262
+ // signable permit requirement (when the extension was created with `supportSignature: true`).
252
263
  const requirements = await getRequirements();
253
- const tx = buildTx([requirementSignature]);
264
+ const signatures = [];
265
+ for (const requirement of requirements) {
266
+ if (isRequirementApproval(requirement)) {
267
+ await walletClient.sendTransaction(requirement); // approve GA1 to pull V1 shares
268
+ } else if (isRequirementSignature(requirement)) {
269
+ signatures.push(await requirement.sign(walletClient, "0xUser..."));
270
+ }
271
+ }
272
+
273
+ const tx = buildTx(signatures);
254
274
  ```
255
275
 
256
276
  ### Blue
@@ -45,8 +45,9 @@ export interface BlueActions {
45
45
  /**
46
46
  * Prepares a loan-asset supply transaction.
47
47
  *
48
- * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from market supply
49
- * state and `slippageTolerance` to protect against share-price inflation.
48
+ * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from the supply state of
49
+ * `marketData` forward-accrued to execution and `slippageTolerance` to protect against
50
+ * share-price inflation.
50
51
  * `getRequirements` returns ERC20 approval or permit for `GeneralAdapter1` on the loan token.
51
52
  * When `nativeAmount` is provided, native token is wrapped; the loan token must be wNative.
52
53
  *
@@ -54,9 +54,12 @@ class MorphoBlue {
54
54
  if (nativeAmount !== undefined && nativeAmount > 0n) {
55
55
  (0, index_js_2.validateNativeAsset)(this.chainId, this.marketParams.loanToken);
56
56
  }
57
+ // Forward-accrue (2h) before deriving `maxSharePrice`: on-chain `morphoSupply` accrues `lastUpdate → execution`, raising the supply share price, so an un-accrued bound reverts on quiet markets.
58
+ const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), marketData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
59
+ const marketForSupply = marketData.accrueInterest(accrualTimestamp);
57
60
  const maxSharePrice = (0, index_js_2.computeMaxSupplySharePrice)({
58
61
  supplyAssets: totalAssets,
59
- market: marketData,
62
+ market: marketForSupply,
60
63
  slippageTolerance,
61
64
  });
62
65
  return {
@@ -45,8 +45,9 @@ export interface BlueActions {
45
45
  /**
46
46
  * Prepares a loan-asset supply transaction.
47
47
  *
48
- * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from market supply
49
- * state and `slippageTolerance` to protect against share-price inflation.
48
+ * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from the supply state of
49
+ * `marketData` forward-accrued to execution and `slippageTolerance` to protect against
50
+ * share-price inflation.
50
51
  * `getRequirements` returns ERC20 approval or permit for `GeneralAdapter1` on the loan token.
51
52
  * When `nativeAmount` is provided, native token is wrapped; the loan token must be wNative.
52
53
  *
@@ -51,9 +51,12 @@ export class MorphoBlue {
51
51
  if (nativeAmount !== undefined && nativeAmount > 0n) {
52
52
  validateNativeAsset(this.chainId, this.marketParams.loanToken);
53
53
  }
54
+ // Forward-accrue (2h) before deriving `maxSharePrice`: on-chain `morphoSupply` accrues `lastUpdate → execution`, raising the supply share price, so an un-accrued bound reverts on quiet markets.
55
+ const accrualTimestamp = MathLib.max(Time.timestamp(), marketData.lastUpdate) + Time.s.from.h(2n);
56
+ const marketForSupply = marketData.accrueInterest(accrualTimestamp);
54
57
  const maxSharePrice = computeMaxSupplySharePrice({
55
58
  supplyAssets: totalAssets,
56
- market: marketData,
59
+ market: marketForSupply,
57
60
  slippageTolerance,
58
61
  });
59
62
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "5.3.1",
4
+ "version": "5.3.3",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"
@@ -145,9 +145,9 @@
145
145
  ],
146
146
  "dependencies": {
147
147
  "zod": "^4.4.3",
148
- "@morpho-org/blue-sdk": "^6.3.1",
149
- "@morpho-org/blue-sdk-viem": "^5.2.0",
150
- "@morpho-org/midnight-sdk": "^1.2.0",
148
+ "@morpho-org/blue-sdk": "^6.4.0",
149
+ "@morpho-org/blue-sdk-viem": "^5.2.1",
150
+ "@morpho-org/midnight-sdk": "^1.2.1",
151
151
  "@morpho-org/morpho-ts": "^2.8.0"
152
152
  },
153
153
  "peerDependencies": {