@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.3
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 +83 -29
- package/README.md +9 -7
- package/lib/cjs/abis.d.ts +3 -2844
- package/lib/cjs/abis.js +1 -1951
- package/lib/cjs/actions/blue/borrow.d.ts +3 -2
- package/lib/cjs/actions/blue/borrow.js +3 -2
- package/lib/cjs/actions/blue/common.js +1 -9
- package/lib/cjs/actions/blue/refinance.d.ts +2 -2
- package/lib/cjs/actions/blue/refinance.js +2 -2
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/cjs/actions/blue/supply.d.ts +2 -2
- package/lib/cjs/actions/blue/supply.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +3 -3
- package/lib/cjs/actions/blue/withdraw.js +3 -3
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/bundles/common.d.ts +6 -2
- package/lib/cjs/actions/bundles/common.js +23 -5
- package/lib/cjs/actions/index.d.ts +0 -1
- package/lib/cjs/actions/index.js +0 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -16
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/cjs/actions/requirements/encode/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/encode/index.js +0 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/cjs/actions/requirements/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/index.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV1/deposit.js +1 -2
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/cjs/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/cjs/actions/vaultV2/deposit.js +1 -2
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -5
- package/lib/cjs/blue/abis.js +1 -7
- package/lib/cjs/blue/entities.d.ts +2 -8
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/fetch.d.ts +1 -3
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +1 -3
- package/lib/cjs/blue/utils.js +1 -3
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -1
- package/lib/cjs/constants.d.ts +3 -37
- package/lib/cjs/constants.js +1 -39
- package/lib/cjs/entities/blue/blue.d.ts +30 -265
- package/lib/cjs/entities/blue/blue.js +1 -205
- package/lib/cjs/entities/index.d.ts +3 -66
- package/lib/cjs/entities/index.js +1 -21
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/cjs/entities/vaultV1/vaultV1.js +12 -7
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/cjs/entities/vaultV2/vaultV2.js +28 -15
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +1 -46
- package/lib/cjs/fetch.d.ts +1 -17
- package/lib/cjs/fetch.js +1 -17
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +2 -3
- package/lib/cjs/helpers/index.js +1 -9
- package/lib/cjs/helpers/slippage.d.ts +1 -103
- package/lib/cjs/helpers/slippage.js +0 -150
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +1 -24
- package/lib/cjs/helpers/validate.js +2 -49
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/types/action.d.ts +17 -65
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +50 -381
- package/lib/cjs/types/error.js +64 -395
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +6 -35
- package/lib/cjs/utils.js +2 -36
- package/lib/esm/abis.d.ts +3 -2844
- package/lib/esm/abis.js +3 -1950
- package/lib/esm/actions/blue/borrow.d.ts +3 -2
- package/lib/esm/actions/blue/borrow.js +3 -2
- package/lib/esm/actions/blue/common.js +1 -9
- package/lib/esm/actions/blue/refinance.d.ts +2 -2
- package/lib/esm/actions/blue/refinance.js +2 -2
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +2 -2
- package/lib/esm/actions/blue/supply.d.ts +2 -2
- package/lib/esm/actions/blue/supply.js +2 -2
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/supplyCollateral.js +2 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -2
- package/lib/esm/actions/blue/withdraw.d.ts +3 -3
- package/lib/esm/actions/blue/withdraw.js +3 -3
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -2
- package/lib/esm/actions/bundles/common.d.ts +6 -2
- package/lib/esm/actions/bundles/common.js +24 -6
- package/lib/esm/actions/index.d.ts +0 -1
- package/lib/esm/actions/index.js +0 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +12 -17
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +4 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +5 -5
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +6 -11
- package/lib/esm/actions/requirements/encode/index.d.ts +0 -1
- package/lib/esm/actions/requirements/encode/index.js +0 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +5 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -6
- package/lib/esm/actions/requirements/index.d.ts +0 -1
- package/lib/esm/actions/requirements/index.js +0 -1
- package/lib/esm/actions/vaultV1/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV1/deposit.js +1 -2
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV1/inKindRedeem.js +10 -7
- package/lib/esm/actions/vaultV2/deposit.d.ts +1 -2
- package/lib/esm/actions/vaultV2/deposit.js +1 -2
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -5
- package/lib/esm/actions/vaultV2/inKindRedeem.js +10 -7
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -5
- package/lib/esm/blue/abis.js +1 -5
- package/lib/esm/blue/entities.d.ts +2 -8
- package/lib/esm/blue/entities.js +1 -3
- package/lib/esm/blue/fetch.d.ts +1 -3
- package/lib/esm/blue/fetch.js +1 -3
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +1 -3
- package/lib/esm/blue/utils.js +1 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -1
- package/lib/esm/constants.d.ts +3 -37
- package/lib/esm/constants.js +3 -37
- package/lib/esm/entities/blue/blue.d.ts +30 -265
- package/lib/esm/entities/blue/blue.js +4 -208
- package/lib/esm/entities/index.d.ts +3 -66
- package/lib/esm/entities/index.js +1 -18
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +9 -2
- package/lib/esm/entities/vaultV1/vaultV1.js +15 -10
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +22 -9
- package/lib/esm/entities/vaultV2/vaultV2.js +32 -19
- package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -17
- package/lib/esm/fetch.js +1 -17
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +2 -3
- package/lib/esm/helpers/index.js +2 -3
- package/lib/esm/helpers/slippage.d.ts +1 -103
- package/lib/esm/helpers/slippage.js +1 -147
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +1 -24
- package/lib/esm/helpers/validate.js +2 -48
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/types/action.d.ts +17 -65
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +50 -381
- package/lib/esm/types/error.js +58 -377
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +6 -35
- package/lib/esm/utils.js +5 -34
- package/package.json +5 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -152
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -53
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -74
- package/lib/cjs/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/cjs/actions/requirements/generalAdapter/index.js +0 -19
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/cjs/actions/signatures/getBlueAuthorizationAction.js +0 -48
- package/lib/cjs/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +0 -119
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -45
- package/lib/cjs/actions/signatures/index.d.ts +0 -3
- package/lib/cjs/actions/signatures/index.js +0 -19
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +0 -8
- package/lib/cjs/bundler/actions.d.ts +0 -797
- package/lib/cjs/bundler/actions.js +0 -1371
- package/lib/cjs/bundler/index.d.ts +0 -2
- package/lib/cjs/bundler/index.js +0 -18
- package/lib/cjs/bundler/types.d.ts +0 -235
- package/lib/cjs/bundler/types.js +0 -2
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -557
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -245
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -44
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -84
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -148
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -40
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -49
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +0 -57
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +0 -70
- package/lib/esm/actions/requirements/generalAdapter/index.d.ts +0 -3
- package/lib/esm/actions/requirements/generalAdapter/index.js +0 -3
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.d.ts +0 -29
- package/lib/esm/actions/signatures/getBlueAuthorizationAction.js +0 -44
- package/lib/esm/actions/signatures/getTokenRequirementActions.d.ts +0 -58
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +0 -115
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +0 -50
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -41
- package/lib/esm/actions/signatures/index.d.ts +0 -3
- package/lib/esm/actions/signatures/index.js +0 -3
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +0 -11
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -7
- package/lib/esm/bundler/actions.d.ts +0 -797
- package/lib/esm/bundler/actions.js +0 -1368
- package/lib/esm/bundler/index.d.ts +0 -2
- package/lib/esm/bundler/index.js +0 -2
- package/lib/esm/bundler/types.d.ts +0 -235
- package/lib/esm/bundler/types.js +0 -1
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +0 -332
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -559
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -80
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -241
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket,
|
|
2
|
+
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
|
-
import {
|
|
4
|
+
import { isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
|
|
6
6
|
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
8
8
|
import { ExpiredDeadlineError, InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
9
9
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
10
|
-
import { VaultV1ReallocationData } from "../vaultV1ReallocationData.js";
|
|
11
10
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
12
11
|
export class MorphoBlue {
|
|
13
12
|
client;
|
|
@@ -78,7 +77,6 @@ export class MorphoBlue {
|
|
|
78
77
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
79
78
|
return fetchMarket(this.marketParams.id, this.client.viemClient, {
|
|
80
79
|
...parameters,
|
|
81
|
-
chainId: this.chainId,
|
|
82
80
|
deployless: this.client.options.supportDeployless,
|
|
83
81
|
});
|
|
84
82
|
}
|
|
@@ -87,7 +85,6 @@ export class MorphoBlue {
|
|
|
87
85
|
return fetchAccrualPosition(userAddress, this.marketParams.id, this.client.viemClient, {
|
|
88
86
|
...parameters,
|
|
89
87
|
deployless: this.client.options.supportDeployless,
|
|
90
|
-
chainId: this.chainId,
|
|
91
88
|
});
|
|
92
89
|
}
|
|
93
90
|
/** {@inheritDoc BlueActions.supply} */
|
|
@@ -438,14 +435,7 @@ export class MorphoBlue {
|
|
|
438
435
|
? this.getTokenRequirements({
|
|
439
436
|
token: this.marketParams.loanToken,
|
|
440
437
|
amount: maxRepayAssets,
|
|
441
|
-
|
|
442
|
-
// the token's reusable cap. Checksum the key so a differently-cased loan token
|
|
443
|
-
// (common from subgraphs/APIs) resolves that cap instead of falling back to
|
|
444
|
-
// maxUint256, which UNI/ONDO/COMP/FLUID reject.
|
|
445
|
-
approvalAmount: requirementsParams?.approvalAmount ??
|
|
446
|
-
(saturatedRepay
|
|
447
|
-
? (MAX_TOKEN_APPROVALS[this.chainId]?.[getAddress(this.marketParams.loanToken)] ?? maxUint256)
|
|
448
|
-
: undefined),
|
|
438
|
+
approvalAmount: requirementsParams?.approvalAmount,
|
|
449
439
|
userAddress,
|
|
450
440
|
deadline,
|
|
451
441
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
@@ -659,120 +649,6 @@ export class MorphoBlue {
|
|
|
659
649
|
},
|
|
660
650
|
};
|
|
661
651
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Fetches all on-chain inputs needed to compute public allocator reallocations.
|
|
664
|
-
*
|
|
665
|
-
* @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
|
|
666
|
-
* @param params.block.number - Block number used for every RPC read.
|
|
667
|
-
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
668
|
-
* @returns Reallocation data ready for {@link getVaultV1Reallocations}.
|
|
669
|
-
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
670
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
671
|
-
* {@link getVaultV2BlueReallocationData}.
|
|
672
|
-
* @example
|
|
673
|
-
* ```ts
|
|
674
|
-
* import { markets, vaults } from "@morpho-org/morpho-test";
|
|
675
|
-
* import { createPublicClient, http } from "viem";
|
|
676
|
-
* import { mainnet } from "viem/chains";
|
|
677
|
-
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
678
|
-
* import type { VaultV1ReallocationData } from "@morpho-org/morpho-sdk/entities";
|
|
679
|
-
*
|
|
680
|
-
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
681
|
-
* .extend(morphoViemExtension());
|
|
682
|
-
* const market = client.morpho.blue(markets[mainnet.id].usdc_wbtc, mainnet.id);
|
|
683
|
-
* const block = await client.getBlock();
|
|
684
|
-
* const data: VaultV1ReallocationData = await market.getVaultV1ReallocationData({
|
|
685
|
-
* vaultAddresses: [vaults[mainnet.id].steakUsdc.address],
|
|
686
|
-
* block,
|
|
687
|
-
* });
|
|
688
|
-
* ```
|
|
689
|
-
*/
|
|
690
|
-
async getVaultV1ReallocationData({ vaultAddresses, block, }) {
|
|
691
|
-
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
692
|
-
const client = this.client.viemClient;
|
|
693
|
-
const fetchParams = {
|
|
694
|
-
blockNumber: block.number,
|
|
695
|
-
chainId: this.chainId,
|
|
696
|
-
deployless: this.client.options.supportDeployless,
|
|
697
|
-
};
|
|
698
|
-
const targetMarketId = this.marketParams.id;
|
|
699
|
-
// Phase 1: Fetch the target market and all vaults at `block.number` in
|
|
700
|
-
// parallel so every row of the resulting state comes from the same epoch
|
|
701
|
-
// and the planner never trusts a caller-owned target-market snapshot.
|
|
702
|
-
const [targetMarket, vaults] = await Promise.all([
|
|
703
|
-
fetchMarket(targetMarketId, client, fetchParams),
|
|
704
|
-
Promise.all(vaultAddresses.map((addr) => fetchVault(addr, client, fetchParams))),
|
|
705
|
-
]);
|
|
706
|
-
const allMarketIds = new Set([targetMarketId]);
|
|
707
|
-
const vaultMarketPairs = [];
|
|
708
|
-
for (const vault of vaults) {
|
|
709
|
-
// Always include target market pair so its config/position is fetched
|
|
710
|
-
// even when the target market is only in the vault's supplyQueue.
|
|
711
|
-
vaultMarketPairs.push({ vault: vault.address, marketId: targetMarketId });
|
|
712
|
-
for (const mid of vault.withdrawQueue) {
|
|
713
|
-
allMarketIds.add(mid);
|
|
714
|
-
if (mid !== targetMarketId) {
|
|
715
|
-
vaultMarketPairs.push({ vault: vault.address, marketId: mid });
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
// Phase 2: Fetch all source markets, vault configs, and positions in parallel.
|
|
720
|
-
const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
|
|
721
|
-
const [markets, configs, positions] = await Promise.all([
|
|
722
|
-
Promise.all(sourceMarketIds.map((mid) => fetchMarket(mid, client, fetchParams))),
|
|
723
|
-
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchVaultMarketConfig(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
|
|
724
|
-
Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => fetchPosition(vault, mid, client, fetchParams).then((position) => ({
|
|
725
|
-
vault,
|
|
726
|
-
mid,
|
|
727
|
-
position,
|
|
728
|
-
})))),
|
|
729
|
-
]);
|
|
730
|
-
// Assemble records for VaultV1ReallocationData.
|
|
731
|
-
const marketsRecord = {
|
|
732
|
-
[targetMarketId]: targetMarket,
|
|
733
|
-
};
|
|
734
|
-
for (const m of markets) {
|
|
735
|
-
marketsRecord[m.id] = m;
|
|
736
|
-
}
|
|
737
|
-
const vaultsRecord = {};
|
|
738
|
-
for (const v of vaults) {
|
|
739
|
-
vaultsRecord[v.address] = v;
|
|
740
|
-
}
|
|
741
|
-
const vaultMarketConfigsRecord = {};
|
|
742
|
-
for (const { vault, mid, config } of configs) {
|
|
743
|
-
(vaultMarketConfigsRecord[vault] ??= {})[mid] = config;
|
|
744
|
-
}
|
|
745
|
-
const positionsRecord = {};
|
|
746
|
-
for (const { vault, mid, position } of positions) {
|
|
747
|
-
(positionsRecord[vault] ??= {})[mid] = position;
|
|
748
|
-
}
|
|
749
|
-
return new VaultV1ReallocationData({
|
|
750
|
-
chainId: this.chainId,
|
|
751
|
-
markets: marketsRecord,
|
|
752
|
-
vaults: vaultsRecord,
|
|
753
|
-
vaultMarketConfigs: vaultMarketConfigsRecord,
|
|
754
|
-
positions: positionsRecord,
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Fetches Vault V1 PublicAllocator state using the deprecated unversioned name.
|
|
759
|
-
*
|
|
760
|
-
* @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
|
|
761
|
-
* @param params.block.number - Block number used for every RPC read.
|
|
762
|
-
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
763
|
-
* @returns A `VaultV1ReallocationData` snapshot populated from one block.
|
|
764
|
-
* @throws {ChainIdMismatchError} when the client chain does not match this market.
|
|
765
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
766
|
-
* {@link getVaultV2BlueReallocationData}.
|
|
767
|
-
* @example
|
|
768
|
-
* ```ts
|
|
769
|
-
* const data = await market.getReallocationData({ vaultAddresses, block });
|
|
770
|
-
* // Equivalent to market.getVaultV1ReallocationData({ vaultAddresses, block }).
|
|
771
|
-
* ```
|
|
772
|
-
*/
|
|
773
|
-
getReallocationData(params) {
|
|
774
|
-
return this.getVaultV1ReallocationData(params);
|
|
775
|
-
}
|
|
776
652
|
/**
|
|
777
653
|
* Fetches Vault V2 BluePublicAllocator state for this target market.
|
|
778
654
|
*
|
|
@@ -851,86 +727,6 @@ export class MorphoBlue {
|
|
|
851
727
|
])),
|
|
852
728
|
});
|
|
853
729
|
}
|
|
854
|
-
/**
|
|
855
|
-
* Computes Vault V1 PublicAllocator reallocations for this market.
|
|
856
|
-
*
|
|
857
|
-
* Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
|
|
858
|
-
* or `{ operation, amount }` for a borrow or loan-asset withdraw.
|
|
859
|
-
*
|
|
860
|
-
* @param params - Reallocation computation parameters.
|
|
861
|
-
* @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
|
|
862
|
-
* @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
|
|
863
|
-
* @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
|
|
864
|
-
* @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
|
|
865
|
-
* @param params.options - Optional allocator and utilization options.
|
|
866
|
-
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
867
|
-
* @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
|
|
868
|
-
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
869
|
-
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
|
|
870
|
-
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
|
|
871
|
-
* @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
|
|
872
|
-
* @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
|
|
873
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
874
|
-
* {@link getVaultV2BlueReallocations}.
|
|
875
|
-
* @example
|
|
876
|
-
* ```ts
|
|
877
|
-
* const reallocations = market.getVaultV1Reallocations({
|
|
878
|
-
* reallocationData,
|
|
879
|
-
* operation: "borrow",
|
|
880
|
-
* amount: 1_000_000n,
|
|
881
|
-
* });
|
|
882
|
-
* ```
|
|
883
|
-
*/
|
|
884
|
-
getVaultV1Reallocations(params) {
|
|
885
|
-
validateChainId(params.reallocationData.chainId, this.chainId);
|
|
886
|
-
const marketId = this.marketParams.id;
|
|
887
|
-
const options = { enabled: true, ...params.options };
|
|
888
|
-
if (params.borrowAmount !== undefined) {
|
|
889
|
-
return computeVaultV1Reallocations({
|
|
890
|
-
reallocationData: params.reallocationData,
|
|
891
|
-
marketId,
|
|
892
|
-
operation: "borrow",
|
|
893
|
-
amount: params.borrowAmount,
|
|
894
|
-
options,
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
return computeVaultV1Reallocations({
|
|
898
|
-
reallocationData: params.reallocationData,
|
|
899
|
-
marketId,
|
|
900
|
-
operation: params.operation,
|
|
901
|
-
amount: params.amount,
|
|
902
|
-
options,
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Computes Vault V1 PublicAllocator reallocations using the deprecated unversioned name.
|
|
907
|
-
*
|
|
908
|
-
* @param params.reallocationData - State returned by {@link getVaultV1ReallocationData}.
|
|
909
|
-
* @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
|
|
910
|
-
* @param params.amount - The borrow or withdraw amount used to compute post-state utilization.
|
|
911
|
-
* @param params.borrowAmount - Deprecated borrow amount alias.
|
|
912
|
-
* @param params.options - Optional allocator and utilization options.
|
|
913
|
-
* @returns Vault V1 reallocations for explicit low-level Bundler3 composition.
|
|
914
|
-
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
915
|
-
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
916
|
-
* @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation.
|
|
917
|
-
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
918
|
-
* @throws {MissingPublicAllocatorConfigError} when a selected vault lacks allocator state.
|
|
919
|
-
* @throws {UnknownReallocationMarketError} when the target market is absent.
|
|
920
|
-
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
921
|
-
* {@link getVaultV2BlueReallocations}.
|
|
922
|
-
* @example
|
|
923
|
-
* ```ts
|
|
924
|
-
* const reallocations = market.getReallocations({
|
|
925
|
-
* reallocationData,
|
|
926
|
-
* operation: "borrow",
|
|
927
|
-
* amount: 1_000_000n,
|
|
928
|
-
* });
|
|
929
|
-
* ```
|
|
930
|
-
*/
|
|
931
|
-
getReallocations(params) {
|
|
932
|
-
return this.getVaultV1Reallocations(params);
|
|
933
|
-
}
|
|
934
730
|
/**
|
|
935
731
|
* Computes Vault V2 BluePublicAllocator reallocations for this market.
|
|
936
732
|
*
|
|
@@ -1,75 +1,12 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition,
|
|
2
|
-
|
|
3
|
-
IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket,
|
|
4
|
-
/** @deprecated Use `IBlueMarket` or the raw Blue subpath. */
|
|
5
|
-
IMarket, IMarketParams as IBlueMarketParams,
|
|
6
|
-
/** @deprecated Use `IBlueMarketParams` or the raw Blue subpath. */
|
|
7
|
-
IMarketParams, IPosition as IBluePosition,
|
|
8
|
-
/** @deprecated Use `IBluePosition` or the raw Blue subpath. */
|
|
9
|
-
IPosition, IPreLiquidationParams as IBluePreLiquidationParams,
|
|
10
|
-
/** @deprecated Use `IBluePreLiquidationParams` or the raw Blue subpath. */
|
|
11
|
-
IPreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition,
|
|
12
|
-
/** @deprecated Use `IBluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
|
-
IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig,
|
|
14
|
-
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BlueMarketPublicAllocatorConfig`. */
|
|
15
|
-
IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType,
|
|
16
|
-
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `IVaultV2BluePublicAllocatorConfig`. */
|
|
17
|
-
VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
|
|
18
|
-
export { AccrualPosition as BlueAccrualPosition,
|
|
19
|
-
/** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
|
|
20
|
-
AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
|
|
21
|
-
/** @deprecated Use `BlueMarket` or the raw Blue subpath. */
|
|
22
|
-
Market, MarketParams as BlueMarketParams,
|
|
23
|
-
/** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
|
|
24
|
-
MarketParams, Position as BluePosition,
|
|
25
|
-
/** @deprecated Use `BluePosition` or the raw Blue subpath. */
|
|
26
|
-
Position, PreLiquidationParams as BluePreLiquidationParams,
|
|
27
|
-
/** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
|
|
28
|
-
PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
29
|
-
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
30
|
-
PreLiquidationPosition, Token, User as BlueUser,
|
|
31
|
-
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
32
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
33
|
-
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
|
|
34
|
-
VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition, IPreLiquidationParams as IBluePreLiquidationParams, IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
2
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition, PreLiquidationParams as BluePreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
35
3
|
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";
|
|
36
4
|
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";
|
|
37
5
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
38
6
|
export { MorphoBlue } from "./blue/index.js";
|
|
39
|
-
export type { GetOffersDataParams as MidnightGetOffersDataParams,
|
|
40
|
-
/** @deprecated Use `MidnightGetOffersDataParams`. */
|
|
41
|
-
GetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams,
|
|
42
|
-
/** @deprecated Use `MidnightGetPositionDataParams`. */
|
|
43
|
-
GetPositionDataParams, MakeLendParams as MidnightMakeLendParams,
|
|
44
|
-
/** @deprecated Use `MidnightMakeLendParams`. */
|
|
45
|
-
MakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput,
|
|
46
|
-
/** @deprecated Use `MidnightMakeOffersOutput`. */
|
|
47
|
-
MakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams,
|
|
48
|
-
/** @deprecated Use `MidnightMakeOffersParams`. */
|
|
49
|
-
MakeOffersParams, MarketActionParams as MidnightMarketActionParams,
|
|
50
|
-
/** @deprecated Use `MidnightMarketActionParams`. */
|
|
51
|
-
MarketActionParams, OffersData as MidnightOffersData,
|
|
52
|
-
/** @deprecated Use `MidnightOffersData`. */
|
|
53
|
-
OffersData, OfferValidationParams as MidnightOfferValidationParams,
|
|
54
|
-
/** @deprecated Use `MidnightOfferValidationParams`. */
|
|
55
|
-
OfferValidationParams, RedeemParams as MidnightRedeemParams,
|
|
56
|
-
/** @deprecated Use `MidnightRedeemParams`. */
|
|
57
|
-
RedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams,
|
|
58
|
-
/** @deprecated Use `MidnightRepayWithdrawCollateralParams`. */
|
|
59
|
-
RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams,
|
|
60
|
-
/** @deprecated Use `MidnightSupplyCollateralMakeBorrowParams`. */
|
|
61
|
-
SupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams,
|
|
62
|
-
/** @deprecated Use `MidnightSupplyCollateralParams`. */
|
|
63
|
-
SupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams,
|
|
64
|
-
/** @deprecated Use `MidnightSupplyCollateralTakeBorrowParams`. */
|
|
65
|
-
SupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams,
|
|
66
|
-
/** @deprecated Use `MidnightTakeBorrowParams`. */
|
|
67
|
-
TakeBorrowParams, TakeLendParams as MidnightTakeLendParams,
|
|
68
|
-
/** @deprecated Use `MidnightTakeLendParams`. */
|
|
69
|
-
TakeLendParams, } from "./midnight/index.js";
|
|
7
|
+
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, } from "./midnight/index.js";
|
|
70
8
|
export { type MidnightActionOutput, type MidnightActionSignatures, type MidnightActions, MorphoMidnight, } from "./midnight/index.js";
|
|
71
9
|
export * from "./requirements/index.js";
|
|
72
10
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
73
|
-
export { type InputReallocationData, type InputVaultV1ReallocationData, ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
|
|
74
11
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
75
12
|
export { type InputVaultV2BlueReallocationData, VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition,
|
|
2
|
-
/** @deprecated Use `BlueAccrualPosition` or the raw Blue subpath. */
|
|
3
|
-
AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket,
|
|
4
|
-
/** @deprecated Use `BlueMarket` or the raw Blue subpath. */
|
|
5
|
-
Market, MarketParams as BlueMarketParams,
|
|
6
|
-
/** @deprecated Use `BlueMarketParams` or the raw Blue subpath. */
|
|
7
|
-
MarketParams, Position as BluePosition,
|
|
8
|
-
/** @deprecated Use `BluePosition` or the raw Blue subpath. */
|
|
9
|
-
Position, PreLiquidationParams as BluePreLiquidationParams,
|
|
10
|
-
/** @deprecated Use `BluePreLiquidationParams` or the raw Blue subpath. */
|
|
11
|
-
PreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition,
|
|
12
|
-
/** @deprecated Use `BluePreLiquidationPosition` or the raw Blue subpath. */
|
|
13
|
-
PreLiquidationPosition, Token, User as BlueUser,
|
|
14
|
-
/** @deprecated Use `BlueUser` or the raw Blue subpath. */
|
|
15
|
-
User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig,
|
|
16
|
-
/** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `VaultV2BlueMarketPublicAllocatorConfig`. */
|
|
17
|
-
VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition, PreLiquidationParams as BluePreLiquidationParams, PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
18
2
|
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";
|
|
19
3
|
export { MorphoBlue } from "./blue/index.js";
|
|
20
4
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
21
5
|
export * from "./requirements/index.js";
|
|
22
6
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
23
|
-
export { ReallocationData, VaultV1ReallocationData, } from "./vaultV1ReallocationData.js";
|
|
24
7
|
export { MorphoVaultV2 } from "./vaultV2/index.js";
|
|
25
8
|
export { VaultV2BlueReallocationData, } from "./vaultV2BlueReallocationData.js";
|
|
@@ -36,6 +36,7 @@ export interface VaultV1Actions {
|
|
|
36
36
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
37
37
|
* transaction builder.
|
|
38
38
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
39
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated market with positive debt uses an unsupported IRM.
|
|
39
40
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
40
41
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
41
42
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
@@ -240,6 +241,10 @@ export interface VaultV1Actions {
|
|
|
240
241
|
* Snapshot state can drift before inclusion, so a later reallocation may still make the on-chain
|
|
241
242
|
* loop under-cover even after pre-flight succeeds.
|
|
242
243
|
*
|
|
244
|
+
* In-kind exits require an exact vault-share allowance for the computed cap. An ERC-2612 permit
|
|
245
|
+
* is emitted only to raise an insufficient allowance; an oversized allowance is always reset
|
|
246
|
+
* with an onchain approval before the exit.
|
|
247
|
+
*
|
|
243
248
|
* @param params - In-kind redemption parameters.
|
|
244
249
|
* @param params.amount - Asset-denominated amount to exit.
|
|
245
250
|
* @param params.marketParamsList - Ordered vault markets consumed greedily by the contract;
|
|
@@ -266,7 +271,9 @@ export interface VaultV1Actions {
|
|
|
266
271
|
* @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the flash loan.
|
|
267
272
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
268
273
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
269
|
-
* @throws {
|
|
274
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
275
|
+
* the wrong asset, owner, or signature encoding, or names another spender, amount, or deadline
|
|
276
|
+
* than the prepared cap.
|
|
270
277
|
* @example
|
|
271
278
|
* ```ts
|
|
272
279
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -329,8 +336,8 @@ export interface VaultV1Actions {
|
|
|
329
336
|
* satisfied between calls stops being reported, while the derived source share cap stays
|
|
330
337
|
* pinned to the supplied snapshot.
|
|
331
338
|
* @throws {UnknownBlueMarketAllocationError} when a source withdraw-queue market has no allocation snapshot.
|
|
332
|
-
* @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
|
|
333
339
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
340
|
+
* @throws {UnsupportedBlueMarketIrmError} when an allocated source or target market with positive debt uses an unsupported IRM.
|
|
334
341
|
* @throws {VaultAddressMismatchError} when `sourceVault` belongs to another vault.
|
|
335
342
|
* @throws {VaultAssetMismatchError} when the source and destination vault assets differ.
|
|
336
343
|
* @throws {SameVaultMigrationError} when the source and destination vault addresses are equal.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain,
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
9
|
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
-
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError,
|
|
10
|
+
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
11
11
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
12
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
13
13
|
export class MorphoVaultV1 {
|
|
@@ -27,7 +27,6 @@ export class MorphoVaultV1 {
|
|
|
27
27
|
}
|
|
28
28
|
return fetchAccrualVault(this.vault, this.client.viemClient, {
|
|
29
29
|
...parameters,
|
|
30
|
-
chainId: this.chainId,
|
|
31
30
|
deployless: this.client.options.supportDeployless,
|
|
32
31
|
});
|
|
33
32
|
}
|
|
@@ -293,8 +292,7 @@ export class MorphoVaultV1 {
|
|
|
293
292
|
if (deadline <= now)
|
|
294
293
|
throw new ExpiredDeadlineError(deadline, now);
|
|
295
294
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
296
|
-
const
|
|
297
|
-
const blue = addresses.blue ?? addresses.morpho;
|
|
295
|
+
const blue = getChainAddress(this.chainId, "blue");
|
|
298
296
|
let covered = 0n;
|
|
299
297
|
const assignedByMarket = new Map();
|
|
300
298
|
for (const marketParams of marketParamsListSnapshot) {
|
|
@@ -392,9 +390,14 @@ export class MorphoVaultV1 {
|
|
|
392
390
|
required: amount,
|
|
393
391
|
});
|
|
394
392
|
}
|
|
395
|
-
|
|
393
|
+
// In-kind withdrawals carry no onchain share cap, so the allowance itself is the cap. A
|
|
394
|
+
// larger leftover allowance would let a share-price loss burn past `requiredShareAllowance`.
|
|
395
|
+
if (allowance === requiredShareAllowance)
|
|
396
396
|
return [];
|
|
397
|
-
|
|
397
|
+
// A lowering permit can be skipped after its nonce is consumed, so oversized allowances
|
|
398
|
+
// must be reset with an onchain approval.
|
|
399
|
+
if (allowance < requiredShareAllowance &&
|
|
400
|
+
this.client.options.supportSignature) {
|
|
398
401
|
return [
|
|
399
402
|
encodeVaultSharesPermit({
|
|
400
403
|
vault: vaultData,
|
|
@@ -418,8 +421,10 @@ export class MorphoVaultV1 {
|
|
|
418
421
|
];
|
|
419
422
|
},
|
|
420
423
|
buildTx: (signatures) => {
|
|
421
|
-
const
|
|
422
|
-
|
|
424
|
+
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
425
|
+
spender: vaultExitBundlesV1,
|
|
426
|
+
amount: requiredShareAllowance,
|
|
427
|
+
deadline,
|
|
423
428
|
});
|
|
424
429
|
return vaultV1InKindRedeem({
|
|
425
430
|
vault: { chainId: this.chainId, address: this.vault },
|
|
@@ -37,8 +37,8 @@ export interface VaultV2Actions {
|
|
|
37
37
|
* two hours from handle creation.
|
|
38
38
|
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
39
39
|
* transaction builder.
|
|
40
|
-
* @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
|
|
41
40
|
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
41
|
+
* @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
|
|
42
42
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
43
43
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
44
44
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
@@ -233,6 +233,10 @@ export interface VaultV2Actions {
|
|
|
233
233
|
* Idle balance, penalty, and adapter positions can drift after the snapshot, so an on-chain
|
|
234
234
|
* under-coverage panic remains possible if vault state changes between preparation and inclusion.
|
|
235
235
|
*
|
|
236
|
+
* In-kind exits require an exact vault-share allowance for the computed cap. An ERC-2612 permit
|
|
237
|
+
* is emitted only to raise an insufficient allowance; an oversized allowance is always reset
|
|
238
|
+
* with an onchain approval before the exit.
|
|
239
|
+
*
|
|
236
240
|
* @param params - In-kind redemption parameters.
|
|
237
241
|
* @param params.amount - Penalty-inclusive, asset-denominated amount to exit.
|
|
238
242
|
* @param params.marketParamsList - Ordered adapter markets consumed greedily after idle assets;
|
|
@@ -262,7 +266,9 @@ export interface VaultV2Actions {
|
|
|
262
266
|
* @throws {InsufficientBlueBalanceForInKindRedeemError} from `getRequirements()` when Blue cannot fund the largest callback.
|
|
263
267
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
264
268
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
265
|
-
* @throws {
|
|
269
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit is not ERC-2612, has
|
|
270
|
+
* the wrong asset, owner, or signature encoding, or names another spender, amount, or deadline
|
|
271
|
+
* than the prepared cap.
|
|
266
272
|
* @example
|
|
267
273
|
* ```ts
|
|
268
274
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
@@ -313,10 +319,13 @@ export interface VaultV2Actions {
|
|
|
313
319
|
* adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
|
|
314
320
|
* and permit nonce are read on-chain.
|
|
315
321
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
322
|
+
* The SDK derives a conservative lower bound on the realized exit share price from the snapshot
|
|
323
|
+
* and `slippageTolerance`. A supplied `minSharePriceE27` replaces the tolerance-derived bound
|
|
324
|
+
* (it may be tighter or looser) but must be at least the floor derived at
|
|
325
|
+
* `MAX_SLIPPAGE_TOLERANCE`, so an override can never disable meaningful protection.
|
|
326
|
+
* The bound rejects a share price drop, a penalty increase, and liquidity shifting from the
|
|
327
|
+
* penalty-free leg to the penalised leg. It does **not** cover the referral fee, which the
|
|
328
|
+
* contract deducts afterwards.
|
|
320
329
|
*
|
|
321
330
|
* Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
|
|
322
331
|
* gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
|
|
@@ -343,8 +352,10 @@ export interface VaultV2Actions {
|
|
|
343
352
|
* Deadlines more than one year after handle creation are rejected.
|
|
344
353
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
|
|
345
354
|
* price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
|
|
346
|
-
* @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound.
|
|
347
|
-
*
|
|
355
|
+
* @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. It replaces
|
|
356
|
+
* the tolerance-derived bound and may be tighter or looser, but must be at least the floor
|
|
357
|
+
* derived at `MAX_SLIPPAGE_TOLERANCE`. When that floor rounds down to zero (dust exits) it is
|
|
358
|
+
* clamped to `1`, so any positive override is accepted.
|
|
348
359
|
* @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
|
|
349
360
|
* `referralFeeRecipient`. Defaults to `0n`.
|
|
350
361
|
* @param params.referralFeeRecipient - Optional referral fee recipient, required when
|
|
@@ -373,6 +384,8 @@ export interface VaultV2Actions {
|
|
|
373
384
|
* which would overrun the contract's unbounded loop.
|
|
374
385
|
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
|
|
375
386
|
* to zero, which the contract would read as no bound at all.
|
|
387
|
+
* @throws {VaultV2ForceWithdrawSharePriceBelowFloorError} when a supplied `minSharePriceE27`
|
|
388
|
+
* is below the floor derived at `MAX_SLIPPAGE_TOLERANCE`.
|
|
376
389
|
* @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
|
|
377
390
|
* fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
|
|
378
391
|
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
@@ -384,7 +397,7 @@ export interface VaultV2Actions {
|
|
|
384
397
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
385
398
|
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
386
399
|
* permit; the nonce is verified onchain by the vault's `permit`.
|
|
387
|
-
* @throws {
|
|
400
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
388
401
|
* @example
|
|
389
402
|
* ```ts
|
|
390
403
|
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|