@morpho-org/blue-sdk 5.16.0 → 5.17.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/cjs/package.json +1 -0
- package/lib/{position → cjs/position}/PreLiquidationPosition.d.ts +3 -3
- package/lib/{position → cjs/position}/PreLiquidationPosition.js +16 -16
- package/lib/{preLiquidation.d.ts → cjs/preLiquidation.d.ts} +1 -1
- package/lib/{preLiquidation.js → cjs/preLiquidation.js} +2 -2
- package/lib/{vault → cjs/vault}/index.d.ts +1 -1
- package/lib/{vault → cjs/vault}/index.js +1 -1
- package/lib/{vault → cjs/vault}/v2/VaultV2.d.ts +5 -5
- package/lib/{vault → cjs/vault}/v2/VaultV2.js +25 -25
- package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.d.ts +2 -2
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.d.ts +7 -7
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.js +9 -9
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.js +8 -8
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.js +2 -2
- package/lib/esm/addresses.d.ts +2231 -0
- package/lib/esm/addresses.js +1309 -0
- package/lib/esm/chain.d.ts +405 -0
- package/lib/esm/chain.js +276 -0
- package/lib/esm/constants.d.ts +20 -0
- package/lib/esm/constants.js +21 -0
- package/lib/esm/errors.d.ts +101 -0
- package/lib/esm/errors.js +192 -0
- package/lib/esm/holding/AssetBalances.d.ts +48 -0
- package/lib/esm/holding/AssetBalances.js +38 -0
- package/lib/esm/holding/Holding.d.ts +63 -0
- package/lib/esm/holding/Holding.js +63 -0
- package/lib/esm/holding/index.d.ts +2 -0
- package/lib/esm/holding/index.js +2 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/market/Market.d.ts +424 -0
- package/lib/esm/market/Market.js +576 -0
- package/lib/esm/market/MarketParams.d.ts +74 -0
- package/lib/esm/market/MarketParams.js +91 -0
- package/lib/esm/market/MarketUtils.d.ts +273 -0
- package/lib/esm/market/MarketUtils.js +323 -0
- package/lib/esm/market/index.d.ts +3 -0
- package/lib/esm/market/index.js +3 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +40 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.js +133 -0
- package/lib/esm/math/MathLib.d.ts +102 -0
- package/lib/esm/math/MathLib.js +168 -0
- package/lib/esm/math/SharesMath.d.ts +12 -0
- package/lib/esm/math/SharesMath.js +18 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/position/Position.d.ts +147 -0
- package/lib/esm/position/Position.js +237 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +60 -0
- package/lib/esm/position/PreLiquidationPosition.js +97 -0
- package/lib/esm/position/index.d.ts +2 -0
- package/lib/esm/position/index.js +2 -0
- package/lib/esm/preLiquidation.d.ts +15 -0
- package/lib/esm/preLiquidation.js +91 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +17 -0
- package/lib/esm/token/ConstantWrappedToken.js +30 -0
- package/lib/esm/token/Eip5267Domain.d.ts +55 -0
- package/lib/esm/token/Eip5267Domain.js +66 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +17 -0
- package/lib/esm/token/Token.d.ts +52 -0
- package/lib/esm/token/Token.js +62 -0
- package/lib/esm/token/VaultToken.d.ts +23 -0
- package/lib/esm/token/VaultToken.js +27 -0
- package/lib/esm/token/WrappedToken.d.ts +17 -0
- package/lib/esm/token/WrappedToken.js +29 -0
- package/lib/esm/token/index.d.ts +6 -0
- package/lib/esm/token/index.js +6 -0
- package/lib/esm/types.d.ts +26 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +20 -0
- package/lib/esm/user/User.js +19 -0
- package/lib/esm/user/index.d.ts +1 -0
- package/lib/esm/user/index.js +1 -0
- package/lib/esm/utils.d.ts +13 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/vault/Vault.d.ts +214 -0
- package/lib/esm/vault/Vault.js +289 -0
- package/lib/esm/vault/VaultConfig.d.ts +11 -0
- package/lib/esm/vault/VaultConfig.js +10 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/esm/vault/VaultMarketAllocation.js +27 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/esm/vault/VaultMarketConfig.js +39 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +24 -0
- package/lib/esm/vault/VaultUser.d.ts +26 -0
- package/lib/esm/vault/VaultUser.js +24 -0
- package/lib/esm/vault/VaultUtils.d.ts +16 -0
- package/lib/esm/vault/VaultUtils.js +17 -0
- package/lib/esm/vault/index.d.ts +8 -0
- package/lib/esm/vault/index.js +8 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +87 -0
- package/lib/esm/vault/v2/VaultV2.js +154 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +29 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +12 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +30 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +54 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +33 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +63 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +24 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +36 -0
- package/lib/esm/vault/v2/index.d.ts +5 -0
- package/lib/esm/vault/v2/index.js +5 -0
- package/package.json +16 -7
- package/src/index.ts +14 -0
- /package/lib/{addresses.d.ts → cjs/addresses.d.ts} +0 -0
- /package/lib/{addresses.js → cjs/addresses.js} +0 -0
- /package/lib/{chain.d.ts → cjs/chain.d.ts} +0 -0
- /package/lib/{chain.js → cjs/chain.js} +0 -0
- /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/lib/{constants.js → cjs/constants.js} +0 -0
- /package/lib/{errors.d.ts → cjs/errors.d.ts} +0 -0
- /package/lib/{errors.js → cjs/errors.js} +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.js +0 -0
- /package/lib/{holding → cjs/holding}/Holding.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/Holding.js +0 -0
- /package/lib/{holding → cjs/holding}/index.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/index.js +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → cjs/index.js} +0 -0
- /package/lib/{market → cjs/market}/Market.d.ts +0 -0
- /package/lib/{market → cjs/market}/Market.js +0 -0
- /package/lib/{market → cjs/market}/MarketParams.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketParams.js +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.js +0 -0
- /package/lib/{market → cjs/market}/index.d.ts +0 -0
- /package/lib/{market → cjs/market}/index.js +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.js +0 -0
- /package/lib/{math → cjs/math}/MathLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/MathLib.js +0 -0
- /package/lib/{math → cjs/math}/SharesMath.d.ts +0 -0
- /package/lib/{math → cjs/math}/SharesMath.js +0 -0
- /package/lib/{math → cjs/math}/index.d.ts +0 -0
- /package/lib/{math → cjs/math}/index.js +0 -0
- /package/lib/{position → cjs/position}/Position.d.ts +0 -0
- /package/lib/{position → cjs/position}/Position.js +0 -0
- /package/lib/{position → cjs/position}/index.d.ts +0 -0
- /package/lib/{position → cjs/position}/index.js +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.d.ts +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.js +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Token.d.ts +0 -0
- /package/lib/{token → cjs/token}/Token.js +0 -0
- /package/lib/{token → cjs/token}/VaultToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/VaultToken.js +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/index.d.ts +0 -0
- /package/lib/{token → cjs/token}/index.js +0 -0
- /package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/lib/{types.js → cjs/types.js} +0 -0
- /package/lib/{user → cjs/user}/User.d.ts +0 -0
- /package/lib/{user → cjs/user}/User.js +0 -0
- /package/lib/{user → cjs/user}/index.d.ts +0 -0
- /package/lib/{user → cjs/user}/index.js +0 -0
- /package/lib/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/lib/{utils.js → cjs/utils.js} +0 -0
- /package/lib/{vault → cjs/vault}/Vault.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/Vault.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import { type IMarket, Market } from "../market";
|
|
3
|
-
import type { BigIntish } from "../types";
|
|
4
|
-
import { AccrualPosition, type IAccrualPosition } from "./Position";
|
|
2
|
+
import { type IMarket, Market } from "../market/index.js";
|
|
3
|
+
import type { BigIntish } from "../types.js";
|
|
4
|
+
import { AccrualPosition, type IAccrualPosition } from "./Position.js";
|
|
5
5
|
export interface IPreLiquidationParams {
|
|
6
6
|
preLltv: BigIntish;
|
|
7
7
|
preLCF1: BigIntish;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PreLiquidationPosition = exports.PreLiquidationParams = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
5
|
+
const index_js_1 = require("../market/index.js");
|
|
6
|
+
const index_js_2 = require("../math/index.js");
|
|
7
|
+
const Position_js_1 = require("./Position.js");
|
|
8
8
|
class PreLiquidationParams {
|
|
9
9
|
preLltv;
|
|
10
10
|
preLCF1;
|
|
@@ -21,14 +21,14 @@ class PreLiquidationParams {
|
|
|
21
21
|
this.preLiquidationOracle = preLiquidationOracle;
|
|
22
22
|
}
|
|
23
23
|
getCloseFactor(quotient) {
|
|
24
|
-
return (this.preLCF1 +
|
|
24
|
+
return (this.preLCF1 + index_js_2.MathLib.wMulDown(quotient, this.preLCF2 - this.preLCF1));
|
|
25
25
|
}
|
|
26
26
|
getIncentiveFactor(quotient) {
|
|
27
|
-
return (this.preLIF1 +
|
|
27
|
+
return (this.preLIF1 + index_js_2.MathLib.wMulDown(quotient, this.preLIF2 - this.preLIF1));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.PreLiquidationParams = PreLiquidationParams;
|
|
31
|
-
class PreLiquidationPosition extends
|
|
31
|
+
class PreLiquidationPosition extends Position_js_1.AccrualPosition {
|
|
32
32
|
preLiquidationParams;
|
|
33
33
|
preLiquidation;
|
|
34
34
|
preLiquidationOraclePrice;
|
|
@@ -48,7 +48,7 @@ class PreLiquidationPosition extends Position_1.AccrualPosition {
|
|
|
48
48
|
this.preLiquidation = preLiquidation;
|
|
49
49
|
if (preLiquidationOraclePrice != null)
|
|
50
50
|
this.preLiquidationOraclePrice = BigInt(preLiquidationOraclePrice);
|
|
51
|
-
this._baseMarket = new
|
|
51
|
+
this._baseMarket = new index_js_1.Market(market);
|
|
52
52
|
}
|
|
53
53
|
get market() {
|
|
54
54
|
return this._baseMarket;
|
|
@@ -65,10 +65,10 @@ class PreLiquidationPosition extends Position_1.AccrualPosition {
|
|
|
65
65
|
if (collateralValue == null)
|
|
66
66
|
return;
|
|
67
67
|
const { borrowAssets } = this;
|
|
68
|
-
if (borrowAssets >
|
|
68
|
+
if (borrowAssets > index_js_2.MathLib.wMulDown(collateralValue, this._lltv))
|
|
69
69
|
return;
|
|
70
70
|
return (borrowAssets <=
|
|
71
|
-
|
|
71
|
+
index_js_2.MathLib.wMulDown(collateralValue, this.preLiquidationParams.preLltv));
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* @inheritdoc `undefined` if the pre-liquidation's oracle reverts.
|
|
@@ -79,8 +79,8 @@ class PreLiquidationPosition extends Position_1.AccrualPosition {
|
|
|
79
79
|
return;
|
|
80
80
|
const { borrowAssets } = this;
|
|
81
81
|
return (borrowAssets >
|
|
82
|
-
|
|
83
|
-
borrowAssets <=
|
|
82
|
+
index_js_2.MathLib.wMulDown(collateralValue, this.preLiquidationParams.preLltv) &&
|
|
83
|
+
borrowAssets <= index_js_2.MathLib.wMulDown(collateralValue, this._lltv));
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* @inheritdoc `undefined` if the pre-liquidation's oracle reverts.
|
|
@@ -93,10 +93,10 @@ class PreLiquidationPosition extends Position_1.AccrualPosition {
|
|
|
93
93
|
const { ltv } = this;
|
|
94
94
|
if (ltv == null)
|
|
95
95
|
return;
|
|
96
|
-
const quotient =
|
|
97
|
-
const repayableShares =
|
|
98
|
-
const repayableAssets =
|
|
99
|
-
return
|
|
96
|
+
const quotient = index_js_2.MathLib.wDivDown(ltv - this.preLiquidationParams.preLltv, this._lltv - this.preLiquidationParams.preLltv);
|
|
97
|
+
const repayableShares = index_js_2.MathLib.wMulDown(this.borrowShares, this.preLiquidationParams.getCloseFactor(quotient));
|
|
98
|
+
const repayableAssets = index_js_2.MathLib.wMulDown(index_js_2.SharesMath.toAssets(repayableShares, this._market.totalBorrowAssets, this._market.totalBorrowShares, "Down"), this.preLiquidationParams.getIncentiveFactor(quotient));
|
|
99
|
+
return index_js_2.MathLib.mulDivDown(repayableAssets, constants_js_1.ORACLE_PRICE_SCALE, this._market.price);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
exports.PreLiquidationPosition = PreLiquidationPosition;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDefaultPreLiquidationParams = exports.defaultPreLiquidationParamsRegistry = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
6
|
exports.defaultPreLiquidationParamsRegistry = new Map([
|
|
7
7
|
[
|
|
8
8
|
(0, viem_1.parseEther)("0.385"),
|
|
@@ -89,7 +89,7 @@ const getDefaultPreLiquidationParams = (lltv) => {
|
|
|
89
89
|
lltv = BigInt(lltv);
|
|
90
90
|
const defaultParams = exports.defaultPreLiquidationParamsRegistry.get(lltv);
|
|
91
91
|
if (defaultParams == null)
|
|
92
|
-
throw new
|
|
92
|
+
throw new errors_js_1.UnsupportedPreLiquidationParamsError(lltv);
|
|
93
93
|
return defaultParams;
|
|
94
94
|
};
|
|
95
95
|
exports.getDefaultPreLiquidationParams = getDefaultPreLiquidationParams;
|
|
@@ -21,4 +21,4 @@ __exportStar(require("./VaultMarketConfig.js"), exports);
|
|
|
21
21
|
__exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
|
|
22
22
|
__exportStar(require("./VaultUser.js"), exports);
|
|
23
23
|
__exportStar(require("./Vault.js"), exports);
|
|
24
|
-
__exportStar(require("./v2"), exports);
|
|
24
|
+
__exportStar(require("./v2/index.js"), exports);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Address, type Hash, type Hex } from "viem";
|
|
2
|
-
import { type RoundingDirection } from "../../math";
|
|
3
|
-
import { type IToken, WrappedToken } from "../../token";
|
|
4
|
-
import type { BigIntish } from "../../types";
|
|
5
|
-
import { type CapacityLimit } from "../../utils";
|
|
6
|
-
import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
|
|
2
|
+
import { type RoundingDirection } from "../../math/index.js";
|
|
3
|
+
import { type IToken, WrappedToken } from "../../token/index.js";
|
|
4
|
+
import type { BigIntish } from "../../types.js";
|
|
5
|
+
import { type CapacityLimit } from "../../utils.js";
|
|
6
|
+
import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter.js";
|
|
7
7
|
export interface IVaultV2Allocation {
|
|
8
8
|
id: Hash;
|
|
9
9
|
absoluteCap: bigint;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVaultV2 = exports.VaultV2 = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
class VaultV2 extends
|
|
5
|
+
const errors_js_1 = require("../../errors.js");
|
|
6
|
+
const index_js_1 = require("../../math/index.js");
|
|
7
|
+
const index_js_2 = require("../../token/index.js");
|
|
8
|
+
const utils_js_1 = require("../../utils.js");
|
|
9
|
+
class VaultV2 extends index_js_2.WrappedToken {
|
|
10
10
|
asset;
|
|
11
11
|
totalAssets;
|
|
12
12
|
_totalAssets;
|
|
@@ -47,10 +47,10 @@ class VaultV2 extends token_1.WrappedToken {
|
|
|
47
47
|
return this._wrap(assets, "Down");
|
|
48
48
|
}
|
|
49
49
|
_wrap(amount, rounding) {
|
|
50
|
-
return
|
|
50
|
+
return index_js_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
|
|
51
51
|
}
|
|
52
52
|
_unwrap(amount, rounding) {
|
|
53
|
-
return
|
|
53
|
+
return index_js_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
exports.VaultV2 = VaultV2;
|
|
@@ -70,29 +70,29 @@ class AccrualVaultV2 extends VaultV2 {
|
|
|
70
70
|
*/
|
|
71
71
|
maxDeposit(assets) {
|
|
72
72
|
if (this.liquidityAdapter === viem_1.zeroAddress)
|
|
73
|
-
return { value: BigInt(assets), limiter:
|
|
73
|
+
return { value: BigInt(assets), limiter: utils_js_1.CapacityLimitReason.balance };
|
|
74
74
|
let liquidityAdapterLimit;
|
|
75
75
|
if (this.accrualLiquidityAdapter != null)
|
|
76
76
|
liquidityAdapterLimit = this.accrualLiquidityAdapter.maxDeposit(this.liquidityData, assets);
|
|
77
77
|
if (this.liquidityAllocations == null || liquidityAdapterLimit == null)
|
|
78
|
-
throw new
|
|
78
|
+
throw new errors_js_1.VaultV2Errors.UnsupportedLiquidityAdapter(this.liquidityAdapter);
|
|
79
79
|
// At this stage: `liquidityAdapterLimit.value <= assets`
|
|
80
80
|
for (const { absoluteCap, relativeCap, allocation } of this
|
|
81
81
|
.liquidityAllocations) {
|
|
82
82
|
// `absoluteCap` can be set lower than `allocation`.
|
|
83
|
-
const absoluteMaxDeposit =
|
|
83
|
+
const absoluteMaxDeposit = index_js_1.MathLib.zeroFloorSub(absoluteCap, allocation);
|
|
84
84
|
if (liquidityAdapterLimit.value > absoluteMaxDeposit)
|
|
85
85
|
liquidityAdapterLimit = {
|
|
86
86
|
value: absoluteMaxDeposit,
|
|
87
|
-
limiter:
|
|
87
|
+
limiter: utils_js_1.CapacityLimitReason.vaultV2_absoluteCap,
|
|
88
88
|
};
|
|
89
|
-
if (relativeCap !==
|
|
89
|
+
if (relativeCap !== index_js_1.MathLib.WAD) {
|
|
90
90
|
// `relativeCap` can be set lower than `allocation / totalAssets`.
|
|
91
|
-
const relativeMaxDeposit =
|
|
91
|
+
const relativeMaxDeposit = index_js_1.MathLib.zeroFloorSub(index_js_1.MathLib.wMulDown(this.totalAssets, relativeCap), allocation);
|
|
92
92
|
if (liquidityAdapterLimit.value > relativeMaxDeposit)
|
|
93
93
|
liquidityAdapterLimit = {
|
|
94
94
|
value: relativeMaxDeposit,
|
|
95
|
-
limiter:
|
|
95
|
+
limiter: utils_js_1.CapacityLimitReason.vaultV2_relativeCap,
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -105,18 +105,18 @@ class AccrualVaultV2 extends VaultV2 {
|
|
|
105
105
|
maxWithdraw(shares) {
|
|
106
106
|
const assets = this.toAssets(shares);
|
|
107
107
|
if (this.liquidityAdapter === viem_1.zeroAddress)
|
|
108
|
-
return { value: BigInt(assets), limiter:
|
|
108
|
+
return { value: BigInt(assets), limiter: utils_js_1.CapacityLimitReason.balance };
|
|
109
109
|
let liquidity = this.assetBalance;
|
|
110
110
|
if (this.accrualLiquidityAdapter != null)
|
|
111
111
|
liquidity += this.accrualLiquidityAdapter.maxWithdraw(this.liquidityData).value;
|
|
112
112
|
if (assets > liquidity)
|
|
113
113
|
return {
|
|
114
114
|
value: liquidity,
|
|
115
|
-
limiter:
|
|
115
|
+
limiter: utils_js_1.CapacityLimitReason.liquidity,
|
|
116
116
|
};
|
|
117
117
|
return {
|
|
118
118
|
value: assets,
|
|
119
|
-
limiter:
|
|
119
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -128,24 +128,24 @@ class AccrualVaultV2 extends VaultV2 {
|
|
|
128
128
|
timestamp = BigInt(timestamp);
|
|
129
129
|
const elapsed = timestamp - this.lastUpdate;
|
|
130
130
|
if (elapsed < 0n)
|
|
131
|
-
throw new
|
|
131
|
+
throw new errors_js_1.VaultV2Errors.InvalidInterestAccrual(this.address, timestamp, this.lastUpdate);
|
|
132
132
|
// Corresponds to the `firstTotalAssets == 0` onchain check.
|
|
133
133
|
if (elapsed === 0n)
|
|
134
134
|
return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
|
|
135
135
|
const realAssets = vault.accrualAdapters.reduce((curr, adapter) => curr + adapter.realAssets(timestamp), vault.assetBalance);
|
|
136
136
|
const maxTotalAssets = vault._totalAssets +
|
|
137
|
-
|
|
138
|
-
const newTotalAssets =
|
|
139
|
-
const interest =
|
|
137
|
+
index_js_1.MathLib.wMulDown(vault._totalAssets * elapsed, vault.maxRate);
|
|
138
|
+
const newTotalAssets = index_js_1.MathLib.min(realAssets, maxTotalAssets);
|
|
139
|
+
const interest = index_js_1.MathLib.zeroFloorSub(newTotalAssets, vault._totalAssets);
|
|
140
140
|
const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
|
|
141
|
-
?
|
|
141
|
+
? index_js_1.MathLib.wMulDown(interest, vault.performanceFee)
|
|
142
142
|
: 0n;
|
|
143
143
|
const managementFeeAssets = elapsed > 0n && vault.managementFee > 0n
|
|
144
|
-
?
|
|
144
|
+
? index_js_1.MathLib.wMulDown(newTotalAssets * elapsed, vault.managementFee)
|
|
145
145
|
: 0n;
|
|
146
146
|
const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
|
|
147
|
-
const performanceFeeShares =
|
|
148
|
-
const managementFeeShares =
|
|
147
|
+
const performanceFeeShares = index_js_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
148
|
+
const managementFeeShares = index_js_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
149
149
|
vault.totalAssets = newTotalAssets;
|
|
150
150
|
vault._totalAssets = newTotalAssets;
|
|
151
151
|
if (performanceFeeShares)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address, Hash, Hex } from "viem";
|
|
2
|
-
import type { BigIntish } from "../../types";
|
|
3
|
-
import type { CapacityLimit } from "../../utils";
|
|
2
|
+
import type { BigIntish } from "../../types.js";
|
|
3
|
+
import type { CapacityLimit } from "../../utils.js";
|
|
4
4
|
export interface IVaultV2Adapter {
|
|
5
5
|
address: Address;
|
|
6
6
|
parentVault: Address;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import { type IMarketParams, MarketParams } from "../../market";
|
|
3
|
-
import type { AccrualPosition } from "../../position";
|
|
4
|
-
import type { BigIntish } from "../../types";
|
|
5
|
-
import { CapacityLimitReason } from "../../utils";
|
|
6
|
-
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
7
|
-
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
2
|
+
import { type IMarketParams, MarketParams } from "../../market/index.js";
|
|
3
|
+
import type { AccrualPosition } from "../../position/index.js";
|
|
4
|
+
import type { BigIntish } from "../../types.js";
|
|
5
|
+
import { CapacityLimitReason } from "../../utils.js";
|
|
6
|
+
import { VaultV2Adapter } from "./VaultV2Adapter.js";
|
|
7
|
+
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter.js";
|
|
8
8
|
export interface IVaultV2MorphoMarketV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
|
|
9
9
|
marketParamsList: IMarketParams[];
|
|
10
10
|
}
|
|
@@ -26,5 +26,5 @@ export declare class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMa
|
|
|
26
26
|
value: bigint;
|
|
27
27
|
limiter: CapacityLimitReason;
|
|
28
28
|
};
|
|
29
|
-
maxWithdraw(data: Hex): import("../../utils").CapacityLimit;
|
|
29
|
+
maxWithdraw(data: Hex): import("../../utils.js").CapacityLimit;
|
|
30
30
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVaultV2MorphoMarketV1Adapter = exports.VaultV2MorphoMarketV1Adapter = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
class VaultV2MorphoMarketV1Adapter extends
|
|
5
|
+
const index_js_1 = require("../../market/index.js");
|
|
6
|
+
const utils_js_1 = require("../../utils.js");
|
|
7
|
+
const VaultV2Adapter_js_1 = require("./VaultV2Adapter.js");
|
|
8
|
+
class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_js_1.VaultV2Adapter {
|
|
9
9
|
static adapterId(address) {
|
|
10
10
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
|
13
13
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["collateralToken", address]));
|
|
14
14
|
}
|
|
15
15
|
static marketParamsId(address, params) {
|
|
16
|
-
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" },
|
|
16
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, index_js_1.marketParamsAbi], ["this/marketParams", address, params]));
|
|
17
17
|
}
|
|
18
18
|
marketParamsList;
|
|
19
19
|
constructor({ marketParamsList, ...vaultV2Adapter }) {
|
|
@@ -21,7 +21,7 @@ class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
|
21
21
|
...vaultV2Adapter,
|
|
22
22
|
adapterId: VaultV2MorphoMarketV1Adapter.adapterId(vaultV2Adapter.address),
|
|
23
23
|
});
|
|
24
|
-
this.marketParamsList = marketParamsList.map((params) => new
|
|
24
|
+
this.marketParamsList = marketParamsList.map((params) => new index_js_1.MarketParams(params));
|
|
25
25
|
}
|
|
26
26
|
ids(params) {
|
|
27
27
|
return [
|
|
@@ -44,15 +44,15 @@ class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
|
|
|
44
44
|
maxDeposit(_data, assets) {
|
|
45
45
|
return {
|
|
46
46
|
value: BigInt(assets),
|
|
47
|
-
limiter:
|
|
47
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
maxWithdraw(data) {
|
|
51
|
-
const marketId =
|
|
51
|
+
const marketId = index_js_1.MarketParams.fromHex(data).id;
|
|
52
52
|
const position = this.positions.find((position) => position.marketId === marketId);
|
|
53
53
|
return (position?.market?.getWithdrawCapacityLimit(position) ?? {
|
|
54
54
|
value: 0n,
|
|
55
|
-
limiter:
|
|
55
|
+
limiter: utils_js_1.CapacityLimitReason.position,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import { type Market, MarketParams } from "../../market";
|
|
3
|
-
import type { BigIntish, MarketId } from "../../types";
|
|
4
|
-
import { CapacityLimitReason } from "../../utils";
|
|
5
|
-
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
6
|
-
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
2
|
+
import { type Market, MarketParams } from "../../market/index.js";
|
|
3
|
+
import type { BigIntish, MarketId } from "../../types.js";
|
|
4
|
+
import { CapacityLimitReason } from "../../utils.js";
|
|
5
|
+
import { VaultV2Adapter } from "./VaultV2Adapter.js";
|
|
6
|
+
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter.js";
|
|
7
7
|
export interface IVaultV2MorphoMarketV1AdapterV2 extends Omit<IVaultV2Adapter, "adapterId"> {
|
|
8
8
|
marketIds: MarketId[];
|
|
9
9
|
adaptiveCurveIrm: Address;
|
|
@@ -29,5 +29,5 @@ export declare class AccrualVaultV2MorphoMarketV1AdapterV2 extends VaultV2Morpho
|
|
|
29
29
|
value: bigint;
|
|
30
30
|
limiter: CapacityLimitReason;
|
|
31
31
|
};
|
|
32
|
-
maxWithdraw(data: Hex): import("../../utils").CapacityLimit;
|
|
32
|
+
maxWithdraw(data: Hex): import("../../utils.js").CapacityLimit;
|
|
33
33
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1AdapterV2 = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
class VaultV2MorphoMarketV1AdapterV2 extends
|
|
5
|
+
const index_js_1 = require("../../market/index.js");
|
|
6
|
+
const utils_js_1 = require("../../utils.js");
|
|
7
|
+
const VaultV2Adapter_js_1 = require("./VaultV2Adapter.js");
|
|
8
|
+
class VaultV2MorphoMarketV1AdapterV2 extends VaultV2Adapter_js_1.VaultV2Adapter {
|
|
9
9
|
static adapterId(address) {
|
|
10
10
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ class VaultV2MorphoMarketV1AdapterV2 extends VaultV2Adapter_1.VaultV2Adapter {
|
|
|
13
13
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["collateralToken", address]));
|
|
14
14
|
}
|
|
15
15
|
static marketParamsId(address, params) {
|
|
16
|
-
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" },
|
|
16
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, index_js_1.marketParamsAbi], ["this/marketParams", address, params]));
|
|
17
17
|
}
|
|
18
18
|
marketIds;
|
|
19
19
|
adaptiveCurveIrm;
|
|
@@ -51,17 +51,17 @@ class AccrualVaultV2MorphoMarketV1AdapterV2 extends VaultV2MorphoMarketV1Adapter
|
|
|
51
51
|
maxDeposit(_data, assets) {
|
|
52
52
|
return {
|
|
53
53
|
value: BigInt(assets),
|
|
54
|
-
limiter:
|
|
54
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
maxWithdraw(data) {
|
|
58
|
-
const marketId =
|
|
58
|
+
const marketId = index_js_1.MarketParams.fromHex(data).id;
|
|
59
59
|
const market = this.markets.find((market) => market.id === marketId);
|
|
60
60
|
return (market?.getWithdrawCapacityLimit({
|
|
61
61
|
supplyShares: this.supplyShares[marketId] ?? 0n,
|
|
62
62
|
}) ?? {
|
|
63
63
|
value: 0n,
|
|
64
|
-
limiter:
|
|
64
|
+
limiter: utils_js_1.CapacityLimitReason.position,
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
|
-
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
2
|
+
import { VaultV2Adapter } from "./VaultV2Adapter.js";
|
|
3
3
|
export interface IVaultV2MorphoVaultV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
|
|
4
4
|
morphoVaultV1: Address;
|
|
5
5
|
}
|
|
6
|
-
import type { BigIntish } from "../../types";
|
|
7
|
-
import type { AccrualVault } from "../Vault";
|
|
8
|
-
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
6
|
+
import type { BigIntish } from "../../types.js";
|
|
7
|
+
import type { AccrualVault } from "../Vault.js";
|
|
8
|
+
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter.js";
|
|
9
9
|
export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter {
|
|
10
10
|
static adapterId(address: Address): `0x${string}`;
|
|
11
11
|
readonly morphoVaultV1: Address;
|
|
@@ -19,6 +19,6 @@ export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVau
|
|
|
19
19
|
shares: bigint;
|
|
20
20
|
constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, accrualVaultV1: AccrualVault, shares: bigint);
|
|
21
21
|
realAssets(timestamp?: BigIntish): bigint;
|
|
22
|
-
maxDeposit(_data: Hex, assets: BigIntish): import("
|
|
23
|
-
maxWithdraw(_data: Hex): import("
|
|
22
|
+
maxDeposit(_data: Hex, assets: BigIntish): import("../../utils.js").CapacityLimit;
|
|
23
|
+
maxWithdraw(_data: Hex): import("../../utils.js").CapacityLimit;
|
|
24
24
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AccrualVaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoVaultV1Adapter = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
6
|
-
class VaultV2MorphoVaultV1Adapter extends
|
|
5
|
+
const VaultV2Adapter_js_1 = require("./VaultV2Adapter.js");
|
|
6
|
+
class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter_js_1.VaultV2Adapter {
|
|
7
7
|
static adapterId(address) {
|
|
8
8
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
9
9
|
}
|