Skip to content

Commit 422309a

Browse files
fix(zksync): resolve issues with account hoisting for signEip712Transaction
1 parent 6ae1307 commit 422309a

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

.changeset/empty-baboons-fry.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"viem": patch
3+
---
4+
5+
Fixed account hoisting with `signEip712Transaction` in ZKsync extension

src/zksync/actions/signEip712Transaction.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, test } from 'vitest'
22

33
import { accounts } from '~test/src/constants.js'
44

5-
import { anvilZksync } from '../../../test/src/anvil.js'
5+
import { anvilZksync } from '~test/src/anvil.js'
66
import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js'
77
import type { ZksyncTransactionRequestEIP712 } from '../../zksync/index.js'
88
import { signTransaction } from './signTransaction.js'

src/zksync/actions/signEip712Transaction.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export type SignEip712TransactionErrorType = SignTransactionErrorType
5353
/**
5454
* Signs an EIP712 transaction.
5555
*
56+
*
57+
* @param client - Client to use
5658
* @param args - {@link SignTransactionParameters}
5759
* @returns The signed serialized transaction. {@link SignTransactionReturnType}
5860
*
@@ -102,11 +104,12 @@ export async function signEip712Transaction<
102104
...transaction
103105
} = args
104106

105-
if (!account_)
107+
const account = account_ ? parseAccount(account_) : client.account
108+
109+
if (!account)
106110
throw new AccountNotFoundError({
107111
docsPath: '/docs/actions/wallet/signTransaction',
108112
})
109-
const account = parseAccount(account_)
110113

111114
assertEip712Request({
112115
account,

src/zksync/decorators/eip712.test.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { expect, test } from 'vitest'
22

33
import { greeterContract } from '~test/src/abis.js'
4+
import { anvilZksync } from '~test/src/anvil.js'
45
import { accounts } from '~test/src/constants.js'
5-
import { anvilZksync } from '../../../test/src/anvil.js'
6+
import { accounts as acc } from '~test/src/zksync.js'
67
import { privateKeyToAccount } from '../../accounts/privateKeyToAccount.js'
78
import { simulateContract } from '../../actions/index.js'
9+
import { zksyncLocalHyperchain } from '../../chains/definitions/zksyncLocalHyperchain.js'
10+
import { createWalletClient } from '../../clients/createWalletClient.js'
11+
import { http } from '../../clients/transports/http.js'
812
import type { EIP1193RequestFn } from '../../types/eip1193.js'
913
import { eip712WalletActions } from './eip712.js'
1014

@@ -65,6 +69,29 @@ test('signTransaction', async () => {
6569
expect(signature).toBeDefined()
6670
})
6771

72+
test('signTransaction with account hoisting', async () => {
73+
const zksyncWallet = createWalletClient({
74+
account: privateKeyToAccount(acc[0].privateKey),
75+
chain: zksyncLocalHyperchain,
76+
transport: http(),
77+
}).extend(eip712WalletActions())
78+
79+
const signature = await zksyncWallet.signTransaction({
80+
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
81+
maxFeePerGas: 10000000000n,
82+
maxPriorityFeePerGas: 10000000000n,
83+
gas: 158774n,
84+
value: 10000000000n,
85+
data: '0x0',
86+
paymaster: '0xFD9aE5ebB0F6656f4b77a0E99dCbc5138d54b0BA',
87+
paymasterInput:
88+
'0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000',
89+
type: 'eip712',
90+
gasPerPubdata: 50000n,
91+
})
92+
expect(signature).toBeDefined()
93+
})
94+
6895
test('writeContract', async () => {
6996
zksyncClient.request = (async ({ method, params }) => {
7097
if (method === 'eth_sendRawTransaction')

test/src/zksync.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { zksyncLocalNode } from '~viem/chains/index.js'
22
import { createClient } from '~viem/clients/createClient.js'
33
import { http } from '~viem/index.js'
4-
import { accounts } from './constants.js'
4+
import { accounts as acc } from './constants.js'
55

66
export const zksyncClientLocalNode = createClient({
77
chain: zksyncLocalNode,
88
transport: http(),
99
})
1010

1111
export const zksyncClientLocalNodeWithAccount = createClient({
12-
account: accounts[0].address,
12+
account: acc[0].address,
1313
chain: zksyncLocalNode,
1414
transport: http(),
1515
})
@@ -209,3 +209,16 @@ export function mockClientPublicActionsL2(client: any) {
209209
return mockRequestReturnData(method)
210210
}
211211
}
212+
213+
export const accounts = [
214+
{
215+
address: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049',
216+
privateKey:
217+
'0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110',
218+
},
219+
{
220+
address: '0xa61464658AfeAf65CccaaFD3a512b69A83B77618',
221+
privateKey:
222+
'0xac1e735be8536c6534bb4f17f06f6afc73b2b5ba84ac2cfb12f7461b20c0bbe3',
223+
},
224+
] as const

0 commit comments

Comments
 (0)