@morpho-org/morpho-sdk 10.5.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 (192) hide show
  1. package/README.md +44 -1
  2. package/lib/cjs/abis.d.ts +794 -1
  3. package/lib/cjs/abis.js +815 -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/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  16. package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
  17. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  18. package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
  19. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  20. package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
  21. package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
  22. package/lib/cjs/actions/requirements/blue/index.js +17 -0
  23. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  24. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
  25. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
  26. package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
  27. package/lib/cjs/addresses.d.ts +1 -1
  28. package/lib/cjs/addresses.js +6 -1
  29. package/lib/cjs/blue/abis.d.ts +1 -1
  30. package/lib/cjs/blue/abis.js +5 -1
  31. package/lib/cjs/blue/addresses.d.ts +1 -1
  32. package/lib/cjs/blue/addresses.js +6 -1
  33. package/lib/cjs/blue/entities.d.ts +4 -4
  34. package/lib/cjs/blue/entities.js +3 -1
  35. package/lib/cjs/blue/errors.d.ts +2 -2
  36. package/lib/cjs/blue/errors.js +5 -1
  37. package/lib/cjs/blue/fetch.d.ts +2 -2
  38. package/lib/cjs/blue/fetch.js +3 -1
  39. package/lib/cjs/blue/utils.d.ts +1 -1
  40. package/lib/cjs/blue/utils.js +2 -1
  41. package/lib/cjs/constants.d.ts +1 -1
  42. package/lib/cjs/constants.js +6 -2
  43. package/lib/cjs/entities/blue/blue.d.ts +486 -2
  44. package/lib/cjs/entities/blue/blue.js +529 -34
  45. package/lib/cjs/entities/index.d.ts +5 -5
  46. package/lib/cjs/entities/index.js +3 -1
  47. package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
  48. package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
  53. package/lib/cjs/errors.d.ts +4 -4
  54. package/lib/cjs/errors.js +7 -5
  55. package/lib/cjs/fetch.d.ts +2 -2
  56. package/lib/cjs/fetch.js +3 -1
  57. package/lib/cjs/helpers/constant.d.ts +34 -0
  58. package/lib/cjs/helpers/constant.js +35 -1
  59. package/lib/cjs/helpers/deadShares.js +3 -0
  60. package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
  61. package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
  62. package/lib/cjs/helpers/index.d.ts +4 -1
  63. package/lib/cjs/helpers/index.js +28 -1
  64. package/lib/cjs/helpers/leverage/index.d.ts +1 -0
  65. package/lib/cjs/helpers/leverage/index.js +11 -0
  66. package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
  67. package/lib/cjs/helpers/leverage/limits.js +715 -0
  68. package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
  69. package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
  70. package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
  71. package/lib/cjs/helpers/leverage/reallocations.js +276 -0
  72. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  73. package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
  74. package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
  75. package/lib/cjs/helpers/zeroExQuote.js +763 -0
  76. package/lib/cjs/index.d.ts +1 -0
  77. package/lib/cjs/index.js +5 -2
  78. package/lib/cjs/midnight/errors.d.ts +2 -1
  79. package/lib/cjs/midnight/errors.js +5 -4
  80. package/lib/cjs/reads/assertContractCode.d.ts +25 -0
  81. package/lib/cjs/reads/assertContractCode.js +30 -0
  82. package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
  83. package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
  84. package/lib/cjs/types/action.d.ts +130 -1
  85. package/lib/cjs/types/error.d.ts +59 -0
  86. package/lib/cjs/types/error.js +82 -3
  87. package/lib/cjs/types/index.d.ts +2 -0
  88. package/lib/cjs/types/index.js +2 -0
  89. package/lib/cjs/types/leverageError.d.ts +1552 -0
  90. package/lib/cjs/types/leverageError.js +1711 -0
  91. package/lib/cjs/types/zeroEx.d.ts +171 -0
  92. package/lib/cjs/types/zeroEx.js +2 -0
  93. package/lib/cjs/utils.d.ts +2 -2
  94. package/lib/cjs/utils.js +4 -2
  95. package/lib/cjs/version.d.ts +1 -1
  96. package/lib/cjs/version.js +1 -1
  97. package/lib/esm/abis.d.ts +794 -1
  98. package/lib/esm/abis.js +810 -1
  99. package/lib/esm/actions/blue/close.d.ts +169 -0
  100. package/lib/esm/actions/blue/close.js +266 -0
  101. package/lib/esm/actions/blue/common.js +3 -3
  102. package/lib/esm/actions/blue/delever.d.ts +156 -0
  103. package/lib/esm/actions/blue/delever.js +219 -0
  104. package/lib/esm/actions/blue/index.d.ts +3 -0
  105. package/lib/esm/actions/blue/index.js +3 -0
  106. package/lib/esm/actions/blue/lever.d.ts +184 -0
  107. package/lib/esm/actions/blue/lever.js +268 -0
  108. package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
  109. package/lib/esm/actions/blue/leverageIntent.js +96 -0
  110. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
  111. package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
  112. package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
  113. package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
  114. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
  115. package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
  116. package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
  117. package/lib/esm/actions/requirements/blue/index.js +3 -0
  118. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
  119. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
  120. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
  121. package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
  122. package/lib/esm/addresses.d.ts +1 -1
  123. package/lib/esm/addresses.js +1 -1
  124. package/lib/esm/blue/abis.d.ts +1 -1
  125. package/lib/esm/blue/abis.js +1 -1
  126. package/lib/esm/blue/addresses.d.ts +1 -1
  127. package/lib/esm/blue/addresses.js +1 -1
  128. package/lib/esm/blue/entities.d.ts +4 -4
  129. package/lib/esm/blue/entities.js +2 -2
  130. package/lib/esm/blue/errors.d.ts +2 -2
  131. package/lib/esm/blue/errors.js +2 -2
  132. package/lib/esm/blue/fetch.d.ts +2 -2
  133. package/lib/esm/blue/fetch.js +2 -2
  134. package/lib/esm/blue/utils.d.ts +1 -1
  135. package/lib/esm/blue/utils.js +1 -1
  136. package/lib/esm/constants.d.ts +1 -1
  137. package/lib/esm/constants.js +1 -1
  138. package/lib/esm/entities/blue/blue.d.ts +486 -2
  139. package/lib/esm/entities/blue/blue.js +501 -6
  140. package/lib/esm/entities/index.d.ts +5 -5
  141. package/lib/esm/entities/index.js +2 -2
  142. package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
  143. package/lib/esm/entities/requirements/assertContractCode.js +1 -25
  144. package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
  145. package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
  146. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
  147. package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
  148. package/lib/esm/errors.d.ts +4 -4
  149. package/lib/esm/errors.js +4 -4
  150. package/lib/esm/fetch.d.ts +2 -2
  151. package/lib/esm/fetch.js +2 -2
  152. package/lib/esm/helpers/constant.d.ts +34 -0
  153. package/lib/esm/helpers/constant.js +34 -0
  154. package/lib/esm/helpers/deadShares.js +4 -1
  155. package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
  156. package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
  157. package/lib/esm/helpers/index.d.ts +4 -1
  158. package/lib/esm/helpers/index.js +4 -1
  159. package/lib/esm/helpers/leverage/index.d.ts +1 -0
  160. package/lib/esm/helpers/leverage/index.js +1 -0
  161. package/lib/esm/helpers/leverage/limits.d.ts +472 -0
  162. package/lib/esm/helpers/leverage/limits.js +705 -0
  163. package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
  164. package/lib/esm/helpers/leverage/positionMarket.js +24 -0
  165. package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
  166. package/lib/esm/helpers/leverage/reallocations.js +271 -0
  167. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  168. package/lib/esm/helpers/validateRequirementSpender.js +5 -1
  169. package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
  170. package/lib/esm/helpers/zeroExQuote.js +754 -0
  171. package/lib/esm/index.d.ts +1 -0
  172. package/lib/esm/index.js +1 -0
  173. package/lib/esm/midnight/errors.d.ts +2 -1
  174. package/lib/esm/midnight/errors.js +2 -1
  175. package/lib/esm/reads/assertContractCode.d.ts +25 -0
  176. package/lib/esm/reads/assertContractCode.js +26 -0
  177. package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
  178. package/lib/esm/reads/fetchZeroExQuote.js +326 -0
  179. package/lib/esm/types/action.d.ts +130 -1
  180. package/lib/esm/types/error.d.ts +59 -0
  181. package/lib/esm/types/error.js +76 -0
  182. package/lib/esm/types/index.d.ts +2 -0
  183. package/lib/esm/types/index.js +2 -0
  184. package/lib/esm/types/leverageError.d.ts +1552 -0
  185. package/lib/esm/types/leverageError.js +1660 -0
  186. package/lib/esm/types/zeroEx.d.ts +171 -0
  187. package/lib/esm/types/zeroEx.js +1 -0
  188. package/lib/esm/utils.d.ts +2 -2
  189. package/lib/esm/utils.js +2 -2
  190. package/lib/esm/version.d.ts +1 -1
  191. package/lib/esm/version.js +1 -1
  192. package/package.json +7 -7
