@morpho-org/morpho-sdk 6.0.0-next.2 → 6.0.0-next.4
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 +88 -32
- package/README.md +9 -7
- package/lib/cjs/abis.d.ts +7 -2844
- package/lib/cjs/abis.js +3 -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 +31 -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 +7 -5
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +11 -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 +7 -5
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +11 -7
- package/lib/cjs/augment/AccrualPosition.d.ts +1 -0
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +5 -5
- package/lib/cjs/blue/abis.js +3 -7
- package/lib/cjs/blue/entities.d.ts +10 -8
- package/lib/cjs/blue/entities.js +3 -3
- package/lib/cjs/blue/errors.d.ts +4 -2
- package/lib/cjs/blue/errors.js +3 -1
- package/lib/cjs/blue/fetch.d.ts +5 -3
- package/lib/cjs/blue/fetch.js +3 -3
- package/lib/cjs/blue/types.d.ts +2 -4
- package/lib/cjs/blue/utils.d.ts +6 -4
- package/lib/cjs/blue/utils.js +3 -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 +11 -66
- package/lib/cjs/entities/index.js +3 -21
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +13 -5
- package/lib/cjs/entities/vaultV1/vaultV1.js +16 -10
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +40 -19
- package/lib/cjs/entities/vaultV2/vaultV2.js +57 -26
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +4 -21
- package/lib/cjs/errors.d.ts +5 -47
- package/lib/cjs/errors.js +4 -46
- package/lib/cjs/fetch.d.ts +5 -17
- package/lib/cjs/fetch.js +3 -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/previewVaultV2ForceWithdraw.js +11 -5
- 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/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/cjs/midnight/errors.d.ts +1 -1
- package/lib/cjs/midnight/errors.js +2 -1
- 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 +10 -35
- package/lib/cjs/utils.js +4 -36
- package/lib/esm/abis.d.ts +7 -2844
- package/lib/esm/abis.js +7 -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 +32 -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 +7 -5
- package/lib/esm/actions/vaultV1/inKindRedeem.js +11 -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 +7 -5
- package/lib/esm/actions/vaultV2/inKindRedeem.js +11 -7
- package/lib/esm/augment/AccrualPosition.d.ts +1 -0
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +5 -5
- package/lib/esm/blue/abis.js +5 -5
- package/lib/esm/blue/entities.d.ts +10 -8
- package/lib/esm/blue/entities.js +5 -3
- package/lib/esm/blue/errors.d.ts +4 -2
- package/lib/esm/blue/errors.js +4 -2
- package/lib/esm/blue/fetch.d.ts +5 -3
- package/lib/esm/blue/fetch.js +5 -3
- package/lib/esm/blue/types.d.ts +2 -4
- package/lib/esm/blue/utils.d.ts +6 -4
- package/lib/esm/blue/utils.js +6 -4
- 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 +11 -66
- package/lib/esm/entities/index.js +5 -18
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -3
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +13 -5
- package/lib/esm/entities/vaultV1/vaultV1.js +19 -13
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +40 -19
- package/lib/esm/entities/vaultV2/vaultV2.js +61 -30
- package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -19
- package/lib/esm/errors.d.ts +5 -47
- package/lib/esm/errors.js +5 -47
- package/lib/esm/fetch.d.ts +5 -17
- package/lib/esm/fetch.js +5 -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/previewVaultV2ForceWithdraw.js +11 -5
- 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/helpers/vaultV2ForceWithdrawPlan.d.ts +48 -15
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +48 -15
- package/lib/esm/midnight/errors.d.ts +1 -1
- package/lib/esm/midnight/errors.js +1 -1
- 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 +10 -35
- package/lib/esm/utils.js +9 -34
- package/package.json +6 -17
- 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
|
@@ -95,15 +95,21 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
95
95
|
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
96
96
|
// dwarfing `totalAssets`) offers no price protection at all. Screen at the entity's default
|
|
97
97
|
// `DEFAULT_SLIPPAGE_TOLERANCE`, not slippage-free, against the same burn upper bound the entity
|
|
98
|
-
// divides by (
|
|
99
|
-
// realized price is a single RAY-unit, yet
|
|
100
|
-
// to zero — so the entity would reject
|
|
98
|
+
// divides by (the larger of the raw snapshot burn and the net burn accrued to `timestamp` like
|
|
99
|
+
// the plan): a tolerance-free screen clears an exit whose realized price is a single RAY-unit, yet
|
|
100
|
+
// the default tolerance scales that below 1 and rounds it to zero — so the entity would reject
|
|
101
|
+
// with `VaultV2ForceWithdrawZeroSharePriceError` the very
|
|
101
102
|
// `exitAssets` this preview handed back. A caller passing a larger tolerance still relies on the
|
|
102
103
|
// entity's own guard. The entity validates this derived value with
|
|
103
104
|
// `validateUint256Field("minSharePriceE27")`, which throws `InputExceedsMaxError` when it
|
|
104
105
|
// cannot fit uint256.
|
|
105
106
|
const { vault: accruedVaultData } = vaultData.accrueInterest(MathLib.max(timestamp, vaultData.lastUpdate));
|
|
106
|
-
const
|
|
107
|
+
const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
108
|
+
vaultData,
|
|
109
|
+
deadlineVaultData: vaultData,
|
|
110
|
+
plan,
|
|
111
|
+
});
|
|
112
|
+
const sharesBurntAccrued = computeVaultV2ForceWithdrawSharesBurnt({
|
|
107
113
|
vaultData: accruedVaultData,
|
|
108
114
|
deadlineVaultData: accruedVaultData,
|
|
109
115
|
plan,
|
|
@@ -132,7 +138,7 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
132
138
|
return undefined;
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
|
-
const sharesBurntForFloor =
|
|
141
|
+
const sharesBurntForFloor = MathLib.max(sharesBurntRaw, sharesBurntAccrued - feeShares);
|
|
136
142
|
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
137
143
|
? MathLib.mulDivDown(plan.withdrawnAssets, MathLib.wToRay(MathLib.WAD - DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
138
144
|
: 0n;
|
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
import { type AccrualVault, AccrualVaultV2
|
|
2
|
-
/**
|
|
3
|
-
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
4
|
-
*
|
|
5
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
|
|
6
|
-
* ```solidity
|
|
7
|
-
* require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
|
|
8
|
-
* ```
|
|
9
|
-
*
|
|
10
|
-
* @param params - Computation parameters.
|
|
11
|
-
* @param params.borrowAmount - The amount of assets to borrow.
|
|
12
|
-
* @param params.market - The market to compute the minimum borrow share price for.
|
|
13
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
14
|
-
* @returns minSharePriceE27 in RAY scale (1e27).
|
|
15
|
-
*/
|
|
16
|
-
export declare function computeMinBorrowSharePrice(params: {
|
|
17
|
-
borrowAmount: bigint;
|
|
18
|
-
market: Market;
|
|
19
|
-
slippageTolerance: bigint;
|
|
20
|
-
}): bigint;
|
|
21
|
-
/**
|
|
22
|
-
* Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
|
|
23
|
-
*
|
|
24
|
-
* Supports both repay-by-assets and repay-by-shares paths:
|
|
25
|
-
* - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
|
|
26
|
-
* - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
|
|
27
|
-
*
|
|
28
|
-
* Direction is opposite of borrow's `minSharePrice`:
|
|
29
|
-
* - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
|
|
30
|
-
* - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
|
|
31
|
-
*
|
|
32
|
-
* Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
|
|
33
|
-
*
|
|
34
|
-
* @param params - Computation parameters.
|
|
35
|
-
* @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
|
|
36
|
-
* @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
|
|
37
|
-
* @param params.market - The market to compute the maximum repay share price for.
|
|
38
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
39
|
-
* @returns maxSharePriceE27 in RAY scale (1e27).
|
|
40
|
-
*/
|
|
41
|
-
export declare function computeMaxRepaySharePrice(params: {
|
|
42
|
-
repayAssets: bigint;
|
|
43
|
-
repayShares: bigint;
|
|
44
|
-
market: Market;
|
|
45
|
-
slippageTolerance: bigint;
|
|
46
|
-
}): bigint;
|
|
47
|
-
/**
|
|
48
|
-
* Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
|
|
49
|
-
*
|
|
50
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
|
|
51
|
-
* ```solidity
|
|
52
|
-
* require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
|
|
56
|
-
*
|
|
57
|
-
* @param params - Computation parameters.
|
|
58
|
-
* @param params.supplyAssets - The amount of loan assets to supply.
|
|
59
|
-
* @param params.market - The market to compute the maximum supply share price for.
|
|
60
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
61
|
-
* @returns `maxSharePriceE27` in RAY scale (1e27).
|
|
62
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
63
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
64
|
-
*/
|
|
65
|
-
export declare function computeMaxSupplySharePrice(params: {
|
|
66
|
-
supplyAssets: bigint;
|
|
67
|
-
market: Market;
|
|
68
|
-
slippageTolerance: bigint;
|
|
69
|
-
}): bigint;
|
|
1
|
+
import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
70
2
|
/**
|
|
71
3
|
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
72
4
|
*
|
|
@@ -113,40 +45,6 @@ export declare function computeMinForceWithdrawSharePrice(params: {
|
|
|
113
45
|
readonly sharesBurnt: bigint;
|
|
114
46
|
readonly slippageTolerance: bigint;
|
|
115
47
|
}): bigint;
|
|
116
|
-
/**
|
|
117
|
-
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
118
|
-
*
|
|
119
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
|
|
120
|
-
* ```solidity
|
|
121
|
-
* require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* Supports both assets and shares modes:
|
|
125
|
-
* - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
|
|
126
|
-
* withdrawer against over-burning shares).
|
|
127
|
-
* - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
|
|
128
|
-
* amount paid out).
|
|
129
|
-
*
|
|
130
|
-
* Direction is opposite of supply's `maxSharePrice`:
|
|
131
|
-
* - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
|
|
132
|
-
* - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
|
|
133
|
-
* assets per share burned).
|
|
134
|
-
*
|
|
135
|
-
* @param params - Computation parameters.
|
|
136
|
-
* @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
|
|
137
|
-
* @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
|
|
138
|
-
* @param params.market - The market to compute the minimum withdraw share price for.
|
|
139
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
140
|
-
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
141
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
142
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
143
|
-
*/
|
|
144
|
-
export declare function computeMinWithdrawSharePrice(params: {
|
|
145
|
-
withdrawAssets: bigint;
|
|
146
|
-
withdrawShares: bigint;
|
|
147
|
-
market: Market;
|
|
148
|
-
slippageTolerance: bigint;
|
|
149
|
-
}): bigint;
|
|
150
48
|
/**
|
|
151
49
|
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
152
50
|
*
|
|
@@ -1,103 +1,7 @@
|
|
|
1
1
|
import { AccrualVaultV2, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { NonPositiveInputError, VaultV2ForceWithdrawZeroSharePriceError, } from "../types/index.js";
|
|
3
3
|
import { MAX_ABSOLUTE_SHARE_PRICE } from "./constant.js";
|
|
4
4
|
import { validateSlippageTolerance } from "./validate.js";
|
|
5
|
-
/**
|
|
6
|
-
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
7
|
-
*
|
|
8
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoBorrow`:
|
|
9
|
-
* ```solidity
|
|
10
|
-
* require(borrowedAssets.rDivDown(borrowedShares) >= minSharePriceE27)
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @param params - Computation parameters.
|
|
14
|
-
* @param params.borrowAmount - The amount of assets to borrow.
|
|
15
|
-
* @param params.market - The market to compute the minimum borrow share price for.
|
|
16
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
17
|
-
* @returns minSharePriceE27 in RAY scale (1e27).
|
|
18
|
-
*/
|
|
19
|
-
export function computeMinBorrowSharePrice(params) {
|
|
20
|
-
const { borrowAmount, market, slippageTolerance } = params;
|
|
21
|
-
if (slippageTolerance >= MathLib.WAD) {
|
|
22
|
-
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
23
|
-
}
|
|
24
|
-
const expectedShares = market.toBorrowShares(borrowAmount, "Up");
|
|
25
|
-
if (expectedShares === 0n) {
|
|
26
|
-
throw new ShareDivideByZeroError(market.params.id);
|
|
27
|
-
}
|
|
28
|
-
return MathLib.mulDivDown(borrowAmount, MathLib.wToRay(MathLib.WAD - slippageTolerance), expectedShares);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
|
|
32
|
-
*
|
|
33
|
-
* Supports both repay-by-assets and repay-by-shares paths:
|
|
34
|
-
* - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
|
|
35
|
-
* - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
|
|
36
|
-
*
|
|
37
|
-
* Direction is opposite of borrow's `minSharePrice`:
|
|
38
|
-
* - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
|
|
39
|
-
* - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
|
|
40
|
-
*
|
|
41
|
-
* Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
|
|
42
|
-
*
|
|
43
|
-
* @param params - Computation parameters.
|
|
44
|
-
* @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
|
|
45
|
-
* @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
|
|
46
|
-
* @param params.market - The market to compute the maximum repay share price for.
|
|
47
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
48
|
-
* @returns maxSharePriceE27 in RAY scale (1e27).
|
|
49
|
-
*/
|
|
50
|
-
export function computeMaxRepaySharePrice(params) {
|
|
51
|
-
const { repayAssets, repayShares, market, slippageTolerance } = params;
|
|
52
|
-
if (slippageTolerance >= MathLib.WAD) {
|
|
53
|
-
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
54
|
-
}
|
|
55
|
-
let assets;
|
|
56
|
-
let shares;
|
|
57
|
-
if (repayShares > 0n) {
|
|
58
|
-
assets = market.toBorrowAssets(repayShares, "Up");
|
|
59
|
-
shares = repayShares;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
assets = repayAssets;
|
|
63
|
-
shares = market.toBorrowShares(repayAssets, "Down");
|
|
64
|
-
}
|
|
65
|
-
if (shares === 0n) {
|
|
66
|
-
throw new ShareDivideByZeroError(market.params.id);
|
|
67
|
-
}
|
|
68
|
-
const maxSharePrice = MathLib.mulDivUp(assets, MathLib.wToRay(MathLib.WAD + slippageTolerance), shares);
|
|
69
|
-
return MathLib.min(maxSharePrice, MAX_ABSOLUTE_SHARE_PRICE);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
|
|
73
|
-
*
|
|
74
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
|
|
75
|
-
* ```solidity
|
|
76
|
-
* require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* Caps at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values on extreme markets.
|
|
80
|
-
*
|
|
81
|
-
* @param params - Computation parameters.
|
|
82
|
-
* @param params.supplyAssets - The amount of loan assets to supply.
|
|
83
|
-
* @param params.market - The market to compute the maximum supply share price for.
|
|
84
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
85
|
-
* @returns `maxSharePriceE27` in RAY scale (1e27).
|
|
86
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
87
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
88
|
-
*/
|
|
89
|
-
export function computeMaxSupplySharePrice(params) {
|
|
90
|
-
const { supplyAssets, market, slippageTolerance } = params;
|
|
91
|
-
if (slippageTolerance >= MathLib.WAD) {
|
|
92
|
-
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
93
|
-
}
|
|
94
|
-
const expectedShares = market.toSupplyShares(supplyAssets, "Down");
|
|
95
|
-
if (expectedShares === 0n) {
|
|
96
|
-
throw new ShareDivideByZeroError(market.params.id);
|
|
97
|
-
}
|
|
98
|
-
const maxSharePrice = MathLib.mulDivUp(supplyAssets, MathLib.wToRay(MathLib.WAD + slippageTolerance), expectedShares);
|
|
99
|
-
return MathLib.min(maxSharePrice, MAX_ABSOLUTE_SHARE_PRICE);
|
|
100
|
-
}
|
|
101
5
|
/**
|
|
102
6
|
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
103
7
|
*
|
|
@@ -162,56 +66,6 @@ export function computeMinForceWithdrawSharePrice(params) {
|
|
|
162
66
|
}
|
|
163
67
|
return minSharePriceE27;
|
|
164
68
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
167
|
-
*
|
|
168
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoWithdraw`:
|
|
169
|
-
* ```solidity
|
|
170
|
-
* require(withdrawnAssets.rDivDown(withdrawnShares) >= minSharePriceE27)
|
|
171
|
-
* ```
|
|
172
|
-
*
|
|
173
|
-
* Supports both assets and shares modes:
|
|
174
|
-
* - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
|
|
175
|
-
* withdrawer against over-burning shares).
|
|
176
|
-
* - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
|
|
177
|
-
* amount paid out).
|
|
178
|
-
*
|
|
179
|
-
* Direction is opposite of supply's `maxSharePrice`:
|
|
180
|
-
* - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
|
|
181
|
-
* - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
|
|
182
|
-
* assets per share burned).
|
|
183
|
-
*
|
|
184
|
-
* @param params - Computation parameters.
|
|
185
|
-
* @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
|
|
186
|
-
* @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
|
|
187
|
-
* @param params.market - The market to compute the minimum withdraw share price for.
|
|
188
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
189
|
-
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
190
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
191
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
192
|
-
*/
|
|
193
|
-
export function computeMinWithdrawSharePrice(params) {
|
|
194
|
-
const { withdrawAssets, withdrawShares, market, slippageTolerance } = params;
|
|
195
|
-
if (slippageTolerance >= MathLib.WAD) {
|
|
196
|
-
throw new ExcessiveSlippageToleranceError(slippageTolerance);
|
|
197
|
-
}
|
|
198
|
-
let assets;
|
|
199
|
-
let shares;
|
|
200
|
-
if (withdrawShares > 0n) {
|
|
201
|
-
assets = market.toSupplyAssets(withdrawShares, "Down");
|
|
202
|
-
shares = withdrawShares;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
assets = withdrawAssets;
|
|
206
|
-
shares = market.toSupplyShares(withdrawAssets, "Up");
|
|
207
|
-
}
|
|
208
|
-
// Dust shares can round to `assets === 0n` here, which would make
|
|
209
|
-
// `minSharePriceE27 = 0` and silently nullify the on-chain slippage cap.
|
|
210
|
-
if (shares === 0n || assets === 0n) {
|
|
211
|
-
throw new ShareDivideByZeroError(market.params.id);
|
|
212
|
-
}
|
|
213
|
-
return MathLib.mulDivDown(assets, MathLib.wToRay(MathLib.WAD - slippageTolerance), shares);
|
|
214
|
-
}
|
|
215
69
|
/**
|
|
216
70
|
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
217
71
|
*
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { MarketId } from "@morpho-org/blue-sdk";
|
|
2
|
-
import type { ReallocationComputeOptions } from "../types/index.js";
|
|
3
1
|
/**
|
|
4
|
-
* Resolves
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
2
|
+
* Resolves and validates a source withdrawal utilization ceiling.
|
|
3
|
+
* @internal
|
|
4
|
+
* @param value - Optional WAD-scaled utilization ceiling.
|
|
5
|
+
* @param field - Option name reported in validation errors.
|
|
6
|
+
* @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
|
|
7
|
+
* @throws {NegativeInputError} when the ceiling is negative.
|
|
8
|
+
* @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const ceiling = resolveMaxWithdrawalUtilization(undefined);
|
|
12
|
+
* ```
|
|
11
13
|
*/
|
|
12
|
-
export declare const
|
|
14
|
+
export declare const resolveMaxWithdrawalUtilization: (value: bigint | undefined, field?: "maxWithdrawalUtilization" | "defaultMaxWithdrawalUtilization") => bigint;
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { InputExceedsMaxError, NegativeInputError } from "../types/index.js";
|
|
3
|
+
import { DEFAULT_WITHDRAWAL_TARGET_UTILIZATION } from "./constant.js";
|
|
2
4
|
/**
|
|
3
|
-
* Resolves
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
5
|
+
* Resolves and validates a source withdrawal utilization ceiling.
|
|
6
|
+
* @internal
|
|
7
|
+
* @param value - Optional WAD-scaled utilization ceiling.
|
|
8
|
+
* @param field - Option name reported in validation errors.
|
|
9
|
+
* @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
|
|
10
|
+
* @throws {NegativeInputError} when the ceiling is negative.
|
|
11
|
+
* @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const ceiling = resolveMaxWithdrawalUtilization(undefined);
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
export const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
|
|
18
|
+
const utilization = value ?? DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
|
|
19
|
+
if (utilization < 0n)
|
|
20
|
+
throw new NegativeInputError(field, utilization);
|
|
21
|
+
if (utilization > MathLib.WAD)
|
|
22
|
+
throw new InputExceedsMaxError({
|
|
23
|
+
field,
|
|
24
|
+
value: utilization,
|
|
25
|
+
max: MathLib.WAD,
|
|
26
|
+
});
|
|
27
|
+
return utilization;
|
|
28
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
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 VaultV2BlueReallocation } from "../types/index.js";
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0 | 1;
|
|
7
7
|
/**
|
|
@@ -209,29 +209,6 @@ export declare const validateRepayShares: (params: {
|
|
|
209
209
|
repayShares: bigint;
|
|
210
210
|
marketId: MarketId;
|
|
211
211
|
}) => void;
|
|
212
|
-
/**
|
|
213
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
214
|
-
*
|
|
215
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
216
|
-
* @param targetMarketId - The operation's target market ID.
|
|
217
|
-
* @returns Nothing when every reallocation is valid.
|
|
218
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
219
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
220
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
221
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
222
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
223
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
224
|
-
* reallocations for new integrations.
|
|
225
|
-
* @example
|
|
226
|
-
* ```ts
|
|
227
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
228
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
229
|
-
* import { zeroHash } from "viem";
|
|
230
|
-
*
|
|
231
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
|
|
235
212
|
/** @internal */
|
|
236
213
|
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
|
|
237
214
|
/**
|
|
@@ -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
3
|
import { isAddress, isAddressEqual, maxUint128, maxUint256, zeroAddress, } from "viem";
|
|
4
|
-
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError,
|
|
4
|
+
import { AccrualPositionUserMismatchError, AddressMismatchError, BorrowExceedsSafeLtvError, ChainIdMismatchError, ChainWNativeMissingError, ExcessiveSlippageToleranceError, InconsistentReallocationPenaltyError, InputExceedsMaxError, InvalidReallocationAddressError, InvalidReallocationSourceTypeError, InvalidVaultV2BlueReallocationShapeError, MarketIdMismatchError, MissingClientPropertyError, MissingMarketPriceError, NativeAmountOnNonWNativeAssetError, NativeAmountOnNonWNativeVaultError, NegativeInputError, NonPositiveInputError, ReallocationWithdrawalOnTargetMarketError, ReferralFeePctExceededError, ReferralFeeRecipientMissingError, RepayExceedsDebtError, RepaySharesExceedDebtError, 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) => {
|
|
@@ -318,52 +318,6 @@ export const validateRepayShares = (params) => {
|
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
};
|
|
321
|
-
/**
|
|
322
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
323
|
-
*
|
|
324
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
325
|
-
* @param targetMarketId - The operation's target market ID.
|
|
326
|
-
* @returns Nothing when every reallocation is valid.
|
|
327
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
328
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
329
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
330
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
331
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
332
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
333
|
-
* reallocations for new integrations.
|
|
334
|
-
* @example
|
|
335
|
-
* ```ts
|
|
336
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
337
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
338
|
-
* import { zeroHash } from "viem";
|
|
339
|
-
*
|
|
340
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
341
|
-
* ```
|
|
342
|
-
*/
|
|
343
|
-
export const validateReallocations = (reallocations, targetMarketId) => {
|
|
344
|
-
for (const reallocation of reallocations) {
|
|
345
|
-
if (reallocation.fee < 0n) {
|
|
346
|
-
throw new NegativeInputError("reallocation.fee", reallocation.fee);
|
|
347
|
-
}
|
|
348
|
-
if (reallocation.withdrawals.length === 0) {
|
|
349
|
-
throw new EmptyReallocationWithdrawalsError(reallocation.vault);
|
|
350
|
-
}
|
|
351
|
-
let previousMarketId;
|
|
352
|
-
for (const withdrawal of reallocation.withdrawals) {
|
|
353
|
-
if (withdrawal.amount <= 0n) {
|
|
354
|
-
throw new NonPositiveInputError(`reallocation.withdrawals[${withdrawal.marketParams.id}].amount`, withdrawal.amount);
|
|
355
|
-
}
|
|
356
|
-
if (withdrawal.marketParams.id === targetMarketId) {
|
|
357
|
-
throw new ReallocationWithdrawalOnTargetMarketError(reallocation.vault, withdrawal.marketParams.id);
|
|
358
|
-
}
|
|
359
|
-
if (previousMarketId !== undefined &&
|
|
360
|
-
compareMarketIds(withdrawal.marketParams.id, previousMarketId) <= 0) {
|
|
361
|
-
throw new UnsortedReallocationWithdrawalsError(reallocation.vault, withdrawal.marketParams.id);
|
|
362
|
-
}
|
|
363
|
-
previousMarketId = withdrawal.marketParams.id;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
321
|
/** @internal */
|
|
368
322
|
export const validateVaultV2BlueReallocations = (reallocations, targetMarketId) => {
|
|
369
323
|
const penaltyByVault = new Map();
|
|
@@ -375,7 +329,7 @@ export const validateVaultV2BlueReallocations = (reallocations, targetMarketId)
|
|
|
375
329
|
reallocation === null ||
|
|
376
330
|
"withdrawals" in reallocation ||
|
|
377
331
|
"fee" in reallocation) {
|
|
378
|
-
throw new
|
|
332
|
+
throw new InvalidVaultV2BlueReallocationShapeError();
|
|
379
333
|
}
|
|
380
334
|
if (typeof reallocation.vault !== "string" ||
|
|
381
335
|
!isAddress(reallocation.vault)) {
|
|
@@ -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 = "
|
|
3
|
+
export type RequirementSpenderKey = "permit2" | "midnight" | "midnightBundles" | "vaultExitBundlesV1" | "vaultBundlesV1" | "blueBundlesV1";
|
|
4
4
|
/**
|
|
5
5
|
* Validates that a requirement encoder spender matches one of the allowed chain addresses.
|
|
6
6
|
*
|
|
@@ -24,9 +24,8 @@ import { UnsupportedErc20ApprovalSpenderError } from "../types/index.js";
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export const validateRequirementSpender = (params) => {
|
|
27
|
-
const { permit2, midnight, midnightBundles,
|
|
27
|
+
const { permit2, midnight, midnightBundles, bundles } = getChainAddresses(params.chainId);
|
|
28
28
|
const addresses = {
|
|
29
|
-
generalAdapter1,
|
|
30
29
|
permit2,
|
|
31
30
|
midnight,
|
|
32
31
|
midnightBundles,
|
|
@@ -39,7 +38,6 @@ export const validateRequirementSpender = (params) => {
|
|
|
39
38
|
throw new UnsupportedErc20ApprovalSpenderError({
|
|
40
39
|
spender: params.spender,
|
|
41
40
|
chainId: params.chainId,
|
|
42
|
-
generalAdapter1,
|
|
43
41
|
permit2,
|
|
44
42
|
midnight,
|
|
45
43
|
midnightBundles,
|
|
@@ -192,23 +192,34 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
192
192
|
* The result is the **denominator of {@link computeMinForceWithdrawSharePrice}** — the largest share
|
|
193
193
|
* burn the realized exit price is measured against. It takes the max over the two supplied snapshots
|
|
194
194
|
* because interest lowers the burn while management fees raise it, so neither snapshot alone bounds
|
|
195
|
-
* execution. The entity passes
|
|
196
|
-
* underestimates the burn a stale fee-bearing vault realizes —
|
|
197
|
-
* management fees before burning shares —
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
195
|
+
* execution. The entity passes the raw `lastUpdate` snapshot and the same vault accrued to `now`
|
|
196
|
+
* (execution time): the raw snapshot underestimates the burn a stale fee-bearing vault realizes —
|
|
197
|
+
* the first withdrawal accrues pending management fees before burning shares — while the `now`
|
|
198
|
+
* accrual underestimates it when it projects interest the chain has not realized (a wall clock
|
|
199
|
+
* running ahead of the chain, or a capped `maxRate`); either alone would lift the floor above the
|
|
200
|
+
* faithful price and trip `SlippageExceeded`. Accruing to `now`, not the caller-chosen `deadline`,
|
|
201
|
+
* tracks execution without letting a long deadline silently weaken the guard; `slippageTolerance`
|
|
202
|
+
* absorbs the residual drift until inclusion.
|
|
201
203
|
*
|
|
202
|
-
* This is **not** the share allowance to authorize. The
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* `
|
|
206
|
-
*
|
|
204
|
+
* This is **not** the share allowance to authorize. The contract measures the *net* burn, which
|
|
205
|
+
* fee mints to `owner` shrink, and the raw snapshot mints none while the `now` accrual mints
|
|
206
|
+
* `computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: now })`; so the
|
|
207
|
+
* entity nets each endpoint before taking the max (`max(burnRaw, burnNow - feeSharesNow)`) rather
|
|
208
|
+
* than subtracting the `now` fee from a gross max. The allowance is
|
|
209
|
+
* `min(max(mulDivUp(exitAssets, RAY, max(min(mulDivDown(minSharePriceE27, WAD - slippageTolerance,
|
|
210
|
+
* WAD), minSharePriceE27 - 1), 1)), mulDivUp(exitAssets, RAY, minSharePriceE27) + 1)
|
|
211
|
+
* + computeVaultV2ForceWithdrawFeeSharesMinted({ vaultData, owner, timestamp: deadline }),
|
|
212
|
+
* maxUint256)`: the permit pays for the *gross* burn, covering a burn at least one tolerance step
|
|
213
|
+
* below the floor whenever the floor exceeds one RAY unit and, in any case, at least one share
|
|
214
|
+
* above the burn at the floor, so a price within that headroom below the floor reverts on the
|
|
215
|
+
* contract's `minSharePriceE27` check rather than on the allowance; a deeper drop can still
|
|
216
|
+
* surface as an ERC-20 allowance underflow.
|
|
207
217
|
*
|
|
208
218
|
* @param params - Share-bound inputs.
|
|
209
219
|
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
210
220
|
* @param params.deadlineVaultData - The same vault accrued to a second timestamp; the max of the two
|
|
211
|
-
* share burns is returned. The entity
|
|
221
|
+
* share burns is returned. The entity calls this twice — the raw snapshot for both parameters,
|
|
222
|
+
* then the `now` accrual for both — and nets each result before taking the max.
|
|
212
223
|
* @param params.plan - Plan from {@link computeVaultV2ForceWithdrawPlan}.
|
|
213
224
|
* @returns An upper bound, in vault shares, of what the exit burns.
|
|
214
225
|
* @example
|
|
@@ -220,7 +231,12 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
220
231
|
* } from "@morpho-org/morpho-sdk";
|
|
221
232
|
*
|
|
222
233
|
* const { vault: nowVaultData } = vaultData.accrueInterest(now);
|
|
223
|
-
* const
|
|
234
|
+
* const sharesBurntRaw = computeVaultV2ForceWithdrawSharesBurnt({
|
|
235
|
+
* vaultData,
|
|
236
|
+
* deadlineVaultData: vaultData,
|
|
237
|
+
* plan,
|
|
238
|
+
* });
|
|
239
|
+
* const sharesBurntNow = computeVaultV2ForceWithdrawSharesBurnt({
|
|
224
240
|
* vaultData: nowVaultData,
|
|
225
241
|
* deadlineVaultData: nowVaultData,
|
|
226
242
|
* plan,
|
|
@@ -230,9 +246,26 @@ export declare function computeVaultV2ForceWithdrawPlan(params: {
|
|
|
230
246
|
* owner,
|
|
231
247
|
* timestamp: now,
|
|
232
248
|
* });
|
|
233
|
-
* const sharesBurntForFloor =
|
|
249
|
+
* const sharesBurntForFloor = MathLib.max(
|
|
250
|
+
* sharesBurntRaw,
|
|
251
|
+
* sharesBurntNow - feeSharesNow,
|
|
252
|
+
* );
|
|
253
|
+
* const allowanceSharePriceE27 = MathLib.max(
|
|
254
|
+
* MathLib.min(
|
|
255
|
+
* MathLib.mulDivDown(
|
|
256
|
+
* minSharePriceE27,
|
|
257
|
+
* MathLib.WAD - slippageTolerance,
|
|
258
|
+
* MathLib.WAD,
|
|
259
|
+
* ),
|
|
260
|
+
* minSharePriceE27 - 1n,
|
|
261
|
+
* ),
|
|
262
|
+
* 1n,
|
|
263
|
+
* );
|
|
234
264
|
* const requiredShareAllowance = MathLib.min(
|
|
235
|
-
* MathLib.
|
|
265
|
+
* MathLib.max(
|
|
266
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, allowanceSharePriceE27),
|
|
267
|
+
* MathLib.mulDivUp(exitAssets, MathLib.RAY, minSharePriceE27) + 1n,
|
|
268
|
+
* ) +
|
|
236
269
|
* computeVaultV2ForceWithdrawFeeSharesMinted({
|
|
237
270
|
* vaultData,
|
|
238
271
|
* owner,
|