@morpho-org/morpho-sdk 10.0.0-next.0 → 10.0.1
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/README.md +104 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- 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.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.js +2 -1
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +2 -1
- package/lib/cjs/actions/midnight/takeLend.js +2 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +2 -1
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -11
- 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/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/blue/blue.js +8 -4
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/deadline.js +2 -1
- package/lib/cjs/entities/midnight/midnight.js +14 -7
- package/lib/cjs/entities/midnight/publication.js +73 -44
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +9 -13
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- 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.js +51 -181
- 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 +8 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +62 -429
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +34 -19
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.js +12 -6
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +12 -6
- 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 +44 -22
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- 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 +72 -22
- 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 +41 -15
- 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 +14 -31
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +15 -141
- 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 +14 -27
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +17 -124
- 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.js +16 -8
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +10 -1
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.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.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.js +2 -1
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeBorrow.js +2 -1
- package/lib/esm/actions/midnight/takeLend.js +2 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +2 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +2 -1
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +4 -13
- 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/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.js +8 -4
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.js +2 -1
- package/lib/esm/entities/midnight/midnight.js +14 -7
- package/lib/esm/entities/midnight/publication.js +73 -44
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +10 -14
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +2 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +7 -1
- 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.js +57 -187
- 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 +8 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +70 -437
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +346 -234
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +35 -20
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.js +12 -6
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +10 -5
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +6 -3
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +12 -6
- 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 +44 -22
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +14 -7
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- 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 +68 -18
- 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 +41 -15
- 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 +14 -31
- package/lib/esm/transactionPlan/vaultv2/deposit.js +17 -142
- 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 +14 -27
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +19 -125
- 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.js +16 -8
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +10 -1
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
3
|
+
import { vaultV2Redeem } from "../../actions/vaultV2/redeem.js";
|
|
4
|
+
import { getVaultPermit } from "../permit.js";
|
|
5
|
+
import { prepareVaultRedeem } from "../redeem.js";
|
|
6
|
+
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Prepares an exact-share redemption through VaultBundlesV1. Reads share allowance and, when a
|
|
9
|
+
* permit is needed, the vault nonce. No quote or fetch request is needed for an exact share count.
|
|
10
|
+
* @param client - Viem client targeting `params.chainId`.
|
|
11
|
+
* @param params.shareToken - Vault share token; an address-only Token is sufficient, without an accrual snapshot.
|
|
12
|
+
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
13
|
+
* @param params.account - Non-zero share owner, permit signer and transaction sender; receives the net assets.
|
|
14
|
+
* @param params.shares - Positive exact shares to burn, in share base units; use the account's balance for full redemption.
|
|
15
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of gross redeemed assets; defaults to zero and must be below 10,000.
|
|
16
|
+
* @param params.referralFee.recipient - Optional fee recipient; must be non-zero when the fee is positive.
|
|
17
|
+
* @param params.supportSignature - Optional ERC-2612 share-permit preference; defaults to `false` for direct approval.
|
|
18
|
+
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
19
|
+
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
20
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
21
|
+
* @returns A deep-frozen, serializable `TransactionPlan` with version, chain, account, expiry,
|
|
22
|
+
* ordered approval/redeem steps and signature requests. Any required share approval or permit is unlimited.
|
|
23
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
24
|
+
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
25
|
+
* @throws {NonPositiveInputError} when `expiresAt` or `shares` is not positive.
|
|
26
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is not in the future.
|
|
27
|
+
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
28
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `shares` exceeds uint256.
|
|
29
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
30
|
+
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
31
|
+
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no non-zero recipient.
|
|
32
|
+
* @throws {ChainIdMismatchError} when the declared or RPC chain differs from `chainId`.
|
|
33
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
34
|
+
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
35
|
+
* @throws {MissingContractCodeError} when VaultBundlesV1 is absent on the target chain.
|
|
36
|
+
* @throws {viem.BaseError} when a chain, bytecode, allowance or permit nonce read fails.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Token } from "@morpho-org/morpho-sdk/blue/entities";
|
|
40
|
+
* import { prepareVaultV2Redeem, type TransactionPlan } from "@morpho-org/morpho-sdk";
|
|
41
|
+
* import { type Address, createPublicClient, http } from "viem";
|
|
42
|
+
* import { mainnet } from "viem/chains";
|
|
43
|
+
*
|
|
44
|
+
* // Supply a non-zero share owner and its desired redemption shares in share base units.
|
|
45
|
+
* export async function prepareRedeem(account: Address, shares: bigint): Promise<TransactionPlan> {
|
|
46
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
47
|
+
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
48
|
+
* const plan = await prepareVaultV2Redeem(client, {
|
|
49
|
+
* shareToken: new Token({ address: vault }), chainId: mainnet.id, account, shares, supportSignature: false,
|
|
50
|
+
* });
|
|
51
|
+
* // plan: TransactionPlan = { version: 2, chainId: 1, account, expiresAt,
|
|
52
|
+
* // steps: [optional unlimited approval, vaultV2Redeem], signatureRequests: [] }.
|
|
53
|
+
* return plan;
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export async function prepareVaultV2Redeem(client, params) {
|
|
58
|
+
return prepareVaultRedeem(client, { ...params, type: "vaultV2Redeem" });
|
|
59
|
+
}
|
|
60
|
+
/** @internal Encodes a redemption from its fixed inputs and referenced share permit. */
|
|
61
|
+
export function buildVaultV2Redeem(action, requests) {
|
|
62
|
+
const { chainId, account, vault, shares, ...common } = action.inputs;
|
|
63
|
+
const signature = getVaultPermit(requests, {
|
|
64
|
+
id: action.signatureRequestIds.tokenPermit,
|
|
65
|
+
asset: vault,
|
|
66
|
+
owner: account,
|
|
67
|
+
});
|
|
68
|
+
const permit = selectBundlesSharesPermitSignature(signature ? [signature] : [], {
|
|
69
|
+
spender: getChainAddress(chainId, "bundles.vaultBundlesV1"),
|
|
70
|
+
amount: shares,
|
|
71
|
+
deadline: action.inputs.deadline,
|
|
72
|
+
});
|
|
73
|
+
return vaultV2Redeem({
|
|
74
|
+
vault: { chainId, address: vault },
|
|
75
|
+
args: {
|
|
76
|
+
...common,
|
|
77
|
+
shares,
|
|
78
|
+
userAddress: account,
|
|
79
|
+
requirementSignature: permit,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { type IntentParams } from "../intent.js";
|
|
1
|
+
import type { AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import type { Transaction, VaultV2WithdrawAction } from "../../types/index.js";
|
|
5
4
|
import type { Action, SignatureRequest, TransactionPlan } from "../types.js";
|
|
6
|
-
|
|
7
|
-
export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|
|
5
|
+
import { type WithdrawPlanParams } from "../withdraw.js";
|
|
8
6
|
/**
|
|
9
|
-
* Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
|
|
10
7
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
8
|
+
* Caller intent for a Vault V2 asset withdrawal, mirroring the Actions API withdraw inputs, plus the snapshot.
|
|
11
9
|
*/
|
|
12
|
-
export interface VaultV2WithdrawPlanParams extends
|
|
13
|
-
readonly vault: Address;
|
|
14
|
-
/** Gross assets withdrawn, before the referral fee. */
|
|
15
|
-
readonly amount: bigint;
|
|
16
|
-
/**
|
|
17
|
-
* Accrual snapshot of `vault`, fetched by the caller with `fetchAccrualVaultV2`. The required
|
|
18
|
-
* share allowance is derived from it at preparation; the snapshot itself is never stored.
|
|
19
|
-
*/
|
|
20
|
-
readonly vaultData: AccrualVaultV2;
|
|
10
|
+
export interface VaultV2WithdrawPlanParams extends WithdrawPlanParams<AccrualVaultV2> {
|
|
21
11
|
}
|
|
22
12
|
/**
|
|
13
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
23
14
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
24
15
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
25
16
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -28,29 +19,26 @@ export interface VaultV2WithdrawPlanParams extends IntentParams, ReferenceTimest
|
|
|
28
19
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
29
20
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
30
21
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
31
|
-
* @param params.vault -
|
|
32
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
22
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
33
23
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
34
24
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
35
|
-
* @param params.
|
|
36
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
25
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
26
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
37
27
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
38
28
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
39
29
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
40
30
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
41
31
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
42
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
43
32
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
44
33
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
45
34
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
46
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
35
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
47
36
|
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
48
37
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
49
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
38
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
50
39
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
51
40
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
52
41
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
53
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
54
42
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
55
43
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
56
44
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -64,13 +52,12 @@ export interface VaultV2WithdrawPlanParams extends IntentParams, ReferenceTimest
|
|
|
64
52
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
65
53
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
66
54
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
67
|
-
*
|
|
68
|
-
*
|
|
55
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
56
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
69
57
|
* now: (await client.getBlock()).timestamp,
|
|
70
58
|
* });
|
|
71
59
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
72
60
|
* ```
|
|
73
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
74
61
|
*/
|
|
75
62
|
export declare function prepareVaultV2Withdraw(client: Client, params: VaultV2WithdrawPlanParams): Promise<TransactionPlan>;
|
|
76
63
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
@@ -1,53 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isAddressEqual } from "viem";
|
|
4
|
-
import { normalizeBundlesCommonParams, selectBundlesSharesPermitSignature, } from "../../actions/bundles/common.js";
|
|
5
|
-
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
1
|
+
import { getChainAddress } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { selectBundlesSharesPermitSignature } from "../../actions/bundles/common.js";
|
|
6
3
|
import { vaultV2Withdraw } from "../../actions/vaultV2/withdraw.js";
|
|
7
|
-
import { assertRegistryTargetsHaveCode } from "../../entities/requirements/assertContractCode.js";
|
|
8
|
-
import { getVaultBundlesSharesRequirements } from "../../entities/requirements/getVaultBundlesSharesRequirements.js";
|
|
9
|
-
import { computeVaultMaxShareAllowance } from "../../helpers/index.js";
|
|
10
|
-
import { validateUint256Field } from "../../helpers/validate.js";
|
|
11
|
-
import { NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
12
|
-
import { resolveIntent } from "../intent.js";
|
|
13
4
|
import { getVaultPermit } from "../permit.js";
|
|
14
|
-
import {
|
|
15
|
-
import { validatePlanFields, validateVaultPlanAction } from "../validation.js";
|
|
16
|
-
/** @internal Validates the stored Vault V2 withdrawal action's input shape. */
|
|
17
|
-
export function validateWithdrawPlanAction(action, path) {
|
|
18
|
-
const inputs = validateVaultPlanAction(action, path);
|
|
19
|
-
validatePlanFields(inputs, {
|
|
20
|
-
path: `${path}.inputs`,
|
|
21
|
-
fields: {
|
|
22
|
-
amount: "uint256 bigint",
|
|
23
|
-
requiredShareAllowance: "uint256 bigint",
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function resolveWithdrawInputs(params, now) {
|
|
28
|
-
const { vault, amount, vaultData } = params;
|
|
29
|
-
const intent = resolveIntent(params, now);
|
|
30
|
-
if (amount <= 0n)
|
|
31
|
-
throw new NonPositiveInputError("amount", amount);
|
|
32
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
33
|
-
validateUint256Field("amount", amount);
|
|
34
|
-
const common = normalizeBundlesCommonParams({
|
|
35
|
-
deadline: intent.deadline,
|
|
36
|
-
referralFeePct: intent.referralFeePct,
|
|
37
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
38
|
-
});
|
|
39
|
-
if (!isAddressEqual(vaultData.address, vault))
|
|
40
|
-
throw new VaultAddressMismatchError(vaultData.address, vault);
|
|
41
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
42
|
-
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
43
|
-
vaultData,
|
|
44
|
-
deadline: intent.deadline,
|
|
45
|
-
assets: amount,
|
|
46
|
-
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
47
|
-
});
|
|
48
|
-
return { intent, common, requiredShareAllowance };
|
|
49
|
-
}
|
|
5
|
+
import { prepareVaultWithdraw } from "../withdraw.js";
|
|
50
6
|
/**
|
|
7
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
51
8
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
52
9
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
53
10
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -56,29 +13,26 @@ function resolveWithdrawInputs(params, now) {
|
|
|
56
13
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
57
14
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
58
15
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
59
|
-
* @param params.vault -
|
|
60
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
16
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
61
17
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
62
18
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
63
|
-
* @param params.
|
|
64
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
19
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
20
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
65
21
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
66
22
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
67
23
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
68
24
|
* @param params.expiresAt - Optional Unix timestamp in seconds as a safe integer, later than `now`; defaults to `now + 2h` (device clock when `now` is omitted).
|
|
69
25
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
70
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
71
26
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
72
27
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
73
28
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
74
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
29
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
75
30
|
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
76
31
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
77
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
32
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
78
33
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
79
34
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
80
35
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
81
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
82
36
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
83
37
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
84
38
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -92,84 +46,19 @@ function resolveWithdrawInputs(params, now) {
|
|
|
92
46
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
93
47
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
94
48
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
95
|
-
*
|
|
96
|
-
*
|
|
49
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
50
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
97
51
|
* now: (await client.getBlock()).timestamp,
|
|
98
52
|
* });
|
|
99
53
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
100
54
|
* ```
|
|
101
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
102
55
|
*/
|
|
103
56
|
export async function prepareVaultV2Withdraw(client, params) {
|
|
104
|
-
|
|
105
|
-
const now = params.now ?? Time.timestamp();
|
|
106
|
-
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
107
|
-
const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
|
|
108
|
-
const [, , requirements] = await Promise.all([
|
|
109
|
-
validateClientChainId(client, chainId),
|
|
110
|
-
assertRegistryTargetsHaveCode(client, chainId, [
|
|
111
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
112
|
-
]),
|
|
113
|
-
getVaultBundlesSharesRequirements(client, {
|
|
114
|
-
vaultData: new Token({ address: vault }),
|
|
115
|
-
version: "vaultV2",
|
|
116
|
-
owner: account,
|
|
117
|
-
chainId,
|
|
118
|
-
requiredShareAllowance,
|
|
119
|
-
deadline: intent.deadline,
|
|
120
|
-
supportSignature: intent.supportSignature,
|
|
121
|
-
now,
|
|
122
|
-
}),
|
|
123
|
-
]);
|
|
124
|
-
const approvals = [];
|
|
125
|
-
const signatureRequests = [];
|
|
126
|
-
const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
|
|
127
|
-
const requirement = requirements[0];
|
|
128
|
-
if (requirement !== undefined) {
|
|
129
|
-
if ("sign" in requirement) {
|
|
130
|
-
signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
approvals.push(buildApprovalStep(requirement, {
|
|
134
|
-
id: "vaultV2Withdraw:approval",
|
|
135
|
-
chainId,
|
|
136
|
-
account,
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return deepFreeze(structuredClone({
|
|
141
|
-
version: 1,
|
|
142
|
-
account,
|
|
143
|
-
chainId,
|
|
144
|
-
expiresAt: intent.expiresAt,
|
|
145
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
146
|
-
steps: [
|
|
147
|
-
...approvals,
|
|
148
|
-
{
|
|
149
|
-
id: "vaultV2Withdraw",
|
|
150
|
-
label: "Withdraw from vault",
|
|
151
|
-
action: {
|
|
152
|
-
type: "vaultV2Withdraw",
|
|
153
|
-
inputs: {
|
|
154
|
-
chainId,
|
|
155
|
-
account,
|
|
156
|
-
vault,
|
|
157
|
-
amount,
|
|
158
|
-
requiredShareAllowance,
|
|
159
|
-
...common,
|
|
160
|
-
},
|
|
161
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
162
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
163
|
-
: {},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
],
|
|
167
|
-
signatureRequests,
|
|
168
|
-
}));
|
|
57
|
+
return prepareVaultWithdraw(client, { ...params, type: "vaultV2Withdraw" });
|
|
169
58
|
}
|
|
170
59
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
171
60
|
export function buildVaultV2Withdraw(action, requests) {
|
|
172
|
-
const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
61
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
173
62
|
const signature = getVaultPermit(requests, {
|
|
174
63
|
id: action.signatureRequestIds.tokenPermit,
|
|
175
64
|
asset: action.inputs.vault,
|
|
@@ -182,6 +71,11 @@ export function buildVaultV2Withdraw(action, requests) {
|
|
|
182
71
|
});
|
|
183
72
|
return vaultV2Withdraw({
|
|
184
73
|
vault: { chainId, address: action.inputs.vault },
|
|
185
|
-
args: {
|
|
74
|
+
args: {
|
|
75
|
+
...args,
|
|
76
|
+
amount: assets,
|
|
77
|
+
userAddress: account,
|
|
78
|
+
requirementSignature: permit,
|
|
79
|
+
},
|
|
186
80
|
});
|
|
187
81
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UnsupportedTransactionPlanVersionError } from "./error.js";
|
|
2
2
|
/** @internal Rejects unsupported plan versions before interpreting stored fields. */
|
|
3
3
|
export function validateTransactionPlanVersion(version) {
|
|
4
|
-
if (version !==
|
|
4
|
+
if (version !== 2) {
|
|
5
5
|
throw new UnsupportedTransactionPlanVersionError(version);
|
|
6
|
+
}
|
|
6
7
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type ReferenceTimestampParams } from "../types/index.js";
|
|
4
|
+
import { type IntentParams } from "./intent.js";
|
|
5
|
+
import type { TransactionPlan } from "./types.js";
|
|
6
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
7
|
+
export declare function validateWithdrawPlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
|
+
/** @internal Snapshot-based asset withdrawal intent shared by V1 and V2. */
|
|
9
|
+
export interface WithdrawPlanParams<TSnapshot extends AccrualVault | AccrualVaultV2> extends Omit<IntentParams, "deployless">, ReferenceTimestampParams {
|
|
10
|
+
/** Caller-fetched accrual snapshot used to quote the required share allowance. */
|
|
11
|
+
readonly vault: TSnapshot;
|
|
12
|
+
/** Gross assets withdrawn, before the referral fee. */
|
|
13
|
+
readonly assets: bigint;
|
|
14
|
+
}
|
|
15
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
16
|
+
export declare function prepareVaultWithdraw<TSnapshot extends AccrualVault | AccrualVaultV2>(client: Client, params: WithdrawPlanParams<TSnapshot> & {
|
|
17
|
+
readonly type: "vaultV1Withdraw" | "vaultV2Withdraw";
|
|
18
|
+
}): Promise<TransactionPlan>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, Token, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { normalizeBundlesCommonParams } from "../actions/bundles/common.js";
|
|
4
|
+
import { computeVaultMaxShareAllowance } from "../helpers/index.js";
|
|
5
|
+
import { validateUint256Field } from "../helpers/validate.js";
|
|
6
|
+
import { NonPositiveInputError, } from "../types/index.js";
|
|
7
|
+
import { resolveIntent } from "./intent.js";
|
|
8
|
+
import { getVaultShareSpendingRequirements } from "./shareSpending.js";
|
|
9
|
+
import { validatePlanFields, validateVaultPlanAction } from "./validation.js";
|
|
10
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
11
|
+
export function validateWithdrawPlanAction(action, path) {
|
|
12
|
+
const inputs = validateVaultPlanAction(action, path);
|
|
13
|
+
validatePlanFields(inputs, {
|
|
14
|
+
path: `${path}.inputs`,
|
|
15
|
+
fields: {
|
|
16
|
+
assets: "uint256 bigint",
|
|
17
|
+
requiredShareAllowance: "uint256 bigint",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function resolveWithdrawInputs(params, now) {
|
|
22
|
+
const { vault, assets } = params;
|
|
23
|
+
const intent = resolveIntent(params, now);
|
|
24
|
+
if (assets <= 0n) {
|
|
25
|
+
throw new NonPositiveInputError("assets", assets);
|
|
26
|
+
}
|
|
27
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
28
|
+
validateUint256Field("assets", assets);
|
|
29
|
+
const common = normalizeBundlesCommonParams({
|
|
30
|
+
deadline: intent.deadline,
|
|
31
|
+
referralFeePct: intent.referralFeePct,
|
|
32
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
33
|
+
});
|
|
34
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
35
|
+
const requiredShareAllowance = computeVaultMaxShareAllowance({
|
|
36
|
+
vaultData: vault,
|
|
37
|
+
deadline: intent.deadline,
|
|
38
|
+
assets,
|
|
39
|
+
slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
|
|
40
|
+
});
|
|
41
|
+
return { intent, common, requiredShareAllowance };
|
|
42
|
+
}
|
|
43
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
44
|
+
export async function prepareVaultWithdraw(client, params) {
|
|
45
|
+
const { chainId, account, assets } = params;
|
|
46
|
+
const vault = params.vault.address;
|
|
47
|
+
const now = params.now ?? Time.timestamp();
|
|
48
|
+
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
49
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await getVaultShareSpendingRequirements(client, {
|
|
50
|
+
type: params.type,
|
|
51
|
+
shareToken: params.type === "vaultV1Withdraw"
|
|
52
|
+
? params.vault
|
|
53
|
+
: new Token({ address: vault }),
|
|
54
|
+
chainId,
|
|
55
|
+
account,
|
|
56
|
+
requiredShareAllowance,
|
|
57
|
+
deadline: intent.deadline,
|
|
58
|
+
supportSignature: intent.supportSignature,
|
|
59
|
+
now,
|
|
60
|
+
});
|
|
61
|
+
return deepFreeze(structuredClone({
|
|
62
|
+
version: 2,
|
|
63
|
+
account,
|
|
64
|
+
chainId,
|
|
65
|
+
expiresAt: intent.expiresAt,
|
|
66
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
67
|
+
steps: [
|
|
68
|
+
...approvals,
|
|
69
|
+
{
|
|
70
|
+
id: params.type,
|
|
71
|
+
label: "Withdraw from vault",
|
|
72
|
+
action: {
|
|
73
|
+
type: params.type,
|
|
74
|
+
inputs: {
|
|
75
|
+
chainId,
|
|
76
|
+
account,
|
|
77
|
+
vault,
|
|
78
|
+
assets,
|
|
79
|
+
requiredShareAllowance,
|
|
80
|
+
...common,
|
|
81
|
+
},
|
|
82
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
83
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
84
|
+
: {},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
signatureRequests,
|
|
89
|
+
}));
|
|
90
|
+
}
|
package/lib/esm/types/action.js
CHANGED
|
@@ -209,28 +209,36 @@ export function isAuthorizationSignature(signature) {
|
|
|
209
209
|
* ```
|
|
210
210
|
*/
|
|
211
211
|
export function selectRequirementSignatures(signatures, accepts) {
|
|
212
|
-
if (signatures == null)
|
|
212
|
+
if (signatures == null) {
|
|
213
213
|
return {};
|
|
214
|
+
}
|
|
214
215
|
const permits = signatures.filter(isPermitSignature);
|
|
215
216
|
const permit2Transfers = signatures.filter(isPermit2SignatureTransferSignature);
|
|
216
217
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
217
218
|
const unsupported = signatures.find((signature) => !isPermitSignature(signature) &&
|
|
218
219
|
!isPermit2SignatureTransferSignature(signature) &&
|
|
219
220
|
!isAuthorizationSignature(signature));
|
|
220
|
-
if (unsupported != null)
|
|
221
|
+
if (unsupported != null) {
|
|
221
222
|
throw new UnsupportedRequirementSignatureError(unsupported.action.type);
|
|
222
|
-
|
|
223
|
+
}
|
|
224
|
+
if (!accepts.permit && permits.length > 0) {
|
|
223
225
|
throw new UnexpectedRequirementSignatureError("permit");
|
|
224
|
-
|
|
226
|
+
}
|
|
227
|
+
if (!accepts.permit2SignatureTransfer && permit2Transfers.length > 0) {
|
|
225
228
|
throw new UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
226
|
-
|
|
229
|
+
}
|
|
230
|
+
if (!accepts.authorization && authorizations.length > 0) {
|
|
227
231
|
throw new UnexpectedRequirementSignatureError("authorization");
|
|
228
|
-
|
|
232
|
+
}
|
|
233
|
+
if (permits.length > 1) {
|
|
229
234
|
throw new AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
230
|
-
|
|
235
|
+
}
|
|
236
|
+
if (permit2Transfers.length > 1) {
|
|
231
237
|
throw new AmbiguousRequirementSignaturesError("permit2SignatureTransfer", permit2Transfers.length);
|
|
232
|
-
|
|
238
|
+
}
|
|
239
|
+
if (authorizations.length > 1) {
|
|
233
240
|
throw new AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
241
|
+
}
|
|
234
242
|
return {
|
|
235
243
|
permit: permits[0],
|
|
236
244
|
permit2SignatureTransfer: permit2Transfers[0],
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -711,7 +711,10 @@ export declare class AddressMismatchError extends Error {
|
|
|
711
711
|
export declare class ChainIdMismatchError extends Error {
|
|
712
712
|
constructor(clientChainId: number | undefined, argsChainId: number);
|
|
713
713
|
}
|
|
714
|
-
/**
|
|
714
|
+
/**
|
|
715
|
+
* Thrown when a runtime crypto API is required but unavailable.
|
|
716
|
+
* @deprecated This error is never thrown by the SDK and will be removed in the next major version.
|
|
717
|
+
*/
|
|
715
718
|
export declare class CryptoUnavailableError extends Error {
|
|
716
719
|
constructor(feature: string);
|
|
717
720
|
}
|
|
@@ -775,6 +778,10 @@ export declare class ChainWNativeMissingError extends Error {
|
|
|
775
778
|
}
|
|
776
779
|
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
777
780
|
export declare class VaultAddressMismatchError extends Error {
|
|
781
|
+
/** Vault targeted by the caller. */
|
|
782
|
+
readonly expected: Address;
|
|
783
|
+
/** Vault address found in the supplied snapshot. */
|
|
784
|
+
readonly actual: Address;
|
|
778
785
|
constructor(vaultAddress: Address, argsVaultAddress: Address);
|
|
779
786
|
}
|
|
780
787
|
/** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
|
package/lib/esm/types/error.js
CHANGED
|
@@ -851,7 +851,10 @@ export class ChainIdMismatchError extends Error {
|
|
|
851
851
|
this.name = "ChainIdMismatchError";
|
|
852
852
|
}
|
|
853
853
|
}
|
|
854
|
-
/**
|
|
854
|
+
/**
|
|
855
|
+
* Thrown when a runtime crypto API is required but unavailable.
|
|
856
|
+
* @deprecated This error is never thrown by the SDK and will be removed in the next major version.
|
|
857
|
+
*/
|
|
855
858
|
export class CryptoUnavailableError extends Error {
|
|
856
859
|
constructor(feature) {
|
|
857
860
|
super(`Crypto API is required for ${feature} but is unavailable.`);
|
|
@@ -949,9 +952,15 @@ export class ChainWNativeMissingError extends Error {
|
|
|
949
952
|
}
|
|
950
953
|
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
951
954
|
export class VaultAddressMismatchError extends Error {
|
|
955
|
+
/** Vault targeted by the caller. */
|
|
956
|
+
expected;
|
|
957
|
+
/** Vault address found in the supplied snapshot. */
|
|
958
|
+
actual;
|
|
952
959
|
constructor(vaultAddress, argsVaultAddress) {
|
|
953
960
|
super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
|
|
954
961
|
this.name = "VaultAddressMismatchError";
|
|
962
|
+
this.expected = vaultAddress;
|
|
963
|
+
this.actual = argsVaultAddress;
|
|
955
964
|
}
|
|
956
965
|
}
|
|
957
966
|
/** Thrown when an action uses `nativeAmount` but the target asset is not the chain's wNative. */
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
6
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
8
8
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
9
9
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -17,7 +17,7 @@ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier
|
|
|
17
17
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
18
18
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
19
19
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
|
|
20
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys,
|
|
20
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
21
21
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
22
22
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
23
23
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/lib/esm/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils,
|
|
5
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
7
7
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
8
8
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -15,7 +15,7 @@ RateRatifierV1Utils as MidnightRateRatifierV1Utils, Ratifier as MidnightRatifier
|
|
|
15
15
|
RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier,
|
|
16
16
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
17
17
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
18
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys,
|
|
18
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
19
19
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
20
20
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
21
21
|
export { previewVaultV2ForceWithdraw, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/morpho-sdk package version. */
|
|
2
|
-
export declare const version = "10.0.
|
|
2
|
+
export declare const version = "10.0.1";
|
package/lib/esm/version.js
CHANGED