@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
@@ -0,0 +1,17 @@
1
+ import type { AccrualPosition, MarketParams } from "@morpho-org/blue-sdk";
2
+ /**
3
+ * Refuses leverage data whose position carries another market's tuple: the leverage bounds, LTV and oracle price
4
+ * come from `position.market`, so it must hash to its cached id and be the expected market. Callers check the
5
+ * position's own `marketId` separately.
6
+ *
7
+ * @internal
8
+ * @param position - Position of the one-block leverage data.
9
+ * @param marketParams - Market the action is built for.
10
+ * @throws {MarketIdMismatchError} when the position's market tuple does not hash to its cached id or is another
11
+ * market than `marketParams`.
12
+ * @example
13
+ * ```ts
14
+ * validateLeveragePositionMarket(leverageData.position, marketParams);
15
+ * ```
16
+ */
17
+ export declare const validateLeveragePositionMarket: (position: AccrualPosition, marketParams: MarketParams) => void;
@@ -0,0 +1,24 @@
1
+ import { MarketIdMismatchError } from "../../types/index.js";
2
+ import { validateMarketParamsId } from "../validate.js";
3
+ /**
4
+ * Refuses leverage data whose position carries another market's tuple: the leverage bounds, LTV and oracle price
5
+ * come from `position.market`, so it must hash to its cached id and be the expected market. Callers check the
6
+ * position's own `marketId` separately.
7
+ *
8
+ * @internal
9
+ * @param position - Position of the one-block leverage data.
10
+ * @param marketParams - Market the action is built for.
11
+ * @throws {MarketIdMismatchError} when the position's market tuple does not hash to its cached id or is another
12
+ * market than `marketParams`.
13
+ * @example
14
+ * ```ts
15
+ * validateLeveragePositionMarket(leverageData.position, marketParams);
16
+ * ```
17
+ */
18
+ export const validateLeveragePositionMarket = (position, marketParams) => {
19
+ const positionMarketParams = position.market.params;
20
+ validateMarketParamsId(positionMarketParams);
21
+ if (positionMarketParams.id !== marketParams.id) {
22
+ throw new MarketIdMismatchError(positionMarketParams.id, marketParams.id);
23
+ }
24
+ };
@@ -0,0 +1,159 @@
1
+ import { type InputMarketParams, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Hash } from "viem";
3
+ /**
4
+ * One public-allocator call of a ZeroExLeverageBundlesV1 Lever, with the fields the leverage guard
5
+ * reads. It matches the bundle's `PublicAllocations` struct, so the encoded allocations pass as is.
6
+ */
7
+ export interface LeverageReallocation {
8
+ /** Vault V2 whose liquidity is moved. */
9
+ readonly vault: Address;
10
+ /** Vault V2 MorphoMarketV1AdapterV2 supplying the target market. */
11
+ readonly adapter: Address;
12
+ /** Target market, which must be the Lever's market. */
13
+ readonly marketParams: InputMarketParams;
14
+ /** Whether the liquidity comes from the vault's idle assets rather than a market. */
15
+ readonly fromIdle: boolean;
16
+ /** Adapter supplying the source market; ignored when `fromIdle`. */
17
+ readonly sourceAdapter: Address;
18
+ /** Source market; ignored when `fromIdle`. */
19
+ readonly sourceMarketParams: InputMarketParams;
20
+ /** Loan-token assets moved into the target market. */
21
+ readonly assets: bigint;
22
+ /** Vault penalty rate passed to the allocator, WAD-scaled. */
23
+ readonly penalty: bigint;
24
+ }
25
+ /**
26
+ * BluePublicAllocator state the leverage guard reads, indexed by vault address (any casing): each
27
+ * vault's allocator configuration (absent when the vault does not authorize the allocator), its
28
+ * active adapters, and each adapter-market configuration keyed by its `adapterMarketCapId`.
29
+ * `VaultV2BlueReallocationData` matches this shape.
30
+ */
31
+ export interface LeverageAllocatorState {
32
+ /** Vault-wide allocator configuration, per vault; absent when the allocator is not authorized. */
33
+ readonly publicAllocatorConfigs: Readonly<Record<Address, Pick<IVaultV2BluePublicAllocatorConfig, "canPullFromIdle" | "penalty"> | undefined>>;
34
+ /** Adapters active for the allocator, per vault. */
35
+ readonly activeAdapters: Readonly<Record<Address, ReadonlySet<Address> | undefined>>;
36
+ /** Adapter-market allocator configurations, per vault and `adapterMarketCapId`. */
37
+ readonly marketPublicAllocatorConfigs: Readonly<Record<Address, Readonly<Record<Hash, Pick<IVaultV2BlueMarketPublicAllocatorConfig, "vault" | "adapter" | "absoluteCap" | "canPullFromMarket"> | undefined>> | undefined>>;
38
+ }
39
+ /**
40
+ * Computes the `penaltyAssets` a ZeroExLeverageBundlesV1 Lever must sign: each reallocation's
41
+ * `assets × penalty / WAD` rounded up on its own, then summed, exactly as the bundle's
42
+ * `totalPenaltyAssets` and the public allocator charge it. Rounding the sum once instead can be
43
+ * lower and makes the Lever revert. BlueBundlesV1 charges its public-allocator reallocations the same
44
+ * way, so its penalty sum calls this function too and signing and funding checks use one amount.
45
+ *
46
+ * @param reallocations - Reallocations of the Lever, in any order.
47
+ * @returns Total penalty in loan-token assets; zero without reallocations.
48
+ * @example
49
+ * ```ts
50
+ * import { computeLeveragePenaltyAssets } from "@morpho-org/morpho-sdk";
51
+ *
52
+ * const penaltyAssets = computeLeveragePenaltyAssets([
53
+ * { assets: 1n, penalty: 5_000_000_000_000_000n },
54
+ * { assets: 1n, penalty: 5_000_000_000_000_000n },
55
+ * ]);
56
+ * // penaltyAssets === 2n
57
+ * ```
58
+ */
59
+ export declare const computeLeveragePenaltyAssets: (reallocations: readonly Pick<LeverageReallocation, "assets" | "penalty">[]) => bigint;
60
+ /**
61
+ * Refuses a Lever's public-allocator reallocations unless each one targets exactly the Lever's
62
+ * market, carries the vault's configured penalty rate and at most
63
+ * {@link LEVERAGE_MAX_REALLOCATION_PENALTY}, and follows a route the vault's BluePublicAllocator
64
+ * allows at the data block: the vault authorizes the allocator, the target adapter is active
65
+ * with a positive cap into the market, and the source is either idle the allocator may pull, or
66
+ * another market with the same loan token whose active adapter the allocator may pull from.
67
+ * Together the reallocations must move no more than `maxBorrowAssets`. That sum counts the moved assets only: the
68
+ * penalties and the 0x swap are already inside `maxBorrowAssets` (`maxSwapIn + penaltyAssets − loanAssets`), and the
69
+ * contract pays each penalty out of the borrow. ZeroExLeverageBundlesV1 checks only each target's loan token and pays every
70
+ * penalty asked, so a reallocation into another market with the same loan token would still charge
71
+ * the user. The guard checks that the allocator's own state enables a route, not that the route can execute:
72
+ * adapter compatibility (the market's IRM must be the adapter's `adaptiveCurveIrm`), remaining cap and
73
+ * source liquidity are the planner's (`VaultV2BlueReallocationData`), so pass only reallocations it
74
+ * built; one that fails them reverts onchain without charging anything. The allocator charges only the vault's
75
+ * current penalty rate, so a vault that changes its penalty after the data block makes the Lever revert rather than
76
+ * overcharge. The integrator, such as the front end, supplies and curates the vaults the reallocations come
77
+ * from, and the SDK keeps no vault allowlist: the guard checks each vault's own allocator state, not whether the
78
+ * vault is one to trust. Pure: reads nothing on chain.
79
+ *
80
+ * @param params - Guard inputs.
81
+ * @param params.reallocations - Reallocations the Lever will sign.
82
+ * @param params.marketParams - The Lever's market.
83
+ * @param params.allocator - BluePublicAllocator state at the data block, indexed by vault: the
84
+ * vault configurations, active adapters and adapter-market configurations keyed by
85
+ * `adapterMarketCapId`. The guard trusts it as given, so pass the onchain state read at the data block, the
86
+ * snapshot `market.getVaultV2BlueReallocationData(...)` returns, never a hand-built one: a route that state
87
+ * wrongly allows is not caught here and reverts onchain or charges the vault's real penalty.
88
+ * @param params.maxBorrowAssets - The Lever's signed borrow cap.
89
+ * @returns Nothing; it throws on the first unsafe reallocation.
90
+ * @throws {LeverageReallocationMarketMismatchError} When a reallocation targets another market.
91
+ * @throws {LeverageReallocationPenaltyAboveLimitError} When a penalty rate exceeds 1%.
92
+ * @throws {InconsistentReallocationPenaltyError} When a penalty rate differs from the vault's configured one.
93
+ * @throws {ReallocationLoanTokenMismatchError} When a source market has another loan token.
94
+ * @throws {ReallocationWithdrawalOnTargetMarketError} When a reallocation pulls from the Lever's own market.
95
+ * @throws {LeverageReallocationNoFlowError} When the allocator cannot move liquidity along the route.
96
+ * @throws {LeverageReallocationExceedsBorrowError} When the reallocations move more than `maxBorrowAssets`, so any
97
+ * reallocation of a Lever that borrows nothing, which the bundle refuses with `InconsistentBorrowInput`.
98
+ * @throws {InvalidBigIntInputError} When `maxBorrowAssets`, a reallocation's assets or its penalty rate is missing or not
99
+ * a bigint.
100
+ * @throws {NonPositiveInputError} When a reallocation moves no assets.
101
+ * @throws {NegativeInputError} When a penalty rate is negative.
102
+ * @throws {NonBooleanInputError} When a reallocation's `fromIdle` is missing or not a boolean, with
103
+ * `field: "reallocation.fromIdle"`.
104
+ * @throws {InvalidBigIntInputError} When the lltv of `marketParams`, or of a reallocation's `marketParams` or
105
+ * `sourceMarketParams`, does not convert to a bigint, with `field` naming which.
106
+ * @throws {NegativeInputError} When such an lltv is negative, with `field` naming which.
107
+ * @throws {InputExceedsMaxError} When such an lltv exceeds `uint256`, with `field` naming which.
108
+ * A reallocation's target is checked before its market id is compared.
109
+ * @example
110
+ * ```ts
111
+ * import { validateLeverageReallocations } from "@morpho-org/morpho-sdk";
112
+ * import { VaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
113
+ * import { zeroAddress } from "viem";
114
+ *
115
+ * // `marketParams` is the Lever's market, `vault` a Vault V2 and `adapter` its MorphoMarketV1AdapterV2.
116
+ * const capId = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter, marketParams);
117
+ *
118
+ * const penalty = 1_000_000_000_000_000n;
119
+ *
120
+ * // The `allocator` object below only illustrates state that passes. Never build it by hand: the guard
121
+ * // trusts it as given, so read it at the planning block with `getVaultV2BlueReallocationData` and
122
+ * // validate legs from that snapshot.
123
+ *
124
+ * // Passes: the vault authorizes the allocator and may pull its idle assets, the adapter is active
125
+ * // with a positive cap into the market, the penalty is the vault's 0.1% and 1_000_000 assets stay
126
+ * // within the 2_000_000 borrow cap.
127
+ * validateLeverageReallocations({
128
+ * reallocations: [
129
+ * {
130
+ * vault,
131
+ * adapter,
132
+ * marketParams,
133
+ * fromIdle: true,
134
+ * sourceAdapter: zeroAddress,
135
+ * sourceMarketParams: marketParams,
136
+ * assets: 1_000_000n,
137
+ * penalty,
138
+ * },
139
+ * ],
140
+ * marketParams,
141
+ * allocator: {
142
+ * publicAllocatorConfigs: { [vault]: { canPullFromIdle: true, penalty } },
143
+ * activeAdapters: { [vault]: new Set([adapter]) },
144
+ * marketPublicAllocatorConfigs: {
145
+ * [vault]: {
146
+ * [capId]: { vault, adapter, absoluteCap: 10_000_000n, canPullFromMarket: false },
147
+ * },
148
+ * },
149
+ * },
150
+ * maxBorrowAssets: 2_000_000n,
151
+ * });
152
+ * ```
153
+ */
154
+ export declare const validateLeverageReallocations: ({ reallocations, marketParams, allocator, maxBorrowAssets, }: {
155
+ readonly reallocations: readonly LeverageReallocation[];
156
+ readonly marketParams: InputMarketParams;
157
+ readonly allocator: LeverageAllocatorState;
158
+ readonly maxBorrowAssets: bigint;
159
+ }) => void;
@@ -0,0 +1,271 @@
1
+ import { MarketUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MorphoMarketV1AdapterV2, } from "@morpho-org/blue-sdk";
2
+ import { isAddressEqual } from "viem";
3
+ import { InconsistentReallocationPenaltyError, InvalidBigIntInputError, LeverageReallocationExceedsBorrowError, LeverageReallocationMarketMismatchError, LeverageReallocationNoFlowError, LeverageReallocationPenaltyAboveLimitError, NegativeInputError, NonBooleanInputError, NonPositiveInputError, ReallocationLoanTokenMismatchError, ReallocationWithdrawalOnTargetMarketError, } from "../../types/index.js";
4
+ import { LEVERAGE_MAX_REALLOCATION_PENALTY } from "../constant.js";
5
+ import { validateUint256Field } from "../validate.js";
6
+ /**
7
+ * Computes the `penaltyAssets` a ZeroExLeverageBundlesV1 Lever must sign: each reallocation's
8
+ * `assets × penalty / WAD` rounded up on its own, then summed, exactly as the bundle's
9
+ * `totalPenaltyAssets` and the public allocator charge it. Rounding the sum once instead can be
10
+ * lower and makes the Lever revert. BlueBundlesV1 charges its public-allocator reallocations the same
11
+ * way, so its penalty sum calls this function too and signing and funding checks use one amount.
12
+ *
13
+ * @param reallocations - Reallocations of the Lever, in any order.
14
+ * @returns Total penalty in loan-token assets; zero without reallocations.
15
+ * @example
16
+ * ```ts
17
+ * import { computeLeveragePenaltyAssets } from "@morpho-org/morpho-sdk";
18
+ *
19
+ * const penaltyAssets = computeLeveragePenaltyAssets([
20
+ * { assets: 1n, penalty: 5_000_000_000_000_000n },
21
+ * { assets: 1n, penalty: 5_000_000_000_000_000n },
22
+ * ]);
23
+ * // penaltyAssets === 2n
24
+ * ```
25
+ */
26
+ export const computeLeveragePenaltyAssets = (reallocations) => reallocations.reduce((total, reallocation) => total +
27
+ VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets(reallocation, reallocation.assets), 0n);
28
+ /**
29
+ * Refuses a Lever's public-allocator reallocations unless each one targets exactly the Lever's
30
+ * market, carries the vault's configured penalty rate and at most
31
+ * {@link LEVERAGE_MAX_REALLOCATION_PENALTY}, and follows a route the vault's BluePublicAllocator
32
+ * allows at the data block: the vault authorizes the allocator, the target adapter is active
33
+ * with a positive cap into the market, and the source is either idle the allocator may pull, or
34
+ * another market with the same loan token whose active adapter the allocator may pull from.
35
+ * Together the reallocations must move no more than `maxBorrowAssets`. That sum counts the moved assets only: the
36
+ * penalties and the 0x swap are already inside `maxBorrowAssets` (`maxSwapIn + penaltyAssets − loanAssets`), and the
37
+ * contract pays each penalty out of the borrow. ZeroExLeverageBundlesV1 checks only each target's loan token and pays every
38
+ * penalty asked, so a reallocation into another market with the same loan token would still charge
39
+ * the user. The guard checks that the allocator's own state enables a route, not that the route can execute:
40
+ * adapter compatibility (the market's IRM must be the adapter's `adaptiveCurveIrm`), remaining cap and
41
+ * source liquidity are the planner's (`VaultV2BlueReallocationData`), so pass only reallocations it
42
+ * built; one that fails them reverts onchain without charging anything. The allocator charges only the vault's
43
+ * current penalty rate, so a vault that changes its penalty after the data block makes the Lever revert rather than
44
+ * overcharge. The integrator, such as the front end, supplies and curates the vaults the reallocations come
45
+ * from, and the SDK keeps no vault allowlist: the guard checks each vault's own allocator state, not whether the
46
+ * vault is one to trust. Pure: reads nothing on chain.
47
+ *
48
+ * @param params - Guard inputs.
49
+ * @param params.reallocations - Reallocations the Lever will sign.
50
+ * @param params.marketParams - The Lever's market.
51
+ * @param params.allocator - BluePublicAllocator state at the data block, indexed by vault: the
52
+ * vault configurations, active adapters and adapter-market configurations keyed by
53
+ * `adapterMarketCapId`. The guard trusts it as given, so pass the onchain state read at the data block, the
54
+ * snapshot `market.getVaultV2BlueReallocationData(...)` returns, never a hand-built one: a route that state
55
+ * wrongly allows is not caught here and reverts onchain or charges the vault's real penalty.
56
+ * @param params.maxBorrowAssets - The Lever's signed borrow cap.
57
+ * @returns Nothing; it throws on the first unsafe reallocation.
58
+ * @throws {LeverageReallocationMarketMismatchError} When a reallocation targets another market.
59
+ * @throws {LeverageReallocationPenaltyAboveLimitError} When a penalty rate exceeds 1%.
60
+ * @throws {InconsistentReallocationPenaltyError} When a penalty rate differs from the vault's configured one.
61
+ * @throws {ReallocationLoanTokenMismatchError} When a source market has another loan token.
62
+ * @throws {ReallocationWithdrawalOnTargetMarketError} When a reallocation pulls from the Lever's own market.
63
+ * @throws {LeverageReallocationNoFlowError} When the allocator cannot move liquidity along the route.
64
+ * @throws {LeverageReallocationExceedsBorrowError} When the reallocations move more than `maxBorrowAssets`, so any
65
+ * reallocation of a Lever that borrows nothing, which the bundle refuses with `InconsistentBorrowInput`.
66
+ * @throws {InvalidBigIntInputError} When `maxBorrowAssets`, a reallocation's assets or its penalty rate is missing or not
67
+ * a bigint.
68
+ * @throws {NonPositiveInputError} When a reallocation moves no assets.
69
+ * @throws {NegativeInputError} When a penalty rate is negative.
70
+ * @throws {NonBooleanInputError} When a reallocation's `fromIdle` is missing or not a boolean, with
71
+ * `field: "reallocation.fromIdle"`.
72
+ * @throws {InvalidBigIntInputError} When the lltv of `marketParams`, or of a reallocation's `marketParams` or
73
+ * `sourceMarketParams`, does not convert to a bigint, with `field` naming which.
74
+ * @throws {NegativeInputError} When such an lltv is negative, with `field` naming which.
75
+ * @throws {InputExceedsMaxError} When such an lltv exceeds `uint256`, with `field` naming which.
76
+ * A reallocation's target is checked before its market id is compared.
77
+ * @example
78
+ * ```ts
79
+ * import { validateLeverageReallocations } from "@morpho-org/morpho-sdk";
80
+ * import { VaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
81
+ * import { zeroAddress } from "viem";
82
+ *
83
+ * // `marketParams` is the Lever's market, `vault` a Vault V2 and `adapter` its MorphoMarketV1AdapterV2.
84
+ * const capId = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter, marketParams);
85
+ *
86
+ * const penalty = 1_000_000_000_000_000n;
87
+ *
88
+ * // The `allocator` object below only illustrates state that passes. Never build it by hand: the guard
89
+ * // trusts it as given, so read it at the planning block with `getVaultV2BlueReallocationData` and
90
+ * // validate legs from that snapshot.
91
+ *
92
+ * // Passes: the vault authorizes the allocator and may pull its idle assets, the adapter is active
93
+ * // with a positive cap into the market, the penalty is the vault's 0.1% and 1_000_000 assets stay
94
+ * // within the 2_000_000 borrow cap.
95
+ * validateLeverageReallocations({
96
+ * reallocations: [
97
+ * {
98
+ * vault,
99
+ * adapter,
100
+ * marketParams,
101
+ * fromIdle: true,
102
+ * sourceAdapter: zeroAddress,
103
+ * sourceMarketParams: marketParams,
104
+ * assets: 1_000_000n,
105
+ * penalty,
106
+ * },
107
+ * ],
108
+ * marketParams,
109
+ * allocator: {
110
+ * publicAllocatorConfigs: { [vault]: { canPullFromIdle: true, penalty } },
111
+ * activeAdapters: { [vault]: new Set([adapter]) },
112
+ * marketPublicAllocatorConfigs: {
113
+ * [vault]: {
114
+ * [capId]: { vault, adapter, absoluteCap: 10_000_000n, canPullFromMarket: false },
115
+ * },
116
+ * },
117
+ * },
118
+ * maxBorrowAssets: 2_000_000n,
119
+ * });
120
+ * ```
121
+ */
122
+ export const validateLeverageReallocations = ({ reallocations, marketParams, allocator, maxBorrowAssets, }) => {
123
+ // A JavaScript caller can omit the cap; refuse it before the aggregate check compares against it.
124
+ if (typeof maxBorrowAssets !== "bigint") {
125
+ throw new InvalidBigIntInputError("maxBorrowAssets", maxBorrowAssets);
126
+ }
127
+ const market = toMarketParams(marketParams, "marketParams");
128
+ let total = 0n;
129
+ for (const reallocation of reallocations) {
130
+ if (typeof reallocation.assets !== "bigint") {
131
+ throw new InvalidBigIntInputError("reallocation.assets", reallocation.assets);
132
+ }
133
+ if (reallocation.assets <= 0n) {
134
+ throw new NonPositiveInputError("reallocation.assets", reallocation.assets);
135
+ }
136
+ if (typeof reallocation.penalty !== "bigint") {
137
+ throw new InvalidBigIntInputError("reallocation.penalty", reallocation.penalty);
138
+ }
139
+ if (reallocation.penalty < 0n) {
140
+ throw new NegativeInputError("reallocation.penalty", reallocation.penalty);
141
+ }
142
+ // `fromIdle` selects the route to check: a truthy string or a missing field would check the wrong one.
143
+ if (typeof reallocation.fromIdle !== "boolean") {
144
+ throw new NonBooleanInputError("reallocation.fromIdle", reallocation.fromIdle);
145
+ }
146
+ const targetId = toMarketParams(reallocation.marketParams, "reallocation.marketParams").id;
147
+ if (targetId !== market.id) {
148
+ throw new LeverageReallocationMarketMismatchError({
149
+ vault: reallocation.vault,
150
+ expected: market.id,
151
+ actual: targetId,
152
+ });
153
+ }
154
+ if (reallocation.penalty > LEVERAGE_MAX_REALLOCATION_PENALTY) {
155
+ throw new LeverageReallocationPenaltyAboveLimitError({
156
+ vault: reallocation.vault,
157
+ penalty: reallocation.penalty,
158
+ max: LEVERAGE_MAX_REALLOCATION_PENALTY,
159
+ });
160
+ }
161
+ validateAllocatorRoute(allocator, { ...reallocation, market });
162
+ total += reallocation.assets;
163
+ }
164
+ if (total > maxBorrowAssets) {
165
+ throw new LeverageReallocationExceedsBorrowError({
166
+ total,
167
+ maxBorrowAssets,
168
+ });
169
+ }
170
+ };
171
+ /**
172
+ * Builds the market's params without the `MarketParams` constructor, which registers them globally:
173
+ * a validation helper must leave the registry as it found it, even for a market it refuses.
174
+ * @internal
175
+ */
176
+ const toMarketParams = (params, field) => {
177
+ let lltv;
178
+ try {
179
+ lltv = BigInt(params.lltv);
180
+ }
181
+ catch {
182
+ // A JavaScript caller can pass a fractional, non-numeric or missing LLTV, which BigInt rejects untyped.
183
+ throw new InvalidBigIntInputError(`${field}.lltv`, params.lltv);
184
+ }
185
+ // A negative or oversized LLTV converts, but the market id hash would reject it untyped or hash another market.
186
+ validateUint256Field(`${field}.lltv`, lltv);
187
+ return {
188
+ collateralToken: params.collateralToken,
189
+ loanToken: params.loanToken,
190
+ oracle: params.oracle,
191
+ irm: params.irm,
192
+ lltv,
193
+ id: MarketUtils.getMarketId(params),
194
+ liquidationIncentiveFactor: MarketUtils.getLiquidationIncentiveFactor(params),
195
+ };
196
+ };
197
+ /** Reads a vault-indexed record whatever the casing of its address keys. @internal */
198
+ const byAddress = (record, address) => {
199
+ const key = Object.keys(record).find((candidate) => isAddressEqual(candidate, address));
200
+ return key == null ? undefined : record[key];
201
+ };
202
+ /** Finds the adapter-market configuration of a vault whatever the casing of its keys. @internal */
203
+ const findMarketConfig = (allocator, { vault, adapter, marketParams, }) => {
204
+ const capId = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter, marketParams).toLowerCase();
205
+ const config = Object.entries(byAddress(allocator.marketPublicAllocatorConfigs, vault) ?? {}).find(([id]) => id.toLowerCase() === capId)?.[1];
206
+ if (config == null ||
207
+ !isAddressEqual(config.vault, vault) ||
208
+ !isAddressEqual(config.adapter, adapter)) {
209
+ return undefined;
210
+ }
211
+ return config;
212
+ };
213
+ /**
214
+ * Throws unless the vault's allocator can move liquidity along the reallocation's route.
215
+ * @internal
216
+ */
217
+ const validateAllocatorRoute = (allocator, reallocation) => {
218
+ const { vault, adapter, market } = reallocation;
219
+ const noFlow = new LeverageReallocationNoFlowError({
220
+ vault,
221
+ marketId: market.id,
222
+ });
223
+ const vaultConfig = byAddress(allocator.publicAllocatorConfigs, vault);
224
+ if (vaultConfig == null) {
225
+ throw noFlow;
226
+ }
227
+ if (reallocation.penalty !== vaultConfig.penalty) {
228
+ throw new InconsistentReallocationPenaltyError({
229
+ vault,
230
+ expected: vaultConfig.penalty,
231
+ actual: reallocation.penalty,
232
+ });
233
+ }
234
+ const active = byAddress(allocator.activeAdapters, vault);
235
+ const isActive = (candidate) => active != null &&
236
+ [...active].some((activeAdapter) => isAddressEqual(activeAdapter, candidate));
237
+ const target = findMarketConfig(allocator, {
238
+ vault,
239
+ adapter,
240
+ marketParams: market,
241
+ });
242
+ if (!isActive(adapter) ||
243
+ target == null ||
244
+ typeof target.absoluteCap !== "bigint" ||
245
+ target.absoluteCap <= 0n) {
246
+ throw noFlow;
247
+ }
248
+ if (reallocation.fromIdle) {
249
+ if (vaultConfig.canPullFromIdle !== true) {
250
+ throw noFlow;
251
+ }
252
+ return;
253
+ }
254
+ const source = toMarketParams(reallocation.sourceMarketParams, "reallocation.sourceMarketParams");
255
+ if (!isAddressEqual(source.loanToken, market.loanToken)) {
256
+ throw new ReallocationLoanTokenMismatchError(market.loanToken, source.loanToken);
257
+ }
258
+ if (source.id === market.id) {
259
+ throw new ReallocationWithdrawalOnTargetMarketError(vault, market.id);
260
+ }
261
+ const sourceConfig = findMarketConfig(allocator, {
262
+ vault,
263
+ adapter: reallocation.sourceAdapter,
264
+ marketParams: source,
265
+ });
266
+ if (!isActive(reallocation.sourceAdapter) ||
267
+ sourceConfig == null ||
268
+ sourceConfig.canPullFromMarket !== true) {
269
+ throw noFlow;
270
+ }
271
+ };
@@ -235,6 +235,20 @@ export declare const validateMidnightBorrowHealth: (params: {
235
235
  readonly debt: bigint;
236
236
  readonly borrowUnits: bigint;
237
237
  }) => void;
