@morpho-org/blue-sdk 1.0.5 → 1.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/README.md +2 -2
- package/lib/addresses.d.ts +35 -21
- package/lib/addresses.js +51 -14
- package/lib/chain.d.ts +30 -0
- package/lib/chain.js +288 -0
- package/lib/chain.test.js +22 -0
- package/lib/constants.d.ts +27 -6
- package/lib/constants.js +28 -8
- package/lib/errors.d.ts +18 -7
- package/lib/errors.js +38 -10
- package/lib/helpers/format/format.js +21 -60
- package/lib/helpers/index.d.ts +0 -2
- package/lib/helpers/index.js +0 -2
- package/lib/holding/Holding.d.ts +3 -4
- package/lib/holding/Holding.js +32 -4
- package/lib/index.d.ts +0 -8
- package/lib/index.js +1 -9
- package/lib/market/Market.d.ts +206 -55
- package/lib/market/Market.js +266 -64
- package/lib/market/MarketConfig.d.ts +17 -9
- package/lib/market/MarketConfig.js +39 -21
- package/lib/market/MarketUtils.d.ts +151 -102
- package/lib/market/MarketUtils.js +94 -38
- package/lib/market/MarketUtils.test.js +1 -2
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
- package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
- package/lib/maths/MathLib.d.ts +35 -15
- package/lib/maths/MathLib.js +53 -33
- package/lib/maths/SharesMath.d.ts +3 -3
- package/lib/maths/SharesMath.js +2 -3
- package/lib/maths/index.d.ts +0 -1
- package/lib/maths/index.js +0 -1
- package/lib/position/Position.d.ts +5 -26
- package/lib/position/Position.js +29 -36
- package/lib/tests/mocks/markets.d.ts +1 -0
- package/lib/tests/mocks/markets.js +35 -29
- package/lib/token/Token.d.ts +4 -3
- package/lib/token/Token.js +28 -3
- package/lib/token/WrappedToken.d.ts +3 -3
- package/lib/token/WrappedToken.js +18 -11
- package/lib/token/index.d.ts +1 -1
- package/lib/token/index.js +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -4
- package/lib/user/User.js +12 -0
- package/lib/vault/Vault.d.ts +12 -12
- package/lib/vault/Vault.js +102 -18
- package/lib/vault/VaultConfig.js +9 -3
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +30 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +43 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
- package/lib/vault/VaultUtils.d.ts +8 -9
- package/lib/vault/VaultUtils.js +2 -3
- package/lib/vault/index.d.ts +3 -1
- package/lib/vault/index.js +3 -1
- package/package.json +3 -6
- package/lib/chain/chain.constants.d.ts +0 -3
- package/lib/chain/chain.constants.js +0 -232
- package/lib/chain/chain.test.js +0 -37
- package/lib/chain/chain.types.d.ts +0 -20
- package/lib/chain/chain.types.js +0 -30
- package/lib/chain/chain.utils.d.ts +0 -14
- package/lib/chain/chain.utils.js +0 -30
- package/lib/chain/index.d.ts +0 -2
- package/lib/chain/index.js +0 -18
- package/lib/ethers/ethers.test.d.ts +0 -1
- package/lib/ethers/ethers.test.js +0 -11
- package/lib/ethers/index.d.ts +0 -2
- package/lib/ethers/index.js +0 -18
- package/lib/ethers/safeGetAddress.d.ts +0 -1
- package/lib/ethers/safeGetAddress.js +0 -6
- package/lib/ethers/safeParseUnits.d.ts +0 -2
- package/lib/ethers/safeParseUnits.js +0 -25
- package/lib/evm.d.ts +0 -36
- package/lib/evm.js +0 -113
- package/lib/helpers/getChecksumedAddress.d.ts +0 -7
- package/lib/helpers/getChecksumedAddress.js +0 -17
- package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
- package/lib/helpers/isZeroAddressOrUnset.js +0 -14
- package/lib/maths/MathUtils.d.ts +0 -15
- package/lib/maths/MathUtils.js +0 -33
- package/lib/notifications.d.ts +0 -98
- package/lib/notifications.js +0 -52
- package/lib/signatures/index.d.ts +0 -12
- package/lib/signatures/index.js +0 -39
- package/lib/signatures/manager.d.ts +0 -10
- package/lib/signatures/manager.js +0 -37
- package/lib/signatures/permit.d.ts +0 -21
- package/lib/signatures/permit.js +0 -101
- package/lib/signatures/permit2.d.ts +0 -20
- package/lib/signatures/permit2.js +0 -91
- package/lib/signatures/types.d.ts +0 -13
- package/lib/signatures/types.js +0 -2
- package/lib/signatures/utils.d.ts +0 -6
- package/lib/signatures/utils.js +0 -44
- package/lib/token/ERC20Metadata.d.ts +0 -249
- package/lib/token/ERC20Metadata.js +0 -81
- package/lib/token/TokenNamespace.d.ts +0 -18
- package/lib/token/TokenNamespace.js +0 -55
- package/lib/vault/VaultAllocation.d.ts +0 -38
- package/lib/vault/VaultAllocation.js +0 -18
- /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
package/lib/token/Token.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChainId } from "../chain";
|
|
2
2
|
import { RoundingDirection } from "../maths";
|
|
3
3
|
import { Address } from "../types";
|
|
4
4
|
export interface InputToken {
|
|
@@ -8,6 +8,7 @@ export interface InputToken {
|
|
|
8
8
|
name?: string;
|
|
9
9
|
}
|
|
10
10
|
export declare class Token implements InputToken {
|
|
11
|
+
static native(chainId: ChainId): Token;
|
|
11
12
|
/**
|
|
12
13
|
* The token's address.
|
|
13
14
|
*/
|
|
@@ -36,10 +37,10 @@ export declare class TokenWithPrice extends Token {
|
|
|
36
37
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
37
38
|
* @param amount The amount of USD to quote.
|
|
38
39
|
*/
|
|
39
|
-
fromUsd(amount:
|
|
40
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
40
41
|
/**
|
|
41
42
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
42
43
|
* @param amount The amount of tokens to quote.
|
|
43
44
|
*/
|
|
44
|
-
toUsd(amount:
|
|
45
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | null;
|
|
45
46
|
}
|
package/lib/token/Token.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenWithPrice = exports.Token = void 0;
|
|
4
|
-
const
|
|
4
|
+
const addresses_1 = require("../addresses");
|
|
5
|
+
const chain_1 = require("../chain");
|
|
5
6
|
const maths_1 = require("../maths");
|
|
6
7
|
class Token {
|
|
8
|
+
static native(chainId) {
|
|
9
|
+
const currency = chain_1.ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
10
|
+
return new Token({ ...currency, address: addresses_1.NATIVE_ADDRESS });
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The token's address.
|
|
14
|
+
*/
|
|
15
|
+
address;
|
|
16
|
+
/**
|
|
17
|
+
* The token's number of decimals.
|
|
18
|
+
*/
|
|
19
|
+
decimals;
|
|
20
|
+
/**
|
|
21
|
+
* The token's symbol.
|
|
22
|
+
*/
|
|
23
|
+
symbol;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the token (defaults to the symbol).
|
|
26
|
+
*/
|
|
27
|
+
name;
|
|
7
28
|
constructor({ address, decimals, symbol, name }) {
|
|
8
29
|
this.address = address;
|
|
9
30
|
this.decimals = decimals;
|
|
@@ -13,6 +34,10 @@ class Token {
|
|
|
13
34
|
}
|
|
14
35
|
exports.Token = Token;
|
|
15
36
|
class TokenWithPrice extends Token {
|
|
37
|
+
/**
|
|
38
|
+
* Price of the token in USD (scaled by WAD).
|
|
39
|
+
*/
|
|
40
|
+
price;
|
|
16
41
|
constructor(token, price) {
|
|
17
42
|
super(token);
|
|
18
43
|
this.price = price;
|
|
@@ -24,7 +49,7 @@ class TokenWithPrice extends Token {
|
|
|
24
49
|
fromUsd(amount, rounding = "Down") {
|
|
25
50
|
if (this.price == null)
|
|
26
51
|
return null;
|
|
27
|
-
return maths_1.MathLib.mulDiv(amount,
|
|
52
|
+
return maths_1.MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
28
53
|
}
|
|
29
54
|
/**
|
|
30
55
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
@@ -33,7 +58,7 @@ class TokenWithPrice extends Token {
|
|
|
33
58
|
toUsd(amount, rounding = "Down") {
|
|
34
59
|
if (this.price == null)
|
|
35
60
|
return null;
|
|
36
|
-
return maths_1.MathLib.mulDiv(amount, this.price,
|
|
61
|
+
return maths_1.MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
37
62
|
}
|
|
38
63
|
}
|
|
39
64
|
exports.TokenWithPrice = TokenWithPrice;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RoundingDirection } from "../maths";
|
|
2
2
|
import { Address } from "../types";
|
|
3
|
-
import { Vault } from "../vault";
|
|
3
|
+
import { Vault, VaultConfig } from "../vault";
|
|
4
4
|
import { InputToken, Token } from "./Token";
|
|
5
5
|
export declare abstract class WrappedToken extends Token {
|
|
6
6
|
readonly underlying: Address;
|
|
@@ -33,10 +33,10 @@ export declare class ExchangeRateWrappedToken extends WrappedToken {
|
|
|
33
33
|
constructor(token: InputToken, underlying: Address, wrappedTokenExchangeRate: bigint);
|
|
34
34
|
}
|
|
35
35
|
export declare class VaultToken extends WrappedToken {
|
|
36
|
-
readonly underlying: Address;
|
|
37
36
|
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
38
37
|
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
39
38
|
totalAssets: bigint;
|
|
40
39
|
totalSupply: bigint;
|
|
41
|
-
|
|
40
|
+
config: VaultConfig;
|
|
41
|
+
constructor(token: InputToken, { totalAssets, totalSupply, config, }: Pick<Vault, "totalAssets" | "totalSupply" | "config">);
|
|
42
42
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultToken = exports.ExchangeRateWrappedToken = exports.ConstantWrappedToken = exports.WrappedToken = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const ethers_2 = require("../ethers");
|
|
6
4
|
const maths_1 = require("../maths");
|
|
5
|
+
const vault_1 = require("../vault");
|
|
7
6
|
const Token_1 = require("./Token");
|
|
8
7
|
class WrappedToken extends Token_1.Token {
|
|
8
|
+
underlying;
|
|
9
|
+
_noSlippage = false;
|
|
9
10
|
constructor(token, underlying) {
|
|
10
11
|
super(token);
|
|
11
12
|
this.underlying = underlying;
|
|
12
|
-
this._noSlippage = false;
|
|
13
13
|
}
|
|
14
14
|
/** The expected amount when wrapping `unwrappedAmount` */
|
|
15
15
|
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
@@ -42,21 +42,25 @@ class WrappedToken extends Token_1.Token {
|
|
|
42
42
|
}
|
|
43
43
|
exports.WrappedToken = WrappedToken;
|
|
44
44
|
class ConstantWrappedToken extends WrappedToken {
|
|
45
|
+
underlying;
|
|
46
|
+
_underlyingDecimals;
|
|
47
|
+
_noSlippage = true;
|
|
45
48
|
constructor(token, underlying, _underlyingDecimals = 18) {
|
|
46
49
|
super(token, underlying);
|
|
47
50
|
this.underlying = underlying;
|
|
48
51
|
this._underlyingDecimals = _underlyingDecimals;
|
|
49
|
-
this._noSlippage = true;
|
|
50
52
|
}
|
|
51
53
|
_wrap(amount) {
|
|
52
|
-
return
|
|
54
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this.decimals), 10n ** BigInt(this._underlyingDecimals));
|
|
53
55
|
}
|
|
54
56
|
_unwrap(amount) {
|
|
55
|
-
return
|
|
57
|
+
return maths_1.MathLib.mulDivDown(amount, 10n ** BigInt(this._underlyingDecimals), 10n ** BigInt(this.decimals));
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
exports.ConstantWrappedToken = ConstantWrappedToken;
|
|
59
61
|
class ExchangeRateWrappedToken extends WrappedToken {
|
|
62
|
+
underlying;
|
|
63
|
+
wrappedTokenExchangeRate;
|
|
60
64
|
_wrap(amount, rounding) {
|
|
61
65
|
return maths_1.MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
62
66
|
}
|
|
@@ -72,16 +76,19 @@ class ExchangeRateWrappedToken extends WrappedToken {
|
|
|
72
76
|
exports.ExchangeRateWrappedToken = ExchangeRateWrappedToken;
|
|
73
77
|
class VaultToken extends WrappedToken {
|
|
74
78
|
_wrap(amount, rounding) {
|
|
75
|
-
return
|
|
79
|
+
return vault_1.VaultUtils.toShares(amount, this, this.config, rounding);
|
|
76
80
|
}
|
|
77
81
|
_unwrap(amount, rounding) {
|
|
78
|
-
return
|
|
82
|
+
return vault_1.VaultUtils.toAssets(amount, this, this.config, rounding);
|
|
79
83
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
totalAssets;
|
|
85
|
+
totalSupply;
|
|
86
|
+
config;
|
|
87
|
+
constructor(token, { totalAssets, totalSupply, config, }) {
|
|
88
|
+
super(token, config.asset);
|
|
83
89
|
this.totalAssets = totalAssets;
|
|
84
90
|
this.totalSupply = totalSupply;
|
|
91
|
+
this.config = config;
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
exports.VaultToken = VaultToken;
|
package/lib/token/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Token";
|
|
2
2
|
export * from "./WrappedToken";
|
package/lib/token/index.js
CHANGED
|
@@ -14,5 +14,5 @@ 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("./Token"), exports);
|
|
18
18
|
__exportStar(require("./WrappedToken"), exports);
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMarketId = exports.
|
|
4
|
-
|
|
3
|
+
exports.isMarketId = exports.TransactionType = void 0;
|
|
4
|
+
exports.isFetched = isFetched;
|
|
5
5
|
/**
|
|
6
6
|
* The possible transaction type on the Blue contract
|
|
7
7
|
*/
|
|
@@ -18,6 +18,5 @@ var TransactionType;
|
|
|
18
18
|
function isFetched(v) {
|
|
19
19
|
return v !== undefined && v !== null;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
const isMarketId = (value) => (0, ethers_1.isHexString)(value, 32);
|
|
21
|
+
const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
23
22
|
exports.isMarketId = isMarketId;
|
package/lib/user/User.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.User = void 0;
|
|
4
4
|
class User {
|
|
5
|
+
/**
|
|
6
|
+
* The user's address.
|
|
7
|
+
*/
|
|
8
|
+
address;
|
|
9
|
+
/**
|
|
10
|
+
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
11
|
+
*/
|
|
12
|
+
isBundlerAuthorized;
|
|
13
|
+
/**
|
|
14
|
+
* The user's nonce on Morpho Blue.
|
|
15
|
+
*/
|
|
16
|
+
morphoNonce;
|
|
5
17
|
constructor({ address, isBundlerAuthorized, morphoNonce, }) {
|
|
6
18
|
this.address = address;
|
|
7
19
|
this.isBundlerAuthorized = isBundlerAuthorized;
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers";
|
|
2
1
|
import { CapacityLimit } from "../market";
|
|
3
2
|
import { RoundingDirection } from "../maths";
|
|
4
3
|
import { Token } from "../token";
|
|
5
4
|
import { Address, MarketId } from "../types";
|
|
6
|
-
import { InputVaultAllocation, VaultAllocation } from "./VaultAllocation";
|
|
7
5
|
import { VaultConfig } from "./VaultConfig";
|
|
6
|
+
import { InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation";
|
|
8
7
|
export interface Pending<T> {
|
|
9
8
|
value: T;
|
|
10
9
|
validAt: bigint;
|
|
@@ -28,18 +27,18 @@ export interface InputVault {
|
|
|
28
27
|
curator: Address;
|
|
29
28
|
owner: Address;
|
|
30
29
|
guardian: Address;
|
|
31
|
-
fee:
|
|
30
|
+
fee: bigint;
|
|
32
31
|
feeRecipient: Address;
|
|
33
32
|
skimRecipient: Address;
|
|
34
|
-
pendingTimelock: Pending<
|
|
33
|
+
pendingTimelock: Pending<bigint>;
|
|
35
34
|
pendingGuardian: Pending<Address>;
|
|
36
35
|
pendingOwner: Address;
|
|
37
|
-
timelock:
|
|
36
|
+
timelock: bigint;
|
|
38
37
|
supplyQueue: MarketId[];
|
|
39
38
|
withdrawQueue: MarketId[];
|
|
40
|
-
totalSupply:
|
|
41
|
-
totalAssets:
|
|
42
|
-
lastTotalAssets:
|
|
39
|
+
totalSupply: bigint;
|
|
40
|
+
totalAssets: bigint;
|
|
41
|
+
lastTotalAssets: bigint;
|
|
43
42
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
44
43
|
}
|
|
45
44
|
export declare class Vault implements InputVault {
|
|
@@ -118,8 +117,8 @@ export declare class Vault implements InputVault {
|
|
|
118
117
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
119
118
|
*/
|
|
120
119
|
get totalInterest(): bigint;
|
|
121
|
-
toAssets(shares:
|
|
122
|
-
toShares(assets:
|
|
120
|
+
toAssets(shares: bigint, rounding?: RoundingDirection): bigint;
|
|
121
|
+
toShares(assets: bigint, rounding?: RoundingDirection): bigint;
|
|
123
122
|
}
|
|
124
123
|
export interface CollateralAllocation {
|
|
125
124
|
address: Address;
|
|
@@ -134,7 +133,7 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
134
133
|
/**
|
|
135
134
|
* The allocation of the vault on each market enabled.
|
|
136
135
|
*/
|
|
137
|
-
readonly allocations: Map<MarketId,
|
|
136
|
+
readonly allocations: Map<MarketId, VaultMarketAllocation>;
|
|
138
137
|
/**
|
|
139
138
|
* The ERC4626 vault's share token.
|
|
140
139
|
*/
|
|
@@ -148,7 +147,7 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
148
147
|
* The allocation of the vault on each market of the withdraw queue,
|
|
149
148
|
* in the same order as the withdraw queue.
|
|
150
149
|
*/
|
|
151
|
-
allocations: Omit<
|
|
150
|
+
allocations: Omit<InputVaultMarketAllocation, "proportion">[]);
|
|
152
151
|
/**
|
|
153
152
|
* The vault's liquidity directly available from allocated markets.
|
|
154
153
|
*/
|
|
@@ -161,6 +160,7 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
161
160
|
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
162
161
|
*/
|
|
163
162
|
get netApy(): bigint;
|
|
163
|
+
getAllocationProportion(marketId: MarketId): bigint;
|
|
164
164
|
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
165
165
|
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
166
166
|
accrueInterest(timestamp: bigint): AccrualVault;
|
package/lib/vault/Vault.js
CHANGED
|
@@ -1,33 +1,100 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
4
|
const market_1 = require("../market");
|
|
6
5
|
const maths_1 = require("../maths");
|
|
7
6
|
const token_1 = require("../token");
|
|
8
|
-
const
|
|
7
|
+
const VaultMarketAllocation_1 = require("./VaultMarketAllocation");
|
|
9
8
|
const VaultUtils_1 = require("./VaultUtils");
|
|
10
9
|
class Vault {
|
|
10
|
+
/**
|
|
11
|
+
* The MetaMorpho vault's config.
|
|
12
|
+
*/
|
|
13
|
+
config;
|
|
14
|
+
/**
|
|
15
|
+
* The MetaMorpho vault's owner address.
|
|
16
|
+
*/
|
|
17
|
+
owner;
|
|
18
|
+
/**
|
|
19
|
+
* The MetaMorpho vault's curator address.
|
|
20
|
+
*/
|
|
21
|
+
curator;
|
|
22
|
+
/**
|
|
23
|
+
* The MetaMorpho vault's guardian address.
|
|
24
|
+
*/
|
|
25
|
+
guardian;
|
|
26
|
+
/**
|
|
27
|
+
* The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
|
|
28
|
+
*/
|
|
29
|
+
skimRecipient;
|
|
30
|
+
/**
|
|
31
|
+
* The MetaMorpho vault's fee recipient address.
|
|
32
|
+
*/
|
|
33
|
+
feeRecipient;
|
|
34
|
+
/**
|
|
35
|
+
* The MetaMorpho vault's timelock (in seconds).
|
|
36
|
+
*/
|
|
37
|
+
timelock;
|
|
38
|
+
/**
|
|
39
|
+
* The MetaMorpho vault's fee.
|
|
40
|
+
*/
|
|
41
|
+
fee;
|
|
42
|
+
/**
|
|
43
|
+
* The MetaMorpho vault's pending owner address and activation timestamp.
|
|
44
|
+
*/
|
|
45
|
+
pendingOwner;
|
|
46
|
+
/**
|
|
47
|
+
* The MetaMorpho vault's pending guardian address and activation timestamp.
|
|
48
|
+
*/
|
|
49
|
+
pendingGuardian;
|
|
50
|
+
/**
|
|
51
|
+
* The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
|
|
52
|
+
*/
|
|
53
|
+
pendingTimelock;
|
|
54
|
+
/**
|
|
55
|
+
* The MetaMorpho vault's ordered supply queue.
|
|
56
|
+
*/
|
|
57
|
+
supplyQueue;
|
|
58
|
+
/**
|
|
59
|
+
* The MetaMorpho vault's ordered withdraw queue.
|
|
60
|
+
*/
|
|
61
|
+
withdrawQueue;
|
|
62
|
+
/**
|
|
63
|
+
* The ERC4626 vault's total supply of shares.
|
|
64
|
+
*/
|
|
65
|
+
totalSupply;
|
|
66
|
+
/**
|
|
67
|
+
* The ERC4626 vault's total assets.
|
|
68
|
+
*/
|
|
69
|
+
totalAssets;
|
|
70
|
+
/**
|
|
71
|
+
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
72
|
+
*/
|
|
73
|
+
lastTotalAssets;
|
|
74
|
+
/**
|
|
75
|
+
* The MetaMorpho vault's public allocator configuration.
|
|
76
|
+
*/
|
|
77
|
+
publicAllocatorConfig;
|
|
11
78
|
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }) {
|
|
12
79
|
this.config = config;
|
|
13
80
|
this.curator = curator;
|
|
14
81
|
this.owner = owner;
|
|
15
82
|
this.guardian = guardian;
|
|
16
|
-
this.fee =
|
|
83
|
+
this.fee = fee;
|
|
17
84
|
this.feeRecipient = feeRecipient;
|
|
18
85
|
this.skimRecipient = skimRecipient;
|
|
19
86
|
this.pendingTimelock = {
|
|
20
|
-
value:
|
|
87
|
+
value: pendingTimelock.value,
|
|
21
88
|
validAt: pendingTimelock.validAt,
|
|
22
89
|
};
|
|
23
90
|
this.pendingGuardian = pendingGuardian;
|
|
24
91
|
this.pendingOwner = pendingOwner;
|
|
25
|
-
this.timelock =
|
|
92
|
+
this.timelock = timelock;
|
|
26
93
|
this.supplyQueue = supplyQueue;
|
|
27
94
|
this.withdrawQueue = withdrawQueue;
|
|
28
|
-
this.totalSupply =
|
|
29
|
-
this.totalAssets =
|
|
30
|
-
this.lastTotalAssets =
|
|
95
|
+
this.totalSupply = totalSupply;
|
|
96
|
+
this.totalAssets = totalAssets;
|
|
97
|
+
this.lastTotalAssets = lastTotalAssets;
|
|
31
98
|
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
32
99
|
}
|
|
33
100
|
get address() {
|
|
@@ -40,7 +107,7 @@ class Vault {
|
|
|
40
107
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
41
108
|
*/
|
|
42
109
|
get totalInterest() {
|
|
43
|
-
return maths_1.
|
|
110
|
+
return maths_1.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
44
111
|
}
|
|
45
112
|
toAssets(shares, rounding) {
|
|
46
113
|
return VaultUtils_1.VaultUtils.toAssets(shares, this, this.config, rounding);
|
|
@@ -51,6 +118,18 @@ class Vault {
|
|
|
51
118
|
}
|
|
52
119
|
exports.Vault = Vault;
|
|
53
120
|
class AccrualVault extends Vault {
|
|
121
|
+
/**
|
|
122
|
+
* The allocation of the vault on each market enabled.
|
|
123
|
+
*/
|
|
124
|
+
allocations;
|
|
125
|
+
/**
|
|
126
|
+
* The ERC4626 vault's share token.
|
|
127
|
+
*/
|
|
128
|
+
token;
|
|
129
|
+
/**
|
|
130
|
+
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
131
|
+
*/
|
|
132
|
+
collateralAllocations;
|
|
54
133
|
constructor(vault,
|
|
55
134
|
/**
|
|
56
135
|
* The allocation of the vault on each market of the withdraw queue,
|
|
@@ -64,17 +143,14 @@ class AccrualVault extends Vault {
|
|
|
64
143
|
});
|
|
65
144
|
this.allocations = new Map(allocations.map(({ config, position }) => [
|
|
66
145
|
position.market.id,
|
|
67
|
-
new
|
|
146
|
+
new VaultMarketAllocation_1.VaultMarketAllocation({
|
|
68
147
|
config,
|
|
69
148
|
position,
|
|
70
|
-
proportion: this.totalAssets === 0n
|
|
71
|
-
? 0n
|
|
72
|
-
: maths_1.MathLib.wDivDown(position.supplyAssets, this.totalAssets),
|
|
73
149
|
}),
|
|
74
150
|
]));
|
|
75
151
|
this.token = new token_1.Token(this.config);
|
|
76
152
|
this.collateralAllocations = new Map();
|
|
77
|
-
for (const {
|
|
153
|
+
for (const { marketId, position } of this.allocations.values()) {
|
|
78
154
|
const address = position.market.config.collateralToken;
|
|
79
155
|
let exposure = this.collateralAllocations.get(address);
|
|
80
156
|
if (!exposure)
|
|
@@ -87,8 +163,8 @@ class AccrualVault extends Vault {
|
|
|
87
163
|
}));
|
|
88
164
|
exposure.lltvs.add(position.market.config.lltv);
|
|
89
165
|
exposure.oracles.add(position.market.config.oracle);
|
|
90
|
-
exposure.markets.add(
|
|
91
|
-
exposure.proportion +=
|
|
166
|
+
exposure.markets.add(marketId);
|
|
167
|
+
exposure.proportion += this.getAllocationProportion(marketId);
|
|
92
168
|
}
|
|
93
169
|
}
|
|
94
170
|
/**
|
|
@@ -111,11 +187,19 @@ class AccrualVault extends Vault {
|
|
|
111
187
|
get netApy() {
|
|
112
188
|
return maths_1.MathLib.wMulDown(this.avgApy, maths_1.MathLib.WAD - this.fee);
|
|
113
189
|
}
|
|
190
|
+
getAllocationProportion(marketId) {
|
|
191
|
+
if (this.totalAssets === 0n)
|
|
192
|
+
return 0n;
|
|
193
|
+
const allocation = this.allocations.get(marketId);
|
|
194
|
+
if (!allocation)
|
|
195
|
+
return 0n;
|
|
196
|
+
return maths_1.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
197
|
+
}
|
|
114
198
|
getDepositCapacityLimit(assets) {
|
|
115
199
|
const suppliable = Array.from(this.allocations.values()).reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => maths_1.MathLib.min(total +
|
|
116
200
|
(this.supplyQueue.includes(marketId)
|
|
117
|
-
? maths_1.
|
|
118
|
-
: 0n),
|
|
201
|
+
? maths_1.MathLib.zeroFloorSub(cap, supplyAssets)
|
|
202
|
+
: 0n), maths_1.MathLib.MAX_UINT_256), 0n);
|
|
119
203
|
if (assets > suppliable)
|
|
120
204
|
return {
|
|
121
205
|
value: suppliable,
|
package/lib/vault/VaultConfig.js
CHANGED
|
@@ -3,14 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.VaultConfig = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
5
|
class VaultConfig {
|
|
6
|
+
chainId;
|
|
7
|
+
static _CACHE = {};
|
|
6
8
|
static get(address, chainId) {
|
|
7
9
|
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
8
10
|
if (!config)
|
|
9
11
|
throw new errors_1.UnknownVaultConfigError(address);
|
|
10
12
|
return config;
|
|
11
13
|
}
|
|
14
|
+
address;
|
|
15
|
+
decimals;
|
|
16
|
+
decimalsOffset;
|
|
17
|
+
symbol;
|
|
18
|
+
name;
|
|
19
|
+
asset;
|
|
12
20
|
constructor({ address, decimals, decimalsOffset, symbol, name, asset, }, chainId) {
|
|
13
|
-
var _a;
|
|
14
21
|
this.chainId = chainId;
|
|
15
22
|
this.address = address;
|
|
16
23
|
this.decimals = decimals;
|
|
@@ -19,8 +26,7 @@ class VaultConfig {
|
|
|
19
26
|
this.name = name;
|
|
20
27
|
this.asset = asset;
|
|
21
28
|
if (chainId != null)
|
|
22
|
-
(
|
|
29
|
+
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
exports.VaultConfig = VaultConfig;
|
|
26
|
-
VaultConfig._CACHE = {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AccrualPosition } from "../position";
|
|
2
|
+
import { VaultMarketConfig } from "./VaultMarketConfig";
|
|
3
|
+
export interface InputVaultMarketAllocation {
|
|
4
|
+
config: VaultMarketConfig;
|
|
5
|
+
position: AccrualPosition;
|
|
6
|
+
}
|
|
7
|
+
export declare class VaultMarketAllocation implements InputVaultMarketAllocation {
|
|
8
|
+
/**
|
|
9
|
+
* The vault's configuration on the corresponding market.
|
|
10
|
+
*/
|
|
11
|
+
config: VaultMarketConfig;
|
|
12
|
+
/**
|
|
13
|
+
* The vault's position on the corresponding market.
|
|
14
|
+
*/
|
|
15
|
+
readonly position: AccrualPosition;
|
|
16
|
+
constructor({ config, position }: InputVaultMarketAllocation);
|
|
17
|
+
get vault(): string;
|
|
18
|
+
get marketId(): import("..").MarketId;
|
|
19
|
+
get utilization(): bigint;
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultMarketAllocation = void 0;
|
|
4
|
+
const maths_1 = require("../maths");
|
|
5
|
+
class VaultMarketAllocation {
|
|
6
|
+
/**
|
|
7
|
+
* The vault's configuration on the corresponding market.
|
|
8
|
+
*/
|
|
9
|
+
config;
|
|
10
|
+
/**
|
|
11
|
+
* The vault's position on the corresponding market.
|
|
12
|
+
*/
|
|
13
|
+
position;
|
|
14
|
+
constructor({ config, position }) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.position = position;
|
|
17
|
+
}
|
|
18
|
+
get vault() {
|
|
19
|
+
return this.config.vault;
|
|
20
|
+
}
|
|
21
|
+
get marketId() {
|
|
22
|
+
return this.config.marketId;
|
|
23
|
+
}
|
|
24
|
+
get utilization() {
|
|
25
|
+
if (this.config.cap === 0n)
|
|
26
|
+
return maths_1.MathLib.MAX_UINT_256;
|
|
27
|
+
return maths_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.VaultMarketAllocation = VaultMarketAllocation;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Address, MarketId } from "../types";
|
|
2
|
+
import { Pending } from "./Vault";
|
|
3
|
+
import { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig";
|
|
4
|
+
export interface InputVaultMarketConfig {
|
|
5
|
+
vault: Address;
|
|
6
|
+
marketId: MarketId;
|
|
7
|
+
cap: bigint;
|
|
8
|
+
pendingCap: Pending<bigint>;
|
|
9
|
+
removableAt: bigint;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
12
|
+
}
|
|
13
|
+
export declare class VaultMarketConfig implements InputVaultMarketConfig {
|
|
14
|
+
/**
|
|
15
|
+
* The vault's address.
|
|
16
|
+
*/
|
|
17
|
+
vault: Address;
|
|
18
|
+
/**
|
|
19
|
+
* The market's id.
|
|
20
|
+
*/
|
|
21
|
+
marketId: MarketId;
|
|
22
|
+
/**
|
|
23
|
+
* The maximum amount of tokens that can be allocated to this market.
|
|
24
|
+
*/
|
|
25
|
+
cap: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* The pending maximum amount of tokens that can be allocated to this market.
|
|
28
|
+
*/
|
|
29
|
+
pendingCap: Pending<bigint>;
|
|
30
|
+
/**
|
|
31
|
+
* The timestamp at which the market can be removed from the withdraw queue.
|
|
32
|
+
*/
|
|
33
|
+
removableAt: bigint;
|
|
34
|
+
/**
|
|
35
|
+
* Whether this market is enabled, i.e. whether additional tokens can be allocated to it.
|
|
36
|
+
*/
|
|
37
|
+
enabled: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The vault's PublicAllocator configuration on the corresponding market.
|
|
40
|
+
*/
|
|
41
|
+
publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
|
|
42
|
+
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }: InputVaultMarketConfig);
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultMarketConfig = void 0;
|
|
4
|
+
class VaultMarketConfig {
|
|
5
|
+
/**
|
|
6
|
+
* The vault's address.
|
|
7
|
+
*/
|
|
8
|
+
vault;
|
|
9
|
+
/**
|
|
10
|
+
* The market's id.
|
|
11
|
+
*/
|
|
12
|
+
marketId;
|
|
13
|
+
/**
|
|
14
|
+
* The maximum amount of tokens that can be allocated to this market.
|
|
15
|
+
*/
|
|
16
|
+
cap;
|
|
17
|
+
/**
|
|
18
|
+
* The pending maximum amount of tokens that can be allocated to this market.
|
|
19
|
+
*/
|
|
20
|
+
pendingCap;
|
|
21
|
+
/**
|
|
22
|
+
* The timestamp at which the market can be removed from the withdraw queue.
|
|
23
|
+
*/
|
|
24
|
+
removableAt;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this market is enabled, i.e. whether additional tokens can be allocated to it.
|
|
27
|
+
*/
|
|
28
|
+
enabled;
|
|
29
|
+
/**
|
|
30
|
+
* The vault's PublicAllocator configuration on the corresponding market.
|
|
31
|
+
*/
|
|
32
|
+
publicAllocatorConfig;
|
|
33
|
+
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }) {
|
|
34
|
+
this.vault = vault;
|
|
35
|
+
this.marketId = marketId;
|
|
36
|
+
this.cap = cap;
|
|
37
|
+
this.pendingCap = pendingCap;
|
|
38
|
+
this.removableAt = removableAt;
|
|
39
|
+
this.enabled = enabled;
|
|
40
|
+
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.VaultMarketConfig = VaultMarketConfig;
|