From e4e8eaef1d065cffdcb379b001c62d0fa971010e Mon Sep 17 00:00:00 2001 From: rndquu Date: Mon, 21 Oct 2024 15:29:46 +0300 Subject: [PATCH] fix: fix permit signer --- src/handlers/generate-erc20-permit.ts | 9 +-------- tests/generate-erc20-permit.test.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/handlers/generate-erc20-permit.ts b/src/handlers/generate-erc20-permit.ts index b4c00f2..35f1e1d 100644 --- a/src/handlers/generate-erc20-permit.ts +++ b/src/handlers/generate-erc20-permit.ts @@ -90,15 +90,8 @@ export async function generateErc20PermitSignature( const { domain, types, values } = SignatureTransfer.getPermitData(permitTransferFromData, PERMIT2_ADDRESS, evmNetworkId); - const domainData = { - name: domain.name, - version: domain.version || "1", // default to 1 if it's undefined - chainId: domain.chainId, - verifyingContract: domain.verifyingContract, - }; - try { - const signature = await adminWallet._signTypedData(domainData, types, values); + const signature = await adminWallet._signTypedData(domain, types, values); const erc20Permit: PermitReward = { tokenType: TokenType.ERC20, diff --git a/tests/generate-erc20-permit.test.ts b/tests/generate-erc20-permit.test.ts index 2cfe63e..a18f82d 100644 --- a/tests/generate-erc20-permit.test.ts +++ b/tests/generate-erc20-permit.test.ts @@ -68,10 +68,21 @@ describe("generateErc20PermitSignature", () => { const result = await generateErc20PermitSignature(context, SPENDER, amount, ERC20_REWARD_TOKEN_ADDRESS); - expect(result).toBeDefined(); - expect(result).not.toContain("Permit not generated"); - expect(result).toBeInstanceOf(Object); + const expectedResult = { + tokenType: 'ERC20', + tokenAddress: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', + beneficiary: '0xefC0e701A824943b469a694aC564Aa1efF7Ab7dd', + nonce: '28290789875493039658039458533958603742651083423638415458747066904844975862062', + deadline: '115792089237316195423570985008687907853269984665640564039457584007913129639935', + amount: '100000000000000000000', + owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', + signature: '0xad87653fb0ecf740c73b78a8f414cdd5b1ffb18670cde5a1d21c65e43d6bb2a36c5470c5529334dc11566f0c380889b734a8539d69ec74cc2abf37af0ea7a7781b', + networkId: 100 + }; + + expect(result).toEqual(expectedResult); expect(context.logger.info).toHaveBeenCalledWith("Generated ERC20 permit2 signature", expect.any(Object)); + }); it("should throw error when evmPrivateEncrypted is not defined", async () => {