@morpho-org/morpho-sdk 3.2.0 → 4.1.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.
- package/README.md +19 -16
- package/lib/cjs/actions/{marketV1 → blue}/borrow.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/borrow.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/buildReallocationActions.d.ts +1 -1
- package/lib/cjs/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/refinance.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/refinance.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repay.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/repay.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/repayWithdrawCollateral.js +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supply.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supply.js +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateralBorrow.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdraw.d.ts +11 -11
- package/lib/cjs/actions/{marketV1 → blue}/withdraw.js +10 -10
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdrawCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/withdrawCollateral.js +8 -8
- package/lib/cjs/actions/index.d.ts +2 -2
- package/lib/cjs/actions/index.js +1 -1
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
- package/lib/cjs/client/index.d.ts +0 -1
- package/lib/cjs/client/index.js +0 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +17 -11
- package/lib/cjs/client/morphoViemExtension.js +55 -10
- package/lib/cjs/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +22 -22
- package/lib/cjs/entities/{marketV1/marketV1.js → blue/blue.js} +12 -12
- package/lib/cjs/entities/blue/index.d.ts +1 -0
- package/lib/cjs/entities/{marketV1 → blue}/index.js +1 -1
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/index.js +3 -3
- package/lib/cjs/entities/reallocationData.d.ts +96 -2
- package/lib/cjs/entities/reallocationData.js +112 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
- package/lib/cjs/helpers/computeReallocations.d.ts +1 -1
- package/lib/cjs/helpers/computeReallocations.js +3 -5
- package/lib/cjs/helpers/utilization.d.ts +12 -0
- package/lib/cjs/helpers/utilization.js +17 -0
- package/lib/cjs/helpers/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +2 -2
- package/lib/cjs/types/action.d.ts +10 -10
- package/lib/cjs/types/client.d.ts +5 -4
- package/lib/esm/actions/{marketV1 → blue}/borrow.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/borrow.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/buildReallocationActions.d.ts +1 -1
- package/lib/esm/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/refinance.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/refinance.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repay.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/repay.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/repayWithdrawCollateral.js +6 -6
- package/lib/esm/actions/{marketV1 → blue}/supply.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supply.js +6 -6
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateralBorrow.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdraw.d.ts +11 -11
- package/lib/esm/actions/{marketV1 → blue}/withdraw.js +8 -8
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdrawCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/withdrawCollateral.js +6 -6
- package/lib/esm/actions/index.d.ts +2 -2
- package/lib/esm/actions/index.js +1 -1
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
- package/lib/esm/client/index.d.ts +0 -1
- package/lib/esm/client/index.js +0 -1
- package/lib/esm/client/morphoViemExtension.d.ts +17 -11
- package/lib/esm/client/morphoViemExtension.js +55 -10
- package/lib/esm/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +22 -22
- package/lib/esm/entities/{marketV1/marketV1.js → blue/blue.js} +11 -11
- package/lib/esm/entities/blue/index.d.ts +1 -0
- package/lib/esm/entities/blue/index.js +1 -0
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/index.js +1 -1
- package/lib/esm/entities/reallocationData.d.ts +96 -2
- package/lib/esm/entities/reallocationData.js +114 -3
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
- package/lib/esm/helpers/computeReallocations.d.ts +1 -1
- package/lib/esm/helpers/computeReallocations.js +3 -5
- package/lib/esm/helpers/utilization.d.ts +12 -0
- package/lib/esm/helpers/utilization.js +13 -0
- package/lib/esm/helpers/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +2 -2
- package/lib/esm/types/action.d.ts +10 -10
- package/lib/esm/types/client.d.ts +5 -4
- package/package.json +5 -5
- package/lib/cjs/client/morphoClient.d.ts +0 -152
- package/lib/cjs/client/morphoClient.js +0 -162
- package/lib/cjs/entities/marketV1/index.d.ts +0 -1
- package/lib/esm/client/morphoClient.d.ts +0 -152
- package/lib/esm/client/morphoClient.js +0 -158
- package/lib/esm/entities/marketV1/index.d.ts +0 -1
- package/lib/esm/entities/marketV1/index.js +0 -1
- /package/lib/cjs/actions/{marketV1 → blue}/index.d.ts +0 -0
- /package/lib/cjs/actions/{marketV1 → blue}/index.js +0 -0
- /package/lib/esm/actions/{marketV1 → blue}/index.d.ts +0 -0
- /package/lib/esm/actions/{marketV1 → blue}/index.js +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
3
|
import type { FetchParameters } from "../../types/data.js";
|
|
4
|
-
import { type AssetsOrSharesArgs, type
|
|
4
|
+
import { type AssetsOrSharesArgs, type BlueBorrowAction, type BlueRefinanceAction, type BlueRepayAction, type BlueRepayWithdrawCollateralAction, type BlueSupplyAction, type BlueSupplyCollateralAction, type BlueSupplyCollateralBorrowAction, type BlueWithdrawAction, type BlueWithdrawCollateralAction, type DepositAmountArgs, type ERC20ApprovalAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
5
5
|
import { ReallocationData } from "../reallocationData.js";
|
|
6
|
-
export interface
|
|
6
|
+
export interface BlueActions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest market data with accrued interest.
|
|
9
9
|
*
|
|
@@ -32,7 +32,7 @@ export interface MarketV1Actions {
|
|
|
32
32
|
supplyCollateral: (params: {
|
|
33
33
|
userAddress: Address;
|
|
34
34
|
} & DepositAmountArgs) => {
|
|
35
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
35
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralAction>>;
|
|
36
36
|
getRequirements: (params?: {
|
|
37
37
|
useSimplePermit?: boolean;
|
|
38
38
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
@@ -55,7 +55,7 @@ export interface MarketV1Actions {
|
|
|
55
55
|
marketData: Market;
|
|
56
56
|
slippageTolerance?: bigint;
|
|
57
57
|
} & DepositAmountArgs) => {
|
|
58
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
58
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyAction>>;
|
|
59
59
|
getRequirements: (params?: {
|
|
60
60
|
useSimplePermit?: boolean;
|
|
61
61
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
@@ -89,7 +89,7 @@ export interface MarketV1Actions {
|
|
|
89
89
|
slippageTolerance?: bigint;
|
|
90
90
|
reallocations?: readonly VaultReallocation[];
|
|
91
91
|
} & AssetsOrSharesArgs) => {
|
|
92
|
-
buildTx: () => Readonly<Transaction<
|
|
92
|
+
buildTx: () => Readonly<Transaction<BlueWithdrawAction>>;
|
|
93
93
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
94
94
|
};
|
|
95
95
|
/**
|
|
@@ -117,7 +117,7 @@ export interface MarketV1Actions {
|
|
|
117
117
|
slippageTolerance?: bigint;
|
|
118
118
|
reallocations?: readonly VaultReallocation[];
|
|
119
119
|
}) => {
|
|
120
|
-
buildTx: () => Readonly<Transaction<
|
|
120
|
+
buildTx: () => Readonly<Transaction<BlueBorrowAction>>;
|
|
121
121
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
122
122
|
};
|
|
123
123
|
/**
|
|
@@ -143,7 +143,7 @@ export interface MarketV1Actions {
|
|
|
143
143
|
positionData: AccrualPosition;
|
|
144
144
|
slippageTolerance?: bigint;
|
|
145
145
|
} & RepayAmountArgs) => {
|
|
146
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
146
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayAction>>;
|
|
147
147
|
getRequirements: (params?: {
|
|
148
148
|
useSimplePermit?: boolean;
|
|
149
149
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
@@ -168,7 +168,7 @@ export interface MarketV1Actions {
|
|
|
168
168
|
amount: bigint;
|
|
169
169
|
positionData: AccrualPosition;
|
|
170
170
|
}) => {
|
|
171
|
-
buildTx: () => Readonly<Transaction<
|
|
171
|
+
buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Prepares an atomic repay-and-withdraw-collateral transaction.
|
|
@@ -192,7 +192,7 @@ export interface MarketV1Actions {
|
|
|
192
192
|
positionData: AccrualPosition;
|
|
193
193
|
slippageTolerance?: bigint;
|
|
194
194
|
} & RepayAmountArgs) => {
|
|
195
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
195
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
196
196
|
getRequirements: (params?: {
|
|
197
197
|
useSimplePermit?: boolean;
|
|
198
198
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
|
|
@@ -222,14 +222,14 @@ export interface MarketV1Actions {
|
|
|
222
222
|
slippageTolerance?: bigint;
|
|
223
223
|
reallocations?: readonly VaultReallocation[];
|
|
224
224
|
} & DepositAmountArgs) => {
|
|
225
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
225
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
226
226
|
getRequirements: (params?: {
|
|
227
227
|
useSimplePermit?: boolean;
|
|
228
228
|
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
|
|
229
229
|
};
|
|
230
230
|
/**
|
|
231
231
|
* Prepares an atomic refinance migrating this market's position to another Morpho Blue market
|
|
232
|
-
* that shares the same loan and collateral tokens. See {@link
|
|
232
|
+
* that shares the same loan and collateral tokens. See {@link blueRefinance} for the bundle.
|
|
233
233
|
*
|
|
234
234
|
* Validates ownership, token/id match, that amounts do not exceed the source position, and that
|
|
235
235
|
* both the residual source and the aggregate target position stay within LLTV − buffer. Both
|
|
@@ -263,7 +263,7 @@ export interface MarketV1Actions {
|
|
|
263
263
|
slippageTolerance?: bigint;
|
|
264
264
|
targetReallocations?: readonly VaultReallocation[];
|
|
265
265
|
}) => {
|
|
266
|
-
buildTx: () => Readonly<Transaction<
|
|
266
|
+
buildTx: () => Readonly<Transaction<BlueRefinanceAction>>;
|
|
267
267
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
268
268
|
};
|
|
269
269
|
/**
|
|
@@ -333,7 +333,7 @@ export interface MarketV1Actions {
|
|
|
333
333
|
amount?: never;
|
|
334
334
|
})) => readonly VaultReallocation[];
|
|
335
335
|
}
|
|
336
|
-
export declare class
|
|
336
|
+
export declare class MorphoBlue implements BlueActions {
|
|
337
337
|
private readonly client;
|
|
338
338
|
readonly marketParams: MarketParams;
|
|
339
339
|
private readonly chainId;
|
|
@@ -348,7 +348,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
348
348
|
getRequirements: (params?: {
|
|
349
349
|
useSimplePermit?: boolean;
|
|
350
350
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
351
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
351
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyAction>>;
|
|
352
352
|
};
|
|
353
353
|
withdraw(params: {
|
|
354
354
|
userAddress: Address;
|
|
@@ -358,7 +358,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
358
358
|
reallocations?: readonly VaultReallocation[];
|
|
359
359
|
} & AssetsOrSharesArgs): {
|
|
360
360
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
361
|
-
buildTx: () => Readonly<Transaction<
|
|
361
|
+
buildTx: () => Readonly<Transaction<BlueWithdrawAction>>;
|
|
362
362
|
};
|
|
363
363
|
supplyCollateral({ amount, userAddress, nativeAmount, }: {
|
|
364
364
|
userAddress: Address;
|
|
@@ -366,7 +366,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
366
366
|
getRequirements: (params?: {
|
|
367
367
|
useSimplePermit?: boolean;
|
|
368
368
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
369
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
369
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralAction>>;
|
|
370
370
|
};
|
|
371
371
|
borrow({ amount, userAddress, positionData, slippageTolerance, reallocations, }: {
|
|
372
372
|
amount: bigint;
|
|
@@ -376,7 +376,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
376
376
|
reallocations?: readonly VaultReallocation[];
|
|
377
377
|
}): {
|
|
378
378
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
379
|
-
buildTx: () => Readonly<Transaction<
|
|
379
|
+
buildTx: () => Readonly<Transaction<BlueBorrowAction>>;
|
|
380
380
|
};
|
|
381
381
|
repay(params: {
|
|
382
382
|
userAddress: Address;
|
|
@@ -386,14 +386,14 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
386
386
|
getRequirements: (reqParams?: {
|
|
387
387
|
useSimplePermit?: boolean;
|
|
388
388
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
389
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
389
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayAction>>;
|
|
390
390
|
};
|
|
391
391
|
withdrawCollateral({ userAddress, amount, positionData, }: {
|
|
392
392
|
userAddress: Address;
|
|
393
393
|
amount: bigint;
|
|
394
394
|
positionData: AccrualPosition;
|
|
395
395
|
}): {
|
|
396
|
-
buildTx: () => Readonly<Transaction<
|
|
396
|
+
buildTx: () => Readonly<Transaction<BlueWithdrawCollateralAction>>;
|
|
397
397
|
};
|
|
398
398
|
repayWithdrawCollateral(params: {
|
|
399
399
|
userAddress: Address;
|
|
@@ -404,7 +404,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
404
404
|
getRequirements: (reqParams?: {
|
|
405
405
|
useSimplePermit?: boolean;
|
|
406
406
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
407
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
407
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueRepayWithdrawCollateralAction>>;
|
|
408
408
|
};
|
|
409
409
|
supplyCollateralBorrow({ amount, userAddress, positionData, borrowAmount, nativeAmount, slippageTolerance, reallocations, }: {
|
|
410
410
|
userAddress: Address;
|
|
@@ -416,7 +416,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
416
416
|
getRequirements: (params?: {
|
|
417
417
|
useSimplePermit?: boolean;
|
|
418
418
|
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
|
|
419
|
-
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<
|
|
419
|
+
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<BlueSupplyCollateralBorrowAction>>;
|
|
420
420
|
};
|
|
421
421
|
refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance, targetReallocations, }: {
|
|
422
422
|
userAddress: Address;
|
|
@@ -432,7 +432,7 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
|
|
|
432
432
|
targetReallocations?: readonly VaultReallocation[];
|
|
433
433
|
}): {
|
|
434
434
|
getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
|
|
435
|
-
buildTx: () => Readonly<Transaction<
|
|
435
|
+
buildTx: () => Readonly<Transaction<BlueRefinanceAction>>;
|
|
436
436
|
};
|
|
437
437
|
/**
|
|
438
438
|
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MorphoBlue = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -9,7 +9,7 @@ const index_js_1 = require("../../actions/index.js");
|
|
|
9
9
|
const index_js_2 = require("../../helpers/index.js");
|
|
10
10
|
const index_js_3 = require("../../types/index.js");
|
|
11
11
|
const reallocationData_js_1 = require("../reallocationData.js");
|
|
12
|
-
class
|
|
12
|
+
class MorphoBlue {
|
|
13
13
|
client;
|
|
14
14
|
marketParams;
|
|
15
15
|
chainId;
|
|
@@ -68,7 +68,7 @@ class MorphoMarketV1 {
|
|
|
68
68
|
useSimplePermit: params?.useSimplePermit,
|
|
69
69
|
args: { amount, from: userAddress },
|
|
70
70
|
}),
|
|
71
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
71
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupply)({
|
|
72
72
|
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
73
73
|
args: {
|
|
74
74
|
amount,
|
|
@@ -136,7 +136,7 @@ class MorphoMarketV1 {
|
|
|
136
136
|
});
|
|
137
137
|
return authTx ? [authTx] : [];
|
|
138
138
|
},
|
|
139
|
-
buildTx: () => (0, index_js_1.
|
|
139
|
+
buildTx: () => (0, index_js_1.blueWithdraw)({
|
|
140
140
|
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
141
141
|
args: {
|
|
142
142
|
assets,
|
|
@@ -173,7 +173,7 @@ class MorphoMarketV1 {
|
|
|
173
173
|
useSimplePermit: params?.useSimplePermit,
|
|
174
174
|
args: { amount, from: userAddress },
|
|
175
175
|
}),
|
|
176
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
176
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupplyCollateral)({
|
|
177
177
|
market: {
|
|
178
178
|
chainId: this.chainId,
|
|
179
179
|
marketParams: this.marketParams,
|
|
@@ -223,7 +223,7 @@ class MorphoMarketV1 {
|
|
|
223
223
|
});
|
|
224
224
|
return authTx ? [authTx] : [];
|
|
225
225
|
},
|
|
226
|
-
buildTx: () => (0, index_js_1.
|
|
226
|
+
buildTx: () => (0, index_js_1.blueBorrow)({
|
|
227
227
|
market: {
|
|
228
228
|
chainId: this.chainId,
|
|
229
229
|
marketParams: this.marketParams,
|
|
@@ -309,7 +309,7 @@ class MorphoMarketV1 {
|
|
|
309
309
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
310
310
|
args: { amount: transferAmount, from: userAddress },
|
|
311
311
|
}),
|
|
312
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
312
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueRepay)({
|
|
313
313
|
market: {
|
|
314
314
|
chainId: this.chainId,
|
|
315
315
|
marketParams: this.marketParams,
|
|
@@ -354,7 +354,7 @@ class MorphoMarketV1 {
|
|
|
354
354
|
marketId: this.marketParams.id,
|
|
355
355
|
});
|
|
356
356
|
return {
|
|
357
|
-
buildTx: () => (0, index_js_1.
|
|
357
|
+
buildTx: () => (0, index_js_1.blueWithdrawCollateral)({
|
|
358
358
|
market: {
|
|
359
359
|
chainId: this.chainId,
|
|
360
360
|
marketParams: this.marketParams,
|
|
@@ -466,7 +466,7 @@ class MorphoMarketV1 {
|
|
|
466
466
|
]);
|
|
467
467
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
468
468
|
},
|
|
469
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
469
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueRepayWithdrawCollateral)({
|
|
470
470
|
market: {
|
|
471
471
|
chainId: this.chainId,
|
|
472
472
|
marketParams: this.marketParams,
|
|
@@ -543,7 +543,7 @@ class MorphoMarketV1 {
|
|
|
543
543
|
]);
|
|
544
544
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
545
545
|
},
|
|
546
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
546
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupplyCollateralBorrow)({
|
|
547
547
|
market: {
|
|
548
548
|
chainId: this.chainId,
|
|
549
549
|
marketParams: this.marketParams,
|
|
@@ -700,7 +700,7 @@ class MorphoMarketV1 {
|
|
|
700
700
|
});
|
|
701
701
|
return authTx ? [authTx] : [];
|
|
702
702
|
},
|
|
703
|
-
buildTx: () => (0, index_js_1.
|
|
703
|
+
buildTx: () => (0, index_js_1.blueRefinance)({
|
|
704
704
|
source: {
|
|
705
705
|
chainId: this.chainId,
|
|
706
706
|
marketParams: this.marketParams,
|
|
@@ -836,4 +836,4 @@ class MorphoMarketV1 {
|
|
|
836
836
|
});
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
|
-
exports.
|
|
839
|
+
exports.MorphoBlue = MorphoBlue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./blue.js";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./blue.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
3
|
-
export {
|
|
3
|
+
export { MorphoBlue } from "./blue/index.js";
|
|
4
4
|
export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
|
|
5
5
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
6
6
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.
|
|
3
|
+
exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.MorphoBlue = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.Token = exports.PreLiquidationPosition = exports.PreLiquidationParams = exports.Position = exports.MarketParams = exports.Market = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "AccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
|
|
6
6
|
Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
|
|
@@ -33,8 +33,8 @@ Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: tru
|
|
|
33
33
|
Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
|
|
34
34
|
Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
|
|
35
35
|
Object.defineProperty(exports, "WrappedToken", { enumerable: true, get: function () { return blue_sdk_1.WrappedToken; } });
|
|
36
|
-
var index_js_1 = require("./
|
|
37
|
-
Object.defineProperty(exports, "
|
|
36
|
+
var index_js_1 = require("./blue/index.js");
|
|
37
|
+
Object.defineProperty(exports, "MorphoBlue", { enumerable: true, get: function () { return index_js_1.MorphoBlue; } });
|
|
38
38
|
var reallocationData_js_1 = require("./reallocationData.js");
|
|
39
39
|
Object.defineProperty(exports, "ReallocationData", { enumerable: true, get: function () { return reallocationData_js_1.ReallocationData; } });
|
|
40
40
|
var index_js_2 = require("./vaultV1/index.js");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AccrualPosition, Market, type MarketId, Position, Vault, VaultMarketConfig } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import type { PublicAllocatorOptions, PublicReallocation } from "../types/index.js";
|
|
3
|
+
import type { PublicAllocatorOptions, PublicReallocation, ReallocationComputeOptions } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Input state required to construct {@link ReallocationData}.
|
|
6
6
|
*/
|
|
@@ -140,7 +140,7 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
140
140
|
* }).extend(morphoViemExtension());
|
|
141
141
|
*
|
|
142
142
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
143
|
-
* const market = client.morpho.
|
|
143
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
144
144
|
* const block = await client.getBlock();
|
|
145
145
|
* const reallocationData = await market.getReallocationData({
|
|
146
146
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -159,6 +159,100 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
159
159
|
readonly withdrawals: readonly PublicReallocation[];
|
|
160
160
|
data: ReallocationData;
|
|
161
161
|
};
|
|
162
|
+
/**
|
|
163
|
+
* Sums the public-allocator liquidity reallocatable into `marketId` from
|
|
164
|
+
* sibling markets.
|
|
165
|
+
*
|
|
166
|
+
* Read-only metric — never throws on insufficiency (returns `0n`). Bounded by
|
|
167
|
+
* each source market's withdrawal utilization cap and the target market's
|
|
168
|
+
* vault supply-cap headroom. Pass `options.defaultMaxWithdrawalUtilization` to
|
|
169
|
+
* widen the source ceiling (e.g. `MathLib.WAD` for the full drain).
|
|
170
|
+
*
|
|
171
|
+
* @param marketId - Target market that would receive the liquidity.
|
|
172
|
+
* @param options - Optional allocator discovery options.
|
|
173
|
+
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
174
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { createPublicClient, http } from "viem";
|
|
178
|
+
* import { mainnet } from "viem/chains";
|
|
179
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
180
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
181
|
+
*
|
|
182
|
+
* const client = createPublicClient({
|
|
183
|
+
* chain: mainnet,
|
|
184
|
+
* transport: http(),
|
|
185
|
+
* }).extend(morphoViemExtension());
|
|
186
|
+
*
|
|
187
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
188
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
189
|
+
* const block = await client.getBlock();
|
|
190
|
+
* const reallocationData = await market.getReallocationData({
|
|
191
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
192
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* const liquidity: bigint = reallocationData.getPublicReallocationLiquidity(
|
|
196
|
+
* marketParams.id,
|
|
197
|
+
* { timestamp: block.timestamp },
|
|
198
|
+
* );
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
getPublicReallocationLiquidity(marketId: MarketId, options?: PublicAllocatorOptions): bigint;
|
|
202
|
+
/**
|
|
203
|
+
* Computes the liquidity available to bring `marketId` to `targetUtilization`,
|
|
204
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
205
|
+
*
|
|
206
|
+
* Returns the max borrow `x` keeping post-borrow utilization
|
|
207
|
+
* `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
|
|
208
|
+
* reallocatable liquidity added to the market's supply — equivalently
|
|
209
|
+
* `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
|
|
210
|
+
* the target this is the market's own borrow headroom plus `targetUtilization · L`;
|
|
211
|
+
* reallocated supply also raises the supply denominator, so only that scaled
|
|
212
|
+
* share backs further borrow.
|
|
213
|
+
*
|
|
214
|
+
* Read-only metric — never throws on insufficiency:
|
|
215
|
+
* - returns only the market's own borrow headroom when
|
|
216
|
+
* `supplyTargetUtilization > targetUtilization` (reallocation would not
|
|
217
|
+
* trigger at that target);
|
|
218
|
+
* - returns `0n` when the market is already at or above the target and `L` is
|
|
219
|
+
* too small to bring it back under.
|
|
220
|
+
*
|
|
221
|
+
* @param marketId - Target market to borrow from.
|
|
222
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
223
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
224
|
+
* @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
|
|
225
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
229
|
+
* import { mainnet } from "viem/chains";
|
|
230
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
231
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
232
|
+
*
|
|
233
|
+
* const client = createPublicClient({
|
|
234
|
+
* chain: mainnet,
|
|
235
|
+
* transport: http(),
|
|
236
|
+
* }).extend(morphoViemExtension());
|
|
237
|
+
*
|
|
238
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
239
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
240
|
+
* const block = await client.getBlock();
|
|
241
|
+
* const reallocationData = await market.getReallocationData({
|
|
242
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
243
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
244
|
+
* });
|
|
245
|
+
*
|
|
246
|
+
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
247
|
+
* const available: bigint =
|
|
248
|
+
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
249
|
+
* marketParams.id,
|
|
250
|
+
* parseEther("0.9"),
|
|
251
|
+
* { timestamp: block.timestamp },
|
|
252
|
+
* );
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
getAvailableLiquidityToTargetUtilization(marketId: MarketId, targetUtilization?: bigint, options?: ReallocationComputeOptions): bigint;
|
|
162
256
|
/**
|
|
163
257
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
164
258
|
*
|
|
@@ -4,6 +4,7 @@ exports.ReallocationData = void 0;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const constant_js_1 = require("../helpers/constant.js");
|
|
7
|
+
const utilization_js_1 = require("../helpers/utilization.js");
|
|
7
8
|
const index_js_1 = require("../types/index.js");
|
|
8
9
|
/**
|
|
9
10
|
* Clones a market so simulated interest and liquidity changes never mutate caller input.
|
|
@@ -232,7 +233,7 @@ class ReallocationData {
|
|
|
232
233
|
* }).extend(morphoViemExtension());
|
|
233
234
|
*
|
|
234
235
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
235
|
-
* const market = client.morpho.
|
|
236
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
236
237
|
* const block = await client.getBlock();
|
|
237
238
|
* const reallocationData = await market.getReallocationData({
|
|
238
239
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -303,6 +304,116 @@ class ReallocationData {
|
|
|
303
304
|
});
|
|
304
305
|
}
|
|
305
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Sums the public-allocator liquidity reallocatable into `marketId` from
|
|
309
|
+
* sibling markets.
|
|
310
|
+
*
|
|
311
|
+
* Read-only metric — never throws on insufficiency (returns `0n`). Bounded by
|
|
312
|
+
* each source market's withdrawal utilization cap and the target market's
|
|
313
|
+
* vault supply-cap headroom. Pass `options.defaultMaxWithdrawalUtilization` to
|
|
314
|
+
* widen the source ceiling (e.g. `MathLib.WAD` for the full drain).
|
|
315
|
+
*
|
|
316
|
+
* @param marketId - Target market that would receive the liquidity.
|
|
317
|
+
* @param options - Optional allocator discovery options.
|
|
318
|
+
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
319
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* import { createPublicClient, http } from "viem";
|
|
323
|
+
* import { mainnet } from "viem/chains";
|
|
324
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
325
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
326
|
+
*
|
|
327
|
+
* const client = createPublicClient({
|
|
328
|
+
* chain: mainnet,
|
|
329
|
+
* transport: http(),
|
|
330
|
+
* }).extend(morphoViemExtension());
|
|
331
|
+
*
|
|
332
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
333
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
334
|
+
* const block = await client.getBlock();
|
|
335
|
+
* const reallocationData = await market.getReallocationData({
|
|
336
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
337
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* const liquidity: bigint = reallocationData.getPublicReallocationLiquidity(
|
|
341
|
+
* marketParams.id,
|
|
342
|
+
* { timestamp: block.timestamp },
|
|
343
|
+
* );
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
getPublicReallocationLiquidity(marketId, options) {
|
|
347
|
+
const { withdrawals } = this.getMarketPublicReallocations(marketId, options);
|
|
348
|
+
return withdrawals.reduce((total, { assets }) => total + assets, 0n);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Computes the liquidity available to bring `marketId` to `targetUtilization`,
|
|
352
|
+
* counting the public-allocator liquidity reallocatable into it.
|
|
353
|
+
*
|
|
354
|
+
* Returns the max borrow `x` keeping post-borrow utilization
|
|
355
|
+
* `(borrow + x) / (supply + L) ≤ targetUtilization`, where `L` is the
|
|
356
|
+
* reallocatable liquidity added to the market's supply — equivalently
|
|
357
|
+
* `getBorrowToUtilization({ supply + L, borrow }, targetUtilization)`. Below
|
|
358
|
+
* the target this is the market's own borrow headroom plus `targetUtilization · L`;
|
|
359
|
+
* reallocated supply also raises the supply denominator, so only that scaled
|
|
360
|
+
* share backs further borrow.
|
|
361
|
+
*
|
|
362
|
+
* Read-only metric — never throws on insufficiency:
|
|
363
|
+
* - returns only the market's own borrow headroom when
|
|
364
|
+
* `supplyTargetUtilization > targetUtilization` (reallocation would not
|
|
365
|
+
* trigger at that target);
|
|
366
|
+
* - returns `0n` when the market is already at or above the target and `L` is
|
|
367
|
+
* too small to bring it back under.
|
|
368
|
+
*
|
|
369
|
+
* @param marketId - Target market to borrow from.
|
|
370
|
+
* @param targetUtilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
371
|
+
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
372
|
+
* @returns Available liquidity to the target utilization in loan-token units; `0n` when none is available.
|
|
373
|
+
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts
|
|
376
|
+
* import { createPublicClient, http, parseEther } from "viem";
|
|
377
|
+
* import { mainnet } from "viem/chains";
|
|
378
|
+
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
379
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
380
|
+
*
|
|
381
|
+
* const client = createPublicClient({
|
|
382
|
+
* chain: mainnet,
|
|
383
|
+
* transport: http(),
|
|
384
|
+
* }).extend(morphoViemExtension());
|
|
385
|
+
*
|
|
386
|
+
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
387
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
388
|
+
* const block = await client.getBlock();
|
|
389
|
+
* const reallocationData = await market.getReallocationData({
|
|
390
|
+
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
391
|
+
* block: { number: block.number, timestamp: block.timestamp },
|
|
392
|
+
* });
|
|
393
|
+
*
|
|
394
|
+
* // Max borrow keeping utilization at or below 90%, counting shared liquidity.
|
|
395
|
+
* const available: bigint =
|
|
396
|
+
* reallocationData.getAvailableLiquidityToTargetUtilization(
|
|
397
|
+
* marketParams.id,
|
|
398
|
+
* parseEther("0.9"),
|
|
399
|
+
* { timestamp: block.timestamp },
|
|
400
|
+
* );
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
// biome-ignore lint/complexity/useMaxParams: (marketId, targetUtilization, options) is the metric's public API
|
|
404
|
+
getAvailableLiquidityToTargetUtilization(marketId, targetUtilization = constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION, options) {
|
|
405
|
+
const market = this.getMarket(marketId).accrueInterest(options?.timestamp);
|
|
406
|
+
// Below the allocator's trigger, no reallocation happens: own headroom only.
|
|
407
|
+
const supplyTargetUtilization = (0, utilization_js_1.getSupplyTargetUtilization)(marketId, options);
|
|
408
|
+
if (supplyTargetUtilization > targetUtilization)
|
|
409
|
+
return market.getBorrowToUtilization(targetUtilization);
|
|
410
|
+
// Borrow-to-target on the post-reallocation supply; clamps to 0n above target.
|
|
411
|
+
const availableLiquidity = this.getPublicReallocationLiquidity(marketId, options);
|
|
412
|
+
return blue_sdk_1.MarketUtils.getBorrowToUtilization({
|
|
413
|
+
totalSupplyAssets: market.totalSupplyAssets + availableLiquidity,
|
|
414
|
+
totalBorrowAssets: market.totalBorrowAssets,
|
|
415
|
+
}, targetUtilization);
|
|
416
|
+
}
|
|
306
417
|
/**
|
|
307
418
|
* Gets the largest currently valid source-market withdrawal for a vault.
|
|
308
419
|
*
|
|
@@ -62,7 +62,7 @@ class MorphoVaultV2 {
|
|
|
62
62
|
}
|
|
63
63
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
64
64
|
// Accrue interest forward to bound the on-chain share price at execution.
|
|
65
|
-
// Mirrors
|
|
65
|
+
// Mirrors blue repay's 2h forward-accrual buffer.
|
|
66
66
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
67
67
|
const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
|
|
68
68
|
const shares = accruedVault.toShares(totalAssets);
|
|
@@ -42,7 +42,7 @@ import { type ReallocationComputeOptions, type VaultReallocation } from "../type
|
|
|
42
42
|
*
|
|
43
43
|
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
44
44
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
45
|
-
* const market = client.morpho.
|
|
45
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
46
46
|
* const block = await client.getBlock();
|
|
47
47
|
* const reallocationData = await market.getReallocationData({
|
|
48
48
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.computeReallocations = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const index_js_1 = require("../types/index.js");
|
|
6
|
-
const
|
|
6
|
+
const utilization_js_1 = require("./utilization.js");
|
|
7
7
|
const validate_js_1 = require("./validate.js");
|
|
8
8
|
const groupWithdrawalsByVault = (withdrawals) => {
|
|
9
9
|
const groups = [];
|
|
@@ -98,7 +98,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
98
98
|
*
|
|
99
99
|
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
100
100
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
101
|
-
* const market = client.morpho.
|
|
101
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
102
102
|
* const block = await client.getBlock();
|
|
103
103
|
* const reallocationData = await market.getReallocationData({
|
|
104
104
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -145,9 +145,7 @@ const computeReallocations = ({ reallocationData: data, marketId, operation, amo
|
|
|
145
145
|
const newTotalSupplyAssets = operation === "withdraw"
|
|
146
146
|
? market.totalSupplyAssets - amount
|
|
147
147
|
: market.totalSupplyAssets;
|
|
148
|
-
const supplyTargetUtilization =
|
|
149
|
-
options?.defaultSupplyTargetUtilization ??
|
|
150
|
-
constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION;
|
|
148
|
+
const supplyTargetUtilization = (0, utilization_js_1.getSupplyTargetUtilization)(market.params.id, options);
|
|
151
149
|
if (blue_sdk_1.MarketUtils.getUtilization({
|
|
152
150
|
totalSupplyAssets: newTotalSupplyAssets,
|
|
153
151
|
totalBorrowAssets: newTotalBorrowAssets,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { ReallocationComputeOptions } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the effective supply target utilization for a market: the per-market
|
|
5
|
+
* override, then the global default override, then
|
|
6
|
+
* {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
7
|
+
*
|
|
8
|
+
* @param marketId - The market whose supply target utilization to resolve.
|
|
9
|
+
* @param options - Reallocation options carrying the per-market and default overrides.
|
|
10
|
+
* @returns The supply target utilization, scaled by WAD.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getSupplyTargetUtilization: (marketId: MarketId, options?: ReallocationComputeOptions) => bigint;
|