@morpho-org/morpho-sdk 10.5.0-next.0 → 10.6.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.
Files changed (170) hide show
  1. package/README.md +44 -1
  2. package/lib/cjs/abis.d.ts +793 -0
  3. package/lib/cjs/abis.js +811 -1
  4. package/lib/cjs/actions/blue/close.d.ts +169 -0
  5. package/lib/cjs/actions/blue/close.js +270 -0
  6. package/lib/cjs/actions/blue/common.js +2 -2
  7. package/lib/cjs/actions/blue/delever.d.ts +156 -0
  8. package/lib/cjs/actions/blue/delever.js +223 -0
  9. package/lib/cjs/actions/blue/index.d.ts +3 -0
  10. package/lib/cjs/actions/blue/index.js +3 -0
  11. package/lib/cjs/actions/blue/lever.d.ts +184 -0
  12. package/lib/cjs/actions/blue/lever.js +272 -0
  13. package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
  14. package/lib/cjs/actions/blue/leverageIntent.js +103 -0
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  16. package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
  17. package/lib/cjs/actions/midnight/takeLend.js +15 -9
  18. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  19. package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
  20. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  21. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
  22. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  23. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
  24. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  25. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
  26. package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
  27. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  30. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
  31. package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
  32. package/lib/cjs/addresses.d.ts +1 -1
  33. package/lib/cjs/addresses.js +6 -1
  34. package/lib/cjs/blue/addresses.d.ts +1 -1
  35. package/lib/cjs/blue/addresses.js +6 -1
  36. package/lib/cjs/constants.d.ts +1 -1
  37. package/lib/cjs/constants.js +7 -2
  38. package/lib/cjs/entities/blue/blue.d.ts +486 -2
  39. package/lib/cjs/entities/blue/blue.js +529 -34
  40. package/lib/cjs/entities/index.d.ts +1 -1
  41. package/lib/cjs/entities/midnight/midnight.d.ts +6 -0
  42. package/lib/cjs/entities/midnight/midnight.js +21 -2
  43. package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
  44. package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
  45. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +117 -0
  46. package/lib/cjs/entities/vaultV2BlueReallocationData.js +226 -2
  47. package/lib/cjs/helpers/constant.d.ts +41 -0
  48. package/lib/cjs/helpers/constant.js +42 -1
  49. package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
  50. package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
  51. package/lib/cjs/helpers/index.d.ts +4 -1
  52. package/lib/cjs/helpers/index.js +29 -1
  53. package/lib/cjs/helpers/leverage/index.d.ts +1 -0
  54. package/lib/cjs/helpers/leverage/index.js +11 -0
  55. package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
  56. package/lib/cjs/helpers/leverage/limits.js +715 -0
  57. package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
  58. package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
  59. package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
  60. package/lib/cjs/helpers/leverage/reallocations.js +276 -0
  61. package/lib/cjs/helpers/validate.d.ts +14 -0
  62. package/lib/cjs/helpers/validate.js +25 -1
  63. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  64. package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
  65. package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
  66. package/lib/cjs/helpers/zeroExQuote.js +763 -0
  67. package/lib/cjs/index.d.ts +1 -0
  68. package/lib/cjs/index.js +5 -2
  69. package/lib/cjs/reads/assertContractCode.d.ts +25 -0
  70. package/lib/cjs/reads/assertContractCode.js +30 -0
  71. package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
  72. package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
  73. package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +4 -0
  74. package/lib/cjs/transactionPlan/midnight/takeBorrow.js +8 -2
  75. package/lib/cjs/types/action.d.ts +130 -1
  76. package/lib/cjs/types/error.d.ts +84 -0
  77. package/lib/cjs/types/error.js +110 -3
  78. package/lib/cjs/types/index.d.ts +2 -0
  79. package/lib/cjs/types/index.js +2 -0
  80. package/lib/cjs/types/leverageError.d.ts +1552 -0
  81. package/lib/cjs/types/leverageError.js +1711 -0
  82. package/lib/cjs/types/zeroEx.d.ts +171 -0
  83. package/lib/cjs/types/zeroEx.js +2 -0
  84. package/lib/cjs/version.d.ts +1 -1
  85. package/lib/cjs/version.js +1 -1
  86. package/lib/esm/abis.d.ts +793 -0
  87. package/lib/esm/abis.js +809 -0
  88. package/lib/esm/actions/blue/close.d.ts +169 -0
  89. package/lib/esm/actions/blue/close.js +266 -0
  90. package/lib/esm/actions/blue/common.js +3 -3
  91. package/lib/esm/actions/blue/delever.d.ts +156 -0
  92. package/lib/esm/actions/blue/delever.js +219 -0
  93. package/lib/esm/actions/blue/index.d.ts +3 -0
  94. package/lib/esm/actions/blue/index.js +3 -0
  95. package/lib/esm/actions/blue/lever.d.ts +184 -0
  96. package/lib/esm/actions/blue/lever.js +268 -0
  97. package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
  98. package/lib/esm/actions/blue/leverageIntent.js +96 -0
  99. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +16 -11
  100. package/lib/esm/actions/midnight/takeBorrow.js +14 -8
  101. package/lib/esm/actions/midnight/takeLend.js +15 -9
  102. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
  103. package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
  104. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  105. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
  106. package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  107. package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
  108. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  109. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
  110. package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
  111. package/lib/esm/actions/requirements/blue/index.js +3 -0
  112. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  113. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  114. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
  115. package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
  116. package/lib/esm/addresses.d.ts +1 -1
  117. package/lib/esm/addresses.js +1 -1
  118. package/lib/esm/blue/addresses.d.ts +1 -1
  119. package/lib/esm/blue/addresses.js +1 -1
  120. package/lib/esm/constants.d.ts +1 -1
  121. package/lib/esm/constants.js +1 -1
  122. package/lib/esm/entities/blue/blue.d.ts +486 -2
  123. package/lib/esm/entities/blue/blue.js +501 -6
  124. package/lib/esm/entities/index.d.ts +1 -1
  125. package/lib/esm/entities/midnight/midnight.d.ts +6 -0
  126. package/lib/esm/entities/midnight/midnight.js +21 -2
  127. package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
  128. package/lib/esm/entities/requirements/assertContractCode.js +1 -25
  129. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +117 -0
  130. package/lib/esm/entities/vaultV2BlueReallocationData.js +227 -3
  131. package/lib/esm/helpers/constant.d.ts +41 -0
  132. package/lib/esm/helpers/constant.js +41 -0
  133. package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
  134. package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
  135. package/lib/esm/helpers/index.d.ts +4 -1
  136. package/lib/esm/helpers/index.js +4 -1
  137. package/lib/esm/helpers/leverage/index.d.ts +1 -0
  138. package/lib/esm/helpers/leverage/index.js +1 -0
  139. package/lib/esm/helpers/leverage/limits.d.ts +472 -0
  140. package/lib/esm/helpers/leverage/limits.js +705 -0
  141. package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
  142. package/lib/esm/helpers/leverage/positionMarket.js +24 -0
  143. package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
  144. package/lib/esm/helpers/leverage/reallocations.js +271 -0
  145. package/lib/esm/helpers/validate.d.ts +14 -0
  146. package/lib/esm/helpers/validate.js +25 -2
  147. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  148. package/lib/esm/helpers/validateRequirementSpender.js +5 -1
  149. package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
  150. package/lib/esm/helpers/zeroExQuote.js +754 -0
  151. package/lib/esm/index.d.ts +1 -0
  152. package/lib/esm/index.js +1 -0
  153. package/lib/esm/reads/assertContractCode.d.ts +25 -0
  154. package/lib/esm/reads/assertContractCode.js +26 -0
  155. package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
  156. package/lib/esm/reads/fetchZeroExQuote.js +326 -0
  157. package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +4 -0
  158. package/lib/esm/transactionPlan/midnight/takeBorrow.js +9 -3
  159. package/lib/esm/types/action.d.ts +130 -1
  160. package/lib/esm/types/error.d.ts +84 -0
  161. package/lib/esm/types/error.js +103 -0
  162. package/lib/esm/types/index.d.ts +2 -0
  163. package/lib/esm/types/index.js +2 -0
  164. package/lib/esm/types/leverageError.d.ts +1552 -0
  165. package/lib/esm/types/leverageError.js +1660 -0
  166. package/lib/esm/types/zeroEx.d.ts +171 -0
  167. package/lib/esm/types/zeroEx.js +1 -0
  168. package/lib/esm/version.d.ts +1 -1
  169. package/lib/esm/version.js +1 -1
  170. package/package.json +7 -7
