@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
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { DEFAULT_SLIPPAGE_TOLERANCE, getChainAddresses, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, getChainAddresses, MarketUtils, MathLib, Token, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { blueAbi, erc2612Abi, fetchAccrualVault, metaMorphoAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual } from "viem";
|
|
5
5
|
import { multicall } from "viem/actions";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
-
import {
|
|
6
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesRequirementSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
|
+
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
|
+
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
9
|
+
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
10
|
+
import { AmountAndSharesExclusiveError, ChainIdMismatchError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, isRequirementSignature, NonPositiveInputError, SameVaultMigrationError, selectRequirementSignatures, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
11
|
+
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
12
|
+
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
10
13
|
export class MorphoVaultV1 {
|
|
11
14
|
client;
|
|
12
15
|
vault;
|
|
@@ -28,100 +31,242 @@ export class MorphoVaultV1 {
|
|
|
28
31
|
deployless: this.client.options.supportDeployless,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
31
|
-
|
|
34
|
+
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
35
|
+
deposit(params) {
|
|
36
|
+
const { userAddress, vaultData } = params;
|
|
37
|
+
const { asset: vaultAsset } = vaultData;
|
|
32
38
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
33
39
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
34
40
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!isAddressEqual(vaultData.asset, wNative)) {
|
|
52
|
-
throw new NativeAmountOnNonWNativeVaultError(vaultData.asset, wNative);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
56
|
-
if (totalAssets === 0n) {
|
|
57
|
-
throw new NonPositiveInputError("totalAssets", totalAssets);
|
|
58
|
-
}
|
|
59
|
-
const shares = vaultData.toShares(totalAssets);
|
|
60
|
-
if (shares <= 0n) {
|
|
61
|
-
throw new NonPositiveInputError("shares", shares);
|
|
42
|
+
const createdAt = Time.timestamp();
|
|
43
|
+
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
44
|
+
if (deadline <= createdAt)
|
|
45
|
+
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
46
|
+
const common = normalizeBundlesCommonParams({
|
|
47
|
+
deadline,
|
|
48
|
+
referralFeePct: params.referralFeePct,
|
|
49
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
50
|
+
});
|
|
51
|
+
const funding = resolveBundlesFunding(params);
|
|
52
|
+
// Reject overflow before share-price math or native-only prerequisite resolution.
|
|
53
|
+
validateUint256Field(funding.value > 0n ? "nativeAmount" : "amount", funding.assets);
|
|
54
|
+
if (funding.value > 0n) {
|
|
55
|
+
// The native path must target the chain's registered wrapped-native asset.
|
|
56
|
+
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
62
57
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
59
|
+
const maxSharePrice = computeVaultMaxSharePrice({
|
|
60
|
+
vaultData,
|
|
61
|
+
deadline,
|
|
62
|
+
assets: funding.assets - referralFeeAssets,
|
|
63
|
+
slippageTolerance: params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE,
|
|
64
|
+
});
|
|
65
|
+
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
66
|
+
let pendingRequirements;
|
|
67
|
+
let expectedRequirement;
|
|
68
|
+
return Object.freeze({
|
|
69
|
+
getRequirements: async (requirementOptions) => {
|
|
70
|
+
const now = Time.timestamp();
|
|
71
|
+
if (deadline <= now)
|
|
72
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
73
|
+
if (pendingRequirements != null)
|
|
74
|
+
return await pendingRequirements;
|
|
75
|
+
// Memoize the in-flight promise, not just its result: concurrent callers
|
|
76
|
+
// requesting different routes would otherwise both resolve requirements and
|
|
77
|
+
// the slower one would overwrite `expectedRequirement`, making `buildTx()`
|
|
78
|
+
// reject the signature returned by the other call.
|
|
79
|
+
const pending = (async () => {
|
|
80
|
+
const requirements = funding.value > 0n
|
|
81
|
+
? []
|
|
82
|
+
: await getBundlesTokenRequirements(this.client.viemClient, {
|
|
83
|
+
token: vaultAsset,
|
|
84
|
+
spender,
|
|
85
|
+
amount: funding.assets,
|
|
86
|
+
owner: userAddress,
|
|
87
|
+
chainId: this.chainId,
|
|
88
|
+
deadline,
|
|
89
|
+
supportSignature: this.client.options.supportSignature,
|
|
90
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
91
|
+
useSimplePermit: requirementOptions?.useSimplePermit,
|
|
92
|
+
permit2Nonce: requirementOptions?.permit2Nonce,
|
|
93
|
+
});
|
|
94
|
+
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
95
|
+
expectedRequirement =
|
|
96
|
+
signatureRequirement?.action.type === "permit" ||
|
|
97
|
+
signatureRequirement?.action.type === "permit2SignatureTransfer"
|
|
98
|
+
? signatureRequirement.action
|
|
99
|
+
: undefined;
|
|
100
|
+
return requirements;
|
|
101
|
+
})();
|
|
102
|
+
pendingRequirements = pending;
|
|
103
|
+
try {
|
|
104
|
+
return await pending;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
// Later calls must re-read live allowances/nonces and honor their own options.
|
|
108
|
+
if (pendingRequirements === pending)
|
|
109
|
+
pendingRequirements = undefined;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
76
112
|
buildTx: (signatures) => {
|
|
77
|
-
const
|
|
78
|
-
permit: true,
|
|
79
|
-
});
|
|
113
|
+
const requirementSignature = selectBundlesTokenRequirementSignature(signatures, expectedRequirement);
|
|
80
114
|
return vaultV1Deposit({
|
|
81
115
|
vault: {
|
|
82
116
|
chainId: this.chainId,
|
|
83
117
|
address: this.vault,
|
|
84
|
-
asset:
|
|
118
|
+
asset: vaultAsset,
|
|
85
119
|
},
|
|
86
120
|
args: {
|
|
87
|
-
|
|
121
|
+
...(funding.value > 0n
|
|
122
|
+
? { nativeAmount: funding.assets }
|
|
123
|
+
: { amount: funding.assets }),
|
|
88
124
|
maxSharePrice,
|
|
89
|
-
|
|
90
|
-
requirementSignature
|
|
91
|
-
|
|
125
|
+
userAddress,
|
|
126
|
+
requirementSignature,
|
|
127
|
+
referralFeePct: common.referralFeePct,
|
|
128
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
129
|
+
deadline,
|
|
92
130
|
},
|
|
93
131
|
metadata: this.client.options.metadata,
|
|
94
132
|
});
|
|
95
133
|
},
|
|
96
|
-
};
|
|
134
|
+
});
|
|
97
135
|
}
|
|
98
|
-
withdraw(
|
|
136
|
+
withdraw(params) {
|
|
137
|
+
const { amount, userAddress } = params;
|
|
99
138
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
139
|
+
if (amount <= 0n)
|
|
140
|
+
throw new NonPositiveInputError("amount", amount);
|
|
141
|
+
// Reject values outside the ABI range before resolving any requirements.
|
|
142
|
+
validateUint256Field("amount", amount);
|
|
143
|
+
const createdAt = Time.timestamp();
|
|
144
|
+
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
145
|
+
if (deadline <= createdAt)
|
|
146
|
+
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
147
|
+
const common = normalizeBundlesCommonParams({
|
|
148
|
+
deadline,
|
|
149
|
+
referralFeePct: params.referralFeePct,
|
|
150
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
151
|
+
});
|
|
152
|
+
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
153
|
+
validateSlippageTolerance(slippageTolerance);
|
|
154
|
+
// Fail eagerly if VaultBundlesV1 is unavailable; only validation is needed here.
|
|
155
|
+
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
156
|
+
let requiredShareAllowance;
|
|
157
|
+
let vaultSnapshot;
|
|
158
|
+
let expectedRequirement;
|
|
159
|
+
return Object.freeze({
|
|
160
|
+
getRequirements: async () => {
|
|
161
|
+
const now = Time.timestamp();
|
|
162
|
+
if (deadline <= now)
|
|
163
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
164
|
+
// Re-read the live share allowance on every call instead of caching the resolved
|
|
165
|
+
// requirements: the allowance is the sole cap on the burn, so a caller that executed the
|
|
166
|
+
// returned approval must see it satisfied on the next call, and an allowance revoked or
|
|
167
|
+
// raised afterwards must resurface as an outstanding requirement. Only the vault snapshot
|
|
168
|
+
// and the cap derived from it are pinned, so re-reading cannot move the cap this handle
|
|
169
|
+
// already committed to; the snapshot is used for immutable identity and permit-domain
|
|
170
|
+
// fields only.
|
|
171
|
+
const vaultData = (vaultSnapshot ??= await this.getData());
|
|
172
|
+
requiredShareAllowance ??= computeVaultMaxShareAllowance({
|
|
173
|
+
vaultData,
|
|
174
|
+
deadline,
|
|
175
|
+
assets: amount,
|
|
176
|
+
slippageTolerance,
|
|
177
|
+
});
|
|
178
|
+
const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
179
|
+
vaultData,
|
|
180
|
+
version: "vaultV1",
|
|
181
|
+
owner: userAddress,
|
|
182
|
+
chainId: this.chainId,
|
|
183
|
+
requiredShareAllowance,
|
|
184
|
+
deadline,
|
|
185
|
+
supportSignature: this.client.options.supportSignature,
|
|
186
|
+
});
|
|
187
|
+
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
188
|
+
if (signatureRequirement?.action.type === "permit") {
|
|
189
|
+
expectedRequirement = signatureRequirement.action;
|
|
190
|
+
}
|
|
191
|
+
return requirements;
|
|
192
|
+
},
|
|
193
|
+
buildTx: (signatures) => {
|
|
194
|
+
const permit = selectBundlesSharesRequirementSignature(signatures, {
|
|
195
|
+
requiredShareAllowance,
|
|
196
|
+
expectedRequirement,
|
|
197
|
+
});
|
|
198
|
+
return vaultV1Withdraw({
|
|
199
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
200
|
+
args: {
|
|
201
|
+
amount,
|
|
202
|
+
userAddress,
|
|
203
|
+
requirementSignature: permit,
|
|
204
|
+
referralFeePct: common.referralFeePct,
|
|
205
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
206
|
+
deadline,
|
|
207
|
+
},
|
|
208
|
+
metadata: this.client.options.metadata,
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
});
|
|
111
212
|
}
|
|
112
|
-
|
|
213
|
+
/** {@inheritDoc VaultV1Actions.redeem} */
|
|
214
|
+
redeem(params) {
|
|
113
215
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
216
|
+
const { shares, userAddress } = params;
|
|
217
|
+
if (shares <= 0n)
|
|
218
|
+
throw new NonPositiveInputError("shares", shares);
|
|
219
|
+
const createdAt = Time.timestamp();
|
|
220
|
+
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
221
|
+
if (deadline <= createdAt)
|
|
222
|
+
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
223
|
+
const common = normalizeBundlesCommonParams({
|
|
224
|
+
deadline,
|
|
225
|
+
referralFeePct: params.referralFeePct,
|
|
226
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
227
|
+
});
|
|
228
|
+
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
229
|
+
let expectedRequirement;
|
|
230
|
+
return Object.freeze({
|
|
231
|
+
getRequirements: async () => {
|
|
232
|
+
const now = Time.timestamp();
|
|
233
|
+
if (deadline <= now)
|
|
234
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
235
|
+
const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
236
|
+
vaultData: await this.getData(),
|
|
237
|
+
version: "vaultV1",
|
|
238
|
+
owner: userAddress,
|
|
239
|
+
chainId: this.chainId,
|
|
240
|
+
requiredShareAllowance: shares,
|
|
241
|
+
deadline,
|
|
242
|
+
supportSignature: this.client.options.supportSignature,
|
|
243
|
+
});
|
|
244
|
+
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
245
|
+
expectedRequirement =
|
|
246
|
+
signatureRequirement?.action.type === "permit"
|
|
247
|
+
? signatureRequirement.action
|
|
248
|
+
: undefined;
|
|
249
|
+
return requirements;
|
|
250
|
+
},
|
|
251
|
+
buildTx: (signatures) => {
|
|
252
|
+
const permit = selectBundlesSharesRequirementSignature(signatures, {
|
|
253
|
+
requiredShareAllowance: shares,
|
|
254
|
+
expectedRequirement,
|
|
255
|
+
});
|
|
256
|
+
return vaultV1Redeem({
|
|
257
|
+
vault: { chainId: this.chainId, address: this.vault },
|
|
258
|
+
args: {
|
|
259
|
+
shares,
|
|
260
|
+
userAddress,
|
|
261
|
+
requirementSignature: permit,
|
|
262
|
+
referralFeePct: common.referralFeePct,
|
|
263
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
264
|
+
deadline,
|
|
265
|
+
},
|
|
266
|
+
metadata: this.client.options.metadata,
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
});
|
|
125
270
|
}
|
|
126
271
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
127
272
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, }) {
|
|
@@ -142,6 +287,9 @@ export class MorphoVaultV1 {
|
|
|
142
287
|
}));
|
|
143
288
|
const now = Time.timestamp();
|
|
144
289
|
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
290
|
+
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
291
|
+
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
292
|
+
validateDeadline(deadline);
|
|
145
293
|
if (deadline <= now)
|
|
146
294
|
throw new ExpiredDeadlineError(deadline, now);
|
|
147
295
|
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
@@ -156,6 +304,8 @@ export class MorphoVaultV1 {
|
|
|
156
304
|
const allocation = vaultData.allocations.get(marketId);
|
|
157
305
|
if (allocation?.config.enabled !== true)
|
|
158
306
|
continue;
|
|
307
|
+
if (allocation.position.supplyShares === 0n)
|
|
308
|
+
continue;
|
|
159
309
|
const market = allocation.position.market.accrueInterest(now);
|
|
160
310
|
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
161
311
|
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
@@ -177,11 +327,12 @@ export class MorphoVaultV1 {
|
|
|
177
327
|
maxExitAssets: covered,
|
|
178
328
|
});
|
|
179
329
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
330
|
+
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
331
|
+
vaultData,
|
|
332
|
+
deadline: now,
|
|
333
|
+
assets: amount,
|
|
334
|
+
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
335
|
+
});
|
|
185
336
|
return {
|
|
186
337
|
getRequirements: async () => {
|
|
187
338
|
const requirementsTimestamp = Time.timestamp();
|
|
@@ -284,65 +435,128 @@ export class MorphoVaultV1 {
|
|
|
284
435
|
},
|
|
285
436
|
};
|
|
286
437
|
}
|
|
287
|
-
|
|
438
|
+
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
439
|
+
migrateToV2(params) {
|
|
288
440
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
289
|
-
if (!isAddressEqual(sourceVault.address, this.vault)) {
|
|
290
|
-
throw new VaultAddressMismatchError(this.vault, sourceVault.address);
|
|
441
|
+
if (!isAddressEqual(params.sourceVault.address, this.vault)) {
|
|
442
|
+
throw new VaultAddressMismatchError(this.vault, params.sourceVault.address);
|
|
291
443
|
}
|
|
292
|
-
if (!isAddressEqual(sourceVault.asset, targetVault.asset)) {
|
|
293
|
-
throw new VaultAssetMismatchError(sourceVault.asset, targetVault.asset);
|
|
444
|
+
if (!isAddressEqual(params.sourceVault.asset, params.targetVault.asset)) {
|
|
445
|
+
throw new VaultAssetMismatchError(params.sourceVault.asset, params.targetVault.asset);
|
|
294
446
|
}
|
|
295
|
-
if (
|
|
296
|
-
throw new
|
|
447
|
+
if (isAddressEqual(this.vault, params.targetVault.address)) {
|
|
448
|
+
throw new SameVaultMigrationError(this.vault);
|
|
297
449
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// Compute maxSharePriceVaultV2 for V2 deposit (slippage upward).
|
|
303
|
-
// Accrue VaultV2 interest forward to bound the on-chain share price at execution.
|
|
304
|
-
const targetAccrualTimestamp = MathLib.max(Time.timestamp(), targetVault.lastUpdate) + Time.s.from.h(2n);
|
|
305
|
-
const { vault: accruedTargetVault } = targetVault.accrueInterest(targetAccrualTimestamp);
|
|
306
|
-
const v2RefShares = accruedTargetVault.toShares(v1RefAssets);
|
|
307
|
-
if (v2RefShares <= 0n) {
|
|
308
|
-
throw new NonPositiveInputError("targetVaultShares", v2RefShares);
|
|
450
|
+
const assets = "assets" in params ? params.assets : undefined;
|
|
451
|
+
const shares = "shares" in params ? params.shares : undefined;
|
|
452
|
+
if ((assets == null) === (shares == null)) {
|
|
453
|
+
throw new AmountAndSharesExclusiveError();
|
|
309
454
|
}
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
455
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
456
|
+
if (selectedAmount <= 0n) {
|
|
457
|
+
throw new NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
|
|
458
|
+
}
|
|
459
|
+
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
460
|
+
validateSlippageTolerance(slippageTolerance);
|
|
461
|
+
const createdAt = Time.timestamp();
|
|
462
|
+
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
463
|
+
if (deadline <= createdAt)
|
|
464
|
+
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
465
|
+
const common = normalizeBundlesCommonParams({
|
|
466
|
+
deadline,
|
|
467
|
+
referralFeePct: params.referralFeePct,
|
|
468
|
+
referralFeeRecipient: params.referralFeeRecipient,
|
|
469
|
+
});
|
|
470
|
+
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
471
|
+
const grossAssets = assets ??
|
|
472
|
+
params.sourceVault
|
|
473
|
+
.accrueInterest(params.sourceVault.allocations
|
|
474
|
+
.values()
|
|
475
|
+
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
|
|
476
|
+
.toAssets(shares ?? 0n, "Down");
|
|
477
|
+
const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
|
|
478
|
+
const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
|
|
479
|
+
vaultData: params.targetVault,
|
|
480
|
+
deadline,
|
|
481
|
+
assets: grossAssets - referralFeeAssets,
|
|
482
|
+
slippageTolerance,
|
|
483
|
+
});
|
|
484
|
+
const requiredShareAllowance = shares ??
|
|
485
|
+
computeVaultMaxShareAllowance({
|
|
486
|
+
vaultData: params.sourceVault,
|
|
487
|
+
deadline,
|
|
488
|
+
assets: assets ?? 0n,
|
|
489
|
+
slippageTolerance,
|
|
490
|
+
});
|
|
491
|
+
getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
492
|
+
const { userAddress } = params;
|
|
493
|
+
const sourceAsset = params.sourceVault.asset;
|
|
494
|
+
const targetAddress = params.targetVault.address;
|
|
495
|
+
const targetAsset = params.targetVault.asset;
|
|
496
|
+
const domain = params.sourceVault.eip5267Domain;
|
|
497
|
+
const sourceToken = new Token({
|
|
498
|
+
address: params.sourceVault.address,
|
|
499
|
+
name: params.sourceVault.name,
|
|
500
|
+
eip5267Domain: domain == null
|
|
501
|
+
? undefined
|
|
502
|
+
: new Eip5267Domain({
|
|
503
|
+
...domain,
|
|
504
|
+
extensions: [...domain.extensions],
|
|
505
|
+
}),
|
|
506
|
+
});
|
|
507
|
+
let expectedRequirement;
|
|
508
|
+
return Object.freeze({
|
|
509
|
+
getRequirements: async () => {
|
|
510
|
+
const now = Time.timestamp();
|
|
511
|
+
if (deadline <= now)
|
|
512
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
513
|
+
// Re-read the live share allowance on every call instead of caching the resolved
|
|
514
|
+
// requirements: in assets mode the calldata carries no share limit, so the allowance is
|
|
515
|
+
// the sole cap on the burn. A caller that executed the returned approval must see it
|
|
516
|
+
// satisfied on the next call, and an allowance revoked or raised afterwards must resurface
|
|
517
|
+
// as an outstanding requirement. The pinned snapshot and the cap derived from it stay
|
|
518
|
+
// fixed, so re-reading cannot move the cap this handle already committed to.
|
|
519
|
+
const requirements = await getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
520
|
+
vaultData: sourceToken,
|
|
521
|
+
version: "vaultV1",
|
|
522
|
+
owner: userAddress,
|
|
523
|
+
chainId: this.chainId,
|
|
524
|
+
requiredShareAllowance,
|
|
525
|
+
deadline,
|
|
526
|
+
supportSignature: this.client.options.supportSignature,
|
|
527
|
+
});
|
|
528
|
+
const signatureRequirement = requirements.find(isRequirementSignature);
|
|
529
|
+
expectedRequirement =
|
|
530
|
+
signatureRequirement?.action.type === "permit"
|
|
531
|
+
? signatureRequirement.action
|
|
532
|
+
: undefined;
|
|
533
|
+
return requirements;
|
|
534
|
+
},
|
|
324
535
|
buildTx: (signatures) => {
|
|
325
|
-
const
|
|
326
|
-
|
|
536
|
+
const permit = selectBundlesSharesRequirementSignature(signatures, {
|
|
537
|
+
requiredShareAllowance,
|
|
538
|
+
expectedRequirement,
|
|
327
539
|
});
|
|
328
540
|
return vaultV1MigrateToV2({
|
|
329
541
|
vault: {
|
|
330
542
|
chainId: this.chainId,
|
|
331
543
|
address: this.vault,
|
|
332
|
-
asset:
|
|
544
|
+
asset: sourceAsset,
|
|
333
545
|
},
|
|
334
546
|
args: {
|
|
335
|
-
targetVault:
|
|
336
|
-
targetAsset
|
|
337
|
-
shares,
|
|
338
|
-
minSharePriceVaultV1,
|
|
547
|
+
targetVault: targetAddress,
|
|
548
|
+
targetAsset,
|
|
549
|
+
...(assets != null ? { assets } : { shares: shares ?? 0n }),
|
|
339
550
|
maxSharePriceVaultV2,
|
|
340
|
-
|
|
551
|
+
userAddress,
|
|
341
552
|
requirementSignature: permit,
|
|
553
|
+
referralFeePct: common.referralFeePct,
|
|
554
|
+
referralFeeRecipient: common.referralFeeRecipient,
|
|
555
|
+
deadline,
|
|
342
556
|
},
|
|
343
557
|
metadata: this.client.options.metadata,
|
|
344
558
|
});
|
|
345
559
|
},
|
|
346
|
-
};
|
|
560
|
+
});
|
|
347
561
|
}
|
|
348
562
|
}
|
|
@@ -130,10 +130,13 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
130
130
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
131
131
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
132
132
|
* least one computed withdrawal.
|
|
133
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
134
|
+
* are skipped before projecting source interest.
|
|
133
135
|
*
|
|
134
136
|
* @param marketId - Target market to supply with shared liquidity.
|
|
135
137
|
* @param options - Optional allocator discovery options.
|
|
136
138
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
139
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
137
140
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
138
141
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
139
142
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -179,6 +182,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
179
182
|
* @param marketId - Target market to supply with shared liquidity.
|
|
180
183
|
* @param options - Optional allocator discovery options.
|
|
181
184
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
185
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
182
186
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
183
187
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
184
188
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -199,6 +203,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
199
203
|
* @param marketId - Target market that would receive the liquidity.
|
|
200
204
|
* @param options - Optional allocator discovery options.
|
|
201
205
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
206
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
202
207
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
203
208
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
204
209
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -252,6 +257,7 @@ export declare class VaultV1ReallocationData implements InputVaultV1Reallocation
|
|
|
252
257
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
253
258
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
254
259
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
260
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
255
261
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
256
262
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
257
263
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|