Skip to content

Commit

Permalink
fix(zksync): resolve issues with account hoisting for `sendEip712Tran…
Browse files Browse the repository at this point in the history
…saction`
  • Loading branch information
danijelTxFusion committed Dec 9, 2024
1 parent 422309a commit ad71ab8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-geckos-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed account hoisting for `sendEip712Transaction` in ZKsync extension
8 changes: 5 additions & 3 deletions src/zksync/actions/sendEip712Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ export async function sendEip712Transaction<
request
>,
): Promise<SendEip712TransactionReturnType> {
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)
Expand Down
28 changes: 27 additions & 1 deletion src/zksync/decorators/eip712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions test/src/zksync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ export function mockClientPublicActionsL2(client: any) {
}
}

export const approvalToken = '0x2dc3685cA34163952CF4A5395b0039c00DFa851D'
export const paymaster = '0x0EEc6f45108B4b806e27B81d9002e162BD910670'

export const accounts = [
{
address: '0x36615Cf349d7F6344891B1e7CA7C72883F5dc049',
Expand Down

0 comments on commit ad71ab8

Please sign in to comment.