From 32319e12013f7267b6489b5bcacd84b8b91cdcd1 Mon Sep 17 00:00:00 2001 From: Karandeep Singh <90941366+KannuSingh@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:01:58 -0600 Subject: [PATCH] Local aa infra without foundry chain (#637) * removed hardcoded url * resolve merge * removed toggle implemenation * remove localAAInfraEnabled state * fix type error --- .../react-wallet-v2/.env.local.example | 4 + .../src/consts/smartAccounts.ts | 4 +- .../react-wallet-v2/src/data/EIP155Data.ts | 9 -- .../react-wallet-v2/src/data/EIP5792Data.ts | 6 - .../src/hooks/useSmartAccounts.ts | 15 +- .../src/lib/smart-accounts/SmartAccountLib.ts | 13 +- .../react-wallet-v2/src/pages/settings.tsx | 20 +-- .../src/store/SettingsStore.ts | 129 +++--------------- .../src/utils/EIP5792RequestHandlerUtils.ts | 15 +- .../src/utils/SmartAccountUtil.ts | 51 +++---- .../signerToSafe7579SmartAccount.ts | 4 +- 11 files changed, 66 insertions(+), 204 deletions(-) diff --git a/advanced/wallets/react-wallet-v2/.env.local.example b/advanced/wallets/react-wallet-v2/.env.local.example index 04e54bae6..7a1ee6da9 100644 --- a/advanced/wallets/react-wallet-v2/.env.local.example +++ b/advanced/wallets/react-wallet-v2/.env.local.example @@ -2,3 +2,7 @@ NEXT_PUBLIC_PROJECT_ID= NEXT_PUBLIC_RELAY_URL=wss://relay.walletconnect.com NEXT_PUBLIC_PIMLICO_KEY= NEXT_PUBLIC_ZERODEV_PROJECT_ID= +#if using local AA infra then set these values +NEXT_PUBLIC_LOCAL_BUNDLER_URL= +NEXT_PUBLIC_LOCAL_PAYMASTER_URL= +NEXT_PUBLIC_LOCAL_CLIENT_URL= diff --git a/advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts b/advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts index 6c710fe85..89e2c73b6 100644 --- a/advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts +++ b/advanced/wallets/react-wallet-v2/src/consts/smartAccounts.ts @@ -1,9 +1,9 @@ import { KernelSmartAccountLib } from '@/lib/smart-accounts/KernelSmartAccountLib' import { SafeSmartAccountLib } from '@/lib/smart-accounts/SafeSmartAccountLib' -import { foundry, goerli, polygonMumbai, sepolia } from 'viem/chains' +import { goerli, polygonMumbai, sepolia } from 'viem/chains' // Types -export const allowedChains = [sepolia, polygonMumbai, goerli, foundry] +export const allowedChains = [sepolia, polygonMumbai, goerli] // build chains so I can access them by id export const chains = allowedChains.reduce((acc, chain) => { acc[chain.id] = chain diff --git a/advanced/wallets/react-wallet-v2/src/data/EIP155Data.ts b/advanced/wallets/react-wallet-v2/src/data/EIP155Data.ts index 6515d6cd8..3055e9d49 100644 --- a/advanced/wallets/react-wallet-v2/src/data/EIP155Data.ts +++ b/advanced/wallets/react-wallet-v2/src/data/EIP155Data.ts @@ -115,15 +115,6 @@ export const EIP155_TEST_CHAINS: Record = { rgb: '242, 242, 242', rpc: 'https://testnet.era.zksync.dev/', namespace: 'eip155' - }, - 'eip155:31337': { - chainId: 31337, - name: 'Foundry Testnet', - logo: '/chain-logos/eip155-1.png', - rgb: '242, 242, 242', - rpc: 'https://localhost:8545/', - namespace: 'eip155', - smartAccountEnabled: true } } diff --git a/advanced/wallets/react-wallet-v2/src/data/EIP5792Data.ts b/advanced/wallets/react-wallet-v2/src/data/EIP5792Data.ts index f81c5528e..26f5f7315 100644 --- a/advanced/wallets/react-wallet-v2/src/data/EIP5792Data.ts +++ b/advanced/wallets/react-wallet-v2/src/data/EIP5792Data.ts @@ -67,11 +67,5 @@ export const supportedEIP5792CapabilitiesForSCA: GetCapabilitiesResult = { atomicBatch: { supported: true } - }, - // foundry chain - '0x7a69': { - atomicBatch: { - supported: true - } } } diff --git a/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts b/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts index 1e0840d6e..538e58237 100644 --- a/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts +++ b/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts @@ -7,35 +7,28 @@ import { } from '@/utils/SmartAccountUtil' import { useSnapshot } from 'valtio' -import { foundry, sepolia } from 'viem/chains' export default function useSmartAccounts() { const { smartAccountEnabled, kernelSmartAccountEnabled, safeSmartAccountEnabled, - biconomySmartAccountEnabled, - localAAInfraEnabled + biconomySmartAccountEnabled } = useSnapshot(SettingsStore.state) const initializeSmartAccounts = async (privateKey: string) => { - const chain = localAAInfraEnabled ? foundry : sepolia if (smartAccountEnabled) { if (kernelSmartAccountEnabled) { - const { kernelSmartAccountAddress } = await createOrRestoreKernelSmartAccount( - privateKey, - chain - ) + const { kernelSmartAccountAddress } = await createOrRestoreKernelSmartAccount(privateKey) SettingsStore.setKernelSmartAccountAddress(kernelSmartAccountAddress) } if (safeSmartAccountEnabled) { - const { safeSmartAccountAddress } = await createOrRestoreSafeSmartAccount(privateKey, chain) + const { safeSmartAccountAddress } = await createOrRestoreSafeSmartAccount(privateKey) SettingsStore.setSafeSmartAccountAddress(safeSmartAccountAddress) } if (biconomySmartAccountEnabled) { const { biconomySmartAccountAddress } = await createOrRestoreBiconomySmartAccount( - privateKey, - chain + privateKey ) SettingsStore.setBiconomySmartAccountAddress(biconomySmartAccountAddress) } diff --git a/advanced/wallets/react-wallet-v2/src/lib/smart-accounts/SmartAccountLib.ts b/advanced/wallets/react-wallet-v2/src/lib/smart-accounts/SmartAccountLib.ts index 15e2f390b..29df6a713 100644 --- a/advanced/wallets/react-wallet-v2/src/lib/smart-accounts/SmartAccountLib.ts +++ b/advanced/wallets/react-wallet-v2/src/lib/smart-accounts/SmartAccountLib.ts @@ -72,16 +72,19 @@ export abstract class SmartAccountLib implements EIP155Wallet { entryPointVersion = 6 }: SmartAccountLibOptions) { const apiKey = process.env.NEXT_PUBLIC_PIMLICO_KEY + const publicClientRPCUrl = process.env.NEXT_PUBLIC_LOCAL_CLIENT_URL || publicRPCUrl({ chain }) const paymasterUrl = ({ chain }: UrlConfig) => { - if (chain.id === foundry.id) { - return `http://localhost:3000` + const localPaymasterUrl = process.env.NEXT_PUBLIC_LOCAL_PAYMASTER_URL + if (localPaymasterUrl) { + return localPaymasterUrl } return `https://api.pimlico.io/v2/${PIMLICO_NETWORK_NAMES[chain.name]}/rpc?apikey=${apiKey}` } const bundlerUrl = ({ chain }: UrlConfig) => { - if (chain.id === foundry.id) { - return `http://localhost:4337` + const localBundlerUrl = process.env.NEXT_PUBLIC_LOCAL_BUNDLER_URL + if (localBundlerUrl) { + return localBundlerUrl } return `https://api.pimlico.io/v1/${PIMLICO_NETWORK_NAMES[chain.name]}/rpc?apikey=${apiKey}` } @@ -101,7 +104,7 @@ export abstract class SmartAccountLib implements EIP155Wallet { this.paymasterUrl = http(paymasterUrl({ chain: this.chain })) this.publicClient = createPublicClient({ - transport: http(publicRPCUrl({ chain: this.chain })) + transport: http(publicClientRPCUrl) }).extend(bundlerActions(this.entryPoint)) this.paymasterClient = createPimlicoPaymasterClient({ diff --git a/advanced/wallets/react-wallet-v2/src/pages/settings.tsx b/advanced/wallets/react-wallet-v2/src/pages/settings.tsx index 97f3c9191..7bd54dc39 100644 --- a/advanced/wallets/react-wallet-v2/src/pages/settings.tsx +++ b/advanced/wallets/react-wallet-v2/src/pages/settings.tsx @@ -28,8 +28,7 @@ export default function SettingsPage() { kernelSmartAccountEnabled, safeSmartAccountEnabled, biconomySmartAccountEnabled, - moduleManagementEnabled, - localAAInfraEnabled + moduleManagementEnabled } = useSnapshot(SettingsStore.state) return ( @@ -142,23 +141,6 @@ export default function SettingsPage() { /> {moduleManagementEnabled ? 'Enabled' : 'Disabled'} - - - Local AA Infra - - - - {localAAInfraEnabled ? 'Enabled' : 'Disabled'} - ) : null} diff --git a/advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts b/advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts index 9011cc6f4..ac3d2f653 100644 --- a/advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts +++ b/advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts @@ -7,7 +7,6 @@ import { } from '@/utils/SmartAccountUtil' import { Verify, SessionTypes } from '@walletconnect/types' import { proxy } from 'valtio' -import { foundry, sepolia } from 'viem/chains' const TEST_NETS_ENABLED_KEY = 'TEST_NETS' const SMART_ACCOUNTS_ENABLED_KEY = 'SMART_ACCOUNTS' @@ -15,7 +14,6 @@ const ZERO_DEV_SMART_ACCOUNTS_ENABLED_KEY = 'ZERO_DEV_SMART_ACCOUNTS' const SAFE_SMART_ACCOUNTS_ENABLED_KEY = 'SAFE_SMART_ACCOUNTS' const BICONOMY_SMART_ACCOUNTS_ENABLED_KEY = 'BICONOMY_SMART_ACCOUNTS' const MODULE_MANAGEMENT_ENABLED_KEY = 'MODULE_MANAGEMENT' -const LOCAL_AA_INFRA_ENABLED_KEY = 'LOCAL_AA_INFRA' /** * Types @@ -45,7 +43,6 @@ interface State { safeSmartAccountEnabled: boolean biconomySmartAccountEnabled: boolean moduleManagementEnabled: boolean - localAAInfraEnabled: boolean } /** @@ -92,10 +89,6 @@ const state = proxy({ moduleManagementEnabled: typeof localStorage !== 'undefined' ? Boolean(localStorage.getItem(MODULE_MANAGEMENT_ENABLED_KEY)) - : false, - localAAInfraEnabled: - typeof localStorage !== 'undefined' - ? Boolean(localStorage.getItem(LOCAL_AA_INFRA_ENABLED_KEY)) : false }) @@ -199,82 +192,18 @@ const SettingsStore = { localStorage.removeItem(MODULE_MANAGEMENT_ENABLED_KEY) } }, - async toggleLocalAAInfra() { - try { - state.localAAInfraEnabled = !state.localAAInfraEnabled - - // Update local storage based on the state - state.localAAInfraEnabled - ? localStorage.setItem(LOCAL_AA_INFRA_ENABLED_KEY, 'YES') - : localStorage.removeItem(LOCAL_AA_INFRA_ENABLED_KEY) - - // Define account types with corresponding properties - const accountTypes = [ - { - enabled: state.safeSmartAccountEnabled, - address: SettingsStore.state.safeSmartAccountAddress, - createOrRestore: createOrRestoreSafeSmartAccount, - setter: SettingsStore.setSafeSmartAccountAddress - }, - { - enabled: state.kernelSmartAccountEnabled, - address: SettingsStore.state.kernelSmartAccountAddress, - createOrRestore: createOrRestoreKernelSmartAccount, - setter: SettingsStore.setKernelSmartAccountAddress - }, - { - enabled: state.biconomySmartAccountEnabled, - address: SettingsStore.state.biconomySmartAccountAddress, - createOrRestore: createOrRestoreBiconomySmartAccount, - setter: SettingsStore.setBiconomySmartAccountAddress - } - ] - - // Create or restore EIP-155 wallet - const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() - const privateKey = eip155Wallets[eip155Addresses[0]].getPrivateKey() - const newChain = state.localAAInfraEnabled ? foundry : sepolia - const oldChain = state.localAAInfraEnabled ? sepolia : foundry - - // Process account types concurrently - await Promise.all( - accountTypes.map(async account => { - // Remove smart account from the old chain - removeSmartAccount(account.address, oldChain) - - if (account.enabled) { - // Create or restore account on the new chain - const result = await account.createOrRestore(privateKey, newChain) - const [newAddress] = Object.values(result) - account.setter(newAddress) - } - }) - ) - } catch (e) { - state.localAAInfraEnabled = false - localStorage.removeItem(LOCAL_AA_INFRA_ENABLED_KEY) - } - }, async toggleKernelSmartAccountsEnabled() { state.kernelSmartAccountEnabled = !state.kernelSmartAccountEnabled if (state.kernelSmartAccountEnabled) { - try { - const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() - const chain = state.localAAInfraEnabled ? foundry : sepolia - const { kernelSmartAccountAddress } = await createOrRestoreKernelSmartAccount( - eip155Wallets[eip155Addresses[0]].getPrivateKey(), - chain - ) - SettingsStore.setKernelSmartAccountAddress(kernelSmartAccountAddress) - localStorage.setItem(ZERO_DEV_SMART_ACCOUNTS_ENABLED_KEY, 'YES') - } catch (e) { - state.kernelSmartAccountEnabled = false - localStorage.removeItem(ZERO_DEV_SMART_ACCOUNTS_ENABLED_KEY) - } + const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() + const { kernelSmartAccountAddress } = await createOrRestoreKernelSmartAccount( + eip155Wallets[eip155Addresses[0]].getPrivateKey() + ) + SettingsStore.setKernelSmartAccountAddress(kernelSmartAccountAddress) + localStorage.setItem(ZERO_DEV_SMART_ACCOUNTS_ENABLED_KEY, 'YES') } else { - const chain = state.localAAInfraEnabled ? foundry : sepolia - removeSmartAccount(SettingsStore.state.kernelSmartAccountAddress, chain) + removeSmartAccount(SettingsStore.state.kernelSmartAccountAddress) SettingsStore.setKernelSmartAccountAddress('') state.moduleManagementEnabled = false localStorage.removeItem(MODULE_MANAGEMENT_ENABLED_KEY) @@ -285,22 +214,14 @@ const SettingsStore = { async toggleSafeSmartAccountsEnabled() { state.safeSmartAccountEnabled = !state.safeSmartAccountEnabled if (state.safeSmartAccountEnabled) { - try { - const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() - const chain = state.localAAInfraEnabled ? foundry : sepolia - const { safeSmartAccountAddress } = await createOrRestoreSafeSmartAccount( - eip155Wallets[eip155Addresses[0]].getPrivateKey(), - chain - ) - SettingsStore.setSafeSmartAccountAddress(safeSmartAccountAddress) - localStorage.setItem(SAFE_SMART_ACCOUNTS_ENABLED_KEY, 'YES') - } catch (e) { - state.safeSmartAccountEnabled = false - localStorage.removeItem(SAFE_SMART_ACCOUNTS_ENABLED_KEY) - } + const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() + const { safeSmartAccountAddress } = await createOrRestoreSafeSmartAccount( + eip155Wallets[eip155Addresses[0]].getPrivateKey() + ) + SettingsStore.setSafeSmartAccountAddress(safeSmartAccountAddress) + localStorage.setItem(SAFE_SMART_ACCOUNTS_ENABLED_KEY, 'YES') } else { - const chain = state.localAAInfraEnabled ? foundry : sepolia - removeSmartAccount(SettingsStore.state.safeSmartAccountAddress, chain) + removeSmartAccount(SettingsStore.state.safeSmartAccountAddress) SettingsStore.setSafeSmartAccountAddress('') state.moduleManagementEnabled = false localStorage.removeItem(MODULE_MANAGEMENT_ENABLED_KEY) @@ -311,22 +232,14 @@ const SettingsStore = { async toggleBiconomySmartAccountsEnabled() { state.biconomySmartAccountEnabled = !state.biconomySmartAccountEnabled if (state.biconomySmartAccountEnabled) { - try { - const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() - const chain = state.localAAInfraEnabled ? foundry : sepolia - const { biconomySmartAccountAddress } = await createOrRestoreBiconomySmartAccount( - eip155Wallets[eip155Addresses[0]].getPrivateKey(), - chain - ) - SettingsStore.setBiconomySmartAccountAddress(biconomySmartAccountAddress) - localStorage.setItem(BICONOMY_SMART_ACCOUNTS_ENABLED_KEY, 'YES') - } catch (e) { - state.biconomySmartAccountEnabled = false - localStorage.removeItem(BICONOMY_SMART_ACCOUNTS_ENABLED_KEY) - } + const { eip155Addresses, eip155Wallets } = createOrRestoreEIP155Wallet() + const { biconomySmartAccountAddress } = await createOrRestoreBiconomySmartAccount( + eip155Wallets[eip155Addresses[0]].getPrivateKey() + ) + SettingsStore.setBiconomySmartAccountAddress(biconomySmartAccountAddress) + localStorage.setItem(BICONOMY_SMART_ACCOUNTS_ENABLED_KEY, 'YES') } else { - const chain = state.localAAInfraEnabled ? foundry : sepolia - removeSmartAccount(SettingsStore.state.biconomySmartAccountAddress, chain) + removeSmartAccount(SettingsStore.state.biconomySmartAccountAddress) SettingsStore.setBiconomySmartAccountAddress('') state.moduleManagementEnabled = false localStorage.removeItem(MODULE_MANAGEMENT_ENABLED_KEY) diff --git a/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts b/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts index c9b4d4750..3dc17d941 100644 --- a/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts +++ b/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts @@ -15,28 +15,21 @@ import { getSdkError } from '@walletconnect/utils' import SettingsStore from '@/store/SettingsStore' import EIP155Lib from '@/lib/EIP155Lib' import { - ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07, GetUserOperationReceiptReturnType, createBundlerClient } from 'permissionless' import { http, toHex } from 'viem' -import { foundry } from 'viem/chains' type RequestEventArgs = Omit - -const getCallsReceipt = async (getCallParams: GetCallsParams, chainId: string) => { +const getCallsReceipt = async (getCallParams: GetCallsParams) => { /** * This is hardcode implementation of wallet_getCallsStatus * as we are not maintaining the data for calls bundled right now. * Getting directly from bundler the receipt on sepolia chain. */ const apiKey = process.env.NEXT_PUBLIC_PIMLICO_KEY - let bundlerUrl = `https://api.pimlico.io/v1/sepolia/rpc?apikey=${apiKey}` - - if (chainId.split(':')[1] === foundry.id.toString()) { - bundlerUrl = 'http://localhost:4337' - } - + const localBundlerUrl = process.env.NEXT_PUBLIC_LOCAL_BUNDLER_URL + const bundlerUrl = localBundlerUrl || `https://api.pimlico.io/v1/sepolia/rpc?apikey=${apiKey}` const bundlerClient = createBundlerClient({ entryPoint: ENTRYPOINT_ADDRESS_V07, transport: http(bundlerUrl) @@ -89,7 +82,7 @@ export async function approveEIP5792Request(requestEvent: RequestEventArgs) { case EIP5792_METHODS.WALLET_GET_CALLS_STATUS: { try { const getCallParams = request.params[0] as GetCallsParams - const receipt = await getCallsReceipt(getCallParams, chainId) + const receipt = await getCallsReceipt(getCallParams) return formatJsonRpcResult(id, receipt) } catch (error: any) { console.error(error) diff --git a/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtil.ts b/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtil.ts index 06b017f90..265ceb78d 100644 --- a/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtil.ts +++ b/advanced/wallets/react-wallet-v2/src/utils/SmartAccountUtil.ts @@ -3,7 +3,7 @@ import { Hex } from 'viem' import { SessionTypes } from '@walletconnect/types' import { Chain, allowedChains } from '@/consts/smartAccounts' import { KernelSmartAccountLib } from '@/lib/smart-accounts/KernelSmartAccountLib' -import { foundry, sepolia } from 'viem/chains' +import { sepolia } from 'viem/chains' import { SafeSmartAccountLib } from '@/lib/smart-accounts/SafeSmartAccountLib' import { SmartAccountLib } from '@/lib/smart-accounts/SmartAccountLib' @@ -15,8 +15,7 @@ export type UrlConfig = { export const ENTRYPOINT_ADDRESSES: Record = { Sepolia: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', 'Polygon Mumbai': '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', - Goerli: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', - Foundry: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' + Goerli: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' } // Paymasters @@ -24,32 +23,28 @@ export const ENTRYPOINT_ADDRESSES: Record = { export const PAYMASTER_ADDRESSES: Record = { Sepolia: '0x0000000000325602a77416A16136FDafd04b299f', 'Polygon Mumbai': '0x000000000009B901DeC1aaB9389285965F49D387', - Goerli: '0xEc43912D8C772A0Eba5a27ea5804Ba14ab502009', - Foundry: '0x0000000000325602a77416A16136FDafd04b299f' + Goerli: '0xEc43912D8C772A0Eba5a27ea5804Ba14ab502009' } // USDC export const USDC_ADDRESSES: Record = { Sepolia: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', 'Polygon Mumbai': '0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97', - Goerli: '0x07865c6e87b9f70255377e024ace6630c1eaa37f', - Foundry: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' + Goerli: '0x07865c6e87b9f70255377e024ace6630c1eaa37f' } // RPC URLs export const RPC_URLS: Record = { Sepolia: 'https://rpc.ankr.com/eth_sepolia', 'Polygon Mumbai': 'https://mumbai.rpc.thirdweb.com', - Goerli: 'https://ethereum-goerli.publicnode.com', - Foundry: 'http://localhost:8545' + Goerli: 'https://ethereum-goerli.publicnode.com' } // Pimlico RPC names export const PIMLICO_NETWORK_NAMES: Record = { Sepolia: 'sepolia', 'Polygon Mumbai': 'mumbai', - Goerli: 'goerli', - Foundry: 'foundry' + Goerli: 'goerli' } export const publicRPCUrl = ({ chain }: UrlConfig) => { @@ -81,9 +76,9 @@ export function supportedAddressPriority( return [] } -export const kernelAllowedChains = [sepolia, foundry] -export const safeAllowedChains = [sepolia, foundry] -export const biconomyAllowedChains = [sepolia, foundry] +export const kernelAllowedChains = [sepolia] +export const safeAllowedChains = [sepolia] +export const biconomyAllowedChains = [sepolia] export let smartAccountWallets: Record = {} @@ -91,19 +86,16 @@ export function isAllowedKernelChain(chainId: number): boolean { return kernelAllowedChains.some(chain => chain.id == chainId) } -export async function createOrRestoreKernelSmartAccount( - privateKey: string, - chain: Chain = sepolia -) { +export async function createOrRestoreKernelSmartAccount(privateKey: string) { const lib = new KernelSmartAccountLib({ privateKey, - chain: chain, + chain: sepolia, sponsored: true, entryPointVersion: 6 }) await lib.init() const address = lib.getAddress() - const key = `${chain.id}:${address}` + const key = `${sepolia.id}:${address}` if (!smartAccountWallets[key]) { smartAccountWallets[key] = lib } @@ -116,16 +108,16 @@ export function isAllowedSafeChain(chainId: number): boolean { return safeAllowedChains.some(chain => chain.id == chainId) } -export async function createOrRestoreSafeSmartAccount(privateKey: string, chain: Chain = sepolia) { +export async function createOrRestoreSafeSmartAccount(privateKey: string) { const lib = new SafeSmartAccountLib({ privateKey, - chain: chain, + chain: sepolia, sponsored: true, entryPointVersion: 7 }) await lib.init() const address = lib.getAddress() - const key = `${chain.id}:${address}` + const key = `${sepolia.id}:${address}` if (!smartAccountWallets[key]) { smartAccountWallets[key] = lib } @@ -133,21 +125,18 @@ export async function createOrRestoreSafeSmartAccount(privateKey: string, chain: safeSmartAccountAddress: address } } -export function removeSmartAccount(address: string, chain: Chain = sepolia) { - const key = `${chain.id}:${address}` +export function removeSmartAccount(address: string) { + const key = `${sepolia.id}:${address}` if (smartAccountWallets[key]) { delete smartAccountWallets[key] } } -export async function createOrRestoreBiconomySmartAccount( - privateKey: string, - chain: Chain = sepolia -) { - const lib = new BiconomySmartAccountLib({ privateKey, chain: chain, sponsored: true }) +export async function createOrRestoreBiconomySmartAccount(privateKey: string) { + const lib = new BiconomySmartAccountLib({ privateKey, chain: sepolia, sponsored: true }) await lib.init() const address = lib.getAddress() - const key = `${chain.id}:${address}` + const key = `${sepolia.id}:${address}` if (!smartAccountWallets[key]) { smartAccountWallets[key] = lib } diff --git a/advanced/wallets/react-wallet-v2/src/utils/safe7579AccountUtils/signerToSafe7579SmartAccount.ts b/advanced/wallets/react-wallet-v2/src/utils/safe7579AccountUtils/signerToSafe7579SmartAccount.ts index 88ed9808f..41513f752 100644 --- a/advanced/wallets/react-wallet-v2/src/utils/safe7579AccountUtils/signerToSafe7579SmartAccount.ts +++ b/advanced/wallets/react-wallet-v2/src/utils/safe7579AccountUtils/signerToSafe7579SmartAccount.ts @@ -1,4 +1,4 @@ -import type { SignableMessage, TypedData } from 'viem' +import type { PublicActions, PublicRpcSchema, SignableMessage, TypedData } from 'viem' import { type Address, type Chain, @@ -294,7 +294,7 @@ export async function signerToSafe7579SmartAccount< TSource extends string = string, TAddress extends Address = Address >( - client: Client, + client: Client, { signer, entryPoint: entryPointAddress,