forked from alchemyplatform/aa-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleAccount.ts
87 lines (82 loc) · 2.69 KB
/
simpleAccount.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import hre from "hardhat";
import {encodeFunctionData, encodePacked, getAbiItem, getContract} from "viem";
import {AccountConfig, AccountDataV07} from "../accounts";
import {SIMPLE_ACCOUNT_ARTIFACTS} from "../artifacts/simpleAccount";
import {getEntryPointV07} from "../utils/entryPoint";
async function accountFixture(): Promise<AccountDataV07> {
const [walletClient] = await hre.viem.getWalletClients();
const publicClient = await hre.viem.getPublicClient();
for (const {address, bytecode} of Object.values(SIMPLE_ACCOUNT_ARTIFACTS)) {
await hre.network.provider.send("hardhat_setCode", [address, bytecode]);
}
const simpleAccountFactory = getContract({
address: SIMPLE_ACCOUNT_ARTIFACTS.SimpleAccountFactory.address,
abi: SIMPLE_ACCOUNT_ARTIFACTS.SimpleAccountFactory.abi,
publicClient,
walletClient,
});
return {
entryPoint: getEntryPointV07({publicClient, walletClient}),
createAccount: async (salt, ownerAddress) => {
return await simpleAccountFactory.write.createAccount([
ownerAddress,
salt,
]);
},
getAccountAddress: async (salt, ownerAddress) => {
return await simpleAccountFactory.read.getAddress([ownerAddress, salt]);
},
getOwnerSignature: async (owner, userOp, entryPoint) => {
const userOpHash = await entryPoint.read.getUserOpHash([userOp]);
return await owner.signMessage({
message: {raw: userOpHash},
});
},
encodeUserOpExecute: (to, value, data) => {
return encodeFunctionData({
abi: [
getAbiItem({
abi: SIMPLE_ACCOUNT_ARTIFACTS.SimpleAccount.abi,
name: "execute",
}),
],
args: [to, value, data],
});
},
encodeRuntimeExecute: async (to, value, data) => {
return encodeFunctionData({
abi: [
getAbiItem({
abi: SIMPLE_ACCOUNT_ARTIFACTS.SimpleAccount.abi,
name: "execute",
}),
],
args: [to, value, data],
});
},
getDummySignature: (_userOp) => {
return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
},
getInitCode: (salt, ownerAddress) => {
return encodePacked(
["address", "bytes"],
[
simpleAccountFactory.address,
encodeFunctionData({
abi: [
getAbiItem({
abi: simpleAccountFactory.abi,
name: "createAccount",
}),
],
args: [ownerAddress, salt],
}),
],
);
},
};
}
export const simpleAccount: AccountConfig = {
name: "Simple Account",
accountFixture,
};