@morpho-org/morpho-sdk 8.2.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 +14 -8
  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 +4 -1
  12. package/lib/cjs/actions/midnight/redeem.js +13 -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 +5 -1
  16. package/lib/cjs/actions/midnight/supplyCollateral.js +14 -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 +58 -17
  48. package/lib/cjs/entities/midnight/midnight.js +133 -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 +64 -5
  78. package/lib/cjs/types/error.js +152 -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 +4 -1
  88. package/lib/esm/actions/midnight/redeem.js +15 -5
  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 +5 -1
  92. package/lib/esm/actions/midnight/supplyCollateral.js +16 -5
  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 +58 -17
  124. package/lib/esm/entities/midnight/midnight.js +134 -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 +64 -5
  154. package/lib/esm/types/error.js +146 -6
  155. package/package.json +6 -5
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateTakeableOffers = void 0;
4
- const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
5
4
  const index_js_1 = require("../types/index.js");
5
+ const encodeMidnightCalldata_js_1 = require("./encodeMidnightCalldata.js");
6
6
  const validateOfferSides_js_1 = require("./validateOfferSides.js");
7
7
  /**
8
8
  * Validates the pure invariants shared by Midnight take entity and action layers.
@@ -12,16 +12,17 @@ const validateOfferSides_js_1 = require("./validateOfferSides.js");
12
12
  * @throws {EmptyMidnightTakeableOffersError} when no offers are provided.
13
13
  * @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
14
14
  * @throws {MidnightTakeableOfferMarketMismatchError} when an offer belongs to another market.
15
+ * @throws {MidnightCalldataEncodingError} when a market cannot be ABI-encoded.
15
16
  * @internal
16
17
  */
17
18
  const validateTakeableOffers = (params) => {
18
19
  if (params.takeableOffers.length === 0) {
19
20
  throw new index_js_1.EmptyMidnightTakeableOffersError();
20
21
  }
21
- const marketId = midnight_sdk_1.MarketUtils.toId(params.market);
22
+ const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(params.market);
22
23
  (0, validateOfferSides_js_1.validateOfferSides)(params.takeableOffers.map((take) => take.offer), params.expectedBuy);
23
24
  for (const [index, take] of params.takeableOffers.entries()) {
24
- const actualMarketId = midnight_sdk_1.MarketUtils.toId(take.offer.market);
25
+ const actualMarketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(take.offer.market);
25
26
  if (actualMarketId.toLowerCase() !== marketId.toLowerCase()) {
26
27
  throw new index_js_1.MidnightTakeableOfferMarketMismatchError({
27
28
  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: {
@@ -1220,6 +1216,14 @@ export declare class MidnightZeroReceiverError extends Error {
1220
1216
  */
1221
1217
  constructor(field: "receiver" | "collateralReceiver");
1222
1218
  }
1219
+ /** Thrown when a Midnight flow uses the zero address as the account it acts for. */
1220
+ export declare class MidnightZeroOnBehalfError extends Error {
1221
+ readonly field: "onBehalf";
1222
+ /**
1223
+ * @param field - Account field containing the zero address.
1224
+ */
1225
+ constructor(field: "onBehalf");
1226
+ }
1223
1227
  /**
1224
1228
  * Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
1225
1229
  * forward received assets.
@@ -1488,3 +1492,58 @@ export declare class MissingContractCodeError extends Error {
1488
1492
  */
1489
1493
  constructor(address: Address, chainId: number, role: AddressLabel);
1490
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
+ }