@morpho-org/morpho-sdk 7.0.0 → 8.1.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 (192) hide show
  1. package/MIGRATION-v6-to-v7.md +6 -0
  2. package/MIGRATION-v7-to-v8.md +290 -0
  3. package/README.md +11 -6
  4. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  5. package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  6. package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
  7. package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
  8. package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
  9. package/lib/cjs/actions/midnight/redeem.js +18 -1
  10. package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  11. package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
  12. package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
  13. package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
  14. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  15. package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
  16. package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
  17. package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
  18. package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
  19. package/lib/cjs/actions/midnight/takeLend.js +27 -9
  20. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  21. package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
  22. package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
  23. package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
  24. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  25. package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
  26. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  27. package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  28. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  29. package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
  30. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  31. package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  32. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  33. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  34. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  35. package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  36. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  37. package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  38. package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
  39. package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
  40. package/lib/cjs/blue/errors.d.ts +1 -1
  41. package/lib/cjs/blue/errors.js +3 -1
  42. package/lib/cjs/blue/types.d.ts +1 -1
  43. package/lib/cjs/blue/utils.d.ts +1 -1
  44. package/lib/cjs/blue/utils.js +5 -1
  45. package/lib/cjs/entities/blue/blue.d.ts +109 -27
  46. package/lib/cjs/entities/blue/blue.js +103 -28
  47. package/lib/cjs/entities/index.d.ts +1 -1
  48. package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
  49. package/lib/cjs/entities/midnight/deadline.js +24 -0
  50. package/lib/cjs/entities/midnight/midnight.d.ts +432 -74
  51. package/lib/cjs/entities/midnight/midnight.js +869 -188
  52. package/lib/cjs/entities/midnight/publication.d.ts +134 -0
  53. package/lib/cjs/entities/midnight/publication.js +404 -0
  54. package/lib/cjs/entities/midnight/types.d.ts +26 -5
  55. package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
  56. package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
  57. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  58. package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
  59. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  60. package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  61. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  62. package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  63. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
  64. package/lib/cjs/entities/vaultV1/vaultV1.js +83 -49
  65. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +54 -12
  66. package/lib/cjs/entities/vaultV2/vaultV2.js +86 -55
  67. package/lib/cjs/errors.d.ts +1 -1
  68. package/lib/cjs/errors.js +4 -2
  69. package/lib/cjs/helpers/constant.d.ts +5 -0
  70. package/lib/cjs/helpers/constant.js +6 -1
  71. package/lib/cjs/helpers/index.d.ts +1 -1
  72. package/lib/cjs/helpers/index.js +2 -1
  73. package/lib/cjs/helpers/validate.d.ts +163 -8
  74. package/lib/cjs/helpers/validate.js +179 -8
  75. package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
  76. package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
  77. package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
  78. package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
  79. package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
  80. package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
  81. package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  82. package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
  83. package/lib/cjs/index.d.ts +1 -0
  84. package/lib/cjs/index.js +3 -0
  85. package/lib/cjs/types/action.d.ts +102 -1
  86. package/lib/cjs/types/action.js +102 -1
  87. package/lib/cjs/types/error.d.ts +197 -4
  88. package/lib/cjs/types/error.js +265 -5
  89. package/lib/cjs/types/index.d.ts +1 -0
  90. package/lib/cjs/types/index.js +1 -0
  91. package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
  92. package/lib/cjs/types/midnightCancelAndMake.js +2 -0
  93. package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
  94. package/lib/cjs/types/midnightPublicationError.js +376 -0
  95. package/lib/cjs/types.d.ts +1 -1
  96. package/lib/cjs/utils.d.ts +2 -1
  97. package/lib/cjs/utils.js +8 -2
  98. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
  99. package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
  100. package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
  101. package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
  102. package/lib/esm/actions/midnight/redeem.d.ts +8 -1
  103. package/lib/esm/actions/midnight/redeem.js +18 -1
  104. package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
  105. package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
  106. package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
  107. package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
  108. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
  109. package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
  110. package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
  111. package/lib/esm/actions/midnight/takeBorrow.js +47 -15
  112. package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
  113. package/lib/esm/actions/midnight/takeLend.js +27 -9
  114. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
  115. package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
  116. package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
  117. package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
  118. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
  119. package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
  120. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
  121. package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
  122. package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
  123. package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
  124. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
  125. package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
  126. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
  127. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
  128. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
  129. package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
  130. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
  131. package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
  132. package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
  133. package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
  134. package/lib/esm/blue/errors.d.ts +1 -1
  135. package/lib/esm/blue/errors.js +1 -1
  136. package/lib/esm/blue/types.d.ts +1 -1
  137. package/lib/esm/blue/utils.d.ts +1 -1
  138. package/lib/esm/blue/utils.js +1 -1
  139. package/lib/esm/entities/blue/blue.d.ts +109 -27
  140. package/lib/esm/entities/blue/blue.js +104 -29
  141. package/lib/esm/entities/index.d.ts +1 -1
  142. package/lib/esm/entities/midnight/deadline.d.ts +15 -0
  143. package/lib/esm/entities/midnight/deadline.js +20 -0
  144. package/lib/esm/entities/midnight/midnight.d.ts +432 -74
  145. package/lib/esm/entities/midnight/midnight.js +870 -189
  146. package/lib/esm/entities/midnight/publication.d.ts +134 -0
  147. package/lib/esm/entities/midnight/publication.js +397 -0
  148. package/lib/esm/entities/midnight/types.d.ts +26 -5
  149. package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
  150. package/lib/esm/entities/requirements/assertContractCode.js +74 -0
  151. package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
  152. package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
  153. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
  154. package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
  155. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
  156. package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
  157. package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
  158. package/lib/esm/entities/vaultV1/vaultV1.js +85 -51
  159. package/lib/esm/entities/vaultV2/vaultV2.d.ts +54 -12
  160. package/lib/esm/entities/vaultV2/vaultV2.js +88 -57
  161. package/lib/esm/errors.d.ts +1 -1
  162. package/lib/esm/errors.js +1 -1
  163. package/lib/esm/helpers/constant.d.ts +5 -0
  164. package/lib/esm/helpers/constant.js +5 -0
  165. package/lib/esm/helpers/index.d.ts +1 -1
  166. package/lib/esm/helpers/index.js +1 -1
  167. package/lib/esm/helpers/validate.d.ts +163 -8
  168. package/lib/esm/helpers/validate.js +177 -7
  169. package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
  170. package/lib/esm/helpers/validateMidnightBounds.js +72 -0
  171. package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
  172. package/lib/esm/helpers/validateMidnightPublication.js +139 -0
  173. package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
  174. package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
  175. package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
  176. package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
  177. package/lib/esm/index.d.ts +1 -0
  178. package/lib/esm/index.js +1 -0
  179. package/lib/esm/types/action.d.ts +102 -1
  180. package/lib/esm/types/action.js +102 -1
  181. package/lib/esm/types/error.d.ts +197 -4
  182. package/lib/esm/types/error.js +253 -2
  183. package/lib/esm/types/index.d.ts +1 -0
  184. package/lib/esm/types/index.js +1 -0
  185. package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
  186. package/lib/esm/types/midnightCancelAndMake.js +1 -0
  187. package/lib/esm/types/midnightPublicationError.d.ts +332 -0
  188. package/lib/esm/types/midnightPublicationError.js +359 -0
  189. package/lib/esm/types.d.ts +1 -1
  190. package/lib/esm/utils.d.ts +2 -1
  191. package/lib/esm/utils.js +2 -1
  192. package/package.json +10 -10
