From 978bfba334ec3fbee554b19744bc1d7ce865e8be Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Tue, 10 Dec 2024 20:23:40 +0100 Subject: [PATCH] fix(zksync): resovle issue with account hoisting for `sendEip712Transaction` --- .changeset/tall-pets-impress.md | 5 ++++ src/zksync/actions/sendEip712Transaction.ts | 8 +++--- src/zksync/decorators/eip712.test.ts | 28 ++++++++++++++++++++- test/src/zksync.ts | 3 +++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .changeset/tall-pets-impress.md diff --git a/.changeset/tall-pets-impress.md b/.changeset/tall-pets-impress.md new file mode 100644 index 00000000000..4e9b9ef99e3 --- /dev/null +++ b/.changeset/tall-pets-impress.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Fixed account hoisting for `signEip712Transaction` and `sendEip712Transaction` in ZKsync extension. diff --git a/src/zksync/actions/sendEip712Transaction.ts b/src/zksync/actions/sendEip712Transaction.ts index 1804c69b2cd..2ff0b062018 100644 --- a/src/zksync/actions/sendEip712Transaction.ts +++ b/src/zksync/actions/sendEip712Transaction.ts @@ -92,13 +92,15 @@ export async function sendEip712Transaction< request >, ): Promise { - const { chain = client.chain } = parameters + const { account: account_ = client.account, chain = client.chain } = + parameters - if (!parameters.account) + const account = account_ ? parseAccount(account_) : client.account + + if (!account) throw new AccountNotFoundError({ docsPath: '/docs/actions/wallet/sendTransaction', }) - const account = parseAccount(parameters.account) try { assertEip712Request(parameters) diff --git a/src/zksync/decorators/eip712.test.ts b/src/zksync/decorators/eip712.test.ts index 92369afc070..77eadbf82ff 100644 --- a/src/zksync/decorators/eip712.test.ts +++ b/src/zksync/decorators/eip712.test.ts @@ -3,7 +3,8 @@ import { expect, test } from 'vitest' import { greeterContract } from '~test/src/abis.js' import { anvilZksync } from '~test/src/anvil.js' import { accounts } from '~test/src/constants.js' -import { accounts as acc } from '~test/src/zksync.js' +import { accounts as acc, approvalToken, paymaster } from '~test/src/zksync.js' +import { getApprovalBasedPaymasterInput } from '~viem/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js' import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js' import { simulateContract } from '../../actions/index.js' import { zksyncLocalHyperchain } from '../../chains/definitions/zksyncLocalHyperchain.js' @@ -51,6 +52,31 @@ test('sendTransaction', async () => { expect(result).toBeDefined() }) +test('sendTransaction with account hoisting', async () => { + const zksyncWallet = createWalletClient({ + account: privateKeyToAccount(acc[0].privateKey), + chain: zksyncLocalHyperchain, + transport: http(), + }).extend(eip712WalletActions()) + + const result = await zksyncWallet.sendTransaction({ + to: acc[1].address, + data: '0x0', + value: 7_000_000_000n, + maxFeePerGas: 10000000000n, + maxPriorityFeePerGas: 10000000000n, + gas: 158774n, + paymaster: paymaster, + paymasterInput: getApprovalBasedPaymasterInput({ + minAllowance: 1n, + token: approvalToken, + innerInput: new Uint8Array(), + }), + gasPerPubdata: 50_000n, + }) + expect(result).toBeDefined() +}) + test('signTransaction', async () => { const signature = await zksyncClient.signTransaction({ account: privateKeyToAccount(accounts[0].privateKey), diff --git a/test/src/zksync.ts b/test/src/zksync.ts index 3c29b952f58..8ce49fc7061 100644 --- a/test/src/zksync.ts +++ b/test/src/zksync.ts @@ -210,6 +210,9 @@ export function mockClientPublicActionsL2(client: any) { } } +export const approvalToken = '0x2dc3685cA34163952CF4A5395b0039c00DFa851D' +export const paymaster = '0x0EEc6f45108B4b806e27B81d9002e162BD910670' + export const accounts = [ { address: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049',