@morpho-org/blue-sdk 2.0.0-next.8 → 2.0.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/lib/errors.d.ts +1 -1
- package/lib/errors.js +1 -1
- package/lib/market/Market.d.ts +5 -5
- package/lib/market/Market.js +19 -19
- package/lib/market/{MarketConfig.d.ts → MarketParams.d.ts} +6 -6
- package/lib/market/{MarketConfig.js → MarketParams.js} +9 -9
- package/lib/market/MarketUtils.d.ts +8 -8
- package/lib/market/MarketUtils.js +12 -12
- package/lib/market/index.d.ts +1 -1
- package/lib/market/index.js +1 -1
- package/lib/vault/Vault.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
Framework-agnostic package that defines Morpho-related entity classes:
|
|
25
25
|
|
|
26
|
-
- [**`
|
|
26
|
+
- [**`MarketParams`**](./src/market/MarketParams.ts): represents the immutable configuration of a market on Morpho
|
|
27
27
|
- [**`Market`**](./src/market/Market.ts): represents the state of a market on Morpho
|
|
28
28
|
- [**`Token`**](./src/token/Token.ts): represents a ERC20 token
|
|
29
29
|
- [**`User`**](./src/user/User.ts): represents a user of Morpho
|
|
@@ -46,12 +46,12 @@ yarn add @morpho-org/blue-sdk
|
|
|
46
46
|
|
|
47
47
|
### Instance of the immutable configuration of a specific market
|
|
48
48
|
|
|
49
|
-
Leverage the [`
|
|
49
|
+
Leverage the [`MarketParams`](./src/market/MarketParams.ts) class to manipulate a given market's immutable configuration:
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
import {
|
|
52
|
+
import { MarketParams } from "@morpho-org/blue-sdk";
|
|
53
53
|
|
|
54
|
-
const config = new
|
|
54
|
+
const config = new MarketParams({
|
|
55
55
|
loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
56
56
|
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
|
|
57
57
|
oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
|
|
@@ -67,11 +67,11 @@ config.liquidationIncentiveFactor; // e.g. 1_090000000000000000n (109%).
|
|
|
67
67
|
Leverage the [`Market`](./src/market/Market.ts) class to manipulate a specific market:
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
|
-
import { Market } from "@morpho-org/blue-sdk";
|
|
70
|
+
import { Market, MarketParams } from "@morpho-org/blue-sdk";
|
|
71
71
|
import { Time } from "@morpho-org/morpho-ts";
|
|
72
72
|
|
|
73
73
|
const market = new Market({
|
|
74
|
-
config: new
|
|
74
|
+
config: new MarketParams({
|
|
75
75
|
loanToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
|
|
76
76
|
collateralToken: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", // wstETH
|
|
77
77
|
oracle: "0x2a01EB9496094dA03c4E364Def50f5aD1280AD72",
|
package/lib/errors.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class UnknownTokenPriceError extends UnknownDataError {
|
|
|
9
9
|
readonly address: Address;
|
|
10
10
|
constructor(address: Address);
|
|
11
11
|
}
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class UnknownMarketParamsError extends UnknownDataError {
|
|
13
13
|
readonly marketId: MarketId;
|
|
14
14
|
constructor(marketId: MarketId);
|
|
15
15
|
}
|
package/lib/errors.js
CHANGED
|
@@ -14,7 +14,7 @@ export class UnknownTokenPriceError extends UnknownDataError {
|
|
|
14
14
|
this.address = address;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
export class
|
|
17
|
+
export class UnknownMarketParamsError extends UnknownDataError {
|
|
18
18
|
marketId;
|
|
19
19
|
constructor(marketId) {
|
|
20
20
|
super(`unknown config for market ${marketId}`);
|
package/lib/market/Market.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { BigIntish } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { MarketParams } from "./MarketParams.js";
|
|
4
4
|
export declare enum CapacityLimitReason {
|
|
5
5
|
liquidity = "Liquidity",
|
|
6
6
|
balance = "Balance",
|
|
@@ -27,7 +27,7 @@ export interface MaxPositionCapacities {
|
|
|
27
27
|
withdrawCollateral: CapacityLimit;
|
|
28
28
|
}
|
|
29
29
|
export interface InputMarket {
|
|
30
|
-
|
|
30
|
+
params: MarketParams;
|
|
31
31
|
totalSupplyAssets: bigint;
|
|
32
32
|
totalBorrowAssets: bigint;
|
|
33
33
|
totalSupplyShares: bigint;
|
|
@@ -42,9 +42,9 @@ export interface InputMarket {
|
|
|
42
42
|
*/
|
|
43
43
|
export declare class Market implements InputMarket {
|
|
44
44
|
/**
|
|
45
|
-
* The market's
|
|
45
|
+
* The market's params.
|
|
46
46
|
*/
|
|
47
|
-
readonly
|
|
47
|
+
readonly params: MarketParams;
|
|
48
48
|
/**
|
|
49
49
|
* The amount of loan assets supplied in total on the market.
|
|
50
50
|
*/
|
|
@@ -78,7 +78,7 @@ export declare class Market implements InputMarket {
|
|
|
78
78
|
* Undefined otherwise.
|
|
79
79
|
*/
|
|
80
80
|
rateAtTarget?: bigint;
|
|
81
|
-
constructor({
|
|
81
|
+
constructor({ params, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }: InputMarket);
|
|
82
82
|
/**
|
|
83
83
|
* The market's hex-encoded id, defined as the hash of the market params.
|
|
84
84
|
*/
|
package/lib/market/Market.js
CHANGED
|
@@ -15,9 +15,9 @@ export var CapacityLimitReason;
|
|
|
15
15
|
*/
|
|
16
16
|
export class Market {
|
|
17
17
|
/**
|
|
18
|
-
* The market's
|
|
18
|
+
* The market's params.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
params;
|
|
21
21
|
/**
|
|
22
22
|
* The amount of loan assets supplied in total on the market.
|
|
23
23
|
*/
|
|
@@ -51,8 +51,8 @@ export class Market {
|
|
|
51
51
|
* Undefined otherwise.
|
|
52
52
|
*/
|
|
53
53
|
rateAtTarget;
|
|
54
|
-
constructor({
|
|
55
|
-
this.
|
|
54
|
+
constructor({ params, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }) {
|
|
55
|
+
this.params = params;
|
|
56
56
|
this.totalSupplyAssets = totalSupplyAssets;
|
|
57
57
|
this.totalBorrowAssets = totalBorrowAssets;
|
|
58
58
|
this.totalSupplyShares = totalSupplyShares;
|
|
@@ -67,13 +67,13 @@ export class Market {
|
|
|
67
67
|
* The market's hex-encoded id, defined as the hash of the market params.
|
|
68
68
|
*/
|
|
69
69
|
get id() {
|
|
70
|
-
return this.
|
|
70
|
+
return this.params.id;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Whether the market satisfies the canonical definition of an idle market (i.e. collateral token is the zero address).
|
|
74
74
|
*/
|
|
75
75
|
get isIdle() {
|
|
76
|
-
return this.
|
|
76
|
+
return this.params.collateralToken === ZERO_ADDRESS;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* @warning Cannot be used to calculate the liquidity available inside a callback,
|
|
@@ -276,9 +276,9 @@ export class Market {
|
|
|
276
276
|
* To calculate the amount of loan assets that can be borrowed, use `getMaxBorrowableAssets`.
|
|
277
277
|
* @param collateral The amount of collateral to consider.
|
|
278
278
|
*/
|
|
279
|
-
getMaxBorrowAssets(collateral, { maxLtv = this.
|
|
279
|
+
getMaxBorrowAssets(collateral, { maxLtv = this.params.lltv } = {}) {
|
|
280
280
|
return MarketUtils.getMaxBorrowAssets(collateral, this, {
|
|
281
|
-
lltv: MathLib.min(maxLtv, this.
|
|
281
|
+
lltv: MathLib.min(maxLtv, this.params.lltv),
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
@@ -286,36 +286,36 @@ export class Market {
|
|
|
286
286
|
* @param position The borrow position to consider.
|
|
287
287
|
*/
|
|
288
288
|
getMaxBorrowableAssets(position) {
|
|
289
|
-
return MarketUtils.getMaxBorrowableAssets(position, this, this.
|
|
289
|
+
return MarketUtils.getMaxBorrowableAssets(position, this, this.params);
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
292
|
* Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares.
|
|
293
293
|
* @param repaidShares The amount of shares hypothetically repaid.
|
|
294
294
|
*/
|
|
295
295
|
getLiquidationSeizedAssets(repaidShares) {
|
|
296
|
-
return MarketUtils.getLiquidationSeizedAssets(repaidShares, this, this.
|
|
296
|
+
return MarketUtils.getLiquidationSeizedAssets(repaidShares, this, this.params);
|
|
297
297
|
}
|
|
298
298
|
/**
|
|
299
299
|
* Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral.
|
|
300
300
|
* @param seizedAssets The amount of collateral hypothetically seized.
|
|
301
301
|
*/
|
|
302
302
|
getLiquidationRepaidShares(seizedAssets) {
|
|
303
|
-
return MarketUtils.getLiquidationRepaidShares(seizedAssets, this, this.
|
|
303
|
+
return MarketUtils.getLiquidationRepaidShares(seizedAssets, this, this.params);
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
306
|
* Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position.
|
|
307
307
|
* @param position The borrow position to consider.
|
|
308
308
|
*/
|
|
309
309
|
getSeizableCollateral(position) {
|
|
310
|
-
return MarketUtils.getSeizableCollateral(position, this, this.
|
|
310
|
+
return MarketUtils.getSeizableCollateral(position, this, this.params);
|
|
311
311
|
}
|
|
312
312
|
/**
|
|
313
313
|
* Returns the amount of collateral that can be withdrawn given a certain borrow position.
|
|
314
314
|
* @param position The borrow position to consider.
|
|
315
315
|
*/
|
|
316
|
-
getWithdrawableCollateral(position, { maxLtv = this.
|
|
316
|
+
getWithdrawableCollateral(position, { maxLtv = this.params.lltv } = {}) {
|
|
317
317
|
return MarketUtils.getWithdrawableCollateral(position, this, {
|
|
318
|
-
lltv: MathLib.min(maxLtv, this.
|
|
318
|
+
lltv: MathLib.min(maxLtv, this.params.lltv),
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
321
|
/**
|
|
@@ -323,14 +323,14 @@ export class Market {
|
|
|
323
323
|
* @param position The borrow position to check.
|
|
324
324
|
*/
|
|
325
325
|
isHealthy(position) {
|
|
326
|
-
return MarketUtils.isHealthy(position, this, this.
|
|
326
|
+
return MarketUtils.isHealthy(position, this, this.params);
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* Returns the liquidation price of a given borrow position.
|
|
330
330
|
* @param position The borrow position to consider.
|
|
331
331
|
*/
|
|
332
332
|
getLiquidationPrice(position) {
|
|
333
|
-
return MarketUtils.getLiquidationPrice(position, this, this.
|
|
333
|
+
return MarketUtils.getLiquidationPrice(position, this, this.params);
|
|
334
334
|
}
|
|
335
335
|
/**
|
|
336
336
|
* Returns the price variation required for the given position to reach its liquidation threshold (scaled by WAD).
|
|
@@ -339,14 +339,14 @@ export class Market {
|
|
|
339
339
|
* @param position The borrow position to consider.
|
|
340
340
|
*/
|
|
341
341
|
getPriceVariationToLiquidationPrice(position) {
|
|
342
|
-
return MarketUtils.getPriceVariationToLiquidationPrice(position, this, this.
|
|
342
|
+
return MarketUtils.getPriceVariationToLiquidationPrice(position, this, this.params);
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
345
345
|
* Returns the health factor of a given borrow position (scaled by WAD).
|
|
346
346
|
* @param position The borrow position to consider.
|
|
347
347
|
*/
|
|
348
348
|
getHealthFactor(position) {
|
|
349
|
-
return MarketUtils.getHealthFactor(position, this, this.
|
|
349
|
+
return MarketUtils.getHealthFactor(position, this, this.params);
|
|
350
350
|
}
|
|
351
351
|
/**
|
|
352
352
|
* Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
|
|
@@ -360,7 +360,7 @@ export class Market {
|
|
|
360
360
|
* @param position The borrow position to consider.
|
|
361
361
|
*/
|
|
362
362
|
getBorrowCapacityUsage(position) {
|
|
363
|
-
return MarketUtils.getBorrowCapacityUsage(position, this, this.
|
|
363
|
+
return MarketUtils.getBorrowCapacityUsage(position, this, this.params);
|
|
364
364
|
}
|
|
365
365
|
/**
|
|
366
366
|
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
2
|
-
export interface
|
|
2
|
+
export interface InputMarketParams {
|
|
3
3
|
loanToken: Address;
|
|
4
4
|
collateralToken: Address;
|
|
5
5
|
oracle: Address;
|
|
@@ -9,17 +9,17 @@ export interface MarketParams {
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents a market's configuration (also called market params).
|
|
11
11
|
*/
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class MarketParams implements InputMarketParams {
|
|
13
13
|
private static readonly _CACHE;
|
|
14
14
|
/**
|
|
15
15
|
* Returns the previously cached market config for the given id, if any.
|
|
16
|
-
* @throws {
|
|
16
|
+
* @throws {UnknownMarketParamsError} If no market config is cached.
|
|
17
17
|
*/
|
|
18
|
-
static get(id: MarketId):
|
|
18
|
+
static get(id: MarketId): MarketParams;
|
|
19
19
|
/**
|
|
20
20
|
* Returns the canonical idle market configuration for the given loan token.
|
|
21
21
|
*/
|
|
22
|
-
static idle(token: Address):
|
|
22
|
+
static idle(token: Address): MarketParams;
|
|
23
23
|
/**
|
|
24
24
|
* The market's collateral token address.
|
|
25
25
|
*/
|
|
@@ -48,5 +48,5 @@ export declare class MarketConfig implements MarketParams {
|
|
|
48
48
|
* The market's liquidation incentive factor.
|
|
49
49
|
*/
|
|
50
50
|
readonly liquidationIncentiveFactor: bigint;
|
|
51
|
-
constructor(params:
|
|
51
|
+
constructor(params: InputMarketParams);
|
|
52
52
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { ZERO_ADDRESS } from "@morpho-org/morpho-ts";
|
|
2
|
-
import {
|
|
2
|
+
import { UnknownMarketParamsError } from "../errors.js";
|
|
3
3
|
import { MarketUtils } from "./MarketUtils.js";
|
|
4
4
|
/**
|
|
5
5
|
* Represents a market's configuration (also called market params).
|
|
6
6
|
*/
|
|
7
|
-
export class
|
|
7
|
+
export class MarketParams {
|
|
8
8
|
static _CACHE = {};
|
|
9
9
|
/**
|
|
10
10
|
* Returns the previously cached market config for the given id, if any.
|
|
11
|
-
* @throws {
|
|
11
|
+
* @throws {UnknownMarketParamsError} If no market config is cached.
|
|
12
12
|
*/
|
|
13
13
|
static get(id) {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
16
|
-
throw new
|
|
17
|
-
return
|
|
14
|
+
const marketParams = MarketParams._CACHE[id];
|
|
15
|
+
if (!marketParams)
|
|
16
|
+
throw new UnknownMarketParamsError(id);
|
|
17
|
+
return marketParams;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Returns the canonical idle market configuration for the given loan token.
|
|
21
21
|
*/
|
|
22
22
|
static idle(token) {
|
|
23
|
-
return new
|
|
23
|
+
return new MarketParams({
|
|
24
24
|
collateralToken: ZERO_ADDRESS,
|
|
25
25
|
loanToken: token,
|
|
26
26
|
oracle: ZERO_ADDRESS,
|
|
@@ -68,6 +68,6 @@ export class MarketConfig {
|
|
|
68
68
|
this.id = MarketUtils.getMarketId(params);
|
|
69
69
|
this.liquidationIncentiveFactor =
|
|
70
70
|
MarketUtils.getLiquidationIncentiveFactor(params);
|
|
71
|
-
|
|
71
|
+
MarketParams._CACHE[this.id] = this;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { BigIntish, MarketId } from "../types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { InputMarketParams } from "./MarketParams.js";
|
|
4
4
|
/**
|
|
5
5
|
* Namespace of utility functions to ease market-related calculations.
|
|
6
6
|
*/
|
|
@@ -9,7 +9,7 @@ export declare namespace MarketUtils {
|
|
|
9
9
|
* Returns the id of a market based on its params.
|
|
10
10
|
* @param market The market params.
|
|
11
11
|
*/
|
|
12
|
-
function getMarketId(market:
|
|
12
|
+
function getMarketId(market: InputMarketParams): MarketId;
|
|
13
13
|
/**
|
|
14
14
|
* Returns the liquidation incentive factor for a given market params.
|
|
15
15
|
* @param config The market params.
|
|
@@ -110,7 +110,7 @@ export declare namespace MarketUtils {
|
|
|
110
110
|
totalBorrowAssets: BigIntish;
|
|
111
111
|
totalBorrowShares: BigIntish;
|
|
112
112
|
price: BigIntish;
|
|
113
|
-
},
|
|
113
|
+
}, marketParams: {
|
|
114
114
|
lltv: BigIntish;
|
|
115
115
|
}): bigint;
|
|
116
116
|
function getLiquidationSeizedAssets(repaidShares: BigIntish, market: {
|
|
@@ -154,7 +154,7 @@ export declare namespace MarketUtils {
|
|
|
154
154
|
totalBorrowAssets: BigIntish;
|
|
155
155
|
totalBorrowShares: BigIntish;
|
|
156
156
|
price: BigIntish;
|
|
157
|
-
},
|
|
157
|
+
}, marketParams: {
|
|
158
158
|
lltv: BigIntish;
|
|
159
159
|
}): boolean;
|
|
160
160
|
/**
|
|
@@ -168,7 +168,7 @@ export declare namespace MarketUtils {
|
|
|
168
168
|
}, market: {
|
|
169
169
|
totalBorrowAssets: BigIntish;
|
|
170
170
|
totalBorrowShares: BigIntish;
|
|
171
|
-
},
|
|
171
|
+
}, marketParams: {
|
|
172
172
|
lltv: BigIntish;
|
|
173
173
|
}): bigint | null;
|
|
174
174
|
/**
|
|
@@ -183,7 +183,7 @@ export declare namespace MarketUtils {
|
|
|
183
183
|
totalBorrowAssets: BigIntish;
|
|
184
184
|
totalBorrowShares: BigIntish;
|
|
185
185
|
price: BigIntish;
|
|
186
|
-
},
|
|
186
|
+
}, marketParams: {
|
|
187
187
|
lltv: BigIntish;
|
|
188
188
|
}): bigint | null;
|
|
189
189
|
function getHealthFactor({ collateral, borrowShares, }: {
|
|
@@ -193,7 +193,7 @@ export declare namespace MarketUtils {
|
|
|
193
193
|
totalBorrowAssets: BigIntish;
|
|
194
194
|
totalBorrowShares: BigIntish;
|
|
195
195
|
price: BigIntish;
|
|
196
|
-
},
|
|
196
|
+
}, marketParams: {
|
|
197
197
|
lltv: BigIntish;
|
|
198
198
|
}): bigint | null;
|
|
199
199
|
function getLtv({ collateral, borrowShares, }: {
|
|
@@ -211,7 +211,7 @@ export declare namespace MarketUtils {
|
|
|
211
211
|
totalBorrowAssets: BigIntish;
|
|
212
212
|
totalBorrowShares: BigIntish;
|
|
213
213
|
price: BigIntish;
|
|
214
|
-
},
|
|
214
|
+
}, marketParams: {
|
|
215
215
|
lltv: BigIntish;
|
|
216
216
|
}): bigint | null;
|
|
217
217
|
function toSupplyAssets(shares: BigIntish, market: {
|
|
@@ -140,8 +140,8 @@ export var MarketUtils;
|
|
|
140
140
|
return MathLib.wMulDown(getCollateralValue(collateral, market), lltv);
|
|
141
141
|
}
|
|
142
142
|
MarketUtils.getMaxBorrowAssets = getMaxBorrowAssets;
|
|
143
|
-
function getMaxBorrowableAssets({ collateral, borrowShares, }, market,
|
|
144
|
-
return MathLib.zeroFloorSub(getMaxBorrowAssets(collateral, market,
|
|
143
|
+
function getMaxBorrowableAssets({ collateral, borrowShares, }, market, marketParams) {
|
|
144
|
+
return MathLib.zeroFloorSub(getMaxBorrowAssets(collateral, market, marketParams), toBorrowAssets(borrowShares, market));
|
|
145
145
|
}
|
|
146
146
|
MarketUtils.getMaxBorrowableAssets = getMaxBorrowableAssets;
|
|
147
147
|
function getLiquidationSeizedAssets(repaidShares, market, config) {
|
|
@@ -169,8 +169,8 @@ export var MarketUtils;
|
|
|
169
169
|
return MathLib.zeroFloorSub(collateral, MathLib.wDivUp(MathLib.mulDivUp(toBorrowAssets(borrowShares, market), ORACLE_PRICE_SCALE, market.price), lltv));
|
|
170
170
|
}
|
|
171
171
|
MarketUtils.getWithdrawableCollateral = getWithdrawableCollateral;
|
|
172
|
-
function isHealthy({ collateral, borrowShares, }, market,
|
|
173
|
-
return (getMaxBorrowAssets(collateral, market,
|
|
172
|
+
function isHealthy({ collateral, borrowShares, }, market, marketParams) {
|
|
173
|
+
return (getMaxBorrowAssets(collateral, market, marketParams) >=
|
|
174
174
|
toBorrowAssets(borrowShares, market));
|
|
175
175
|
}
|
|
176
176
|
MarketUtils.isHealthy = isHealthy;
|
|
@@ -179,12 +179,12 @@ export var MarketUtils;
|
|
|
179
179
|
* that set the user's position to be liquidatable.
|
|
180
180
|
* Returns null if the position is not a borrow.
|
|
181
181
|
*/
|
|
182
|
-
function getLiquidationPrice({ collateral, borrowShares, }, market,
|
|
182
|
+
function getLiquidationPrice({ collateral, borrowShares, }, market, marketParams) {
|
|
183
183
|
borrowShares = BigInt(borrowShares);
|
|
184
184
|
market.totalBorrowShares = BigInt(market.totalBorrowShares);
|
|
185
185
|
if (borrowShares === 0n || market.totalBorrowShares === 0n)
|
|
186
186
|
return null;
|
|
187
|
-
const collateralPower = getCollateralPower(collateral,
|
|
187
|
+
const collateralPower = getCollateralPower(collateral, marketParams);
|
|
188
188
|
if (collateralPower === 0n)
|
|
189
189
|
return MathLib.MAX_UINT_256;
|
|
190
190
|
const borrowAssets = toBorrowAssets(borrowShares, market);
|
|
@@ -196,17 +196,17 @@ export var MarketUtils;
|
|
|
196
196
|
* Negative when healthy (the price needs to drop x%), positive when unhealthy (the price needs to soar x%).
|
|
197
197
|
* Returns null if the position is not a borrow.
|
|
198
198
|
*/
|
|
199
|
-
function getPriceVariationToLiquidationPrice(position, market,
|
|
199
|
+
function getPriceVariationToLiquidationPrice(position, market, marketParams) {
|
|
200
200
|
market.price = BigInt(market.price);
|
|
201
201
|
if (market.price === 0n)
|
|
202
202
|
return null;
|
|
203
|
-
const liquidationPrice = getLiquidationPrice(position, market,
|
|
203
|
+
const liquidationPrice = getLiquidationPrice(position, market, marketParams);
|
|
204
204
|
if (liquidationPrice == null)
|
|
205
205
|
return null;
|
|
206
206
|
return MathLib.wDivUp(liquidationPrice, market.price) - MathLib.WAD;
|
|
207
207
|
}
|
|
208
208
|
MarketUtils.getPriceVariationToLiquidationPrice = getPriceVariationToLiquidationPrice;
|
|
209
|
-
function getHealthFactor({ collateral, borrowShares, }, market,
|
|
209
|
+
function getHealthFactor({ collateral, borrowShares, }, market, marketParams) {
|
|
210
210
|
borrowShares = BigInt(borrowShares);
|
|
211
211
|
market.totalBorrowShares = BigInt(market.totalBorrowShares);
|
|
212
212
|
if (borrowShares === 0n || market.totalBorrowShares === 0n)
|
|
@@ -214,7 +214,7 @@ export var MarketUtils;
|
|
|
214
214
|
const borrowAssets = toBorrowAssets(borrowShares, market);
|
|
215
215
|
if (borrowAssets === 0n)
|
|
216
216
|
return MathLib.MAX_UINT_256;
|
|
217
|
-
const maxBorrowAssets = getMaxBorrowAssets(collateral, market,
|
|
217
|
+
const maxBorrowAssets = getMaxBorrowAssets(collateral, market, marketParams);
|
|
218
218
|
return MathLib.wDivDown(maxBorrowAssets, borrowAssets);
|
|
219
219
|
}
|
|
220
220
|
MarketUtils.getHealthFactor = getHealthFactor;
|
|
@@ -229,8 +229,8 @@ export var MarketUtils;
|
|
|
229
229
|
return MathLib.wDivUp(toBorrowAssets(borrowShares, market), collateralValue);
|
|
230
230
|
}
|
|
231
231
|
MarketUtils.getLtv = getLtv;
|
|
232
|
-
function getBorrowCapacityUsage(position, market,
|
|
233
|
-
const hf = getHealthFactor(position, market,
|
|
232
|
+
function getBorrowCapacityUsage(position, market, marketParams) {
|
|
233
|
+
const hf = getHealthFactor(position, market, marketParams);
|
|
234
234
|
if (hf === null)
|
|
235
235
|
return null;
|
|
236
236
|
if (hf === 0n)
|
package/lib/market/index.d.ts
CHANGED
package/lib/market/index.js
CHANGED
package/lib/vault/Vault.js
CHANGED
|
@@ -118,7 +118,7 @@ export class AccrualVault extends Vault {
|
|
|
118
118
|
]));
|
|
119
119
|
this.collateralAllocations = new Map();
|
|
120
120
|
for (const { marketId, position } of this.allocations.values()) {
|
|
121
|
-
const address = position.market.
|
|
121
|
+
const address = position.market.params.collateralToken;
|
|
122
122
|
let exposure = this.collateralAllocations.get(address);
|
|
123
123
|
if (!exposure)
|
|
124
124
|
this.collateralAllocations.set(address, (exposure = {
|
|
@@ -128,8 +128,8 @@ export class AccrualVault extends Vault {
|
|
|
128
128
|
markets: new Set(),
|
|
129
129
|
proportion: 0n,
|
|
130
130
|
}));
|
|
131
|
-
exposure.lltvs.add(position.market.
|
|
132
|
-
exposure.oracles.add(position.market.
|
|
131
|
+
exposure.lltvs.add(position.market.params.lltv);
|
|
132
|
+
exposure.oracles.add(position.market.params.oracle);
|
|
133
133
|
exposure.markets.add(marketId);
|
|
134
134
|
exposure.proportion += this.getAllocationProportion(marketId);
|
|
135
135
|
}
|
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": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.9",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|