@@ -677,8 +677,99 @@ export interface ActionOutput<TAction extends BaseAction = TransactionAction, TS
677
677
  readonly buildTx: (signatures?: TSignatures) => Readonly<Transaction<TAction>>;
678
678
  readonly getRequirements: (params?: TRequirementsParams) => Promise<readonly ActionRequirement[]>;
679
679
  }
680
+ /**
681
+ * Narrows an action requirement to an ERC-20 approval transaction.
682
+ *
683
+ * @param requirement - The requirement returned by `getRequirements()` to test.
684
+ * @returns `true` when `requirement.action.type` is `"erc20Approval"`.
685
+ * @example
686
+ * ```ts
687
+ * import { vaults } from "@morpho-org/morpho-test";
688
+ * import {
689
+ * isRequirementApproval,
690
+ * morphoViemExtension,
691
+ * } from "@morpho-org/morpho-sdk";
692
+ * import { createWalletClient, http, publicActions, zeroAddress } from "viem";
693
+ * import { mainnet } from "viem/chains";
694
+ *
695
+ * const client = createWalletClient({
696
+ * chain: mainnet,
697
+ * transport: http(),
698
+ * account: zeroAddress,
699
+ * })
700
+ * .extend(publicActions)
701
+ * .extend(morphoViemExtension());
702
+ *
703
+ * const vault = client.morpho.vaultV1(
704
+ * vaults[mainnet.id].steakUsdc.address,
705
+ * mainnet.id,
706
+ * );
707
+ * const vaultData = await vault.getData();
708
+ * const handle = vault.deposit({
709
+ * amount: 1_000_000n,
710
+ * userAddress: zeroAddress,
711
+ * vaultData,
712
+ * });
713
+ *
714
+ * for (const requirement of await handle.getRequirements()) {
715
+ * if (!isRequirementApproval(requirement)) continue;
716
+ *
717
+ * const { amount, spender } = requirement.action.args;
718
+ * const hash = await client.sendTransaction(requirement);
719
+ * console.log({ amount, spender, hash });
720
+ * await client.waitForTransactionReceipt({ hash });
721
+ * }
722
+ * ```
723
+ */
680
724
  export declare function isRequirementApproval(requirement: unknown): requirement is Transaction<ERC20ApprovalAction>;
