@morpho-org/consumer-sdk 0.1.7 → 0.2.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/lib/actions/requirements/encode/encodeErc20Permit.d.ts +1 -0
- package/lib/actions/requirements/encode/encodeErc20Permit.js +4 -2
- package/lib/actions/requirements/getRequirements.d.ts +2 -0
- package/lib/actions/requirements/getRequirements.js +5 -1
- package/lib/actions/requirements/getRequirementsAction.d.ts +5 -2
- package/lib/actions/requirements/getRequirementsAction.js +11 -13
- package/lib/actions/requirements/getRequirementsPermit.d.ts +2 -0
- package/lib/actions/requirements/getRequirementsPermit.js +3 -1
- package/lib/actions/vaultV2/deposit.js +6 -1
- package/lib/client/morphoClient.d.ts +3 -0
- package/lib/client/morphoClient.js +1 -0
- package/lib/client/morphoViemExtension.d.ts +5 -2
- package/lib/client/morphoViemExtension.js +2 -0
- package/lib/entities/vaultV2/vaultV2.d.ts +7 -5
- package/lib/entities/vaultV2/vaultV2.js +20 -2
- package/lib/helpers/constant.d.ts +1 -0
- package/lib/helpers/constant.js +5 -0
- package/lib/types/client.d.ts +1 -0
- package/lib/types/data.d.ts +2 -0
- package/lib/types/data.js +2 -0
- package/lib/types/error.d.ts +9 -0
- package/lib/types/error.js +19 -1
- package/package.json +1 -1
|
@@ -7,13 +7,15 @@ const viem_1 = require("viem");
|
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
8
|
const types_1 = require("../../../types");
|
|
9
9
|
const encodeErc20Permit = async (viemClient, params) => {
|
|
10
|
-
const { token, spender, amount, chainId, nonce } = params;
|
|
10
|
+
const { token, spender, amount, chainId, nonce, supportDeployless } = params;
|
|
11
11
|
if (viemClient.chain?.id !== chainId) {
|
|
12
12
|
throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
13
13
|
}
|
|
14
14
|
const now = morpho_ts_1.Time.timestamp();
|
|
15
15
|
const deadline = now + morpho_ts_1.Time.s.from.h(2n);
|
|
16
|
-
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient
|
|
16
|
+
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient, {
|
|
17
|
+
deployless: supportDeployless,
|
|
18
|
+
});
|
|
17
19
|
const action = {
|
|
18
20
|
type: "permit",
|
|
19
21
|
args: {
|
|
@@ -4,6 +4,7 @@ import { type ERC20ApprovalAction, type Requirement, type Transaction } from "..
|
|
|
4
4
|
type GetRequirementsBaseParams = {
|
|
5
5
|
address: Address;
|
|
6
6
|
chainId: number;
|
|
7
|
+
supportDeployless?: boolean;
|
|
7
8
|
args: {
|
|
8
9
|
amount: bigint;
|
|
9
10
|
from: Address;
|
|
@@ -33,6 +34,7 @@ type GetRequirementsParams = (GetRequirementsBaseParams & {
|
|
|
33
34
|
* @param params.args.amount - Required token amount.
|
|
34
35
|
* @param params.args.from - The account that will grant approval.
|
|
35
36
|
* @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
37
|
+
* @param params.supportDeployless - Whether to use deployless mode.
|
|
36
38
|
* @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
|
|
37
39
|
* @returns Promise of array of approval transaction or requirement objects.
|
|
38
40
|
*/
|
|
@@ -23,6 +23,7 @@ const getRequirementsPermit2_1 = require("./getRequirementsPermit2");
|
|
|
23
23
|
* @param params.args.amount - Required token amount.
|
|
24
24
|
* @param params.args.from - The account that will grant approval.
|
|
25
25
|
* @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
26
|
+
* @param params.supportDeployless - Whether to use deployless mode.
|
|
26
27
|
* @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
|
|
27
28
|
* @returns Promise of array of approval transaction or requirement objects.
|
|
28
29
|
*/
|
|
@@ -32,7 +33,9 @@ const getRequirements = async (viemClient, params) => {
|
|
|
32
33
|
throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
33
34
|
}
|
|
34
35
|
const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
35
|
-
const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient
|
|
36
|
+
const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient, {
|
|
37
|
+
deployless: params.supportDeployless,
|
|
38
|
+
});
|
|
36
39
|
if (supportSignature) {
|
|
37
40
|
const { useSimplePermit } = params;
|
|
38
41
|
const supportSimplePermit = (0, morpho_ts_1.isDefined)(erc2612Nonce) && address !== dai;
|
|
@@ -43,6 +46,7 @@ const getRequirements = async (viemClient, params) => {
|
|
|
43
46
|
args: { amount },
|
|
44
47
|
allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
|
|
45
48
|
nonce: erc2612Nonce,
|
|
49
|
+
supportDeployless: params.supportDeployless,
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
if (permit2) {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Action } from "@morpho-org/bundler-sdk-viem";
|
|
2
|
-
import
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type Permit2Action, type PermitAction, type PermitArgs } from "../../types";
|
|
3
4
|
interface GetRequirementsActionParams {
|
|
4
5
|
chainId: number;
|
|
6
|
+
asset: Address;
|
|
7
|
+
assets: bigint;
|
|
5
8
|
requirementSignature: {
|
|
6
9
|
args: PermitArgs;
|
|
7
10
|
action: PermitAction | Permit2Action;
|
|
@@ -10,5 +13,5 @@ interface GetRequirementsActionParams {
|
|
|
10
13
|
/**
|
|
11
14
|
* Get the actions required to transfer the asset based on the requirement signature.
|
|
12
15
|
*/
|
|
13
|
-
export declare const getRequirementsAction: ({ chainId, requirementSignature, }: GetRequirementsActionParams) => Action[];
|
|
16
|
+
export declare const getRequirementsAction: ({ chainId, asset, assets, requirementSignature, }: GetRequirementsActionParams) => Action[];
|
|
14
17
|
export {};
|
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRequirementsAction = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const types_1 = require("../../types");
|
|
5
7
|
/**
|
|
6
8
|
* Get the actions required to transfer the asset based on the requirement signature.
|
|
7
9
|
*/
|
|
8
|
-
const getRequirementsAction = ({ chainId, requirementSignature, }) => {
|
|
10
|
+
const getRequirementsAction = ({ chainId, asset, assets, requirementSignature, }) => {
|
|
11
|
+
if (!(0, viem_1.isAddressEqual)(requirementSignature.args.asset, asset)) {
|
|
12
|
+
throw new types_1.DepositAssetMismatchError(asset, requirementSignature.args.asset);
|
|
13
|
+
}
|
|
14
|
+
if (requirementSignature.args.amount !== assets) {
|
|
15
|
+
throw new types_1.DepositAmountMismatchError(assets, requirementSignature.args.amount);
|
|
16
|
+
}
|
|
9
17
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
10
18
|
if (requirementSignature.action.type === "permit2") {
|
|
11
19
|
if (!("expiration" in requirementSignature.args)) {
|
|
@@ -31,12 +39,7 @@ const getRequirementsAction = ({ chainId, requirementSignature, }) => {
|
|
|
31
39
|
},
|
|
32
40
|
{
|
|
33
41
|
type: "transferFrom2",
|
|
34
|
-
args: [
|
|
35
|
-
requirementSignature.args.asset,
|
|
36
|
-
requirementSignature.args.amount,
|
|
37
|
-
generalAdapter1,
|
|
38
|
-
false,
|
|
39
|
-
],
|
|
42
|
+
args: [asset, assets, generalAdapter1, false],
|
|
40
43
|
},
|
|
41
44
|
];
|
|
42
45
|
}
|
|
@@ -54,12 +57,7 @@ const getRequirementsAction = ({ chainId, requirementSignature, }) => {
|
|
|
54
57
|
},
|
|
55
58
|
{
|
|
56
59
|
type: "erc20TransferFrom",
|
|
57
|
-
args: [
|
|
58
|
-
requirementSignature.args.asset,
|
|
59
|
-
requirementSignature.args.amount,
|
|
60
|
-
generalAdapter1,
|
|
61
|
-
false,
|
|
62
|
-
],
|
|
60
|
+
args: [asset, assets, generalAdapter1, false],
|
|
63
61
|
},
|
|
64
62
|
];
|
|
65
63
|
};
|
|
@@ -13,6 +13,7 @@ import type { Address, Client } from "viem";
|
|
|
13
13
|
* @param params.args.amount - Required token amount.
|
|
14
14
|
* @param params.allowancesGeneralAdapter - Allowance for general adapter from permit contract.
|
|
15
15
|
* @param params.nonce - Nonce for permit (EIP-2612).
|
|
16
|
+
* @param params.supportDeployless - Whether to use deployless mode.
|
|
16
17
|
* @returns An array of requirement signature object.
|
|
17
18
|
*/
|
|
18
19
|
export declare const getRequirementsPermit: (viemClient: Client, params: {
|
|
@@ -23,4 +24,5 @@ export declare const getRequirementsPermit: (viemClient: Client, params: {
|
|
|
23
24
|
};
|
|
24
25
|
allowancesGeneralAdapter: bigint;
|
|
25
26
|
nonce: bigint;
|
|
27
|
+
supportDeployless?: boolean;
|
|
26
28
|
}) => Promise<import("../..").Requirement[]>;
|
|
@@ -17,10 +17,11 @@ const encode_1 = require("./encode");
|
|
|
17
17
|
* @param params.args.amount - Required token amount.
|
|
18
18
|
* @param params.allowancesGeneralAdapter - Allowance for general adapter from permit contract.
|
|
19
19
|
* @param params.nonce - Nonce for permit (EIP-2612).
|
|
20
|
+
* @param params.supportDeployless - Whether to use deployless mode.
|
|
20
21
|
* @returns An array of requirement signature object.
|
|
21
22
|
*/
|
|
22
23
|
const getRequirementsPermit = async (viemClient, params) => {
|
|
23
|
-
const { token, chainId, args: { amount }, allowancesGeneralAdapter, nonce, } = params;
|
|
24
|
+
const { token, chainId, args: { amount }, allowancesGeneralAdapter, nonce, supportDeployless, } = params;
|
|
24
25
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
25
26
|
if (allowancesGeneralAdapter < amount) {
|
|
26
27
|
return [
|
|
@@ -30,6 +31,7 @@ const getRequirementsPermit = async (viemClient, params) => {
|
|
|
30
31
|
amount,
|
|
31
32
|
chainId,
|
|
32
33
|
nonce,
|
|
34
|
+
supportDeployless,
|
|
33
35
|
}),
|
|
34
36
|
];
|
|
35
37
|
}
|
|
@@ -45,7 +45,12 @@ const vaultV2Deposit = ({ vault: { chainId, address: vaultAddress, asset }, args
|
|
|
45
45
|
}
|
|
46
46
|
const actions = [];
|
|
47
47
|
if (requirementSignature) {
|
|
48
|
-
actions.push(...(0, getRequirementsAction_1.getRequirementsAction)({
|
|
48
|
+
actions.push(...(0, getRequirementsAction_1.getRequirementsAction)({
|
|
49
|
+
chainId,
|
|
50
|
+
asset,
|
|
51
|
+
assets,
|
|
52
|
+
requirementSignature,
|
|
53
|
+
}));
|
|
49
54
|
}
|
|
50
55
|
else {
|
|
51
56
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
@@ -5,14 +5,17 @@ export declare class MorphoClient implements MorphoClientType {
|
|
|
5
5
|
readonly viemClient: Client;
|
|
6
6
|
readonly _options?: {
|
|
7
7
|
readonly supportSignature?: boolean;
|
|
8
|
+
readonly supportDeployless?: boolean;
|
|
8
9
|
readonly metadata?: Metadata;
|
|
9
10
|
} | undefined;
|
|
10
11
|
readonly options: {
|
|
11
12
|
readonly supportSignature: boolean;
|
|
13
|
+
readonly supportDeployless?: boolean;
|
|
12
14
|
readonly metadata?: Metadata;
|
|
13
15
|
};
|
|
14
16
|
constructor(viemClient: Client, _options?: {
|
|
15
17
|
readonly supportSignature?: boolean;
|
|
18
|
+
readonly supportDeployless?: boolean;
|
|
16
19
|
readonly metadata?: Metadata;
|
|
17
20
|
} | undefined);
|
|
18
21
|
vaultV2(vault: Address, chainId: number): MorphoVaultV2;
|
|
@@ -6,6 +6,8 @@ import { MorphoClient } from "./morphoClient";
|
|
|
6
6
|
* Adds `morpho` namespace to viem clients with vaultV2 actions.
|
|
7
7
|
*
|
|
8
8
|
* @param metadata - (Optional) Metadata object that will be passed to all morpho actions. If provided, this metadata can be used for analytics, logging, or to carry additional information with each action.
|
|
9
|
+
* @param supportSignature - (Optional) Whether to support off-chain signature requirements. If true, the SDK will try to use permit or permit2 if the token supports it.
|
|
10
|
+
* @param supportDeployless - (Optional) Whether to support deployless mode. If true, the SDK will use the deployless mode to fetch data.
|
|
9
11
|
* @returns Extension function that adds morpho namespace to viem clients
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
@@ -26,8 +28,9 @@ import { MorphoClient } from "./morphoClient";
|
|
|
26
28
|
* ```
|
|
27
29
|
*/
|
|
28
30
|
export declare function morphoViemExtension(_options?: {
|
|
29
|
-
metadata?: Metadata;
|
|
30
|
-
supportSignature?: boolean;
|
|
31
|
+
readonly metadata?: Metadata;
|
|
32
|
+
readonly supportSignature?: boolean;
|
|
33
|
+
readonly supportDeployless?: boolean;
|
|
31
34
|
}): <TClient extends Client>(client: TClient) => {
|
|
32
35
|
morpho: MorphoClient;
|
|
33
36
|
};
|
|
@@ -7,6 +7,8 @@ const morphoClient_1 = require("./morphoClient");
|
|
|
7
7
|
* Adds `morpho` namespace to viem clients with vaultV2 actions.
|
|
8
8
|
*
|
|
9
9
|
* @param metadata - (Optional) Metadata object that will be passed to all morpho actions. If provided, this metadata can be used for analytics, logging, or to carry additional information with each action.
|
|
10
|
+
* @param supportSignature - (Optional) Whether to support off-chain signature requirements. If true, the SDK will try to use permit or permit2 if the token supports it.
|
|
11
|
+
* @param supportDeployless - (Optional) Whether to support deployless mode. If true, the SDK will use the deployless mode to fetch data.
|
|
10
12
|
* @returns Extension function that adds morpho namespace to viem clients
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
3
|
import { type ERC20ApprovalAction, type MorphoClientType, type Requirement, type RequirementSignature, type Transaction, type VaultV2DepositAction, type VaultV2RedeemAction, type VaultV2WithdrawAction } from "../../types";
|
|
4
|
+
import type { FetchParameters } from "../../types/data";
|
|
4
5
|
export interface VaultV2Actions {
|
|
5
6
|
/**
|
|
6
7
|
* Fetches the latest vault data.
|
|
7
8
|
*
|
|
8
9
|
* This function fetches the latest vault data from the blockchain.
|
|
10
|
+
* @param {FetchParameters} [parameters] - The parameters for the fetch operation.
|
|
9
11
|
*
|
|
10
12
|
* @returns {Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>} The latest vault data.
|
|
11
13
|
*/
|
|
12
|
-
getData: () => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
14
|
+
getData: (parameters?: FetchParameters) => Promise<Awaited<ReturnType<typeof fetchAccrualVaultV2>>>;
|
|
13
15
|
/**
|
|
14
16
|
* Prepares a deposit transaction for the VaultV2 contract.
|
|
15
17
|
*
|
|
@@ -21,7 +23,7 @@ export interface VaultV2Actions {
|
|
|
21
23
|
* @param {Object} params - The deposit parameters.
|
|
22
24
|
* @param {bigint} params.assets - The amount of assets to deposit.
|
|
23
25
|
* @param {Address} [params.userAddress] - Optional user address initiating the deposit. Default is the client's user address is used.
|
|
24
|
-
* @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%.
|
|
26
|
+
* @param {bigint} [params.slippageTolerance=DEFAULT_SLIPPAGE_TOLERANCE] - Optional slippage tolerance value. Default is 0.03%. Slippage tolerance must be less than 10%.
|
|
25
27
|
* @returns {Object} The result object.
|
|
26
28
|
* @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
|
|
27
29
|
* @returns {Promise<Readonly<Transaction<ERC20ApprovalAction>[]>>} returns.getRequirements The function for retrieving all required approval transactions.
|
|
@@ -43,7 +45,7 @@ export interface VaultV2Actions {
|
|
|
43
45
|
*
|
|
44
46
|
* @param {Object} params - The withdraw parameters.
|
|
45
47
|
* @param {bigint} params.assets - The amount of assets to withdraw.
|
|
46
|
-
* @param {Address}
|
|
48
|
+
* @param {Address} params.userAddress - User address initiating the withdraw.
|
|
47
49
|
* @returns {Object} The result object.
|
|
48
50
|
* @returns {Readonly<Transaction<VaultV2WithdrawAction>>} returns.tx The prepared withdraw transaction.
|
|
49
51
|
*/
|
|
@@ -60,7 +62,7 @@ export interface VaultV2Actions {
|
|
|
60
62
|
*
|
|
61
63
|
* @param {Object} params - The redeem parameters.
|
|
62
64
|
* @param {bigint} params.shares - The amount of shares to redeem.
|
|
63
|
-
* @param {Address}
|
|
65
|
+
* @param {Address} params.userAddress - User address initiating the redeem.
|
|
64
66
|
* @returns {Object} The result object.
|
|
65
67
|
* @returns {Readonly<Transaction<VaultV2RedeemAction>>} returns.tx The prepared redeem transaction.
|
|
66
68
|
*/
|
|
@@ -76,7 +78,7 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
76
78
|
private readonly vault;
|
|
77
79
|
private readonly chainId;
|
|
78
80
|
constructor(client: MorphoClientType, vault: Address, chainId: number);
|
|
79
|
-
getData(): Promise<import("@morpho-org/blue-sdk").AccrualVaultV2>;
|
|
81
|
+
getData(parameters?: FetchParameters): Promise<import("@morpho-org/blue-sdk").AccrualVaultV2>;
|
|
80
82
|
deposit({ assets, userAddress, slippageTolerance, }: {
|
|
81
83
|
assets: bigint;
|
|
82
84
|
userAddress: Address;
|
|
@@ -4,6 +4,7 @@ exports.MorphoVaultV2 = void 0;
|
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
6
6
|
const actions_1 = require("../../actions");
|
|
7
|
+
const constant_1 = require("../../helpers/constant");
|
|
7
8
|
const types_1 = require("../../types");
|
|
8
9
|
class MorphoVaultV2 {
|
|
9
10
|
client;
|
|
@@ -14,9 +15,11 @@ class MorphoVaultV2 {
|
|
|
14
15
|
this.vault = vault;
|
|
15
16
|
this.chainId = chainId;
|
|
16
17
|
}
|
|
17
|
-
async getData() {
|
|
18
|
+
async getData(parameters) {
|
|
18
19
|
return (0, blue_sdk_viem_1.fetchAccrualVaultV2)(this.vault, this.client.viemClient, {
|
|
20
|
+
...parameters,
|
|
19
21
|
chainId: this.chainId,
|
|
22
|
+
deployless: this.client.options.supportDeployless,
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
async deposit({ assets, userAddress, slippageTolerance = blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE, }) {
|
|
@@ -25,13 +28,22 @@ class MorphoVaultV2 {
|
|
|
25
28
|
}
|
|
26
29
|
const vaultData = await (0, blue_sdk_viem_1.fetchVaultV2)(this.vault, this.client.viemClient, {
|
|
27
30
|
chainId: this.chainId,
|
|
31
|
+
deployless: this.client.options.supportDeployless,
|
|
28
32
|
});
|
|
29
|
-
|
|
33
|
+
if (slippageTolerance > constant_1.MAX_SLIPPAGE_TOLERANCE) {
|
|
34
|
+
throw new types_1.ExcessiveSlippageToleranceError(slippageTolerance);
|
|
35
|
+
}
|
|
36
|
+
const shares = vaultData.toShares(assets);
|
|
37
|
+
if (shares === 0n) {
|
|
38
|
+
throw new types_1.ZeroSharesAmountError(this.vault);
|
|
39
|
+
}
|
|
40
|
+
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), shares), blue_sdk_1.MathLib.RAY * 100n);
|
|
30
41
|
return {
|
|
31
42
|
getRequirements: async (params) => await (0, actions_1.getRequirements)(this.client.viemClient, {
|
|
32
43
|
address: vaultData.asset,
|
|
33
44
|
chainId: this.chainId,
|
|
34
45
|
supportSignature: this.client.options.supportSignature,
|
|
46
|
+
supportDeployless: this.client.options.supportDeployless,
|
|
35
47
|
useSimplePermit: params?.useSimplePermit,
|
|
36
48
|
args: {
|
|
37
49
|
amount: assets,
|
|
@@ -55,6 +67,9 @@ class MorphoVaultV2 {
|
|
|
55
67
|
};
|
|
56
68
|
}
|
|
57
69
|
withdraw({ assets, userAddress }) {
|
|
70
|
+
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
71
|
+
throw new types_1.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
72
|
+
}
|
|
58
73
|
return {
|
|
59
74
|
buildTx: () => (0, actions_1.vaultV2Withdraw)({
|
|
60
75
|
vault: { address: this.vault },
|
|
@@ -68,6 +83,9 @@ class MorphoVaultV2 {
|
|
|
68
83
|
};
|
|
69
84
|
}
|
|
70
85
|
redeem({ shares, userAddress }) {
|
|
86
|
+
if (this.client.viemClient.chain?.id !== this.chainId) {
|
|
87
|
+
throw new types_1.ChainIdMismatchError(this.client.viemClient.chain?.id, this.chainId);
|
|
88
|
+
}
|
|
71
89
|
return {
|
|
72
90
|
buildTx: () => (0, actions_1.vaultV2Redeem)({
|
|
73
91
|
vault: { address: this.vault },
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
|
package/lib/types/client.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface MorphoClientType {
|
|
|
5
5
|
readonly viemClient: Client;
|
|
6
6
|
readonly options: {
|
|
7
7
|
readonly supportSignature: boolean;
|
|
8
|
+
readonly supportDeployless?: boolean;
|
|
8
9
|
readonly metadata?: Metadata;
|
|
9
10
|
};
|
|
10
11
|
vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
|
package/lib/types/error.d.ts
CHANGED
|
@@ -20,3 +20,12 @@ export declare class MissingClientPropertyError extends Error {
|
|
|
20
20
|
export declare class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
21
21
|
constructor();
|
|
22
22
|
}
|
|
23
|
+
export declare class ExcessiveSlippageToleranceError extends Error {
|
|
24
|
+
constructor(slippageTolerance: bigint);
|
|
25
|
+
}
|
|
26
|
+
export declare class DepositAmountMismatchError extends Error {
|
|
27
|
+
constructor(depositAmount: bigint, signatureAmount: bigint);
|
|
28
|
+
}
|
|
29
|
+
export declare class DepositAssetMismatchError extends Error {
|
|
30
|
+
constructor(depositAsset: Address, signatureAsset: Address);
|
|
31
|
+
}
|
package/lib/types/error.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.ZeroMaxSharePriceError = exports.ZeroSharesAmountError = exports.ZeroAssetAmountError = void 0;
|
|
3
|
+
exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.ExcessiveSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.ZeroMaxSharePriceError = exports.ZeroSharesAmountError = exports.ZeroAssetAmountError = void 0;
|
|
4
4
|
class ZeroAssetAmountError extends Error {
|
|
5
5
|
constructor(asset) {
|
|
6
6
|
super(`Asset amount cannot be zero for address: ${asset}`);
|
|
@@ -43,3 +43,21 @@ class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.ApprovalAmountLessThanSpendAmountError = ApprovalAmountLessThanSpendAmountError;
|
|
46
|
+
class ExcessiveSlippageToleranceError extends Error {
|
|
47
|
+
constructor(slippageTolerance) {
|
|
48
|
+
super(`Slippage tolerance ${slippageTolerance} exceeds maximum allowed (10%)`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ExcessiveSlippageToleranceError = ExcessiveSlippageToleranceError;
|
|
52
|
+
class DepositAmountMismatchError extends Error {
|
|
53
|
+
constructor(depositAmount, signatureAmount) {
|
|
54
|
+
super(`Deposit amount ${depositAmount} does not match requirement signature amount ${signatureAmount}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.DepositAmountMismatchError = DepositAmountMismatchError;
|
|
58
|
+
class DepositAssetMismatchError extends Error {
|
|
59
|
+
constructor(depositAsset, signatureAsset) {
|
|
60
|
+
super(`Deposit asset ${depositAsset} does not match requirement signature asset ${signatureAsset}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.DepositAssetMismatchError = DepositAssetMismatchError;
|
package/package.json
CHANGED