From 75ec09e6097b5f1a2baabedca7b63c7240c34dcc Mon Sep 17 00:00:00 2001 From: Karandeep Singh Date: Wed, 10 Jul 2024 11:05:08 -0400 Subject: [PATCH] removed toggle implemenation --- .../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 | 12 +- .../react-wallet-v2/src/pages/settings.tsx | 20 +-- .../src/store/SettingsStore.ts | 129 +++--------------- .../src/utils/EIP5792RequestHandlerUtils.ts | 1 - .../src/utils/SmartAccountUtil.ts | 51 +++---- 8 files changed, 47 insertions(+), 185 deletions(-) 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..bcc3ca5ca 100644 --- a/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts +++ b/advanced/wallets/react-wallet-v2/src/hooks/useSmartAccounts.ts @@ -7,7 +7,6 @@ import { } from '@/utils/SmartAccountUtil' import { useSnapshot } from 'valtio' -import { foundry, sepolia } from 'viem/chains' export default function useSmartAccounts() { const { @@ -19,23 +18,18 @@ export default function useSmartAccounts() { } = 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/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 98f052be5..3dc17d941 100644 --- a/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts +++ b/advanced/wallets/react-wallet-v2/src/utils/EIP5792RequestHandlerUtils.ts @@ -20,7 +20,6 @@ import { createBundlerClient } from 'permissionless' import { http, toHex } from 'viem' -import { foundry } from 'viem/chains' type RequestEventArgs = Omit const getCallsReceipt = async (getCallParams: GetCallsParams) => { /** 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 }