From accb23bd37fef6027f718a9204fb7d5fc22b0678 Mon Sep 17 00:00:00 2001 From: Michael Moldoveanu Date: Wed, 29 May 2024 23:00:33 -0400 Subject: [PATCH] refactor: don't throw in get default address methods (#677) --- packages/accounts/src/msca/utils.ts | 41 ++------------------------- packages/core/src/entrypoint/0.6.ts | 41 +-------------------------- packages/core/src/entrypoint/0.7.ts | 41 +-------------------------- packages/core/src/entrypoint/index.ts | 5 +++- packages/core/src/entrypoint/types.ts | 2 +- packages/core/src/utils/defaults.ts | 23 ++------------- 6 files changed, 12 insertions(+), 141 deletions(-) diff --git a/packages/accounts/src/msca/utils.ts b/packages/accounts/src/msca/utils.ts index 9f37c435ba..70f9096ecf 100644 --- a/packages/accounts/src/msca/utils.ts +++ b/packages/accounts/src/msca/utils.ts @@ -1,26 +1,16 @@ import { AccountNotFoundError, ChainNotFoundError, - DefaultFactoryNotDefinedError, arbitrum, - arbitrumGoerli, arbitrumSepolia, base, - baseGoerli, baseSepolia, - fraxtal, - fraxtalSepolia, - goerli, mainnet, optimism, - optimismGoerli, optimismSepolia, polygon, polygonAmoy, - polygonMumbai, sepolia, - zora, - zoraSepolia, type GetAccountParameter, type SmartAccountClient, type SmartAccountSigner, @@ -67,13 +57,9 @@ export const getDefaultMultisigModularAccountFactoryAddress = ( case arbitrum.id: case arbitrumSepolia.id: case base.id: + default: return "0x000000000000204327E6669f00901a57CE15aE15"; } - throw new DefaultFactoryNotDefinedError( - "MultisigModularAccount", - chain, - "0.6.0" - ); }; /** @@ -87,32 +73,9 @@ export const getDefaultMultiOwnerModularAccountFactoryAddress = ( chain: Chain ): Address => { switch (chain.id) { - case sepolia.id: - case baseSepolia.id: - case polygon.id: - case mainnet.id: - case goerli.id: - case polygonAmoy.id: - case polygonMumbai.id: - case optimism.id: - case optimismGoerli.id: - case optimismSepolia.id: - case arbitrum.id: - case arbitrumGoerli.id: - case arbitrumSepolia.id: - case base.id: - case baseGoerli.id: - case fraxtal.id: - case fraxtalSepolia.id: - case zora.id: - case zoraSepolia.id: + default: return "0x000000e92D78D90000007F0082006FDA09BD5f11"; } - throw new DefaultFactoryNotDefinedError( - "MultiOwnerModularAccount", - chain, - "0.6.0" - ); }; export async function getMSCAUpgradeToData< diff --git a/packages/core/src/entrypoint/0.6.ts b/packages/core/src/entrypoint/0.6.ts index 8efd4b7705..6464474e9e 100644 --- a/packages/core/src/entrypoint/0.6.ts +++ b/packages/core/src/entrypoint/0.6.ts @@ -7,27 +7,6 @@ import { type Hash, type Hex, } from "viem"; -import { - arbitrum, - arbitrumGoerli, - arbitrumSepolia, - base, - baseGoerli, - baseSepolia, - goerli, - mainnet, - optimism, - optimismGoerli, - optimismSepolia, - polygon, - polygonAmoy, - polygonMumbai, - sepolia, - fraxtal, - fraxtalSepolia, - zora, - zoraSepolia, -} from "../chains/index.js"; import { EntryPointAbi_v6 } from "../abis/EntryPointAbi_v6.js"; import type { UserOperationRequest } from "../types.js"; import type { SupportedEntryPoint } from "./types.js"; @@ -69,25 +48,7 @@ export default { version: "0.6.0", address: { - [mainnet.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [sepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [goerli.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [polygon.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [polygonMumbai.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [polygonAmoy.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [optimism.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [optimismGoerli.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [optimismSepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [arbitrum.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [arbitrumGoerli.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [arbitrumSepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [base.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [baseGoerli.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [baseSepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [fraxtal.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [fraxtalSepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [zora.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - [zoraSepolia.id]: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", + default: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", }, abi: EntryPointAbi_v6, diff --git a/packages/core/src/entrypoint/0.7.ts b/packages/core/src/entrypoint/0.7.ts index d992d7bd94..678b4cb5a5 100644 --- a/packages/core/src/entrypoint/0.7.ts +++ b/packages/core/src/entrypoint/0.7.ts @@ -10,27 +10,6 @@ import { type Hash, type Hex, } from "viem"; -import { - arbitrum, - arbitrumGoerli, - arbitrumSepolia, - base, - baseGoerli, - baseSepolia, - goerli, - mainnet, - optimism, - optimismGoerli, - optimismSepolia, - polygon, - polygonAmoy, - polygonMumbai, - sepolia, - fraxtal, - fraxtalSepolia, - zora, - zoraSepolia, -} from "../chains/index.js"; import { EntryPointAbi_v7 } from "../abis/EntryPointAbi_v7.js"; import type { UserOperationRequest, @@ -102,25 +81,7 @@ export default { version: "0.7.0", address: { - [mainnet.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [sepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [goerli.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [polygon.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [polygonMumbai.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [polygonAmoy.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [optimism.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [optimismGoerli.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [optimismSepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [arbitrum.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [arbitrumGoerli.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [arbitrumSepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [base.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [baseGoerli.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [baseSepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [fraxtal.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [fraxtalSepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [zora.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", - [zoraSepolia.id]: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", + default: "0x0000000071727De22E5E9d8BAf0edAc6f37da032", }, abi: EntryPointAbi_v7, diff --git a/packages/core/src/entrypoint/index.ts b/packages/core/src/entrypoint/index.ts index 0083e87649..dc80a7131a 100644 --- a/packages/core/src/entrypoint/index.ts +++ b/packages/core/src/entrypoint/index.ts @@ -56,7 +56,10 @@ export function getEntryPoint< }; const entryPoint = entryPointRegistry[version ?? defaultEntryPointVersion]; - const address = addressOverride || entryPoint.address[chain.id]; + const address = + addressOverride ?? + entryPoint.address[chain.id] ?? + entryPoint.address.default; if (!address) { throw new EntryPointNotFoundError(chain, version); } diff --git a/packages/core/src/entrypoint/types.ts b/packages/core/src/entrypoint/types.ts index 54cb8b4ca7..db240bf629 100644 --- a/packages/core/src/entrypoint/types.ts +++ b/packages/core/src/entrypoint/types.ts @@ -26,7 +26,7 @@ export type SupportedEntryPoint< TAbi extends Abi | readonly unknown[] = Abi > = { version: TEntryPointVersion; - address: Record; + address: Record; abi: GetContractParameters["abi"]; /** diff --git a/packages/core/src/utils/defaults.ts b/packages/core/src/utils/defaults.ts index daf198f4ee..d396a506ca 100644 --- a/packages/core/src/utils/defaults.ts +++ b/packages/core/src/utils/defaults.ts @@ -6,6 +6,8 @@ import { base, baseGoerli, baseSepolia, + fraxtal, + fraxtalSepolia, goerli, mainnet, optimism, @@ -15,8 +17,6 @@ import { polygonAmoy, polygonMumbai, sepolia, - fraxtal, - fraxtalSepolia, zora, zoraSepolia, } from "../chains/index.js"; @@ -67,26 +67,9 @@ export const getDefaultSimpleAccountFactoryAddress = ( break; case "0.7.0": switch (chain.id) { - case mainnet.id: - case polygon.id: - case polygonMumbai.id: - case polygonAmoy.id: - case optimism.id: - case optimismSepolia.id: - case arbitrum.id: - case arbitrumSepolia.id: - case base.id: - case baseSepolia.id: - case sepolia.id: - case fraxtal.id: - case fraxtalSepolia.id: - case zora.id: - case zoraSepolia.id: - return "0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985"; default: - break; + return "0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985"; } - break; } throw new DefaultFactoryNotDefinedError("SimpleAccount", chain, version);