@morpho-org/morpho-sdk 5.9.0 → 5.10.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.
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +69 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +7 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +5 -1
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +69 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +7 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +5 -1
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/package.json +8 -8
|
@@ -40,8 +40,8 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
|
|
|
40
40
|
* chainId: 8453,
|
|
41
41
|
* market: marketData.params,
|
|
42
42
|
* collateralAssets: 2_000_000n,
|
|
43
|
-
* loanAssets:
|
|
44
|
-
* maxUnits:
|
|
43
|
+
* loanAssets: 1_000_000n,
|
|
44
|
+
* maxUnits: 1_100_000n,
|
|
45
45
|
* taker: borrower,
|
|
46
46
|
* takeableOffers: quote.data.takeableOffers,
|
|
47
47
|
* deadline: maxUint256,
|
|
@@ -44,8 +44,8 @@ const types_js_1 = require("./types.js");
|
|
|
44
44
|
* chainId: 8453,
|
|
45
45
|
* market: marketData.params,
|
|
46
46
|
* collateralAssets: 2_000_000n,
|
|
47
|
-
* loanAssets:
|
|
48
|
-
* maxUnits:
|
|
47
|
+
* loanAssets: 1_000_000n,
|
|
48
|
+
* maxUnits: 1_100_000n,
|
|
49
49
|
* taker: borrower,
|
|
50
50
|
* takeableOffers: quote.data.takeableOffers,
|
|
51
51
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeBorrowParams {
|
|
|
46
46
|
* const tx = midnightTakeBorrow({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* loanAssets:
|
|
50
|
-
* maxUnits:
|
|
49
|
+
* loanAssets: 1_000_000n,
|
|
50
|
+
* maxUnits: 1_100_000n,
|
|
51
51
|
* taker: borrower,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -40,8 +40,8 @@ const index_js_2 = require("../../types/index.js");
|
|
|
40
40
|
* const tx = midnightTakeBorrow({
|
|
41
41
|
* chainId: 8453,
|
|
42
42
|
* market: marketData.params,
|
|
43
|
-
* loanAssets:
|
|
44
|
-
* maxUnits:
|
|
43
|
+
* loanAssets: 1_000_000n,
|
|
44
|
+
* maxUnits: 1_100_000n,
|
|
45
45
|
* taker: borrower,
|
|
46
46
|
* takeableOffers: quote.data.takeableOffers,
|
|
47
47
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeLendParams {
|
|
|
46
46
|
* const tx = midnightTakeLend({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* assets:
|
|
50
|
-
* minUnits:
|
|
49
|
+
* assets: 1_000_000n,
|
|
50
|
+
* minUnits: 900_000n,
|
|
51
51
|
* taker: lender,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -41,8 +41,8 @@ const types_js_1 = require("./types.js");
|
|
|
41
41
|
* const tx = midnightTakeLend({
|
|
42
42
|
* chainId: 8453,
|
|
43
43
|
* market: marketData.params,
|
|
44
|
-
* assets:
|
|
45
|
-
* minUnits:
|
|
44
|
+
* assets: 1_000_000n,
|
|
45
|
+
* minUnits: 900_000n,
|
|
46
46
|
* taker: lender,
|
|
47
47
|
* takeableOffers: quote.data.takeableOffers,
|
|
48
48
|
* deadline: maxUint256,
|
|
@@ -20,8 +20,8 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
|
|
|
20
20
|
* const output = midnight.takeLend({
|
|
21
21
|
* accountAddress: lender,
|
|
22
22
|
* marketData,
|
|
23
|
-
* assets:
|
|
24
|
-
* minUnits:
|
|
23
|
+
* assets: 1_000_000n,
|
|
24
|
+
* minUnits: 900_000n,
|
|
25
25
|
* takeableOffers: quote.data.takeableOffers,
|
|
26
26
|
* deadline: maxUint256,
|
|
27
27
|
* });
|
|
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
|
|
|
5
5
|
import { type ActionOutput, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
|
-
* Fetches
|
|
8
|
+
* Fetches direct onchain vault and allocation state without applying virtual interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
@@ -134,18 +134,74 @@ export interface VaultV1Actions {
|
|
|
134
134
|
readonly deadline?: bigint;
|
|
135
135
|
}) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
136
136
|
/**
|
|
137
|
-
* Prepares
|
|
137
|
+
* Prepares an atomic migration of Vault V1 shares to Vault V2 through bundler3.
|
|
138
138
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
139
|
+
* Accrues the source snapshot before converting V1 shares to assets so pending Vault V1
|
|
140
|
+
* performance-fee shares are reflected in both migration bounds. Projects the target Vault V2
|
|
141
|
+
* two hours forward when computing the deposit-leg maximum share price.
|
|
141
142
|
*
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
*
|
|
148
|
-
* @
|
|
143
|
+
* @param params - Migration parameters.
|
|
144
|
+
* @param params.userAddress - Account whose Vault V1 shares are migrated and that receives Vault
|
|
145
|
+
* V2 shares.
|
|
146
|
+
* @param params.sourceVault - Pre-fetched Vault V1 state with market allocations for local accrual.
|
|
147
|
+
* @param params.targetVault - Pre-fetched Vault V2 accrual snapshot with the same underlying
|
|
148
|
+
* asset.
|
|
149
|
+
* @param params.shares - Positive number of Vault V1 shares to migrate.
|
|
150
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to
|
|
151
|
+
* `DEFAULT_SLIPPAGE_TOLERANCE` and cannot exceed 10%.
|
|
152
|
+
* @returns Lazy approval or permit resolution through `getRequirements()` and a synchronous
|
|
153
|
+
* `buildTx()` returning a deep-frozen `Transaction<VaultV1MigrateToV2Action>`.
|
|
154
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
155
|
+
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
156
|
+
* @throws {VaultAssetMismatchError} when the source and target assets differ.
|
|
157
|
+
* @throws {NonPositiveInputError} when `shares` is not positive or the target projection yields
|
|
158
|
+
* no shares.
|
|
159
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
160
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
161
|
+
* @throws {UnknownBlueMarketAllocationError} when `sourceVault.withdrawQueue` references a market
|
|
162
|
+
* absent from `sourceVault.allocations`.
|
|
163
|
+
* @throws {UnsupportedChainIdError} from `getRequirements()` or `buildTx()` when the chain has no
|
|
164
|
+
* address registry.
|
|
165
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC contract read fails.
|
|
166
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is
|
|
167
|
+
* supplied.
|
|
168
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when several permit signatures
|
|
169
|
+
* are supplied.
|
|
170
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when a supplied permit targets another
|
|
171
|
+
* token.
|
|
172
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when a supplied permit covers another
|
|
173
|
+
* amount.
|
|
174
|
+
* @throws {Permit2ExpirationMissingError} from `buildTx()` when a Permit2 signature lacks an
|
|
175
|
+
* expiration.
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* import {
|
|
179
|
+
* morphoViemExtension,
|
|
180
|
+
* type Transaction,
|
|
181
|
+
* type VaultV1MigrateToV2Action,
|
|
182
|
+
* } from "@morpho-org/morpho-sdk";
|
|
183
|
+
* import { createPublicClient, http } from "viem";
|
|
184
|
+
* import { mainnet } from "viem/chains";
|
|
185
|
+
*
|
|
186
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
|
|
187
|
+
* morphoViemExtension(),
|
|
188
|
+
* );
|
|
189
|
+
* const sourceVaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
190
|
+
* const targetVaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
191
|
+
* const userAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
192
|
+
* const source = client.morpho.vaultV1(sourceVaultAddress, mainnet.id);
|
|
193
|
+
* const [sourceVault, targetVault] = await Promise.all([
|
|
194
|
+
* source.getData(),
|
|
195
|
+
* client.morpho.vaultV2(targetVaultAddress, mainnet.id).getData(),
|
|
196
|
+
* ]);
|
|
197
|
+
* const { buildTx } = source.migrateToV2({
|
|
198
|
+
* userAddress,
|
|
199
|
+
* sourceVault,
|
|
200
|
+
* targetVault,
|
|
201
|
+
* shares: 1_000_000n,
|
|
202
|
+
* });
|
|
203
|
+
* const tx: Readonly<Transaction<VaultV1MigrateToV2Action>> = buildTx();
|
|
204
|
+
* ```
|
|
149
205
|
*/
|
|
150
206
|
migrateToV2: (params: {
|
|
151
207
|
userAddress: Address;
|
|
@@ -194,6 +250,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
194
250
|
readonly userAddress: Address;
|
|
195
251
|
readonly deadline?: bigint;
|
|
196
252
|
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
253
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
197
254
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
|
|
198
255
|
userAddress: Address;
|
|
199
256
|
sourceVault: AccrualVault;
|
|
@@ -287,6 +287,7 @@ class MorphoVaultV1 {
|
|
|
287
287
|
},
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
290
291
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
291
292
|
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
292
293
|
if (!(0, viem_1.isAddressEqual)(sourceVault.address, this.vault)) {
|
|
@@ -299,8 +300,12 @@ class MorphoVaultV1 {
|
|
|
299
300
|
throw new index_js_3.NonPositiveInputError("shares", shares);
|
|
300
301
|
}
|
|
301
302
|
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
302
|
-
//
|
|
303
|
-
const
|
|
303
|
+
// V1 redeem accrues pending market interest and performance fees before converting shares.
|
|
304
|
+
const sourceAccrualTimestamp = sourceVault.allocations
|
|
305
|
+
.values()
|
|
306
|
+
.reduce((timestamp, { position }) => blue_sdk_1.MathLib.max(timestamp, position.market.lastUpdate), morpho_ts_1.Time.timestamp());
|
|
307
|
+
const accruedSourceVault = sourceVault.accrueInterest(sourceAccrualTimestamp);
|
|
308
|
+
const v1RefAssets = accruedSourceVault.toAssets(shares);
|
|
304
309
|
const minSharePriceVaultV1 = blue_sdk_1.MathLib.mulDivDown(v1RefAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
|
|
305
310
|
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
306
311
|
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
@@ -107,7 +107,11 @@ const cloneAdapter = (adapter, markets) => {
|
|
|
107
107
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter)
|
|
108
108
|
return new blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter({ ...base, marketParamsList: [...adapter.marketParamsList] }, adapter.positions.map((position) => clonePosition(position, markets)));
|
|
109
109
|
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter)
|
|
110
|
-
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
110
|
+
return new blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter({
|
|
111
|
+
...base,
|
|
112
|
+
morphoVaultV1: adapter.morphoVaultV1,
|
|
113
|
+
parentAllocation: adapter.parentAllocation,
|
|
114
|
+
}, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
|
|
111
115
|
throw new blue_sdk_1.UnsupportedVaultV2AdapterError(adapter.address);
|
|
112
116
|
};
|
|
113
117
|
const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
|
|
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
|
|
|
26
26
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
27
27
|
* such as `timestamp` and `origin`.
|
|
28
28
|
*
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* If no `data` is present in the original transaction, the function returns
|
|
33
|
-
* the transaction unmodified.
|
|
29
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
34
32
|
*/
|
|
35
33
|
export declare function addTransactionMetadata(tx: {
|
|
36
34
|
data: Hex;
|
|
@@ -29,15 +29,13 @@ const viem_1 = require("viem");
|
|
|
29
29
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
30
30
|
* such as `timestamp` and `origin`.
|
|
31
31
|
*
|
|
32
|
-
* @returns
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* If no `data` is present in the original transaction, the function returns
|
|
36
|
-
* the transaction unmodified.
|
|
32
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
33
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
34
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
37
35
|
*/
|
|
38
36
|
function addTransactionMetadata(tx, metadata) {
|
|
39
37
|
const { data, ..._tx } = tx;
|
|
40
|
-
if (!data)
|
|
38
|
+
if (!data || data === "0x")
|
|
41
39
|
return tx;
|
|
42
40
|
const concatItems = [data];
|
|
43
41
|
if (metadata.timestamp) {
|
|
@@ -40,8 +40,8 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
|
|
|
40
40
|
* chainId: 8453,
|
|
41
41
|
* market: marketData.params,
|
|
42
42
|
* collateralAssets: 2_000_000n,
|
|
43
|
-
* loanAssets:
|
|
44
|
-
* maxUnits:
|
|
43
|
+
* loanAssets: 1_000_000n,
|
|
44
|
+
* maxUnits: 1_100_000n,
|
|
45
45
|
* taker: borrower,
|
|
46
46
|
* takeableOffers: quote.data.takeableOffers,
|
|
47
47
|
* deadline: maxUint256,
|
|
@@ -41,8 +41,8 @@ import { PermitKind } from "./types.js";
|
|
|
41
41
|
* chainId: 8453,
|
|
42
42
|
* market: marketData.params,
|
|
43
43
|
* collateralAssets: 2_000_000n,
|
|
44
|
-
* loanAssets:
|
|
45
|
-
* maxUnits:
|
|
44
|
+
* loanAssets: 1_000_000n,
|
|
45
|
+
* maxUnits: 1_100_000n,
|
|
46
46
|
* taker: borrower,
|
|
47
47
|
* takeableOffers: quote.data.takeableOffers,
|
|
48
48
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeBorrowParams {
|
|
|
46
46
|
* const tx = midnightTakeBorrow({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* loanAssets:
|
|
50
|
-
* maxUnits:
|
|
49
|
+
* loanAssets: 1_000_000n,
|
|
50
|
+
* maxUnits: 1_100_000n,
|
|
51
51
|
* taker: borrower,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -37,8 +37,8 @@ import { NegativeInputError, NonPositiveInputError, } from "../../types/index.js
|
|
|
37
37
|
* const tx = midnightTakeBorrow({
|
|
38
38
|
* chainId: 8453,
|
|
39
39
|
* market: marketData.params,
|
|
40
|
-
* loanAssets:
|
|
41
|
-
* maxUnits:
|
|
40
|
+
* loanAssets: 1_000_000n,
|
|
41
|
+
* maxUnits: 1_100_000n,
|
|
42
42
|
* taker: borrower,
|
|
43
43
|
* takeableOffers: quote.data.takeableOffers,
|
|
44
44
|
* deadline: maxUint256,
|
|
@@ -46,8 +46,8 @@ export interface MidnightTakeLendParams {
|
|
|
46
46
|
* const tx = midnightTakeLend({
|
|
47
47
|
* chainId: 8453,
|
|
48
48
|
* market: marketData.params,
|
|
49
|
-
* assets:
|
|
50
|
-
* minUnits:
|
|
49
|
+
* assets: 1_000_000n,
|
|
50
|
+
* minUnits: 900_000n,
|
|
51
51
|
* taker: lender,
|
|
52
52
|
* takeableOffers: quote.data.takeableOffers,
|
|
53
53
|
* deadline: maxUint256,
|
|
@@ -38,8 +38,8 @@ import { PermitKind } from "./types.js";
|
|
|
38
38
|
* const tx = midnightTakeLend({
|
|
39
39
|
* chainId: 8453,
|
|
40
40
|
* market: marketData.params,
|
|
41
|
-
* assets:
|
|
42
|
-
* minUnits:
|
|
41
|
+
* assets: 1_000_000n,
|
|
42
|
+
* minUnits: 900_000n,
|
|
43
43
|
* taker: lender,
|
|
44
44
|
* takeableOffers: quote.data.takeableOffers,
|
|
45
45
|
* deadline: maxUint256,
|
|
@@ -20,8 +20,8 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
|
|
|
20
20
|
* const output = midnight.takeLend({
|
|
21
21
|
* accountAddress: lender,
|
|
22
22
|
* marketData,
|
|
23
|
-
* assets:
|
|
24
|
-
* minUnits:
|
|
23
|
+
* assets: 1_000_000n,
|
|
24
|
+
* minUnits: 900_000n,
|
|
25
25
|
* takeableOffers: quote.data.takeableOffers,
|
|
26
26
|
* deadline: maxUint256,
|
|
27
27
|
* });
|
|
@@ -5,10 +5,10 @@ import type { FetchParameters } from "../../types/data.js";
|
|
|
5
5
|
import { type ActionOutput, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoClientType, type PermitRequirementSignature, type Requirement, type RequirementSignature, type Transaction, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV1Actions {
|
|
7
7
|
/**
|
|
8
|
-
* Fetches
|
|
8
|
+
* Fetches direct onchain vault and allocation state without applying virtual interest.
|
|
9
9
|
*
|
|
10
10
|
* @param {FetchParameters} [parameters] - Optional fetch parameters (block number, state overrides, etc.).
|
|
11
|
-
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The
|
|
11
|
+
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>} The requested vault state.
|
|
12
12
|
*/
|
|
13
13
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVault>>>;
|
|
14
14
|
/**
|
|
@@ -134,18 +134,74 @@ export interface VaultV1Actions {
|
|
|
134
134
|
readonly deadline?: bigint;
|
|
135
135
|
}) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
136
136
|
/**
|
|
137
|
-
* Prepares
|
|
137
|
+
* Prepares an atomic migration of Vault V1 shares to Vault V2 through bundler3.
|
|
138
138
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
139
|
+
* Accrues the source snapshot before converting V1 shares to assets so pending Vault V1
|
|
140
|
+
* performance-fee shares are reflected in both migration bounds. Projects the target Vault V2
|
|
141
|
+
* two hours forward when computing the deposit-leg maximum share price.
|
|
141
142
|
*
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
*
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
*
|
|
148
|
-
* @
|
|
143
|
+
* @param params - Migration parameters.
|
|
144
|
+
* @param params.userAddress - Account whose Vault V1 shares are migrated and that receives Vault
|
|
145
|
+
* V2 shares.
|
|
146
|
+
* @param params.sourceVault - Pre-fetched Vault V1 state with market allocations for local accrual.
|
|
147
|
+
* @param params.targetVault - Pre-fetched Vault V2 accrual snapshot with the same underlying
|
|
148
|
+
* asset.
|
|
149
|
+
* @param params.shares - Positive number of Vault V1 shares to migrate.
|
|
150
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to
|
|
151
|
+
* `DEFAULT_SLIPPAGE_TOLERANCE` and cannot exceed 10%.
|
|
152
|
+
* @returns Lazy approval or permit resolution through `getRequirements()` and a synchronous
|
|
153
|
+
* `buildTx()` returning a deep-frozen `Transaction<VaultV1MigrateToV2Action>`.
|
|
154
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
155
|
+
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
156
|
+
* @throws {VaultAssetMismatchError} when the source and target assets differ.
|
|
157
|
+
* @throws {NonPositiveInputError} when `shares` is not positive or the target projection yields
|
|
158
|
+
* no shares.
|
|
159
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
160
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
161
|
+
* @throws {UnknownBlueMarketAllocationError} when `sourceVault.withdrawQueue` references a market
|
|
162
|
+
* absent from `sourceVault.allocations`.
|
|
163
|
+
* @throws {UnsupportedChainIdError} from `getRequirements()` or `buildTx()` when the chain has no
|
|
164
|
+
* address registry.
|
|
165
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC contract read fails.
|
|
166
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is
|
|
167
|
+
* supplied.
|
|
168
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when several permit signatures
|
|
169
|
+
* are supplied.
|
|
170
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when a supplied permit targets another
|
|
171
|
+
* token.
|
|
172
|
+
* @throws {DepositAmountMismatchError} from `buildTx()` when a supplied permit covers another
|
|
173
|
+
* amount.
|
|
174
|
+
* @throws {Permit2ExpirationMissingError} from `buildTx()` when a Permit2 signature lacks an
|
|
175
|
+
* expiration.
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* import {
|
|
179
|
+
* morphoViemExtension,
|
|
180
|
+
* type Transaction,
|
|
181
|
+
* type VaultV1MigrateToV2Action,
|
|
182
|
+
* } from "@morpho-org/morpho-sdk";
|
|
183
|
+
* import { createPublicClient, http } from "viem";
|
|
184
|
+
* import { mainnet } from "viem/chains";
|
|
185
|
+
*
|
|
186
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() }).extend(
|
|
187
|
+
* morphoViemExtension(),
|
|
188
|
+
* );
|
|
189
|
+
* const sourceVaultAddress = "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB";
|
|
190
|
+
* const targetVaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
191
|
+
* const userAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
|
192
|
+
* const source = client.morpho.vaultV1(sourceVaultAddress, mainnet.id);
|
|
193
|
+
* const [sourceVault, targetVault] = await Promise.all([
|
|
194
|
+
* source.getData(),
|
|
195
|
+
* client.morpho.vaultV2(targetVaultAddress, mainnet.id).getData(),
|
|
196
|
+
* ]);
|
|
197
|
+
* const { buildTx } = source.migrateToV2({
|
|
198
|
+
* userAddress,
|
|
199
|
+
* sourceVault,
|
|
200
|
+
* targetVault,
|
|
201
|
+
* shares: 1_000_000n,
|
|
202
|
+
* });
|
|
203
|
+
* const tx: Readonly<Transaction<VaultV1MigrateToV2Action>> = buildTx();
|
|
204
|
+
* ```
|
|
149
205
|
*/
|
|
150
206
|
migrateToV2: (params: {
|
|
151
207
|
userAddress: Address;
|
|
@@ -194,6 +250,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
194
250
|
readonly userAddress: Address;
|
|
195
251
|
readonly deadline?: bigint;
|
|
196
252
|
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
253
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
197
254
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance, }: {
|
|
198
255
|
userAddress: Address;
|
|
199
256
|
sourceVault: AccrualVault;
|
|
@@ -284,6 +284,7 @@ export class MorphoVaultV1 {
|
|
|
284
284
|
},
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
287
288
|
migrateToV2({ userAddress, sourceVault, targetVault, shares, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
288
289
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
289
290
|
if (!isAddressEqual(sourceVault.address, this.vault)) {
|
|
@@ -296,8 +297,12 @@ export class MorphoVaultV1 {
|
|
|
296
297
|
throw new NonPositiveInputError("shares", shares);
|
|
297
298
|
}
|
|
298
299
|
validateSlippageTolerance(slippageTolerance);
|
|
299
|
-
//
|
|
300
|
-
const
|
|
300
|
+
// V1 redeem accrues pending market interest and performance fees before converting shares.
|
|
301
|
+
const sourceAccrualTimestamp = sourceVault.allocations
|
|
302
|
+
.values()
|
|
303
|
+
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), Time.timestamp());
|
|
304
|
+
const accruedSourceVault = sourceVault.accrueInterest(sourceAccrualTimestamp);
|
|
305
|
+
const v1RefAssets = accruedSourceVault.toAssets(shares);
|
|
301
306
|
const minSharePriceVaultV1 = MathLib.mulDivDown(v1RefAssets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
|
|
302
307
|
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
303
308
|
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
@@ -104,7 +104,11 @@ const cloneAdapter = (adapter, markets) => {
|
|
|
104
104
|
if (adapter instanceof AccrualVaultV2MorphoMarketV1Adapter)
|
|
105
105
|
return new AccrualVaultV2MorphoMarketV1Adapter({ ...base, marketParamsList: [...adapter.marketParamsList] }, adapter.positions.map((position) => clonePosition(position, markets)));
|
|
106
106
|
if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter)
|
|
107
|
-
return new AccrualVaultV2MorphoVaultV1Adapter({
|
|
107
|
+
return new AccrualVaultV2MorphoVaultV1Adapter({
|
|
108
|
+
...base,
|
|
109
|
+
morphoVaultV1: adapter.morphoVaultV1,
|
|
110
|
+
parentAllocation: adapter.parentAllocation,
|
|
111
|
+
}, cloneAccrualVault(adapter.accrualVaultV1, markets), adapter.shares);
|
|
108
112
|
throw new UnsupportedVaultV2AdapterError(adapter.address);
|
|
109
113
|
};
|
|
110
114
|
const cloneVault = (vault, { markets, adapterKeysToClone, }) => {
|
|
@@ -26,11 +26,9 @@ import type { Metadata } from "../types/index.js";
|
|
|
26
26
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
27
27
|
* such as `timestamp` and `origin`.
|
|
28
28
|
*
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* If no `data` is present in the original transaction, the function returns
|
|
33
|
-
* the transaction unmodified.
|
|
29
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
34
32
|
*/
|
|
35
33
|
export declare function addTransactionMetadata(tx: {
|
|
36
34
|
data: Hex;
|
|
@@ -26,15 +26,13 @@ import { concatHex, isHex, numberToHex } from "viem";
|
|
|
26
26
|
* @param {Metadata} metadata - An object containing optional metadata fields
|
|
27
27
|
* such as `timestamp` and `origin`.
|
|
28
28
|
*
|
|
29
|
-
* @returns
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* If no `data` is present in the original transaction, the function returns
|
|
33
|
-
* the transaction unmodified.
|
|
29
|
+
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
|
+
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
|
+
* with `data` containing any appended metadata. The input is never mutated.
|
|
34
32
|
*/
|
|
35
33
|
export function addTransactionMetadata(tx, metadata) {
|
|
36
34
|
const { data, ..._tx } = tx;
|
|
37
|
-
if (!data)
|
|
35
|
+
if (!data || data === "0x")
|
|
38
36
|
return tx;
|
|
39
37
|
const concatItems = [data];
|
|
40
38
|
if (metadata.timestamp) {
|
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.
|
|
4
|
+
"version": "5.10.1",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Foulks-Plb <https://x.com/FoulkPlb>"
|
|
@@ -161,10 +161,10 @@
|
|
|
161
161
|
],
|
|
162
162
|
"dependencies": {
|
|
163
163
|
"zod": "^4.4.3",
|
|
164
|
-
"@morpho-org/blue-sdk": "^6.
|
|
165
|
-
"@morpho-org/blue-sdk-viem": "^5.
|
|
166
|
-
"@morpho-org/midnight-sdk": "^1.
|
|
167
|
-
"@morpho-org/morpho-ts": "^2.
|
|
164
|
+
"@morpho-org/blue-sdk": "^6.8.0",
|
|
165
|
+
"@morpho-org/blue-sdk-viem": "^5.6.1",
|
|
166
|
+
"@morpho-org/midnight-sdk": "^1.4.0",
|
|
167
|
+
"@morpho-org/morpho-ts": "^2.12.0"
|
|
168
168
|
},
|
|
169
169
|
"peerDependencies": {
|
|
170
170
|
"viem": "^2.0.0"
|
|
@@ -172,14 +172,14 @@
|
|
|
172
172
|
"devDependencies": {
|
|
173
173
|
"dotenv": "^17.4.2",
|
|
174
174
|
"fast-check": "^4.9.0",
|
|
175
|
-
"typescript": "
|
|
175
|
+
"typescript": "7.0.2",
|
|
176
176
|
"viem": "^2.55.10",
|
|
177
177
|
"vitest": "^4.1.10",
|
|
178
178
|
"@morpho-org/test": "^2.10.0"
|
|
179
179
|
},
|
|
180
180
|
"scripts": {
|
|
181
|
-
"prepublish": "
|
|
182
|
-
"build": "tsc --noEmit &&
|
|
181
|
+
"prepublish": "pnpm build",
|
|
182
|
+
"build": "tsc --noEmit && pnpm build:cjs && pnpm build:esm",
|
|
183
183
|
"build:cjs": "tsc --build tsconfig.build.cjs.json && echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json",
|
|
184
184
|
"build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
|
|
185
185
|
"test": "vitest --root ../.. --project morpho-sdk --project morpho-sdk-fork"
|