Skip to content

Feat/kernel metafactory flag #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 15, 2025
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
5 changes: 5 additions & 0 deletions .changeset/polite-cups-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"permissionless": patch
---

Added useMetaFactory flag for toEcdsaKernelSmartAccount
65 changes: 64 additions & 1 deletion packages/permissionless-test/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,11 @@ export const getKernelEcdsaClient = async <
entryPoint,
anvilRpc,
version,
privateKey
privateKey,
useMetaFactory
}: AAParamType<entryPointVersion> & {
version?: KernelVersion<entryPointVersion>
useMetaFactory?: boolean
}) => {
const publicClient = getPublicClient(anvilRpc)

Expand All @@ -336,6 +338,7 @@ export const getKernelEcdsaClient = async <
: entryPoint07Address,
version: entryPoint.version === "0.6" ? "0.6" : "0.7"
},
useMetaFactory,
owners: [privateKeyToAccount(privateKey ?? generatePrivateKey())],
version
})
Expand Down Expand Up @@ -549,6 +552,36 @@ export const getCoreSmartAccounts = () => [
supportsEntryPointV07: false,
isEip1271Compliant: true
},
{
name: "Kernel 7579 0.3.0-beta (non meta factory deployment)",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.3.0-beta" as KernelVersion<entryPointVersion>,
useMetaFactory: false
}),
...conf
}),
getErc7579SmartAccountClient: async <
entryPointVersion extends "0.6" | "0.7"
>(
conf: AAParamType<entryPointVersion>
) =>
getSmartAccountClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.3.0-beta" as KernelVersion<entryPointVersion>,
useMetaFactory: false
}),
...conf
}),
supportsEntryPointV06: false,
supportsEntryPointV07: true,
isEip1271Compliant: true
},
{
name: "Kernel 7579 0.3.0-beta",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
Expand Down Expand Up @@ -577,6 +610,36 @@ export const getCoreSmartAccounts = () => [
supportsEntryPointV07: true,
isEip1271Compliant: true
},
{
name: "Kernel 7579 0.3.1 (non meta factory deployment)",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
conf: AAParamType<entryPointVersion>
) =>
getBundlerClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.3.1" as KernelVersion<entryPointVersion>,
useMetaFactory: false
}),
...conf
}),
getErc7579SmartAccountClient: async <
entryPointVersion extends "0.6" | "0.7"
>(
conf: AAParamType<entryPointVersion>
) =>
getSmartAccountClient({
account: await getKernelEcdsaClient({
...conf,
version: "0.3.1" as KernelVersion<entryPointVersion>,
useMetaFactory: false
}),
...conf
}),
supportsEntryPointV06: false,
supportsEntryPointV07: true,
isEip1271Compliant: true
},
{
name: "Kernel 7579 0.3.1",
getSmartAccountClient: async <entryPointVersion extends "0.6" | "0.7">(
Expand Down
12 changes: 12 additions & 0 deletions packages/permissionless/accounts/kernel/abi/KernelV3FactoryAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const KernelV3FactoryAbi = [
{
type: "function",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just use createAccount can we remove rest of unused abi

name: "createAccount",
inputs: [
{ name: "data", type: "bytes", internalType: "bytes" },
{ name: "salt", type: "bytes32", internalType: "bytes32" }
],
outputs: [{ name: "", type: "address", internalType: "address" }],
stateMutability: "payable"
}
] as const
22 changes: 18 additions & 4 deletions packages/permissionless/accounts/kernel/toKernelSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
KernelV3InitAbi,
KernelV3_1AccountAbi
} from "./abi/KernelV3AccountAbi.js"
import { KernelV3FactoryAbi } from "./abi/KernelV3FactoryAbi.js"
import { KernelV3MetaFactoryDeployWithFactoryAbi } from "./abi/KernelV3MetaFactoryAbi.js"
import {
DUMMY_ECDSA_SIGNATURE,
Expand Down Expand Up @@ -315,7 +316,8 @@ const getAccountInitCode = async <entryPointVersion extends "0.6" | "0.7">({
index,
factoryAddress,
accountLogicAddress,
validatorAddress
validatorAddress,
useMetaFactory
}: {
kernelVersion: KernelVersion<entryPointVersion>
entryPointVersion: entryPointVersion
Expand All @@ -324,6 +326,7 @@ const getAccountInitCode = async <entryPointVersion extends "0.6" | "0.7">({
factoryAddress: Address
accountLogicAddress: Address
validatorAddress: Address
useMetaFactory: boolean
}): Promise<Hex> => {
// Build the account initialization data
const initializationData = getInitializationData({
Expand All @@ -343,6 +346,14 @@ const getAccountInitCode = async <entryPointVersion extends "0.6" | "0.7">({
})
}

if (!useMetaFactory) {
return encodeFunctionData({
abi: KernelV3FactoryAbi,
functionName: "createAccount",
args: [initializationData, toHex(index, { size: 32 })]
})
}

return encodeFunctionData({
abi: KernelV3MetaFactoryDeployWithFactoryAbi,
functionName: "deployWithFactory",
Expand Down Expand Up @@ -374,6 +385,7 @@ export type ToKernelSmartAccountParameters<
accountLogicAddress?: Address
validatorAddress?: Address
nonceKey?: bigint
useMetaFactory?: boolean
}

export type KernelSmartAccountImplementation<
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -484,7 +497,8 @@ export async function toKernelSmartAccount<
index,
factoryAddress,
accountLogicAddress,
validatorAddress
validatorAddress,
useMetaFactory
})

let accountAddress: Address | undefined = address
Expand All @@ -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()
Expand Down
Loading