@morpho-org/morpho-sdk 8.3.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/MIGRATION-v8-to-v9.md +54 -0
  2. package/README.md +13 -7
  3. package/lib/cjs/actions/bundles/common.d.ts +4 -7
  4. package/lib/cjs/actions/bundles/common.js +8 -14
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  6. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -8
  7. package/lib/cjs/actions/midnight/authorization.d.ts +3 -1
  8. package/lib/cjs/actions/midnight/authorization.js +11 -1
  9. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -0
  10. package/lib/cjs/actions/midnight/cancelAndMake.js +10 -2
  11. package/lib/cjs/actions/midnight/redeem.d.ts +3 -1
  12. package/lib/cjs/actions/midnight/redeem.js +9 -3
  13. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  14. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +7 -3
  15. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +4 -1
  16. package/lib/cjs/actions/midnight/supplyCollateral.js +10 -3
  17. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  18. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +9 -3
  19. package/lib/cjs/actions/midnight/takeBorrow.d.ts +3 -1
  20. package/lib/cjs/actions/midnight/takeBorrow.js +9 -3
  21. package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
  22. package/lib/cjs/actions/midnight/takeLend.js +7 -2
  23. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  24. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +8 -2
  25. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +3 -1
  26. package/lib/cjs/actions/midnight/takeWithdraw.js +10 -3
  27. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  28. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +5 -7
  29. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +7 -11
  30. package/lib/cjs/actions/requirements/getRequirementsApproval.js +8 -15
  31. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  32. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +11 -8
  33. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  34. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  35. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -1
  36. package/lib/cjs/actions/vaultV1/inKindRedeem.js +1 -1
  37. package/lib/cjs/actions/vaultV1/withdraw.d.ts +4 -4
  38. package/lib/cjs/actions/vaultV1/withdraw.js +4 -4
  39. package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
  40. package/lib/cjs/actions/vaultV2/forceWithdraw.js +1 -1
  41. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +1 -1
  42. package/lib/cjs/actions/vaultV2/inKindRedeem.js +1 -1
  43. package/lib/cjs/actions/vaultV2/withdraw.d.ts +4 -4
  44. package/lib/cjs/actions/vaultV2/withdraw.js +4 -4
  45. package/lib/cjs/entities/blue/blue.d.ts +2 -12
  46. package/lib/cjs/entities/blue/blue.js +0 -4
  47. package/lib/cjs/entities/midnight/midnight.d.ts +56 -17
  48. package/lib/cjs/entities/midnight/midnight.js +131 -52
  49. package/lib/cjs/entities/midnight/types.d.ts +2 -9
  50. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  51. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +0 -7
  52. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  53. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -20
  54. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +40 -37
  55. package/lib/cjs/entities/vaultV1/vaultV1.js +5 -34
  56. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +36 -34
  57. package/lib/cjs/entities/vaultV2/vaultV2.js +8 -34
  58. package/lib/cjs/helpers/encodeMidnightCalldata.d.ts +48 -0
  59. package/lib/cjs/helpers/encodeMidnightCalldata.js +74 -0
  60. package/lib/cjs/helpers/slippage.d.ts +9 -25
  61. package/lib/cjs/helpers/slippage.js +10 -27
  62. package/lib/cjs/helpers/validate.d.ts +1 -0
  63. package/lib/cjs/helpers/validate.js +5 -0
  64. package/lib/cjs/helpers/validateMidnightAccount.d.ts +34 -0
  65. package/lib/cjs/helpers/validateMidnightAccount.js +47 -0
  66. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  67. package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +4 -0
  68. package/lib/cjs/helpers/validateMidnightMarket.d.ts +2 -0
  69. package/lib/cjs/helpers/validateMidnightMarket.js +5 -0
  70. package/lib/cjs/helpers/validateMidnightPublication.d.ts +11 -0
  71. package/lib/cjs/helpers/validateMidnightPublication.js +12 -1
  72. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +1 -0
  73. package/lib/cjs/helpers/validateMidnightReceiver.js +8 -0
  74. package/lib/cjs/helpers/validateTakeableOffers.d.ts +2 -1
  75. package/lib/cjs/helpers/validateTakeableOffers.js +4 -3
  76. package/lib/cjs/types/action.d.ts +3 -1
  77. package/lib/cjs/types/error.d.ts +56 -5
  78. package/lib/cjs/types/error.js +139 -10
  79. package/lib/esm/actions/bundles/common.d.ts +4 -7
  80. package/lib/esm/actions/bundles/common.js +8 -14
  81. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +1 -5
  82. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -9
  83. package/lib/esm/actions/midnight/authorization.d.ts +3 -1
  84. package/lib/esm/actions/midnight/authorization.js +12 -2
  85. package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -0
  86. package/lib/esm/actions/midnight/cancelAndMake.js +11 -3
  87. package/lib/esm/actions/midnight/redeem.d.ts +3 -1
  88. package/lib/esm/actions/midnight/redeem.js +10 -4
  89. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +1 -0
  90. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +8 -4
  91. package/lib/esm/actions/midnight/supplyCollateral.d.ts +4 -1
  92. package/lib/esm/actions/midnight/supplyCollateral.js +11 -4
  93. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +3 -1
  94. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +10 -4
  95. package/lib/esm/actions/midnight/takeBorrow.d.ts +3 -1
  96. package/lib/esm/actions/midnight/takeBorrow.js +10 -4
  97. package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
  98. package/lib/esm/actions/midnight/takeLend.js +8 -3
  99. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
  100. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +9 -3
  101. package/lib/esm/actions/midnight/takeWithdraw.d.ts +3 -1
  102. package/lib/esm/actions/midnight/takeWithdraw.js +11 -4
  103. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +1 -5
  104. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +6 -8
  105. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +7 -11
  106. package/lib/esm/actions/requirements/getRequirementsApproval.js +9 -16
  107. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +5 -10
  108. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +12 -9
  109. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +2 -0
  110. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -0
  111. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -1
  112. package/lib/esm/actions/vaultV1/inKindRedeem.js +1 -1
  113. package/lib/esm/actions/vaultV1/withdraw.d.ts +4 -4
  114. package/lib/esm/actions/vaultV1/withdraw.js +4 -4
  115. package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
  116. package/lib/esm/actions/vaultV2/forceWithdraw.js +1 -1
  117. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +1 -1
  118. package/lib/esm/actions/vaultV2/inKindRedeem.js +1 -1
  119. package/lib/esm/actions/vaultV2/withdraw.d.ts +4 -4
  120. package/lib/esm/actions/vaultV2/withdraw.js +4 -4
  121. package/lib/esm/entities/blue/blue.d.ts +2 -12
  122. package/lib/esm/entities/blue/blue.js +0 -4
  123. package/lib/esm/entities/midnight/midnight.d.ts +56 -17
  124. package/lib/esm/entities/midnight/midnight.js +132 -53
  125. package/lib/esm/entities/midnight/types.d.ts +2 -9
  126. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +0 -4
  127. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +1 -8
  128. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -14
  129. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +9 -21
  130. package/lib/esm/entities/vaultV1/vaultV1.d.ts +40 -37
  131. package/lib/esm/entities/vaultV1/vaultV1.js +6 -35
  132. package/lib/esm/entities/vaultV2/vaultV2.d.ts +36 -34
  133. package/lib/esm/entities/vaultV2/vaultV2.js +8 -34
  134. package/lib/esm/helpers/encodeMidnightCalldata.d.ts +48 -0
  135. package/lib/esm/helpers/encodeMidnightCalldata.js +69 -0
  136. package/lib/esm/helpers/slippage.d.ts +9 -25
  137. package/lib/esm/helpers/slippage.js +9 -25
  138. package/lib/esm/helpers/validate.d.ts +1 -0
  139. package/lib/esm/helpers/validate.js +5 -0
  140. package/lib/esm/helpers/validateMidnightAccount.d.ts +34 -0
  141. package/lib/esm/helpers/validateMidnightAccount.js +43 -0
  142. package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -0
  143. package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +4 -0
  144. package/lib/esm/helpers/validateMidnightMarket.d.ts +2 -0
  145. package/lib/esm/helpers/validateMidnightMarket.js +5 -0
  146. package/lib/esm/helpers/validateMidnightPublication.d.ts +11 -0
  147. package/lib/esm/helpers/validateMidnightPublication.js +10 -0
  148. package/lib/esm/helpers/validateMidnightReceiver.d.ts +1 -0
  149. package/lib/esm/helpers/validateMidnightReceiver.js +8 -0
  150. package/lib/esm/helpers/validateTakeableOffers.d.ts +2 -1
  151. package/lib/esm/helpers/validateTakeableOffers.js +4 -3
  152. package/lib/esm/types/action.d.ts +3 -1
  153. package/lib/esm/types/error.d.ts +56 -5
  154. package/lib/esm/types/error.js +134 -6
  155. package/package.json +4 -3
