@morpho-org/blue-sdk 1.7.3 → 1.7.5
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/market/Market.d.ts +14 -5
- package/lib/market/Market.js +15 -11
- package/lib/position/Position.d.ts +5 -2
- package/lib/position/Position.js +2 -2
- package/package.json +5 -5
package/lib/market/Market.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface CapacityLimit {
|
|
|
12
12
|
value: bigint;
|
|
13
13
|
limiter: CapacityLimitReason;
|
|
14
14
|
}
|
|
15
|
+
export interface MaxBorrowOptions {
|
|
16
|
+
maxLtv?: bigint;
|
|
17
|
+
}
|
|
18
|
+
export interface MaxWithdrawCollateralOptions {
|
|
19
|
+
maxLtv?: bigint;
|
|
20
|
+
}
|
|
15
21
|
export interface MaxPositionCapacities {
|
|
16
22
|
supply: CapacityLimit;
|
|
17
23
|
withdraw: CapacityLimit;
|
|
@@ -190,7 +196,7 @@ export declare class Market implements InputMarket {
|
|
|
190
196
|
* Returns the maximum amount of loan assets that can be borrowed given a certain amount of collateral.
|
|
191
197
|
* @param collateral The amount of collateral to consider.
|
|
192
198
|
*/
|
|
193
|
-
getMaxBorrowAssets(collateral: bigint): bigint;
|
|
199
|
+
getMaxBorrowAssets(collateral: bigint, { maxLtv }?: MaxBorrowOptions): bigint;
|
|
194
200
|
/**
|
|
195
201
|
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
|
|
196
202
|
* @param position The borrow position to consider.
|
|
@@ -224,7 +230,7 @@ export declare class Market implements InputMarket {
|
|
|
224
230
|
getWithdrawableCollateral(position: {
|
|
225
231
|
collateral: bigint;
|
|
226
232
|
borrowShares: bigint;
|
|
227
|
-
}): bigint;
|
|
233
|
+
}, { maxLtv }?: MaxWithdrawCollateralOptions): bigint;
|
|
228
234
|
/**
|
|
229
235
|
* Returns whether a given borrow position is healthy.
|
|
230
236
|
* @param position The borrow position to check.
|
|
@@ -281,7 +287,7 @@ export declare class Market implements InputMarket {
|
|
|
281
287
|
getBorrowCapacityLimit({ collateral, borrowShares, }: {
|
|
282
288
|
collateral: bigint;
|
|
283
289
|
borrowShares?: bigint;
|
|
284
|
-
}): CapacityLimit;
|
|
290
|
+
}, options?: MaxBorrowOptions): CapacityLimit;
|
|
285
291
|
/**
|
|
286
292
|
* Returns the maximum amount of loan assets that can be repaid given a certain borrow position
|
|
287
293
|
* and a balance of loan assets, and the reason for the limit.
|
|
@@ -304,7 +310,7 @@ export declare class Market implements InputMarket {
|
|
|
304
310
|
getWithdrawCollateralCapacityLimit(position: {
|
|
305
311
|
collateral: bigint;
|
|
306
312
|
borrowShares: bigint;
|
|
307
|
-
}): CapacityLimit;
|
|
313
|
+
}, options?: MaxWithdrawCollateralOptions): CapacityLimit;
|
|
308
314
|
/**
|
|
309
315
|
* Returns the maximum capacity for all interactions with Morpho Blue given a certain position
|
|
310
316
|
* and loan and collateral balances.
|
|
@@ -316,5 +322,8 @@ export declare class Market implements InputMarket {
|
|
|
316
322
|
collateral: bigint;
|
|
317
323
|
supplyShares: bigint;
|
|
318
324
|
borrowShares: bigint;
|
|
319
|
-
}, loanTokenBalance: bigint, collateralTokenBalance: bigint
|
|
325
|
+
}, loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
|
|
326
|
+
borrow?: MaxBorrowOptions;
|
|
327
|
+
withdrawCollateral?: MaxWithdrawCollateralOptions;
|
|
328
|
+
}): MaxPositionCapacities;
|
|
320
329
|
}
|
package/lib/market/Market.js
CHANGED
|
@@ -278,8 +278,10 @@ class Market {
|
|
|
278
278
|
* Returns the maximum amount of loan assets that can be borrowed given a certain amount of collateral.
|
|
279
279
|
* @param collateral The amount of collateral to consider.
|
|
280
280
|
*/
|
|
281
|
-
getMaxBorrowAssets(collateral) {
|
|
282
|
-
return MarketUtils_1.MarketUtils.getMaxBorrowAssets(collateral, this,
|
|
281
|
+
getMaxBorrowAssets(collateral, { maxLtv = this.config.lltv } = {}) {
|
|
282
|
+
return MarketUtils_1.MarketUtils.getMaxBorrowAssets(collateral, this, {
|
|
283
|
+
lltv: maths_1.MathLib.min(maxLtv, this.config.lltv),
|
|
284
|
+
});
|
|
283
285
|
}
|
|
284
286
|
/**
|
|
285
287
|
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
|
|
@@ -313,8 +315,10 @@ class Market {
|
|
|
313
315
|
* Returns the amount of collateral that can be withdrawn given a certain borrow position.
|
|
314
316
|
* @param position The borrow position to consider.
|
|
315
317
|
*/
|
|
316
|
-
getWithdrawableCollateral(position) {
|
|
317
|
-
return MarketUtils_1.MarketUtils.getWithdrawableCollateral(position, this,
|
|
318
|
+
getWithdrawableCollateral(position, { maxLtv = this.config.lltv } = {}) {
|
|
319
|
+
return MarketUtils_1.MarketUtils.getWithdrawableCollateral(position, this, {
|
|
320
|
+
lltv: maths_1.MathLib.min(maxLtv, this.config.lltv),
|
|
321
|
+
});
|
|
318
322
|
}
|
|
319
323
|
/**
|
|
320
324
|
* Returns whether a given borrow position is healthy.
|
|
@@ -363,9 +367,9 @@ class Market {
|
|
|
363
367
|
* and the reason for the limit.
|
|
364
368
|
* @param position The borrow position to consider.
|
|
365
369
|
*/
|
|
366
|
-
getBorrowCapacityLimit({ collateral, borrowShares = 0n, }) {
|
|
370
|
+
getBorrowCapacityLimit({ collateral, borrowShares = 0n, }, options) {
|
|
367
371
|
// handle edge cases when the user is liquidatable (maxBorrow < borrow)
|
|
368
|
-
const maxBorrowableAssets = maths_1.MathLib.zeroFloorSub(this.getMaxBorrowAssets(collateral), this.toBorrowAssets(borrowShares));
|
|
372
|
+
const maxBorrowableAssets = maths_1.MathLib.zeroFloorSub(this.getMaxBorrowAssets(collateral, options), this.toBorrowAssets(borrowShares));
|
|
369
373
|
const { liquidity } = this;
|
|
370
374
|
if (maxBorrowableAssets > liquidity)
|
|
371
375
|
return {
|
|
@@ -417,8 +421,8 @@ class Market {
|
|
|
417
421
|
* and the reason for the limit.
|
|
418
422
|
* @param position The borrow position to consider.
|
|
419
423
|
*/
|
|
420
|
-
getWithdrawCollateralCapacityLimit(position) {
|
|
421
|
-
const withdrawableCollateral = this.getWithdrawableCollateral(position);
|
|
424
|
+
getWithdrawCollateralCapacityLimit(position, options) {
|
|
425
|
+
const withdrawableCollateral = this.getWithdrawableCollateral(position, options);
|
|
422
426
|
if (position.collateral > withdrawableCollateral)
|
|
423
427
|
return {
|
|
424
428
|
value: withdrawableCollateral,
|
|
@@ -436,20 +440,20 @@ class Market {
|
|
|
436
440
|
* @param loanTokenBalance The balance of loan assets.
|
|
437
441
|
* @param collateralTokenBalance The balance of collateral assets.
|
|
438
442
|
*/
|
|
439
|
-
getMaxCapacities(position, loanTokenBalance, collateralTokenBalance) {
|
|
443
|
+
getMaxCapacities(position, loanTokenBalance, collateralTokenBalance, options) {
|
|
440
444
|
return {
|
|
441
445
|
supply: {
|
|
442
446
|
value: loanTokenBalance,
|
|
443
447
|
limiter: CapacityLimitReason.balance,
|
|
444
448
|
},
|
|
445
449
|
withdraw: this.getWithdrawCapacityLimit(position),
|
|
446
|
-
borrow: this.getBorrowCapacityLimit(position),
|
|
450
|
+
borrow: this.getBorrowCapacityLimit(position, options?.borrow),
|
|
447
451
|
repay: this.getRepayCapacityLimit(position.borrowShares, loanTokenBalance),
|
|
448
452
|
supplyCollateral: {
|
|
449
453
|
value: collateralTokenBalance,
|
|
450
454
|
limiter: CapacityLimitReason.balance,
|
|
451
455
|
},
|
|
452
|
-
withdrawCollateral: this.getWithdrawCollateralCapacityLimit(position),
|
|
456
|
+
withdrawCollateral: this.getWithdrawCollateralCapacityLimit(position, options?.withdrawCollateral),
|
|
453
457
|
};
|
|
454
458
|
}
|
|
455
459
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Market } from "../market";
|
|
1
|
+
import { Market, MaxBorrowOptions, MaxWithdrawCollateralOptions } from "../market";
|
|
2
2
|
import { Address, BigIntish, MarketId } from "../types";
|
|
3
3
|
export interface InputPosition {
|
|
4
4
|
user: Address;
|
|
@@ -119,5 +119,8 @@ export declare class AccrualPosition extends Position implements InputAccrualPos
|
|
|
119
119
|
shares: bigint;
|
|
120
120
|
};
|
|
121
121
|
getRepayCapacityLimit(loanTokenBalance: bigint): import("../market").CapacityLimit;
|
|
122
|
-
getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint
|
|
122
|
+
getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
|
|
123
|
+
borrow?: MaxBorrowOptions;
|
|
124
|
+
withdrawCollateral?: MaxWithdrawCollateralOptions;
|
|
125
|
+
}): import("../market").MaxPositionCapacities;
|
|
123
126
|
}
|
package/lib/position/Position.js
CHANGED
|
@@ -196,8 +196,8 @@ class AccrualPosition extends Position {
|
|
|
196
196
|
getRepayCapacityLimit(loanTokenBalance) {
|
|
197
197
|
return this.market.getRepayCapacityLimit(this.borrowShares, loanTokenBalance);
|
|
198
198
|
}
|
|
199
|
-
getMaxCapacities(loanTokenBalance, collateralTokenBalance) {
|
|
200
|
-
return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance);
|
|
199
|
+
getMaxCapacities(loanTokenBalance, collateralTokenBalance, options) {
|
|
200
|
+
return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance, options);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
exports.AccrualPosition = AccrualPosition;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"author": "Morpho Association <contact@morpho.org>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"keccak256": "^1.0.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@morpho-org/morpho-test": "^1.7.
|
|
20
|
-
"@morpho-org/morpho-ts": "^1.7.
|
|
19
|
+
"@morpho-org/morpho-test": "^1.7.5",
|
|
20
|
+
"@morpho-org/morpho-ts": "^1.7.5",
|
|
21
21
|
"@types/jest": "^29.5.12",
|
|
22
22
|
"@types/node": "^22.1.0",
|
|
23
23
|
"jest": "^29.7.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"typescript": "^5.4.5"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@morpho-org/morpho-ts": "^1.7.
|
|
28
|
+
"@morpho-org/morpho-ts": "^1.7.5"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
],
|
|
50
50
|
"preset": "ts-jest"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "6c51df2e43f997e52ae7a62b9778e7cfbdf18971"
|
|
53
53
|
}
|