681
- /** Checks whether an action requirement is a Blue authorization call. */
725
+ /**
726
+ * Narrows an action requirement to a Blue authorization call.
727
+ *
728
+ * @param requirement - The requirement returned by `getRequirements()` to test.
729
+ * @returns `true` when the requirement is a call whose `action.type` is `"blueAuthorization"`.
730
+ * @example
731
+ * ```ts
732
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
733
+ * import { markets } from "@morpho-org/morpho-test";
734
+ * import { Time } from "@morpho-org/morpho-ts";
735
+ * import { createWalletClient, http, publicActions, zeroAddress } from "viem";
736
+ * import { mainnet } from "viem/chains";
737
+ * import {
738
+ * isRequirementBlueAuthorization,
739
+ * morphoViemExtension,
740
+ * } from "@morpho-org/morpho-sdk";
741
+ *
742
+ * const client = createWalletClient({
743
+ * chain: mainnet,
744
+ * transport: http(),
745
+ * account: zeroAddress,
746
+ * })
747
+ * .extend(publicActions)
748
+ * .extend(morphoViemExtension());
749
+ *
750
+ * const blue = client.morpho.blue(
751
+ * markets[mainnet.id].usdc_wbtc,
752
+ * mainnet.id,
753
+ * );
754
+ * const positionData = new AccrualPosition(
755
+ * { user: zeroAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 8n },
756
+ * await blue.getMarketData(),
757
+ * );
758
+ * const handle = blue.borrow({
759
+ * userAddress: zeroAddress,
760
+ * borrowAssets: 1_000_000n,
761
+ * positionData,
762
+ * deadline: Time.timestamp() + 600n,
763
+ * });
764
+ *
765
+ * for (const requirement of await handle.getRequirements()) {
766
+ * if (!isRequirementBlueAuthorization(requirement)) continue;
767
+ *
768
+ * const hash = await client.sendTransaction(requirement);
769
+ * await client.waitForTransactionReceipt({ hash });
770
+ * }
771
+ * ```
772
+ */
682
773
  export declare function isRequirementBlueAuthorization(requirement: unknown): requirement is Transaction<BlueAuthorizationAction>;
