@morpho-org/morpho-sdk 5.8.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 +62 -40
- package/lib/cjs/abis.d.ts +543 -0
- package/lib/cjs/abis.js +738 -0
- package/lib/cjs/actions/blue/borrow.d.ts +62 -58
- 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 -107
- package/lib/cjs/actions/blue/refinance.js +97 -197
- 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 -86
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +133 -119
- package/lib/cjs/actions/blue/withdraw.d.ts +68 -78
- 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/blue/types.d.ts +3 -1
- package/lib/cjs/blue/utils.d.ts +3 -1
- package/lib/cjs/blue/utils.js +1 -0
- package/lib/cjs/bundler/actions.d.ts +6 -4
- package/lib/cjs/bundler/actions.js +6 -4
- package/lib/cjs/bundler/types.d.ts +10 -1
- 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 +817 -360
- package/lib/cjs/entities/blue/blue.js +455 -698
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +4 -12
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/cjs/entities/vaultV1ReallocationData.js +11 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +6 -18
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/cjs/helpers/validate.d.ts +16 -23
- package/lib/cjs/helpers/validate.js +32 -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 +173 -18
- package/lib/cjs/types/error.js +230 -25
- package/lib/cjs/types/sharedLiquidity.d.ts +20 -4
- package/lib/cjs/types.d.ts +3 -1
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +1 -0
- package/lib/esm/abis.d.ts +543 -0
- package/lib/esm/abis.js +737 -0
- package/lib/esm/actions/blue/borrow.d.ts +62 -58
- 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 -107
- package/lib/esm/actions/blue/refinance.js +98 -198
- 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 -86
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +134 -120
- package/lib/esm/actions/blue/withdraw.d.ts +68 -78
- 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/blue/types.d.ts +3 -1
- package/lib/esm/blue/utils.d.ts +3 -1
- package/lib/esm/blue/utils.js +3 -1
- package/lib/esm/bundler/actions.d.ts +6 -4
- package/lib/esm/bundler/actions.js +6 -4
- package/lib/esm/bundler/types.d.ts +10 -1
- 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 +817 -360
- package/lib/esm/entities/blue/blue.js +461 -704
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +4 -12
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +18 -3
- package/lib/esm/entities/vaultV1ReallocationData.js +13 -2
- package/lib/esm/entities/vaultV2/vaultV2.js +7 -19
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +7 -10
- package/lib/esm/helpers/computeVaultV1Reallocations.js +7 -10
- package/lib/esm/helpers/validate.d.ts +16 -23
- package/lib/esm/helpers/validate.js +32 -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 +173 -18
- package/lib/esm/types/error.js +216 -21
- package/lib/esm/types/sharedLiquidity.d.ts +20 -4
- package/lib/esm/types.d.ts +3 -1
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -6
- 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`. */
|
|
@@ -32,9 +32,7 @@ class MorphoVaultV1 {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
35
|
-
|
|
36
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
37
|
-
}
|
|
35
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
38
36
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
39
37
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
40
38
|
}
|
|
@@ -101,9 +99,7 @@ class MorphoVaultV1 {
|
|
|
101
99
|
};
|
|
102
100
|
}
|
|
103
101
|
withdraw({ amount, userAddress }) {
|
|
104
|
-
|
|
105
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
106
|
-
}
|
|
102
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
107
103
|
return {
|
|
108
104
|
buildTx: () => (0, index_js_1.vaultV1Withdraw)({
|
|
109
105
|
vault: { address: this.vault },
|
|
@@ -117,9 +113,7 @@ class MorphoVaultV1 {
|
|
|
117
113
|
};
|
|
118
114
|
}
|
|
119
115
|
redeem({ shares, userAddress }) {
|
|
120
|
-
|
|
121
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
122
|
-
}
|
|
116
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
123
117
|
return {
|
|
124
118
|
buildTx: () => (0, index_js_1.vaultV1Redeem)({
|
|
125
119
|
vault: { address: this.vault },
|
|
@@ -134,9 +128,7 @@ class MorphoVaultV1 {
|
|
|
134
128
|
}
|
|
135
129
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
136
130
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
|
|
137
|
-
|
|
138
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
139
|
-
}
|
|
131
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
140
132
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
141
133
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
142
134
|
}
|
|
@@ -3,6 +3,9 @@ import type { Address } from "viem";
|
|
|
3
3
|
import type { PublicAllocatorOptions, PublicReallocation, ReallocationComputeOptions } from "../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Input state required to construct {@link VaultV1ReallocationData}.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
8
|
+
* `InputVaultV2BlueReallocationData`.
|
|
6
9
|
*/
|
|
7
10
|
export interface InputVaultV1ReallocationData {
|
|
8
11
|
/** Chain id associated with the fetched state. */
|
|
@@ -19,7 +22,8 @@ export interface InputVaultV1ReallocationData {
|
|
|
19
22
|
/**
|
|
20
23
|
* Deprecated input name for Vault V1 reallocation data.
|
|
21
24
|
*
|
|
22
|
-
* @deprecated
|
|
25
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
26
|
+
* `InputVaultV2BlueReallocationData`.
|
|
23
27
|
*/
|
|
24
28
|
export type InputReallocationData = InputVaultV1ReallocationData;
|
|
25
29
|
/**
|
|
@@ -35,6 +39,9 @@ export type InputReallocationData = InputVaultV1ReallocationData;
|
|
|
35
39
|
* `markets`, `vaults`, `positions`, and `vaultMarketConfigs` as a read
|
|
36
40
|
* contract keyed by market id or address; use the getters for typed absence
|
|
37
41
|
* errors and use simulation methods to produce updated state.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
44
|
+
* `VaultV2BlueReallocationData`.
|
|
38
45
|
*/
|
|
39
46
|
export declare class VaultV1ReallocationData implements InputVaultV1ReallocationData {
|
|
40
47
|
/** Chain id associated with the fetched reallocation data. */
|
|
@@ -128,6 +135,8 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
128
135
|
* @param options - Optional allocator discovery options.
|
|
129
136
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
130
137
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
138
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
139
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
131
140
|
* @example
|
|
132
141
|
* ```ts
|
|
133
142
|
* import { createPublicClient, http } from "viem";
|
|
@@ -171,7 +180,8 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
171
180
|
* @param options - Optional allocator discovery options.
|
|
172
181
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
173
182
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
174
|
-
* @deprecated
|
|
183
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
184
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
175
185
|
*/
|
|
176
186
|
getMarketPublicReallocations(marketId: MarketId, options?: PublicAllocatorOptions): {
|
|
177
187
|
readonly withdrawals: readonly PublicReallocation[];
|
|
@@ -190,6 +200,8 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
190
200
|
* @param options - Optional allocator discovery options.
|
|
191
201
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
192
202
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
203
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
204
|
+
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
193
205
|
* @example
|
|
194
206
|
* ```ts
|
|
195
207
|
* import { createPublicClient, http } from "viem";
|
|
@@ -241,6 +253,8 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
241
253
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
242
254
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
243
255
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
256
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
257
|
+
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
244
258
|
* @example
|
|
245
259
|
* ```ts
|
|
246
260
|
* import { createPublicClient, http, parseEther } from "viem";
|
|
@@ -306,6 +320,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
306
320
|
/**
|
|
307
321
|
* Deprecated class name for Vault V1 reallocation data.
|
|
308
322
|
*
|
|
309
|
-
* @deprecated
|
|
323
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
324
|
+
* `VaultV2BlueReallocationData`.
|
|
310
325
|
*/
|
|
311
326
|
export { VaultV1ReallocationData as ReallocationData };
|
|
@@ -60,6 +60,9 @@ const cloneVaultMarketConfig = (config) => new blue_sdk_1.VaultMarketConfig({
|
|
|
60
60
|
* `markets`, `vaults`, `positions`, and `vaultMarketConfigs` as a read
|
|
61
61
|
* contract keyed by market id or address; use the getters for typed absence
|
|
62
62
|
* errors and use simulation methods to produce updated state.
|
|
63
|
+
*
|
|
64
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
65
|
+
* `VaultV2BlueReallocationData`.
|
|
63
66
|
*/
|
|
64
67
|
class VaultV1ReallocationData {
|
|
65
68
|
/** Chain id associated with the fetched reallocation data. */
|
|
@@ -215,6 +218,8 @@ class VaultV1ReallocationData {
|
|
|
215
218
|
* @param options - Optional allocator discovery options.
|
|
216
219
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
217
220
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
221
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
222
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
218
223
|
* @example
|
|
219
224
|
* ```ts
|
|
220
225
|
* import { createPublicClient, http } from "viem";
|
|
@@ -310,7 +315,8 @@ class VaultV1ReallocationData {
|
|
|
310
315
|
* @param options - Optional allocator discovery options.
|
|
311
316
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
312
317
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
313
|
-
* @deprecated
|
|
318
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
319
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
314
320
|
*/
|
|
315
321
|
getMarketPublicReallocations(marketId, options = {}) {
|
|
316
322
|
return this.computeVaultV1Reallocations(marketId, options);
|
|
@@ -328,6 +334,8 @@ class VaultV1ReallocationData {
|
|
|
328
334
|
* @param options - Optional allocator discovery options.
|
|
329
335
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
330
336
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
337
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
338
|
+
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
331
339
|
* @example
|
|
332
340
|
* ```ts
|
|
333
341
|
* import { createPublicClient, http } from "viem";
|
|
@@ -382,6 +390,8 @@ class VaultV1ReallocationData {
|
|
|
382
390
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
383
391
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
384
392
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
393
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
394
|
+
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
385
395
|
* @example
|
|
386
396
|
* ```ts
|
|
387
397
|
* import { createPublicClient, http, parseEther } from "viem";
|
|
@@ -31,9 +31,7 @@ class MorphoVaultV2 {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
34
|
-
|
|
35
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
36
|
-
}
|
|
34
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
37
35
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
38
36
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
39
37
|
}
|
|
@@ -104,9 +102,7 @@ class MorphoVaultV2 {
|
|
|
104
102
|
};
|
|
105
103
|
}
|
|
106
104
|
withdraw({ amount, userAddress }) {
|
|
107
|
-
|
|
108
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
109
|
-
}
|
|
105
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
110
106
|
return {
|
|
111
107
|
buildTx: () => (0, index_js_1.vaultV2Withdraw)({
|
|
112
108
|
vault: { address: this.vault },
|
|
@@ -120,9 +116,7 @@ class MorphoVaultV2 {
|
|
|
120
116
|
};
|
|
121
117
|
}
|
|
122
118
|
redeem({ shares, userAddress }) {
|
|
123
|
-
|
|
124
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
125
|
-
}
|
|
119
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
126
120
|
return {
|
|
127
121
|
buildTx: () => (0, index_js_1.vaultV2Redeem)({
|
|
128
122
|
vault: { address: this.vault },
|
|
@@ -137,9 +131,7 @@ class MorphoVaultV2 {
|
|
|
137
131
|
}
|
|
138
132
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
139
133
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
|
|
140
|
-
|
|
141
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
142
|
-
}
|
|
134
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
143
135
|
if (!(0, viem_1.isAddressEqual)(vaultData.address, this.vault)) {
|
|
144
136
|
throw new index_js_3.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
145
137
|
}
|
|
@@ -316,9 +308,7 @@ class MorphoVaultV2 {
|
|
|
316
308
|
};
|
|
317
309
|
}
|
|
318
310
|
forceWithdraw({ deallocations, withdraw, userAddress, }) {
|
|
319
|
-
|
|
320
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
321
|
-
}
|
|
311
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
322
312
|
return {
|
|
323
313
|
buildTx: () => (0, index_js_1.vaultV2ForceWithdraw)({
|
|
324
314
|
vault: { address: this.vault },
|
|
@@ -335,9 +325,7 @@ class MorphoVaultV2 {
|
|
|
335
325
|
};
|
|
336
326
|
}
|
|
337
327
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
338
|
-
|
|
339
|
-
throw new index_js_3.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
340
|
-
}
|
|
328
|
+
(0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
341
329
|
return {
|
|
342
330
|
buildTx: () => (0, index_js_1.vaultV2ForceRedeem)({
|
|
343
331
|
vault: { address: this.vault },
|
|
@@ -25,6 +25,8 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
25
25
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
|
|
26
26
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
27
27
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
28
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
29
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
28
30
|
* @example
|
|
29
31
|
* ```ts
|
|
30
32
|
* import { createPublicClient, http, parseUnits } from "viem";
|
|
@@ -40,7 +42,6 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
40
42
|
* transport: http(),
|
|
41
43
|
* }).extend(morphoViemExtension());
|
|
42
44
|
*
|
|
43
|
-
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
44
45
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
45
46
|
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
46
47
|
* const block = await client.getBlock();
|
|
@@ -56,14 +57,9 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
|
|
|
56
57
|
* amount: borrowAmount,
|
|
57
58
|
* options: { timestamp: block.timestamp },
|
|
58
59
|
* });
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* amount: borrowAmount,
|
|
63
|
-
* positionData,
|
|
64
|
-
* reallocations,
|
|
65
|
-
* });
|
|
66
|
-
* // 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.
|
|
67
63
|
* ```
|
|
68
64
|
*/
|
|
69
65
|
export declare const computeVaultV1Reallocations: ({ reallocationData: data, marketId, operation, amount, options, }: {
|
|
@@ -76,6 +72,7 @@ export declare const computeVaultV1Reallocations: ({ reallocationData: data, mar
|
|
|
76
72
|
/**
|
|
77
73
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
78
74
|
*
|
|
79
|
-
* @deprecated
|
|
75
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
76
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
80
77
|
*/
|
|
81
78
|
export declare const computeReallocations: typeof computeVaultV1Reallocations;
|
|
@@ -81,6 +81,8 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
81
81
|
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
|
|
82
82
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
83
83
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
84
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
85
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
84
86
|
* @example
|
|
85
87
|
* ```ts
|
|
86
88
|
* import { createPublicClient, http, parseUnits } from "viem";
|
|
@@ -96,7 +98,6 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
96
98
|
* transport: http(),
|
|
97
99
|
* }).extend(morphoViemExtension());
|
|
98
100
|
*
|
|
99
|
-
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
100
101
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
101
102
|
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
102
103
|
* const block = await client.getBlock();
|
|
@@ -112,14 +113,9 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
112
113
|
* amount: borrowAmount,
|
|
113
114
|
* options: { timestamp: block.timestamp },
|
|
114
115
|
* });
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* amount: borrowAmount,
|
|
119
|
-
* positionData,
|
|
120
|
-
* reallocations,
|
|
121
|
-
* });
|
|
122
|
-
* // 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.
|
|
123
119
|
* ```
|
|
124
120
|
*/
|
|
125
121
|
const computeVaultV1Reallocations = ({ reallocationData: data, marketId, operation, amount, options, }) => {
|
|
@@ -241,6 +237,7 @@ exports.computeVaultV1Reallocations = computeVaultV1Reallocations;
|
|
|
241
237
|
/**
|
|
242
238
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
243
239
|
*
|
|
244
|
-
* @deprecated
|
|
240
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
241
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
245
242
|
*/
|
|
246
243
|
exports.computeReallocations = exports.computeVaultV1Reallocations;
|
|
@@ -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
|
*
|
|
@@ -148,6 +161,8 @@ export declare const validateRepayShares: (params: {
|
|
|
148
161
|
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
149
162
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
150
163
|
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
164
|
+
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
165
|
+
* reallocations for new integrations.
|
|
151
166
|
* @example
|
|
152
167
|
* ```ts
|
|
153
168
|
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
@@ -160,28 +175,6 @@ export declare const validateRepayShares: (params: {
|
|
|
160
175
|
export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
|
|
161
176
|
/** @internal */
|
|
162
177
|
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
|
|
163
|
-
/**
|
|
164
|
-
* Validates and normalizes a homogeneous Blue reallocation plan.
|
|
165
|
-
*
|
|
166
|
-
* @param params - Validation parameters.
|
|
167
|
-
* @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan.
|
|
168
|
-
* @param params.targetMarketId - Morpho Blue market receiving the liquidity.
|
|
169
|
-
* @param params.chainId - Chain whose allocator deployment is required for a V2 plan.
|
|
170
|
-
* @returns The validated plan tagged with its allocator version.
|
|
171
|
-
* @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
export declare const validateAndNormalizeReallocations: ({ reallocations, targetMarketId, chainId, }: {
|
|
175
|
-
readonly reallocations: BlueReallocationPlan | undefined;
|
|
176
|
-
readonly targetMarketId: MarketId;
|
|
177
|
-
readonly chainId: number;
|
|
178
|
-
}) => {
|
|
179
|
-
type: "vaultV2Blue";
|
|
180
|
-
reallocations: VaultV2BlueReallocation[];
|
|
181
|
-
} | {
|
|
182
|
-
type: "vaultV1";
|
|
183
|
-
reallocations: VaultV1Reallocation[];
|
|
184
|
-
};
|
|
185
178
|
/**
|
|
186
179
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
187
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
|
*
|
|
@@ -241,6 +261,8 @@ exports.validateRepayShares = validateRepayShares;
|
|
|
241
261
|
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
242
262
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
243
263
|
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
264
|
+
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
265
|
+
* reallocations for new integrations.
|
|
244
266
|
* @example
|
|
245
267
|
* ```ts
|
|
246
268
|
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
@@ -279,6 +301,15 @@ exports.validateReallocations = validateReallocations;
|
|
|
279
301
|
const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
280
302
|
const penaltyByVault = new Map();
|
|
281
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
|
+
}
|
|
282
313
|
if (typeof reallocation.vault !== "string" ||
|
|
283
314
|
!(0, viem_1.isAddress)(reallocation.vault)) {
|
|
284
315
|
throw new index_js_1.InvalidReallocationAddressError("vault");
|
|
@@ -349,53 +380,6 @@ const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
|
349
380
|
}
|
|
350
381
|
};
|
|
351
382
|
exports.validateVaultV2BlueReallocations = validateVaultV2BlueReallocations;
|
|
352
|
-
/**
|
|
353
|
-
* Validates and normalizes a homogeneous Blue reallocation plan.
|
|
354
|
-
*
|
|
355
|
-
* @param params - Validation parameters.
|
|
356
|
-
* @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan.
|
|
357
|
-
* @param params.targetMarketId - Morpho Blue market receiving the liquidity.
|
|
358
|
-
* @param params.chainId - Chain whose allocator deployment is required for a V2 plan.
|
|
359
|
-
* @returns The validated plan tagged with its allocator version.
|
|
360
|
-
* @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
|
|
361
|
-
* @internal
|
|
362
|
-
*/
|
|
363
|
-
const validateAndNormalizeReallocations = ({ reallocations, targetMarketId, chainId, }) => {
|
|
364
|
-
const vaultV1Reallocations = [];
|
|
365
|
-
const vaultV2Reallocations = [];
|
|
366
|
-
for (const reallocation of reallocations ?? []) {
|
|
367
|
-
if (typeof reallocation !== "object" || reallocation === null) {
|
|
368
|
-
throw new index_js_1.InvalidReallocationShapeError();
|
|
369
|
-
}
|
|
370
|
-
if ("from" in reallocation === "withdrawals" in reallocation) {
|
|
371
|
-
throw new index_js_1.InvalidReallocationShapeError();
|
|
372
|
-
}
|
|
373
|
-
if ("withdrawals" in reallocation) {
|
|
374
|
-
vaultV1Reallocations.push(reallocation);
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
vaultV2Reallocations.push(reallocation);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (vaultV1Reallocations.length > 0 && vaultV2Reallocations.length > 0) {
|
|
381
|
-
throw new index_js_1.MixedReallocationVersionsError();
|
|
382
|
-
}
|
|
383
|
-
if (vaultV2Reallocations.length > 0) {
|
|
384
|
-
(0, exports.validateVaultV2BlueReallocations)(vaultV2Reallocations, targetMarketId);
|
|
385
|
-
if ((0, blue_sdk_1.getChainAddresses)(chainId).vaultV2BluePublicAllocator == null) {
|
|
386
|
-
throw new index_js_1.BundlerErrors.UnexpectedAction(vaultV2Reallocations[0]?.from.type === "market"
|
|
387
|
-
? "vaultV2BluePublicAllocatorReallocate"
|
|
388
|
-
: "vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
389
|
-
}
|
|
390
|
-
return {
|
|
391
|
-
type: "vaultV2Blue",
|
|
392
|
-
reallocations: vaultV2Reallocations,
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
(0, exports.validateReallocations)(vaultV1Reallocations, targetMarketId);
|
|
396
|
-
return { type: "vaultV1", reallocations: vaultV1Reallocations };
|
|
397
|
-
};
|
|
398
|
-
exports.validateAndNormalizeReallocations = validateAndNormalizeReallocations;
|
|
399
383
|
/**
|
|
400
384
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
401
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))) {
|