@morpho-org/morpho-sdk 5.9.0 → 6.0.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/MIGRATION-v5-to-v6.md +201 -0
- package/README.md +58 -40
- package/lib/cjs/actions/blue/borrow.d.ts +62 -61
- package/lib/cjs/actions/blue/borrow.js +48 -80
- package/lib/cjs/actions/blue/common.d.ts +99 -0
- package/lib/cjs/actions/blue/common.js +318 -0
- package/lib/cjs/actions/blue/refinance.d.ts +72 -112
- package/lib/cjs/actions/blue/refinance.js +97 -199
- package/lib/cjs/actions/blue/repay.d.ts +72 -68
- package/lib/cjs/actions/blue/repay.js +56 -118
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +148 -137
- package/lib/cjs/actions/blue/supply.d.ts +62 -45
- package/lib/cjs/actions/blue/supply.js +94 -70
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/cjs/actions/blue/supplyCollateral.js +52 -69
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -120
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -79
- package/lib/cjs/actions/blue/withdraw.js +101 -97
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/cjs/actions/blue/withdrawCollateral.js +45 -50
- package/lib/cjs/actions/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +60 -19
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/cjs/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +207 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/cjs/actions/requirements/blue/getUnusedPermit2Nonce.js +72 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +2 -0
- package/lib/cjs/actions/requirements/blue/index.js +2 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +30 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +7 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +33 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +123 -0
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/encode/index.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +4 -0
- package/lib/cjs/bundler/actions.d.ts +4 -4
- package/lib/cjs/bundler/actions.js +4 -4
- package/lib/cjs/client/morphoViemExtension.d.ts +2 -1
- package/lib/cjs/client/morphoViemExtension.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +806 -374
- package/lib/cjs/entities/blue/blue.js +447 -696
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/cjs/helpers/validate.d.ts +14 -23
- package/lib/cjs/helpers/validate.js +30 -48
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +2 -0
- package/lib/cjs/types/action.d.ts +146 -162
- package/lib/cjs/types/action.js +29 -2
- package/lib/cjs/types/client.d.ts +9 -0
- package/lib/cjs/types/error.d.ts +141 -14
- package/lib/cjs/types/error.js +198 -21
- package/lib/cjs/types/sharedLiquidity.d.ts +0 -7
- package/lib/esm/actions/blue/borrow.d.ts +62 -61
- package/lib/esm/actions/blue/borrow.js +48 -80
- package/lib/esm/actions/blue/common.d.ts +99 -0
- package/lib/esm/actions/blue/common.js +306 -0
- package/lib/esm/actions/blue/refinance.d.ts +72 -112
- package/lib/esm/actions/blue/refinance.js +98 -200
- package/lib/esm/actions/blue/repay.d.ts +72 -68
- package/lib/esm/actions/blue/repay.js +56 -118
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +85 -90
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +149 -138
- package/lib/esm/actions/blue/supply.d.ts +62 -45
- package/lib/esm/actions/blue/supply.js +94 -70
- package/lib/esm/actions/blue/supplyCollateral.d.ts +63 -40
- package/lib/esm/actions/blue/supplyCollateral.js +52 -69
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +82 -90
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -121
- package/lib/esm/actions/blue/withdraw.d.ts +68 -79
- package/lib/esm/actions/blue/withdraw.js +100 -96
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +56 -28
- package/lib/esm/actions/blue/withdrawCollateral.js +45 -50
- package/lib/esm/actions/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +29 -17
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +63 -22
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts +80 -0
- package/lib/esm/actions/requirements/blue/getBlueBundlesV1TokenRequirements.js +203 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.d.ts +48 -0
- package/lib/esm/actions/requirements/blue/getUnusedPermit2Nonce.js +68 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +2 -0
- package/lib/esm/actions/requirements/blue/index.js +2 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -7
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +31 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +8 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +16 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +34 -7
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts +61 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.js +119 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
- package/lib/esm/actions/requirements/encode/index.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -4
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +1 -0
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +5 -1
- package/lib/esm/bundler/actions.d.ts +4 -4
- package/lib/esm/bundler/actions.js +4 -4
- package/lib/esm/client/morphoViemExtension.d.ts +2 -1
- package/lib/esm/client/morphoViemExtension.js +2 -1
- package/lib/esm/entities/blue/blue.d.ts +806 -374
- package/lib/esm/entities/blue/blue.js +453 -702
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +3 -9
- package/lib/esm/helpers/computeVaultV1Reallocations.js +3 -9
- package/lib/esm/helpers/validate.d.ts +14 -23
- package/lib/esm/helpers/validate.js +30 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +2 -1
- package/lib/esm/helpers/validateRequirementSpender.js +2 -0
- package/lib/esm/types/action.d.ts +146 -162
- package/lib/esm/types/action.js +28 -2
- package/lib/esm/types/client.d.ts +9 -0
- package/lib/esm/types/error.d.ts +141 -14
- package/lib/esm/types/error.js +184 -17
- package/lib/esm/types/sharedLiquidity.d.ts +0 -7
- package/package.json +4 -3
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +0 -63
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/cjs/actions/blue/buildReallocationActions.js +0 -141
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/cjs/actions/blue/resolveRepayFunding.js +0 -85
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +0 -47
- package/lib/esm/actions/blue/buildAssetFundingActions.js +0 -59
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +0 -69
- package/lib/esm/actions/blue/buildReallocationActions.js +0 -135
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +0 -66
- package/lib/esm/actions/blue/resolveRepayFunding.js +0 -81
|
@@ -28,6 +28,7 @@ PreLiquidationPosition, Token, User as BlueUser,
|
|
|
28
28
|
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
29
29
|
export type { BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, RatifierTreeInput as MidnightRatifierTreeInput, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeDescriptor as MidnightTreeDescriptor, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, } from "@morpho-org/midnight-sdk";
|
|
30
30
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
31
|
+
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
31
32
|
export { MorphoBlue } from "./blue/index.js";
|
|
32
33
|
export type { GetOffersDataParams as MidnightGetOffersDataParams,
|
|
33
34
|
/** @deprecated Use `MidnightGetOffersDataParams`. */
|
|
@@ -42,7 +42,6 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
42
42
|
* transport: http(),
|
|
43
43
|
* }).extend(morphoViemExtension());
|
|
44
44
|
*
|
|
45
|
-
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
46
45
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
47
46
|
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
48
47
|
* const block = await client.getBlock();
|
|
@@ -58,14 +57,9 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
58
57
|
* amount: borrowAmount,
|
|
59
58
|
* options: { timestamp: block.timestamp },
|
|
60
59
|
* });
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* amount: borrowAmount,
|
|
65
|
-
* positionData,
|
|
66
|
-
* reallocations,
|
|
67
|
-
* });
|
|
68
|
-
* // borrow.buildTx() includes any required PublicAllocator reallocations.
|
|
60
|
+
* // Encode `reallocations` explicitly with
|
|
61
|
+
* // BundlerAction.publicAllocatorReallocateTo(...) when composing a low-level bundle.
|
|
62
|
+
* // High-level Blue writes accept Vault V2 reallocations only.
|
|
69
63
|
* ```
|
|
70
64
|
*/
|
|
71
65
|
export declare const computeVaultV1Reallocations: ({ reallocationData: data, marketId, operation, amount, options, }: {
|
|
@@ -98,7 +98,6 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
98
98
|
* transport: http(),
|
|
99
99
|
* }).extend(morphoViemExtension());
|
|
100
100
|
*
|
|
101
|
-
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
102
101
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
103
102
|
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
104
103
|
* const block = await client.getBlock();
|
|
@@ -114,14 +113,9 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
114
113
|
* amount: borrowAmount,
|
|
115
114
|
* options: { timestamp: block.timestamp },
|
|
116
115
|
* });
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* amount: borrowAmount,
|
|
121
|
-
* positionData,
|
|
122
|
-
* reallocations,
|
|
123
|
-
* });
|
|
124
|
-
* // borrow.buildTx() includes any required PublicAllocator reallocations.
|
|
116
|
+
* // Encode `reallocations` explicitly with
|
|
117
|
+
* // BundlerAction.publicAllocatorReallocateTo(...) when composing a low-level bundle.
|
|
118
|
+
* // High-level Blue writes accept Vault V2 reallocations only.
|
|
125
119
|
* ```
|
|
126
120
|
*/
|
|
127
121
|
const computeVaultV1Reallocations = ({ reallocationData: data, marketId, operation, amount, options, }) => {
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { type AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { MarketInput as MidnightMarketInput } from "@morpho-org/midnight-sdk";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
|
-
import { type
|
|
4
|
+
import { type VaultV1Reallocation, type VaultV2BlueReallocation } from "../types/index.js";
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
|
|
7
|
+
/**
|
|
8
|
+
* Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
|
|
9
|
+
* gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
|
|
10
|
+
* stays valid — it is the accepted `maxLtv` / full-repay `repayShares` sentinel.
|
|
11
|
+
*
|
|
12
|
+
* @param field - Field name surfaced in the thrown error.
|
|
13
|
+
* @param value - Candidate value; must be in `[0, maxUint256]`.
|
|
14
|
+
* @returns Nothing when `value` is within range.
|
|
15
|
+
* @throws {NegativeInputError} when `value` is negative.
|
|
16
|
+
* @throws {InputExceedsMaxError} when `value` exceeds `maxUint256`.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const validateUint256Field: (field: string, value: bigint) => void;
|
|
7
20
|
/**
|
|
8
21
|
* Validates that a raw or hydrated Midnight market belongs to the expected chain.
|
|
9
22
|
*
|
|
@@ -162,28 +175,6 @@ export declare const validateRepayShares: (params: {
|
|
|
162
175
|
export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
|
|
163
176
|
/** @internal */
|
|
164
177
|
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
|
|
165
|
-
/**
|
|
166
|
-
* Validates and normalizes a homogeneous Blue reallocation plan.
|
|
167
|
-
*
|
|
168
|
-
* @param params - Validation parameters.
|
|
169
|
-
* @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan.
|
|
170
|
-
* @param params.targetMarketId - Morpho Blue market receiving the liquidity.
|
|
171
|
-
* @param params.chainId - Chain whose allocator deployment is required for a V2 plan.
|
|
172
|
-
* @returns The validated plan tagged with its allocator version.
|
|
173
|
-
* @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
export declare const validateAndNormalizeReallocations: ({ reallocations, targetMarketId, chainId, }: {
|
|
177
|
-
readonly reallocations: BlueReallocationPlan | undefined;
|
|
178
|
-
readonly targetMarketId: MarketId;
|
|
179
|
-
readonly chainId: number;
|
|
180
|
-
}) => {
|
|
181
|
-
type: "vaultV2Blue";
|
|
182
|
-
reallocations: VaultV2BlueReallocation[];
|
|
183
|
-
} | {
|
|
184
|
-
type: "vaultV1";
|
|
185
|
-
reallocations: VaultV1Reallocation[];
|
|
186
|
-
};
|
|
187
178
|
/**
|
|
188
179
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
189
180
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.
|
|
3
|
+
exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateSlippageTolerance = exports.validateVaultV2BlueReallocations = exports.validateReallocations = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validateNativeAsset = exports.validateChainId = exports.validatePositionHealth = exports.validateAccrualPosition = exports.validateMidnightMarketChainId = exports.validateUint256Field = exports.compareMarketIds = void 0;
|
|
4
4
|
exports.validateUserAddress = validateUserAddress;
|
|
5
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
@@ -18,6 +18,26 @@ const compareMarketIds = (idA, idB) => {
|
|
|
18
18
|
return 0;
|
|
19
19
|
};
|
|
20
20
|
exports.compareMarketIds = compareMarketIds;
|
|
21
|
+
/**
|
|
22
|
+
* Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
|
|
23
|
+
* gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
|
|
24
|
+
* stays valid — it is the accepted `maxLtv` / full-repay `repayShares` sentinel.
|
|
25
|
+
*
|
|
26
|
+
* @param field - Field name surfaced in the thrown error.
|
|
27
|
+
* @param value - Candidate value; must be in `[0, maxUint256]`.
|
|
28
|
+
* @returns Nothing when `value` is within range.
|
|
29
|
+
* @throws {NegativeInputError} when `value` is negative.
|
|
30
|
+
* @throws {InputExceedsMaxError} when `value` exceeds `maxUint256`.
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
const validateUint256Field = (field, value) => {
|
|
34
|
+
if (value < 0n)
|
|
35
|
+
throw new index_js_1.NegativeInputError(field, value);
|
|
36
|
+
if (value > viem_1.maxUint256) {
|
|
37
|
+
throw new index_js_1.InputExceedsMaxError({ field, value, max: viem_1.maxUint256 });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.validateUint256Field = validateUint256Field;
|
|
21
41
|
/**
|
|
22
42
|
* Validates that a raw or hydrated Midnight market belongs to the expected chain.
|
|
23
43
|
*
|
|
@@ -281,6 +301,15 @@ exports.validateReallocations = validateReallocations;
|
|
|
281
301
|
const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
282
302
|
const penaltyByVault = new Map();
|
|
283
303
|
for (const reallocation of reallocations) {
|
|
304
|
+
// Reject non-object entries and Vault V1-shaped entries (which carry
|
|
305
|
+
// `withdrawals`/`fee`) with a typed, instructive error instead of a raw
|
|
306
|
+
// TypeError or a misleading `to.adapter` address error.
|
|
307
|
+
if (typeof reallocation !== "object" ||
|
|
308
|
+
reallocation === null ||
|
|
309
|
+
"withdrawals" in reallocation ||
|
|
310
|
+
"fee" in reallocation) {
|
|
311
|
+
throw new index_js_1.InvalidReallocationShapeError();
|
|
312
|
+
}
|
|
284
313
|
if (typeof reallocation.vault !== "string" ||
|
|
285
314
|
!(0, viem_1.isAddress)(reallocation.vault)) {
|
|
286
315
|
throw new index_js_1.InvalidReallocationAddressError("vault");
|
|
@@ -351,53 +380,6 @@ const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
|
351
380
|
}
|
|
352
381
|
};
|
|
353
382
|
exports.validateVaultV2BlueReallocations = validateVaultV2BlueReallocations;
|
|
354
|
-
/**
|
|
355
|
-
* Validates and normalizes a homogeneous Blue reallocation plan.
|
|
356
|
-
*
|
|
357
|
-
* @param params - Validation parameters.
|
|
358
|
-
* @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan.
|
|
359
|
-
* @param params.targetMarketId - Morpho Blue market receiving the liquidity.
|
|
360
|
-
* @param params.chainId - Chain whose allocator deployment is required for a V2 plan.
|
|
361
|
-
* @returns The validated plan tagged with its allocator version.
|
|
362
|
-
* @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
|
|
363
|
-
* @internal
|
|
364
|
-
*/
|
|
365
|
-
const validateAndNormalizeReallocations = ({ reallocations, targetMarketId, chainId, }) => {
|
|
366
|
-
const vaultV1Reallocations = [];
|
|
367
|
-
const vaultV2Reallocations = [];
|
|
368
|
-
for (const reallocation of reallocations ?? []) {
|
|
369
|
-
if (typeof reallocation !== "object" || reallocation === null) {
|
|
370
|
-
throw new index_js_1.InvalidReallocationShapeError();
|
|
371
|
-
}
|
|
372
|
-
if ("from" in reallocation === "withdrawals" in reallocation) {
|
|
373
|
-
throw new index_js_1.InvalidReallocationShapeError();
|
|
374
|
-
}
|
|
375
|
-
if ("withdrawals" in reallocation) {
|
|
376
|
-
vaultV1Reallocations.push(reallocation);
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
vaultV2Reallocations.push(reallocation);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
if (vaultV1Reallocations.length > 0 && vaultV2Reallocations.length > 0) {
|
|
383
|
-
throw new index_js_1.MixedReallocationVersionsError();
|
|
384
|
-
}
|
|
385
|
-
if (vaultV2Reallocations.length > 0) {
|
|
386
|
-
(0, exports.validateVaultV2BlueReallocations)(vaultV2Reallocations, targetMarketId);
|
|
387
|
-
if ((0, blue_sdk_1.getChainAddresses)(chainId).vaultV2BluePublicAllocator == null) {
|
|
388
|
-
throw new index_js_1.BundlerErrors.UnexpectedAction(vaultV2Reallocations[0]?.from.type === "market"
|
|
389
|
-
? "vaultV2BluePublicAllocatorReallocate"
|
|
390
|
-
: "vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
391
|
-
}
|
|
392
|
-
return {
|
|
393
|
-
type: "vaultV2Blue",
|
|
394
|
-
reallocations: vaultV2Reallocations,
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
(0, exports.validateReallocations)(vaultV1Reallocations, targetMarketId);
|
|
398
|
-
return { type: "vaultV1", reallocations: vaultV1Reallocations };
|
|
399
|
-
};
|
|
400
|
-
exports.validateAndNormalizeReallocations = validateAndNormalizeReallocations;
|
|
401
383
|
/**
|
|
402
384
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
403
385
|
*
|
|
@@ -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 = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1";
|
|
3
|
+
export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "blueBundlesV1";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that a requirement encoder spender matches one of the allowed chain addresses.
|
|
6
6
|
*
|
|
@@ -9,6 +9,7 @@ export type RequirementSpenderKey = "generalAdapter1" | "permit2" | "midnight" |
|
|
|
9
9
|
* @param params.spender - Spender address to validate.
|
|
10
10
|
* @param params.allowed - Allowed registry slots for this requirement.
|
|
11
11
|
* @returns Nothing after the spender matches an allowed chain address.
|
|
12
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
12
13
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` does not match any allowed slot.
|
|
13
14
|
* @example
|
|
14
15
|
* ```ts
|
|
@@ -12,6 +12,7 @@ const index_js_1 = require("../types/index.js");
|
|
|
12
12
|
* @param params.spender - Spender address to validate.
|
|
13
13
|
* @param params.allowed - Allowed registry slots for this requirement.
|
|
14
14
|
* @returns Nothing after the spender matches an allowed chain address.
|
|
15
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
15
16
|
* @throws {UnsupportedErc20ApprovalSpenderError} when `spender` does not match any allowed slot.
|
|
16
17
|
* @example
|
|
17
18
|
* ```ts
|
|
@@ -33,6 +34,7 @@ const validateRequirementSpender = (params) => {
|
|
|
33
34
|
midnight,
|
|
34
35
|
midnightBundles,
|
|
35
36
|
vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
|
|
37
|
+
blueBundlesV1: bundles?.blueBundlesV1,
|
|
36
38
|
};
|
|
37
39
|
const supportedSpenders = params.allowed.map((key) => addresses[key]);
|
|
38
40
|
if (!supportedSpenders.some((supported) => supported != null && (0, viem_1.isAddressEqual)(params.spender, supported))) {
|