From a2ede909610d4cc67418d41e0c715ce7cf484745 Mon Sep 17 00:00:00 2001 From: limitofzero Date: Sun, 19 Nov 2023 20:19:33 +0400 Subject: [PATCH] fix(permit2): correct primary type for eip712 object --- src/e2e/permit2.utils.test.ts | 4 ++-- src/eip-2612-permit.helper.ts | 17 +++++++---------- src/model/eip712-permit2.model.ts | 10 ++++++++++ src/permit2.utils.ts | 7 ++++++- 4 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 src/model/eip712-permit2.model.ts diff --git a/src/e2e/permit2.utils.test.ts b/src/e2e/permit2.utils.test.ts index f1d0ae8..49b92f4 100644 --- a/src/e2e/permit2.utils.test.ts +++ b/src/e2e/permit2.utils.test.ts @@ -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"; @@ -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; diff --git a/src/eip-2612-permit.helper.ts b/src/eip-2612-permit.helper.ts index 082a73f..ecd3ddc 100644 --- a/src/eip-2612-permit.helper.ts +++ b/src/eip-2612-permit.helper.ts @@ -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( input: null | undefined | T @@ -47,17 +48,13 @@ export function buildPermitTypedData(data: PermitTypedDataParamsModel): EIP712Ty export function buildPermit2TypedData( { domain, types, values }: ReturnType, -): 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} { diff --git a/src/model/eip712-permit2.model.ts b/src/model/eip712-permit2.model.ts new file mode 100644 index 0000000..71b77d0 --- /dev/null +++ b/src/model/eip712-permit2.model.ts @@ -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; + domain: TypedDataDomain; + message: PermitSingle | PermitBatchData; + primaryType: string; +} & EIP712TypedData; diff --git a/src/permit2.utils.ts b/src/permit2.utils.ts index 9b80aba..d295221 100644 --- a/src/permit2.utils.ts +++ b/src/permit2.utils.ts @@ -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) @@ -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,