Skip to content

Commit

Permalink
fix(permit2): correct primary type for eip712 object
Browse files Browse the repository at this point in the history
  • Loading branch information
limitofzero committed Nov 19, 2023
1 parent cc13867 commit a2ede90
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/e2e/permit2.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deploySwapTokens } from "./helpers/fixtures";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { Permit2Utils } from "../permit2.utils";
import { getProviderConnector, Signer } from "./helpers/provider-connector.mock";
import { PERMIT2_ADDRESS } from "@uniswap/permit2-sdk";
import { MaxUint256, PERMIT2_ADDRESS } from "@uniswap/permit2-sdk";
import { expect } from 'chai';
import { decodeUncompressedPermitSingle } from "./helpers/decode-uncompressed-permit-single";
import { createPermit2ContractAndDeploy } from "./helpers/create-permit2-contract-and-deployt";
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('permit2', () => {
});

it('set expiry & sigDeadline', async () => {
await dai.connect(addr1).approve(PERMIT2_ADDRESS, 2);
await dai.connect(addr1).approve(PERMIT2_ADDRESS, MaxUint256.toBigInt());

const deadline = Math.round((Date.now() / 1000)) + 3000;

Expand Down
17 changes: 7 additions & 10 deletions src/eip-2612-permit.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EIP712Object, EIP712TypedData } from './model/eip712.model';
import { DaiPermitParams, PermitParams } from './model/permit.model';
import {PermitTypedDataParamsModel} from './model/permit-typed-data-params.model';
import { AllowanceTransfer } from "@uniswap/permit2-sdk";
import { Eip712Permit2 } from "./model/eip712-permit2.model";

export function inputIsNotNullOrUndefined<T>(
input: null | undefined | T
Expand Down Expand Up @@ -47,17 +48,13 @@ export function buildPermitTypedData(data: PermitTypedDataParamsModel): EIP712Ty

export function buildPermit2TypedData(
{ domain, types, values }: ReturnType<typeof AllowanceTransfer.getPermitData>,
): EIP712TypedData {
// todo support batch of data
const PrimaryType = 'PermitSingleData';

): Eip712Permit2 {
return {
// todo resolve problem with types
types: types as never,
primaryType: PrimaryType,
domain: domain as never,
message: values as never,
};
primaryType: 'PermitSingle',
types: types,
domain: domain,
message: values,
} as Eip712Permit2;
}

export function fromRpcSig(sig: string): {v: number; r: Buffer; s: Buffer} {
Expand Down
10 changes: 10 additions & 0 deletions src/model/eip712-permit2.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { EIP712TypedData } from "./eip712.model";
import { TypedDataDomain, TypedDataField } from "@ethersproject/abstract-signer";
import { PermitBatchData, PermitSingle } from "@uniswap/permit2-sdk/dist/allowanceTransfer";

export type Eip712Permit2 = {
types: Record<string, TypedDataField[]>;
domain: TypedDataDomain;
message: PermitSingle | PermitBatchData;
primaryType: string;
} & EIP712TypedData;
7 changes: 6 additions & 1 deletion src/permit2.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { compressPermit } from "./helpers/compress-permit";
import { decompressPermit } from "./helpers/decompress-permit";
import { MAX_UINT48 } from "./helpers/constants";
import { trim0x } from "./helpers/trim-0x";

function cutSelector(data: string): string {
const hexPrefix = '0x'
return hexPrefix + data.substr(hexPrefix.length + 8)
Expand All @@ -26,6 +25,12 @@ export interface Permit2Params {
compact?: boolean;
}

export interface AllowanceResponse {
amount: bigint;
expiration: number;
nonce: bigint;
}

export class Permit2Utils {
constructor(
private connector: ProviderConnector,
Expand Down

0 comments on commit a2ede90

Please sign in to comment.