diff --git a/packages/accounts/package.json b/packages/accounts/package.json index 05414e9b94..09f3d7826a 100644 --- a/packages/accounts/package.json +++ b/packages/accounts/package.json @@ -75,6 +75,6 @@ "gitHead": "ee46e8bb857de3b631044fa70714ea706d9e317d", "dependencies": { "@alchemy/aa-core": "^3.0.0-alpha.0", - "viem": "^1.21.4" + "viem": "^2.5.0" } } diff --git a/packages/accounts/plugindefs/multi-owner/config.ts b/packages/accounts/plugindefs/multi-owner/config.ts index 34477bce65..e1d4597784 100644 --- a/packages/accounts/plugindefs/multi-owner/config.ts +++ b/packages/accounts/plugindefs/multi-owner/config.ts @@ -1,5 +1,5 @@ +import { sepolia } from "@alchemy/aa-core"; import { parseAbiParameters } from "viem"; -import { sepolia } from "viem/chains"; import type { PluginGenConfig } from "../types"; import { MultiOwnerPluginAbi } from "./abi.js"; diff --git a/packages/accounts/plugindefs/session-key/config.ts b/packages/accounts/plugindefs/session-key/config.ts index 6eacd62225..72d66b90ae 100644 --- a/packages/accounts/plugindefs/session-key/config.ts +++ b/packages/accounts/plugindefs/session-key/config.ts @@ -1,5 +1,5 @@ +import { sepolia } from "@alchemy/aa-core"; import { parseAbiParameters } from "viem"; -import { sepolia } from "viem/chains"; import { MultiOwnerPluginGenConfig } from "../multi-owner/config.js"; import type { PluginGenConfig } from "../types"; import { SessionKeyPluginAbi } from "./abi.js"; diff --git a/packages/accounts/plugindefs/token-receiver/config.ts b/packages/accounts/plugindefs/token-receiver/config.ts index 2cdb8c33b1..3936ada822 100644 --- a/packages/accounts/plugindefs/token-receiver/config.ts +++ b/packages/accounts/plugindefs/token-receiver/config.ts @@ -1,4 +1,4 @@ -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import type { PluginGenConfig } from "../types"; import { TokenReceiverPluginAbi } from "./abi.js"; diff --git a/packages/accounts/plugingen/index.ts b/packages/accounts/plugingen/index.ts index 840b1039df..641093db8a 100644 --- a/packages/accounts/plugingen/index.ts +++ b/packages/accounts/plugingen/index.ts @@ -118,7 +118,7 @@ export function plugingen({ const plugin = getContract({ address: address[chain.id], abi: IPluginAbi, - publicClient: client, + client, }); const result = await asyncPipe(...phases)({ diff --git a/packages/accounts/plugingen/phases/plugin-actions/index.ts b/packages/accounts/plugingen/phases/plugin-actions/index.ts index ce1ae3853b..3a8a242243 100644 --- a/packages/accounts/plugingen/phases/plugin-actions/index.ts +++ b/packages/accounts/plugingen/phases/plugin-actions/index.ts @@ -12,7 +12,7 @@ export const PluginActionsGenPhase: Phase = async (input) => { const executionAbiConst = `${contract.name}ExecutionFunctionAbi`; const executionAbi = extractExecutionAbi(executionFunctions, contract.abi); - addImport("viem", { name: "GetFunctionArgs", isType: true }); + addImport("viem", { name: "EncodeFunctionDataParameters", isType: true }); addImport("viem", { name: "Transport", isType: true }); addImport("viem", { name: "Chain", isType: true }); addImport("@alchemy/aa-core", { @@ -54,9 +54,9 @@ export const PluginActionsGenPhase: Phase = async (input) => { providerFunctionDefs.push(dedent` ${camelCase( n.name - )}: (args: GetFunctionArgs & { overrides?: UserOperationOverrides; } & GetAccountParameter) => Promise + }">, "args"> & { overrides?: UserOperationOverrides; } & GetAccountParameter) => Promise `); return dedent` ${camelCase(n.name)}(${argsParamString}) { diff --git a/packages/accounts/plugingen/phases/plugin-actions/read-actions.ts b/packages/accounts/plugingen/phases/plugin-actions/read-actions.ts index b2ba7b6675..fad3fae8f4 100644 --- a/packages/accounts/plugingen/phases/plugin-actions/read-actions.ts +++ b/packages/accounts/plugingen/phases/plugin-actions/read-actions.ts @@ -9,7 +9,7 @@ export const AccountReadActionsGenPhase: Phase = async (input) => { const executionAbiConst = `${contract.name}ExecutionFunctionAbi`; const executionAbi = extractExecutionAbi(executionFunctions, contract.abi); - addImport("viem", { name: "GetFunctionArgs", isType: true }); + addImport("viem", { name: "EncodeFunctionDataParameters", isType: true }); addImport("viem", { name: "encodeFunctionData" }); addImport("viem", { name: "Hex", isType: true }); @@ -24,9 +24,9 @@ export const AccountReadActionsGenPhase: Phase = async (input) => { accountFunctionActionDefs.push( dedent`encode${pascalCase( n.name - )}: (args: GetFunctionArgs) => Hex` + }">, "args">) => Hex` ); methodContent.push(dedent` encode${pascalCase(n.name)}(${argsParamString}) { @@ -49,9 +49,9 @@ export const AccountReadActionsGenPhase: Phase = async (input) => { n.inputs.length > 0 ? dedent`read${pascalCase( n.name - )}: (args: GetFunctionArgs & GetAccountParameter) => Promise, "args"> & GetAccountParameter) => Promise>` : dedent`read${pascalCase( diff --git a/packages/accounts/plugingen/phases/plugin-generator/client-actions.ts b/packages/accounts/plugingen/phases/plugin-generator/client-actions.ts deleted file mode 100644 index f1855a68b1..0000000000 --- a/packages/accounts/plugingen/phases/plugin-generator/client-actions.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { camelCase } from "change-case"; -import dedent from "dedent"; -import type { Phase } from "../../types"; -import { extractExecutionAbi } from "../../utils.js"; -import { ManagementActionsGenPhase } from "../plugin-actions/management-actions.js"; -import { AccountReadActionsGenPhase } from "../plugin-actions/read-actions.js"; - -export const ClientDecoratorGenPhase: Phase = async (input) => { - const { plugin, contract, addImport, addType } = input; - const { executionFunctions } = await plugin.read.pluginManifest(); - const executionAbiConst = `${contract.name}ExecutionFunctionAbi`; - const executionAbi = extractExecutionAbi(executionFunctions, contract.abi); - - addImport("viem", { name: "GetFunctionArgs", isType: true }); - addImport("viem", { name: "Transport", isType: true }); - addImport("viem", { name: "Chain", isType: true }); - addImport("@alchemy/aa-core", { - name: "SmartContractAccount", - isType: true, - }); - addImport("@alchemy/aa-core", { - name: "UserOperationOverrides", - isType: true, - }); - addImport("@alchemy/aa-core", { - name: "SmartAccountClient", - isType: true, - }); - addImport("@alchemy/aa-core", { - name: "GetAccountParameter", - isType: true, - }); - addImport("@alchemy/aa-core", { - name: "SendUserOperationResult", - isType: true, - }); - - const providerFunctionDefs: string[] = []; - const providerFunctions = executionAbi - .filter((n) => n.stateMutability !== "view") - .map((n) => { - const argsParamString = - n.inputs.length > 0 - ? dedent`{ - args, - overrides, - account = client.account - }: GetFunctionArgs & { overrides?: UserOperationOverrides; } & GetAccountParameter` - : ""; - const argsEncodeString = n.inputs.length > 0 ? "args," : ""; - - providerFunctionDefs.push(dedent` - ${camelCase( - n.name - )}: (args: GetFunctionArgs & { overrides?: UserOperationOverrides; } & GetAccountParameter) => Promise - `); - return dedent` - ${camelCase(n.name)}: (${argsParamString}) => { - if (!account) { - throw new AccountNotFoundError(); - } - - const data = encodeFunctionData({ - abi: ${executionAbiConst}, - functionName: "${n.name}", - ${argsEncodeString} - }); - - return client.sendUserOperation({ data, overrides, account }); - } - `; - }); - - addType( - "ExecutionActions", - dedent`{ - ${providerFunctionDefs.join(";\n\n")} - }` - ); - - // TODO: async pipe this - await ManagementActionsGenPhase({ - ...input, - content: providerFunctions, - }); - - await AccountReadActionsGenPhase({ - ...input, - content: providerFunctions, - }); - - input.content.push(dedent` - actions< - TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartContractAccount | undefined = - | SmartContractAccount - | undefined - >( - client: SmartAccountClient - ): ${contract.name}Actions { return { ${providerFunctions.join( - ",\n\n" - )} }; } - `); - - return input; -}; diff --git a/packages/accounts/plugingen/phases/plugin-generator/get-contract-gen.ts b/packages/accounts/plugingen/phases/plugin-generator/get-contract-gen.ts index 3e873a51ce..ff05fe41dc 100644 --- a/packages/accounts/plugingen/phases/plugin-generator/get-contract-gen.ts +++ b/packages/accounts/plugingen/phases/plugin-generator/get-contract-gen.ts @@ -19,13 +19,13 @@ export const GetContractGenPhase: Phase = async (input) => { getContract: ( client: C, address?: Address - ): GetContractReturnType => { + ): GetContractReturnType => { if (!client.chain) throw new Error("Missing chain on client"); return getContract({ address: address || addresses[client.chain.id], abi: ${contract.name}Abi, - publicClient: client, + client: client, }); }`); diff --git a/packages/accounts/plugingen/phases/plugin-generator/index.ts b/packages/accounts/plugingen/phases/plugin-generator/index.ts index dfcdd61454..2b47e22262 100644 --- a/packages/accounts/plugingen/phases/plugin-generator/index.ts +++ b/packages/accounts/plugingen/phases/plugin-generator/index.ts @@ -5,11 +5,7 @@ import { GetContractGenPhase } from "./get-contract-gen.js"; import { MetaGenPhase } from "./meta-gen.js"; export const PluginGeneratorPhase: Phase = async (input) => { - const pluginPhases: Phase[] = [ - MetaGenPhase, - GetContractGenPhase, - // ClientDecoratorGenPhase, - ]; + const pluginPhases: Phase[] = [MetaGenPhase, GetContractGenPhase]; const { contract, addImport } = input; const result = await asyncPipe(...pluginPhases)({ diff --git a/packages/accounts/src/light-account/account.test.ts b/packages/accounts/src/light-account/account.test.ts index bdd262f40a..d63b589026 100644 --- a/packages/accounts/src/light-account/account.test.ts +++ b/packages/accounts/src/light-account/account.test.ts @@ -1,11 +1,11 @@ import { LocalAccountSigner, createPublicErc4337FromClient, + polygonMumbai, type BatchUserOperationCallData, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { createPublicClient, custom } from "viem"; -import { polygonMumbai, type Chain } from "viem/chains"; +import { createPublicClient, custom, type Chain } from "viem"; import { createLightAccountClient } from "./createLightAccountClient.js"; const chain = polygonMumbai; diff --git a/packages/accounts/src/light-account/account.ts b/packages/accounts/src/light-account/account.ts index 00760668c8..f2a62789e3 100644 --- a/packages/accounts/src/light-account/account.ts +++ b/packages/accounts/src/light-account/account.ts @@ -16,6 +16,7 @@ import { hashMessage, hashTypedData, trim, + type SignTypedDataParameters, type Transport, } from "viem"; import { LightAccountAbi } from "./abis/LightAccountAbi.js"; @@ -203,8 +204,11 @@ export async function createLightAccount({ async signTypedData(params) { const version = await getLightAccountVersion(account); switch (version) { - case "v1.0.1": - return owner.signTypedData(params); + case "v1.0.1": { + return owner.signTypedData( + params as unknown as SignTypedDataParameters + ); + } case "v1.0.2": throw new Error( `Version ${version} of LightAccount doesn't support 1271` diff --git a/packages/accounts/src/light-account/e2e-tests/light-account.e2e.test.ts b/packages/accounts/src/light-account/e2e-tests/light-account.e2e.test.ts index bf5f785dcc..b3d0984e04 100644 --- a/packages/accounts/src/light-account/e2e-tests/light-account.e2e.test.ts +++ b/packages/accounts/src/light-account/e2e-tests/light-account.e2e.test.ts @@ -4,12 +4,12 @@ import { Logger, createPublicErc4337Client, createSmartAccountClientFromExisting, + sepolia, type SmartAccountSigner, type UserOperationFeeOptions, } from "@alchemy/aa-core"; import { isAddress, type Address, type Chain, type HDAccount } from "viem"; import { generatePrivateKey } from "viem/accounts"; -import { sepolia } from "viem/chains"; import { multiOwnerPluginActions, type LightAccountVersion, diff --git a/packages/accounts/src/light-account/utils.ts b/packages/accounts/src/light-account/utils.ts index 6b5f502546..a4673a613c 100644 --- a/packages/accounts/src/light-account/utils.ts +++ b/packages/accounts/src/light-account/utils.ts @@ -1,4 +1,3 @@ -import type { Address, Chain } from "viem"; import { arbitrum, arbitrumGoerli, @@ -14,7 +13,8 @@ import { polygon, polygonMumbai, sepolia, -} from "viem/chains"; +} from "@alchemy/aa-core"; +import type { Address, Chain } from "viem"; export type LightAccountVersion = /** @deprecated This version does not support 1271 signature validation */ diff --git a/packages/accounts/src/msca/plugins/multi-owner/plugin.ts b/packages/accounts/src/msca/plugins/multi-owner/plugin.ts index b12f30704c..a3f45884ff 100644 --- a/packages/accounts/src/msca/plugins/multi-owner/plugin.ts +++ b/packages/accounts/src/msca/plugins/multi-owner/plugin.ts @@ -7,7 +7,7 @@ import { type Transport, type PublicClient, type Client, - type GetFunctionArgs, + type EncodeFunctionDataParameters, type Chain, type Hex, type ReadContractReturnType, @@ -34,9 +34,12 @@ type ExecutionActions< | undefined > = { updateOwners: ( - args: GetFunctionArgs< - typeof MultiOwnerPluginExecutionFunctionAbi, - "updateOwners" + args: Pick< + EncodeFunctionDataParameters< + typeof MultiOwnerPluginExecutionFunctionAbi, + "updateOwners" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; }; @@ -68,16 +71,22 @@ type ReadAndEncodeActions< | undefined > = { encodeUpdateOwners: ( - args: GetFunctionArgs< - typeof MultiOwnerPluginExecutionFunctionAbi, - "updateOwners" + args: Pick< + EncodeFunctionDataParameters< + typeof MultiOwnerPluginExecutionFunctionAbi, + "updateOwners" + >, + "args" > ) => Hex; encodeEip712Domain: ( - args: GetFunctionArgs< - typeof MultiOwnerPluginExecutionFunctionAbi, - "eip712Domain" + args: Pick< + EncodeFunctionDataParameters< + typeof MultiOwnerPluginExecutionFunctionAbi, + "eip712Domain" + >, + "args" > ) => Hex; @@ -91,16 +100,22 @@ type ReadAndEncodeActions< >; encodeIsValidSignature: ( - args: GetFunctionArgs< - typeof MultiOwnerPluginExecutionFunctionAbi, - "isValidSignature" + args: Pick< + EncodeFunctionDataParameters< + typeof MultiOwnerPluginExecutionFunctionAbi, + "isValidSignature" + >, + "args" > ) => Hex; readIsValidSignature: ( - args: GetFunctionArgs< - typeof MultiOwnerPluginExecutionFunctionAbi, - "isValidSignature" + args: Pick< + EncodeFunctionDataParameters< + typeof MultiOwnerPluginExecutionFunctionAbi, + "isValidSignature" + >, + "args" > & GetAccountParameter ) => Promise< @@ -135,7 +150,6 @@ export const MultiOwnerPlugin: Plugin = { ): GetContractReturnType< typeof MultiOwnerPluginAbi, PublicClient, - undefined, Address > => { if (!client.chain) throw new Error("Missing chain on client"); @@ -143,7 +157,7 @@ export const MultiOwnerPlugin: Plugin = { return getContract({ address: address || addresses[client.chain.id], abi: MultiOwnerPluginAbi, - publicClient: client, + client: client, }); }, }; diff --git a/packages/accounts/src/msca/plugins/multi-owner/signer.ts b/packages/accounts/src/msca/plugins/multi-owner/signer.ts index 16b93ede25..63f1f123c9 100644 --- a/packages/accounts/src/msca/plugins/multi-owner/signer.ts +++ b/packages/accounts/src/msca/plugins/multi-owner/signer.ts @@ -71,12 +71,12 @@ export const multiOwnerMessageSigner = < }, signTypedData: < - const TTypedData extends TypedData | { [key: string]: unknown }, - TPrimaryType extends string = string + const typedData extends TypedData | Record, + primaryType extends keyof typedData | "EIP712Domain" = keyof typedData >( - typedData: TypedDataDefinition + typedDataDefinition: TypedDataDefinition ): Promise => { - return signWith712Wrapper(hashTypedData(typedData)); + return signWith712Wrapper(hashTypedData(typedDataDefinition)); }, }; }; diff --git a/packages/accounts/src/msca/plugins/session-key/extension.ts b/packages/accounts/src/msca/plugins/session-key/extension.ts index c4c28f0ca0..34fdb7b8bd 100644 --- a/packages/accounts/src/msca/plugins/session-key/extension.ts +++ b/packages/accounts/src/msca/plugins/session-key/extension.ts @@ -59,6 +59,7 @@ export const sessionKeyPluginActions: < client: SmartAccountClient ) => { const { removeSessionKey, ...og } = sessionKeyPluginActions_(client); + return { ...og, isAccountSessionKey: async ({ diff --git a/packages/accounts/src/msca/plugins/session-key/plugin.ts b/packages/accounts/src/msca/plugins/session-key/plugin.ts index 09473064a5..38f3020841 100644 --- a/packages/accounts/src/msca/plugins/session-key/plugin.ts +++ b/packages/accounts/src/msca/plugins/session-key/plugin.ts @@ -8,7 +8,7 @@ import { type Transport, type PublicClient, type Client, - type GetFunctionArgs, + type EncodeFunctionDataParameters, type Chain, type Hex, } from "viem"; @@ -35,37 +35,52 @@ type ExecutionActions< | undefined > = { executeWithSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "executeWithSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "executeWithSessionKey" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; addSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "addSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "addSessionKey" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; removeSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "removeSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "removeSessionKey" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; rotateSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "rotateSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "rotateSessionKey" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; updateKeyPermissions: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "updateKeyPermissions" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "updateKeyPermissions" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; }; @@ -97,37 +112,52 @@ type ManagementActions< type ReadAndEncodeActions = { encodeExecuteWithSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "executeWithSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "executeWithSessionKey" + >, + "args" > ) => Hex; encodeAddSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "addSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "addSessionKey" + >, + "args" > ) => Hex; encodeRemoveSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "removeSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "removeSessionKey" + >, + "args" > ) => Hex; encodeRotateSessionKey: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "rotateSessionKey" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "rotateSessionKey" + >, + "args" > ) => Hex; encodeUpdateKeyPermissions: ( - args: GetFunctionArgs< - typeof SessionKeyPluginExecutionFunctionAbi, - "updateKeyPermissions" + args: Pick< + EncodeFunctionDataParameters< + typeof SessionKeyPluginExecutionFunctionAbi, + "updateKeyPermissions" + >, + "args" > ) => Hex; }; @@ -156,7 +186,6 @@ export const SessionKeyPlugin: Plugin = { ): GetContractReturnType< typeof SessionKeyPluginAbi, PublicClient, - undefined, Address > => { if (!client.chain) throw new Error("Missing chain on client"); @@ -164,7 +193,7 @@ export const SessionKeyPlugin: Plugin = { return getContract({ address: address || addresses[client.chain.id], abi: SessionKeyPluginAbi, - publicClient: client, + client: client, }); }, }; diff --git a/packages/accounts/src/msca/plugins/token-receiver/plugin.ts b/packages/accounts/src/msca/plugins/token-receiver/plugin.ts index 75caa76012..49c25700a7 100644 --- a/packages/accounts/src/msca/plugins/token-receiver/plugin.ts +++ b/packages/accounts/src/msca/plugins/token-receiver/plugin.ts @@ -7,7 +7,7 @@ import { type Transport, type PublicClient, type Client, - type GetFunctionArgs, + type EncodeFunctionDataParameters, type Chain, type Hex, } from "viem"; @@ -33,30 +33,42 @@ type ExecutionActions< | undefined > = { tokensReceived: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "tokensReceived" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "tokensReceived" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; onErc721Received: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC721Received" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC721Received" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; onErc1155Received: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC1155Received" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC1155Received" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; onErc1155BatchReceived: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC1155BatchReceived" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC1155BatchReceived" + >, + "args" > & { overrides?: UserOperationOverrides } & GetAccountParameter ) => Promise; }; @@ -84,30 +96,42 @@ type ManagementActions< type ReadAndEncodeActions = { encodeTokensReceived: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "tokensReceived" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "tokensReceived" + >, + "args" > ) => Hex; encodeOnErc721Received: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC721Received" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC721Received" + >, + "args" > ) => Hex; encodeOnErc1155Received: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC1155Received" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC1155Received" + >, + "args" > ) => Hex; encodeOnErc1155BatchReceived: ( - args: GetFunctionArgs< - typeof TokenReceiverPluginExecutionFunctionAbi, - "onERC1155BatchReceived" + args: Pick< + EncodeFunctionDataParameters< + typeof TokenReceiverPluginExecutionFunctionAbi, + "onERC1155BatchReceived" + >, + "args" > ) => Hex; }; @@ -136,7 +160,6 @@ export const TokenReceiverPlugin: Plugin = { ): GetContractReturnType< typeof TokenReceiverPluginAbi, PublicClient, - undefined, Address > => { if (!client.chain) throw new Error("Missing chain on client"); @@ -144,7 +167,7 @@ export const TokenReceiverPlugin: Plugin = { return getContract({ address: address || addresses[client.chain.id], abi: TokenReceiverPluginAbi, - publicClient: client, + client: client, }); }, }; diff --git a/packages/accounts/src/msca/plugins/types.ts b/packages/accounts/src/msca/plugins/types.ts index d04fe68c55..0774e0da3a 100644 --- a/packages/accounts/src/msca/plugins/types.ts +++ b/packages/accounts/src/msca/plugins/types.ts @@ -15,5 +15,5 @@ export type Plugin = { getContract: ( client: C, address?: Address - ) => GetContractReturnType; + ) => GetContractReturnType; }; diff --git a/packages/accounts/src/msca/utils.ts b/packages/accounts/src/msca/utils.ts index ccd34a7767..6beafcc195 100644 --- a/packages/accounts/src/msca/utils.ts +++ b/packages/accounts/src/msca/utils.ts @@ -1,6 +1,20 @@ import { AccountNotFoundError, + arbitrum, + arbitrumGoerli, + arbitrumSepolia, + base, + baseGoerli, + baseSepolia, createPublicErc4337FromClient, + goerli, + mainnet, + optimism, + optimismGoerli, + optimismSepolia, + polygon, + polygonMumbai, + sepolia, type GetAccountParameter, type OwnedSmartContractAccount, type SmartAccountClient, @@ -17,22 +31,6 @@ import { keccak256, parseAbiParameters, } from "viem"; -import { - arbitrum, - arbitrumGoerli, - arbitrumSepolia, - base, - baseGoerli, - baseSepolia, - goerli, - mainnet, - optimism, - optimismGoerli, - optimismSepolia, - polygon, - polygonMumbai, - sepolia, -} from "viem/chains"; import { IPluginAbi } from "./abis/IPlugin.js"; import { MultiOwnerTokenReceiverMSCAFactoryAbi } from "./abis/MultiOwnerTokenReceiverMSCAFactory.js"; import { UpgradeableModularAccountAbi } from "./abis/UpgradeableModularAccount.js"; diff --git a/packages/accounts/src/nani-account/__tests__/account.test.ts b/packages/accounts/src/nani-account/__tests__/account.test.ts index 076c686263..fa631e1109 100644 --- a/packages/accounts/src/nani-account/__tests__/account.test.ts +++ b/packages/accounts/src/nani-account/__tests__/account.test.ts @@ -1,11 +1,11 @@ import { LocalAccountSigner, createPublicErc4337Client, + polygonMumbai, type Address, type Hex, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; import { createNaniAccount } from "../account.js"; import { getDefaultNaniAccountFactoryAddress } from "../utils.js"; diff --git a/packages/accounts/src/nani-account/utils.ts b/packages/accounts/src/nani-account/utils.ts index 23c8c0d52b..2104faf99b 100644 --- a/packages/accounts/src/nani-account/utils.ts +++ b/packages/accounts/src/nani-account/utils.ts @@ -1,4 +1,3 @@ -import type { Address, Chain } from "viem"; import { arbitrum, arbitrumGoerli, @@ -6,14 +5,15 @@ import { base, baseGoerli, baseSepolia, - sepolia, mainnet, optimism, optimismGoerli, optimismSepolia, polygon, polygonMumbai, -} from "viem/chains"; + sepolia, +} from "@alchemy/aa-core"; +import type { Address, Chain } from "viem"; /** * Utility method returning the default nani account factory address given a {@link Chain} object diff --git a/packages/alchemy/README.md b/packages/alchemy/README.md index 0213834c06..76df108936 100644 --- a/packages/alchemy/README.md +++ b/packages/alchemy/README.md @@ -29,7 +29,7 @@ import { } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const chain = sepolia; const PRIVATE_KEY = "0xYourEOAPrivateKey"; diff --git a/packages/alchemy/e2e-tests/light-account.e2e.test.ts b/packages/alchemy/e2e-tests/light-account.e2e.test.ts index 1c5bd54325..c41ea89030 100644 --- a/packages/alchemy/e2e-tests/light-account.e2e.test.ts +++ b/packages/alchemy/e2e-tests/light-account.e2e.test.ts @@ -1,6 +1,5 @@ -import { LocalAccountSigner } from "@alchemy/aa-core"; +import { LocalAccountSigner, sepolia } from "@alchemy/aa-core"; import { Alchemy, Network } from "alchemy-sdk"; -import { sepolia } from "viem/chains"; import * as simulateUoActions from "../src/actions/simulateUserOperationChanges.js"; import { alchemyEnhancedApiActions } from "../src/client/decorators/alchemyEnhancedApis.js"; import { diff --git a/packages/alchemy/package.json b/packages/alchemy/package.json index 241cab4118..b15c1d446c 100644 --- a/packages/alchemy/package.json +++ b/packages/alchemy/package.json @@ -58,7 +58,7 @@ }, "dependencies": { "@alchemy/aa-core": "^3.0.0-alpha.0", - "viem": "^1.21.4" + "viem": "^2.5.0" }, "publishConfig": { "access": "public", diff --git a/packages/alchemy/src/chains.ts b/packages/alchemy/src/chains.ts index a88dd6c736..859729d822 100644 --- a/packages/alchemy/src/chains.ts +++ b/packages/alchemy/src/chains.ts @@ -1,8 +1,10 @@ -import type { Chain } from "viem"; import { arbitrum, arbitrumGoerli, arbitrumSepolia, + base, + baseGoerli, + baseSepolia, goerli, mainnet, optimism, @@ -11,10 +13,8 @@ import { polygon, polygonMumbai, sepolia, - base, - baseGoerli, - baseSepolia, -} from "viem/chains"; +} from "@alchemy/aa-core"; +import type { Chain } from "viem"; export const SupportedChains = new Map([ [polygonMumbai.id, polygonMumbai], diff --git a/packages/alchemy/src/client/lightAccountClient.test.ts b/packages/alchemy/src/client/lightAccountClient.test.ts index 7ae0aa5f6a..027beaaef3 100644 --- a/packages/alchemy/src/client/lightAccountClient.test.ts +++ b/packages/alchemy/src/client/lightAccountClient.test.ts @@ -1,11 +1,12 @@ import * as AACoreModule from "@alchemy/aa-core"; import { LocalAccountSigner, + polygonMumbai, type BatchUserOperationCallData, type SmartAccountSigner, } from "@alchemy/aa-core"; import { Alchemy, Network } from "alchemy-sdk"; -import { avalanche, polygonMumbai, type Chain } from "viem/chains"; +import { avalanche, type Chain } from "viem/chains"; import { alchemyEnhancedApiActions } from "./decorators/alchemyEnhancedApis.js"; import { createLightAccountAlchemyClient } from "./lightAccountClient.js"; import { createAlchemySmartAccountClient } from "./smartAccountClient.js"; diff --git a/packages/alchemy/src/client/rpcClient.ts b/packages/alchemy/src/client/rpcClient.ts index ed4e892fcc..157ad9fd7a 100644 --- a/packages/alchemy/src/client/rpcClient.ts +++ b/packages/alchemy/src/client/rpcClient.ts @@ -5,6 +5,7 @@ import { } from "@alchemy/aa-core"; import type { Chain } from "viem"; import { SupportedChains } from "../chains.js"; +import { InvalidRpcUrlError } from "../errors/rpcUrl.js"; import type { ClientWithAlchemyMethods } from "./types.js"; export const createAlchemyPublicRpcClient = ({ @@ -25,6 +26,10 @@ export const createAlchemyPublicRpcClient = ({ ? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}` : connectionConfig.rpcUrl; + if (!rpcUrl) { + throw new InvalidRpcUrlError({ chain, connectionConfig }); + } + return createPublicErc4337Client({ chain: chain, rpcUrl, diff --git a/packages/alchemy/src/defaults.ts b/packages/alchemy/src/defaults.ts index a31e7ff3a6..e75c842181 100644 --- a/packages/alchemy/src/defaults.ts +++ b/packages/alchemy/src/defaults.ts @@ -1,5 +1,4 @@ import type { UserOperationFeeOptions } from "@alchemy/aa-core"; -import type { Chain } from "viem"; import { arbitrum, arbitrumGoerli, @@ -7,7 +6,8 @@ import { optimism, optimismGoerli, optimismSepolia, -} from "viem/chains"; +} from "@alchemy/aa-core"; +import type { Chain } from "viem"; export const getDefaultUserOperationFeeOptions = ( chain: Chain diff --git a/packages/alchemy/src/errors/rpcUrl.ts b/packages/alchemy/src/errors/rpcUrl.ts new file mode 100644 index 0000000000..374b98c6f0 --- /dev/null +++ b/packages/alchemy/src/errors/rpcUrl.ts @@ -0,0 +1,21 @@ +import type { ConnectionConfig } from "@alchemy/aa-core"; +import { BaseError, type Chain } from "viem"; +import { version } from "../../package.json"; + +export class InvalidRpcUrlError extends BaseError { + override name = "InvalidRpcUrlError"; + override version = version; + + constructor(context: { chain: Chain; connectionConfig: ConnectionConfig }) { + super(["RPC Url not provided"].join("\n"), { + details: [ + "If you are passing in a chain object and only an API key, make sure to use the chain object exported from @alchemy/aa-core", + "Otherwise, pass in an RPC URL directly", + ].join("\n"), + metaMessages: [ + `Chain: ${JSON.stringify(context.chain, null, 2)}`, + `ConnectionConfig: ${JSON.stringify(context.connectionConfig)}`, + ], + }); + } +} diff --git a/packages/core/README.md b/packages/core/README.md index 4bc836d752..1ed4fb9b62 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -36,7 +36,7 @@ import { SmartAccountProvider, SmartAccountSigner, } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; const chain = polygonMumbai; const owner: SmartAccountSigner = diff --git a/packages/core/e2e-tests/simple-account.e2e.test.ts b/packages/core/e2e-tests/simple-account.e2e.test.ts index bc997c0055..cc92da7300 100644 --- a/packages/core/e2e-tests/simple-account.e2e.test.ts +++ b/packages/core/e2e-tests/simple-account.e2e.test.ts @@ -1,6 +1,6 @@ +import { polygonMumbai } from "@alchemy/aa-core"; import { fromHex, isAddress, type Address, type Chain, type Hex } from "viem"; import { generatePrivateKey } from "viem/accounts"; -import { polygonMumbai } from "viem/chains"; import { createPublicErc4337Client, createSimpleSmartAccount, diff --git a/packages/core/package.json b/packages/core/package.json index 8c76fd2e27..bb878cd4c1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -59,7 +59,7 @@ "dependencies": { "abitype": "^0.8.3", "eventemitter3": "^5.0.1", - "viem": "^1.21.4", + "viem": "^2.5.0", "zod": "^3.22.4" }, "repository": { diff --git a/packages/core/src/__tests__/utils.test.ts b/packages/core/src/__tests__/utils.test.ts index 3c665967d5..457e778bc5 100644 --- a/packages/core/src/__tests__/utils.test.ts +++ b/packages/core/src/__tests__/utils.test.ts @@ -1,4 +1,4 @@ -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import type { UserOperationRequest } from "../types"; import { getDefaultEntryPointAddress, diff --git a/packages/core/src/account/__tests__/simple.test.ts b/packages/core/src/account/__tests__/simple.test.ts index 09ef66dbff..64485c32f5 100644 --- a/packages/core/src/account/__tests__/simple.test.ts +++ b/packages/core/src/account/__tests__/simple.test.ts @@ -1,5 +1,5 @@ +import { polygonMumbai, sepolia, type Chain } from "@alchemy/aa-core"; import { createPublicClient, custom, http, type Address } from "viem"; -import { polygonMumbai, sepolia, type Chain } from "viem/chains"; import { describe, it } from "vitest"; import { createPublicErc4337FromClient } from "../../client/publicErc4337Client.js"; import { createSmartAccountClient } from "../../client/smartAccountClient.js"; diff --git a/packages/core/src/account/base.ts b/packages/core/src/account/base.ts index fa0236a095..d5a69fe27a 100644 --- a/packages/core/src/account/base.ts +++ b/packages/core/src/account/base.ts @@ -2,7 +2,6 @@ import type { Address } from "abitype"; import { getContract, trim, - type Chain, type GetContractReturnType, type Hash, type Hex, @@ -48,8 +47,7 @@ export abstract class BaseSmartContractAccount< protected owner: TOwner; protected entryPoint: GetContractReturnType< typeof EntryPointAbi, - PublicClient, - Chain + PublicClient >; protected entryPointAddress: Address; readonly rpcProvider: @@ -108,9 +106,7 @@ export abstract class BaseSmartContractAccount< this.entryPoint = getContract({ address: this.entryPointAddress, abi: EntryPointAbi, - // Need to cast this as PublicClient or else it breaks ABI typing. - // This is valid because our PublicClient is a subclass of PublicClient - publicClient: this.rpcProvider as PublicClient, + client: this.rpcProvider as PublicClient, }); } diff --git a/packages/core/src/account/smartContractAccount.ts b/packages/core/src/account/smartContractAccount.ts index 1c4cc37604..6faf97c07f 100644 --- a/packages/core/src/account/smartContractAccount.ts +++ b/packages/core/src/account/smartContractAccount.ts @@ -57,10 +57,10 @@ export type SmartContractAccount = signUserOperationHash: (uoHash: Hex) => Promise; signMessageWith6492: (params: { message: SignableMessage }) => Promise; signTypedDataWith6492: < - const TTypedData extends TypedData | { [key: string]: unknown }, - TPrimaryType extends string = string + const typedData extends TypedData | Record, + primaryType extends keyof typedData | "EIP712Domain" = keyof typedData >( - typedData: TypedDataDefinition + typedDataDefinition: TypedDataDefinition ) => Promise; encodeUpgradeToAndCall: (params: UpgradeToAndCallParams) => Promise; getNonce(): Promise; @@ -115,7 +115,7 @@ export const getAccountAddress = async ({ abi: EntryPointAbi, // Need to cast this as PublicClient or else it breaks ABI typing. // This is valid because our PublicClient is a subclass of PublicClient - publicClient: client as PublicClient, + client: client as PublicClient, }); const initCode = await getAccountInitCode(); @@ -169,7 +169,7 @@ export async function toSmartContractAccount< abi: EntryPointAbi, // Need to cast this as PublicClient or else it breaks ABI typing. // This is valid because our PublicClient is a subclass of PublicClient - publicClient: client as PublicClient, + client: client as PublicClient, }); const accountAddress_ = await getAccountAddress({ @@ -265,14 +265,14 @@ export async function toSmartContractAccount< }; const signTypedDataWith6492 = async < - const TTypedData extends TypedData | { [key: string]: unknown }, - TPrimaryType extends string = string + const typedData extends TypedData | Record, + primaryType extends keyof typedData | "EIP712Domain" = keyof typedData >( - typedData: TypedDataDefinition + typedDataDefinition: TypedDataDefinition ): Promise => { const [isDeployed, signature] = await Promise.all([ isAccountDeployed(), - account.signTypedData(typedData), + account.signTypedData(typedDataDefinition), ]); return create6492Signature(isDeployed, signature); diff --git a/packages/core/src/actions/smartAccount/waitForUserOperationTransacation.ts b/packages/core/src/actions/smartAccount/waitForUserOperationTransacation.ts index 76a0c23665..a7f53981cb 100644 --- a/packages/core/src/actions/smartAccount/waitForUserOperationTransacation.ts +++ b/packages/core/src/actions/smartAccount/waitForUserOperationTransacation.ts @@ -1,18 +1,14 @@ import type { Chain, Hex, Transport } from "viem"; -import { getTransaction } from "viem/public"; -import type { SmartContractAccount } from "../../account/smartContractAccount.js"; +import { getTransaction } from "viem/actions"; import type { BaseSmartAccountClient } from "../../client/smartAccountClient.js"; import { Logger } from "../../logger.js"; import type { WaitForUserOperationTxParameters } from "./types.js"; export const waitForUserOperationTransaction: < TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartContractAccount | undefined = - | SmartContractAccount - | undefined + TChain extends Chain | undefined = Chain | undefined >( - client: BaseSmartAccountClient, + client: BaseSmartAccountClient, args: WaitForUserOperationTxParameters ) => Promise = async (client, args) => { const { hash } = args; diff --git a/packages/core/src/chain/index.ts b/packages/core/src/chain/index.ts new file mode 100644 index 0000000000..cc1ea7b354 --- /dev/null +++ b/packages/core/src/chain/index.ts @@ -0,0 +1,148 @@ +import 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, + sepolia as vsep, +} 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 polygon: Chain = { + ...vpg, + rpcUrls: { + ...vpg.rpcUrls, + alchemy: { + http: ["https://polygon-mainnet.g.alchemy.com/v2"], + }, + }, +}; diff --git a/packages/core/src/client/smartAccountClient.test.ts b/packages/core/src/client/smartAccountClient.test.ts index e8d1213448..127dd231a0 100644 --- a/packages/core/src/client/smartAccountClient.test.ts +++ b/packages/core/src/client/smartAccountClient.test.ts @@ -1,5 +1,5 @@ +import { polygonMumbai } from "@alchemy/aa-core"; import { custom, type Transaction } from "viem"; -import { polygonMumbai } from "viem/chains"; import type { SpyInstance } from "vitest"; import * as receiptActions from "../actions/publicErc4337/getUserOperationReceipt.js"; import type { UserOperationReceipt } from "../types.js"; diff --git a/packages/core/src/ens/utils.ts b/packages/core/src/ens/utils.ts index 6cdb113b90..737a073187 100644 --- a/packages/core/src/ens/utils.ts +++ b/packages/core/src/ens/utils.ts @@ -1,5 +1,6 @@ +import type { Chain } from "viem/chains"; import * as chains from "viem/chains"; -import { mainnet, type Chain } from "viem/chains"; +import { mainnet } from "../chain/index.js"; export const ChainsById: Map = new Map( Object.values(chains).map((x) => [x.id, x]) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 27da46ca2a..11495901f5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -109,3 +109,20 @@ export { noopMiddleware } from "./middleware/noopMiddleware.js"; export type * from "./middleware/types.js"; export { AccountNotFoundError } from "./errors/account.js"; + +export { + arbitrum, + arbitrumGoerli, + arbitrumSepolia, + base, + baseGoerli, + baseSepolia, + goerli, + mainnet, + optimism, + optimismGoerli, + optimismSepolia, + polygon, + polygonMumbai, + sepolia, +} from "./chain/index.js"; diff --git a/packages/core/src/signer/__tests__/wallet-client.test.ts b/packages/core/src/signer/__tests__/wallet-client.test.ts index fc83dd738c..33c40805a4 100644 --- a/packages/core/src/signer/__tests__/wallet-client.test.ts +++ b/packages/core/src/signer/__tests__/wallet-client.test.ts @@ -1,7 +1,7 @@ +import { polygonMumbai } from "@alchemy/aa-core"; import { createWalletClient, http } from "viem"; import { mnemonicToAccount } from "viem/accounts"; import { WalletClientSigner } from "../wallet-client.js"; -import { polygonMumbai } from "viem/chains"; describe("Wallet Client Signer Tests", () => { it("should successfully sign", async () => { diff --git a/packages/core/src/utils/defaults.ts b/packages/core/src/utils/defaults.ts index 349697a829..2c1fa81642 100644 --- a/packages/core/src/utils/defaults.ts +++ b/packages/core/src/utils/defaults.ts @@ -14,7 +14,7 @@ import { polygon, polygonMumbai, sepolia, -} from "viem/chains"; +} from "../chain/index.js"; import type { UserOperationFeeOptions } from "../types"; /** diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 4fa7dfde2c..127984ee64 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -1,6 +1,7 @@ import type { Address, Chain, Hash, Hex } from "viem"; import { encodeAbiParameters, hexToBigInt, keccak256, toHex } from "viem"; import * as chains from "viem/chains"; +import * as alchemyChains from "../chain/index.js"; import type { BigNumberish, Percentage, @@ -9,6 +10,10 @@ import type { } from "../types.js"; import { BigNumberishSchema, PercentageSchema } from "./schema.js"; +const AlchemyChainMap = new Map( + Object.values(alchemyChains).map((c) => [c.id, c]) +); + /** * Utility method for converting a chainId to a {@link Chain} object * @@ -19,7 +24,7 @@ import { BigNumberishSchema, PercentageSchema } from "./schema.js"; export const getChain = (chainId: number): Chain => { for (const chain of Object.values(chains)) { if (chain.id === chainId) { - return chain; + return AlchemyChainMap.get(chain.id) ?? chain; } } throw new Error("could not find chain"); diff --git a/packages/ethers/README.md b/packages/ethers/README.md index 999439cfb2..382365608a 100644 --- a/packages/ethers/README.md +++ b/packages/ethers/README.md @@ -34,7 +34,7 @@ import { import { EthersProviderAdapter } from "@alchemy/aa-ethers"; import { LocalAccountSigner, SmartAccountSigner } from "@alchemy/aa-core"; import { Alchemy, Network } from "alchemy-sdk"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; const chain = polygonMumbai; diff --git a/packages/ethers/package.json b/packages/ethers/package.json index 2bead87236..e2c2e13515 100644 --- a/packages/ethers/package.json +++ b/packages/ethers/package.json @@ -58,7 +58,7 @@ "@ethersproject/keccak256": "^5.7.0", "@ethersproject/providers": "^5.7.2", "@ethersproject/wallet": "^5.7.0", - "viem": "^1.21.4" + "viem": "^2.5.0" }, "repository": { "type": "git", diff --git a/packages/signers/package.json b/packages/signers/package.json index ba758afa1f..7de00bed61 100644 --- a/packages/signers/package.json +++ b/packages/signers/package.json @@ -115,7 +115,7 @@ "gitHead": "ee46e8bb857de3b631044fa70714ea706d9e317d", "dependencies": { "@alchemy/aa-core": "^3.0.0-alpha.0", - "viem": "^1.21.4" + "viem": "^2.5.0" }, "optionalDependencies": { "@arcana/auth": "^1.0.8", diff --git a/packages/signers/src/capsule/__tests__/signer.test.ts b/packages/signers/src/capsule/__tests__/signer.test.ts index c4839d146e..84be261999 100644 --- a/packages/signers/src/capsule/__tests__/signer.test.ts +++ b/packages/signers/src/capsule/__tests__/signer.test.ts @@ -1,3 +1,4 @@ +import { sepolia } from "@alchemy/aa-core"; import Capsule, { Environment, createCapsuleViemClient, @@ -8,7 +9,6 @@ import { type EIP1474Methods, type WalletClient, } from "viem"; -import { sepolia } from "viem/chains"; import { CapsuleSigner } from "../signer.js"; describe("Capsule Signer Tests", () => { diff --git a/packages/signers/src/lit-protocol/signer.ts b/packages/signers/src/lit-protocol/signer.ts index e3592385a8..f8bf0ced14 100644 --- a/packages/signers/src/lit-protocol/signer.ts +++ b/packages/signers/src/lit-protocol/signer.ts @@ -109,7 +109,7 @@ export class LitSigner return this.signer?._signTypedData( params.domain as TypedDataDomain, params.types as any, - params.message + params.message as Record ) as Promise; }; diff --git a/packages/signers/src/portal/__tests__/signer.test.ts b/packages/signers/src/portal/__tests__/signer.test.ts index 597eda0439..cb17c45a6a 100644 --- a/packages/signers/src/portal/__tests__/signer.test.ts +++ b/packages/signers/src/portal/__tests__/signer.test.ts @@ -1,5 +1,5 @@ +import { sepolia } from "@alchemy/aa-core"; import Portal from "@portal-hq/web"; -import { sepolia } from "viem/chains"; import { PortalSigner } from "../signer.js"; // taken from Portal SDK since not exported diff --git a/packages/signers/src/turnkey/signer.ts b/packages/signers/src/turnkey/signer.ts index 5e8341f912..ffb5ec0538 100644 --- a/packages/signers/src/turnkey/signer.ts +++ b/packages/signers/src/turnkey/signer.ts @@ -6,6 +6,7 @@ import { TurnkeyClient } from "@turnkey/http"; import { createAccount } from "@turnkey/viem"; import { createWalletClient, + type LocalAccount, type TypedData, type TypedDataDefinition, } from "viem"; @@ -74,11 +75,11 @@ export class TurnkeySigner this.subOrganization = await params.resolveSubOrganization(); this.signer = new WalletClientSigner( createWalletClient({ - account: await createAccount({ + account: (await createAccount({ client: this.inner, organizationId: this.subOrganization.subOrganizationId, signWith: this.subOrganization.signWith, - }), + })) as LocalAccount, transport: params.transport, }), this.signerType diff --git a/site/migration-guide.md b/site/migration-guide.md index 7b47ed686b..1345cf8585 100644 --- a/site/migration-guide.md +++ b/site/migration-guide.md @@ -28,6 +28,10 @@ This version update brings a lot of breaking changes. As we began to support Mod 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. To address this, version 3.x.x of the SDK switches to an approach more idiomatic to `viem`. +### Viem Version + +We have updated our dependency to viem v2.x.x. This means you will need to update your project to use >= v2.5.0 of viem. + ### Client: `SmartAccountProvider` → `SmartAccountClient` The biggest change is that the `SmartAccountProvider` class has been removed and replaced with a `SmartAccountClient` type that extends @@ -37,7 +41,7 @@ The biggest change is that the `SmartAccountProvider` class has been removed and import { SmartAccountProvider } from "@alchemy/aa-core"; // [!code --] import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; // [!code --] import { http } from "viem"; // [!code ++] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const provider = new SmartAccountProvider({ // [!code --] const client = createSmartAccountClient({ // [!code ++] @@ -57,7 +61,7 @@ The concept of the middlewares is still present in this version, but their confi import { SmartAccountProvider } from "@alchemy/aa-core"; // [!code --] import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; // [!code --] import { http } from "viem"; // [!code ++] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const provider = new SmartAccountProvider({ // [!code --] const client = createSmartAccountClient({ // [!code ++] @@ -94,7 +98,7 @@ import { LocalAccountSigner, type Hex, } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const chain = sepolia; @@ -129,7 +133,7 @@ import { LocalAccountSigner, type Hex, } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const chain = sepolia; @@ -172,7 +176,7 @@ import { LocalAccountSigner, type Hex, } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/packages/aa-accounts/light-account/constructor.md b/site/packages/aa-accounts/light-account/constructor.md index cb67fcad4e..2006f167a5 100644 --- a/site/packages/aa-accounts/light-account/constructor.md +++ b/site/packages/aa-accounts/light-account/constructor.md @@ -33,7 +33,7 @@ import { getDefaultEntryPointAddress, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const PRIVATE_KEY = "0xYourEOAPrivateKey"; const eoaSigner: SmartAccountSigner = diff --git a/site/packages/aa-accounts/utils/getDefaultLightAccountFactoryAddress.md b/site/packages/aa-accounts/utils/getDefaultLightAccountFactoryAddress.md index 84151eb764..166949983f 100644 --- a/site/packages/aa-accounts/utils/getDefaultLightAccountFactoryAddress.md +++ b/site/packages/aa-accounts/utils/getDefaultLightAccountFactoryAddress.md @@ -21,7 +21,7 @@ Utility method that returns the default Light Account Factory contract address f ::: code-group ```ts [example.ts] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { getDefaultLightAccountFactoryAddress } from "@alchemy/aa-accounts"; const chain = sepolia; diff --git a/site/packages/aa-alchemy/provider/constructor.md b/site/packages/aa-alchemy/provider/constructor.md index 59fa452e0d..f9ed698b53 100644 --- a/site/packages/aa-alchemy/provider/constructor.md +++ b/site/packages/aa-alchemy/provider/constructor.md @@ -23,7 +23,7 @@ To initialize an `AlchemyProvider`, you must provide a set of parameters detaile ```ts [example.ts] import { AlchemyProvider } from "@alchemy/aa-alchemy"; import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; // instantiates using every possible parameter, as a reference export const provider = new AlchemyProvider({ diff --git a/site/packages/aa-core/accounts/constructor.md b/site/packages/aa-core/accounts/constructor.md index ba8f2f5bdb..2283408176 100644 --- a/site/packages/aa-core/accounts/constructor.md +++ b/site/packages/aa-core/accounts/constructor.md @@ -32,7 +32,7 @@ import { getDefaultSimpleAccountFactoryAddress, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; const PRIVATE_KEY = "0xYourEOAPrivateKey"; const eoaSigner: SmartAccountSigner = diff --git a/site/packages/aa-core/client/createPublicErc4337Client.md b/site/packages/aa-core/client/createPublicErc4337Client.md index 26498cb416..7c53bca93d 100644 --- a/site/packages/aa-core/client/createPublicErc4337Client.md +++ b/site/packages/aa-core/client/createPublicErc4337Client.md @@ -22,7 +22,7 @@ Allows you to create an HTTP-based PublicErc4337Client with a given RPC provider ```ts [example.ts] import { createPublicErc4337Client } from "@alchemy/aa-core"; -import { mainnet } from "viem/chains"; +import { mainnet } from "@alchemy/aa-core"; const client = createPublicErc4337Client({ chain: mainnet, diff --git a/site/packages/aa-core/client/createPublicErc4337FromClient.md b/site/packages/aa-core/client/createPublicErc4337FromClient.md index 6c7a294720..4a6424c4ac 100644 --- a/site/packages/aa-core/client/createPublicErc4337FromClient.md +++ b/site/packages/aa-core/client/createPublicErc4337FromClient.md @@ -22,7 +22,7 @@ Allows you to create an HTTP-based PublicErc4337Client from an already created P ```ts [example.ts] import { createPublicErc4337FromClient } from "@alchemy/aa-core"; -import { mainnet } from "viem/chains"; +import { mainnet } from "@alchemy/aa-core"; import { createPublicClient, http } from "viem"; const publicClient = createPublicClient({ diff --git a/site/packages/aa-core/provider/constructor.md b/site/packages/aa-core/provider/constructor.md index 5f0078c650..75c237a772 100644 --- a/site/packages/aa-core/provider/constructor.md +++ b/site/packages/aa-core/provider/constructor.md @@ -23,7 +23,7 @@ To initialize a `SmartAccountProvider`, you must provide a set of parameters det ```ts [example.ts] import { SmartAccountProvider } from "@alchemy/aa-core"; import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; // instantiates using every possible parameter, as a reference export const provider = new SmartAccountProvider({ diff --git a/site/packages/aa-core/provider/types/userOperationFeeOptions.md b/site/packages/aa-core/provider/types/userOperationFeeOptions.md index eff39350f9..c585702917 100644 --- a/site/packages/aa-core/provider/types/userOperationFeeOptions.md +++ b/site/packages/aa-core/provider/types/userOperationFeeOptions.md @@ -33,7 +33,7 @@ type UserOperationFeeOptions { ::: code-group ```ts [example.ts] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { type Chain } from "viem"; import { diff --git a/site/packages/aa-core/signers/utils/verifyEIP6492Signature.md b/site/packages/aa-core/signers/utils/verifyEIP6492Signature.md index 1a64ca563a..cad45dc8b3 100644 --- a/site/packages/aa-core/signers/utils/verifyEIP6492Signature.md +++ b/site/packages/aa-core/signers/utils/verifyEIP6492Signature.md @@ -25,7 +25,7 @@ Uses a the universal validator defined [here](https://github.com/AmbireTech/sign ```ts [example.ts] import { verifyEIP6492Signature } from "@alchemy/aa-core"; import { http } from "viem"; -import { mainnet } from "viem/chains"; +import { mainnet } from "@alchemy/aa-core"; const signature = await verifyEIP6492Signature({ signer: "0xAccountAddress", diff --git a/site/packages/aa-core/utils/getDefaultEntryPointAddress.md b/site/packages/aa-core/utils/getDefaultEntryPointAddress.md index 9ae026f582..07588cdb9f 100644 --- a/site/packages/aa-core/utils/getDefaultEntryPointAddress.md +++ b/site/packages/aa-core/utils/getDefaultEntryPointAddress.md @@ -21,7 +21,7 @@ Utility method that returns the default EntryPoint contract address for a given ::: code-group ```ts [example.ts] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/packages/aa-core/utils/getDefaultSimpleAccountFactoryAddress.md b/site/packages/aa-core/utils/getDefaultSimpleAccountFactoryAddress.md index b960cd6e9d..821bf19639 100644 --- a/site/packages/aa-core/utils/getDefaultSimpleAccountFactoryAddress.md +++ b/site/packages/aa-core/utils/getDefaultSimpleAccountFactoryAddress.md @@ -21,7 +21,7 @@ Utility method that returns the default Simple Account Factory contract address ::: code-group ```ts [example.ts] -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { getDefaultSimpleAccountFactoryAddress } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/packages/aa-ethers/provider-adapter/constructor.md b/site/packages/aa-ethers/provider-adapter/constructor.md index bf2c05c0eb..72e5786edb 100644 --- a/site/packages/aa-ethers/provider-adapter/constructor.md +++ b/site/packages/aa-ethers/provider-adapter/constructor.md @@ -26,7 +26,7 @@ Or you can also input a `SmartAccountProvider` instance already initialized (`Al import { AlchemyProvider } from "@alchemy/aa-alchemy"; import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; import { EthersProviderAdapter } from "@alchemy/aa-ethers"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; // one way to initialize export const provider = new EthersProviderAdapter({ diff --git a/site/packages/aa-ethers/provider-adapter/introduction.md b/site/packages/aa-ethers/provider-adapter/introduction.md index e6167bbb6e..ccd29cbfd3 100644 --- a/site/packages/aa-ethers/provider-adapter/introduction.md +++ b/site/packages/aa-ethers/provider-adapter/introduction.md @@ -34,7 +34,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; // [!code focus:99] // EIP-1193 compliant requests const chainId = await provider.send("eth_chainId", []); diff --git a/site/smart-accounts/signers/guides/arcana-auth.md b/site/smart-accounts/signers/guides/arcana-auth.md index ab9033c40a..010f916973 100644 --- a/site/smart-accounts/signers/guides/arcana-auth.md +++ b/site/smart-accounts/signers/guides/arcana-auth.md @@ -62,7 +62,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createArcanaAuthSigner } from "./arcana-auth"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/capsule.md b/site/smart-accounts/signers/guides/capsule.md index 335c14bc85..0b34b3ae39 100644 --- a/site/smart-accounts/signers/guides/capsule.md +++ b/site/smart-accounts/signers/guides/capsule.md @@ -82,7 +82,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createCapsuleSigner } from "./capsule"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/dfns.md b/site/smart-accounts/signers/guides/dfns.md index e00cce1e7c..3d89d27155 100644 --- a/site/smart-accounts/signers/guides/dfns.md +++ b/site/smart-accounts/signers/guides/dfns.md @@ -51,7 +51,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { encodeFunctionData, parseAbi } from "viem"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createDfnsSigner } from "./dfns"; // Remember to replace "ALCHEMY_API_KEY" with your own Alchemy API key, get one here: https://dashboard.alchemy.com/ diff --git a/site/smart-accounts/signers/guides/dynamic.md b/site/smart-accounts/signers/guides/dynamic.md index e2ef440886..7d2eca3950 100644 --- a/site/smart-accounts/signers/guides/dynamic.md +++ b/site/smart-accounts/signers/guides/dynamic.md @@ -87,7 +87,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { dynamicSigner } from "./dynamic"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/eoa.md b/site/smart-accounts/signers/guides/eoa.md index fb3cfd4cc5..2bd6486b6b 100644 --- a/site/smart-accounts/signers/guides/eoa.md +++ b/site/smart-accounts/signers/guides/eoa.md @@ -32,7 +32,7 @@ A JSON RPC based account is one where the key material is not available locally, ```ts import { createWalletClient, custom } from "viem"; -import { mainnet } from "viem/chains"; +import { mainnet } from "@alchemy/aa-core"; import { WalletClientSigner } from "@alchemy/core"; const client = createWalletClient({ @@ -55,7 +55,7 @@ In this example we assume you have access to the private key locally. import { createWalletClient, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; // import { mnemonicToAccount } from "viem/accounts"; -import { mainnet } from "viem/chains"; +import { mainnet } from "@alchemy/aa-core"; import { WalletClientSigner } from "@alchemy/core"; // if you have a mnemonic, viem also exports a mnemonicToAccount function (see above import) diff --git a/site/smart-accounts/signers/guides/fireblocks.md b/site/smart-accounts/signers/guides/fireblocks.md index 73d72d568a..64afc63020 100644 --- a/site/smart-accounts/signers/guides/fireblocks.md +++ b/site/smart-accounts/signers/guides/fireblocks.md @@ -63,7 +63,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createFireblocksSigner } from "./fireblocks"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/magic.md b/site/smart-accounts/signers/guides/magic.md index 8e966d13aa..9c0dca7ee0 100644 --- a/site/smart-accounts/signers/guides/magic.md +++ b/site/smart-accounts/signers/guides/magic.md @@ -61,7 +61,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createMagicSigner } from "./magic"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/particle-network.md b/site/smart-accounts/signers/guides/particle-network.md index 83c8eec63a..24012c6a12 100644 --- a/site/smart-accounts/signers/guides/particle-network.md +++ b/site/smart-accounts/signers/guides/particle-network.md @@ -63,7 +63,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { getDefaultEntryPointAddress } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; import { createParticleSigner } from "./particle"; const chain = polygonMumbai; diff --git a/site/smart-accounts/signers/guides/portal.md b/site/smart-accounts/signers/guides/portal.md index 2a21a8b93b..5bcf6d8e73 100644 --- a/site/smart-accounts/signers/guides/portal.md +++ b/site/smart-accounts/signers/guides/portal.md @@ -61,7 +61,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; import { createPortalSigner } from "./portal"; const chain = polygonMumbai; diff --git a/site/smart-accounts/signers/guides/turnkey.md b/site/smart-accounts/signers/guides/turnkey.md index 977ffe4950..721ccfb5d7 100644 --- a/site/smart-accounts/signers/guides/turnkey.md +++ b/site/smart-accounts/signers/guides/turnkey.md @@ -67,7 +67,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createTurnkeySigner } from "./turnkey"; const chain = sepolia; diff --git a/site/smart-accounts/signers/guides/web3auth.md b/site/smart-accounts/signers/guides/web3auth.md index f930ddd5fc..74ad36a864 100644 --- a/site/smart-accounts/signers/guides/web3auth.md +++ b/site/smart-accounts/signers/guides/web3auth.md @@ -61,7 +61,7 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; import { createWeb3AuthSigner } from "./web3auth"; const chain = sepolia; diff --git a/site/snippets/account-alchemy.ts b/site/snippets/account-alchemy.ts index 936b7a5603..eac7c3b8a6 100644 --- a/site/snippets/account-alchemy.ts +++ b/site/snippets/account-alchemy.ts @@ -6,9 +6,9 @@ import { SimpleSmartContractAccount, getDefaultEntryPointAddress, getDefaultSimpleAccountFactoryAddress, + polygonMumbai, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; const chain = polygonMumbai; diff --git a/site/snippets/account-core.ts b/site/snippets/account-core.ts index 943751f2d7..deb604c833 100644 --- a/site/snippets/account-core.ts +++ b/site/snippets/account-core.ts @@ -5,9 +5,9 @@ import { SimpleSmartContractAccount, SmartAccountProvider, getDefaultSimpleAccountFactoryAddress, + polygonMumbai, type SmartAccountSigner, } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; // 1. define the EOA owner of the smart account // this uses a utility method for creating an account signer using mnemonic diff --git a/site/snippets/capsule.ts b/site/snippets/capsule.ts index 89b92d7996..20dcd65d47 100644 --- a/site/snippets/capsule.ts +++ b/site/snippets/capsule.ts @@ -1,7 +1,7 @@ +import { sepolia } from "@alchemy/aa-core"; import { CapsuleSigner } from "@alchemy/aa-signers/capsule"; import { Environment } from "@usecapsule/web-sdk"; import { http } from "viem"; -import { sepolia } from "viem/chains"; export const createCapsuleSigner = async () => { // get an API Key by filling out this form: https://form.typeform.com/to/hLaJeYJW diff --git a/site/snippets/client.ts b/site/snippets/client.ts index 86858eb150..8e1907b968 100644 --- a/site/snippets/client.ts +++ b/site/snippets/client.ts @@ -1,5 +1,4 @@ -import { createPublicErc4337Client } from "@alchemy/aa-core"; -import { mainnet } from "viem/chains"; +import { createPublicErc4337Client, mainnet } from "@alchemy/aa-core"; export const client = createPublicErc4337Client({ chain: mainnet, diff --git a/site/snippets/core-provider.ts b/site/snippets/core-provider.ts index 3cc4faea51..ad7fd878ab 100644 --- a/site/snippets/core-provider.ts +++ b/site/snippets/core-provider.ts @@ -6,8 +6,8 @@ import { LocalAccountSigner, SmartAccountProvider, SmartAccountSigner, + polygonMumbai, } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; const chain = polygonMumbai; const owner: SmartAccountSigner = diff --git a/site/snippets/enhanced-apis-example/nft.ts b/site/snippets/enhanced-apis-example/nft.ts index b6fcf68df4..171c05ff28 100644 --- a/site/snippets/enhanced-apis-example/nft.ts +++ b/site/snippets/enhanced-apis-example/nft.ts @@ -1,6 +1,6 @@ import { AlchemyProvider } from "@alchemy/aa-alchemy"; +import { sepolia } from "@alchemy/aa-core"; import { Alchemy, Network } from "alchemy-sdk"; -import { sepolia } from "viem/chains"; const alchemy = new Alchemy({ network: Network.ETH_SEPOLIA, diff --git a/site/snippets/enhanced-apis-example/token.ts b/site/snippets/enhanced-apis-example/token.ts index 068639453d..bff9b3bb1c 100644 --- a/site/snippets/enhanced-apis-example/token.ts +++ b/site/snippets/enhanced-apis-example/token.ts @@ -1,6 +1,6 @@ import { AlchemyProvider } from "@alchemy/aa-alchemy"; +import { sepolia } from "@alchemy/aa-core"; import { Alchemy, Network } from "alchemy-sdk"; -import { sepolia } from "viem/chains"; const alchemy = new Alchemy({ network: Network.ETH_SEPOLIA, diff --git a/site/snippets/ethers-signer.ts b/site/snippets/ethers-signer.ts index 06d770e192..bcd07733af 100644 --- a/site/snippets/ethers-signer.ts +++ b/site/snippets/ethers-signer.ts @@ -2,8 +2,11 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { LocalAccountSigner, SmartAccountSigner } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; +import { + LocalAccountSigner, + SmartAccountSigner, + polygonMumbai, +} from "@alchemy/aa-core"; import { provider } from "./ethers-provider.js"; const owner: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner( diff --git a/site/snippets/getting-started/provider.ts b/site/snippets/getting-started/provider.ts index 3531754eab..b17e54a55e 100644 --- a/site/snippets/getting-started/provider.ts +++ b/site/snippets/getting-started/provider.ts @@ -3,8 +3,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner, type Hex } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia, type Hex } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/snippets/getting-started/send-user-operation.ts b/site/snippets/getting-started/send-user-operation.ts index 838dec49fa..46a894f67f 100644 --- a/site/snippets/getting-started/send-user-operation.ts +++ b/site/snippets/getting-started/send-user-operation.ts @@ -3,8 +3,12 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { Address, LocalAccountSigner, type Hex } from "@alchemy/aa-core"; -import { polygonMumbai } from "viem/chains"; +import { + Address, + LocalAccountSigner, + polygonMumbai, + type Hex, +} from "@alchemy/aa-core"; const chain = polygonMumbai; diff --git a/site/snippets/light-account-alchemy-provider.ts b/site/snippets/light-account-alchemy-provider.ts index f0dc2aa429..2c2690ccec 100644 --- a/site/snippets/light-account-alchemy-provider.ts +++ b/site/snippets/light-account-alchemy-provider.ts @@ -1,6 +1,5 @@ import { createLightAccountAlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia } from "@alchemy/aa-core"; export const provider = createLightAccountAlchemyProvider({ apiKey: "YOUR_API_KEY", diff --git a/site/snippets/light-account-provider.ts b/site/snippets/light-account-provider.ts index 9d3b3b9c32..5502427377 100644 --- a/site/snippets/light-account-provider.ts +++ b/site/snippets/light-account-provider.ts @@ -1,6 +1,5 @@ import { createLightAccountProvider } from "@alchemy/aa-accounts"; -import { LocalAccountSigner } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia } from "@alchemy/aa-core"; export const provider = createLightAccountProvider({ rpcProvider: `${sepolia.rpcUrls.alchemy.http[0]}/${"YOUR_API_KEY"}`, diff --git a/site/snippets/light-account.ts b/site/snippets/light-account.ts index d69986fa07..f84e288074 100644 --- a/site/snippets/light-account.ts +++ b/site/snippets/light-account.ts @@ -3,8 +3,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner, type Hex } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia, type Hex } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/snippets/lit.ts b/site/snippets/lit.ts index cd1c8d062a..2e5a8737d4 100644 --- a/site/snippets/lit.ts +++ b/site/snippets/lit.ts @@ -1,5 +1,5 @@ -import { LitSigner, LitAuthMethod } from "@alchemy/aa-signers/lit-protocol"; -import { polygonMumbai } from "viem/chains"; +import { polygonMumbai } from "@alchemy/aa-core"; +import { LitAuthMethod, LitSigner } from "@alchemy/aa-signers/lit-protocol"; const API_KEY = ""; const POLYGON_MUMBAI_RPC_URL = `${polygonMumbai.rpcUrls.alchemy.http[0]}/${API_KEY}`; diff --git a/site/snippets/nani-account.ts b/site/snippets/nani-account.ts index b5a814f31b..a8ca07ba5d 100644 --- a/site/snippets/nani-account.ts +++ b/site/snippets/nani-account.ts @@ -1,10 +1,6 @@ -import { - NaniAccount, - getDefaultNaniAccountFactoryAddress, -} from "@alchemy/aa-accounts"; +import { getDefaultNaniAccountFactoryAddress } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner, type Hex } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia, type Hex } from "@alchemy/aa-core"; const chain = sepolia; diff --git a/site/snippets/portal.ts b/site/snippets/portal.ts index d4c6bc3ae3..f600bbb624 100644 --- a/site/snippets/portal.ts +++ b/site/snippets/portal.ts @@ -1,5 +1,5 @@ +import { sepolia } from "@alchemy/aa-core"; import { PortalSigner } from "@alchemy/aa-signers/portal"; -import { sepolia } from "viem/chains"; export const createPortalSigner = async () => { const portalSigner = new PortalSigner({ diff --git a/site/snippets/privy.ts b/site/snippets/privy.ts index ebce55a6e7..5f1c04a3b5 100644 --- a/site/snippets/privy.ts +++ b/site/snippets/privy.ts @@ -7,10 +7,13 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { WalletClientSigner, type SmartAccountSigner } from "@alchemy/aa-core"; +import { + WalletClientSigner, + sepolia, + type SmartAccountSigner, +} from "@alchemy/aa-core"; import { useWallets } from "@privy-io/react-auth"; import { createWalletClient, custom } from "viem"; -import { sepolia } from "viem/chains"; // The code below makes use of Privy's React hooks. You must paste // or use it within a React Component or Context. diff --git a/site/snippets/provider.ts b/site/snippets/provider.ts index 0259382116..3209146d3d 100644 --- a/site/snippets/provider.ts +++ b/site/snippets/provider.ts @@ -3,8 +3,7 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner, type Hex } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { LocalAccountSigner, sepolia, type Hex } from "@alchemy/aa-core"; const chain = sepolia; const PRIVATE_KEY = "0xYourEOAPrivateKey" as Hex; diff --git a/site/snippets/send-uo-example/connect-account.ts b/site/snippets/send-uo-example/connect-account.ts index c4050dc2e2..6486ff4c9e 100644 --- a/site/snippets/send-uo-example/connect-account.ts +++ b/site/snippets/send-uo-example/connect-account.ts @@ -2,8 +2,11 @@ import { LightSmartContractAccount, getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; -import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core"; -import { sepolia } from "viem/chains"; +import { + LocalAccountSigner, + sepolia, + type SmartAccountSigner, +} from "@alchemy/aa-core"; import { provider } from "./create-provider.js"; const chain = sepolia; diff --git a/site/snippets/send-uo-example/create-provider.ts b/site/snippets/send-uo-example/create-provider.ts index 8f7abb3ba2..9c36fac54c 100644 --- a/site/snippets/send-uo-example/create-provider.ts +++ b/site/snippets/send-uo-example/create-provider.ts @@ -1,5 +1,5 @@ import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { sepolia } from "viem/chains"; +import { sepolia } from "@alchemy/aa-core"; export const provider = new AlchemyProvider({ apiKey: "ALCHEMY_API_KEY", // replace with your Alchemy API Key diff --git a/site/snippets/send-uo-example/full-example.ts b/site/snippets/send-uo-example/full-example.ts index ef9b00e27f..cbdddadcb8 100644 --- a/site/snippets/send-uo-example/full-example.ts +++ b/site/snippets/send-uo-example/full-example.ts @@ -3,9 +3,12 @@ import { getDefaultLightAccountFactoryAddress, } from "@alchemy/aa-accounts"; import { AlchemyProvider } from "@alchemy/aa-alchemy"; -import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core"; +import { + LocalAccountSigner, + sepolia, + type SmartAccountSigner, +} from "@alchemy/aa-core"; import { encodeFunctionData } from "viem"; -import { sepolia } from "viem/chains"; const provider = new AlchemyProvider({ apiKey: "ALCHEMY_API_KEY", // replace with your Alchemy API Key diff --git a/site/snippets/wallet-client-signer.ts b/site/snippets/wallet-client-signer.ts index 5956e8b386..6e57ba64a5 100644 --- a/site/snippets/wallet-client-signer.ts +++ b/site/snippets/wallet-client-signer.ts @@ -1,6 +1,9 @@ -import { WalletClientSigner, type SmartAccountSigner } from "@alchemy/aa-core"; +import { + WalletClientSigner, + sepolia, + type SmartAccountSigner, +} from "@alchemy/aa-core"; import { createWalletClient, custom } from "viem"; -import { sepolia } from "viem/chains"; const externalProvider = window.ethereum; // or anyother EIP-1193 provider diff --git a/yarn.lock b/yarn.lock index 352c0af452..287536737b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7881,6 +7881,11 @@ abitype@0.9.8: resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.9.8.tgz#1f120b6b717459deafd213dfbf3a3dd1bf10ae8c" integrity sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ== +abitype@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/abitype/-/abitype-1.0.0.tgz#237176dace81d90d018bebf3a45cb42f2a2d9e97" + integrity sha512-NMeMah//6bJ56H5XRj8QCV4AwuW6hB6zqz2LnhhLdcWVQOsXki6/Pn3APeqxCma62nXIcmZWdu1DlHWS74umVQ== + abitype@^0.8.3: version "0.8.11" resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.8.11.tgz#66e1cf2cbf46f48d0e57132d7c1c392447536cc1" @@ -18291,6 +18296,20 @@ viem@^1.21.4: isows "1.0.3" ws "8.13.0" +viem@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/viem/-/viem-2.5.0.tgz#1d7bd5333a6b9387d42c1c2d368d0b88c2961ee1" + integrity sha512-ytHXIWtlgPs4mcsGxXjJrQ25v+N4dE2hBzgCU8CVv4iXNh3PRFRgyYa7igZlmxiMVzkfSHHADOtivS980JhilA== + dependencies: + "@adraffy/ens-normalize" "1.10.0" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.2" + "@scure/bip32" "1.3.2" + "@scure/bip39" "1.2.1" + abitype "1.0.0" + isows "1.0.3" + ws "8.13.0" + vite-node@0.31.4: version "0.31.4" resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-0.31.4.tgz#0437f76c35fa83f0a868d3fb5896ca9e164291f5"