diff --git a/packages/sdk/src/client/passkey/actions/account.test.ts b/packages/sdk/src/client/passkey/actions/account.test.ts index 88769d05..d3c73108 100644 --- a/packages/sdk/src/client/passkey/actions/account.test.ts +++ b/packages/sdk/src/client/passkey/actions/account.test.ts @@ -33,6 +33,25 @@ vi.mock("../../../abi/Factory.js", () => ({ stateMutability: "nonpayable", type: "function", }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "accountAddress", + type: "address", + }, + { + indexed: false, + internalType: "string", + name: "uniqueAccountId", + type: "string", + }, + ], + name: "AccountCreated", + type: "event", + }, ], })); @@ -74,11 +93,26 @@ describe("deployAccount", () => { const mockTransactionHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" as Hash; const mockTransactionReceipt: TransactionReceipt = { status: "success", - contractAddress: "0x4234567890123456789012345678901234567890", + contractAddress: null, blockNumber: 1n, blockHash: "0x5e1d3a76f1b1c3a2b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7" as Hash, transactionHash: mockTransactionHash, - logs: [], + logs: [ + { + address: mockContracts.accountFactory, + blockHash: "0x5e1d3a76f1b1c3a2b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7", + blockNumber: 1n, + data: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001b67615039747050496b704445496c6c52504e65594b706d3264514d0000000000", + logIndex: 0, + removed: false, + topics: [ + "0xb3202828e8e55b43ee1a77a1ee6ffbe19f0205767feb21e28cadd26390ff0501", // event AccountCreated(address,string) + "0x0000000000000000000000004234567890123456789012345678901234567890", + ], + transactionHash: "0x0b8154f57a02650c3cf622c19f1d90899d4779b3d181dfd03a53b3b257d76dd5", + transactionIndex: 0, + }, + ], logsBloom: "0x", cumulativeGasUsed: 0n, effectiveGasPrice: 0n, @@ -140,7 +174,7 @@ describe("deployAccount", () => { vi.mocked(writeContract).mockResolvedValue(mockTransactionHash); vi.mocked(waitForTransactionReceipt).mockResolvedValue({ ...mockTransactionReceipt, - contractAddress: null, + logs: [], }); await expect( diff --git a/packages/sdk/src/client/passkey/actions/account.ts b/packages/sdk/src/client/passkey/actions/account.ts index 972a0ed6..ab251870 100644 --- a/packages/sdk/src/client/passkey/actions/account.ts +++ b/packages/sdk/src/client/passkey/actions/account.ts @@ -1,4 +1,4 @@ -import { type Account, type Address, type Chain, type Client, getAddress, type Hash, type Hex, parseAbi, type Prettify, toHex, type TransactionReceipt, type Transport } from "viem"; +import { type Account, type Address, type Chain, type Client, getAddress, type Hash, type Hex, parseAbi, parseEventLogs, type Prettify, toHex, type TransactionReceipt, type Transport } from "viem"; import { readContract, waitForTransactionReceipt, writeContract } from "viem/actions"; import { getGeneralPaymasterInput } from "viem/zksync"; @@ -113,13 +113,17 @@ export const deployAccount = async < const transactionReceipt = await waitForTransactionReceipt(client, { hash: transactionHash }); if (transactionReceipt.status !== "success") throw new Error("Account deployment transaction reverted"); - const proxyAccountAddress = transactionReceipt.contractAddress; - if (!proxyAccountAddress) { + const accountCreatedEvent = parseEventLogs({ abi: FactoryAbi, logs: transactionReceipt.logs }) + .find((log) => log && log.eventName === "AccountCreated"); + + if (!accountCreatedEvent) { throw new Error("No contract address in transaction receipt"); } + const { accountAddress } = accountCreatedEvent.args; + return { - address: getAddress(proxyAccountAddress), + address: getAddress(accountAddress), transactionReceipt: transactionReceipt, }; };