@morpho-org/blue-sdk 2.0.0-test.1 → 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/LICENSE +21 -0
- package/README.md +46 -26
- package/lib/addresses.d.ts +59 -55
- package/lib/addresses.js +42 -43
- package/lib/chain.d.ts +1 -1
- package/lib/chain.js +3 -3
- package/lib/errors.d.ts +7 -8
- package/lib/errors.js +21 -19
- package/lib/holding/AssetBalances.d.ts +3 -3
- package/lib/holding/Holding.d.ts +10 -5
- package/lib/holding/Holding.js +14 -4
- package/lib/holding/index.d.ts +2 -2
- package/lib/holding/index.js +2 -2
- package/lib/index.d.ts +12 -25
- package/lib/index.js +12 -38
- package/lib/market/Market.d.ts +48 -34
- package/lib/market/Market.js +76 -57
- package/lib/market/{MarketConfig.d.ts → MarketParams.d.ts} +8 -7
- package/lib/market/{MarketConfig.js → MarketParams.js} +20 -21
- package/lib/market/MarketUtils.d.ts +94 -42
- package/lib/market/MarketUtils.js +145 -67
- package/lib/market/index.d.ts +3 -3
- package/lib/market/index.js +3 -3
- package/lib/{maths → math}/AdaptiveCurveIrmLib.d.ts +1 -1
- package/lib/{maths → math}/AdaptiveCurveIrmLib.js +20 -20
- package/lib/{maths → math}/MathLib.d.ts +24 -42
- package/lib/{maths → math}/MathLib.js +41 -54
- package/lib/{maths → math}/SharesMath.d.ts +2 -2
- package/lib/{maths → math}/SharesMath.js +3 -3
- package/lib/math/index.d.ts +3 -0
- package/lib/{helpers/format → math}/index.js +3 -1
- package/lib/position/Position.d.ts +35 -25
- package/lib/position/Position.js +46 -44
- package/lib/position/index.d.ts +1 -1
- package/lib/position/index.js +1 -1
- package/lib/token/ConstantWrappedToken.d.ts +6 -7
- package/lib/token/ConstantWrappedToken.js +8 -10
- package/lib/token/ExchangeRateWrappedToken.d.ts +5 -5
- package/lib/token/ExchangeRateWrappedToken.js +5 -5
- package/lib/token/Token.d.ts +18 -18
- package/lib/token/Token.js +24 -27
- package/lib/token/VaultToken.d.ts +20 -11
- package/lib/token/VaultToken.js +15 -7
- package/lib/token/WrappedToken.d.ts +4 -4
- package/lib/token/WrappedToken.js +7 -7
- package/lib/token/index.d.ts +5 -5
- package/lib/token/index.js +5 -5
- package/lib/types.d.ts +3 -6
- package/lib/user/User.d.ts +1 -1
- package/lib/user/index.d.ts +1 -1
- package/lib/user/index.js +1 -1
- package/lib/vault/Vault.d.ts +22 -28
- package/lib/vault/Vault.js +43 -51
- package/lib/vault/VaultConfig.d.ts +6 -7
- package/lib/vault/VaultConfig.js +5 -5
- package/lib/vault/VaultMarketAllocation.d.ts +8 -8
- package/lib/vault/VaultMarketAllocation.js +3 -3
- package/lib/vault/VaultMarketConfig.d.ts +10 -10
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +6 -6
- package/lib/vault/VaultUser.d.ts +26 -0
- package/lib/vault/VaultUser.js +28 -0
- package/lib/vault/VaultUtils.d.ts +4 -6
- package/lib/vault/VaultUtils.js +6 -6
- package/lib/vault/index.d.ts +7 -6
- package/lib/vault/index.js +7 -6
- package/package.json +25 -56
- package/lib/chain.test.d.ts +0 -1
- package/lib/chain.test.js +0 -21
- package/lib/helpers/format/format.d.ts +0 -122
- package/lib/helpers/format/format.js +0 -286
- package/lib/helpers/format/format.test.d.ts +0 -1
- package/lib/helpers/format/format.test.js +0 -255
- package/lib/helpers/format/index.d.ts +0 -1
- package/lib/helpers/index.d.ts +0 -2
- package/lib/helpers/index.js +0 -18
- package/lib/helpers/locale.d.ts +0 -46
- package/lib/helpers/locale.js +0 -96
- package/lib/market/MarketUtils.test.d.ts +0 -1
- package/lib/market/MarketUtils.test.js +0 -38
- 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
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 {
|
|
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 { 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,8 +22,7 @@ export interface VaultPublicAllocatorConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
accruedFee: bigint;
|
|
24
24
|
}
|
|
25
|
-
export interface
|
|
26
|
-
config: VaultConfig;
|
|
25
|
+
export interface IVault extends IVaultConfig {
|
|
27
26
|
curator: Address;
|
|
28
27
|
owner: Address;
|
|
29
28
|
guardian: Address;
|
|
@@ -41,11 +40,15 @@ export interface InputVault {
|
|
|
41
40
|
lastTotalAssets: bigint;
|
|
42
41
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
43
42
|
}
|
|
44
|
-
export declare class Vault extends VaultToken implements
|
|
43
|
+
export declare class Vault extends VaultToken implements IVault {
|
|
45
44
|
/**
|
|
46
|
-
* The
|
|
45
|
+
* The vault's share token's name.
|
|
47
46
|
*/
|
|
48
|
-
readonly
|
|
47
|
+
readonly name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The vault's share token's symbol.
|
|
50
|
+
*/
|
|
51
|
+
readonly symbol: string;
|
|
49
52
|
/**
|
|
50
53
|
* The MetaMorpho vault's owner address.
|
|
51
54
|
*/
|
|
@@ -94,14 +97,6 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
94
97
|
* The MetaMorpho vault's ordered withdraw queue.
|
|
95
98
|
*/
|
|
96
99
|
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
100
|
/**
|
|
106
101
|
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
107
102
|
*/
|
|
@@ -110,8 +105,7 @@ export declare class Vault extends VaultToken implements InputVault {
|
|
|
110
105
|
* The MetaMorpho vault's public allocator configuration.
|
|
111
106
|
*/
|
|
112
107
|
publicAllocatorConfig?: VaultPublicAllocatorConfig;
|
|
113
|
-
constructor({
|
|
114
|
-
get asset(): string;
|
|
108
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }: IVault);
|
|
115
109
|
/**
|
|
116
110
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
111
|
*/
|
|
@@ -126,9 +120,9 @@ export interface CollateralAllocation {
|
|
|
126
120
|
markets: Set<MarketId>;
|
|
127
121
|
proportion: bigint;
|
|
128
122
|
}
|
|
129
|
-
export interface
|
|
123
|
+
export interface IAccrualVault extends Omit<IVault, "withdrawQueue" | "totalAssets"> {
|
|
130
124
|
}
|
|
131
|
-
export declare class AccrualVault extends Vault implements
|
|
125
|
+
export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
132
126
|
/**
|
|
133
127
|
* The allocation of the vault on each market enabled.
|
|
134
128
|
*/
|
|
@@ -137,22 +131,22 @@ export declare class AccrualVault extends Vault implements InputAccrualVault {
|
|
|
137
131
|
* The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
|
|
138
132
|
*/
|
|
139
133
|
readonly collateralAllocations: Map<Address, CollateralAllocation>;
|
|
140
|
-
constructor(vault:
|
|
134
|
+
constructor(vault: IAccrualVault,
|
|
141
135
|
/**
|
|
142
136
|
* The allocation of the vault on each market of the withdraw queue,
|
|
143
137
|
* in the same order as the withdraw queue.
|
|
144
138
|
*/
|
|
145
|
-
allocations: Omit<
|
|
139
|
+
allocations: Omit<IVaultMarketAllocation, "proportion">[]);
|
|
146
140
|
/**
|
|
147
141
|
* The vault's liquidity directly available from allocated markets.
|
|
148
142
|
*/
|
|
149
143
|
get liquidity(): bigint;
|
|
150
144
|
/**
|
|
151
|
-
* The MetaMorpho vault's
|
|
145
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, before deducting the performance fee.
|
|
152
146
|
*/
|
|
153
|
-
get
|
|
147
|
+
get apy(): bigint;
|
|
154
148
|
/**
|
|
155
|
-
* The MetaMorpho vault's
|
|
149
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, after deducting the performance fee.
|
|
156
150
|
*/
|
|
157
151
|
get netApy(): bigint;
|
|
158
152
|
getAllocationProportion(marketId: MarketId): bigint;
|
package/lib/vault/Vault.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
class Vault extends token_1.VaultToken {
|
|
10
|
-
/**
|
|
11
|
-
* The MetaMorpho vault's config.
|
|
12
|
-
*/
|
|
13
|
-
config;
|
|
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 {
|
|
14
9
|
/**
|
|
15
10
|
* The MetaMorpho vault's owner address.
|
|
16
11
|
*/
|
|
@@ -59,14 +54,6 @@ class Vault extends token_1.VaultToken {
|
|
|
59
54
|
* The MetaMorpho vault's ordered withdraw queue.
|
|
60
55
|
*/
|
|
61
56
|
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
57
|
/**
|
|
71
58
|
* The MetaMorpho vault's last total assets used to calculate performance fees.
|
|
72
59
|
*/
|
|
@@ -75,9 +62,8 @@ class Vault extends token_1.VaultToken {
|
|
|
75
62
|
* The MetaMorpho vault's public allocator configuration.
|
|
76
63
|
*/
|
|
77
64
|
publicAllocatorConfig;
|
|
78
|
-
constructor({
|
|
65
|
+
constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }) {
|
|
79
66
|
super(config, { totalAssets, totalSupply });
|
|
80
|
-
this.config = config;
|
|
81
67
|
this.curator = curator;
|
|
82
68
|
this.owner = owner;
|
|
83
69
|
this.guardian = guardian;
|
|
@@ -93,25 +79,20 @@ class Vault extends token_1.VaultToken {
|
|
|
93
79
|
this.timelock = timelock;
|
|
94
80
|
this.supplyQueue = supplyQueue;
|
|
95
81
|
this.withdrawQueue = withdrawQueue;
|
|
96
|
-
this.totalSupply = totalSupply;
|
|
97
|
-
this.totalAssets = totalAssets;
|
|
98
82
|
this.lastTotalAssets = lastTotalAssets;
|
|
99
83
|
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
100
84
|
}
|
|
101
|
-
get asset() {
|
|
102
|
-
return this.config.asset;
|
|
103
|
-
}
|
|
104
85
|
/**
|
|
105
86
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
106
87
|
*/
|
|
107
88
|
get totalInterest() {
|
|
108
|
-
return
|
|
89
|
+
return index_js_2.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
109
90
|
}
|
|
110
91
|
toAssets(shares, rounding) {
|
|
111
|
-
return
|
|
92
|
+
return this._unwrap(shares, rounding);
|
|
112
93
|
}
|
|
113
94
|
toShares(assets, rounding) {
|
|
114
|
-
return
|
|
95
|
+
return this._wrap(assets, rounding);
|
|
115
96
|
}
|
|
116
97
|
}
|
|
117
98
|
exports.Vault = Vault;
|
|
@@ -137,11 +118,11 @@ class AccrualVault extends Vault {
|
|
|
137
118
|
});
|
|
138
119
|
this.allocations = new Map(allocations.map((allocation) => [
|
|
139
120
|
allocation.position.market.id,
|
|
140
|
-
new
|
|
121
|
+
new VaultMarketAllocation_js_1.VaultMarketAllocation(allocation),
|
|
141
122
|
]));
|
|
142
123
|
this.collateralAllocations = new Map();
|
|
143
124
|
for (const { marketId, position } of this.allocations.values()) {
|
|
144
|
-
const address = position.market.
|
|
125
|
+
const address = position.market.params.collateralToken;
|
|
145
126
|
let exposure = this.collateralAllocations.get(address);
|
|
146
127
|
if (!exposure)
|
|
147
128
|
this.collateralAllocations.set(address, (exposure = {
|
|
@@ -151,8 +132,8 @@ class AccrualVault extends Vault {
|
|
|
151
132
|
markets: new Set(),
|
|
152
133
|
proportion: 0n,
|
|
153
134
|
}));
|
|
154
|
-
exposure.lltvs.add(position.market.
|
|
155
|
-
exposure.oracles.add(position.market.
|
|
135
|
+
exposure.lltvs.add(position.market.params.lltv);
|
|
136
|
+
exposure.oracles.add(position.market.params.oracle);
|
|
156
137
|
exposure.markets.add(marketId);
|
|
157
138
|
exposure.proportion += this.getAllocationProportion(marketId);
|
|
158
139
|
}
|
|
@@ -161,21 +142,25 @@ class AccrualVault extends Vault {
|
|
|
161
142
|
* The vault's liquidity directly available from allocated markets.
|
|
162
143
|
*/
|
|
163
144
|
get liquidity() {
|
|
164
|
-
return
|
|
145
|
+
return this.allocations
|
|
146
|
+
.values()
|
|
147
|
+
.reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
|
|
165
148
|
}
|
|
166
149
|
/**
|
|
167
|
-
* The MetaMorpho vault's
|
|
150
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, before deducting the performance fee.
|
|
168
151
|
*/
|
|
169
|
-
get
|
|
152
|
+
get apy() {
|
|
170
153
|
if (this.totalAssets === 0n)
|
|
171
154
|
return 0n;
|
|
172
|
-
return (
|
|
155
|
+
return (this.allocations
|
|
156
|
+
.values()
|
|
157
|
+
.reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
|
|
173
158
|
}
|
|
174
159
|
/**
|
|
175
|
-
* The MetaMorpho vault's
|
|
160
|
+
* The MetaMorpho vault's APY on its assets averaged over its market deposits, after deducting the performance fee.
|
|
176
161
|
*/
|
|
177
162
|
get netApy() {
|
|
178
|
-
return
|
|
163
|
+
return index_js_2.MathLib.wMulDown(this.apy, index_js_2.MathLib.WAD - this.fee);
|
|
179
164
|
}
|
|
180
165
|
getAllocationProportion(marketId) {
|
|
181
166
|
if (this.totalAssets === 0n)
|
|
@@ -183,21 +168,23 @@ class AccrualVault extends Vault {
|
|
|
183
168
|
const allocation = this.allocations.get(marketId);
|
|
184
169
|
if (!allocation)
|
|
185
170
|
return 0n;
|
|
186
|
-
return
|
|
171
|
+
return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
187
172
|
}
|
|
188
173
|
getDepositCapacityLimit(assets) {
|
|
189
|
-
const suppliable =
|
|
174
|
+
const suppliable = this.allocations
|
|
175
|
+
.values()
|
|
176
|
+
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
|
|
190
177
|
(this.supplyQueue.includes(marketId)
|
|
191
|
-
?
|
|
192
|
-
: 0n),
|
|
178
|
+
? index_js_2.MathLib.zeroFloorSub(cap, supplyAssets)
|
|
179
|
+
: 0n), index_js_2.MathLib.MAX_UINT_256), 0n);
|
|
193
180
|
if (assets > suppliable)
|
|
194
181
|
return {
|
|
195
182
|
value: suppliable,
|
|
196
|
-
limiter:
|
|
183
|
+
limiter: index_js_1.CapacityLimitReason.cap,
|
|
197
184
|
};
|
|
198
185
|
return {
|
|
199
186
|
value: assets,
|
|
200
|
-
limiter:
|
|
187
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
201
188
|
};
|
|
202
189
|
}
|
|
203
190
|
getWithdrawCapacityLimit(shares) {
|
|
@@ -206,11 +193,11 @@ class AccrualVault extends Vault {
|
|
|
206
193
|
if (assets > liquidity)
|
|
207
194
|
return {
|
|
208
195
|
value: liquidity,
|
|
209
|
-
limiter:
|
|
196
|
+
limiter: index_js_1.CapacityLimitReason.liquidity,
|
|
210
197
|
};
|
|
211
198
|
return {
|
|
212
199
|
value: assets,
|
|
213
|
-
limiter:
|
|
200
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
214
201
|
};
|
|
215
202
|
}
|
|
216
203
|
/**
|
|
@@ -218,11 +205,16 @@ class AccrualVault extends Vault {
|
|
|
218
205
|
* @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
206
|
*/
|
|
220
207
|
accrueInterest(timestamp) {
|
|
221
|
-
const vault = new AccrualVault(this,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
208
|
+
const vault = new AccrualVault(this,
|
|
209
|
+
// Keep withdraw queue order.
|
|
210
|
+
this.withdrawQueue.map((marketId) => {
|
|
211
|
+
const { config, position } = this.allocations.get(marketId);
|
|
212
|
+
return {
|
|
213
|
+
config,
|
|
214
|
+
position: position.accrueInterest(timestamp),
|
|
215
|
+
};
|
|
216
|
+
}));
|
|
217
|
+
const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
226
218
|
vault.totalAssets -= feeAssets;
|
|
227
219
|
const feeShares = vault.toShares(feeAssets, "Down");
|
|
228
220
|
vault.totalAssets += feeAssets;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { ChainId } from "../chain";
|
|
2
|
-
import { Address } from "../types";
|
|
3
|
-
export interface
|
|
1
|
+
import type { ChainId } from "../chain.js";
|
|
2
|
+
import type { Address, BigIntish } from "../types.js";
|
|
3
|
+
export interface IVaultConfig {
|
|
4
4
|
address: Address;
|
|
5
|
-
|
|
6
|
-
decimalsOffset: bigint;
|
|
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,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
5
|
class VaultConfig {
|
|
6
6
|
chainId;
|
|
7
7
|
static _CACHE = {};
|
|
8
8
|
static get(address, chainId) {
|
|
9
9
|
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
10
10
|
if (!config)
|
|
11
|
-
throw new
|
|
11
|
+
throw new errors_js_1.UnknownVaultConfigError(address);
|
|
12
12
|
return config;
|
|
13
13
|
}
|
|
14
14
|
address;
|
|
@@ -17,11 +17,11 @@ class VaultConfig {
|
|
|
17
17
|
symbol;
|
|
18
18
|
name;
|
|
19
19
|
asset;
|
|
20
|
-
constructor({ address,
|
|
20
|
+
constructor({ address, decimalsOffset, symbol, name, asset }, chainId) {
|
|
21
21
|
this.chainId = chainId;
|
|
22
22
|
this.address = address;
|
|
23
|
-
this.decimals =
|
|
24
|
-
this.decimalsOffset = decimalsOffset;
|
|
23
|
+
this.decimals = 18;
|
|
24
|
+
this.decimalsOffset = BigInt(decimalsOffset);
|
|
25
25
|
this.symbol = symbol;
|
|
26
26
|
this.name = name;
|
|
27
27
|
this.asset = asset;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { AccrualPosition } from "../position";
|
|
2
|
-
import { VaultMarketConfig } from "./VaultMarketConfig";
|
|
3
|
-
export interface
|
|
1
|
+
import type { AccrualPosition } from "../position/index.js";
|
|
2
|
+
import type { VaultMarketConfig } from "./VaultMarketConfig.js";
|
|
3
|
+
export interface IVaultMarketAllocation {
|
|
4
4
|
config: VaultMarketConfig;
|
|
5
5
|
position: AccrualPosition;
|
|
6
6
|
}
|
|
7
|
-
export declare class VaultMarketAllocation implements
|
|
7
|
+
export declare class VaultMarketAllocation implements IVaultMarketAllocation {
|
|
8
8
|
/**
|
|
9
9
|
* The vault's configuration on the corresponding market.
|
|
10
10
|
*/
|
|
11
|
-
config: VaultMarketConfig;
|
|
11
|
+
readonly config: VaultMarketConfig;
|
|
12
12
|
/**
|
|
13
13
|
* The vault's position on the corresponding market.
|
|
14
14
|
*/
|
|
15
15
|
readonly position: AccrualPosition;
|
|
16
|
-
constructor({ config, position }:
|
|
17
|
-
get vault(): string
|
|
18
|
-
get marketId(): import("
|
|
16
|
+
constructor({ config, position }: IVaultMarketAllocation);
|
|
17
|
+
get vault(): `0x${string}`;
|
|
18
|
+
get marketId(): import("../types.js").MarketId;
|
|
19
19
|
get utilization(): bigint;
|
|
20
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultMarketAllocation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
5
|
class VaultMarketAllocation {
|
|
6
6
|
/**
|
|
7
7
|
* The vault's configuration on the corresponding market.
|
|
@@ -23,8 +23,8 @@ class VaultMarketAllocation {
|
|
|
23
23
|
}
|
|
24
24
|
get utilization() {
|
|
25
25
|
if (this.config.cap === 0n)
|
|
26
|
-
return
|
|
27
|
-
return
|
|
26
|
+
return index_js_1.MathLib.MAX_UINT_256;
|
|
27
|
+
return index_js_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.VaultMarketAllocation = VaultMarketAllocation;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Address, MarketId } from "../types";
|
|
2
|
-
import { Pending } from "./Vault";
|
|
3
|
-
import { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig";
|
|
4
|
-
export interface
|
|
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 IVaultMarketConfig {
|
|
5
5
|
vault: Address;
|
|
6
6
|
marketId: MarketId;
|
|
7
7
|
cap: bigint;
|
|
8
8
|
pendingCap: Pending<bigint>;
|
|
9
9
|
removableAt: bigint;
|
|
10
10
|
enabled: boolean;
|
|
11
|
-
publicAllocatorConfig
|
|
11
|
+
publicAllocatorConfig: VaultMarketPublicAllocatorConfig;
|
|
12
12
|
}
|
|
13
|
-
export declare class VaultMarketConfig implements
|
|
13
|
+
export declare class VaultMarketConfig implements IVaultMarketConfig {
|
|
14
14
|
/**
|
|
15
15
|
* The vault's address.
|
|
16
16
|
*/
|
|
17
|
-
vault: Address;
|
|
17
|
+
readonly vault: Address;
|
|
18
18
|
/**
|
|
19
19
|
* The market's id.
|
|
20
20
|
*/
|
|
21
|
-
marketId: MarketId;
|
|
21
|
+
readonly marketId: MarketId;
|
|
22
22
|
/**
|
|
23
23
|
* The maximum amount of tokens that can be allocated to this market.
|
|
24
24
|
*/
|
|
@@ -38,6 +38,6 @@ export declare class VaultMarketConfig implements InputVaultMarketConfig {
|
|
|
38
38
|
/**
|
|
39
39
|
* The vault's PublicAllocator configuration on the corresponding market.
|
|
40
40
|
*/
|
|
41
|
-
publicAllocatorConfig
|
|
42
|
-
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }:
|
|
41
|
+
readonly publicAllocatorConfig: VaultMarketPublicAllocatorConfig;
|
|
42
|
+
constructor({ vault, marketId, cap, pendingCap, removableAt, enabled, publicAllocatorConfig, }: IVaultMarketConfig);
|
|
43
43
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { Address, MarketId } from "../types";
|
|
1
|
+
import type { Address, MarketId } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* The vault's configuration of a market on the PublicAllocator.
|
|
4
4
|
*/
|
|
5
|
-
export interface
|
|
5
|
+
export interface IVaultMarketPublicAllocatorConfig {
|
|
6
6
|
vault: Address;
|
|
7
7
|
marketId: MarketId;
|
|
8
8
|
maxIn: bigint;
|
|
9
9
|
maxOut: bigint;
|
|
10
10
|
}
|
|
11
|
-
export declare class VaultMarketPublicAllocatorConfig implements
|
|
11
|
+
export declare class VaultMarketPublicAllocatorConfig implements IVaultMarketPublicAllocatorConfig {
|
|
12
12
|
/**
|
|
13
13
|
* The vault's address.
|
|
14
14
|
*/
|
|
15
|
-
vault: Address;
|
|
15
|
+
readonly vault: Address;
|
|
16
16
|
/**
|
|
17
17
|
* The market's id.
|
|
18
18
|
*/
|
|
19
|
-
marketId: MarketId;
|
|
19
|
+
readonly marketId: MarketId;
|
|
20
20
|
/**
|
|
21
21
|
* The maximum amount of tokens that can be allocated to this market by the vault via the PublicAllocator.
|
|
22
22
|
*/
|
|
@@ -25,5 +25,5 @@ export declare class VaultMarketPublicAllocatorConfig implements InputVaultMarke
|
|
|
25
25
|
* The maximum amount of tokens that can be allocated out of this market by the vault via the PublicAllocator.
|
|
26
26
|
*/
|
|
27
27
|
maxOut: bigint;
|
|
28
|
-
constructor({ vault, marketId, maxIn, maxOut, }:
|
|
28
|
+
constructor({ vault, marketId, maxIn, maxOut, }: IVaultMarketPublicAllocatorConfig);
|
|
29
29
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Address } from "../types.js";
|
|
2
|
+
export interface IVaultUser {
|
|
3
|
+
vault: Address;
|
|
4
|
+
user: Address;
|
|
5
|
+
isAllocator: boolean;
|
|
6
|
+
allowance: bigint;
|
|
7
|
+
}
|
|
8
|
+
export declare class VaultUser implements IVaultUser {
|
|
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 }: IVaultUser);
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultUser = void 0;
|
|
4
|
+
class VaultUser {
|
|
5
|
+
/**
|
|
6
|
+
* The vault's address.
|
|
7
|
+
*/
|
|
8
|
+
vault;
|
|
9
|
+
/**
|
|
10
|
+
* The user's address.
|
|
11
|
+
*/
|
|
12
|
+
user;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the user is an allocator of the vault.
|
|
15
|
+
*/
|
|
16
|
+
isAllocator;
|
|
17
|
+
/**
|
|
18
|
+
* The allowance of the vault over the user's underlying assets.
|
|
19
|
+
*/
|
|
20
|
+
allowance;
|
|
21
|
+
constructor({ vault, user, isAllocator, allowance }) {
|
|
22
|
+
this.vault = vault;
|
|
23
|
+
this.user = user;
|
|
24
|
+
this.isAllocator = isAllocator;
|
|
25
|
+
this.allowance = allowance;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
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,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VaultUtils = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
5
|
var VaultUtils;
|
|
6
6
|
(function (VaultUtils) {
|
|
7
7
|
VaultUtils.VIRTUAL_ASSETS = 1n;
|
|
8
8
|
function decimalsOffset(decimals) {
|
|
9
|
-
return
|
|
9
|
+
return index_js_1.MathLib.zeroFloorSub(18n, decimals);
|
|
10
10
|
}
|
|
11
11
|
VaultUtils.decimalsOffset = decimalsOffset;
|
|
12
|
-
function toAssets(shares, { totalAssets, totalSupply,
|
|
13
|
-
return
|
|
12
|
+
function toAssets(shares, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Down") {
|
|
13
|
+
return index_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
|
|
14
14
|
}
|
|
15
15
|
VaultUtils.toAssets = toAssets;
|
|
16
|
-
function toShares(assets, { totalAssets, totalSupply,
|
|
17
|
-
return
|
|
16
|
+
function toShares(assets, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Up") {
|
|
17
|
+
return index_js_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
|
|
18
18
|
}
|
|
19
19
|
VaultUtils.toShares = toShares;
|
|
20
20
|
})(VaultUtils || (exports.VaultUtils = VaultUtils = {}));
|
package/lib/vault/index.d.ts
CHANGED
|
@@ -1,6 +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 "./
|
|
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/lib/vault/index.js
CHANGED
|
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./VaultUtils"), exports);
|
|
18
|
-
__exportStar(require("./VaultConfig"), exports);
|
|
19
|
-
__exportStar(require("./VaultMarketAllocation"), exports);
|
|
20
|
-
__exportStar(require("./VaultMarketConfig"), exports);
|
|
21
|
-
__exportStar(require("./VaultMarketPublicAllocatorConfig"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./VaultUtils.js"), exports);
|
|
18
|
+
__exportStar(require("./VaultConfig.js"), exports);
|
|
19
|
+
__exportStar(require("./VaultMarketAllocation.js"), exports);
|
|
20
|
+
__exportStar(require("./VaultMarketConfig.js"), exports);
|
|
21
|
+
__exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
|
|
22
|
+
__exportStar(require("./VaultUser.js"), exports);
|
|
23
|
+
__exportStar(require("./Vault.js"), exports);
|