@morpho-org/consumer-sdk 0.1.5 → 0.1.6
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.
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { type Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Client } from "viem";
|
|
3
3
|
import { type ERC20ApprovalAction, type Requirement, type Transaction } from "../../types";
|
|
4
|
+
type GetRequirementsBaseParams = {
|
|
5
|
+
address: Address;
|
|
6
|
+
chainId: number;
|
|
7
|
+
args: {
|
|
8
|
+
amount: bigint;
|
|
9
|
+
from: Address;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type GetRequirementsParams = (GetRequirementsBaseParams & {
|
|
13
|
+
/** Signature-based approvals are not supported. Classic approval (transaction) will be used. */
|
|
14
|
+
supportSignature: false;
|
|
15
|
+
}) | (GetRequirementsBaseParams & {
|
|
16
|
+
/** Signature-based approvals are supported. Will try permit (EIP-2612), else fallback to permit2. */
|
|
17
|
+
supportSignature: true;
|
|
18
|
+
/** Allow simple permit if EIP-2612 is supported. Only applicable when `supportSignature` is `true`. */
|
|
19
|
+
useSimplePermit?: boolean;
|
|
20
|
+
});
|
|
4
21
|
/**
|
|
5
22
|
* Get token "requirement" for approval/permit before interacting with protocol.
|
|
6
23
|
*
|
|
@@ -15,15 +32,9 @@ import { type ERC20ApprovalAction, type Requirement, type Transaction } from "..
|
|
|
15
32
|
* @param params.args - Object with:
|
|
16
33
|
* @param params.args.amount - Required token amount.
|
|
17
34
|
* @param params.args.from - The account that will grant approval.
|
|
18
|
-
* @param supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
35
|
+
* @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
36
|
+
* @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
|
|
19
37
|
* @returns Promise of array of approval transaction or requirement objects.
|
|
20
38
|
*/
|
|
21
|
-
export declare const getRequirements: (viemClient: Client, params:
|
|
22
|
-
|
|
23
|
-
chainId: number;
|
|
24
|
-
supportSignature: boolean;
|
|
25
|
-
args: {
|
|
26
|
-
amount: bigint;
|
|
27
|
-
from: Address;
|
|
28
|
-
};
|
|
29
|
-
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
39
|
+
export declare const getRequirements: (viemClient: Client, params: GetRequirementsParams) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
40
|
+
export {};
|
|
@@ -22,7 +22,8 @@ const getRequirementsPermit2_1 = require("./getRequirementsPermit2");
|
|
|
22
22
|
* @param params.args - Object with:
|
|
23
23
|
* @param params.args.amount - Required token amount.
|
|
24
24
|
* @param params.args.from - The account that will grant approval.
|
|
25
|
-
* @param supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
25
|
+
* @param params.supportSignature - Whether signature-based approvals are supported. If true, will try to use permit or permit2.
|
|
26
|
+
* @param params.useSimplePermit - use simple permit if EIP-2612 is supported. Only available when `supportSignature` is `true`.
|
|
26
27
|
* @returns Promise of array of approval transaction or requirement objects.
|
|
27
28
|
*/
|
|
28
29
|
const getRequirements = async (viemClient, params) => {
|
|
@@ -33,8 +34,9 @@ const getRequirements = async (viemClient, params) => {
|
|
|
33
34
|
const { permit2, dai, bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
34
35
|
const { erc20Allowances, erc2612Nonce, permit2BundlerAllowance } = await (0, blue_sdk_viem_1.fetchHolding)(from, address, viemClient);
|
|
35
36
|
if (supportSignature) {
|
|
37
|
+
const { useSimplePermit } = params;
|
|
36
38
|
const supportSimplePermit = (0, morpho_ts_1.isDefined)(erc2612Nonce) && address !== dai;
|
|
37
|
-
if (supportSimplePermit) {
|
|
39
|
+
if (supportSimplePermit && useSimplePermit) {
|
|
38
40
|
return await (0, getRequirementsPermit_1.getRequirementsPermit)(viemClient, {
|
|
39
41
|
token: address,
|
|
40
42
|
chainId,
|
|
@@ -32,7 +32,9 @@ export interface VaultV2Actions {
|
|
|
32
32
|
slippageTolerance?: bigint;
|
|
33
33
|
}) => Promise<{
|
|
34
34
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
35
|
-
getRequirements: (
|
|
35
|
+
getRequirements: (params?: {
|
|
36
|
+
useSimplePermit?: boolean;
|
|
37
|
+
}) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
|
|
36
38
|
}>;
|
|
37
39
|
/**
|
|
38
40
|
* Prepares a withdraw transaction for the VaultV2 contract.
|
|
@@ -80,7 +82,9 @@ export declare class MorphoVaultV2 implements VaultV2Actions {
|
|
|
80
82
|
userAddress: Address;
|
|
81
83
|
slippageTolerance?: bigint;
|
|
82
84
|
}): Promise<{
|
|
83
|
-
getRequirements: (
|
|
85
|
+
getRequirements: (params?: {
|
|
86
|
+
useSimplePermit?: boolean;
|
|
87
|
+
}) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
|
|
84
88
|
buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<VaultV2DepositAction>>;
|
|
85
89
|
}>;
|
|
86
90
|
withdraw({ assets, userAddress }: {
|
|
@@ -28,10 +28,11 @@ class MorphoVaultV2 {
|
|
|
28
28
|
});
|
|
29
29
|
const maxSharePrice = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.mulDivUp(assets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD + slippageTolerance), vaultData.toShares(assets)), blue_sdk_1.MathLib.RAY * 100n);
|
|
30
30
|
return {
|
|
31
|
-
getRequirements: async () => await (0, actions_1.getRequirements)(this.client.viemClient, {
|
|
31
|
+
getRequirements: async (params) => await (0, actions_1.getRequirements)(this.client.viemClient, {
|
|
32
32
|
address: vaultData.asset,
|
|
33
33
|
chainId: this.chainId,
|
|
34
34
|
supportSignature: this.client.options.supportSignature,
|
|
35
|
+
useSimplePermit: params?.useSimplePermit,
|
|
35
36
|
args: {
|
|
36
37
|
amount: assets,
|
|
37
38
|
from: userAddress,
|
package/package.json
CHANGED