@morpho-org/consumer-sdk 0.3.0 → 0.5.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 +301 -41
- package/lib/actions/index.d.ts +2 -0
- package/lib/actions/index.js +2 -0
- package/lib/actions/marketV1/borrow.d.ts +34 -0
- package/lib/actions/marketV1/borrow.js +62 -0
- package/lib/actions/marketV1/buildReallocationActions.d.ts +17 -0
- package/lib/actions/marketV1/buildReallocationActions.js +36 -0
- package/lib/actions/marketV1/index.d.ts +6 -0
- package/lib/actions/marketV1/index.js +22 -0
- package/lib/actions/marketV1/repay.d.ts +44 -0
- package/lib/actions/marketV1/repay.js +93 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +51 -0
- package/lib/actions/marketV1/repayWithdrawCollateral.js +108 -0
- package/lib/actions/marketV1/supplyCollateral.d.ts +28 -0
- package/lib/actions/marketV1/supplyCollateral.js +85 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +37 -0
- package/lib/actions/marketV1/supplyCollateralBorrow.js +109 -0
- package/lib/actions/marketV1/withdrawCollateral.d.ts +28 -0
- package/lib/actions/marketV1/withdrawCollateral.js +51 -0
- package/lib/actions/requirements/encode/encodeErc20Permit.js +4 -1
- package/lib/actions/requirements/encode/encodeErc20Permit2.js +4 -1
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +21 -0
- package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +55 -0
- package/lib/actions/requirements/getRequirements.js +3 -0
- package/lib/actions/requirements/getRequirementsAction.d.ts +2 -2
- package/lib/actions/requirements/getRequirementsAction.js +7 -7
- package/lib/actions/requirements/index.d.ts +1 -0
- package/lib/actions/requirements/index.js +1 -0
- package/lib/actions/vaultV1/deposit.d.ts +41 -0
- package/lib/actions/vaultV1/deposit.js +116 -0
- package/lib/actions/vaultV1/index.d.ts +3 -0
- package/lib/actions/vaultV1/index.js +19 -0
- package/lib/actions/vaultV1/redeem.d.ts +29 -0
- package/lib/actions/vaultV1/redeem.js +48 -0
- package/lib/actions/vaultV1/withdraw.d.ts +29 -0
- package/lib/actions/vaultV1/withdraw.js +48 -0
- package/lib/actions/vaultV2/deposit.d.ts +20 -25
- package/lib/actions/vaultV2/deposit.js +78 -40
- package/lib/actions/vaultV2/forceRedeem.js +2 -2
- package/lib/actions/vaultV2/forceWithdraw.d.ts +2 -2
- package/lib/actions/vaultV2/forceWithdraw.js +12 -8
- package/lib/actions/vaultV2/redeem.js +2 -2
- package/lib/actions/vaultV2/withdraw.d.ts +3 -3
- package/lib/actions/vaultV2/withdraw.js +6 -6
- package/lib/client/morphoClient.d.ts +4 -1
- package/lib/client/morphoClient.js +6 -0
- package/lib/client/morphoViemExtension.d.ts +12 -9
- package/lib/client/morphoViemExtension.js +12 -9
- package/lib/entities/index.d.ts +2 -0
- package/lib/entities/index.js +2 -0
- package/lib/entities/marketV1/index.d.ts +1 -0
- package/lib/entities/marketV1/index.js +17 -0
- package/lib/entities/marketV1/marketV1.d.ts +290 -0
- package/lib/entities/marketV1/marketV1.js +528 -0
- package/lib/entities/vaultV1/index.d.ts +1 -0
- package/lib/entities/vaultV1/index.js +17 -0
- package/lib/entities/vaultV1/vaultV1.d.ts +95 -0
- package/lib/entities/vaultV1/vaultV1.js +129 -0
- package/lib/entities/vaultV2/vaultV2.d.ts +24 -21
- package/lib/entities/vaultV2/vaultV2.js +43 -16
- package/lib/helpers/computeReallocations.d.ts +23 -0
- package/lib/helpers/computeReallocations.js +98 -0
- package/lib/helpers/constant.d.ts +5 -0
- package/lib/helpers/constant.js +6 -1
- package/lib/helpers/encodeDeallocation.js +3 -3
- package/lib/helpers/index.d.ts +3 -0
- package/lib/helpers/index.js +18 -1
- package/lib/helpers/slippage.d.ts +46 -0
- package/lib/helpers/slippage.js +73 -0
- package/lib/helpers/validate.d.ts +150 -0
- package/lib/helpers/validate.js +279 -0
- package/lib/types/action.d.ts +113 -6
- package/lib/types/action.js +12 -1
- package/lib/types/client.d.ts +4 -1
- package/lib/types/deallocation.d.ts +1 -1
- package/lib/types/error.d.ts +127 -4
- package/lib/types/error.js +210 -12
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/sharedLiquidity.d.ts +41 -0
- package/lib/types/sharedLiquidity.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMorphoAuthorizationRequirement = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const types_1 = require("../../types");
|
|
9
|
+
/**
|
|
10
|
+
* Checks whether GeneralAdapter1 is authorized on Morpho for the given user.
|
|
11
|
+
* If not authorized, returns a deep-frozen `morpho.setAuthorization(generalAdapter1, true)` transaction.
|
|
12
|
+
* Returns `null` if authorization is already in place.
|
|
13
|
+
*
|
|
14
|
+
* Required before any bundled borrow on behalf of the user (e.g. `supplyCollateralBorrow`).
|
|
15
|
+
*
|
|
16
|
+
* @param params - Request parameters.
|
|
17
|
+
* @param params.viemClient - Connected viem client.
|
|
18
|
+
* @param params.chainId - Target chain ID (used to look up Morpho and GeneralAdapter1 addresses).
|
|
19
|
+
* @param params.userAddress - The user who needs to authorize GeneralAdapter1.
|
|
20
|
+
* @returns Deep-frozen authorization transaction, or `null` if already authorized.
|
|
21
|
+
*/
|
|
22
|
+
const getMorphoAuthorizationRequirement = async (params) => {
|
|
23
|
+
const { viemClient, chainId, userAddress } = params;
|
|
24
|
+
if (viemClient.chain?.id !== chainId) {
|
|
25
|
+
throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
26
|
+
}
|
|
27
|
+
const { morpho, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
28
|
+
const pc = viemClient.extend(viem_1.publicActions);
|
|
29
|
+
const isAuthorized = await pc.readContract({
|
|
30
|
+
address: morpho,
|
|
31
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
32
|
+
functionName: "isAuthorized",
|
|
33
|
+
args: [userAddress, generalAdapter1],
|
|
34
|
+
});
|
|
35
|
+
if (isAuthorized) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
39
|
+
to: morpho,
|
|
40
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
41
|
+
abi: blue_sdk_viem_1.blueAbi,
|
|
42
|
+
functionName: "setAuthorization",
|
|
43
|
+
args: [generalAdapter1, true],
|
|
44
|
+
}),
|
|
45
|
+
value: 0n,
|
|
46
|
+
action: {
|
|
47
|
+
type: "morphoAuthorization",
|
|
48
|
+
args: {
|
|
49
|
+
authorized: generalAdapter1,
|
|
50
|
+
isAuthorized: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.getMorphoAuthorizationRequirement = getMorphoAuthorizationRequirement;
|
|
@@ -32,6 +32,9 @@ const getRequirements = async (viemClient, params) => {
|
|
|
32
32
|
if (viemClient.chain?.id !== chainId) {
|
|
33
33
|
throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
34
34
|
}
|
|
35
|
+
if (amount === 0n) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
35
38
|
const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
36
39
|
const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient, {
|
|
37
40
|
deployless: params.supportDeployless,
|
|
@@ -4,7 +4,7 @@ import { type Permit2Action, type PermitAction, type PermitArgs } from "../../ty
|
|
|
4
4
|
interface GetRequirementsActionParams {
|
|
5
5
|
chainId: number;
|
|
6
6
|
asset: Address;
|
|
7
|
-
|
|
7
|
+
amount: bigint;
|
|
8
8
|
requirementSignature: {
|
|
9
9
|
args: PermitArgs;
|
|
10
10
|
action: PermitAction | Permit2Action;
|
|
@@ -13,5 +13,5 @@ interface GetRequirementsActionParams {
|
|
|
13
13
|
/**
|
|
14
14
|
* Get the actions required to transfer the asset based on the requirement signature.
|
|
15
15
|
*/
|
|
16
|
-
export declare const getRequirementsAction: ({ chainId, asset,
|
|
16
|
+
export declare const getRequirementsAction: ({ chainId, asset, amount, requirementSignature, }: GetRequirementsActionParams) => Action[];
|
|
17
17
|
export {};
|
|
@@ -7,12 +7,12 @@ const types_1 = require("../../types");
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the actions required to transfer the asset based on the requirement signature.
|
|
9
9
|
*/
|
|
10
|
-
const getRequirementsAction = ({ chainId, asset,
|
|
10
|
+
const getRequirementsAction = ({ chainId, asset, amount, requirementSignature, }) => {
|
|
11
11
|
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, asset)) {
|
|
12
12
|
throw new types_1.DepositAssetMismatchError(asset, requirementSignature.args.asset);
|
|
13
13
|
}
|
|
14
|
-
if (requirementSignature.args.amount !==
|
|
15
|
-
throw new types_1.DepositAmountMismatchError(
|
|
14
|
+
if (requirementSignature.args.amount !== amount) {
|
|
15
|
+
throw new types_1.DepositAmountMismatchError(amount, requirementSignature.args.amount);
|
|
16
16
|
}
|
|
17
17
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
18
18
|
if (requirementSignature.action.type === "permit2") {
|
|
@@ -34,12 +34,12 @@ const getRequirementsAction = ({ chainId, asset, assets, requirementSignature, }
|
|
|
34
34
|
sigDeadline: requirementSignature.args.deadline,
|
|
35
35
|
},
|
|
36
36
|
requirementSignature.args.signature,
|
|
37
|
-
false
|
|
37
|
+
false /* skipRevert */,
|
|
38
38
|
],
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
type: "transferFrom2",
|
|
42
|
-
args: [asset,
|
|
42
|
+
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
43
43
|
},
|
|
44
44
|
];
|
|
45
45
|
}
|
|
@@ -52,12 +52,12 @@ const getRequirementsAction = ({ chainId, asset, assets, requirementSignature, }
|
|
|
52
52
|
requirementSignature.args.amount,
|
|
53
53
|
requirementSignature.args.deadline,
|
|
54
54
|
requirementSignature.args.signature,
|
|
55
|
-
false
|
|
55
|
+
false /* skipRevert */,
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
type: "erc20TransferFrom",
|
|
60
|
-
args: [asset,
|
|
60
|
+
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
61
61
|
},
|
|
62
62
|
];
|
|
63
63
|
};
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./encode/index"), exports);
|
|
18
|
+
__exportStar(require("./getMorphoAuthorizationRequirement"), exports);
|
|
18
19
|
__exportStar(require("./getRequirements"), exports);
|
|
19
20
|
__exportStar(require("./getRequirementsApproval"), exports);
|
|
20
21
|
__exportStar(require("./getRequirementsPermit"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultV1DepositAction } from "../../types";
|
|
3
|
+
export interface VaultV1DepositParams {
|
|
4
|
+
vault: {
|
|
5
|
+
chainId: number;
|
|
6
|
+
address: Address;
|
|
7
|
+
asset: Address;
|
|
8
|
+
};
|
|
9
|
+
args: DepositAmountArgs & {
|
|
10
|
+
maxSharePrice: bigint;
|
|
11
|
+
recipient: Address;
|
|
12
|
+
requirementSignature?: RequirementSignature;
|
|
13
|
+
};
|
|
14
|
+
metadata?: Metadata;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
|
|
18
|
+
*
|
|
19
|
+
* Routed through the bundler to atomically execute the asset transfer and vault deposit.
|
|
20
|
+
* The general adapter enforces `maxSharePrice` on-chain to prevent inflation attacks.
|
|
21
|
+
* Never bypass the general adapter.
|
|
22
|
+
*
|
|
23
|
+
* When `nativeAmount` is provided, that amount of native ETH is sent as `msg.value`
|
|
24
|
+
* to the Bundler3 multicall and wrapped into WETH via `GeneralAdapter1.wrapNative()`.
|
|
25
|
+
* The vault's underlying asset must be the chain's wrapped native token (wNative).
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} params - The deposit parameters.
|
|
28
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
29
|
+
* @param {number} params.vault.chainId - The chain ID.
|
|
30
|
+
* @param {Address} params.vault.address - The vault address.
|
|
31
|
+
* @param {Address} params.vault.asset - The underlying ERC20 asset address.
|
|
32
|
+
* @param {Object} params.args - The deposit arguments.
|
|
33
|
+
* @param {bigint} [params.args.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
|
|
34
|
+
* @param {bigint} params.args.maxSharePrice - Maximum acceptable share price (slippage protection).
|
|
35
|
+
* @param {Address} params.args.recipient - Receives the vault shares.
|
|
36
|
+
* @param {RequirementSignature} [params.args.requirementSignature] - Pre-signed permit/permit2 approval.
|
|
37
|
+
* @param {bigint} [params.args.nativeAmount] - Amount of native token to wrap into wNative for the deposit.
|
|
38
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
39
|
+
* @returns {Readonly<Transaction<VaultV1DepositAction>>} The prepared deposit transaction.
|
|
40
|
+
*/
|
|
41
|
+
export declare const vaultV1Deposit: ({ vault: { chainId, address: vaultAddress, asset }, args: { amount, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }: VaultV1DepositParams) => Readonly<Transaction<VaultV1DepositAction>>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vaultV1Deposit = 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 helpers_1 = require("../../helpers");
|
|
9
|
+
const types_1 = require("../../types");
|
|
10
|
+
const getRequirementsAction_1 = require("../requirements/getRequirementsAction");
|
|
11
|
+
/**
|
|
12
|
+
* Prepares a deposit transaction for a VaultV1 (MetaMorpho) contract.
|
|
13
|
+
*
|
|
14
|
+
* Routed through the bundler to atomically execute the asset transfer and vault deposit.
|
|
15
|
+
* The general adapter enforces `maxSharePrice` on-chain to prevent inflation attacks.
|
|
16
|
+
* Never bypass the general adapter.
|
|
17
|
+
*
|
|
18
|
+
* When `nativeAmount` is provided, that amount of native ETH is sent as `msg.value`
|
|
19
|
+
* to the Bundler3 multicall and wrapped into WETH via `GeneralAdapter1.wrapNative()`.
|
|
20
|
+
* The vault's underlying asset must be the chain's wrapped native token (wNative).
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} params - The deposit parameters.
|
|
23
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
24
|
+
* @param {number} params.vault.chainId - The chain ID.
|
|
25
|
+
* @param {Address} params.vault.address - The vault address.
|
|
26
|
+
* @param {Address} params.vault.asset - The underlying ERC20 asset address.
|
|
27
|
+
* @param {Object} params.args - The deposit arguments.
|
|
28
|
+
* @param {bigint} [params.args.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
|
|
29
|
+
* @param {bigint} params.args.maxSharePrice - Maximum acceptable share price (slippage protection).
|
|
30
|
+
* @param {Address} params.args.recipient - Receives the vault shares.
|
|
31
|
+
* @param {RequirementSignature} [params.args.requirementSignature] - Pre-signed permit/permit2 approval.
|
|
32
|
+
* @param {bigint} [params.args.nativeAmount] - Amount of native token to wrap into wNative for the deposit.
|
|
33
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
34
|
+
* @returns {Readonly<Transaction<VaultV1DepositAction>>} The prepared deposit transaction.
|
|
35
|
+
*/
|
|
36
|
+
const vaultV1Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
37
|
+
if (amount < 0n) {
|
|
38
|
+
throw new types_1.NonPositiveAssetAmountError(asset);
|
|
39
|
+
}
|
|
40
|
+
if (maxSharePrice <= 0n) {
|
|
41
|
+
throw new types_1.NonPositiveMaxSharePriceError(vaultAddress);
|
|
42
|
+
}
|
|
43
|
+
const actions = [];
|
|
44
|
+
const { bundler3: { generalAdapter1, bundler3 }, wNative, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
45
|
+
if (nativeAmount) {
|
|
46
|
+
if (nativeAmount < 0n) {
|
|
47
|
+
throw new types_1.NegativeNativeAmountError(nativeAmount);
|
|
48
|
+
}
|
|
49
|
+
if (!(0, morpho_ts_1.isDefined)(wNative)) {
|
|
50
|
+
throw new types_1.ChainWNativeMissingError(chainId);
|
|
51
|
+
}
|
|
52
|
+
if (!(0, viem_1.isAddressEqual)(asset, wNative)) {
|
|
53
|
+
throw new types_1.NativeAmountOnNonWNativeVaultError(asset, wNative);
|
|
54
|
+
}
|
|
55
|
+
actions.push(
|
|
56
|
+
// Transfers native token from Bundler3 to GeneralAdapter1 for wrapping.
|
|
57
|
+
{
|
|
58
|
+
type: "nativeTransfer",
|
|
59
|
+
args: [bundler3, generalAdapter1, nativeAmount, false /* skipRevert */],
|
|
60
|
+
}, {
|
|
61
|
+
type: "wrapNative",
|
|
62
|
+
args: [nativeAmount, generalAdapter1, false /* skipRevert */],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (amount > 0n) {
|
|
66
|
+
if (requirementSignature) {
|
|
67
|
+
actions.push(...(0, getRequirementsAction_1.getRequirementsAction)({
|
|
68
|
+
chainId,
|
|
69
|
+
asset,
|
|
70
|
+
amount,
|
|
71
|
+
requirementSignature,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
actions.push({
|
|
76
|
+
type: "erc20TransferFrom",
|
|
77
|
+
args: [asset, amount, generalAdapter1, false /* skipRevert */],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const totalAssets = amount + (nativeAmount ?? 0n);
|
|
82
|
+
if (totalAssets === 0n) {
|
|
83
|
+
throw new types_1.ZeroDepositAmountError(vaultAddress);
|
|
84
|
+
}
|
|
85
|
+
actions.push({
|
|
86
|
+
type: "erc4626Deposit",
|
|
87
|
+
args: [
|
|
88
|
+
vaultAddress,
|
|
89
|
+
totalAssets,
|
|
90
|
+
maxSharePrice,
|
|
91
|
+
recipient,
|
|
92
|
+
false /* skipRevert */,
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
let tx = bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions);
|
|
96
|
+
if (nativeAmount) {
|
|
97
|
+
tx = { ...tx, value: nativeAmount };
|
|
98
|
+
}
|
|
99
|
+
if (metadata) {
|
|
100
|
+
tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
|
|
101
|
+
}
|
|
102
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
103
|
+
...tx,
|
|
104
|
+
action: {
|
|
105
|
+
type: "vaultV1Deposit",
|
|
106
|
+
args: {
|
|
107
|
+
vault: vaultAddress,
|
|
108
|
+
amount,
|
|
109
|
+
maxSharePrice,
|
|
110
|
+
recipient,
|
|
111
|
+
nativeAmount,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
exports.vaultV1Deposit = vaultV1Deposit;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./deposit"), exports);
|
|
18
|
+
__exportStar(require("./redeem"), exports);
|
|
19
|
+
__exportStar(require("./withdraw"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Metadata, type Transaction, type VaultV1RedeemAction } from "../../types";
|
|
3
|
+
export interface VaultV1RedeemParams {
|
|
4
|
+
vault: {
|
|
5
|
+
address: Address;
|
|
6
|
+
};
|
|
7
|
+
args: {
|
|
8
|
+
shares: bigint;
|
|
9
|
+
recipient: Address;
|
|
10
|
+
onBehalf: Address;
|
|
11
|
+
};
|
|
12
|
+
metadata?: Metadata;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Prepares a redeem transaction for a VaultV1 (MetaMorpho) contract.
|
|
16
|
+
*
|
|
17
|
+
* Direct vault call — no bundler needed. Redeem has no inflation attack surface.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} params - The redeem parameters.
|
|
20
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
21
|
+
* @param {Address} params.vault.address - The vault address.
|
|
22
|
+
* @param {Object} params.args - The redeem arguments.
|
|
23
|
+
* @param {bigint} params.args.shares - Amount of shares to redeem.
|
|
24
|
+
* @param {Address} params.args.recipient - Receives the redeemed assets.
|
|
25
|
+
* @param {Address} params.args.onBehalf - Address whose shares are burned.
|
|
26
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
27
|
+
* @returns {Readonly<Transaction<VaultV1RedeemAction>>} The prepared redeem transaction.
|
|
28
|
+
*/
|
|
29
|
+
export declare const vaultV1Redeem: ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }: VaultV1RedeemParams) => Readonly<Transaction<VaultV1RedeemAction>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 helpers_1 = require("../../helpers");
|
|
8
|
+
const types_1 = require("../../types");
|
|
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 {Object} params - The redeem parameters.
|
|
15
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
16
|
+
* @param {Address} params.vault.address - The vault address.
|
|
17
|
+
* @param {Object} params.args - The redeem arguments.
|
|
18
|
+
* @param {bigint} params.args.shares - Amount of shares to redeem.
|
|
19
|
+
* @param {Address} params.args.recipient - Receives the redeemed assets.
|
|
20
|
+
* @param {Address} params.args.onBehalf - Address whose shares are burned.
|
|
21
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
22
|
+
* @returns {Readonly<Transaction<VaultV1RedeemAction>>} The prepared redeem transaction.
|
|
23
|
+
*/
|
|
24
|
+
const vaultV1Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
|
|
25
|
+
if (shares <= 0n) {
|
|
26
|
+
throw new types_1.NonPositiveSharesAmountError(vaultAddress);
|
|
27
|
+
}
|
|
28
|
+
let tx = {
|
|
29
|
+
to: vaultAddress,
|
|
30
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
31
|
+
abi: blue_sdk_viem_1.metaMorphoAbi,
|
|
32
|
+
functionName: "redeem",
|
|
33
|
+
args: [shares, recipient, onBehalf],
|
|
34
|
+
}),
|
|
35
|
+
value: 0n,
|
|
36
|
+
};
|
|
37
|
+
if (metadata) {
|
|
38
|
+
tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
|
|
39
|
+
}
|
|
40
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
41
|
+
...tx,
|
|
42
|
+
action: {
|
|
43
|
+
type: "vaultV1Redeem",
|
|
44
|
+
args: { vault: vaultAddress, shares, recipient },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.vaultV1Redeem = vaultV1Redeem;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type Metadata, type Transaction, type VaultV1WithdrawAction } from "../../types";
|
|
3
|
+
export interface VaultV1WithdrawParams {
|
|
4
|
+
vault: {
|
|
5
|
+
address: Address;
|
|
6
|
+
};
|
|
7
|
+
args: {
|
|
8
|
+
amount: bigint;
|
|
9
|
+
recipient: Address;
|
|
10
|
+
onBehalf: Address;
|
|
11
|
+
};
|
|
12
|
+
metadata?: Metadata;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Prepares a withdraw transaction for a VaultV1 (MetaMorpho) contract.
|
|
16
|
+
*
|
|
17
|
+
* Direct vault call — no bundler needed. Withdraw has no inflation attack surface.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} params - The withdraw parameters.
|
|
20
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
21
|
+
* @param {Address} params.vault.address - The vault address.
|
|
22
|
+
* @param {Object} params.args - The withdraw arguments.
|
|
23
|
+
* @param {bigint} params.args.amount - Amount of assets to withdraw.
|
|
24
|
+
* @param {Address} params.args.recipient - Receives the withdrawn assets.
|
|
25
|
+
* @param {Address} params.args.onBehalf - Address whose shares are burned.
|
|
26
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
27
|
+
* @returns {Readonly<Transaction<VaultV1WithdrawAction>>} The prepared withdraw transaction.
|
|
28
|
+
*/
|
|
29
|
+
export declare const vaultV1Withdraw: ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }: VaultV1WithdrawParams) => Readonly<Transaction<VaultV1WithdrawAction>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
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 helpers_1 = require("../../helpers");
|
|
8
|
+
const types_1 = require("../../types");
|
|
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 {Object} params - The withdraw parameters.
|
|
15
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
16
|
+
* @param {Address} params.vault.address - The vault address.
|
|
17
|
+
* @param {Object} params.args - The withdraw arguments.
|
|
18
|
+
* @param {bigint} params.args.amount - Amount of assets to withdraw.
|
|
19
|
+
* @param {Address} params.args.recipient - Receives the withdrawn assets.
|
|
20
|
+
* @param {Address} params.args.onBehalf - Address whose shares are burned.
|
|
21
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
22
|
+
* @returns {Readonly<Transaction<VaultV1WithdrawAction>>} The prepared withdraw transaction.
|
|
23
|
+
*/
|
|
24
|
+
const vaultV1Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
|
|
25
|
+
if (amount <= 0n) {
|
|
26
|
+
throw new types_1.NonPositiveAssetAmountError(vaultAddress);
|
|
27
|
+
}
|
|
28
|
+
let tx = {
|
|
29
|
+
to: vaultAddress,
|
|
30
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
31
|
+
abi: blue_sdk_viem_1.metaMorphoAbi,
|
|
32
|
+
functionName: "withdraw",
|
|
33
|
+
args: [amount, recipient, onBehalf],
|
|
34
|
+
}),
|
|
35
|
+
value: 0n,
|
|
36
|
+
};
|
|
37
|
+
if (metadata) {
|
|
38
|
+
tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
|
|
39
|
+
}
|
|
40
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
41
|
+
...tx,
|
|
42
|
+
action: {
|
|
43
|
+
type: "vaultV1Withdraw",
|
|
44
|
+
args: { vault: vaultAddress, amount, recipient },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.vaultV1Withdraw = vaultV1Withdraw;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type Metadata, type RequirementSignature, type Transaction, type VaultV2DepositAction } from "../../types";
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import { type DepositAmountArgs, type Metadata, type RequirementSignature, type Transaction, type VaultV2DepositAction } from "../../types";
|
|
3
3
|
export interface VaultV2DepositParams {
|
|
4
4
|
vault: {
|
|
5
5
|
chainId: number;
|
|
6
6
|
address: Address;
|
|
7
7
|
asset: Address;
|
|
8
8
|
};
|
|
9
|
-
args: {
|
|
10
|
-
assets: bigint;
|
|
9
|
+
args: DepositAmountArgs & {
|
|
11
10
|
maxSharePrice: bigint;
|
|
12
11
|
recipient: Address;
|
|
13
12
|
requirementSignature?: RequirementSignature;
|
|
@@ -17,30 +16,26 @@ export interface VaultV2DepositParams {
|
|
|
17
16
|
/**
|
|
18
17
|
* Prepares a deposit transaction for the VaultV2 contract.
|
|
19
18
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* Routed through the bundler to atomically execute the asset transfer and vault deposit.
|
|
20
|
+
* The general adapter enforces `maxSharePrice` on-chain to prevent inflation attacks.
|
|
21
|
+
* Never bypass the general adapter.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Do not bypass the general adapter or remove this check, as doing so would expose the flow to potential exploits.
|
|
27
|
-
* The maxSharePrice constraint ensures that the user does not receive unfavorable share pricing due to malicious or sudden vault changes.
|
|
23
|
+
* When `nativeAmount` is provided, that amount of native ETH is sent as `msg.value`
|
|
24
|
+
* to the Bundler3 multicall and wrapped into WETH via `GeneralAdapter1.wrapNative()`.
|
|
25
|
+
* The vault's underlying asset must be the chain's wrapped native token (wNative).
|
|
28
26
|
*
|
|
29
|
-
*
|
|
30
|
-
* @param {Object} params - The vault
|
|
31
|
-
* @param {Object} params.vault - The vault related parameters.
|
|
27
|
+
* @param {Object} params - The deposit parameters.
|
|
28
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
32
29
|
* @param {number} params.vault.chainId - The chain ID.
|
|
33
30
|
* @param {Address} params.vault.address - The vault address.
|
|
34
|
-
* @param {Address} params.vault.asset - The
|
|
35
|
-
* @param {Object} params.args - The deposit
|
|
36
|
-
* @param {bigint} params.args.
|
|
37
|
-
* @param {bigint} params.args.maxSharePrice -
|
|
38
|
-
* @param {Address} params.args.recipient -
|
|
39
|
-
* @param {
|
|
40
|
-
* @param {
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {Metadata} [params.metadata] - Optional the metadata.
|
|
43
|
-
*
|
|
31
|
+
* @param {Address} params.vault.asset - The underlying ERC20 asset address.
|
|
32
|
+
* @param {Object} params.args - The deposit arguments.
|
|
33
|
+
* @param {bigint} [params.args.amount=0n] - Amount of ERC-20 assets to deposit. At least one of amount or nativeAmount must be provided.
|
|
34
|
+
* @param {bigint} params.args.maxSharePrice - Maximum acceptable share price (slippage protection).
|
|
35
|
+
* @param {Address} params.args.recipient - Receives the vault shares.
|
|
36
|
+
* @param {RequirementSignature} [params.args.requirementSignature] - Pre-signed permit/permit2 approval.
|
|
37
|
+
* @param {bigint} [params.args.nativeAmount] - Amount of native token to wrap into wNative for the deposit.
|
|
38
|
+
* @param {Metadata} [params.metadata] - Optional analytics metadata.
|
|
44
39
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} The prepared deposit transaction.
|
|
45
40
|
*/
|
|
46
|
-
export declare const vaultV2Deposit: ({ vault: { chainId, address: vaultAddress, asset }, args: {
|
|
41
|
+
export declare const vaultV2Deposit: ({ vault: { chainId, address: vaultAddress, asset }, args: { amount, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }: VaultV2DepositParams) => Readonly<Transaction<VaultV2DepositAction>>;
|