@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`. */
|
|
@@ -29,9 +29,7 @@ export class MorphoVaultV1 {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
32
|
-
|
|
33
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
34
|
-
}
|
|
32
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
35
33
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
36
34
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
37
35
|
}
|
|
@@ -98,9 +96,7 @@ export class MorphoVaultV1 {
|
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
withdraw({ amount, userAddress }) {
|
|
101
|
-
|
|
102
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
103
|
-
}
|
|
99
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
104
100
|
return {
|
|
105
101
|
buildTx: () => vaultV1Withdraw({
|
|
106
102
|
vault: { address: this.vault },
|
|
@@ -114,9 +110,7 @@ export class MorphoVaultV1 {
|
|
|
114
110
|
};
|
|
115
111
|
}
|
|
116
112
|
redeem({ shares, userAddress }) {
|
|
117
|
-
|
|
118
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
119
|
-
}
|
|
113
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
120
114
|
return {
|
|
121
115
|
buildTx: () => vaultV1Redeem({
|
|
122
116
|
vault: { address: this.vault },
|
|
@@ -131,9 +125,7 @@ export class MorphoVaultV1 {
|
|
|
131
125
|
}
|
|
132
126
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
133
127
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
|
|
134
|
-
|
|
135
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
136
|
-
}
|
|
128
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
137
129
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
138
130
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
139
131
|
}
|
|
@@ -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 };
|
|
@@ -57,6 +57,9 @@ const cloneVaultMarketConfig = (config) => new VaultMarketConfig({
|
|
|
57
57
|
* `markets`, `vaults`, `positions`, and `vaultMarketConfigs` as a read
|
|
58
58
|
* contract keyed by market id or address; use the getters for typed absence
|
|
59
59
|
* errors and use simulation methods to produce updated state.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
62
|
+
* `VaultV2BlueReallocationData`.
|
|
60
63
|
*/
|
|
61
64
|
export class VaultV1ReallocationData {
|
|
62
65
|
/** Chain id associated with the fetched reallocation data. */
|
|
@@ -212,6 +215,8 @@ export class VaultV1ReallocationData {
|
|
|
212
215
|
* @param options - Optional allocator discovery options.
|
|
213
216
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
214
217
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
218
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
219
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
215
220
|
* @example
|
|
216
221
|
* ```ts
|
|
217
222
|
* import { createPublicClient, http } from "viem";
|
|
@@ -307,7 +312,8 @@ export class VaultV1ReallocationData {
|
|
|
307
312
|
* @param options - Optional allocator discovery options.
|
|
308
313
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
309
314
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
310
|
-
* @deprecated
|
|
315
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
316
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
311
317
|
*/
|
|
312
318
|
getMarketPublicReallocations(marketId, options = {}) {
|
|
313
319
|
return this.computeVaultV1Reallocations(marketId, options);
|
|
@@ -325,6 +331,8 @@ export class VaultV1ReallocationData {
|
|
|
325
331
|
* @param options - Optional allocator discovery options.
|
|
326
332
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
327
333
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
334
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
335
|
+
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
328
336
|
* @example
|
|
329
337
|
* ```ts
|
|
330
338
|
* import { createPublicClient, http } from "viem";
|
|
@@ -379,6 +387,8 @@ export class VaultV1ReallocationData {
|
|
|
379
387
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
380
388
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
381
389
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
390
|
+
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
391
|
+
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
382
392
|
* @example
|
|
383
393
|
* ```ts
|
|
384
394
|
* import { createPublicClient, http, parseEther } from "viem";
|
|
@@ -528,6 +538,7 @@ export class VaultV1ReallocationData {
|
|
|
528
538
|
/**
|
|
529
539
|
* Deprecated class name for Vault V1 reallocation data.
|
|
530
540
|
*
|
|
531
|
-
* @deprecated
|
|
541
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
542
|
+
* `VaultV2BlueReallocationData`.
|
|
532
543
|
*/
|
|
533
544
|
export { VaultV1ReallocationData as ReallocationData };
|
|
@@ -4,7 +4,7 @@ import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
|
4
4
|
import { erc20Abi, isAddressEqual } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
6
|
import { encodeErc20Approval, encodeVaultSharesPermit, getGeneralAdapterRequirements, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
7
|
-
import { validateSlippageTolerance } from "../../helpers/index.js";
|
|
7
|
+
import { validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
8
8
|
import { AdapterNotPartOfVaultError, ChainIdMismatchError, ChainWNativeMissingError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemRequiresSingleAdapterError, InKindRedeemZeroDeallocationError, InsufficientBlueBalanceForInKindRedeemError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, selectRequirementSignatures, UnsupportedInKindAdapterError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
9
9
|
export class MorphoVaultV2 {
|
|
10
10
|
client;
|
|
@@ -28,9 +28,7 @@ export class MorphoVaultV2 {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
deposit({ amount = 0n, userAddress, vaultData, slippageTolerance = DEFAULT_SLIPPAGE_TOLERANCE, nativeAmount, }) {
|
|
31
|
-
|
|
32
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
33
|
-
}
|
|
31
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
34
32
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
35
33
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
36
34
|
}
|
|
@@ -101,9 +99,7 @@ export class MorphoVaultV2 {
|
|
|
101
99
|
};
|
|
102
100
|
}
|
|
103
101
|
withdraw({ amount, userAddress }) {
|
|
104
|
-
|
|
105
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
106
|
-
}
|
|
102
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
107
103
|
return {
|
|
108
104
|
buildTx: () => vaultV2Withdraw({
|
|
109
105
|
vault: { address: this.vault },
|
|
@@ -117,9 +113,7 @@ export class MorphoVaultV2 {
|
|
|
117
113
|
};
|
|
118
114
|
}
|
|
119
115
|
redeem({ shares, userAddress }) {
|
|
120
|
-
|
|
121
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
122
|
-
}
|
|
116
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
123
117
|
return {
|
|
124
118
|
buildTx: () => vaultV2Redeem({
|
|
125
119
|
vault: { address: this.vault },
|
|
@@ -134,9 +128,7 @@ export class MorphoVaultV2 {
|
|
|
134
128
|
}
|
|
135
129
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
136
130
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }) {
|
|
137
|
-
|
|
138
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
139
|
-
}
|
|
131
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
140
132
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
141
133
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
142
134
|
}
|
|
@@ -313,9 +305,7 @@ export class MorphoVaultV2 {
|
|
|
313
305
|
};
|
|
314
306
|
}
|
|
315
307
|
forceWithdraw({ deallocations, withdraw, userAddress, }) {
|
|
316
|
-
|
|
317
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
318
|
-
}
|
|
308
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
319
309
|
return {
|
|
320
310
|
buildTx: () => vaultV2ForceWithdraw({
|
|
321
311
|
vault: { address: this.vault },
|
|
@@ -332,9 +322,7 @@ export class MorphoVaultV2 {
|
|
|
332
322
|
};
|
|
333
323
|
}
|
|
334
324
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
335
|
-
|
|
336
|
-
throw new ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
337
|
-
}
|
|
325
|
+
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
338
326
|
return {
|
|
339
327
|
buildTx: () => vaultV2ForceRedeem({
|
|
340
328
|
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;
|
|
@@ -78,6 +78,8 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
78
78
|
* @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.
|
|
79
79
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
|
|
80
80
|
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
81
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
82
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
81
83
|
* @example
|
|
82
84
|
* ```ts
|
|
83
85
|
* import { createPublicClient, http, parseUnits } from "viem";
|
|
@@ -93,7 +95,6 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
93
95
|
* transport: http(),
|
|
94
96
|
* }).extend(morphoViemExtension());
|
|
95
97
|
*
|
|
96
|
-
* const userAddress = "0x000000000000000000000000000000000000dEaD";
|
|
97
98
|
* const marketParams = markets[mainnet.id].usdc_wbtc;
|
|
98
99
|
* const market = client.morpho.blue(marketParams, mainnet.id);
|
|
99
100
|
* const block = await client.getBlock();
|
|
@@ -109,14 +110,9 @@ const capVaultWithdrawals = (withdrawals, assets) => {
|
|
|
109
110
|
* amount: borrowAmount,
|
|
110
111
|
* options: { timestamp: block.timestamp },
|
|
111
112
|
* });
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* amount: borrowAmount,
|
|
116
|
-
* positionData,
|
|
117
|
-
* reallocations,
|
|
118
|
-
* });
|
|
119
|
-
* // borrow.buildTx() includes any required PublicAllocator reallocations.
|
|
113
|
+
* // Encode `reallocations` explicitly with
|
|
114
|
+
* // BundlerAction.publicAllocatorReallocateTo(...) when composing a low-level bundle.
|
|
115
|
+
* // High-level Blue writes accept Vault V2 reallocations only.
|
|
120
116
|
* ```
|
|
121
117
|
*/
|
|
122
118
|
export const computeVaultV1Reallocations = ({ reallocationData: data, marketId, operation, amount, options, }) => {
|
|
@@ -237,6 +233,7 @@ export const computeVaultV1Reallocations = ({ reallocationData: data, marketId,
|
|
|
237
233
|
/**
|
|
238
234
|
* Deprecated name for the Vault V1 amount-aware reallocation planner.
|
|
239
235
|
*
|
|
240
|
-
* @deprecated
|
|
236
|
+
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
237
|
+
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
241
238
|
*/
|
|
242
239
|
export const computeReallocations = 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,7 +1,7 @@
|
|
|
1
1
|
import { getChainAddresses, MarketUtils, MathLib, ORACLE_PRICE_SCALE, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { isDefined } from "@morpho-org/morpho-ts";
|
|
3
|
-
import { isAddress, isAddressEqual, maxUint128 } from "viem";
|
|
4
|
-
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError,
|
|
3
|
+
import { isAddress, isAddressEqual, maxUint128, maxUint256, } from "viem";
|
|
4
|
+
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, EmptyReallocationWithdrawalsError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationShapeError, InvalidReallocationSourceTypeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, RepayExceedsDebtError, RepaySharesExceedDebtError, UnsortedReallocationWithdrawalsError, WithdrawExceedsCollateralError, WithdrawExceedsSupplyError, WithdrawMakesPositionUnhealthyError, WithdrawSharesExceedSupplyError, } from "../types/index.js";
|
|
5
5
|
import { DEFAULT_LLTV_BUFFER, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, } from "./constant.js";
|
|
6
6
|
/** @internal */
|
|
7
7
|
export const compareMarketIds = (idA, idB) => {
|
|
@@ -13,6 +13,25 @@ export const compareMarketIds = (idA, idB) => {
|
|
|
13
13
|
return -1;
|
|
14
14
|
return 0;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Rejects a `bigint` field that falls outside the unsigned 256-bit ABI range so a direct caller
|
|
18
|
+
* gets the SDK's typed error instead of viem's `IntegerOutOfRangeError` at encode time. `maxUint256`
|
|
19
|
+
* stays valid — it is the accepted `maxLtv` / full-repay `repayShares` sentinel.
|
|
20
|
+
*
|
|
21
|
+
* @param field - Field name surfaced in the thrown error.
|
|
22
|
+
* @param value - Candidate value; must be in `[0, maxUint256]`.
|
|
23
|
+
* @returns Nothing when `value` is within range.
|
|
24
|
+
* @throws {NegativeInputError} when `value` is negative.
|
|
25
|
+
* @throws {InputExceedsMaxError} when `value` exceeds `maxUint256`.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export const validateUint256Field = (field, value) => {
|
|
29
|
+
if (value < 0n)
|
|
30
|
+
throw new NegativeInputError(field, value);
|
|
31
|
+
if (value > maxUint256) {
|
|
32
|
+
throw new InputExceedsMaxError({ field, value, max: maxUint256 });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
16
35
|
/**
|
|
17
36
|
* Validates that a raw or hydrated Midnight market belongs to the expected chain.
|
|
18
37
|
*
|
|
@@ -228,6 +247,8 @@ export const validateRepayShares = (params) => {
|
|
|
228
247
|
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
229
248
|
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
230
249
|
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
250
|
+
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
251
|
+
* reallocations for new integrations.
|
|
231
252
|
* @example
|
|
232
253
|
* ```ts
|
|
233
254
|
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
@@ -265,6 +286,15 @@ export const validateReallocations = (reallocations, targetMarketId) => {
|
|
|
265
286
|
export const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
266
287
|
const penaltyByVault = new Map();
|
|
267
288
|
for (const reallocation of reallocations) {
|
|
289
|
+
// Reject non-object entries and Vault V1-shaped entries (which carry
|
|
290
|
+
// `withdrawals`/`fee`) with a typed, instructive error instead of a raw
|
|
291
|
+
// TypeError or a misleading `to.adapter` address error.
|
|
292
|
+
if (typeof reallocation !== "object" ||
|
|
293
|
+
reallocation === null ||
|
|
294
|
+
"withdrawals" in reallocation ||
|
|
295
|
+
"fee" in reallocation) {
|
|
296
|
+
throw new InvalidReallocationShapeError();
|
|
297
|
+
}
|
|
268
298
|
if (typeof reallocation.vault !== "string" ||
|
|
269
299
|
!isAddress(reallocation.vault)) {
|
|
270
300
|
throw new InvalidReallocationAddressError("vault");
|
|
@@ -334,52 +364,6 @@ export const validateVaultV2BlueReallocations = (reallocations, targetMarketId)
|
|
|
334
364
|
}
|
|
335
365
|
}
|
|
336
366
|
};
|
|
337
|
-
/**
|
|
338
|
-
* Validates and normalizes a homogeneous Blue reallocation plan.
|
|
339
|
-
*
|
|
340
|
-
* @param params - Validation parameters.
|
|
341
|
-
* @param params.reallocations - Optional Vault V1 or Vault V2 reallocation plan.
|
|
342
|
-
* @param params.targetMarketId - Morpho Blue market receiving the liquidity.
|
|
343
|
-
* @param params.chainId - Chain whose allocator deployment is required for a V2 plan.
|
|
344
|
-
* @returns The validated plan tagged with its allocator version.
|
|
345
|
-
* @throws {BundlerErrors.UnexpectedAction} when a V2 plan is unsupported on the chain.
|
|
346
|
-
* @internal
|
|
347
|
-
*/
|
|
348
|
-
export const validateAndNormalizeReallocations = ({ reallocations, targetMarketId, chainId, }) => {
|
|
349
|
-
const vaultV1Reallocations = [];
|
|
350
|
-
const vaultV2Reallocations = [];
|
|
351
|
-
for (const reallocation of reallocations ?? []) {
|
|
352
|
-
if (typeof reallocation !== "object" || reallocation === null) {
|
|
353
|
-
throw new InvalidReallocationShapeError();
|
|
354
|
-
}
|
|
355
|
-
if ("from" in reallocation === "withdrawals" in reallocation) {
|
|
356
|
-
throw new InvalidReallocationShapeError();
|
|
357
|
-
}
|
|
358
|
-
if ("withdrawals" in reallocation) {
|
|
359
|
-
vaultV1Reallocations.push(reallocation);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
vaultV2Reallocations.push(reallocation);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
if (vaultV1Reallocations.length > 0 && vaultV2Reallocations.length > 0) {
|
|
366
|
-
throw new MixedReallocationVersionsError();
|
|
367
|
-
}
|
|
368
|
-
if (vaultV2Reallocations.length > 0) {
|
|
369
|
-
validateVaultV2BlueReallocations(vaultV2Reallocations, targetMarketId);
|
|
370
|
-
if (getChainAddresses(chainId).vaultV2BluePublicAllocator == null) {
|
|
371
|
-
throw new BundlerErrors.UnexpectedAction(vaultV2Reallocations[0]?.from.type === "market"
|
|
372
|
-
? "vaultV2BluePublicAllocatorReallocate"
|
|
373
|
-
: "vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
374
|
-
}
|
|
375
|
-
return {
|
|
376
|
-
type: "vaultV2Blue",
|
|
377
|
-
reallocations: vaultV2Reallocations,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
validateReallocations(vaultV1Reallocations, targetMarketId);
|
|
381
|
-
return { type: "vaultV1", reallocations: vaultV1Reallocations };
|
|
382
|
-
};
|
|
383
367
|
/**
|
|
384
368
|
* Validates that a slippage tolerance is within an acceptable range.
|
|
385
369
|
*
|
|
@@ -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
|
|
@@ -9,6 +9,7 @@ import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
|
|
|
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
|
|
@@ -30,6 +31,7 @@ export const validateRequirementSpender = (params) => {
|
|
|
30
31
|
midnight,
|
|
31
32
|
midnightBundles,
|
|
32
33
|
vaultExitBundlesV1: bundles?.vaultExitBundlesV1,
|
|
34
|
+
blueBundlesV1: bundles?.blueBundlesV1,
|
|
33
35
|
};
|
|
34
36
|
const supportedSpenders = params.allowed.map((key) => addresses[key]);
|
|
35
37
|
if (!supportedSpenders.some((supported) => supported != null && isAddressEqual(params.spender, supported))) {
|