@morpho-org/blue-sdk 6.0.1 → 6.2.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/lib/cjs/addresses.d.ts +225 -0
- package/lib/cjs/addresses.js +140 -0
- package/lib/cjs/chain.d.ts +108 -1
- package/lib/cjs/chain.js +94 -0
- package/lib/cjs/errors.d.ts +39 -0
- package/lib/cjs/errors.js +38 -1
- package/lib/cjs/holding/AssetBalances.d.ts +3 -0
- package/lib/cjs/holding/AssetBalances.js +1 -0
- package/lib/cjs/holding/Holding.d.ts +6 -0
- package/lib/cjs/holding/Holding.js +2 -0
- package/lib/cjs/market/Market.d.ts +4 -0
- package/lib/cjs/market/MarketParams.d.ts +3 -0
- package/lib/cjs/market/MarketParams.js +1 -0
- package/lib/cjs/market/MarketUtils.d.ts +397 -0
- package/lib/cjs/market/MarketUtils.js +397 -2
- package/lib/cjs/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/cjs/math/AdaptiveCurveIrmLib.js +52 -2
- package/lib/cjs/math/MathLib.d.ts +152 -4
- package/lib/cjs/math/MathLib.js +151 -4
- package/lib/cjs/math/SharesMath.d.ts +34 -0
- package/lib/cjs/math/SharesMath.js +34 -0
- package/lib/cjs/position/Position.d.ts +4 -0
- package/lib/cjs/position/Position.js +2 -0
- package/lib/cjs/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/cjs/position/PreLiquidationPosition.js +2 -0
- package/lib/cjs/preLiquidation.d.ts +16 -0
- package/lib/cjs/preLiquidation.js +16 -0
- package/lib/cjs/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ConstantWrappedToken.js +1 -0
- package/lib/cjs/token/Eip5267Domain.d.ts +4 -0
- package/lib/cjs/token/Eip5267Domain.js +2 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/cjs/token/Token.d.ts +2 -0
- package/lib/cjs/token/Token.js +1 -0
- package/lib/cjs/token/VaultToken.d.ts +2 -0
- package/lib/cjs/token/VaultToken.js +1 -0
- package/lib/cjs/token/WrappedToken.d.ts +1 -0
- package/lib/cjs/token/WrappedToken.js +1 -0
- package/lib/cjs/types.d.ts +17 -0
- package/lib/cjs/types.js +13 -0
- package/lib/cjs/user/User.d.ts +1 -0
- package/lib/cjs/user/User.js +1 -0
- package/lib/cjs/utils.d.ts +2 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/vault/Vault.d.ts +9 -0
- package/lib/cjs/vault/Vault.js +14 -1
- package/lib/cjs/vault/VaultConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketAllocation.js +1 -0
- package/lib/cjs/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/cjs/vault/VaultUser.d.ts +2 -0
- package/lib/cjs/vault/VaultUser.js +1 -0
- package/lib/cjs/vault/VaultUtils.d.ts +49 -0
- package/lib/cjs/vault/VaultUtils.js +51 -2
- package/lib/cjs/vault/v2/VaultV2.d.ts +5 -0
- package/lib/cjs/vault/v2/VaultV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/lib/esm/addresses.d.ts +225 -0
- package/lib/esm/addresses.js +140 -0
- package/lib/esm/chain.d.ts +108 -1
- package/lib/esm/chain.js +94 -0
- package/lib/esm/errors.d.ts +39 -0
- package/lib/esm/errors.js +36 -0
- package/lib/esm/holding/AssetBalances.d.ts +3 -0
- package/lib/esm/holding/AssetBalances.js +1 -0
- package/lib/esm/holding/Holding.d.ts +6 -0
- package/lib/esm/holding/Holding.js +2 -0
- package/lib/esm/market/Market.d.ts +4 -0
- package/lib/esm/market/MarketParams.d.ts +3 -0
- package/lib/esm/market/MarketParams.js +1 -0
- package/lib/esm/market/MarketUtils.d.ts +397 -0
- package/lib/esm/market/MarketUtils.js +397 -2
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/esm/math/AdaptiveCurveIrmLib.js +52 -2
- package/lib/esm/math/MathLib.d.ts +152 -4
- package/lib/esm/math/MathLib.js +151 -4
- package/lib/esm/math/SharesMath.d.ts +34 -0
- package/lib/esm/math/SharesMath.js +34 -0
- package/lib/esm/position/Position.d.ts +4 -0
- package/lib/esm/position/Position.js +2 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/esm/position/PreLiquidationPosition.js +2 -0
- package/lib/esm/preLiquidation.d.ts +16 -0
- package/lib/esm/preLiquidation.js +16 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/esm/token/ConstantWrappedToken.js +1 -0
- package/lib/esm/token/Eip5267Domain.d.ts +4 -0
- package/lib/esm/token/Eip5267Domain.js +2 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/esm/token/Token.d.ts +2 -0
- package/lib/esm/token/Token.js +1 -0
- package/lib/esm/token/VaultToken.d.ts +2 -0
- package/lib/esm/token/VaultToken.js +1 -0
- package/lib/esm/token/WrappedToken.d.ts +1 -0
- package/lib/esm/token/WrappedToken.js +1 -0
- package/lib/esm/types.d.ts +17 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +1 -0
- package/lib/esm/user/User.js +1 -0
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +1 -0
- package/lib/esm/vault/Vault.d.ts +9 -0
- package/lib/esm/vault/Vault.js +14 -1
- package/lib/esm/vault/VaultConfig.d.ts +2 -0
- package/lib/esm/vault/VaultConfig.js +1 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/esm/vault/VaultMarketAllocation.js +1 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/esm/vault/VaultMarketConfig.js +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/esm/vault/VaultUser.d.ts +2 -0
- package/lib/esm/vault/VaultUser.js +1 -0
- package/lib/esm/vault/VaultUtils.d.ts +49 -0
- package/lib/esm/vault/VaultUtils.js +51 -2
- package/lib/esm/vault/v2/VaultV2.d.ts +5 -0
- package/lib/esm/vault/v2/VaultV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/package.json +4 -4
|
@@ -8,13 +8,47 @@ const MathLib_js_1 = require("./MathLib.js");
|
|
|
8
8
|
*/
|
|
9
9
|
var SharesMath;
|
|
10
10
|
(function (SharesMath) {
|
|
11
|
+
/** Virtual shares added to Morpho Blue and ERC-4626 share conversions. */
|
|
11
12
|
SharesMath.VIRTUAL_SHARES = 1000000n;
|
|
13
|
+
/** Virtual assets added to Morpho Blue and ERC-4626 asset conversions. */
|
|
12
14
|
SharesMath.VIRTUAL_ASSETS = 1n;
|
|
15
|
+
/**
|
|
16
|
+
* Converts shares to assets using Morpho virtual shares and assets.
|
|
17
|
+
*
|
|
18
|
+
* @param shares - The amount of shares.
|
|
19
|
+
* @param totalAssets - The total assets before conversion.
|
|
20
|
+
* @param totalShares - The total shares before conversion.
|
|
21
|
+
* @param rounding - The rounding direction.
|
|
22
|
+
* @returns The equivalent amount of assets.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { SharesMath } from "@morpho-org/blue-sdk";
|
|
26
|
+
*
|
|
27
|
+
* const assets = SharesMath.toAssets(100n, 1_000n, 100n, "Down");
|
|
28
|
+
* // assets satisfies bigint
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
13
31
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
14
32
|
function toAssets(shares, totalAssets, totalShares, rounding) {
|
|
15
33
|
return MathLib_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, rounding);
|
|
16
34
|
}
|
|
17
35
|
SharesMath.toAssets = toAssets;
|
|
36
|
+
/**
|
|
37
|
+
* Converts assets to shares using Morpho virtual shares and assets.
|
|
38
|
+
*
|
|
39
|
+
* @param assets - The amount of assets.
|
|
40
|
+
* @param totalAssets - The total assets before conversion.
|
|
41
|
+
* @param totalShares - The total shares before conversion.
|
|
42
|
+
* @param rounding - The rounding direction.
|
|
43
|
+
* @returns The equivalent amount of shares.
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { SharesMath } from "@morpho-org/blue-sdk";
|
|
47
|
+
*
|
|
48
|
+
* const shares = SharesMath.toShares(100n, 1_000n, 100n, "Up");
|
|
49
|
+
* // shares satisfies bigint
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
18
52
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
19
53
|
function toShares(assets, totalAssets, totalShares, rounding) {
|
|
20
54
|
return MathLib_js_1.MathLib.mulDiv(assets, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, rounding);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type IMarket, Market, type MaxBorrowOptions, type MaxPositionCapacities, type MaxWithdrawCollateralOptions } from "../market/index.js";
|
|
2
2
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
3
|
+
/** Plain input shape for a user's Morpho Blue market position. */
|
|
3
4
|
export interface IPosition {
|
|
4
5
|
user: Address;
|
|
5
6
|
marketId: MarketId;
|
|
@@ -7,6 +8,7 @@ export interface IPosition {
|
|
|
7
8
|
borrowShares: bigint;
|
|
8
9
|
collateral: bigint;
|
|
9
10
|
}
|
|
11
|
+
/** Represents a user's supply, borrow, and collateral balances on one market. */
|
|
10
12
|
export declare class Position implements IPosition {
|
|
11
13
|
/**
|
|
12
14
|
* The user holding this position.
|
|
@@ -30,8 +32,10 @@ export declare class Position implements IPosition {
|
|
|
30
32
|
collateral: bigint;
|
|
31
33
|
constructor({ user, marketId, supplyShares, borrowShares, collateral, }: IPosition);
|
|
32
34
|
}
|
|
35
|
+
/** Plain input shape for a position paired with market state for accrual math. */
|
|
33
36
|
export interface IAccrualPosition extends Omit<IPosition, "marketId"> {
|
|
34
37
|
}
|
|
38
|
+
/** Represents a position paired with market state for derived and accrued values. */
|
|
35
39
|
export declare class AccrualPosition extends Position implements IAccrualPosition {
|
|
36
40
|
protected readonly _market: Market;
|
|
37
41
|
constructor(position: IAccrualPosition, market: IMarket);
|
|
@@ -5,6 +5,7 @@ const errors_js_1 = require("../errors.js");
|
|
|
5
5
|
const index_js_1 = require("../market/index.js");
|
|
6
6
|
const MathLib_js_1 = require("../math/MathLib.js");
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
|
+
/** Represents a user's supply, borrow, and collateral balances on one market. */
|
|
8
9
|
class Position {
|
|
9
10
|
/**
|
|
10
11
|
* The user holding this position.
|
|
@@ -35,6 +36,7 @@ class Position {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.Position = Position;
|
|
39
|
+
/** Represents a position paired with market state for derived and accrued values. */
|
|
38
40
|
class AccrualPosition extends Position {
|
|
39
41
|
_market;
|
|
40
42
|
constructor(position, market) {
|
|
@@ -2,6 +2,7 @@ import type { Address } from "viem";
|
|
|
2
2
|
import { type IMarket, Market } from "../market/index.js";
|
|
3
3
|
import type { BigIntish } from "../types.js";
|
|
4
4
|
import { AccrualPosition, type IAccrualPosition } from "./Position.js";
|
|
5
|
+
/** Plain input shape for PreLiquidation contract parameters. */
|
|
5
6
|
export interface IPreLiquidationParams {
|
|
6
7
|
preLltv: BigIntish;
|
|
7
8
|
preLCF1: BigIntish;
|
|
@@ -10,6 +11,7 @@ export interface IPreLiquidationParams {
|
|
|
10
11
|
preLIF2: BigIntish;
|
|
11
12
|
preLiquidationOracle: Address;
|
|
12
13
|
}
|
|
14
|
+
/** Represents PreLiquidation contract parameters and factor interpolation helpers. */
|
|
13
15
|
export declare class PreLiquidationParams implements IPreLiquidationParams {
|
|
14
16
|
readonly preLltv: bigint;
|
|
15
17
|
readonly preLCF1: bigint;
|
|
@@ -21,6 +23,7 @@ export declare class PreLiquidationParams implements IPreLiquidationParams {
|
|
|
21
23
|
getCloseFactor(quotient: BigIntish): bigint;
|
|
22
24
|
getIncentiveFactor(quotient: BigIntish): bigint;
|
|
23
25
|
}
|
|
26
|
+
/** Plain input shape for a position associated with a PreLiquidation contract. */
|
|
24
27
|
export interface IPreLiquidationPosition extends IAccrualPosition {
|
|
25
28
|
/**
|
|
26
29
|
* The pre-liquidation parameters of the associated PreLiquidation contract.
|
|
@@ -36,6 +39,7 @@ export interface IPreLiquidationPosition extends IAccrualPosition {
|
|
|
36
39
|
*/
|
|
37
40
|
preLiquidationOraclePrice?: BigIntish;
|
|
38
41
|
}
|
|
42
|
+
/** Represents a position evaluated under PreLiquidation-specific risk parameters. */
|
|
39
43
|
export declare class PreLiquidationPosition extends AccrualPosition implements IPreLiquidationPosition {
|
|
40
44
|
readonly preLiquidationParams: PreLiquidationParams;
|
|
41
45
|
readonly preLiquidation: `0x${string}`;
|
|
@@ -5,6 +5,7 @@ const constants_js_1 = require("../constants.js");
|
|
|
5
5
|
const index_js_1 = require("../market/index.js");
|
|
6
6
|
const index_js_2 = require("../math/index.js");
|
|
7
7
|
const Position_js_1 = require("./Position.js");
|
|
8
|
+
/** Represents PreLiquidation contract parameters and factor interpolation helpers. */
|
|
8
9
|
class PreLiquidationParams {
|
|
9
10
|
preLltv;
|
|
10
11
|
preLCF1;
|
|
@@ -28,6 +29,7 @@ class PreLiquidationParams {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
exports.PreLiquidationParams = PreLiquidationParams;
|
|
32
|
+
/** Represents a position evaluated under PreLiquidation-specific risk parameters. */
|
|
31
33
|
class PreLiquidationPosition extends Position_js_1.AccrualPosition {
|
|
32
34
|
preLiquidationParams;
|
|
33
35
|
preLiquidation;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BigIntish } from "./types.js";
|
|
2
|
+
/** Default PreLiquidation parameter registry keyed by Morpho Blue LLTV. */
|
|
2
3
|
export declare const defaultPreLiquidationParamsRegistry: Map<bigint, {
|
|
3
4
|
preLltv: bigint;
|
|
4
5
|
preLCF1: bigint;
|
|
@@ -6,6 +7,21 @@ export declare const defaultPreLiquidationParamsRegistry: Map<bigint, {
|
|
|
6
7
|
preLIF1: bigint;
|
|
7
8
|
preLIF2: bigint;
|
|
8
9
|
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns default PreLiquidation params for a supported Morpho Blue LLTV.
|
|
12
|
+
*
|
|
13
|
+
* @param lltv - The Morpho Blue liquidation loan-to-value, scaled by WAD.
|
|
14
|
+
* @returns The default PreLiquidation parameter set for `lltv`.
|
|
15
|
+
* @throws {UnsupportedPreLiquidationParamsError} when no default parameters exist for `lltv`.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { getDefaultPreLiquidationParams } from "@morpho-org/blue-sdk";
|
|
19
|
+
* import { parseEther } from "viem";
|
|
20
|
+
*
|
|
21
|
+
* const params = getDefaultPreLiquidationParams(parseEther("0.86"));
|
|
22
|
+
* // params satisfies { preLltv: bigint; preLCF1: bigint; preLCF2: bigint; preLIF1: bigint; preLIF2: bigint }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
9
25
|
export declare const getDefaultPreLiquidationParams: (lltv: BigIntish) => {
|
|
10
26
|
preLltv: bigint;
|
|
11
27
|
preLCF1: bigint;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDefaultPreLiquidationParams = exports.defaultPreLiquidationParamsRegistry = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
|
+
/** Default PreLiquidation parameter registry keyed by Morpho Blue LLTV. */
|
|
6
7
|
exports.defaultPreLiquidationParamsRegistry = new Map([
|
|
7
8
|
[
|
|
8
9
|
(0, viem_1.parseEther)("0.385"),
|
|
@@ -85,6 +86,21 @@ exports.defaultPreLiquidationParamsRegistry = new Map([
|
|
|
85
86
|
},
|
|
86
87
|
],
|
|
87
88
|
]);
|
|
89
|
+
/**
|
|
90
|
+
* Returns default PreLiquidation params for a supported Morpho Blue LLTV.
|
|
91
|
+
*
|
|
92
|
+
* @param lltv - The Morpho Blue liquidation loan-to-value, scaled by WAD.
|
|
93
|
+
* @returns The default PreLiquidation parameter set for `lltv`.
|
|
94
|
+
* @throws {UnsupportedPreLiquidationParamsError} when no default parameters exist for `lltv`.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { getDefaultPreLiquidationParams } from "@morpho-org/blue-sdk";
|
|
98
|
+
* import { parseEther } from "viem";
|
|
99
|
+
*
|
|
100
|
+
* const params = getDefaultPreLiquidationParams(parseEther("0.86"));
|
|
101
|
+
* // params satisfies { preLltv: bigint; preLCF1: bigint; preLCF2: bigint; preLIF1: bigint; preLIF2: bigint }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
88
104
|
const getDefaultPreLiquidationParams = (lltv) => {
|
|
89
105
|
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
90
106
|
lltv = BigInt(lltv);
|
|
@@ -2,6 +2,7 @@ import { type RoundingDirection } from "../math/index.js";
|
|
|
2
2
|
import type { Address, BigIntish } from "../types.js";
|
|
3
3
|
import type { IToken } from "./Token.js";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
+
/** Represents a wrapped token with a constant decimals-based conversion rate. */
|
|
5
6
|
export declare class ConstantWrappedToken extends WrappedToken {
|
|
6
7
|
readonly underlyingDecimals: bigint;
|
|
7
8
|
constructor(token: IToken, underlying: Address, underlyingDecimals?: BigIntish);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConstantWrappedToken = void 0;
|
|
4
4
|
const index_js_1 = require("../math/index.js");
|
|
5
5
|
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
|
+
/** Represents a wrapped token with a constant decimals-based conversion rate. */
|
|
6
7
|
class ConstantWrappedToken extends WrappedToken_js_1.WrappedToken {
|
|
7
8
|
underlyingDecimals;
|
|
8
9
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Address } from "../types.js";
|
|
2
|
+
/** Ordered EIP-712 domain fields exposed by EIP-5267. */
|
|
2
3
|
export declare const EIP_712_FIELDS: readonly ["name", "version", "chainId", "verifyingContract", "salt"];
|
|
4
|
+
/** EIP-712 domain field name exposed by EIP-5267. */
|
|
3
5
|
export type Eip712Field = (typeof EIP_712_FIELDS)[number];
|
|
6
|
+
/** Plain input shape for an EIP-5267 signing domain. */
|
|
4
7
|
export interface IEip5267Domain {
|
|
5
8
|
fields: `0x${string}`;
|
|
6
9
|
name: string;
|
|
@@ -10,6 +13,7 @@ export interface IEip5267Domain {
|
|
|
10
13
|
salt: `0x${string}`;
|
|
11
14
|
extensions: readonly bigint[];
|
|
12
15
|
}
|
|
16
|
+
/** Represents an EIP-5267 signing domain and derived EIP-712 domain object. */
|
|
13
17
|
export declare class Eip5267Domain implements IEip5267Domain {
|
|
14
18
|
/**
|
|
15
19
|
* A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Eip5267Domain = exports.EIP_712_FIELDS = void 0;
|
|
4
|
+
/** Ordered EIP-712 domain fields exposed by EIP-5267. */
|
|
4
5
|
exports.EIP_712_FIELDS = [
|
|
5
6
|
"name",
|
|
6
7
|
"version",
|
|
@@ -8,6 +9,7 @@ exports.EIP_712_FIELDS = [
|
|
|
8
9
|
"verifyingContract",
|
|
9
10
|
"salt",
|
|
10
11
|
];
|
|
12
|
+
/** Represents an EIP-5267 signing domain and derived EIP-712 domain object. */
|
|
11
13
|
class Eip5267Domain {
|
|
12
14
|
/**
|
|
13
15
|
* A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4).
|
|
@@ -2,6 +2,7 @@ import { type RoundingDirection } from "../math/index.js";
|
|
|
2
2
|
import type { Address } from "../types.js";
|
|
3
3
|
import type { IToken } from "./Token.js";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
+
/** Represents a wrapped token whose conversion uses a WAD-scaled exchange rate. */
|
|
5
6
|
export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
6
7
|
readonly underlying: Address;
|
|
7
8
|
wrappedTokenExchangeRate: bigint;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExchangeRateWrappedToken = void 0;
|
|
4
4
|
const index_js_1 = require("../math/index.js");
|
|
5
5
|
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
|
+
/** Represents a wrapped token whose conversion uses a WAD-scaled exchange rate. */
|
|
6
7
|
class ExchangeRateWrappedToken extends WrappedToken_js_1.WrappedToken {
|
|
7
8
|
underlying;
|
|
8
9
|
wrappedTokenExchangeRate;
|
package/lib/cjs/token/Token.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type ChainId } from "../chain.js";
|
|
|
2
2
|
import { type RoundingDirection } from "../math/index.js";
|
|
3
3
|
import type { Address, BigIntish } from "../types.js";
|
|
4
4
|
import type { Eip5267Domain } from "./Eip5267Domain.js";
|
|
5
|
+
/** Plain input shape for an ERC-20-like token. */
|
|
5
6
|
export interface IToken {
|
|
6
7
|
address: Address;
|
|
7
8
|
name?: string;
|
|
@@ -10,6 +11,7 @@ export interface IToken {
|
|
|
10
11
|
price?: BigIntish;
|
|
11
12
|
eip5267Domain?: Eip5267Domain;
|
|
12
13
|
}
|
|
14
|
+
/** Represents an ERC-20-like token and optional price/signing metadata. */
|
|
13
15
|
export declare class Token implements IToken {
|
|
14
16
|
static native(chainId: ChainId): Token;
|
|
15
17
|
/**
|
package/lib/cjs/token/Token.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Token = void 0;
|
|
|
4
4
|
const addresses_js_1 = require("../addresses.js");
|
|
5
5
|
const chain_js_1 = require("../chain.js");
|
|
6
6
|
const index_js_1 = require("../math/index.js");
|
|
7
|
+
/** Represents an ERC-20-like token and optional price/signing metadata. */
|
|
7
8
|
class Token {
|
|
8
9
|
static native(chainId) {
|
|
9
10
|
const currency = chain_js_1.ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
@@ -2,10 +2,12 @@ import type { RoundingDirection } from "../math/index.js";
|
|
|
2
2
|
import type { Address, BigIntish } from "../types.js";
|
|
3
3
|
import type { IVaultConfig } from "../vault/VaultConfig.js";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
+
/** Plain input shape for ERC-4626-like vault token totals. */
|
|
5
6
|
export interface IVaultToken {
|
|
6
7
|
totalAssets: bigint;
|
|
7
8
|
totalSupply: bigint;
|
|
8
9
|
}
|
|
10
|
+
/** Represents an ERC-4626-like vault token with share and asset conversion math. */
|
|
9
11
|
export declare class VaultToken extends WrappedToken implements IVaultToken {
|
|
10
12
|
readonly asset: Address;
|
|
11
13
|
readonly decimalsOffset: bigint;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VaultToken = void 0;
|
|
4
4
|
const VaultUtils_js_1 = require("../vault/VaultUtils.js");
|
|
5
5
|
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
|
+
/** Represents an ERC-4626-like vault token with share and asset conversion math. */
|
|
6
7
|
class VaultToken extends WrappedToken_js_1.WrappedToken {
|
|
7
8
|
asset;
|
|
8
9
|
decimalsOffset;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { Address } from "../types.js";
|
|
3
3
|
import { type IToken, Token } from "./Token.js";
|
|
4
|
+
/** Base class for tokens that wrap and unwrap another token. */
|
|
4
5
|
export declare abstract class WrappedToken extends Token {
|
|
5
6
|
readonly underlying: Address;
|
|
6
7
|
constructor(token: IToken, underlying: Address);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WrappedToken = void 0;
|
|
4
4
|
const index_js_1 = require("../math/index.js");
|
|
5
5
|
const Token_js_1 = require("./Token.js");
|
|
6
|
+
/** Base class for tokens that wrap and unwrap another token. */
|
|
6
7
|
class WrappedToken extends Token_js_1.Token {
|
|
7
8
|
underlying;
|
|
8
9
|
constructor(token, underlying) {
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type Address = `0x${string}`;
|
|
|
8
8
|
export type MarketId = `0x${string}` & {
|
|
9
9
|
__TYPE__: "marketId";
|
|
10
10
|
};
|
|
11
|
+
/** Primitive values accepted at SDK boundaries and normalized to `bigint`. */
|
|
11
12
|
export type BigIntish = bigint | string | number | boolean;
|
|
12
13
|
/**
|
|
13
14
|
* The possible transaction type on the Blue contract
|
|
@@ -20,7 +21,23 @@ export declare enum TransactionType {
|
|
|
20
21
|
Borrow = "Borrow",
|
|
21
22
|
Repay = "Repay"
|
|
22
23
|
}
|
|
24
|
+
/** Value that may not have been loaded yet. */
|
|
23
25
|
export type Loadable<T> = T | undefined;
|
|
26
|
+
/** Value that may fail to resolve. */
|
|
24
27
|
export type Failable<T> = T | null;
|
|
28
|
+
/** Value that may be unloaded or fail to resolve. */
|
|
25
29
|
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Checks whether a value is a 32-byte Morpho Blue market id.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The unknown value to inspect.
|
|
34
|
+
* @returns `true` when `value` is a `0x`-prefixed 32-byte hex string.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { isMarketId } from "@morpho-org/blue-sdk";
|
|
38
|
+
*
|
|
39
|
+
* const valid = isMarketId("0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
40
|
+
* // valid satisfies boolean
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
26
43
|
export declare const isMarketId: (value: unknown) => value is MarketId;
|
package/lib/cjs/types.js
CHANGED
|
@@ -13,5 +13,18 @@ var TransactionType;
|
|
|
13
13
|
TransactionType["Borrow"] = "Borrow";
|
|
14
14
|
TransactionType["Repay"] = "Repay";
|
|
15
15
|
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether a value is a 32-byte Morpho Blue market id.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The unknown value to inspect.
|
|
20
|
+
* @returns `true` when `value` is a `0x`-prefixed 32-byte hex string.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { isMarketId } from "@morpho-org/blue-sdk";
|
|
24
|
+
*
|
|
25
|
+
* const valid = isMarketId("0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
26
|
+
* // valid satisfies boolean
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
16
29
|
const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
17
30
|
exports.isMarketId = isMarketId;
|
package/lib/cjs/user/User.d.ts
CHANGED
package/lib/cjs/user/User.js
CHANGED
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Reason why a capacity calculation is capped. */
|
|
1
2
|
export declare enum CapacityLimitReason {
|
|
2
3
|
liquidity = "Liquidity",
|
|
3
4
|
balance = "Balance",
|
|
@@ -7,6 +8,7 @@ export declare enum CapacityLimitReason {
|
|
|
7
8
|
vaultV2_absoluteCap = "VaultV2_AbsoluteCap",
|
|
8
9
|
vaultV2_relativeCap = "VaultV2_RelativeCap"
|
|
9
10
|
}
|
|
11
|
+
/** Bounded capacity value and the reason for the bound. */
|
|
10
12
|
export interface CapacityLimit {
|
|
11
13
|
value: bigint;
|
|
12
14
|
limiter: CapacityLimitReason;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CapacityLimitReason = void 0;
|
|
4
|
+
/** Reason why a capacity calculation is capped. */
|
|
4
5
|
var CapacityLimitReason;
|
|
5
6
|
(function (CapacityLimitReason) {
|
|
6
7
|
CapacityLimitReason["liquidity"] = "Liquidity";
|
package/lib/cjs/vault/Vault.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ import type { Address, BigIntish, MarketId } from "../types.js";
|
|
|
4
4
|
import { type CapacityLimit } from "../utils.js";
|
|
5
5
|
import type { IVaultConfig } from "./VaultConfig.js";
|
|
6
6
|
import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
|
|
7
|
+
/** Pending governance value and the timestamp at which it becomes valid. */
|
|
7
8
|
export interface Pending<T> {
|
|
8
9
|
value: T;
|
|
9
10
|
validAt: bigint;
|
|
10
11
|
}
|
|
12
|
+
/** PublicAllocator configuration attached to a MetaMorpho vault. */
|
|
11
13
|
export interface VaultPublicAllocatorConfig {
|
|
12
14
|
/**
|
|
13
15
|
* The PublicAllocator's admin address.
|
|
@@ -22,6 +24,7 @@ export interface VaultPublicAllocatorConfig {
|
|
|
22
24
|
*/
|
|
23
25
|
accruedFee: bigint;
|
|
24
26
|
}
|
|
27
|
+
/** Plain input shape for a MetaMorpho vault. */
|
|
25
28
|
export interface IVault extends IVaultConfig {
|
|
26
29
|
curator: Address;
|
|
27
30
|
owner: Address;
|
|
@@ -41,6 +44,7 @@ export interface IVault extends IVaultConfig {
|
|
|
41
44
|
lostAssets?: bigint;
|
|
42
45
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
43
46
|
}
|
|
47
|
+
/** Represents a MetaMorpho vault and its governance, queue, and accounting state. */
|
|
44
48
|
export declare class Vault extends VaultToken implements IVault {
|
|
45
49
|
/**
|
|
46
50
|
* The vault's share token's name.
|
|
@@ -119,6 +123,7 @@ export declare class Vault extends VaultToken implements IVault {
|
|
|
119
123
|
toAssets(shares: BigIntish, rounding?: RoundingDirection): bigint;
|
|
120
124
|
toShares(assets: BigIntish, rounding?: RoundingDirection): bigint;
|
|
121
125
|
}
|
|
126
|
+
/** Aggregated vault allocation exposure for one collateral asset. */
|
|
122
127
|
export interface CollateralAllocation {
|
|
123
128
|
address: Address;
|
|
124
129
|
lltvs: Set<bigint>;
|
|
@@ -126,8 +131,10 @@ export interface CollateralAllocation {
|
|
|
126
131
|
markets: Set<MarketId>;
|
|
127
132
|
proportion: bigint;
|
|
128
133
|
}
|
|
134
|
+
/** Plain input shape for a MetaMorpho vault paired with accrued market allocations. */
|
|
129
135
|
export interface IAccrualVault extends Omit<IVault, "withdrawQueue" | "totalAssets"> {
|
|
130
136
|
}
|
|
137
|
+
/** Represents a MetaMorpho vault with accrued market allocation state. */
|
|
131
138
|
export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
132
139
|
/**
|
|
133
140
|
* @inheritdoc
|
|
@@ -209,6 +216,8 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
|
209
216
|
/**
|
|
210
217
|
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
211
218
|
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
219
|
+
* @returns A new vault whose market positions and fee accounting reflect accrued interest.
|
|
220
|
+
* @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
|
|
212
221
|
*/
|
|
213
222
|
accrueInterest(timestamp?: BigIntish): AccrualVault;
|
|
214
223
|
}
|
package/lib/cjs/vault/Vault.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVault = exports.Vault = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
5
6
|
const index_js_1 = require("../market/index.js");
|
|
6
7
|
const index_js_2 = require("../math/index.js");
|
|
7
8
|
const index_js_3 = require("../token/index.js");
|
|
8
9
|
const utils_js_1 = require("../utils.js");
|
|
9
10
|
const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
|
|
11
|
+
/** Represents a MetaMorpho vault and its governance, queue, and accounting state. */
|
|
10
12
|
class Vault extends index_js_3.VaultToken {
|
|
11
13
|
/**
|
|
12
14
|
* The MetaMorpho vault's owner address.
|
|
@@ -104,6 +106,7 @@ class Vault extends index_js_3.VaultToken {
|
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
exports.Vault = Vault;
|
|
109
|
+
/** Represents a MetaMorpho vault with accrued market allocation state. */
|
|
107
110
|
class AccrualVault extends Vault {
|
|
108
111
|
/**
|
|
109
112
|
* The allocation of the vault on each market enabled.
|
|
@@ -268,12 +271,22 @@ class AccrualVault extends Vault {
|
|
|
268
271
|
/**
|
|
269
272
|
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
270
273
|
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
274
|
+
* @returns A new vault whose market positions and fee accounting reflect accrued interest.
|
|
275
|
+
* @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
|
|
271
276
|
*/
|
|
272
277
|
accrueInterest(timestamp) {
|
|
273
278
|
const vault = new AccrualVault(this,
|
|
274
279
|
// Keep withdraw queue order.
|
|
275
280
|
this.withdrawQueue.map((marketId) => {
|
|
276
|
-
const
|
|
281
|
+
const allocation = this.allocations.get(marketId);
|
|
282
|
+
// Fail loudly rather than silently dropping the market: a stale
|
|
283
|
+
// `withdrawQueue` entry (e.g., one mutated after construction to
|
|
284
|
+
// reference a market that is no longer allocated) would otherwise
|
|
285
|
+
// crash with an opaque "Cannot destructure property 'config' of
|
|
286
|
+
// 'undefined'" via the non-null assertion below.
|
|
287
|
+
if (allocation == null)
|
|
288
|
+
throw new errors_js_1.UnknownMarketAllocationError(marketId);
|
|
289
|
+
const { config, position } = allocation;
|
|
277
290
|
return {
|
|
278
291
|
config,
|
|
279
292
|
position: position.accrueInterest(timestamp),
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type IToken, Token } from "../token/Token.js";
|
|
2
2
|
import type { Address, BigIntish } from "../types.js";
|
|
3
|
+
/** Plain input shape for immutable MetaMorpho vault token configuration. */
|
|
3
4
|
export interface IVaultConfig extends Omit<IToken, "decimals"> {
|
|
4
5
|
decimalsOffset: BigIntish;
|
|
5
6
|
asset: Address;
|
|
6
7
|
}
|
|
8
|
+
/** Represents immutable MetaMorpho vault token configuration. */
|
|
7
9
|
export declare class VaultConfig extends Token implements IVaultConfig {
|
|
8
10
|
readonly decimalsOffset: bigint;
|
|
9
11
|
readonly asset: `0x${string}`;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultConfig = void 0;
|
|
4
4
|
const Token_js_1 = require("../token/Token.js");
|
|
5
|
+
/** Represents immutable MetaMorpho vault token configuration. */
|
|
5
6
|
class VaultConfig extends Token_js_1.Token {
|
|
6
7
|
decimalsOffset;
|
|
7
8
|
asset;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AccrualPosition } from "../position/index.js";
|
|
2
2
|
import { type IVaultMarketConfig, VaultMarketConfig } from "./VaultMarketConfig.js";
|
|
3
|
+
/** Plain input shape for a vault allocation on one Morpho Blue market. */
|
|
3
4
|
export interface IVaultMarketAllocation {
|
|
4
5
|
config: IVaultMarketConfig;
|
|
5
6
|
position: AccrualPosition;
|
|
6
7
|
}
|
|
8
|
+
/** Represents a vault allocation on one Morpho Blue market. */
|
|
7
9
|
export declare class VaultMarketAllocation implements IVaultMarketAllocation {
|
|
8
10
|
/**
|
|
9
11
|
* The vault's configuration on the corresponding market.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VaultMarketAllocation = void 0;
|
|
4
4
|
const index_js_1 = require("../math/index.js");
|
|
5
5
|
const VaultMarketConfig_js_1 = require("./VaultMarketConfig.js");
|
|
6
|
+
/** Represents a vault allocation on one Morpho Blue market. */
|
|
6
7
|
class VaultMarketAllocation {
|
|
7
8
|
/**
|
|
8
9
|
* The vault's configuration on the corresponding market.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Address, MarketId } from "../types.js";
|
|
2
2
|
import type { Pending } from "./Vault.js";
|
|
3
3
|
import type { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig.js";
|
|
4
|
+
/** Plain input shape for a vault's configuration on one Morpho Blue market. */
|
|
4
5
|
export interface IVaultMarketConfig {
|
|
5
6
|
vault: Address;
|
|
6
7
|
marketId: MarketId;
|
|
@@ -10,6 +11,7 @@ export interface IVaultMarketConfig {
|
|
|
10
11
|
enabled: boolean;
|
|
11
12
|
publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
12
13
|
}
|
|
14
|
+
/** Represents a vault's configuration on one Morpho Blue market. */
|
|
13
15
|
export declare class VaultMarketConfig implements IVaultMarketConfig {
|
|
14
16
|
/**
|
|
15
17
|
* The vault's address.
|
|
@@ -8,6 +8,7 @@ export interface IVaultMarketPublicAllocatorConfig {
|
|
|
8
8
|
maxIn: bigint;
|
|
9
9
|
maxOut: bigint;
|
|
10
10
|
}
|
|
11
|
+
/** Represents a vault market's PublicAllocator limits. */
|
|
11
12
|
export declare class VaultMarketPublicAllocatorConfig implements IVaultMarketPublicAllocatorConfig {
|
|
12
13
|
/**
|
|
13
14
|
* The vault's address.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Address } from "../types.js";
|
|
2
|
+
/** Plain input shape for a user's MetaMorpho vault state. */
|
|
2
3
|
export interface IVaultUser {
|
|
3
4
|
vault: Address;
|
|
4
5
|
user: Address;
|
|
5
6
|
isAllocator: boolean;
|
|
6
7
|
allowance: bigint;
|
|
7
8
|
}
|
|
9
|
+
/** Represents a user's MetaMorpho vault allocator and allowance state. */
|
|
8
10
|
export declare class VaultUser implements IVaultUser {
|
|
9
11
|
/**
|
|
10
12
|
* The vault's address.
|