@morpho-org/blue-sdk 5.23.1 → 5.23.3
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 +11 -2
- package/lib/cjs/addresses.d.ts +184 -0
- package/lib/cjs/addresses.js +102 -0
- package/lib/cjs/chain.d.ts +37 -1
- package/lib/cjs/chain.js +24 -0
- package/lib/cjs/errors.js +2 -0
- package/lib/cjs/holding/index.d.ts +1 -1
- package/lib/cjs/holding/index.js +1 -1
- package/lib/cjs/index.d.ts +6 -6
- package/lib/cjs/index.js +6 -6
- package/lib/cjs/market/Market.js +15 -0
- package/lib/cjs/market/MarketParams.d.ts +1 -1
- package/lib/cjs/market/MarketParams.js +1 -1
- package/lib/cjs/market/MarketUtils.d.ts +26 -2
- package/lib/cjs/market/MarketUtils.js +49 -6
- package/lib/cjs/market/index.d.ts +2 -2
- package/lib/cjs/market/index.js +2 -2
- package/lib/cjs/math/AdaptiveCurveIrmLib.js +8 -0
- package/lib/cjs/math/MathLib.js +14 -0
- package/lib/cjs/math/SharesMath.js +2 -0
- package/lib/cjs/math/index.d.ts +1 -1
- package/lib/cjs/math/index.js +1 -1
- package/lib/cjs/position/Position.js +9 -0
- package/lib/cjs/position/PreLiquidationPosition.d.ts +1 -0
- package/lib/cjs/position/PreLiquidationPosition.js +8 -0
- package/lib/cjs/preLiquidation.js +1 -0
- package/lib/cjs/token/ConstantWrappedToken.js +5 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/cjs/token/WrappedToken.js +4 -0
- package/lib/cjs/token/index.d.ts +3 -3
- package/lib/cjs/token/index.js +3 -3
- package/lib/cjs/vault/Vault.js +1 -0
- package/lib/cjs/vault/VaultUtils.js +8 -2
- package/lib/cjs/vault/index.d.ts +2 -2
- package/lib/cjs/vault/index.js +2 -2
- package/lib/cjs/vault/v2/VaultV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +1 -1
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +1 -1
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +1 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +1 -0
- package/lib/esm/addresses.d.ts +184 -0
- package/lib/esm/addresses.js +102 -0
- package/lib/esm/chain.d.ts +37 -1
- package/lib/esm/chain.js +24 -0
- package/lib/esm/errors.js +2 -0
- package/lib/esm/holding/index.d.ts +1 -1
- package/lib/esm/holding/index.js +1 -1
- package/lib/esm/index.d.ts +6 -6
- package/lib/esm/index.js +6 -6
- package/lib/esm/market/Market.js +15 -0
- package/lib/esm/market/MarketParams.d.ts +1 -1
- package/lib/esm/market/MarketParams.js +1 -1
- package/lib/esm/market/MarketUtils.d.ts +26 -2
- package/lib/esm/market/MarketUtils.js +48 -5
- package/lib/esm/market/index.d.ts +2 -2
- package/lib/esm/market/index.js +2 -2
- package/lib/esm/math/AdaptiveCurveIrmLib.js +8 -0
- package/lib/esm/math/MathLib.js +14 -0
- package/lib/esm/math/SharesMath.js +2 -0
- package/lib/esm/math/index.d.ts +1 -1
- package/lib/esm/math/index.js +1 -1
- package/lib/esm/position/Position.js +9 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +1 -0
- package/lib/esm/position/PreLiquidationPosition.js +8 -0
- package/lib/esm/preLiquidation.js +1 -0
- package/lib/esm/token/ConstantWrappedToken.js +5 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/esm/token/WrappedToken.js +4 -0
- package/lib/esm/token/index.d.ts +3 -3
- package/lib/esm/token/index.js +3 -3
- package/lib/esm/vault/Vault.js +1 -0
- package/lib/esm/vault/VaultUtils.js +8 -2
- package/lib/esm/vault/index.d.ts +2 -2
- package/lib/esm/vault/index.js +2 -2
- package/lib/esm/vault/v2/VaultV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +1 -1
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +1 -1
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +1 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +1 -0
- package/package.json +6 -6
- package/src/index.ts +6 -6
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MarketParams = exports.marketParamsAbi = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
|
-
const errors_js_1 = require("../errors.js");
|
|
6
5
|
const viem_1 = require("viem");
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
7
|
const MarketUtils_js_1 = require("./MarketUtils.js");
|
|
8
8
|
exports.marketParamsAbi = {
|
|
9
9
|
type: "tuple",
|
|
@@ -34,11 +34,35 @@ export declare namespace MarketUtils {
|
|
|
34
34
|
/**
|
|
35
35
|
* Returns the interest accrued on both sides of the given market
|
|
36
36
|
* as well as the supply shares minted to the fee recipient.
|
|
37
|
+
*
|
|
38
|
+
* Fee shares are converted from the fee amount against post-interest supply assets minus the fee amount,
|
|
39
|
+
* matching Morpho Blue's onchain accrual.
|
|
40
|
+
*
|
|
37
41
|
* @param borrowRate The average borrow rate since the last market update (scaled by WAD).
|
|
38
|
-
* @param market The market
|
|
42
|
+
* @param market.totalSupplyAssets The market's total supplied assets before accrual.
|
|
43
|
+
* @param market.totalBorrowAssets The market's total borrowed assets before accrual.
|
|
44
|
+
* @param market.totalSupplyShares The market's total supply shares before fee shares are minted.
|
|
45
|
+
* @param market.fee The market fee percentage, scaled by WAD.
|
|
39
46
|
* @param elapsed The time elapsed since the last market update (in seconds).
|
|
47
|
+
* @returns The accrued interest and the supply shares minted to the fee recipient.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
51
|
+
*
|
|
52
|
+
* const { interest, feeShares } = MarketUtils.getAccruedInterest(
|
|
53
|
+
* 5_0000000000000000n,
|
|
54
|
+
* {
|
|
55
|
+
* totalSupplyAssets: 1_000_000n * MathLib.WAD,
|
|
56
|
+
* totalBorrowAssets: 800_000n * MathLib.WAD,
|
|
57
|
+
* totalSupplyShares: 1_100_000n * MathLib.WAD,
|
|
58
|
+
* fee: 10_0000000000000000n,
|
|
59
|
+
* },
|
|
60
|
+
* 1n,
|
|
61
|
+
* );
|
|
62
|
+
* // { interest, feeShares } satisfies { interest: bigint; feeShares: bigint }
|
|
63
|
+
* ```
|
|
40
64
|
*/
|
|
41
|
-
function getAccruedInterest(borrowRate: BigIntish,
|
|
65
|
+
function getAccruedInterest(borrowRate: BigIntish, market: {
|
|
42
66
|
totalSupplyAssets: BigIntish;
|
|
43
67
|
totalBorrowAssets: BigIntish;
|
|
44
68
|
totalSupplyShares: BigIntish;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MarketUtils = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
5
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const constants_js_1 = require("../constants.js");
|
|
8
8
|
const index_js_1 = require("../math/index.js");
|
|
@@ -16,7 +16,7 @@ var MarketUtils;
|
|
|
16
16
|
* @param market The market params.
|
|
17
17
|
*/
|
|
18
18
|
function getMarketId(market) {
|
|
19
|
-
return `0x${(0,
|
|
19
|
+
return `0x${(0, utils_js_1.bytesToHex)((0, sha3_js_1.keccak_256)((0, utils_js_1.hexToBytes)(`${market.loanToken.substring(2).toLowerCase().padStart(64, "0") +
|
|
20
20
|
market.collateralToken
|
|
21
21
|
.substring(2)
|
|
22
22
|
.toLowerCase()
|
|
@@ -62,15 +62,41 @@ var MarketUtils;
|
|
|
62
62
|
/**
|
|
63
63
|
* Returns the interest accrued on both sides of the given market
|
|
64
64
|
* as well as the supply shares minted to the fee recipient.
|
|
65
|
+
*
|
|
66
|
+
* Fee shares are converted from the fee amount against post-interest supply assets minus the fee amount,
|
|
67
|
+
* matching Morpho Blue's onchain accrual.
|
|
68
|
+
*
|
|
65
69
|
* @param borrowRate The average borrow rate since the last market update (scaled by WAD).
|
|
66
|
-
* @param market The market
|
|
70
|
+
* @param market.totalSupplyAssets The market's total supplied assets before accrual.
|
|
71
|
+
* @param market.totalBorrowAssets The market's total borrowed assets before accrual.
|
|
72
|
+
* @param market.totalSupplyShares The market's total supply shares before fee shares are minted.
|
|
73
|
+
* @param market.fee The market fee percentage, scaled by WAD.
|
|
67
74
|
* @param elapsed The time elapsed since the last market update (in seconds).
|
|
75
|
+
* @returns The accrued interest and the supply shares minted to the fee recipient.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
79
|
+
*
|
|
80
|
+
* const { interest, feeShares } = MarketUtils.getAccruedInterest(
|
|
81
|
+
* 5_0000000000000000n,
|
|
82
|
+
* {
|
|
83
|
+
* totalSupplyAssets: 1_000_000n * MathLib.WAD,
|
|
84
|
+
* totalBorrowAssets: 800_000n * MathLib.WAD,
|
|
85
|
+
* totalSupplyShares: 1_100_000n * MathLib.WAD,
|
|
86
|
+
* fee: 10_0000000000000000n,
|
|
87
|
+
* },
|
|
88
|
+
* 1n,
|
|
89
|
+
* );
|
|
90
|
+
* // { interest, feeShares } satisfies { interest: bigint; feeShares: bigint }
|
|
91
|
+
* ```
|
|
68
92
|
*/
|
|
69
|
-
|
|
93
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
94
|
+
function getAccruedInterest(borrowRate, market, elapsed = 0n) {
|
|
95
|
+
const { totalSupplyAssets, totalBorrowAssets, totalSupplyShares, fee } = market;
|
|
70
96
|
const interest = index_js_1.MathLib.wMulDown(totalBorrowAssets, index_js_1.MathLib.wTaylorCompounded(borrowRate, elapsed));
|
|
71
97
|
const feeAmount = index_js_1.MathLib.wMulDown(interest, fee);
|
|
72
98
|
const feeShares = toSupplyShares(feeAmount, {
|
|
73
|
-
totalSupplyAssets: BigInt(totalSupplyAssets) - feeAmount,
|
|
99
|
+
totalSupplyAssets: BigInt(totalSupplyAssets) + interest - feeAmount,
|
|
74
100
|
totalSupplyShares,
|
|
75
101
|
}, "Down");
|
|
76
102
|
return { interest, feeShares };
|
|
@@ -82,6 +108,7 @@ var MarketUtils;
|
|
|
82
108
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
83
109
|
*/
|
|
84
110
|
function getSupplyToUtilization(market, utilization) {
|
|
111
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
85
112
|
utilization = BigInt(utilization);
|
|
86
113
|
if (utilization === 0n) {
|
|
87
114
|
if (getUtilization(market) === 0n)
|
|
@@ -97,6 +124,7 @@ var MarketUtils;
|
|
|
97
124
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
98
125
|
*/
|
|
99
126
|
function getWithdrawToUtilization({ totalSupplyAssets, totalBorrowAssets, }, utilization) {
|
|
127
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
100
128
|
utilization = BigInt(utilization);
|
|
101
129
|
totalSupplyAssets = BigInt(totalSupplyAssets);
|
|
102
130
|
totalBorrowAssets = BigInt(totalBorrowAssets);
|
|
@@ -145,6 +173,7 @@ var MarketUtils;
|
|
|
145
173
|
* Return `undefined` iff the market's price is undefined.
|
|
146
174
|
* To calculate the amount of loan assets that can be borrowed, use `getMaxBorrowableAssets`.
|
|
147
175
|
*/
|
|
176
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
148
177
|
function getMaxBorrowAssets(collateral, market, { lltv }) {
|
|
149
178
|
const collateralValue = getCollateralValue(collateral, market);
|
|
150
179
|
if (collateralValue == null)
|
|
@@ -156,6 +185,7 @@ var MarketUtils;
|
|
|
156
185
|
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
|
|
157
186
|
* Return `undefined` iff the market's price is undefined.
|
|
158
187
|
*/
|
|
188
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
159
189
|
function getMaxBorrowableAssets({ collateral, borrowShares, }, market, marketParams) {
|
|
160
190
|
const maxBorrowAssets = getMaxBorrowAssets(collateral, market, marketParams);
|
|
161
191
|
if (maxBorrowAssets == null)
|
|
@@ -167,6 +197,7 @@ var MarketUtils;
|
|
|
167
197
|
* Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares.
|
|
168
198
|
* Return `undefined` iff the market's price is undefined.
|
|
169
199
|
*/
|
|
200
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
170
201
|
function getLiquidationSeizedAssets(repaidShares, market, config) {
|
|
171
202
|
if (market.price == null)
|
|
172
203
|
return;
|
|
@@ -180,6 +211,7 @@ var MarketUtils;
|
|
|
180
211
|
* Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral.
|
|
181
212
|
* Return `undefined` iff the market's price is undefined.
|
|
182
213
|
*/
|
|
214
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
183
215
|
function getLiquidationRepaidShares(seizedAssets, market, config) {
|
|
184
216
|
if (market.price == null)
|
|
185
217
|
return;
|
|
@@ -190,6 +222,7 @@ var MarketUtils;
|
|
|
190
222
|
* Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position.
|
|
191
223
|
* Return `undefined` iff the market's price is undefined.
|
|
192
224
|
*/
|
|
225
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
193
226
|
function getSeizableCollateral(position, market, config) {
|
|
194
227
|
if (market.price == null)
|
|
195
228
|
return; // Must be checked before calling `isHealthy`.
|
|
@@ -203,6 +236,7 @@ var MarketUtils;
|
|
|
203
236
|
* Returns the amount of collateral that can be withdrawn given a certain borrow position.
|
|
204
237
|
* Return `undefined` iff the market's price is undefined.
|
|
205
238
|
*/
|
|
239
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
206
240
|
function getWithdrawableCollateral({ collateral, borrowShares, }, market, { lltv }) {
|
|
207
241
|
if (market.price == null)
|
|
208
242
|
return;
|
|
@@ -217,6 +251,7 @@ var MarketUtils;
|
|
|
217
251
|
* Return `undefined` iff the market's price is undefined.
|
|
218
252
|
* @param position The borrow position to check.
|
|
219
253
|
*/
|
|
254
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
220
255
|
function isHealthy({ collateral, borrowShares, }, market, marketParams) {
|
|
221
256
|
const maxBorrowAssets = getMaxBorrowAssets(collateral, market, marketParams);
|
|
222
257
|
if (maxBorrowAssets == null)
|
|
@@ -229,6 +264,7 @@ var MarketUtils;
|
|
|
229
264
|
* that set the user's position to be liquidatable.
|
|
230
265
|
* Returns null if the position is not a borrow.
|
|
231
266
|
*/
|
|
267
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
232
268
|
function getLiquidationPrice({ collateral, borrowShares, }, market, marketParams) {
|
|
233
269
|
borrowShares = BigInt(borrowShares);
|
|
234
270
|
market.totalBorrowShares = BigInt(market.totalBorrowShares);
|
|
@@ -247,6 +283,7 @@ var MarketUtils;
|
|
|
247
283
|
* Returns `undefined` iff the market's price is undefined.
|
|
248
284
|
* Returns null if the position is not a borrow.
|
|
249
285
|
*/
|
|
286
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
250
287
|
function getPriceVariationToLiquidationPrice(position, market, marketParams) {
|
|
251
288
|
if (market.price == null)
|
|
252
289
|
return;
|
|
@@ -264,6 +301,7 @@ var MarketUtils;
|
|
|
264
301
|
* If the debt is 0, health factor is `MaxUint256`.
|
|
265
302
|
* Returns `undefined` iff the market's price is undefined.
|
|
266
303
|
*/
|
|
304
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
267
305
|
function getHealthFactor({ collateral, borrowShares, }, market, marketParams) {
|
|
268
306
|
const borrowAssets = toBorrowAssets(borrowShares, market);
|
|
269
307
|
if (borrowAssets === 0n)
|
|
@@ -296,6 +334,7 @@ var MarketUtils;
|
|
|
296
334
|
* Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
|
|
297
335
|
* Returns `undefined` iff the market's price is undefined.
|
|
298
336
|
*/
|
|
337
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
299
338
|
function getBorrowCapacityUsage(position, market, marketParams) {
|
|
300
339
|
const hf = getHealthFactor(position, market, marketParams);
|
|
301
340
|
if (hf === undefined)
|
|
@@ -307,18 +346,22 @@ var MarketUtils;
|
|
|
307
346
|
return index_js_1.MathLib.wDivUp(index_js_1.MathLib.WAD, hf);
|
|
308
347
|
}
|
|
309
348
|
MarketUtils.getBorrowCapacityUsage = getBorrowCapacityUsage;
|
|
349
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
310
350
|
function toSupplyAssets(shares, market, rounding = "Down") {
|
|
311
351
|
return index_js_1.SharesMath.toAssets(shares, market.totalSupplyAssets, market.totalSupplyShares, rounding);
|
|
312
352
|
}
|
|
313
353
|
MarketUtils.toSupplyAssets = toSupplyAssets;
|
|
354
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
314
355
|
function toSupplyShares(assets, market, rounding = "Up") {
|
|
315
356
|
return index_js_1.SharesMath.toShares(assets, market.totalSupplyAssets, market.totalSupplyShares, rounding);
|
|
316
357
|
}
|
|
317
358
|
MarketUtils.toSupplyShares = toSupplyShares;
|
|
359
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
318
360
|
function toBorrowAssets(shares, market, rounding = "Up") {
|
|
319
361
|
return index_js_1.SharesMath.toAssets(shares, market.totalBorrowAssets, market.totalBorrowShares, rounding);
|
|
320
362
|
}
|
|
321
363
|
MarketUtils.toBorrowAssets = toBorrowAssets;
|
|
364
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
322
365
|
function toBorrowShares(assets, market, rounding = "Down") {
|
|
323
366
|
return index_js_1.SharesMath.toShares(assets, market.totalBorrowAssets, market.totalBorrowShares, rounding);
|
|
324
367
|
}
|
package/lib/cjs/market/index.js
CHANGED
|
@@ -14,6 +14,6 @@ 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("./MarketUtils.js"), exports);
|
|
18
|
-
__exportStar(require("./MarketParams.js"), exports);
|
|
19
17
|
__exportStar(require("./Market.js"), exports);
|
|
18
|
+
__exportStar(require("./MarketParams.js"), exports);
|
|
19
|
+
__exportStar(require("./MarketUtils.js"), exports);
|
|
@@ -36,6 +36,7 @@ var AdaptiveCurveIrmLib;
|
|
|
36
36
|
* @param x
|
|
37
37
|
*/
|
|
38
38
|
function wExp(x) {
|
|
39
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
39
40
|
x = BigInt(x);
|
|
40
41
|
// If x < ln(1e-18) then exp(x) < 1e-18 so it is rounded to zero.
|
|
41
42
|
if (x < AdaptiveCurveIrmLib.LN_WEI_INT)
|
|
@@ -56,9 +57,13 @@ var AdaptiveCurveIrmLib;
|
|
|
56
57
|
return expR >> -q;
|
|
57
58
|
}
|
|
58
59
|
AdaptiveCurveIrmLib.wExp = wExp;
|
|
60
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
59
61
|
function getBorrowRate(startUtilization, startRateAtTarget, elapsed) {
|
|
62
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
60
63
|
startUtilization = BigInt(startUtilization);
|
|
64
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
61
65
|
startRateAtTarget = BigInt(startRateAtTarget);
|
|
66
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
62
67
|
elapsed = BigInt(elapsed);
|
|
63
68
|
const errNormFactor = startUtilization > AdaptiveCurveIrmLib.TARGET_UTILIZATION
|
|
64
69
|
? MathLib_js_1.MathLib.WAD - AdaptiveCurveIrmLib.TARGET_UTILIZATION
|
|
@@ -83,6 +88,7 @@ var AdaptiveCurveIrmLib;
|
|
|
83
88
|
}
|
|
84
89
|
else {
|
|
85
90
|
// Non negative because MIN_RATE_AT_TARGET > 0.
|
|
91
|
+
// biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
|
|
86
92
|
const _newRateAtTarget = (linearAdaptation) => MathLib_js_1.MathLib.min(MathLib_js_1.MathLib.max(MathLib_js_1.MathLib.wMulDown(startRateAtTarget, wExp(linearAdaptation)), AdaptiveCurveIrmLib.MIN_RATE_AT_TARGET), AdaptiveCurveIrmLib.MAX_RATE_AT_TARGET);
|
|
87
93
|
// Formula of the average rate that should be returned to Morpho Blue:
|
|
88
94
|
// avg = 1/T * ∫_0^T curve(startRateAtTarget*exp(speed*x), err) dx
|
|
@@ -119,7 +125,9 @@ var AdaptiveCurveIrmLib;
|
|
|
119
125
|
}
|
|
120
126
|
AdaptiveCurveIrmLib.getBorrowRate = getBorrowRate;
|
|
121
127
|
function getUtilizationAtBorrowRate(borrowRate, rateAtTarget) {
|
|
128
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
122
129
|
borrowRate = BigInt(borrowRate);
|
|
130
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
123
131
|
rateAtTarget = BigInt(rateAtTarget);
|
|
124
132
|
if (borrowRate >= rateAtTarget) {
|
|
125
133
|
const maxBorrowRate = MathLib_js_1.MathLib.wMulDown(rateAtTarget, AdaptiveCurveIrmLib.CURVE_STEEPNESS);
|
package/lib/cjs/math/MathLib.js
CHANGED
|
@@ -24,6 +24,7 @@ var MathLib;
|
|
|
24
24
|
* @param a The number
|
|
25
25
|
*/
|
|
26
26
|
function abs(a) {
|
|
27
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
27
28
|
a = BigInt(a);
|
|
28
29
|
return a >= 0 ? a : -a;
|
|
29
30
|
}
|
|
@@ -52,7 +53,9 @@ var MathLib;
|
|
|
52
53
|
* @param y The second number
|
|
53
54
|
*/
|
|
54
55
|
function zeroFloorSub(x, y) {
|
|
56
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
55
57
|
x = BigInt(x);
|
|
58
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
56
59
|
y = BigInt(y);
|
|
57
60
|
return x <= y ? 0n : x - y;
|
|
58
61
|
}
|
|
@@ -80,6 +83,7 @@ var MathLib;
|
|
|
80
83
|
* @param x The first number
|
|
81
84
|
* @param y The second number
|
|
82
85
|
*/
|
|
86
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
83
87
|
function wMul(x, y, rounding) {
|
|
84
88
|
return MathLib.mulDiv(x, y, MathLib.WAD, rounding);
|
|
85
89
|
}
|
|
@@ -107,6 +111,7 @@ var MathLib;
|
|
|
107
111
|
* @param x The first number
|
|
108
112
|
* @param y The second number
|
|
109
113
|
*/
|
|
114
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
110
115
|
function wDiv(x, y, rounding) {
|
|
111
116
|
return MathLib.mulDiv(x, MathLib.WAD, y, rounding);
|
|
112
117
|
}
|
|
@@ -117,9 +122,13 @@ var MathLib;
|
|
|
117
122
|
* @param y The second number
|
|
118
123
|
* @param denominator The denominator
|
|
119
124
|
*/
|
|
125
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
120
126
|
function mulDivDown(x, y, denominator) {
|
|
127
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
121
128
|
x = BigInt(x);
|
|
129
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
122
130
|
y = BigInt(y);
|
|
131
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
123
132
|
denominator = BigInt(denominator);
|
|
124
133
|
if (denominator === 0n)
|
|
125
134
|
throw Error("MathLib: DIVISION_BY_ZERO");
|
|
@@ -132,9 +141,13 @@ var MathLib;
|
|
|
132
141
|
* @param y The second number
|
|
133
142
|
* @param denominator The denominator
|
|
134
143
|
*/
|
|
144
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
135
145
|
function mulDivUp(x, y, denominator) {
|
|
146
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
136
147
|
x = BigInt(x);
|
|
148
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
137
149
|
y = BigInt(y);
|
|
150
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
138
151
|
denominator = BigInt(denominator);
|
|
139
152
|
if (denominator === 0n)
|
|
140
153
|
throw Error("MathLib: DIVISION_BY_ZERO");
|
|
@@ -142,6 +155,7 @@ var MathLib;
|
|
|
142
155
|
return (x * y) / denominator + roundup;
|
|
143
156
|
}
|
|
144
157
|
MathLib.mulDivUp = mulDivUp;
|
|
158
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
145
159
|
function mulDiv(x, y, denominator, rounding) {
|
|
146
160
|
return MathLib[`mulDiv${rounding}`](x, y, denominator);
|
|
147
161
|
}
|
|
@@ -10,10 +10,12 @@ var SharesMath;
|
|
|
10
10
|
(function (SharesMath) {
|
|
11
11
|
SharesMath.VIRTUAL_SHARES = 1000000n;
|
|
12
12
|
SharesMath.VIRTUAL_ASSETS = 1n;
|
|
13
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
13
14
|
function toAssets(shares, totalAssets, totalShares, rounding) {
|
|
14
15
|
return MathLib_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, rounding);
|
|
15
16
|
}
|
|
16
17
|
SharesMath.toAssets = toAssets;
|
|
18
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
17
19
|
function toShares(assets, totalAssets, totalShares, rounding) {
|
|
18
20
|
return MathLib_js_1.MathLib.mulDiv(assets, BigInt(totalShares) + SharesMath.VIRTUAL_SHARES, BigInt(totalAssets) + SharesMath.VIRTUAL_ASSETS, rounding);
|
|
19
21
|
}
|
package/lib/cjs/math/index.d.ts
CHANGED
package/lib/cjs/math/index.js
CHANGED
|
@@ -14,6 +14,6 @@ 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("./AdaptiveCurveIrmLib.js"), exports);
|
|
17
18
|
__exportStar(require("./MathLib.js"), exports);
|
|
18
19
|
__exportStar(require("./SharesMath.js"), exports);
|
|
19
|
-
__exportStar(require("./AdaptiveCurveIrmLib.js"), exports);
|
|
@@ -162,15 +162,19 @@ class AccrualPosition extends Position {
|
|
|
162
162
|
accrueInterest(timestamp) {
|
|
163
163
|
return new AccrualPosition(this, this._market.accrueInterest(timestamp));
|
|
164
164
|
}
|
|
165
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
165
166
|
supply(assets, shares, timestamp) {
|
|
166
167
|
let { _market: market } = this;
|
|
168
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
167
169
|
({ market, assets, shares } = market.supply(assets, shares, timestamp));
|
|
168
170
|
const position = new AccrualPosition(this, market);
|
|
169
171
|
position.supplyShares += shares;
|
|
170
172
|
return { position, assets, shares };
|
|
171
173
|
}
|
|
174
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
172
175
|
withdraw(assets, shares, timestamp) {
|
|
173
176
|
let { _market: market } = this;
|
|
177
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
174
178
|
({ market, assets, shares } = market.withdraw(assets, shares, timestamp));
|
|
175
179
|
const position = new AccrualPosition(this, market);
|
|
176
180
|
position.supplyShares -= shares;
|
|
@@ -193,10 +197,12 @@ class AccrualPosition extends Position {
|
|
|
193
197
|
throw new errors_js_1.BlueErrors.InsufficientCollateral(position.user, position.marketId);
|
|
194
198
|
return position;
|
|
195
199
|
}
|
|
200
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
196
201
|
borrow(assets, shares, timestamp) {
|
|
197
202
|
let { _market: market } = this;
|
|
198
203
|
if (market.price == null)
|
|
199
204
|
throw new errors_js_1.BlueErrors.UnknownOraclePrice(market.id);
|
|
205
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
200
206
|
({ market, assets, shares } = market.borrow(assets, shares, timestamp));
|
|
201
207
|
const position = new AccrualPosition(this, market);
|
|
202
208
|
position.borrowShares += shares;
|
|
@@ -204,8 +210,10 @@ class AccrualPosition extends Position {
|
|
|
204
210
|
throw new errors_js_1.BlueErrors.InsufficientCollateral(this.user, this.marketId);
|
|
205
211
|
return { position, assets, shares };
|
|
206
212
|
}
|
|
213
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
207
214
|
repay(assets, shares, timestamp) {
|
|
208
215
|
let { _market: market } = this;
|
|
216
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
209
217
|
({ market, assets, shares } = market.repay(assets, shares, timestamp));
|
|
210
218
|
const position = new AccrualPosition(this, market);
|
|
211
219
|
position.borrowShares -= shares;
|
|
@@ -222,6 +230,7 @@ class AccrualPosition extends Position {
|
|
|
222
230
|
getRepayCapacityLimit(loanTokenBalance) {
|
|
223
231
|
return this._market.getRepayCapacityLimit(this.borrowShares, loanTokenBalance);
|
|
224
232
|
}
|
|
233
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
225
234
|
getMaxCapacities(loanTokenBalance, collateralTokenBalance, options) {
|
|
226
235
|
return {
|
|
227
236
|
supply: {
|
|
@@ -44,6 +44,7 @@ export declare class PreLiquidationPosition extends AccrualPosition implements I
|
|
|
44
44
|
constructor({ preLiquidationParams, preLiquidation, preLiquidationOraclePrice, ...position }: IPreLiquidationPosition, market: IMarket);
|
|
45
45
|
get market(): Market;
|
|
46
46
|
protected get _lltv(): bigint;
|
|
47
|
+
accrueInterest(timestamp?: BigIntish): PreLiquidationPosition;
|
|
47
48
|
/**
|
|
48
49
|
* @inheritdoc `undefined` if the pre-liquidation's oracle reverts.
|
|
49
50
|
* `undefined` if it may be liquidatable on Morpho.
|
|
@@ -56,6 +56,14 @@ class PreLiquidationPosition extends Position_js_1.AccrualPosition {
|
|
|
56
56
|
get _lltv() {
|
|
57
57
|
return this._baseMarket.params.lltv;
|
|
58
58
|
}
|
|
59
|
+
accrueInterest(timestamp) {
|
|
60
|
+
return new PreLiquidationPosition({
|
|
61
|
+
...this,
|
|
62
|
+
preLiquidationParams: this.preLiquidationParams,
|
|
63
|
+
preLiquidation: this.preLiquidation,
|
|
64
|
+
preLiquidationOraclePrice: this.preLiquidationOraclePrice,
|
|
65
|
+
}, this._baseMarket.accrueInterest(timestamp));
|
|
66
|
+
}
|
|
59
67
|
/**
|
|
60
68
|
* @inheritdoc `undefined` if the pre-liquidation's oracle reverts.
|
|
61
69
|
* `undefined` if it may be liquidatable on Morpho.
|
|
@@ -86,6 +86,7 @@ exports.defaultPreLiquidationParamsRegistry = new Map([
|
|
|
86
86
|
],
|
|
87
87
|
]);
|
|
88
88
|
const getDefaultPreLiquidationParams = (lltv) => {
|
|
89
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
89
90
|
lltv = BigInt(lltv);
|
|
90
91
|
const defaultParams = exports.defaultPreLiquidationParamsRegistry.get(lltv);
|
|
91
92
|
if (defaultParams == null)
|
|
@@ -5,22 +5,27 @@ const index_js_1 = require("../math/index.js");
|
|
|
5
5
|
const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
6
6
|
class ConstantWrappedToken extends WrappedToken_js_1.WrappedToken {
|
|
7
7
|
underlyingDecimals;
|
|
8
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
8
9
|
constructor(token, underlying, underlyingDecimals = 0) {
|
|
9
10
|
super(token, underlying);
|
|
10
11
|
this.underlyingDecimals = BigInt(underlyingDecimals);
|
|
11
12
|
}
|
|
13
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
12
14
|
toWrappedExactAmountIn(unwrappedAmount, _slippage, rounding = "Down") {
|
|
13
15
|
return super.toWrappedExactAmountIn(unwrappedAmount, 0n, rounding);
|
|
14
16
|
}
|
|
15
17
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
18
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
16
19
|
toWrappedExactAmountOut(wrappedAmount, _slippage, rounding = "Up") {
|
|
17
20
|
return super.toWrappedExactAmountOut(wrappedAmount, 0n, rounding);
|
|
18
21
|
}
|
|
19
22
|
/** The expected amount when unwrapping `wrappedAmount` */
|
|
23
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
20
24
|
toUnwrappedExactAmountIn(wrappedAmount, _slippage, rounding = "Down") {
|
|
21
25
|
return super.toUnwrappedExactAmountIn(wrappedAmount, 0n, rounding);
|
|
22
26
|
}
|
|
23
27
|
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
28
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
24
29
|
toUnwrappedExactAmountOut(unwrappedAmount, _slippage, rounding = "Up") {
|
|
25
30
|
return super.toUnwrappedExactAmountOut(unwrappedAmount, 0n, rounding);
|
|
26
31
|
}
|
|
@@ -6,6 +6,7 @@ const WrappedToken_js_1 = require("./WrappedToken.js");
|
|
|
6
6
|
class ExchangeRateWrappedToken extends WrappedToken_js_1.WrappedToken {
|
|
7
7
|
underlying;
|
|
8
8
|
wrappedTokenExchangeRate;
|
|
9
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
9
10
|
constructor(token, underlying, wrappedTokenExchangeRate) {
|
|
10
11
|
super(token, underlying);
|
|
11
12
|
this.underlying = underlying;
|
|
@@ -10,21 +10,25 @@ class WrappedToken extends Token_js_1.Token {
|
|
|
10
10
|
this.underlying = underlying;
|
|
11
11
|
}
|
|
12
12
|
/** The expected amount when wrapping `unwrappedAmount` */
|
|
13
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
13
14
|
toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
|
|
14
15
|
const wrappedAmount = this._wrap(unwrappedAmount, rounding);
|
|
15
16
|
return index_js_1.MathLib.wMulDown(wrappedAmount, index_js_1.MathLib.WAD - slippage);
|
|
16
17
|
}
|
|
17
18
|
/** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
|
|
19
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
18
20
|
toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
|
|
19
21
|
const wAmountTarget = index_js_1.MathLib.wDiv(wrappedAmount, index_js_1.MathLib.WAD - slippage, rounding);
|
|
20
22
|
return this._unwrap(wAmountTarget, rounding);
|
|
21
23
|
}
|
|
22
24
|
/** The expected amount when unwrapping `wrappedAmount` */
|
|
25
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
23
26
|
toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
|
|
24
27
|
const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
|
|
25
28
|
return index_js_1.MathLib.wMulUp(unwrappedAmount, index_js_1.MathLib.WAD - slippage);
|
|
26
29
|
}
|
|
27
30
|
/** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
|
|
31
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
28
32
|
toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
|
|
29
33
|
const unwrappedAmountToTarget = index_js_1.MathLib.wDiv(unwrappedAmount, index_js_1.MathLib.WAD - slippage, rounding);
|
|
30
34
|
return this._wrap(unwrappedAmountToTarget, rounding);
|
package/lib/cjs/token/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./Token.js";
|
|
2
|
-
export * from "./WrappedToken.js";
|
|
3
1
|
export * from "./ConstantWrappedToken.js";
|
|
2
|
+
export * from "./Eip5267Domain.js";
|
|
4
3
|
export * from "./ExchangeRateWrappedToken.js";
|
|
4
|
+
export * from "./Token.js";
|
|
5
5
|
export * from "./VaultToken.js";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./WrappedToken.js";
|
package/lib/cjs/token/index.js
CHANGED
|
@@ -14,9 +14,9 @@ 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("./Token.js"), exports);
|
|
18
|
-
__exportStar(require("./WrappedToken.js"), exports);
|
|
19
17
|
__exportStar(require("./ConstantWrappedToken.js"), exports);
|
|
18
|
+
__exportStar(require("./Eip5267Domain.js"), exports);
|
|
20
19
|
__exportStar(require("./ExchangeRateWrappedToken.js"), exports);
|
|
20
|
+
__exportStar(require("./Token.js"), exports);
|
|
21
21
|
__exportStar(require("./VaultToken.js"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./WrappedToken.js"), exports);
|
package/lib/cjs/vault/Vault.js
CHANGED
|
@@ -230,6 +230,7 @@ class AccrualVault extends Vault {
|
|
|
230
230
|
* @param assets The maximum amount of assets to deposit.
|
|
231
231
|
*/
|
|
232
232
|
maxDeposit(assets) {
|
|
233
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
233
234
|
assets = BigInt(assets);
|
|
234
235
|
const suppliable = this.allocations
|
|
235
236
|
.values()
|
|
@@ -9,11 +9,17 @@ var VaultUtils;
|
|
|
9
9
|
return index_js_1.MathLib.zeroFloorSub(18n, decimals);
|
|
10
10
|
}
|
|
11
11
|
VaultUtils.decimalsOffset = decimalsOffset;
|
|
12
|
-
|
|
12
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
13
|
+
function toAssets(shares, { totalAssets, totalSupply,
|
|
14
|
+
// biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
|
|
15
|
+
decimalsOffset, }, rounding = "Down") {
|
|
13
16
|
return index_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
|
|
14
17
|
}
|
|
15
18
|
VaultUtils.toAssets = toAssets;
|
|
16
|
-
|
|
19
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
20
|
+
function toShares(assets, { totalAssets, totalSupply,
|
|
21
|
+
// biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
|
|
22
|
+
decimalsOffset, }, rounding = "Up") {
|
|
17
23
|
return index_js_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
|
|
18
24
|
}
|
|
19
25
|
VaultUtils.toShares = toShares;
|
package/lib/cjs/vault/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Vault.js";
|
|
2
2
|
export * from "./VaultConfig.js";
|
|
3
3
|
export * from "./VaultMarketAllocation.js";
|
|
4
4
|
export * from "./VaultMarketConfig.js";
|
|
5
5
|
export * from "./VaultMarketPublicAllocatorConfig.js";
|
|
6
6
|
export * from "./VaultUser.js";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./VaultUtils.js";
|
|
8
8
|
export * from "./v2/index.js";
|
package/lib/cjs/vault/index.js
CHANGED
|
@@ -14,11 +14,11 @@ 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("./
|
|
17
|
+
__exportStar(require("./Vault.js"), exports);
|
|
18
18
|
__exportStar(require("./VaultConfig.js"), exports);
|
|
19
19
|
__exportStar(require("./VaultMarketAllocation.js"), exports);
|
|
20
20
|
__exportStar(require("./VaultMarketConfig.js"), exports);
|
|
21
21
|
__exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
|
|
22
22
|
__exportStar(require("./VaultUser.js"), exports);
|
|
23
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./VaultUtils.js"), exports);
|
|
24
24
|
__exportStar(require("./v2/index.js"), exports);
|
|
@@ -59,6 +59,7 @@ class AccrualVaultV2 extends VaultV2 {
|
|
|
59
59
|
accrualAdapters;
|
|
60
60
|
assetBalance;
|
|
61
61
|
forceDeallocatePenalties;
|
|
62
|
+
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
62
63
|
constructor(vault, accrualLiquidityAdapter, accrualAdapters, assetBalance,
|
|
63
64
|
/**
|
|
64
65
|
* The force deallocate penalty for each adapter, keyed by adapter address.
|
|
@@ -130,6 +131,7 @@ class AccrualVaultV2 extends VaultV2 {
|
|
|
130
131
|
*/
|
|
131
132
|
accrueInterest(timestamp) {
|
|
132
133
|
const vault = new AccrualVaultV2(this, this.accrualLiquidityAdapter, this.accrualAdapters, this.assetBalance, this.forceDeallocatePenalties);
|
|
134
|
+
// biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
|
|
133
135
|
timestamp = BigInt(timestamp);
|
|
134
136
|
const elapsed = timestamp - this.lastUpdate;
|
|
135
137
|
if (elapsed < 0n)
|