@morpho-org/morpho-sdk 1.1.0 → 1.2.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/LICENSE +2 -2
- package/README.md +31 -33
- package/lib/cjs/actions/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/index.js +4 -4
- package/lib/cjs/actions/marketV1/borrow.d.ts +69 -0
- package/lib/cjs/actions/marketV1/borrow.js +97 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/cjs/actions/marketV1/buildReallocationActions.js +47 -0
- package/lib/cjs/actions/marketV1/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/marketV1/index.js +6 -6
- package/lib/cjs/actions/marketV1/repay.d.ts +89 -0
- package/lib/cjs/actions/marketV1/repay.js +134 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +155 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/cjs/actions/marketV1/supplyCollateral.js +116 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +163 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/cjs/actions/marketV1/withdrawCollateral.js +72 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Approval.js +25 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +108 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/{actions → cjs/actions}/requirements/encode/encodeErc20Permit2.js +36 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +3 -0
- package/lib/{actions → cjs/actions}/requirements/encode/index.js +3 -3
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/cjs/actions/requirements/getMorphoAuthorizationRequirement.js +71 -0
- package/lib/cjs/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/cjs/actions/requirements/getRequirements.js +112 -0
- package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/{actions → cjs/actions}/requirements/getRequirementsAction.js +20 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit.js +57 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/cjs/actions/requirements/getRequirementsPermit2.js +85 -0
- package/lib/cjs/actions/requirements/index.d.ts +6 -0
- package/lib/{actions → cjs/actions}/requirements/index.js +6 -6
- package/lib/cjs/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV1/deposit.js +146 -0
- package/lib/cjs/actions/vaultV1/index.d.ts +4 -0
- package/lib/{actions → cjs/actions}/vaultV1/index.js +4 -4
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +143 -0
- package/lib/cjs/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/redeem.js +57 -0
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/cjs/actions/vaultV1/withdraw.js +57 -0
- package/lib/cjs/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/cjs/actions/vaultV2/deposit.js +146 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/cjs/actions/vaultV2/forceRedeem.js +99 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +94 -0
- package/lib/cjs/actions/vaultV2/index.d.ts +5 -0
- package/lib/{actions → cjs/actions}/vaultV2/index.js +5 -5
- package/lib/cjs/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/redeem.js +58 -0
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/cjs/actions/vaultV2/withdraw.js +58 -0
- package/lib/cjs/client/index.d.ts +2 -0
- package/lib/{client → cjs/client}/index.js +2 -2
- package/lib/cjs/client/morphoClient.d.ts +113 -0
- package/lib/cjs/client/morphoClient.js +123 -0
- package/lib/cjs/client/morphoViemExtension.d.ts +45 -0
- package/lib/cjs/client/morphoViemExtension.js +46 -0
- package/lib/cjs/entities/index.d.ts +3 -0
- package/lib/{entities → cjs/entities}/index.js +3 -3
- package/lib/cjs/entities/marketV1/index.d.ts +1 -0
- package/lib/{entities/vaultV1 → cjs/entities/marketV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/marketV1/marketV1.d.ts +9 -6
- package/lib/{entities → cjs/entities}/marketV1/marketV1.js +89 -87
- package/lib/cjs/entities/vaultV1/index.d.ts +1 -0
- package/lib/{entities/marketV1 → cjs/entities/vaultV1}/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.d.ts +4 -8
- package/lib/{entities → cjs/entities}/vaultV1/vaultV1.js +39 -35
- package/lib/cjs/entities/vaultV2/index.d.ts +1 -0
- package/lib/{entities → cjs/entities}/vaultV2/index.js +1 -1
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.d.ts +2 -2
- package/lib/{entities → cjs/entities}/vaultV2/vaultV2.js +25 -24
- package/lib/{helpers → cjs/helpers}/computeReallocations.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/computeReallocations.js +2 -2
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/encodeDeallocation.js +2 -2
- package/lib/{helpers → cjs/helpers}/index.d.ts +4 -4
- package/lib/{helpers → cjs/helpers}/index.js +19 -19
- package/lib/{helpers → cjs/helpers}/metadata.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/slippage.js +7 -7
- package/lib/{helpers → cjs/helpers}/validate.d.ts +1 -1
- package/lib/{helpers → cjs/helpers}/validate.js +33 -33
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{types → cjs/types}/action.d.ts +1 -1
- package/lib/{types → cjs/types}/client.d.ts +6 -2
- package/lib/{types → cjs/types}/error.d.ts +46 -0
- package/lib/{types → cjs/types}/error.js +46 -0
- package/lib/cjs/types/index.d.ts +7 -0
- package/lib/cjs/types/index.js +23 -0
- package/lib/esm/actions/index.d.ts +4 -0
- package/lib/esm/actions/index.js +4 -0
- package/lib/esm/actions/marketV1/borrow.d.ts +69 -0
- package/lib/esm/actions/marketV1/borrow.js +93 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +28 -0
- package/lib/esm/actions/marketV1/buildReallocationActions.js +43 -0
- package/lib/esm/actions/marketV1/index.d.ts +6 -0
- package/lib/esm/actions/marketV1/index.js +6 -0
- package/lib/esm/actions/marketV1/repay.d.ts +89 -0
- package/lib/esm/actions/marketV1/repay.js +130 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +103 -0
- package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +151 -0
- package/lib/esm/actions/marketV1/supplyCollateral.d.ts +59 -0
- package/lib/esm/actions/marketV1/supplyCollateral.js +112 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +91 -0
- package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +159 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.d.ts +49 -0
- package/lib/esm/actions/marketV1/withdrawCollateral.js +68 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +36 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +46 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +52 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +104 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.d.ts +44 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2.js +98 -0
- package/lib/esm/actions/requirements/encode/index.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/index.js +3 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.d.ts +37 -0
- package/lib/esm/actions/requirements/getMorphoAuthorizationRequirement.js +67 -0
- package/lib/esm/actions/requirements/getRequirements.d.ts +74 -0
- package/lib/esm/actions/requirements/getRequirements.js +108 -0
- package/lib/esm/actions/requirements/getRequirementsAction.d.ts +33 -0
- package/lib/esm/actions/requirements/getRequirementsAction.js +76 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +43 -0
- package/lib/esm/actions/requirements/getRequirementsApproval.js +59 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.d.ts +45 -0
- package/lib/esm/actions/requirements/getRequirementsPermit.js +53 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.d.ts +63 -0
- package/lib/esm/actions/requirements/getRequirementsPermit2.js +81 -0
- package/lib/esm/actions/requirements/index.d.ts +6 -0
- package/lib/esm/actions/requirements/index.js +6 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV1/deposit.js +142 -0
- package/lib/esm/actions/vaultV1/index.d.ts +4 -0
- package/lib/esm/actions/vaultV1/index.js +4 -0
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +84 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +139 -0
- package/lib/esm/actions/vaultV1/redeem.d.ts +39 -0
- package/lib/esm/actions/vaultV1/redeem.js +53 -0
- package/lib/esm/actions/vaultV1/withdraw.d.ts +39 -0
- package/lib/esm/actions/vaultV1/withdraw.js +53 -0
- package/lib/esm/actions/vaultV2/deposit.d.ts +72 -0
- package/lib/esm/actions/vaultV2/deposit.js +142 -0
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +63 -0
- package/lib/esm/actions/vaultV2/forceRedeem.js +95 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +58 -0
- package/lib/esm/actions/vaultV2/forceWithdraw.js +90 -0
- package/lib/esm/actions/vaultV2/index.d.ts +5 -0
- package/lib/esm/actions/vaultV2/index.js +5 -0
- package/lib/esm/actions/vaultV2/redeem.d.ts +40 -0
- package/lib/esm/actions/vaultV2/redeem.js +54 -0
- package/lib/esm/actions/vaultV2/withdraw.d.ts +40 -0
- package/lib/esm/actions/vaultV2/withdraw.js +54 -0
- package/lib/esm/client/index.d.ts +2 -0
- package/lib/esm/client/index.js +2 -0
- package/lib/esm/client/morphoClient.d.ts +113 -0
- package/lib/esm/client/morphoClient.js +119 -0
- package/lib/esm/client/morphoViemExtension.d.ts +45 -0
- package/lib/esm/client/morphoViemExtension.js +43 -0
- package/lib/esm/entities/index.d.ts +3 -0
- package/lib/esm/entities/index.js +3 -0
- package/lib/esm/entities/marketV1/index.d.ts +1 -0
- package/lib/esm/entities/marketV1/index.js +1 -0
- package/lib/esm/entities/marketV1/marketV1.d.ts +293 -0
- package/lib/esm/entities/marketV1/marketV1.js +529 -0
- package/lib/esm/entities/vaultV1/index.d.ts +1 -0
- package/lib/esm/entities/vaultV1/index.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +129 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +186 -0
- package/lib/esm/entities/vaultV2/index.d.ts +1 -0
- package/lib/esm/entities/vaultV2/index.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +180 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +164 -0
- package/lib/esm/helpers/computeReallocations.d.ts +23 -0
- package/lib/esm/helpers/computeReallocations.js +94 -0
- package/lib/esm/helpers/constant.d.ts +6 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +10 -0
- package/lib/esm/helpers/encodeDeallocation.js +34 -0
- package/lib/esm/helpers/index.d.ts +4 -0
- package/lib/esm/helpers/index.js +4 -0
- package/lib/esm/helpers/metadata.d.ts +33 -0
- package/lib/esm/helpers/metadata.js +46 -0
- package/lib/esm/helpers/slippage.d.ts +46 -0
- package/lib/esm/helpers/slippage.js +69 -0
- package/lib/esm/helpers/validate.d.ts +156 -0
- package/lib/esm/helpers/validate.js +273 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/types/action.d.ts +216 -0
- package/lib/esm/types/action.js +21 -0
- package/lib/esm/types/client.d.ts +19 -0
- package/lib/esm/types/client.js +1 -0
- package/lib/esm/types/data.d.ts +2 -0
- package/lib/esm/types/data.js +1 -0
- package/lib/esm/types/deallocation.d.ts +15 -0
- package/lib/esm/types/deallocation.js +1 -0
- package/lib/esm/types/entity.d.ts +5 -0
- package/lib/esm/types/entity.js +1 -0
- package/lib/esm/types/error.d.ts +205 -0
- package/lib/esm/types/error.js +276 -0
- package/lib/esm/types/index.d.ts +7 -0
- package/lib/esm/types/index.js +7 -0
- package/lib/esm/types/metadata.d.ts +4 -0
- package/lib/esm/types/metadata.js +1 -0
- package/lib/esm/types/sharedLiquidity.d.ts +41 -0
- package/lib/esm/types/sharedLiquidity.js +1 -0
- package/package.json +29 -54
- package/src/index.ts +5 -0
- package/lib/actions/index.d.ts +0 -4
- package/lib/actions/marketV1/borrow.d.ts +0 -34
- package/lib/actions/marketV1/borrow.js +0 -62
- package/lib/actions/marketV1/buildReallocationActions.d.ts +0 -17
- package/lib/actions/marketV1/buildReallocationActions.js +0 -36
- package/lib/actions/marketV1/index.d.ts +0 -6
- package/lib/actions/marketV1/repay.d.ts +0 -44
- package/lib/actions/marketV1/repay.js +0 -93
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +0 -51
- package/lib/actions/marketV1/repayWithdrawCollateral.js +0 -108
- package/lib/actions/marketV1/supplyCollateral.d.ts +0 -28
- package/lib/actions/marketV1/supplyCollateral.js +0 -85
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +0 -37
- package/lib/actions/marketV1/supplyCollateralBorrow.js +0 -109
- package/lib/actions/marketV1/withdrawCollateral.d.ts +0 -28
- package/lib/actions/marketV1/withdrawCollateral.js +0 -51
- package/lib/actions/requirements/encode/encodeErc20Approval.d.ts +0 -10
- package/lib/actions/requirements/encode/encodeErc20Permit.d.ts +0 -13
- package/lib/actions/requirements/encode/encodeErc20Permit.js +0 -70
- package/lib/actions/requirements/encode/encodeErc20Permit2.d.ts +0 -11
- package/lib/actions/requirements/encode/index.d.ts +0 -3
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +0 -21
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +0 -55
- package/lib/actions/requirements/getRequirements.d.ts +0 -42
- package/lib/actions/requirements/getRequirements.js +0 -80
- package/lib/actions/requirements/getRequirementsAction.d.ts +0 -17
- package/lib/actions/requirements/getRequirementsApproval.d.ts +0 -31
- package/lib/actions/requirements/getRequirementsApproval.js +0 -51
- package/lib/actions/requirements/getRequirementsPermit.d.ts +0 -28
- package/lib/actions/requirements/getRequirementsPermit.js +0 -40
- package/lib/actions/requirements/getRequirementsPermit2.d.ts +0 -37
- package/lib/actions/requirements/getRequirementsPermit2.js +0 -59
- package/lib/actions/requirements/index.d.ts +0 -6
- package/lib/actions/vaultV1/deposit.d.ts +0 -41
- package/lib/actions/vaultV1/deposit.js +0 -116
- package/lib/actions/vaultV1/index.d.ts +0 -4
- package/lib/actions/vaultV1/migrateToV2.d.ts +0 -50
- package/lib/actions/vaultV1/migrateToV2.js +0 -108
- package/lib/actions/vaultV1/redeem.d.ts +0 -29
- package/lib/actions/vaultV1/redeem.js +0 -48
- package/lib/actions/vaultV1/withdraw.d.ts +0 -29
- package/lib/actions/vaultV1/withdraw.js +0 -48
- package/lib/actions/vaultV2/deposit.d.ts +0 -41
- package/lib/actions/vaultV2/deposit.js +0 -116
- package/lib/actions/vaultV2/forceRedeem.d.ts +0 -48
- package/lib/actions/vaultV2/forceRedeem.js +0 -85
- package/lib/actions/vaultV2/forceWithdraw.d.ts +0 -40
- package/lib/actions/vaultV2/forceWithdraw.js +0 -77
- package/lib/actions/vaultV2/index.d.ts +0 -5
- package/lib/actions/vaultV2/redeem.d.ts +0 -32
- package/lib/actions/vaultV2/redeem.js +0 -51
- package/lib/actions/vaultV2/withdraw.d.ts +0 -32
- package/lib/actions/vaultV2/withdraw.js +0 -51
- package/lib/client/index.d.ts +0 -2
- package/lib/client/morphoClient.d.ts +0 -25
- package/lib/client/morphoClient.js +0 -28
- package/lib/client/morphoViemExtension.d.ts +0 -39
- package/lib/client/morphoViemExtension.js +0 -40
- package/lib/entities/index.d.ts +0 -3
- package/lib/entities/marketV1/index.d.ts +0 -1
- package/lib/entities/vaultV1/index.d.ts +0 -1
- package/lib/entities/vaultV2/index.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -21
- package/lib/types/index.d.ts +0 -7
- package/lib/types/index.js +0 -23
- /package/lib/{helpers → cjs/helpers}/constant.d.ts +0 -0
- /package/lib/{helpers → cjs/helpers}/constant.js +0 -0
- /package/lib/{helpers → cjs/helpers}/metadata.js +0 -0
- /package/lib/{helpers → cjs/helpers}/slippage.d.ts +0 -0
- /package/lib/{types → cjs/types}/action.js +0 -0
- /package/lib/{types → cjs/types}/client.js +0 -0
- /package/lib/{types → cjs/types}/data.d.ts +0 -0
- /package/lib/{types → cjs/types}/data.js +0 -0
- /package/lib/{types → cjs/types}/deallocation.d.ts +0 -0
- /package/lib/{types → cjs/types}/deallocation.js +0 -0
- /package/lib/{types → cjs/types}/entity.d.ts +0 -0
- /package/lib/{types → cjs/types}/entity.js +0 -0
- /package/lib/{types → cjs/types}/metadata.d.ts +0 -0
- /package/lib/{types → cjs/types}/metadata.js +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.d.ts +0 -0
- /package/lib/{types → cjs/types}/sharedLiquidity.js +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultV1Redeem = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Prepares a redeem transaction for a VaultV1 (MetaMorpho) contract.
|
|
11
|
+
*
|
|
12
|
+
* Direct vault call — no bundler needed. Redeem has no inflation-attack surface.
|
|
13
|
+
*
|
|
14
|
+
* @param params.vault.address - The VaultV1 (MetaMorpho) address.
|
|
15
|
+
* @param params.args.shares - Amount of vault shares to redeem.
|
|
16
|
+
* @param params.args.recipient - Address that receives the redeemed assets.
|
|
17
|
+
* @param params.args.onBehalf - Address whose shares are burned.
|
|
18
|
+
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
19
|
+
* @returns A deep-frozen `Transaction<VaultV1RedeemAction>` with `to`, `value`, `data`, and the
|
|
20
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
21
|
+
* @throws {NonPositiveSharesAmountError} when `shares <= 0n`.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { vaultV1Redeem } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const tx = vaultV1Redeem({
|
|
27
|
+
* vault: { address: vaultAddress },
|
|
28
|
+
* args: { shares: 1_000_000n, recipient, onBehalf },
|
|
29
|
+
* });
|
|
30
|
+
* // tx satisfies Readonly<Transaction<VaultV1RedeemAction>>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const vaultV1Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
|
|
34
|
+
if (shares <= 0n) {
|
|
35
|
+
throw new index_js_2.NonPositiveSharesAmountError(vaultAddress);
|
|
36
|
+
}
|
|
37
|
+
let tx = {
|
|
38
|
+
to: vaultAddress,
|
|
39
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
40
|
+
abi: blue_sdk_viem_1.metaMorphoAbi,
|
|
41
|
+
functionName: "redeem",
|
|
42
|
+
args: [shares, recipient, onBehalf],
|
|
43
|
+
}),
|
|
44
|
+
value: 0n,
|
|
45
|
+
};
|
|
46
|
+
if (metadata) {
|
|
47
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
48
|
+
}
|
|
49
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
50
|
+
...tx,
|
|
51
|
+
action: {
|
|
52
|
+
type: "vaultV1Redeem",
|
|
53
|
+
args: { vault: vaultAddress, shares, recipient },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.vaultV1Redeem = vaultV1Redeem;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Metadata, type Transaction, type VaultV1WithdrawAction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for {@link vaultV1Withdraw}. */
|
|
4
|
+
export interface VaultV1WithdrawParams {
|
|
5
|
+
vault: {
|
|
6
|
+
address: Address;
|
|
7
|
+
};
|
|
8
|
+
args: {
|
|
9
|
+
amount: bigint;
|
|
10
|
+
recipient: Address;
|
|
11
|
+
onBehalf: Address;
|
|
12
|
+
};
|
|
13
|
+
metadata?: Metadata;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Prepares a withdraw transaction for a VaultV1 (MetaMorpho) contract.
|
|
17
|
+
*
|
|
18
|
+
* Direct vault call — no bundler needed. Withdraw has no inflation-attack surface.
|
|
19
|
+
*
|
|
20
|
+
* @param params.vault.address - The VaultV1 (MetaMorpho) address.
|
|
21
|
+
* @param params.args.amount - Amount of underlying assets to withdraw.
|
|
22
|
+
* @param params.args.recipient - Address that receives the withdrawn assets.
|
|
23
|
+
* @param params.args.onBehalf - Address whose shares are burned.
|
|
24
|
+
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
25
|
+
* @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
|
|
26
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
27
|
+
* @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
31
|
+
*
|
|
32
|
+
* const tx = vaultV1Withdraw({
|
|
33
|
+
* vault: { address: vaultAddress },
|
|
34
|
+
* args: { amount: 500_000n, recipient, onBehalf },
|
|
35
|
+
* });
|
|
36
|
+
* // tx satisfies Readonly<Transaction<VaultV1WithdrawAction>>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const vaultV1Withdraw: ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }: VaultV1WithdrawParams) => Readonly<Transaction<VaultV1WithdrawAction>>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultV1Withdraw = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Prepares a withdraw transaction for a VaultV1 (MetaMorpho) contract.
|
|
11
|
+
*
|
|
12
|
+
* Direct vault call — no bundler needed. Withdraw has no inflation-attack surface.
|
|
13
|
+
*
|
|
14
|
+
* @param params.vault.address - The VaultV1 (MetaMorpho) address.
|
|
15
|
+
* @param params.args.amount - Amount of underlying assets to withdraw.
|
|
16
|
+
* @param params.args.recipient - Address that receives the withdrawn assets.
|
|
17
|
+
* @param params.args.onBehalf - Address whose shares are burned.
|
|
18
|
+
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
19
|
+
* @returns A deep-frozen `Transaction<VaultV1WithdrawAction>` with `to`, `value`, `data`, and the
|
|
20
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
21
|
+
* @throws {NonPositiveAssetAmountError} when `amount <= 0n`.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { vaultV1Withdraw } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const tx = vaultV1Withdraw({
|
|
27
|
+
* vault: { address: vaultAddress },
|
|
28
|
+
* args: { amount: 500_000n, recipient, onBehalf },
|
|
29
|
+
* });
|
|
30
|
+
* // tx satisfies Readonly<Transaction<VaultV1WithdrawAction>>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
const vaultV1Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
|
|
34
|
+
if (amount <= 0n) {
|
|
35
|
+
throw new index_js_2.NonPositiveAssetAmountError(vaultAddress);
|
|
36
|
+
}
|
|
37
|
+
let tx = {
|
|
38
|
+
to: vaultAddress,
|
|
39
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
40
|
+
abi: blue_sdk_viem_1.metaMorphoAbi,
|
|
41
|
+
functionName: "withdraw",
|
|
42
|
+
args: [amount, recipient, onBehalf],
|
|
43
|
+
}),
|
|
44
|
+
value: 0n,
|
|
45
|
+
};
|
|
46
|
+
if (metadata) {
|
|
47
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
48
|
+
}
|
|
49
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
50
|
+
...tx,
|
|
51
|
+
action: {
|
|
52
|
+
type: "vaultV1Withdraw",
|
|
53
|
+
args: { vault: vaultAddress, amount, recipient },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
exports.vaultV1Withdraw = vaultV1Withdraw;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultV2DepositAction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for {@link vaultV2Deposit}. */
|
|
4
|
+
export interface VaultV2DepositParams {
|
|
5
|
+
vault: {
|
|
6
|
+
chainId: number;
|
|
7
|
+
address: Address;
|
|
8
|
+
asset: Address;
|
|
9
|
+
};
|
|
10
|
+
args: DepositAmountArgs & {
|
|
11
|
+
maxSharePrice: bigint;
|
|
12
|
+
recipient: Address;
|
|
13
|
+
requirementSignature?: RequirementSignature;
|
|
14
|
+
};
|
|
15
|
+
metadata?: Metadata;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Prepares a deposit transaction for a VaultV2 contract.
|
|
19
|
+
*
|
|
20
|
+
* Routed through bundler3 to atomically execute the asset transfer and vault deposit. The
|
|
21
|
+
* `GeneralAdapter1` enforces `maxSharePrice` on-chain to prevent inflation attacks. Never bypass
|
|
22
|
+
* the general adapter.
|
|
23
|
+
*
|
|
24
|
+
* When `nativeAmount > 0`, that amount of native ETH is sent as `msg.value` to the bundler3
|
|
25
|
+
* multicall and wrapped into wNative via `GeneralAdapter1.wrapNative()`. The vault's underlying
|
|
26
|
+
* asset must be the chain's wrapped native token.
|
|
27
|
+
*
|
|
28
|
+
* @param params.vault.chainId - The chain the vault lives on.
|
|
29
|
+
* @param params.vault.address - The VaultV2 address.
|
|
30
|
+
* @param params.vault.asset - The vault's underlying ERC-20 asset.
|
|
31
|
+
* @param params.args.amount - Amount of ERC-20 assets to deposit. At least one of `amount` or
|
|
32
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
33
|
+
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
34
|
+
* protection enforced on-chain by `GeneralAdapter1`).
|
|
35
|
+
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
36
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
37
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
38
|
+
* approved `GeneralAdapter1`.
|
|
39
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
40
|
+
* deposit. Requires the vault asset to be the chain's wNative.
|
|
41
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
42
|
+
* @returns A deep-frozen `Transaction<VaultV2DepositAction>` with `to`, `value`, `data`, and the
|
|
43
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
44
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
45
|
+
* @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
46
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
47
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
|
|
48
|
+
* configured wNative.
|
|
49
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
50
|
+
* asset is not the chain's wNative.
|
|
51
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
52
|
+
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
53
|
+
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
54
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
55
|
+
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
56
|
+
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { vaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
60
|
+
*
|
|
61
|
+
* const tx = vaultV2Deposit({
|
|
62
|
+
* vault: { chainId: 1, address: vaultAddress, asset: USDC },
|
|
63
|
+
* args: {
|
|
64
|
+
* amount: 1_000_000n,
|
|
65
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
66
|
+
* recipient: depositor,
|
|
67
|
+
* },
|
|
68
|
+
* });
|
|
69
|
+
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const vaultV2Deposit: ({ vault: { chainId, address: vaultAddress, asset }, args: { amount, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }: VaultV2DepositParams) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultV2Deposit = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const index_js_2 = require("../../types/index.js");
|
|
10
|
+
const getRequirementsAction_js_1 = require("../requirements/getRequirementsAction.js");
|
|
11
|
+
/**
|
|
12
|
+
* Prepares a deposit transaction for a VaultV2 contract.
|
|
13
|
+
*
|
|
14
|
+
* Routed through bundler3 to atomically execute the asset transfer and vault deposit. The
|
|
15
|
+
* `GeneralAdapter1` enforces `maxSharePrice` on-chain to prevent inflation attacks. Never bypass
|
|
16
|
+
* the general adapter.
|
|
17
|
+
*
|
|
18
|
+
* When `nativeAmount > 0`, that amount of native ETH is sent as `msg.value` to the bundler3
|
|
19
|
+
* multicall and wrapped into wNative via `GeneralAdapter1.wrapNative()`. The vault's underlying
|
|
20
|
+
* asset must be the chain's wrapped native token.
|
|
21
|
+
*
|
|
22
|
+
* @param params.vault.chainId - The chain the vault lives on.
|
|
23
|
+
* @param params.vault.address - The VaultV2 address.
|
|
24
|
+
* @param params.vault.asset - The vault's underlying ERC-20 asset.
|
|
25
|
+
* @param params.args.amount - Amount of ERC-20 assets to deposit. At least one of `amount` or
|
|
26
|
+
* `nativeAmount` must be positive. Defaults to `0n`.
|
|
27
|
+
* @param params.args.maxSharePrice - Maximum acceptable share price (in RAY, slippage
|
|
28
|
+
* protection enforced on-chain by `GeneralAdapter1`).
|
|
29
|
+
* @param params.args.recipient - Address that receives the minted vault shares.
|
|
30
|
+
* @param params.args.requirementSignature - Optional pre-signed permit/permit2 approval. When
|
|
31
|
+
* absent, the bundle uses a plain `erc20TransferFrom` and assumes the user has already
|
|
32
|
+
* approved `GeneralAdapter1`.
|
|
33
|
+
* @param params.args.nativeAmount - Optional amount of native token to wrap into wNative for the
|
|
34
|
+
* deposit. Requires the vault asset to be the chain's wNative.
|
|
35
|
+
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
36
|
+
* @returns A deep-frozen `Transaction<VaultV2DepositAction>` with `to`, `value`, `data`, and the
|
|
37
|
+
* typed `action` discriminator the simulation layer consumes.
|
|
38
|
+
* @throws {NonPositiveAssetAmountError} when `amount < 0n`.
|
|
39
|
+
* @throws {NonPositiveMaxSharePriceError} when `maxSharePrice <= 0n`.
|
|
40
|
+
* @throws {NegativeNativeAmountError} when `nativeAmount < 0n`.
|
|
41
|
+
* @throws {ChainWNativeMissingError} when `nativeAmount` is provided but the chain has no
|
|
42
|
+
* configured wNative.
|
|
43
|
+
* @throws {NativeAmountOnNonWNativeVaultError} when `nativeAmount` is provided but the vault
|
|
44
|
+
* asset is not the chain's wNative.
|
|
45
|
+
* @throws {DepositAssetMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
46
|
+
* `requirementSignature` is provided and the signed asset differs from `vault.asset`. The
|
|
47
|
+
* signature is ignored on the native-only path (`amount === 0n` with `nativeAmount > 0n`).
|
|
48
|
+
* @throws {DepositAmountMismatchError} from `getRequirementsAction` when `amount > 0n` and
|
|
49
|
+
* `requirementSignature` is provided and the signed amount differs from `args.amount`.
|
|
50
|
+
* @throws {ZeroDepositAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { vaultV2Deposit } from "@morpho-org/morpho-sdk";
|
|
54
|
+
*
|
|
55
|
+
* const tx = vaultV2Deposit({
|
|
56
|
+
* vault: { chainId: 1, address: vaultAddress, asset: USDC },
|
|
57
|
+
* args: {
|
|
58
|
+
* amount: 1_000_000n,
|
|
59
|
+
* maxSharePrice: 1_010_000_000_000_000_000_000_000_000n, // RAY-scaled, 1.01x
|
|
60
|
+
* recipient: depositor,
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
67
|
+
if (amount < 0n) {
|
|
68
|
+
throw new index_js_2.NonPositiveAssetAmountError(asset);
|
|
69
|
+
}
|
|
70
|
+
if (maxSharePrice <= 0n) {
|
|
71
|
+
throw new index_js_2.NonPositiveMaxSharePriceError(vaultAddress);
|
|
72
|
+
}
|
|
73
|
+
const actions = [];
|
|
74
|
+
const { bundler3: { generalAdapter1, bundler3 }, wNative, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
75
|
+
if (nativeAmount) {
|
|
76
|
+
if (nativeAmount < 0n) {
|
|
77
|
+
throw new index_js_2.NegativeNativeAmountError(nativeAmount);
|
|
78
|
+
}
|
|
79
|
+
if (!(0, morpho_ts_1.isDefined)(wNative)) {
|
|
80
|
+
throw new index_js_2.ChainWNativeMissingError(chainId);
|
|
81
|
+
}
|
|
82
|
+
if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
|
|
83
|
+
throw new index_js_2.NativeAmountOnNonWNativeVaultError(asset, wNative);
|
|
84
|
+
}
|
|
85
|
+
actions.push(
|
|
86
|
+
// Transfers native token from Bundler3 to GeneralAdapter1 for wrapping.
|
|
87
|
+
{
|
|
88
|
+
type: "nativeTransfer",
|
|
89
|
+
args: [bundler3, generalAdapter1, nativeAmount, false /* skipRevert */],
|
|
90
|
+
}, {
|
|
91
|
+
type: "wrapNative",
|
|
92
|
+
args: [nativeAmount, generalAdapter1, false /* skipRevert */],
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (amount > 0n) {
|
|
96
|
+
if (requirementSignature) {
|
|
97
|
+
actions.push(...(0, getRequirementsAction_js_1.getRequirementsAction)({
|
|
98
|
+
chainId,
|
|
99
|
+
asset,
|
|
100
|
+
amount,
|
|
101
|
+
requirementSignature,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
actions.push({
|
|
106
|
+
type: "erc20TransferFrom",
|
|
107
|
+
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
112
|
+
if (totalAssets === 0n) {
|
|
113
|
+
throw new index_js_2.ZeroDepositAmountError(vaultAddress);
|
|
114
|
+
}
|
|
115
|
+
actions.push({
|
|
116
|
+
type: "erc4626Deposit",
|
|
117
|
+
args: [
|
|
118
|
+
vaultAddress,
|
|
119
|
+
totalAssets,
|
|
120
|
+
maxSharePrice,
|
|
121
|
+
recipient,
|
|
122
|
+
false /* skipRevert */,
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
let tx = bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions);
|
|
126
|
+
if (nativeAmount) {
|
|
127
|
+
tx = { ...tx, value: nativeAmount };
|
|
128
|
+
}
|
|
129
|
+
if (metadata) {
|
|
130
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
131
|
+
}
|
|
132
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
133
|
+
...tx,
|
|
134
|
+
action: {
|
|
135
|
+
type: "vaultV2Deposit",
|
|
136
|
+
args: {
|
|
137
|
+
vault: vaultAddress,
|
|
138
|
+
amount,
|
|
139
|
+
maxSharePrice,
|
|
140
|
+
recipient,
|
|
141
|
+
nativeAmount,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
exports.vaultV2Deposit = vaultV2Deposit;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Deallocation, type Metadata, type Transaction, type VaultV2ForceRedeemAction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for {@link vaultV2ForceRedeem}. */
|
|
4
|
+
export interface VaultV2ForceRedeemParams {
|
|
5
|
+
vault: {
|
|
6
|
+
address: Address;
|
|
7
|
+
};
|
|
8
|
+
args: {
|
|
9
|
+
deallocations: readonly Deallocation[];
|
|
10
|
+
redeem: {
|
|
11
|
+
shares: bigint;
|
|
12
|
+
recipient: Address;
|
|
13
|
+
};
|
|
14
|
+
onBehalf: Address;
|
|
15
|
+
};
|
|
16
|
+
metadata?: Metadata;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Prepares a force-redeem transaction for a VaultV2 contract via the vault's native `multicall`.
|
|
20
|
+
*
|
|
21
|
+
* Encodes one or more `forceDeallocate` calls followed by a single `redeem`, executed atomically
|
|
22
|
+
* through VaultV2's `multicall`. Share-based counterpart to {@link vaultV2ForceWithdraw} — use
|
|
23
|
+
* when the user wants to redeem an exact share amount rather than withdraw exact assets.
|
|
24
|
+
*
|
|
25
|
+
* The total assets passed to `forceDeallocate` calls must be greater than or equal to the
|
|
26
|
+
* asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
|
|
27
|
+
* amounts to absorb share-price drift between submission and execution.
|
|
28
|
+
*
|
|
29
|
+
* A penalty is taken from `onBehalf` for each deallocation to discourage allocation
|
|
30
|
+
* manipulation. The penalty is applied as a share burn where assets are returned to the vault,
|
|
31
|
+
* so the share price stays stable (except for rounding).
|
|
32
|
+
*
|
|
33
|
+
* @param params.vault.address - The VaultV2 address.
|
|
34
|
+
* @param params.args.deallocations - The deallocations to perform before redeeming. Must be
|
|
35
|
+
* non-empty.
|
|
36
|
+
* @param params.args.redeem.shares - Amount of vault shares to redeem after the deallocations
|
|
37
|
+
* complete.
|
|
38
|
+
* @param params.args.redeem.recipient - Address that receives the redeemed assets.
|
|
39
|
+
* @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
|
|
40
|
+
* penalty is taken.
|
|
41
|
+
* @param params.metadata - Optional analytics metadata attached to the multicall transaction.
|
|
42
|
+
* @returns A deep-frozen `Transaction<VaultV2ForceRedeemAction>` with `to`, `value`, `data`, and
|
|
43
|
+
* the typed `action` discriminator the simulation layer consumes.
|
|
44
|
+
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
45
|
+
* @throws {NonPositiveSharesAmountError} when `redeem.shares <= 0n`.
|
|
46
|
+
* @throws {NonPositiveAssetAmountError} when any `deallocations[i].amount <= 0n` (raised by
|
|
47
|
+
* `encodeForceDeallocateCall`).
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { vaultV2ForceRedeem } from "@morpho-org/morpho-sdk";
|
|
51
|
+
*
|
|
52
|
+
* const tx = vaultV2ForceRedeem({
|
|
53
|
+
* vault: { address: vaultAddress },
|
|
54
|
+
* args: {
|
|
55
|
+
* deallocations: [{ adapter, marketParams, amount: 1_010_000n }],
|
|
56
|
+
* redeem: { shares: 1_000_000n, recipient },
|
|
57
|
+
* onBehalf,
|
|
58
|
+
* },
|
|
59
|
+
* });
|
|
60
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const vaultV2ForceRedeem: ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, metadata, }: VaultV2ForceRedeemParams) => Readonly<Transaction<VaultV2ForceRedeemAction>>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultV2ForceRedeem = void 0;
|
|
4
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const encodeDeallocation_js_1 = require("../../helpers/encodeDeallocation.js");
|
|
8
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
+
const index_js_2 = require("../../types/index.js");
|
|
10
|
+
/**
|
|
11
|
+
* Prepares a force-redeem transaction for a VaultV2 contract via the vault's native `multicall`.
|
|
12
|
+
*
|
|
13
|
+
* Encodes one or more `forceDeallocate` calls followed by a single `redeem`, executed atomically
|
|
14
|
+
* through VaultV2's `multicall`. Share-based counterpart to {@link vaultV2ForceWithdraw} — use
|
|
15
|
+
* when the user wants to redeem an exact share amount rather than withdraw exact assets.
|
|
16
|
+
*
|
|
17
|
+
* The total assets passed to `forceDeallocate` calls must be greater than or equal to the
|
|
18
|
+
* asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
|
|
19
|
+
* amounts to absorb share-price drift between submission and execution.
|
|
20
|
+
*
|
|
21
|
+
* A penalty is taken from `onBehalf` for each deallocation to discourage allocation
|
|
22
|
+
* manipulation. The penalty is applied as a share burn where assets are returned to the vault,
|
|
23
|
+
* so the share price stays stable (except for rounding).
|
|
24
|
+
*
|
|
25
|
+
* @param params.vault.address - The VaultV2 address.
|
|
26
|
+
* @param params.args.deallocations - The deallocations to perform before redeeming. Must be
|
|
27
|
+
* non-empty.
|
|
28
|
+
* @param params.args.redeem.shares - Amount of vault shares to redeem after the deallocations
|
|
29
|
+
* complete.
|
|
30
|
+
* @param params.args.redeem.recipient - Address that receives the redeemed assets.
|
|
31
|
+
* @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
|
|
32
|
+
* penalty is taken.
|
|
33
|
+
* @param params.metadata - Optional analytics metadata attached to the multicall transaction.
|
|
34
|
+
* @returns A deep-frozen `Transaction<VaultV2ForceRedeemAction>` with `to`, `value`, `data`, and
|
|
35
|
+
* the typed `action` discriminator the simulation layer consumes.
|
|
36
|
+
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
37
|
+
* @throws {NonPositiveSharesAmountError} when `redeem.shares <= 0n`.
|
|
38
|
+
* @throws {NonPositiveAssetAmountError} when any `deallocations[i].amount <= 0n` (raised by
|
|
39
|
+
* `encodeForceDeallocateCall`).
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { vaultV2ForceRedeem } from "@morpho-org/morpho-sdk";
|
|
43
|
+
*
|
|
44
|
+
* const tx = vaultV2ForceRedeem({
|
|
45
|
+
* vault: { address: vaultAddress },
|
|
46
|
+
* args: {
|
|
47
|
+
* deallocations: [{ adapter, marketParams, amount: 1_010_000n }],
|
|
48
|
+
* redeem: { shares: 1_000_000n, recipient },
|
|
49
|
+
* onBehalf,
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceRedeemAction>>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
const vaultV2ForceRedeem = ({ vault: { address: vaultAddress }, args: { deallocations, redeem, onBehalf }, metadata, }) => {
|
|
56
|
+
if (deallocations.length === 0) {
|
|
57
|
+
throw new index_js_2.EmptyDeallocationsError(vaultAddress);
|
|
58
|
+
}
|
|
59
|
+
if (redeem.shares <= 0n) {
|
|
60
|
+
throw new index_js_2.NonPositiveSharesAmountError(vaultAddress);
|
|
61
|
+
}
|
|
62
|
+
const calls = [];
|
|
63
|
+
for (const deallocation of deallocations) {
|
|
64
|
+
calls.push((0, encodeDeallocation_js_1.encodeForceDeallocateCall)(deallocation, onBehalf));
|
|
65
|
+
}
|
|
66
|
+
calls.push((0, viem_1.encodeFunctionData)({
|
|
67
|
+
abi: blue_sdk_viem_1.vaultV2Abi,
|
|
68
|
+
functionName: "redeem",
|
|
69
|
+
args: [redeem.shares, redeem.recipient, onBehalf],
|
|
70
|
+
}));
|
|
71
|
+
let tx = {
|
|
72
|
+
to: vaultAddress,
|
|
73
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
74
|
+
abi: blue_sdk_viem_1.vaultV2Abi,
|
|
75
|
+
functionName: "multicall",
|
|
76
|
+
args: [calls],
|
|
77
|
+
}),
|
|
78
|
+
value: 0n,
|
|
79
|
+
};
|
|
80
|
+
if (metadata) {
|
|
81
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, metadata);
|
|
82
|
+
}
|
|
83
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
84
|
+
...tx,
|
|
85
|
+
action: {
|
|
86
|
+
type: "vaultV2ForceRedeem",
|
|
87
|
+
args: {
|
|
88
|
+
vault: vaultAddress,
|
|
89
|
+
deallocations: deallocations.map((d) => ({ ...d })),
|
|
90
|
+
redeem: {
|
|
91
|
+
shares: redeem.shares,
|
|
92
|
+
recipient: redeem.recipient,
|
|
93
|
+
},
|
|
94
|
+
onBehalf,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.vaultV2ForceRedeem = vaultV2ForceRedeem;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Deallocation, type Metadata, type Transaction, type VaultV2ForceWithdrawAction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for {@link vaultV2ForceWithdraw}. */
|
|
4
|
+
export interface VaultV2ForceWithdrawParams {
|
|
5
|
+
vault: {
|
|
6
|
+
address: Address;
|
|
7
|
+
};
|
|
8
|
+
args: {
|
|
9
|
+
deallocations: readonly Deallocation[];
|
|
10
|
+
withdraw: {
|
|
11
|
+
amount: bigint;
|
|
12
|
+
recipient: Address;
|
|
13
|
+
};
|
|
14
|
+
onBehalf: Address;
|
|
15
|
+
};
|
|
16
|
+
metadata?: Metadata;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Prepares a force-withdraw transaction for a VaultV2 contract via the vault's native `multicall`.
|
|
20
|
+
*
|
|
21
|
+
* Encodes one or more `forceDeallocate` calls followed by a single `withdraw`, executed
|
|
22
|
+
* atomically through VaultV2's `multicall`. Frees liquidity from non-liquidity adapters and
|
|
23
|
+
* withdraws the resulting assets in one transaction.
|
|
24
|
+
*
|
|
25
|
+
* A penalty is taken from `onBehalf` for each deallocation to discourage allocation
|
|
26
|
+
* manipulation. The penalty is applied as a share burn where assets are returned to the vault,
|
|
27
|
+
* so the share price stays stable (except for rounding).
|
|
28
|
+
*
|
|
29
|
+
* @param params.vault.address - The VaultV2 address.
|
|
30
|
+
* @param params.args.deallocations - The deallocations to perform before withdrawing. Must be
|
|
31
|
+
* non-empty.
|
|
32
|
+
* @param params.args.withdraw.amount - Amount of underlying assets to withdraw after the
|
|
33
|
+
* deallocations complete.
|
|
34
|
+
* @param params.args.withdraw.recipient - Address that receives the withdrawn assets.
|
|
35
|
+
* @param params.args.onBehalf - Address whose shares are burned and from which the deallocation
|
|
36
|
+
* penalty is taken.
|
|
37
|
+
* @param params.metadata - Optional analytics metadata attached to the multicall transaction.
|
|
38
|
+
* @returns A deep-frozen `Transaction<VaultV2ForceWithdrawAction>` with `to`, `value`, `data`,
|
|
39
|
+
* and the typed `action` discriminator the simulation layer consumes.
|
|
40
|
+
* @throws {EmptyDeallocationsError} when `deallocations` is empty.
|
|
41
|
+
* @throws {NonPositiveAssetAmountError} when `withdraw.amount <= 0n`, or when any
|
|
42
|
+
* `deallocations[i].amount <= 0n` (raised by `encodeForceDeallocateCall`).
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { vaultV2ForceWithdraw } from "@morpho-org/morpho-sdk";
|
|
46
|
+
*
|
|
47
|
+
* const tx = vaultV2ForceWithdraw({
|
|
48
|
+
* vault: { address: vaultAddress },
|
|
49
|
+
* args: {
|
|
50
|
+
* deallocations: [{ adapter, marketParams, amount: 500_000n }],
|
|
51
|
+
* withdraw: { amount: 500_000n, recipient },
|
|
52
|
+
* onBehalf,
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* // tx satisfies Readonly<Transaction<VaultV2ForceWithdrawAction>>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const vaultV2ForceWithdraw: ({ vault: { address: vaultAddress }, args: { deallocations, withdraw, onBehalf }, metadata, }: VaultV2ForceWithdrawParams) => Readonly<Transaction<VaultV2ForceWithdrawAction>>;
|