@morpho-org/blue-sdk 2.0.0-alpha.6 → 2.0.0-next.2
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/LICENSE +21 -0
- package/README.md +41 -21
- package/lib/addresses.d.ts +58 -54
- package/lib/addresses.js +60 -66
- package/lib/chain.d.ts +1 -1
- package/lib/chain.js +7 -10
- package/lib/constants.js +9 -12
- package/lib/errors.d.ts +1 -1
- package/lib/errors.js +9 -19
- package/lib/holding/AssetBalances.d.ts +1 -1
- package/lib/holding/AssetBalances.js +1 -5
- package/lib/holding/Holding.d.ts +1 -1
- package/lib/holding/Holding.js +5 -9
- package/lib/holding/index.d.ts +2 -2
- package/lib/holding/index.js +2 -18
- package/lib/index.d.ts +12 -23
- package/lib/index.js +12 -52
- package/lib/market/Market.d.ts +8 -6
- package/lib/market/Market.js +51 -53
- package/lib/market/MarketConfig.d.ts +1 -1
- package/lib/market/MarketConfig.js +10 -13
- package/lib/market/MarketUtils.d.ts +8 -7
- package/lib/market/MarketUtils.js +48 -54
- package/lib/market/index.d.ts +3 -3
- package/lib/market/index.js +3 -19
- package/lib/{maths → math}/AdaptiveCurveIrmLib.d.ts +1 -1
- package/lib/{maths → math}/AdaptiveCurveIrmLib.js +22 -25
- package/lib/{maths → math}/MathLib.d.ts +25 -28
- package/lib/{maths → math}/MathLib.js +51 -40
- package/lib/{maths → math}/SharesMath.d.ts +2 -2
- package/lib/{maths → math}/SharesMath.js +5 -8
- package/lib/math/index.d.ts +3 -0
- package/lib/math/index.js +3 -0
- package/lib/position/Position.d.ts +11 -10
- package/lib/position/Position.js +15 -19
- package/lib/position/index.d.ts +1 -1
- package/lib/position/index.js +1 -17
- package/lib/token/ConstantWrappedToken.d.ts +4 -4
- package/lib/token/ConstantWrappedToken.js +5 -9
- package/lib/token/ExchangeRateWrappedToken.d.ts +4 -4
- package/lib/token/ExchangeRateWrappedToken.js +5 -9
- package/lib/token/Token.d.ts +3 -3
- package/lib/token/Token.js +9 -14
- package/lib/token/VaultToken.d.ts +20 -11
- package/lib/token/VaultToken.js +14 -10
- package/lib/token/WrappedToken.d.ts +3 -3
- package/lib/token/WrappedToken.js +7 -11
- package/lib/token/index.d.ts +5 -5
- package/lib/token/index.js +5 -21
- package/lib/types.d.ts +1 -1
- package/lib/types.js +4 -9
- package/lib/user/User.d.ts +1 -1
- package/lib/user/User.js +1 -5
- package/lib/user/index.d.ts +1 -1
- package/lib/user/index.js +1 -17
- package/lib/vault/Vault.d.ts +8 -22
- package/lib/vault/Vault.js +38 -51
- package/lib/vault/VaultConfig.d.ts +2 -2
- package/lib/vault/VaultConfig.js +3 -7
- package/lib/vault/VaultMarketAllocation.d.ts +3 -3
- package/lib/vault/VaultMarketAllocation.js +4 -8
- package/lib/vault/VaultMarketConfig.d.ts +3 -3
- package/lib/vault/VaultMarketConfig.js +1 -5
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -1
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +1 -5
- package/lib/vault/VaultUser.d.ts +1 -1
- package/lib/vault/VaultUser.js +1 -5
- package/lib/vault/VaultUtils.d.ts +4 -6
- package/lib/vault/VaultUtils.js +8 -11
- package/lib/vault/index.d.ts +7 -7
- package/lib/vault/index.js +7 -23
- package/package.json +46 -33
- package/lib/helpers/format/format.d.ts +0 -122
- package/lib/helpers/format/format.js +0 -286
- package/lib/helpers/locale.d.ts +0 -46
- package/lib/helpers/locale.js +0 -96
- package/lib/maths/index.d.ts +0 -3
- package/lib/maths/index.js +0 -19
- package/lib/tests/mocks/markets.d.ts +0 -19
- package/lib/tests/mocks/markets.js +0 -121
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RoundingDirection } from "../
|
|
2
|
-
import { Address } from "../types";
|
|
3
|
-
import { InputToken, Token } from "./Token";
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { Address } from "../types.js";
|
|
3
|
+
import { type InputToken, Token } from "./Token.js";
|
|
4
4
|
export declare abstract class WrappedToken extends Token {
|
|
5
5
|
readonly underlying: Address;
|
|
6
6
|
constructor(token: InputToken, underlying: Address);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const maths_1 = require("../maths");
|
|
5
|
-
const Token_1 = require("./Token");
|
|
6
|
-
class WrappedToken extends Token_1.Token {
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
import { Token } from "./Token.js";
|
|
3
|
+
export class WrappedToken extends Token {
|
|
7
4
|
underlying;
|
|
8
5
|
constructor(token, underlying) {
|
|
9
6
|
super(token);
|
|
@@ -12,22 +9,21 @@ class WrappedToken extends Token_1.Token {
|
|
|
12
9
|
/** The expected amount when wrapping `unwrappedAmount` */
|
|
13
10
|
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
14
11
|
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
15
|
-
return
|
|
12
|
+
return MathLib.wMul(wrappedAmount, MathLib.WAD - slippage, "Down");
|
|
16
13
|
}
|
|
17
14
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
18
15
|
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
19
|
-
const wAmountTarget =
|
|
16
|
+
const wAmountTarget = MathLib.wDiv(wrappedAmount, MathLib.WAD - slippage, rounding);
|
|
20
17
|
return this._unwrap(wAmountTarget, rounding);
|
|
21
18
|
}
|
|
22
19
|
/** The expected amount when unwrapping `wrappedAmount` */
|
|
23
20
|
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
24
21
|
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
25
|
-
return
|
|
22
|
+
return MathLib.wMul(unwrappedAmount, MathLib.WAD - slippage, "Up");
|
|
26
23
|
}
|
|
27
24
|
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
28
25
|
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
29
|
-
const unwrappedAmountToTarget =
|
|
26
|
+
const unwrappedAmountToTarget = MathLib.wDiv(unwrappedAmount, MathLib.WAD - slippage, rounding);
|
|
30
27
|
return this._wrap(unwrappedAmountToTarget, rounding);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.WrappedToken = WrappedToken;
|
package/lib/token/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./Token";
|
|
2
|
-
export * from "./WrappedToken";
|
|
3
|
-
export * from "./ConstantWrappedToken";
|
|
4
|
-
export * from "./ExchangeRateWrappedToken";
|
|
5
|
-
export * from "./VaultToken";
|
|
1
|
+
export * from "./Token.js";
|
|
2
|
+
export * from "./WrappedToken.js";
|
|
3
|
+
export * from "./ConstantWrappedToken.js";
|
|
4
|
+
export * from "./ExchangeRateWrappedToken.js";
|
|
5
|
+
export * from "./VaultToken.js";
|
package/lib/token/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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"), exports);
|
|
18
|
-
__exportStar(require("./WrappedToken"), exports);
|
|
19
|
-
__exportStar(require("./ConstantWrappedToken"), exports);
|
|
20
|
-
__exportStar(require("./ExchangeRateWrappedToken"), exports);
|
|
21
|
-
__exportStar(require("./VaultToken"), exports);
|
|
1
|
+
export * from "./Token.js";
|
|
2
|
+
export * from "./WrappedToken.js";
|
|
3
|
+
export * from "./ConstantWrappedToken.js";
|
|
4
|
+
export * from "./ExchangeRateWrappedToken.js";
|
|
5
|
+
export * from "./VaultToken.js";
|
package/lib/types.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export type Loadable<T> = T | undefined;
|
|
|
24
24
|
export type Failable<T> = T | null;
|
|
25
25
|
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
26
26
|
export declare function isFetched<T>(v: Fetchable<T>): v is T;
|
|
27
|
-
export declare const isMarketId: (value:
|
|
27
|
+
export declare const isMarketId: (value: unknown) => value is MarketId;
|
package/lib/types.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMarketId = exports.TransactionType = void 0;
|
|
4
|
-
exports.isFetched = isFetched;
|
|
5
1
|
/**
|
|
6
2
|
* The possible transaction type on the Blue contract
|
|
7
3
|
*/
|
|
8
|
-
var TransactionType;
|
|
4
|
+
export var TransactionType;
|
|
9
5
|
(function (TransactionType) {
|
|
10
6
|
TransactionType["Supply"] = "Supply";
|
|
11
7
|
TransactionType["SupplyCollateral"] = "Supply Collateral";
|
|
@@ -13,10 +9,9 @@ var TransactionType;
|
|
|
13
9
|
TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
|
|
14
10
|
TransactionType["Borrow"] = "Borrow";
|
|
15
11
|
TransactionType["Repay"] = "Repay";
|
|
16
|
-
})(TransactionType || (
|
|
12
|
+
})(TransactionType || (TransactionType = {}));
|
|
17
13
|
// TODO: replace with isDefined
|
|
18
|
-
function isFetched(v) {
|
|
14
|
+
export function isFetched(v) {
|
|
19
15
|
return v !== undefined && v !== null;
|
|
20
16
|
}
|
|
21
|
-
const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
22
|
-
exports.isMarketId = isMarketId;
|
|
17
|
+
export const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
package/lib/user/User.d.ts
CHANGED
package/lib/user/User.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.User = void 0;
|
|
4
|
-
class User {
|
|
1
|
+
export class User {
|
|
5
2
|
/**
|
|
6
3
|
* The user's address.
|
|
7
4
|
*/
|
|
@@ -20,4 +17,3 @@ class User {
|
|
|
20
17
|
this.morphoNonce = morphoNonce;
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.User = User;
|
package/lib/user/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./User";
|
|
1
|
+
export * from "./User.js";
|
package/lib/user/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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"), exports);
|
|
1
|
+
export * from "./User.js";
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CapacityLimit } from "../market";
|
|
2
|
-
import { RoundingDirection } from "../
|
|
3
|
-
import { VaultToken } from "../token";
|
|
4
|
-
import { Address, BigIntish, MarketId } from "../types";
|
|
5
|
-
import {
|
|
6
|
-
import { InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation";
|
|
1
|
+
import { type CapacityLimit } from "../market/index.js";
|
|
2
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
3
|
+
import { VaultToken } from "../token/index.js";
|
|
4
|
+
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
5
|
+
import type { InputVaultConfig } from "./VaultConfig.js";
|
|
6
|
+
import { type InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
|
|
7
7
|
export interface Pending<T> {
|
|
8
8
|
value: T;
|
|
9
9
|
validAt: bigint;
|
|
@@ -22,8 +22,7 @@ export interface VaultPublicAllocatorConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
accruedFee: bigint;
|
|
24
24
|
}
|
|
25
|
-
export interface InputVault {
|
|
26
|
-
config: VaultConfig;
|
|
25
|
+
export interface InputVault extends InputVaultConfig {
|
|
27
26
|
curator: Address;
|
|
28
27
|
owner: Address;
|
|
29
28
|
guardian: Address;
|
|
@@ -42,10 +41,6 @@ export interface InputVault {
|
|
|
42
41
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
43
42
|
}
|
|
44
43
|
export declare class Vault extends VaultToken implements InputVault {
|
|
45
|
-
/**
|
|
46
|
-
* The MetaMorpho vault's config.
|
|
47
|
-
*/
|
|
48
|
-
readonly config: VaultConfig;
|
|
49
44
|
/**
|
|
50
45
|
* The MetaMorpho vault's owner address.
|
|
51
46
|
*/
|
|
@@ -94,14 +89,6 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
94
89
|
* The MetaMorpho vault's ordered withdraw queue.
|
|
95
90
|
*/
|
|
96
91
|
withdrawQueue: MarketId[];
|
|
97
|
-
/**
|
|
98
|
-
* The ERC4626 vault's total supply of shares.
|
|
99
|
-
*/
|
|
100
|
-
totalSupply: bigint;
|
|
101
|
-
/**
|
|
102
|
-
* The ERC4626 vault's total assets.
|
|
103
|
-
*/
|
|
104
|
-
totalAssets: bigint;
|
|
105
92
|
/**
|
|
106
93
|
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
107
94
|
*/
|
|
@@ -110,8 +97,7 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
110
97
|
* The MetaMorpho vault's public allocator configuration.
|
|
111
98
|
*/
|
|
112
99
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
113
|
-
constructor({
|
|
114
|
-
get asset(): `0x${string}`;
|
|
100
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }: InputVault);
|
|
115
101
|
/**
|
|
116
102
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
103
|
*/
|
package/lib/vault/Vault.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const token_1 = require("../token");
|
|
7
|
-
const VaultMarketAllocation_1 = require("./VaultMarketAllocation");
|
|
8
|
-
const VaultUtils_1 = require("./VaultUtils");
|
|
9
|
-
class Vault extends token_1.VaultToken {
|
|
10
|
-
/**
|
|
11
|
-
* The MetaMorpho vault's config.
|
|
12
|
-
*/
|
|
13
|
-
config;
|
|
1
|
+
import { CapacityLimitReason } from "../market/index.js";
|
|
2
|
+
import { MathLib } from "../math/index.js";
|
|
3
|
+
import { VaultToken } from "../token/index.js";
|
|
4
|
+
import { VaultMarketAllocation, } from "./VaultMarketAllocation.js";
|
|
5
|
+
export class Vault extends VaultToken {
|
|
14
6
|
/**
|
|
15
7
|
* The MetaMorpho vault's owner address.
|
|
16
8
|
*/
|
|
@@ -59,14 +51,6 @@ class Vault extends token_1.VaultToken {
|
|
|
59
51
|
* The MetaMorpho vault's ordered withdraw queue.
|
|
60
52
|
*/
|
|
61
53
|
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
54
|
/**
|
|
71
55
|
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
72
56
|
*/
|
|
@@ -75,9 +59,8 @@ class Vault extends token_1.VaultToken {
|
|
|
75
59
|
* The MetaMorpho vault's public allocator configuration.
|
|
76
60
|
*/
|
|
77
61
|
publicAllocatorConfig;
|
|
78
|
-
constructor({
|
|
62
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }) {
|
|
79
63
|
super(config, { totalAssets, totalSupply });
|
|
80
|
-
this.config = config;
|
|
81
64
|
this.curator = curator;
|
|
82
65
|
this.owner = owner;
|
|
83
66
|
this.guardian = guardian;
|
|
@@ -93,29 +76,23 @@ class Vault extends token_1.VaultToken {
|
|
|
93
76
|
this.timelock = timelock;
|
|
94
77
|
this.supplyQueue = supplyQueue;
|
|
95
78
|
this.withdrawQueue = withdrawQueue;
|
|
96
|
-
this.totalSupply = totalSupply;
|
|
97
|
-
this.totalAssets = totalAssets;
|
|
98
79
|
this.lastTotalAssets = lastTotalAssets;
|
|
99
80
|
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
100
81
|
}
|
|
101
|
-
get asset() {
|
|
102
|
-
return this.config.asset;
|
|
103
|
-
}
|
|
104
82
|
/**
|
|
105
83
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
106
84
|
*/
|
|
107
85
|
get totalInterest() {
|
|
108
|
-
return
|
|
86
|
+
return MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
109
87
|
}
|
|
110
88
|
toAssets(shares, rounding) {
|
|
111
|
-
return
|
|
89
|
+
return this._unwrap(shares, rounding);
|
|
112
90
|
}
|
|
113
91
|
toShares(assets, rounding) {
|
|
114
|
-
return
|
|
92
|
+
return this._wrap(assets, rounding);
|
|
115
93
|
}
|
|
116
94
|
}
|
|
117
|
-
|
|
118
|
-
class AccrualVault extends Vault {
|
|
95
|
+
export class AccrualVault extends Vault {
|
|
119
96
|
/**
|
|
120
97
|
* The allocation of the vault on each market enabled.
|
|
121
98
|
*/
|
|
@@ -137,7 +114,7 @@ class AccrualVault extends Vault {
|
|
|
137
114
|
});
|
|
138
115
|
this.allocations = new Map(allocations.map((allocation) => [
|
|
139
116
|
allocation.position.market.id,
|
|
140
|
-
new
|
|
117
|
+
new VaultMarketAllocation(allocation),
|
|
141
118
|
]));
|
|
142
119
|
this.collateralAllocations = new Map();
|
|
143
120
|
for (const { marketId, position } of this.allocations.values()) {
|
|
@@ -161,7 +138,9 @@ class AccrualVault extends Vault {
|
|
|
161
138
|
* The vault's liquidity directly available from allocated markets.
|
|
162
139
|
*/
|
|
163
140
|
get liquidity() {
|
|
164
|
-
return
|
|
141
|
+
return this.allocations
|
|
142
|
+
.values()
|
|
143
|
+
.reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
165
144
|
}
|
|
166
145
|
/**
|
|
167
146
|
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
@@ -169,13 +148,15 @@ class AccrualVault extends Vault {
|
|
|
169
148
|
get avgApy() {
|
|
170
149
|
if (this.totalAssets === 0n)
|
|
171
150
|
return 0n;
|
|
172
|
-
return (
|
|
151
|
+
return (this.allocations
|
|
152
|
+
.values()
|
|
153
|
+
.reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
173
154
|
}
|
|
174
155
|
/**
|
|
175
156
|
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
176
157
|
*/
|
|
177
158
|
get netApy() {
|
|
178
|
-
return
|
|
159
|
+
return MathLib.wMulDown(this.avgApy, MathLib.WAD - this.fee);
|
|
179
160
|
}
|
|
180
161
|
getAllocationProportion(marketId) {
|
|
181
162
|
if (this.totalAssets === 0n)
|
|
@@ -183,21 +164,23 @@ class AccrualVault extends Vault {
|
|
|
183
164
|
const allocation = this.allocations.get(marketId);
|
|
184
165
|
if (!allocation)
|
|
185
166
|
return 0n;
|
|
186
|
-
return
|
|
167
|
+
return MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
187
168
|
}
|
|
188
169
|
getDepositCapacityLimit(assets) {
|
|
189
|
-
const suppliable =
|
|
170
|
+
const suppliable = this.allocations
|
|
171
|
+
.values()
|
|
172
|
+
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => MathLib.min(total +
|
|
190
173
|
(this.supplyQueue.includes(marketId)
|
|
191
|
-
?
|
|
192
|
-
: 0n),
|
|
174
|
+
? MathLib.zeroFloorSub(cap, supplyAssets)
|
|
175
|
+
: 0n), MathLib.MAX_UINT_256), 0n);
|
|
193
176
|
if (assets > suppliable)
|
|
194
177
|
return {
|
|
195
178
|
value: suppliable,
|
|
196
|
-
limiter:
|
|
179
|
+
limiter: CapacityLimitReason.cap,
|
|
197
180
|
};
|
|
198
181
|
return {
|
|
199
182
|
value: assets,
|
|
200
|
-
limiter:
|
|
183
|
+
limiter: CapacityLimitReason.balance,
|
|
201
184
|
};
|
|
202
185
|
}
|
|
203
186
|
getWithdrawCapacityLimit(shares) {
|
|
@@ -206,11 +189,11 @@ class AccrualVault extends Vault {
|
|
|
206
189
|
if (assets > liquidity)
|
|
207
190
|
return {
|
|
208
191
|
value: liquidity,
|
|
209
|
-
limiter:
|
|
192
|
+
limiter: CapacityLimitReason.liquidity,
|
|
210
193
|
};
|
|
211
194
|
return {
|
|
212
195
|
value: assets,
|
|
213
|
-
limiter:
|
|
196
|
+
limiter: CapacityLimitReason.balance,
|
|
214
197
|
};
|
|
215
198
|
}
|
|
216
199
|
/**
|
|
@@ -218,11 +201,16 @@ class AccrualVault extends Vault {
|
|
|
218
201
|
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
219
202
|
*/
|
|
220
203
|
accrueInterest(timestamp) {
|
|
221
|
-
const vault = new AccrualVault(this,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
204
|
+
const vault = new AccrualVault(this,
|
|
205
|
+
// Keep withdraw queue order.
|
|
206
|
+
this.withdrawQueue.map((marketId) => {
|
|
207
|
+
const { config, position } = this.allocations.get(marketId);
|
|
208
|
+
return {
|
|
209
|
+
config,
|
|
210
|
+
position: position.accrueInterest(timestamp),
|
|
211
|
+
};
|
|
212
|
+
}));
|
|
213
|
+
const feeAssets = MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
226
214
|
vault.totalAssets -= feeAssets;
|
|
227
215
|
const feeShares = vault.toShares(feeAssets, "Down");
|
|
228
216
|
vault.totalAssets += feeAssets;
|
|
@@ -231,4 +219,3 @@ class AccrualVault extends Vault {
|
|
|
231
219
|
return vault;
|
|
232
220
|
}
|
|
233
221
|
}
|
|
234
|
-
exports.AccrualVault = AccrualVault;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChainId } from "../chain";
|
|
2
|
-
import { Address, BigIntish } from "../types";
|
|
1
|
+
import type { ChainId } from "../chain.js";
|
|
2
|
+
import type { Address, BigIntish } from "../types.js";
|
|
3
3
|
export interface InputVaultConfig {
|
|
4
4
|
address: Address;
|
|
5
5
|
decimals: BigIntish;
|
package/lib/vault/VaultConfig.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.VaultConfig = void 0;
|
|
4
|
-
const errors_1 = require("../errors");
|
|
5
|
-
class VaultConfig {
|
|
1
|
+
import { UnknownVaultConfigError } from "../errors.js";
|
|
2
|
+
export class VaultConfig {
|
|
6
3
|
chainId;
|
|
7
4
|
static _CACHE = {};
|
|
8
5
|
static get(address, chainId) {
|
|
9
6
|
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
10
7
|
if (!config)
|
|
11
|
-
throw new
|
|
8
|
+
throw new UnknownVaultConfigError(address);
|
|
12
9
|
return config;
|
|
13
10
|
}
|
|
14
11
|
address;
|
|
@@ -29,4 +26,3 @@ class VaultConfig {
|
|
|
29
26
|
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
exports.VaultConfig = VaultConfig;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AccrualPosition } from "../position";
|
|
2
|
-
import { VaultMarketConfig } from "./VaultMarketConfig";
|
|
1
|
+
import type { AccrualPosition } from "../position/index.js";
|
|
2
|
+
import type { VaultMarketConfig } from "./VaultMarketConfig.js";
|
|
3
3
|
export interface InputVaultMarketAllocation {
|
|
4
4
|
config: VaultMarketConfig;
|
|
5
5
|
position: AccrualPosition;
|
|
@@ -15,6 +15,6 @@ export declare class VaultMarketAllocation implements InputVaultMarketAllocation
|
|
|
15
15
|
readonly position: AccrualPosition;
|
|
16
16
|
constructor({ config, position }: InputVaultMarketAllocation);
|
|
17
17
|
get vault(): `0x${string}`;
|
|
18
|
-
get marketId(): import("
|
|
18
|
+
get marketId(): import("../types.js").MarketId;
|
|
19
19
|
get utilization(): bigint;
|
|
20
20
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.VaultMarketAllocation = void 0;
|
|
4
|
-
const maths_1 = require("../maths");
|
|
5
|
-
class VaultMarketAllocation {
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
export class VaultMarketAllocation {
|
|
6
3
|
/**
|
|
7
4
|
* The vault's configuration on the corresponding market.
|
|
8
5
|
*/
|
|
@@ -23,8 +20,7 @@ class VaultMarketAllocation {
|
|
|
23
20
|
}
|
|
24
21
|
get utilization() {
|
|
25
22
|
if (this.config.cap === 0n)
|
|
26
|
-
return
|
|
27
|
-
return
|
|
23
|
+
return MathLib.MAX_UINT_256;
|
|
24
|
+
return MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.VaultMarketAllocation = VaultMarketAllocation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Address, MarketId } from "../types";
|
|
2
|
-
import { Pending } from "./Vault";
|
|
3
|
-
import { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig";
|
|
1
|
+
import type { Address, MarketId } from "../types.js";
|
|
2
|
+
import type { Pending } from "./Vault.js";
|
|
3
|
+
import type { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig.js";
|
|
4
4
|
export interface InputVaultMarketConfig {
|
|
5
5
|
vault: Address;
|
|
6
6
|
marketId: MarketId;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultMarketConfig = void 0;
|
|
4
|
-
class VaultMarketConfig {
|
|
1
|
+
export class VaultMarketConfig {
|
|
5
2
|
/**
|
|
6
3
|
* The vault's address.
|
|
7
4
|
*/
|
|
@@ -40,4 +37,3 @@ class VaultMarketConfig {
|
|
|
40
37
|
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
exports.VaultMarketConfig = VaultMarketConfig;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultMarketPublicAllocatorConfig = void 0;
|
|
4
|
-
class VaultMarketPublicAllocatorConfig {
|
|
1
|
+
export class VaultMarketPublicAllocatorConfig {
|
|
5
2
|
/**
|
|
6
3
|
* The vault's address.
|
|
7
4
|
*/
|
|
@@ -25,4 +22,3 @@ class VaultMarketPublicAllocatorConfig {
|
|
|
25
22
|
this.maxOut = maxOut;
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.VaultMarketPublicAllocatorConfig = VaultMarketPublicAllocatorConfig;
|
package/lib/vault/VaultUser.d.ts
CHANGED
package/lib/vault/VaultUser.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultUser = void 0;
|
|
4
|
-
class VaultUser {
|
|
1
|
+
export class VaultUser {
|
|
5
2
|
/**
|
|
6
3
|
* The vault's address.
|
|
7
4
|
*/
|
|
@@ -25,4 +22,3 @@ class VaultUser {
|
|
|
25
22
|
this.allowance = allowance;
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.VaultUser = VaultUser;
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { RoundingDirection } from "../
|
|
2
|
-
import { BigIntish } from "../types";
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { BigIntish } from "../types.js";
|
|
3
3
|
export declare namespace VaultUtils {
|
|
4
4
|
const VIRTUAL_ASSETS = 1n;
|
|
5
5
|
function decimalsOffset(decimals: BigIntish): bigint;
|
|
6
|
-
function toAssets(shares: BigIntish, { totalAssets, totalSupply, }: {
|
|
6
|
+
function toAssets(shares: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
|
|
7
7
|
totalAssets: BigIntish;
|
|
8
8
|
totalSupply: BigIntish;
|
|
9
|
-
}, { decimalsOffset }: {
|
|
10
9
|
decimalsOffset: BigIntish;
|
|
11
10
|
}, rounding?: RoundingDirection): bigint;
|
|
12
|
-
function toShares(assets: BigIntish, { totalAssets, totalSupply, }: {
|
|
11
|
+
function toShares(assets: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
|
|
13
12
|
totalAssets: BigIntish;
|
|
14
13
|
totalSupply: BigIntish;
|
|
15
|
-
}, { decimalsOffset }: {
|
|
16
14
|
decimalsOffset: BigIntish;
|
|
17
15
|
}, rounding?: RoundingDirection): bigint;
|
|
18
16
|
}
|
package/lib/vault/VaultUtils.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.VaultUtils = void 0;
|
|
4
|
-
const maths_1 = require("../maths");
|
|
5
|
-
var VaultUtils;
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
export var VaultUtils;
|
|
6
3
|
(function (VaultUtils) {
|
|
7
4
|
VaultUtils.VIRTUAL_ASSETS = 1n;
|
|
8
5
|
function decimalsOffset(decimals) {
|
|
9
|
-
return
|
|
6
|
+
return MathLib.zeroFloorSub(18n, decimals);
|
|
10
7
|
}
|
|
11
8
|
VaultUtils.decimalsOffset = decimalsOffset;
|
|
12
|
-
function toAssets(shares, { totalAssets, totalSupply,
|
|
13
|
-
return
|
|
9
|
+
function toAssets(shares, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Down") {
|
|
10
|
+
return MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
|
|
14
11
|
}
|
|
15
12
|
VaultUtils.toAssets = toAssets;
|
|
16
|
-
function toShares(assets, { totalAssets, totalSupply,
|
|
17
|
-
return
|
|
13
|
+
function toShares(assets, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Up") {
|
|
14
|
+
return MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
|
|
18
15
|
}
|
|
19
16
|
VaultUtils.toShares = toShares;
|
|
20
|
-
})(VaultUtils || (
|
|
17
|
+
})(VaultUtils || (VaultUtils = {}));
|
package/lib/vault/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./VaultUtils";
|
|
2
|
-
export * from "./VaultConfig";
|
|
3
|
-
export * from "./VaultMarketAllocation";
|
|
4
|
-
export * from "./VaultMarketConfig";
|
|
5
|
-
export * from "./VaultMarketPublicAllocatorConfig";
|
|
6
|
-
export * from "./VaultUser";
|
|
7
|
-
export * from "./Vault";
|
|
1
|
+
export * from "./VaultUtils.js";
|
|
2
|
+
export * from "./VaultConfig.js";
|
|
3
|
+
export * from "./VaultMarketAllocation.js";
|
|
4
|
+
export * from "./VaultMarketConfig.js";
|
|
5
|
+
export * from "./VaultMarketPublicAllocatorConfig.js";
|
|
6
|
+
export * from "./VaultUser.js";
|
|
7
|
+
export * from "./Vault.js";
|