683
774
  /**
684
775
  * Narrows an action requirement to a signature requirement.
@@ -743,6 +834,16 @@ export declare function isPermit2SignatureTransferSignature(signature: Requireme
743
834
  *
744
835
  * @param signature - The signed requirement to test.
745
836
  * @returns `true` when `signature.action.type` is `"authorization"`.
837
+ * @example
838
+ * ```ts
839
+ * import {
840
+ * isAuthorizationSignature,
841
+ * type RequirementSignature,
842
+ * } from "@morpho-org/morpho-sdk";
843
+ *
844
+ * const getAuthorizationNonce = (signature: RequirementSignature): bigint | undefined =>
845
+ * isAuthorizationSignature(signature) ? signature.args.nonce : undefined;
846
+ * ```
746
847
  */
747
848
  export declare function isAuthorizationSignature(signature: RequirementSignature): signature is AuthorizationRequirementSignature;
748
849
  /** The typed requirement-signature slots a transaction builder consumes, split from a `buildTx` array. */
@@ -1,4 +1,48 @@
1
1
  import { AmbiguousRequirementSignaturesError, UnexpectedRequirementSignatureError, UnsupportedRequirementSignatureError, } from "./error.js";
2
+ /**
3
+ * Narrows an action requirement to an ERC-20 approval transaction.
4
+ *
5
+ * @param requirement - The requirement returned by `getRequirements()` to test.
6
+ * @returns `true` when `requirement.action.type` is `"erc20Approval"`.
7
+ * @example
8
+ * ```ts
9
+ * import { vaults } from "@morpho-org/morpho-test";
10
+ * import {
11
+ * isRequirementApproval,
12
+ * morphoViemExtension,
13
+ * } from "@morpho-org/morpho-sdk";
14
+ * import { createWalletClient, http, publicActions, zeroAddress } from "viem";
15
+ * import { mainnet } from "viem/chains";
16
+ *
17
+ * const client = createWalletClient({
18
+ * chain: mainnet,
19
+ * transport: http(),
20
+ * account: zeroAddress,
21
+ * })
22
+ * .extend(publicActions)
23
+ * .extend(morphoViemExtension());
24
+ *
25
+ * const vault = client.morpho.vaultV1(
26
+ * vaults[mainnet.id].steakUsdc.address,
27
+ * mainnet.id,
28
+ * );
29
+ * const vaultData = await vault.getData();
30
+ * const handle = vault.deposit({
31
+ * amount: 1_000_000n,
32
+ * userAddress: zeroAddress,
33
+ * vaultData,
34
+ * });
35
+ *
36
+ * for (const requirement of await handle.getRequirements()) {
37
+ * if (!isRequirementApproval(requirement)) continue;
38
+ *
39
+ * const { amount, spender } = requirement.action.args;
40
+ * const hash = await client.sendTransaction(requirement);
41
+ * console.log({ amount, spender, hash });
42
+ * await client.waitForTransactionReceipt({ hash });
43
+ * }
44
+ * ```
45
+ */
2
46
  export function isRequirementApproval(requirement) {
3
47
  return (typeof requirement === "object" &&
4
48
  requirement !== null &&
@@ -11,7 +55,54 @@ export function isRequirementApproval(requirement) {
11
55
  "type" in requirement.action &&
12
56
  requirement.action.type === "erc20Approval");
13
57
  }
14
- /** Checks whether an action requirement is a Blue authorization call. */
58
+ /**
59
+ * Narrows an action requirement to a Blue authorization call.
60
+ *
61
+ * @param requirement - The requirement returned by `getRequirements()` to test.
62
+ * @returns `true` when the requirement is a call whose `action.type` is `"blueAuthorization"`.
63
+ * @example
64
+ * ```ts
65
+ * import { AccrualPosition } from "@morpho-org/blue-sdk";
66
+ * import { markets } from "@morpho-org/morpho-test";
67
+ * import { Time } from "@morpho-org/morpho-ts";
68
+ * import { createWalletClient, http, publicActions, zeroAddress } from "viem";
69
+ * import { mainnet } from "viem/chains";
70
+ * import {
71
+ * isRequirementBlueAuthorization,
72
+ * morphoViemExtension,
73
+ * } from "@morpho-org/morpho-sdk";
74
+ *
75
+ * const client = createWalletClient({
76
+ * chain: mainnet,
77
+ * transport: http(),
78
+ * account: zeroAddress,
79
+ * })
80
+ * .extend(publicActions)
81
+ * .extend(morphoViemExtension());
82
+ *
83
+ * const blue = client.morpho.blue(
84
+ * markets[mainnet.id].usdc_wbtc,
85
+ * mainnet.id,
86
+ * );
87
+ * const positionData = new AccrualPosition(
88
+ * { user: zeroAddress, supplyShares: 0n, borrowShares: 0n, collateral: 10n ** 8n },
89
+ * await blue.getMarketData(),
90
+ * );
91
+ * const handle = blue.borrow({
92
+ * userAddress: zeroAddress,
93
+ * borrowAssets: 1_000_000n,
94
+ * positionData,
95
+ * deadline: Time.timestamp() + 600n,
96
+ * });
97
+ *
98
+ * for (const requirement of await handle.getRequirements()) {
99
+ * if (!isRequirementBlueAuthorization(requirement)) continue;
100
+ *
101
+ * const hash = await client.sendTransaction(requirement);
102
+ * await client.waitForTransactionReceipt({ hash });
103
+ * }
104
+ * ```
105
+ */
15
106
  export function isRequirementBlueAuthorization(requirement) {
16
107
  return (typeof requirement === "object" &&
17
108
  requirement !== null &&
@@ -74,6 +165,16 @@ export function isPermit2SignatureTransferSignature(signature) {
74
165
  *
75
166
  * @param signature - The signed requirement to test.
76
167
  * @returns `true` when `signature.action.type` is `"authorization"`.
168
+ * @example
169
+ * ```ts
170
+ * import {
171
+ * isAuthorizationSignature,
172
+ * type RequirementSignature,
173
+ * } from "@morpho-org/morpho-sdk";
174
+ *
175
+ * const getAuthorizationNonce = (signature: RequirementSignature): bigint | undefined =>
176
+ * isAuthorizationSignature(signature) ? signature.args.nonce : undefined;
177
+ * ```
77
178
  */
78
179
  export function isAuthorizationSignature(signature) {
79
180
  return signature.action.type === "authorization";
@@ -1,4 +1,5 @@
1
1
  import { type MarketId, UnknownDataError } from "@morpho-org/blue-sdk";
2
+ import type { AddressLabel } from "@morpho-org/morpho-ts";
2
3
  import type { Address, Hash, Hex } from "viem";
3
4
  /**
4
5
  * Thrown when a morpho-sdk input that must be non-negative is negative.
@@ -583,6 +584,19 @@ export declare class ReferralFeePctExceededError extends InputExceedsMaxError {
583
584
  /** @param referralFeePct - WAD-scaled referral fee percentage supplied by the caller. */
584
585
  constructor(referralFeePct: bigint);
585
586
  }
587
+ /**
588
+ * Thrown when the SDK's 10% (`WAD / 10n`) Midnight referral-fee cap is exceeded;
589
+ * the contract itself only requires `referralFeePct < WAD`.
590
+ */
591
+ export declare class MidnightReferralFeePctExceededError extends InputExceedsMaxError {
592
+ readonly referralFeePct: bigint;
593
+ /**
594
+ * @param referralFeePct - WAD-scaled referral fee percentage supplied by the caller.
595
+ * The SDK cap is 10% (`WAD / 10n`); the contract itself only requires
596
+ * `referralFeePct < WAD`.
597
+ */
598
+ constructor(referralFeePct: bigint);
599
+ }
586
600
  /** Thrown when a fixed bundles call mixes ERC-20 and native funding. */
587
601
  export declare class MixedBundlesFundingError extends Error {
588
602
  constructor();
@@ -1112,13 +1126,128 @@ export declare class UnboundedMidnightTakeInputError extends Error {
1112
1126
  */
1113
1127
  constructor(field: "target.units" | "target.maxBuyerAssets" | "target.maxUnits" | "deadline");
1114
1128
  }
1115
- /** Thrown when a Midnight taker flow uses a zero address as its receiver. */
1129
+ /**
1130
+ * Thrown when none of a Midnight take's offers can fill and the flow has no other source of units,
1131
+ * so `MidnightBundlesV2` would revert with `OutOfOffers()`, or when every offer would abort the
1132
+ * bundle before its take (`Panic(0x12)`, `PriceGreaterThanOne()` or an underflow), whatever the
1133
+ * fallback.
1134
+ */
1135
+ export declare class MidnightTakeableOffersNotFillableError extends Error {
1136
+ /** Every supplied offer with the reason it cannot fill. */
1137
+ readonly offers: readonly {
1138
+ /** Offer index in the supplied `takeableOffers`. */
1139
+ readonly index: number;
1140
+ /** Why the offer cannot fill. */
1141
+ readonly reason: "expired" | "notStarted" | "selfTake" | "continuousFeeCapBelowMarketFee" | "zeroUnits" | "receiverIfMakerIsSellerNotZero" | "marketMatured" | "zeroBuyerPrice" | "buyerPriceAboveOne" | "priceBelowSettlementFee" | "tickOutOfRange";
1142
+ }[];
1143
+ /**
1144
+ * @param offers - Every supplied offer with the reason it cannot fill.
1145
+ */
1146
+ constructor(offers: MidnightTakeableOffersNotFillableError["offers"]);
1147
+ }
1148
+ /**
1149
+ * Thrown when a Midnight take target can never be met, so `MidnightBundlesV2` would revert
1150
+ * (`OutOfOffers()`, `SellerAssetsTooLow()`, `UnitsTooHigh()` or a loan-token transfer error).
1151
+ */
1152
+ export declare class MidnightTakeTargetUnreachableError extends Error {
1153
+ /** Target bound that cannot be met, or `takeableOffers` when the offers lack capacity. */
1154
+ readonly field: "target.minSellerAssets" | "target.maxUnits" | "target.maxBuyerAssets" | "repay.maxBuyerAssets" | "takeableOffers";
1155
+ /** Supplied bound, or the fillable units for `takeableOffers`. */
1156
+ readonly value: bigint;
1157
+ /** Bound the target needs. */
1158
+ readonly limit: bigint;
1159
+ /**
1160
+ * @param params - Unreachable bound, supplied value and required limit.
1161
+ * @param params.field - Target bound that cannot be met, or `takeableOffers`.
1162
+ * @param params.value - Supplied bound, or the fillable units for `takeableOffers`.
1163
+ * @param params.limit - Bound the target needs.
1164
+ */
1165
+ constructor(params: {
1166
+ readonly field: MidnightTakeTargetUnreachableError["field"];
1167
+ readonly value: bigint;
1168
+ readonly limit: bigint;
1169
+ });
1170
+ }
1171
+ /**
1172
+ * Thrown when a Midnight buy's `maxContinuousFee` is below the market's continuous fee, so
1173
+ * `MidnightBundlesV2` would revert with `ContinuousFeeAboveMax()`.
1174
+ */
1175
+ export declare class MidnightContinuousFeeAboveMaxError extends Error {
1176
+ /** Largest continuous fee the caller accepts. */
1177
+ readonly maxContinuousFee: bigint;
1178
+ /** Market continuous fee from the market snapshot. */
1179
+ readonly continuousFee: bigint;
1180
+ /**
1181
+ * @param params - Caller cap and market fee.
1182
+ * @param params.maxContinuousFee - Largest continuous fee the caller accepts.
1183
+ * @param params.continuousFee - Market continuous fee from the market snapshot.
1184
+ */
1185
+ constructor(params: {
1186
+ readonly maxContinuousFee: bigint;
1187
+ readonly continuousFee: bigint;
1188
+ });
1189
+ }
1190
+ /**
1191
+ * Thrown when a Midnight reduce-only repay targets more than the position's debt, so
1192
+ * `MidnightBundlesV2` would revert with `NotReduceOnly()` or `OutOfOffers()`.
1193
+ */
1194
+ export declare class MidnightRepayExceedsDebtError extends Error {
1195
+ /** Repay input that exceeds the debt. */
1196
+ readonly field: "target.units" | "target.minUnits" | "target.assets" | "repay.assets";
1197
+ /** Supplied repay amount; for `target.assets`, net of the referral fee. */
1198
+ readonly value: bigint;
1199
+ /** Debt from the position snapshot. */
1200
+ readonly debt: bigint;
1201
+ /**
1202
+ * @param params - Repay input, amount and debt.
1203
+ * @param params.field - Repay input that exceeds the debt.
1204
+ * @param params.value - Supplied repay amount; for `target.assets`, net of the referral fee.
1205
+ * @param params.debt - Debt from the position snapshot.
1206
+ */
1207
+ constructor(params: {
1208
+ readonly field: "target.units" | "target.minUnits" | "target.assets" | "repay.assets";
1209
+ readonly value: bigint;
1210
+ readonly debt: bigint;
1211
+ });
1212
+ }
1213
+ /**
1214
+ * Thrown when a Midnight flow uses a zero receiver or a zero collateral receiver with withdrawals.
1215
+ */
1116
1216
  export declare class MidnightZeroReceiverError extends Error {
1117
- readonly field: "receiver";
1217
+ readonly field: "receiver" | "collateralReceiver";
1218
+ /**
1219
+ * @param field - Receiver field or collateral receiver field containing the zero address.
1220
+ */
1221
+ constructor(field: "receiver" | "collateralReceiver");
1222
+ }
1223
+ /**
1224
+ * Thrown when a Midnight receiver is a Midnight protocol or market token contract that cannot
1225
+ * forward received assets.
1226
+ */
1227
+ export declare class MidnightContractReceiverError extends Error {
1228
+ /** Receiver field supplied with the contract address. */
1229
+ readonly field: "receiver" | "collateralReceiver" | "referralFeeRecipient";
1230
+ /** Contract address supplied as the receiver. */
1231
+ readonly receiver: Address;
1232
+ /** Midnight registry key (`"midnight"`, `"midnightBundlesV2"`,
1233
+ * `"midnightBlueBuyCallbackFactory"`, `"midnightMempool"`, `"ecrecoverRatifier"`,
1234
+ * `"ecrecoverAuthorizer"`, `"setterRatifier"`, `"priceRatifierV1"`,
1235
+ * `"rateRatifierV1"`) or market token label (`"loanToken"`, `"collateralToken[i]"`)
1236
+ * identifying the matched contract. */
1237
+ readonly contract: "midnight" | "midnightBundlesV2" | "midnightBlueBuyCallbackFactory" | "midnightMempool" | "ecrecoverRatifier" | "ecrecoverAuthorizer" | "setterRatifier" | "priceRatifierV1" | "rateRatifierV1" | "loanToken" | `collateralToken[${number}]`;
1118
1238
  /**
1119
- * @param field - Receiver field containing the zero address.
1239
+ * @param params - Matched receiver field, contract address, and contract label.
1240
+ * @param params.field - Receiver field supplied with the contract address.
1241
+ * @param params.receiver - Contract address supplied as the receiver.
1242
+ * @param params.contract - Midnight registry key (for example `"midnightBundlesV2"`) or
1243
+ * market token label (`"loanToken"`, `"collateralToken[i]"`) identifying the matched
1244
+ * contract.
1120
1245
  */
1121
- constructor(field: "receiver");
1246
+ constructor(params: {
1247
+ readonly field: "receiver" | "collateralReceiver" | "referralFeeRecipient";
1248
+ readonly receiver: Address;
1249
+ readonly contract: "midnight" | "midnightBundlesV2" | "midnightBlueBuyCallbackFactory" | "midnightMempool" | "ecrecoverRatifier" | "ecrecoverAuthorizer" | "setterRatifier" | "priceRatifierV1" | "rateRatifierV1" | "loanToken" | `collateralToken[${number}]`;
1250
+ });
1122
1251
  }
1123
1252
  /** Thrown when a Midnight take deadline is more than one hour from the current time. */
1124
1253
  export declare class MidnightTakeDeadlineTooFarError extends Error {
@@ -1238,6 +1367,37 @@ export declare class InsufficientMidnightWithdrawableLiquidityError extends Erro
1238
1367
  withdrawable: bigint;
1239
1368
  });
1240
1369
  }
1370
+ /**
1371
+ * Thrown when a Midnight root, publication or cancellation group, Blue callback salt,
1372
+ * root-signature `r`/`s`, or payload is not valid bounded hex input.
1373
+ */
1374
+ export declare class InvalidMidnightHexInputError extends Error {
1375
+ /**
1376
+ * @param params - Invalid hex field details.
1377
+ * @param params.field - Midnight input field containing the invalid value.
1378
+ * @param params.value - Supplied hex value.
1379
+ * @param params.reason - Why the supplied value is invalid.
1380
+ */
1381
+ constructor(params: {
1382
+ readonly field: string;
1383
+ readonly value: string;
1384
+ readonly reason: "notHex" | "oddLength" | "wrongSize" | "tooLong";
1385
+ });
1386
+ /** Midnight input field containing the invalid value. */
1387
+ readonly field: string;
1388
+ /** Supplied hex value. */
1389
+ readonly value: string;
1390
+ /** Why the supplied value is invalid. */
1391
+ readonly reason: "notHex" | "oddLength" | "wrongSize" | "tooLong";
1392
+ }
1393
+ /** Thrown when a Midnight entity account is malformed or the zero address. */
1394
+ export declare class MidnightInvalidAccountAddressError extends Error {
1395
+ readonly value: string;
1396
+ /**
1397
+ * @param value - Account address supplied by the caller.
1398
+ */
1399
+ constructor(value: string);
1400
+ }
1241
1401
  /** Thrown when a loan-asset withdraw specifies both `assets` and `shares` as non-zero (modes are mutually exclusive). */
1242
1402
  export declare class MutuallyExclusiveWithdrawAmountsError extends Error {
1243
1403
  constructor(market: string);
@@ -1295,3 +1455,36 @@ export declare class MidnightOfferNotReduceOnlyError extends Error {
1295
1455
  readonly index: number;
1296
1456
  });
1297
1457
  }
1458
+ /**
1459
+ * Thrown when a configured registry address holds no contract code.
1460
+ *
1461
+ * A call to a code-less address succeeds on-chain as a no-op, so entity
1462
+ * `getRequirements()` checks each registry target with one `eth_getCode`
1463
+ * before returning requirements. Use {@link MissingContractCodeError.address}
1464
+ * and {@link MissingContractCodeError.role} to find the misconfigured registry
1465
+ * entry.
1466
+ *
1467
+ * @example
1468
+ * ```ts
1469
+ * import { MissingContractCodeError } from "@morpho-org/morpho-sdk";
1470
+ *
1471
+ * try {
1472
+ * await deposit.getRequirements();
1473
+ * } catch (error) {
1474
+ * if (error instanceof MissingContractCodeError) {
1475
+ * console.error(error.address, error.chainId, error.role);
1476
+ * }
1477
+ * }
1478
+ * ```
1479
+ */
1480
+ export declare class MissingContractCodeError extends Error {
1481
+ readonly address: Address;
1482
+ readonly chainId: number;
1483
+ readonly role: AddressLabel;
1484
+ /**
1485
+ * @param address - Registry-configured address without deployed code.
1486
+ * @param chainId - Chain id the flow targets.
1487
+ * @param role - Registry label naming the address's role in the flow.
1488
+ */
1489
+ constructor(address: Address, chainId: number, role: AddressLabel);
1490
+ }