@morpho-org/blue-sdk 6.0.1 → 6.1.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/addresses.d.ts +105 -0
- package/lib/cjs/addresses.js +74 -0
- package/lib/cjs/chain.d.ts +84 -1
- package/lib/cjs/chain.js +78 -0
- package/lib/cjs/errors.d.ts +34 -0
- package/lib/cjs/errors.js +28 -0
- package/lib/cjs/holding/AssetBalances.d.ts +3 -0
- package/lib/cjs/holding/AssetBalances.js +1 -0
- package/lib/cjs/holding/Holding.d.ts +6 -0
- package/lib/cjs/holding/Holding.js +2 -0
- package/lib/cjs/market/Market.d.ts +4 -0
- package/lib/cjs/market/MarketParams.d.ts +3 -0
- package/lib/cjs/market/MarketParams.js +1 -0
- package/lib/cjs/market/MarketUtils.d.ts +397 -0
- package/lib/cjs/market/MarketUtils.js +397 -2
- package/lib/cjs/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/cjs/math/AdaptiveCurveIrmLib.js +51 -1
- package/lib/cjs/math/MathLib.d.ts +152 -4
- package/lib/cjs/math/MathLib.js +151 -4
- package/lib/cjs/math/SharesMath.d.ts +34 -0
- package/lib/cjs/math/SharesMath.js +34 -0
- package/lib/cjs/position/Position.d.ts +4 -0
- package/lib/cjs/position/Position.js +2 -0
- package/lib/cjs/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/cjs/position/PreLiquidationPosition.js +2 -0
- package/lib/cjs/preLiquidation.d.ts +16 -0
- package/lib/cjs/preLiquidation.js +16 -0
- package/lib/cjs/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ConstantWrappedToken.js +1 -0
- package/lib/cjs/token/Eip5267Domain.d.ts +4 -0
- package/lib/cjs/token/Eip5267Domain.js +2 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/cjs/token/Token.d.ts +2 -0
- package/lib/cjs/token/Token.js +1 -0
- package/lib/cjs/token/VaultToken.d.ts +2 -0
- package/lib/cjs/token/VaultToken.js +1 -0
- package/lib/cjs/token/WrappedToken.d.ts +1 -0
- package/lib/cjs/token/WrappedToken.js +1 -0
- package/lib/cjs/types.d.ts +17 -0
- package/lib/cjs/types.js +13 -0
- package/lib/cjs/user/User.d.ts +1 -0
- package/lib/cjs/user/User.js +1 -0
- package/lib/cjs/utils.d.ts +2 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/vault/Vault.d.ts +7 -0
- package/lib/cjs/vault/Vault.js +2 -0
- package/lib/cjs/vault/VaultConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketAllocation.js +1 -0
- package/lib/cjs/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/cjs/vault/VaultUser.d.ts +2 -0
- package/lib/cjs/vault/VaultUser.js +1 -0
- package/lib/cjs/vault/VaultUtils.d.ts +49 -0
- package/lib/cjs/vault/VaultUtils.js +49 -0
- package/lib/cjs/vault/v2/VaultV2.d.ts +5 -0
- package/lib/cjs/vault/v2/VaultV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/lib/esm/addresses.d.ts +105 -0
- package/lib/esm/addresses.js +74 -0
- package/lib/esm/chain.d.ts +84 -1
- package/lib/esm/chain.js +78 -0
- package/lib/esm/errors.d.ts +34 -0
- package/lib/esm/errors.js +28 -0
- package/lib/esm/holding/AssetBalances.d.ts +3 -0
- package/lib/esm/holding/AssetBalances.js +1 -0
- package/lib/esm/holding/Holding.d.ts +6 -0
- package/lib/esm/holding/Holding.js +2 -0
- package/lib/esm/market/Market.d.ts +4 -0
- package/lib/esm/market/MarketParams.d.ts +3 -0
- package/lib/esm/market/MarketParams.js +1 -0
- package/lib/esm/market/MarketUtils.d.ts +397 -0
- package/lib/esm/market/MarketUtils.js +397 -2
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/esm/math/AdaptiveCurveIrmLib.js +51 -1
- package/lib/esm/math/MathLib.d.ts +152 -4
- package/lib/esm/math/MathLib.js +151 -4
- package/lib/esm/math/SharesMath.d.ts +34 -0
- package/lib/esm/math/SharesMath.js +34 -0
- package/lib/esm/position/Position.d.ts +4 -0
- package/lib/esm/position/Position.js +2 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/esm/position/PreLiquidationPosition.js +2 -0
- package/lib/esm/preLiquidation.d.ts +16 -0
- package/lib/esm/preLiquidation.js +16 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/esm/token/ConstantWrappedToken.js +1 -0
- package/lib/esm/token/Eip5267Domain.d.ts +4 -0
- package/lib/esm/token/Eip5267Domain.js +2 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/esm/token/Token.d.ts +2 -0
- package/lib/esm/token/Token.js +1 -0
- package/lib/esm/token/VaultToken.d.ts +2 -0
- package/lib/esm/token/VaultToken.js +1 -0
- package/lib/esm/token/WrappedToken.d.ts +1 -0
- package/lib/esm/token/WrappedToken.js +1 -0
- package/lib/esm/types.d.ts +17 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +1 -0
- package/lib/esm/user/User.js +1 -0
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +1 -0
- package/lib/esm/vault/Vault.d.ts +7 -0
- package/lib/esm/vault/Vault.js +2 -0
- package/lib/esm/vault/VaultConfig.d.ts +2 -0
- package/lib/esm/vault/VaultConfig.js +1 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/esm/vault/VaultMarketAllocation.js +1 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/esm/vault/VaultMarketConfig.js +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/esm/vault/VaultUser.d.ts +2 -0
- package/lib/esm/vault/VaultUser.js +1 -0
- package/lib/esm/vault/VaultUtils.d.ts +49 -0
- package/lib/esm/vault/VaultUtils.js +49 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +5 -0
- package/lib/esm/vault/v2/VaultV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/package.json +2 -2
|
@@ -8,11 +8,35 @@ export declare namespace MarketUtils {
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns the id of a market based on its params.
|
|
10
10
|
* @param market The market params.
|
|
11
|
+
* @returns The deterministic Morpho Blue market id.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
15
|
+
*
|
|
16
|
+
* const marketParams = {
|
|
17
|
+
* loanToken: "0x0000000000000000000000000000000000000001",
|
|
18
|
+
* collateralToken: "0x0000000000000000000000000000000000000002",
|
|
19
|
+
* oracle: "0x0000000000000000000000000000000000000003",
|
|
20
|
+
* irm: "0x0000000000000000000000000000000000000004",
|
|
21
|
+
* lltv: 860_000_000_000_000_000n,
|
|
22
|
+
* } as const;
|
|
23
|
+
*
|
|
24
|
+
* const id = MarketUtils.getMarketId(marketParams);
|
|
25
|
+
* // id satisfies MarketId
|
|
26
|
+
* ```
|
|
11
27
|
*/
|
|
12
28
|
function getMarketId(market: IMarketParams): MarketId;
|
|
13
29
|
/**
|
|
14
30
|
* Returns the liquidation incentive factor for a given market params.
|
|
15
31
|
* @param config The market params.
|
|
32
|
+
* @returns The liquidation incentive factor, scaled by WAD.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
36
|
+
*
|
|
37
|
+
* const lif = MarketUtils.getLiquidationIncentiveFactor({ lltv: 86_0000000000000000n });
|
|
38
|
+
* // lif satisfies bigint
|
|
39
|
+
* ```
|
|
16
40
|
*/
|
|
17
41
|
function getLiquidationIncentiveFactor({ lltv }: {
|
|
18
42
|
lltv: BigIntish;
|
|
@@ -20,6 +44,17 @@ export declare namespace MarketUtils {
|
|
|
20
44
|
/**
|
|
21
45
|
* Returns the market's utilization rate (scaled by WAD).
|
|
22
46
|
* @param market The market state.
|
|
47
|
+
* @returns The market utilization rate, scaled by WAD.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
51
|
+
*
|
|
52
|
+
* const utilization = MarketUtils.getUtilization({
|
|
53
|
+
* totalSupplyAssets: 100n,
|
|
54
|
+
* totalBorrowAssets: 50n,
|
|
55
|
+
* });
|
|
56
|
+
* // utilization === 500000000000000000n
|
|
57
|
+
* ```
|
|
23
58
|
*/
|
|
24
59
|
function getUtilization({ totalSupplyAssets, totalBorrowAssets, }: {
|
|
25
60
|
totalSupplyAssets: BigIntish;
|
|
@@ -29,6 +64,14 @@ export declare namespace MarketUtils {
|
|
|
29
64
|
* Returns the per-second rate continuously compounded over a year,
|
|
30
65
|
* as calculated in Morpho Blue assuming the market is frequently accrued onchain.
|
|
31
66
|
* @param rate The per-second rate to compound annually.
|
|
67
|
+
* @returns The annual percentage yield as a JavaScript number.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
71
|
+
*
|
|
72
|
+
* const apy = MarketUtils.rateToApy(1n);
|
|
73
|
+
* // apy satisfies number
|
|
74
|
+
* ```
|
|
32
75
|
*/
|
|
33
76
|
function rateToApy(rate: BigIntish): number;
|
|
34
77
|
/**
|
|
@@ -75,6 +118,17 @@ export declare namespace MarketUtils {
|
|
|
75
118
|
* Returns the smallest volume to supply until the market gets the closest to the given utilization rate.
|
|
76
119
|
* @param market The market state.
|
|
77
120
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
121
|
+
* @returns The amount to supply to approach the target utilization.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
125
|
+
*
|
|
126
|
+
* const assets = MarketUtils.getSupplyToUtilization(
|
|
127
|
+
* { totalSupplyAssets: 100n, totalBorrowAssets: 80n },
|
|
128
|
+
* MathLib.WAD / 2n,
|
|
129
|
+
* );
|
|
130
|
+
* // assets satisfies bigint
|
|
131
|
+
* ```
|
|
78
132
|
*/
|
|
79
133
|
function getSupplyToUtilization(market: {
|
|
80
134
|
totalSupplyAssets: BigIntish;
|
|
@@ -84,6 +138,17 @@ export declare namespace MarketUtils {
|
|
|
84
138
|
* Returns the liquidity available to withdraw until the market gets the closest to the given utilization rate.
|
|
85
139
|
* @param market The market state.
|
|
86
140
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
141
|
+
* @returns The amount withdrawable before reaching the target utilization.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
145
|
+
*
|
|
146
|
+
* const assets = MarketUtils.getWithdrawToUtilization(
|
|
147
|
+
* { totalSupplyAssets: 100n, totalBorrowAssets: 50n },
|
|
148
|
+
* MathLib.WAD,
|
|
149
|
+
* );
|
|
150
|
+
* // assets satisfies bigint
|
|
151
|
+
* ```
|
|
87
152
|
*/
|
|
88
153
|
function getWithdrawToUtilization({ totalSupplyAssets, totalBorrowAssets, }: {
|
|
89
154
|
totalSupplyAssets: BigIntish;
|
|
@@ -93,6 +158,17 @@ export declare namespace MarketUtils {
|
|
|
93
158
|
* Returns the liquidity available to borrow until the market gets the closest to the given utilization rate.
|
|
94
159
|
* @param market The market state.
|
|
95
160
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
161
|
+
* @returns The amount borrowable before reaching the target utilization.
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
165
|
+
*
|
|
166
|
+
* const assets = MarketUtils.getBorrowToUtilization(
|
|
167
|
+
* { totalSupplyAssets: 100n, totalBorrowAssets: 50n },
|
|
168
|
+
* MathLib.WAD,
|
|
169
|
+
* );
|
|
170
|
+
* // assets satisfies bigint
|
|
171
|
+
* ```
|
|
96
172
|
*/
|
|
97
173
|
function getBorrowToUtilization({ totalSupplyAssets, totalBorrowAssets, }: {
|
|
98
174
|
totalSupplyAssets: BigIntish;
|
|
@@ -102,17 +178,53 @@ export declare namespace MarketUtils {
|
|
|
102
178
|
* Returns the smallest volume to repay until the market gets the closest to the given utilization rate.
|
|
103
179
|
* @param market The market state.
|
|
104
180
|
* @param utilization The target utilization rate (scaled by WAD).
|
|
181
|
+
* @returns The amount to repay before reaching the target utilization.
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { MarketUtils, MathLib } from "@morpho-org/blue-sdk";
|
|
185
|
+
*
|
|
186
|
+
* const assets = MarketUtils.getRepayToUtilization(
|
|
187
|
+
* { totalSupplyAssets: 100n, totalBorrowAssets: 80n },
|
|
188
|
+
* MathLib.WAD / 2n,
|
|
189
|
+
* );
|
|
190
|
+
* // assets satisfies bigint
|
|
191
|
+
* ```
|
|
105
192
|
*/
|
|
106
193
|
function getRepayToUtilization({ totalSupplyAssets, totalBorrowAssets, }: {
|
|
107
194
|
totalSupplyAssets: BigIntish;
|
|
108
195
|
totalBorrowAssets: BigIntish;
|
|
109
196
|
}, utilization: BigIntish): bigint;
|
|
197
|
+
/**
|
|
198
|
+
* Returns the borrow power of a collateral amount before oracle pricing.
|
|
199
|
+
*
|
|
200
|
+
* @param collateral - The collateral amount.
|
|
201
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
202
|
+
* @returns The collateral amount multiplied by LLTV.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
206
|
+
*
|
|
207
|
+
* const power = MarketUtils.getCollateralPower(100n, { lltv: 50_0000000000000000n });
|
|
208
|
+
* // power === 50n
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
110
211
|
function getCollateralPower(collateral: BigIntish, { lltv }: {
|
|
111
212
|
lltv: BigIntish;
|
|
112
213
|
}): bigint;
|
|
113
214
|
/**
|
|
114
215
|
* Returns the value of a given amount of collateral quoted in loan assets.
|
|
115
216
|
* Return `undefined` iff the market's price is undefined.
|
|
217
|
+
*
|
|
218
|
+
* @param collateral - The collateral amount.
|
|
219
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
220
|
+
* @returns The collateral value in loan assets, or `undefined` when price is unavailable.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
224
|
+
*
|
|
225
|
+
* const value = MarketUtils.getCollateralValue(2n, { price: ORACLE_PRICE_SCALE });
|
|
226
|
+
* // value === 2n
|
|
227
|
+
* ```
|
|
116
228
|
*/
|
|
117
229
|
function getCollateralValue(collateral: BigIntish, { price }: {
|
|
118
230
|
price?: BigIntish;
|
|
@@ -121,6 +233,22 @@ export declare namespace MarketUtils {
|
|
|
121
233
|
* Returns the maximum debt allowed given a certain amount of collateral.
|
|
122
234
|
* Return `undefined` iff the market's price is undefined.
|
|
123
235
|
* To calculate the amount of loan assets that can be borrowed, use `getMaxBorrowableAssets`.
|
|
236
|
+
*
|
|
237
|
+
* @param collateral - The collateral amount.
|
|
238
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
239
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
240
|
+
* @returns The maximum borrow assets allowed, or `undefined` when price is unavailable.
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
244
|
+
*
|
|
245
|
+
* const maxBorrow = MarketUtils.getMaxBorrowAssets(
|
|
246
|
+
* 2n,
|
|
247
|
+
* { price: ORACLE_PRICE_SCALE },
|
|
248
|
+
* { lltv: 50_0000000000000000n },
|
|
249
|
+
* );
|
|
250
|
+
* // maxBorrow === 1n
|
|
251
|
+
* ```
|
|
124
252
|
*/
|
|
125
253
|
function getMaxBorrowAssets(collateral: BigIntish, market: {
|
|
126
254
|
price?: BigIntish;
|
|
@@ -130,6 +258,25 @@ export declare namespace MarketUtils {
|
|
|
130
258
|
/**
|
|
131
259
|
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
|
|
132
260
|
* Return `undefined` iff the market's price is undefined.
|
|
261
|
+
*
|
|
262
|
+
* @param position.collateral - The collateral amount in the position.
|
|
263
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
264
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
265
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
266
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
267
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
268
|
+
* @returns The additional borrowable loan assets, or `undefined` when price is unavailable.
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
272
|
+
*
|
|
273
|
+
* const borrowable = MarketUtils.getMaxBorrowableAssets(
|
|
274
|
+
* { collateral: 2n, borrowShares: 0n },
|
|
275
|
+
* { totalBorrowAssets: 0n, totalBorrowShares: 0n, price: ORACLE_PRICE_SCALE },
|
|
276
|
+
* { lltv: 50_0000000000000000n },
|
|
277
|
+
* );
|
|
278
|
+
* // borrowable satisfies bigint | undefined
|
|
279
|
+
* ```
|
|
133
280
|
*/
|
|
134
281
|
function getMaxBorrowableAssets({ collateral, borrowShares, }: {
|
|
135
282
|
collateral: BigIntish;
|
|
@@ -144,6 +291,24 @@ export declare namespace MarketUtils {
|
|
|
144
291
|
/**
|
|
145
292
|
* Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares.
|
|
146
293
|
* Return `undefined` iff the market's price is undefined.
|
|
294
|
+
*
|
|
295
|
+
* @param repaidShares - The borrow shares repaid by the liquidation.
|
|
296
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
297
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
298
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
299
|
+
* @param config.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
300
|
+
* @returns The seized collateral amount, or `undefined` when price is unavailable.
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
304
|
+
*
|
|
305
|
+
* const seized = MarketUtils.getLiquidationSeizedAssets(
|
|
306
|
+
* 1n,
|
|
307
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
308
|
+
* { lltv: 86_0000000000000000n },
|
|
309
|
+
* );
|
|
310
|
+
* // seized satisfies bigint | undefined
|
|
311
|
+
* ```
|
|
147
312
|
*/
|
|
148
313
|
function getLiquidationSeizedAssets(repaidShares: BigIntish, market: {
|
|
149
314
|
totalBorrowAssets: BigIntish;
|
|
@@ -155,6 +320,24 @@ export declare namespace MarketUtils {
|
|
|
155
320
|
/**
|
|
156
321
|
* Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral.
|
|
157
322
|
* Return `undefined` iff the market's price is undefined.
|
|
323
|
+
*
|
|
324
|
+
* @param seizedAssets - The collateral amount seized by the liquidation.
|
|
325
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
326
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
327
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
328
|
+
* @param config.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
329
|
+
* @returns The borrow shares repaid, or `undefined` when price is unavailable.
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
333
|
+
*
|
|
334
|
+
* const shares = MarketUtils.getLiquidationRepaidShares(
|
|
335
|
+
* 1n,
|
|
336
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
337
|
+
* { lltv: 86_0000000000000000n },
|
|
338
|
+
* );
|
|
339
|
+
* // shares satisfies bigint | undefined
|
|
340
|
+
* ```
|
|
158
341
|
*/
|
|
159
342
|
function getLiquidationRepaidShares(seizedAssets: BigIntish, market: {
|
|
160
343
|
totalBorrowAssets: BigIntish;
|
|
@@ -166,6 +349,25 @@ export declare namespace MarketUtils {
|
|
|
166
349
|
/**
|
|
167
350
|
* Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position.
|
|
168
351
|
* Return `undefined` iff the market's price is undefined.
|
|
352
|
+
*
|
|
353
|
+
* @param position.collateral - The collateral amount in the position.
|
|
354
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
355
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
356
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
357
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
358
|
+
* @param config.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
359
|
+
* @returns The maximum seizable collateral, or `undefined` when price is unavailable.
|
|
360
|
+
* @example
|
|
361
|
+
* ```ts
|
|
362
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
363
|
+
*
|
|
364
|
+
* const collateral = MarketUtils.getSeizableCollateral(
|
|
365
|
+
* { collateral: 1n, borrowShares: 1n },
|
|
366
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
367
|
+
* { lltv: 50_0000000000000000n },
|
|
368
|
+
* );
|
|
369
|
+
* // collateral satisfies bigint | undefined
|
|
370
|
+
* ```
|
|
169
371
|
*/
|
|
170
372
|
function getSeizableCollateral(position: {
|
|
171
373
|
collateral: BigIntish;
|
|
@@ -180,6 +382,25 @@ export declare namespace MarketUtils {
|
|
|
180
382
|
/**
|
|
181
383
|
* Returns the amount of collateral that can be withdrawn given a certain borrow position.
|
|
182
384
|
* Return `undefined` iff the market's price is undefined.
|
|
385
|
+
*
|
|
386
|
+
* @param position.collateral - The collateral amount in the position.
|
|
387
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
388
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
389
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
390
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
391
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
392
|
+
* @returns The withdrawable collateral amount, or `undefined` when price is unavailable.
|
|
393
|
+
* @example
|
|
394
|
+
* ```ts
|
|
395
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
396
|
+
*
|
|
397
|
+
* const collateral = MarketUtils.getWithdrawableCollateral(
|
|
398
|
+
* { collateral: 2n, borrowShares: 0n },
|
|
399
|
+
* { totalBorrowAssets: 0n, totalBorrowShares: 0n, price: ORACLE_PRICE_SCALE },
|
|
400
|
+
* { lltv: 50_0000000000000000n },
|
|
401
|
+
* );
|
|
402
|
+
* // collateral satisfies bigint | undefined
|
|
403
|
+
* ```
|
|
183
404
|
*/
|
|
184
405
|
function getWithdrawableCollateral({ collateral, borrowShares, }: {
|
|
185
406
|
collateral: BigIntish;
|
|
@@ -195,6 +416,20 @@ export declare namespace MarketUtils {
|
|
|
195
416
|
* Returns whether a given borrow position is healthy.
|
|
196
417
|
* Return `undefined` iff the market's price is undefined.
|
|
197
418
|
* @param position The borrow position to check.
|
|
419
|
+
* @param market The market state used to value the position.
|
|
420
|
+
* @param marketParams The market params containing LLTV.
|
|
421
|
+
* @returns Whether the position is healthy, or `undefined` when price is unavailable.
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
425
|
+
*
|
|
426
|
+
* const healthy = MarketUtils.isHealthy(
|
|
427
|
+
* { collateral: 2n, borrowShares: 0n },
|
|
428
|
+
* { totalBorrowAssets: 0n, totalBorrowShares: 0n, price: ORACLE_PRICE_SCALE },
|
|
429
|
+
* { lltv: 50_0000000000000000n },
|
|
430
|
+
* );
|
|
431
|
+
* // healthy satisfies boolean | undefined
|
|
432
|
+
* ```
|
|
198
433
|
*/
|
|
199
434
|
function isHealthy({ collateral, borrowShares, }: {
|
|
200
435
|
collateral: BigIntish;
|
|
@@ -210,6 +445,24 @@ export declare namespace MarketUtils {
|
|
|
210
445
|
* Returns the price of the collateral quoted in the loan token (e.g. ETH/DAI)
|
|
211
446
|
* that set the user's position to be liquidatable.
|
|
212
447
|
* Returns null if the position is not a borrow.
|
|
448
|
+
*
|
|
449
|
+
* @param position.collateral - The collateral amount in the position.
|
|
450
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
451
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
452
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
453
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
454
|
+
* @returns The liquidation price, or `null` when the position has no borrow.
|
|
455
|
+
* @example
|
|
456
|
+
* ```ts
|
|
457
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
458
|
+
*
|
|
459
|
+
* const price = MarketUtils.getLiquidationPrice(
|
|
460
|
+
* { collateral: 2n, borrowShares: 1n },
|
|
461
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n },
|
|
462
|
+
* { lltv: 50_0000000000000000n },
|
|
463
|
+
* );
|
|
464
|
+
* // price satisfies bigint | null
|
|
465
|
+
* ```
|
|
213
466
|
*/
|
|
214
467
|
function getLiquidationPrice({ collateral, borrowShares, }: {
|
|
215
468
|
collateral: BigIntish;
|
|
@@ -225,6 +478,22 @@ export declare namespace MarketUtils {
|
|
|
225
478
|
* Negative when healthy (the price needs to drop x%), positive when unhealthy (the price needs to soar x%).
|
|
226
479
|
* Returns `undefined` iff the market's price is undefined.
|
|
227
480
|
* Returns null if the position is not a borrow.
|
|
481
|
+
*
|
|
482
|
+
* @param position - The borrow position to evaluate.
|
|
483
|
+
* @param market - The market state used to value the position.
|
|
484
|
+
* @param marketParams - The market params containing LLTV.
|
|
485
|
+
* @returns The WAD-scaled price variation, `undefined`, or `null` when the position has no borrow.
|
|
486
|
+
* @example
|
|
487
|
+
* ```ts
|
|
488
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
489
|
+
*
|
|
490
|
+
* const variation = MarketUtils.getPriceVariationToLiquidationPrice(
|
|
491
|
+
* { collateral: 2n, borrowShares: 1n },
|
|
492
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
493
|
+
* { lltv: 50_0000000000000000n },
|
|
494
|
+
* );
|
|
495
|
+
* // variation satisfies bigint | null | undefined
|
|
496
|
+
* ```
|
|
228
497
|
*/
|
|
229
498
|
function getPriceVariationToLiquidationPrice(position: {
|
|
230
499
|
collateral: BigIntish;
|
|
@@ -240,6 +509,25 @@ export declare namespace MarketUtils {
|
|
|
240
509
|
* Returns the health factor of a given borrow position (scaled by WAD).
|
|
241
510
|
* If the debt is 0, health factor is `MaxUint256`.
|
|
242
511
|
* Returns `undefined` iff the market's price is undefined.
|
|
512
|
+
*
|
|
513
|
+
* @param position.collateral - The collateral amount in the position.
|
|
514
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
515
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
516
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
517
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
518
|
+
* @param marketParams.lltv - The market liquidation loan-to-value, scaled by WAD.
|
|
519
|
+
* @returns The WAD-scaled health factor, or `undefined` when price is unavailable.
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
523
|
+
*
|
|
524
|
+
* const healthFactor = MarketUtils.getHealthFactor(
|
|
525
|
+
* { collateral: 2n, borrowShares: 1n },
|
|
526
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
527
|
+
* { lltv: 50_0000000000000000n },
|
|
528
|
+
* );
|
|
529
|
+
* // healthFactor satisfies bigint | undefined
|
|
530
|
+
* ```
|
|
243
531
|
*/
|
|
244
532
|
function getHealthFactor({ collateral, borrowShares, }: {
|
|
245
533
|
collateral: BigIntish;
|
|
@@ -255,6 +543,23 @@ export declare namespace MarketUtils {
|
|
|
255
543
|
* Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
|
|
256
544
|
* Returns `undefined` iff the market's price is undefined.
|
|
257
545
|
* Returns null if the position is not a borrow.
|
|
546
|
+
*
|
|
547
|
+
* @param position.collateral - The collateral amount in the position.
|
|
548
|
+
* @param position.borrowShares - The borrow shares in the position.
|
|
549
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
550
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
551
|
+
* @param market.price - The oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
552
|
+
* @returns The WAD-scaled loan-to-value ratio, `undefined`, or `null` when the position has no borrow.
|
|
553
|
+
* @example
|
|
554
|
+
* ```ts
|
|
555
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
556
|
+
*
|
|
557
|
+
* const ltv = MarketUtils.getLtv(
|
|
558
|
+
* { collateral: 2n, borrowShares: 1n },
|
|
559
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
560
|
+
* );
|
|
561
|
+
* // ltv satisfies bigint | null | undefined
|
|
562
|
+
* ```
|
|
258
563
|
*/
|
|
259
564
|
function getLtv({ collateral, borrowShares, }: {
|
|
260
565
|
collateral: BigIntish;
|
|
@@ -267,6 +572,22 @@ export declare namespace MarketUtils {
|
|
|
267
572
|
/**
|
|
268
573
|
* Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
|
|
269
574
|
* Returns `undefined` iff the market's price is undefined.
|
|
575
|
+
*
|
|
576
|
+
* @param position - The borrow position to evaluate.
|
|
577
|
+
* @param market - The market state used to value the position.
|
|
578
|
+
* @param marketParams - The market params containing LLTV.
|
|
579
|
+
* @returns The WAD-scaled borrow capacity usage, or `undefined` when price is unavailable.
|
|
580
|
+
* @example
|
|
581
|
+
* ```ts
|
|
582
|
+
* import { MarketUtils, ORACLE_PRICE_SCALE } from "@morpho-org/blue-sdk";
|
|
583
|
+
*
|
|
584
|
+
* const usage = MarketUtils.getBorrowCapacityUsage(
|
|
585
|
+
* { collateral: 2n, borrowShares: 1n },
|
|
586
|
+
* { totalBorrowAssets: 1n, totalBorrowShares: 1n, price: ORACLE_PRICE_SCALE },
|
|
587
|
+
* { lltv: 50_0000000000000000n },
|
|
588
|
+
* );
|
|
589
|
+
* // usage satisfies bigint | undefined
|
|
590
|
+
* ```
|
|
270
591
|
*/
|
|
271
592
|
function getBorrowCapacityUsage(position: {
|
|
272
593
|
collateral: BigIntish;
|
|
@@ -278,18 +599,94 @@ export declare namespace MarketUtils {
|
|
|
278
599
|
}, marketParams: {
|
|
279
600
|
lltv: BigIntish;
|
|
280
601
|
}): bigint | undefined;
|
|
602
|
+
/**
|
|
603
|
+
* Converts market supply shares to loan assets.
|
|
604
|
+
*
|
|
605
|
+
* @param shares - The supply shares to convert.
|
|
606
|
+
* @param market.totalSupplyAssets - The market's total supplied assets.
|
|
607
|
+
* @param market.totalSupplyShares - The market's total supply shares.
|
|
608
|
+
* @param rounding - Optional rounding direction. Defaults to `"Down"`.
|
|
609
|
+
* @returns The equivalent amount of supplied loan assets.
|
|
610
|
+
* @example
|
|
611
|
+
* ```ts
|
|
612
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
613
|
+
*
|
|
614
|
+
* const assets = MarketUtils.toSupplyAssets(100n, {
|
|
615
|
+
* totalSupplyAssets: 1_000n,
|
|
616
|
+
* totalSupplyShares: 100n,
|
|
617
|
+
* });
|
|
618
|
+
* // assets satisfies bigint
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
281
621
|
function toSupplyAssets(shares: BigIntish, market: {
|
|
282
622
|
totalSupplyAssets: BigIntish;
|
|
283
623
|
totalSupplyShares: BigIntish;
|
|
284
624
|
}, rounding?: RoundingDirection): bigint;
|
|
625
|
+
/**
|
|
626
|
+
* Converts market supply assets to supply shares.
|
|
627
|
+
*
|
|
628
|
+
* @param assets - The supplied loan assets to convert.
|
|
629
|
+
* @param market.totalSupplyAssets - The market's total supplied assets.
|
|
630
|
+
* @param market.totalSupplyShares - The market's total supply shares.
|
|
631
|
+
* @param rounding - Optional rounding direction. Defaults to `"Up"`.
|
|
632
|
+
* @returns The equivalent amount of supply shares.
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
636
|
+
*
|
|
637
|
+
* const shares = MarketUtils.toSupplyShares(100n, {
|
|
638
|
+
* totalSupplyAssets: 1_000n,
|
|
639
|
+
* totalSupplyShares: 100n,
|
|
640
|
+
* });
|
|
641
|
+
* // shares satisfies bigint
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
285
644
|
function toSupplyShares(assets: BigIntish, market: {
|
|
286
645
|
totalSupplyAssets: BigIntish;
|
|
287
646
|
totalSupplyShares: BigIntish;
|
|
288
647
|
}, rounding?: RoundingDirection): bigint;
|
|
648
|
+
/**
|
|
649
|
+
* Converts market borrow shares to loan assets.
|
|
650
|
+
*
|
|
651
|
+
* @param shares - The borrow shares to convert.
|
|
652
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
653
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
654
|
+
* @param rounding - Optional rounding direction. Defaults to `"Up"`.
|
|
655
|
+
* @returns The equivalent amount of borrowed loan assets.
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
659
|
+
*
|
|
660
|
+
* const assets = MarketUtils.toBorrowAssets(100n, {
|
|
661
|
+
* totalBorrowAssets: 1_000n,
|
|
662
|
+
* totalBorrowShares: 100n,
|
|
663
|
+
* });
|
|
664
|
+
* // assets satisfies bigint
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
289
667
|
function toBorrowAssets(shares: BigIntish, market: {
|
|
290
668
|
totalBorrowAssets: BigIntish;
|
|
291
669
|
totalBorrowShares: BigIntish;
|
|
292
670
|
}, rounding?: RoundingDirection): bigint;
|
|
671
|
+
/**
|
|
672
|
+
* Converts market borrow assets to borrow shares.
|
|
673
|
+
*
|
|
674
|
+
* @param assets - The borrowed loan assets to convert.
|
|
675
|
+
* @param market.totalBorrowAssets - The market's total borrowed assets.
|
|
676
|
+
* @param market.totalBorrowShares - The market's total borrow shares.
|
|
677
|
+
* @param rounding - Optional rounding direction. Defaults to `"Down"`.
|
|
678
|
+
* @returns The equivalent amount of borrow shares.
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* import { MarketUtils } from "@morpho-org/blue-sdk";
|
|
682
|
+
*
|
|
683
|
+
* const shares = MarketUtils.toBorrowShares(100n, {
|
|
684
|
+
* totalBorrowAssets: 1_000n,
|
|
685
|
+
* totalBorrowShares: 100n,
|
|
686
|
+
* });
|
|
687
|
+
* // shares satisfies bigint
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
293
690
|
function toBorrowShares(assets: BigIntish, market: {
|
|
294
691
|
totalBorrowAssets: BigIntish;
|
|
295
692
|
totalBorrowShares: BigIntish;
|