@morpho-org/morpho-sdk 8.2.0 → 8.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 +1 -1
- package/lib/cjs/actions/midnight/redeem.d.ts +1 -0
- package/lib/cjs/actions/midnight/redeem.js +4 -0
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +4 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +3 -1
- package/lib/cjs/entities/midnight/midnight.js +3 -1
- package/lib/cjs/types/error.d.ts +8 -0
- package/lib/cjs/types/error.js +15 -2
- package/lib/esm/actions/midnight/redeem.d.ts +1 -0
- package/lib/esm/actions/midnight/redeem.js +6 -2
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +6 -2
- package/lib/esm/entities/midnight/midnight.d.ts +3 -1
- package/lib/esm/entities/midnight/midnight.js +3 -1
- package/lib/esm/types/error.d.ts +8 -0
- package/lib/esm/types/error.js +12 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ then call `buildTx()` without a separate root signature.
|
|
|
62
62
|
|
|
63
63
|
`VaultExitBundlesV1`, `VaultBundlesV1`, and `BlueBundlesV1` are registered on Ethereum, Base,
|
|
64
64
|
Arbitrum, Optimism, Polygon, World Chain, Unichain, HyperEVM, Katana, Monad, Stable, Tempo,
|
|
65
|
-
Robinhood Chain, and
|
|
65
|
+
Robinhood Chain, Arc, and X Layer. Custom deployments can still be configured with `registerCustomAddresses`.
|
|
66
66
|
|
|
67
67
|
## How it works
|
|
68
68
|
|
|
@@ -30,6 +30,7 @@ export interface MidnightRedeemParams {
|
|
|
30
30
|
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
31
31
|
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
32
32
|
* @throws {InputExceedsMaxError} when `units` exceeds `uint128`.
|
|
33
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
33
34
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
34
35
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
35
36
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
@@ -29,6 +29,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
29
29
|
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
30
30
|
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
31
31
|
* @throws {InputExceedsMaxError} when `units` exceeds `uint128`.
|
|
32
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
32
33
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
33
34
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
34
35
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
@@ -51,6 +52,9 @@ const midnightRedeem = (params) => {
|
|
|
51
52
|
throw new index_js_2.NonPositiveInputError("units", params.units);
|
|
52
53
|
}
|
|
53
54
|
(0, validateMidnightBounds_js_1.validateMidnightUint128Field)("units", params.units);
|
|
55
|
+
if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
|
|
56
|
+
throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
|
|
57
|
+
}
|
|
54
58
|
// Reject markets from another chain deployment before encoding the call.
|
|
55
59
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
56
60
|
const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
|
|
@@ -27,6 +27,7 @@ export interface MidnightSupplyCollateralParams {
|
|
|
27
27
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
28
28
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
29
29
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
|
|
30
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
30
31
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
31
32
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
32
33
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
@@ -25,6 +25,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
25
25
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
26
26
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
27
27
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
|
|
28
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
28
29
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
29
30
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
30
31
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
@@ -46,6 +47,9 @@ const midnightSupplyCollateral = (params) => {
|
|
|
46
47
|
throw new index_js_2.NonPositiveInputError("assets", params.assets);
|
|
47
48
|
}
|
|
48
49
|
(0, validateMidnightBounds_js_1.validateMidnightUint128Field)("assets", params.assets);
|
|
50
|
+
if ((0, viem_1.isAddressEqual)(params.onBehalf, viem_1.zeroAddress)) {
|
|
51
|
+
throw new index_js_2.MidnightZeroOnBehalfError("onBehalf");
|
|
52
|
+
}
|
|
49
53
|
// Reject markets from another chain deployment before encoding the call.
|
|
50
54
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
51
55
|
const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
|
|
@@ -594,6 +594,7 @@ export declare class MorphoMidnight {
|
|
|
594
594
|
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
595
595
|
* @throws {InputExceedsMaxError} when `collateralAssets` exceeds `uint128`.
|
|
596
596
|
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
597
|
+
* @throws {MidnightZeroOnBehalfError} from `buildTx()` when `accountAddress` is the zero address.
|
|
597
598
|
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
598
599
|
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
|
|
599
600
|
* @example
|
|
@@ -1080,14 +1081,15 @@ export declare class MorphoMidnight {
|
|
|
1080
1081
|
* @throws {MissingAccrualPositionError} when no position snapshot is supplied.
|
|
1081
1082
|
* @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
|
|
1082
1083
|
* @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
|
|
1084
|
+
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1083
1085
|
* @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds the accrued
|
|
1084
1086
|
* position credit.
|
|
1085
1087
|
* @throws {InvalidMidnightPositionLossFactorError} when the market loss factor is below the
|
|
1086
1088
|
* position's `lastLossFactor`, which `getPositionData` snapshots never are.
|
|
1087
1089
|
* @throws {InvalidMidnightPositionAccrualStateError} when the snapshot's credit, pending fee or
|
|
1088
1090
|
* loss factor are inconsistent, which `getPositionData` snapshots never are.
|
|
1089
|
-
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1090
1091
|
* @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
|
|
1092
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
1091
1093
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
1092
1094
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
1093
1095
|
* market token contract.
|
|
@@ -1062,6 +1062,7 @@ class MorphoMidnight {
|
|
|
1062
1062
|
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
1063
1063
|
* @throws {InputExceedsMaxError} when `collateralAssets` exceeds `uint128`.
|
|
1064
1064
|
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
1065
|
+
* @throws {MidnightZeroOnBehalfError} from `buildTx()` when `accountAddress` is the zero address.
|
|
1065
1066
|
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
1066
1067
|
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
|
|
1067
1068
|
* @example
|
|
@@ -1863,14 +1864,15 @@ class MorphoMidnight {
|
|
|
1863
1864
|
* @throws {MissingAccrualPositionError} when no position snapshot is supplied.
|
|
1864
1865
|
* @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
|
|
1865
1866
|
* @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
|
|
1867
|
+
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1866
1868
|
* @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds the accrued
|
|
1867
1869
|
* position credit.
|
|
1868
1870
|
* @throws {InvalidMidnightPositionLossFactorError} when the market loss factor is below the
|
|
1869
1871
|
* position's `lastLossFactor`, which `getPositionData` snapshots never are.
|
|
1870
1872
|
* @throws {InvalidMidnightPositionAccrualStateError} when the snapshot's credit, pending fee or
|
|
1871
1873
|
* loss factor are inconsistent, which `getPositionData` snapshots never are.
|
|
1872
|
-
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1873
1874
|
* @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
|
|
1875
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
1874
1876
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
1875
1877
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
1876
1878
|
* market token contract.
|
package/lib/cjs/types/error.d.ts
CHANGED
|
@@ -1220,6 +1220,14 @@ export declare class MidnightZeroReceiverError extends Error {
|
|
|
1220
1220
|
*/
|
|
1221
1221
|
constructor(field: "receiver" | "collateralReceiver");
|
|
1222
1222
|
}
|
|
1223
|
+
/** Thrown when a Midnight flow uses the zero address as the account it acts for. */
|
|
1224
|
+
export declare class MidnightZeroOnBehalfError extends Error {
|
|
1225
|
+
readonly field: "onBehalf";
|
|
1226
|
+
/**
|
|
1227
|
+
* @param field - Account field containing the zero address.
|
|
1228
|
+
*/
|
|
1229
|
+
constructor(field: "onBehalf");
|
|
1230
|
+
}
|
|
1223
1231
|
/**
|
|
1224
1232
|
* Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
|
|
1225
1233
|
* forward received assets.
|
package/lib/cjs/types/error.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.UnsupportedMidnightAuthorizationTargetError = exports.UnsupportedErc20ApprovalSpenderError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.CryptoUnavailableError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.UnsupportedRequirementSignatureError = exports.UnexpectedRequirementSignatureError = exports.AmbiguousRequirementSignaturesError = exports.MaxRepayAssetsBelowRepayAssetsError = exports.ReallocationsRequireBorrowError = exports.UnsupportedAuthorizationOperatorError = exports.ReallocationLoanTokenMismatchError = exports.SameVaultMigrationError = exports.AmountAndSharesExclusiveError = exports.MixedBundlesFundingError = exports.MidnightReferralFeePctExceededError = exports.ReferralFeePctExceededError = exports.ReferralFeeRecipientMissingError = exports.NativeFundingAmountMismatchError = exports.NoUnusedPermit2NonceError = exports.Permit2SignatureTransferNonceAlreadyUsedError = exports.BundlesRequirementSignatureMismatchError = exports.BundlesPermitMismatchError = exports.VaultIsBlueFeeRecipientError = exports.VaultMorphoMismatchError = exports.InsufficientBlueBalanceForInKindRedeemError = exports.InKindRedeemCoverageError = exports.InKindRedeemZeroDeallocationError = exports.VaultV2ForceWithdrawFeeSharesExceedBurnError = exports.VaultV2ForceWithdrawSharePriceBelowFloorError = exports.VaultV2ForceWithdrawZeroSharePriceError = exports.VaultV2ForceWithdrawZeroWithdrawalError = exports.VaultV2ForceWithdrawCoverageError = exports.VaultV2UndecodableLiquidityDataError = exports.VaultV2UnsupportedLiquidityAdapterError = exports.VaultV2UnsupportedExitAdapterError = exports.AdapterNotPartOfVaultError = exports.VaultV2SingleAdapterRequiredError = exports.ExpiredDeadlineError = exports.EmptyMarketParamsListError = exports.InputExceedsMaxError = exports.NonPositiveInputError = exports.NegativeInputError = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferMarketMismatchError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = void 0;
|
|
4
|
+
exports.MidnightOfferMarketChainMismatchError = exports.MidnightTakeDeadlineTooFarError = exports.MidnightContractReceiverError = exports.MidnightZeroOnBehalfError = exports.MidnightZeroReceiverError = exports.MidnightRepayExceedsDebtError = exports.MidnightContinuousFeeAboveMaxError = exports.MidnightTakeTargetUnreachableError = exports.MidnightTakeableOffersNotFillableError = exports.UnboundedMidnightTakeInputError = exports.MidnightOfferSellerReceiverMismatchError = exports.MidnightOfferContinuousFeeCapError = exports.MidnightOfferMakerMismatchError = exports.MidnightOfferReduceOnlyError = exports.MidnightOfferSideMismatchError = exports.EmptyMidnightTakeableOffersError = exports.DuplicateMidnightGroupCancellationError = exports.EmptyMidnightCollateralSuppliesError = exports.EmptyMidnightGroupCancellationsError = exports.ReallocationAdapterSupplySharesUnderflowError = exports.ReallocationAllocationUnderflowError = exports.UnknownReallocationAdapterError = exports.UnknownReallocationMarketPublicAllocatorConfigError = exports.UnknownReallocationActiveAdaptersError = exports.UnknownReallocationPublicAllocatorConfigError = exports.UnknownReallocationAllocationError = exports.UnknownReallocationVaultError = exports.UnknownReallocationMarketError = exports.InsufficientSharedLiquidityError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.MutuallyExclusiveRepayAmountsError = exports.InconsistentReallocationPenaltyError = exports.InvalidReallocationSourceTypeError = exports.InvalidReallocationAddressError = exports.InvalidVaultV2BlueReallocationShapeError = exports.ReallocationWithdrawalOnTargetMarketError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeAssetError = exports.VaultAddressMismatchError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DepositSpenderMismatchError = exports.DepositOwnerMismatchError = void 0;
|
|
5
|
+
exports.MissingContractCodeError = exports.MidnightOfferNotReduceOnlyError = exports.RefinanceTokenMismatchError = exports.RefinanceSameMarketError = exports.VaultAssetMismatchError = exports.ReallocationWithdrawExceedsMarketSupplyError = exports.WithdrawSharesExceedSupplyError = exports.WithdrawExceedsSupplyError = exports.MutuallyExclusiveWithdrawAmountsError = exports.MidnightInvalidAccountAddressError = exports.InvalidMidnightHexInputError = exports.InsufficientMidnightWithdrawableLiquidityError = exports.MidnightRedeemExceedsCreditError = exports.NoMidnightCreditToRedeemError = exports.MidnightReplacementGroupCancelledError = exports.MidnightOfferRatifierMismatchError = exports.MidnightTakeableOfferMarketMismatchError = exports.ZeroBlueParkingSharesError = exports.EmptyBlueParkingMarketError = exports.MidnightOfferCallbackDataMismatchError = exports.MidnightOfferCallbackMismatchError = exports.MidnightOfferMarketLoanTokenMismatchError = exports.MidnightMarketAddressMismatchError = exports.MidnightOfferMarketAddressMismatchError = void 0;
|
|
6
6
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
7
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
8
8
|
const constant_js_1 = require("../helpers/constant.js");
|
|
@@ -1536,6 +1536,19 @@ class MidnightZeroReceiverError extends Error {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
}
|
|
1538
1538
|
exports.MidnightZeroReceiverError = MidnightZeroReceiverError;
|
|
1539
|
+
/** Thrown when a Midnight flow uses the zero address as the account it acts for. */
|
|
1540
|
+
class MidnightZeroOnBehalfError extends Error {
|
|
1541
|
+
field;
|
|
1542
|
+
/**
|
|
1543
|
+
* @param field - Account field containing the zero address.
|
|
1544
|
+
*/
|
|
1545
|
+
constructor(field) {
|
|
1546
|
+
super(`Midnight "${field}" cannot be the zero address. Provide a valid account.`);
|
|
1547
|
+
this.field = field;
|
|
1548
|
+
this.name = "MidnightZeroOnBehalfError";
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
exports.MidnightZeroOnBehalfError = MidnightZeroOnBehalfError;
|
|
1539
1552
|
/**
|
|
1540
1553
|
* Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
|
|
1541
1554
|
* forward received assets.
|
|
@@ -30,6 +30,7 @@ export interface MidnightRedeemParams {
|
|
|
30
30
|
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
31
31
|
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
32
32
|
* @throws {InputExceedsMaxError} when `units` exceeds `uint128`.
|
|
33
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
33
34
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
34
35
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
35
36
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MarketUtils, midnightAbi, } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { encodeFunctionData } from "viem";
|
|
3
|
+
import { encodeFunctionData, isAddressEqual, zeroAddress, } from "viem";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
5
|
import { validateMidnightUint128Field } from "../../helpers/validateMidnightBounds.js";
|
|
6
6
|
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
7
7
|
import { validateMidnightReceiver } from "../../helpers/validateMidnightReceiver.js";
|
|
8
|
-
import { NonPositiveInputError, } from "../../types/index.js";
|
|
8
|
+
import { MidnightZeroOnBehalfError, NonPositiveInputError, } from "../../types/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Encodes a direct Midnight credit redemption.
|
|
11
11
|
*
|
|
@@ -26,6 +26,7 @@ import { NonPositiveInputError, } from "../../types/index.js";
|
|
|
26
26
|
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
27
27
|
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
28
28
|
* @throws {InputExceedsMaxError} when `units` exceeds `uint128`.
|
|
29
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
29
30
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
30
31
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
31
32
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
@@ -48,6 +49,9 @@ export const midnightRedeem = (params) => {
|
|
|
48
49
|
throw new NonPositiveInputError("units", params.units);
|
|
49
50
|
}
|
|
50
51
|
validateMidnightUint128Field("units", params.units);
|
|
52
|
+
if (isAddressEqual(params.onBehalf, zeroAddress)) {
|
|
53
|
+
throw new MidnightZeroOnBehalfError("onBehalf");
|
|
54
|
+
}
|
|
51
55
|
// Reject markets from another chain deployment before encoding the call.
|
|
52
56
|
validateMidnightMarket({ market: params.market, chainId: params.chainId });
|
|
53
57
|
const marketId = MarketUtils.toId(params.market);
|
|
@@ -27,6 +27,7 @@ export interface MidnightSupplyCollateralParams {
|
|
|
27
27
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
28
28
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
29
29
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
|
|
30
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
30
31
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
31
32
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
32
33
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MarketUtils, midnightAbi, } from "@morpho-org/midnight-sdk";
|
|
2
2
|
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { encodeFunctionData } from "viem";
|
|
3
|
+
import { encodeFunctionData, isAddressEqual, zeroAddress, } from "viem";
|
|
4
4
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
5
|
import { validateMidnightUint128Field } from "../../helpers/validateMidnightBounds.js";
|
|
6
6
|
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
7
|
-
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
import { MidnightZeroOnBehalfError, NonPositiveInputError, } from "../../types/index.js";
|
|
8
8
|
/**
|
|
9
9
|
* Encodes a direct Midnight collateral supply.
|
|
10
10
|
*
|
|
@@ -22,6 +22,7 @@ import { NonPositiveInputError, } from "../../types/index.js";
|
|
|
22
22
|
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralAction>` targeting `Midnight`.
|
|
23
23
|
* @throws {NonPositiveInputError} when `assets <= 0n`.
|
|
24
24
|
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`.
|
|
25
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
25
26
|
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
26
27
|
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
27
28
|
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
@@ -43,6 +44,9 @@ export const midnightSupplyCollateral = (params) => {
|
|
|
43
44
|
throw new NonPositiveInputError("assets", params.assets);
|
|
44
45
|
}
|
|
45
46
|
validateMidnightUint128Field("assets", params.assets);
|
|
47
|
+
if (isAddressEqual(params.onBehalf, zeroAddress)) {
|
|
48
|
+
throw new MidnightZeroOnBehalfError("onBehalf");
|
|
49
|
+
}
|
|
46
50
|
// Reject markets from another chain deployment before encoding the call.
|
|
47
51
|
validateMidnightMarket({ market: params.market, chainId: params.chainId });
|
|
48
52
|
const marketId = MarketUtils.toId(params.market);
|
|
@@ -594,6 +594,7 @@ export declare class MorphoMidnight {
|
|
|
594
594
|
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
595
595
|
* @throws {InputExceedsMaxError} when `collateralAssets` exceeds `uint128`.
|
|
596
596
|
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
597
|
+
* @throws {MidnightZeroOnBehalfError} from `buildTx()` when `accountAddress` is the zero address.
|
|
597
598
|
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
598
599
|
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
|
|
599
600
|
* @example
|
|
@@ -1080,14 +1081,15 @@ export declare class MorphoMidnight {
|
|
|
1080
1081
|
* @throws {MissingAccrualPositionError} when no position snapshot is supplied.
|
|
1081
1082
|
* @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
|
|
1082
1083
|
* @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
|
|
1084
|
+
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1083
1085
|
* @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds the accrued
|
|
1084
1086
|
* position credit.
|
|
1085
1087
|
* @throws {InvalidMidnightPositionLossFactorError} when the market loss factor is below the
|
|
1086
1088
|
* position's `lastLossFactor`, which `getPositionData` snapshots never are.
|
|
1087
1089
|
* @throws {InvalidMidnightPositionAccrualStateError} when the snapshot's credit, pending fee or
|
|
1088
1090
|
* loss factor are inconsistent, which `getPositionData` snapshots never are.
|
|
1089
|
-
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1090
1091
|
* @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
|
|
1092
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
1091
1093
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
1092
1094
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
1093
1095
|
* market token contract.
|
|
@@ -1059,6 +1059,7 @@ export class MorphoMidnight {
|
|
|
1059
1059
|
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
1060
1060
|
* @throws {InputExceedsMaxError} when `collateralAssets` exceeds `uint128`.
|
|
1061
1061
|
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
1062
|
+
* @throws {MidnightZeroOnBehalfError} from `buildTx()` when `accountAddress` is the zero address.
|
|
1062
1063
|
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
1063
1064
|
* @throws {ApprovalAmountLessThanSpendAmountError} from `getRequirements()` when `approvalAmount` is below the pulled collateral assets.
|
|
1064
1065
|
* @example
|
|
@@ -1860,14 +1861,15 @@ export class MorphoMidnight {
|
|
|
1860
1861
|
* @throws {MissingAccrualPositionError} when no position snapshot is supplied.
|
|
1861
1862
|
* @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
|
|
1862
1863
|
* @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
|
|
1864
|
+
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1863
1865
|
* @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds the accrued
|
|
1864
1866
|
* position credit.
|
|
1865
1867
|
* @throws {InvalidMidnightPositionLossFactorError} when the market loss factor is below the
|
|
1866
1868
|
* position's `lastLossFactor`, which `getPositionData` snapshots never are.
|
|
1867
1869
|
* @throws {InvalidMidnightPositionAccrualStateError} when the snapshot's credit, pending fee or
|
|
1868
1870
|
* loss factor are inconsistent, which `getPositionData` snapshots never are.
|
|
1869
|
-
* @throws {InputExceedsMaxError} when the selected units exceed `uint128`.
|
|
1870
1871
|
* @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
|
|
1872
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
1871
1873
|
* @throws {MidnightZeroReceiverError} when `receiver` resolves to the zero address.
|
|
1872
1874
|
* @throws {MidnightContractReceiverError} when `receiver` is a Midnight protocol contract or a
|
|
1873
1875
|
* market token contract.
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -1220,6 +1220,14 @@ export declare class MidnightZeroReceiverError extends Error {
|
|
|
1220
1220
|
*/
|
|
1221
1221
|
constructor(field: "receiver" | "collateralReceiver");
|
|
1222
1222
|
}
|
|
1223
|
+
/** Thrown when a Midnight flow uses the zero address as the account it acts for. */
|
|
1224
|
+
export declare class MidnightZeroOnBehalfError extends Error {
|
|
1225
|
+
readonly field: "onBehalf";
|
|
1226
|
+
/**
|
|
1227
|
+
* @param field - Account field containing the zero address.
|
|
1228
|
+
*/
|
|
1229
|
+
constructor(field: "onBehalf");
|
|
1230
|
+
}
|
|
1223
1231
|
/**
|
|
1224
1232
|
* Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
|
|
1225
1233
|
* forward received assets.
|
package/lib/esm/types/error.js
CHANGED
|
@@ -1435,6 +1435,18 @@ export class MidnightZeroReceiverError extends Error {
|
|
|
1435
1435
|
this.name = "MidnightZeroReceiverError";
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
1438
|
+
/** Thrown when a Midnight flow uses the zero address as the account it acts for. */
|
|
1439
|
+
export class MidnightZeroOnBehalfError extends Error {
|
|
1440
|
+
field;
|
|
1441
|
+
/**
|
|
1442
|
+
* @param field - Account field containing the zero address.
|
|
1443
|
+
*/
|
|
1444
|
+
constructor(field) {
|
|
1445
|
+
super(`Midnight "${field}" cannot be the zero address. Provide a valid account.`);
|
|
1446
|
+
this.field = field;
|
|
1447
|
+
this.name = "MidnightZeroOnBehalfError";
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1438
1450
|
/**
|
|
1439
1451
|
* Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
|
|
1440
1452
|
* forward received assets.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.3.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -155,7 +155,7 @@
|
|
|
155
155
|
"@morpho-org/blue-sdk": "^8.0.1",
|
|
156
156
|
"@morpho-org/blue-sdk-viem": "^7.0.0",
|
|
157
157
|
"@morpho-org/midnight-sdk": "^2.1.0",
|
|
158
|
-
"@morpho-org/morpho-ts": "^4.0
|
|
158
|
+
"@morpho-org/morpho-ts": "^4.1.0"
|
|
159
159
|
},
|
|
160
160
|
"peerDependencies": {
|
|
161
161
|
"viem": "^2.0.0"
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
"fast-check": "^4.9.0",
|
|
167
167
|
"typescript": "7.0.2",
|
|
168
168
|
"viem": "^2.55.10",
|
|
169
|
-
"vitest": "^4.1.
|
|
169
|
+
"vitest": "^4.1.12"
|
|
170
170
|
},
|
|
171
171
|
"scripts": {
|
|
172
172
|
"prepublish": "pnpm build",
|