@@ -1,6 +1,7 @@
1
1
  import type { InputMarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { CollateralTransfer as MidnightCollateralTransfer, GroupCancellation as MidnightGroupCancellation } from "@morpho-org/midnight-sdk";
3
3
  import type { Address, Hex, TypedDataDefinition, WalletClient } from "viem";
4
+ import type { LeverageActionOracleDeviation } from "../helpers/leverage/limits.js";
4
5
  import type { Deallocation } from "./deallocation.js";
5
6
  export type { CollateralTransfer as MidnightCollateralTransfer, GroupCancellation as MidnightGroupCancellation, } from "@morpho-org/midnight-sdk";
6
7
  /**
@@ -354,6 +355,36 @@ export interface BlueWithdrawCollateralAction extends BaseAction<"blueWithdrawCo
354
355
  /** Metadata for a direct BlueBundlesV1 repay and/or collateral withdrawal. */
355
356
  export interface BlueRepayWithdrawCollateralAction extends BaseAction<"blueRepayWithdrawCollateral", BlueRepayWithdrawCollateralActionArgs> {
356
357
  }
358
+ /**
359
+ * Path a ZeroExLeverageBundlesV1 Close took: `keepCollateral` sells collateral for the debt plus its interest
360
+ * buffer and returns whatever collateral the swap does not sell, which can be none when the fill reaches
361
+ * `maxCollateralIn` and that equals the whole position. A position without debt has no Close.
362
+ */
363
+ export type BlueCloseMode = "keepCollateral";
364
+ /** Metadata for a ZeroExLeverageBundlesV1 Close, with its signed bounds. */
365
+ export interface BlueCloseAction extends BaseAction<"blueClose", {
366
+ readonly market: Hex;
367
+ readonly onBehalf: Address;
368
+ readonly mode: BlueCloseMode;
369
+ /** Most collateral the swap may sell. */
370
+ readonly maxCollateralIn: bigint;
371
+ /** Least loan token the swap must return. */
372
+ readonly minLoanOut: bigint;
373
+ /** 0x Settler the swap runs through. */
374
+ readonly settler: Address;
375
+ /**
376
+ * Worst fill against the oracle (`computeLeverageOracleDeviation`): `"measured"` with the deviation, positive
377
+ * when it costs the user. Reported, never refused.
378
+ */
379
+ readonly oracleDeviation: LeverageActionOracleDeviation;
380
+ readonly deadline: bigint;
381
+ /** Leverage data block the bounds were computed at. */
382
+ readonly block: {
383
+ readonly number: bigint;
384
+ readonly timestamp: bigint;
385
+ };
386
+ }> {
387
+ }
357
388
  /** Metadata for a direct BlueBundlesV1 full borrow-position migration. */
358
389
  export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
359
390
  readonly sourceMarket: Hex;
@@ -368,6 +399,47 @@ export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
368
399
  readonly deadline: bigint;
369
400
  }> {
370
401
  }
