From d29dd4e0bfc9c1738e4c1193c261fc5ca6daaa0f Mon Sep 17 00:00:00 2001 From: Michael Moldoveanu Date: Fri, 28 Jun 2024 12:14:42 -0400 Subject: [PATCH] refactor!: move chain definitions out of aa-sdk core (#772) BREAKING CHANGE: moves the chain definitions out of aa-sdk core and into account-kit/infra --- aa-sdk/core/src/__tests__/utils.test.ts | 2 +- .../core/src/account/__tests__/simple.test.ts | 6 +- aa-sdk/core/src/chains/index.ts | 194 ----------------- .../src/client/smartAccountClient.test.ts | 2 +- aa-sdk/core/src/ens/utils.ts | 3 +- aa-sdk/core/src/index.ts | 23 --- .../signer/__tests__/wallet-client.test.ts | 4 +- aa-sdk/core/src/utils/defaults.ts | 7 +- aa-sdk/core/src/utils/index.ts | 23 --- .../src/__tests__/provider-adapter.test.ts | 11 +- aa-sdk/ethers/src/provider-adapter.ts | 22 +- aa-sdk/ethers/src/types.ts | 2 +- account-kit/infra/src/chains.ts | 195 ++++++++++++++++++ account-kit/infra/src/client/rpcClient.ts | 2 +- .../src/client/smartAccountClient.test.ts | 4 +- account-kit/infra/src/defaults.ts | 8 +- account-kit/infra/src/gas-manager.ts | 6 +- account-kit/infra/src/index.ts | 23 ++- account-kit/infra/src/schema.ts | 12 +- .../plugindefs/multi-owner/config.ts | 3 +- .../plugindefs/multisig/config.ts | 2 +- .../plugindefs/session-key/config.ts | 2 +- .../light-account/accounts/account.test.ts | 2 +- .../clients/alchemyClient.test.ts | 10 +- .../light-account/clients/alchemyClient.ts | 4 +- .../clients/multiOwnerAlchemyClient.test.ts | 10 +- .../clients/multiOwnerAlchemyClient.ts | 4 +- .../light-account/decorators/lightAccount.ts | 2 +- .../decorators/multiOwnerLightAccount.ts | 2 +- .../src/light-account/utils.ts | 5 +- .../src/msca/client/alchemyClient.ts | 4 +- .../src/msca/client/multiSigAlchemyClient.ts | 10 +- account-kit/smart-contracts/src/msca/utils.ts | 16 +- .../pages/migration-guides/migrating-to-v3.md | 12 ++ 34 files changed, 312 insertions(+), 325 deletions(-) delete mode 100644 aa-sdk/core/src/chains/index.ts diff --git a/aa-sdk/core/src/__tests__/utils.test.ts b/aa-sdk/core/src/__tests__/utils.test.ts index 80d956a506..d63d113d95 100644 --- a/aa-sdk/core/src/__tests__/utils.test.ts +++ b/aa-sdk/core/src/__tests__/utils.test.ts @@ -1,4 +1,4 @@ -import { sepolia } from "@aa-sdk/core"; +import { sepolia } from "viem/chains"; import { getEntryPoint } from "../entrypoint/index.js"; import { stringToIndex } from "../utils/index.js"; diff --git a/aa-sdk/core/src/account/__tests__/simple.test.ts b/aa-sdk/core/src/account/__tests__/simple.test.ts index 72f9506502..88b29687e2 100644 --- a/aa-sdk/core/src/account/__tests__/simple.test.ts +++ b/aa-sdk/core/src/account/__tests__/simple.test.ts @@ -5,8 +5,8 @@ import { type Address, type Chain, } from "viem"; +import { sepolia } from "viem/chains"; import { describe, it } from "vitest"; -import { sepolia } from "../../chains/index.js"; import { createBundlerClientFromExisting } from "../../client/bundlerClient.js"; import { createSmartAccountClient } from "../../client/smartAccountClient.js"; import { LocalAccountSigner } from "../../signer/local-account.js"; @@ -96,14 +96,14 @@ describe("Account Simple Tests", async () => { chain: Chain; }) => createSmartAccountClient({ - transport: http(`${chain.rpcUrls.alchemy.http[0]}/${"test"}`), + transport: http(`https://test.com`), chain: chain, account: await createSimpleSmartAccount({ chain, signer, accountAddress: "0x1234567890123456789012345678901234567890", factoryAddress: getDefaultSimpleAccountFactoryAddress(chain), - transport: http(`${chain.rpcUrls.alchemy.http[0]}/${"test"}`), + transport: http(`https://test.com`), }), }); }); diff --git a/aa-sdk/core/src/chains/index.ts b/aa-sdk/core/src/chains/index.ts deleted file mode 100644 index c2c8d61fc9..0000000000 --- a/aa-sdk/core/src/chains/index.ts +++ /dev/null @@ -1,194 +0,0 @@ -import { defineChain, type Chain } from "viem"; -import { - arbitrum as vab, - arbitrumGoerli as vabg, - arbitrumSepolia as vabs, - base as vbase, - baseGoerli as vbaseg, - baseSepolia as vbases, - goerli as vgo, - mainnet as vmain, - optimism as vop, - optimismGoerli as vopg, - optimismSepolia as vops, - polygon as vpg, - polygonMumbai as vpgm, - polygonAmoy as vpga, - sepolia as vsep, - fraxtal as vfrax, - zora as vzora, - zoraSepolia as vzoras, -} from "viem/chains"; - -export const arbitrum: Chain = { - ...vab, - rpcUrls: { - ...vab.rpcUrls, - alchemy: { - http: ["https://arb-mainnet.g.alchemy.com/v2"], - }, - }, -}; - -export const arbitrumGoerli: Chain = { - ...vabg, - rpcUrls: { - ...vabg.rpcUrls, - alchemy: { - http: ["https://arb-goerli.g.alchemy.com/v2"], - }, - }, -}; - -export const arbitrumSepolia: Chain = { - ...vabs, - rpcUrls: { - ...vabs.rpcUrls, - alchemy: { - http: ["https://arb-sepolia.g.alchemy.com/v2"], - }, - }, -}; -export const goerli: Chain = { - ...vgo, - rpcUrls: { - ...vgo.rpcUrls, - alchemy: { - http: ["https://eth-goerli.g.alchemy.com/v2"], - }, - }, -}; -export const mainnet: Chain = { - ...vmain, - rpcUrls: { - ...vmain.rpcUrls, - alchemy: { - http: ["https://eth-mainnet.g.alchemy.com/v2"], - }, - }, -}; -export const optimism: Chain = { - ...vop, - rpcUrls: { - ...vop.rpcUrls, - alchemy: { - http: ["https://opt-mainnet.g.alchemy.com/v2"], - }, - }, -}; -export const optimismGoerli: Chain = { - ...vopg, - rpcUrls: { - ...vopg.rpcUrls, - alchemy: { - http: ["https://opt-goerli.g.alchemy.com/v2"], - }, - }, -}; -export const optimismSepolia: Chain = { - ...vops, - rpcUrls: { - ...vops.rpcUrls, - alchemy: { - http: ["https://opt-sepolia.g.alchemy.com/v2"], - }, - }, -}; -export const sepolia: Chain = { - ...vsep, - rpcUrls: { - ...vsep.rpcUrls, - alchemy: { - http: ["https://eth-sepolia.g.alchemy.com/v2"], - }, - }, -}; -export const base: Chain = { - ...vbase, - rpcUrls: { - ...vbase.rpcUrls, - alchemy: { - http: ["https://base-mainnet.g.alchemy.com/v2"], - }, - }, -}; -export const baseGoerli: Chain = { - ...vbaseg, - rpcUrls: { - ...vbaseg.rpcUrls, - alchemy: { - http: ["https://base-goerli.g.alchemy.com/v2"], - }, - }, -}; -export const baseSepolia: Chain = { - ...vbases, - rpcUrls: { - ...vbases.rpcUrls, - alchemy: { - http: ["https://base-sepolia.g.alchemy.com/v2"], - }, - }, -}; - -export const polygonMumbai: Chain = { - ...vpgm, - rpcUrls: { - ...vpgm.rpcUrls, - alchemy: { - http: ["https://polygon-mumbai.g.alchemy.com/v2"], - }, - }, -}; - -export const polygonAmoy: Chain = { - ...vpga, - rpcUrls: { - ...vpga.rpcUrls, - alchemy: { - http: ["https://polygon-amoy.g.alchemy.com/v2"], - }, - }, -}; - -export const polygon: Chain = { - ...vpg, - rpcUrls: { - ...vpg.rpcUrls, - alchemy: { - http: ["https://polygon-mainnet.g.alchemy.com/v2"], - }, - }, -}; - -export const fraxtal: Chain = { - ...vfrax, - rpcUrls: { - ...vfrax.rpcUrls, - }, -}; - -export const fraxtalSepolia: Chain = defineChain({ - id: 2523, - name: "Fraxtal Sepolia", - nativeCurrency: { name: "Frax Ether", symbol: "frxETH", decimals: 18 }, - rpcUrls: { - default: { - http: ["https://rpc.testnet-sepolia.frax.com"], - }, - }, -}); - -export const zora: Chain = { - ...vzora, - rpcUrls: { - ...vzora.rpcUrls, - }, -}; - -export const zoraSepolia: Chain = { - ...vzoras, - rpcUrls: { - ...vzoras.rpcUrls, - }, -}; diff --git a/aa-sdk/core/src/client/smartAccountClient.test.ts b/aa-sdk/core/src/client/smartAccountClient.test.ts index c141c48957..33e6650fd9 100644 --- a/aa-sdk/core/src/client/smartAccountClient.test.ts +++ b/aa-sdk/core/src/client/smartAccountClient.test.ts @@ -1,5 +1,5 @@ -import { polygonMumbai } from "@aa-sdk/core"; import { custom, type Transaction } from "viem"; +import { polygonMumbai } from "viem/chains"; import type { SpyInstance } from "vitest"; import * as receiptActions from "../actions/bundler/getUserOperationReceipt.js"; import type { UserOperationReceipt } from "../types.js"; diff --git a/aa-sdk/core/src/ens/utils.ts b/aa-sdk/core/src/ens/utils.ts index 382604360f..b52065e48c 100644 --- a/aa-sdk/core/src/ens/utils.ts +++ b/aa-sdk/core/src/ens/utils.ts @@ -1,6 +1,5 @@ -import type { Chain } from "viem/chains"; import * as chains from "viem/chains"; -import { mainnet } from "../chains/index.js"; +import { mainnet, type Chain } from "viem/chains"; export const ChainsById: Map = new Map( Object.values(chains).map((x) => [x.id, x]) diff --git a/aa-sdk/core/src/index.ts b/aa-sdk/core/src/index.ts index 034d1a50d5..7a3613df2c 100644 --- a/aa-sdk/core/src/index.ts +++ b/aa-sdk/core/src/index.ts @@ -31,27 +31,6 @@ export { sendTransactions } from "./actions/smartAccount/sendTransactions.js"; export { sendUserOperation } from "./actions/smartAccount/sendUserOperation.js"; export type * from "./actions/smartAccount/types.js"; export { waitForUserOperationTransaction } from "./actions/smartAccount/waitForUserOperationTransacation.js"; -export { - arbitrum, - arbitrumGoerli, - arbitrumSepolia, - base, - baseGoerli, - baseSepolia, - fraxtal, - fraxtalSepolia, - goerli, - mainnet, - optimism, - optimismGoerli, - optimismSepolia, - polygon, - polygonAmoy, - polygonMumbai, - sepolia, - zora, - zoraSepolia, -} from "./chains/index.js"; export type * from "./client/bundlerClient.js"; export { createBundlerClient, @@ -136,7 +115,6 @@ export { split, type SplitTransportParams } from "./transport/split.js"; export type * from "./types.js"; export type * from "./utils/index.js"; export { - AlchemyChainMap, BigNumberishRangeSchema, BigNumberishSchema, ChainSchema, @@ -154,7 +132,6 @@ export { concatPaymasterAndData, deepHexlify, filterUndefined, - getChain, getDefaultSimpleAccountFactoryAddress, getDefaultUserOperationFeeOptions, isBigNumberish, diff --git a/aa-sdk/core/src/signer/__tests__/wallet-client.test.ts b/aa-sdk/core/src/signer/__tests__/wallet-client.test.ts index c5a6a2c85f..56e1bbf861 100644 --- a/aa-sdk/core/src/signer/__tests__/wallet-client.test.ts +++ b/aa-sdk/core/src/signer/__tests__/wallet-client.test.ts @@ -1,4 +1,3 @@ -import { polygonMumbai } from "@aa-sdk/core"; import { createWalletClient, http } from "viem"; import { mnemonicToAccount } from "viem/accounts"; import { WalletClientSigner } from "../wallet-client.js"; @@ -10,7 +9,8 @@ describe("Wallet Client Signer Tests", () => { const wallet = mnemonicToAccount(dummyMnemonic); const walletClient = createWalletClient({ account: wallet, - transport: http(`${polygonMumbai.rpcUrls.alchemy.http[0]}/test`), + // just a nonsense URL + transport: http(`https://rpc.testnet.viem.io`), }); const smartAccountSigner: WalletClientSigner = new WalletClientSigner( diff --git a/aa-sdk/core/src/utils/defaults.ts b/aa-sdk/core/src/utils/defaults.ts index d396a506ca..9b85459943 100644 --- a/aa-sdk/core/src/utils/defaults.ts +++ b/aa-sdk/core/src/utils/defaults.ts @@ -7,7 +7,6 @@ import { baseGoerli, baseSepolia, fraxtal, - fraxtalSepolia, goerli, mainnet, optimism, @@ -19,11 +18,11 @@ import { sepolia, zora, zoraSepolia, -} from "../chains/index.js"; +} from "viem/chains"; import { defaultEntryPointVersion } from "../entrypoint/index.js"; import type { EntryPointVersion } from "../entrypoint/types.js"; import { DefaultFactoryNotDefinedError } from "../errors/account.js"; -import type { UserOperationFeeOptions } from "../types"; +import type { UserOperationFeeOptions } from "../types.js"; /** * Utility method returning the default simple account factory address given a {@link Chain} object @@ -51,7 +50,7 @@ export const getDefaultSimpleAccountFactoryAddress = ( case baseGoerli.id: case baseSepolia.id: case fraxtal.id: - case fraxtalSepolia.id: + case 2523: case zora.id: case zoraSepolia.id: return "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232"; diff --git a/aa-sdk/core/src/utils/index.ts b/aa-sdk/core/src/utils/index.ts index d9e0507f91..148c29ffdd 100644 --- a/aa-sdk/core/src/utils/index.ts +++ b/aa-sdk/core/src/utils/index.ts @@ -1,30 +1,7 @@ -import type { Chain } from "viem"; import { toHex } from "viem"; -import * as chains from "viem/chains"; -import * as alchemyChains from "../chains/index.js"; import type { PromiseOrValue } from "../types.js"; import type { RecordableKeys } from "./types.js"; -export const AlchemyChainMap = new Map( - Object.values(alchemyChains).map((c) => [c.id, c]) -); - -/** - * Utility method for converting a chainId to a {@link Chain} object - * - * @param chainId - the chainId to convert - * @returns a {@link Chain} object for the given chainId - * @throws if the chainId is not found - */ -export const getChain = (chainId: number): Chain => { - for (const chain of Object.values(chains)) { - if (chain.id === chainId) { - return AlchemyChainMap.get(chain.id) ?? chain; - } - } - throw new Error("could not find chain"); -}; - /** * Utility function that allows for piping a series of async functions together * diff --git a/aa-sdk/ethers/src/__tests__/provider-adapter.test.ts b/aa-sdk/ethers/src/__tests__/provider-adapter.test.ts index 09f82e06a8..be214fbd20 100644 --- a/aa-sdk/ethers/src/__tests__/provider-adapter.test.ts +++ b/aa-sdk/ethers/src/__tests__/provider-adapter.test.ts @@ -1,11 +1,11 @@ import { createSimpleSmartAccount, - getChain, getDefaultSimpleAccountFactoryAddress, } from "@aa-sdk/core"; import { Wallet } from "@ethersproject/wallet"; import { Alchemy, Network, type AlchemyProvider } from "alchemy-sdk"; import { http } from "viem"; +import { polygonMumbai } from "viem/chains"; import { EthersProviderAdapter } from "../../src/provider-adapter.js"; import { convertWalletToAccountSigner } from "../utils.js"; @@ -39,19 +39,18 @@ const givenConnectedProvider = async ({ alchemyProvider: AlchemyProvider; signer: Wallet; }) => { - const chain = getChain(alchemyProvider.network.chainId); + const chain = polygonMumbai; return EthersProviderAdapter.fromEthersProvider( - alchemyProvider + alchemyProvider, + chain ).connectToAccount( await createSimpleSmartAccount({ chain, signer: convertWalletToAccountSigner(signer), accountAddress: "0x856185aedfab56809e6686d2d6d0c039d615bd9c", factoryAddress: getDefaultSimpleAccountFactoryAddress(chain), - transport: http( - `${chain.rpcUrls.alchemy.http[0]}/${alchemyProvider.apiKey}` - ), + transport: http(`${alchemyProvider.connection.url}`), }) ); }; diff --git a/aa-sdk/ethers/src/provider-adapter.ts b/aa-sdk/ethers/src/provider-adapter.ts index dbdce800e9..b507474831 100644 --- a/aa-sdk/ethers/src/provider-adapter.ts +++ b/aa-sdk/ethers/src/provider-adapter.ts @@ -1,13 +1,18 @@ import { createBundlerClientFromExisting, createSmartAccountClient, - getChain, type BundlerClient, type SmartAccountClient, type SmartContractAccount, } from "@aa-sdk/core"; import { JsonRpcProvider } from "@ethersproject/providers"; -import { createPublicClient, custom, http, type Transport } from "viem"; +import { + createPublicClient, + custom, + http, + type Chain, + type Transport, +} from "viem"; import { AccountSigner } from "./account-signer.js"; import type { EthersProviderAdapterOpts } from "./types.js"; @@ -21,7 +26,8 @@ export class EthersProviderAdapter extends JsonRpcProvider { if ("accountProvider" in opts) { this.accountProvider = opts.accountProvider; } else { - const chain = getChain(opts.chainId); + const { chain } = opts; + if (typeof opts.rpcProvider === "string") { this.accountProvider = createSmartAccountClient({ transport: http(opts.rpcProvider), @@ -75,13 +81,17 @@ export class EthersProviderAdapter extends JsonRpcProvider { /** * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider. * - * @param provider - the ethers JSON RPC provider to convert + * @param provider the ethers JSON RPC provider to convert + * @param chain the chain to connect to * @returns an instance of {@link EthersProviderAdapter} */ - static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter { + static fromEthersProvider( + provider: JsonRpcProvider, + chain: Chain + ): EthersProviderAdapter { return new EthersProviderAdapter({ rpcProvider: provider.connection.url, - chainId: provider.network.chainId, + chain, }); } } diff --git a/aa-sdk/ethers/src/types.ts b/aa-sdk/ethers/src/types.ts index 1a1703e1ef..2ebab879bf 100644 --- a/aa-sdk/ethers/src/types.ts +++ b/aa-sdk/ethers/src/types.ts @@ -16,7 +16,7 @@ export type EthersProviderAdapterOpts< } & ( | { rpcProvider: string | BundlerClient; - chainId: number; + chain: Chain; } | { accountProvider: SmartAccountClient; diff --git a/account-kit/infra/src/chains.ts b/account-kit/infra/src/chains.ts index 99fbc34522..5f7c0bb669 100644 --- a/account-kit/infra/src/chains.ts +++ b/account-kit/infra/src/chains.ts @@ -1,5 +1,27 @@ import type { Chain } from "viem"; +import { defineChain } from "viem"; +import { + arbitrum as vab, + arbitrumGoerli as vabg, + arbitrumSepolia as vabs, + base as vbase, + baseGoerli as vbaseg, + baseSepolia as vbases, + fraxtal as vfrax, + goerli as vgo, + mainnet as vmain, + optimism as vop, + optimismGoerli as vopg, + optimismSepolia as vops, + polygon as vpg, + polygonAmoy as vpga, + polygonMumbai as vpgm, + sepolia as vsep, + zora as vzora, + zoraSepolia as vzoras, +} from "viem/chains"; + export type AlchemyChainConfig = { chain: Chain; rpcBaseUrl: string; @@ -41,3 +63,176 @@ export const defineAlchemyChain = ({ }, }; }; + +export const arbitrum: Chain = { + ...vab, + rpcUrls: { + ...vab.rpcUrls, + alchemy: { + http: ["https://arb-mainnet.g.alchemy.com/v2"], + }, + }, +}; + +export const arbitrumGoerli: Chain = { + ...vabg, + rpcUrls: { + ...vabg.rpcUrls, + alchemy: { + http: ["https://arb-goerli.g.alchemy.com/v2"], + }, + }, +}; + +export const arbitrumSepolia: Chain = { + ...vabs, + rpcUrls: { + ...vabs.rpcUrls, + alchemy: { + http: ["https://arb-sepolia.g.alchemy.com/v2"], + }, + }, +}; +export const goerli: Chain = { + ...vgo, + rpcUrls: { + ...vgo.rpcUrls, + alchemy: { + http: ["https://eth-goerli.g.alchemy.com/v2"], + }, + }, +}; +export const mainnet: Chain = { + ...vmain, + rpcUrls: { + ...vmain.rpcUrls, + alchemy: { + http: ["https://eth-mainnet.g.alchemy.com/v2"], + }, + }, +}; +export const optimism: Chain = { + ...vop, + rpcUrls: { + ...vop.rpcUrls, + alchemy: { + http: ["https://opt-mainnet.g.alchemy.com/v2"], + }, + }, +}; +export const optimismGoerli: Chain = { + ...vopg, + rpcUrls: { + ...vopg.rpcUrls, + alchemy: { + http: ["https://opt-goerli.g.alchemy.com/v2"], + }, + }, +}; +export const optimismSepolia: Chain = { + ...vops, + rpcUrls: { + ...vops.rpcUrls, + alchemy: { + http: ["https://opt-sepolia.g.alchemy.com/v2"], + }, + }, +}; +export const sepolia: Chain = { + ...vsep, + rpcUrls: { + ...vsep.rpcUrls, + alchemy: { + http: ["https://eth-sepolia.g.alchemy.com/v2"], + }, + }, +}; +export const base: Chain = { + ...vbase, + rpcUrls: { + ...vbase.rpcUrls, + alchemy: { + http: ["https://base-mainnet.g.alchemy.com/v2"], + }, + }, +}; +export const baseGoerli: Chain = { + ...vbaseg, + rpcUrls: { + ...vbaseg.rpcUrls, + alchemy: { + http: ["https://base-goerli.g.alchemy.com/v2"], + }, + }, +}; +export const baseSepolia: Chain = { + ...vbases, + rpcUrls: { + ...vbases.rpcUrls, + alchemy: { + http: ["https://base-sepolia.g.alchemy.com/v2"], + }, + }, +}; + +export const polygonMumbai: Chain = { + ...vpgm, + rpcUrls: { + ...vpgm.rpcUrls, + alchemy: { + http: ["https://polygon-mumbai.g.alchemy.com/v2"], + }, + }, +}; + +export const polygonAmoy: Chain = { + ...vpga, + rpcUrls: { + ...vpga.rpcUrls, + alchemy: { + http: ["https://polygon-amoy.g.alchemy.com/v2"], + }, + }, +}; + +export const polygon: Chain = { + ...vpg, + rpcUrls: { + ...vpg.rpcUrls, + alchemy: { + http: ["https://polygon-mainnet.g.alchemy.com/v2"], + }, + }, +}; + +export const fraxtal: Chain = { + ...vfrax, + rpcUrls: { + ...vfrax.rpcUrls, + }, +}; + +export const fraxtalSepolia: Chain = defineChain({ + id: 2523, + name: "Fraxtal Sepolia", + nativeCurrency: { name: "Frax Ether", symbol: "frxETH", decimals: 18 }, + rpcUrls: { + default: { + http: ["https://rpc.testnet-sepolia.frax.com"], + }, + }, +}); + +export const zora: Chain = { + ...vzora, + rpcUrls: { + ...vzora.rpcUrls, + }, +}; + +export const zoraSepolia: Chain = { + ...vzoras, + rpcUrls: { + ...vzoras.rpcUrls, + }, +}; diff --git a/account-kit/infra/src/client/rpcClient.ts b/account-kit/infra/src/client/rpcClient.ts index 665bb490dd..0e10294fd3 100644 --- a/account-kit/infra/src/client/rpcClient.ts +++ b/account-kit/infra/src/client/rpcClient.ts @@ -14,7 +14,7 @@ import type { ClientWithAlchemyMethods } from "./types.js"; * @example * ```ts * import { createAlchemyPublicRpcClient } from "@account-kit/infra"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * * const client = createAlchemyPublicRpcClient({ * chain: sepolia, diff --git a/account-kit/infra/src/client/smartAccountClient.test.ts b/account-kit/infra/src/client/smartAccountClient.test.ts index 9f807e2a74..9be7fd612f 100644 --- a/account-kit/infra/src/client/smartAccountClient.test.ts +++ b/account-kit/infra/src/client/smartAccountClient.test.ts @@ -1,12 +1,12 @@ -import { createLightAccount } from "@account-kit/smart-contracts"; import { LocalAccountSigner, - sepolia, type ClientMiddlewareFn, type SmartContractAccount, } from "@aa-sdk/core"; +import { createLightAccount } from "@account-kit/smart-contracts"; import { http, zeroAddress } from "viem"; import { generatePrivateKey } from "viem/accounts"; +import { sepolia } from "../chains.js"; import { createAlchemySmartAccountClient } from "./smartAccountClient.js"; const headerMatcher = { diff --git a/account-kit/infra/src/defaults.ts b/account-kit/infra/src/defaults.ts index e37680a6f5..f9d4bacb12 100644 --- a/account-kit/infra/src/defaults.ts +++ b/account-kit/infra/src/defaults.ts @@ -1,3 +1,5 @@ +import { type UserOperationFeeOptions } from "@aa-sdk/core"; +import type { Chain } from "viem"; import { arbitrum, arbitrumGoerli, @@ -5,9 +7,7 @@ import { optimism, optimismGoerli, optimismSepolia, - type UserOperationFeeOptions, -} from "@aa-sdk/core"; -import type { Chain } from "viem"; +} from "./chains.js"; /** * Retrieves the default user operation fee options for a given chain. Adjusts fees for specific chains like Arbitrum and Optimism. @@ -15,7 +15,7 @@ import type { Chain } from "viem"; * @example * ```ts * import { getDefaultUserOperationFeeOptions } from "@account-kit/infra"; - * import { arbitrum } from "@account-kit/infra/chains"; + * import { arbitrum } from "@account-kit/infra"; * * const feeOpts = getDefaultUserOperationFeeOptions(arbitrum); * ``` diff --git a/account-kit/infra/src/gas-manager.ts b/account-kit/infra/src/gas-manager.ts index 9d51387865..d343ece7e6 100644 --- a/account-kit/infra/src/gas-manager.ts +++ b/account-kit/infra/src/gas-manager.ts @@ -1,3 +1,4 @@ +import type { Address, Chain } from "viem"; import { arbitrum, arbitrumSepolia, @@ -14,8 +15,7 @@ import { sepolia, zora, zoraSepolia, -} from "@aa-sdk/core"; -import type { Address, Chain } from "viem"; +} from "./chains.js"; export const AlchemyPaymasterAddressV3 = "0x4f84a207A80c39E9e8BaE717c1F25bA7AD1fB08F"; @@ -31,7 +31,7 @@ export const AlchemyPaymasterAddressV1 = * * @example * ```ts - * import { sepolia, getAlchemyPaymasterAddress } from "@account-kit/infra/chains"; + * import { sepolia, getAlchemyPaymasterAddress } from "@account-kit/infra"; * * const paymasterAddress = getAlchemyPaymasterAddress(sepolia); * ``` diff --git a/account-kit/infra/src/index.ts b/account-kit/infra/src/index.ts index 168c9138bb..d48eda6390 100644 --- a/account-kit/infra/src/index.ts +++ b/account-kit/infra/src/index.ts @@ -2,7 +2,28 @@ export type * from "./actions/simulateUserOperationChanges.js"; export { simulateUserOperationChanges } from "./actions/simulateUserOperationChanges.js"; export type * from "./actions/types.js"; export type * from "./chains.js"; -export { defineAlchemyChain } from "./chains.js"; +export { + arbitrum, + arbitrumGoerli, + arbitrumSepolia, + base, + baseGoerli, + baseSepolia, + defineAlchemyChain, + fraxtal, + fraxtalSepolia, + goerli, + mainnet, + optimism, + optimismGoerli, + optimismSepolia, + polygon, + polygonAmoy, + polygonMumbai, + sepolia, + zora, + zoraSepolia, +} from "./chains.js"; export type * from "./client/decorators/alchemyEnhancedApis.js"; export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js"; export type * from "./client/decorators/smartAccount.js"; diff --git a/account-kit/infra/src/schema.ts b/account-kit/infra/src/schema.ts index c9b46a7ce0..b442f22fe6 100644 --- a/account-kit/infra/src/schema.ts +++ b/account-kit/infra/src/schema.ts @@ -2,23 +2,15 @@ import { ChainSchema, ConnectionConfigSchema, SmartAccountClientOptsSchema, - getChain, } from "@aa-sdk/core"; import { Alchemy } from "alchemy-sdk"; import type { Chain } from "viem"; import z from "zod"; export const AlchemyChainSchema = z.custom((chain) => { - const _chain = ChainSchema.parse(chain); + const chain_ = ChainSchema.parse(chain); - let chainObject; - try { - chainObject = getChain(_chain.id); - } catch { - return false; - } - - return chainObject.rpcUrls.alchemy != null; + return chain_.rpcUrls.alchemy != null; }, "chain must include an alchemy rpc url. See `createAlchemyChain` or use the `AlchemyChainMap` exported from `@aa-sdk/core`"); export const AlchemyProviderConfigSchema = ConnectionConfigSchema.and( diff --git a/account-kit/smart-contracts/plugindefs/multi-owner/config.ts b/account-kit/smart-contracts/plugindefs/multi-owner/config.ts index 6ac258f5db..4aedab1809 100644 --- a/account-kit/smart-contracts/plugindefs/multi-owner/config.ts +++ b/account-kit/smart-contracts/plugindefs/multi-owner/config.ts @@ -14,7 +14,7 @@ import { sepolia, zora, zoraSepolia, -} from "@aa-sdk/core"; +} from "@account-kit/infra"; import type { PluginConfig } from "@account-kit/plugingen"; import { parseAbiParameters } from "viem"; import { MultiOwnerPluginAbi } from "./abi.js"; @@ -33,7 +33,6 @@ export const MultiOwnerPluginGenConfig: PluginConfig = { [arbitrum.id]: "0xcE0000007B008F50d762D155002600004cD6c647", [arbitrumSepolia.id]: "0xcE0000007B008F50d762D155002600004cD6c647", [base.id]: "0xcE0000007B008F50d762D155002600004cD6c647", - [baseSepolia.id]: "0xcE0000007B008F50d762D155002600004cD6c647", [fraxtal.id]: "0xcE0000007B008F50d762D155002600004cD6c647", [fraxtalSepolia.id]: "0xcE0000007B008F50d762D155002600004cD6c647", [zora.id]: "0xcE0000007B008F50d762D155002600004cD6c647", diff --git a/account-kit/smart-contracts/plugindefs/multisig/config.ts b/account-kit/smart-contracts/plugindefs/multisig/config.ts index 088da22bce..5b1a93aff5 100644 --- a/account-kit/smart-contracts/plugindefs/multisig/config.ts +++ b/account-kit/smart-contracts/plugindefs/multisig/config.ts @@ -13,7 +13,7 @@ import { sepolia, zora, zoraSepolia, -} from "@aa-sdk/core"; +} from "@account-kit/infra"; import type { PluginConfig } from "@account-kit/plugingen"; import { parseAbiParameters } from "viem"; import { MultisigPluginAbi } from "./abi.js"; diff --git a/account-kit/smart-contracts/plugindefs/session-key/config.ts b/account-kit/smart-contracts/plugindefs/session-key/config.ts index 4fe224474a..2d6ef1f6b8 100644 --- a/account-kit/smart-contracts/plugindefs/session-key/config.ts +++ b/account-kit/smart-contracts/plugindefs/session-key/config.ts @@ -14,7 +14,7 @@ import { sepolia, zora, zoraSepolia, -} from "@aa-sdk/core"; +} from "@account-kit/infra"; import type { PluginConfig } from "@account-kit/plugingen"; import { parseAbiParameters } from "viem"; import { MultiOwnerPluginGenConfig } from "../multi-owner/config.js"; diff --git a/account-kit/smart-contracts/src/light-account/accounts/account.test.ts b/account-kit/smart-contracts/src/light-account/accounts/account.test.ts index f74aa3f321..141e83a9be 100644 --- a/account-kit/smart-contracts/src/light-account/accounts/account.test.ts +++ b/account-kit/smart-contracts/src/light-account/accounts/account.test.ts @@ -1,9 +1,9 @@ import { LocalAccountSigner, - polygonMumbai, type BatchUserOperationCallData, type SmartAccountSigner, } from "@aa-sdk/core"; +import { polygonMumbai } from "@account-kit/infra"; import { custom, type Chain } from "viem"; import { createLightAccountClient } from "../clients/client.js"; import type { LightAccountVersion } from "../types.js"; diff --git a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts index 4084993756..2d8d392557 100644 --- a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts +++ b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts @@ -1,14 +1,14 @@ -import { - alchemyEnhancedApiActions, - createAlchemySmartAccountClient, -} from "@account-kit/infra"; import * as AACoreModule from "@aa-sdk/core"; import { LocalAccountSigner, - polygonMumbai, type BatchUserOperationCallData, type SmartAccountSigner, } from "@aa-sdk/core"; +import { + alchemyEnhancedApiActions, + createAlchemySmartAccountClient, + polygonMumbai, +} from "@account-kit/infra"; import { Alchemy, Network } from "alchemy-sdk"; import { avalanche, type Chain } from "viem/chains"; import { createLightAccountAlchemyClient } from "./alchemyClient.js"; diff --git a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.ts b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.ts index 50c7f617cb..b4db13cee0 100644 --- a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.ts +++ b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.ts @@ -1,3 +1,4 @@ +import type { HttpTransport, SmartAccountSigner } from "@aa-sdk/core"; import { AlchemyProviderConfigSchema, createAlchemyPublicRpcClient, @@ -12,7 +13,6 @@ import { type LightAccount, type LightAccountClientActions, } from "@account-kit/smart-contracts"; -import type { HttpTransport, SmartAccountSigner } from "@aa-sdk/core"; import { custom, type Chain, type CustomTransport, type Transport } from "viem"; export type AlchemyLightAccountClientConfig< @@ -45,7 +45,7 @@ export async function createLightAccountAlchemyClient< * @example * ```ts * import { createLightAccountAlchemyClient } from "@account-kit/smart-contracts"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * import { LocalAccountSigner } from "@aa-sdk/core"; * import { generatePrivateKey } from "viem" * diff --git a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts index 35dde9f7aa..2b9bb30085 100644 --- a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts +++ b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts @@ -1,14 +1,14 @@ -import { - alchemyEnhancedApiActions, - createAlchemySmartAccountClient, -} from "@account-kit/infra"; import * as AACoreModule from "@aa-sdk/core"; import { - arbitrumSepolia, LocalAccountSigner, type BatchUserOperationCallData, type SmartAccountSigner, } from "@aa-sdk/core"; +import { + alchemyEnhancedApiActions, + arbitrumSepolia, + createAlchemySmartAccountClient, +} from "@account-kit/infra"; import { Alchemy, Network } from "alchemy-sdk"; import { avalanche, type Chain } from "viem/chains"; import { createMultiOwnerLightAccountAlchemyClient } from "./multiOwnerAlchemyClient.js"; diff --git a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.ts b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.ts index 62d2172436..880815739e 100644 --- a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.ts +++ b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.ts @@ -1,3 +1,4 @@ +import type { HttpTransport, SmartAccountSigner } from "@aa-sdk/core"; import { AlchemyProviderConfigSchema, createAlchemyPublicRpcClient, @@ -12,7 +13,6 @@ import { type MultiOwnerLightAccount, type MultiOwnerLightAccountClientActions, } from "@account-kit/smart-contracts"; -import type { HttpTransport, SmartAccountSigner } from "@aa-sdk/core"; import { custom, type Chain, type CustomTransport, type Transport } from "viem"; export type AlchemyMultiOwnerLightAccountClientConfig< @@ -49,7 +49,7 @@ export async function createMultiOwnerLightAccountAlchemyClient< * @example * ```ts * import { createMultiOwnerLightAccountAlchemyClient } from "@account-kit/smart-contracts"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * import { LocalAccountSigner } from "@aa-sdk/core"; * import { generatePrivateKey } from "viem" * diff --git a/account-kit/smart-contracts/src/light-account/decorators/lightAccount.ts b/account-kit/smart-contracts/src/light-account/decorators/lightAccount.ts index 8df7fd35d9..0c07d20990 100644 --- a/account-kit/smart-contracts/src/light-account/decorators/lightAccount.ts +++ b/account-kit/smart-contracts/src/light-account/decorators/lightAccount.ts @@ -24,7 +24,7 @@ export type LightAccountClientActions< * ```ts * import { lightAccountClientActions, createLightAccount } from "@account-kit/smart-contracts"; * import { createAlchemySmartAccountClient } from "@account-kit/infra"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * * const smartAccountClient = createAlchemySmartAccountClient({ * account: await createLightAccount(...), diff --git a/account-kit/smart-contracts/src/light-account/decorators/multiOwnerLightAccount.ts b/account-kit/smart-contracts/src/light-account/decorators/multiOwnerLightAccount.ts index b9802696b9..7309ebd698 100644 --- a/account-kit/smart-contracts/src/light-account/decorators/multiOwnerLightAccount.ts +++ b/account-kit/smart-contracts/src/light-account/decorators/multiOwnerLightAccount.ts @@ -24,7 +24,7 @@ export type MultiOwnerLightAccountClientActions< * ```ts * import { multiOwnerLightAccountClientActions, createMultiOwnerLightAccount } from "@account-kit/smart-contracts"; * import { createAlchemySmartAccountClient } from "@account-kit/infra"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * * const smartAccountClient = createAlchemySmartAccountClient({ * account: await createMultiOwnerLightAccount(...), diff --git a/account-kit/smart-contracts/src/light-account/utils.ts b/account-kit/smart-contracts/src/light-account/utils.ts index 7948ed7cde..2dea8a29cc 100644 --- a/account-kit/smart-contracts/src/light-account/utils.ts +++ b/account-kit/smart-contracts/src/light-account/utils.ts @@ -1,5 +1,5 @@ +import { DefaultFactoryNotDefinedError, toRecord } from "@aa-sdk/core"; import { - DefaultFactoryNotDefinedError, arbitrum, arbitrumGoerli, arbitrumSepolia, @@ -17,10 +17,9 @@ import { polygonAmoy, polygonMumbai, sepolia, - toRecord, zora, zoraSepolia, -} from "@aa-sdk/core"; +} from "@account-kit/infra"; import { fromHex, type Address, type Chain } from "viem"; import type { LightAccountBase } from "./accounts/base"; import type { diff --git a/account-kit/smart-contracts/src/msca/client/alchemyClient.ts b/account-kit/smart-contracts/src/msca/client/alchemyClient.ts index 446c2fcdf6..6adca7cd34 100644 --- a/account-kit/smart-contracts/src/msca/client/alchemyClient.ts +++ b/account-kit/smart-contracts/src/msca/client/alchemyClient.ts @@ -1,3 +1,4 @@ +import type { SmartAccountSigner } from "@aa-sdk/core"; import { AlchemyProviderConfigSchema, createAlchemyPublicRpcClient, @@ -17,7 +18,6 @@ import { type MultiOwnerPluginActions, type PluginManagerActions, } from "@account-kit/smart-contracts"; -import type { SmartAccountSigner } from "@aa-sdk/core"; import { custom, type Chain, @@ -58,7 +58,7 @@ export function createModularAccountAlchemyClient< * @example * ```ts * import { createModularAccountAlchemyClient } from "@account-kit/smart-contracts"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * import { LocalAccountSigner } from "@aa-sdk/core"; * import { generatePrivateKey } from "viem" * diff --git a/account-kit/smart-contracts/src/msca/client/multiSigAlchemyClient.ts b/account-kit/smart-contracts/src/msca/client/multiSigAlchemyClient.ts index 4c9603e972..1b9f4bd8ca 100644 --- a/account-kit/smart-contracts/src/msca/client/multiSigAlchemyClient.ts +++ b/account-kit/smart-contracts/src/msca/client/multiSigAlchemyClient.ts @@ -1,3 +1,7 @@ +import { + smartAccountClientActions, + type SmartAccountSigner, +} from "@aa-sdk/core"; import { AlchemyProviderConfigSchema, createAlchemyPublicRpcClient, @@ -19,10 +23,6 @@ import { type MultisigUserOperationContext, type PluginManagerActions, } from "@account-kit/smart-contracts"; -import { - smartAccountClientActions, - type SmartAccountSigner, -} from "@aa-sdk/core"; import { custom, type Chain, @@ -71,7 +71,7 @@ export function createMultisigAccountAlchemyClient< * @example * ```ts * import { createMultisigAccountAlchemyClient } from "@account-kit/smart-contracts"; - * import { sepolia } from "@account-kit/infra/chains"; + * import { sepolia } from "@account-kit/infra"; * import { LocalAccountSigner } from "@aa-sdk/core"; * import { generatePrivateKey } from "viem" * diff --git a/account-kit/smart-contracts/src/msca/utils.ts b/account-kit/smart-contracts/src/msca/utils.ts index 8b22f6b347..d793d074b8 100644 --- a/account-kit/smart-contracts/src/msca/utils.ts +++ b/account-kit/smart-contracts/src/msca/utils.ts @@ -1,6 +1,14 @@ import { AccountNotFoundError, ChainNotFoundError, + type GetAccountParameter, + type SmartAccountClient, + type SmartAccountSigner, + type SmartContractAccount, + type SmartContractAccountWithSigner, + type UpgradeToData, +} from "@aa-sdk/core"; +import { arbitrum, arbitrumSepolia, base, @@ -11,13 +19,7 @@ import { polygon, polygonAmoy, sepolia, - type GetAccountParameter, - type SmartAccountClient, - type SmartAccountSigner, - type SmartContractAccount, - type SmartContractAccountWithSigner, - type UpgradeToData, -} from "@aa-sdk/core"; +} from "@account-kit/infra"; import type { Address, Chain, Transport } from "viem"; import { custom, diff --git a/site/pages/migration-guides/migrating-to-v3.md b/site/pages/migration-guides/migrating-to-v3.md index 1b837e4444..e3aee5c2c7 100644 --- a/site/pages/migration-guides/migrating-to-v3.md +++ b/site/pages/migration-guides/migrating-to-v3.md @@ -32,6 +32,18 @@ This method has been removed. Use [`verifyMessage`](https://viem.sh/docs/actions This method is no longer used internally and has been removed. The reference impl can be found within `ethers.js`. +### Utils: `getChain` removed + +This method was not super efficient and maintainable because it was importing all the chains from viem. That meant that if you used this method, it risked increasing your bundle size massively. Now all methods require a `Chain` instead of `chainId` in some places. + +### Ethers: `Chain` required param + +Certain methods required a `chainId` which would be converted into a `Chain` using the above method. This has been removed for the reasons above. + +### Alchemy `Chain` defs + +The Alchemy `Chain` definitions have been moved from `@aa-sdk/core` to `@account-kit/infra`. + ## Migrating to version 3.x.x This version update brings a lot of breaking changes. As we began to support Modular Accounts and their interfaces, we realized that the previous version of the SDK was not as flexible as it could have been to handle the modularity of the new account interfaces.