@morpho-org/morpho-sdk 9.8.0 → 10.0.0
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-v9-to-v10.md +114 -0
- package/README.md +109 -13
- package/lib/cjs/actions/blue/common.js +4 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/cjs/actions/bundles/common.js +20 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeLend.js +3 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/cjs/entities/blue/blue.d.ts +34 -28
- package/lib/cjs/entities/blue/blue.js +107 -77
- package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
- package/lib/cjs/entities/midnight/deadline.js +4 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
- package/lib/cjs/entities/midnight/midnight.js +158 -138
- package/lib/cjs/entities/midnight/publication.d.ts +2 -0
- package/lib/cjs/entities/midnight/publication.js +193 -138
- package/lib/cjs/entities/midnight/types.d.ts +4 -4
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +2 -1
- package/lib/cjs/helpers/deadShares.js +83 -47
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.d.ts +14 -2
- package/lib/cjs/helpers/metadata.js +49 -8
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +88 -67
- package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/transactionPlan/approval.js +12 -1
- package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
- package/lib/cjs/transactionPlan/deposit.js +139 -0
- package/lib/cjs/transactionPlan/error.d.ts +10 -8
- package/lib/cjs/transactionPlan/error.js +10 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
- package/lib/cjs/transactionPlan/index.d.ts +18 -0
- package/lib/cjs/transactionPlan/index.js +23 -5
- package/lib/cjs/transactionPlan/intent.d.ts +3 -3
- package/lib/cjs/transactionPlan/intent.js +14 -7
- package/lib/cjs/transactionPlan/permit.d.ts +1 -1
- package/lib/cjs/transactionPlan/permit.js +86 -20
- package/lib/cjs/transactionPlan/plan.d.ts +16 -6
- package/lib/cjs/transactionPlan/plan.js +77 -24
- package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
- package/lib/cjs/transactionPlan/redeem.js +63 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
- package/lib/cjs/transactionPlan/requirements.js +12 -6
- package/lib/cjs/transactionPlan/serde.d.ts +2 -2
- package/lib/cjs/transactionPlan/serde.js +45 -19
- package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/cjs/transactionPlan/shareSpending.js +50 -0
- package/lib/cjs/transactionPlan/types.d.ts +117 -11
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.js +6 -3
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
- package/lib/cjs/transactionPlan/version.js +2 -1
- package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
- package/lib/cjs/transactionPlan/withdraw.js +94 -0
- package/lib/cjs/types/action.d.ts +26 -2
- package/lib/cjs/types/action.js +17 -9
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +21 -6
- package/lib/cjs/types/metadata.d.ts +12 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +4 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/esm/actions/bundles/common.js +20 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/esm/actions/midnight/cancelOffers.js +104 -0
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/takeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
- package/lib/esm/actions/midnight/takeLend.js +3 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/esm/entities/blue/blue.d.ts +34 -28
- package/lib/esm/entities/blue/blue.js +107 -77
- package/lib/esm/entities/midnight/deadline.d.ts +2 -2
- package/lib/esm/entities/midnight/deadline.js +4 -3
- package/lib/esm/entities/midnight/midnight.d.ts +49 -51
- package/lib/esm/entities/midnight/midnight.js +159 -139
- package/lib/esm/entities/midnight/publication.d.ts +2 -0
- package/lib/esm/entities/midnight/publication.js +193 -138
- package/lib/esm/entities/midnight/types.d.ts +4 -4
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/deadShares.js +83 -47
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.d.ts +14 -2
- package/lib/esm/helpers/metadata.js +48 -8
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +88 -67
- package/lib/esm/helpers/validateMidnightBounds.js +2 -1
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/esm/helpers/validateMidnightPublication.js +4 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/transactionPlan/approval.js +13 -2
- package/lib/esm/transactionPlan/deposit.d.ts +22 -0
- package/lib/esm/transactionPlan/deposit.js +135 -0
- package/lib/esm/transactionPlan/error.d.ts +10 -8
- package/lib/esm/transactionPlan/error.js +10 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
- package/lib/esm/transactionPlan/index.d.ts +18 -0
- package/lib/esm/transactionPlan/index.js +9 -0
- package/lib/esm/transactionPlan/intent.d.ts +3 -3
- package/lib/esm/transactionPlan/intent.js +14 -7
- package/lib/esm/transactionPlan/permit.d.ts +1 -1
- package/lib/esm/transactionPlan/permit.js +86 -20
- package/lib/esm/transactionPlan/plan.d.ts +16 -6
- package/lib/esm/transactionPlan/plan.js +73 -20
- package/lib/esm/transactionPlan/redeem.d.ts +18 -0
- package/lib/esm/transactionPlan/redeem.js +59 -0
- package/lib/esm/transactionPlan/requirements.d.ts +4 -3
- package/lib/esm/transactionPlan/requirements.js +12 -6
- package/lib/esm/transactionPlan/serde.d.ts +2 -2
- package/lib/esm/transactionPlan/serde.js +45 -19
- package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/esm/transactionPlan/shareSpending.js +47 -0
- package/lib/esm/transactionPlan/types.d.ts +117 -11
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.js +6 -3
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
- package/lib/esm/transactionPlan/version.js +2 -1
- package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
- package/lib/esm/transactionPlan/withdraw.js +90 -0
- package/lib/esm/types/action.d.ts +26 -2
- package/lib/esm/types/action.js +17 -9
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +21 -6
- package/lib/esm/types/metadata.d.ts +12 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -14
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { VaultV1MigrateToV2AmountArgs } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal Quotes a migration from validated snapshots and intent without reading chain state.
|
|
5
|
+
* The source accrues interest and performance fees before a shares-mode conversion; the target
|
|
6
|
+
* price bound uses assets net of the referral fee. Neither snapshot is mutated.
|
|
7
|
+
* @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
|
|
8
|
+
* @returns The destination maximum share price and minimum source share allowance.
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeVaultV1MigrateToV2Quote(params: VaultV1MigrateToV2AmountArgs & {
|
|
11
|
+
readonly sourceVault: AccrualVault;
|
|
12
|
+
readonly targetVault: AccrualVaultV2;
|
|
13
|
+
readonly referralFeePct: bigint;
|
|
14
|
+
readonly slippageTolerance: bigint;
|
|
15
|
+
readonly deadline: bigint;
|
|
16
|
+
readonly now: bigint;
|
|
17
|
+
}): {
|
|
18
|
+
readonly maxSharePriceVaultV2: bigint;
|
|
19
|
+
readonly requiredShareAllowance: bigint;
|
|
20
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { getBundlesReferralFeeAssets } from "../../actions/bundles/common.js";
|
|
3
|
+
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, } from "../../helpers/slippage.js";
|
|
4
|
+
/**
|
|
5
|
+
* @internal Quotes a migration from validated snapshots and intent without reading chain state.
|
|
6
|
+
* The source accrues interest and performance fees before a shares-mode conversion; the target
|
|
7
|
+
* price bound uses assets net of the referral fee. Neither snapshot is mutated.
|
|
8
|
+
* @param params - Source, target, exclusive amount, fee, slippage, deadline and preparation time.
|
|
9
|
+
* @returns The destination maximum share price and minimum source share allowance.
|
|
10
|
+
*/
|
|
11
|
+
export function computeVaultV1MigrateToV2Quote(params) {
|
|
12
|
+
const { sourceVault, targetVault, assets, shares, referralFeePct, slippageTolerance, deadline, now, } = params;
|
|
13
|
+
const grossAssets = assets ??
|
|
14
|
+
sourceVault
|
|
15
|
+
.accrueInterest(sourceVault.allocations
|
|
16
|
+
.values()
|
|
17
|
+
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), now))
|
|
18
|
+
.toAssets(shares ?? 0n, "Down");
|
|
19
|
+
const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, referralFeePct);
|
|
20
|
+
const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
|
|
21
|
+
vaultData: targetVault,
|
|
22
|
+
deadline,
|
|
23
|
+
assets: grossAssets - referralFeeAssets,
|
|
24
|
+
slippageTolerance,
|
|
25
|
+
});
|
|
26
|
+
const requiredShareAllowance = shares ??
|
|
27
|
+
computeVaultMaxShareAllowance({
|
|
28
|
+
vaultData: sourceVault,
|
|
29
|
+
deadline,
|
|
30
|
+
assets: assets ?? 0n,
|
|
31
|
+
slippageTolerance,
|
|
32
|
+
});
|
|
33
|
+
return { maxSharePriceVaultV2, requiredShareAllowance };
|
|
34
|
+
}
|
|
@@ -2,7 +2,7 @@ import { type AccrualVault, type AccrualVaultV2, type MarketParams } from "@morp
|
|
|
2
2
|
import { fetchAccrualVault } 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 ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
5
|
+
import { type ActionOutput, type ActionRequirement, type BundlesFundingArgs, type BundlesTokenRequirementsOptions, type MorphoClientType, type ReferenceTimestampParams, type RequirementSignature, type VaultV1DepositAction, type VaultV1InKindRedeemAction, type VaultV1MigrateToV2Action, type VaultV1MigrateToV2AmountArgs, type VaultV1RedeemAction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
6
6
|
/** Action surface for Vault V1 reads and writes; writes route through VaultBundlesV1 and VaultExitBundlesV1. */
|
|
7
7
|
export interface VaultV1Actions {
|
|
8
8
|
/**
|
|
@@ -107,7 +107,7 @@ export interface VaultV1Actions {
|
|
|
107
107
|
readonly referralFeePct?: bigint;
|
|
108
108
|
readonly referralFeeRecipient?: Address;
|
|
109
109
|
readonly deadline?: bigint;
|
|
110
|
-
} & BundlesFundingArgs) => ActionOutput<VaultV1DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
|
|
110
|
+
} & ReferenceTimestampParams & BundlesFundingArgs) => ActionOutput<VaultV1DepositAction, readonly RequirementSignature[], BundlesTokenRequirementsOptions>;
|
|
111
111
|
/**
|
|
112
112
|
* Prepares an exact-assets Vault V1 withdrawal through VaultBundlesV1.
|
|
113
113
|
*
|
|
@@ -189,7 +189,7 @@ export interface VaultV1Actions {
|
|
|
189
189
|
readonly referralFeePct?: bigint;
|
|
190
190
|
readonly referralFeeRecipient?: Address;
|
|
191
191
|
readonly deadline?: bigint;
|
|
192
|
-
}) => ActionOutput<VaultV1WithdrawAction, readonly RequirementSignature[], undefined>;
|
|
192
|
+
} & ReferenceTimestampParams) => ActionOutput<VaultV1WithdrawAction, readonly RequirementSignature[], undefined>;
|
|
193
193
|
/**
|
|
194
194
|
* Prepares an exact-shares Vault V1 redemption through VaultBundlesV1.
|
|
195
195
|
*
|
|
@@ -270,7 +270,7 @@ export interface VaultV1Actions {
|
|
|
270
270
|
readonly referralFeePct?: bigint;
|
|
271
271
|
readonly referralFeeRecipient?: Address;
|
|
272
272
|
readonly deadline?: bigint;
|
|
273
|
-
}) => ActionOutput<VaultV1RedeemAction, readonly RequirementSignature[], undefined>;
|
|
273
|
+
} & ReferenceTimestampParams) => ActionOutput<VaultV1RedeemAction, readonly RequirementSignature[], undefined>;
|
|
274
274
|
/**
|
|
275
275
|
* Prepares an illiquid Vault V1 exit into the vault's Morpho Blue supply positions.
|
|
276
276
|
*
|
|
@@ -355,7 +355,7 @@ export interface VaultV1Actions {
|
|
|
355
355
|
readonly vaultData: AccrualVault;
|
|
356
356
|
readonly userAddress: Address;
|
|
357
357
|
readonly deadline?: bigint;
|
|
358
|
-
}) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
358
|
+
} & ReferenceTimestampParams) => ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
359
359
|
/**
|
|
360
360
|
* Prepares a Vault V1-to-Vault V2 migration through VaultBundlesV1.
|
|
361
361
|
*
|
|
@@ -461,7 +461,7 @@ export interface VaultV1Actions {
|
|
|
461
461
|
readonly referralFeePct?: bigint;
|
|
462
462
|
readonly referralFeeRecipient?: Address;
|
|
463
463
|
readonly deadline?: bigint;
|
|
464
|
-
} & VaultV1MigrateToV2AmountArgs) => ActionOutput<VaultV1MigrateToV2Action, readonly RequirementSignature[], undefined>;
|
|
464
|
+
} & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs) => ActionOutput<VaultV1MigrateToV2Action, readonly RequirementSignature[], undefined>;
|
|
465
465
|
}
|
|
466
466
|
/** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
|
|
467
467
|
export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
@@ -487,7 +487,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
487
487
|
readonly referralFeePct?: bigint;
|
|
488
488
|
readonly referralFeeRecipient?: Address;
|
|
489
489
|
readonly deadline?: bigint;
|
|
490
|
-
} & BundlesFundingArgs): Readonly<{
|
|
490
|
+
} & ReferenceTimestampParams & BundlesFundingArgs): Readonly<{
|
|
491
491
|
getRequirements: (requirementOptions?: BundlesTokenRequirementsOptions) => Promise<readonly ActionRequirement[]>;
|
|
492
492
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<VaultV1DepositAction>>;
|
|
493
493
|
}>;
|
|
@@ -499,7 +499,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
499
499
|
readonly referralFeePct?: bigint;
|
|
500
500
|
readonly referralFeeRecipient?: Address;
|
|
501
501
|
readonly deadline?: bigint;
|
|
502
|
-
}): Readonly<{
|
|
502
|
+
} & ReferenceTimestampParams): Readonly<{
|
|
503
503
|
getRequirements: () => Promise<readonly (Readonly<import("../../types/action.js").Transaction<import("../../types/action.js").ERC20ApprovalAction>> | import("../../types/action.js").Requirement<import("../../types/action.js").Erc2612RequirementSignature, undefined>)[]>;
|
|
504
504
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<VaultV1WithdrawAction>>;
|
|
505
505
|
}>;
|
|
@@ -510,18 +510,18 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
510
510
|
readonly referralFeePct?: bigint;
|
|
511
511
|
readonly referralFeeRecipient?: Address;
|
|
512
512
|
readonly deadline?: bigint;
|
|
513
|
-
}): Readonly<{
|
|
513
|
+
} & ReferenceTimestampParams): Readonly<{
|
|
514
514
|
getRequirements: () => Promise<readonly (Readonly<import("../../types/action.js").Transaction<import("../../types/action.js").ERC20ApprovalAction>> | import("../../types/action.js").Requirement<import("../../types/action.js").Erc2612RequirementSignature, undefined>)[]>;
|
|
515
515
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<VaultV1RedeemAction>>;
|
|
516
516
|
}>;
|
|
517
517
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
518
|
-
inKindRedeem(
|
|
518
|
+
inKindRedeem(params: {
|
|
519
519
|
readonly amount: bigint;
|
|
520
520
|
readonly marketParamsList: readonly MarketParams[];
|
|
521
521
|
readonly vaultData: AccrualVault;
|
|
522
522
|
readonly userAddress: Address;
|
|
523
523
|
readonly deadline?: bigint;
|
|
524
|
-
}): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
524
|
+
} & ReferenceTimestampParams): ActionOutput<VaultV1InKindRedeemAction, readonly RequirementSignature[], undefined>;
|
|
525
525
|
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
526
526
|
migrateToV2(params: {
|
|
527
527
|
readonly userAddress: Address;
|
|
@@ -531,7 +531,7 @@ export declare class MorphoVaultV1 implements VaultV1Actions {
|
|
|
531
531
|
readonly referralFeePct?: bigint;
|
|
532
532
|
readonly referralFeeRecipient?: Address;
|
|
533
533
|
readonly deadline?: bigint;
|
|
534
|
-
} & VaultV1MigrateToV2AmountArgs): Readonly<{
|
|
534
|
+
} & ReferenceTimestampParams & VaultV1MigrateToV2AmountArgs): Readonly<{
|
|
535
535
|
getRequirements: () => Promise<readonly (Readonly<import("../../types/action.js").Transaction<import("../../types/action.js").ERC20ApprovalAction>> | import("../../types/action.js").Requirement<import("../../types/action.js").Erc2612RequirementSignature, undefined>)[]>;
|
|
536
536
|
buildTx: (signatures?: readonly RequirementSignature[]) => Readonly<import("../../types/action.js").Transaction<VaultV1MigrateToV2Action>>;
|
|
537
537
|
}>;
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain,
|
|
2
|
-
import {
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Eip5267Domain, Token, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { fetchAccrualVault } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, Time, } from "@morpho-org/morpho-ts";
|
|
4
|
-
import {
|
|
5
|
-
import { readContract } from "viem/actions";
|
|
4
|
+
import { isAddressEqual } from "viem";
|
|
6
5
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
|
-
import {
|
|
6
|
+
import { vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
7
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
8
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import { resolveTransactionMetadata } from "../../helpers/metadata.js";
|
|
10
|
+
import { validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
11
|
+
import { AmountAndSharesExclusiveError, ExpiredDeadlineError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
12
12
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
13
13
|
import { getVaultBundlesSharesRequirements } from "../requirements/getVaultBundlesSharesRequirements.js";
|
|
14
|
+
import { getVaultV1InKindRedeemRequirements } from "../requirements/getVaultV1InKindRedeemRequirements.js";
|
|
14
15
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
16
|
+
import { computeVaultV1InKindRedeemQuote } from "./inKindRedeemQuote.js";
|
|
17
|
+
import { computeVaultV1MigrateToV2Quote } from "./migrateToV2Quote.js";
|
|
18
|
+
function getMigrationAmounts(params) {
|
|
19
|
+
const assets = "assets" in params ? params.assets : undefined;
|
|
20
|
+
const shares = "shares" in params ? params.shares : undefined;
|
|
21
|
+
if ((assets == null) === (shares == null)) {
|
|
22
|
+
throw new AmountAndSharesExclusiveError();
|
|
23
|
+
}
|
|
24
|
+
const selectedAmount = assets ?? shares ?? 0n;
|
|
25
|
+
if (selectedAmount <= 0n) {
|
|
26
|
+
throw new NonPositiveInputError(assets == null ? "shares" : "assets", selectedAmount);
|
|
27
|
+
}
|
|
28
|
+
return { assets, shares };
|
|
29
|
+
}
|
|
15
30
|
/** Binds a viem client to a Vault V1 (MetaMorpho) vault's action builders. */
|
|
16
31
|
export class MorphoVaultV1 {
|
|
17
32
|
client;
|
|
@@ -48,16 +63,19 @@ export class MorphoVaultV1 {
|
|
|
48
63
|
}
|
|
49
64
|
/** {@inheritDoc VaultV1Actions.deposit} */
|
|
50
65
|
deposit(params) {
|
|
66
|
+
const suppliedNow = params.now;
|
|
67
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
51
68
|
const { userAddress, vaultData } = params;
|
|
52
69
|
const { asset: vaultAsset } = vaultData;
|
|
53
70
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
54
71
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
55
72
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
56
73
|
}
|
|
57
|
-
const createdAt = Time.timestamp();
|
|
74
|
+
const createdAt = suppliedNow ?? Time.timestamp();
|
|
58
75
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
59
|
-
if (deadline <= createdAt)
|
|
76
|
+
if (deadline <= createdAt) {
|
|
60
77
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
78
|
+
}
|
|
61
79
|
const common = normalizeBundlesCommonParams({
|
|
62
80
|
deadline,
|
|
63
81
|
referralFeePct: params.referralFeePct,
|
|
@@ -81,11 +99,13 @@ export class MorphoVaultV1 {
|
|
|
81
99
|
let pendingRequirements;
|
|
82
100
|
return Object.freeze({
|
|
83
101
|
getRequirements: async (requirementOptions) => {
|
|
84
|
-
const now = Time.timestamp();
|
|
85
|
-
if (deadline <= now)
|
|
102
|
+
const now = suppliedNow ?? Time.timestamp();
|
|
103
|
+
if (deadline <= now) {
|
|
86
104
|
throw new ExpiredDeadlineError(deadline, now);
|
|
87
|
-
|
|
105
|
+
}
|
|
106
|
+
if (pendingRequirements != null) {
|
|
88
107
|
return await pendingRequirements;
|
|
108
|
+
}
|
|
89
109
|
// Memoize the in-flight promise so concurrent callers share one round of
|
|
90
110
|
// allowance/nonce reads.
|
|
91
111
|
const pending = (async () => {
|
|
@@ -111,8 +131,9 @@ export class MorphoVaultV1 {
|
|
|
111
131
|
}
|
|
112
132
|
finally {
|
|
113
133
|
// Later calls must re-read live allowances/nonces and honor their own options.
|
|
114
|
-
if (pendingRequirements === pending)
|
|
134
|
+
if (pendingRequirements === pending) {
|
|
115
135
|
pendingRequirements = undefined;
|
|
136
|
+
}
|
|
116
137
|
}
|
|
117
138
|
},
|
|
118
139
|
buildTx: (signatures) => {
|
|
@@ -135,25 +156,29 @@ export class MorphoVaultV1 {
|
|
|
135
156
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
136
157
|
deadline,
|
|
137
158
|
},
|
|
138
|
-
metadata
|
|
159
|
+
metadata,
|
|
139
160
|
});
|
|
140
161
|
},
|
|
141
162
|
});
|
|
142
163
|
}
|
|
143
164
|
withdraw(params) {
|
|
165
|
+
const suppliedNow = params.now;
|
|
166
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
144
167
|
const { amount, userAddress, vaultData } = params;
|
|
145
168
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
146
169
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
147
170
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
148
171
|
}
|
|
149
|
-
if (amount <= 0n)
|
|
172
|
+
if (amount <= 0n) {
|
|
150
173
|
throw new NonPositiveInputError("amount", amount);
|
|
174
|
+
}
|
|
151
175
|
// Reject values outside the ABI range before resolving any requirements.
|
|
152
176
|
validateUint256Field("amount", amount);
|
|
153
|
-
const createdAt = Time.timestamp();
|
|
177
|
+
const createdAt = suppliedNow ?? Time.timestamp();
|
|
154
178
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
155
|
-
if (deadline <= createdAt)
|
|
179
|
+
if (deadline <= createdAt) {
|
|
156
180
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
181
|
+
}
|
|
157
182
|
const common = normalizeBundlesCommonParams({
|
|
158
183
|
deadline,
|
|
159
184
|
referralFeePct: params.referralFeePct,
|
|
@@ -171,9 +196,10 @@ export class MorphoVaultV1 {
|
|
|
171
196
|
});
|
|
172
197
|
return Object.freeze({
|
|
173
198
|
getRequirements: async () => {
|
|
174
|
-
const now = Time.timestamp();
|
|
175
|
-
if (deadline <= now)
|
|
199
|
+
const now = suppliedNow ?? Time.timestamp();
|
|
200
|
+
if (deadline <= now) {
|
|
176
201
|
throw new ExpiredDeadlineError(deadline, now);
|
|
202
|
+
}
|
|
177
203
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
178
204
|
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
179
205
|
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
@@ -203,21 +229,25 @@ export class MorphoVaultV1 {
|
|
|
203
229
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
204
230
|
deadline,
|
|
205
231
|
},
|
|
206
|
-
metadata
|
|
232
|
+
metadata,
|
|
207
233
|
});
|
|
208
234
|
},
|
|
209
235
|
});
|
|
210
236
|
}
|
|
211
237
|
/** {@inheritDoc VaultV1Actions.redeem} */
|
|
212
238
|
redeem(params) {
|
|
239
|
+
const suppliedNow = params.now;
|
|
240
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
213
241
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
214
242
|
const { shares, userAddress } = params;
|
|
215
|
-
if (shares <= 0n)
|
|
243
|
+
if (shares <= 0n) {
|
|
216
244
|
throw new NonPositiveInputError("shares", shares);
|
|
217
|
-
|
|
245
|
+
}
|
|
246
|
+
const createdAt = suppliedNow ?? Time.timestamp();
|
|
218
247
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
219
|
-
if (deadline <= createdAt)
|
|
248
|
+
if (deadline <= createdAt) {
|
|
220
249
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
250
|
+
}
|
|
221
251
|
const common = normalizeBundlesCommonParams({
|
|
222
252
|
deadline,
|
|
223
253
|
referralFeePct: params.referralFeePct,
|
|
@@ -226,9 +256,10 @@ export class MorphoVaultV1 {
|
|
|
226
256
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
227
257
|
return Object.freeze({
|
|
228
258
|
getRequirements: async () => {
|
|
229
|
-
const now = Time.timestamp();
|
|
230
|
-
if (deadline <= now)
|
|
259
|
+
const now = suppliedNow ?? Time.timestamp();
|
|
260
|
+
if (deadline <= now) {
|
|
231
261
|
throw new ExpiredDeadlineError(deadline, now);
|
|
262
|
+
}
|
|
232
263
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
233
264
|
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
234
265
|
vaultData: await this.getData(),
|
|
@@ -257,158 +288,40 @@ export class MorphoVaultV1 {
|
|
|
257
288
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
258
289
|
deadline,
|
|
259
290
|
},
|
|
260
|
-
metadata
|
|
291
|
+
metadata,
|
|
261
292
|
});
|
|
262
293
|
},
|
|
263
294
|
});
|
|
264
295
|
}
|
|
265
296
|
/** {@inheritDoc VaultV1Actions.inKindRedeem} */
|
|
266
|
-
inKindRedeem(
|
|
297
|
+
inKindRedeem(params) {
|
|
298
|
+
const suppliedNow = params.now;
|
|
299
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
300
|
+
const { amount, marketParamsList, vaultData, userAddress, deadline: deadlineOverride, } = params;
|
|
267
301
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
268
302
|
if (!isAddressEqual(vaultData.address, this.vault)) {
|
|
269
303
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
270
304
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
throw new EmptyMarketParamsListError();
|
|
275
|
-
const marketParamsListSnapshot = marketParamsList.map(({ loanToken, collateralToken, oracle, irm, lltv }) => ({
|
|
276
|
-
loanToken,
|
|
277
|
-
collateralToken,
|
|
278
|
-
oracle,
|
|
279
|
-
irm,
|
|
280
|
-
lltv,
|
|
281
|
-
}));
|
|
282
|
-
const now = Time.timestamp();
|
|
283
|
-
const deadline = deadlineOverride ?? now + Time.s.from.h(2n);
|
|
284
|
-
// Reject the same bounds the action enforces, before `getRequirements()` can walk the caller
|
|
285
|
-
// through a vault-share approval or an EIP-712 permit for a deadline `buildTx()` cannot encode.
|
|
286
|
-
validateDeadline(deadline);
|
|
287
|
-
if (deadline <= now)
|
|
288
|
-
throw new ExpiredDeadlineError(deadline, now);
|
|
289
|
-
const vaultExitBundlesV1 = getChainAddress(this.chainId, "bundles.vaultExitBundlesV1");
|
|
290
|
-
const blue = getChainAddress(this.chainId, "blue");
|
|
291
|
-
let covered = 0n;
|
|
292
|
-
const assignedByMarket = new Map();
|
|
293
|
-
for (const marketParams of marketParamsListSnapshot) {
|
|
294
|
-
if (covered === amount)
|
|
295
|
-
break;
|
|
296
|
-
const marketId = MarketUtils.getMarketId(marketParams);
|
|
297
|
-
const allocation = vaultData.allocations.get(marketId);
|
|
298
|
-
if (allocation?.config.enabled !== true)
|
|
299
|
-
continue;
|
|
300
|
-
if (allocation.position.supplyShares === 0n)
|
|
301
|
-
continue;
|
|
302
|
-
const market = allocation.position.market.accrueInterest(now);
|
|
303
|
-
const available = market.toSupplyAssets(allocation.position.supplyShares);
|
|
304
|
-
const assigned = assignedByMarket.get(marketId) ?? 0n;
|
|
305
|
-
const chunk = MathLib.min(available, amount - covered);
|
|
306
|
-
if (assigned + chunk > available) {
|
|
307
|
-
throw new InKindRedeemCoverageError({
|
|
308
|
-
required: amount,
|
|
309
|
-
covered,
|
|
310
|
-
maxExitAssets: covered,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
assignedByMarket.set(marketId, assigned + chunk);
|
|
314
|
-
covered += chunk;
|
|
315
|
-
}
|
|
316
|
-
if (covered < amount) {
|
|
317
|
-
throw new InKindRedeemCoverageError({
|
|
318
|
-
required: amount,
|
|
319
|
-
covered,
|
|
320
|
-
maxExitAssets: covered,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
305
|
+
const { deadline, marketParamsListSnapshot, requiredShareAllowance, vaultExitBundlesV1, } = computeVaultV1InKindRedeemQuote({
|
|
306
|
+
amount,
|
|
307
|
+
marketParamsList,
|
|
324
308
|
vaultData,
|
|
325
|
-
deadline:
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
deadline: deadlineOverride,
|
|
310
|
+
now: suppliedNow ?? Time.timestamp(),
|
|
311
|
+
chainId: this.chainId,
|
|
328
312
|
});
|
|
329
313
|
return {
|
|
330
|
-
getRequirements:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
functionName: "allowance",
|
|
342
|
-
args: [userAddress, vaultExitBundlesV1],
|
|
343
|
-
}),
|
|
344
|
-
readContract(this.client.viemClient, {
|
|
345
|
-
address: this.vault,
|
|
346
|
-
abi: erc2612Abi,
|
|
347
|
-
functionName: "nonces",
|
|
348
|
-
args: [userAddress],
|
|
349
|
-
}),
|
|
350
|
-
readContract(this.client.viemClient, {
|
|
351
|
-
address: vaultData.asset,
|
|
352
|
-
abi: erc20Abi,
|
|
353
|
-
functionName: "balanceOf",
|
|
354
|
-
args: [blue],
|
|
355
|
-
}),
|
|
356
|
-
readContract(this.client.viemClient, {
|
|
357
|
-
address: this.vault,
|
|
358
|
-
abi: metaMorphoAbi,
|
|
359
|
-
functionName: "MORPHO",
|
|
360
|
-
}),
|
|
361
|
-
// feeRecipient() is trusted as returned by the RPC. See THREAT_MODEL.md, RPC.
|
|
362
|
-
readContract(this.client.viemClient, {
|
|
363
|
-
address: blue,
|
|
364
|
-
abi: blueAbi,
|
|
365
|
-
functionName: "feeRecipient",
|
|
366
|
-
}),
|
|
367
|
-
]);
|
|
368
|
-
if (!isAddressEqual(morpho, blue)) {
|
|
369
|
-
throw new VaultMorphoMismatchError({
|
|
370
|
-
vault: this.vault,
|
|
371
|
-
expected: blue,
|
|
372
|
-
actual: morpho,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
// Reject this unsupported configuration before authorizing vault shares:
|
|
376
|
-
// VaultExitBundlesV1 omits newly accrued Morpho fee shares when estimating the
|
|
377
|
-
// vault position, so its callback can exhaust marketParamsList and panic on-chain.
|
|
378
|
-
if (isAddressEqual(blueFeeRecipient, this.vault)) {
|
|
379
|
-
throw new VaultIsBlueFeeRecipientError(this.vault, blue);
|
|
380
|
-
}
|
|
381
|
-
if (blueBalance < amount) {
|
|
382
|
-
throw new InsufficientBlueBalanceForInKindRedeemError({
|
|
383
|
-
asset: vaultData.asset,
|
|
384
|
-
available: blueBalance,
|
|
385
|
-
required: amount,
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
if (allowance >= requiredShareAllowance)
|
|
389
|
-
return [];
|
|
390
|
-
if (this.client.options.supportSignature) {
|
|
391
|
-
return [
|
|
392
|
-
encodeVaultSharesPermit({
|
|
393
|
-
vault: vaultData,
|
|
394
|
-
version: "vaultV1",
|
|
395
|
-
spender: vaultExitBundlesV1,
|
|
396
|
-
owner: userAddress,
|
|
397
|
-
chainId: this.chainId,
|
|
398
|
-
nonce,
|
|
399
|
-
deadline,
|
|
400
|
-
}),
|
|
401
|
-
];
|
|
402
|
-
}
|
|
403
|
-
return [
|
|
404
|
-
encodeErc20Approval({
|
|
405
|
-
token: this.vault,
|
|
406
|
-
spender: vaultExitBundlesV1,
|
|
407
|
-
amount: maxUint256,
|
|
408
|
-
chainId: this.chainId,
|
|
409
|
-
}),
|
|
410
|
-
];
|
|
411
|
-
},
|
|
314
|
+
getRequirements: () => getVaultV1InKindRedeemRequirements(this.client.viemClient, {
|
|
315
|
+
vaultData,
|
|
316
|
+
vault: this.vault,
|
|
317
|
+
userAddress,
|
|
318
|
+
chainId: this.chainId,
|
|
319
|
+
deadline,
|
|
320
|
+
requiredShareAllowance,
|
|
321
|
+
supportSignature: this.client.options.supportSignature,
|
|
322
|
+
amount,
|
|
323
|
+
now: suppliedNow,
|
|
324
|
+
}),
|
|
412
325
|
buildTx: (signatures) => {
|
|
413
326
|
const permit = selectBundlesSharesPermitSignature(signatures, {
|
|
414
327
|
spender: vaultExitBundlesV1,
|
|
@@ -424,13 +337,15 @@ export class MorphoVaultV1 {
|
|
|
424
337
|
deadline,
|
|
425
338
|
requirementSignature: permit,
|
|
426
339
|
},
|
|
427
|
-
metadata
|
|
340
|
+
metadata,
|
|
428
341
|
});
|
|
429
342
|
},
|
|
430
343
|
};
|
|
431
344
|
}
|
|
432
345
|
/** {@inheritDoc VaultV1Actions.migrateToV2} */
|
|
433
346
|
migrateToV2(params) {
|
|
347
|
+
const suppliedNow = params.now;
|
|
348
|
+
const metadata = resolveTransactionMetadata(this.client.options.metadata, suppliedNow);
|
|
434
349
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
435
350
|
if (!isAddressEqual(params.sourceVault.address, this.vault)) {
|
|
436
351
|
throw new VaultAddressMismatchError(this.vault, params.sourceVault.address);
|
|
@@ -441,48 +356,28 @@ export class MorphoVaultV1 {
|
|
|
441
356
|
if (isAddressEqual(this.vault, params.targetVault.address)) {
|
|
442
357
|
throw new SameVaultMigrationError(this.vault);
|
|
443
358
|
}
|
|
444
|
-
const
|
|
445
|
-
const shares = "shares" in params ? params.shares : undefined;
|
|
446
|
-
if ((assets == null) === (shares == null)) {
|
|
447
|
-
throw new AmountAndSharesExclusiveError();
|
|
448
|
-
}
|
|
449
|
-
const selectedAmount = assets ?? shares ?? 0n;
|
|
450
|
-
if (selectedAmount <= 0n) {
|
|
451
|
-
throw new NonPositiveInputError(assets != null ? "assets" : "shares", selectedAmount);
|
|
452
|
-
}
|
|
359
|
+
const { assets, shares } = getMigrationAmounts(params);
|
|
453
360
|
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
454
361
|
validateSlippageTolerance(slippageTolerance);
|
|
455
|
-
const createdAt = Time.timestamp();
|
|
362
|
+
const createdAt = suppliedNow ?? Time.timestamp();
|
|
456
363
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
457
|
-
if (deadline <= createdAt)
|
|
364
|
+
if (deadline <= createdAt) {
|
|
458
365
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
366
|
+
}
|
|
459
367
|
const common = normalizeBundlesCommonParams({
|
|
460
368
|
deadline,
|
|
461
369
|
referralFeePct: params.referralFeePct,
|
|
462
370
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
463
371
|
});
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
.values()
|
|
470
|
-
.reduce((timestamp, { position }) => MathLib.max(timestamp, position.market.lastUpdate), createdAt))
|
|
471
|
-
.toAssets(shares ?? 0n, "Down");
|
|
472
|
-
const referralFeeAssets = getBundlesReferralFeeAssets(grossAssets, common.referralFeePct);
|
|
473
|
-
const maxSharePriceVaultV2 = computeVaultMaxSharePrice({
|
|
474
|
-
vaultData: params.targetVault,
|
|
372
|
+
const { maxSharePriceVaultV2, requiredShareAllowance } = computeVaultV1MigrateToV2Quote({
|
|
373
|
+
sourceVault: params.sourceVault,
|
|
374
|
+
targetVault: params.targetVault,
|
|
375
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
376
|
+
referralFeePct: common.referralFeePct,
|
|
475
377
|
deadline,
|
|
476
|
-
assets: grossAssets - referralFeeAssets,
|
|
477
378
|
slippageTolerance,
|
|
379
|
+
now: createdAt,
|
|
478
380
|
});
|
|
479
|
-
const requiredShareAllowance = shares ??
|
|
480
|
-
computeVaultMaxShareAllowance({
|
|
481
|
-
vaultData: params.sourceVault,
|
|
482
|
-
deadline,
|
|
483
|
-
assets: assets ?? 0n,
|
|
484
|
-
slippageTolerance,
|
|
485
|
-
});
|
|
486
381
|
const spender = getChainAddress(this.chainId, "bundles.vaultBundlesV1");
|
|
487
382
|
const { userAddress } = params;
|
|
488
383
|
const sourceAsset = params.sourceVault.asset;
|
|
@@ -501,9 +396,10 @@ export class MorphoVaultV1 {
|
|
|
501
396
|
});
|
|
502
397
|
return Object.freeze({
|
|
503
398
|
getRequirements: async () => {
|
|
504
|
-
const now = Time.timestamp();
|
|
505
|
-
if (deadline <= now)
|
|
399
|
+
const now = suppliedNow ?? Time.timestamp();
|
|
400
|
+
if (deadline <= now) {
|
|
506
401
|
throw new ExpiredDeadlineError(deadline, now);
|
|
402
|
+
}
|
|
507
403
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
508
404
|
// Re-read the live share allowance on every call instead of caching the resolved requirements.
|
|
509
405
|
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
@@ -532,7 +428,7 @@ export class MorphoVaultV1 {
|
|
|
532
428
|
args: {
|
|
533
429
|
targetVault: targetAddress,
|
|
534
430
|
targetAsset,
|
|
535
|
-
...(assets
|
|
431
|
+
...(assets == null ? { shares: shares ?? 0n } : { assets }),
|
|
536
432
|
maxSharePriceVaultV2,
|
|
537
433
|
userAddress,
|
|
538
434
|
requirementSignature: permit,
|
|
@@ -540,7 +436,7 @@ export class MorphoVaultV1 {
|
|
|
540
436
|
referralFeeRecipient: common.referralFeeRecipient,
|
|
541
437
|
deadline,
|
|
542
438
|
},
|
|
543
|
-
metadata
|
|
439
|
+
metadata,
|
|
544
440
|
});
|
|
545
441
|
},
|
|
546
442
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* @internal Computes the fixed exit quote from a snapshot without reads or signing.
|
|
5
|
+
* @param params - Snapshot, caller intent and explicit quote timestamp.
|
|
6
|
+
* @returns Fixed action fields and the minimum share allowance.
|
|
7
|
+
*/
|
|
8
|
+
export declare function computeVaultV2ForceWithdrawQuote({ exitAssets, vaultData, userAddress, adapter: adapterOverride, deadline: deadlineOverride, slippageTolerance, minSharePriceE27: minSharePriceE27Override, referralFeePct, referralFeeRecipient, now, vault, }: {
|
|
9
|
+
readonly exitAssets: bigint;
|
|
10
|
+
readonly vaultData: AccrualVaultV2;
|
|
11
|
+
readonly userAddress: Address;
|
|
12
|
+
readonly adapter?: Address;
|
|
13
|
+
readonly deadline?: bigint;
|
|
14
|
+
readonly slippageTolerance?: bigint;
|
|
15
|
+
readonly minSharePriceE27?: bigint;
|
|
16
|
+
readonly referralFeePct?: bigint;
|
|
17
|
+
readonly referralFeeRecipient?: Address;
|
|
18
|
+
readonly now: bigint;
|
|
19
|
+
readonly vault: Address;
|
|
20
|
+
}): {
|
|
21
|
+
deadline: bigint;
|
|
22
|
+
adapter: `0x${string}`;
|
|
23
|
+
minSharePriceE27: bigint;
|
|
24
|
+
requiredShareAllowance: bigint;
|
|
25
|
+
};
|