From 14596f95973c2dfce9c47cdb811aaa3cd9c7703f Mon Sep 17 00:00:00 2001 From: jp-dakota Date: Wed, 24 Jul 2024 19:44:28 +0000 Subject: [PATCH] Check if a smart contract is deployed only when needed --- .../accounts/kernel/createKernelAccount.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/core/accounts/kernel/createKernelAccount.ts b/packages/core/accounts/kernel/createKernelAccount.ts index af781130..6dda69d3 100644 --- a/packages/core/accounts/kernel/createKernelAccount.ts +++ b/packages/core/accounts/kernel/createKernelAccount.ts @@ -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, @@ -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( @@ -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( @@ -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(