@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
|
@@ -213,10 +213,13 @@ class VaultV1ReallocationData {
|
|
|
213
213
|
* Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
|
|
214
214
|
* on-chain `reallocateTo` fee semantics: one fee charge per vault with at
|
|
215
215
|
* least one computed withdrawal.
|
|
216
|
+
* Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
|
|
217
|
+
* are skipped before projecting source interest.
|
|
216
218
|
*
|
|
217
219
|
* @param marketId - Target market to supply with shared liquidity.
|
|
218
220
|
* @param options - Optional allocator discovery options.
|
|
219
221
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
222
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
220
223
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
221
224
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
222
225
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -314,6 +317,7 @@ class VaultV1ReallocationData {
|
|
|
314
317
|
* @param marketId - Target market to supply with shared liquidity.
|
|
315
318
|
* @param options - Optional allocator discovery options.
|
|
316
319
|
* @returns Computed source-market withdrawals and the post-reallocation state.
|
|
320
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
317
321
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
318
322
|
* @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
|
|
319
323
|
* `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
|
|
@@ -333,6 +337,7 @@ class VaultV1ReallocationData {
|
|
|
333
337
|
* @param marketId - Target market that would receive the liquidity.
|
|
334
338
|
* @param options - Optional allocator discovery options.
|
|
335
339
|
* @returns Total reallocatable assets in loan-token units; `0n` when none is available.
|
|
340
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
336
341
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
337
342
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
338
343
|
* `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
|
|
@@ -389,6 +394,7 @@ class VaultV1ReallocationData {
|
|
|
389
394
|
* @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
|
|
390
395
|
* @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
|
|
391
396
|
* @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
|
|
397
|
+
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
392
398
|
* @throws {@link UnknownReallocationMarketError} when the target market is absent.
|
|
393
399
|
* @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
|
|
394
400
|
* `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
|
|
@@ -446,25 +452,34 @@ class VaultV1ReallocationData {
|
|
|
446
452
|
getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
|
|
447
453
|
return (0, morpho_ts_1._try)(() => {
|
|
448
454
|
const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
|
|
455
|
+
const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
|
|
449
456
|
const validCap = pendingCap.validAt >= timestamp
|
|
450
457
|
? blue_sdk_1.MathLib.min(pendingCap.value, cap)
|
|
451
458
|
: cap;
|
|
459
|
+
if (maxIn === 0n || validCap === 0n)
|
|
460
|
+
return { vault };
|
|
452
461
|
const suppliable = blue_sdk_1.MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
|
|
453
462
|
.supplyAssets);
|
|
463
|
+
if (suppliable === 0n)
|
|
464
|
+
return { vault };
|
|
454
465
|
const marketWithdrawals = this.getVault(vault)
|
|
455
466
|
.withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
|
|
456
467
|
!withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
|
|
457
468
|
.map((srcMarketId) => {
|
|
458
469
|
const withdrawal = (0, morpho_ts_1._try)(() => {
|
|
459
|
-
const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
|
|
460
|
-
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
461
|
-
defaultMaxWithdrawalUtilization);
|
|
462
470
|
const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
|
|
463
|
-
|
|
471
|
+
const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
|
|
472
|
+
if (!srcConfig.enabled || maxOut === 0n)
|
|
473
|
+
return { id: srcMarketId, assets: 0n };
|
|
474
|
+
const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
|
|
475
|
+
if (rawSrcPosition.supplyShares === 0n)
|
|
464
476
|
return { id: srcMarketId, assets: 0n };
|
|
477
|
+
const srcPosition = rawSrcPosition.accrueInterest(timestamp);
|
|
478
|
+
const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
|
|
479
|
+
defaultMaxWithdrawalUtilization);
|
|
465
480
|
return {
|
|
466
481
|
id: srcMarketId,
|
|
467
|
-
assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable,
|
|
482
|
+
assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
|
|
468
483
|
};
|
|
469
484
|
}, blue_sdk_1.UnknownDataError);
|
|
470
485
|
return withdrawal ?? { id: srcMarketId, assets: 0n };
|
|
@@ -2,7 +2,7 @@ import { type AccrualVaultV2, type MarketParams } from "@morpho-org/blue-sdk";
|
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
5
|
-
import { type ActionOutput, type
|
|
5
|
+
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type Deallocation, type MorphoClientType, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2ForceRedeemAction, type VaultV2ForceWithdrawAction, type VaultV2InKindRedeemAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types/index.js";
|
|
6
6
|
export interface VaultV2Actions {
|
|
7
7
|
/**
|
|
8
8
|
* Fetches the latest vault data.
|
|
@@ -14,67 +14,209 @@ export interface VaultV2Actions {
|
|
|
14
14
|
*/
|
|
15
15
|
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
16
16
|
/**
|
|
17
|
-
* Prepares a deposit
|
|
17
|
+
* Prepares a Vault V2 deposit through the registered VaultBundlesV1 contract.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* Uses the supplied vault snapshot to compute the deadline-accrued `maxSharePrice`.
|
|
20
|
+
* `getRequirements()` reads the asset allowance and, when enabled, the selected ERC-2612 or
|
|
21
|
+
* Permit2 nonce state. Native funding is exclusive and skips token requirements. Shares are
|
|
22
|
+
* always minted to the transaction sender, which must be `userAddress`.
|
|
23
|
+
* Concurrent requirement reads share the first caller's options; later calls refresh on-chain
|
|
24
|
+
* state using their own options. `buildTx()` accepts signatures from the latest completed read.
|
|
23
25
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
26
|
+
* @param params.userAddress - Account that funds, signs, submits, and receives the vault shares.
|
|
27
|
+
* @param params.vaultData - Pre-fetched Vault V2 snapshot used for asset and share conversion.
|
|
28
|
+
* @param params.amount - Optional gross ERC-20 assets; exclusive with `nativeAmount`.
|
|
29
|
+
* @param params.nativeAmount - Optional gross native assets; exclusive with `amount` and valid
|
|
30
|
+
* only for a wNative vault.
|
|
31
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
|
|
32
|
+
* exceed 10%.
|
|
33
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee below 100%, deducted before
|
|
34
|
+
* the vault deposit.
|
|
35
|
+
* @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
|
|
36
|
+
* @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
|
|
37
|
+
* two hours from handle creation.
|
|
38
|
+
* @returns Lazy token prerequisite resolution and a synchronous deep-frozen VaultBundlesV1
|
|
39
|
+
* transaction builder.
|
|
40
|
+
* @throws {UnsupportedBlueMarketIrmError} when required interest projection encounters an unsupported IRM.
|
|
41
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
42
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
43
|
+
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
44
|
+
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
45
|
+
* @throws {NegativeInputError} when funding, slippage, the referral fee, or a Permit2 nonce is negative.
|
|
46
|
+
* @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
|
|
47
|
+
* @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
|
|
48
|
+
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
49
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
50
|
+
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
51
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
52
|
+
* @throws {NoUnusedPermit2NonceError} from `getRequirements()` when every Permit2 nonce for the
|
|
53
|
+
* owner is consumed and none was passed explicitly.
|
|
54
|
+
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
55
|
+
* explicit Permit2 nonce is consumed.
|
|
56
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
57
|
+
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
58
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
59
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
60
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature was not produced for
|
|
61
|
+
* this prepared handle.
|
|
62
|
+
* @throws {DepositOwnerMismatchError} from `buildTx()` when the signed owner differs from `userAddress`.
|
|
63
|
+
* @throws {DepositAssetMismatchError} from `buildTx()` when the signed asset differs from the vault asset.
|
|
64
|
+
* @throws {BundlesRequirementSignatureMismatchError} from `buildTx()` when signature metadata is malformed.
|
|
65
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
66
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered.
|
|
67
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, or token metadata read fails.
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
71
|
+
* import { createPublicClient, http, type Address, zeroAddress } from "viem";
|
|
72
|
+
* import { mainnet } from "viem/chains";
|
|
73
|
+
*
|
|
74
|
+
* const keyrockUsdcVaultV2 =
|
|
75
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
76
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
77
|
+
* .extend(morphoViemExtension());
|
|
78
|
+
* const vault = client.morpho.vaultV2(keyrockUsdcVaultV2, mainnet.id);
|
|
79
|
+
* const vaultData = await vault.getData();
|
|
80
|
+
* const action = vault.deposit({
|
|
81
|
+
* amount: 1_000_000n,
|
|
82
|
+
* userAddress: zeroAddress,
|
|
83
|
+
* vaultData,
|
|
84
|
+
* });
|
|
85
|
+
* const requirements = await action.getRequirements(); // Satisfy these first.
|
|
86
|
+
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
87
|
+
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
88
|
+
* ```
|
|
33
89
|
*/
|
|
34
90
|
deposit: (params: {
|
|
35
|
-
userAddress: Address;
|
|
36
|
-
vaultData: AccrualVaultV2;
|
|
37
|
-
slippageTolerance?: bigint;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>;
|
|
43
|
-
};
|
|
91
|
+
readonly userAddress: Address;
|
|
92
|
+
readonly vaultData: AccrualVaultV2;
|
|
93
|
+
readonly slippageTolerance?: bigint;
|
|
94
|
+
readonly referralFeePct?: bigint;
|
|
95
|
+
readonly referralFeeRecipient?: Address;
|
|
96
|
+
readonly deadline?: bigint;
|
|
97
|
+
} & BundlesFundingArgs) => ActionOutput<VaultV2DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
|
|
44
98
|
/**
|
|
45
|
-
* Prepares
|
|
99
|
+
* Prepares an exact-assets Vault V2 withdrawal through VaultBundlesV1.
|
|
46
100
|
*
|
|
47
|
-
*
|
|
101
|
+
* Reads the vault accrual state on the first `getRequirements()` call, then reads the live
|
|
102
|
+
* vault-share allowance and, when a signature is needed, the permit nonce on each call.
|
|
103
|
+
* Captures the requested amount and owner at creation, so later changes to `params` do not
|
|
104
|
+
* change this handle's requirements or transaction.
|
|
48
105
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
*
|
|
53
|
-
*
|
|
106
|
+
* @param params.amount - Positive gross withdrawal in underlying asset base units, before fees.
|
|
107
|
+
* @param params.userAddress - Share owner that must sign and submit; receives the net assets.
|
|
108
|
+
* @param params.slippageTolerance - Optional WAD-scaled share-price loss tolerance applied to
|
|
109
|
+
* the share cap.
|
|
110
|
+
* Defaults to 0.03% and cannot exceed 10%.
|
|
111
|
+
* @param params.referralFeePct - Optional WAD-scaled fee in [0, 1e18), defaulting to zero;
|
|
112
|
+
* rounded down and deducted from the gross withdrawn assets.
|
|
113
|
+
* @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
|
|
114
|
+
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
|
|
115
|
+
* defaults to two hours from handle creation.
|
|
116
|
+
* @returns A frozen handle with lazy `getRequirements()` and synchronous `buildTx(signatures?)`,
|
|
117
|
+
* which returns a deep-frozen `Transaction<VaultV2WithdrawAction>`. Requirements are empty
|
|
118
|
+
* when the allowance equals the cap; otherwise they contain an exact approval or, with
|
|
119
|
+
* signature support, an ERC-2612 request. The cap stays pinned to the first resolution while
|
|
120
|
+
* each call re-reads the allowance. Confirm the approval or pass its signed permit to `buildTx`.
|
|
121
|
+
* @throws {ChainIdMismatchError} when the connected client targets another chain.
|
|
122
|
+
* @throws {NonPositiveInputError} when `amount` or the computed share cap is not positive.
|
|
123
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
124
|
+
* at any `getRequirements()` call.
|
|
125
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
126
|
+
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
127
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
128
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
129
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
130
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
131
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
132
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
133
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple permits are supplied.
|
|
134
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the share permit is malformed,
|
|
135
|
+
* was not resolved for this handle, or has incompatible vault, owner, spender, amount,
|
|
136
|
+
* deadline, or nonce values.
|
|
137
|
+
* @throws {viem.BaseError} when a vault, allowance, or nonce read or transaction encoding fails.
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
141
|
+
* import { createPublicClient, http, type Address } from "viem";
|
|
142
|
+
* import { mainnet } from "viem/chains";
|
|
143
|
+
*
|
|
144
|
+
* export async function prepareUsdcWithdrawal(userAddress: Address) {
|
|
145
|
+
* const vaultAddress = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
146
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() })
|
|
147
|
+
* .extend(morphoViemExtension({ supportSignature: false }));
|
|
148
|
+
* const vault = client.morpho.vaultV2(vaultAddress, mainnet.id);
|
|
149
|
+
* const action = vault.withdraw({ amount: 1_000_000n, userAddress });
|
|
150
|
+
* const requirements = await action.getRequirements();
|
|
151
|
+
* // Send and confirm each approval before calling action.buildTx().
|
|
152
|
+
* // action.buildTx() returns Readonly<Transaction<VaultV2WithdrawAction>>.
|
|
153
|
+
* return { action, requirements }; // Prepared handle and its outstanding share approvals.
|
|
154
|
+
* }
|
|
155
|
+
* ```
|
|
54
156
|
*/
|
|
55
157
|
withdraw: (params: {
|
|
56
|
-
amount: bigint;
|
|
57
|
-
userAddress: Address;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
158
|
+
readonly amount: bigint;
|
|
159
|
+
readonly userAddress: Address;
|
|
160
|
+
readonly slippageTolerance?: bigint;
|
|
161
|
+
readonly referralFeePct?: bigint;
|
|
162
|
+
readonly referralFeeRecipient?: Address;
|
|
163
|
+
readonly deadline?: bigint;
|
|
164
|
+
}) => ActionOutput<VaultV2WithdrawAction, readonly RequirementSignature[], undefined>;
|
|
61
165
|
/**
|
|
62
|
-
* Prepares
|
|
166
|
+
* Prepares an exact-shares Vault V2 redemption through VaultBundlesV1.
|
|
63
167
|
*
|
|
64
|
-
*
|
|
168
|
+
* Captures `shares` and `userAddress` at handle creation for both requirements and `buildTx()`.
|
|
169
|
+
* The caller must satisfy the exact vault-share allowance returned by `getRequirements()` before
|
|
170
|
+
* `buildTx()`; every requirement resolution re-reads the live allowance and checks the deadline.
|
|
171
|
+
* `buildTx()` accepts permits from the latest completed requirement resolution.
|
|
65
172
|
*
|
|
66
173
|
* @param {Object} params - The redeem parameters.
|
|
67
|
-
* @param {bigint} params.shares -
|
|
68
|
-
* @param {Address} params.userAddress -
|
|
69
|
-
* @
|
|
70
|
-
* @
|
|
174
|
+
* @param {bigint} params.shares - Exact vault shares to burn.
|
|
175
|
+
* @param {Address} params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
176
|
+
* @param {bigint} [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be below WAD.
|
|
177
|
+
* @param {Address} [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
178
|
+
* @param {bigint} [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
179
|
+
* @returns Lazy exact share-allowance requirements and a synchronous transaction builder.
|
|
180
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
181
|
+
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
182
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
183
|
+
* requirement resolution.
|
|
184
|
+
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
185
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
186
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
187
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
188
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
189
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance or nonce read fails.
|
|
190
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
191
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
192
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the supplied permit does not match the
|
|
193
|
+
* resolved share cap, spender, owner, nonce, or deadline.
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
197
|
+
*
|
|
198
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
199
|
+
* const redemption = vault.redeem({ shares: 1_000_000n, userAddress });
|
|
200
|
+
* const signatures = [];
|
|
201
|
+
* for (const requirement of await redemption.getRequirements()) {
|
|
202
|
+
* if (isRequirementSignature(requirement)) {
|
|
203
|
+
* signatures.push(await requirement.sign(walletClient, userAddress));
|
|
204
|
+
* } else {
|
|
205
|
+
* const hash = await walletClient.sendTransaction(requirement);
|
|
206
|
+
* await client.waitForTransactionReceipt({ hash });
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* const tx = redemption.buildTx(signatures);
|
|
210
|
+
* // tx satisfies Readonly<Transaction<VaultV2RedeemAction>>
|
|
211
|
+
* ```
|
|
71
212
|
*/
|
|
72
213
|
redeem: (params: {
|
|
73
|
-
shares: bigint;
|
|
74
|
-
userAddress: Address;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
214
|
+
readonly shares: bigint;
|
|
215
|
+
readonly userAddress: Address;
|
|
216
|
+
readonly referralFeePct?: bigint;
|
|
217
|
+
readonly referralFeeRecipient?: Address;
|
|
218
|
+
readonly deadline?: bigint;
|
|
219
|
+
}) => ActionOutput<VaultV2RedeemAction, readonly RequirementSignature[], undefined>;
|
|
78
220
|
/**
|
|
79
221
|
* Prepares an illiquid Vault V2 exit into idle assets and Morpho Blue supply positions.
|
|
80
222
|
*
|
|
@@ -101,16 +243,18 @@ export interface VaultV2Actions {
|
|
|
101
243
|
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
102
244
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
103
245
|
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
246
|
+
* @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
|
|
104
247
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
105
|
-
* @throws {NonPositiveInputError} when `amount` is not positive.
|
|
248
|
+
* @throws {NonPositiveInputError} when `amount` or `deadline` is not positive.
|
|
106
249
|
* @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
|
|
107
250
|
* penalty-adjusted amount rounds to zero deallocated assets.
|
|
108
251
|
* @throws {EmptyMarketParamsListError} when assets must be deallocated and the market list is empty.
|
|
252
|
+
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
109
253
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
110
254
|
* requirement resolution.
|
|
111
|
-
* @throws {
|
|
255
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
112
256
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
113
|
-
* @throws {
|
|
257
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
114
258
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
115
259
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
116
260
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -153,29 +297,129 @@ export interface VaultV2Actions {
|
|
|
153
297
|
readonly deadline?: bigint;
|
|
154
298
|
}) => ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
155
299
|
/**
|
|
156
|
-
* Prepares a
|
|
300
|
+
* Prepares a Vault V2 force withdrawal through VaultExitBundlesV1.
|
|
157
301
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
302
|
+
* The contract withdraws everything the vault can pay without a penalty — its idle assets plus
|
|
303
|
+
* the liquidity available through its liquidity adapter — then force-deallocates the remainder by
|
|
304
|
+
* looping over the adapter's markets. It computes the deallocations itself: the caller supplies
|
|
305
|
+
* neither a market list nor an order.
|
|
161
306
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
307
|
+
* `exitAssets` is **penalty-inclusive**, matching `inKindRedeem`. The contract debits it from the
|
|
308
|
+
* user's position but pays out only
|
|
309
|
+
* `assetsToWithdraw + floor((exitAssets - assetsToWithdraw) * WAD / (WAD + penalty))`, minus the
|
|
310
|
+
* referral fee. Quote the split with `previewVaultV2ForceWithdraw`.
|
|
311
|
+
*
|
|
312
|
+
* The vault must have exactly one `MorphoMarketV1AdapterV2` and route liquidity through that same
|
|
313
|
+
* adapter or none at all. Call `getRequirements()` before `buildTx()` so the vault-share allowance
|
|
314
|
+
* and permit nonce are read on-chain.
|
|
315
|
+
*
|
|
316
|
+
* Unless `minSharePriceE27` is overridden, the SDK derives a conservative lower bound on the
|
|
317
|
+
* realized exit share price from the snapshot and `slippageTolerance`. The bound rejects a share
|
|
318
|
+
* price drop, a penalty increase, and liquidity shifting from the penalty-free leg to the
|
|
319
|
+
* penalised leg. It does **not** cover the referral fee, which the contract deducts afterwards.
|
|
320
|
+
*
|
|
321
|
+
* Vault gates are enforced by the final transaction and are not preflighted: the receive-assets
|
|
322
|
+
* gate must allow VaultExitBundlesV1 and may depend on its transient initiator, while a
|
|
323
|
+
* send-shares gate is arbitrary code re-evaluated after each penalty burn. The SDK also does not
|
|
324
|
+
* validate the user's share balance. Per-market penalties and each vault withdrawal round the
|
|
325
|
+
* share burn up independently, so the exit can burn marginally more shares than `exitAssets` alone
|
|
326
|
+
* implies; size `exitAssets` a small buffer below `vault.previewRedeem(sharesHeld)` — the approved
|
|
327
|
+
* share allowance this handle returns is the exact upper bound on the burn — so a full-balance
|
|
328
|
+
* exit does not revert for insufficient shares.
|
|
329
|
+
*
|
|
330
|
+
* Idle balance, penalty, adapter positions, and market liquidity can drift after the snapshot, so
|
|
331
|
+
* an on-chain revert remains possible if vault state changes between preparation and inclusion.
|
|
332
|
+
* A fee-recipient `userAddress` gets a floor from the net share burn after fee mints at `now`,
|
|
333
|
+
* and a guard against fee mints reaching the lower burn bound by the deadline. Its allowance
|
|
334
|
+
* includes the projected fee shares through that same deadline. Deadlines beyond one year after
|
|
335
|
+
* handle creation are rejected, so the guard and allowance cover the whole accepted window.
|
|
336
|
+
*
|
|
337
|
+
* @param params - Force withdrawal parameters.
|
|
338
|
+
* @param params.exitAssets - Penalty-inclusive, asset-denominated amount to exit.
|
|
339
|
+
* @param params.vaultData - Pre-fetched Vault V2 accrual snapshot.
|
|
340
|
+
* @param params.userAddress - Account that signs and submits the exit, and receives the assets.
|
|
341
|
+
* @param params.adapter - Optional adapter override; defaults to the vault's sole adapter.
|
|
342
|
+
* @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
|
|
343
|
+
* Deadlines more than one year after handle creation are rejected.
|
|
344
|
+
* @param params.slippageTolerance - Optional WAD-scaled tolerance applied to the derived share
|
|
345
|
+
* price bound. Defaults to `DEFAULT_SLIPPAGE_TOLERANCE`, capped at `MAX_SLIPPAGE_TOLERANCE`.
|
|
346
|
+
* @param params.minSharePriceE27 - Optional RAY-scaled override of the derived bound. Must be
|
|
347
|
+
* positive: the contract reads `0` as "no bound", so it cannot be used to opt out.
|
|
348
|
+
* @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
|
|
349
|
+
* `referralFeeRecipient`. Defaults to `0n`.
|
|
350
|
+
* @param params.referralFeeRecipient - Optional referral fee recipient, required when
|
|
351
|
+
* `referralFeePct` is positive.
|
|
352
|
+
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
353
|
+
* @throws {ChainIdMismatchError} when the client and entity target different chains.
|
|
354
|
+
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
355
|
+
* @throws {NonPositiveInputError} when `exitAssets`, `deadline`, or a supplied
|
|
356
|
+
* `minSharePriceE27` is not positive.
|
|
357
|
+
* @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
|
|
358
|
+
* @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
|
|
359
|
+
* `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `referralFeePct` is not
|
|
360
|
+
* below WAD, or when `deadline` is more than one year after handle creation.
|
|
361
|
+
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
362
|
+
* requirement resolution.
|
|
363
|
+
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
364
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
365
|
+
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
366
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
367
|
+
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
368
|
+
* another adapter.
|
|
369
|
+
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
370
|
+
* as `MarketParams`.
|
|
371
|
+
* @throws {VaultV2ForceWithdrawZeroWithdrawalError} when the exit would withdraw nothing.
|
|
372
|
+
* @throws {VaultV2ForceWithdrawCoverageError} when the adapter's markets cannot cover the exit,
|
|
373
|
+
* which would overrun the contract's unbounded loop.
|
|
374
|
+
* @throws {VaultV2ForceWithdrawZeroSharePriceError} when the derived share-price floor rounds down
|
|
375
|
+
* to zero, which the contract would read as no bound at all.
|
|
376
|
+
* @throws {VaultV2ForceWithdrawFeeSharesExceedBurnError} when fee shares are minted to a
|
|
377
|
+
* fee-recipient `userAddress` and reach the lower-bound share burn at the deadline.
|
|
378
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive `referralFeePct` has no recipient.
|
|
379
|
+
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
380
|
+
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
381
|
+
* @throws {viem.BaseError} from `getRequirements()` when an RPC or multicall contract read fails.
|
|
382
|
+
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when more than one permit signature is supplied.
|
|
383
|
+
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when a non-permit signature is supplied.
|
|
384
|
+
* @throws {BundlesPermitMismatchError} from `buildTx()` when the permit's spender, amount, or
|
|
385
|
+
* deadline differs from this operation. Any handle built from the same inputs accepts the
|
|
386
|
+
* permit; the nonce is verified onchain by the vault's `permit`.
|
|
387
|
+
* @throws {VaultExitBundlesV1PermitMismatchError} from `buildTx()` when the requirement has the wrong permit kind, asset, or signature encoding.
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* import { isRequirementSignature } from "@morpho-org/morpho-sdk";
|
|
391
|
+
*
|
|
392
|
+
* const vault = client.morpho.vaultV2(vaultAddress, 1);
|
|
393
|
+
* const vaultData = await vault.getData();
|
|
394
|
+
* const exit = vault.forceWithdraw({
|
|
395
|
+
* exitAssets: 1_000_000n,
|
|
396
|
+
* vaultData,
|
|
397
|
+
* userAddress,
|
|
398
|
+
* });
|
|
399
|
+
* const signatures = [];
|
|
400
|
+
* for (const requirement of await exit.getRequirements()) {
|
|
401
|
+
* if (isRequirementSignature(requirement)) {
|
|
402
|
+
* signatures.push(await requirement.sign(walletClient, userAddress));
|
|
403
|
+
* } else {
|
|
404
|
+
* const hash = await walletClient.sendTransaction(requirement);
|
|
405
|
+
* await client.waitForTransactionReceipt({ hash });
|
|
406
|
+
* }
|
|
407
|
+
* }
|
|
408
|
+
* const tx = exit.buildTx(signatures);
|
|
409
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
|
|
410
|
+
* ```
|
|
169
411
|
*/
|
|
170
|
-
forceWithdraw: (params: {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
412
|
+
readonly forceWithdraw: (params: {
|
|
413
|
+
readonly exitAssets: bigint;
|
|
414
|
+
readonly vaultData: AccrualVaultV2;
|
|
415
|
+
readonly userAddress: Address;
|
|
416
|
+
readonly adapter?: Address;
|
|
417
|
+
readonly deadline?: bigint;
|
|
418
|
+
readonly slippageTolerance?: bigint;
|
|
419
|
+
readonly minSharePriceE27?: bigint;
|
|
420
|
+
readonly referralFeePct?: bigint;
|
|
421
|
+
readonly referralFeeRecipient?: Address;
|
|
422
|
+
}) => ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
179
423
|
/**
|
|
180
424
|
* Prepares a force redeem transaction for the VaultV2 contract using the vault's native multicall.
|
|
181
425
|
*
|
|
@@ -214,28 +458,40 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
214
458
|
private readonly chainId;
|
|
215
459
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
216
460
|
getData(parameters?: FetchParameters): Promise<AccrualVaultV2>;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
461
|
+
/** {@inheritDoc VaultV2Actions.deposit} */
|
|
462
|
+
deposit(params: {
|
|
463
|
+
readonly userAddress: Address;
|
|
464
|
+
readonly vaultData: AccrualVaultV2;
|
|
465
|
+
readonly slippageTolerance?: bigint;
|
|
466
|
+
readonly referralFeePct?: bigint;
|
|
467
|
+
readonly referralFeeRecipient?: Address;
|
|
468
|
+
readonly deadline?: bigint;
|
|
469
|
+
} & BundlesFundingArgs): Readonly<{
|
|
470
|
+
getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
|
|
225
471
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
226
|
-
}
|
|
227
|
-
withdraw(
|
|
228
|
-
amount: bigint;
|
|
229
|
-
userAddress: Address;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
472
|
+
}>;
|
|
473
|
+
withdraw(params: {
|
|
474
|
+
readonly amount: bigint;
|
|
475
|
+
readonly userAddress: Address;
|
|
476
|
+
readonly slippageTolerance?: bigint;
|
|
477
|
+
readonly referralFeePct?: bigint;
|
|
478
|
+
readonly referralFeeRecipient?: Address;
|
|
479
|
+
readonly deadline?: bigint;
|
|
480
|
+
}): Readonly<{
|
|
481
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
482
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2WithdrawAction>>;
|
|
483
|
+
}>;
|
|
484
|
+
/** {@inheritDoc VaultV2Actions.redeem} */
|
|
485
|
+
redeem(params: {
|
|
486
|
+
readonly shares: bigint;
|
|
487
|
+
readonly userAddress: Address;
|
|
488
|
+
readonly referralFeePct?: bigint;
|
|
489
|
+
readonly referralFeeRecipient?: Address;
|
|
490
|
+
readonly deadline?: bigint;
|
|
491
|
+
}): Readonly<{
|
|
492
|
+
getRequirements: () => Promise<readonly ActionRequirement[]>;
|
|
493
|
+
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<Transaction<VaultV2RedeemAction>>;
|
|
494
|
+
}>;
|
|
239
495
|
/** {@inheritDoc VaultV2Actions.inKindRedeem} */
|
|
240
496
|
inKindRedeem({ amount, marketParamsList, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, }: {
|
|
241
497
|
readonly amount: bigint;
|
|
@@ -245,15 +501,18 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
245
501
|
readonly adapter?: Address;
|
|
246
502
|
readonly deadline?: bigint;
|
|
247
503
|
}): ActionOutput<VaultV2InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
504
|
+
/** {@inheritDoc VaultV2Actions.forceWithdraw} */
|
|
505
|
+
forceWithdraw({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, }: {
|
|
506
|
+
readonly exitAssets: bigint;
|
|
507
|
+
readonly vaultData: AccrualVaultV2;
|
|
508
|
+
readonly userAddress: Address;
|
|
509
|
+
readonly adapter?: Address;
|
|
510
|
+
readonly deadline?: bigint;
|
|
511
|
+
readonly slippageTolerance?: bigint;
|
|
512
|
+
readonly minSharePriceE27?: bigint;
|
|
513
|
+
readonly referralFeePct?: bigint;
|
|
514
|
+
readonly referralFeeRecipient?: Address;
|
|
515
|
+
}): ActionOutput<VaultV2ForceWithdrawAction, readonly RequirementSignature[], undefined>;
|
|
257
516
|
forceRedeem({ deallocations, redeem, userAddress, }: {
|
|
258
517
|
deallocations: readonly Deallocation[];
|
|
259
518
|
redeem: {
|