@morpho-org/morpho-sdk 9.2.0 → 9.3.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 +4 -4
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +50 -0
- package/lib/cjs/actions/midnight/withdrawCollateral.js +105 -0
- package/lib/cjs/entities/blue/blue.d.ts +4 -7
- package/lib/cjs/entities/blue/blue.js +0 -3
- package/lib/cjs/entities/index.d.ts +1 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +57 -12
- package/lib/cjs/entities/midnight/midnight.js +102 -12
- package/lib/cjs/entities/midnight/publication.d.ts +2 -1
- package/lib/cjs/entities/midnight/publication.js +44 -64
- package/lib/cjs/entities/midnight/types.d.ts +8 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/cjs/entities/vaultV1/vaultV1.js +0 -4
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +0 -4
- package/lib/cjs/entities/vaultV2/vaultV2.js +0 -3
- package/lib/cjs/helpers/deadShares.d.ts +5 -4
- package/lib/cjs/helpers/deadShares.js +5 -4
- package/lib/cjs/types/action.d.ts +10 -1
- package/lib/cjs/types/error.d.ts +1 -6
- package/lib/cjs/types/error.js +1 -6
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +50 -0
- package/lib/esm/actions/midnight/withdrawCollateral.js +101 -0
- package/lib/esm/entities/blue/blue.d.ts +4 -7
- package/lib/esm/entities/blue/blue.js +0 -3
- package/lib/esm/entities/index.d.ts +1 -1
- package/lib/esm/entities/midnight/midnight.d.ts +57 -12
- package/lib/esm/entities/midnight/midnight.js +104 -14
- package/lib/esm/entities/midnight/publication.d.ts +2 -1
- package/lib/esm/entities/midnight/publication.js +45 -65
- package/lib/esm/entities/midnight/types.d.ts +8 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +0 -8
- package/lib/esm/entities/vaultV1/vaultV1.js +0 -4
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +0 -4
- package/lib/esm/entities/vaultV2/vaultV2.js +0 -3
- package/lib/esm/helpers/deadShares.d.ts +5 -4
- package/lib/esm/helpers/deadShares.js +5 -4
- package/lib/esm/types/action.d.ts +10 -1
- package/lib/esm/types/error.d.ts +1 -6
- package/lib/esm/types/error.js +1 -6
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AccrualPosition, type Market, type MidnightFetchParams } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { type Address, type Hex } from "viem";
|
|
3
3
|
import type { MorphoClientType } from "../../types/client.js";
|
|
4
|
-
import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction } from "../../types/index.js";
|
|
5
|
-
import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams } from "./types.js";
|
|
4
|
+
import { type MidnightCancelAndMakeAction, type MidnightGroupCancellation, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction, type MidnightTakeRepayWithdrawCollateralAction, type MidnightTakeWithdrawAction, type MidnightWithdrawCollateralAction } from "../../types/index.js";
|
|
5
|
+
import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams, TakeRepayWithdrawCollateralParams, TakeWithdrawParams, WithdrawCollateralParams } from "./types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Entity methods exposed by `client.morpho.midnight(chainId)`.
|
|
8
8
|
*
|
|
@@ -30,7 +30,7 @@ import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOf
|
|
|
30
30
|
* const tx = output.buildTx();
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
|
|
33
|
+
export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "takeWithdraw" | "supplyCollateralTakeBorrow" | "takeRepayWithdrawCollateral" | "supplyCollateral" | "withdrawCollateral" | "makeLend" | "makeBorrow" | "supplyBlueMakeLend" | "makeWithdraw" | "makeRepay" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffers">;
|
|
34
34
|
/**
|
|
35
35
|
* Entity facade for Midnight fixed-rate action flows.
|
|
36
36
|
*
|
|
@@ -126,7 +126,7 @@ export declare class MorphoMidnight {
|
|
|
126
126
|
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
127
127
|
* @throws {MidnightZeroAccountError} when `accountAddress` is the zero address.
|
|
128
128
|
* @throws {MidnightCalldataEncodingError} when an offer cannot be ABI-encoded, such as an out-of-range integer, or `accountAddress` is not a well-formed address.
|
|
129
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
129
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
130
130
|
* @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
|
|
131
131
|
* @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
|
|
132
132
|
* @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
|
|
@@ -591,6 +591,52 @@ export declare class MorphoMidnight {
|
|
|
591
591
|
* ```
|
|
592
592
|
*/
|
|
593
593
|
takeRepayWithdrawCollateral(params: TakeRepayWithdrawCollateralParams): MidnightActionOutput<MidnightTakeRepayWithdrawCollateralAction>;
|
|
594
|
+
/**
|
|
595
|
+
* Withdraws collateral directly from Midnight without bundle authorization or token pulls.
|
|
596
|
+
*
|
|
597
|
+
* Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
|
|
598
|
+
* No requirements or RPC reads are needed. The signing account must be accountAddress.
|
|
599
|
+
*
|
|
600
|
+
* @param params - Market, owner-bound position, collateral prices and withdrawal amount.
|
|
601
|
+
* @param params.accountAddress - Collateral owner. This account must send the transaction.
|
|
602
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
603
|
+
* @param params.positionData - Owner-bound position snapshot returned by getPositionData.
|
|
604
|
+
* @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
|
|
605
|
+
* ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
|
|
606
|
+
* @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
|
|
607
|
+
* market's collateral parameters, which Midnight sorts by token address, not the order they were
|
|
608
|
+
* listed in when the market was built; check marketData.getCollateralByIndex(index).token.
|
|
609
|
+
* @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
|
|
610
|
+
* the selected collateral from positionData before building the transaction.
|
|
611
|
+
* @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
|
|
612
|
+
* @returns Lazy handles for a direct Midnight withdrawal.
|
|
613
|
+
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
614
|
+
* @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
|
|
615
|
+
* @throws {MidnightZeroAccountError} when accountAddress is zero.
|
|
616
|
+
* @throws {MidnightMarketAddressMismatchError} when marketData targets another Midnight deployment.
|
|
617
|
+
* @throws {MissingMarketPriceError} when debt is positive and held collateral has no supplied price.
|
|
618
|
+
* @throws {MarketIdMismatchError} when positionData belongs to another market.
|
|
619
|
+
* @throws {AccrualPositionUserMismatchError} when positionData belongs to another account.
|
|
620
|
+
* @throws {UnknownCollateralIndexError} when collateralIndex is not configured.
|
|
621
|
+
* @throws {NonPositiveInputError} when the resolved amount is not positive.
|
|
622
|
+
* @throws {InputExceedsMaxError} when assets exceeds uint128.
|
|
623
|
+
* @throws {WithdrawExceedsCollateralError} when assets exceeds the collateral balance.
|
|
624
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when remaining collateral cannot safely cover debt.
|
|
625
|
+
* @throws {MidnightZeroReceiverError} when receiver is zero.
|
|
626
|
+
* @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
|
|
627
|
+
* @example
|
|
628
|
+
* ```ts
|
|
629
|
+
* const output = midnight.withdrawCollateral({
|
|
630
|
+
* accountAddress: user,
|
|
631
|
+
* marketData,
|
|
632
|
+
* positionData,
|
|
633
|
+
* collateralPrices,
|
|
634
|
+
* assets: 1_000n,
|
|
635
|
+
* });
|
|
636
|
+
* const tx = output.buildTx();
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
withdrawCollateral(params: WithdrawCollateralParams): MidnightActionOutput<MidnightWithdrawCollateralAction>;
|
|
594
640
|
/**
|
|
595
641
|
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
596
642
|
*
|
|
@@ -684,7 +730,7 @@ export declare class MorphoMidnight {
|
|
|
684
730
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
685
731
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
686
732
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
687
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
733
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
688
734
|
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
|
|
689
735
|
* @example
|
|
690
736
|
* ```ts
|
|
@@ -746,7 +792,7 @@ export declare class MorphoMidnight {
|
|
|
746
792
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
747
793
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
748
794
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
749
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
795
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
750
796
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
751
797
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
752
798
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
@@ -847,9 +893,8 @@ export declare class MorphoMidnight {
|
|
|
847
893
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
848
894
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
849
895
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
850
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
851
|
-
* @throws {
|
|
852
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
896
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
897
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
853
898
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
854
899
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
855
900
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -923,7 +968,7 @@ export declare class MorphoMidnight {
|
|
|
923
968
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
924
969
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
925
970
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
926
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
971
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
927
972
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
928
973
|
* (not thrown when `validation` is `false`).
|
|
929
974
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
@@ -997,7 +1042,7 @@ export declare class MorphoMidnight {
|
|
|
997
1042
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
998
1043
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
999
1044
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1000
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1045
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1001
1046
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1002
1047
|
* (not thrown when `validation` is `false`).
|
|
1003
1048
|
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
@@ -1082,7 +1127,7 @@ export declare class MorphoMidnight {
|
|
|
1082
1127
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1083
1128
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1084
1129
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1085
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1130
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1086
1131
|
* @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
|
|
1087
1132
|
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
1088
1133
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
@@ -3,12 +3,11 @@ import { fetchMarket as fetchBlueMarket } from "@morpho-org/blue-sdk-viem";
|
|
|
3
3
|
import { fetchAccrualPosition, fetchMarket, MarketParams, MarketUtils, Payload, PriceRatifierV1, RateRatifierV1, Tree, } from "@morpho-org/midnight-sdk";
|
|
4
4
|
import { _try, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
5
5
|
import { isAddress, isAddressEqual, maxUint256, zeroAddress, } from "viem";
|
|
6
|
-
import { midnightCancelAndMake, midnightRedeem, midnightRepayWithdrawCollateral, midnightSupplyCollateral, midnightSupplyCollateralTakeBorrow, midnightTakeBorrow, midnightTakeLend, midnightTakeRepayWithdrawCollateral, midnightTakeWithdraw, } from "../../actions/midnight/index.js";
|
|
6
|
+
import { midnightCancelAndMake, midnightRedeem, midnightRepayWithdrawCollateral, midnightSupplyCollateral, midnightSupplyCollateralTakeBorrow, midnightTakeBorrow, midnightTakeLend, midnightTakeRepayWithdrawCollateral, midnightTakeWithdraw, midnightWithdrawCollateral, } from "../../actions/midnight/index.js";
|
|
7
7
|
import { getMidnightApprovalRequirements, getMidnightAuthorizationRequirement, } from "../../actions/requirements/index.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
9
|
import { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "../../helpers/callback.js";
|
|
10
10
|
import { MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS } from "../../helpers/constant.js";
|
|
11
|
-
import { validateBlueMarketDeadShares } from "../../helpers/deadShares.js";
|
|
12
11
|
import { encodeMidnightMarketId, wrapMidnightEncoding, } from "../../helpers/encodeMidnightCalldata.js";
|
|
13
12
|
import { getMidnightMaxSafeDebt, validateChainId, } from "../../helpers/index.js";
|
|
14
13
|
import { validateMidnightAccount, validateMidnightAddress, } from "../../helpers/validateMidnightAccount.js";
|
|
@@ -17,7 +16,7 @@ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js"
|
|
|
17
16
|
import { validateMidnightBytes32 } from "../../helpers/validateMidnightPublication.js";
|
|
18
17
|
import { validateMidnightTakeFeasibility } from "../../helpers/validateMidnightTakeFeasibility.js";
|
|
19
18
|
import { validateOfferSides } from "../../helpers/validateOfferSides.js";
|
|
20
|
-
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError, InsufficientMidnightWithdrawableLiquidityError, MarketIdMismatchError, MidnightInvalidAccountAddressError, MidnightOfferCallbackDataMismatchError, MidnightOfferCallbackMismatchError, MidnightOfferContinuousFeeCapError, MidnightOfferMakerMismatchError, MidnightOfferMarketAddressMismatchError, MidnightOfferMarketChainMismatchError, MidnightOfferMarketLoanTokenMismatchError, MidnightOfferNotReduceOnlyError, MidnightOfferRatifierMismatchError, MidnightOfferReduceOnlyError, MidnightOfferSellerReceiverMismatchError, MidnightRedeemExceedsCreditError, MidnightRepayExceedsDebtError, MidnightTakeDeadlineTooFarError, MidnightTakeTargetUnreachableError, MidnightZeroOnBehalfError, MissingAccrualPositionError, NegativeInputError, NoMidnightCreditToRedeemError, NonPositiveInputError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, ZeroBlueParkingSharesError, } from "../../types/index.js";
|
|
19
|
+
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError, EmptyBlueParkingMarketError, InsufficientMidnightWithdrawableLiquidityError, MarketIdMismatchError, MidnightInvalidAccountAddressError, MidnightOfferCallbackDataMismatchError, MidnightOfferCallbackMismatchError, MidnightOfferContinuousFeeCapError, MidnightOfferMakerMismatchError, MidnightOfferMarketAddressMismatchError, MidnightOfferMarketChainMismatchError, MidnightOfferMarketLoanTokenMismatchError, MidnightOfferNotReduceOnlyError, MidnightOfferRatifierMismatchError, MidnightOfferReduceOnlyError, MidnightOfferSellerReceiverMismatchError, MidnightRedeemExceedsCreditError, MidnightRepayExceedsDebtError, MidnightTakeDeadlineTooFarError, MidnightTakeTargetUnreachableError, MidnightZeroOnBehalfError, MissingAccrualPositionError, NegativeInputError, NoMidnightCreditToRedeemError, NonPositiveInputError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, ZeroBlueParkingSharesError, } from "../../types/index.js";
|
|
21
20
|
import { validateMidnightDeadline } from "./deadline.js";
|
|
22
21
|
import { fetchMidnightMakerOfferStates, offerMarketParams, validateMidnightMakerOfferCallbacks, validateMidnightMakerOfferStates, } from "./publication.js";
|
|
23
22
|
const validatePositionBinding = (params) => {
|
|
@@ -263,7 +262,7 @@ export class MorphoMidnight {
|
|
|
263
262
|
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
264
263
|
* @throws {MidnightZeroAccountError} when `accountAddress` is the zero address.
|
|
265
264
|
* @throws {MidnightCalldataEncodingError} when an offer cannot be ABI-encoded, such as an out-of-range integer, or `accountAddress` is not a well-formed address.
|
|
266
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
265
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
267
266
|
* @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
|
|
268
267
|
* @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
|
|
269
268
|
* @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
|
|
@@ -1071,6 +1070,97 @@ export class MorphoMidnight {
|
|
|
1071
1070
|
buildTx: () => tx,
|
|
1072
1071
|
};
|
|
1073
1072
|
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Withdraws collateral directly from Midnight without bundle authorization or token pulls.
|
|
1075
|
+
*
|
|
1076
|
+
* Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
|
|
1077
|
+
* No requirements or RPC reads are needed. The signing account must be accountAddress.
|
|
1078
|
+
*
|
|
1079
|
+
* @param params - Market, owner-bound position, collateral prices and withdrawal amount.
|
|
1080
|
+
* @param params.accountAddress - Collateral owner. This account must send the transaction.
|
|
1081
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
1082
|
+
* @param params.positionData - Owner-bound position snapshot returned by getPositionData.
|
|
1083
|
+
* @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
|
|
1084
|
+
* ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
|
|
1085
|
+
* @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
|
|
1086
|
+
* market's collateral parameters, which Midnight sorts by token address, not the order they were
|
|
1087
|
+
* listed in when the market was built; check marketData.getCollateralByIndex(index).token.
|
|
1088
|
+
* @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
|
|
1089
|
+
* the selected collateral from positionData before building the transaction.
|
|
1090
|
+
* @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
|
|
1091
|
+
* @returns Lazy handles for a direct Midnight withdrawal.
|
|
1092
|
+
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
1093
|
+
* @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
|
|
1094
|
+
* @throws {MidnightZeroAccountError} when accountAddress is zero.
|
|
1095
|
+
* @throws {MidnightMarketAddressMismatchError} when marketData targets another Midnight deployment.
|
|
1096
|
+
* @throws {MissingMarketPriceError} when debt is positive and held collateral has no supplied price.
|
|
1097
|
+
* @throws {MarketIdMismatchError} when positionData belongs to another market.
|
|
1098
|
+
* @throws {AccrualPositionUserMismatchError} when positionData belongs to another account.
|
|
1099
|
+
* @throws {UnknownCollateralIndexError} when collateralIndex is not configured.
|
|
1100
|
+
* @throws {NonPositiveInputError} when the resolved amount is not positive.
|
|
1101
|
+
* @throws {InputExceedsMaxError} when assets exceeds uint128.
|
|
1102
|
+
* @throws {WithdrawExceedsCollateralError} when assets exceeds the collateral balance.
|
|
1103
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when remaining collateral cannot safely cover debt.
|
|
1104
|
+
* @throws {MidnightZeroReceiverError} when receiver is zero.
|
|
1105
|
+
* @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* const output = midnight.withdrawCollateral({
|
|
1109
|
+
* accountAddress: user,
|
|
1110
|
+
* marketData,
|
|
1111
|
+
* positionData,
|
|
1112
|
+
* collateralPrices,
|
|
1113
|
+
* assets: 1_000n,
|
|
1114
|
+
* });
|
|
1115
|
+
* const tx = output.buildTx();
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
withdrawCollateral(params) {
|
|
1119
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
1120
|
+
// Reject invalid owners before preparing the direct call.
|
|
1121
|
+
validateMidnightAccount("accountAddress", params.accountAddress);
|
|
1122
|
+
validateMarketData(params.marketData, this.chainId);
|
|
1123
|
+
validatePositionBinding(params);
|
|
1124
|
+
const collateralIndex = params.collateralIndex ?? 0n;
|
|
1125
|
+
// Reject unconfigured indexes before reading the position balance.
|
|
1126
|
+
MarketUtils.getCollateralByIndex(params.marketData.params, collateralIndex);
|
|
1127
|
+
const index = Number(collateralIndex);
|
|
1128
|
+
const available = params.positionData.collateral[index] ?? 0n;
|
|
1129
|
+
const assets = params.assets === maxUint256 ? available : params.assets;
|
|
1130
|
+
const tx = midnightWithdrawCollateral({
|
|
1131
|
+
chainId: this.chainId,
|
|
1132
|
+
market: params.marketData.params,
|
|
1133
|
+
collateralIndex,
|
|
1134
|
+
assets,
|
|
1135
|
+
onBehalf: params.accountAddress,
|
|
1136
|
+
receiver: params.receiver ?? params.accountAddress,
|
|
1137
|
+
metadata: this.client.options.metadata,
|
|
1138
|
+
});
|
|
1139
|
+
if (assets > available) {
|
|
1140
|
+
throw new WithdrawExceedsCollateralError({
|
|
1141
|
+
withdrawAmount: assets,
|
|
1142
|
+
available,
|
|
1143
|
+
market: params.marketData.id,
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
if (params.positionData.debt > 0n) {
|
|
1147
|
+
const collateral = Array.from({ length: params.marketData.params.collateralParams.length }, (_, i) => params.positionData.collateral[i] ?? 0n);
|
|
1148
|
+
collateral[index] = available - assets;
|
|
1149
|
+
const maxSafeDebt = getMidnightMaxSafeDebt({
|
|
1150
|
+
market: params.marketData,
|
|
1151
|
+
collateral,
|
|
1152
|
+
collateralPrices: params.collateralPrices,
|
|
1153
|
+
});
|
|
1154
|
+
if (params.positionData.debt > maxSafeDebt) {
|
|
1155
|
+
throw new WithdrawMakesPositionUnhealthyError({
|
|
1156
|
+
withdrawAmount: assets,
|
|
1157
|
+
borrowAssets: params.positionData.debt,
|
|
1158
|
+
maxSafeBorrow: maxSafeDebt,
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return { getRequirements: async () => [], buildTx: () => tx };
|
|
1163
|
+
}
|
|
1074
1164
|
/**
|
|
1075
1165
|
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
1076
1166
|
*
|
|
@@ -1200,7 +1290,7 @@ export class MorphoMidnight {
|
|
|
1200
1290
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1201
1291
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1202
1292
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1203
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1293
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1204
1294
|
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
|
|
1205
1295
|
* @example
|
|
1206
1296
|
* ```ts
|
|
@@ -1271,7 +1361,7 @@ export class MorphoMidnight {
|
|
|
1271
1361
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1272
1362
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1273
1363
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1274
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1364
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1275
1365
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1276
1366
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
1277
1367
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
@@ -1435,9 +1525,8 @@ export class MorphoMidnight {
|
|
|
1435
1525
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1436
1526
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1437
1527
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1438
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1439
|
-
* @throws {
|
|
1440
|
-
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
1528
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1529
|
+
* @throws {EmptyBlueParkingMarketError} when `blueMarket` has no supply shares.
|
|
1441
1530
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
1442
1531
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1443
1532
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -1493,8 +1582,9 @@ export class MorphoMidnight {
|
|
|
1493
1582
|
}),
|
|
1494
1583
|
]);
|
|
1495
1584
|
const market = _try(() => fetched.accrueInterest(MathLib.max(Time.timestamp(), fetched.lastUpdate)), UnsupportedMarketIrmError) ?? fetched;
|
|
1496
|
-
|
|
1497
|
-
|
|
1585
|
+
if (market.totalSupplyShares === 0n) {
|
|
1586
|
+
throw new EmptyBlueParkingMarketError({ marketId: blueMarketId });
|
|
1587
|
+
}
|
|
1498
1588
|
if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
|
|
1499
1589
|
throw new ZeroBlueParkingSharesError({
|
|
1500
1590
|
marketId: blueMarketId,
|
|
@@ -1640,7 +1730,7 @@ export class MorphoMidnight {
|
|
|
1640
1730
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1641
1731
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1642
1732
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1643
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1733
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1644
1734
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1645
1735
|
* (not thrown when `validation` is `false`).
|
|
1646
1736
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
@@ -1728,7 +1818,7 @@ export class MorphoMidnight {
|
|
|
1728
1818
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1729
1819
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1730
1820
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1731
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1821
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1732
1822
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1733
1823
|
* (not thrown when `validation` is `false`).
|
|
1734
1824
|
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
@@ -1827,7 +1917,7 @@ export class MorphoMidnight {
|
|
|
1827
1917
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1828
1918
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1829
1919
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1830
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1920
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1831
1921
|
* @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
|
|
1832
1922
|
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
1833
1923
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
@@ -87,6 +87,7 @@ export declare function validateMidnightMakerOfferStates(params: {
|
|
|
87
87
|
*
|
|
88
88
|
* The reader uses a single block for contract reads and returns that block's
|
|
89
89
|
* timestamp as `now`; oracle code checks use the same block number.
|
|
90
|
+
* Contract reads do not require a Multicall3 deployment or viem chain metadata.
|
|
90
91
|
*
|
|
91
92
|
* @internal
|
|
92
93
|
* @param params.client - Viem client used for state reads.
|
|
@@ -96,7 +97,7 @@ export declare function validateMidnightMakerOfferStates(params: {
|
|
|
96
97
|
* @returns Per-offer states plus the timestamp of the pinned block.
|
|
97
98
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
98
99
|
* another chain than `params.chainId`.
|
|
99
|
-
* @throws {viem.BaseError} when block,
|
|
100
|
+
* @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
|
|
100
101
|
* @example
|
|
101
102
|
* ```ts
|
|
102
103
|
* const { states, now } = await fetchMidnightMakerOfferStates({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEFAULT_TICK_SPACING, Market, MarketParams, MarketUtils, midnightAbi, RateRatifierV1, } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { getChainAddress, MathLib } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256, zeroAddress } from "viem";
|
|
4
|
-
import { getBlock, getBlockNumber, getCode,
|
|
4
|
+
import { getBlock, getBlockNumber, getCode, readContract } from "viem/actions";
|
|
5
5
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
6
6
|
import { MidnightMarketLiquidationCursorNotEnabledError, MidnightMarketLltvNotEnabledError, MidnightMarketMaturityTooFarError, MidnightMarketOracleWithoutCodeError, MidnightOfferCallbackNotSupportedError, MidnightOfferContinuousFeeCapBelowMarketFeeError, MidnightOfferExpiredError, MidnightOfferExpiryAfterMaturityError, MidnightOfferGroupConsumedError, MidnightOfferNoCreditError, MidnightOfferNoDebtError, MidnightOfferRateBoundUnreachableError, MidnightOfferTickSpacingError, MidnightOfferZeroPriceSellError, } from "../../types/midnightPublicationError.js";
|
|
7
7
|
// Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
|
|
@@ -164,6 +164,7 @@ export function validateMidnightMakerOfferStates(params) {
|
|
|
164
164
|
*
|
|
165
165
|
* The reader uses a single block for contract reads and returns that block's
|
|
166
166
|
* timestamp as `now`; oracle code checks use the same block number.
|
|
167
|
+
* Contract reads do not require a Multicall3 deployment or viem chain metadata.
|
|
167
168
|
*
|
|
168
169
|
* @internal
|
|
169
170
|
* @param params.client - Viem client used for state reads.
|
|
@@ -173,7 +174,7 @@ export function validateMidnightMakerOfferStates(params) {
|
|
|
173
174
|
* @returns Per-offer states plus the timestamp of the pinned block.
|
|
174
175
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
175
176
|
* another chain than `params.chainId`.
|
|
176
|
-
* @throws {viem.BaseError} when block,
|
|
177
|
+
* @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
|
|
177
178
|
* @example
|
|
178
179
|
* ```ts
|
|
179
180
|
* const { states, now } = await fetchMidnightMakerOfferStates({
|
|
@@ -222,76 +223,55 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
222
223
|
])).values(),
|
|
223
224
|
];
|
|
224
225
|
const [marketStates, consumedValues, creditValues, debtValues, defaultFees, lltvEnabledByCollateral, liquidationCursorEnabledByCollateral,] = await Promise.all([
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
args: [id],
|
|
231
|
-
})),
|
|
232
|
-
allowFailure: false,
|
|
226
|
+
Promise.all(markets.map(({ id }) => readContract(params.client, {
|
|
227
|
+
address: midnight,
|
|
228
|
+
abi: midnightAbi,
|
|
229
|
+
functionName: "marketState",
|
|
230
|
+
args: [id],
|
|
233
231
|
blockNumber,
|
|
234
|
-
}),
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
args: [maker, group],
|
|
241
|
-
})),
|
|
242
|
-
allowFailure: false,
|
|
232
|
+
}))),
|
|
233
|
+
Promise.all(groups.map(({ maker, group }) => readContract(params.client, {
|
|
234
|
+
address: midnight,
|
|
235
|
+
abi: midnightAbi,
|
|
236
|
+
functionName: "consumed",
|
|
237
|
+
args: [maker, group],
|
|
243
238
|
blockNumber,
|
|
244
|
-
}),
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
args: [id, maker],
|
|
251
|
-
})),
|
|
252
|
-
allowFailure: false,
|
|
239
|
+
}))),
|
|
240
|
+
Promise.all(owners.map(({ id, maker }) => readContract(params.client, {
|
|
241
|
+
address: midnight,
|
|
242
|
+
abi: midnightAbi,
|
|
243
|
+
functionName: "credit",
|
|
244
|
+
args: [id, maker],
|
|
253
245
|
blockNumber,
|
|
254
|
-
}),
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
args: [id, maker],
|
|
261
|
-
})),
|
|
262
|
-
allowFailure: false,
|
|
246
|
+
}))),
|
|
247
|
+
Promise.all(owners.map(({ id, maker }) => readContract(params.client, {
|
|
248
|
+
address: midnight,
|
|
249
|
+
abi: midnightAbi,
|
|
250
|
+
functionName: "debt",
|
|
251
|
+
args: [id, maker],
|
|
263
252
|
blockNumber,
|
|
264
|
-
}),
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
args: [loanToken],
|
|
271
|
-
})),
|
|
272
|
-
allowFailure: false,
|
|
253
|
+
}))),
|
|
254
|
+
Promise.all(defaultFeeTokens.map((loanToken) => readContract(params.client, {
|
|
255
|
+
address: midnight,
|
|
256
|
+
abi: midnightAbi,
|
|
257
|
+
functionName: "defaultContinuousFee",
|
|
258
|
+
args: [loanToken],
|
|
273
259
|
blockNumber,
|
|
274
|
-
}),
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
args: [collateral.lltv],
|
|
281
|
-
})),
|
|
282
|
-
allowFailure: false,
|
|
260
|
+
}))),
|
|
261
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(params.client, {
|
|
262
|
+
address: midnight,
|
|
263
|
+
abi: midnightAbi,
|
|
264
|
+
functionName: "isLltvEnabled",
|
|
265
|
+
args: [collateral.lltv],
|
|
283
266
|
blockNumber,
|
|
284
|
-
}),
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
args: [collateral.liquidationCursor],
|
|
291
|
-
})),
|
|
292
|
-
allowFailure: false,
|
|
267
|
+
}))),
|
|
268
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(params.client, {
|
|
269
|
+
address: midnight,
|
|
270
|
+
abi: midnightAbi,
|
|
271
|
+
functionName: "isLiquidationCursorEnabled",
|
|
272
|
+
args: [collateral.liquidationCursor],
|
|
293
273
|
blockNumber,
|
|
294
|
-
}),
|
|
274
|
+
}))),
|
|
295
275
|
]);
|
|
296
276
|
const defaultFeeByLoanToken = new Map(defaultFeeTokens.map((loanToken, index) => [
|
|
297
277
|
loanToken.toLowerCase(),
|
|
@@ -235,6 +235,14 @@ export interface SupplyCollateralParams extends MarketActionParams {
|
|
|
235
235
|
readonly reservedCollateralAssets?: bigint;
|
|
236
236
|
readonly collateralIndex?: bigint;
|
|
237
237
|
}
|
|
238
|
+
/** Parameters for a direct Midnight collateral withdrawal. */
|
|
239
|
+
export interface WithdrawCollateralParams extends MarketActionParams, MidnightPositionHealthParams {
|
|
240
|
+
readonly collateralIndex?: bigint;
|
|
241
|
+
/** Collateral assets to withdraw; maxUint256 resolves the snapshot's whole balance. */
|
|
242
|
+
readonly assets: bigint;
|
|
243
|
+
/** Defaults to accountAddress. */
|
|
244
|
+
readonly receiver?: Address;
|
|
245
|
+
}
|
|
238
246
|
/** Parameters for the Midnight redeem flow. */
|
|
239
247
|
export interface RedeemParams {
|
|
240
248
|
readonly accountAddress: Address;
|
|
@@ -104,10 +104,6 @@ export interface VaultV1Actions {
|
|
|
104
104
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
105
105
|
* // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
|
|
106
106
|
* ```
|
|
107
|
-
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
108
|
-
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
109
|
-
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
110
|
-
* holds less than the required dead deposit.
|
|
111
107
|
*/
|
|
112
108
|
deposit: (params: {
|
|
113
109
|
readonly userAddress: Address;
|
|
@@ -461,10 +457,6 @@ export interface VaultV1Actions {
|
|
|
461
457
|
* const tx = migration.buildTx(signatures);
|
|
462
458
|
* // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
|
|
463
459
|
* ```
|
|
464
|
-
* @throws {MissingDeadSharesDataError} when `targetVault` lacks the dead-share, cap or adapter data
|
|
465
|
-
* the dead-deposit check needs. The source Vault V1 is not checked.
|
|
466
|
-
* @throws {InsufficientDeadSharesError} when `targetVault`, or a market or vault it can allocate
|
|
467
|
-
* to, holds less than the required dead deposit.
|
|
468
460
|
*/
|
|
469
461
|
migrateToV2: (params: {
|
|
470
462
|
readonly userAddress: Address;
|
|
@@ -6,7 +6,6 @@ import { readContract } from "viem/actions";
|
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
-
import { validateVaultV1DeadShares, validateVaultV2DeadShares, } from "../../helpers/deadShares.js";
|
|
10
9
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
11
10
|
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
12
11
|
import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
@@ -76,8 +75,6 @@ export class MorphoVaultV1 {
|
|
|
76
75
|
// The native path must target the chain's registered wrapped-native asset.
|
|
77
76
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
78
77
|
}
|
|
79
|
-
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
80
|
-
validateVaultV1DeadShares(vaultData);
|
|
81
78
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
82
79
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
83
80
|
vaultData,
|
|
@@ -473,7 +470,6 @@ export class MorphoVaultV1 {
|
|
|
473
470
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
474
471
|
});
|
|
475
472
|
// Only the destination receives a deposit; the source vault is an exit.
|
|
476
|
-
validateVaultV2DeadShares(params.targetVault);
|
|
477
473
|
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
478
474
|
const grossAssets = assets ??
|
|
479
475
|
params.sourceVault
|
|
@@ -110,10 +110,6 @@ export interface VaultV2Actions {
|
|
|
110
110
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
111
111
|
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
112
112
|
* ```
|
|
113
|
-
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
114
|
-
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
115
|
-
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
116
|
-
* holds less than the required dead deposit.
|
|
117
113
|
*/
|
|
118
114
|
deposit: (params: {
|
|
119
115
|
readonly userAddress: Address;
|
|
@@ -6,7 +6,6 @@ import { readContract } from "viem/actions";
|
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
-
import { validateVaultV2DeadShares } from "../../helpers/deadShares.js";
|
|
10
9
|
import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
11
10
|
import { validateDeadline, validateNativeVaultAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
12
11
|
import { AdapterNotPartOfVaultError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemZeroDeallocationError, InputExceedsMaxError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, VaultAddressMismatchError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawSharePriceBelowFloorError, VaultV2ForceWithdrawZeroSharePriceError, VaultV2ForceWithdrawZeroWithdrawalError, VaultV2SingleAdapterRequiredError, VaultV2UndecodableLiquidityDataError, VaultV2UnsupportedExitAdapterError, VaultV2UnsupportedLiquidityAdapterError, } from "../../types/index.js";
|
|
@@ -79,8 +78,6 @@ export class MorphoVaultV2 {
|
|
|
79
78
|
// The native path must target the chain's registered wrapped-native asset.
|
|
80
79
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
81
80
|
}
|
|
82
|
-
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
83
|
-
validateVaultV2DeadShares(vaultData);
|
|
84
81
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
85
82
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
86
83
|
vaultData,
|
|
@@ -55,15 +55,16 @@ export declare function validateVaultV1DeadShares(vault: AccrualVault, path?: De
|
|
|
55
55
|
/**
|
|
56
56
|
* Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
|
|
57
57
|
* `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
|
|
58
|
-
* `1 / (10 * virtualShares)`, and
|
|
59
|
-
* absolute cap
|
|
58
|
+
* `1 / (10 * virtualShares)`, and each currently allocated Blue market or Vault V1 with a non-zero
|
|
59
|
+
* absolute cap passing its own rule. A market with a positive cap but no current allocation is not
|
|
60
|
+
* checked; a later reallocation can reach it.
|
|
60
61
|
*
|
|
61
62
|
* @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
|
|
62
63
|
* @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
|
|
63
|
-
* @returns Nothing; returns normally when the vault and
|
|
64
|
+
* @returns Nothing; returns normally when the vault and its checked allocations pass.
|
|
64
65
|
* @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
|
|
65
66
|
* adapter the SDK cannot hydrate is missing.
|
|
66
|
-
* @throws {InsufficientDeadSharesError} when the vault or
|
|
67
|
+
* @throws {InsufficientDeadSharesError} when the vault or a checked market or Vault V1 fails the rule.
|
|
67
68
|
* @example
|
|
68
69
|
* ```ts
|
|
69
70
|
* import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
|