402
+ /**
403
+ * Metadata for a ZeroExLeverageBundlesV1 Lever: the signed bounds, the swap's Settler and the leverage data
404
+ * block the bounds were computed at.
405
+ */
406
+ export interface BlueLeverAction extends BaseAction<"blueLever", {
407
+ readonly market: Hex;
408
+ readonly onBehalf: Address;
409
+ /** Collateral pulled from the user and supplied. */
410
+ readonly collateralAssets: bigint;
411
+ /** Loan assets pulled from the user and swapped. */
412
+ readonly loanAssets: bigint;
413
+ /** Collateral the swap must deliver: the exact-output quote's `buyAmount`. */
414
+ readonly minCollateralToBuy: bigint;
415
+ /** Assets borrowed on Blue for the user. */
416
+ readonly maxBorrowAssets: bigint;
417
+ /** Swap input cap the bundle allows: `loanAssets + maxBorrowAssets - penaltyAssets`. */
418
+ readonly maxSwapIn: bigint;
419
+ /** LTV the bundle checks after the Lever, WAD-scaled. */
420
+ readonly maxLtv: bigint;
421
+ /** Number of BluePublicAllocator reallocations executed before the borrow. */
422
+ readonly reallocations: number;
423
+ /** Loan-token assets donated as BluePublicAllocator penalties. */
424
+ readonly penaltyAssets: bigint;
425
+ /** 0x Settler the swap runs through. */
426
+ readonly settler: Address;
427
+ /**
428
+ * Worst price against the oracle (`computeLeverageOracleDeviation`), always `"measured"`: the deviation is
429
+ * positive when it costs the user, and at most 15% above the oracle.
430
+ */
431
+ readonly oracleDeviation: Extract<LeverageActionOracleDeviation, {
432
+ readonly status: "measured";
433
+ }>;
434
+ /** Execution deadline in Unix seconds. */
435
+ readonly deadline: bigint;
436
+ /** Leverage data block the bounds were computed at. */
437
+ readonly block: {
438
+ readonly number: bigint;
439
+ readonly timestamp: bigint;
440
+ };
441
+ }> {
442
+ }
371
443
  /**
372
444
  * Enforces that exactly one of `assets` / `shares` is provided.
373
445
  *
@@ -556,12 +628,46 @@ export interface MidnightCancelOffersAction extends BaseAction<"midnightCancelOf
556
628
  readonly onBehalf: Address;
557
629
  }> {
558
630
  }
631
+ /**
632
+ * Metadata for a ZeroExLeverageBundlesV1 Delever (pay back with collateral): the signed bounds, the 0x Settler
633
+ * the swap runs through and the data block the bounds were priced at.
634
+ */
635
+ export interface BlueDeleverAction extends BaseAction<"blueDelever", {
636
+ readonly market: Hex;
637
+ readonly onBehalf: Address;
638
+ /** Collateral withdrawn: the most the swap may sell; the bundle supplies any unsold part back. */
639
+ readonly maxCollateralToSell: bigint;
640
+ /** Exact debt repaid first; the swap's output floor. */
641
+ readonly minRepayAssets: bigint;
642
+ /**
643
+ * WAD-scaled LTV cap checked after the action: the position's LTV with its debt accrued to the deadline,
644
+ * at the data block's price. It exceeds the data-block LTV on a market that accrues interest.
645
+ */
646
+ readonly maxLtv: bigint;
647
+ /** Unix-seconds deadline: the data block timestamp plus one hour. */
648
+ readonly deadline: bigint;
649
+ /** 0x Settler the swap calldata calls. */
650
+ readonly settler: Address;
651
+ /**
652
+ * Worst fill against the oracle (`computeLeverageOracleDeviation`), always `"measured"`: the deviation is
653
+ * positive when it costs the user. Reported, never refused.
654
+ */
655
+ readonly oracleDeviation: Extract<LeverageActionOracleDeviation, {
656
+ readonly status: "measured";
657
+ }>;
658
+ /** Leverage data block the bounds were priced at. */
659
+ readonly block: {
660
+ readonly number: bigint;
661
+ readonly timestamp: bigint;
662
+ };
663
+ }> {
664
+ }
559
665
  /**
560
666
  * Enumerates every action a {@link Transaction} can describe across the VaultV1,
561
667
  * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
562
668
  * consumers can `switch` exhaustively on it.
563
669
  */