238
+ /**
239
+ * @internal Rejects a Midnight borrow that could execute less than
240
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` before the market's maturity, when unpaid debt becomes
241
+ * liquidatable. The sell is not reduce-only, so any units beyond the credit left at execution open
242
+ * debt; credit covering the target when the borrow is prepared does not exempt it. Once `now` is
243
+ * past maturity the protocol rejects new debt, so the check does not apply, matching the
244
+ * post-maturity credit cap in `validateMidnightTakeFeasibility`.
245
+ * Used by the entity and TransactionPlan borrow flows.
246
+ */
247
+ export declare const validateMidnightBorrowMaturity: (params: {
248
+ readonly marketData: MidnightMarket;
249
+ readonly now: bigint;
250
+ readonly deadline: bigint;
251
+ }) => void;
238
252
  /**
239
253
  * @internal Rejects a Midnight collateral withdrawal whose post-operation debt exceeds the remaining
240
254
  * collateral's capacity at LLTV minus `DEFAULT_LLTV_BUFFER`, with the same check and error as the
@@ -2,9 +2,9 @@ import { getChainAddresses, MarketUtils, MathLib, ORACLE_PRICE_SCALE, } from "@m
2
2
  import { MarketUtils as MidnightMarketUtils, } from "@morpho-org/midnight-sdk";
3
3
  import { isDefined, isHexEqual } from "@morpho-org/morpho-ts";
4
4
  import { isAddress, isAddressEqual, maxUint128, maxUint256, zeroAddress, } from "viem";
5
- import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidBigIntInputError, InvalidMidnightNativeAmountTypeError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MidnightRepayExceedsDebtError, MidnightTakeTargetUnreachableError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
5
+ import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidBigIntInputError, InvalidMidnightNativeAmountTypeError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MidnightBorrowTooCloseToMaturityError, MidnightRepayExceedsDebtError, MidnightTakeTargetUnreachableError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
6
6
  import { computeMidnightPostWithdrawalCollateral } from "./computeMidnightPostWithdrawalCollateral.js";
7
- import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
7
+ import { DEFAULT_LLTV_BUFFER, MAX_SLIPPAGE_TOLERANCE, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
8
8
  import { resolveMaxPenalty } from "./reallocationPenalty.js";
9
9
  import { validateMidnightAddress } from "./validateMidnightAccount.js";
10
10
  import { validateMidnightReferralFeeCap } from "./validateMidnightBounds.js";
@@ -323,6 +323,29 @@ export const validateMidnightBorrowHealth = (params) => {
323
323
  throw new BorrowExceedsSafeLtvError(params.borrowUnits, MathLib.zeroFloorSub(maxSafeDebt, params.debt));
324
324
  }
325
325
  };
326
+ /**
327
+ * @internal Rejects a Midnight borrow that could execute less than
328
+ * `MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY` before the market's maturity, when unpaid debt becomes
329
+ * liquidatable. The sell is not reduce-only, so any units beyond the credit left at execution open
330
+ * debt; credit covering the target when the borrow is prepared does not exempt it. Once `now` is
331
+ * past maturity the protocol rejects new debt, so the check does not apply, matching the
332
+ * post-maturity credit cap in `validateMidnightTakeFeasibility`.
333
+ * Used by the entity and TransactionPlan borrow flows.
334
+ */
335
+ export const validateMidnightBorrowMaturity = (params) => {
336
+ const { maturity } = params.marketData.params;
337
+ if (params.now > maturity) {
338
+ return;
339
+ }
340
+ const latestDeadline = maturity - MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY;
341
+ if (params.deadline > latestDeadline) {
342
+ throw new MidnightBorrowTooCloseToMaturityError({
343
+ deadline: params.deadline,
344
+ maturity,
345
+ latestDeadline,
346
+ });
347
+ }
348
+ };
326
349
  /**
327
350
  * @internal Rejects a Midnight collateral withdrawal whose post-operation debt exceeds the remaining
328
351
  * collateral's capacity at LLTV minus `DEFAULT_LLTV_BUFFER`, with the same check and error as the
@@ -1,6 +1,6 @@
1
1
  import { type Address } from "@morpho-org/blue-sdk";
2
2
  /** Supported spender slots that can be validated against the chain address registry. */