@@ -1,6 +1,7 @@
1
1
  import { getChainAddresses } from "@morpho-org/morpho-ts";
2
2
  import { isAddressEqual } from "viem";
3
3
  import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
4
+ import { validateMidnightAddress } from "./validateMidnightAccount.js";
4
5
  /**
5
6
  * Validates that a Midnight authorization grant targets a supported protocol operator.
6
7
  *
@@ -8,10 +9,13 @@ import { UnsupportedMidnightAuthorizationTargetError } from "../types/index.js";
8
9
  * @param params.chainId - Chain id used to resolve supported Midnight operators.
9
10
  * @param params.authorized - Operator address receiving authorization.
10
11
  * @returns Nothing after the operator matches MidnightBundlesV2.
12
+ * @throws {MidnightCalldataEncodingError} when `authorized` is not a 20-byte hex address.
11
13
  * @throws {UnsupportedMidnightAuthorizationTargetError} when `authorized` is not a supported operator.
12
14
  * @internal
13
15
  */
14
16
  export const validateMidnightAuthorizationTarget = (params) => {
17
+ // Reject a malformed address before viem compares it.
18
+ validateMidnightAddress("authorized", params.authorized);
15
19
  const { midnightBundlesV2 } = getChainAddresses(params.chainId);
16
20
  const supportedTargets = midnightBundlesV2 == null ? [] : [midnightBundlesV2];
17
21
  if (!supportedTargets.some((supported) => isAddressEqual(params.authorized, supported))) {
@@ -2,6 +2,8 @@ import type { MarketInput } from "@morpho-org/midnight-sdk";
2
2
  /**
3
3
  * Validates that a Midnight market belongs to the configured chain deployment.
4
4
  *
5
+ * @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
6
+ *
5
7
  * @internal
6
8
  */
7
9
  export declare const validateMidnightMarket: (params: {
@@ -2,14 +2,19 @@ import { getChainAddress } from "@morpho-org/morpho-ts";
2
2
  import { isAddressEqual } from "viem";
3
3
  import { MidnightMarketAddressMismatchError } from "../types/index.js";
4
4
  import { validateChainId } from "./validate.js";
5
+ import { validateMidnightAddress } from "./validateMidnightAccount.js";
5
6
  /**
6
7
  * Validates that a Midnight market belongs to the configured chain deployment.
7
8
  *
9
+ * @throws {MidnightCalldataEncodingError} when `market.midnight` is not a 20-byte hex address.
10
+ *
8
11
  * @internal
9
12
  */
10
13
  export const validateMidnightMarket = (params) => {
11
14
  const market = "params" in params.market ? params.market.params : params.market;
12
15
  validateChainId(Number(market.chainId), params.chainId);
16
+ // Reject a malformed address before viem compares it.
17
+ validateMidnightAddress("market.midnight", market.midnight);
13
18
  const expectedMidnight = getChainAddress(params.chainId, "midnight");
14
19
  if (!isAddressEqual(market.midnight, expectedMidnight)) {
15
20
  throw new MidnightMarketAddressMismatchError({
@@ -1,3 +1,4 @@
1
+ import { type Hex } from "viem";
1
2
  import type { MidnightCancelAndMakeParams } from "../types/midnightCancelAndMake.js";
2
3
  /** @internal */
3
4
  export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCancelAndMakeParams) => MidnightCancelAndMakeParams;
@@ -10,3 +11,13 @@ export declare const snapshotMidnightCancelAndMakeParams: (params: MidnightCance
10
11
  * callback salt, or root-signature `r`/`s` is not 32-byte hex, or payload is malformed or oversized.
11
12
  */
12
13
  export declare const validateMidnightPublication: (params: MidnightCancelAndMakeParams) => void;
14
+ /**
15
+ * @internal
16
+ * Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
17
+ * from it.
18
+ *
19
+ * @param field - Input name reported by the error.
20
+ * @param value - Fixed-length bytes value to validate.
21
+ * @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
22
+ */
23
+ export declare const validateMidnightBytes32: (field: string, value: Hex) => void;
@@ -105,6 +105,16 @@ export const validateMidnightPublication = (params) => {
105
105
  maxBytes: Payload.MAX_PAYLOAD_BYTES,
106
106
  });
107
107
  };
108
+ /**
109
+ * @internal
110
+ * Rejects a value that is not exactly 32 bytes of hex before a Midnight flow derives or encodes
111
+ * from it.
112
+ *
113
+ * @param field - Input name reported by the error.
114
+ * @param value - Fixed-length bytes value to validate.
115
+ * @throws {InvalidMidnightHexInputError} when `value` is not exactly 32 bytes of hex.
116
+ */
117
+ export const validateMidnightBytes32 = (field, value) => validateHexInput(value, field, { exactBytes: 32 });
108
118
  // biome-ignore lint/complexity/useMaxParams: Keep value, field, and size explicit.
109
119
  const validateHexInput = (value, field, size) => {
110
120
  if (!isHex(value)) {
@@ -12,6 +12,7 @@ import { type Address } from "viem";
12
12
  * @param params.market - Midnight market whose token contracts are also rejected.
13
13
  * @param params.field - Receiver field being validated, reported on the thrown error.
14
14
  * @param params.receiver - Receiver address to check.
15
+ * @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
15
16
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
16
17
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
17
18
  * `"referralFeeRecipient"`.
@@ -1,6 +1,7 @@
1
1
  import { getChainAddresses } from "@morpho-org/morpho-ts";
2
2
  import { isAddressEqual, zeroAddress } from "viem";
3
3
  import { MidnightContractReceiverError, MidnightZeroReceiverError, ReferralFeeRecipientMissingError, } from "../types/index.js";
4
+ import { validateMidnightAddress } from "./validateMidnightAccount.js";
4
5
  /** Registry keys of the Midnight protocol contracts that cannot forward received assets. */
5
6
  const MIDNIGHT_CONTRACT_KEYS = [
6
7
  "midnight",
@@ -25,6 +26,7 @@ const MIDNIGHT_CONTRACT_KEYS = [
25
26
  * @param params.market - Midnight market whose token contracts are also rejected.
26
27
  * @param params.field - Receiver field being validated, reported on the thrown error.
27
28
  * @param params.receiver - Receiver address to check.
29
+ * @throws {MidnightCalldataEncodingError} when the receiver or a market token address is malformed.
28
30
  * @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
29
31
  * @throws {MidnightZeroReceiverError} when `receiver` is the zero address and `field` is not
30
32
  * `"referralFeeRecipient"`.
@@ -37,6 +39,12 @@ const MIDNIGHT_CONTRACT_KEYS = [
37
39
  export const validateMidnightReceiver = (params) => {
38
40
  const { field, receiver } = params;
39
41
  const market = "params" in params.market ? params.market.params : params.market;
42
+ // Validate addresses before comparing them so malformed values stay a typed SDK error.
43
+ validateMidnightAddress(field, receiver);
44
+ validateMidnightAddress("market.loanToken", market.loanToken);
45
+ for (const [index, { token }] of market.collateralParams.entries()) {
46
+ validateMidnightAddress(`market.collateralParams[${index}].token`, token);
47
+ }
40
48
  if (isAddressEqual(receiver, zeroAddress)) {
41
49
  if (field === "referralFeeRecipient") {
42
50
  throw new ReferralFeeRecipientMissingError();
@@ -1,4 +1,4 @@
1
- import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
1
+ import type { MarketInput, OfferStruct } from "@morpho-org/midnight-sdk";
2
2
  /**
3
3
  * Validates the pure invariants shared by Midnight take entity and action layers.
4
4
  *
@@ -7,6 +7,7 @@ import { type MarketInput, type OfferStruct } from "@morpho-org/midnight-sdk";
7
7
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
8
8
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
9
9
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
10
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
10
11
  * @internal
11
12
  */
12
13
  export declare const validateTakeableOffers: (params: {
@@ -1,5 +1,5 @@
1
- import { MarketUtils, } from "@morpho-org/midnight-sdk";
2
1
  import { EmptyMidnightTakeableOffersError, MidnightTakeableOfferMarketMismatchError, } from "../types/index.js";
2
+ import { encodeMidnightMarketId } from "./encodeMidnightCalldata.js";
3
3
  import { validateOfferSides } from "./validateOfferSides.js";
4
4
  /**
5
5
  * Validates the pure invariants shared by Midnight take entity and action layers.
@@ -9,16 +9,17 @@ import { validateOfferSides } from "./validateOfferSides.js";
9
9
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
10
10
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
11
11
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
12
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
12
13
  * @internal
13
14
  */
14
15
  export const validateTakeableOffers = (params) => {
15
16
  if (params.takeableOffers.length === 0) {
16
17
  throw new EmptyMidnightTakeableOffersError();
17
18
  }
18
- const marketId = MarketUtils.toId(params.market);
19
+ const marketId = encodeMidnightMarketId(params.market);
19
20
  validateOfferSides(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
20
21
  for (const [index, take] of params.takeableOffers.entries()) {
21
- const actualMarketId = MarketUtils.toId(take.offer.market);
22
+ const actualMarketId = encodeMidnightMarketId(take.offer.market);
22
23
  if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
23
24
  throw new MidnightTakeableOfferMarketMismatchError({
24
25
  index,
@@ -37,7 +37,7 @@ export type MidnightBuyTarget = {
37
37
  */
38
38
  export type MidnightSellTarget = {
39
39
  readonly type: "assets";
40
- /** Loan assets received before the referral fee. */
40
+ /** Exact loan assets paid to `receiver`; any referral fee is sold on top of this amount. */
41
41
  readonly assets: bigint;
42
42
  readonly maxUnits: bigint;
43
43
  } | {
@@ -491,6 +491,8 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
491
491
  readonly cancellations: readonly MidnightGroupCancellation[];
492
492
  readonly collateralSupplies: readonly MidnightCollateralTransfer[];
493
493
  readonly blueSupply?: MidnightBlueSupply;
494
+ /** Native ETH wrapped into wNative to fund this bundle. */
495
+ readonly nativeAmount?: bigint;
494
496
  readonly deadline: bigint;
495
497
  }> {
496
498
  }
@@ -1,6 +1,6 @@
1
1
  import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
2
2
  import type { AddressLabel } from "@morpho-org/morpho-ts";
3
- import type { Address, Hash, Hex } from "viem";
3
+ import type { Address, BaseError, Hash, Hex } from "viem";
4
4
  /**
5
5
  * Thrown when a morpho-sdk input that must be non-negative is negative.
6
6
  *
@@ -713,10 +713,6 @@ export declare class CryptoUnavailableError extends Error {
713
713
  export declare class MissingClientPropertyError extends Error {
714
714
  constructor(property: string);
715
715
  }
716
- /** Thrown when an approval amount is smaller than the spend amount it must cover. */
717
- export declare class ApprovalAmountLessThanSpendAmountError extends Error {
718
- constructor();
719
- }
720
716
  /** Thrown when a requirement encoder targets an unsupported spender. */
721
717
  export declare class UnsupportedErc20ApprovalSpenderError extends Error {
722
718
  constructor(params: {
@@ -1496,3 +1492,58 @@ export declare class MissingContractCodeError extends Error {
1496
1492
  */
1497
1493
  constructor(address: Address, chainId: number, role: AddressLabel);
1498
1494
  }
1495
+ /**
1496
+ * Thrown when a Midnight flow is prepared for the zero address. Midnight would revert
1497
+ * `Unauthorized()`, and requirements resolved for the zero address can never be sent.
1498
+ *
1499
+ * @example
1500
+ * ```ts
1501
+ * import { MidnightZeroAccountError } from "@morpho-org/morpho-sdk";
1502
+ *
1503
+ * const error = new MidnightZeroAccountError("accountAddress");
1504
+ * // error.field === "accountAddress"
1505
+ * ```
1506
+ */
1507
+ export declare class MidnightZeroAccountError extends Error {
1508
+ readonly field: "accountAddress" | "owner";
1509
+ /**
1510
+ * @param field - Account field containing the zero address: `accountAddress` for an entity
1511
+ * method, `owner` for a requirement helper. A zero `onBehalf` on a direct Midnight call throws
1512
+ * {@link MidnightZeroOnBehalfError} instead.
1513
+ */
1514
+ constructor(field: "accountAddress" | "owner");
1515
+ }
1516
+ /**
1517
+ * Thrown when a Midnight builder or `MorphoMidnight` method cannot ABI-encode its calldata,
1518
+ * offer tree or market id, for example a `bytes32` field that is not 32 bytes, an integer
1519
+ * outside its Solidity type or a malformed address. Wraps the viem error as `cause`.
1520
+ *
1521
+ * @example
1522
+ * ```ts
1523
+ * import { MidnightCalldataEncodingError } from "@morpho-org/morpho-sdk";
1524
+ * import { BaseError } from "viem";
1525
+ *
1526
+ * const error = new MidnightCalldataEncodingError(
1527
+ * "midnightBundlesV2CancelAndMake",
1528
+ * new BaseError("bad bytes32"),
1529
+ * );
1530
+ * // error.input === "midnightBundlesV2CancelAndMake"
1531
+ * ```
1532
+ */
1533
+ export declare class MidnightCalldataEncodingError extends Error {
1534
+ readonly input: string;
1535
+ readonly cause: BaseError;
1536
+ /**
1537
+ * @param input - Input that could not be encoded: the contract function whose calldata
1538
+ * failed, `"offers"` for offer-tree hashing, `"marketId"` for market-id hashing, or the name
1539
+ * of the malformed address input, such as `"accountAddress"`, `"onBehalf"`, `"owner"`,
1540
+ * `"receiver"`, `"collateralReceiver"`, `"referralFeeRecipient"`, `"market.midnight"`,
1541
+ * `"authorized"`, `"publication.ratifier"`, `"loanToken"`, `"market.loanToken"`,
1542
+ * `"market.collateralParams[i].token"`, `"positionData.user"`, `"spender"` or `"token"` (a token
1543
+ * pulled with native funding, or the token checked by
1544
+ * `getMidnightApprovalRequirements`). `"blueMarket"` reports the Blue market encoding in
1545
+ * `supplyBlueMakeLend`: a malformed address or an out-of-range `lltv`.
1546
+ * @param cause - viem encoding error.
1547
+ */
1548
+ constructor(input: string, cause: BaseError);
1549
+ }