@@ -0,0 +1,250 @@
1
+ import type { MarketParams } from "@morpho-org/blue-sdk";
2
+ import { type Address } from "viem";
3
+ import type { ValidatedZeroExSwap, ZeroExLeverageSwapKind, ZeroExQuote, ZeroExQuoteMode } from "../types/zeroEx.js";
4
+ /**
5
+ * Parts per million: the unit of the 0x `slippagePpm` parameter.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const ZERO_EX_SLIPPAGE_PPM = 1000000n;
10
+ /**
11
+ * Converts a WAD-scaled slippage to the whole parts per million 0x applies, rounded down as the
12
+ * `slippagePpm` request parameter carries it.
13
+ *
14
+ * @internal
15
+ * @param slippage - Caller slippage, WAD-scaled.
16
+ * @returns The slippage 0x applies, in parts per million.
17
+ * @example
18
+ * ```ts
19
+ * toZeroExSlippagePpm(5_000_000_000_000_000n); // 5_000n
20
+ * ```
21
+ */
22
+ export declare const toZeroExSlippagePpm: (slippage: bigint) => bigint;
23
+ /**
24
+ * Tokens and quote mode of the 0x swap a leverage action needs.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import type { ZeroExSwapRoute } from "@morpho-org/morpho-sdk";
29
+ *
30
+ * declare const route: ZeroExSwapRoute;
31
+ * console.log(route.mode, route.sellToken, route.buyToken);
32
+ * ```
33
+ */
34
+ export interface ZeroExSwapRoute {
35
+ /** Quote mode the action requires. */
36
+ readonly mode: ZeroExQuoteMode;
37
+ /** Token the bundle sells. */
38
+ readonly sellToken: Address;
39
+ /** Token the bundle buys. */
40
+ readonly buyToken: Address;
41
+ }
42
+ /**
43
+ * Returns the tokens and quote mode of the 0x swap a ZeroExLeverageBundlesV1 action needs on a market.
44
+ *
45
+ * Lever buys exactly the collateral with loan tokens (exact output). Delever and Close sell collateral for
46
+ * loan tokens: Delever sells an exact amount (exact input), while Close buys exactly the debt plus its
47
+ * buffer (exact output).
48
+ *
49
+ * @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L60
50
+ * @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L128
51
+ * @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L159-L161
52
+ * @param kind - Swap the action needs.
53
+ * @param marketParams - Market whose tokens the swap trades.
54
+ * @returns The quote mode and the sell and buy tokens.
55
+ * @throws {ZeroExUnknownSwapKindError} when `kind` is not one of the three leverage swap kinds.
56
+ * @example
57
+ * ```ts
58
+ * import { getZeroExSwapRoute } from "@morpho-org/morpho-sdk";
59
+ *
60
+ * declare const marketParams: { loanToken: `0x${string}`; collateralToken: `0x${string}` };
61
+ * const route = getZeroExSwapRoute("lever", marketParams);
62
+ * // { mode: "exactOutput", sellToken: marketParams.loanToken, buyToken: marketParams.collateralToken }
63
+ * ```
64
+ */
65
+ export declare function getZeroExSwapRoute(kind: ZeroExLeverageSwapKind, marketParams: Pick<MarketParams, "loanToken" | "collateralToken">): ZeroExSwapRoute;
66
+ /**
67
+ * Returns the ZeroExLeverageBundlesV1 address registered for a chain where AllowanceHolder sits at its Cancun
68
+ * address.
69
+ *
70
+ * @internal
71
+ * @param chainId - Chain of the action.
72
+ * @returns The leverage bundle address.
73
+ * @throws {LeverageUnsupportedChainError} when AllowanceHolder is not at its Cancun address on the chain, or no
74
+ * bundle is registered there, including a bundle registered as the zero address.
75
+ */
76
+ export declare function getZeroExLeverageBundle(chainId: number): Address;
77
+ /**
78
+ * Refuses an exact-output swap between the chain's native token and its wrapped-native token, which 0x does not
79
+ * support.
80
+ *
81
+ * @internal
82
+ * @param params - Swap details.
83
+ * @param params.chainId - Chain of the swap.
84
+ * @param params.mode - Quote mode.
85
+ * @param params.sellToken - Token the swap sells.
86
+ * @param params.buyToken - Token the swap buys.
87
+ * @throws {ZeroExExactOutputUnsupportedError} when the mode is exact output and the tokens are the native and
88
+ * the wrapped-native token, in either order.
89
+ */
90
+ export declare function validateZeroExExactOutputPair(params: {
91
+ readonly chainId: number;
92
+ readonly mode: ZeroExQuoteMode;
93
+ readonly sellToken: Address;
94
+ readonly buyToken: Address;
95
+ }): void;
96
+ /**
97
+ * Returns the transaction origin of a leverage action: `txOrigin` when given, else the user. Only the 0x request
98
+ * and its echo use it; the taker, recipient, position owner and authorization stay the bundle and the user.
99
+ *
100
+ * @internal
101
+ * @param txOrigin - Optional sender of the outer onchain transaction, such as a Safe's executing owner or an ERC-4337 bundler.
102
+ * @param userAddress - Account whose position the action changes.
103
+ * @returns The transaction origin.
104
+ * @throws {ZeroExInvalidTxOriginError} when `txOrigin` is given and is not a valid address.
105
+ */
106
+ export declare function resolveZeroExTxOrigin(txOrigin: Address | undefined, userAddress: Address): Address;
107
+ /**
108
+ * Validates a 0x quote for a ZeroExLeverageBundlesV1 action and returns it as a {@link ValidatedZeroExSwap}.
109
+ *
110
+ * The bundle runs `swapData` through AllowanceHolder unchecked and only measures its own balance changes
111
+ * (ZeroExLeverageBundlesV1.sol:385-408), so this is the SDK's check of the calldata. It is strict on the envelope:
112
+ * the quote's chain, mode and tokens, its taker and txOrigin, no native value, and a call to AllowanceHolder. Every
113
+ * calldata layer must decode, whichever leverage bundle takes the quote: a layer that does not refuses with
114
+ * `ZeroExQuoteUndecodableCalldataError`, and a decoded layer that does not match refuses the swap.
115
+ * - AllowanceHolder layer: the `exec` call's operator and target are the same Settler, pulling the sell token, at most
116
+ * the action's swap input cap and exactly the quote's sell amount (`maxSellAmount` for an exact output).
117
+ * - Settler layer: the `exec` data is Settler's taker-submitted `execute`, whose slippage pays the bundle in the buy
118
+ * token with a minimum output at least the quote's floor. Another recognized entry point (`executeWithPermit` or
119
+ * `executeMetaTxn`) refuses.
120
+ * - Settler actions: every action, and every action of every `SELECT` candidate down to three levels, is classed by
121
+ * its selector, and anything not classed refuses. AMM actions pass. A signed-order fill (`RFQ`, `RFQ_VIP`, `BEBOP`,
122
+ * any `METATXN_*`) refuses at any depth, since its maker's expiry can come before the leverage deadline. The permit
123
+ * action (`TRANSFER_FROM` and the `*_VIP` actions) may only be the first top-level action, where Settler runs it,
124
+ * and its deadline must equal `deadline`. `NATIVE_CHECK` and `ATTEST` may only be top-level, with a deadline of at
125
+ * least `deadline`. An opaque `BASIC` or `BASIC_PUSH` call refuses when any 32-byte word of its data reads as a
126
+ * time bound in the hour and day before `deadline`; one equal to `deadline` is how 0x writes router deadlines. The
127
+ * scan cannot tell a deadline from another value, so an ordinary amount in that window refuses too; a new quote
128
+ * clears it only when its calldata differs, so a fixed value such as the caller's amount needs another amount, a
129
+ * later retry or a no-swap exit. A
130
+ * `SELECT` that does not decode, or nests more than three levels deep, refuses.
131
+ * So every time bound the calldata shows reaches `deadline`, whichever sources 0x routes through; this is the
132
+ * backstop for a short-lived source 0x adds after `ZERO_EX_LEVERAGE_EXCLUDED_SOURCES`. A venue whose validity depends
133
+ * on an offchain keeper, with no time bound in the calldata, is kept out only by the sources `fetchZeroExQuote`
134
+ * excludes. In every case the bundle's onchain bounds (`spent <= maxIn`, `received >= minOut`)
135
+ * still bind what the swap does inside Settler. A slippage struct that is all zero, which 0x sends for some
136
+ * single-pool routes, is accepted: Settler then checks no output, and the bundle's `received >= minOut` check
137
+ * protects the swap. The leverage limits compare the swap's worst price with the market oracle: a Lever refuses past
138
+ * the bound, while a Delever or a Close only reports the deviation. Whether that Settler is 0x's official one, and
139
+ * whether 0x paused it, is not checked here; the bundle's bounds limit what the swap can lose.
140
+ *
141
+ * The quote's `chainId`, `taker` and `txOrigin` are also checked against the action's chain, the leverage
142
+ * bundle and the action's `txOrigin` (`userAddress` by default), but these are request-context checks: `fetchZeroExQuote` fills them from its own request,
143
+ * so they show what was asked for, not whom 0x built the calldata for. The quote's `blockNumber` is not checked
144
+ * either: a quote has no age limit here beyond the leverage deadline the builders sign. Pure and synchronous:
145
+ * builders call it again on every build.
146
+ *
147
+ * @param params - Validation parameters.
148
+ * @param params.quote - Quote returned by `fetchZeroExQuote`.
149
+ * @param params.kind - Swap the action needs.
150
+ * @param params.chainId - Chain of the action.
151
+ * @param params.marketParams - Market of the action.
152
+ * @param params.userAddress - Account whose position the action changes (`msg.sender`).
153
+ * @param params.txOrigin - Transaction origin the quote must have been requested for, when it differs from the user,
154
+ * such as a Safe's executing owner or an ERC-4337 bundler sending the outer transaction. Defaults to `userAddress`.
155
+ * @param params.maxSwapInput - Largest amount of the sell token the action lets the swap spend: the swap input
156
+ * cap the transaction enforces: `maxIn` of the bundle's swap, as the builder signs it. When that cap comes from
157
+ * the quote, such as an exact-output quote's `maxSellAmount`, validation only proves that the calldata stays within
158
+ * the signed limit; deciding whether the quoted price is acceptable stays with the caller.
159
+ * @param params.deadline - Deadline the action signs, in seconds: for the leverage builders, the leverage data's
160
+ * block timestamp plus one hour. Fetch the quote with the same `deadline`: the permit must carry it, and every other
161
+ * time bound the Settler actions show must reach it.
162
+ * @returns The quote with its swap calldata, its Settler, its swap input and its Settler minimum output.
163
+ * @throws {LeverageUnsupportedChainError} when the chain has no AllowanceHolder at its Cancun address or no
164
+ * registered leverage bundle.
165
+ * @throws {ZeroExQuoteChainMismatchError} when the quote is for another chain.
166
+ * @throws {ZeroExQuoteTypeMismatchError} when the quote mode is not the one the action requires.
167
+ * @throws {ZeroExQuoteTokenMismatchError} when the quote, the AllowanceHolder token or Settler's buy token is
168
+ * not the action's sell or buy token.
169
+ * @throws {ZeroExExactOutputUnsupportedError} when an exact-output action swaps a native and wrapped-native pair.
170
+ * @throws {ZeroExQuoteTakerMismatchError} when the quote's taker is not the leverage bundle.
171
+ * @throws {ZeroExQuoteTxOriginMismatchError} when the quote's txOrigin is not `txOrigin`, or the user by default.
172
+ * @throws {ZeroExInvalidTxOriginError} when `txOrigin` is given and is not a valid address.
173
+ * @throws {ZeroExQuoteNonZeroValueError} when the quote sends native value.
174
+ * @throws {ZeroExQuoteTargetMismatchError} when the quote does not call AllowanceHolder.
175
+ * @throws {ZeroExUnknownSwapKindError} when `kind` is not one of the three leverage swap kinds.
176
+ * @throws {InvalidBigIntInputError} when `maxSwapInput`, the quote's `buyAmount`, its floor (`minBuyAmount` for an
177
+ * exact input, `buyAmount` for an exact output) or its sell amount (`sellAmount` for an exact input, `maxSellAmount` for an
178
+ * exact output) is missing or not a bigint, before any calldata is decoded.
179
+ * @throws {NonPositiveInputError} when `maxSwapInput` is not positive.
180
+ * @throws {InputExceedsMaxError} when `maxSwapInput` exceeds `uint256`.
181
+ * @throws {InvalidBigIntInputError} when `deadline` is missing or not a bigint.
182
+ * @throws {NonPositiveInputError} when `deadline` is not positive.
183
+ * @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
184
+ * @throws {ZeroExSettlerOperatorTargetMismatchError} when the AllowanceHolder target is not the operator.
185
+ * @throws {ZeroExQuoteAmountExceedsCapError} when AllowanceHolder may pull more than `maxSwapInput`.
186
+ * @throws {ZeroExQuoteSellAmountMismatchError} when AllowanceHolder pulls another amount than the quote's sell
187
+ * amount.
188
+ * @throws {ZeroExQuoteMalformedCalldataError} when the Settler layer decodes as an entry point other than `execute`,
189
+ * a permit, `NATIVE_CHECK` or `ATTEST` action is too short to hold its deadline, a `BASIC` or `BASIC_PUSH` action
190
+ * does not decode, or a `SELECT` action does not decode or nests deeper than three levels.
191
+ * @throws {ZeroExQuoteUndecodableCalldataError} when the AllowanceHolder or Settler layer does not decode.
192
+ * @throws {ZeroExQuoteSignedOrderActionError} when a Settler action, or one in a `SELECT` candidate, fills a signed
193
+ * order (`RFQ`, `RFQ_VIP`, `BEBOP` or any `METATXN_*` action).
194
+ * @throws {ZeroExQuoteUnsupportedActionError} when a Settler action is not one the SDK classes, or stands where it may
195
+ * not: a permit action other than the first top-level one, or a `NATIVE_CHECK` or `ATTEST` in a `SELECT` candidate.
196
+ * @throws {ZeroExQuoteShortTimeBoundError} when a `BASIC` or `BASIC_PUSH` call holds a word that looks like a deadline
197
+ * before `deadline`.
198
+ * @throws {ZeroExQuoteDeadlineMismatchError} when the permit deadline is not `deadline`, or a `NATIVE_CHECK` or
199
+ * `ATTEST` deadline is below it.
200
+ * @throws {ZeroExQuoteRecipientMismatchError} when the Settler slippage pays anyone but the leverage bundle.
201
+ * @throws {ZeroExQuoteMinAmountOutMismatchError} when the Settler slippage's minimum output is zero or below the
202
+ * quote's floor (`minBuyAmount` for an exact input, `buyAmount` for an exact output).
203
+ * @example
204
+ * ```ts
205
+ * import { fetchZeroExQuote, validateZeroExQuote } from "@morpho-org/morpho-sdk";
206
+ * import { isBlueZeroExLeverageChain } from "@morpho-org/morpho-sdk/addresses";
207
+ *
208
+ * declare const marketParams: { loanToken: `0x${string}`; collateralToken: `0x${string}` };
209
+ * declare const userAddress: `0x${string}`;
210
+ * // Swap input cap the transaction enforces: the bundle's `maxIn`, as the builder signs it. The leverage builders
211
+ * // derive it from the action's limits (a Lever's `maxSwapIn`, a Delever's `maxCollateralToSell`, a Close's
212
+ * // `maxCollateralIn`); a direct caller must bound it on its own, not copy it from the quote.
213
+ * declare const maxSwapInput: bigint;
214
+ * // Deadline the action signs, in seconds: the leverage builders sign the leverage data's block timestamp plus one hour.
215
+ * declare const deadline: bigint;
216
+ *
217
+ * // Leverage needs a ZeroExLeverageBundlesV1 registered on the chain. None ships yet: register a verified
218
+ * // address with `registerCustomAddresses` first, or the call throws LeverageUnsupportedChainError before any request.
219
+ * if (!isBlueZeroExLeverageChain(8453)) throw new Error("No leverage bundle is registered on Base yet.");
220
+ * const quote = await fetchZeroExQuote({
221
+ * chainId: 8453,
222
+ * kind: "lever",
223
+ * marketParams,
224
+ * userAddress,
225
+ * amount: 10n ** 18n,
226
+ * slippage: 5_000_000_000_000_000n,
227
+ * deadline,
228
+ * apiKey: process.env.ZEROEX_API_KEY!,
229
+ * });
230
+ * const swap = validateZeroExQuote({
231
+ * quote,
232
+ * kind: "lever",
233
+ * chainId: 8453,
234
+ * marketParams,
235
+ * userAddress,
236
+ * maxSwapInput,
237
+ * deadline,
238
+ * });
239
+ * ```
240
+ */
241
+ export declare function validateZeroExQuote(params: {
242
+ readonly quote: ZeroExQuote;
243
+ readonly kind: ZeroExLeverageSwapKind;
244
+ readonly chainId: number;
245
+ readonly marketParams: Pick<MarketParams, "loanToken" | "collateralToken">;
246
+ readonly userAddress: Address;
247
+ readonly txOrigin?: Address;
248
+ readonly maxSwapInput: bigint;
249
+ readonly deadline: bigint;
250
+ }): ValidatedZeroExSwap;