Skip to content

Commit

Permalink
refactor: don't throw in get default address methods (alchemyplatform…
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored May 30, 2024
1 parent b1082f9 commit accb23b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 141 deletions.
41 changes: 2 additions & 39 deletions packages/accounts/src/msca/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"
);
};

/**
Expand All @@ -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<
Expand Down
41 changes: 1 addition & 40 deletions packages/core/src/entrypoint/0.6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
41 changes: 1 addition & 40 deletions packages/core/src/entrypoint/0.7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/entrypoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/entrypoint/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type SupportedEntryPoint<
TAbi extends Abi | readonly unknown[] = Abi
> = {
version: TEntryPointVersion;
address: Record<TChain["id"], Address>;
address: Record<TChain["id"] | "default", Address>;
abi: GetContractParameters<Transport, TChain, Account, TAbi>["abi"];

/**
Expand Down
23 changes: 3 additions & 20 deletions packages/core/src/utils/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
base,
baseGoerli,
baseSepolia,
fraxtal,
fraxtalSepolia,
goerli,
mainnet,
optimism,
Expand All @@ -15,8 +17,6 @@ import {
polygonAmoy,
polygonMumbai,
sepolia,
fraxtal,
fraxtalSepolia,
zora,
zoraSepolia,
} from "../chains/index.js";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit accb23b

Please sign in to comment.