Skip to content
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

Check if a smart contract is deployed only when needed #172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 19 additions & 4 deletions packages/core/accounts/kernel/createKernelAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,7 @@ export async function createKernelAccount<

if (!accountAddress) throw new Error("Account address not found")

let smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)
let smartAccountDeployed: boolean | undefined;

return {
kernelVersion,
Expand Down Expand Up @@ -454,6 +451,12 @@ export async function createKernelAccount<
return encodeCallDataEpV07(tx)
},
async getFactory() {
if (smartAccountDeployed === undefined) {
smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)
}
if (smartAccountDeployed) return undefined

smartAccountDeployed = await isSmartAccountDeployed(
Expand All @@ -471,6 +474,12 @@ export async function createKernelAccount<
},

async getFactoryData() {
if (smartAccountDeployed === undefined) {
smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)
}
if (smartAccountDeployed) return undefined

smartAccountDeployed = await isSmartAccountDeployed(
Expand Down Expand Up @@ -589,6 +598,12 @@ export async function createKernelAccount<

// Encode the init code
async getInitCode() {
if (smartAccountDeployed === undefined) {
smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)
}
if (smartAccountDeployed) return "0x"

smartAccountDeployed = await isSmartAccountDeployed(
Expand Down
Loading