@morpho-org/blue-sdk 4.10.0-next.0 → 4.10.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/lib/addresses.d.ts +4 -6
- package/lib/addresses.js +2 -2
- package/lib/errors.d.ts +0 -4
- package/lib/errors.js +1 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/market/Market.js +3 -3
- package/lib/market/MarketUtils.d.ts +7 -1
- package/lib/market/MarketUtils.js +13 -1
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +67 -0
- package/package.json +3 -3
- package/lib/vault-v2/VaultV2.d.ts +0 -56
- package/lib/vault-v2/VaultV2.js +0 -90
- package/lib/vault-v2/VaultV2Adapter.d.ts +0 -18
- package/lib/vault-v2/VaultV2Adapter.js +0 -16
- package/lib/vault-v2/VaultV2MorphoVaultV1Adapter.d.ts +0 -21
- package/lib/vault-v2/VaultV2MorphoVaultV1Adapter.js +0 -28
- package/lib/vault-v2/index.d.ts +0 -3
- package/lib/vault-v2/index.js +0 -19
package/lib/addresses.d.ts
CHANGED
|
@@ -63,8 +63,6 @@ export interface ChainAddresses {
|
|
|
63
63
|
usdc?: Address;
|
|
64
64
|
stEth?: Address;
|
|
65
65
|
wstEth?: Address;
|
|
66
|
-
vaultV2Factory?: Address;
|
|
67
|
-
vaultV2MorphoVaultV1AdapterFactory?: Address;
|
|
68
66
|
}
|
|
69
67
|
declare const _addressesRegistry: {
|
|
70
68
|
readonly 1: {
|
|
@@ -176,8 +174,6 @@ declare const _addressesRegistry: {
|
|
|
176
174
|
readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
177
175
|
readonly verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b";
|
|
178
176
|
readonly testUsdc: "0xBC77067f829979812d795d516E523C4033b66409";
|
|
179
|
-
readonly vaultV2Factory: "0xC2F730a67AE81a7D2C17268A9652338449BF264b";
|
|
180
|
-
readonly vaultV2MorphoVaultV1AdapterFactory: "0xF123759C14B824e5670258e67C9FcEa7Ff368b50";
|
|
181
177
|
};
|
|
182
178
|
readonly 137: {
|
|
183
179
|
readonly morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67";
|
|
@@ -288,6 +284,7 @@ declare const _addressesRegistry: {
|
|
|
288
284
|
};
|
|
289
285
|
readonly 130: {
|
|
290
286
|
readonly morpho: "0x8f5ae9CddB9f68de460C77730b018Ae7E04a140A";
|
|
287
|
+
readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
291
288
|
readonly bundler3: {
|
|
292
289
|
readonly bundler3: "0x7DD85759182495AF7F6757DA75036d24A9B58bc3";
|
|
293
290
|
readonly generalAdapter1: "0xC11329d19C2275c9E759867e879ECFcEeD7e30A0";
|
|
@@ -589,6 +586,7 @@ declare const _deployments: {
|
|
|
589
586
|
};
|
|
590
587
|
readonly 130: {
|
|
591
588
|
readonly morpho: 9139027n;
|
|
589
|
+
readonly permit2: 0n;
|
|
592
590
|
readonly bundler3: {
|
|
593
591
|
readonly bundler3: 9381237n;
|
|
594
592
|
readonly generalAdapter1: 9381237n;
|
|
@@ -871,8 +869,6 @@ export declare let addressesRegistry: {
|
|
|
871
869
|
readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
872
870
|
readonly verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b";
|
|
873
871
|
readonly testUsdc: "0xBC77067f829979812d795d516E523C4033b66409";
|
|
874
|
-
readonly vaultV2Factory: "0xC2F730a67AE81a7D2C17268A9652338449BF264b";
|
|
875
|
-
readonly vaultV2MorphoVaultV1AdapterFactory: "0xF123759C14B824e5670258e67C9FcEa7Ff368b50";
|
|
876
872
|
};
|
|
877
873
|
readonly 137: {
|
|
878
874
|
readonly morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67";
|
|
@@ -983,6 +979,7 @@ export declare let addressesRegistry: {
|
|
|
983
979
|
};
|
|
984
980
|
readonly 130: {
|
|
985
981
|
readonly morpho: "0x8f5ae9CddB9f68de460C77730b018Ae7E04a140A";
|
|
982
|
+
readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
986
983
|
readonly bundler3: {
|
|
987
984
|
readonly bundler3: "0x7DD85759182495AF7F6757DA75036d24A9B58bc3";
|
|
988
985
|
readonly generalAdapter1: "0xC11329d19C2275c9E759867e879ECFcEeD7e30A0";
|
|
@@ -1282,6 +1279,7 @@ export declare let deployments: {
|
|
|
1282
1279
|
};
|
|
1283
1280
|
readonly 130: {
|
|
1284
1281
|
readonly morpho: 9139027n;
|
|
1282
|
+
readonly permit2: 0n;
|
|
1285
1283
|
readonly bundler3: {
|
|
1286
1284
|
readonly bundler3: 9381237n;
|
|
1287
1285
|
readonly generalAdapter1: 9381237n;
|
package/lib/addresses.js
CHANGED
|
@@ -133,8 +133,6 @@ const _addressesRegistry = {
|
|
|
133
133
|
usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
134
134
|
verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b",
|
|
135
135
|
testUsdc: "0xBC77067f829979812d795d516E523C4033b66409",
|
|
136
|
-
vaultV2Factory: "0xC2F730a67AE81a7D2C17268A9652338449BF264b",
|
|
137
|
-
vaultV2MorphoVaultV1AdapterFactory: "0xF123759C14B824e5670258e67C9FcEa7Ff368b50",
|
|
138
136
|
},
|
|
139
137
|
[chain_js_1.ChainId.PolygonMainnet]: {
|
|
140
138
|
morpho: "0x1bF0c2541F820E775182832f06c0B7Fc27A25f67",
|
|
@@ -250,6 +248,7 @@ const _addressesRegistry = {
|
|
|
250
248
|
},
|
|
251
249
|
[chain_js_1.ChainId.Unichain]: {
|
|
252
250
|
morpho: "0x8f5ae9CddB9f68de460C77730b018Ae7E04a140A",
|
|
251
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
253
252
|
bundler3: {
|
|
254
253
|
bundler3: "0x7DD85759182495AF7F6757DA75036d24A9B58bc3",
|
|
255
254
|
generalAdapter1: "0xC11329d19C2275c9E759867e879ECFcEeD7e30A0",
|
|
@@ -552,6 +551,7 @@ const _deployments = {
|
|
|
552
551
|
},
|
|
553
552
|
[chain_js_1.ChainId.Unichain]: {
|
|
554
553
|
morpho: 9139027n,
|
|
554
|
+
permit2: 0n,
|
|
555
555
|
bundler3: {
|
|
556
556
|
bundler3: 9381237n,
|
|
557
557
|
generalAdapter1: 9381237n,
|
package/lib/errors.d.ts
CHANGED
|
@@ -25,10 +25,6 @@ export declare class UnsupportedPreLiquidationParamsError extends Error {
|
|
|
25
25
|
readonly lltv: bigint;
|
|
26
26
|
constructor(lltv: bigint);
|
|
27
27
|
}
|
|
28
|
-
export declare class UnsupportedVaultV2AdapterError extends Error {
|
|
29
|
-
readonly address: Address;
|
|
30
|
-
constructor(address: Address);
|
|
31
|
-
}
|
|
32
28
|
export declare namespace BlueErrors {
|
|
33
29
|
class AlreadySet extends Error {
|
|
34
30
|
readonly name: string;
|
package/lib/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlueErrors = exports.
|
|
3
|
+
exports.BlueErrors = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
|
|
4
4
|
exports._try = _try;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
class UnknownDataError extends Error {
|
|
@@ -54,14 +54,6 @@ class UnsupportedPreLiquidationParamsError extends Error {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
exports.UnsupportedPreLiquidationParamsError = UnsupportedPreLiquidationParamsError;
|
|
57
|
-
class UnsupportedVaultV2AdapterError extends Error {
|
|
58
|
-
address;
|
|
59
|
-
constructor(address) {
|
|
60
|
-
super(`vault v2 adapter "${address}" is not supported`);
|
|
61
|
-
this.address = address;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.UnsupportedVaultV2AdapterError = UnsupportedVaultV2AdapterError;
|
|
65
57
|
var BlueErrors;
|
|
66
58
|
(function (BlueErrors) {
|
|
67
59
|
class AlreadySet extends Error {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -27,4 +27,4 @@ __exportStar(require("./holding/index.js"), exports);
|
|
|
27
27
|
__exportStar(require("./position/index.js"), exports);
|
|
28
28
|
__exportStar(require("./vault/index.js"), exports);
|
|
29
29
|
__exportStar(require("./preLiquidation.js"), exports);
|
|
30
|
-
__exportStar(require("./
|
|
30
|
+
__exportStar(require("./utils.js"), exports);
|
package/lib/market/Market.js
CHANGED
|
@@ -99,7 +99,7 @@ class Market {
|
|
|
99
99
|
get apyAtTarget() {
|
|
100
100
|
if (this.rateAtTarget == null)
|
|
101
101
|
return;
|
|
102
|
-
return MarketUtils_js_1.MarketUtils.
|
|
102
|
+
return MarketUtils_js_1.MarketUtils.rateToApy(this.rateAtTarget);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Returns the rate at which interest accrued for suppliers of this market,
|
|
@@ -218,7 +218,7 @@ class Market {
|
|
|
218
218
|
*/
|
|
219
219
|
getBorrowApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
220
220
|
const borrowRate = this.getEndBorrowRate(timestamp);
|
|
221
|
-
return MarketUtils_js_1.MarketUtils.
|
|
221
|
+
return MarketUtils_js_1.MarketUtils.rateToApy(borrowRate);
|
|
222
222
|
}
|
|
223
223
|
/**
|
|
224
224
|
* The market's instantaneous supply-side Annual Percentage Yield (APY) at the given timestamp,
|
|
@@ -240,7 +240,7 @@ class Market {
|
|
|
240
240
|
*/
|
|
241
241
|
getAvgBorrowApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
242
242
|
const borrowRate = this.getAvgBorrowRate(timestamp);
|
|
243
|
-
return MarketUtils_js_1.MarketUtils.
|
|
243
|
+
return MarketUtils_js_1.MarketUtils.rateToApy(borrowRate);
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
246
|
* The market's experienced supply-side Annual Percentage Yield (APY),
|
|
@@ -38,11 +38,17 @@ export declare namespace MarketUtils {
|
|
|
38
38
|
}): bigint;
|
|
39
39
|
/**
|
|
40
40
|
* Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
|
|
41
|
-
* If the period is 1 year, the compounded rate correspond to the Annual Percentage Yield (APY)
|
|
42
41
|
* @param rate The per-second rate to compound (scaled by WAD).
|
|
43
42
|
* @param period The period to compound the rate over (in seconds). Defaults to 1 year.
|
|
43
|
+
* @deprecated The compounded rate is inaccurate if rate * period >> 0. If interested in the APY, use `rateToApy` instead.
|
|
44
44
|
*/
|
|
45
45
|
function compoundRate(rate: BigIntish, period?: BigIntish): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the per-second rate continuously compounded over a year (scaled by WAD),
|
|
48
|
+
* as calculated in Morpho Blue assuming the market is frequently accrued onchain.
|
|
49
|
+
* @param rate The per-second rate to compound annually (scaled by WAD).
|
|
50
|
+
*/
|
|
51
|
+
function rateToApy(rate: BigIntish): bigint;
|
|
46
52
|
/**
|
|
47
53
|
* Returns the interest accrued on both sides of the given market
|
|
48
54
|
* as well as the supply shares minted to the fee recipient.
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MarketUtils = void 0;
|
|
4
4
|
const sha3_1 = require("@noble/hashes/sha3");
|
|
5
5
|
const utils_1 = require("@noble/hashes/utils");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const constants_js_1 = require("../constants.js");
|
|
7
8
|
const index_js_1 = require("../math/index.js");
|
|
9
|
+
const utils_js_1 = require("../utils.js");
|
|
8
10
|
/**
|
|
9
11
|
* Namespace of utility functions to ease market-related calculations.
|
|
10
12
|
*/
|
|
@@ -63,14 +65,24 @@ var MarketUtils;
|
|
|
63
65
|
MarketUtils.getSupplyRate = getSupplyRate;
|
|
64
66
|
/**
|
|
65
67
|
* Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
|
|
66
|
-
* If the period is 1 year, the compounded rate correspond to the Annual Percentage Yield (APY)
|
|
67
68
|
* @param rate The per-second rate to compound (scaled by WAD).
|
|
68
69
|
* @param period The period to compound the rate over (in seconds). Defaults to 1 year.
|
|
70
|
+
* @deprecated The compounded rate is inaccurate if rate * period >> 0. If interested in the APY, use `rateToApy` instead.
|
|
69
71
|
*/
|
|
70
72
|
function compoundRate(rate, period = constants_js_1.SECONDS_PER_YEAR) {
|
|
71
73
|
return index_js_1.MathLib.wTaylorCompounded(rate, period);
|
|
72
74
|
}
|
|
73
75
|
MarketUtils.compoundRate = compoundRate;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the per-second rate continuously compounded over a year (scaled by WAD),
|
|
78
|
+
* as calculated in Morpho Blue assuming the market is frequently accrued onchain.
|
|
79
|
+
* @param rate The per-second rate to compound annually (scaled by WAD).
|
|
80
|
+
*/
|
|
81
|
+
// TODO: return a Number for APYs.
|
|
82
|
+
function rateToApy(rate) {
|
|
83
|
+
return (0, utils_js_1.safeParseNumber)(Math.expm1(+(0, viem_1.formatEther)(BigInt(rate) * constants_js_1.SECONDS_PER_YEAR)));
|
|
84
|
+
}
|
|
85
|
+
MarketUtils.rateToApy = rateToApy;
|
|
74
86
|
/**
|
|
75
87
|
* Returns the interest accrued on both sides of the given market
|
|
76
88
|
* as well as the supply shares minted to the fee recipient.
|
package/lib/utils.d.ts
ADDED
package/lib/utils.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeParseUnits = exports.safeParseNumber = void 0;
|
|
4
|
+
// Alternative to Number.toFixed that doesn't use scientific notation for excessively small or large numbers.
|
|
5
|
+
const toFixed = (x, decimals) => new Intl.NumberFormat("en-US", {
|
|
6
|
+
style: "decimal",
|
|
7
|
+
useGrouping: false,
|
|
8
|
+
maximumFractionDigits: decimals,
|
|
9
|
+
minimumFractionDigits: decimals,
|
|
10
|
+
}).format(x);
|
|
11
|
+
const safeParseNumber = (value, decimals = 18) => (0, exports.safeParseUnits)(toFixed(value, decimals), decimals);
|
|
12
|
+
exports.safeParseNumber = safeParseNumber;
|
|
13
|
+
const safeParseUnits = (strValue, decimals = 18) => {
|
|
14
|
+
if (!/[-+]?[0-9]*\.?[0-9]+/.test(strValue))
|
|
15
|
+
throw Error(`invalid number: ${strValue}`);
|
|
16
|
+
let [whole, dec = ""] = strValue.split(".");
|
|
17
|
+
dec = dec.slice(0, decimals);
|
|
18
|
+
return parseUnits([whole || "0", dec].filter((v) => v.length > 0).join("."), decimals);
|
|
19
|
+
};
|
|
20
|
+
exports.safeParseUnits = safeParseUnits;
|
|
21
|
+
/**
|
|
22
|
+
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
23
|
+
*
|
|
24
|
+
* - Docs: https://viem.sh/docs/utilities/parseUnits
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* import { parseUnits } from 'viem'
|
|
28
|
+
*
|
|
29
|
+
* parseUnits('420', 9)
|
|
30
|
+
* // 420000000000n
|
|
31
|
+
*/
|
|
32
|
+
// TODO: get rid of this copy.
|
|
33
|
+
function parseUnits(value, decimals) {
|
|
34
|
+
let [integer, fraction = "0"] = value.split(".");
|
|
35
|
+
const negative = integer.startsWith("-");
|
|
36
|
+
if (negative)
|
|
37
|
+
integer = integer.slice(1);
|
|
38
|
+
// trim trailing zeros.
|
|
39
|
+
fraction = fraction.replace(/(0+)$/, "");
|
|
40
|
+
// round off if the fraction is larger than the number of decimals.
|
|
41
|
+
if (decimals === 0) {
|
|
42
|
+
if (Math.round(Number(`.${fraction}`)) === 1)
|
|
43
|
+
integer = `${BigInt(integer) + 1n}`;
|
|
44
|
+
fraction = "";
|
|
45
|
+
}
|
|
46
|
+
else if (fraction.length > decimals) {
|
|
47
|
+
const [left, unit, right] = [
|
|
48
|
+
fraction.slice(0, decimals - 1),
|
|
49
|
+
fraction.slice(decimals - 1, decimals),
|
|
50
|
+
fraction.slice(decimals),
|
|
51
|
+
];
|
|
52
|
+
const rounded = Math.round(Number(`${unit}.${right}`));
|
|
53
|
+
if (rounded > 9)
|
|
54
|
+
fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, "0");
|
|
55
|
+
else
|
|
56
|
+
fraction = `${left}${rounded}`;
|
|
57
|
+
if (fraction.length > decimals) {
|
|
58
|
+
fraction = fraction.slice(1);
|
|
59
|
+
integer = `${BigInt(integer) + 1n}`;
|
|
60
|
+
}
|
|
61
|
+
fraction = fraction.slice(0, decimals);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
fraction = fraction.padEnd(decimals, "0");
|
|
65
|
+
}
|
|
66
|
+
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
|
67
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
3
|
"description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
|
|
4
|
-
"version": "4.10.0
|
|
4
|
+
"version": "4.10.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
|
-
"viem": "^2.
|
|
32
|
+
"viem": "^2.23.0",
|
|
33
33
|
"vitest": "^3.0.5",
|
|
34
34
|
"@morpho-org/morpho-ts": "^2.4.1",
|
|
35
|
-
"@morpho-org/test": "^2.
|
|
35
|
+
"@morpho-org/test": "^2.4.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"prepublish": "$npm_execpath build",
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import { type RoundingDirection } from "../math";
|
|
3
|
-
import { type IToken, WrappedToken } from "../token";
|
|
4
|
-
import type { BigIntish } from "../types";
|
|
5
|
-
import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
|
|
6
|
-
export interface IVaultV2 extends IToken {
|
|
7
|
-
asset: Address;
|
|
8
|
-
totalSupply: bigint;
|
|
9
|
-
totalAssets: bigint;
|
|
10
|
-
performanceFee: bigint;
|
|
11
|
-
managementFee: bigint;
|
|
12
|
-
virtualShares: bigint;
|
|
13
|
-
lastUpdate: bigint;
|
|
14
|
-
adapters: Address[];
|
|
15
|
-
maxRate: bigint;
|
|
16
|
-
liquidityAdapter: Address;
|
|
17
|
-
performanceFeeRecipient: Address;
|
|
18
|
-
managementFeeRecipient: Address;
|
|
19
|
-
}
|
|
20
|
-
export declare class VaultV2 extends WrappedToken implements IVaultV2 {
|
|
21
|
-
readonly asset: Address;
|
|
22
|
-
/**
|
|
23
|
-
* The ERC4626 vault's total supply of shares.
|
|
24
|
-
*/
|
|
25
|
-
totalSupply: bigint;
|
|
26
|
-
/**
|
|
27
|
-
* The ERC4626 vault's total assets, without accrued interest
|
|
28
|
-
*/
|
|
29
|
-
totalAssets: bigint;
|
|
30
|
-
virtualShares: bigint;
|
|
31
|
-
lastUpdate: bigint;
|
|
32
|
-
adapters: Address[];
|
|
33
|
-
maxRate: bigint;
|
|
34
|
-
performanceFee: bigint;
|
|
35
|
-
managementFee: bigint;
|
|
36
|
-
liquidityAdapter: Address;
|
|
37
|
-
performanceFeeRecipient: Address;
|
|
38
|
-
managementFeeRecipient: Address;
|
|
39
|
-
constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
|
|
40
|
-
toAssets(shares: bigint): bigint;
|
|
41
|
-
toShares(assets: bigint): bigint;
|
|
42
|
-
protected _wrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
43
|
-
protected _unwrap(amount: bigint, rounding: RoundingDirection): bigint;
|
|
44
|
-
}
|
|
45
|
-
export interface IAccrualVaultV2 extends Omit<IVaultV2, "adapters"> {
|
|
46
|
-
}
|
|
47
|
-
export declare class AccrualVaultV2 extends VaultV2 implements IAccrualVaultV2 {
|
|
48
|
-
readonly accrualAdapters: IAccrualVaultV2Adapter[];
|
|
49
|
-
readonly assetBalance: bigint;
|
|
50
|
-
constructor(vault: IAccrualVaultV2, accrualAdapters: IAccrualVaultV2Adapter[], assetBalance: bigint);
|
|
51
|
-
accrueInterest(timestamp: BigIntish): {
|
|
52
|
-
vault: AccrualVaultV2;
|
|
53
|
-
performanceFeeShares: bigint;
|
|
54
|
-
managementFeeShares: bigint;
|
|
55
|
-
};
|
|
56
|
-
}
|
package/lib/vault-v2/VaultV2.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccrualVaultV2 = exports.VaultV2 = void 0;
|
|
4
|
-
const math_1 = require("../math");
|
|
5
|
-
const token_1 = require("../token");
|
|
6
|
-
class VaultV2 extends token_1.WrappedToken {
|
|
7
|
-
asset;
|
|
8
|
-
/**
|
|
9
|
-
* The ERC4626 vault's total supply of shares.
|
|
10
|
-
*/
|
|
11
|
-
totalSupply;
|
|
12
|
-
/**
|
|
13
|
-
* The ERC4626 vault's total assets, without accrued interest
|
|
14
|
-
*/
|
|
15
|
-
totalAssets;
|
|
16
|
-
virtualShares;
|
|
17
|
-
lastUpdate;
|
|
18
|
-
adapters;
|
|
19
|
-
maxRate;
|
|
20
|
-
performanceFee;
|
|
21
|
-
managementFee;
|
|
22
|
-
liquidityAdapter;
|
|
23
|
-
performanceFeeRecipient;
|
|
24
|
-
managementFeeRecipient;
|
|
25
|
-
constructor({ totalSupply, asset, totalAssets, virtualShares, lastUpdate, adapters, maxRate, performanceFee, managementFee, liquidityAdapter, performanceFeeRecipient, managementFeeRecipient, ...config }) {
|
|
26
|
-
super(config, asset);
|
|
27
|
-
this.totalSupply = totalSupply;
|
|
28
|
-
this.totalAssets = totalAssets;
|
|
29
|
-
this.virtualShares = virtualShares;
|
|
30
|
-
this.lastUpdate = lastUpdate;
|
|
31
|
-
this.asset = asset;
|
|
32
|
-
this.maxRate = maxRate;
|
|
33
|
-
this.adapters = adapters;
|
|
34
|
-
this.performanceFee = performanceFee;
|
|
35
|
-
this.managementFee = managementFee;
|
|
36
|
-
this.liquidityAdapter = liquidityAdapter;
|
|
37
|
-
this.performanceFeeRecipient = performanceFeeRecipient;
|
|
38
|
-
this.managementFeeRecipient = managementFeeRecipient;
|
|
39
|
-
}
|
|
40
|
-
toAssets(shares) {
|
|
41
|
-
return this._unwrap(shares, "Down");
|
|
42
|
-
}
|
|
43
|
-
toShares(assets) {
|
|
44
|
-
return this._wrap(assets, "Down");
|
|
45
|
-
}
|
|
46
|
-
_wrap(amount, rounding) {
|
|
47
|
-
return math_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
|
|
48
|
-
}
|
|
49
|
-
_unwrap(amount, rounding) {
|
|
50
|
-
return math_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.VaultV2 = VaultV2;
|
|
54
|
-
class AccrualVaultV2 extends VaultV2 {
|
|
55
|
-
accrualAdapters;
|
|
56
|
-
assetBalance;
|
|
57
|
-
constructor(vault, accrualAdapters, assetBalance) {
|
|
58
|
-
super({ ...vault, adapters: accrualAdapters.map((a) => a.address) });
|
|
59
|
-
this.accrualAdapters = accrualAdapters;
|
|
60
|
-
this.assetBalance = assetBalance;
|
|
61
|
-
}
|
|
62
|
-
accrueInterest(timestamp) {
|
|
63
|
-
const vault = new AccrualVaultV2(this, this.accrualAdapters, this.assetBalance);
|
|
64
|
-
const elapsed = BigInt(timestamp) - vault.lastUpdate;
|
|
65
|
-
if (elapsed <= 0n)
|
|
66
|
-
return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
|
|
67
|
-
const realAssets = vault.accrualAdapters.reduce((curr, adapter) => curr + adapter.realAssets(timestamp), vault.assetBalance);
|
|
68
|
-
const maxTotalAssets = vault.totalAssets +
|
|
69
|
-
math_1.MathLib.wMulDown(vault.totalAssets * elapsed, vault.maxRate);
|
|
70
|
-
const newTotalAssets = math_1.MathLib.min(realAssets, maxTotalAssets);
|
|
71
|
-
const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault.totalAssets);
|
|
72
|
-
const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
|
|
73
|
-
? math_1.MathLib.wMulDown(interest, vault.performanceFee)
|
|
74
|
-
: 0n;
|
|
75
|
-
const managementFeeAssets = elapsed > 0n && vault.managementFee > 0n
|
|
76
|
-
? math_1.MathLib.wMulDown(newTotalAssets * elapsed, vault.managementFee)
|
|
77
|
-
: 0n;
|
|
78
|
-
const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
|
|
79
|
-
const performanceFeeShares = math_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
80
|
-
const managementFeeShares = math_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
81
|
-
vault.totalAssets = newTotalAssets;
|
|
82
|
-
if (performanceFeeShares)
|
|
83
|
-
vault.totalSupply += performanceFeeShares;
|
|
84
|
-
if (managementFeeShares)
|
|
85
|
-
vault.totalSupply += managementFeeShares;
|
|
86
|
-
vault.lastUpdate = BigInt(timestamp);
|
|
87
|
-
return { vault, performanceFeeShares, managementFeeShares };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
exports.AccrualVaultV2 = AccrualVaultV2;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Address, Hash } from "viem";
|
|
2
|
-
import type { BigIntish } from "../types";
|
|
3
|
-
export interface IVaultV2Adapter {
|
|
4
|
-
address: Address;
|
|
5
|
-
parentVault: Address;
|
|
6
|
-
adapterId: Hash;
|
|
7
|
-
skimRecipient: Address;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class VaultV2Adapter implements IVaultV2Adapter {
|
|
10
|
-
readonly address: Address;
|
|
11
|
-
readonly parentVault: Address;
|
|
12
|
-
readonly adapterId: Hash;
|
|
13
|
-
skimRecipient: Address;
|
|
14
|
-
constructor({ address, parentVault, adapterId, skimRecipient, }: IVaultV2Adapter);
|
|
15
|
-
}
|
|
16
|
-
export interface IAccrualVaultV2Adapter extends IVaultV2Adapter {
|
|
17
|
-
realAssets(timestamp: BigIntish): bigint;
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultV2Adapter = void 0;
|
|
4
|
-
class VaultV2Adapter {
|
|
5
|
-
address;
|
|
6
|
-
parentVault;
|
|
7
|
-
adapterId;
|
|
8
|
-
skimRecipient;
|
|
9
|
-
constructor({ address, parentVault, adapterId, skimRecipient, }) {
|
|
10
|
-
this.address = address;
|
|
11
|
-
this.parentVault = parentVault;
|
|
12
|
-
this.adapterId = adapterId;
|
|
13
|
-
this.skimRecipient = skimRecipient;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.VaultV2Adapter = VaultV2Adapter;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
3
|
-
export interface IVaultV2MorphoVaultV1Adapter extends IVaultV2Adapter {
|
|
4
|
-
morphoVaultV1: Address;
|
|
5
|
-
}
|
|
6
|
-
import type { BigIntish } from "../types";
|
|
7
|
-
import type { AccrualVault } from "../vault";
|
|
8
|
-
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
9
|
-
export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter {
|
|
10
|
-
readonly morphoVaultV1: Address;
|
|
11
|
-
constructor({ morphoVaultV1, ...vaultV2Adapter }: IVaultV2MorphoVaultV1Adapter);
|
|
12
|
-
ids(): `0x${string}`[];
|
|
13
|
-
}
|
|
14
|
-
export interface IAccrualVaultV2MorphoVaultV1Adapter extends IVaultV2MorphoVaultV1Adapter {
|
|
15
|
-
}
|
|
16
|
-
export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter implements IAccrualVaultV2MorphoVaultV1Adapter, IAccrualVaultV2Adapter {
|
|
17
|
-
vaultV1: AccrualVault;
|
|
18
|
-
shares: bigint;
|
|
19
|
-
constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, vaultV1: AccrualVault, shares: bigint);
|
|
20
|
-
realAssets(timestamp: BigIntish): bigint;
|
|
21
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AccrualVaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoVaultV1Adapter = void 0;
|
|
4
|
-
const VaultV2Adapter_1 = require("./VaultV2Adapter");
|
|
5
|
-
class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
6
|
-
morphoVaultV1;
|
|
7
|
-
constructor({ morphoVaultV1, ...vaultV2Adapter }) {
|
|
8
|
-
super(vaultV2Adapter);
|
|
9
|
-
this.morphoVaultV1 = morphoVaultV1;
|
|
10
|
-
}
|
|
11
|
-
ids() {
|
|
12
|
-
return [this.adapterId];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.VaultV2MorphoVaultV1Adapter = VaultV2MorphoVaultV1Adapter;
|
|
16
|
-
class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter {
|
|
17
|
-
vaultV1;
|
|
18
|
-
shares;
|
|
19
|
-
constructor(adapter, vaultV1, shares) {
|
|
20
|
-
super(adapter);
|
|
21
|
-
this.vaultV1 = vaultV1;
|
|
22
|
-
this.shares = shares;
|
|
23
|
-
}
|
|
24
|
-
realAssets(timestamp) {
|
|
25
|
-
return this.vaultV1.accrueInterest(timestamp).toAssets(this.shares);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.AccrualVaultV2MorphoVaultV1Adapter = AccrualVaultV2MorphoVaultV1Adapter;
|
package/lib/vault-v2/index.d.ts
DELETED
package/lib/vault-v2/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./VaultV2.js"), exports);
|
|
18
|
-
__exportStar(require("./VaultV2Adapter.js"), exports);
|
|
19
|
-
__exportStar(require("./VaultV2MorphoVaultV1Adapter.js"), exports);
|