@morpho-org/blue-sdk 5.15.0 → 5.17.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/{errors.d.ts → cjs/errors.d.ts} +8 -0
- package/lib/{errors.js → cjs/errors.js} +17 -1
- package/lib/cjs/package.json +1 -0
- package/lib/{position → cjs/position}/PreLiquidationPosition.d.ts +3 -3
- package/lib/{position → cjs/position}/PreLiquidationPosition.js +16 -16
- package/lib/{preLiquidation.d.ts → cjs/preLiquidation.d.ts} +1 -1
- package/lib/{preLiquidation.js → cjs/preLiquidation.js} +2 -2
- package/lib/{vault → cjs/vault}/index.d.ts +1 -1
- package/lib/{vault → cjs/vault}/index.js +1 -1
- package/lib/{vault → cjs/vault}/v2/VaultV2.d.ts +5 -5
- package/lib/{vault → cjs/vault}/v2/VaultV2.js +25 -25
- package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.d.ts +2 -2
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.d.ts +7 -7
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.js +9 -9
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.js +8 -8
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.js +2 -2
- package/lib/esm/addresses.d.ts +2231 -0
- package/lib/esm/addresses.js +1309 -0
- package/lib/esm/chain.d.ts +405 -0
- package/lib/esm/chain.js +276 -0
- package/lib/esm/constants.d.ts +20 -0
- package/lib/esm/constants.js +21 -0
- package/lib/esm/errors.d.ts +101 -0
- package/lib/esm/errors.js +192 -0
- package/lib/esm/holding/AssetBalances.d.ts +48 -0
- package/lib/esm/holding/AssetBalances.js +38 -0
- package/lib/esm/holding/Holding.d.ts +63 -0
- package/lib/esm/holding/Holding.js +63 -0
- package/lib/esm/holding/index.d.ts +2 -0
- package/lib/esm/holding/index.js +2 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/market/Market.d.ts +424 -0
- package/lib/esm/market/Market.js +576 -0
- package/lib/esm/market/MarketParams.d.ts +74 -0
- package/lib/esm/market/MarketParams.js +91 -0
- package/lib/esm/market/MarketUtils.d.ts +273 -0
- package/lib/esm/market/MarketUtils.js +323 -0
- package/lib/esm/market/index.d.ts +3 -0
- package/lib/esm/market/index.js +3 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +40 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.js +133 -0
- package/lib/esm/math/MathLib.d.ts +102 -0
- package/lib/esm/math/MathLib.js +168 -0
- package/lib/esm/math/SharesMath.d.ts +12 -0
- package/lib/esm/math/SharesMath.js +18 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/position/Position.d.ts +147 -0
- package/lib/esm/position/Position.js +237 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +60 -0
- package/lib/esm/position/PreLiquidationPosition.js +97 -0
- package/lib/esm/position/index.d.ts +2 -0
- package/lib/esm/position/index.js +2 -0
- package/lib/esm/preLiquidation.d.ts +15 -0
- package/lib/esm/preLiquidation.js +91 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +17 -0
- package/lib/esm/token/ConstantWrappedToken.js +30 -0
- package/lib/esm/token/Eip5267Domain.d.ts +55 -0
- package/lib/esm/token/Eip5267Domain.js +66 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +17 -0
- package/lib/esm/token/Token.d.ts +52 -0
- package/lib/esm/token/Token.js +62 -0
- package/lib/esm/token/VaultToken.d.ts +23 -0
- package/lib/esm/token/VaultToken.js +27 -0
- package/lib/esm/token/WrappedToken.d.ts +17 -0
- package/lib/esm/token/WrappedToken.js +29 -0
- package/lib/esm/token/index.d.ts +6 -0
- package/lib/esm/token/index.js +6 -0
- package/lib/esm/types.d.ts +26 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +20 -0
- package/lib/esm/user/User.js +19 -0
- package/lib/esm/user/index.d.ts +1 -0
- package/lib/esm/user/index.js +1 -0
- package/lib/esm/utils.d.ts +13 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/vault/Vault.d.ts +214 -0
- package/lib/esm/vault/Vault.js +289 -0
- package/lib/esm/vault/VaultConfig.d.ts +11 -0
- package/lib/esm/vault/VaultConfig.js +10 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/esm/vault/VaultMarketAllocation.js +27 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/esm/vault/VaultMarketConfig.js +39 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +24 -0
- package/lib/esm/vault/VaultUser.d.ts +26 -0
- package/lib/esm/vault/VaultUser.js +24 -0
- package/lib/esm/vault/VaultUtils.d.ts +16 -0
- package/lib/esm/vault/VaultUtils.js +17 -0
- package/lib/esm/vault/index.d.ts +8 -0
- package/lib/esm/vault/index.js +8 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +87 -0
- package/lib/esm/vault/v2/VaultV2.js +154 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +29 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +12 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +30 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +54 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +33 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +63 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +24 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +36 -0
- package/lib/esm/vault/v2/index.d.ts +5 -0
- package/lib/esm/vault/v2/index.js +5 -0
- package/package.json +16 -7
- package/src/index.ts +14 -0
- /package/lib/{addresses.d.ts → cjs/addresses.d.ts} +0 -0
- /package/lib/{addresses.js → cjs/addresses.js} +0 -0
- /package/lib/{chain.d.ts → cjs/chain.d.ts} +0 -0
- /package/lib/{chain.js → cjs/chain.js} +0 -0
- /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/lib/{constants.js → cjs/constants.js} +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.js +0 -0
- /package/lib/{holding → cjs/holding}/Holding.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/Holding.js +0 -0
- /package/lib/{holding → cjs/holding}/index.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/index.js +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → cjs/index.js} +0 -0
- /package/lib/{market → cjs/market}/Market.d.ts +0 -0
- /package/lib/{market → cjs/market}/Market.js +0 -0
- /package/lib/{market → cjs/market}/MarketParams.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketParams.js +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.js +0 -0
- /package/lib/{market → cjs/market}/index.d.ts +0 -0
- /package/lib/{market → cjs/market}/index.js +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.js +0 -0
- /package/lib/{math → cjs/math}/MathLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/MathLib.js +0 -0
- /package/lib/{math → cjs/math}/SharesMath.d.ts +0 -0
- /package/lib/{math → cjs/math}/SharesMath.js +0 -0
- /package/lib/{math → cjs/math}/index.d.ts +0 -0
- /package/lib/{math → cjs/math}/index.js +0 -0
- /package/lib/{position → cjs/position}/Position.d.ts +0 -0
- /package/lib/{position → cjs/position}/Position.js +0 -0
- /package/lib/{position → cjs/position}/index.d.ts +0 -0
- /package/lib/{position → cjs/position}/index.js +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.d.ts +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.js +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Token.d.ts +0 -0
- /package/lib/{token → cjs/token}/Token.js +0 -0
- /package/lib/{token → cjs/token}/VaultToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/VaultToken.js +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/index.d.ts +0 -0
- /package/lib/{token → cjs/token}/index.js +0 -0
- /package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/lib/{types.js → cjs/types.js} +0 -0
- /package/lib/{user → cjs/user}/User.d.ts +0 -0
- /package/lib/{user → cjs/user}/User.js +0 -0
- /package/lib/{user → cjs/user}/index.d.ts +0 -0
- /package/lib/{user → cjs/user}/index.js +0 -0
- /package/lib/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/lib/{utils.js → cjs/utils.js} +0 -0
- /package/lib/{vault → cjs/vault}/Vault.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/Vault.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.js +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { Address } from "../types.js";
|
|
3
|
+
import type { IToken } from "./Token.js";
|
|
4
|
+
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
+
export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
6
|
+
readonly underlying: Address;
|
|
7
|
+
wrappedTokenExchangeRate: bigint;
|
|
8
|
+
constructor(token: IToken, underlying: Address, wrappedTokenExchangeRate: bigint);
|
|
9
|
+
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
10
|
+
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
import { WrappedToken } from "./WrappedToken.js";
|
|
3
|
+
export class ExchangeRateWrappedToken extends WrappedToken {
|
|
4
|
+
underlying;
|
|
5
|
+
wrappedTokenExchangeRate;
|
|
6
|
+
constructor(token, underlying, wrappedTokenExchangeRate) {
|
|
7
|
+
super(token, underlying);
|
|
8
|
+
this.underlying = underlying;
|
|
9
|
+
this.wrappedTokenExchangeRate = wrappedTokenExchangeRate;
|
|
10
|
+
}
|
|
11
|
+
_wrap(amount, rounding) {
|
|
12
|
+
return MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
13
|
+
}
|
|
14
|
+
_unwrap(amount, rounding) {
|
|
15
|
+
return MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type ChainId } from "../chain.js";
|
|
2
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
3
|
+
import type { Address, BigIntish } from "../types.js";
|
|
4
|
+
import type { Eip5267Domain } from "./Eip5267Domain.js";
|
|
5
|
+
export interface IToken {
|
|
6
|
+
address: Address;
|
|
7
|
+
name?: string;
|
|
8
|
+
symbol?: string;
|
|
9
|
+
decimals?: BigIntish;
|
|
10
|
+
price?: BigIntish;
|
|
11
|
+
eip5267Domain?: Eip5267Domain;
|
|
12
|
+
}
|
|
13
|
+
export declare class Token implements IToken {
|
|
14
|
+
static native(chainId: ChainId): Token;
|
|
15
|
+
/**
|
|
16
|
+
* The token's address.
|
|
17
|
+
*/
|
|
18
|
+
readonly address: Address;
|
|
19
|
+
/**
|
|
20
|
+
* The token's name.
|
|
21
|
+
*/
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The token's symbol.
|
|
25
|
+
*/
|
|
26
|
+
readonly symbol?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The token's number of decimals. Defaults to 0.
|
|
29
|
+
*/
|
|
30
|
+
readonly decimals: number;
|
|
31
|
+
/**
|
|
32
|
+
* The eip712 domain of the token if it can be directly queried onchain
|
|
33
|
+
*/
|
|
34
|
+
readonly eip5267Domain?: Eip5267Domain;
|
|
35
|
+
/**
|
|
36
|
+
* Price of the token in USD (scaled by WAD).
|
|
37
|
+
*/
|
|
38
|
+
price?: bigint;
|
|
39
|
+
constructor({ address, name, symbol, decimals, price, eip5267Domain, }: IToken);
|
|
40
|
+
/**
|
|
41
|
+
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
42
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
43
|
+
* @param amount The amount of USD to quote.
|
|
44
|
+
*/
|
|
45
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
48
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
49
|
+
* @param amount The amount of tokens to quote.
|
|
50
|
+
*/
|
|
51
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
52
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { NATIVE_ADDRESS } from "../addresses.js";
|
|
2
|
+
import { ChainUtils } from "../chain.js";
|
|
3
|
+
import { MathLib } from "../math/index.js";
|
|
4
|
+
export class Token {
|
|
5
|
+
static native(chainId) {
|
|
6
|
+
const currency = ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
7
|
+
return new Token({ ...currency, address: NATIVE_ADDRESS });
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The token's address.
|
|
11
|
+
*/
|
|
12
|
+
address;
|
|
13
|
+
/**
|
|
14
|
+
* The token's name.
|
|
15
|
+
*/
|
|
16
|
+
name;
|
|
17
|
+
/**
|
|
18
|
+
* The token's symbol.
|
|
19
|
+
*/
|
|
20
|
+
symbol;
|
|
21
|
+
/**
|
|
22
|
+
* The token's number of decimals. Defaults to 0.
|
|
23
|
+
*/
|
|
24
|
+
decimals;
|
|
25
|
+
/**
|
|
26
|
+
* The eip712 domain of the token if it can be directly queried onchain
|
|
27
|
+
*/
|
|
28
|
+
eip5267Domain;
|
|
29
|
+
/**
|
|
30
|
+
* Price of the token in USD (scaled by WAD).
|
|
31
|
+
*/
|
|
32
|
+
price;
|
|
33
|
+
constructor({ address, name, symbol, decimals = 0, price, eip5267Domain, }) {
|
|
34
|
+
this.address = address;
|
|
35
|
+
this.name = name;
|
|
36
|
+
this.symbol = symbol;
|
|
37
|
+
this.decimals = Number(decimals);
|
|
38
|
+
this.eip5267Domain = eip5267Domain;
|
|
39
|
+
if (price != null)
|
|
40
|
+
this.price = BigInt(price);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
44
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
45
|
+
* @param amount The amount of USD to quote.
|
|
46
|
+
*/
|
|
47
|
+
fromUsd(amount, rounding = "Down") {
|
|
48
|
+
if (this.price == null)
|
|
49
|
+
return;
|
|
50
|
+
return MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
54
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
55
|
+
* @param amount The amount of tokens to quote.
|
|
56
|
+
*/
|
|
57
|
+
toUsd(amount, rounding = "Down") {
|
|
58
|
+
if (this.price == null)
|
|
59
|
+
return;
|
|
60
|
+
return MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { Address, BigIntish } from "../types.js";
|
|
3
|
+
import type { IVaultConfig } from "../vault/VaultConfig.js";
|
|
4
|
+
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
+
export interface IVaultToken {
|
|
6
|
+
totalAssets: bigint;
|
|
7
|
+
totalSupply: bigint;
|
|
8
|
+
}
|
|
9
|
+
export declare class VaultToken extends WrappedToken implements IVaultToken {
|
|
10
|
+
readonly asset: Address;
|
|
11
|
+
readonly decimalsOffset: bigint;
|
|
12
|
+
/**
|
|
13
|
+
* The ERC4626 vault's total supply of shares.
|
|
14
|
+
*/
|
|
15
|
+
totalSupply: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* The ERC4626 vault's total assets.
|
|
18
|
+
*/
|
|
19
|
+
totalAssets: bigint;
|
|
20
|
+
constructor(config: IVaultConfig, { totalAssets, totalSupply }: IVaultToken);
|
|
21
|
+
protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
22
|
+
protected _unwrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { VaultUtils } from "../vault/VaultUtils.js";
|
|
2
|
+
import { WrappedToken } from "./WrappedToken.js";
|
|
3
|
+
export class VaultToken extends WrappedToken {
|
|
4
|
+
asset;
|
|
5
|
+
decimalsOffset;
|
|
6
|
+
/**
|
|
7
|
+
* The ERC4626 vault's total supply of shares.
|
|
8
|
+
*/
|
|
9
|
+
totalSupply;
|
|
10
|
+
/**
|
|
11
|
+
* The ERC4626 vault's total assets.
|
|
12
|
+
*/
|
|
13
|
+
totalAssets;
|
|
14
|
+
constructor(config, { totalAssets, totalSupply }) {
|
|
15
|
+
super(config, config.asset);
|
|
16
|
+
this.asset = config.asset;
|
|
17
|
+
this.totalAssets = totalAssets;
|
|
18
|
+
this.totalSupply = totalSupply;
|
|
19
|
+
this.decimalsOffset = BigInt(config.decimalsOffset);
|
|
20
|
+
}
|
|
21
|
+
_wrap(amount, rounding) {
|
|
22
|
+
return VaultUtils.toShares(amount, this, rounding);
|
|
23
|
+
}
|
|
24
|
+
_unwrap(amount, rounding) {
|
|
25
|
+
return VaultUtils.toAssets(amount, this, rounding);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { Address } from "../types.js";
|
|
3
|
+
import { type IToken, Token } from "./Token.js";
|
|
4
|
+
export declare abstract class WrappedToken extends Token {
|
|
5
|
+
readonly underlying: Address;
|
|
6
|
+
constructor(token: IToken, underlying: Address);
|
|
7
|
+
/** The expected amount when wrapping `unwrappedAmount` */
|
|
8
|
+
toWrappedExactAmountIn(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
9
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
10
|
+
toWrappedExactAmountOut(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
11
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
12
|
+
toUnwrappedExactAmountIn(wrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
13
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
14
|
+
toUnwrappedExactAmountOut(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
15
|
+
protected abstract _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
16
|
+
protected abstract _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
import { Token } from "./Token.js";
|
|
3
|
+
export class WrappedToken extends Token {
|
|
4
|
+
underlying;
|
|
5
|
+
constructor(token, underlying) {
|
|
6
|
+
super(token);
|
|
7
|
+
this.underlying = underlying;
|
|
8
|
+
}
|
|
9
|
+
/** The expected amount when wrapping `unwrappedAmount` */
|
|
10
|
+
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
11
|
+
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
12
|
+
return MathLib.wMulDown(wrappedAmount, MathLib.WAD - slippage);
|
|
13
|
+
}
|
|
14
|
+
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
15
|
+
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
16
|
+
const wAmountTarget = MathLib.wDiv(wrappedAmount, MathLib.WAD - slippage, rounding);
|
|
17
|
+
return this._unwrap(wAmountTarget, rounding);
|
|
18
|
+
}
|
|
19
|
+
/** The expected amount when unwrapping `wrappedAmount` */
|
|
20
|
+
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
21
|
+
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
22
|
+
return MathLib.wMulUp(unwrappedAmount, MathLib.WAD - slippage);
|
|
23
|
+
}
|
|
24
|
+
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
25
|
+
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
26
|
+
const unwrappedAmountToTarget = MathLib.wDiv(unwrappedAmount, MathLib.WAD - slippage, rounding);
|
|
27
|
+
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The address of a Contract, or an EOA
|
|
3
|
+
*/
|
|
4
|
+
export type Address = `0x${string}`;
|
|
5
|
+
/**
|
|
6
|
+
* The id of a market used on the Blue contract
|
|
7
|
+
*/
|
|
8
|
+
export type MarketId = `0x${string}` & {
|
|
9
|
+
__TYPE__: "marketId";
|
|
10
|
+
};
|
|
11
|
+
export type BigIntish = bigint | string | number | boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The possible transaction type on the Blue contract
|
|
14
|
+
*/
|
|
15
|
+
export declare enum TransactionType {
|
|
16
|
+
Supply = "Supply",
|
|
17
|
+
SupplyCollateral = "Supply Collateral",
|
|
18
|
+
Withdraw = "Withdraw",
|
|
19
|
+
WithdrawCollateral = "Withdraw Collateral",
|
|
20
|
+
Borrow = "Borrow",
|
|
21
|
+
Repay = "Repay"
|
|
22
|
+
}
|
|
23
|
+
export type Loadable<T> = T | undefined;
|
|
24
|
+
export type Failable<T> = T | null;
|
|
25
|
+
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
26
|
+
export declare const isMarketId: (value: unknown) => value is MarketId;
|
package/lib/esm/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The possible transaction type on the Blue contract
|
|
3
|
+
*/
|
|
4
|
+
export var TransactionType;
|
|
5
|
+
(function (TransactionType) {
|
|
6
|
+
TransactionType["Supply"] = "Supply";
|
|
7
|
+
TransactionType["SupplyCollateral"] = "Supply Collateral";
|
|
8
|
+
TransactionType["Withdraw"] = "Withdraw";
|
|
9
|
+
TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
|
|
10
|
+
TransactionType["Borrow"] = "Borrow";
|
|
11
|
+
TransactionType["Repay"] = "Repay";
|
|
12
|
+
})(TransactionType || (TransactionType = {}));
|
|
13
|
+
export const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address } from "../types.js";
|
|
2
|
+
export declare class User {
|
|
3
|
+
/**
|
|
4
|
+
* The user's address.
|
|
5
|
+
*/
|
|
6
|
+
readonly address: Address;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
9
|
+
*/
|
|
10
|
+
isBundlerAuthorized: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The user's nonce on Morpho Blue.
|
|
13
|
+
*/
|
|
14
|
+
morphoNonce: bigint;
|
|
15
|
+
constructor({ address, isBundlerAuthorized, morphoNonce, }: {
|
|
16
|
+
address: Address;
|
|
17
|
+
isBundlerAuthorized: boolean;
|
|
18
|
+
morphoNonce: bigint;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class User {
|
|
2
|
+
/**
|
|
3
|
+
* The user's address.
|
|
4
|
+
*/
|
|
5
|
+
address;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
8
|
+
*/
|
|
9
|
+
isBundlerAuthorized;
|
|
10
|
+
/**
|
|
11
|
+
* The user's nonce on Morpho Blue.
|
|
12
|
+
*/
|
|
13
|
+
morphoNonce;
|
|
14
|
+
constructor({ address, isBundlerAuthorized, morphoNonce, }) {
|
|
15
|
+
this.address = address;
|
|
16
|
+
this.isBundlerAuthorized = isBundlerAuthorized;
|
|
17
|
+
this.morphoNonce = morphoNonce;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./User.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./User.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum CapacityLimitReason {
|
|
2
|
+
liquidity = "Liquidity",
|
|
3
|
+
balance = "Balance",
|
|
4
|
+
position = "Position",
|
|
5
|
+
collateral = "Collateral",
|
|
6
|
+
cap = "Cap",
|
|
7
|
+
vaultV2_absoluteCap = "VaultV2_AbsoluteCap",
|
|
8
|
+
vaultV2_relativeCap = "VaultV2_RelativeCap"
|
|
9
|
+
}
|
|
10
|
+
export interface CapacityLimit {
|
|
11
|
+
value: bigint;
|
|
12
|
+
limiter: CapacityLimitReason;
|
|
13
|
+
}
|
package/lib/esm/utils.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var CapacityLimitReason;
|
|
2
|
+
(function (CapacityLimitReason) {
|
|
3
|
+
CapacityLimitReason["liquidity"] = "Liquidity";
|
|
4
|
+
CapacityLimitReason["balance"] = "Balance";
|
|
5
|
+
CapacityLimitReason["position"] = "Position";
|
|
6
|
+
CapacityLimitReason["collateral"] = "Collateral";
|
|
7
|
+
CapacityLimitReason["cap"] = "Cap";
|
|
8
|
+
CapacityLimitReason["vaultV2_absoluteCap"] = "VaultV2_AbsoluteCap";
|
|
9
|
+
CapacityLimitReason["vaultV2_relativeCap"] = "VaultV2_RelativeCap";
|
|
10
|
+
})(CapacityLimitReason || (CapacityLimitReason = {}));
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import { VaultToken } from "../token/index.js";
|
|
3
|
+
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
4
|
+
import { type CapacityLimit } from "../utils.js";
|
|
5
|
+
import type { IVaultConfig } from "./VaultConfig.js";
|
|
6
|
+
import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
|
|
7
|
+
export interface Pending<T> {
|
|
8
|
+
value: T;
|
|
9
|
+
validAt: bigint;
|
|
10
|
+
}
|
|
11
|
+
export interface VaultPublicAllocatorConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The PublicAllocator's admin address.
|
|
14
|
+
*/
|
|
15
|
+
admin: Address;
|
|
16
|
+
/**
|
|
17
|
+
* The PublicAllocator's reallocation fee (in native token).
|
|
18
|
+
*/
|
|
19
|
+
fee: bigint;
|
|
20
|
+
/**
|
|
21
|
+
* The PublicAllocator's reallocation fee accrued so far (in native token).
|
|
22
|
+
*/
|
|
23
|
+
accruedFee: bigint;
|
|
24
|
+
}
|
|
25
|
+
export interface IVault extends IVaultConfig {
|
|
26
|
+
curator: Address;
|
|
27
|
+
owner: Address;
|
|
28
|
+
guardian: Address;
|
|
29
|
+
fee: bigint;
|
|
30
|
+
feeRecipient: Address;
|
|
31
|
+
skimRecipient: Address;
|
|
32
|
+
pendingTimelock: Pending<bigint>;
|
|
33
|
+
pendingGuardian: Pending<Address>;
|
|
34
|
+
pendingOwner: Address;
|
|
35
|
+
timelock: bigint;
|
|
36
|
+
supplyQueue: MarketId[];
|
|
37
|
+
withdrawQueue: MarketId[];
|
|
38
|
+
totalSupply: bigint;
|
|
39
|
+
totalAssets: bigint;
|
|
40
|
+
lastTotalAssets: bigint;
|
|
41
|
+
lostAssets?: bigint;
|
|
42
|
+
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
43
|
+
}
|
|
44
|
+
export declare class Vault extends VaultToken implements IVault {
|
|
45
|
+
/**
|
|
46
|
+
* The vault's share token's name.
|
|
47
|
+
*/
|
|
48
|
+
readonly name: string;
|
|
49
|
+
/**
|
|
50
|
+
* The vault's share token's symbol.
|
|
51
|
+
*/
|
|
52
|
+
readonly symbol: string;
|
|
53
|
+
/**
|
|
54
|
+
* The MetaMorpho vault's owner address.
|
|
55
|
+
*/
|
|
56
|
+
owner: Address;
|
|
57
|
+
/**
|
|
58
|
+
* The MetaMorpho vault's curator address.
|
|
59
|
+
*/
|
|
60
|
+
curator: Address;
|
|
61
|
+
/**
|
|
62
|
+
* The MetaMorpho vault's guardian address.
|
|
63
|
+
*/
|
|
64
|
+
guardian: Address;
|
|
65
|
+
/**
|
|
66
|
+
* The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
|
|
67
|
+
*/
|
|
68
|
+
skimRecipient: Address;
|
|
69
|
+
/**
|
|
70
|
+
* The MetaMorpho vault's fee recipient address.
|
|
71
|
+
*/
|
|
72
|
+
feeRecipient: Address;
|
|
73
|
+
/**
|
|
74
|
+
* The MetaMorpho vault's timelock (in seconds).
|
|
75
|
+
*/
|
|
76
|
+
timelock: bigint;
|
|
77
|
+
/**
|
|
78
|
+
* The MetaMorpho vault's fee.
|
|
79
|
+
*/
|
|
80
|
+
fee: bigint;
|
|
81
|
+
/**
|
|
82
|
+
* The MetaMorpho vault's pending owner address and activation timestamp.
|
|
83
|
+
*/
|
|
84
|
+
pendingOwner: Address;
|
|
85
|
+
/**
|
|
86
|
+
* The MetaMorpho vault's pending guardian address and activation timestamp.
|
|
87
|
+
*/
|
|
88
|
+
pendingGuardian: Pending<Address>;
|
|
89
|
+
/**
|
|
90
|
+
* The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
|
|
91
|
+
*/
|
|
92
|
+
pendingTimelock: Pending<bigint>;
|
|
93
|
+
/**
|
|
94
|
+
* The MetaMorpho vault's ordered supply queue.
|
|
95
|
+
*/
|
|
96
|
+
supplyQueue: MarketId[];
|
|
97
|
+
/**
|
|
98
|
+
* The MetaMorpho vault's ordered withdraw queue.
|
|
99
|
+
*/
|
|
100
|
+
withdrawQueue: MarketId[];
|
|
101
|
+
/**
|
|
102
|
+
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
103
|
+
*/
|
|
104
|
+
lastTotalAssets: bigint;
|
|
105
|
+
/**
|
|
106
|
+
* The MetaMorpho vault's lost assets due to realized bad debt.
|
|
107
|
+
* Only defined for MetaMorpho V1.1 vaults.
|
|
108
|
+
*/
|
|
109
|
+
lostAssets?: bigint;
|
|
110
|
+
/**
|
|
111
|
+
* The MetaMorpho vault's public allocator configuration.
|
|
112
|
+
*/
|
|
113
|
+
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
114
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, lostAssets, ...config }: IVault);
|
|
115
|
+
/**
|
|
116
|
+
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
|
+
*/
|
|
118
|
+
get totalInterest(): bigint;
|
|
119
|
+
toAssets(shares: BigIntish, rounding?: RoundingDirection): bigint;
|
|
120
|
+
toShares(assets: BigIntish, rounding?: RoundingDirection): bigint;
|
|
121
|
+
}
|
|
122
|
+
export interface CollateralAllocation {
|
|
123
|
+
address: Address;
|
|
124
|
+
lltvs: Set<bigint>;
|
|
125
|
+
oracles: Set<Address>;
|
|
126
|
+
markets: Set<MarketId>;
|
|
127
|
+
proportion: bigint;
|
|
128
|
+
}
|
|
129
|
+
export interface IAccrualVault extends Omit<IVault, "withdrawQueue" | "totalAssets"> {
|
|
130
|
+
}
|
|
131
|
+
export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
132
|
+
/**
|
|
133
|
+
* @inheritdoc
|
|
134
|
+
* Reflects the sum of assets of the vault's allocations.
|
|
135
|
+
* Only includes virtually accrued interest if the vault's allocations include virtually accrued interest.
|
|
136
|
+
*/
|
|
137
|
+
totalAssets: bigint;
|
|
138
|
+
/**
|
|
139
|
+
* The allocation of the vault on each market enabled.
|
|
140
|
+
*/
|
|
141
|
+
readonly allocations: Map<MarketId, VaultMarketAllocation>;
|
|
142
|
+
/**
|
|
143
|
+
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
144
|
+
*/
|
|
145
|
+
readonly collateralAllocations: Map<Address, CollateralAllocation>;
|
|
146
|
+
constructor(vault: IAccrualVault,
|
|
147
|
+
/**
|
|
148
|
+
* The allocation of the vault on each market of the withdraw queue,
|
|
149
|
+
* in the same order as the withdraw queue.
|
|
150
|
+
*/
|
|
151
|
+
allocations: Omit<IVaultMarketAllocation, "proportion">[]);
|
|
152
|
+
/**
|
|
153
|
+
* The vault's liquidity directly available from allocated markets.
|
|
154
|
+
*/
|
|
155
|
+
get liquidity(): bigint;
|
|
156
|
+
/**
|
|
157
|
+
* The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
|
|
158
|
+
* weighted-averaged over its market deposits, before deducting the performance fee.
|
|
159
|
+
* If interested in the APY at a specific timestamp, use `getApy(timestamp)` instead.
|
|
160
|
+
*/
|
|
161
|
+
get apy(): number;
|
|
162
|
+
/**
|
|
163
|
+
* The MetaMorpho vault's current instantaneous Annual Percentage Yield (APY)
|
|
164
|
+
* weighted-averaged over its market deposits, after deducting the performance fee.
|
|
165
|
+
* If interested in the APY at a specific timestamp, use `getNetApy(timestamp)` instead.
|
|
166
|
+
*/
|
|
167
|
+
get netApy(): number;
|
|
168
|
+
/**
|
|
169
|
+
* The MetaMorpho vault's per-second rate at which interest _would_ accrue,
|
|
170
|
+
* weighted-averaged over its market deposits, before deducting the performance fee,
|
|
171
|
+
* if interest was to be accrued on each market at the given timestamp.
|
|
172
|
+
*/
|
|
173
|
+
private _getAvgRate;
|
|
174
|
+
/**
|
|
175
|
+
* The MetaMorpho vault's experienced Annual Percentage Yield (APY)
|
|
176
|
+
* weighted-averaged over its market deposits, before deducting the performance fee,
|
|
177
|
+
* if interest was to be accrued on each market at the given timestamp.
|
|
178
|
+
*/
|
|
179
|
+
getApy(timestamp?: BigIntish): number;
|
|
180
|
+
/**
|
|
181
|
+
* The MetaMorpho vault's experienced Annual Percentage Yield (APY)
|
|
182
|
+
* weighted-averaged over its market deposits, after deducting the performance fee,
|
|
183
|
+
* if interest was to be accrued on each market at the given timestamp.
|
|
184
|
+
*/
|
|
185
|
+
getNetApy(timestamp?: BigIntish): number;
|
|
186
|
+
getAllocationProportion(marketId: MarketId): bigint;
|
|
187
|
+
/**
|
|
188
|
+
* Returns the deposit capacity limit of a given amount of assets on the vault.
|
|
189
|
+
* @param assets The maximum amount of assets to deposit.
|
|
190
|
+
* @deprecated Use `maxDeposit` instead.
|
|
191
|
+
*/
|
|
192
|
+
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the withdraw capacity limit corresponding to a given amount of shares of the vault.
|
|
195
|
+
* @param shares The maximum amount of shares to redeem.
|
|
196
|
+
* @deprecated Use `maxWithdraw` instead.
|
|
197
|
+
*/
|
|
198
|
+
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the maximum amount of assets that can be deposited to the vault.
|
|
201
|
+
* @param assets The maximum amount of assets to deposit.
|
|
202
|
+
*/
|
|
203
|
+
maxDeposit(assets: BigIntish): CapacityLimit;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the maximum amount of assets that can be withdrawn from the vault.
|
|
206
|
+
* @param shares The maximum amount of shares to redeem.
|
|
207
|
+
*/
|
|
208
|
+
maxWithdraw(shares: BigIntish): CapacityLimit;
|
|
209
|
+
/**
|
|
210
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
211
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
212
|
+
*/
|
|
213
|
+
accrueInterest(timestamp?: BigIntish): AccrualVault;
|
|
214
|
+
}
|