564
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralWithNativeAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction | MidnightCancelOffersAction;
670
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueLeverAction | BlueDeleverAction | BlueCloseAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralWithNativeAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction | MidnightCancelOffersAction;
565
671
  /**
566
672
  * Describes a single, immutable, deep-frozen transaction to submit on-chain:
567
673
  * the target `to`, native `value`, encoded call `data`, and the originating
@@ -774,6 +880,29 @@ interface ActionRequirementsParams {
774
880
  */
775
881
  readonly useSimplePermit?: boolean;
776
882
  }
883
+ /**
884
+ * Lazy entity result of a ZeroExLeverageBundlesV1 action (Lever, Delever, Close).
885
+ *
886
+ * Send `getRequirements()` first (ERC-20 approvals for a Lever, then the Morpho authorization of the bundle),
887
+ * then the transaction `buildTx()` returns. For the ZeroExLeverageBundlesV1 that morpho-ts ships, the approvals
888
+ * are unlimited (capped per token) and persist after the action; for a bundle registered with
889
+ * `registerCustomAddresses`, each approval is exactly the pulled amount, which the action spends. The
890
+ * authorization persists in both cases.
891
+ *
892
+ * @example
893
+ * ```ts
894
+ * import type { LeverageActionOutput, TransactionAction } from "@morpho-org/morpho-sdk";
895
+ *
896
+ * declare const action: LeverageActionOutput<TransactionAction>;
897
+ * const calls = [...(await action.getRequirements()), action.buildTx()];
898
+ * ```
899
+ */
900
+ export interface LeverageActionOutput<TAction extends BaseAction> {
901
+ /** Resolves the missing ERC-20 approvals and the Morpho authorization of the bundle, in submission order. */
902
+ readonly getRequirements: () => Promise<readonly Readonly<Transaction<ERC20ApprovalAction | BlueAuthorizationAction>>[]>;
903
+ /** Returns the deep-frozen leverage transaction; synchronous and identical on every call. */
904
+ readonly buildTx: () => Readonly<Transaction<TAction>>;
905
+ }
777
906
  /** Lazy entity result exposing prerequisite resolution and synchronous transaction building. */
