From ad8a95e5e1d484439543202482e3ca80f8ba101e Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:37:20 +0000 Subject: [PATCH 1/4] add kernel useMetaFactory flag --- packages/permissionless-test/src/utils.ts | 65 ++++++++++++++++++- .../accounts/kernel/abi/KernelV3FactoryAbi.ts | 35 ++++++++++ .../accounts/kernel/toKernelSmartAccount.ts | 22 +++++-- 3 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts diff --git a/packages/permissionless-test/src/utils.ts b/packages/permissionless-test/src/utils.ts index bdd0b4a5..aaae353d 100644 --- a/packages/permissionless-test/src/utils.ts +++ b/packages/permissionless-test/src/utils.ts @@ -314,9 +314,11 @@ export const getKernelEcdsaClient = async < entryPoint, anvilRpc, version, - privateKey + privateKey, + useMetaFactory }: AAParamType & { version?: KernelVersion + useMetaFactory?: boolean }) => { const publicClient = getPublicClient(anvilRpc) @@ -336,6 +338,7 @@ export const getKernelEcdsaClient = async < : entryPoint07Address, version: entryPoint.version === "0.6" ? "0.6" : "0.7" }, + useMetaFactory, owners: [privateKeyToAccount(privateKey ?? generatePrivateKey())], version }) @@ -549,6 +552,36 @@ export const getCoreSmartAccounts = () => [ supportsEntryPointV07: false, isEip1271Compliant: true }, + { + name: "Kernel 7579 0.3.0-beta (non meta factory deployment)", + getSmartAccountClient: async ( + conf: AAParamType + ) => + getBundlerClient({ + account: await getKernelEcdsaClient({ + ...conf, + version: "0.3.0-beta" as KernelVersion, + useMetaFactory: false + }), + ...conf + }), + getErc7579SmartAccountClient: async < + entryPointVersion extends "0.6" | "0.7" + >( + conf: AAParamType + ) => + getSmartAccountClient({ + account: await getKernelEcdsaClient({ + ...conf, + version: "0.3.0-beta" as KernelVersion, + useMetaFactory: false + }), + ...conf + }), + supportsEntryPointV06: false, + supportsEntryPointV07: true, + isEip1271Compliant: true + }, { name: "Kernel 7579 0.3.0-beta", getSmartAccountClient: async ( @@ -577,6 +610,36 @@ export const getCoreSmartAccounts = () => [ supportsEntryPointV07: true, isEip1271Compliant: true }, + { + name: "Kernel 7579 0.3.1 (non meta factory deployment)", + getSmartAccountClient: async ( + conf: AAParamType + ) => + getBundlerClient({ + account: await getKernelEcdsaClient({ + ...conf, + version: "0.3.1" as KernelVersion, + useMetaFactory: false + }), + ...conf + }), + getErc7579SmartAccountClient: async < + entryPointVersion extends "0.6" | "0.7" + >( + conf: AAParamType + ) => + getSmartAccountClient({ + account: await getKernelEcdsaClient({ + ...conf, + version: "0.3.1" as KernelVersion, + useMetaFactory: false + }), + ...conf + }), + supportsEntryPointV06: false, + supportsEntryPointV07: true, + isEip1271Compliant: true + }, { name: "Kernel 7579 0.3.1", getSmartAccountClient: async ( diff --git a/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts b/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts new file mode 100644 index 00000000..2d885abf --- /dev/null +++ b/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts @@ -0,0 +1,35 @@ +export const KernelV3FactoryAbi = [ + { + type: "constructor", + inputs: [{ name: "_impl", type: "address", internalType: "address" }], + stateMutability: "nonpayable" + }, + { + type: "function", + name: "createAccount", + inputs: [ + { name: "data", type: "bytes", internalType: "bytes" }, + { name: "salt", type: "bytes32", internalType: "bytes32" } + ], + outputs: [{ name: "", type: "address", internalType: "address" }], + stateMutability: "payable" + }, + { + type: "function", + name: "getAddress", + inputs: [ + { name: "data", type: "bytes", internalType: "bytes" }, + { name: "salt", type: "bytes32", internalType: "bytes32" } + ], + outputs: [{ name: "", type: "address", internalType: "address" }], + stateMutability: "view" + }, + { + type: "function", + name: "implementation", + inputs: [], + outputs: [{ name: "", type: "address", internalType: "address" }], + stateMutability: "view" + }, + { type: "error", name: "InitializeError", inputs: [] } +] as const diff --git a/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts b/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts index 90de4289..03564838 100644 --- a/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts +++ b/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts @@ -42,6 +42,7 @@ import { KernelV3_1AccountAbi } from "./abi/KernelV3AccountAbi.js" import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi.js" +import { KernelV3FactoryAbi } from "./abi/KernelV3FactoryAbi.js" import { DUMMY_ECDSA_SIGNATURE, ROOT_MODE_KERNEL_V2, @@ -315,7 +316,8 @@ const getAccountInitCode = async ({ index, factoryAddress, accountLogicAddress, - validatorAddress + validatorAddress, + useMetaFactory }: { kernelVersion: KernelVersion entryPointVersion: entryPointVersion @@ -324,6 +326,7 @@ const getAccountInitCode = async ({ factoryAddress: Address accountLogicAddress: Address validatorAddress: Address + useMetaFactory: boolean }): Promise => { // Build the account initialization data const initializationData = getInitializationData({ @@ -343,6 +346,14 @@ const getAccountInitCode = async ({ }) } + if (!useMetaFactory) { + return encodeFunctionData({ + abi: KernelV3FactoryAbi, + functionName: "createAccount", + args: [initializationData, toHex(index, { size: 32 })] + }) + } + return encodeFunctionData({ abi: KernelV3MetaFactoryDeployWithFactoryAbi, functionName: "deployWithFactory", @@ -374,6 +385,7 @@ export type ToKernelSmartAccountParameters< accountLogicAddress?: Address validatorAddress?: Address nonceKey?: bigint + useMetaFactory?: boolean } export type KernelSmartAccountImplementation< @@ -431,7 +443,8 @@ export async function toKernelSmartAccount< validatorAddress: _validatorAddress, factoryAddress: _factoryAddress, metaFactoryAddress: _metaFactoryAddress, - accountLogicAddress: _accountLogicAddress + accountLogicAddress: _accountLogicAddress, + useMetaFactory = true } = parameters const isWebAuthn = owners[0].type === "webAuthn" @@ -484,7 +497,8 @@ export async function toKernelSmartAccount< index, factoryAddress, accountLogicAddress, - validatorAddress + validatorAddress, + useMetaFactory }) let accountAddress: Address | undefined = address @@ -502,7 +516,7 @@ export async function toKernelSmartAccount< const getFactoryArgs = async () => { return { factory: - entryPoint.version === "0.6" + entryPoint.version === "0.6" || useMetaFactory === false ? factoryAddress : metaFactoryAddress, factoryData: await generateInitCode() From 16a4e764997834998d5192b0cf82f58b4ec91e35 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:37:31 +0000 Subject: [PATCH 2/4] lint --- packages/permissionless/accounts/kernel/toKernelSmartAccount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts b/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts index 03564838..5e3d86ec 100644 --- a/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts +++ b/packages/permissionless/accounts/kernel/toKernelSmartAccount.ts @@ -41,8 +41,8 @@ import { KernelV3InitAbi, KernelV3_1AccountAbi } from "./abi/KernelV3AccountAbi.js" -import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi.js" import { KernelV3FactoryAbi } from "./abi/KernelV3FactoryAbi.js" +import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi.js" import { DUMMY_ECDSA_SIGNATURE, ROOT_MODE_KERNEL_V2, From 86dc887aa1c3c5990751b5ed7d4237fc4ee0afbc Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 15 Jan 2025 13:38:29 +0000 Subject: [PATCH 3/4] add changeset --- .changeset/polite-cups-shout.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/polite-cups-shout.md diff --git a/.changeset/polite-cups-shout.md b/.changeset/polite-cups-shout.md new file mode 100644 index 00000000..7be7e82a --- /dev/null +++ b/.changeset/polite-cups-shout.md @@ -0,0 +1,5 @@ +--- +"permissionless": patch +--- + +Added useMetaFactory flag for toEcdsaKernelSmartAccount From 6ea966da1c0851168af1e924681d75d4a3e6f3e3 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 15 Jan 2025 14:17:42 +0000 Subject: [PATCH 4/4] remove unused functions --- .../accounts/kernel/abi/KernelV3FactoryAbi.ts | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts b/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts index 2d885abf..7bb8f515 100644 --- a/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts +++ b/packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts @@ -1,9 +1,4 @@ export const KernelV3FactoryAbi = [ - { - type: "constructor", - inputs: [{ name: "_impl", type: "address", internalType: "address" }], - stateMutability: "nonpayable" - }, { type: "function", name: "createAccount", @@ -13,23 +8,5 @@ export const KernelV3FactoryAbi = [ ], outputs: [{ name: "", type: "address", internalType: "address" }], stateMutability: "payable" - }, - { - type: "function", - name: "getAddress", - inputs: [ - { name: "data", type: "bytes", internalType: "bytes" }, - { name: "salt", type: "bytes32", internalType: "bytes32" } - ], - outputs: [{ name: "", type: "address", internalType: "address" }], - stateMutability: "view" - }, - { - type: "function", - name: "implementation", - inputs: [], - outputs: [{ name: "", type: "address", internalType: "address" }], - stateMutability: "view" - }, - { type: "error", name: "InitializeError", inputs: [] } + } ] as const