Skip to content

Commit 62c3563

Browse files
committed
fix: permitBatch can be used by viem and ethers
1 parent f4f3a18 commit 62c3563

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

src/types/utils/preparePermit2BatchData.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { PermitBatch } from "@uniswap/permit2-sdk";
22
import type { BatchPermitOptions } from "@uniswap/v4-sdk";
3-
import type { TypedDataDomain, TypedDataField } from "ethers";
3+
import type { TypedDataField } from "ethers";
44
import type { Address, Hex } from "viem";
55

66
/**
@@ -32,10 +32,19 @@ export interface PreparePermit2BatchDataResult {
3232
/** Data needed to sign the permit2 batch data */
3333
toSign: {
3434
/** Domain of the permit2 batch data */
35-
domain: TypedDataDomain;
35+
domain: {
36+
name: string;
37+
version: string;
38+
chainId: number;
39+
verifyingContract: `0x${string}`;
40+
};
3641
/** Types of the permit2 batch data */
3742
types: Record<string, TypedDataField[]>;
3843
/** Values of the permit2 batch data */
3944
values: PermitBatch;
45+
/** Primary type of the permit2 batch data */
46+
primaryType: "PermitBatch";
47+
/** Message of the permit2 batch data */
48+
message: Record<string, unknown>;
4049
};
4150
}

src/utils/preparePermit2BatchData.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ import {
1010
type PermitBatch,
1111
} from "@uniswap/permit2-sdk";
1212
import type { BatchPermitOptions } from "@uniswap/v4-sdk";
13-
import type { TypedDataDomain, TypedDataField } from "ethers";
14-
import { zeroAddress } from "viem";
15-
import type { Hex } from "viem/_types/types/misc";
16-
17-
/**
13+
import type { TypedDataField } from "ethers";
14+
import type { Hex } from "viem";
15+
import { zeroAddress } from "viem"; /**
1816
* Prepares the permit2 batch data for multiple tokens
1917
*
2018
* This function creates a batch permit that allows a spender to use multiple tokens
2119
* on behalf of the user. It fetches current allowance details for each token and
22-
* prepares the data needed for signing.
20+
* prepares the data needed for signing. You can use with viem or ethers.
2321
*
2422
* The complete flow to use this function is:
2523
* 1. Prepare the permit data:
@@ -33,10 +31,14 @@ import type { Hex } from "viem/_types/types/misc";
3331
*
3432
* 2. Sign the permit data using your signer:
3533
* ```typescript
34+
* // viem
35+
* const signature = await signer._signTypedData(permitData.toSign)
36+
*
37+
* // ethers
3638
* const signature = await signer.signTypedData(
3739
* permitData.toSign.domain,
3840
* permitData.toSign.types,
39-
* permitData.toSign.values
41+
* permitData.toSign.values,
4042
* )
4143
* ```
4244
*
@@ -135,7 +137,7 @@ export async function preparePermit2BatchData(
135137
PERMIT2_ADDRESS,
136138
chainId,
137139
) as {
138-
domain: TypedDataDomain;
140+
domain: PreparePermit2BatchDataResult["toSign"]["domain"];
139141
types: Record<string, TypedDataField[]>;
140142
values: PermitBatch;
141143
};
@@ -158,6 +160,8 @@ export async function preparePermit2BatchData(
158160
domain,
159161
types,
160162
values,
163+
primaryType: "PermitBatch",
164+
message: values as unknown as Record<string, unknown>,
161165
},
162166
};
163167
}

0 commit comments

Comments
 (0)