Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions packages/sdk/src/client/passkey/actions/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
}));

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -140,7 +174,7 @@ describe("deployAccount", () => {
vi.mocked(writeContract).mockResolvedValue(mockTransactionHash);
vi.mocked(waitForTransactionReceipt).mockResolvedValue({
...mockTransactionReceipt,
contractAddress: null,
logs: [],
});

await expect(
Expand Down
12 changes: 8 additions & 4 deletions packages/sdk/src/client/passkey/actions/account.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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,
};
};
Expand Down
Loading