778
907
  export interface ActionOutput<TAction extends BaseAction = TransactionAction, TSignatures = RequirementSignature, TRequirementsParams = ActionRequirementsParams> {
779
908
  readonly buildTx: (signatures?: TSignatures) => Readonly<Transaction<TAction>>;
@@ -23,6 +23,25 @@ export declare class NegativeInputError extends Error {
23
23
  */
24
24
  constructor(field: string, value: bigint);
25
25
  }
26
+ /**
27
+ * Thrown when a morpho-sdk input that must be a boolean is missing or of another type, such as a truthy string.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { NonBooleanInputError } from "@morpho-org/morpho-sdk";
32
+ *
33
+ * const error = new NonBooleanInputError("reallocation.fromIdle", "false");
34
+ * ```
35
+ */
36
+ export declare class NonBooleanInputError extends Error {
37
+ readonly field: string;
38
+ readonly value: unknown;
39
+ /**
40
+ * @param field - Public input field whose value is invalid.
41
+ * @param value - Value supplied for the field.
42
+ */
43
+ constructor(field: string, value: unknown);
44
+ }
26
45
  /**
27
46
  * Thrown when a morpho-sdk input that must be positive is zero or negative.
28
47
  *
@@ -97,6 +116,28 @@ export declare class ExpiredDeadlineError extends Error {
97
116
  */
98
117
  constructor(deadline: bigint, timestamp: bigint);
99
118
  }
