@morpho-org/morpho-sdk 6.0.0-next.1 → 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 +199 -34
- package/README.md +23 -15
- package/lib/cjs/abis.d.ts +3 -2829
- package/lib/cjs/abis.js +1 -1938
- 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 +6 -35
- 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 +4 -9
- 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 +38 -4
- package/lib/cjs/actions/bundles/common.js +91 -35
- 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 +9 -8
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +17 -26
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/blue/index.js +0 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +24 -25
- 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 +21 -12
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +39 -38
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- 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 -4
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +12 -8
- 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 +58 -39
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +87 -60
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/cjs/augment.d.ts +0 -1
- package/lib/cjs/augment.js +0 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +2 -2
- package/lib/cjs/blue/entities.js +1 -2
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +1 -1
- package/lib/cjs/blue/fetch.js +1 -2
- 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 +38 -264
- package/lib/cjs/entities/blue/blue.js +2 -203
- package/lib/cjs/entities/index.d.ts +3 -60
- package/lib/cjs/entities/index.js +1 -20
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +19 -14
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/cjs/entities/requirements/index.d.ts +1 -0
- package/lib/cjs/entities/requirements/index.js +1 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +25 -8
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/cjs/entities/vaultV2/vaultV2.js +249 -23
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +50 -34
- package/lib/cjs/errors.d.ts +2 -46
- package/lib/cjs/errors.js +2 -46
- package/lib/cjs/fetch.d.ts +1 -15
- package/lib/cjs/fetch.js +1 -16
- package/lib/cjs/helpers/constant.d.ts +0 -2
- package/lib/cjs/helpers/constant.js +0 -2
- package/lib/cjs/helpers/index.d.ts +4 -3
- package/lib/cjs/helpers/index.js +10 -9
- package/lib/cjs/helpers/metadata.d.ts +3 -5
- package/lib/cjs/helpers/metadata.js +4 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +164 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/cjs/helpers/slippage.d.ts +34 -90
- package/lib/cjs/helpers/slippage.js +52 -137
- package/lib/cjs/helpers/utilization.d.ts +12 -10
- package/lib/cjs/helpers/utilization.js +27 -12
- package/lib/cjs/helpers/validate.d.ts +66 -32
- package/lib/cjs/helpers/validate.js +84 -57
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -3
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/types/action.d.ts +102 -68
- package/lib/cjs/types/action.js +11 -4
- package/lib/cjs/types/error.d.ts +332 -385
- package/lib/cjs/types/error.js +369 -412
- package/lib/cjs/types/sharedLiquidity.d.ts +1 -117
- package/lib/cjs/types.d.ts +2 -18
- package/lib/cjs/utils.d.ts +8 -35
- package/lib/cjs/utils.js +11 -36
- package/lib/esm/abis.d.ts +3 -2829
- package/lib/esm/abis.js +3 -1935
- 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 +8 -37
- 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 +6 -11
- 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 +38 -4
- package/lib/esm/actions/bundles/common.js +91 -36
- 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 +9 -8
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +20 -29
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -1
- package/lib/esm/actions/requirements/blue/index.js +0 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +20 -14
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +25 -26
- 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 +21 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +40 -39
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +14 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +9 -6
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +22 -17
- 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 -4
- package/lib/esm/actions/vaultV1/inKindRedeem.js +12 -8
- 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 +58 -39
- package/lib/esm/actions/vaultV2/forceWithdraw.js +89 -62
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +6 -4
- package/lib/esm/actions/vaultV2/inKindRedeem.js +12 -8
- package/lib/esm/augment.d.ts +0 -1
- package/lib/esm/augment.js +0 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +2 -2
- package/lib/esm/blue/entities.js +1 -1
- package/lib/esm/blue/errors.d.ts +1 -1
- package/lib/esm/blue/errors.js +1 -1
- package/lib/esm/blue/fetch.d.ts +1 -1
- package/lib/esm/blue/fetch.js +1 -1
- 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 +38 -264
- package/lib/esm/entities/blue/blue.js +5 -206
- package/lib/esm/entities/index.d.ts +3 -60
- package/lib/esm/entities/index.js +1 -16
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +7 -6
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +20 -15
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +3 -3
- package/lib/esm/entities/requirements/index.d.ts +1 -0
- package/lib/esm/entities/requirements/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +18 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +29 -12
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +154 -35
- package/lib/esm/entities/vaultV2/vaultV2.js +256 -30
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +48 -32
- package/lib/esm/errors.d.ts +2 -46
- package/lib/esm/errors.js +2 -46
- package/lib/esm/fetch.d.ts +1 -15
- package/lib/esm/fetch.js +1 -15
- package/lib/esm/helpers/constant.d.ts +0 -2
- package/lib/esm/helpers/constant.js +0 -2
- package/lib/esm/helpers/index.d.ts +4 -3
- package/lib/esm/helpers/index.js +4 -3
- package/lib/esm/helpers/metadata.d.ts +3 -5
- package/lib/esm/helpers/metadata.js +4 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +107 -0
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +161 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
- package/lib/esm/helpers/slippage.d.ts +34 -90
- package/lib/esm/helpers/slippage.js +52 -134
- package/lib/esm/helpers/utilization.d.ts +12 -10
- package/lib/esm/helpers/utilization.js +26 -11
- package/lib/esm/helpers/validate.d.ts +66 -32
- package/lib/esm/helpers/validate.js +83 -57
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -3
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/types/action.d.ts +102 -68
- package/lib/esm/types/action.js +12 -5
- package/lib/esm/types/error.d.ts +332 -385
- package/lib/esm/types/error.js +355 -392
- package/lib/esm/types/sharedLiquidity.d.ts +1 -117
- package/lib/esm/types.d.ts +2 -18
- package/lib/esm/utils.d.ts +8 -35
- package/lib/esm/utils.js +7 -34
- package/package.json +7 -15
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -83
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -151
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -50
- 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 -44
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -43
- 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 -8
- 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 -326
- package/lib/cjs/entities/vaultV1ReallocationData.js +0 -542
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +0 -243
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +0 -42
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +0 -79
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.d.ts +0 -88
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +0 -147
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +0 -37
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +0 -46
- 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 -44
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +0 -39
- 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 -8
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +0 -5
- 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 -326
- package/lib/esm/entities/vaultV1ReallocationData.js +0 -544
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +0 -78
- package/lib/esm/helpers/computeVaultV1Reallocations.js +0 -239
- /package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
- /package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.d.ts +0 -0
|
@@ -1,105 +1,49 @@
|
|
|
1
|
-
import { type AccrualVault, AccrualVaultV2
|
|
1
|
+
import { type AccrualVault, AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
2
|
/**
|
|
3
|
-
* Computes the minimum
|
|
3
|
+
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
4
4
|
*
|
|
5
|
-
* Mirrors the on-chain check in
|
|
5
|
+
* Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
|
|
6
6
|
* ```solidity
|
|
7
|
-
* require(
|
|
7
|
+
* require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
10
|
+
* The realized price sits structurally *below* the vault's share price because the
|
|
11
|
+
* force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
|
|
12
|
+
* from the raw share price would reject every penalised exit. Both inputs are therefore taken from
|
|
13
|
+
* the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
|
|
14
|
+
* `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
|
|
15
|
+
* faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
|
|
16
|
+
* shifting from the penalty-free leg to the penalised leg all do.
|
|
49
17
|
*
|
|
50
|
-
*
|
|
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.
|
|
18
|
+
* The referral fee is deducted *after* this check, so it is outside the bound's protection.
|
|
56
19
|
*
|
|
57
20
|
* @param params - Computation parameters.
|
|
58
|
-
* @param params.
|
|
59
|
-
* @param params.
|
|
21
|
+
* @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
|
|
22
|
+
* @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
|
|
60
23
|
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
61
|
-
* @returns `
|
|
62
|
-
* @throws {
|
|
63
|
-
* @throws {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
24
|
+
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
25
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
26
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
|
|
27
|
+
* `MAX_SLIPPAGE_TOLERANCE`.
|
|
28
|
+
* @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
|
|
29
|
+
* would silently nullify the on-chain bound.
|
|
30
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
|
|
31
|
+
* would nullify the bound just as a non-positive input would.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
72
35
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
36
|
+
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
37
|
+
* withdrawnAssets: plan.withdrawnAssets,
|
|
38
|
+
* sharesBurnt,
|
|
39
|
+
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
40
|
+
* });
|
|
76
41
|
* ```
|
|
77
|
-
*
|
|
78
|
-
* Supports both assets and shares modes:
|
|
79
|
-
* - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
|
|
80
|
-
* withdrawer against over-burning shares).
|
|
81
|
-
* - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
|
|
82
|
-
* amount paid out).
|
|
83
|
-
*
|
|
84
|
-
* Direction is opposite of supply's `maxSharePrice`:
|
|
85
|
-
* - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
|
|
86
|
-
* - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
|
|
87
|
-
* assets per share burned).
|
|
88
|
-
*
|
|
89
|
-
* @param params - Computation parameters.
|
|
90
|
-
* @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
|
|
91
|
-
* @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
|
|
92
|
-
* @param params.market - The market to compute the minimum withdraw share price for.
|
|
93
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
94
|
-
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
95
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
96
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
97
42
|
*/
|
|
98
|
-
export declare function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
slippageTolerance: bigint;
|
|
43
|
+
export declare function computeMinForceWithdrawSharePrice(params: {
|
|
44
|
+
readonly withdrawnAssets: bigint;
|
|
45
|
+
readonly sharesBurnt: bigint;
|
|
46
|
+
readonly slippageTolerance: bigint;
|
|
103
47
|
}): bigint;
|
|
104
48
|
/**
|
|
105
49
|
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
@@ -1,159 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
|
|
6
|
-
exports.computeMaxSupplySharePrice = computeMaxSupplySharePrice;
|
|
7
|
-
exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
|
|
4
|
+
exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
|
|
8
5
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
9
6
|
const index_js_1 = require("../types/index.js");
|
|
10
7
|
const constant_js_1 = require("./constant.js");
|
|
11
8
|
const validate_js_1 = require("./validate.js");
|
|
12
9
|
/**
|
|
13
|
-
* Computes the minimum
|
|
10
|
+
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
14
11
|
*
|
|
15
|
-
* Mirrors the on-chain check in
|
|
12
|
+
* Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
|
|
16
13
|
* ```solidity
|
|
17
|
-
* require(
|
|
14
|
+
* require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
|
|
18
15
|
* ```
|
|
19
16
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const { borrowAmount, market, slippageTolerance } = params;
|
|
28
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
29
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
30
|
-
}
|
|
31
|
-
const expectedShares = market.toBorrowShares(borrowAmount, "Up");
|
|
32
|
-
if (expectedShares === 0n) {
|
|
33
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
34
|
-
}
|
|
35
|
-
return blue_sdk_1.MathLib.mulDivDown(borrowAmount, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), expectedShares);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Computes the maximum repay share price (in RAY, 1e27) for slippage protection.
|
|
39
|
-
*
|
|
40
|
-
* Supports both repay-by-assets and repay-by-shares paths:
|
|
41
|
-
* - By assets: derives expected shares from the repay amount via `toBorrowShares("Down")`.
|
|
42
|
-
* - By shares: derives expected assets from the shares via `toBorrowAssets("Up")`.
|
|
43
|
-
*
|
|
44
|
-
* Direction is opposite of borrow's `minSharePrice`:
|
|
45
|
-
* - Borrow uses `(WAD - slippage)` → lower bound (protects borrower from getting fewer assets per share).
|
|
46
|
-
* - Repay uses `(WAD + slippage)` → upper bound (protects repayer from paying too many assets per share).
|
|
47
|
-
*
|
|
48
|
-
* Capped at {@link MAX_ABSOLUTE_SHARE_PRICE} to prevent absurd values.
|
|
49
|
-
*
|
|
50
|
-
* @param params - Computation parameters.
|
|
51
|
-
* @param params.repayAssets - The amount of assets to repay (0n when repaying by shares).
|
|
52
|
-
* @param params.repayShares - The amount of shares to repay (0n when repaying by assets).
|
|
53
|
-
* @param params.market - The market to compute the maximum repay share price for.
|
|
54
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. 0.003e18 = 0.3%).
|
|
55
|
-
* @returns maxSharePriceE27 in RAY scale (1e27).
|
|
56
|
-
*/
|
|
57
|
-
function computeMaxRepaySharePrice(params) {
|
|
58
|
-
const { repayAssets, repayShares, market, slippageTolerance } = params;
|
|
59
|
-
if (slippageTolerance >= blue_sdk_1.MathLib.WAD) {
|
|
60
|
-
throw new index_js_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
61
|
-
}
|
|
62
|
-
let assets;
|
|
63
|
-
let shares;
|
|
64
|
-
if (repayShares > 0n) {
|
|
65
|
-
assets = market.toBorrowAssets(repayShares, "Up");
|
|
66
|
-
shares = repayShares;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
assets = repayAssets;
|
|
70
|
-
shares = market.toBorrowShares(repayAssets, "Down");
|
|
71
|
-
}
|
|
72
|
-
if (shares === 0n) {
|
|
73
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
74
|
-
}
|
|
75
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares);
|
|
76
|
-
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Computes the maximum supply share price (in RAY, 1e27) for slippage protection.
|
|
80
|
-
*
|
|
81
|
-
* Mirrors the on-chain check in GeneralAdapter1's `morphoSupply`:
|
|
82
|
-
* ```solidity
|
|
83
|
-
* require(suppliedAssets.rDivUp(suppliedShares) <= maxSharePriceE27)
|
|
84
|
-
* ```
|
|
17
|
+
* The realized price sits structurally *below* the vault's share price because the
|
|
18
|
+
* force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
|
|
19
|
+
* from the raw share price would reject every penalised exit. Both inputs are therefore taken from
|
|
20
|
+
* the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
|
|
21
|
+
* `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
|
|
22
|
+
* faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
|
|
23
|
+
* shifting from the penalty-free leg to the penalised leg all do.
|
|
85
24
|
*
|
|
86
|
-
*
|
|
25
|
+
* The referral fee is deducted *after* this check, so it is outside the bound's protection.
|
|
87
26
|
*
|
|
88
27
|
* @param params - Computation parameters.
|
|
89
|
-
* @param params.
|
|
90
|
-
* @param params.
|
|
28
|
+
* @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
|
|
29
|
+
* @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
|
|
91
30
|
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
92
|
-
* @returns `
|
|
93
|
-
* @throws {
|
|
94
|
-
* @throws {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
throw new index_js_1.ShareDivideByZeroError(market.params.id);
|
|
104
|
-
}
|
|
105
|
-
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(supplyAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), expectedShares);
|
|
106
|
-
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
31
|
+
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
32
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
33
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
|
|
34
|
+
* `MAX_SLIPPAGE_TOLERANCE`.
|
|
35
|
+
* @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
|
|
36
|
+
* would silently nullify the on-chain bound.
|
|
37
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
|
|
38
|
+
* would nullify the bound just as a non-positive input would.
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
110
42
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
43
|
+
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
44
|
+
* withdrawnAssets: plan.withdrawnAssets,
|
|
45
|
+
* sharesBurnt,
|
|
46
|
+
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
47
|
+
* });
|
|
114
48
|
* ```
|
|
115
|
-
*
|
|
116
|
-
* Supports both assets and shares modes:
|
|
117
|
-
* - By assets: derives expected shares via `toSupplyShares("Up")` (upper bound, protects the
|
|
118
|
-
* withdrawer against over-burning shares).
|
|
119
|
-
* - By shares: derives expected assets via `toSupplyAssets("Down")` (lower bound, the on-chain
|
|
120
|
-
* amount paid out).
|
|
121
|
-
*
|
|
122
|
-
* Direction is opposite of supply's `maxSharePrice`:
|
|
123
|
-
* - Supply uses `(WAD + slippage)` → upper bound (anti-inflation).
|
|
124
|
-
* - Withdraw uses `(WAD − slippage)` → lower bound (protects withdrawer from receiving too few
|
|
125
|
-
* assets per share burned).
|
|
126
|
-
*
|
|
127
|
-
* @param params - Computation parameters.
|
|
128
|
-
* @param params.withdrawAssets - The amount of assets to withdraw (`0n` when withdrawing by shares).
|
|
129
|
-
* @param params.withdrawShares - The amount of shares to withdraw (`0n` when withdrawing by assets).
|
|
130
|
-
* @param params.market - The market to compute the minimum withdraw share price for.
|
|
131
|
-
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
132
|
-
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
133
|
-
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance >= WAD`.
|
|
134
|
-
* @throws {ShareDivideByZeroError} when expected shares round down to zero.
|
|
135
49
|
*/
|
|
136
|
-
function
|
|
137
|
-
const {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
50
|
+
function computeMinForceWithdrawSharePrice(params) {
|
|
51
|
+
const { withdrawnAssets, sharesBurnt, slippageTolerance } = params;
|
|
52
|
+
(0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
53
|
+
// A zero on either side would yield `minSharePriceE27 = 0`, i.e. no bound at all.
|
|
54
|
+
if (withdrawnAssets <= 0n) {
|
|
55
|
+
throw new index_js_1.NonPositiveInputError("withdrawnAssets", withdrawnAssets);
|
|
56
|
+
}
|
|
57
|
+
if (sharesBurnt <= 0n) {
|
|
58
|
+
throw new index_js_1.NonPositiveInputError("sharesBurnt", sharesBurnt);
|
|
59
|
+
}
|
|
60
|
+
const minSharePriceE27 = blue_sdk_1.MathLib.mulDivDown(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), sharesBurnt);
|
|
61
|
+
// Positive inputs are not enough: the ratio itself can round down to zero once the burn exceeds
|
|
62
|
+
// what the withdrawn assets can price at RAY scale, which would reintroduce the very opt-out the
|
|
63
|
+
// guards above exist to prevent.
|
|
64
|
+
if (minSharePriceE27 === 0n) {
|
|
65
|
+
throw new index_js_1.VaultV2ForceWithdrawZeroSharePriceError({
|
|
66
|
+
withdrawnAssets,
|
|
67
|
+
sharesBurnt,
|
|
68
|
+
slippageTolerance,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return minSharePriceE27;
|
|
157
72
|
}
|
|
158
73
|
/**
|
|
159
74
|
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
@@ -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,17 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveMaxWithdrawalUtilization = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const index_js_1 = require("../types/index.js");
|
|
4
6
|
const constant_js_1 = require("./constant.js");
|
|
5
7
|
/**
|
|
6
|
-
* Resolves
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
8
|
+
* Resolves and validates a source withdrawal utilization ceiling.
|
|
9
|
+
* @internal
|
|
10
|
+
* @param value - Optional WAD-scaled utilization ceiling.
|
|
11
|
+
* @param field - Option name reported in validation errors.
|
|
12
|
+
* @returns A ceiling between zero and WAD, defaulting to the shared withdrawal target.
|
|
13
|
+
* @throws {NegativeInputError} when the ceiling is negative.
|
|
14
|
+
* @throws {InputExceedsMaxError} when the ceiling exceeds WAD.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const ceiling = resolveMaxWithdrawalUtilization(undefined);
|
|
18
|
+
* ```
|
|
13
19
|
*/
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
|
|
21
|
+
const utilization = value ?? constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
|
|
22
|
+
if (utilization < 0n)
|
|
23
|
+
throw new index_js_1.NegativeInputError(field, utilization);
|
|
24
|
+
if (utilization > blue_sdk_1.MathLib.WAD)
|
|
25
|
+
throw new index_js_1.InputExceedsMaxError({
|
|
26
|
+
field,
|
|
27
|
+
value: utilization,
|
|
28
|
+
max: blue_sdk_1.MathLib.WAD,
|
|
29
|
+
});
|
|
30
|
+
return utilization;
|
|
31
|
+
};
|
|
32
|
+
exports.resolveMaxWithdrawalUtilization = resolveMaxWithdrawalUtilization;
|
|
@@ -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
|
/**
|
|
@@ -17,6 +17,41 @@ export declare const compareMarketIds: (idA: MarketId, idB: MarketId) => -1 | 0
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
export declare const validateUint256Field: (field: string, value: bigint) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Rejects a deadline that no periphery can honour: the contracts read `0` as "unset" and the ABI
|
|
22
|
+
* slot is a `uint256`. Callers that also need the deadline to be in the future layer their own
|
|
23
|
+
* `ExpiredDeadlineError` on top — this check stays clock-free so transaction builders can use it.
|
|
24
|
+
*
|
|
25
|
+
* @param deadline - Candidate deadline, in seconds.
|
|
26
|
+
* @returns Nothing when `deadline` is a positive `uint256`.
|
|
27
|
+
* @throws {NonPositiveInputError} when `deadline` is not positive.
|
|
28
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `maxUint256`.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare const validateDeadline: (deadline: bigint) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Validates an optional referral fee and returns the pair every referral-fee-bearing periphery
|
|
34
|
+
* encodes. Shared by the direct BlueBundlesV1 writes and the VaultExitBundlesV1 force withdrawal,
|
|
35
|
+
* whose contracts apply the same `[0, WAD)` bound and both transfer the fee unconditionally.
|
|
36
|
+
*
|
|
37
|
+
* @param params - Referral fee inputs.
|
|
38
|
+
* @param params.referralFeePct - Optional WAD-scaled fee share. Defaults to `0n`.
|
|
39
|
+
* @param params.referralFeeRecipient - Optional fee recipient. Defaults to the zero address, which
|
|
40
|
+
* is only valid alongside a zero `referralFeePct`.
|
|
41
|
+
* @returns The normalized `{ referralFeePct, referralFeeRecipient }` pair.
|
|
42
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
43
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD (the contracts reject
|
|
44
|
+
* it with `PctExceeded`); it extends `InputExceedsMaxError`, preserving that pattern-match.
|
|
45
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const validateReferralFee: (params: {
|
|
49
|
+
readonly referralFeePct?: bigint;
|
|
50
|
+
readonly referralFeeRecipient?: Address;
|
|
51
|
+
}) => {
|
|
52
|
+
readonly referralFeePct: bigint;
|
|
53
|
+
readonly referralFeeRecipient: Address;
|
|
54
|
+
};
|
|
20
55
|
/**
|
|
21
56
|
* Validates that a raw or hydrated Midnight market belongs to the expected chain.
|
|
22
57
|
*
|
|
@@ -36,22 +71,44 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
|
|
|
36
71
|
* Asserts that the client has a connected account AND that it matches
|
|
37
72
|
* the provided user address.
|
|
38
73
|
*
|
|
39
|
-
* Used
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
74
|
+
* Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
|
|
75
|
+
* backs the permit, Permit2, Blue authorization, and Midnight offer-root
|
|
76
|
+
* signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
|
|
77
|
+
* signer: the signing flow is
|
|
78
|
+
* the only path where an account/address mismatch is a real security concern
|
|
79
|
+
* (rather than just an integrator footgun).
|
|
43
80
|
*
|
|
44
81
|
* Transaction builders no longer call this helper — callers are
|
|
45
82
|
* responsible for keeping `userAddress` aligned with the signing account
|
|
46
83
|
* at the builder layer.
|
|
47
84
|
*
|
|
48
|
-
* Throws {@link MissingClientPropertyError} if the client has no account.
|
|
49
|
-
* Throws {@link AddressMismatchError} if the client account differs from
|
|
50
|
-
* `userAddress`.
|
|
51
|
-
*
|
|
52
85
|
* @param clientAccountAddress - The client's account address; if undefined,
|
|
53
86
|
* `MissingClientPropertyError` is thrown.
|
|
54
87
|
* @param userAddress - The user address provided by the caller.
|
|
88
|
+
* @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when
|
|
89
|
+
* it is present and equal to `userAddress`.
|
|
90
|
+
* @throws {MissingClientPropertyError} when the client has no connected account.
|
|
91
|
+
* @throws {AddressMismatchError} when the client account differs from
|
|
92
|
+
* `userAddress`.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { createWalletClient, http } from "viem";
|
|
96
|
+
* import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
97
|
+
* import { mainnet } from "viem/chains";
|
|
98
|
+
* import { validateUserAddress } from "@morpho-org/morpho-sdk";
|
|
99
|
+
*
|
|
100
|
+
* const account = privateKeyToAccount(generatePrivateKey());
|
|
101
|
+
* const walletClient = createWalletClient({
|
|
102
|
+
* account,
|
|
103
|
+
* chain: mainnet,
|
|
104
|
+
* transport: http(),
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // Inside a `sign()` flow, before producing a typed-data signature:
|
|
108
|
+
* validateUserAddress(walletClient.account?.address, account.address);
|
|
109
|
+
* // Passes when the connected account equals the expected signer;
|
|
110
|
+
* // throws if the wallet has no account or signs for a different address.
|
|
111
|
+
* ```
|
|
55
112
|
*/
|
|
56
113
|
export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address;
|
|
57
114
|
/**
|
|
@@ -152,29 +209,6 @@ export declare const validateRepayShares: (params: {
|
|
|
152
209
|
repayShares: bigint;
|
|
153
210
|
marketId: MarketId;
|
|
154
211
|
}) => void;
|
|
155
|
-
/**
|
|
156
|
-
* Validates that Vault V1 PublicAllocator reallocations are well-formed.
|
|
157
|
-
*
|
|
158
|
-
* @param reallocations - Vault V1 reallocations to validate.
|
|
159
|
-
* @param targetMarketId - The operation's target market ID.
|
|
160
|
-
* @returns Nothing when every reallocation is valid.
|
|
161
|
-
* @throws {NegativeInputError} when a reallocation fee is negative.
|
|
162
|
-
* @throws {EmptyReallocationWithdrawalsError} when a reallocation has no withdrawals.
|
|
163
|
-
* @throws {NonPositiveInputError} when a withdrawal amount is non-positive.
|
|
164
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
165
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals are not strictly market-id sorted.
|
|
166
|
-
* @deprecated Vault V1 PublicAllocator validation will be removed in the next major. Use Vault V2
|
|
167
|
-
* reallocations for new integrations.
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* import type { BlueMarketId } from "@morpho-org/morpho-sdk/types";
|
|
171
|
-
* import { validateReallocations } from "@morpho-org/morpho-sdk";
|
|
172
|
-
* import { zeroHash } from "viem";
|
|
173
|
-
*
|
|
174
|
-
* const result: void = validateReallocations([], zeroHash as BlueMarketId);
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
export declare const validateReallocations: (reallocations: Iterable<VaultV1Reallocation>, targetMarketId: MarketId) => void;
|
|
178
212
|
/** @internal */
|
|
179
213
|
export declare const validateVaultV2BlueReallocations: (reallocations: Iterable<VaultV2BlueReallocation>, targetMarketId: MarketId) => void;
|
|
180
214
|
/**
|