@morpho-org/morpho-sdk 10.0.0-next.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/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
|
@@ -1,58 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateWithdrawPlanAction = validateWithdrawPlanAction;
|
|
4
3
|
exports.prepareVaultV2Withdraw = prepareVaultV2Withdraw;
|
|
5
4
|
exports.buildVaultV2Withdraw = buildVaultV2Withdraw;
|
|
6
|
-
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
-
const viem_1 = require("viem");
|
|
9
6
|
const common_js_1 = require("../../actions/bundles/common.js");
|
|
10
|
-
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
11
7
|
const withdraw_js_1 = require("../../actions/vaultV2/withdraw.js");
|
|
12
|
-
const assertContractCode_js_1 = require("../../entities/requirements/assertContractCode.js");
|
|
13
|
-
const getVaultBundlesSharesRequirements_js_1 = require("../../entities/requirements/getVaultBundlesSharesRequirements.js");
|
|
14
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
15
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
16
|
-
const index_js_2 = require("../../types/index.js");
|
|
17
|
-
const intent_js_1 = require("../intent.js");
|
|
18
8
|
const permit_js_1 = require("../permit.js");
|
|
19
|
-
const
|
|
20
|
-
const validation_js_1 = require("../validation.js");
|
|
21
|
-
/** @internal Validates the stored Vault V2 withdrawal action's input shape. */
|
|
22
|
-
function validateWithdrawPlanAction(action, path) {
|
|
23
|
-
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
24
|
-
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
25
|
-
path: `${path}.inputs`,
|
|
26
|
-
fields: {
|
|
27
|
-
amount: "uint256 bigint",
|
|
28
|
-
requiredShareAllowance: "uint256 bigint",
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function resolveWithdrawInputs(params, now) {
|
|
33
|
-
const { vault, amount, vaultData } = params;
|
|
34
|
-
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
35
|
-
if (amount <= 0n)
|
|
36
|
-
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
37
|
-
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
38
|
-
(0, validate_js_1.validateUint256Field)("amount", amount);
|
|
39
|
-
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
40
|
-
deadline: intent.deadline,
|
|
41
|
-
referralFeePct: intent.referralFeePct,
|
|
42
|
-
referralFeeRecipient: intent.referralFeeRecipient,
|
|
43
|
-
});
|
|
44
|
-
if (!(0, viem_1.isAddressEqual)(vaultData.address, vault))
|
|
45
|
-
throw new index_js_2.VaultAddressMismatchError(vaultData.address, vault);
|
|
46
|
-
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
47
|
-
const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
|
|
48
|
-
vaultData,
|
|
49
|
-
deadline: intent.deadline,
|
|
50
|
-
assets: amount,
|
|
51
|
-
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
52
|
-
});
|
|
53
|
-
return { intent, common, requiredShareAllowance };
|
|
54
|
-
}
|
|
9
|
+
const withdraw_js_2 = require("../withdraw.js");
|
|
55
10
|
/**
|
|
11
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
56
12
|
* Prepares a withdrawal plan from caller intent and a vault snapshot. The share quote is fixed on
|
|
57
13
|
* the withdrawal step at preparation, because the required share allowance decides the approval or
|
|
58
14
|
* permit prerequisite, so the returned plan is static: only signatures are added before building.
|
|
@@ -61,29 +17,26 @@ function resolveWithdrawInputs(params, now) {
|
|
|
61
17
|
* The share-allowance quote uses `DEFAULT_SLIPPAGE_TOLERANCE` internally. The withdrawal has no
|
|
62
18
|
* on-chain share-price or max-shares bound and accepts no slippage tolerance input.
|
|
63
19
|
* @param client - Viem client for `params.chainId`, used for allowance and nonce reads only.
|
|
64
|
-
* @param params.vault -
|
|
65
|
-
* @param params.vaultData - Caller-fetched `AccrualVaultV2` snapshot of `vault`, used to derive the required share allowance.
|
|
20
|
+
* @param params.vault - Caller-fetched AccrualVaultV2 snapshot used for the quote; the address is vault.address.
|
|
66
21
|
* @param params.chainId - Chain containing the vault and registered VaultBundlesV1 contract.
|
|
67
22
|
* @param params.account - Non-zero account approving or permitting shares and sending the withdrawal.
|
|
68
|
-
* @param params.
|
|
69
|
-
* @param params.referralFee.bps - Optional integer fee in basis points of the gross
|
|
23
|
+
* @param params.assets - Positive gross withdrawal in asset base units, before referral fees.
|
|
24
|
+
* @param params.referralFee.bps - Optional integer fee in basis points of the gross assets; defaults to zero and must be below 10,000.
|
|
70
25
|
* @param params.referralFee.recipient - Recipient of the optional fee; must be non-zero when the fee is positive.
|
|
71
26
|
* @param params.supportSignature - Optional unlimited share-permit preference, defaulting to `false`; otherwise uses unlimited direct share approval when allowance is insufficient.
|
|
72
27
|
* @param params.now - Reference timestamp in seconds, normally the latest block's `timestamp`; uses the device clock when omitted.
|
|
73
28
|
* @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).
|
|
74
29
|
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to each built transaction's calldata.
|
|
75
|
-
* @param params.deployless - Optional shared intent field; unused by withdrawal share-permit reads.
|
|
76
30
|
* @returns A plan with the withdrawal step and any required share approval or signature request.
|
|
77
31
|
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
78
32
|
* @throws {NonIntegerInputError} when `expiresAt` or `referralFee.bps` is not a safe integer.
|
|
79
|
-
* @throws {NonPositiveInputError} when `expiresAt`, `
|
|
33
|
+
* @throws {NonPositiveInputError} when `expiresAt`, `assets` or the computed required shares are not positive.
|
|
80
34
|
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now` (device clock when `now` is omitted).
|
|
81
35
|
* @throws {NegativeInputError} when `referralFee.bps` is negative.
|
|
82
|
-
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `
|
|
36
|
+
* @throws {InputExceedsMaxError} when `referralFee.bps` exceeds 10,000 or `assets` exceeds uint256.
|
|
83
37
|
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
84
38
|
* @throws {ReferralFeePctExceededError} when `referralFee.bps` equals 10,000; the normalized fee must be below WAD.
|
|
85
39
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient or a zero recipient.
|
|
86
|
-
* @throws {VaultAddressMismatchError} when `vaultData` describes another vault.
|
|
87
40
|
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
88
41
|
* @throws {MissingContractCodeError} when the VaultBundlesV1 contract is absent.
|
|
89
42
|
* @see computeVaultMaxShareAllowance for quote errors.
|
|
@@ -97,84 +50,19 @@ function resolveWithdrawInputs(params, now) {
|
|
|
97
50
|
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
98
51
|
* const vault = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
99
52
|
* const plan = await prepareVaultV2Withdraw(client, {
|
|
100
|
-
*
|
|
101
|
-
*
|
|
53
|
+
* chainId: 1, account: "0x0000000000000000000000000000000000000001", assets: 1_000_000n, supportSignature: true,
|
|
54
|
+
* vault: await fetchAccrualVaultV2(vault, client),
|
|
102
55
|
* now: (await client.getBlock()).timestamp,
|
|
103
56
|
* });
|
|
104
57
|
* // Sign the pending requests, verify and attach with applySignatures, then build.
|
|
105
58
|
* ```
|
|
106
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
107
59
|
*/
|
|
108
60
|
async function prepareVaultV2Withdraw(client, params) {
|
|
109
|
-
|
|
110
|
-
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
111
|
-
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
112
|
-
const spender = (0, morpho_ts_1.getChainAddress)(chainId, "bundles.vaultBundlesV1");
|
|
113
|
-
const [, , requirements] = await Promise.all([
|
|
114
|
-
(0, validateClientChainId_js_1.validateClientChainId)(client, chainId),
|
|
115
|
-
(0, assertContractCode_js_1.assertRegistryTargetsHaveCode)(client, chainId, [
|
|
116
|
-
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
117
|
-
]),
|
|
118
|
-
(0, getVaultBundlesSharesRequirements_js_1.getVaultBundlesSharesRequirements)(client, {
|
|
119
|
-
vaultData: new blue_sdk_1.Token({ address: vault }),
|
|
120
|
-
version: "vaultV2",
|
|
121
|
-
owner: account,
|
|
122
|
-
chainId,
|
|
123
|
-
requiredShareAllowance,
|
|
124
|
-
deadline: intent.deadline,
|
|
125
|
-
supportSignature: intent.supportSignature,
|
|
126
|
-
now,
|
|
127
|
-
}),
|
|
128
|
-
]);
|
|
129
|
-
const approvals = [];
|
|
130
|
-
const signatureRequests = [];
|
|
131
|
-
const tokenPermitRequestId = "vaultV2Withdraw:tokenPermit";
|
|
132
|
-
const requirement = requirements[0];
|
|
133
|
-
if (requirement !== undefined) {
|
|
134
|
-
if ("sign" in requirement) {
|
|
135
|
-
signatureRequests.push((0, requirements_js_1.buildPermitSignatureRequest)(requirement, tokenPermitRequestId));
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
approvals.push((0, requirements_js_1.buildApprovalStep)(requirement, {
|
|
139
|
-
id: "vaultV2Withdraw:approval",
|
|
140
|
-
chainId,
|
|
141
|
-
account,
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
146
|
-
version: 1,
|
|
147
|
-
account,
|
|
148
|
-
chainId,
|
|
149
|
-
expiresAt: intent.expiresAt,
|
|
150
|
-
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
151
|
-
steps: [
|
|
152
|
-
...approvals,
|
|
153
|
-
{
|
|
154
|
-
id: "vaultV2Withdraw",
|
|
155
|
-
label: "Withdraw from vault",
|
|
156
|
-
action: {
|
|
157
|
-
type: "vaultV2Withdraw",
|
|
158
|
-
inputs: {
|
|
159
|
-
chainId,
|
|
160
|
-
account,
|
|
161
|
-
vault,
|
|
162
|
-
amount,
|
|
163
|
-
requiredShareAllowance,
|
|
164
|
-
...common,
|
|
165
|
-
},
|
|
166
|
-
signatureRequestIds: signatureRequests.length > 0
|
|
167
|
-
? { tokenPermit: tokenPermitRequestId }
|
|
168
|
-
: {},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
signatureRequests,
|
|
173
|
-
}));
|
|
61
|
+
return (0, withdraw_js_2.prepareVaultWithdraw)(client, { ...params, type: "vaultV2Withdraw" });
|
|
174
62
|
}
|
|
175
63
|
/** @internal Encodes the withdrawal from its self-contained inputs and resolved signature requests. */
|
|
176
64
|
function buildVaultV2Withdraw(action, requests) {
|
|
177
|
-
const { requiredShareAllowance, chainId, account, ...args } = action.inputs;
|
|
65
|
+
const { requiredShareAllowance, chainId, account, assets, ...args } = action.inputs;
|
|
178
66
|
const signature = (0, permit_js_1.getVaultPermit)(requests, {
|
|
179
67
|
id: action.signatureRequestIds.tokenPermit,
|
|
180
68
|
asset: action.inputs.vault,
|
|
@@ -187,6 +75,11 @@ function buildVaultV2Withdraw(action, requests) {
|
|
|
187
75
|
});
|
|
188
76
|
return (0, withdraw_js_1.vaultV2Withdraw)({
|
|
189
77
|
vault: { chainId, address: action.inputs.vault },
|
|
190
|
-
args: {
|
|
78
|
+
args: {
|
|
79
|
+
...args,
|
|
80
|
+
amount: assets,
|
|
81
|
+
userAddress: account,
|
|
82
|
+
requirementSignature: permit,
|
|
83
|
+
},
|
|
191
84
|
});
|
|
192
85
|
}
|
|
@@ -4,6 +4,7 @@ exports.validateTransactionPlanVersion = validateTransactionPlanVersion;
|
|
|
4
4
|
const error_js_1 = require("./error.js");
|
|
5
5
|
/** @internal Rejects unsupported plan versions before interpreting stored fields. */
|
|
6
6
|
function validateTransactionPlanVersion(version) {
|
|
7
|
-
if (version !==
|
|
7
|
+
if (version !== 2) {
|
|
8
8
|
throw new error_js_1.UnsupportedTransactionPlanVersionError(version);
|
|
9
|
+
}
|
|
9
10
|
}
|
|
@@ -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,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateWithdrawPlanAction = validateWithdrawPlanAction;
|
|
4
|
+
exports.prepareVaultWithdraw = prepareVaultWithdraw;
|
|
5
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const common_js_1 = require("../actions/bundles/common.js");
|
|
8
|
+
const index_js_1 = require("../helpers/index.js");
|
|
9
|
+
const validate_js_1 = require("../helpers/validate.js");
|
|
10
|
+
const index_js_2 = require("../types/index.js");
|
|
11
|
+
const intent_js_1 = require("./intent.js");
|
|
12
|
+
const shareSpending_js_1 = require("./shareSpending.js");
|
|
13
|
+
const validation_js_1 = require("./validation.js");
|
|
14
|
+
/** @internal Validates the stored vault withdrawal action's input shape. */
|
|
15
|
+
function validateWithdrawPlanAction(action, path) {
|
|
16
|
+
const inputs = (0, validation_js_1.validateVaultPlanAction)(action, path);
|
|
17
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
18
|
+
path: `${path}.inputs`,
|
|
19
|
+
fields: {
|
|
20
|
+
assets: "uint256 bigint",
|
|
21
|
+
requiredShareAllowance: "uint256 bigint",
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function resolveWithdrawInputs(params, now) {
|
|
26
|
+
const { vault, assets } = params;
|
|
27
|
+
const intent = (0, intent_js_1.resolveIntent)(params, now);
|
|
28
|
+
if (assets <= 0n) {
|
|
29
|
+
throw new index_js_2.NonPositiveInputError("assets", assets);
|
|
30
|
+
}
|
|
31
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
32
|
+
(0, validate_js_1.validateUint256Field)("assets", assets);
|
|
33
|
+
const common = (0, common_js_1.normalizeBundlesCommonParams)({
|
|
34
|
+
deadline: intent.deadline,
|
|
35
|
+
referralFeePct: intent.referralFeePct,
|
|
36
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
37
|
+
});
|
|
38
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
39
|
+
const requiredShareAllowance = (0, index_js_1.computeVaultMaxShareAllowance)({
|
|
40
|
+
vaultData: vault,
|
|
41
|
+
deadline: intent.deadline,
|
|
42
|
+
assets,
|
|
43
|
+
slippageTolerance: blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE,
|
|
44
|
+
});
|
|
45
|
+
return { intent, common, requiredShareAllowance };
|
|
46
|
+
}
|
|
47
|
+
/** @internal Fixes a withdrawal quote and resolves the vault-share prerequisites. */
|
|
48
|
+
async function prepareVaultWithdraw(client, params) {
|
|
49
|
+
const { chainId, account, assets } = params;
|
|
50
|
+
const vault = params.vault.address;
|
|
51
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
52
|
+
const { intent, common, requiredShareAllowance } = resolveWithdrawInputs(params, now);
|
|
53
|
+
const { approvals, signatureRequests, tokenPermitRequestId } = await (0, shareSpending_js_1.getVaultShareSpendingRequirements)(client, {
|
|
54
|
+
type: params.type,
|
|
55
|
+
shareToken: params.type === "vaultV1Withdraw"
|
|
56
|
+
? params.vault
|
|
57
|
+
: new blue_sdk_1.Token({ address: vault }),
|
|
58
|
+
chainId,
|
|
59
|
+
account,
|
|
60
|
+
requiredShareAllowance,
|
|
61
|
+
deadline: intent.deadline,
|
|
62
|
+
supportSignature: intent.supportSignature,
|
|
63
|
+
now,
|
|
64
|
+
});
|
|
65
|
+
return (0, morpho_ts_1.deepFreeze)(structuredClone({
|
|
66
|
+
version: 2,
|
|
67
|
+
account,
|
|
68
|
+
chainId,
|
|
69
|
+
expiresAt: intent.expiresAt,
|
|
70
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
71
|
+
steps: [
|
|
72
|
+
...approvals,
|
|
73
|
+
{
|
|
74
|
+
id: params.type,
|
|
75
|
+
label: "Withdraw from vault",
|
|
76
|
+
action: {
|
|
77
|
+
type: params.type,
|
|
78
|
+
inputs: {
|
|
79
|
+
chainId,
|
|
80
|
+
account,
|
|
81
|
+
vault,
|
|
82
|
+
assets,
|
|
83
|
+
requiredShareAllowance,
|
|
84
|
+
...common,
|
|
85
|
+
},
|
|
86
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
87
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
88
|
+
: {},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
signatureRequests,
|
|
93
|
+
}));
|
|
94
|
+
}
|
package/lib/cjs/types/action.js
CHANGED
|
@@ -218,28 +218,36 @@ function isAuthorizationSignature(signature) {
|
|
|
218
218
|
* ```
|
|
219
219
|
*/
|
|
220
220
|
function selectRequirementSignatures(signatures, accepts) {
|
|
221
|
-
if (signatures == null)
|
|
221
|
+
if (signatures == null) {
|
|
222
222
|
return {};
|
|
223
|
+
}
|
|
223
224
|
const permits = signatures.filter(isPermitSignature);
|
|
224
225
|
const permit2Transfers = signatures.filter(isPermit2SignatureTransferSignature);
|
|
225
226
|
const authorizations = signatures.filter(isAuthorizationSignature);
|
|
226
227
|
const unsupported = signatures.find((signature) => !isPermitSignature(signature) &&
|
|
227
228
|
!isPermit2SignatureTransferSignature(signature) &&
|
|
228
229
|
!isAuthorizationSignature(signature));
|
|
229
|
-
if (unsupported != null)
|
|
230
|
+
if (unsupported != null) {
|
|
230
231
|
throw new error_js_1.UnsupportedRequirementSignatureError(unsupported.action.type);
|
|
231
|
-
|
|
232
|
+
}
|
|
233
|
+
if (!accepts.permit && permits.length > 0) {
|
|
232
234
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit");
|
|
233
|
-
|
|
235
|
+
}
|
|
236
|
+
if (!accepts.permit2SignatureTransfer && permit2Transfers.length > 0) {
|
|
234
237
|
throw new error_js_1.UnexpectedRequirementSignatureError("permit2SignatureTransfer");
|
|
235
|
-
|
|
238
|
+
}
|
|
239
|
+
if (!accepts.authorization && authorizations.length > 0) {
|
|
236
240
|
throw new error_js_1.UnexpectedRequirementSignatureError("authorization");
|
|
237
|
-
|
|
241
|
+
}
|
|
242
|
+
if (permits.length > 1) {
|
|
238
243
|
throw new error_js_1.AmbiguousRequirementSignaturesError("permit", permits.length);
|
|
239
|
-
|
|
244
|
+
}
|
|
245
|
+
if (permit2Transfers.length > 1) {
|
|
240
246
|
throw new error_js_1.AmbiguousRequirementSignaturesError("permit2SignatureTransfer", permit2Transfers.length);
|
|
241
|
-
|
|
247
|
+
}
|
|
248
|
+
if (authorizations.length > 1) {
|
|
242
249
|
throw new error_js_1.AmbiguousRequirementSignaturesError("authorization", authorizations.length);
|
|
250
|
+
}
|
|
243
251
|
return {
|
|
244
252
|
permit: permits[0],
|
|
245
253
|
permit2SignatureTransfer: permit2Transfers[0],
|
package/lib/cjs/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/cjs/types/error.js
CHANGED
|
@@ -896,7 +896,10 @@ class ChainIdMismatchError extends Error {
|
|
|
896
896
|
}
|
|
897
897
|
}
|
|
898
898
|
exports.ChainIdMismatchError = ChainIdMismatchError;
|
|
899
|
-
/**
|
|
899
|
+
/**
|
|
900
|
+
* Thrown when a runtime crypto API is required but unavailable.
|
|
901
|
+
* @deprecated This error is never thrown by the SDK and will be removed in the next major version.
|
|
902
|
+
*/
|
|
900
903
|
class CryptoUnavailableError extends Error {
|
|
901
904
|
constructor(feature) {
|
|
902
905
|
super(`Crypto API is required for ${feature} but is unavailable.`);
|
|
@@ -1007,9 +1010,15 @@ class ChainWNativeMissingError extends Error {
|
|
|
1007
1010
|
exports.ChainWNativeMissingError = ChainWNativeMissingError;
|
|
1008
1011
|
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
1009
1012
|
class VaultAddressMismatchError extends Error {
|
|
1013
|
+
/** Vault targeted by the caller. */
|
|
1014
|
+
expected;
|
|
1015
|
+
/** Vault address found in the supplied snapshot. */
|
|
1016
|
+
actual;
|
|
1010
1017
|
constructor(vaultAddress, argsVaultAddress) {
|
|
1011
1018
|
super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
|
|
1012
1019
|
this.name = "VaultAddressMismatchError";
|
|
1020
|
+
this.expected = vaultAddress;
|
|
1021
|
+
this.actual = argsVaultAddress;
|
|
1013
1022
|
}
|
|
1014
1023
|
}
|
|
1015
1024
|
exports.VaultAddressMismatchError = VaultAddressMismatchError;
|
package/lib/cjs/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/cjs/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.
|
|
4
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.
|
|
3
|
+
exports.createHasValue = exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
|
|
4
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
|
|
7
7
|
Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "BlueSharesMath", { enumerable: true, get: functi
|
|
|
15
15
|
Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultUtils; } });
|
|
16
16
|
Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfigUtils; } });
|
|
17
17
|
Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils; } });
|
|
18
|
-
Object.defineProperty(exports, "VaultV2MidnightAdapterUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapterUtils; } });
|
|
19
18
|
Object.defineProperty(exports, "VaultV2Utils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Utils; } });
|
|
20
19
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
21
20
|
Object.defineProperty(exports, "catchRevertOnly", { enumerable: true, get: function () { return blue_sdk_viem_1.catchRevertOnly; } });
|
|
@@ -77,7 +76,6 @@ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function ()
|
|
|
77
76
|
Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return morpho_ts_1.isNotNull; } });
|
|
78
77
|
Object.defineProperty(exports, "isNotUndefined", { enumerable: true, get: function () { return morpho_ts_1.isNotUndefined; } });
|
|
79
78
|
Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return morpho_ts_1.keys; } });
|
|
80
|
-
Object.defineProperty(exports, "MidnightPositionLib", { enumerable: true, get: function () { return morpho_ts_1.MidnightPositionLib; } });
|
|
81
79
|
Object.defineProperty(exports, "mergeEntries", { enumerable: true, get: function () { return morpho_ts_1.mergeEntries; } });
|
|
82
80
|
Object.defineProperty(exports, "retryPromiseLinearBackoff", { enumerable: true, get: function () { return morpho_ts_1.retryPromiseLinearBackoff; } });
|
|
83
81
|
Object.defineProperty(exports, "Time", { enumerable: true, get: function () { return morpho_ts_1.Time; } });
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/morpho-sdk package version. */
|
|
2
|
-
export declare const version = "10.0.0
|
|
2
|
+
export declare const version = "10.0.0";
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/abis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
package/lib/esm/abis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
@@ -25,8 +25,9 @@ export const validateBlueBundlesV1NativeFunding = (params) => {
|
|
|
25
25
|
if (nativeAmount < 0n) {
|
|
26
26
|
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
27
27
|
}
|
|
28
|
-
if (nativeAmount === 0n)
|
|
28
|
+
if (nativeAmount === 0n) {
|
|
29
29
|
return 0n;
|
|
30
|
+
}
|
|
30
31
|
validateNativeAsset(params.chainId, params.token);
|
|
31
32
|
if (nativeAmount !== params.fundedAmount) {
|
|
32
33
|
throw new NativeFundingAmountMismatchError(nativeAmount, params.fundedAmount);
|
|
@@ -49,8 +50,9 @@ export const getBlueBundlesV1TokenPermit = (params) => {
|
|
|
49
50
|
/** @internal */
|
|
50
51
|
export const getBlueBundlesV1SignedAuthorization = (params) => {
|
|
51
52
|
const { authorizationSignature } = params;
|
|
52
|
-
if (authorizationSignature == null)
|
|
53
|
+
if (authorizationSignature == null) {
|
|
53
54
|
return EMPTY_SIGNED_AUTHORIZATION;
|
|
55
|
+
}
|
|
54
56
|
const authorized = getChainAddress(params.chainId, "bundles.blueBundlesV1");
|
|
55
57
|
if (!isAddressEqual(authorizationSignature.args.owner, params.userAddress)) {
|
|
56
58
|
throw new DepositOwnerMismatchError(params.userAddress, authorizationSignature.args.owner);
|
|
@@ -46,8 +46,9 @@ export const blueWithdrawBuyCallback = (params) => {
|
|
|
46
46
|
const { callbackAddress, userAddress, shares } = params.args;
|
|
47
47
|
validateMarketParamsId(marketParams);
|
|
48
48
|
validateUint256Field("shares", shares);
|
|
49
|
-
if (shares === 0n)
|
|
49
|
+
if (shares === 0n) {
|
|
50
50
|
throw new NonPositiveInputError("shares", shares);
|
|
51
|
+
}
|
|
51
52
|
let tx = {
|
|
52
53
|
to: getChainAddress(chainId, "blue"),
|
|
53
54
|
value: 0n,
|
|
@@ -62,10 +62,10 @@ export const resolveBundlesFunding = (params) => {
|
|
|
62
62
|
}
|
|
63
63
|
const assets = amount ?? nativeAmount ?? 0n;
|
|
64
64
|
if (assets < 0n) {
|
|
65
|
-
throw new NegativeInputError(amount
|
|
65
|
+
throw new NegativeInputError(amount == null ? "nativeAmount" : "amount", assets);
|
|
66
66
|
}
|
|
67
67
|
if (assets === 0n) {
|
|
68
|
-
throw new NonPositiveInputError(amount
|
|
68
|
+
throw new NonPositiveInputError(amount == null ? "nativeAmount" : "amount", assets);
|
|
69
69
|
}
|
|
70
70
|
return { assets, value: nativeAmount ?? 0n };
|
|
71
71
|
};
|
|
@@ -102,11 +102,13 @@ export const resolveBundlesFunding = (params) => {
|
|
|
102
102
|
*/
|
|
103
103
|
export const getBundlesTokenPermit = (params) => {
|
|
104
104
|
const { requirementSignature } = params;
|
|
105
|
-
if (requirementSignature == null)
|
|
105
|
+
if (requirementSignature == null) {
|
|
106
106
|
return { ...EMPTY_TOKEN_PERMIT };
|
|
107
|
+
}
|
|
107
108
|
const { type } = requirementSignature.action;
|
|
108
|
-
if (type !== "permit" && type !== "permit2SignatureTransfer")
|
|
109
|
+
if (type !== "permit" && type !== "permit2SignatureTransfer") {
|
|
109
110
|
throw new UnsupportedRequirementSignatureError(type);
|
|
111
|
+
}
|
|
110
112
|
if (!isAddressEqual(requirementSignature.args.owner, params.userAddress)) {
|
|
111
113
|
throw new DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
|
|
112
114
|
}
|
|
@@ -354,10 +356,12 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
354
356
|
* from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
|
|
355
357
|
*/
|
|
356
358
|
export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
|
|
357
|
-
if (signatures == null)
|
|
359
|
+
if (signatures == null) {
|
|
358
360
|
return undefined;
|
|
359
|
-
|
|
361
|
+
}
|
|
362
|
+
if (signatures.length === 0) {
|
|
360
363
|
return undefined;
|
|
364
|
+
}
|
|
361
365
|
const selected = signatures.filter((signature) => signature.action.type === "permit" ||
|
|
362
366
|
signature.action.type === "permit2SignatureTransfer");
|
|
363
367
|
if (selected.length !== signatures.length) {
|
|
@@ -369,8 +373,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
369
373
|
throw new AmbiguousRequirementSignaturesError("permit", selected.length);
|
|
370
374
|
}
|
|
371
375
|
const selectedSignature = selected[0];
|
|
372
|
-
if (selectedSignature == null)
|
|
376
|
+
if (selectedSignature == null) {
|
|
373
377
|
return undefined;
|
|
378
|
+
}
|
|
374
379
|
const { action } = selectedSignature;
|
|
375
380
|
if (!isAddressEqual(action.args.spender, expected.spender)) {
|
|
376
381
|
throw new BundlesPermitMismatchError({
|
|
@@ -379,9 +384,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
379
384
|
actual: action.args.spender,
|
|
380
385
|
});
|
|
381
386
|
}
|
|
382
|
-
const actualAmount = selectedSignature.args.amount
|
|
383
|
-
?
|
|
384
|
-
:
|
|
387
|
+
const actualAmount = selectedSignature.args.amount === expected.amount
|
|
388
|
+
? action.args.amount
|
|
389
|
+
: selectedSignature.args.amount;
|
|
385
390
|
if (actualAmount !== expected.amount) {
|
|
386
391
|
throw new BundlesPermitMismatchError({
|
|
387
392
|
field: "amount",
|
|
@@ -389,9 +394,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
389
394
|
actual: String(actualAmount),
|
|
390
395
|
});
|
|
391
396
|
}
|
|
392
|
-
const actualDeadline = selectedSignature.args.deadline
|
|
393
|
-
?
|
|
394
|
-
:
|
|
397
|
+
const actualDeadline = selectedSignature.args.deadline === expected.deadline
|
|
398
|
+
? action.args.deadline
|
|
399
|
+
: selectedSignature.args.deadline;
|
|
395
400
|
if (actualDeadline !== expected.deadline) {
|
|
396
401
|
throw new BundlesPermitMismatchError({
|
|
397
402
|
field: "deadline",
|
|
@@ -427,8 +432,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
427
432
|
*/
|
|
428
433
|
export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
429
434
|
const { permit } = selectRequirementSignatures(signatures, { permit: true });
|
|
430
|
-
if (permit == null)
|
|
435
|
+
if (permit == null) {
|
|
431
436
|
return undefined;
|
|
437
|
+
}
|
|
432
438
|
const { action } = permit;
|
|
433
439
|
if (action.type !== "permit") {
|
|
434
440
|
throw new BundlesPermitMismatchError({
|