@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
package/lib/cjs/types/error.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.DisabledReallocationMarketError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.NativeAmountOnNonWNativeAssetError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.Permit2ExpirationMissingError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = exports.BundlerErrors = void 0;
|
|
4
|
-
exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = void 0;
|
|
4
|
+
exports.RefinanceSharesMissingBorrowAssetsError = exports.RefinanceExceedsBorrowAssetsError = exports.RefinanceExceedsBorrowSharesError = exports.RefinanceExceedsCollateralError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.NegativeMaxRepaySharePriceError = exports.BorrowAmountAndSharesExclusiveError = exports.NegativeBorrowSharesError = exports.NegativeMinSharePriceError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.NegativeWithdrawMinSharePriceError = exports.NonPositiveWithdrawAmountError = exports.ZeroSupplyAmountError = exports.NegativeSupplyMaxSharePriceError = exports.NegativeSupplyAmountError = exports.NonPositiveMinBorrowSharePriceError = exports.UnknownReallocationPositionError = exports.UnknownReallocationVaultMarketConfigError = void 0;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
/**
|
|
7
7
|
* Typed errors thrown while encoding supported Bundler3 actions.
|
|
@@ -536,3 +536,84 @@ class NegativeMinSharePriceError extends Error {
|
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
538
|
exports.NegativeMinSharePriceError = NegativeMinSharePriceError;
|
|
539
|
+
/** Thrown when a refinance's `borrowShares` argument is negative. */
|
|
540
|
+
class NegativeBorrowSharesError extends Error {
|
|
541
|
+
constructor(market) {
|
|
542
|
+
super(`Borrow shares must be non-negative for market: ${market}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
exports.NegativeBorrowSharesError = NegativeBorrowSharesError;
|
|
546
|
+
/** Thrown when a refinance specifies both `borrowAssets` and `borrowShares` as non-zero (modes are mutually exclusive). */
|
|
547
|
+
class BorrowAmountAndSharesExclusiveError extends Error {
|
|
548
|
+
constructor(market) {
|
|
549
|
+
super(`Exactly one of borrowAssets or borrowShares must be non-zero for market: ${market}. Both were provided.`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
exports.BorrowAmountAndSharesExclusiveError = BorrowAmountAndSharesExclusiveError;
|
|
553
|
+
/** Thrown when a refinance's `maxRepaySharePrice` slippage bound is negative. */
|
|
554
|
+
class NegativeMaxRepaySharePriceError extends Error {
|
|
555
|
+
constructor(market) {
|
|
556
|
+
super(`Max repay share price must be non-negative for market: ${market}`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
exports.NegativeMaxRepaySharePriceError = NegativeMaxRepaySharePriceError;
|
|
560
|
+
/** Thrown when a refinance has identical source and target market ids (a refinance to the same market is a costly no-op). */
|
|
561
|
+
class RefinanceSameMarketError extends Error {
|
|
562
|
+
constructor(market) {
|
|
563
|
+
super(`Refinance source and target market ${market} are identical. Refinance requires a different target market.`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
exports.RefinanceSameMarketError = RefinanceSameMarketError;
|
|
567
|
+
/** Thrown when a refinance's source and target markets do not share the same loan or collateral token. */
|
|
568
|
+
class RefinanceTokenMismatchError extends Error {
|
|
569
|
+
constructor(sourceMarket, targetMarket) {
|
|
570
|
+
super(`Refinance source market ${sourceMarket} and target market ${targetMarket} must share the same loanToken and collateralToken.`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
exports.RefinanceTokenMismatchError = RefinanceTokenMismatchError;
|
|
574
|
+
/** Thrown when a refinance's `collateralAmount` exceeds the source position's available collateral. */
|
|
575
|
+
class RefinanceExceedsCollateralError extends Error {
|
|
576
|
+
market;
|
|
577
|
+
requested;
|
|
578
|
+
available;
|
|
579
|
+
constructor(params) {
|
|
580
|
+
super(`Refinance collateral amount ${params.requested} exceeds available collateral ${params.available} for market: ${params.market}`);
|
|
581
|
+
this.market = params.market;
|
|
582
|
+
this.requested = params.requested;
|
|
583
|
+
this.available = params.available;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
exports.RefinanceExceedsCollateralError = RefinanceExceedsCollateralError;
|
|
587
|
+
/** Thrown when a refinance's `borrowShares` exceeds the source position's outstanding borrow shares. */
|
|
588
|
+
class RefinanceExceedsBorrowSharesError extends Error {
|
|
589
|
+
market;
|
|
590
|
+
requested;
|
|
591
|
+
available;
|
|
592
|
+
constructor(params) {
|
|
593
|
+
super(`Refinance borrow shares ${params.requested} exceed outstanding borrow shares ${params.available} for market: ${params.market}`);
|
|
594
|
+
this.market = params.market;
|
|
595
|
+
this.requested = params.requested;
|
|
596
|
+
this.available = params.available;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
exports.RefinanceExceedsBorrowSharesError = RefinanceExceedsBorrowSharesError;
|
|
600
|
+
/** Thrown when a refinance's `borrowAssets` exceeds the source position's outstanding debt assets. */
|
|
601
|
+
class RefinanceExceedsBorrowAssetsError extends Error {
|
|
602
|
+
market;
|
|
603
|
+
requested;
|
|
604
|
+
available;
|
|
605
|
+
constructor(params) {
|
|
606
|
+
super(`Refinance borrow assets ${params.requested} exceed outstanding debt assets ${params.available} for market: ${params.market}`);
|
|
607
|
+
this.market = params.market;
|
|
608
|
+
this.requested = params.requested;
|
|
609
|
+
this.available = params.available;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
exports.RefinanceExceedsBorrowAssetsError = RefinanceExceedsBorrowAssetsError;
|
|
613
|
+
/** Thrown when a refinance in shares mode (`borrowShares > 0n`) omits the `borrowAssets` overshoot for the target borrow leg. */
|
|
614
|
+
class RefinanceSharesMissingBorrowAssetsError extends Error {
|
|
615
|
+
constructor(market) {
|
|
616
|
+
super(`Refinance shares mode requires a positive borrowAssets overshoot for the target borrow leg (market: ${market}).`);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
exports.RefinanceSharesMissingBorrowAssetsError = RefinanceSharesMissingBorrowAssetsError;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type
|
|
4
|
-
/** Parameters for {@link
|
|
5
|
-
export interface
|
|
3
|
+
import { type BlueBorrowAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link blueBorrow}. */
|
|
5
|
+
export interface BlueBorrowParams {
|
|
6
6
|
market: {
|
|
7
7
|
readonly chainId: number;
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
@@ -36,7 +36,7 @@ export interface MarketV1BorrowParams {
|
|
|
36
36
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
37
37
|
* computed by the entity layer.
|
|
38
38
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
39
|
-
* @returns A deep-frozen `Transaction<
|
|
39
|
+
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
40
40
|
* typed `action` discriminator the simulation layer consumes.
|
|
41
41
|
* @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
|
|
42
42
|
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
|
|
@@ -53,9 +53,9 @@ export interface MarketV1BorrowParams {
|
|
|
53
53
|
* reallocation withdrawals are not strictly sorted by market id.
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
|
-
* import {
|
|
56
|
+
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
57
57
|
*
|
|
58
|
-
* const tx =
|
|
58
|
+
* const tx = blueBorrow({
|
|
59
59
|
* market: { chainId: 1, marketParams },
|
|
60
60
|
* args: {
|
|
61
61
|
* amount: 1_000_000n,
|
|
@@ -63,7 +63,7 @@ export interface MarketV1BorrowParams {
|
|
|
63
63
|
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
|
|
64
64
|
* },
|
|
65
65
|
* });
|
|
66
|
-
* // tx satisfies Readonly<Transaction<
|
|
66
|
+
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export declare const
|
|
69
|
+
export declare const blueBorrow: ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }: BlueBorrowParams) => Readonly<Transaction<BlueBorrowAction>>;
|
|
@@ -22,7 +22,7 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
22
22
|
* @param params.args.reallocations - Optional vault reallocations to execute before borrowing,
|
|
23
23
|
* computed by the entity layer.
|
|
24
24
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
25
|
-
* @returns A deep-frozen `Transaction<
|
|
25
|
+
* @returns A deep-frozen `Transaction<BlueBorrowAction>` with `to`, `value`, `data`, and the
|
|
26
26
|
* typed `action` discriminator the simulation layer consumes.
|
|
27
27
|
* @throws {NonPositiveBorrowAmountError} when `amount <= 0n`.
|
|
28
28
|
* @throws {NonPositiveMinBorrowSharePriceError} when `minSharePrice < 0n` (negative; zero is
|
|
@@ -39,9 +39,9 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
39
39
|
* reallocation withdrawals are not strictly sorted by market id.
|
|
40
40
|
* @example
|
|
41
41
|
* ```ts
|
|
42
|
-
* import {
|
|
42
|
+
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
43
43
|
*
|
|
44
|
-
* const tx =
|
|
44
|
+
* const tx = blueBorrow({
|
|
45
45
|
* market: { chainId: 1, marketParams },
|
|
46
46
|
* args: {
|
|
47
47
|
* amount: 1_000_000n,
|
|
@@ -49,10 +49,10 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
49
49
|
* minSharePrice: 0n, // disables slippage protection — production code should compute via `computeMinBorrowSharePrice` from market state + slippage tolerance
|
|
50
50
|
* },
|
|
51
51
|
* });
|
|
52
|
-
* // tx satisfies Readonly<Transaction<
|
|
52
|
+
* // tx satisfies Readonly<Transaction<BlueBorrowAction>>
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export const
|
|
55
|
+
export const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receiver, minSharePrice, reallocations }, metadata, }) => {
|
|
56
56
|
if (amount <= 0n) {
|
|
57
57
|
throw new NonPositiveBorrowAmountError(marketParams.id);
|
|
58
58
|
}
|
|
@@ -77,7 +77,7 @@ export const marketV1Borrow = ({ market: { chainId, marketParams }, args: { amou
|
|
|
77
77
|
return deepFreeze({
|
|
78
78
|
...tx,
|
|
79
79
|
action: {
|
|
80
|
-
type: "
|
|
80
|
+
type: "blueBorrow",
|
|
81
81
|
args: {
|
|
82
82
|
market: marketParams.id,
|
|
83
83
|
amount,
|
|
@@ -7,7 +7,7 @@ import type { VaultReallocation } from "../../types/index.js";
|
|
|
7
7
|
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
8
8
|
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
9
9
|
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
10
|
-
* consumed only by `
|
|
10
|
+
* consumed only by `blueBorrow` and `blueSupplyCollateralBorrow`; not re-exported on the
|
|
11
11
|
* public surface.
|
|
12
12
|
*
|
|
13
13
|
* @param reallocations - The vault reallocations to encode.
|
|
@@ -5,7 +5,7 @@ import { validateReallocations } from "../../helpers/index.js";
|
|
|
5
5
|
* Validates the reallocations, then encodes each as a `reallocateTo` action against the target
|
|
6
6
|
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
7
7
|
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
8
|
-
* consumed only by `
|
|
8
|
+
* consumed only by `blueBorrow` and `blueSupplyCollateralBorrow`; not re-exported on the
|
|
9
9
|
* public surface.
|
|
10
10
|
*
|
|
11
11
|
* @param reallocations - The vault reallocations to encode.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type BlueRefinanceAction, type Metadata, type Transaction, type VaultReallocation } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link blueRefinance}. */
|
|
5
|
+
export interface BlueRefinanceParams {
|
|
6
|
+
source: {
|
|
7
|
+
readonly chainId: number;
|
|
8
|
+
readonly marketParams: MarketParams;
|
|
9
|
+
};
|
|
10
|
+
target: {
|
|
11
|
+
readonly marketParams: MarketParams;
|
|
12
|
+
};
|
|
13
|
+
args: {
|
|
14
|
+
user: Address;
|
|
15
|
+
collateralAmount: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Loan assets to borrow on the target. Assets mode: the exact borrow (exclusive with
|
|
18
|
+
* `borrowShares`). Shares mode: the positive overshoot covering accrual + slippage; omitting it
|
|
19
|
+
* throws {@link RefinanceSharesMissingBorrowAssetsError}.
|
|
20
|
+
*/
|
|
21
|
+
borrowAssets?: bigint;
|
|
22
|
+
/** Source borrow shares to repay (immune to mid-tx accrual); exclusive with `borrowAssets`. */
|
|
23
|
+
borrowShares?: bigint;
|
|
24
|
+
/** Minimum borrow share price on the target market (in ray). */
|
|
25
|
+
minBorrowSharePrice: bigint;
|
|
26
|
+
/** Maximum repay share price on the source market (in ray); must be > 0 when a repay leg exists. */
|
|
27
|
+
maxRepaySharePrice: bigint;
|
|
28
|
+
/** PublicAllocator reallocations into the target market, run before the bundle. Fees add to `tx.value`. */
|
|
29
|
+
targetReallocations?: readonly VaultReallocation[];
|
|
30
|
+
};
|
|
31
|
+
metadata?: Metadata;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
|
|
35
|
+
* chain that shares the same loan and collateral tokens.
|
|
36
|
+
*
|
|
37
|
+
* Strategy: flash-collateral via the target's `onMorphoSupplyCollateral` callback. The collateral
|
|
38
|
+
* is credited before the deferred `safeTransferFrom`, so inside the callback GA1 borrows on the
|
|
39
|
+
* target, repays the source, then withdraws the source collateral to settle the transfer.
|
|
40
|
+
*
|
|
41
|
+
* Bundle shape (callback contents depend on borrow mode):
|
|
42
|
+
*
|
|
43
|
+
* ```text
|
|
44
|
+
* // optional: one reallocateTo per targetReallocations entry, run first
|
|
45
|
+
* reallocateTo(vault_i, fee_i, withdrawals_i, target, false),
|
|
46
|
+
*
|
|
47
|
+
* morphoSupplyCollateral(target, collateralAmount, user, [
|
|
48
|
+
* // omitted in collat-only mode
|
|
49
|
+
* morphoBorrow(target, borrowAssets, 0, minBorrowSharePrice, GA1),
|
|
50
|
+
* morphoRepay(source, assets|0, 0|shares, maxRepaySharePrice, user, []),
|
|
51
|
+
* // shares mode only: sweep overshoot before the withdraw so same-token markets aren't drained
|
|
52
|
+
* morphoRepay(target, maxUint256, 0, maxUint256, user, [], skipRevert=true),
|
|
53
|
+
* // shares mode only: fallback if the repay is skipped, skim residual loan tokens to the user
|
|
54
|
+
* erc20Transfer(loanToken, user, maxUint256, GA1, skipRevert=false),
|
|
55
|
+
* morphoWithdrawCollateral(source, collateralAmount, GA1),
|
|
56
|
+
* ])
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* Borrow modes:
|
|
60
|
+
*
|
|
61
|
+
* - **Assets mode** (`borrowAssets > 0n`): exact-asset borrow and repay, no GA1 dust.
|
|
62
|
+
* - **Shares mode** (`borrowShares > 0n`, `borrowAssets` is the overshoot): the trailing
|
|
63
|
+
* `morphoRepay(target, maxUint256, …, skipRevert=true)` sweeps the residual into the target debt,
|
|
64
|
+
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
65
|
+
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
66
|
+
*
|
|
67
|
+
* Prerequisite: GA1 must be authorized on Morpho — the entity's `getRequirements()` returns the
|
|
68
|
+
* `setAuthorization` transaction when needed.
|
|
69
|
+
*
|
|
70
|
+
* @param params.source.chainId - The chain both markets live on.
|
|
71
|
+
* @param params.source.marketParams - Source market params (the position being closed).
|
|
72
|
+
* @param params.target.marketParams - Target market params; must share both tokens with the source.
|
|
73
|
+
* @param params.args.user - Position owner on both markets.
|
|
74
|
+
* @param params.args.collateralAmount - Amount of collateral to migrate.
|
|
75
|
+
* @param params.args.borrowAssets - Loan assets to borrow on the target; exclusive with `borrowShares`. Defaults to `0n`.
|
|
76
|
+
* @param params.args.borrowShares - Borrow shares to repay on the source; exclusive with `borrowAssets`. Defaults to `0n`.
|
|
77
|
+
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
78
|
+
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
79
|
+
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
80
|
+
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
81
|
+
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
82
|
+
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
83
|
+
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
84
|
+
* @throws {ZeroCollateralAmountError} when `collateralAmount <= 0n`.
|
|
85
|
+
* @throws {NonPositiveAssetAmountError} when `borrowAssets < 0n`.
|
|
86
|
+
* @throws {NegativeBorrowSharesError} when `borrowShares < 0n`.
|
|
87
|
+
* @throws {NonPositiveMinBorrowSharePriceError} when `minBorrowSharePrice < 0n`.
|
|
88
|
+
* @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
|
|
89
|
+
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
90
|
+
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
91
|
+
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|
|
92
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
|
|
93
|
+
* @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
|
|
94
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
95
|
+
* @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
|
|
96
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
|
|
97
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { blueRefinance } from "@morpho-org/morpho-sdk";
|
|
101
|
+
*
|
|
102
|
+
* const tx = blueRefinance({
|
|
103
|
+
* source: { chainId: 1, marketParams: sourceParams },
|
|
104
|
+
* target: { marketParams: targetParams },
|
|
105
|
+
* args: {
|
|
106
|
+
* user: borrower,
|
|
107
|
+
* collateralAmount: 1_000_000_000_000_000_000n,
|
|
108
|
+
* borrowShares: 500_000_000_000n,
|
|
109
|
+
* borrowAssets: 501_000_000n, // overshoot computed by entity layer
|
|
110
|
+
* minBorrowSharePrice: 0n,
|
|
111
|
+
* maxRepaySharePrice: 1_500_000_000_000_000_000_000_000_000n,
|
|
112
|
+
* },
|
|
113
|
+
* });
|
|
114
|
+
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare const blueRefinance: ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets, borrowShares, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }: BlueRefinanceParams) => Readonly<Transaction<BlueRefinanceAction>>;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual, maxUint256 } from "viem";
|
|
4
|
+
import { BundlerAction } from "../../bundler/index.js";
|
|
5
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
+
import { NegativeBorrowSharesError, NegativeMaxRepaySharePriceError, NonPositiveAssetAmountError, NonPositiveMinBorrowSharePriceError, NonPositiveRepayMaxSharePriceError, RefinanceSameMarketError, RefinanceSharesMissingBorrowAssetsError, RefinanceTokenMismatchError, ZeroCollateralAmountError, } from "../../types/index.js";
|
|
7
|
+
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
8
|
+
/**
|
|
9
|
+
* Prepares an atomic refinance migrating a Morpho Blue position to another market on the same
|
|
10
|
+
* chain that shares the same loan and collateral tokens.
|
|
11
|
+
*
|
|
12
|
+
* Strategy: flash-collateral via the target's `onMorphoSupplyCollateral` callback. The collateral
|
|
13
|
+
* is credited before the deferred `safeTransferFrom`, so inside the callback GA1 borrows on the
|
|
14
|
+
* target, repays the source, then withdraws the source collateral to settle the transfer.
|
|
15
|
+
*
|
|
16
|
+
* Bundle shape (callback contents depend on borrow mode):
|
|
17
|
+
*
|
|
18
|
+
* ```text
|
|
19
|
+
* // optional: one reallocateTo per targetReallocations entry, run first
|
|
20
|
+
* reallocateTo(vault_i, fee_i, withdrawals_i, target, false),
|
|
21
|
+
*
|
|
22
|
+
* morphoSupplyCollateral(target, collateralAmount, user, [
|
|
23
|
+
* // omitted in collat-only mode
|
|
24
|
+
* morphoBorrow(target, borrowAssets, 0, minBorrowSharePrice, GA1),
|
|
25
|
+
* morphoRepay(source, assets|0, 0|shares, maxRepaySharePrice, user, []),
|
|
26
|
+
* // shares mode only: sweep overshoot before the withdraw so same-token markets aren't drained
|
|
27
|
+
* morphoRepay(target, maxUint256, 0, maxUint256, user, [], skipRevert=true),
|
|
28
|
+
* // shares mode only: fallback if the repay is skipped, skim residual loan tokens to the user
|
|
29
|
+
* erc20Transfer(loanToken, user, maxUint256, GA1, skipRevert=false),
|
|
30
|
+
* morphoWithdrawCollateral(source, collateralAmount, GA1),
|
|
31
|
+
* ])
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Borrow modes:
|
|
35
|
+
*
|
|
36
|
+
* - **Assets mode** (`borrowAssets > 0n`): exact-asset borrow and repay, no GA1 dust.
|
|
37
|
+
* - **Shares mode** (`borrowShares > 0n`, `borrowAssets` is the overshoot): the trailing
|
|
38
|
+
* `morphoRepay(target, maxUint256, …, skipRevert=true)` sweeps the residual into the target debt,
|
|
39
|
+
* then an `erc20Transfer` skims any residual to the user if that repay is skipped.
|
|
40
|
+
* - **Collat-only** (both zero/omitted): only collateral is migrated; borrow/repay legs omitted.
|
|
41
|
+
*
|
|
42
|
+
* Prerequisite: GA1 must be authorized on Morpho — the entity's `getRequirements()` returns the
|
|
43
|
+
* `setAuthorization` transaction when needed.
|
|
44
|
+
*
|
|
45
|
+
* @param params.source.chainId - The chain both markets live on.
|
|
46
|
+
* @param params.source.marketParams - Source market params (the position being closed).
|
|
47
|
+
* @param params.target.marketParams - Target market params; must share both tokens with the source.
|
|
48
|
+
* @param params.args.user - Position owner on both markets.
|
|
49
|
+
* @param params.args.collateralAmount - Amount of collateral to migrate.
|
|
50
|
+
* @param params.args.borrowAssets - Loan assets to borrow on the target; exclusive with `borrowShares`. Defaults to `0n`.
|
|
51
|
+
* @param params.args.borrowShares - Borrow shares to repay on the source; exclusive with `borrowAssets`. Defaults to `0n`.
|
|
52
|
+
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
53
|
+
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
54
|
+
* @param params.args.targetReallocations - PublicAllocator reallocations into the target, run before the supply leg.
|
|
55
|
+
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
56
|
+
* @returns A deep-frozen `Transaction<BlueRefinanceAction>`.
|
|
57
|
+
* @remarks `borrowAssets` and `borrowShares` describe different markets (target borrow vs. source
|
|
58
|
+
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
59
|
+
* @throws {ZeroCollateralAmountError} when `collateralAmount <= 0n`.
|
|
60
|
+
* @throws {NonPositiveAssetAmountError} when `borrowAssets < 0n`.
|
|
61
|
+
* @throws {NegativeBorrowSharesError} when `borrowShares < 0n`.
|
|
62
|
+
* @throws {NonPositiveMinBorrowSharePriceError} when `minBorrowSharePrice < 0n`.
|
|
63
|
+
* @throws {NegativeMaxRepaySharePriceError} when `maxRepaySharePrice < 0n`.
|
|
64
|
+
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
65
|
+
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
66
|
+
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|
|
67
|
+
* @throws {NonPositiveRepayMaxSharePriceError} when a repay leg is encoded and `maxRepaySharePrice <= 0n`.
|
|
68
|
+
* @throws {NegativeReallocationFeeError} when any `reallocation.fee < 0n`.
|
|
69
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
70
|
+
* @throws {NonPositiveReallocationAmountError} when any `reallocation.withdrawals[i].amount <= 0n`.
|
|
71
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references the target market.
|
|
72
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly sorted by market id.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { blueRefinance } from "@morpho-org/morpho-sdk";
|
|
76
|
+
*
|
|
77
|
+
* const tx = blueRefinance({
|
|
78
|
+
* source: { chainId: 1, marketParams: sourceParams },
|
|
79
|
+
* target: { marketParams: targetParams },
|
|
80
|
+
* args: {
|
|
81
|
+
* user: borrower,
|
|
82
|
+
* collateralAmount: 1_000_000_000_000_000_000n,
|
|
83
|
+
* borrowShares: 500_000_000_000n,
|
|
84
|
+
* borrowAssets: 501_000_000n, // overshoot computed by entity layer
|
|
85
|
+
* minBorrowSharePrice: 0n,
|
|
86
|
+
* maxRepaySharePrice: 1_500_000_000_000_000_000_000_000_000n,
|
|
87
|
+
* },
|
|
88
|
+
* });
|
|
89
|
+
* // tx satisfies Readonly<Transaction<BlueRefinanceAction>>
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export const blueRefinance = ({ source: { chainId, marketParams: sourceParams }, target: { marketParams: targetParams }, args: { user, collateralAmount, borrowAssets = 0n, borrowShares = 0n, minBorrowSharePrice, maxRepaySharePrice, targetReallocations, }, metadata, }) => {
|
|
93
|
+
if (collateralAmount <= 0n) {
|
|
94
|
+
throw new ZeroCollateralAmountError(sourceParams.id);
|
|
95
|
+
}
|
|
96
|
+
if (borrowAssets < 0n) {
|
|
97
|
+
throw new NonPositiveAssetAmountError(sourceParams.loanToken);
|
|
98
|
+
}
|
|
99
|
+
if (borrowShares < 0n) {
|
|
100
|
+
throw new NegativeBorrowSharesError(sourceParams.id);
|
|
101
|
+
}
|
|
102
|
+
if (minBorrowSharePrice < 0n) {
|
|
103
|
+
throw new NonPositiveMinBorrowSharePriceError(targetParams.id);
|
|
104
|
+
}
|
|
105
|
+
if (maxRepaySharePrice < 0n) {
|
|
106
|
+
throw new NegativeMaxRepaySharePriceError(sourceParams.id);
|
|
107
|
+
}
|
|
108
|
+
if (sourceParams.id === targetParams.id) {
|
|
109
|
+
throw new RefinanceSameMarketError(sourceParams.id);
|
|
110
|
+
}
|
|
111
|
+
if (!isAddressEqual(sourceParams.collateralToken, targetParams.collateralToken) ||
|
|
112
|
+
!isAddressEqual(sourceParams.loanToken, targetParams.loanToken)) {
|
|
113
|
+
throw new RefinanceTokenMismatchError(sourceParams.id, targetParams.id);
|
|
114
|
+
}
|
|
115
|
+
const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
|
|
116
|
+
const sharesMode = borrowShares > 0n;
|
|
117
|
+
const shouldMigrateBorrow = borrowAssets > 0n || sharesMode;
|
|
118
|
+
// Shares mode borrows in assets; Morpho rejects a zero borrow, so require a positive overshoot.
|
|
119
|
+
if (sharesMode && borrowAssets <= 0n) {
|
|
120
|
+
throw new RefinanceSharesMissingBorrowAssetsError(sourceParams.id);
|
|
121
|
+
}
|
|
122
|
+
// A repay leg with maxRepaySharePrice = 0n always reverts; require a positive cap when debt is migrated.
|
|
123
|
+
if (shouldMigrateBorrow && maxRepaySharePrice <= 0n) {
|
|
124
|
+
throw new NonPositiveRepayMaxSharePriceError(sourceParams.id);
|
|
125
|
+
}
|
|
126
|
+
const callback = [];
|
|
127
|
+
if (shouldMigrateBorrow) {
|
|
128
|
+
callback.push({
|
|
129
|
+
type: "morphoBorrow",
|
|
130
|
+
args: [
|
|
131
|
+
targetParams,
|
|
132
|
+
borrowAssets,
|
|
133
|
+
0n,
|
|
134
|
+
minBorrowSharePrice,
|
|
135
|
+
generalAdapter1,
|
|
136
|
+
false,
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
callback.push(sharesMode
|
|
140
|
+
? {
|
|
141
|
+
type: "morphoRepay",
|
|
142
|
+
args: [
|
|
143
|
+
sourceParams,
|
|
144
|
+
0n,
|
|
145
|
+
borrowShares,
|
|
146
|
+
maxRepaySharePrice,
|
|
147
|
+
user,
|
|
148
|
+
[],
|
|
149
|
+
false,
|
|
150
|
+
],
|
|
151
|
+
}
|
|
152
|
+
: {
|
|
153
|
+
type: "morphoRepay",
|
|
154
|
+
args: [
|
|
155
|
+
sourceParams,
|
|
156
|
+
borrowAssets,
|
|
157
|
+
0n,
|
|
158
|
+
maxRepaySharePrice,
|
|
159
|
+
user,
|
|
160
|
+
[],
|
|
161
|
+
false,
|
|
162
|
+
],
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
// Sweep the borrow overshoot back into target debt so GA1 ends drained. Must run before the
|
|
166
|
+
// withdraw: in same-token markets maxUint256 would otherwise drain the just-withdrawn collateral.
|
|
167
|
+
if (sharesMode) {
|
|
168
|
+
callback.push({
|
|
169
|
+
type: "morphoRepay",
|
|
170
|
+
args: [targetParams, maxUint256, 0n, maxUint256, user, [], true],
|
|
171
|
+
});
|
|
172
|
+
// Fallback: if the repay above is skipped, skim any residual loan tokens to the user.
|
|
173
|
+
callback.push({
|
|
174
|
+
type: "erc20Transfer",
|
|
175
|
+
args: [targetParams.loanToken, user, maxUint256, generalAdapter1, false],
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
callback.push({
|
|
179
|
+
type: "morphoWithdrawCollateral",
|
|
180
|
+
args: [sourceParams, collateralAmount, generalAdapter1, false],
|
|
181
|
+
});
|
|
182
|
+
const actions = [];
|
|
183
|
+
let reallocationFee = 0n;
|
|
184
|
+
if (targetReallocations && targetReallocations.length > 0) {
|
|
185
|
+
const result = buildReallocationActions(targetReallocations, targetParams);
|
|
186
|
+
actions.push(...result.actions);
|
|
187
|
+
reallocationFee = result.fee;
|
|
188
|
+
}
|
|
189
|
+
actions.push({
|
|
190
|
+
type: "morphoSupplyCollateral",
|
|
191
|
+
args: [targetParams, collateralAmount, user, callback, false],
|
|
192
|
+
});
|
|
193
|
+
let tx = BundlerAction.encodeBundle(chainId, actions);
|
|
194
|
+
if (metadata) {
|
|
195
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
196
|
+
}
|
|
197
|
+
return deepFreeze({
|
|
198
|
+
...tx,
|
|
199
|
+
action: {
|
|
200
|
+
type: "blueRefinance",
|
|
201
|
+
args: {
|
|
202
|
+
sourceMarket: sourceParams.id,
|
|
203
|
+
targetMarket: targetParams.id,
|
|
204
|
+
collateralAmount,
|
|
205
|
+
borrowAssets,
|
|
206
|
+
borrowShares,
|
|
207
|
+
minBorrowSharePrice,
|
|
208
|
+
maxRepaySharePrice,
|
|
209
|
+
user,
|
|
210
|
+
reallocationFee,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import type {
|
|
4
|
-
/** Parameters for {@link
|
|
5
|
-
export interface
|
|
3
|
+
import type { BlueRepayAction, Metadata, RequirementSignature, Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for {@link blueRepay}. */
|
|
5
|
+
export interface BlueRepayParams {
|
|
6
6
|
market: {
|
|
7
7
|
readonly chainId: number;
|
|
8
8
|
readonly marketParams: MarketParams;
|
|
@@ -56,7 +56,7 @@ export interface MarketV1RepayParams {
|
|
|
56
56
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
57
57
|
* loan-token transfer.
|
|
58
58
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
59
|
-
* @returns A deep-frozen `Transaction<
|
|
59
|
+
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value`, `data`, and the
|
|
60
60
|
* typed `action` discriminator the simulation layer consumes.
|
|
61
61
|
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
62
62
|
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
@@ -72,9 +72,9 @@ export interface MarketV1RepayParams {
|
|
|
72
72
|
* signature is missing its expiration.
|
|
73
73
|
* @example
|
|
74
74
|
* ```ts
|
|
75
|
-
* import {
|
|
75
|
+
* import { blueRepay } from "@morpho-org/morpho-sdk";
|
|
76
76
|
*
|
|
77
|
-
* const tx =
|
|
77
|
+
* const tx = blueRepay({
|
|
78
78
|
* market: { chainId: 1, marketParams },
|
|
79
79
|
* args: {
|
|
80
80
|
* assets: 500_000_000n,
|
|
@@ -85,7 +85,7 @@ export interface MarketV1RepayParams {
|
|
|
85
85
|
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
86
86
|
* },
|
|
87
87
|
* });
|
|
88
|
-
* // tx satisfies Readonly<Transaction<
|
|
88
|
+
* // tx satisfies Readonly<Transaction<BlueRepayAction>>
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
export declare const
|
|
91
|
+
export declare const blueRepay: ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }: BlueRepayParams) => Readonly<Transaction<BlueRepayAction>>;
|
|
@@ -32,7 +32,7 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
32
32
|
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval for the
|
|
33
33
|
* loan-token transfer.
|
|
34
34
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
35
|
-
* @returns A deep-frozen `Transaction<
|
|
35
|
+
* @returns A deep-frozen `Transaction<BlueRepayAction>` with `to`, `value`, `data`, and the
|
|
36
36
|
* typed `action` discriminator the simulation layer consumes.
|
|
37
37
|
* @throws {NonPositiveRepayMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
38
38
|
* @throws {NonPositiveRepayAmountError} when either `assets` or `shares` is negative, or when
|
|
@@ -48,9 +48,9 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
48
48
|
* signature is missing its expiration.
|
|
49
49
|
* @example
|
|
50
50
|
* ```ts
|
|
51
|
-
* import {
|
|
51
|
+
* import { blueRepay } from "@morpho-org/morpho-sdk";
|
|
52
52
|
*
|
|
53
|
-
* const tx =
|
|
53
|
+
* const tx = blueRepay({
|
|
54
54
|
* market: { chainId: 1, marketParams },
|
|
55
55
|
* args: {
|
|
56
56
|
* assets: 500_000_000n,
|
|
@@ -61,10 +61,10 @@ import { getRequirementsAction } from "../requirements/getRequirementsAction.js"
|
|
|
61
61
|
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
62
62
|
* },
|
|
63
63
|
* });
|
|
64
|
-
* // tx satisfies Readonly<Transaction<
|
|
64
|
+
* // tx satisfies Readonly<Transaction<BlueRepayAction>>
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
|
-
export const
|
|
67
|
+
export const blueRepay = ({ market: { chainId, marketParams }, args: { assets, shares, transferAmount, onBehalf, receiver, maxSharePrice, requirementSignature, }, metadata, }) => {
|
|
68
68
|
validateRepayParams({
|
|
69
69
|
assets,
|
|
70
70
|
shares,
|
|
@@ -114,7 +114,7 @@ export const marketV1Repay = ({ market: { chainId, marketParams }, args: { asset
|
|
|
114
114
|
return deepFreeze({
|
|
115
115
|
...tx,
|
|
116
116
|
action: {
|
|
117
|
-
type: "
|
|
117
|
+
type: "blueRepay",
|
|
118
118
|
args: {
|
|
119
119
|
market: marketParams.id,
|
|
120
120
|
assets,
|