3
- export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundlesV2" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
3
+ export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundlesV2" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1" | "zeroExLeverageBundlesV1";
4
4
  /**
5
5
  * Validates that a requirement encoder spender matches one of the allowed chain addresses.
6
6
  *
@@ -1,4 +1,4 @@
1
- import { getChainAddresses } from "@morpho-org/blue-sdk";
1
+ import { getChainAddresses, isZeroExLeverageChain, } from "@morpho-org/blue-sdk";
2
2
  import { isAddressEqual } from "viem";
3
3
  import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
4
4
  /**
@@ -32,6 +32,10 @@ export const validateRequirementSpender = (params) => {
32
32
  vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
33
33
  vaultBundlesV1: bundles?.vaultBundlesV1,
34
34
  blueBundlesV1: bundles?.blueBundlesV1,
35
+ // Only a non-zero bundle on a chain with 0x AllowanceHolder may receive approvals.
36
+ zeroExLeverageBundlesV1: isZeroExLeverageChain(params.chainId)
37
+ ? bundles?.zeroExLeverageBundlesV1
38
+ : undefined,
35
39
  };
36
40
  const supportedSpenders = params.allowed.map((key) => addresses[key]);
37
41
  if (!supportedSpenders.some((supported) => supported != null && isAddressEqual(params.spender, supported))) {