119
+ /**
120
+ * Thrown when a leverage action's deadline, the leverage data block plus one hour, has passed. The caller
121
+ * cannot choose that deadline: read the leverage data again first. For a Lever or a Delever, fetch a new 0x
122
+ * quote and rebuild. For a Close, do the same if the position still has debt; if only collateral is left, for
123
+ * example because the debt was repaid while the Close was pending, a Close refuses with
124
+ * `LeverageCloseWithoutDebtError`, so withdraw the collateral with `withdrawCollateral` instead. It extends
125
+ * {@link ExpiredDeadlineError}, so a catch of that class still catches it.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * import { ExpiredLeverageDeadlineError } from "@morpho-org/morpho-sdk";
130
+ *
131
+ * const error = new ExpiredLeverageDeadlineError(1_700_003_600n, 1_700_003_601n);
132
+ * ```
133
+ */
134
+ export declare class ExpiredLeverageDeadlineError extends ExpiredDeadlineError {
135
+ /**
136
+ * @param deadline - Leverage deadline: the leverage data block timestamp plus one hour.
137
+ * @param timestamp - Current timestamp used for validation.
138
+ */
139
+ constructor(deadline: bigint, timestamp: bigint);
140
+ }
100
141
  /**
101
142
  * Thrown when a VaultExitBundlesV1 Vault V2 exit targets a vault without exactly one adapter.
102
143
  *
@@ -657,6 +698,24 @@ export declare class UnsupportedAuthorizationOperatorError extends Error {
657
698
  */
658
699
  constructor(authorized: Address, chainId: number);
659
700
  }
701
+ /**
702
+ * Thrown when a leverage requirement is requested for a malformed input: a missing operation, an
703
+ * operation tag other than `lever`, `delever` or `close`, a Lever amount, approval amount or
704
+ * allowance that is not a bigint, or a user or token address that is not an address.
705
+ */
706
+ export declare class InvalidLeverageOperationError extends Error {
707
+ readonly field: string;
708
+ /** The rejected value when it is a string, such as an unknown operation tag; `undefined` otherwise. */
709
+ readonly value: string | undefined;
710
+ /** The `typeof` of the rejected value, or `"null"` for `null`. */
711
+ readonly valueType: string;
712
+ /**
713
+ * @param field - The field rejected: `operation`, `type`, a Lever amount, `amount`, `allowance`,
714
+ * `userAddress`, `marketParams.loanToken` or `marketParams.collateralToken`.
715
+ * @param input - The rejected value, as received.
716
+ */
717
+ constructor(field: string, input: unknown);
718
+ }
660
719
  /** Thrown when reallocations are attached to a combined call with no borrow leg. */
661
720
  export declare class ReallocationsRequireBorrowError extends Error {
662
721
  constructor();
@@ -1328,6 +1387,31 @@ export declare class MidnightTakeDeadlineTooFarError extends Error {
1328
1387
  readonly maxDeadline: bigint;
1329
1388
  });
1330
1389
  }
1390
+ /**
1391
+ * Thrown when a Midnight borrow prepared at or before maturity could execute less than
1392
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, when unpaid debt becomes liquidatable.
1393
+ * Credit covering the target at preparation does not exempt the borrow, because the sell is not
1394
+ * reduce-only; sell credit only inside the window with `takeWithdraw`.
1395
+ */
1396
+ export declare class MidnightBorrowTooCloseToMaturityError extends Error {
1397
+ /** Deadline supplied by the caller. */
1398
+ readonly deadline: bigint;
1399
+ /** Market maturity timestamp. */
1400
+ readonly maturity: bigint;
1401
+ /** Latest accepted deadline for this maturity. */
1402
+ readonly latestDeadline: bigint;
1403
+ /**
1404
+ * @param params - Supplied deadline, market maturity and latest accepted deadline.
1405
+ * @param params.deadline - Deadline supplied by the caller.
1406
+ * @param params.maturity - Market maturity timestamp.
1407
+ * @param params.latestDeadline - Latest accepted deadline for this maturity.
1408
+ */
1409
+ constructor(params: {
1410
+ readonly deadline: bigint;
1411
+ readonly maturity: bigint;
1412
+ readonly latestDeadline: bigint;
1413
+ });
1414
+ }
1331
1415
  /** Thrown when a Midnight maker offer targets a different chain than the action flow. */
