@morpho-org/morpho-sdk 6.0.0-next.0 → 6.0.0-next.2
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 +329 -15
- package/README.md +93 -47
- package/lib/cjs/abis.d.ts +227 -2
- package/lib/cjs/abis.js +156 -3
- package/lib/cjs/actions/blue/borrow.d.ts +1 -1
- package/lib/cjs/actions/blue/borrow.js +1 -1
- package/lib/cjs/actions/blue/common.d.ts +6 -19
- package/lib/cjs/actions/blue/common.js +28 -162
- package/lib/cjs/actions/blue/refinance.d.ts +1 -1
- package/lib/cjs/actions/blue/refinance.js +1 -1
- package/lib/cjs/actions/blue/repay.d.ts +3 -3
- package/lib/cjs/actions/blue/repay.js +1 -1
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/blue/supply.d.ts +3 -3
- package/lib/cjs/actions/blue/supply.js +3 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -1
- package/lib/cjs/actions/blue/withdraw.js +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -1
- package/lib/cjs/actions/bundles/common.d.ts +230 -0
- package/lib/cjs/actions/bundles/common.js +507 -0
- package/lib/cjs/actions/bundles/index.d.ts +3 -0
- package/lib/cjs/actions/bundles/index.js +23 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +125 -0
- package/lib/cjs/actions/index.d.ts +1 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +2 -2
- package/lib/cjs/actions/midnight/takeLend.js +2 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +6 -10
- package/lib/cjs/actions/requirements/blue/index.d.ts +0 -2
- package/lib/cjs/actions/requirements/blue/index.js +0 -2
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +21 -21
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +43 -31
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{esm/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/cjs/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +27 -22
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/cjs/actions/requirements/encode/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/index.js +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/cjs/actions/signatures/getTokenRequirementActions.js +2 -2
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +20 -66
- package/lib/cjs/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/cjs/actions/vaultV1/deposit.js +110 -109
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/cjs/actions/vaultV1/migrateToV2.js +91 -104
- package/lib/cjs/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/cjs/actions/vaultV1/redeem.js +56 -33
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/cjs/actions/vaultV1/withdraw.js +86 -34
- package/lib/cjs/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/cjs/actions/vaultV2/deposit.js +111 -109
- 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 +1 -0
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/cjs/actions/vaultV2/redeem.js +56 -34
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/cjs/actions/vaultV2/withdraw.js +86 -35
- package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/cjs/blue/abis.d.ts +5 -1
- package/lib/cjs/blue/abis.js +2 -0
- package/lib/cjs/blue/entities.d.ts +8 -2
- package/lib/cjs/blue/entities.js +1 -0
- package/lib/cjs/blue/errors.d.ts +1 -1
- package/lib/cjs/blue/errors.js +2 -1
- package/lib/cjs/blue/fetch.d.ts +3 -1
- package/lib/cjs/blue/fetch.js +1 -0
- package/lib/cjs/entities/blue/blue.d.ts +29 -20
- package/lib/cjs/entities/blue/blue.js +6 -1
- package/lib/cjs/entities/index.d.ts +9 -2
- package/lib/cjs/entities/index.js +16 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.js +20 -24
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/cjs/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +76 -75
- package/lib/{esm/actions/requirements/blue → cjs/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/cjs/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +74 -0
- package/lib/cjs/entities/requirements/index.d.ts +2 -0
- package/lib/cjs/entities/requirements/index.js +18 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/cjs/entities/vaultV1/vaultV1.js +334 -120
- package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/cjs/entities/vaultV2/vaultV2.js +448 -93
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +3 -2
- package/lib/cjs/fetch.d.ts +3 -1
- package/lib/cjs/fetch.js +1 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +14 -1
- 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/referralFee.d.ts +21 -0
- package/lib/cjs/helpers/referralFee.js +35 -0
- package/lib/cjs/helpers/slippage.d.ts +136 -1
- package/lib/cjs/helpers/slippage.js +188 -0
- package/lib/cjs/helpers/validate.d.ts +67 -8
- package/lib/cjs/helpers/validate.js +94 -9
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +1 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +369 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/types/action.d.ts +273 -82
- package/lib/cjs/types/action.js +12 -12
- package/lib/cjs/types/error.d.ts +349 -23
- package/lib/cjs/types/error.js +393 -39
- package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
- package/lib/cjs/utils.d.ts +3 -1
- package/lib/cjs/utils.js +10 -1
- package/lib/esm/abis.d.ts +227 -2
- package/lib/esm/abis.js +157 -2
- package/lib/esm/actions/blue/borrow.d.ts +1 -1
- package/lib/esm/actions/blue/borrow.js +1 -1
- package/lib/esm/actions/blue/common.d.ts +6 -19
- package/lib/esm/actions/blue/common.js +30 -164
- package/lib/esm/actions/blue/refinance.d.ts +1 -1
- package/lib/esm/actions/blue/refinance.js +1 -1
- package/lib/esm/actions/blue/repay.d.ts +3 -3
- package/lib/esm/actions/blue/repay.js +1 -1
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/blue/supply.d.ts +3 -3
- package/lib/esm/actions/blue/supply.js +5 -10
- package/lib/esm/actions/blue/supplyCollateral.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateral.js +1 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +3 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +1 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -1
- package/lib/esm/actions/blue/withdraw.js +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +230 -0
- package/lib/esm/actions/bundles/common.js +494 -0
- package/lib/esm/actions/bundles/index.d.ts +3 -0
- package/lib/esm/actions/bundles/index.js +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +76 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +121 -0
- package/lib/esm/actions/index.d.ts +1 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +2 -2
- package/lib/esm/actions/midnight/takeBorrow.js +2 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +2 -2
- package/lib/esm/actions/midnight/takeLend.js +2 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +8 -12
- package/lib/esm/actions/requirements/blue/index.d.ts +0 -2
- package/lib/esm/actions/requirements/blue/index.js +0 -2
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +15 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +22 -22
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +19 -10
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +44 -32
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +15 -10
- package/lib/{cjs/actions/requirements/encode/encodeErc20Permit2TransferFrom.d.ts → esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts} +16 -14
- package/lib/esm/actions/requirements/encode/{encodeErc20Permit2TransferFrom.js → encodeErc20Permit2SignatureTransfer.js} +25 -20
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +12 -9
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +27 -21
- package/lib/esm/actions/requirements/encode/index.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/index.js +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirements.js +1 -0
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +4 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.js +5 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +4 -3
- package/lib/esm/actions/requirements/getRequirementsApproval.js +4 -3
- package/lib/esm/actions/signatures/getTokenRequirementActions.js +3 -3
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +28 -30
- package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +21 -67
- package/lib/esm/actions/vaultV1/deposit.d.ts +73 -57
- package/lib/esm/actions/vaultV1/deposit.js +112 -111
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +1 -0
- package/lib/esm/actions/vaultV1/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +43 -66
- package/lib/esm/actions/vaultV1/migrateToV2.js +93 -106
- package/lib/esm/actions/vaultV1/redeem.d.ts +30 -23
- package/lib/esm/actions/vaultV1/redeem.js +56 -33
- package/lib/esm/actions/vaultV1/withdraw.d.ts +58 -24
- package/lib/esm/actions/vaultV1/withdraw.js +86 -34
- package/lib/esm/actions/vaultV2/deposit.d.ts +74 -57
- package/lib/esm/actions/vaultV2/deposit.js +113 -111
- 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 +1 -0
- package/lib/esm/actions/vaultV2/inKindRedeem.js +3 -2
- package/lib/esm/actions/vaultV2/redeem.d.ts +30 -24
- package/lib/esm/actions/vaultV2/redeem.js +56 -34
- package/lib/esm/actions/vaultV2/withdraw.d.ts +58 -25
- package/lib/esm/actions/vaultV2/withdraw.js +86 -35
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
- package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
- package/lib/esm/blue/abis.d.ts +5 -1
- package/lib/esm/blue/abis.js +5 -1
- package/lib/esm/blue/entities.d.ts +8 -2
- package/lib/esm/blue/entities.js +3 -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 +3 -1
- package/lib/esm/blue/fetch.js +3 -1
- package/lib/esm/entities/blue/blue.d.ts +29 -20
- package/lib/esm/entities/blue/blue.js +7 -2
- package/lib/esm/entities/index.d.ts +9 -2
- package/lib/esm/entities/index.js +4 -1
- package/lib/esm/entities/midnight/midnight.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.js +20 -24
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.d.ts → entities/requirements/getBundlesTokenRequirements.d.ts} +27 -19
- package/lib/esm/{actions/requirements/blue/getBlueBundlesV1TokenRequirements.js → entities/requirements/getBundlesTokenRequirements.js} +67 -66
- package/lib/{cjs/actions/requirements/blue → esm/entities/requirements}/getUnusedPermit2Nonce.d.ts +1 -1
- package/lib/esm/{actions/requirements/blue → entities/requirements}/getUnusedPermit2Nonce.js +4 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +28 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +70 -0
- package/lib/esm/entities/requirements/index.d.ts +2 -0
- package/lib/esm/entities/requirements/index.js +2 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +356 -101
- package/lib/esm/entities/vaultV1/vaultV1.js +338 -124
- package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
- package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +359 -100
- package/lib/esm/entities/vaultV2/vaultV2.js +452 -97
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.js +46 -13
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/fetch.d.ts +3 -1
- package/lib/esm/fetch.js +3 -1
- package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
- package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- 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/referralFee.d.ts +21 -0
- package/lib/esm/helpers/referralFee.js +31 -0
- package/lib/esm/helpers/slippage.d.ts +136 -1
- package/lib/esm/helpers/slippage.js +186 -2
- package/lib/esm/helpers/validate.d.ts +67 -8
- package/lib/esm/helpers/validate.js +92 -10
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +1 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.d.ts +274 -0
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +362 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/types/action.d.ts +273 -82
- package/lib/esm/types/action.js +11 -11
- package/lib/esm/types/error.d.ts +349 -23
- package/lib/esm/types/error.js +377 -31
- package/lib/esm/types/sharedLiquidity.d.ts +2 -2
- package/lib/esm/utils.d.ts +3 -1
- package/lib/esm/utils.js +3 -1
- package/package.json +7 -7
|
@@ -14,6 +14,7 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
|
14
14
|
* @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
|
|
15
15
|
* @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
|
|
16
16
|
* @returns Frontend-ready market choices, or an empty list when no choices are available.
|
|
17
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
17
18
|
* @example
|
|
18
19
|
* ```ts
|
|
19
20
|
* import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
|
|
@@ -40,6 +41,7 @@ function previewVaultV2InKindRedeem(vaultData, params) {
|
|
|
40
41
|
const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
|
|
41
42
|
const availableIdleAssets = vaultData.assetBalance;
|
|
42
43
|
const allocations = adapter.markets
|
|
44
|
+
.filter((market) => (adapter.supplyShares[market.id] ?? 0n) !== 0n)
|
|
43
45
|
.map((market) => ({
|
|
44
46
|
market,
|
|
45
47
|
allocationAssets: market
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
3
|
+
*
|
|
4
|
+
* @param params - Net target and WAD-scaled referral fee.
|
|
5
|
+
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
6
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
|
|
7
|
+
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
8
|
+
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
9
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
13
|
+
*
|
|
14
|
+
* const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
|
|
15
|
+
* // gross satisfies bigint
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const grossFromNetAssets: (params: {
|
|
19
|
+
readonly netAssets: bigint;
|
|
20
|
+
readonly referralFeePct: bigint;
|
|
21
|
+
}) => bigint;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grossFromNetAssets = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const index_js_1 = require("../types/index.js");
|
|
6
|
+
/**
|
|
7
|
+
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
8
|
+
*
|
|
9
|
+
* @param params - Net target and WAD-scaled referral fee.
|
|
10
|
+
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
11
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); must be below WAD.
|
|
12
|
+
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
13
|
+
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
14
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
18
|
+
*
|
|
19
|
+
* const gross = grossFromNetAssets({ netAssets: 990n, referralFeePct: 10_000000000000000n });
|
|
20
|
+
* // gross satisfies bigint
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const grossFromNetAssets = (params) => {
|
|
24
|
+
if (params.netAssets < 0n) {
|
|
25
|
+
throw new index_js_1.NegativeInputError("netAssets", params.netAssets);
|
|
26
|
+
}
|
|
27
|
+
if (params.referralFeePct < 0n) {
|
|
28
|
+
throw new index_js_1.NegativeInputError("referralFeePct", params.referralFeePct);
|
|
29
|
+
}
|
|
30
|
+
if (params.referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
31
|
+
throw new index_js_1.ReferralFeePctExceededError(params.referralFeePct);
|
|
32
|
+
}
|
|
33
|
+
return blue_sdk_1.MathLib.mulDivDown(params.netAssets, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - params.referralFeePct);
|
|
34
|
+
};
|
|
35
|
+
exports.grossFromNetAssets = grossFromNetAssets;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Market } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { type AccrualVault, AccrualVaultV2, type Market } from "@morpho-org/blue-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
4
4
|
*
|
|
@@ -67,6 +67,52 @@ export declare function computeMaxSupplySharePrice(params: {
|
|
|
67
67
|
market: Market;
|
|
68
68
|
slippageTolerance: bigint;
|
|
69
69
|
}): bigint;
|
|
70
|
+
/**
|
|
71
|
+
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
72
|
+
*
|
|
73
|
+
* Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
|
|
74
|
+
* ```solidity
|
|
75
|
+
* require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* The realized price sits structurally *below* the vault's share price because the
|
|
79
|
+
* force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
|
|
80
|
+
* from the raw share price would reject every penalised exit. Both inputs are therefore taken from
|
|
81
|
+
* the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
|
|
82
|
+
* `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
|
|
83
|
+
* faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
|
|
84
|
+
* shifting from the penalty-free leg to the penalised leg all do.
|
|
85
|
+
*
|
|
86
|
+
* The referral fee is deducted *after* this check, so it is outside the bound's protection.
|
|
87
|
+
*
|
|
88
|
+
* @param params - Computation parameters.
|
|
89
|
+
* @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
|
|
90
|
+
* @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
|
|
91
|
+
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
92
|
+
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
93
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
94
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
|
|
95
|
+
* `MAX_SLIPPAGE_TOLERANCE`.
|
|
96
|
+
* @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
|
|
97
|
+
* would silently nullify the on-chain bound.
|
|
98
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
|
|
99
|
+
* would nullify the bound just as a non-positive input would.
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
103
|
+
*
|
|
104
|
+
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
105
|
+
* withdrawnAssets: plan.withdrawnAssets,
|
|
106
|
+
* sharesBurnt,
|
|
107
|
+
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function computeMinForceWithdrawSharePrice(params: {
|
|
112
|
+
readonly withdrawnAssets: bigint;
|
|
113
|
+
readonly sharesBurnt: bigint;
|
|
114
|
+
readonly slippageTolerance: bigint;
|
|
115
|
+
}): bigint;
|
|
70
116
|
/**
|
|
71
117
|
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
72
118
|
*
|
|
@@ -101,3 +147,92 @@ export declare function computeMinWithdrawSharePrice(params: {
|
|
|
101
147
|
market: Market;
|
|
102
148
|
slippageTolerance: bigint;
|
|
103
149
|
}): bigint;
|
|
150
|
+
/**
|
|
151
|
+
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
152
|
+
*
|
|
153
|
+
* Previews shares on both the supplied Vault V1 or Vault V2 snapshot and its deadline-accrued
|
|
154
|
+
* counterpart, dividing by the smaller of the two so the bound covers the highest price the
|
|
155
|
+
* bundle may execute at. Shares are previewed rounding down, mirroring the ERC-4626 `deposit()`
|
|
156
|
+
* shares the on-chain `maxSharePrice` check divides by.
|
|
157
|
+
*
|
|
158
|
+
* @param params - Vault snapshot, bundles execution deadline, net assets, and slippage.
|
|
159
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
160
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
161
|
+
* @param params.assets - Net assets deposited after referral fees, in the underlying token's smallest unit.
|
|
162
|
+
* @param params.slippageTolerance - Accepted share-price increase as a WAD-scaled fraction (`1e18` = 100%).
|
|
163
|
+
* @returns The capped maximum share price enforced by VaultBundlesV1.
|
|
164
|
+
* @throws {NonPositiveInputError} when `assets` or the previewed shares are not positive.
|
|
165
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
166
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
170
|
+
* import { computeVaultMaxSharePrice } from "@morpho-org/morpho-sdk";
|
|
171
|
+
* import { createPublicClient, http } from "viem";
|
|
172
|
+
* import { mainnet } from "viem/chains";
|
|
173
|
+
*
|
|
174
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
175
|
+
* const vaultData = await fetchAccrualVault(
|
|
176
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
177
|
+
* client,
|
|
178
|
+
* );
|
|
179
|
+
* const { timestamp } = await client.getBlock();
|
|
180
|
+
* const maxSharePrice = computeVaultMaxSharePrice({
|
|
181
|
+
* vaultData,
|
|
182
|
+
* deadline: timestamp + 7_200n,
|
|
183
|
+
* assets: 1_000_000n,
|
|
184
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
185
|
+
* });
|
|
186
|
+
* // maxSharePrice satisfies bigint
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export declare const computeVaultMaxSharePrice: (params: {
|
|
190
|
+
readonly vaultData: AccrualVault | AccrualVaultV2;
|
|
191
|
+
readonly deadline: bigint;
|
|
192
|
+
readonly assets: bigint;
|
|
193
|
+
readonly slippageTolerance: bigint;
|
|
194
|
+
}) => bigint;
|
|
195
|
+
/**
|
|
196
|
+
* Computes the exact vault-share authorization cap for an asset-denominated exit.
|
|
197
|
+
*
|
|
198
|
+
* The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
|
|
199
|
+
* by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
|
|
200
|
+
* MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
|
|
201
|
+
*
|
|
202
|
+
* @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
|
|
203
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
204
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
205
|
+
* @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
|
|
206
|
+
* @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
|
|
207
|
+
* @returns The maximum shares the prepared operation may burn.
|
|
208
|
+
* @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
|
|
209
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
210
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
214
|
+
* import { computeVaultMaxShareAllowance } from "@morpho-org/morpho-sdk";
|
|
215
|
+
* import { createPublicClient, http } from "viem";
|
|
216
|
+
* import { mainnet } from "viem/chains";
|
|
217
|
+
*
|
|
218
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
219
|
+
* const vaultData = await fetchAccrualVault(
|
|
220
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
221
|
+
* client,
|
|
222
|
+
* );
|
|
223
|
+
* const { timestamp } = await client.getBlock();
|
|
224
|
+
* const shares = computeVaultMaxShareAllowance({
|
|
225
|
+
* vaultData,
|
|
226
|
+
* deadline: timestamp + 7_200n,
|
|
227
|
+
* assets: 1_000_000n,
|
|
228
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
229
|
+
* });
|
|
230
|
+
* // shares is the exact allowance or permit value for the prepared exit.
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare const computeVaultMaxShareAllowance: (params: {
|
|
234
|
+
readonly vaultData: AccrualVault | AccrualVaultV2;
|
|
235
|
+
readonly deadline: bigint;
|
|
236
|
+
readonly assets: bigint;
|
|
237
|
+
readonly slippageTolerance: bigint;
|
|
238
|
+
}) => bigint;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeVaultMaxShareAllowance = exports.computeVaultMaxSharePrice = void 0;
|
|
3
4
|
exports.computeMinBorrowSharePrice = computeMinBorrowSharePrice;
|
|
4
5
|
exports.computeMaxRepaySharePrice = computeMaxRepaySharePrice;
|
|
5
6
|
exports.computeMaxSupplySharePrice = computeMaxSupplySharePrice;
|
|
7
|
+
exports.computeMinForceWithdrawSharePrice = computeMinForceWithdrawSharePrice;
|
|
6
8
|
exports.computeMinWithdrawSharePrice = computeMinWithdrawSharePrice;
|
|
7
9
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
8
10
|
const index_js_1 = require("../types/index.js");
|
|
9
11
|
const constant_js_1 = require("./constant.js");
|
|
12
|
+
const validate_js_1 = require("./validate.js");
|
|
10
13
|
/**
|
|
11
14
|
* Computes the minimum borrow share price (in RAY, 1e27) for slippage protection.
|
|
12
15
|
*
|
|
@@ -103,6 +106,70 @@ function computeMaxSupplySharePrice(params) {
|
|
|
103
106
|
const maxSharePrice = blue_sdk_1.MathLib.mulDivUp(supplyAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), expectedShares);
|
|
104
107
|
return blue_sdk_1.MathLib.min(maxSharePrice, constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
105
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Computes the minimum Vault V2 force-withdraw share price (in RAY, 1e27) for slippage protection.
|
|
111
|
+
*
|
|
112
|
+
* Mirrors the on-chain check in `VaultExitBundlesV1.vaultExitBundlesV1ForceWithdrawVaultV2`:
|
|
113
|
+
* ```solidity
|
|
114
|
+
* require(totalSharesBurnt == 0 || withdrawn.mulDivDown(1e27, totalSharesBurnt) >= minSharePriceE27)
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* The realized price sits structurally *below* the vault's share price because the
|
|
118
|
+
* force-deallocation penalty is debited from the position but never withdrawn, so a bound derived
|
|
119
|
+
* from the raw share price would reject every penalised exit. Both inputs are therefore taken from
|
|
120
|
+
* the same plan: `withdrawnAssets` (a lower bound of what the contract pays out) over
|
|
121
|
+
* `sharesBurnt` (an upper bound of what it burns). The result is conservative on both sides, so a
|
|
122
|
+
* faithful snapshot never trips the check while a real price drop, a penalty increase, or liquidity
|
|
123
|
+
* shifting from the penalty-free leg to the penalised leg all do.
|
|
124
|
+
*
|
|
125
|
+
* The referral fee is deducted *after* this check, so it is outside the bound's protection.
|
|
126
|
+
*
|
|
127
|
+
* @param params - Computation parameters.
|
|
128
|
+
* @param params.withdrawnAssets - Assets the contract withdraws in total, before the referral fee.
|
|
129
|
+
* @param params.sharesBurnt - Upper bound of the vault shares the exit burns.
|
|
130
|
+
* @param params.slippageTolerance - Slippage tolerance in WAD (e.g. `0.003e18` = 0.3%).
|
|
131
|
+
* @returns `minSharePriceE27` in RAY scale (1e27).
|
|
132
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
133
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` is above
|
|
134
|
+
* `MAX_SLIPPAGE_TOLERANCE`.
|
|
135
|
+
* @throws {NonPositiveInputError} when `sharesBurnt` or `withdrawnAssets` is not positive, which
|
|
136
|
+
* would silently nullify the on-chain bound.
|
|
137
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the ratio itself rounds down to zero, which
|
|
138
|
+
* would nullify the bound just as a non-positive input would.
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { computeMinForceWithdrawSharePrice } from "@morpho-org/morpho-sdk";
|
|
142
|
+
*
|
|
143
|
+
* const minSharePriceE27 = computeMinForceWithdrawSharePrice({
|
|
144
|
+
* withdrawnAssets: plan.withdrawnAssets,
|
|
145
|
+
* sharesBurnt,
|
|
146
|
+
* slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
147
|
+
* });
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function computeMinForceWithdrawSharePrice(params) {
|
|
151
|
+
const { withdrawnAssets, sharesBurnt, slippageTolerance } = params;
|
|
152
|
+
(0, validate_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
153
|
+
// A zero on either side would yield `minSharePriceE27 = 0`, i.e. no bound at all.
|
|
154
|
+
if (withdrawnAssets <= 0n) {
|
|
155
|
+
throw new index_js_1.NonPositiveInputError("withdrawnAssets", withdrawnAssets);
|
|
156
|
+
}
|
|
157
|
+
if (sharesBurnt <= 0n) {
|
|
158
|
+
throw new index_js_1.NonPositiveInputError("sharesBurnt", sharesBurnt);
|
|
159
|
+
}
|
|
160
|
+
const minSharePriceE27 = blue_sdk_1.MathLib.mulDivDown(withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), sharesBurnt);
|
|
161
|
+
// Positive inputs are not enough: the ratio itself can round down to zero once the burn exceeds
|
|
162
|
+
// what the withdrawn assets can price at RAY scale, which would reintroduce the very opt-out the
|
|
163
|
+
// guards above exist to prevent.
|
|
164
|
+
if (minSharePriceE27 === 0n) {
|
|
165
|
+
throw new index_js_1.VaultV2ForceWithdrawZeroSharePriceError({
|
|
166
|
+
withdrawnAssets,
|
|
167
|
+
sharesBurnt,
|
|
168
|
+
slippageTolerance,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return minSharePriceE27;
|
|
172
|
+
}
|
|
106
173
|
/**
|
|
107
174
|
* Computes the minimum withdraw share price (in RAY, 1e27) for slippage protection.
|
|
108
175
|
*
|
|
@@ -153,3 +220,124 @@ function computeMinWithdrawSharePrice(params) {
|
|
|
153
220
|
}
|
|
154
221
|
return blue_sdk_1.MathLib.mulDivDown(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - slippageTolerance), shares);
|
|
155
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Computes the RAY-scaled maximum share price for a VaultBundlesV1 deposit leg.
|
|
225
|
+
*
|
|
226
|
+
* Previews shares on both the supplied Vault V1 or Vault V2 snapshot and its deadline-accrued
|
|
227
|
+
* counterpart, dividing by the smaller of the two so the bound covers the highest price the
|
|
228
|
+
* bundle may execute at. Shares are previewed rounding down, mirroring the ERC-4626 `deposit()`
|
|
229
|
+
* shares the on-chain `maxSharePrice` check divides by.
|
|
230
|
+
*
|
|
231
|
+
* @param params - Vault snapshot, bundles execution deadline, net assets, and slippage.
|
|
232
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
233
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
234
|
+
* @param params.assets - Net assets deposited after referral fees, in the underlying token's smallest unit.
|
|
235
|
+
* @param params.slippageTolerance - Accepted share-price increase as a WAD-scaled fraction (`1e18` = 100%).
|
|
236
|
+
* @returns The capped maximum share price enforced by VaultBundlesV1.
|
|
237
|
+
* @throws {NonPositiveInputError} when `assets` or the previewed shares are not positive.
|
|
238
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
239
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
243
|
+
* import { computeVaultMaxSharePrice } from "@morpho-org/morpho-sdk";
|
|
244
|
+
* import { createPublicClient, http } from "viem";
|
|
245
|
+
* import { mainnet } from "viem/chains";
|
|
246
|
+
*
|
|
247
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
248
|
+
* const vaultData = await fetchAccrualVault(
|
|
249
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
250
|
+
* client,
|
|
251
|
+
* );
|
|
252
|
+
* const { timestamp } = await client.getBlock();
|
|
253
|
+
* const maxSharePrice = computeVaultMaxSharePrice({
|
|
254
|
+
* vaultData,
|
|
255
|
+
* deadline: timestamp + 7_200n,
|
|
256
|
+
* assets: 1_000_000n,
|
|
257
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
258
|
+
* });
|
|
259
|
+
* // maxSharePrice satisfies bigint
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
const computeVaultMaxSharePrice = (params) => {
|
|
263
|
+
if (params.assets <= 0n) {
|
|
264
|
+
throw new index_js_1.NonPositiveInputError("assets", params.assets);
|
|
265
|
+
}
|
|
266
|
+
(0, validate_js_1.validateSlippageTolerance)(params.slippageTolerance);
|
|
267
|
+
const accrualTimestamp = params.vaultData instanceof blue_sdk_1.AccrualVaultV2
|
|
268
|
+
? blue_sdk_1.MathLib.max(params.deadline, params.vaultData.lastUpdate)
|
|
269
|
+
: params.deadline;
|
|
270
|
+
const accruedVault = params.vaultData instanceof blue_sdk_1.AccrualVaultV2
|
|
271
|
+
? params.vaultData.accrueInterest(accrualTimestamp).vault
|
|
272
|
+
: params.vaultData.accrueInterest(accrualTimestamp);
|
|
273
|
+
// The deadline snapshot is not necessarily the highest price over `[now, deadline]`: Vault V2
|
|
274
|
+
// charges its management fee regardless of yield, minting shares against an unchanged
|
|
275
|
+
// `_totalAssets`, so an idle vault's price *declines*. Bound at the maximum price across both
|
|
276
|
+
// endpoints — the minimum previewed shares — mirroring the `max(current, accrued)` shares the
|
|
277
|
+
// sibling `computeVaultMaxShareAllowance` authorizes.
|
|
278
|
+
const shares = blue_sdk_1.MathLib.min(params.vaultData.toShares(params.assets, "Down"), accruedVault.toShares(params.assets, "Down"));
|
|
279
|
+
if (shares <= 0n) {
|
|
280
|
+
throw new index_js_1.NonPositiveInputError("shares", shares);
|
|
281
|
+
}
|
|
282
|
+
return blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(params.assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + params.slippageTolerance), shares), constant_js_1.MAX_ABSOLUTE_SHARE_PRICE);
|
|
283
|
+
};
|
|
284
|
+
exports.computeVaultMaxSharePrice = computeVaultMaxSharePrice;
|
|
285
|
+
/**
|
|
286
|
+
* Computes the exact vault-share authorization cap for an asset-denominated exit.
|
|
287
|
+
*
|
|
288
|
+
* The cap covers both the current and deadline-accrued preview. Vault V2 and MetaMorpho 1.0 divide
|
|
289
|
+
* by `1 - slippageTolerance`, rounding up, to cover a share-price decline before inclusion;
|
|
290
|
+
* MetaMorpho 1.1's `lostAssets` clamp keeps that preview upper-bounded without widening it.
|
|
291
|
+
*
|
|
292
|
+
* @param params - Vault snapshot, execution deadline, asset amount, and WAD-scaled slippage.
|
|
293
|
+
* @param params.vaultData - Hydrated Vault V1 `AccrualVault` or Vault V2 `AccrualVaultV2` snapshot.
|
|
294
|
+
* @param params.deadline - Bundle execution deadline as a Unix timestamp in seconds, used for accrual.
|
|
295
|
+
* @param params.assets - Assets withdrawn from the vault, in the underlying token's smallest unit.
|
|
296
|
+
* @param params.slippageTolerance - Accepted share-price decline as a WAD-scaled fraction (`1e18` = 100%).
|
|
297
|
+
* @returns The maximum shares the prepared operation may burn.
|
|
298
|
+
* @throws {NonPositiveInputError} when `assets` or the computed share cap is not positive.
|
|
299
|
+
* @throws {NegativeInputError} when `slippageTolerance` is negative.
|
|
300
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
304
|
+
* import { computeVaultMaxShareAllowance } from "@morpho-org/morpho-sdk";
|
|
305
|
+
* import { createPublicClient, http } from "viem";
|
|
306
|
+
* import { mainnet } from "viem/chains";
|
|
307
|
+
*
|
|
308
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
309
|
+
* const vaultData = await fetchAccrualVault(
|
|
310
|
+
* "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB",
|
|
311
|
+
* client,
|
|
312
|
+
* );
|
|
313
|
+
* const { timestamp } = await client.getBlock();
|
|
314
|
+
* const shares = computeVaultMaxShareAllowance({
|
|
315
|
+
* vaultData,
|
|
316
|
+
* deadline: timestamp + 7_200n,
|
|
317
|
+
* assets: 1_000_000n,
|
|
318
|
+
* slippageTolerance: 500_000_000_000_000n,
|
|
319
|
+
* });
|
|
320
|
+
* // shares is the exact allowance or permit value for the prepared exit.
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
const computeVaultMaxShareAllowance = (params) => {
|
|
324
|
+
if (params.assets <= 0n) {
|
|
325
|
+
throw new index_js_1.NonPositiveInputError("assets", params.assets);
|
|
326
|
+
}
|
|
327
|
+
(0, validate_js_1.validateSlippageTolerance)(params.slippageTolerance);
|
|
328
|
+
const isVaultV2 = params.vaultData instanceof blue_sdk_1.AccrualVaultV2;
|
|
329
|
+
const accruedVault = isVaultV2
|
|
330
|
+
? params.vaultData.accrueInterest(blue_sdk_1.MathLib.max(params.deadline, params.vaultData.lastUpdate)).vault
|
|
331
|
+
: params.vaultData.accrueInterest(params.deadline);
|
|
332
|
+
const previewedShares = blue_sdk_1.MathLib.max(params.vaultData.toShares(params.assets, "Up"), accruedVault.toShares(params.assets, "Up"));
|
|
333
|
+
if (previewedShares <= 0n) {
|
|
334
|
+
throw new index_js_1.NonPositiveInputError("shares", previewedShares);
|
|
335
|
+
}
|
|
336
|
+
const needsLossBuffer = isVaultV2 ||
|
|
337
|
+
!("lostAssets" in params.vaultData) ||
|
|
338
|
+
params.vaultData.lostAssets == null;
|
|
339
|
+
return needsLossBuffer
|
|
340
|
+
? blue_sdk_1.MathLib.wDivUp(previewedShares, blue_sdk_1.MathLib.WAD - params.slippageTolerance)
|
|
341
|
+
: previewedShares;
|
|
342
|
+
};
|
|
343
|
+
exports.computeVaultMaxShareAllowance = computeVaultMaxShareAllowance;
|
|
@@ -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
|
/**
|
|
@@ -108,6 +165,8 @@ export declare const validateChainId: (clientChainId: number | undefined, expect
|
|
|
108
165
|
* @throws {NativeAmountOnNonWNativeAssetError} if the asset is not wNative.
|
|
109
166
|
*/
|
|
110
167
|
export declare const validateNativeAsset: (chainId: number, asset: Address) => void;
|
|
168
|
+
/** @internal Validates native funding against a vault's wrapped-native asset. */
|
|
169
|
+
export declare const validateNativeVaultAsset: (chainId: number, vaultAsset: Address) => void;
|
|
111
170
|
/**
|
|
112
171
|
* Validates that the resulting position stays within the safe LTV threshold
|
|
113
172
|
* (LLTV minus buffer) after withdrawing collateral.
|