@morpho-org/morpho-sdk 3.1.1 → 4.0.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/README.md +63 -13
- package/lib/cjs/actions/{marketV1 → blue}/borrow.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/borrow.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/buildReallocationActions.d.ts +1 -1
- package/lib/cjs/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
- package/lib/cjs/actions/{marketV1 → blue}/index.d.ts +1 -0
- package/lib/cjs/actions/{marketV1 → blue}/index.js +1 -0
- package/lib/cjs/actions/blue/refinance.d.ts +117 -0
- package/lib/cjs/actions/blue/refinance.js +218 -0
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repay.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/repay.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/repayWithdrawCollateral.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supply.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supply.js +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateral.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/supplyCollateralBorrow.js +8 -8
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdraw.d.ts +11 -11
- package/lib/cjs/actions/{marketV1 → blue}/withdraw.js +10 -10
- package/lib/{esm/actions/marketV1 → cjs/actions/blue}/withdrawCollateral.d.ts +8 -8
- package/lib/cjs/actions/{marketV1 → blue}/withdrawCollateral.js +8 -8
- package/lib/cjs/actions/index.d.ts +2 -2
- package/lib/cjs/actions/index.js +1 -1
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
- package/lib/cjs/client/index.d.ts +0 -1
- package/lib/cjs/client/index.js +0 -1
- package/lib/cjs/client/morphoViemExtension.d.ts +17 -11
- package/lib/cjs/client/morphoViemExtension.js +55 -10
- package/lib/cjs/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +76 -21
- package/lib/cjs/entities/{marketV1/marketV1.js → blue/blue.js} +169 -11
- package/lib/cjs/entities/blue/index.d.ts +1 -0
- package/lib/cjs/entities/{marketV1 → blue}/index.js +1 -1
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/index.js +3 -3
- package/lib/cjs/entities/reallocationData.d.ts +1 -1
- package/lib/cjs/entities/reallocationData.js +1 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
- package/lib/cjs/helpers/computeReallocations.d.ts +1 -1
- package/lib/cjs/helpers/computeReallocations.js +1 -1
- package/lib/cjs/helpers/validate.d.ts +2 -2
- package/lib/cjs/helpers/validate.js +2 -2
- package/lib/cjs/types/action.d.ts +21 -9
- package/lib/cjs/types/client.d.ts +5 -4
- package/lib/cjs/types/error.d.ts +57 -0
- package/lib/cjs/types/error.js +82 -1
- package/lib/esm/actions/{marketV1 → blue}/borrow.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/borrow.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/buildReallocationActions.d.ts +1 -1
- package/lib/esm/actions/{marketV1 → blue}/buildReallocationActions.js +1 -1
- package/lib/esm/actions/{marketV1 → blue}/index.d.ts +1 -0
- package/lib/esm/actions/{marketV1 → blue}/index.js +1 -0
- package/lib/esm/actions/blue/refinance.d.ts +117 -0
- package/lib/esm/actions/blue/refinance.js +214 -0
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repay.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/repay.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/repayWithdrawCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/repayWithdrawCollateral.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supply.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supply.js +6 -6
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateral.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/supplyCollateralBorrow.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/supplyCollateralBorrow.js +6 -6
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdraw.d.ts +11 -11
- package/lib/esm/actions/{marketV1 → blue}/withdraw.js +8 -8
- package/lib/{cjs/actions/marketV1 → esm/actions/blue}/withdrawCollateral.d.ts +8 -8
- package/lib/esm/actions/{marketV1 → blue}/withdrawCollateral.js +6 -6
- package/lib/esm/actions/index.d.ts +2 -2
- package/lib/esm/actions/index.js +1 -1
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +1 -1
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +1 -1
- package/lib/esm/client/index.d.ts +0 -1
- package/lib/esm/client/index.js +0 -1
- package/lib/esm/client/morphoViemExtension.d.ts +17 -11
- package/lib/esm/client/morphoViemExtension.js +55 -10
- package/lib/esm/entities/{marketV1/marketV1.d.ts → blue/blue.d.ts} +76 -21
- package/lib/esm/entities/{marketV1/marketV1.js → blue/blue.js} +170 -12
- package/lib/esm/entities/blue/index.d.ts +1 -0
- package/lib/esm/entities/blue/index.js +1 -0
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/index.js +1 -1
- package/lib/esm/entities/reallocationData.d.ts +1 -1
- package/lib/esm/entities/reallocationData.js +1 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
- package/lib/esm/helpers/computeReallocations.d.ts +1 -1
- package/lib/esm/helpers/computeReallocations.js +1 -1
- package/lib/esm/helpers/validate.d.ts +2 -2
- package/lib/esm/helpers/validate.js +2 -2
- package/lib/esm/types/action.d.ts +21 -9
- package/lib/esm/types/client.d.ts +5 -4
- package/lib/esm/types/error.d.ts +57 -0
- package/lib/esm/types/error.js +72 -0
- package/package.json +6 -6
- package/lib/cjs/client/morphoClient.d.ts +0 -152
- package/lib/cjs/client/morphoClient.js +0 -162
- package/lib/cjs/entities/marketV1/index.d.ts +0 -1
- package/lib/esm/client/morphoClient.d.ts +0 -152
- package/lib/esm/client/morphoClient.js +0 -158
- package/lib/esm/entities/marketV1/index.d.ts +0 -1
- package/lib/esm/entities/marketV1/index.js +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MorphoBlue = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
7
8
|
const index_js_1 = require("../../actions/index.js");
|
|
8
9
|
const index_js_2 = require("../../helpers/index.js");
|
|
9
10
|
const index_js_3 = require("../../types/index.js");
|
|
10
11
|
const reallocationData_js_1 = require("../reallocationData.js");
|
|
11
|
-
class
|
|
12
|
+
class MorphoBlue {
|
|
12
13
|
client;
|
|
13
14
|
marketParams;
|
|
14
15
|
chainId;
|
|
@@ -67,7 +68,7 @@ class MorphoMarketV1 {
|
|
|
67
68
|
useSimplePermit: params?.useSimplePermit,
|
|
68
69
|
args: { amount, from: userAddress },
|
|
69
70
|
}),
|
|
70
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
71
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupply)({
|
|
71
72
|
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
72
73
|
args: {
|
|
73
74
|
amount,
|
|
@@ -135,7 +136,7 @@ class MorphoMarketV1 {
|
|
|
135
136
|
});
|
|
136
137
|
return authTx ? [authTx] : [];
|
|
137
138
|
},
|
|
138
|
-
buildTx: () => (0, index_js_1.
|
|
139
|
+
buildTx: () => (0, index_js_1.blueWithdraw)({
|
|
139
140
|
market: { chainId: this.chainId, marketParams: this.marketParams },
|
|
140
141
|
args: {
|
|
141
142
|
assets,
|
|
@@ -172,7 +173,7 @@ class MorphoMarketV1 {
|
|
|
172
173
|
useSimplePermit: params?.useSimplePermit,
|
|
173
174
|
args: { amount, from: userAddress },
|
|
174
175
|
}),
|
|
175
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
176
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupplyCollateral)({
|
|
176
177
|
market: {
|
|
177
178
|
chainId: this.chainId,
|
|
178
179
|
marketParams: this.marketParams,
|
|
@@ -222,7 +223,7 @@ class MorphoMarketV1 {
|
|
|
222
223
|
});
|
|
223
224
|
return authTx ? [authTx] : [];
|
|
224
225
|
},
|
|
225
|
-
buildTx: () => (0, index_js_1.
|
|
226
|
+
buildTx: () => (0, index_js_1.blueBorrow)({
|
|
226
227
|
market: {
|
|
227
228
|
chainId: this.chainId,
|
|
228
229
|
marketParams: this.marketParams,
|
|
@@ -308,7 +309,7 @@ class MorphoMarketV1 {
|
|
|
308
309
|
useSimplePermit: reqParams?.useSimplePermit,
|
|
309
310
|
args: { amount: transferAmount, from: userAddress },
|
|
310
311
|
}),
|
|
311
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
312
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueRepay)({
|
|
312
313
|
market: {
|
|
313
314
|
chainId: this.chainId,
|
|
314
315
|
marketParams: this.marketParams,
|
|
@@ -353,7 +354,7 @@ class MorphoMarketV1 {
|
|
|
353
354
|
marketId: this.marketParams.id,
|
|
354
355
|
});
|
|
355
356
|
return {
|
|
356
|
-
buildTx: () => (0, index_js_1.
|
|
357
|
+
buildTx: () => (0, index_js_1.blueWithdrawCollateral)({
|
|
357
358
|
market: {
|
|
358
359
|
chainId: this.chainId,
|
|
359
360
|
marketParams: this.marketParams,
|
|
@@ -465,7 +466,7 @@ class MorphoMarketV1 {
|
|
|
465
466
|
]);
|
|
466
467
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
467
468
|
},
|
|
468
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
469
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueRepayWithdrawCollateral)({
|
|
469
470
|
market: {
|
|
470
471
|
chainId: this.chainId,
|
|
471
472
|
marketParams: this.marketParams,
|
|
@@ -542,7 +543,7 @@ class MorphoMarketV1 {
|
|
|
542
543
|
]);
|
|
543
544
|
return [...erc20Requirements, ...(authTx ? [authTx] : [])];
|
|
544
545
|
},
|
|
545
|
-
buildTx: (requirementSignature) => (0, index_js_1.
|
|
546
|
+
buildTx: (requirementSignature) => (0, index_js_1.blueSupplyCollateralBorrow)({
|
|
546
547
|
market: {
|
|
547
548
|
chainId: this.chainId,
|
|
548
549
|
marketParams: this.marketParams,
|
|
@@ -561,6 +562,163 @@ class MorphoMarketV1 {
|
|
|
561
562
|
}),
|
|
562
563
|
};
|
|
563
564
|
}
|
|
565
|
+
refinance({ userAddress, positionData, target, collateralAmount, borrowAssets, borrowShares, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, targetReallocations, }) {
|
|
566
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
567
|
+
(0, index_js_2.validateSlippageTolerance)(slippageTolerance);
|
|
568
|
+
if (collateralAmount <= 0n) {
|
|
569
|
+
throw new index_js_3.ZeroCollateralAmountError(this.marketParams.id);
|
|
570
|
+
}
|
|
571
|
+
if (!positionData) {
|
|
572
|
+
throw new index_js_3.MissingAccrualPositionError(this.marketParams.id);
|
|
573
|
+
}
|
|
574
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
575
|
+
positionData,
|
|
576
|
+
expectedMarketId: this.marketParams.id,
|
|
577
|
+
expectedUser: userAddress,
|
|
578
|
+
});
|
|
579
|
+
if (this.marketParams.id === target.marketParams.id) {
|
|
580
|
+
throw new index_js_3.RefinanceSameMarketError(this.marketParams.id);
|
|
581
|
+
}
|
|
582
|
+
if (!(0, viem_1.isAddressEqual)(this.marketParams.collateralToken, target.marketParams.collateralToken) ||
|
|
583
|
+
!(0, viem_1.isAddressEqual)(this.marketParams.loanToken, target.marketParams.loanToken)) {
|
|
584
|
+
throw new index_js_3.RefinanceTokenMismatchError(this.marketParams.id, target.marketParams.id);
|
|
585
|
+
}
|
|
586
|
+
(0, index_js_2.validateAccrualPosition)({
|
|
587
|
+
positionData: target.positionData,
|
|
588
|
+
expectedMarketId: target.marketParams.id,
|
|
589
|
+
expectedUser: userAddress,
|
|
590
|
+
});
|
|
591
|
+
const requestedAssets = borrowAssets ?? 0n;
|
|
592
|
+
const requestedShares = borrowShares ?? 0n;
|
|
593
|
+
// Reject negative debt up front; otherwise it slips past the `> 0n` mode checks and only fails at buildTx().
|
|
594
|
+
if (requestedAssets < 0n) {
|
|
595
|
+
throw new index_js_3.NonPositiveAssetAmountError(this.marketParams.loanToken);
|
|
596
|
+
}
|
|
597
|
+
if (requestedShares < 0n) {
|
|
598
|
+
throw new index_js_3.NegativeBorrowSharesError(this.marketParams.id);
|
|
599
|
+
}
|
|
600
|
+
if (requestedAssets > 0n && requestedShares > 0n) {
|
|
601
|
+
throw new index_js_3.BorrowAmountAndSharesExclusiveError(this.marketParams.id);
|
|
602
|
+
}
|
|
603
|
+
const sharesMode = requestedShares > 0n;
|
|
604
|
+
const shouldMigrateBorrow = requestedAssets > 0n || sharesMode;
|
|
605
|
+
if (collateralAmount > positionData.collateral) {
|
|
606
|
+
throw new index_js_3.RefinanceExceedsCollateralError({
|
|
607
|
+
market: this.marketParams.id,
|
|
608
|
+
requested: collateralAmount,
|
|
609
|
+
available: positionData.collateral,
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (requestedShares > positionData.borrowShares) {
|
|
613
|
+
throw new index_js_3.RefinanceExceedsBorrowSharesError({
|
|
614
|
+
market: this.marketParams.id,
|
|
615
|
+
requested: requestedShares,
|
|
616
|
+
available: positionData.borrowShares,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
if (requestedAssets > positionData.borrowAssets) {
|
|
620
|
+
throw new index_js_3.RefinanceExceedsBorrowAssetsError({
|
|
621
|
+
market: this.marketParams.id,
|
|
622
|
+
requested: requestedAssets,
|
|
623
|
+
available: positionData.borrowAssets,
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
// Forward-accrue both markets to now (clamped to lastUpdate). Source gets a 2h buffer in
|
|
627
|
+
// shares mode (as in repay()) for repay headroom; target accrues without buffer to avoid
|
|
628
|
+
// tightening minBorrowSharePrice past on-chain reality.
|
|
629
|
+
const sourceAccrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
|
|
630
|
+
(sharesMode ? morpho_ts_1.Time.s.from.h(2n) : 0n);
|
|
631
|
+
const targetAccrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), target.positionData.market.lastUpdate);
|
|
632
|
+
const accruedSource = positionData.market.accrueInterest(sourceAccrualTimestamp);
|
|
633
|
+
const accruedTarget = target.positionData.market.accrueInterest(targetAccrualTimestamp);
|
|
634
|
+
// Shares burned by the source repay: exact in shares mode, else mirror Morpho's toSharesDown.
|
|
635
|
+
const repaidShares = sharesMode
|
|
636
|
+
? requestedShares
|
|
637
|
+
: accruedSource.toBorrowShares(requestedAssets, "Down");
|
|
638
|
+
// Post-state source health: any remaining debt must stay healthy (accrued market).
|
|
639
|
+
const remainingCollateral = positionData.collateral - collateralAmount;
|
|
640
|
+
const remainingShares = positionData.borrowShares - repaidShares;
|
|
641
|
+
if (remainingShares > 0n) {
|
|
642
|
+
const residualPosition = new blue_sdk_1.AccrualPosition({
|
|
643
|
+
user: positionData.user,
|
|
644
|
+
supplyShares: positionData.supplyShares,
|
|
645
|
+
borrowShares: remainingShares,
|
|
646
|
+
collateral: remainingCollateral,
|
|
647
|
+
}, accruedSource);
|
|
648
|
+
(0, index_js_2.validatePositionHealth)({
|
|
649
|
+
positionData: residualPosition,
|
|
650
|
+
additionalCollateral: 0n,
|
|
651
|
+
borrowAmount: 0n,
|
|
652
|
+
marketId: this.marketParams.id,
|
|
653
|
+
lltv: this.marketParams.lltv,
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
const projectedBorrowAssets = sharesMode
|
|
657
|
+
? accruedSource.toBorrowAssets(requestedShares, "Up")
|
|
658
|
+
: requestedAssets;
|
|
659
|
+
// Shares-mode overshoot covers target drift + accrual on the borrow leg. Computed before the
|
|
660
|
+
// LLTV check so health validates the actual on-chain borrow, not the smaller projected value.
|
|
661
|
+
const borrowAssetsAdjusted = sharesMode
|
|
662
|
+
? blue_sdk_1.MathLib.wMulUp(projectedBorrowAssets, blue_sdk_1.MathLib.WAD + slippageTolerance)
|
|
663
|
+
: projectedBorrowAssets;
|
|
664
|
+
// Post-state target health: aggregate must respect LLTV − buffer. Skipped for collat-only
|
|
665
|
+
// refinances, which can't degrade target health and would fail on missing-oracle markets.
|
|
666
|
+
if (shouldMigrateBorrow) {
|
|
667
|
+
const accruedTargetPosition = target.positionData.accrueInterest(targetAccrualTimestamp);
|
|
668
|
+
(0, index_js_2.validatePositionHealth)({
|
|
669
|
+
positionData: accruedTargetPosition,
|
|
670
|
+
additionalCollateral: collateralAmount,
|
|
671
|
+
borrowAmount: borrowAssetsAdjusted,
|
|
672
|
+
marketId: target.marketParams.id,
|
|
673
|
+
lltv: target.marketParams.lltv,
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
// Share-price bounds only when a debt leg exists (helpers throw on zero inputs); else 0n.
|
|
677
|
+
// Derived from borrowAssetsAdjusted (the encoded value) so rounding can't push the on-chain
|
|
678
|
+
// ratio below a guard computed from the smaller projected amount.
|
|
679
|
+
const minBorrowSharePrice = shouldMigrateBorrow
|
|
680
|
+
? (0, index_js_2.computeMinBorrowSharePrice)({
|
|
681
|
+
borrowAmount: borrowAssetsAdjusted,
|
|
682
|
+
market: accruedTarget,
|
|
683
|
+
slippageTolerance,
|
|
684
|
+
})
|
|
685
|
+
: 0n;
|
|
686
|
+
const maxRepaySharePrice = shouldMigrateBorrow
|
|
687
|
+
? (0, index_js_2.computeMaxRepaySharePrice)({
|
|
688
|
+
repayAssets: requestedAssets,
|
|
689
|
+
repayShares: requestedShares,
|
|
690
|
+
market: accruedSource,
|
|
691
|
+
slippageTolerance,
|
|
692
|
+
})
|
|
693
|
+
: 0n;
|
|
694
|
+
return {
|
|
695
|
+
getRequirements: async () => {
|
|
696
|
+
const authTx = await (0, index_js_1.getMorphoAuthorizationRequirement)({
|
|
697
|
+
viemClient: this.client.viemClient,
|
|
698
|
+
chainId: this.chainId,
|
|
699
|
+
userAddress,
|
|
700
|
+
});
|
|
701
|
+
return authTx ? [authTx] : [];
|
|
702
|
+
},
|
|
703
|
+
buildTx: () => (0, index_js_1.blueRefinance)({
|
|
704
|
+
source: {
|
|
705
|
+
chainId: this.chainId,
|
|
706
|
+
marketParams: this.marketParams,
|
|
707
|
+
},
|
|
708
|
+
target: { marketParams: target.marketParams },
|
|
709
|
+
args: {
|
|
710
|
+
user: userAddress,
|
|
711
|
+
collateralAmount,
|
|
712
|
+
borrowAssets: borrowAssetsAdjusted,
|
|
713
|
+
borrowShares: requestedShares,
|
|
714
|
+
minBorrowSharePrice,
|
|
715
|
+
maxRepaySharePrice,
|
|
716
|
+
targetReallocations,
|
|
717
|
+
},
|
|
718
|
+
metadata: this.client.options.metadata,
|
|
719
|
+
}),
|
|
720
|
+
};
|
|
721
|
+
}
|
|
564
722
|
/**
|
|
565
723
|
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
566
724
|
*
|
|
@@ -678,4 +836,4 @@ class MorphoMarketV1 {
|
|
|
678
836
|
});
|
|
679
837
|
}
|
|
680
838
|
}
|
|
681
|
-
exports.
|
|
839
|
+
exports.MorphoBlue = MorphoBlue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./blue.js";
|
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./blue.js"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
3
|
-
export {
|
|
3
|
+
export { MorphoBlue } from "./blue/index.js";
|
|
4
4
|
export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
|
|
5
5
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
6
6
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.
|
|
3
|
+
exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.MorphoBlue = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.Token = exports.PreLiquidationPosition = exports.PreLiquidationParams = exports.Position = exports.MarketParams = exports.Market = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
Object.defineProperty(exports, "AccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
|
|
6
6
|
Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
|
|
@@ -33,8 +33,8 @@ Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: tru
|
|
|
33
33
|
Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
|
|
34
34
|
Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
|
|
35
35
|
Object.defineProperty(exports, "WrappedToken", { enumerable: true, get: function () { return blue_sdk_1.WrappedToken; } });
|
|
36
|
-
var index_js_1 = require("./
|
|
37
|
-
Object.defineProperty(exports, "
|
|
36
|
+
var index_js_1 = require("./blue/index.js");
|
|
37
|
+
Object.defineProperty(exports, "MorphoBlue", { enumerable: true, get: function () { return index_js_1.MorphoBlue; } });
|
|
38
38
|
var reallocationData_js_1 = require("./reallocationData.js");
|
|
39
39
|
Object.defineProperty(exports, "ReallocationData", { enumerable: true, get: function () { return reallocationData_js_1.ReallocationData; } });
|
|
40
40
|
var index_js_2 = require("./vaultV1/index.js");
|
|
@@ -140,7 +140,7 @@ export declare class ReallocationData implements InputReallocationData {
|
|
|
140
140
|
* }).extend(morphoViemExtension());
|
|
141
141
|
*
|
|
142
142
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
143
|
-
* const market = client.morpho.
|
|
143
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
144
144
|
* const block = await client.getBlock();
|
|
145
145
|
* const reallocationData = await market.getReallocationData({
|
|
146
146
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -232,7 +232,7 @@ class ReallocationData {
|
|
|
232
232
|
* }).extend(morphoViemExtension());
|
|
233
233
|
*
|
|
234
234
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
235
|
-
* const market = client.morpho.
|
|
235
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
236
236
|
* const block = await client.getBlock();
|
|
237
237
|
* const reallocationData = await market.getReallocationData({
|
|
238
238
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -62,7 +62,7 @@ class MorphoVaultV2 {
|
|
|
62
62
|
}
|
|
63
63
|
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
64
64
|
// Accrue interest forward to bound the on-chain share price at execution.
|
|
65
|
-
// Mirrors
|
|
65
|
+
// Mirrors blue repay's 2h forward-accrual buffer.
|
|
66
66
|
const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), vaultData.lastUpdate) + morpho_ts_1.Time.s.from.h(2n);
|
|
67
67
|
const { vault: accruedVault } = vaultData.accrueInterest(accrualTimestamp);
|
|
68
68
|
const shares = accruedVault.toShares(totalAssets);
|
|
@@ -42,7 +42,7 @@ import { type ReallocationComputeOptions, type VaultReallocation } from "../type
|
|
|
42
42
|
*
|
|
43
43
|
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
44
44
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
45
|
-
* const market = client.morpho.
|
|
45
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
46
46
|
* const block = await client.getBlock();
|
|
47
47
|
* const reallocationData = await market.getReallocationData({
|
|
48
48
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -98,7 +98,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
98
98
|
*
|
|
99
99
|
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
100
100
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
101
|
-
* const market = client.morpho.
|
|
101
|
+
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
102
102
|
* const block = await client.getBlock();
|
|
103
103
|
* const reallocationData = await market.getReallocationData({
|
|
104
104
|
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
@@ -122,8 +122,8 @@ export declare const validateRepayShares: (params: {
|
|
|
122
122
|
marketId: MarketId;
|
|
123
123
|
}) => void;
|
|
124
124
|
/**
|
|
125
|
-
* Validates the common repay input parameters shared by `
|
|
126
|
-
* and `
|
|
125
|
+
* Validates the common repay input parameters shared by `blueRepay`
|
|
126
|
+
* and `blueRepayWithdrawCollateral`.
|
|
127
127
|
*
|
|
128
128
|
* @param params - Validation parameters.
|
|
129
129
|
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
@@ -212,8 +212,8 @@ const validateRepayShares = (params) => {
|
|
|
212
212
|
};
|
|
213
213
|
exports.validateRepayShares = validateRepayShares;
|
|
214
214
|
/**
|
|
215
|
-
* Validates the common repay input parameters shared by `
|
|
216
|
-
* and `
|
|
215
|
+
* Validates the common repay input parameters shared by `blueRepay`
|
|
216
|
+
* and `blueRepayWithdrawCollateral`.
|
|
217
217
|
*
|
|
218
218
|
* @param params - Validation parameters.
|
|
219
219
|
* @param params.assets - Repay assets amount (0n when repaying by shares).
|
|
@@ -81,7 +81,7 @@ export interface VaultV1MigrateToV2Action extends BaseAction<"vaultV1MigrateToV2
|
|
|
81
81
|
recipient: Address;
|
|
82
82
|
}> {
|
|
83
83
|
}
|
|
84
|
-
export interface
|
|
84
|
+
export interface BlueSupplyAction extends BaseAction<"blueSupply", {
|
|
85
85
|
market: Hex;
|
|
86
86
|
amount: bigint;
|
|
87
87
|
onBehalf: Address;
|
|
@@ -89,7 +89,7 @@ export interface MarketV1SupplyAction extends BaseAction<"marketV1Supply", {
|
|
|
89
89
|
nativeAmount?: bigint;
|
|
90
90
|
}> {
|
|
91
91
|
}
|
|
92
|
-
export interface
|
|
92
|
+
export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
|
|
93
93
|
market: Hex;
|
|
94
94
|
assets: bigint;
|
|
95
95
|
shares: bigint;
|
|
@@ -98,14 +98,14 @@ export interface MarketV1WithdrawAction extends BaseAction<"marketV1Withdraw", {
|
|
|
98
98
|
reallocationFee: bigint;
|
|
99
99
|
}> {
|
|
100
100
|
}
|
|
101
|
-
export interface
|
|
101
|
+
export interface BlueSupplyCollateralAction extends BaseAction<"blueSupplyCollateral", {
|
|
102
102
|
market: Hex;
|
|
103
103
|
amount: bigint;
|
|
104
104
|
onBehalf: Address;
|
|
105
105
|
nativeAmount?: bigint;
|
|
106
106
|
}> {
|
|
107
107
|
}
|
|
108
|
-
export interface
|
|
108
|
+
export interface BlueBorrowAction extends BaseAction<"blueBorrow", {
|
|
109
109
|
market: Hex;
|
|
110
110
|
amount: bigint;
|
|
111
111
|
receiver: Address;
|
|
@@ -113,7 +113,7 @@ export interface MarketV1BorrowAction extends BaseAction<"marketV1Borrow", {
|
|
|
113
113
|
reallocationFee: bigint;
|
|
114
114
|
}> {
|
|
115
115
|
}
|
|
116
|
-
export interface
|
|
116
|
+
export interface BlueSupplyCollateralBorrowAction extends BaseAction<"blueSupplyCollateralBorrow", {
|
|
117
117
|
market: Hex;
|
|
118
118
|
collateralAmount: bigint;
|
|
119
119
|
borrowAmount: bigint;
|
|
@@ -124,7 +124,7 @@ export interface MarketV1SupplyCollateralBorrowAction extends BaseAction<"market
|
|
|
124
124
|
reallocationFee: bigint;
|
|
125
125
|
}> {
|
|
126
126
|
}
|
|
127
|
-
export interface
|
|
127
|
+
export interface BlueRepayAction extends BaseAction<"blueRepay", {
|
|
128
128
|
market: Hex;
|
|
129
129
|
assets: bigint;
|
|
130
130
|
shares: bigint;
|
|
@@ -134,14 +134,14 @@ export interface MarketV1RepayAction extends BaseAction<"marketV1Repay", {
|
|
|
134
134
|
maxSharePrice: bigint;
|
|
135
135
|
}> {
|
|
136
136
|
}
|
|
137
|
-
export interface
|
|
137
|
+
export interface BlueWithdrawCollateralAction extends BaseAction<"blueWithdrawCollateral", {
|
|
138
138
|
market: Hex;
|
|
139
139
|
amount: bigint;
|
|
140
140
|
onBehalf: Address;
|
|
141
141
|
receiver: Address;
|
|
142
142
|
}> {
|
|
143
143
|
}
|
|
144
|
-
export interface
|
|
144
|
+
export interface BlueRepayWithdrawCollateralAction extends BaseAction<"blueRepayWithdrawCollateral", {
|
|
145
145
|
market: Hex;
|
|
146
146
|
repayAssets: bigint;
|
|
147
147
|
repayShares: bigint;
|
|
@@ -152,6 +152,18 @@ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marke
|
|
|
152
152
|
receiver: Address;
|
|
153
153
|
}> {
|
|
154
154
|
}
|
|
155
|
+
export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
|
|
156
|
+
readonly sourceMarket: Hex;
|
|
157
|
+
readonly targetMarket: Hex;
|
|
158
|
+
readonly collateralAmount: bigint;
|
|
159
|
+
readonly borrowAssets: bigint;
|
|
160
|
+
readonly borrowShares: bigint;
|
|
161
|
+
readonly minBorrowSharePrice: bigint;
|
|
162
|
+
readonly maxRepaySharePrice: bigint;
|
|
163
|
+
readonly user: Address;
|
|
164
|
+
readonly reallocationFee: bigint;
|
|
165
|
+
}> {
|
|
166
|
+
}
|
|
155
167
|
/**
|
|
156
168
|
* Enforces that exactly one of `assets` / `shares` is provided.
|
|
157
169
|
*
|
|
@@ -173,7 +185,7 @@ export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorizati
|
|
|
173
185
|
isAuthorized: boolean;
|
|
174
186
|
}> {
|
|
175
187
|
}
|
|
176
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action |
|
|
188
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | MorphoAuthorizationAction;
|
|
177
189
|
export interface Transaction<TAction extends BaseAction = TransactionAction> {
|
|
178
190
|
readonly to: Address;
|
|
179
191
|
readonly value: bigint;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address, Client } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueActions, VaultV1Actions, VaultV2Actions } from "../actions/index.js";
|
|
4
4
|
import type { Metadata } from "./index.js";
|
|
5
5
|
/**
|
|
6
|
-
* Structural contract
|
|
7
|
-
*
|
|
6
|
+
* Structural contract the `morpho` namespace satisfies — the object exposed under `client.morpho`
|
|
7
|
+
* once a viem client is extended with {@link morphoViemExtension}. Carries the viem client, the
|
|
8
|
+
* resolved options bag, and the three entity-factory methods the SDK exposes.
|
|
8
9
|
*/
|
|
9
10
|
export interface MorphoClientType {
|
|
10
11
|
readonly viemClient: Client;
|
|
@@ -15,5 +16,5 @@ export interface MorphoClientType {
|
|
|
15
16
|
};
|
|
16
17
|
vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
|
|
17
18
|
vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
|
|
18
|
-
|
|
19
|
+
blue: (marketParams: MarketParams, chainId: number) => BlueActions;
|
|
19
20
|
}
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -375,3 +375,60 @@ export declare class VaultAssetMismatchError extends Error {
|
|
|
375
375
|
export declare class NegativeMinSharePriceError extends Error {
|
|
376
376
|
constructor(vault: Address);
|
|
377
377
|
}
|
|
378
|
+
/** Thrown when a refinance's `borrowShares` argument is negative. */
|
|
379
|
+
export declare class NegativeBorrowSharesError extends Error {
|
|
380
|
+
constructor(market: string);
|
|
381
|
+
}
|
|
382
|
+
/** Thrown when a refinance specifies both `borrowAssets` and `borrowShares` as non-zero (modes are mutually exclusive). */
|
|
383
|
+
export declare class BorrowAmountAndSharesExclusiveError extends Error {
|
|
384
|
+
constructor(market: string);
|
|
385
|
+
}
|
|
386
|
+
/** Thrown when a refinance's `maxRepaySharePrice` slippage bound is negative. */
|
|
387
|
+
export declare class NegativeMaxRepaySharePriceError extends Error {
|
|
388
|
+
constructor(market: string);
|
|
389
|
+
}
|
|
390
|
+
/** Thrown when a refinance has identical source and target market ids (a refinance to the same market is a costly no-op). */
|
|
391
|
+
export declare class RefinanceSameMarketError extends Error {
|
|
392
|
+
constructor(market: string);
|
|
393
|
+
}
|
|
394
|
+
/** Thrown when a refinance's source and target markets do not share the same loan or collateral token. */
|
|
395
|
+
export declare class RefinanceTokenMismatchError extends Error {
|
|
396
|
+
constructor(sourceMarket: string, targetMarket: string);
|
|
397
|
+
}
|
|
398
|
+
/** Thrown when a refinance's `collateralAmount` exceeds the source position's available collateral. */
|
|
399
|
+
export declare class RefinanceExceedsCollateralError extends Error {
|
|
400
|
+
readonly market: string;
|
|
401
|
+
readonly requested: bigint;
|
|
402
|
+
readonly available: bigint;
|
|
403
|
+
constructor(params: {
|
|
404
|
+
market: string;
|
|
405
|
+
requested: bigint;
|
|
406
|
+
available: bigint;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/** Thrown when a refinance's `borrowShares` exceeds the source position's outstanding borrow shares. */
|
|
410
|
+
export declare class RefinanceExceedsBorrowSharesError extends Error {
|
|
411
|
+
readonly market: string;
|
|
412
|
+
readonly requested: bigint;
|
|
413
|
+
readonly available: bigint;
|
|
414
|
+
constructor(params: {
|
|
415
|
+
market: string;
|
|
416
|
+
requested: bigint;
|
|
417
|
+
available: bigint;
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/** Thrown when a refinance's `borrowAssets` exceeds the source position's outstanding debt assets. */
|
|
421
|
+
export declare class RefinanceExceedsBorrowAssetsError extends Error {
|
|
422
|
+
readonly market: string;
|
|
423
|
+
readonly requested: bigint;
|
|
424
|
+
readonly available: bigint;
|
|
425
|
+
constructor(params: {
|
|
426
|
+
market: string;
|
|
427
|
+
requested: bigint;
|
|
428
|
+
available: bigint;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/** Thrown when a refinance in shares mode (`borrowShares > 0n`) omits the `borrowAssets` overshoot for the target borrow leg. */
|
|
432
|
+
export declare class RefinanceSharesMissingBorrowAssetsError extends Error {
|
|
433
|
+
constructor(market: string);
|
|
434
|
+
}
|