@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.
- package/README.md +44 -1
- package/lib/cjs/abis.d.ts +794 -1
- package/lib/cjs/abis.js +815 -1
- package/lib/cjs/actions/blue/close.d.ts +169 -0
- package/lib/cjs/actions/blue/close.js +270 -0
- package/lib/cjs/actions/blue/common.js +2 -2
- package/lib/cjs/actions/blue/delever.d.ts +156 -0
- package/lib/cjs/actions/blue/delever.js +223 -0
- package/lib/cjs/actions/blue/index.d.ts +3 -0
- package/lib/cjs/actions/blue/index.js +3 -0
- package/lib/cjs/actions/blue/lever.d.ts +184 -0
- package/lib/cjs/actions/blue/lever.js +272 -0
- package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/cjs/actions/blue/leverageIntent.js +103 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/cjs/addresses.d.ts +1 -1
- package/lib/cjs/addresses.js +6 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/addresses.d.ts +1 -1
- package/lib/cjs/blue/addresses.js +6 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +6 -2
- package/lib/cjs/entities/blue/blue.d.ts +486 -2
- package/lib/cjs/entities/blue/blue.js +529 -34
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/constant.d.ts +34 -0
- package/lib/cjs/helpers/constant.js +35 -1
- package/lib/cjs/helpers/deadShares.js +3 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +28 -1
- package/lib/cjs/helpers/leverage/index.d.ts +1 -0
- package/lib/cjs/helpers/leverage/index.js +11 -0
- package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
- package/lib/cjs/helpers/leverage/limits.js +715 -0
- package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
- package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/cjs/helpers/leverage/reallocations.js +276 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
- package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
- package/lib/cjs/helpers/zeroExQuote.js +763 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +5 -2
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/reads/assertContractCode.d.ts +25 -0
- package/lib/cjs/reads/assertContractCode.js +30 -0
- package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
- package/lib/cjs/types/action.d.ts +130 -1
- package/lib/cjs/types/error.d.ts +59 -0
- package/lib/cjs/types/error.js +82 -3
- package/lib/cjs/types/index.d.ts +2 -0
- package/lib/cjs/types/index.js +2 -0
- package/lib/cjs/types/leverageError.d.ts +1552 -0
- package/lib/cjs/types/leverageError.js +1711 -0
- package/lib/cjs/types/zeroEx.d.ts +171 -0
- package/lib/cjs/types/zeroEx.js +2 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +794 -1
- package/lib/esm/abis.js +810 -1
- package/lib/esm/actions/blue/close.d.ts +169 -0
- package/lib/esm/actions/blue/close.js +266 -0
- package/lib/esm/actions/blue/common.js +3 -3
- package/lib/esm/actions/blue/delever.d.ts +156 -0
- package/lib/esm/actions/blue/delever.js +219 -0
- package/lib/esm/actions/blue/index.d.ts +3 -0
- package/lib/esm/actions/blue/index.js +3 -0
- package/lib/esm/actions/blue/lever.d.ts +184 -0
- package/lib/esm/actions/blue/lever.js +268 -0
- package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/esm/actions/blue/leverageIntent.js +96 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/index.js +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/esm/addresses.d.ts +1 -1
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/addresses.d.ts +1 -1
- package/lib/esm/blue/addresses.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +486 -2
- package/lib/esm/entities/blue/blue.js +501 -6
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/esm/entities/requirements/assertContractCode.js +1 -25
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/constant.d.ts +34 -0
- package/lib/esm/helpers/constant.js +34 -0
- package/lib/esm/helpers/deadShares.js +4 -1
- package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/leverage/index.d.ts +1 -0
- package/lib/esm/helpers/leverage/index.js +1 -0
- package/lib/esm/helpers/leverage/limits.d.ts +472 -0
- package/lib/esm/helpers/leverage/limits.js +705 -0
- package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/esm/helpers/leverage/positionMarket.js +24 -0
- package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/esm/helpers/leverage/reallocations.js +271 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +5 -1
- package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
- package/lib/esm/helpers/zeroExQuote.js +754 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/reads/assertContractCode.d.ts +25 -0
- package/lib/esm/reads/assertContractCode.js +26 -0
- package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/esm/reads/fetchZeroExQuote.js +326 -0
- package/lib/esm/types/action.d.ts +130 -1
- package/lib/esm/types/error.d.ts +59 -0
- package/lib/esm/types/error.js +76 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/esm/types/leverageError.d.ts +1552 -0
- package/lib/esm/types/leverageError.js +1660 -0
- package/lib/esm/types/zeroEx.d.ts +171 -0
- package/lib/esm/types/zeroEx.js +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- 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,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateLeveragePositionMarket = void 0;
|
|
4
|
+
const index_js_1 = require("../../types/index.js");
|
|
5
|
+
const validate_js_1 = require("../validate.js");
|
|
6
|
+
/**
|
|
7
|
+
* Refuses leverage data whose position carries another market's tuple: the leverage bounds, LTV and oracle price
|
|
8
|
+
* come from `position.market`, so it must hash to its cached id and be the expected market. Callers check the
|
|
9
|
+
* position's own `marketId` separately.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
* @param position - Position of the one-block leverage data.
|
|
13
|
+
* @param marketParams - Market the action is built for.
|
|
14
|
+
* @throws {MarketIdMismatchError} when the position's market tuple does not hash to its cached id or is another
|
|
15
|
+
* market than `marketParams`.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* validateLeveragePositionMarket(leverageData.position, marketParams);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const validateLeveragePositionMarket = (position, marketParams) => {
|
|
22
|
+
const positionMarketParams = position.market.params;
|
|
23
|
+
(0, validate_js_1.validateMarketParamsId)(positionMarketParams);
|
|
24
|
+
if (positionMarketParams.id !== marketParams.id) {
|
|
25
|
+
throw new index_js_1.MarketIdMismatchError(positionMarketParams.id, marketParams.id);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.validateLeveragePositionMarket = validateLeveragePositionMarket;
|
|
@@ -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,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateLeverageReallocations = exports.computeLeveragePenaltyAssets = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const index_js_1 = require("../../types/index.js");
|
|
7
|
+
const constant_js_1 = require("../constant.js");
|
|
8
|
+
const validate_js_1 = require("../validate.js");
|
|
9
|
+
/**
|
|
10
|
+
* Computes the `penaltyAssets` a ZeroExLeverageBundlesV1 Lever must sign: each reallocation's
|
|
11
|
+
* `assets × penalty / WAD` rounded up on its own, then summed, exactly as the bundle's
|
|
12
|
+
* `totalPenaltyAssets` and the public allocator charge it. Rounding the sum once instead can be
|
|
13
|
+
* lower and makes the Lever revert. BlueBundlesV1 charges its public-allocator reallocations the same
|
|
14
|
+
* way, so its penalty sum calls this function too and signing and funding checks use one amount.
|
|
15
|
+
*
|
|
16
|
+
* @param reallocations - Reallocations of the Lever, in any order.
|
|
17
|
+
* @returns Total penalty in loan-token assets; zero without reallocations.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { computeLeveragePenaltyAssets } from "@morpho-org/morpho-sdk";
|
|
21
|
+
*
|
|
22
|
+
* const penaltyAssets = computeLeveragePenaltyAssets([
|
|
23
|
+
* { assets: 1n, penalty: 5_000_000_000_000_000n },
|
|
24
|
+
* { assets: 1n, penalty: 5_000_000_000_000_000n },
|
|
25
|
+
* ]);
|
|
26
|
+
* // penaltyAssets === 2n
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const computeLeveragePenaltyAssets = (reallocations) => reallocations.reduce((total, reallocation) => total +
|
|
30
|
+
blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets(reallocation, reallocation.assets), 0n);
|
|
31
|
+
exports.computeLeveragePenaltyAssets = computeLeveragePenaltyAssets;
|
|
32
|
+
/**
|
|
33
|
+
* Refuses a Lever's public-allocator reallocations unless each one targets exactly the Lever's
|
|
34
|
+
* market, carries the vault's configured penalty rate and at most
|
|
35
|
+
* {@link LEVERAGE_MAX_REALLOCATION_PENALTY}, and follows a route the vault's BluePublicAllocator
|
|
36
|
+
* allows at the data block: the vault authorizes the allocator, the target adapter is active
|
|
37
|
+
* with a positive cap into the market, and the source is either idle the allocator may pull, or
|
|
38
|
+
* another market with the same loan token whose active adapter the allocator may pull from.
|
|
39
|
+
* Together the reallocations must move no more than `maxBorrowAssets`. That sum counts the moved assets only: the
|
|
40
|
+
* penalties and the 0x swap are already inside `maxBorrowAssets` (`maxSwapIn + penaltyAssets − loanAssets`), and the
|
|
41
|
+
* contract pays each penalty out of the borrow. ZeroExLeverageBundlesV1 checks only each target's loan token and pays every
|
|
42
|
+
* penalty asked, so a reallocation into another market with the same loan token would still charge
|
|
43
|
+
* the user. The guard checks that the allocator's own state enables a route, not that the route can execute:
|
|
44
|
+
* adapter compatibility (the market's IRM must be the adapter's `adaptiveCurveIrm`), remaining cap and
|
|
45
|
+
* source liquidity are the planner's (`VaultV2BlueReallocationData`), so pass only reallocations it
|
|
46
|
+
* built; one that fails them reverts onchain without charging anything. The allocator charges only the vault's
|
|
47
|
+
* current penalty rate, so a vault that changes its penalty after the data block makes the Lever revert rather than
|
|
48
|
+
* overcharge. The integrator, such as the front end, supplies and curates the vaults the reallocations come
|
|
49
|
+
* from, and the SDK keeps no vault allowlist: the guard checks each vault's own allocator state, not whether the
|
|
50
|
+
* vault is one to trust. Pure: reads nothing on chain.
|
|
51
|
+
*
|
|
52
|
+
* @param params - Guard inputs.
|
|
53
|
+
* @param params.reallocations - Reallocations the Lever will sign.
|
|
54
|
+
* @param params.marketParams - The Lever's market.
|
|
55
|
+
* @param params.allocator - BluePublicAllocator state at the data block, indexed by vault: the
|
|
56
|
+
* vault configurations, active adapters and adapter-market configurations keyed by
|
|
57
|
+
* `adapterMarketCapId`. The guard trusts it as given, so pass the onchain state read at the data block, the
|
|
58
|
+
* snapshot `market.getVaultV2BlueReallocationData(...)` returns, never a hand-built one: a route that state
|
|
59
|
+
* wrongly allows is not caught here and reverts onchain or charges the vault's real penalty.
|
|
60
|
+
* @param params.maxBorrowAssets - The Lever's signed borrow cap.
|
|
61
|
+
* @returns Nothing; it throws on the first unsafe reallocation.
|
|
62
|
+
* @throws {LeverageReallocationMarketMismatchError} When a reallocation targets another market.
|
|
63
|
+
* @throws {LeverageReallocationPenaltyAboveLimitError} When a penalty rate exceeds 1%.
|
|
64
|
+
* @throws {InconsistentReallocationPenaltyError} When a penalty rate differs from the vault's configured one.
|
|
65
|
+
* @throws {ReallocationLoanTokenMismatchError} When a source market has another loan token.
|
|
66
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} When a reallocation pulls from the Lever's own market.
|
|
67
|
+
* @throws {LeverageReallocationNoFlowError} When the allocator cannot move liquidity along the route.
|
|
68
|
+
* @throws {LeverageReallocationExceedsBorrowError} When the reallocations move more than `maxBorrowAssets`, so any
|
|
69
|
+
* reallocation of a Lever that borrows nothing, which the bundle refuses with `InconsistentBorrowInput`.
|
|
70
|
+
* @throws {InvalidBigIntInputError} When `maxBorrowAssets`, a reallocation's assets or its penalty rate is missing or not
|
|
71
|
+
* a bigint.
|
|
72
|
+
* @throws {NonPositiveInputError} When a reallocation moves no assets.
|
|
73
|
+
* @throws {NegativeInputError} When a penalty rate is negative.
|
|
74
|
+
* @throws {NonBooleanInputError} When a reallocation's `fromIdle` is missing or not a boolean, with
|
|
75
|
+
* `field: "reallocation.fromIdle"`.
|
|
76
|
+
* @throws {InvalidBigIntInputError} When the lltv of `marketParams`, or of a reallocation's `marketParams` or
|
|
77
|
+
* `sourceMarketParams`, does not convert to a bigint, with `field` naming which.
|
|
78
|
+
* @throws {NegativeInputError} When such an lltv is negative, with `field` naming which.
|
|
79
|
+
* @throws {InputExceedsMaxError} When such an lltv exceeds `uint256`, with `field` naming which.
|
|
80
|
+
* A reallocation's target is checked before its market id is compared.
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { validateLeverageReallocations } from "@morpho-org/morpho-sdk";
|
|
84
|
+
* import { VaultV2MorphoMarketV1AdapterV2 } from "@morpho-org/morpho-sdk/blue/entities";
|
|
85
|
+
* import { zeroAddress } from "viem";
|
|
86
|
+
*
|
|
87
|
+
* // `marketParams` is the Lever's market, `vault` a Vault V2 and `adapter` its MorphoMarketV1AdapterV2.
|
|
88
|
+
* const capId = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter, marketParams);
|
|
89
|
+
*
|
|
90
|
+
* const penalty = 1_000_000_000_000_000n;
|
|
91
|
+
*
|
|
92
|
+
* // The `allocator` object below only illustrates state that passes. Never build it by hand: the guard
|
|
93
|
+
* // trusts it as given, so read it at the planning block with `getVaultV2BlueReallocationData` and
|
|
94
|
+
* // validate legs from that snapshot.
|
|
95
|
+
*
|
|
96
|
+
* // Passes: the vault authorizes the allocator and may pull its idle assets, the adapter is active
|
|
97
|
+
* // with a positive cap into the market, the penalty is the vault's 0.1% and 1_000_000 assets stay
|
|
98
|
+
* // within the 2_000_000 borrow cap.
|
|
99
|
+
* validateLeverageReallocations({
|
|
100
|
+
* reallocations: [
|
|
101
|
+
* {
|
|
102
|
+
* vault,
|
|
103
|
+
* adapter,
|
|
104
|
+
* marketParams,
|
|
105
|
+
* fromIdle: true,
|
|
106
|
+
* sourceAdapter: zeroAddress,
|
|
107
|
+
* sourceMarketParams: marketParams,
|
|
108
|
+
* assets: 1_000_000n,
|
|
109
|
+
* penalty,
|
|
110
|
+
* },
|
|
111
|
+
* ],
|
|
112
|
+
* marketParams,
|
|
113
|
+
* allocator: {
|
|
114
|
+
* publicAllocatorConfigs: { [vault]: { canPullFromIdle: true, penalty } },
|
|
115
|
+
* activeAdapters: { [vault]: new Set([adapter]) },
|
|
116
|
+
* marketPublicAllocatorConfigs: {
|
|
117
|
+
* [vault]: {
|
|
118
|
+
* [capId]: { vault, adapter, absoluteCap: 10_000_000n, canPullFromMarket: false },
|
|
119
|
+
* },
|
|
120
|
+
* },
|
|
121
|
+
* },
|
|
122
|
+
* maxBorrowAssets: 2_000_000n,
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
const validateLeverageReallocations = ({ reallocations, marketParams, allocator, maxBorrowAssets, }) => {
|
|
127
|
+
// A JavaScript caller can omit the cap; refuse it before the aggregate check compares against it.
|
|
128
|
+
if (typeof maxBorrowAssets !== "bigint") {
|
|
129
|
+
throw new index_js_1.InvalidBigIntInputError("maxBorrowAssets", maxBorrowAssets);
|
|
130
|
+
}
|
|
131
|
+
const market = toMarketParams(marketParams, "marketParams");
|
|
132
|
+
let total = 0n;
|
|
133
|
+
for (const reallocation of reallocations) {
|
|
134
|
+
if (typeof reallocation.assets !== "bigint") {
|
|
135
|
+
throw new index_js_1.InvalidBigIntInputError("reallocation.assets", reallocation.assets);
|
|
136
|
+
}
|
|
137
|
+
if (reallocation.assets <= 0n) {
|
|
138
|
+
throw new index_js_1.NonPositiveInputError("reallocation.assets", reallocation.assets);
|
|
139
|
+
}
|
|
140
|
+
if (typeof reallocation.penalty !== "bigint") {
|
|
141
|
+
throw new index_js_1.InvalidBigIntInputError("reallocation.penalty", reallocation.penalty);
|
|
142
|
+
}
|
|
143
|
+
if (reallocation.penalty < 0n) {
|
|
144
|
+
throw new index_js_1.NegativeInputError("reallocation.penalty", reallocation.penalty);
|
|
145
|
+
}
|
|
146
|
+
// `fromIdle` selects the route to check: a truthy string or a missing field would check the wrong one.
|
|
147
|
+
if (typeof reallocation.fromIdle !== "boolean") {
|
|
148
|
+
throw new index_js_1.NonBooleanInputError("reallocation.fromIdle", reallocation.fromIdle);
|
|
149
|
+
}
|
|
150
|
+
const targetId = toMarketParams(reallocation.marketParams, "reallocation.marketParams").id;
|
|
151
|
+
if (targetId !== market.id) {
|
|
152
|
+
throw new index_js_1.LeverageReallocationMarketMismatchError({
|
|
153
|
+
vault: reallocation.vault,
|
|
154
|
+
expected: market.id,
|
|
155
|
+
actual: targetId,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (reallocation.penalty > constant_js_1.LEVERAGE_MAX_REALLOCATION_PENALTY) {
|
|
159
|
+
throw new index_js_1.LeverageReallocationPenaltyAboveLimitError({
|
|
160
|
+
vault: reallocation.vault,
|
|
161
|
+
penalty: reallocation.penalty,
|
|
162
|
+
max: constant_js_1.LEVERAGE_MAX_REALLOCATION_PENALTY,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
validateAllocatorRoute(allocator, { ...reallocation, market });
|
|
166
|
+
total += reallocation.assets;
|
|
167
|
+
}
|
|
168
|
+
if (total > maxBorrowAssets) {
|
|
169
|
+
throw new index_js_1.LeverageReallocationExceedsBorrowError({
|
|
170
|
+
total,
|
|
171
|
+
maxBorrowAssets,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.validateLeverageReallocations = validateLeverageReallocations;
|
|
176
|
+
/**
|
|
177
|
+
* Builds the market's params without the `MarketParams` constructor, which registers them globally:
|
|
178
|
+
* a validation helper must leave the registry as it found it, even for a market it refuses.
|
|
179
|
+
* @internal
|
|
180
|
+
*/
|
|
181
|
+
const toMarketParams = (params, field) => {
|
|
182
|
+
let lltv;
|
|
183
|
+
try {
|
|
184
|
+
lltv = BigInt(params.lltv);
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
// A JavaScript caller can pass a fractional, non-numeric or missing LLTV, which BigInt rejects untyped.
|
|
188
|
+
throw new index_js_1.InvalidBigIntInputError(`${field}.lltv`, params.lltv);
|
|
189
|
+
}
|
|
190
|
+
// A negative or oversized LLTV converts, but the market id hash would reject it untyped or hash another market.
|
|
191
|
+
(0, validate_js_1.validateUint256Field)(`${field}.lltv`, lltv);
|
|
192
|
+
return {
|
|
193
|
+
collateralToken: params.collateralToken,
|
|
194
|
+
loanToken: params.loanToken,
|
|
195
|
+
oracle: params.oracle,
|
|
196
|
+
irm: params.irm,
|
|
197
|
+
lltv,
|
|
198
|
+
id: blue_sdk_1.MarketUtils.getMarketId(params),
|
|
199
|
+
liquidationIncentiveFactor: blue_sdk_1.MarketUtils.getLiquidationIncentiveFactor(params),
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
/** Reads a vault-indexed record whatever the casing of its address keys. @internal */
|
|
203
|
+
const byAddress = (record, address) => {
|
|
204
|
+
const key = Object.keys(record).find((candidate) => (0, viem_1.isAddressEqual)(candidate, address));
|
|
205
|
+
return key == null ? undefined : record[key];
|
|
206
|
+
};
|
|
207
|
+
/** Finds the adapter-market configuration of a vault whatever the casing of its keys. @internal */
|
|
208
|
+
const findMarketConfig = (allocator, { vault, adapter, marketParams, }) => {
|
|
209
|
+
const capId = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter, marketParams).toLowerCase();
|
|
210
|
+
const config = Object.entries(byAddress(allocator.marketPublicAllocatorConfigs, vault) ?? {}).find(([id]) => id.toLowerCase() === capId)?.[1];
|
|
211
|
+
if (config == null ||
|
|
212
|
+
!(0, viem_1.isAddressEqual)(config.vault, vault) ||
|
|
213
|
+
!(0, viem_1.isAddressEqual)(config.adapter, adapter)) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
return config;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Throws unless the vault's allocator can move liquidity along the reallocation's route.
|
|
220
|
+
* @internal
|
|
221
|
+
*/
|
|
222
|
+
const validateAllocatorRoute = (allocator, reallocation) => {
|
|
223
|
+
const { vault, adapter, market } = reallocation;
|
|
224
|
+
const noFlow = new index_js_1.LeverageReallocationNoFlowError({
|
|
225
|
+
vault,
|
|
226
|
+
marketId: market.id,
|
|
227
|
+
});
|
|
228
|
+
const vaultConfig = byAddress(allocator.publicAllocatorConfigs, vault);
|
|
229
|
+
if (vaultConfig == null) {
|
|
230
|
+
throw noFlow;
|
|
231
|
+
}
|
|
232
|
+
if (reallocation.penalty !== vaultConfig.penalty) {
|
|
233
|
+
throw new index_js_1.InconsistentReallocationPenaltyError({
|
|
234
|
+
vault,
|
|
235
|
+
expected: vaultConfig.penalty,
|
|
236
|
+
actual: reallocation.penalty,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const active = byAddress(allocator.activeAdapters, vault);
|
|
240
|
+
const isActive = (candidate) => active != null &&
|
|
241
|
+
[...active].some((activeAdapter) => (0, viem_1.isAddressEqual)(activeAdapter, candidate));
|
|
242
|
+
const target = findMarketConfig(allocator, {
|
|
243
|
+
vault,
|
|
244
|
+
adapter,
|
|
245
|
+
marketParams: market,
|
|
246
|
+
});
|
|
247
|
+
if (!isActive(adapter) ||
|
|
248
|
+
target == null ||
|
|
249
|
+
typeof target.absoluteCap !== "bigint" ||
|
|
250
|
+
target.absoluteCap <= 0n) {
|
|
251
|
+
throw noFlow;
|
|
252
|
+
}
|
|
253
|
+
if (reallocation.fromIdle) {
|
|
254
|
+
if (vaultConfig.canPullFromIdle !== true) {
|
|
255
|
+
throw noFlow;
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const source = toMarketParams(reallocation.sourceMarketParams, "reallocation.sourceMarketParams");
|
|
260
|
+
if (!(0, viem_1.isAddressEqual)(source.loanToken, market.loanToken)) {
|
|
261
|
+
throw new index_js_1.ReallocationLoanTokenMismatchError(market.loanToken, source.loanToken);
|
|
262
|
+
}
|
|
263
|
+
if (source.id === market.id) {
|
|
264
|
+
throw new index_js_1.ReallocationWithdrawalOnTargetMarketError(vault, market.id);
|
|
265
|
+
}
|
|
266
|
+
const sourceConfig = findMarketConfig(allocator, {
|
|
267
|
+
vault,
|
|
268
|
+
adapter: reallocation.sourceAdapter,
|
|
269
|
+
marketParams: source,
|
|
270
|
+
});
|
|
271
|
+
if (!isActive(reallocation.sourceAdapter) ||
|
|
272
|
+
sourceConfig == null ||
|
|
273
|
+
sourceConfig.canPullFromMarket !== true) {
|
|
274
|
+
throw noFlow;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
@@ -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
|
*
|
|
@@ -35,6 +35,10 @@ const validateRequirementSpender = (params) => {
|
|
|
35
35
|
vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
|
|
36
36
|
vaultBundlesV1: bundles?.vaultBundlesV1,
|
|
37
37
|
blueBundlesV1: bundles?.blueBundlesV1,
|
|
38
|
+
// Only a non-zero bundle on a chain with 0x AllowanceHolder may receive approvals.
|
|
39
|
+
zeroExLeverageBundlesV1: (0, blue_sdk_1.isZeroExLeverageChain)(params.chainId)
|
|
40
|
+
? bundles?.zeroExLeverageBundlesV1
|
|
41
|
+
: undefined,
|
|
38
42
|
};
|
|
39
43
|
const supportedSpenders = params.allowed.map((key) => addresses[key]);
|
|
40
44
|
if (!supportedSpenders.some((supported) => supported != null && (0, viem_1.isAddressEqual)(params.spender, supported))) {
|