@morpho-org/morpho-sdk 5.3.0 → 5.3.2
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 +23 -3
- package/lib/cjs/entities/blue/blue.js +6 -12
- package/lib/esm/entities/blue/blue.js +6 -12
- package/package.json +7 -7
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.
|
|
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
|
|
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
|
|
@@ -317,7 +317,10 @@ class MorphoBlue {
|
|
|
317
317
|
let repayAssets;
|
|
318
318
|
let repayShares;
|
|
319
319
|
let erc20Amount;
|
|
320
|
-
|
|
320
|
+
// Forward-accrue (2h) before deriving `maxSharePrice` (both modes): on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
|
|
321
|
+
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
322
|
+
morpho_ts_1.Time.s.from.h(2n);
|
|
323
|
+
const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
321
324
|
if ("shares" in params) {
|
|
322
325
|
(0, index_js_2.validateRepayShares)({
|
|
323
326
|
positionData,
|
|
@@ -326,11 +329,6 @@ class MorphoBlue {
|
|
|
326
329
|
});
|
|
327
330
|
repayAssets = 0n;
|
|
328
331
|
repayShares = shares;
|
|
329
|
-
// 2h forward accrual upper-bounds the on-chain repay price; bundle
|
|
330
|
-
// skims residual back to the receiver.
|
|
331
|
-
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
332
|
-
morpho_ts_1.Time.s.from.h(2n);
|
|
333
|
-
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
334
332
|
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
335
333
|
// Native funds the transfer first; the ERC-20 pulled is the remainder.
|
|
336
334
|
// When native covers the full (2h-forward-accrued, rounded-up) borrow
|
|
@@ -349,7 +347,6 @@ class MorphoBlue {
|
|
|
349
347
|
});
|
|
350
348
|
repayShares = 0n;
|
|
351
349
|
erc20Amount = amount;
|
|
352
|
-
marketForRepay = positionData.market;
|
|
353
350
|
}
|
|
354
351
|
const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
|
|
355
352
|
repayAssets,
|
|
@@ -493,11 +490,10 @@ class MorphoBlue {
|
|
|
493
490
|
let repayAssets;
|
|
494
491
|
let repayShares;
|
|
495
492
|
let erc20Amount;
|
|
496
|
-
|
|
497
|
-
// 2h forward accrual upper-bounds the on-chain repay price (shares
|
|
498
|
-
// mode) and the post-repay health check; bundle skims residual back.
|
|
493
|
+
// Forward-accrue (2h) for `maxSharePrice` (both modes) and the post-repay health check: on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
|
|
499
494
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
500
495
|
morpho_ts_1.Time.s.from.h(2n);
|
|
496
|
+
const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
501
497
|
if ("shares" in params) {
|
|
502
498
|
(0, index_js_2.validateRepayShares)({
|
|
503
499
|
positionData,
|
|
@@ -506,7 +502,6 @@ class MorphoBlue {
|
|
|
506
502
|
});
|
|
507
503
|
repayAssets = 0n;
|
|
508
504
|
repayShares = shares;
|
|
509
|
-
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
510
505
|
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
511
506
|
// Native funds the transfer first; the ERC-20 pulled is the remainder.
|
|
512
507
|
// When native covers the full (2h-forward-accrued, rounded-up) borrow
|
|
@@ -525,7 +520,6 @@ class MorphoBlue {
|
|
|
525
520
|
});
|
|
526
521
|
repayShares = 0n;
|
|
527
522
|
erc20Amount = amount;
|
|
528
|
-
marketForRepay = positionData.market;
|
|
529
523
|
}
|
|
530
524
|
if (withdrawAmount > positionData.collateral) {
|
|
531
525
|
throw new index_js_3.WithdrawExceedsCollateralError({
|
|
@@ -314,7 +314,10 @@ export class MorphoBlue {
|
|
|
314
314
|
let repayAssets;
|
|
315
315
|
let repayShares;
|
|
316
316
|
let erc20Amount;
|
|
317
|
-
|
|
317
|
+
// Forward-accrue (2h) before deriving `maxSharePrice` (both modes): on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
|
|
318
|
+
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
319
|
+
Time.s.from.h(2n);
|
|
320
|
+
const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
318
321
|
if ("shares" in params) {
|
|
319
322
|
validateRepayShares({
|
|
320
323
|
positionData,
|
|
@@ -323,11 +326,6 @@ export class MorphoBlue {
|
|
|
323
326
|
});
|
|
324
327
|
repayAssets = 0n;
|
|
325
328
|
repayShares = shares;
|
|
326
|
-
// 2h forward accrual upper-bounds the on-chain repay price; bundle
|
|
327
|
-
// skims residual back to the receiver.
|
|
328
|
-
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
329
|
-
Time.s.from.h(2n);
|
|
330
|
-
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
331
329
|
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
332
330
|
// Native funds the transfer first; the ERC-20 pulled is the remainder.
|
|
333
331
|
// When native covers the full (2h-forward-accrued, rounded-up) borrow
|
|
@@ -346,7 +344,6 @@ export class MorphoBlue {
|
|
|
346
344
|
});
|
|
347
345
|
repayShares = 0n;
|
|
348
346
|
erc20Amount = amount;
|
|
349
|
-
marketForRepay = positionData.market;
|
|
350
347
|
}
|
|
351
348
|
const maxSharePrice = computeMaxRepaySharePrice({
|
|
352
349
|
repayAssets,
|
|
@@ -490,11 +487,10 @@ export class MorphoBlue {
|
|
|
490
487
|
let repayAssets;
|
|
491
488
|
let repayShares;
|
|
492
489
|
let erc20Amount;
|
|
493
|
-
|
|
494
|
-
// 2h forward accrual upper-bounds the on-chain repay price (shares
|
|
495
|
-
// mode) and the post-repay health check; bundle skims residual back.
|
|
490
|
+
// Forward-accrue (2h) for `maxSharePrice` (both modes) and the post-repay health check: on-chain `morphoRepay` accrues `lastUpdate → execution`, so an un-accrued bound reverts on quiet markets.
|
|
496
491
|
const accrualTimestamp = MathLib.max(Time.timestamp(), positionData.market.lastUpdate) +
|
|
497
492
|
Time.s.from.h(2n);
|
|
493
|
+
const marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
498
494
|
if ("shares" in params) {
|
|
499
495
|
validateRepayShares({
|
|
500
496
|
positionData,
|
|
@@ -503,7 +499,6 @@ export class MorphoBlue {
|
|
|
503
499
|
});
|
|
504
500
|
repayAssets = 0n;
|
|
505
501
|
repayShares = shares;
|
|
506
|
-
marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
|
|
507
502
|
const borrowAssets = marketForRepay.toBorrowAssets(shares, "Up");
|
|
508
503
|
// Native funds the transfer first; the ERC-20 pulled is the remainder.
|
|
509
504
|
// When native covers the full (2h-forward-accrued, rounded-up) borrow
|
|
@@ -522,7 +517,6 @@ export class MorphoBlue {
|
|
|
522
517
|
});
|
|
523
518
|
repayShares = 0n;
|
|
524
519
|
erc20Amount = amount;
|
|
525
|
-
marketForRepay = positionData.market;
|
|
526
520
|
}
|
|
527
521
|
if (withdrawAmount > positionData.collateral) {
|
|
528
522
|
throw new WithdrawExceedsCollateralError({
|
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.
|
|
4
|
+
"version": "5.3.2",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Foulks-Plb <https://x.com/FoulkPlb>"
|
|
@@ -145,10 +145,10 @@
|
|
|
145
145
|
],
|
|
146
146
|
"dependencies": {
|
|
147
147
|
"zod": "^4.4.3",
|
|
148
|
-
"@morpho-org/blue-sdk": "^6.
|
|
149
|
-
"@morpho-org/blue-sdk-viem": "^5.2.
|
|
150
|
-
"@morpho-org/
|
|
151
|
-
"@morpho-org/
|
|
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
|
+
"@morpho-org/morpho-ts": "^2.8.0"
|
|
152
152
|
},
|
|
153
153
|
"peerDependencies": {
|
|
154
154
|
"viem": "^2.0.0"
|
|
@@ -160,8 +160,8 @@
|
|
|
160
160
|
"viem": "^2.54.2",
|
|
161
161
|
"vitest": "^4.1.9",
|
|
162
162
|
"@morpho-org/bundler-sdk-viem": "^5.0.3",
|
|
163
|
-
"@morpho-org/
|
|
164
|
-
"@morpho-org/
|
|
163
|
+
"@morpho-org/test": "^2.8.3",
|
|
164
|
+
"@morpho-org/simulation-sdk": "^4.0.3"
|
|
165
165
|
},
|
|
166
166
|
"scripts": {
|
|
167
167
|
"prepublish": "$npm_execpath build",
|