Skip to content

Commit

Permalink
feat: added useMetaFactory flag and ZERODEV provider support
Browse files Browse the repository at this point in the history
  • Loading branch information
adnpark committed Aug 19, 2024
1 parent ef0f72f commit 7af3700
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
33 changes: 27 additions & 6 deletions packages/core/accounts/kernel/createKernelAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
} from "../utils/toKernelPluginManager.js"
import { KernelInitAbi } from "./abi/KernelAccountAbi.js"
import { KernelV3InitAbi } from "./abi/kernel_v_3_0_0/KernelAccountAbi.js"
import { KernelV3FactoryAbi } from "./abi/kernel_v_3_0_0/KernelFactoryAbi.js"
import { KernelFactoryStakerAbi } from "./abi/kernel_v_3_0_0/KernelFactoryStakerAbi.js"
import { KernelV3_1AccountAbi } from "./abi/kernel_v_3_1/KernelAccountAbi.js"
import { encodeCallData as encodeCallDataEpV06 } from "./utils/account/ep0_6/encodeCallData.js"
Expand Down Expand Up @@ -86,6 +87,7 @@ export type CreateKernelAccountParameters<
deployedAccountAddress?: Address
kernelVersion: GetKernelVersion<entryPoint>
initConfig?: KernelVerion extends "0.3.1" ? Hex[] : never
useMetaFactory?: boolean
}

/**
Expand Down Expand Up @@ -214,7 +216,8 @@ const getAccountInitCode = async <entryPoint extends EntryPoint>({
kernelPluginManager,
initHook,
kernelVersion,
initConfig
initConfig,
useMetaFactory
}: {
index: bigint
factoryAddress: Address
Expand All @@ -225,6 +228,7 @@ const getAccountInitCode = async <entryPoint extends EntryPoint>({
initHook: boolean
kernelVersion: GetKernelVersion<entryPoint>
initConfig?: GetKernelVersion<entryPoint> extends "0.3.1" ? Hex[] : never
useMetaFactory: boolean
}): Promise<Hex> => {
// Build the account initialization data
const initialisationData = await getKernelInitData<entryPoint>({
Expand All @@ -248,6 +252,17 @@ const getAccountInitCode = async <entryPoint extends EntryPoint>({
])
}

if (!useMetaFactory) {
return concatHex([
factoryAddress,
encodeFunctionData({
abi: KernelV3FactoryAbi,
functionName: "createAccount",
args: [initialisationData, toHex(index, { size: 32 })]
}) as Hex
])
}

return concatHex([
metaFactoryAddress ?? zeroAddress,
encodeFunctionData({
Expand Down Expand Up @@ -359,7 +374,8 @@ export async function createKernelAccount<
metaFactoryAddress: _metaFactoryAddress,
deployedAccountAddress,
kernelVersion,
initConfig
initConfig,
useMetaFactory = true
}: CreateKernelAccountParameters<entryPoint, KernelVersion>
): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
const entryPointVersion = getEntryPointVersion(entryPointAddress)
Expand Down Expand Up @@ -405,7 +421,8 @@ export async function createKernelAccount<
kernelPluginManager,
initHook,
kernelVersion,
initConfig
initConfig,
useMetaFactory
})
}

Expand Down Expand Up @@ -477,9 +494,13 @@ export async function createKernelAccount<

const entryPointVersion =
getEntryPointVersion(entryPointAddress)
return entryPointVersion === "v0.6"
? factoryAddress
: metaFactoryAddress
if (entryPointVersion === "v0.6") {
return factoryAddress
}
if (!useMetaFactory) {
return factoryAddress
}
return metaFactoryAddress
},

async getFactoryData() {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/clients/kernelAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export const createKernelAccountClient = <
})
if (
!shouldIncludePimlicoProvider ||
isProviderSet(_bundlerTransport.value?.url, "ALCHEMY")
isProviderSet(_bundlerTransport.value?.url, "ALCHEMY") ||
isProviderSet(_bundlerTransport.value?.url, "ZERODEV")
)
return _bundlerTransport
_bundlerTransport = http(
Expand Down
3 changes: 2 additions & 1 deletion packages/core/clients/paymasterClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const createZeroDevPaymasterClient = <
})
if (
!shouldIncludePimlicoProvider ||
isProviderSet(_transport.value?.url, "ALCHEMY")
isProviderSet(_transport.value?.url, "ALCHEMY") ||
isProviderSet(_transport.value?.url, "ZERODEV")
)
return _transport
_transport = http(setPimlicoAsProvider(_transport.value?.url))({
Expand Down

0 comments on commit 7af3700

Please sign in to comment.