@morpho-org/consumer-sdk 0.3.0 → 0.4.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 +178 -44
- package/lib/actions/index.d.ts +1 -0
- package/lib/actions/index.js +1 -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/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 +8 -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 +2 -1
- package/lib/client/morphoClient.js +3 -0
- package/lib/client/morphoViemExtension.d.ts +12 -9
- package/lib/client/morphoViemExtension.js +12 -9
- package/lib/entities/index.d.ts +1 -0
- package/lib/entities/index.js +1 -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 +125 -0
- package/lib/entities/vaultV2/vaultV2.d.ts +24 -21
- package/lib/entities/vaultV2/vaultV2.js +39 -16
- package/lib/helpers/encodeDeallocation.js +3 -3
- package/lib/types/action.d.ts +39 -4
- package/lib/types/client.d.ts +2 -1
- package/lib/types/deallocation.d.ts +1 -1
- package/lib/types/error.d.ts +22 -4
- package/lib/types/error.js +48 -12
- package/package.json +1 -1
|
@@ -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>>;
|
|
@@ -4,66 +4,98 @@ exports.vaultV2Deposit = void 0;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const bundler_sdk_viem_1 = require("@morpho-org/bundler-sdk-viem");
|
|
6
6
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
7
8
|
const helpers_1 = require("../../helpers");
|
|
8
9
|
const types_1 = require("../../types");
|
|
9
10
|
const getRequirementsAction_1 = require("../requirements/getRequirementsAction");
|
|
10
11
|
/**
|
|
11
12
|
* Prepares a deposit transaction for the VaultV2 contract.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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.
|
|
15
17
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* Do not bypass the general adapter or remove this check, as doing so would expose the flow to potential exploits.
|
|
20
|
-
* The maxSharePrice constraint ensures that the user does not receive unfavorable share pricing due to malicious or sudden vault changes.
|
|
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
21
|
*
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} params - The vault
|
|
24
|
-
* @param {Object} params.vault - The vault related parameters.
|
|
22
|
+
* @param {Object} params - The deposit parameters.
|
|
23
|
+
* @param {Object} params.vault - The vault identifiers.
|
|
25
24
|
* @param {number} params.vault.chainId - The chain ID.
|
|
26
25
|
* @param {Address} params.vault.address - The vault address.
|
|
27
|
-
* @param {Address} params.vault.asset - The
|
|
28
|
-
* @param {Object} params.args - The deposit
|
|
29
|
-
* @param {bigint} params.args.
|
|
30
|
-
* @param {bigint} params.args.maxSharePrice -
|
|
31
|
-
* @param {Address} params.args.recipient -
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {Metadata} [params.metadata] - Optional the metadata.
|
|
36
|
-
*
|
|
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.
|
|
37
34
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} The prepared deposit transaction.
|
|
38
35
|
*/
|
|
39
|
-
const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: {
|
|
40
|
-
if (
|
|
41
|
-
throw new types_1.
|
|
36
|
+
const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args: { amount = 0n, maxSharePrice, recipient, requirementSignature, nativeAmount, }, metadata, }) => {
|
|
37
|
+
if (amount < 0n) {
|
|
38
|
+
throw new types_1.NonPositiveAssetAmountError(asset);
|
|
42
39
|
}
|
|
43
|
-
if (maxSharePrice
|
|
44
|
-
throw new types_1.
|
|
40
|
+
if (maxSharePrice <= 0n) {
|
|
41
|
+
throw new types_1.NonPositiveMaxSharePriceError(vaultAddress);
|
|
45
42
|
}
|
|
46
43
|
const actions = [];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 */],
|
|
60
63
|
});
|
|
61
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
|
+
}
|
|
62
85
|
actions.push({
|
|
63
86
|
type: "erc4626Deposit",
|
|
64
|
-
args: [
|
|
87
|
+
args: [
|
|
88
|
+
vaultAddress,
|
|
89
|
+
totalAssets,
|
|
90
|
+
maxSharePrice,
|
|
91
|
+
recipient,
|
|
92
|
+
false /* skipRevert */,
|
|
93
|
+
],
|
|
65
94
|
});
|
|
66
95
|
let tx = bundler_sdk_viem_1.BundlerAction.encodeBundle(chainId, actions);
|
|
96
|
+
if (nativeAmount) {
|
|
97
|
+
tx = { ...tx, value: nativeAmount };
|
|
98
|
+
}
|
|
67
99
|
if (metadata) {
|
|
68
100
|
tx = (0, helpers_1.addTransactionMetadata)(tx, metadata);
|
|
69
101
|
}
|
|
@@ -71,7 +103,13 @@ const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args
|
|
|
71
103
|
...tx,
|
|
72
104
|
action: {
|
|
73
105
|
type: "vaultV2Deposit",
|
|
74
|
-
args: {
|
|
106
|
+
args: {
|
|
107
|
+
vault: vaultAddress,
|
|
108
|
+
amount,
|
|
109
|
+
maxSharePrice,
|
|
110
|
+
recipient,
|
|
111
|
+
nativeAmount,
|
|
112
|
+
},
|
|
75
113
|
},
|
|
76
114
|
});
|
|
77
115
|
};
|
|
@@ -42,8 +42,8 @@ const vaultV2ForceRedeem = ({ vault: { address: vaultAddress }, args: { dealloca
|
|
|
42
42
|
if (deallocations.length === 0) {
|
|
43
43
|
throw new types_1.EmptyDeallocationsError(vaultAddress);
|
|
44
44
|
}
|
|
45
|
-
if (redeem.shares
|
|
46
|
-
throw new types_1.
|
|
45
|
+
if (redeem.shares <= 0n) {
|
|
46
|
+
throw new types_1.NonPositiveSharesAmountError(vaultAddress);
|
|
47
47
|
}
|
|
48
48
|
const calls = [];
|
|
49
49
|
for (const deallocation of deallocations) {
|
|
@@ -7,7 +7,7 @@ export interface VaultV2ForceWithdrawParams {
|
|
|
7
7
|
args: {
|
|
8
8
|
deallocations: readonly Deallocation[];
|
|
9
9
|
withdraw: {
|
|
10
|
-
|
|
10
|
+
amount: bigint;
|
|
11
11
|
recipient: Address;
|
|
12
12
|
};
|
|
13
13
|
onBehalf: Address;
|
|
@@ -31,7 +31,7 @@ export interface VaultV2ForceWithdrawParams {
|
|
|
31
31
|
* @param {Object} params.args - The force withdraw related parameters.
|
|
32
32
|
* @param {readonly Deallocation[]} params.args.deallocations - The list of deallocations to perform.
|
|
33
33
|
* @param {Object} params.args.withdraw - The withdraw parameters applied after deallocations.
|
|
34
|
-
* @param {bigint} params.args.withdraw.
|
|
34
|
+
* @param {bigint} params.args.withdraw.amount - The amount of assets to withdraw.
|
|
35
35
|
* @param {Address} params.args.withdraw.recipient - The recipient of the withdrawn assets.
|
|
36
36
|
* @param {Address} params.args.onBehalf - The address from which the penalty is taken (share owner).
|
|
37
37
|
* @param {Metadata} [params.metadata] - Optional analytics metadata to append.
|
|
@@ -24,7 +24,7 @@ const types_1 = require("../../types");
|
|
|
24
24
|
* @param {Object} params.args - The force withdraw related parameters.
|
|
25
25
|
* @param {readonly Deallocation[]} params.args.deallocations - The list of deallocations to perform.
|
|
26
26
|
* @param {Object} params.args.withdraw - The withdraw parameters applied after deallocations.
|
|
27
|
-
* @param {bigint} params.args.withdraw.
|
|
27
|
+
* @param {bigint} params.args.withdraw.amount - The amount of assets to withdraw.
|
|
28
28
|
* @param {Address} params.args.withdraw.recipient - The recipient of the withdrawn assets.
|
|
29
29
|
* @param {Address} params.args.onBehalf - The address from which the penalty is taken (share owner).
|
|
30
30
|
* @param {Metadata} [params.metadata] - Optional analytics metadata to append.
|
|
@@ -34,12 +34,12 @@ const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallo
|
|
|
34
34
|
if (deallocations.length === 0) {
|
|
35
35
|
throw new types_1.EmptyDeallocationsError(vaultAddress);
|
|
36
36
|
}
|
|
37
|
-
if (withdraw.
|
|
38
|
-
throw new types_1.
|
|
37
|
+
if (withdraw.amount <= 0n) {
|
|
38
|
+
throw new types_1.NonPositiveAssetAmountError(vaultAddress);
|
|
39
39
|
}
|
|
40
|
-
const totalDeallocated = deallocations.reduce((sum, d) => sum + d.
|
|
41
|
-
if (withdraw.
|
|
42
|
-
throw new types_1.DeallocationsExceedWithdrawError(vaultAddress, withdraw.
|
|
40
|
+
const totalDeallocated = deallocations.reduce((sum, d) => sum + d.amount, 0n);
|
|
41
|
+
if (withdraw.amount < totalDeallocated) {
|
|
42
|
+
throw new types_1.DeallocationsExceedWithdrawError(vaultAddress, withdraw.amount, totalDeallocated);
|
|
43
43
|
}
|
|
44
44
|
const calls = [];
|
|
45
45
|
for (const deallocation of deallocations) {
|
|
@@ -48,7 +48,7 @@ const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallo
|
|
|
48
48
|
calls.push((0, viem_1.encodeFunctionData)({
|
|
49
49
|
abi: blue_sdk_viem_1.vaultV2Abi,
|
|
50
50
|
functionName: "withdraw",
|
|
51
|
-
args: [withdraw.
|
|
51
|
+
args: [withdraw.amount, withdraw.recipient, onBehalf],
|
|
52
52
|
}));
|
|
53
53
|
let tx = {
|
|
54
54
|
to: vaultAddress,
|
|
@@ -70,7 +70,7 @@ const vaultV2ForceWithdraw = ({ vault: { address: vaultAddress }, args: { deallo
|
|
|
70
70
|
vault: vaultAddress,
|
|
71
71
|
deallocations: deallocations.map((d) => ({ ...d })),
|
|
72
72
|
withdraw: {
|
|
73
|
-
|
|
73
|
+
amount: withdraw.amount,
|
|
74
74
|
recipient: withdraw.recipient,
|
|
75
75
|
},
|
|
76
76
|
onBehalf,
|
|
@@ -25,8 +25,8 @@ const types_1 = require("../../types");
|
|
|
25
25
|
* @returns {Readonly<Transaction<VaultV2RedeemAction>>} The prepared redeem transaction.
|
|
26
26
|
*/
|
|
27
27
|
const vaultV2Redeem = ({ vault: { address: vaultAddress }, args: { shares, recipient, onBehalf }, metadata, }) => {
|
|
28
|
-
if (shares
|
|
29
|
-
throw new types_1.
|
|
28
|
+
if (shares <= 0n) {
|
|
29
|
+
throw new types_1.NonPositiveSharesAmountError(vaultAddress);
|
|
30
30
|
}
|
|
31
31
|
let tx = {
|
|
32
32
|
to: vaultAddress,
|
|
@@ -5,7 +5,7 @@ export interface VaultV2WithdrawParams {
|
|
|
5
5
|
address: Address;
|
|
6
6
|
};
|
|
7
7
|
args: {
|
|
8
|
-
|
|
8
|
+
amount: bigint;
|
|
9
9
|
recipient: Address;
|
|
10
10
|
onBehalf: Address;
|
|
11
11
|
};
|
|
@@ -23,10 +23,10 @@ export interface VaultV2WithdrawParams {
|
|
|
23
23
|
* @param {Object} params.vault - The vault related parameters.
|
|
24
24
|
* @param {Address} params.vault.address - The vault address.
|
|
25
25
|
* @param {Object} params.args - The withdraw related parameters.
|
|
26
|
-
* @param {bigint} params.args.
|
|
26
|
+
* @param {bigint} params.args.amount - The amount of assets to withdraw.
|
|
27
27
|
* @param {Address} params.args.recipient - The recipient address.
|
|
28
28
|
* @param {Address} params.args.onBehalf - The address on behalf of which the withdraw is made.
|
|
29
29
|
* @param {Metadata} [params.metadata] - Optional the metadata.
|
|
30
30
|
* @returns {Readonly<Transaction<VaultV2WithdrawAction>>} The prepared withdraw transaction.
|
|
31
31
|
*/
|
|
32
|
-
export declare const vaultV2Withdraw: ({ vault: { address: vaultAddress }, args: {
|
|
32
|
+
export declare const vaultV2Withdraw: ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }: VaultV2WithdrawParams) => Readonly<Transaction<VaultV2WithdrawAction>>;
|
|
@@ -18,22 +18,22 @@ const types_1 = require("../../types");
|
|
|
18
18
|
* @param {Object} params.vault - The vault related parameters.
|
|
19
19
|
* @param {Address} params.vault.address - The vault address.
|
|
20
20
|
* @param {Object} params.args - The withdraw related parameters.
|
|
21
|
-
* @param {bigint} params.args.
|
|
21
|
+
* @param {bigint} params.args.amount - The amount of assets to withdraw.
|
|
22
22
|
* @param {Address} params.args.recipient - The recipient address.
|
|
23
23
|
* @param {Address} params.args.onBehalf - The address on behalf of which the withdraw is made.
|
|
24
24
|
* @param {Metadata} [params.metadata] - Optional the metadata.
|
|
25
25
|
* @returns {Readonly<Transaction<VaultV2WithdrawAction>>} The prepared withdraw transaction.
|
|
26
26
|
*/
|
|
27
|
-
const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: {
|
|
28
|
-
if (
|
|
29
|
-
throw new types_1.
|
|
27
|
+
const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { amount, recipient, onBehalf }, metadata, }) => {
|
|
28
|
+
if (amount <= 0n) {
|
|
29
|
+
throw new types_1.NonPositiveAssetAmountError(vaultAddress);
|
|
30
30
|
}
|
|
31
31
|
let tx = {
|
|
32
32
|
to: vaultAddress,
|
|
33
33
|
data: (0, viem_1.encodeFunctionData)({
|
|
34
34
|
abi: blue_sdk_viem_1.vaultV2Abi,
|
|
35
35
|
functionName: "withdraw",
|
|
36
|
-
args: [
|
|
36
|
+
args: [amount, recipient, onBehalf],
|
|
37
37
|
}),
|
|
38
38
|
value: 0n,
|
|
39
39
|
};
|
|
@@ -44,7 +44,7 @@ const vaultV2Withdraw = ({ vault: { address: vaultAddress }, args: { assets, rec
|
|
|
44
44
|
...tx,
|
|
45
45
|
action: {
|
|
46
46
|
type: "vaultV2Withdraw",
|
|
47
|
-
args: { vault: vaultAddress,
|
|
47
|
+
args: { vault: vaultAddress, amount, recipient },
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address, Client } from "viem";
|
|
2
|
-
import { MorphoVaultV2 } from "../entities";
|
|
2
|
+
import { MorphoVaultV1, MorphoVaultV2 } from "../entities";
|
|
3
3
|
import type { Metadata, MorphoClientType } from "../types";
|
|
4
4
|
export declare class MorphoClient implements MorphoClientType {
|
|
5
5
|
readonly viemClient: Client;
|
|
@@ -18,5 +18,6 @@ export declare class MorphoClient implements MorphoClientType {
|
|
|
18
18
|
readonly supportDeployless?: boolean;
|
|
19
19
|
readonly metadata?: Metadata;
|
|
20
20
|
} | undefined);
|
|
21
|
+
vaultV1(vault: Address, chainId: number): MorphoVaultV1;
|
|
21
22
|
vaultV2(vault: Address, chainId: number): MorphoVaultV2;
|
|
22
23
|
}
|
|
@@ -15,6 +15,9 @@ class MorphoClient {
|
|
|
15
15
|
supportDeployless: _options?.supportDeployless,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
vaultV1(vault, chainId) {
|
|
19
|
+
return new entities_1.MorphoVaultV1(this, vault, chainId);
|
|
20
|
+
}
|
|
18
21
|
vaultV2(vault, chainId) {
|
|
19
22
|
return new entities_1.MorphoVaultV2(this, vault, chainId);
|
|
20
23
|
}
|
|
@@ -3,18 +3,18 @@ import type { Metadata } from "../types";
|
|
|
3
3
|
import { MorphoClient } from "./morphoClient";
|
|
4
4
|
/**
|
|
5
5
|
* Morpho extension for viem clients.
|
|
6
|
-
* Adds `morpho` namespace
|
|
6
|
+
* Adds `morpho` namespace with `vaultV1` and `vaultV2` accessors.
|
|
7
7
|
*
|
|
8
|
-
* @param metadata - (Optional) Metadata
|
|
9
|
-
* @param supportSignature - (Optional)
|
|
10
|
-
* @param supportDeployless - (Optional)
|
|
11
|
-
* @returns Extension function that adds morpho namespace to viem clients
|
|
8
|
+
* @param metadata - (Optional) Metadata appended to all transactions for analytics.
|
|
9
|
+
* @param supportSignature - (Optional) Enable off-chain permit/permit2 approvals.
|
|
10
|
+
* @param supportDeployless - (Optional) Enable deployless reads for on-chain data fetching.
|
|
11
|
+
* @returns Extension function that adds morpho namespace to viem clients.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
15
|
* import { createWalletClient, http } from 'viem';
|
|
16
16
|
* import { mainnet } from 'viem/chains';
|
|
17
|
-
* import {
|
|
17
|
+
* import { morphoViemExtension } from '@morpho-org/consumer-sdk';
|
|
18
18
|
*
|
|
19
19
|
* const client = createWalletClient({
|
|
20
20
|
* chain: mainnet,
|
|
@@ -22,9 +22,12 @@ import { MorphoClient } from "./morphoClient";
|
|
|
22
22
|
* account: '0x...',
|
|
23
23
|
* }).extend(morphoViemExtension());
|
|
24
24
|
*
|
|
25
|
-
* //
|
|
26
|
-
* const
|
|
27
|
-
* const
|
|
25
|
+
* // VaultV1 (MetaMorpho)
|
|
26
|
+
* const vaultV1 = client.morpho.vaultV1('0x...', 1);
|
|
27
|
+
* const depositV1 = await vaultV1.deposit({ amount: 1000000000000000000n, userAddress: '0x...' });
|
|
28
|
+
*
|
|
29
|
+
* // VaultV2
|
|
30
|
+
* const vaultV2 = client.morpho.vaultV2('0x...', 1);
|
|
28
31
|
* ```
|
|
29
32
|
*/
|
|
30
33
|
export declare function morphoViemExtension(_options?: {
|
|
@@ -4,18 +4,18 @@ exports.morphoViemExtension = morphoViemExtension;
|
|
|
4
4
|
const morphoClient_1 = require("./morphoClient");
|
|
5
5
|
/**
|
|
6
6
|
* Morpho extension for viem clients.
|
|
7
|
-
* Adds `morpho` namespace
|
|
7
|
+
* Adds `morpho` namespace with `vaultV1` and `vaultV2` accessors.
|
|
8
8
|
*
|
|
9
|
-
* @param metadata - (Optional) Metadata
|
|
10
|
-
* @param supportSignature - (Optional)
|
|
11
|
-
* @param supportDeployless - (Optional)
|
|
12
|
-
* @returns Extension function that adds morpho namespace to viem clients
|
|
9
|
+
* @param metadata - (Optional) Metadata appended to all transactions for analytics.
|
|
10
|
+
* @param supportSignature - (Optional) Enable off-chain permit/permit2 approvals.
|
|
11
|
+
* @param supportDeployless - (Optional) Enable deployless reads for on-chain data fetching.
|
|
12
|
+
* @returns Extension function that adds morpho namespace to viem clients.
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
16
|
* import { createWalletClient, http } from 'viem';
|
|
17
17
|
* import { mainnet } from 'viem/chains';
|
|
18
|
-
* import {
|
|
18
|
+
* import { morphoViemExtension } from '@morpho-org/consumer-sdk';
|
|
19
19
|
*
|
|
20
20
|
* const client = createWalletClient({
|
|
21
21
|
* chain: mainnet,
|
|
@@ -23,9 +23,12 @@ const morphoClient_1 = require("./morphoClient");
|
|
|
23
23
|
* account: '0x...',
|
|
24
24
|
* }).extend(morphoViemExtension());
|
|
25
25
|
*
|
|
26
|
-
* //
|
|
27
|
-
* const
|
|
28
|
-
* const
|
|
26
|
+
* // VaultV1 (MetaMorpho)
|
|
27
|
+
* const vaultV1 = client.morpho.vaultV1('0x...', 1);
|
|
28
|
+
* const depositV1 = await vaultV1.deposit({ amount: 1000000000000000000n, userAddress: '0x...' });
|
|
29
|
+
*
|
|
30
|
+
* // VaultV2
|
|
31
|
+
* const vaultV2 = client.morpho.vaultV2('0x...', 1);
|
|
29
32
|
* ```
|
|
30
33
|
*/
|
|
31
34
|
function morphoViemExtension(_options) {
|
package/lib/entities/index.d.ts
CHANGED
package/lib/entities/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./vaultV1"), exports);
|
|
17
18
|
__exportStar(require("./vaultV2"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./vaultV1";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./vaultV1"), exports);
|