@morpho-org/consumer-sdk 0.1.3 → 0.1.4
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 +2 -1
- package/lib/actions/requirements/encode/encodeErc20Permit.js +5 -2
- package/lib/actions/requirements/getRequirements.js +2 -2
- package/lib/actions/requirements/getRequirementsPermit.d.ts +6 -5
- package/lib/actions/requirements/getRequirementsPermit.js +6 -5
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { type Client } from "viem";
|
|
2
3
|
import { type Requirement } from "../../../types";
|
|
3
4
|
interface EncodeErc20PermitParams {
|
|
4
5
|
token: Address;
|
|
@@ -7,5 +8,5 @@ interface EncodeErc20PermitParams {
|
|
|
7
8
|
chainId: number;
|
|
8
9
|
nonce: bigint;
|
|
9
10
|
}
|
|
10
|
-
export declare const encodeErc20Permit: (params: EncodeErc20PermitParams) => Requirement
|
|
11
|
+
export declare const encodeErc20Permit: (viemClient: Client, params: EncodeErc20PermitParams) => Promise<Requirement>;
|
|
11
12
|
export {};
|
|
@@ -6,10 +6,14 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
8
|
const types_1 = require("../../../types");
|
|
9
|
-
const encodeErc20Permit = (params) => {
|
|
9
|
+
const encodeErc20Permit = async (viemClient, params) => {
|
|
10
10
|
const { token, spender, amount, chainId, nonce } = params;
|
|
11
|
+
if (viemClient.chain?.id !== chainId) {
|
|
12
|
+
throw new types_1.ChainIdMismatchError(viemClient.chain?.id, chainId);
|
|
13
|
+
}
|
|
11
14
|
const now = morpho_ts_1.Time.timestamp();
|
|
12
15
|
const deadline = now + morpho_ts_1.Time.s.from.h(2n);
|
|
16
|
+
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, viemClient);
|
|
13
17
|
const action = {
|
|
14
18
|
type: "permit",
|
|
15
19
|
args: {
|
|
@@ -27,7 +31,6 @@ const encodeErc20Permit = (params) => {
|
|
|
27
31
|
if (client.account.address !== userAddress) {
|
|
28
32
|
throw new types_1.AddressMismatchError(client.account.address, userAddress);
|
|
29
33
|
}
|
|
30
|
-
const tokenData = await (0, blue_sdk_viem_1.fetchToken)(token, client);
|
|
31
34
|
const typedData = (0, blue_sdk_viem_1.getPermitTypedData)({
|
|
32
35
|
erc20: tokenData,
|
|
33
36
|
owner: userAddress,
|
|
@@ -35,8 +35,8 @@ const getRequirements = async (viemClient, params) => {
|
|
|
35
35
|
if (supportSignature) {
|
|
36
36
|
const supportSimplePermit = (0, morpho_ts_1.isDefined)(erc2612Nonce) && address !== dai;
|
|
37
37
|
if (supportSimplePermit) {
|
|
38
|
-
return (0, getRequirementsPermit_1.getRequirementsPermit)({
|
|
39
|
-
address,
|
|
38
|
+
return await (0, getRequirementsPermit_1.getRequirementsPermit)(viemClient, {
|
|
39
|
+
token: address,
|
|
40
40
|
chainId,
|
|
41
41
|
args: { amount },
|
|
42
42
|
allowancesGeneralAdapter: erc20Allowances["bundler3.generalAdapter1"],
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
2
|
/**
|
|
3
3
|
* Get token "requirement" for permit (EIP-2612).
|
|
4
4
|
*
|
|
5
5
|
* Verify if the allowance is enough on general adapter from permit (EIP-2612) contract.
|
|
6
6
|
* => If not, approve the token to general adapter from permit via EIP-2612 with permit signature on the required amount.
|
|
7
7
|
*
|
|
8
|
+
* @param viemClient - The viem Client instance
|
|
8
9
|
* @param params - Destructured object with:
|
|
9
|
-
* @param params.
|
|
10
|
+
* @param params.token - ERC20 token.
|
|
10
11
|
* @param params.chainId - Chain/network id.
|
|
11
12
|
* @param params.args - Object with:
|
|
12
13
|
* @param params.args.amount - Required token amount.
|
|
@@ -14,12 +15,12 @@ import { type Address } from "@morpho-org/blue-sdk";
|
|
|
14
15
|
* @param params.nonce - Nonce for permit (EIP-2612).
|
|
15
16
|
* @returns An array of requirement signature object.
|
|
16
17
|
*/
|
|
17
|
-
export declare const getRequirementsPermit: (params: {
|
|
18
|
-
|
|
18
|
+
export declare const getRequirementsPermit: (viemClient: Client, params: {
|
|
19
|
+
token: Address;
|
|
19
20
|
chainId: number;
|
|
20
21
|
args: {
|
|
21
22
|
amount: bigint;
|
|
22
23
|
};
|
|
23
24
|
allowancesGeneralAdapter: bigint;
|
|
24
25
|
nonce: bigint;
|
|
25
|
-
}) => import("../..").Requirement[]
|
|
26
|
+
}) => Promise<import("../..").Requirement[]>;
|
|
@@ -9,8 +9,9 @@ const encode_1 = require("./encode");
|
|
|
9
9
|
* Verify if the allowance is enough on general adapter from permit (EIP-2612) contract.
|
|
10
10
|
* => If not, approve the token to general adapter from permit via EIP-2612 with permit signature on the required amount.
|
|
11
11
|
*
|
|
12
|
+
* @param viemClient - The viem Client instance
|
|
12
13
|
* @param params - Destructured object with:
|
|
13
|
-
* @param params.
|
|
14
|
+
* @param params.token - ERC20 token.
|
|
14
15
|
* @param params.chainId - Chain/network id.
|
|
15
16
|
* @param params.args - Object with:
|
|
16
17
|
* @param params.args.amount - Required token amount.
|
|
@@ -18,13 +19,13 @@ const encode_1 = require("./encode");
|
|
|
18
19
|
* @param params.nonce - Nonce for permit (EIP-2612).
|
|
19
20
|
* @returns An array of requirement signature object.
|
|
20
21
|
*/
|
|
21
|
-
const getRequirementsPermit = (params) => {
|
|
22
|
-
const {
|
|
22
|
+
const getRequirementsPermit = async (viemClient, params) => {
|
|
23
|
+
const { token, chainId, args: { amount }, allowancesGeneralAdapter, nonce, } = params;
|
|
23
24
|
const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
24
25
|
if (allowancesGeneralAdapter < amount) {
|
|
25
26
|
return [
|
|
26
|
-
(0, encode_1.encodeErc20Permit)({
|
|
27
|
-
token
|
|
27
|
+
await (0, encode_1.encodeErc20Permit)(viemClient, {
|
|
28
|
+
token,
|
|
28
29
|
spender: generalAdapter1,
|
|
29
30
|
amount,
|
|
30
31
|
chainId,
|
package/package.json
CHANGED