1332
1416
  export declare class MidnightOfferMarketChainMismatchError extends Error {
1333
1417
  constructor(params: {
@@ -28,6 +28,30 @@ export class NegativeInputError extends Error {
28
28
  this.name = "NegativeInputError";
29
29
  }
30
30
  }
31
+ /**
32
+ * Thrown when a morpho-sdk input that must be a boolean is missing or of another type, such as a truthy string.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { NonBooleanInputError } from "@morpho-org/morpho-sdk";
37
+ *
38
+ * const error = new NonBooleanInputError("reallocation.fromIdle", "false");
39
+ * ```
40
+ */
41
+ export class NonBooleanInputError extends Error {
42
+ field;
43
+ value;
44
+ /**
45
+ * @param field - Public input field whose value is invalid.
46
+ * @param value - Value supplied for the field.
47
+ */
48
+ constructor(field, value) {
49
+ super(`Input "${field}" must be a boolean, got a value of type "${typeof value}". Pass it as a boolean.`);
50
+ this.field = field;
51
+ this.value = value;
52
+ this.name = "NonBooleanInputError";
53
+ }
54
+ }
31
55
  /**
32
56
  * Thrown when a morpho-sdk input that must be positive is zero or negative.
33
57
  *
@@ -126,6 +150,32 @@ export class ExpiredDeadlineError extends Error {
126
150
  this.name = "ExpiredDeadlineError";
127
151
  }
128
152
  }
153
+ /**
154
+ * Thrown when a leverage action's deadline, the leverage data block plus one hour, has passed. The caller
155
+ * cannot choose that deadline: read the leverage data again first. For a Lever or a Delever, fetch a new 0x
156
+ * quote and rebuild. For a Close, do the same if the position still has debt; if only collateral is left, for
157
+ * example because the debt was repaid while the Close was pending, a Close refuses with
158
+ * `LeverageCloseWithoutDebtError`, so withdraw the collateral with `withdrawCollateral` instead. It extends
159
+ * {@link ExpiredDeadlineError}, so a catch of that class still catches it.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * import { ExpiredLeverageDeadlineError } from "@morpho-org/morpho-sdk";
164
+ *
165
+ * const error = new ExpiredLeverageDeadlineError(1_700_003_600n, 1_700_003_601n);
166
+ * ```
167
+ */
168
+ export class ExpiredLeverageDeadlineError extends ExpiredDeadlineError {
169
+ /**
170
+ * @param deadline - Leverage deadline: the leverage data block timestamp plus one hour.
171
+ * @param timestamp - Current timestamp used for validation.
172
+ */
173
+ constructor(deadline, timestamp) {
174
+ super(deadline, timestamp);
175
+ this.message = `Leverage deadline "${deadline}" (the leverage data block plus one hour) has expired at timestamp "${timestamp}". Read the leverage data again with getLeverageData and rebuild, fetching a new 0x quote only if the action swaps.`;
176
+ this.name = "ExpiredLeverageDeadlineError";
177
+ }
178
+ }
129
179
  /**
130
180
  * Thrown when a VaultExitBundlesV1 Vault V2 exit targets a vault without exactly one adapter.
131
181
  *
@@ -784,6 +834,32 @@ export class UnsupportedAuthorizationOperatorError extends Error {
784
834
  this.name = "UnsupportedAuthorizationOperatorError";
785
835
  }
786
836
  }
837
+ /**
838
+ * Thrown when a leverage requirement is requested for a malformed input: a missing operation, an
839
+ * operation tag other than `lever`, `delever` or `close`, a Lever amount, approval amount or
840
+ * allowance that is not a bigint, or a user or token address that is not an address.
841
+ */
842
+ export class InvalidLeverageOperationError extends Error {
843
+ field;
844
+ /** The rejected value when it is a string, such as an unknown operation tag; `undefined` otherwise. */
845
+ value;
846
+ /** The `typeof` of the rejected value, or `"null"` for `null`. */
847
+ valueType;
848
+ /**
849
+ * @param field - The field rejected: `operation`, `type`, a Lever amount, `amount`, `allowance`,
850
+ * `userAddress`, `marketParams.loanToken` or `marketParams.collateralToken`.
851
+ * @param input - The rejected value, as received.
852
+ */
853
+ constructor(field, input) {
854
+ const value = typeof input === "string" ? input : undefined;
855
+ const valueType = input === null ? "null" : typeof input;
856
+ super(`Leverage input field "${field}" is invalid, got ${value === undefined ? `a value of type "${valueType}"` : `"${value}"`}. Pass type "lever", "delever" or "close", bigint amounts and allowances, and valid addresses.`);
857
+ this.field = field;
858
+ this.value = value;
859
+ this.valueType = valueType;
860
+ this.name = "InvalidLeverageOperationError";
861
+ }
862
+ }
787
863
  /** Thrown when reallocations are attached to a combined call with no borrow leg. */
788
864
  export class ReallocationsRequireBorrowError extends Error {
789
865
  constructor() {
@@ -1630,6 +1706,33 @@ export class MidnightTakeDeadlineTooFarError extends Error {
1630
1706
  this.name = "MidnightTakeDeadlineTooFarError";
1631
1707
  }
1632
1708
  }
1709
+ /**
1710
+ * Thrown when a Midnight borrow prepared at or before maturity could execute less than
1711
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` (2 hours) before it, when unpaid debt becomes liquidatable.
1712
+ * Credit covering the target at preparation does not exempt the borrow, because the sell is not
1713
+ * reduce-only; sell credit only inside the window with `takeWithdraw`.
1714
+ */
1715
+ export class MidnightBorrowTooCloseToMaturityError extends Error {
1716
+ /** Deadline supplied by the caller. */
1717
+ deadline;
1718
+ /** Market maturity timestamp. */
1719
+ maturity;
1720
+ /** Latest accepted deadline for this maturity. */
1721
+ latestDeadline;
1722
+ /**
1723
+ * @param params - Supplied deadline, market maturity and latest accepted deadline.
1724
+ * @param params.deadline - Deadline supplied by the caller.
1725
+ * @param params.maturity - Market maturity timestamp.
1726
+ * @param params.latestDeadline - Latest accepted deadline for this maturity.
1727
+ */
1728
+ constructor(params) {
1729
+ super(`Midnight borrow deadline "${params.deadline}" is less than two hours before market maturity "${params.maturity}", when unpaid debt becomes liquidatable. Borrow on a later maturity, sell credit only with takeWithdraw, or, while "${params.latestDeadline}" is still in the future, use a deadline no later than it.`);
1730
+ this.deadline = params.deadline;
1731
+ this.maturity = params.maturity;
1732
+ this.latestDeadline = params.latestDeadline;
1733
+ this.name = "MidnightBorrowTooCloseToMaturityError";
1734
+ }
1735
+ }
1633
1736
  /** Thrown when a Midnight maker offer targets a different chain than the action flow. */
1634
1737
  export class MidnightOfferMarketChainMismatchError extends Error {
1635
1738
  constructor(params) {
@@ -3,6 +3,8 @@ export * from "./client.js";
3
3
  export * from "./deallocation.js";
4
4
  export * from "./entity.js";
5
5
  export * from "./error.js";
6
+ export * from "./leverageError.js";
6
7
  export * from "./metadata.js";
7
8
  export * from "./midnightPublicationError.js";
8
9
  export * from "./sharedLiquidity.js";
10
+ export * from "./zeroEx.js";
@@ -3,6 +3,8 @@ export * from "./client.js";
3
3
  export * from "./deallocation.js";
4
4
  export * from "./entity.js";
5
5
  export * from "./error.js";
6
+ export * from "./leverageError.js";
6
7
  export * from "./metadata.js";
7
8
  export * from "./midnightPublicationError.js";
8
9
  export * from "./sharedLiquidity.js";
10
+ export * from "./zeroEx.js";