@morpho-org/blue-sdk 2.0.0-next.9 → 2.0.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/addresses.d.ts +1 -1
- package/lib/addresses.js +63 -58
- package/lib/chain.js +9 -6
- package/lib/constants.js +12 -9
- package/lib/errors.d.ts +5 -0
- package/lib/errors.js +37 -13
- package/lib/holding/AssetBalances.d.ts +2 -2
- package/lib/holding/AssetBalances.js +5 -1
- package/lib/holding/Holding.d.ts +5 -5
- package/lib/holding/Holding.js +9 -5
- package/lib/holding/index.js +18 -2
- package/lib/index.js +28 -12
- package/lib/market/Market.d.ts +37 -25
- package/lib/market/Market.js +72 -51
- package/lib/market/MarketParams.d.ts +4 -3
- package/lib/market/MarketParams.js +16 -14
- package/lib/market/MarketUtils.d.ts +81 -30
- package/lib/market/MarketUtils.js +135 -51
- package/lib/market/index.js +19 -3
- package/lib/math/AdaptiveCurveIrmLib.js +25 -22
- package/lib/math/MathLib.d.ts +1 -16
- package/lib/math/MathLib.js +6 -29
- package/lib/math/SharesMath.js +8 -5
- package/lib/math/index.js +19 -3
- package/lib/position/Position.d.ts +28 -19
- package/lib/position/Position.js +49 -43
- package/lib/position/index.js +17 -1
- package/lib/token/ConstantWrappedToken.d.ts +2 -2
- package/lib/token/ConstantWrappedToken.js +10 -6
- package/lib/token/ExchangeRateWrappedToken.d.ts +2 -2
- package/lib/token/ExchangeRateWrappedToken.js +9 -5
- package/lib/token/Token.d.ts +15 -15
- package/lib/token/Token.js +27 -25
- package/lib/token/VaultToken.d.ts +4 -4
- package/lib/token/VaultToken.js +9 -5
- package/lib/token/WrappedToken.d.ts +2 -2
- package/lib/token/WrappedToken.js +11 -7
- package/lib/token/index.js +21 -5
- package/lib/types.js +9 -4
- package/lib/user/User.js +5 -1
- package/lib/user/index.js +17 -1
- package/lib/vault/Vault.d.ts +20 -12
- package/lib/vault/Vault.js +26 -21
- package/lib/vault/VaultConfig.d.ts +3 -4
- package/lib/vault/VaultConfig.js +9 -5
- package/lib/vault/VaultMarketAllocation.d.ts +3 -3
- package/lib/vault/VaultMarketAllocation.js +8 -4
- package/lib/vault/VaultMarketConfig.d.ts +3 -3
- package/lib/vault/VaultMarketConfig.js +5 -1
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +3 -3
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +5 -1
- package/lib/vault/VaultUser.d.ts +3 -3
- package/lib/vault/VaultUser.js +5 -1
- package/lib/vault/VaultUtils.js +9 -6
- package/lib/vault/index.js +23 -7
- package/package.json +9 -19
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExchangeRateWrappedToken = void 0;
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
|
+
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
|
+
class ExchangeRateWrappedToken extends WrappedToken_js_1.WrappedToken {
|
|
4
7
|
underlying;
|
|
5
8
|
wrappedTokenExchangeRate;
|
|
6
9
|
constructor(token, underlying, wrappedTokenExchangeRate) {
|
|
@@ -9,9 +12,10 @@ export class ExchangeRateWrappedToken extends WrappedToken {
|
|
|
9
12
|
this.wrappedTokenExchangeRate = wrappedTokenExchangeRate;
|
|
10
13
|
}
|
|
11
14
|
_wrap(amount, rounding) {
|
|
12
|
-
return MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
15
|
+
return index_js_1.MathLib.wDiv(amount, this.wrappedTokenExchangeRate, rounding);
|
|
13
16
|
}
|
|
14
17
|
_unwrap(amount, rounding) {
|
|
15
|
-
return MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
18
|
+
return index_js_1.MathLib.wMul(amount, this.wrappedTokenExchangeRate, rounding);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
exports.ExchangeRateWrappedToken = ExchangeRateWrappedToken;
|
package/lib/token/Token.d.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
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
|
-
export interface
|
|
4
|
+
export interface IToken {
|
|
5
5
|
address: Address;
|
|
6
|
-
decimals: BigIntish;
|
|
7
|
-
symbol: string;
|
|
8
6
|
name?: string;
|
|
7
|
+
symbol?: string;
|
|
8
|
+
decimals?: BigIntish;
|
|
9
|
+
price?: BigIntish;
|
|
9
10
|
}
|
|
10
|
-
export declare class Token implements
|
|
11
|
+
export declare class Token implements IToken {
|
|
11
12
|
static native(chainId: ChainId): Token;
|
|
12
13
|
/**
|
|
13
14
|
* The token's address.
|
|
14
15
|
*/
|
|
15
16
|
readonly address: Address;
|
|
16
17
|
/**
|
|
17
|
-
* The token's
|
|
18
|
+
* The token's name.
|
|
18
19
|
*/
|
|
19
|
-
readonly
|
|
20
|
+
readonly name?: string;
|
|
20
21
|
/**
|
|
21
22
|
* The token's symbol.
|
|
22
23
|
*/
|
|
23
|
-
readonly symbol
|
|
24
|
+
readonly symbol?: string;
|
|
24
25
|
/**
|
|
25
|
-
* The
|
|
26
|
+
* The token's number of decimals. Defaults to 0.
|
|
26
27
|
*/
|
|
27
|
-
readonly
|
|
28
|
-
constructor({ address, decimals, symbol, name }: InputToken);
|
|
29
|
-
}
|
|
30
|
-
export declare class TokenWithPrice extends Token {
|
|
28
|
+
readonly decimals: number;
|
|
31
29
|
/**
|
|
32
30
|
* Price of the token in USD (scaled by WAD).
|
|
33
31
|
*/
|
|
34
32
|
price?: bigint;
|
|
35
|
-
constructor(
|
|
33
|
+
constructor({ address, name, symbol, decimals, price }: IToken);
|
|
36
34
|
/**
|
|
37
35
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
36
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
38
37
|
* @param amount The amount of USD to quote.
|
|
39
38
|
*/
|
|
40
|
-
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint |
|
|
39
|
+
fromUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
41
40
|
/**
|
|
42
41
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
42
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
43
43
|
* @param amount The amount of tokens to quote.
|
|
44
44
|
*/
|
|
45
|
-
toUsd(amount: bigint, rounding?: RoundingDirection): bigint |
|
|
45
|
+
toUsd(amount: bigint, rounding?: RoundingDirection): bigint | undefined;
|
|
46
46
|
}
|
package/lib/token/Token.js
CHANGED
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Token = void 0;
|
|
4
|
+
const addresses_js_1 = require("../addresses.js");
|
|
5
|
+
const chain_js_1 = require("../chain.js");
|
|
6
|
+
const index_js_1 = require("../math/index.js");
|
|
7
|
+
class Token {
|
|
5
8
|
static native(chainId) {
|
|
6
|
-
const currency = ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
7
|
-
return new Token({ ...currency, address: NATIVE_ADDRESS });
|
|
9
|
+
const currency = chain_js_1.ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
|
|
10
|
+
return new Token({ ...currency, address: addresses_js_1.NATIVE_ADDRESS });
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* The token's address.
|
|
11
14
|
*/
|
|
12
15
|
address;
|
|
13
16
|
/**
|
|
14
|
-
* The token's
|
|
17
|
+
* The token's name.
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
name;
|
|
17
20
|
/**
|
|
18
21
|
* The token's symbol.
|
|
19
22
|
*/
|
|
20
23
|
symbol;
|
|
21
24
|
/**
|
|
22
|
-
* The
|
|
25
|
+
* The token's number of decimals. Defaults to 0.
|
|
23
26
|
*/
|
|
24
|
-
|
|
25
|
-
constructor({ address, decimals, symbol, name }) {
|
|
26
|
-
this.address = address;
|
|
27
|
-
this.decimals = Number(decimals);
|
|
28
|
-
this.symbol = symbol;
|
|
29
|
-
this.name = name ?? symbol;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export class TokenWithPrice extends Token {
|
|
27
|
+
decimals;
|
|
33
28
|
/**
|
|
34
29
|
* Price of the token in USD (scaled by WAD).
|
|
35
30
|
*/
|
|
36
31
|
price;
|
|
37
|
-
constructor(
|
|
38
|
-
|
|
39
|
-
this.
|
|
32
|
+
constructor({ address, name, symbol, decimals = 0, price }) {
|
|
33
|
+
this.address = address;
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.symbol = symbol;
|
|
36
|
+
this.decimals = Number(decimals);
|
|
37
|
+
if (price != null)
|
|
38
|
+
this.price = BigInt(price);
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
* Quotes an amount in USD (scaled by WAD) in this token.
|
|
42
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
43
43
|
* @param amount The amount of USD to quote.
|
|
44
44
|
*/
|
|
45
45
|
fromUsd(amount, rounding = "Down") {
|
|
46
46
|
if (this.price == null)
|
|
47
|
-
return
|
|
48
|
-
return MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
47
|
+
return;
|
|
48
|
+
return index_js_1.MathLib.mulDiv(amount, 10n ** BigInt(this.decimals), this.price, rounding);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Quotes an amount of tokens in USD (scaled by WAD).
|
|
52
|
+
* Returns `undefined` iff the token's price is undefined.
|
|
52
53
|
* @param amount The amount of tokens to quote.
|
|
53
54
|
*/
|
|
54
55
|
toUsd(amount, rounding = "Down") {
|
|
55
56
|
if (this.price == null)
|
|
56
|
-
return
|
|
57
|
-
return MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
57
|
+
return;
|
|
58
|
+
return index_js_1.MathLib.mulDiv(amount, this.price, 10n ** BigInt(this.decimals), rounding);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
exports.Token = Token;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { Address } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IVaultConfig } from "../vault/VaultConfig.js";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken.js";
|
|
5
|
-
export interface
|
|
5
|
+
export interface IVaultToken {
|
|
6
6
|
totalAssets: bigint;
|
|
7
7
|
totalSupply: bigint;
|
|
8
8
|
}
|
|
9
|
-
export declare class VaultToken extends WrappedToken implements
|
|
9
|
+
export declare class VaultToken extends WrappedToken implements IVaultToken {
|
|
10
10
|
readonly asset: Address;
|
|
11
11
|
readonly decimalsOffset: bigint;
|
|
12
12
|
/**
|
|
@@ -17,7 +17,7 @@ export declare class VaultToken extends WrappedToken implements InputVaultToken
|
|
|
17
17
|
* The ERC4626 vault's total assets.
|
|
18
18
|
*/
|
|
19
19
|
totalAssets: bigint;
|
|
20
|
-
constructor(config:
|
|
20
|
+
constructor(config: IVaultConfig, { totalAssets, totalSupply }: IVaultToken);
|
|
21
21
|
protected _wrap(amount: bigint, rounding?: RoundingDirection): bigint;
|
|
22
22
|
protected _unwrap(amount: bigint, rounding?: RoundingDirection): bigint;
|
|
23
23
|
}
|
package/lib/token/VaultToken.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultToken = void 0;
|
|
4
|
+
const VaultUtils_js_1 = require("../vault/VaultUtils.js");
|
|
5
|
+
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
|
+
class VaultToken extends WrappedToken_js_1.WrappedToken {
|
|
4
7
|
asset;
|
|
5
8
|
decimalsOffset;
|
|
6
9
|
/**
|
|
@@ -19,9 +22,10 @@ export class VaultToken extends WrappedToken {
|
|
|
19
22
|
this.decimalsOffset = BigInt(config.decimalsOffset);
|
|
20
23
|
}
|
|
21
24
|
_wrap(amount, rounding) {
|
|
22
|
-
return VaultUtils.toShares(amount, this, rounding);
|
|
25
|
+
return VaultUtils_js_1.VaultUtils.toShares(amount, this, rounding);
|
|
23
26
|
}
|
|
24
27
|
_unwrap(amount, rounding) {
|
|
25
|
-
return VaultUtils.toAssets(amount, this, rounding);
|
|
28
|
+
return VaultUtils_js_1.VaultUtils.toAssets(amount, this, rounding);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
31
|
+
exports.VaultToken = VaultToken;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { Address } from "../types.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type IToken, Token } from "./Token.js";
|
|
4
4
|
export declare abstract class WrappedToken extends Token {
|
|
5
5
|
readonly underlying: Address;
|
|
6
|
-
constructor(token:
|
|
6
|
+
constructor(token: IToken, underlying: Address);
|
|
7
7
|
/** The expected amount when wrapping `unwrappedAmount` */
|
|
8
8
|
toWrappedExactAmountIn(unwrappedAmount: bigint, slippage?: bigint, rounding?: RoundingDirection): bigint;
|
|
9
9
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WrappedToken = void 0;
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
|
+
const Token_js_1 = require("./Token.js");
|
|
6
|
+
class WrappedToken extends Token_js_1.Token {
|
|
4
7
|
underlying;
|
|
5
8
|
constructor(token, underlying) {
|
|
6
9
|
super(token);
|
|
@@ -9,21 +12,22 @@ export class WrappedToken extends Token {
|
|
|
9
12
|
/** The expected amount when wrapping `unwrappedAmount` */
|
|
10
13
|
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
11
14
|
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
12
|
-
return MathLib.wMul(wrappedAmount, MathLib.WAD - slippage, "Down");
|
|
15
|
+
return index_js_1.MathLib.wMul(wrappedAmount, index_js_1.MathLib.WAD - slippage, "Down");
|
|
13
16
|
}
|
|
14
17
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
15
18
|
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
16
|
-
const wAmountTarget = MathLib.wDiv(wrappedAmount, MathLib.WAD - slippage, rounding);
|
|
19
|
+
const wAmountTarget = index_js_1.MathLib.wDiv(wrappedAmount, index_js_1.MathLib.WAD - slippage, rounding);
|
|
17
20
|
return this._unwrap(wAmountTarget, rounding);
|
|
18
21
|
}
|
|
19
22
|
/** The expected amount when unwrapping `wrappedAmount` */
|
|
20
23
|
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
21
24
|
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
22
|
-
return MathLib.wMul(unwrappedAmount, MathLib.WAD - slippage, "Up");
|
|
25
|
+
return index_js_1.MathLib.wMul(unwrappedAmount, index_js_1.MathLib.WAD - slippage, "Up");
|
|
23
26
|
}
|
|
24
27
|
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
25
28
|
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
26
|
-
const unwrappedAmountToTarget = MathLib.wDiv(unwrappedAmount, MathLib.WAD - slippage, rounding);
|
|
29
|
+
const unwrappedAmountToTarget = index_js_1.MathLib.wDiv(unwrappedAmount, index_js_1.MathLib.WAD - slippage, rounding);
|
|
27
30
|
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
28
31
|
}
|
|
29
32
|
}
|
|
33
|
+
exports.WrappedToken = WrappedToken;
|
package/lib/token/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Token.js"), exports);
|
|
18
|
+
__exportStar(require("./WrappedToken.js"), exports);
|
|
19
|
+
__exportStar(require("./ConstantWrappedToken.js"), exports);
|
|
20
|
+
__exportStar(require("./ExchangeRateWrappedToken.js"), exports);
|
|
21
|
+
__exportStar(require("./VaultToken.js"), exports);
|
package/lib/types.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMarketId = exports.TransactionType = void 0;
|
|
4
|
+
exports.isFetched = isFetched;
|
|
1
5
|
/**
|
|
2
6
|
* The possible transaction type on the Blue contract
|
|
3
7
|
*/
|
|
4
|
-
|
|
8
|
+
var TransactionType;
|
|
5
9
|
(function (TransactionType) {
|
|
6
10
|
TransactionType["Supply"] = "Supply";
|
|
7
11
|
TransactionType["SupplyCollateral"] = "Supply Collateral";
|
|
@@ -9,9 +13,10 @@ export var TransactionType;
|
|
|
9
13
|
TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
|
|
10
14
|
TransactionType["Borrow"] = "Borrow";
|
|
11
15
|
TransactionType["Repay"] = "Repay";
|
|
12
|
-
})(TransactionType || (TransactionType = {}));
|
|
16
|
+
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
13
17
|
// TODO: replace with isDefined
|
|
14
|
-
|
|
18
|
+
function isFetched(v) {
|
|
15
19
|
return v !== undefined && v !== null;
|
|
16
20
|
}
|
|
17
|
-
|
|
21
|
+
const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
22
|
+
exports.isMarketId = isMarketId;
|
package/lib/user/User.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
class User {
|
|
2
5
|
/**
|
|
3
6
|
* The user's address.
|
|
4
7
|
*/
|
|
@@ -17,3 +20,4 @@ export class User {
|
|
|
17
20
|
this.morphoNonce = morphoNonce;
|
|
18
21
|
}
|
|
19
22
|
}
|
|
23
|
+
exports.User = User;
|
package/lib/user/index.js
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./User.js"), exports);
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { type CapacityLimit } from "../market/index.js";
|
|
|
2
2
|
import { type RoundingDirection } from "../math/index.js";
|
|
3
3
|
import { VaultToken } from "../token/index.js";
|
|
4
4
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
5
|
-
import type {
|
|
6
|
-
import { type
|
|
5
|
+
import type { IVaultConfig } from "./VaultConfig.js";
|
|
6
|
+
import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
|
|
7
7
|
export interface Pending<T> {
|
|
8
8
|
value: T;
|
|
9
9
|
validAt: bigint;
|
|
@@ -22,7 +22,7 @@ export interface VaultPublicAllocatorConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
accruedFee: bigint;
|
|
24
24
|
}
|
|
25
|
-
export interface
|
|
25
|
+
export interface IVault extends IVaultConfig {
|
|
26
26
|
curator: Address;
|
|
27
27
|
owner: Address;
|
|
28
28
|
guardian: Address;
|
|
@@ -40,7 +40,15 @@ export interface InputVault extends InputVaultConfig {
|
|
|
40
40
|
lastTotalAssets: bigint;
|
|
41
41
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
42
42
|
}
|
|
43
|
-
export declare class Vault extends VaultToken implements
|
|
43
|
+
export declare class Vault extends VaultToken implements IVault {
|
|
44
|
+
/**
|
|
45
|
+
* The vault's share token's name.
|
|
46
|
+
*/
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The vault's share token's symbol.
|
|
50
|
+
*/
|
|
51
|
+
readonly symbol: string;
|
|
44
52
|
/**
|
|
45
53
|
* The MetaMorpho vault's owner address.
|
|
46
54
|
*/
|
|
@@ -97,7 +105,7 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
97
105
|
* The MetaMorpho vault's public allocator configuration.
|
|
98
106
|
*/
|
|
99
107
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
100
|
-
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }:
|
|
108
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }: IVault);
|
|
101
109
|
/**
|
|
102
110
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
103
111
|
*/
|
|
@@ -112,9 +120,9 @@ export interface CollateralAllocation {
|
|
|
112
120
|
markets: Set<MarketId>;
|
|
113
121
|
proportion: bigint;
|
|
114
122
|
}
|
|
115
|
-
export interface
|
|
123
|
+
export interface IAccrualVault extends Omit<IVault, "withdrawQueue" | "totalAssets"> {
|
|
116
124
|
}
|
|
117
|
-
export declare class AccrualVault extends Vault implements
|
|
125
|
+
export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
118
126
|
/**
|
|
119
127
|
* The allocation of the vault on each market enabled.
|
|
120
128
|
*/
|
|
@@ -123,22 +131,22 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
123
131
|
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
124
132
|
*/
|
|
125
133
|
readonly collateralAllocations: Map<Address, CollateralAllocation>;
|
|
126
|
-
constructor(vault:
|
|
134
|
+
constructor(vault: IAccrualVault,
|
|
127
135
|
/**
|
|
128
136
|
* The allocation of the vault on each market of the withdraw queue,
|
|
129
137
|
* in the same order as the withdraw queue.
|
|
130
138
|
*/
|
|
131
|
-
allocations: Omit<
|
|
139
|
+
allocations: Omit<IVaultMarketAllocation, "proportion">[]);
|
|
132
140
|
/**
|
|
133
141
|
* The vault's liquidity directly available from allocated markets.
|
|
134
142
|
*/
|
|
135
143
|
get liquidity(): bigint;
|
|
136
144
|
/**
|
|
137
|
-
* The MetaMorpho vault's
|
|
145
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, before deducting the performance fee.
|
|
138
146
|
*/
|
|
139
|
-
get
|
|
147
|
+
get apy(): bigint;
|
|
140
148
|
/**
|
|
141
|
-
* The MetaMorpho vault's
|
|
149
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, after deducting the performance fee.
|
|
142
150
|
*/
|
|
143
151
|
get netApy(): bigint;
|
|
144
152
|
getAllocationProportion(marketId: MarketId): bigint;
|
package/lib/vault/Vault.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
+
const index_js_1 = require("../market/index.js");
|
|
5
|
+
const index_js_2 = require("../math/index.js");
|
|
6
|
+
const index_js_3 = require("../token/index.js");
|
|
7
|
+
const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
|
|
8
|
+
class Vault extends index_js_3.VaultToken {
|
|
6
9
|
/**
|
|
7
10
|
* The MetaMorpho vault's owner address.
|
|
8
11
|
*/
|
|
@@ -83,7 +86,7 @@ export class Vault extends VaultToken {
|
|
|
83
86
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
84
87
|
*/
|
|
85
88
|
get totalInterest() {
|
|
86
|
-
return MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
89
|
+
return index_js_2.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
87
90
|
}
|
|
88
91
|
toAssets(shares, rounding) {
|
|
89
92
|
return this._unwrap(shares, rounding);
|
|
@@ -92,7 +95,8 @@ export class Vault extends VaultToken {
|
|
|
92
95
|
return this._wrap(assets, rounding);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
|
|
98
|
+
exports.Vault = Vault;
|
|
99
|
+
class AccrualVault extends Vault {
|
|
96
100
|
/**
|
|
97
101
|
* The allocation of the vault on each market enabled.
|
|
98
102
|
*/
|
|
@@ -114,7 +118,7 @@ export class AccrualVault extends Vault {
|
|
|
114
118
|
});
|
|
115
119
|
this.allocations = new Map(allocations.map((allocation) => [
|
|
116
120
|
allocation.position.market.id,
|
|
117
|
-
new VaultMarketAllocation(allocation),
|
|
121
|
+
new VaultMarketAllocation_js_1.VaultMarketAllocation(allocation),
|
|
118
122
|
]));
|
|
119
123
|
this.collateralAllocations = new Map();
|
|
120
124
|
for (const { marketId, position } of this.allocations.values()) {
|
|
@@ -143,9 +147,9 @@ export class AccrualVault extends Vault {
|
|
|
143
147
|
.reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
144
148
|
}
|
|
145
149
|
/**
|
|
146
|
-
* The MetaMorpho vault's
|
|
150
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, before deducting the performance fee.
|
|
147
151
|
*/
|
|
148
|
-
get
|
|
152
|
+
get apy() {
|
|
149
153
|
if (this.totalAssets === 0n)
|
|
150
154
|
return 0n;
|
|
151
155
|
return (this.allocations
|
|
@@ -153,10 +157,10 @@ export class AccrualVault extends Vault {
|
|
|
153
157
|
.reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
154
158
|
}
|
|
155
159
|
/**
|
|
156
|
-
* The MetaMorpho vault's
|
|
160
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, after deducting the performance fee.
|
|
157
161
|
*/
|
|
158
162
|
get netApy() {
|
|
159
|
-
return MathLib.wMulDown(this.
|
|
163
|
+
return index_js_2.MathLib.wMulDown(this.apy, index_js_2.MathLib.WAD - this.fee);
|
|
160
164
|
}
|
|
161
165
|
getAllocationProportion(marketId) {
|
|
162
166
|
if (this.totalAssets === 0n)
|
|
@@ -164,23 +168,23 @@ export class AccrualVault extends Vault {
|
|
|
164
168
|
const allocation = this.allocations.get(marketId);
|
|
165
169
|
if (!allocation)
|
|
166
170
|
return 0n;
|
|
167
|
-
return MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
171
|
+
return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
168
172
|
}
|
|
169
173
|
getDepositCapacityLimit(assets) {
|
|
170
174
|
const suppliable = this.allocations
|
|
171
175
|
.values()
|
|
172
|
-
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => MathLib.min(total +
|
|
176
|
+
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
|
|
173
177
|
(this.supplyQueue.includes(marketId)
|
|
174
|
-
? MathLib.zeroFloorSub(cap, supplyAssets)
|
|
175
|
-
: 0n), MathLib.MAX_UINT_256), 0n);
|
|
178
|
+
? index_js_2.MathLib.zeroFloorSub(cap, supplyAssets)
|
|
179
|
+
: 0n), index_js_2.MathLib.MAX_UINT_256), 0n);
|
|
176
180
|
if (assets > suppliable)
|
|
177
181
|
return {
|
|
178
182
|
value: suppliable,
|
|
179
|
-
limiter: CapacityLimitReason.cap,
|
|
183
|
+
limiter: index_js_1.CapacityLimitReason.cap,
|
|
180
184
|
};
|
|
181
185
|
return {
|
|
182
186
|
value: assets,
|
|
183
|
-
limiter: CapacityLimitReason.balance,
|
|
187
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
184
188
|
};
|
|
185
189
|
}
|
|
186
190
|
getWithdrawCapacityLimit(shares) {
|
|
@@ -189,11 +193,11 @@ export class AccrualVault extends Vault {
|
|
|
189
193
|
if (assets > liquidity)
|
|
190
194
|
return {
|
|
191
195
|
value: liquidity,
|
|
192
|
-
limiter: CapacityLimitReason.liquidity,
|
|
196
|
+
limiter: index_js_1.CapacityLimitReason.liquidity,
|
|
193
197
|
};
|
|
194
198
|
return {
|
|
195
199
|
value: assets,
|
|
196
|
-
limiter: CapacityLimitReason.balance,
|
|
200
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
197
201
|
};
|
|
198
202
|
}
|
|
199
203
|
/**
|
|
@@ -210,7 +214,7 @@ export class AccrualVault extends Vault {
|
|
|
210
214
|
position: position.accrueInterest(timestamp),
|
|
211
215
|
};
|
|
212
216
|
}));
|
|
213
|
-
const feeAssets = MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
217
|
+
const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
214
218
|
vault.totalAssets -= feeAssets;
|
|
215
219
|
const feeShares = vault.toShares(feeAssets, "Down");
|
|
216
220
|
vault.totalAssets += feeAssets;
|
|
@@ -219,3 +223,4 @@ export class AccrualVault extends Vault {
|
|
|
219
223
|
return vault;
|
|
220
224
|
}
|
|
221
225
|
}
|
|
226
|
+
exports.AccrualVault = AccrualVault;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { ChainId } from "../chain.js";
|
|
2
2
|
import type { Address, BigIntish } from "../types.js";
|
|
3
|
-
export interface
|
|
3
|
+
export interface IVaultConfig {
|
|
4
4
|
address: Address;
|
|
5
|
-
decimals: BigIntish;
|
|
6
5
|
decimalsOffset: BigIntish;
|
|
7
6
|
symbol: string;
|
|
8
7
|
name: string;
|
|
9
8
|
asset: Address;
|
|
10
9
|
}
|
|
11
|
-
export declare class VaultConfig implements
|
|
10
|
+
export declare class VaultConfig implements IVaultConfig {
|
|
12
11
|
readonly chainId?: number | undefined;
|
|
13
12
|
protected static readonly _CACHE: Record<number, Record<Address, VaultConfig>>;
|
|
14
13
|
static get(address: Address, chainId: ChainId): VaultConfig;
|
|
@@ -18,5 +17,5 @@ export declare class VaultConfig implements InputVaultConfig {
|
|
|
18
17
|
readonly symbol: string;
|
|
19
18
|
readonly name: string;
|
|
20
19
|
readonly asset: Address;
|
|
21
|
-
constructor({ address,
|
|
20
|
+
constructor({ address, decimalsOffset, symbol, name, asset }: IVaultConfig, chainId?: number | undefined);
|
|
22
21
|
}
|
package/lib/vault/VaultConfig.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultConfig = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
|
+
class VaultConfig {
|
|
3
6
|
chainId;
|
|
4
7
|
static _CACHE = {};
|
|
5
8
|
static get(address, chainId) {
|
|
6
9
|
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
7
10
|
if (!config)
|
|
8
|
-
throw new UnknownVaultConfigError(address);
|
|
11
|
+
throw new errors_js_1.UnknownVaultConfigError(address);
|
|
9
12
|
return config;
|
|
10
13
|
}
|
|
11
14
|
address;
|
|
@@ -14,10 +17,10 @@ export class VaultConfig {
|
|
|
14
17
|
symbol;
|
|
15
18
|
name;
|
|
16
19
|
asset;
|
|
17
|
-
constructor({ address,
|
|
20
|
+
constructor({ address, decimalsOffset, symbol, name, asset }, chainId) {
|
|
18
21
|
this.chainId = chainId;
|
|
19
22
|
this.address = address;
|
|
20
|
-
this.decimals =
|
|
23
|
+
this.decimals = 18;
|
|
21
24
|
this.decimalsOffset = BigInt(decimalsOffset);
|
|
22
25
|
this.symbol = symbol;
|
|
23
26
|
this.name = name;
|
|
@@ -26,3 +29,4 @@ export class VaultConfig {
|
|
|
26
29
|
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
exports.VaultConfig = VaultConfig;
|