@morpho-org/morpho-sdk 9.2.0 → 9.3.0-next.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 +1 -1
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- 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/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +56 -10
- package/lib/cjs/entities/midnight/midnight.js +98 -7
- 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/vaultV2/vaultV2.d.ts +33 -9
- package/lib/cjs/entities/vaultV2/vaultV2.js +33 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +5 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +9 -3
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +10 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/deadShares.js +2 -0
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/types/action.d.ts +10 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- 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/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +56 -10
- package/lib/esm/entities/midnight/midnight.js +99 -8
- 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/vaultV2/vaultV2.d.ts +33 -9
- package/lib/esm/entities/vaultV2/vaultV2.js +33 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +5 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +9 -3
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +3 -1
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/types/action.d.ts +10 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +6 -6
package/lib/esm/blue/utils.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
|
+
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
package/lib/esm/blue/utils.js
CHANGED
|
@@ -2,5 +2,5 @@ export { AdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
defaultPreLiquidationParamsRegistry,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
5
|
+
getDefaultPreLiquidationParams, MarketUtils, MathLib, SharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MidnightAdapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MidnightAdapter, IVaultV2MidnightAdapterAccrualMarket, IVaultV2MidnightAdapterCollateralParams, IVaultV2MidnightAdapterMarket, IVaultV2MidnightAdapterMarketData, IVaultV2MidnightAdapterMarketState, IVaultV2MidnightAdapterPosition, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultV2MidnightAdapterAccrualMarket, VaultV2MidnightAdapterMarketData, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
11
11
|
export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
|
|
12
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
13
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
14
14
|
export { MorphoBlue } from "./blue/index.js";
|
|
15
|
-
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
|
|
15
|
+
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, WithdrawCollateralParams as MidnightWithdrawCollateralParams, } from "./midnight/index.js";
|
|
16
16
|
export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
|
|
17
17
|
export * from "./requirements/index.js";
|
|
18
18
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
5
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MidnightAdapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
7
7
|
export { MorphoBlue } from "./blue/index.js";
|
|
8
8
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
@@ -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,7 +893,7 @@ 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,
|
|
896
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
851
897
|
* @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
|
|
852
898
|
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
853
899
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
@@ -923,7 +969,7 @@ export declare class MorphoMidnight {
|
|
|
923
969
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
924
970
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
925
971
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
926
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
972
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
927
973
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
928
974
|
* (not thrown when `validation` is `false`).
|
|
929
975
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
@@ -997,7 +1043,7 @@ export declare class MorphoMidnight {
|
|
|
997
1043
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
998
1044
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
999
1045
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1000
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1046
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1001
1047
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1002
1048
|
* (not thrown when `validation` is `false`).
|
|
1003
1049
|
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
@@ -1082,7 +1128,7 @@ export declare class MorphoMidnight {
|
|
|
1082
1128
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1083
1129
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1084
1130
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1085
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1131
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1086
1132
|
* @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
|
|
1087
1133
|
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
1088
1134
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
@@ -3,7 +3,7 @@ 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";
|
|
@@ -263,7 +263,7 @@ export class MorphoMidnight {
|
|
|
263
263
|
* @throws {MidnightOfferRatifierMismatchError} when an offer does not use its tree's ratifier.
|
|
264
264
|
* @throws {MidnightZeroAccountError} when `accountAddress` is the zero address.
|
|
265
265
|
* @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,
|
|
266
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
267
267
|
* @throws {MidnightOfferExpiredError} when an offer expiry is not later than the pinned block timestamp.
|
|
268
268
|
* @throws {MidnightOfferExpiryAfterMaturityError} when an offer expiry exceeds its market maturity.
|
|
269
269
|
* @throws {MidnightOfferGroupConsumedError} when an offer group has no remaining capacity.
|
|
@@ -1071,6 +1071,97 @@ export class MorphoMidnight {
|
|
|
1071
1071
|
buildTx: () => tx,
|
|
1072
1072
|
};
|
|
1073
1073
|
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Withdraws collateral directly from Midnight without bundle authorization or token pulls.
|
|
1076
|
+
*
|
|
1077
|
+
* Uses the supplied position snapshot to resolve maxUint256 and check collateral health.
|
|
1078
|
+
* No requirements or RPC reads are needed. The signing account must be accountAddress.
|
|
1079
|
+
*
|
|
1080
|
+
* @param params - Market, owner-bound position, collateral prices and withdrawal amount.
|
|
1081
|
+
* @param params.accountAddress - Collateral owner. This account must send the transaction.
|
|
1082
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
1083
|
+
* @param params.positionData - Owner-bound position snapshot returned by getPositionData.
|
|
1084
|
+
* @param params.collateralPrices - Oracle prices indexed like positionData.collateral and scaled by
|
|
1085
|
+
* ORACLE_PRICE_SCALE; required when the position has debt, otherwise an empty array is safe.
|
|
1086
|
+
* @param params.collateralIndex - Optional collateral index; defaults to 0n. Indexes follow the
|
|
1087
|
+
* market's collateral parameters, which Midnight sorts by token address, not the order they were
|
|
1088
|
+
* listed in when the market was built; check marketData.getCollateralByIndex(index).token.
|
|
1089
|
+
* @param params.assets - Collateral assets to withdraw. maxUint256 resolves the whole balance of
|
|
1090
|
+
* the selected collateral from positionData before building the transaction.
|
|
1091
|
+
* @param params.receiver - Account receiving the withdrawn collateral; defaults to accountAddress.
|
|
1092
|
+
* @returns Lazy handles for a direct Midnight withdrawal.
|
|
1093
|
+
* @throws {ChainIdMismatchError} when the client or market targets another chain.
|
|
1094
|
+
* @throws {MidnightCalldataEncodingError} when accountAddress is malformed or an input cannot be ABI-encoded.
|
|
1095
|
+
* @throws {MidnightZeroAccountError} when accountAddress is zero.
|
|
1096
|
+
* @throws {MidnightMarketAddressMismatchError} when marketData targets another Midnight deployment.
|
|
1097
|
+
* @throws {MissingMarketPriceError} when debt is positive and held collateral has no supplied price.
|
|
1098
|
+
* @throws {MarketIdMismatchError} when positionData belongs to another market.
|
|
1099
|
+
* @throws {AccrualPositionUserMismatchError} when positionData belongs to another account.
|
|
1100
|
+
* @throws {UnknownCollateralIndexError} when collateralIndex is not configured.
|
|
1101
|
+
* @throws {NonPositiveInputError} when the resolved amount is not positive.
|
|
1102
|
+
* @throws {InputExceedsMaxError} when assets exceeds uint128.
|
|
1103
|
+
* @throws {WithdrawExceedsCollateralError} when assets exceeds the collateral balance.
|
|
1104
|
+
* @throws {WithdrawMakesPositionUnhealthyError} when remaining collateral cannot safely cover debt.
|
|
1105
|
+
* @throws {MidnightZeroReceiverError} when receiver is zero.
|
|
1106
|
+
* @throws {MidnightContractReceiverError} when receiver cannot safely receive collateral.
|
|
1107
|
+
* @example
|
|
1108
|
+
* ```ts
|
|
1109
|
+
* const output = midnight.withdrawCollateral({
|
|
1110
|
+
* accountAddress: user,
|
|
1111
|
+
* marketData,
|
|
1112
|
+
* positionData,
|
|
1113
|
+
* collateralPrices,
|
|
1114
|
+
* assets: 1_000n,
|
|
1115
|
+
* });
|
|
1116
|
+
* const tx = output.buildTx();
|
|
1117
|
+
* ```
|
|
1118
|
+
*/
|
|
1119
|
+
withdrawCollateral(params) {
|
|
1120
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
1121
|
+
// Reject invalid owners before preparing the direct call.
|
|
1122
|
+
validateMidnightAccount("accountAddress", params.accountAddress);
|
|
1123
|
+
validateMarketData(params.marketData, this.chainId);
|
|
1124
|
+
validatePositionBinding(params);
|
|
1125
|
+
const collateralIndex = params.collateralIndex ?? 0n;
|
|
1126
|
+
// Reject unconfigured indexes before reading the position balance.
|
|
1127
|
+
MarketUtils.getCollateralByIndex(params.marketData.params, collateralIndex);
|
|
1128
|
+
const index = Number(collateralIndex);
|
|
1129
|
+
const available = params.positionData.collateral[index] ?? 0n;
|
|
1130
|
+
const assets = params.assets === maxUint256 ? available : params.assets;
|
|
1131
|
+
const tx = midnightWithdrawCollateral({
|
|
1132
|
+
chainId: this.chainId,
|
|
1133
|
+
market: params.marketData.params,
|
|
1134
|
+
collateralIndex,
|
|
1135
|
+
assets,
|
|
1136
|
+
onBehalf: params.accountAddress,
|
|
1137
|
+
receiver: params.receiver ?? params.accountAddress,
|
|
1138
|
+
metadata: this.client.options.metadata,
|
|
1139
|
+
});
|
|
1140
|
+
if (assets > available) {
|
|
1141
|
+
throw new WithdrawExceedsCollateralError({
|
|
1142
|
+
withdrawAmount: assets,
|
|
1143
|
+
available,
|
|
1144
|
+
market: params.marketData.id,
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
if (params.positionData.debt > 0n) {
|
|
1148
|
+
const collateral = Array.from({ length: params.marketData.params.collateralParams.length }, (_, i) => params.positionData.collateral[i] ?? 0n);
|
|
1149
|
+
collateral[index] = available - assets;
|
|
1150
|
+
const maxSafeDebt = getMidnightMaxSafeDebt({
|
|
1151
|
+
market: params.marketData,
|
|
1152
|
+
collateral,
|
|
1153
|
+
collateralPrices: params.collateralPrices,
|
|
1154
|
+
});
|
|
1155
|
+
if (params.positionData.debt > maxSafeDebt) {
|
|
1156
|
+
throw new WithdrawMakesPositionUnhealthyError({
|
|
1157
|
+
withdrawAmount: assets,
|
|
1158
|
+
borrowAssets: params.positionData.debt,
|
|
1159
|
+
maxSafeBorrow: maxSafeDebt,
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
return { getRequirements: async () => [], buildTx: () => tx };
|
|
1164
|
+
}
|
|
1074
1165
|
/**
|
|
1075
1166
|
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
1076
1167
|
*
|
|
@@ -1200,7 +1291,7 @@ export class MorphoMidnight {
|
|
|
1200
1291
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1201
1292
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1202
1293
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1203
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1294
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1204
1295
|
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
|
|
1205
1296
|
* @example
|
|
1206
1297
|
* ```ts
|
|
@@ -1271,7 +1362,7 @@ export class MorphoMidnight {
|
|
|
1271
1362
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1272
1363
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1273
1364
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1274
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1365
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1275
1366
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1276
1367
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
1277
1368
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
@@ -1435,7 +1526,7 @@ export class MorphoMidnight {
|
|
|
1435
1526
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1436
1527
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1437
1528
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1438
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1529
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1439
1530
|
* @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
|
|
1440
1531
|
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
1441
1532
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
@@ -1640,7 +1731,7 @@ export class MorphoMidnight {
|
|
|
1640
1731
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1641
1732
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1642
1733
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1643
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1734
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1644
1735
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1645
1736
|
* (not thrown when `validation` is `false`).
|
|
1646
1737
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256` or a `maxConsumed` ceiling exceeds `uint128`.
|
|
@@ -1728,7 +1819,7 @@ export class MorphoMidnight {
|
|
|
1728
1819
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1729
1820
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1730
1821
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1731
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1822
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1732
1823
|
* @throws {MidnightMempoolValidationError} when the Midnight mempool API rejects the offer tree
|
|
1733
1824
|
* (not thrown when `validation` is `false`).
|
|
1734
1825
|
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
@@ -1827,7 +1918,7 @@ export class MorphoMidnight {
|
|
|
1827
1918
|
* @throws {MidnightMarketLltvNotEnabledError} when an uncreated market uses a disabled LLTV.
|
|
1828
1919
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1829
1920
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1830
|
-
* @throws {viem.BaseError} when a pinned block,
|
|
1921
|
+
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1831
1922
|
* @throws {MarketIdMismatchError} when an offer targets another market than `collateral.market`, including a `collateral.market` on another chain or Midnight deployment.
|
|
1832
1923
|
* @throws {EmptyMidnightCollateralSuppliesError} when a collateral market has no collateral supplies.
|
|
1833
1924
|
* @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;
|