@morpho-org/blue-sdk 2.0.0-next.1 → 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 +10 -9
- package/lib/addresses.d.ts +117 -0
- package/lib/addresses.js +156 -0
- package/lib/chain.d.ts +29 -0
- package/lib/chain.js +286 -0
- package/lib/constants.d.ts +29 -0
- package/lib/constants.js +30 -0
- package/lib/errors.d.ts +52 -0
- package/lib/errors.js +97 -0
- package/lib/holding/AssetBalances.d.ts +48 -0
- package/lib/holding/AssetBalances.js +38 -0
- package/lib/holding/Holding.d.ts +64 -0
- package/lib/holding/Holding.js +65 -0
- package/lib/holding/index.d.ts +2 -0
- package/lib/holding/index.js +2 -0
- package/lib/index.js +12 -0
- package/lib/market/Market.d.ts +332 -0
- package/lib/market/Market.js +459 -0
- package/lib/market/MarketConfig.d.ts +52 -0
- package/lib/market/MarketConfig.js +73 -0
- package/lib/market/MarketUtils.d.ts +233 -0
- package/lib/market/MarketUtils.js +257 -0
- package/lib/market/index.d.ts +3 -0
- package/lib/market/index.js +3 -0
- package/lib/math/AdaptiveCurveIrmLib.d.ts +39 -0
- package/lib/math/AdaptiveCurveIrmLib.js +131 -0
- package/lib/math/MathLib.d.ts +111 -0
- package/lib/math/MathLib.js +185 -0
- package/lib/math/SharesMath.d.ts +12 -0
- package/lib/math/SharesMath.js +18 -0
- package/lib/math/index.d.ts +3 -0
- package/lib/math/index.js +3 -0
- package/lib/position/Position.d.ts +127 -0
- package/lib/position/Position.js +199 -0
- package/lib/position/index.d.ts +1 -0
- package/lib/position/index.js +1 -0
- package/lib/token/ConstantWrappedToken.d.ts +17 -0
- package/lib/token/ConstantWrappedToken.js +30 -0
- package/lib/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/token/ExchangeRateWrappedToken.js +17 -0
- package/lib/token/Token.d.ts +46 -0
- package/lib/token/Token.js +59 -0
- package/lib/token/VaultToken.d.ts +23 -0
- package/lib/token/VaultToken.js +27 -0
- package/lib/token/WrappedToken.d.ts +17 -0
- package/lib/token/WrappedToken.js +29 -0
- package/lib/token/index.d.ts +5 -0
- package/lib/token/index.js +5 -0
- package/lib/types.d.ts +27 -0
- package/lib/types.js +17 -0
- package/lib/user/User.d.ts +20 -0
- package/lib/user/User.js +19 -0
- package/lib/user/index.d.ts +1 -0
- package/lib/user/index.js +1 -0
- package/lib/vault/Vault.d.ts +152 -0
- package/lib/vault/Vault.js +221 -0
- package/lib/vault/VaultConfig.d.ts +22 -0
- package/lib/vault/VaultConfig.js +28 -0
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +26 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +39 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +24 -0
- package/lib/vault/VaultUser.d.ts +26 -0
- package/lib/vault/VaultUser.js +24 -0
- package/lib/vault/VaultUtils.d.ts +16 -0
- package/lib/vault/VaultUtils.js +17 -0
- package/lib/vault/index.d.ts +7 -0
- package/lib/vault/index.js +7 -0
- package/package.json +33 -25
- /package/{src/index.ts → lib/index.d.ts} +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
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 {
|
|
6
|
+
/**
|
|
7
|
+
* The MetaMorpho vault's owner address.
|
|
8
|
+
*/
|
|
9
|
+
owner;
|
|
10
|
+
/**
|
|
11
|
+
* The MetaMorpho vault's curator address.
|
|
12
|
+
*/
|
|
13
|
+
curator;
|
|
14
|
+
/**
|
|
15
|
+
* The MetaMorpho vault's guardian address.
|
|
16
|
+
*/
|
|
17
|
+
guardian;
|
|
18
|
+
/**
|
|
19
|
+
* The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
|
|
20
|
+
*/
|
|
21
|
+
skimRecipient;
|
|
22
|
+
/**
|
|
23
|
+
* The MetaMorpho vault's fee recipient address.
|
|
24
|
+
*/
|
|
25
|
+
feeRecipient;
|
|
26
|
+
/**
|
|
27
|
+
* The MetaMorpho vault's timelock (in seconds).
|
|
28
|
+
*/
|
|
29
|
+
timelock;
|
|
30
|
+
/**
|
|
31
|
+
* The MetaMorpho vault's fee.
|
|
32
|
+
*/
|
|
33
|
+
fee;
|
|
34
|
+
/**
|
|
35
|
+
* The MetaMorpho vault's pending owner address and activation timestamp.
|
|
36
|
+
*/
|
|
37
|
+
pendingOwner;
|
|
38
|
+
/**
|
|
39
|
+
* The MetaMorpho vault's pending guardian address and activation timestamp.
|
|
40
|
+
*/
|
|
41
|
+
pendingGuardian;
|
|
42
|
+
/**
|
|
43
|
+
* The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
|
|
44
|
+
*/
|
|
45
|
+
pendingTimelock;
|
|
46
|
+
/**
|
|
47
|
+
* The MetaMorpho vault's ordered supply queue.
|
|
48
|
+
*/
|
|
49
|
+
supplyQueue;
|
|
50
|
+
/**
|
|
51
|
+
* The MetaMorpho vault's ordered withdraw queue.
|
|
52
|
+
*/
|
|
53
|
+
withdrawQueue;
|
|
54
|
+
/**
|
|
55
|
+
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
56
|
+
*/
|
|
57
|
+
lastTotalAssets;
|
|
58
|
+
/**
|
|
59
|
+
* The MetaMorpho vault's public allocator configuration.
|
|
60
|
+
*/
|
|
61
|
+
publicAllocatorConfig;
|
|
62
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }) {
|
|
63
|
+
super(config, { totalAssets, totalSupply });
|
|
64
|
+
this.curator = curator;
|
|
65
|
+
this.owner = owner;
|
|
66
|
+
this.guardian = guardian;
|
|
67
|
+
this.fee = fee;
|
|
68
|
+
this.feeRecipient = feeRecipient;
|
|
69
|
+
this.skimRecipient = skimRecipient;
|
|
70
|
+
this.pendingTimelock = {
|
|
71
|
+
value: pendingTimelock.value,
|
|
72
|
+
validAt: pendingTimelock.validAt,
|
|
73
|
+
};
|
|
74
|
+
this.pendingGuardian = pendingGuardian;
|
|
75
|
+
this.pendingOwner = pendingOwner;
|
|
76
|
+
this.timelock = timelock;
|
|
77
|
+
this.supplyQueue = supplyQueue;
|
|
78
|
+
this.withdrawQueue = withdrawQueue;
|
|
79
|
+
this.lastTotalAssets = lastTotalAssets;
|
|
80
|
+
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
84
|
+
*/
|
|
85
|
+
get totalInterest() {
|
|
86
|
+
return MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
87
|
+
}
|
|
88
|
+
toAssets(shares, rounding) {
|
|
89
|
+
return this._unwrap(shares, rounding);
|
|
90
|
+
}
|
|
91
|
+
toShares(assets, rounding) {
|
|
92
|
+
return this._wrap(assets, rounding);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export class AccrualVault extends Vault {
|
|
96
|
+
/**
|
|
97
|
+
* The allocation of the vault on each market enabled.
|
|
98
|
+
*/
|
|
99
|
+
allocations;
|
|
100
|
+
/**
|
|
101
|
+
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
102
|
+
*/
|
|
103
|
+
collateralAllocations;
|
|
104
|
+
constructor(vault,
|
|
105
|
+
/**
|
|
106
|
+
* The allocation of the vault on each market of the withdraw queue,
|
|
107
|
+
* in the same order as the withdraw queue.
|
|
108
|
+
*/
|
|
109
|
+
allocations) {
|
|
110
|
+
super({
|
|
111
|
+
...vault,
|
|
112
|
+
withdrawQueue: allocations.map(({ position }) => position.market.id),
|
|
113
|
+
totalAssets: allocations.reduce((total, { position }) => total + position.supplyAssets, 0n),
|
|
114
|
+
});
|
|
115
|
+
this.allocations = new Map(allocations.map((allocation) => [
|
|
116
|
+
allocation.position.market.id,
|
|
117
|
+
new VaultMarketAllocation(allocation),
|
|
118
|
+
]));
|
|
119
|
+
this.collateralAllocations = new Map();
|
|
120
|
+
for (const { marketId, position } of this.allocations.values()) {
|
|
121
|
+
const address = position.market.config.collateralToken;
|
|
122
|
+
let exposure = this.collateralAllocations.get(address);
|
|
123
|
+
if (!exposure)
|
|
124
|
+
this.collateralAllocations.set(address, (exposure = {
|
|
125
|
+
address,
|
|
126
|
+
lltvs: new Set(),
|
|
127
|
+
oracles: new Set(),
|
|
128
|
+
markets: new Set(),
|
|
129
|
+
proportion: 0n,
|
|
130
|
+
}));
|
|
131
|
+
exposure.lltvs.add(position.market.config.lltv);
|
|
132
|
+
exposure.oracles.add(position.market.config.oracle);
|
|
133
|
+
exposure.markets.add(marketId);
|
|
134
|
+
exposure.proportion += this.getAllocationProportion(marketId);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The vault's liquidity directly available from allocated markets.
|
|
139
|
+
*/
|
|
140
|
+
get liquidity() {
|
|
141
|
+
return this.allocations
|
|
142
|
+
.values()
|
|
143
|
+
.reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The MetaMorpho vault's average APY on its assets, including the performance fee.
|
|
147
|
+
*/
|
|
148
|
+
get avgApy() {
|
|
149
|
+
if (this.totalAssets === 0n)
|
|
150
|
+
return 0n;
|
|
151
|
+
return (this.allocations
|
|
152
|
+
.values()
|
|
153
|
+
.reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
157
|
+
*/
|
|
158
|
+
get netApy() {
|
|
159
|
+
return MathLib.wMulDown(this.avgApy, MathLib.WAD - this.fee);
|
|
160
|
+
}
|
|
161
|
+
getAllocationProportion(marketId) {
|
|
162
|
+
if (this.totalAssets === 0n)
|
|
163
|
+
return 0n;
|
|
164
|
+
const allocation = this.allocations.get(marketId);
|
|
165
|
+
if (!allocation)
|
|
166
|
+
return 0n;
|
|
167
|
+
return MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
168
|
+
}
|
|
169
|
+
getDepositCapacityLimit(assets) {
|
|
170
|
+
const suppliable = this.allocations
|
|
171
|
+
.values()
|
|
172
|
+
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => MathLib.min(total +
|
|
173
|
+
(this.supplyQueue.includes(marketId)
|
|
174
|
+
? MathLib.zeroFloorSub(cap, supplyAssets)
|
|
175
|
+
: 0n), MathLib.MAX_UINT_256), 0n);
|
|
176
|
+
if (assets > suppliable)
|
|
177
|
+
return {
|
|
178
|
+
value: suppliable,
|
|
179
|
+
limiter: CapacityLimitReason.cap,
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
value: assets,
|
|
183
|
+
limiter: CapacityLimitReason.balance,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
getWithdrawCapacityLimit(shares) {
|
|
187
|
+
const assets = this.toAssets(shares);
|
|
188
|
+
const { liquidity } = this;
|
|
189
|
+
if (assets > liquidity)
|
|
190
|
+
return {
|
|
191
|
+
value: liquidity,
|
|
192
|
+
limiter: CapacityLimitReason.liquidity,
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
value: assets,
|
|
196
|
+
limiter: CapacityLimitReason.balance,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
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`.
|
|
202
|
+
*/
|
|
203
|
+
accrueInterest(timestamp) {
|
|
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);
|
|
214
|
+
vault.totalAssets -= feeAssets;
|
|
215
|
+
const feeShares = vault.toShares(feeAssets, "Down");
|
|
216
|
+
vault.totalAssets += feeAssets;
|
|
217
|
+
vault.totalSupply += feeShares;
|
|
218
|
+
vault.lastTotalAssets = vault.totalAssets;
|
|
219
|
+
return vault;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChainId } from "../chain.js";
|
|
2
|
+
import type { Address, BigIntish } from "../types.js";
|
|
3
|
+
export interface InputVaultConfig {
|
|
4
|
+
address: Address;
|
|
5
|
+
decimals: BigIntish;
|
|
6
|
+
decimalsOffset: BigIntish;
|
|
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,28 @@
|
|
|
1
|
+
import { UnknownVaultConfigError } from "../errors.js";
|
|
2
|
+
export class VaultConfig {
|
|
3
|
+
chainId;
|
|
4
|
+
static _CACHE = {};
|
|
5
|
+
static get(address, chainId) {
|
|
6
|
+
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
7
|
+
if (!config)
|
|
8
|
+
throw new UnknownVaultConfigError(address);
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
address;
|
|
12
|
+
decimals;
|
|
13
|
+
decimalsOffset;
|
|
14
|
+
symbol;
|
|
15
|
+
name;
|
|
16
|
+
asset;
|
|
17
|
+
constructor({ address, decimals, decimalsOffset, symbol, name, asset, }, chainId) {
|
|
18
|
+
this.chainId = chainId;
|
|
19
|
+
this.address = address;
|
|
20
|
+
this.decimals = Number(decimals);
|
|
21
|
+
this.decimalsOffset = BigInt(decimalsOffset);
|
|
22
|
+
this.symbol = symbol;
|
|
23
|
+
this.name = name;
|
|
24
|
+
this.asset = asset;
|
|
25
|
+
if (chainId != null)
|
|
26
|
+
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AccrualPosition } from "../position/index.js";
|
|
2
|
+
import type { VaultMarketConfig } from "./VaultMarketConfig.js";
|
|
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
|
+
readonly 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(): `0x${string}`;
|
|
18
|
+
get marketId(): import("../types.js").MarketId;
|
|
19
|
+
get utilization(): bigint;
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
export class VaultMarketAllocation {
|
|
3
|
+
/**
|
|
4
|
+
* The vault's configuration on the corresponding market.
|
|
5
|
+
*/
|
|
6
|
+
config;
|
|
7
|
+
/**
|
|
8
|
+
* The vault's position on the corresponding market.
|
|
9
|
+
*/
|
|
10
|
+
position;
|
|
11
|
+
constructor({ config, position }) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.position = position;
|
|
14
|
+
}
|
|
15
|
+
get vault() {
|
|
16
|
+
return this.config.vault;
|
|
17
|
+
}
|
|
18
|
+
get marketId() {
|
|
19
|
+
return this.config.marketId;
|
|
20
|
+
}
|
|
21
|
+
get utilization() {
|
|
22
|
+
if (this.config.cap === 0n)
|
|
23
|
+
return MathLib.MAX_UINT_256;
|
|
24
|
+
return MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Address, MarketId } from "../types.js";
|
|
2
|
+
import type { Pending } from "./Vault.js";
|
|
3
|
+
import type { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig.js";
|
|
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
|
+
readonly vault: Address;
|
|
18
|
+
/**
|
|
19
|
+
* The market's id.
|
|
20
|
+
*/
|
|
21
|
+
readonly 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
|
+
readonly publicAllocatorConfig: VaultMarketPublicAllocatorConfig;
|
|
42
|
+
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }: InputVaultMarketConfig);
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class VaultMarketConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The vault's address.
|
|
4
|
+
*/
|
|
5
|
+
vault;
|
|
6
|
+
/**
|
|
7
|
+
* The market's id.
|
|
8
|
+
*/
|
|
9
|
+
marketId;
|
|
10
|
+
/**
|
|
11
|
+
* The maximum amount of tokens that can be allocated to this market.
|
|
12
|
+
*/
|
|
13
|
+
cap;
|
|
14
|
+
/**
|
|
15
|
+
* The pending maximum amount of tokens that can be allocated to this market.
|
|
16
|
+
*/
|
|
17
|
+
pendingCap;
|
|
18
|
+
/**
|
|
19
|
+
* The timestamp at which the market can be removed from the withdraw queue.
|
|
20
|
+
*/
|
|
21
|
+
removableAt;
|
|
22
|
+
/**
|
|
23
|
+
* Whether this market is enabled, i.e. whether additional tokens can be allocated to it.
|
|
24
|
+
*/
|
|
25
|
+
enabled;
|
|
26
|
+
/**
|
|
27
|
+
* The vault's PublicAllocator configuration on the corresponding market.
|
|
28
|
+
*/
|
|
29
|
+
publicAllocatorConfig;
|
|
30
|
+
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }) {
|
|
31
|
+
this.vault = vault;
|
|
32
|
+
this.marketId = marketId;
|
|
33
|
+
this.cap = cap;
|
|
34
|
+
this.pendingCap = pendingCap;
|
|
35
|
+
this.removableAt = removableAt;
|
|
36
|
+
this.enabled = enabled;
|
|
37
|
+
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address, MarketId } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The vault's configuration of a market on the PublicAllocator.
|
|
4
|
+
*/
|
|
5
|
+
export interface InputVaultMarketPublicAllocatorConfig {
|
|
6
|
+
vault: Address;
|
|
7
|
+
marketId: MarketId;
|
|
8
|
+
maxIn: bigint;
|
|
9
|
+
maxOut: bigint;
|
|
10
|
+
}
|
|
11
|
+
export declare class VaultMarketPublicAllocatorConfig implements InputVaultMarketPublicAllocatorConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The vault's address.
|
|
14
|
+
*/
|
|
15
|
+
readonly vault: Address;
|
|
16
|
+
/**
|
|
17
|
+
* The market's id.
|
|
18
|
+
*/
|
|
19
|
+
readonly marketId: MarketId;
|
|
20
|
+
/**
|
|
21
|
+
* The maximum amount of tokens that can be allocated to this market by the vault via the PublicAllocator.
|
|
22
|
+
*/
|
|
23
|
+
maxIn: bigint;
|
|
24
|
+
/**
|
|
25
|
+
* The maximum amount of tokens that can be allocated out of this market by the vault via the PublicAllocator.
|
|
26
|
+
*/
|
|
27
|
+
maxOut: bigint;
|
|
28
|
+
constructor({ vault, marketId, maxIn, maxOut, }: InputVaultMarketPublicAllocatorConfig);
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class VaultMarketPublicAllocatorConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The vault's address.
|
|
4
|
+
*/
|
|
5
|
+
vault;
|
|
6
|
+
/**
|
|
7
|
+
* The market's id.
|
|
8
|
+
*/
|
|
9
|
+
marketId;
|
|
10
|
+
/**
|
|
11
|
+
* The maximum amount of tokens that can be allocated to this market by the vault via the PublicAllocator.
|
|
12
|
+
*/
|
|
13
|
+
maxIn;
|
|
14
|
+
/**
|
|
15
|
+
* The maximum amount of tokens that can be allocated out of this market by the vault via the PublicAllocator.
|
|
16
|
+
*/
|
|
17
|
+
maxOut;
|
|
18
|
+
constructor({ vault, marketId, maxIn, maxOut, }) {
|
|
19
|
+
this.vault = vault;
|
|
20
|
+
this.marketId = marketId;
|
|
21
|
+
this.maxIn = maxIn;
|
|
22
|
+
this.maxOut = maxOut;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Address } from "../types.js";
|
|
2
|
+
export interface InputVaultUser {
|
|
3
|
+
vault: Address;
|
|
4
|
+
user: Address;
|
|
5
|
+
isAllocator: boolean;
|
|
6
|
+
allowance: bigint;
|
|
7
|
+
}
|
|
8
|
+
export declare class VaultUser implements InputVaultUser {
|
|
9
|
+
/**
|
|
10
|
+
* The vault's address.
|
|
11
|
+
*/
|
|
12
|
+
readonly vault: Address;
|
|
13
|
+
/**
|
|
14
|
+
* The user's address.
|
|
15
|
+
*/
|
|
16
|
+
readonly user: Address;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the user is an allocator of the vault.
|
|
19
|
+
*/
|
|
20
|
+
isAllocator: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The allowance of the vault over the user's underlying assets.
|
|
23
|
+
*/
|
|
24
|
+
allowance: bigint;
|
|
25
|
+
constructor({ vault, user, isAllocator, allowance }: InputVaultUser);
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class VaultUser {
|
|
2
|
+
/**
|
|
3
|
+
* The vault's address.
|
|
4
|
+
*/
|
|
5
|
+
vault;
|
|
6
|
+
/**
|
|
7
|
+
* The user's address.
|
|
8
|
+
*/
|
|
9
|
+
user;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the user is an allocator of the vault.
|
|
12
|
+
*/
|
|
13
|
+
isAllocator;
|
|
14
|
+
/**
|
|
15
|
+
* The allowance of the vault over the user's underlying assets.
|
|
16
|
+
*/
|
|
17
|
+
allowance;
|
|
18
|
+
constructor({ vault, user, isAllocator, allowance }) {
|
|
19
|
+
this.vault = vault;
|
|
20
|
+
this.user = user;
|
|
21
|
+
this.isAllocator = isAllocator;
|
|
22
|
+
this.allowance = allowance;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type RoundingDirection } from "../math/index.js";
|
|
2
|
+
import type { BigIntish } from "../types.js";
|
|
3
|
+
export declare namespace VaultUtils {
|
|
4
|
+
const VIRTUAL_ASSETS = 1n;
|
|
5
|
+
function decimalsOffset(decimals: BigIntish): bigint;
|
|
6
|
+
function toAssets(shares: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
|
|
7
|
+
totalAssets: BigIntish;
|
|
8
|
+
totalSupply: BigIntish;
|
|
9
|
+
decimalsOffset: BigIntish;
|
|
10
|
+
}, rounding?: RoundingDirection): bigint;
|
|
11
|
+
function toShares(assets: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
|
|
12
|
+
totalAssets: BigIntish;
|
|
13
|
+
totalSupply: BigIntish;
|
|
14
|
+
decimalsOffset: BigIntish;
|
|
15
|
+
}, rounding?: RoundingDirection): bigint;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MathLib } from "../math/index.js";
|
|
2
|
+
export var VaultUtils;
|
|
3
|
+
(function (VaultUtils) {
|
|
4
|
+
VaultUtils.VIRTUAL_ASSETS = 1n;
|
|
5
|
+
function decimalsOffset(decimals) {
|
|
6
|
+
return MathLib.zeroFloorSub(18n, decimals);
|
|
7
|
+
}
|
|
8
|
+
VaultUtils.decimalsOffset = decimalsOffset;
|
|
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);
|
|
11
|
+
}
|
|
12
|
+
VaultUtils.toAssets = toAssets;
|
|
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);
|
|
15
|
+
}
|
|
16
|
+
VaultUtils.toShares = toShares;
|
|
17
|
+
})(VaultUtils || (VaultUtils = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
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";
|
|
@@ -0,0 +1,7 @@
|
|
|
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";
|
package/package.json
CHANGED
|
@@ -1,44 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.2",
|
|
4
4
|
"author": "Morpho Labs <contact@morpho.org>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "
|
|
7
|
+
"main": "lib/index.js",
|
|
8
8
|
"files": [
|
|
9
9
|
"lib"
|
|
10
10
|
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"prepublish": "$npm_execpath build",
|
|
13
|
-
"build": "tsc --build tsconfig.build.json",
|
|
14
|
-
"test": "vitest"
|
|
15
|
-
},
|
|
16
11
|
"dependencies": {
|
|
17
12
|
"keccak256": "^1.0.6"
|
|
18
13
|
},
|
|
19
14
|
"peerDependencies": {
|
|
20
|
-
"@morpho-org/morpho-ts": "
|
|
15
|
+
"@morpho-org/morpho-ts": "^1.12.4"
|
|
21
16
|
},
|
|
22
17
|
"devDependencies": {
|
|
23
|
-
"@morpho-org/morpho-ts": "workspace:^",
|
|
24
|
-
"@morpho-org/test": "workspace:^",
|
|
25
|
-
"@morpho-org/test-viem": "workspace:^",
|
|
26
18
|
"@types/node": "^22.1.0",
|
|
27
19
|
"typescript": "^5.6.3",
|
|
28
20
|
"viem": "^2.21.19",
|
|
29
21
|
"viem-deal": "^2.0.0",
|
|
30
|
-
"vitest": "^2.1.3"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"types": "lib/index.d.ts",
|
|
35
|
-
"exports": {
|
|
36
|
-
".": {
|
|
37
|
-
"types": "./lib/index.d.ts",
|
|
38
|
-
"default": "./lib/index.js"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"access": "public"
|
|
22
|
+
"vitest": "^2.1.3",
|
|
23
|
+
"@morpho-org/morpho-ts": "^1.12.4",
|
|
24
|
+
"@morpho-org/test-viem": "^1.12.4",
|
|
25
|
+
"@morpho-org/test": "^1.12.4"
|
|
42
26
|
},
|
|
43
27
|
"release": {
|
|
44
28
|
"branches": [
|
|
@@ -48,6 +32,30 @@
|
|
|
48
32
|
"prerelease": true
|
|
49
33
|
}
|
|
50
34
|
],
|
|
51
|
-
"extends": "semantic-release-monorepo"
|
|
35
|
+
"extends": "semantic-release-monorepo",
|
|
36
|
+
"plugins": [
|
|
37
|
+
"@semantic-release/commit-analyzer",
|
|
38
|
+
"@semantic-release/release-notes-generator",
|
|
39
|
+
[
|
|
40
|
+
"@semantic-release/exec",
|
|
41
|
+
{
|
|
42
|
+
"prepareCmd": "pnpm version ${nextRelease.version} --no-git-tag-version",
|
|
43
|
+
"publishCmd": "pnpm publish --access public --tag ${nextRelease.channel} --no-git-checks"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"@semantic-release/github"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"prepublish": "$npm_execpath build",
|
|
51
|
+
"build": "tsc --build tsconfig.build.json",
|
|
52
|
+
"test": "vitest"
|
|
53
|
+
},
|
|
54
|
+
"types": "lib/index.d.ts",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./lib/index.d.ts",
|
|
58
|
+
"default": "./lib/index.js"
|
|
59
|
+
}
|
|
52
60
|
}
|
|
53
|
-
}
|
|
61
|
+
}
|
|
File without changes
|