@morpho-org/blue-sdk 1.0.0-integ-650.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 +106 -0
- package/lib/addresses.d.ts +113 -0
- package/lib/addresses.js +162 -0
- package/lib/chain.d.ts +29 -0
- package/lib/chain.js +289 -0
- package/lib/chain.test.d.ts +1 -0
- package/lib/chain.test.js +21 -0
- package/lib/constants.d.ts +29 -0
- package/lib/constants.js +33 -0
- package/lib/errors.d.ts +58 -0
- package/lib/errors.js +119 -0
- package/lib/helpers/format/format.d.ts +122 -0
- package/lib/helpers/format/format.js +286 -0
- package/lib/helpers/format/format.test.d.ts +1 -0
- package/lib/helpers/format/format.test.js +255 -0
- package/lib/helpers/format/index.d.ts +1 -0
- package/lib/helpers/format/index.js +17 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +18 -0
- package/lib/helpers/locale.d.ts +46 -0
- package/lib/helpers/locale.js +96 -0
- package/lib/holding/AssetBalances.d.ts +48 -0
- package/lib/holding/AssetBalances.js +42 -0
- package/lib/holding/Holding.d.ts +59 -0
- package/lib/holding/Holding.js +59 -0
- package/lib/holding/index.d.ts +2 -0
- package/lib/holding/index.js +18 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +54 -0
- package/lib/market/Market.d.ts +329 -0
- package/lib/market/Market.js +460 -0
- package/lib/market/MarketConfig.d.ts +52 -0
- package/lib/market/MarketConfig.js +76 -0
- package/lib/market/MarketUtils.d.ts +232 -0
- package/lib/market/MarketUtils.js +263 -0
- package/lib/market/MarketUtils.test.d.ts +1 -0
- package/lib/market/MarketUtils.test.js +38 -0
- package/lib/market/index.d.ts +3 -0
- package/lib/market/index.js +19 -0
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +39 -0
- package/lib/maths/AdaptiveCurveIrmLib.js +134 -0
- package/lib/maths/MathLib.d.ts +114 -0
- package/lib/maths/MathLib.js +175 -0
- package/lib/maths/SharesMath.d.ts +12 -0
- package/lib/maths/SharesMath.js +21 -0
- package/lib/maths/index.d.ts +3 -0
- package/lib/maths/index.js +19 -0
- package/lib/position/Position.d.ts +126 -0
- package/lib/position/Position.js +203 -0
- package/lib/position/index.d.ts +1 -0
- package/lib/position/index.js +17 -0
- package/lib/tests/mocks/markets.d.ts +19 -0
- package/lib/tests/mocks/markets.js +121 -0
- package/lib/token/ConstantWrappedToken.d.ts +18 -0
- package/lib/token/ConstantWrappedToken.js +36 -0
- package/lib/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/token/ExchangeRateWrappedToken.js +21 -0
- package/lib/token/Token.d.ts +46 -0
- package/lib/token/Token.js +64 -0
- package/lib/token/VaultToken.d.ts +14 -0
- package/lib/token/VaultToken.js +23 -0
- package/lib/token/WrappedToken.d.ts +17 -0
- package/lib/token/WrappedToken.js +33 -0
- package/lib/token/index.d.ts +5 -0
- package/lib/token/index.js +21 -0
- package/lib/types.d.ts +30 -0
- package/lib/types.js +22 -0
- package/lib/user/User.d.ts +20 -0
- package/lib/user/User.js +23 -0
- package/lib/user/index.d.ts +1 -0
- package/lib/user/index.js +17 -0
- package/lib/vault/Vault.d.ts +166 -0
- package/lib/vault/Vault.js +234 -0
- package/lib/vault/VaultConfig.d.ts +22 -0
- package/lib/vault/VaultConfig.js +32 -0
- 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 +18 -0
- package/lib/vault/VaultUtils.js +20 -0
- package/lib/vault/index.d.ts +6 -0
- package/lib/vault/index.js +22 -0
- package/package.json +53 -0
|
@@ -0,0 +1,21 @@
|
|
|
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"), exports);
|
|
18
|
+
__exportStar(require("./WrappedToken"), exports);
|
|
19
|
+
__exportStar(require("./ConstantWrappedToken"), exports);
|
|
20
|
+
__exportStar(require("./ExchangeRateWrappedToken"), exports);
|
|
21
|
+
__exportStar(require("./VaultToken"), exports);
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type Hex64 = string & {
|
|
2
|
+
__LENGTH__: 64;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* The address of a Contract, or an EOA
|
|
6
|
+
*/
|
|
7
|
+
export type Address = string;
|
|
8
|
+
/**
|
|
9
|
+
* The id of a market used on the Blue contract
|
|
10
|
+
*/
|
|
11
|
+
export type MarketId = `0x${Hex64}` & {
|
|
12
|
+
__TYPE__: "marketId";
|
|
13
|
+
};
|
|
14
|
+
export type BigIntish = bigint | string | number | boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The possible transaction type on the Blue contract
|
|
17
|
+
*/
|
|
18
|
+
export declare enum TransactionType {
|
|
19
|
+
Supply = "Supply",
|
|
20
|
+
SupplyCollateral = "Supply Collateral",
|
|
21
|
+
Withdraw = "Withdraw",
|
|
22
|
+
WithdrawCollateral = "Withdraw Collateral",
|
|
23
|
+
Borrow = "Borrow",
|
|
24
|
+
Repay = "Repay"
|
|
25
|
+
}
|
|
26
|
+
export type Loadable<T> = T | undefined;
|
|
27
|
+
export type Failable<T> = T | null;
|
|
28
|
+
export type Fetchable<T> = Failable<Loadable<T>>;
|
|
29
|
+
export declare function isFetched<T>(v: Fetchable<T>): v is T;
|
|
30
|
+
export declare const isMarketId: (value: any) => value is MarketId;
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMarketId = exports.TransactionType = void 0;
|
|
4
|
+
exports.isFetched = isFetched;
|
|
5
|
+
/**
|
|
6
|
+
* The possible transaction type on the Blue contract
|
|
7
|
+
*/
|
|
8
|
+
var TransactionType;
|
|
9
|
+
(function (TransactionType) {
|
|
10
|
+
TransactionType["Supply"] = "Supply";
|
|
11
|
+
TransactionType["SupplyCollateral"] = "Supply Collateral";
|
|
12
|
+
TransactionType["Withdraw"] = "Withdraw";
|
|
13
|
+
TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
|
|
14
|
+
TransactionType["Borrow"] = "Borrow";
|
|
15
|
+
TransactionType["Repay"] = "Repay";
|
|
16
|
+
})(TransactionType || (exports.TransactionType = TransactionType = {}));
|
|
17
|
+
// TODO: replace with isDefined
|
|
18
|
+
function isFetched(v) {
|
|
19
|
+
return v !== undefined && v !== null;
|
|
20
|
+
}
|
|
21
|
+
const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
|
|
22
|
+
exports.isMarketId = isMarketId;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Address } from "../types";
|
|
2
|
+
export declare class User {
|
|
3
|
+
/**
|
|
4
|
+
* The user's address.
|
|
5
|
+
*/
|
|
6
|
+
readonly address: Address;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the bundler is authorized to manage the user's position on Morpho Blue.
|
|
9
|
+
*/
|
|
10
|
+
isBundlerAuthorized: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The user's nonce on Morpho Blue.
|
|
13
|
+
*/
|
|
14
|
+
morphoNonce: bigint;
|
|
15
|
+
constructor({ address, isBundlerAuthorized, morphoNonce, }: {
|
|
16
|
+
address: Address;
|
|
17
|
+
isBundlerAuthorized: boolean;
|
|
18
|
+
morphoNonce: bigint;
|
|
19
|
+
});
|
|
20
|
+
}
|
package/lib/user/User.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
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;
|
|
17
|
+
constructor({ address, isBundlerAuthorized, morphoNonce, }) {
|
|
18
|
+
this.address = address;
|
|
19
|
+
this.isBundlerAuthorized = isBundlerAuthorized;
|
|
20
|
+
this.morphoNonce = morphoNonce;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.User = User;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./User";
|
|
@@ -0,0 +1,17 @@
|
|
|
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"), exports);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { CapacityLimit } from "../market";
|
|
2
|
+
import { RoundingDirection } from "../maths";
|
|
3
|
+
import { VaultToken } from "../token";
|
|
4
|
+
import { Address, BigIntish, MarketId } from "../types";
|
|
5
|
+
import { VaultConfig } from "./VaultConfig";
|
|
6
|
+
import { InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation";
|
|
7
|
+
export interface Pending<T> {
|
|
8
|
+
value: T;
|
|
9
|
+
validAt: bigint;
|
|
10
|
+
}
|
|
11
|
+
export interface VaultPublicAllocatorConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The PublicAllocator's admin address.
|
|
14
|
+
*/
|
|
15
|
+
admin: Address;
|
|
16
|
+
/**
|
|
17
|
+
* The PublicAllocator's reallocation fee (in native token).
|
|
18
|
+
*/
|
|
19
|
+
fee: bigint;
|
|
20
|
+
/**
|
|
21
|
+
* The PublicAllocator's reallocation fee accrued so far (in native token).
|
|
22
|
+
*/
|
|
23
|
+
accruedFee: bigint;
|
|
24
|
+
}
|
|
25
|
+
export interface InputVault {
|
|
26
|
+
config: VaultConfig;
|
|
27
|
+
curator: Address;
|
|
28
|
+
owner: Address;
|
|
29
|
+
guardian: Address;
|
|
30
|
+
fee: bigint;
|
|
31
|
+
feeRecipient: Address;
|
|
32
|
+
skimRecipient: Address;
|
|
33
|
+
pendingTimelock: Pending<bigint>;
|
|
34
|
+
pendingGuardian: Pending<Address>;
|
|
35
|
+
pendingOwner: Address;
|
|
36
|
+
timelock: bigint;
|
|
37
|
+
supplyQueue: MarketId[];
|
|
38
|
+
withdrawQueue: MarketId[];
|
|
39
|
+
totalSupply: bigint;
|
|
40
|
+
totalAssets: bigint;
|
|
41
|
+
lastTotalAssets: bigint;
|
|
42
|
+
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
43
|
+
}
|
|
44
|
+
export declare class Vault extends VaultToken implements InputVault {
|
|
45
|
+
/**
|
|
46
|
+
* The MetaMorpho vault's config.
|
|
47
|
+
*/
|
|
48
|
+
readonly config: VaultConfig;
|
|
49
|
+
/**
|
|
50
|
+
* The MetaMorpho vault's owner address.
|
|
51
|
+
*/
|
|
52
|
+
owner: Address;
|
|
53
|
+
/**
|
|
54
|
+
* The MetaMorpho vault's curator address.
|
|
55
|
+
*/
|
|
56
|
+
curator: Address;
|
|
57
|
+
/**
|
|
58
|
+
* The MetaMorpho vault's guardian address.
|
|
59
|
+
*/
|
|
60
|
+
guardian: Address;
|
|
61
|
+
/**
|
|
62
|
+
* The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
|
|
63
|
+
*/
|
|
64
|
+
skimRecipient: Address;
|
|
65
|
+
/**
|
|
66
|
+
* The MetaMorpho vault's fee recipient address.
|
|
67
|
+
*/
|
|
68
|
+
feeRecipient: Address;
|
|
69
|
+
/**
|
|
70
|
+
* The MetaMorpho vault's timelock (in seconds).
|
|
71
|
+
*/
|
|
72
|
+
timelock: bigint;
|
|
73
|
+
/**
|
|
74
|
+
* The MetaMorpho vault's fee.
|
|
75
|
+
*/
|
|
76
|
+
fee: bigint;
|
|
77
|
+
/**
|
|
78
|
+
* The MetaMorpho vault's pending owner address and activation timestamp.
|
|
79
|
+
*/
|
|
80
|
+
pendingOwner: Address;
|
|
81
|
+
/**
|
|
82
|
+
* The MetaMorpho vault's pending guardian address and activation timestamp.
|
|
83
|
+
*/
|
|
84
|
+
pendingGuardian: Pending<Address>;
|
|
85
|
+
/**
|
|
86
|
+
* The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
|
|
87
|
+
*/
|
|
88
|
+
pendingTimelock: Pending<bigint>;
|
|
89
|
+
/**
|
|
90
|
+
* The MetaMorpho vault's ordered supply queue.
|
|
91
|
+
*/
|
|
92
|
+
supplyQueue: MarketId[];
|
|
93
|
+
/**
|
|
94
|
+
* The MetaMorpho vault's ordered withdraw queue.
|
|
95
|
+
*/
|
|
96
|
+
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
|
+
/**
|
|
106
|
+
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
107
|
+
*/
|
|
108
|
+
lastTotalAssets: bigint;
|
|
109
|
+
/**
|
|
110
|
+
* The MetaMorpho vault's public allocator configuration.
|
|
111
|
+
*/
|
|
112
|
+
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
113
|
+
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }: InputVault);
|
|
114
|
+
get asset(): string;
|
|
115
|
+
/**
|
|
116
|
+
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
|
+
*/
|
|
118
|
+
get totalInterest(): bigint;
|
|
119
|
+
toAssets(shares: bigint, rounding?: RoundingDirection): bigint;
|
|
120
|
+
toShares(assets: bigint, rounding?: RoundingDirection): bigint;
|
|
121
|
+
}
|
|
122
|
+
export interface CollateralAllocation {
|
|
123
|
+
address: Address;
|
|
124
|
+
lltvs: Set<bigint>;
|
|
125
|
+
oracles: Set<Address>;
|
|
126
|
+
markets: Set<MarketId>;
|
|
127
|
+
proportion: bigint;
|
|
128
|
+
}
|
|
129
|
+
export interface InputAccrualVault extends Omit<InputVault, "withdrawQueue" | "totalAssets"> {
|
|
130
|
+
}
|
|
131
|
+
export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
132
|
+
/**
|
|
133
|
+
* The allocation of the vault on each market enabled.
|
|
134
|
+
*/
|
|
135
|
+
readonly allocations: Map<MarketId, VaultMarketAllocation>;
|
|
136
|
+
/**
|
|
137
|
+
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
138
|
+
*/
|
|
139
|
+
readonly collateralAllocations: Map<Address, CollateralAllocation>;
|
|
140
|
+
constructor(vault: InputAccrualVault,
|
|
141
|
+
/**
|
|
142
|
+
* The allocation of the vault on each market of the withdraw queue,
|
|
143
|
+
* in the same order as the withdraw queue.
|
|
144
|
+
*/
|
|
145
|
+
allocations: Omit<InputVaultMarketAllocation, "proportion">[]);
|
|
146
|
+
/**
|
|
147
|
+
* The vault's liquidity directly available from allocated markets.
|
|
148
|
+
*/
|
|
149
|
+
get liquidity(): bigint;
|
|
150
|
+
/**
|
|
151
|
+
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
152
|
+
*/
|
|
153
|
+
get avgApy(): bigint;
|
|
154
|
+
/**
|
|
155
|
+
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
156
|
+
*/
|
|
157
|
+
get netApy(): bigint;
|
|
158
|
+
getAllocationProportion(marketId: MarketId): bigint;
|
|
159
|
+
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
160
|
+
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
161
|
+
/**
|
|
162
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
163
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
164
|
+
*/
|
|
165
|
+
accrueInterest(timestamp: BigIntish): AccrualVault;
|
|
166
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
+
const market_1 = require("../market");
|
|
5
|
+
const maths_1 = require("../maths");
|
|
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;
|
|
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;
|
|
78
|
+
constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }) {
|
|
79
|
+
super(config, { totalAssets, totalSupply });
|
|
80
|
+
this.config = config;
|
|
81
|
+
this.curator = curator;
|
|
82
|
+
this.owner = owner;
|
|
83
|
+
this.guardian = guardian;
|
|
84
|
+
this.fee = fee;
|
|
85
|
+
this.feeRecipient = feeRecipient;
|
|
86
|
+
this.skimRecipient = skimRecipient;
|
|
87
|
+
this.pendingTimelock = {
|
|
88
|
+
value: pendingTimelock.value,
|
|
89
|
+
validAt: pendingTimelock.validAt,
|
|
90
|
+
};
|
|
91
|
+
this.pendingGuardian = pendingGuardian;
|
|
92
|
+
this.pendingOwner = pendingOwner;
|
|
93
|
+
this.timelock = timelock;
|
|
94
|
+
this.supplyQueue = supplyQueue;
|
|
95
|
+
this.withdrawQueue = withdrawQueue;
|
|
96
|
+
this.totalSupply = totalSupply;
|
|
97
|
+
this.totalAssets = totalAssets;
|
|
98
|
+
this.lastTotalAssets = lastTotalAssets;
|
|
99
|
+
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
100
|
+
}
|
|
101
|
+
get asset() {
|
|
102
|
+
return this.config.asset;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
106
|
+
*/
|
|
107
|
+
get totalInterest() {
|
|
108
|
+
return maths_1.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
109
|
+
}
|
|
110
|
+
toAssets(shares, rounding) {
|
|
111
|
+
return VaultUtils_1.VaultUtils.toAssets(shares, this, this.config, rounding);
|
|
112
|
+
}
|
|
113
|
+
toShares(assets, rounding) {
|
|
114
|
+
return VaultUtils_1.VaultUtils.toShares(assets, this, this.config, rounding);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.Vault = Vault;
|
|
118
|
+
class AccrualVault extends Vault {
|
|
119
|
+
/**
|
|
120
|
+
* The allocation of the vault on each market enabled.
|
|
121
|
+
*/
|
|
122
|
+
allocations;
|
|
123
|
+
/**
|
|
124
|
+
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
125
|
+
*/
|
|
126
|
+
collateralAllocations;
|
|
127
|
+
constructor(vault,
|
|
128
|
+
/**
|
|
129
|
+
* The allocation of the vault on each market of the withdraw queue,
|
|
130
|
+
* in the same order as the withdraw queue.
|
|
131
|
+
*/
|
|
132
|
+
allocations) {
|
|
133
|
+
super({
|
|
134
|
+
...vault,
|
|
135
|
+
withdrawQueue: allocations.map(({ position }) => position.market.id),
|
|
136
|
+
totalAssets: allocations.reduce((total, { position }) => total + position.supplyAssets, 0n),
|
|
137
|
+
});
|
|
138
|
+
this.allocations = new Map(allocations.map((allocation) => [
|
|
139
|
+
allocation.position.market.id,
|
|
140
|
+
new VaultMarketAllocation_1.VaultMarketAllocation(allocation),
|
|
141
|
+
]));
|
|
142
|
+
this.collateralAllocations = new Map();
|
|
143
|
+
for (const { marketId, position } of this.allocations.values()) {
|
|
144
|
+
const address = position.market.config.collateralToken;
|
|
145
|
+
let exposure = this.collateralAllocations.get(address);
|
|
146
|
+
if (!exposure)
|
|
147
|
+
this.collateralAllocations.set(address, (exposure = {
|
|
148
|
+
address,
|
|
149
|
+
lltvs: new Set(),
|
|
150
|
+
oracles: new Set(),
|
|
151
|
+
markets: new Set(),
|
|
152
|
+
proportion: 0n,
|
|
153
|
+
}));
|
|
154
|
+
exposure.lltvs.add(position.market.config.lltv);
|
|
155
|
+
exposure.oracles.add(position.market.config.oracle);
|
|
156
|
+
exposure.markets.add(marketId);
|
|
157
|
+
exposure.proportion += this.getAllocationProportion(marketId);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The vault's liquidity directly available from allocated markets.
|
|
162
|
+
*/
|
|
163
|
+
get liquidity() {
|
|
164
|
+
return Array.from(this.allocations.values()).reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
168
|
+
*/
|
|
169
|
+
get avgApy() {
|
|
170
|
+
if (this.totalAssets === 0n)
|
|
171
|
+
return 0n;
|
|
172
|
+
return (Array.from(this.allocations.values()).reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
176
|
+
*/
|
|
177
|
+
get netApy() {
|
|
178
|
+
return maths_1.MathLib.wMulDown(this.avgApy, maths_1.MathLib.WAD - this.fee);
|
|
179
|
+
}
|
|
180
|
+
getAllocationProportion(marketId) {
|
|
181
|
+
if (this.totalAssets === 0n)
|
|
182
|
+
return 0n;
|
|
183
|
+
const allocation = this.allocations.get(marketId);
|
|
184
|
+
if (!allocation)
|
|
185
|
+
return 0n;
|
|
186
|
+
return maths_1.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
187
|
+
}
|
|
188
|
+
getDepositCapacityLimit(assets) {
|
|
189
|
+
const suppliable = Array.from(this.allocations.values()).reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => maths_1.MathLib.min(total +
|
|
190
|
+
(this.supplyQueue.includes(marketId)
|
|
191
|
+
? maths_1.MathLib.zeroFloorSub(cap, supplyAssets)
|
|
192
|
+
: 0n), maths_1.MathLib.MAX_UINT_256), 0n);
|
|
193
|
+
if (assets > suppliable)
|
|
194
|
+
return {
|
|
195
|
+
value: suppliable,
|
|
196
|
+
limiter: market_1.CapacityLimitReason.cap,
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
value: assets,
|
|
200
|
+
limiter: market_1.CapacityLimitReason.balance,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
getWithdrawCapacityLimit(shares) {
|
|
204
|
+
const assets = this.toAssets(shares);
|
|
205
|
+
const { liquidity } = this;
|
|
206
|
+
if (assets > liquidity)
|
|
207
|
+
return {
|
|
208
|
+
value: liquidity,
|
|
209
|
+
limiter: market_1.CapacityLimitReason.liquidity,
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
value: assets,
|
|
213
|
+
limiter: market_1.CapacityLimitReason.balance,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
218
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
219
|
+
*/
|
|
220
|
+
accrueInterest(timestamp) {
|
|
221
|
+
const vault = new AccrualVault(this, Array.from(this.allocations.values(), ({ config, position }) => ({
|
|
222
|
+
config,
|
|
223
|
+
position: position.accrueInterest(timestamp),
|
|
224
|
+
})));
|
|
225
|
+
const feeAssets = maths_1.MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
226
|
+
vault.totalAssets -= feeAssets;
|
|
227
|
+
const feeShares = vault.toShares(feeAssets, "Down");
|
|
228
|
+
vault.totalAssets += feeAssets;
|
|
229
|
+
vault.totalSupply += feeShares;
|
|
230
|
+
vault.lastTotalAssets = vault.totalAssets;
|
|
231
|
+
return vault;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.AccrualVault = AccrualVault;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ChainId } from "../chain";
|
|
2
|
+
import { Address } from "../types";
|
|
3
|
+
export interface InputVaultConfig {
|
|
4
|
+
address: Address;
|
|
5
|
+
decimals: number;
|
|
6
|
+
decimalsOffset: bigint;
|
|
7
|
+
symbol: string;
|
|
8
|
+
name: string;
|
|
9
|
+
asset: Address;
|
|
10
|
+
}
|
|
11
|
+
export declare class VaultConfig implements InputVaultConfig {
|
|
12
|
+
readonly chainId?: number | undefined;
|
|
13
|
+
protected static readonly _CACHE: Record<number, Record<Address, VaultConfig>>;
|
|
14
|
+
static get(address: Address, chainId: ChainId): VaultConfig;
|
|
15
|
+
readonly address: Address;
|
|
16
|
+
readonly decimals: number;
|
|
17
|
+
readonly decimalsOffset: bigint;
|
|
18
|
+
readonly symbol: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly asset: Address;
|
|
21
|
+
constructor({ address, decimals, decimalsOffset, symbol, name, asset, }: InputVaultConfig, chainId?: number | undefined);
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultConfig = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
class VaultConfig {
|
|
6
|
+
chainId;
|
|
7
|
+
static _CACHE = {};
|
|
8
|
+
static get(address, chainId) {
|
|
9
|
+
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
10
|
+
if (!config)
|
|
11
|
+
throw new errors_1.UnknownVaultConfigError(address);
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
address;
|
|
15
|
+
decimals;
|
|
16
|
+
decimalsOffset;
|
|
17
|
+
symbol;
|
|
18
|
+
name;
|
|
19
|
+
asset;
|
|
20
|
+
constructor({ address, decimals, decimalsOffset, symbol, name, asset, }, chainId) {
|
|
21
|
+
this.chainId = chainId;
|
|
22
|
+
this.address = address;
|
|
23
|
+
this.decimals = decimals;
|
|
24
|
+
this.decimalsOffset = decimalsOffset;
|
|
25
|
+
this.symbol = symbol;
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.asset = asset;
|
|
28
|
+
if (chainId != null)
|
|
29
|
+
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.VaultConfig = VaultConfig;
|
|
@@ -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;
|