From af9b152de5d17924fe6429c10c4024be9107456f Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 17:13:46 +0100 Subject: [PATCH 1/6] Fix public actions type --- .../accounts/biconomy/privateKeyToBiconomySmartAccount.ts | 2 +- .../accounts/biconomy/signerToBiconomySmartAccount.ts | 2 +- .../accounts/kernel/signerToEcdsaKernelSmartAccount.ts | 2 +- .../accounts/light/privateKeyToLightSmartAccount.ts | 2 +- .../accounts/light/signerToLightSmartAccount.ts | 2 +- .../accounts/safe/privateKeyToSafeSmartAccount.ts | 2 +- .../accounts/safe/signerToSafeSmartAccount.ts | 2 +- .../accounts/simple/privateKeyToSimpleSmartAccount.ts | 2 +- .../accounts/simple/signerToSimpleSmartAccount.ts | 2 +- packages/permissionless/accounts/toSmartAccount.ts | 8 +++++++- .../accounts/trust/privateKeyToTrustSmartAccount.ts | 2 +- .../accounts/trust/signerToTrustSmartAccount.ts | 2 +- packages/permissionless/accounts/types.ts | 8 +++++++- 13 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/permissionless/accounts/biconomy/privateKeyToBiconomySmartAccount.ts b/packages/permissionless/accounts/biconomy/privateKeyToBiconomySmartAccount.ts index 82c1160f..39f36efb 100644 --- a/packages/permissionless/accounts/biconomy/privateKeyToBiconomySmartAccount.ts +++ b/packages/permissionless/accounts/biconomy/privateKeyToBiconomySmartAccount.ts @@ -37,7 +37,7 @@ export async function privateKeyToBiconomySmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { privateKey, diff --git a/packages/permissionless/accounts/biconomy/signerToBiconomySmartAccount.ts b/packages/permissionless/accounts/biconomy/signerToBiconomySmartAccount.ts index 6866ec36..edc52b4e 100644 --- a/packages/permissionless/accounts/biconomy/signerToBiconomySmartAccount.ts +++ b/packages/permissionless/accounts/biconomy/signerToBiconomySmartAccount.ts @@ -220,7 +220,7 @@ export async function signerToBiconomySmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { signer, diff --git a/packages/permissionless/accounts/kernel/signerToEcdsaKernelSmartAccount.ts b/packages/permissionless/accounts/kernel/signerToEcdsaKernelSmartAccount.ts index ad93ed1c..3eb63024 100644 --- a/packages/permissionless/accounts/kernel/signerToEcdsaKernelSmartAccount.ts +++ b/packages/permissionless/accounts/kernel/signerToEcdsaKernelSmartAccount.ts @@ -381,7 +381,7 @@ export async function signerToEcdsaKernelSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { signer, diff --git a/packages/permissionless/accounts/light/privateKeyToLightSmartAccount.ts b/packages/permissionless/accounts/light/privateKeyToLightSmartAccount.ts index bd2ab349..7d7d7651 100644 --- a/packages/permissionless/accounts/light/privateKeyToLightSmartAccount.ts +++ b/packages/permissionless/accounts/light/privateKeyToLightSmartAccount.ts @@ -38,7 +38,7 @@ export async function privateKeyToLightSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { privateKey, ...rest }: PrivateKeyToLightSmartAccountParameters ): Promise> { diff --git a/packages/permissionless/accounts/light/signerToLightSmartAccount.ts b/packages/permissionless/accounts/light/signerToLightSmartAccount.ts index b73b770b..8f043ad5 100644 --- a/packages/permissionless/accounts/light/signerToLightSmartAccount.ts +++ b/packages/permissionless/accounts/light/signerToLightSmartAccount.ts @@ -199,7 +199,7 @@ export async function signerToLightSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { signer, diff --git a/packages/permissionless/accounts/safe/privateKeyToSafeSmartAccount.ts b/packages/permissionless/accounts/safe/privateKeyToSafeSmartAccount.ts index 80eeecb8..8404f27e 100644 --- a/packages/permissionless/accounts/safe/privateKeyToSafeSmartAccount.ts +++ b/packages/permissionless/accounts/safe/privateKeyToSafeSmartAccount.ts @@ -37,7 +37,7 @@ export async function privateKeyToSafeSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { privateKey, ...rest }: PrivateKeyToSafeSmartAccountParameters ): Promise> { diff --git a/packages/permissionless/accounts/safe/signerToSafeSmartAccount.ts b/packages/permissionless/accounts/safe/signerToSafeSmartAccount.ts index a4c63f61..00311de5 100644 --- a/packages/permissionless/accounts/safe/signerToSafeSmartAccount.ts +++ b/packages/permissionless/accounts/safe/signerToSafeSmartAccount.ts @@ -1096,7 +1096,7 @@ export async function signerToSafeSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, args: SignerToSafeSmartAccountParameters< entryPoint, diff --git a/packages/permissionless/accounts/simple/privateKeyToSimpleSmartAccount.ts b/packages/permissionless/accounts/simple/privateKeyToSimpleSmartAccount.ts index 3d4868b9..927d47bc 100644 --- a/packages/permissionless/accounts/simple/privateKeyToSimpleSmartAccount.ts +++ b/packages/permissionless/accounts/simple/privateKeyToSimpleSmartAccount.ts @@ -38,7 +38,7 @@ export async function privateKeyToSimpleSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { privateKey, diff --git a/packages/permissionless/accounts/simple/signerToSimpleSmartAccount.ts b/packages/permissionless/accounts/simple/signerToSimpleSmartAccount.ts index 6e571faa..7c987bf9 100644 --- a/packages/permissionless/accounts/simple/signerToSimpleSmartAccount.ts +++ b/packages/permissionless/accounts/simple/signerToSimpleSmartAccount.ts @@ -150,7 +150,7 @@ export async function signerToSimpleSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { signer, diff --git a/packages/permissionless/accounts/toSmartAccount.ts b/packages/permissionless/accounts/toSmartAccount.ts index ecf71957..c4637dd5 100644 --- a/packages/permissionless/accounts/toSmartAccount.ts +++ b/packages/permissionless/accounts/toSmartAccount.ts @@ -50,7 +50,13 @@ export function toSmartAccount< signTypedData }: TAccountSource & { source: TSource - client: Client + client: Client< + transport, + chain, + undefined, + PublicRpcSchema, + PublicActions + > entryPoint: TEntryPoint getNonce: (key?: bigint) => Promise getInitCode: () => Promise diff --git a/packages/permissionless/accounts/trust/privateKeyToTrustSmartAccount.ts b/packages/permissionless/accounts/trust/privateKeyToTrustSmartAccount.ts index 9640c313..1613b028 100644 --- a/packages/permissionless/accounts/trust/privateKeyToTrustSmartAccount.ts +++ b/packages/permissionless/accounts/trust/privateKeyToTrustSmartAccount.ts @@ -37,7 +37,7 @@ export async function privateKeyToTrustSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { privateKey, ...rest }: PrivateKeyToTrustSmartAccountParameters ): Promise> { diff --git a/packages/permissionless/accounts/trust/signerToTrustSmartAccount.ts b/packages/permissionless/accounts/trust/signerToTrustSmartAccount.ts index 9e1e112f..6cc97f84 100644 --- a/packages/permissionless/accounts/trust/signerToTrustSmartAccount.ts +++ b/packages/permissionless/accounts/trust/signerToTrustSmartAccount.ts @@ -108,7 +108,7 @@ export async function signerToTrustSmartAccount< TChain, undefined, PublicRpcSchema, - PublicActions + PublicActions >, { signer, diff --git a/packages/permissionless/accounts/types.ts b/packages/permissionless/accounts/types.ts index 263f8ab6..8be7d632 100644 --- a/packages/permissionless/accounts/types.ts +++ b/packages/permissionless/accounts/types.ts @@ -39,7 +39,13 @@ export type SmartAccount< chain extends Chain | undefined = Chain | undefined, TAbi extends Abi | readonly unknown[] = Abi > = LocalAccount & { - client: Client + client: Client< + transport, + chain, + undefined, + PublicRpcSchema, + PublicActions + > entryPoint: entryPoint getNonce: (key?: bigint) => Promise getInitCode: () => Promise From 96a53a0363c9c1eb2537133b4f4acc9ea7532c96 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 17:56:38 +0100 Subject: [PATCH 2/6] Be more strict about smart account type with it's transport --- packages/permissionless/actions/erc7579.ts | 86 ++++++++++++++----- .../actions/erc7579/accountId.ts | 10 ++- .../actions/erc7579/installModule.ts | 20 +++-- .../actions/erc7579/installModules.ts | 21 +++-- .../actions/erc7579/isModuleInstalled.ts | 25 ++++-- .../actions/erc7579/supportsExecutionMode.ts | 28 ++++-- .../actions/erc7579/supportsModule.ts | 22 +++-- .../actions/erc7579/uninstallModule.ts | 29 +++++-- .../actions/erc7579/uninstallModules.ts | 29 +++++-- .../actions/smartAccount/deployContract.ts | 7 +- .../prepareUserOperationRequest.ts | 55 +++++++++--- .../actions/smartAccount/sendTransaction.ts | 13 ++- .../actions/smartAccount/sendTransactions.ts | 23 +++-- .../actions/smartAccount/sendUserOperation.ts | 20 +++-- .../actions/smartAccount/signMessage.ts | 9 +- .../actions/smartAccount/signTypedData.ts | 9 +- .../actions/smartAccount/writeContract.ts | 22 ++++- .../clients/createSmartAccountClient.ts | 25 ++++-- .../clients/decorators/smartAccount.ts | 81 ++++++++++++----- packages/permissionless/types/index.ts | 6 +- 20 files changed, 403 insertions(+), 137 deletions(-) diff --git a/packages/permissionless/actions/erc7579.ts b/packages/permissionless/actions/erc7579.ts index e4e4ca0b..f131ede2 100644 --- a/packages/permissionless/actions/erc7579.ts +++ b/packages/permissionless/actions/erc7579.ts @@ -36,33 +36,77 @@ import { export type Erc7579Actions< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined + TTransport extends Transport, + TChain extends Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined > = { accountId: ( args?: TSmartAccount extends undefined - ? GetAccountParameter + ? GetAccountParameter< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > : undefined ) => Promise installModule: ( - args: InstallModuleParameters + args: InstallModuleParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise installModules: ( - args: InstallModulesParameters + args: InstallModulesParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise isModuleInstalled: ( - args: IsModuleInstalledParameters + args: IsModuleInstalledParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise supportsExecutionMode: ( - args: SupportsExecutionModeParameters + args: SupportsExecutionModeParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise supportsModule: ( - args: SupportsModuleParameters + args: SupportsModuleParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise uninstallModule: ( - args: UninstallModuleParameters + args: UninstallModuleParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise uninstallModules: ( - args: UninstallModulesParameters + args: UninstallModulesParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ) => Promise } @@ -92,47 +136,49 @@ export function erc7579Actions(_args: { entryPoint: TEntryPoint }) { return < - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport, - TChain extends Chain | undefined + TChain extends Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined >( client: Client - ): Erc7579Actions => ({ + ): Erc7579Actions => ({ accountId: (args) => accountId(client, args), installModule: (args) => - installModule( + installModule( client, args ), installModules: (args) => - installModules( + installModules( client, args ), isModuleInstalled: (args) => - isModuleInstalled( + isModuleInstalled( client, args ), supportsExecutionMode: (args) => supportsExecutionMode< TEntryPoint, - TSmartAccount, TTransport, - TChain + TChain, + TSmartAccount >(client, args), supportsModule: (args) => - supportsModule( + supportsModule( client, args ), uninstallModule: (args) => - uninstallModule( + uninstallModule( client, args ), uninstallModules: (args) => - uninstallModules( + uninstallModules( client, args ) diff --git a/packages/permissionless/actions/erc7579/accountId.ts b/packages/permissionless/actions/erc7579/accountId.ts index 0a1210c9..7c2ba4a3 100644 --- a/packages/permissionless/actions/erc7579/accountId.ts +++ b/packages/permissionless/actions/erc7579/accountId.ts @@ -14,13 +14,15 @@ import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashW export async function accountId< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, - TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TTransport extends Transport, + TChain extends Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined >( client: Client, args?: TSmartAccount extends undefined - ? GetAccountParameter + ? GetAccountParameter : undefined ): Promise { let account_ = client.account diff --git a/packages/permissionless/actions/erc7579/installModule.ts b/packages/permissionless/actions/erc7579/installModule.ts index 40a268d0..5cb590ed 100644 --- a/packages/permissionless/actions/erc7579/installModule.ts +++ b/packages/permissionless/actions/erc7579/installModule.ts @@ -19,8 +19,12 @@ import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type InstallModuleParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined -> = GetAccountParameter & { + TTransport extends Transport, + TChain extends Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined +> = GetAccountParameter & { type: ModuleType address: Address context: Hex @@ -31,12 +35,18 @@ export type InstallModuleParameters< export async function installModule< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - parameters: Prettify> + parameters: Prettify< + InstallModuleParameters + > ): Promise { const { account: account_ = client.account, diff --git a/packages/permissionless/actions/erc7579/installModules.ts b/packages/permissionless/actions/erc7579/installModules.ts index 09ac6a8f..a451bf1f 100644 --- a/packages/permissionless/actions/erc7579/installModules.ts +++ b/packages/permissionless/actions/erc7579/installModules.ts @@ -19,8 +19,12 @@ import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type InstallModulesParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined -> = GetAccountParameter & + TTransport extends Transport, + TChain extends Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined +> = GetAccountParameter & Middleware & { modules: { type: ModuleType @@ -34,12 +38,19 @@ export type InstallModulesParameters< export async function installModules< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined + | undefined >( client: Client, - parameters: Prettify> + parameters: Prettify< + InstallModulesParameters + > ): Promise { const { account: account_ = client.account, diff --git a/packages/permissionless/actions/erc7579/isModuleInstalled.ts b/packages/permissionless/actions/erc7579/isModuleInstalled.ts index a002be39..9f632d1b 100644 --- a/packages/permissionless/actions/erc7579/isModuleInstalled.ts +++ b/packages/permissionless/actions/erc7579/isModuleInstalled.ts @@ -18,10 +18,14 @@ import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type IsModuleInstalledParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined -> = GetAccountParameter & { +> = GetAccountParameter & { type: ModuleType address: Address context: Hex @@ -29,12 +33,21 @@ export type IsModuleInstalledParameters< export async function isModuleInstalled< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - parameters: IsModuleInstalledParameters + parameters: IsModuleInstalledParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > ): Promise { const { account: account_ = client.account, address, context } = parameters diff --git a/packages/permissionless/actions/erc7579/supportsExecutionMode.ts b/packages/permissionless/actions/erc7579/supportsExecutionMode.ts index 120ca1bf..dc58a30f 100644 --- a/packages/permissionless/actions/erc7579/supportsExecutionMode.ts +++ b/packages/permissionless/actions/erc7579/supportsExecutionMode.ts @@ -27,11 +27,16 @@ export type ExecutionMode = { export type SupportsExecutionModeParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined, callType extends CallType = CallType -> = GetAccountParameter & ExecutionMode +> = GetAccountParameter & + ExecutionMode function parseCallType(callType: CallType) { switch (callType) { @@ -64,12 +69,23 @@ export function encodeExecutionMode({ export async function supportsExecutionMode< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - args: Prettify> + args: Prettify< + SupportsExecutionModeParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > + > ): Promise { const { account: account_ = client.account, diff --git a/packages/permissionless/actions/erc7579/supportsModule.ts b/packages/permissionless/actions/erc7579/supportsModule.ts index 489789c4..9e62f012 100644 --- a/packages/permissionless/actions/erc7579/supportsModule.ts +++ b/packages/permissionless/actions/erc7579/supportsModule.ts @@ -16,10 +16,14 @@ export type ModuleType = "validator" | "executor" | "fallback" | "hook" export type SupportsModuleParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined -> = GetAccountParameter & { +> = GetAccountParameter & { type: ModuleType } @@ -40,12 +44,18 @@ export function parseModuleTypeId(type: ModuleType): bigint { export async function supportsModule< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - args: Prettify> + args: Prettify< + SupportsModuleParameters + > ): Promise { const { account: account_ = client.account } = args diff --git a/packages/permissionless/actions/erc7579/uninstallModule.ts b/packages/permissionless/actions/erc7579/uninstallModule.ts index 491c8ce0..586f215c 100644 --- a/packages/permissionless/actions/erc7579/uninstallModule.ts +++ b/packages/permissionless/actions/erc7579/uninstallModule.ts @@ -19,10 +19,14 @@ import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type UninstallModuleParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined -> = GetAccountParameter & { +> = GetAccountParameter & { type: ModuleType address: Address context: Hex @@ -33,14 +37,23 @@ export type UninstallModuleParameters< export async function uninstallModule< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount - | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - parameters: Prettify> + parameters: Prettify< + UninstallModuleParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > + > ): Promise { const { account: account_ = client.account, diff --git a/packages/permissionless/actions/erc7579/uninstallModules.ts b/packages/permissionless/actions/erc7579/uninstallModules.ts index fc1452d0..599a32ae 100644 --- a/packages/permissionless/actions/erc7579/uninstallModules.ts +++ b/packages/permissionless/actions/erc7579/uninstallModules.ts @@ -19,10 +19,14 @@ import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type UninstallModulesParameters< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined -> = GetAccountParameter & { +> = GetAccountParameter & { modules: [ { type: ModuleType @@ -37,14 +41,23 @@ export type UninstallModulesParameters< export async function uninstallModules< TEntryPoint extends EntryPoint, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount - | undefined, TTransport extends Transport = Transport, - TChain extends Chain | undefined = Chain | undefined + TChain extends Chain | undefined = Chain | undefined, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, - parameters: Prettify> + parameters: Prettify< + UninstallModulesParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + > + > ): Promise { const { account: account_ = client.account, diff --git a/packages/permissionless/actions/smartAccount/deployContract.ts b/packages/permissionless/actions/smartAccount/deployContract.ts index 74a340e1..8acca74b 100644 --- a/packages/permissionless/actions/smartAccount/deployContract.ts +++ b/packages/permissionless/actions/smartAccount/deployContract.ts @@ -58,9 +58,12 @@ export type DeployContractParametersWithPaymaster< */ export async function deployContract< entryPoint extends EntryPoint, + TTransport extends Transport, TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client, diff --git a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts index 16e9b20b..b6e4214f 100644 --- a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts +++ b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts @@ -72,8 +72,12 @@ export type Middleware = { export type PrepareUserOperationRequestParameters< entryPoint extends EntryPoint, - TAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined > = { userOperation: entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE @@ -107,7 +111,7 @@ export type PrepareUserOperationRequestParameters< | "paymasterData" | "signature" > -} & GetAccountParameter & +} & GetAccountParameter & Middleware export type PrepareUserOperationRequestReturnType< @@ -118,12 +122,21 @@ async function prepareUserOperationRequestForEntryPointV06< entryPoint extends EntryPoint = ENTRYPOINT_ADDRESS_V06_TYPE, TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client, - args: Prettify>, + args: Prettify< + PrepareUserOperationRequestParameters< + entryPoint, + TTransport, + TChain, + TAccount + > + >, stateOverrides?: StateOverrides ): Promise>> { const { @@ -255,12 +268,21 @@ async function prepareUserOperationRequestEntryPointV07< entryPoint extends EntryPoint = ENTRYPOINT_ADDRESS_V07_TYPE, TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client, - args: Prettify>, + args: Prettify< + PrepareUserOperationRequestParameters< + entryPoint, + TTransport, + TChain, + TAccount + > + >, stateOverrides?: StateOverrides ): Promise>> { const { @@ -399,12 +421,21 @@ export async function prepareUserOperationRequest< entryPoint extends EntryPoint, TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client, - args: Prettify>, + args: Prettify< + PrepareUserOperationRequestParameters< + entryPoint, + TTransport, + TChain, + TAccount + > + >, stateOverrides?: StateOverrides ): Promise>> { const { account: account_ = client.account } = args diff --git a/packages/permissionless/actions/smartAccount/sendTransaction.ts b/packages/permissionless/actions/smartAccount/sendTransaction.ts index 7792857d..b120c47b 100644 --- a/packages/permissionless/actions/smartAccount/sendTransaction.ts +++ b/packages/permissionless/actions/smartAccount/sendTransaction.ts @@ -16,9 +16,12 @@ import { sendUserOperation } from "./sendUserOperation" export type SendTransactionWithPaymasterParameters< entryPoint extends EntryPoint, + TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined, TChainOverride extends Chain | undefined = Chain | undefined > = SendTransactionParameters & @@ -71,8 +74,11 @@ export type SendTransactionWithPaymasterParameters< * }) */ export async function sendTransaction< + TTransport extends Transport, TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined, + TAccount extends + | SmartAccount + | undefined, entryPoint extends EntryPoint, TChainOverride extends Chain | undefined = Chain | undefined >( @@ -80,6 +86,7 @@ export async function sendTransaction< args: Prettify< SendTransactionWithPaymasterParameters< entryPoint, + TTransport, TChain, TAccount, TChainOverride diff --git a/packages/permissionless/actions/smartAccount/sendTransactions.ts b/packages/permissionless/actions/smartAccount/sendTransactions.ts index 55af2210..357a1d4e 100644 --- a/packages/permissionless/actions/smartAccount/sendTransactions.ts +++ b/packages/permissionless/actions/smartAccount/sendTransactions.ts @@ -18,12 +18,17 @@ import { sendUserOperation } from "./sendUserOperation" export type SendTransactionsWithPaymasterParameters< entryPoint extends EntryPoint, - TAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined | undefined > = { transactions: { to: Address; value: bigint; data: Hex }[] -} & GetAccountParameter & +} & GetAccountParameter & Middleware & { maxFeePerGas?: bigint maxPriorityFeePerGas?: bigint @@ -77,13 +82,21 @@ export type SendTransactionsWithPaymasterParameters< * }]) */ export async function sendTransactions< + TTransport extends Transport, TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined, + TAccount extends + | SmartAccount + | undefined, entryPoint extends EntryPoint >( client: Client, args: Prettify< - SendTransactionsWithPaymasterParameters + SendTransactionsWithPaymasterParameters< + entryPoint, + TTransport, + TChain, + TAccount + > > ): Promise { const { diff --git a/packages/permissionless/actions/smartAccount/sendUserOperation.ts b/packages/permissionless/actions/smartAccount/sendUserOperation.ts index 84e9afc5..d5e4a447 100644 --- a/packages/permissionless/actions/smartAccount/sendUserOperation.ts +++ b/packages/permissionless/actions/smartAccount/sendUserOperation.ts @@ -21,8 +21,12 @@ import { export type SendUserOperationParameters< entryPoint extends EntryPoint, - TAccount extends SmartAccount | undefined = - | SmartAccount + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined > = { userOperation: entryPoint extends ENTRYPOINT_ADDRESS_V06_TYPE @@ -56,19 +60,23 @@ export type SendUserOperationParameters< | "paymasterData" | "signature" > -} & GetAccountParameter & +} & GetAccountParameter & Middleware export async function sendUserOperation< entryPoint extends EntryPoint, TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client, - args: Prettify> + args: Prettify< + SendUserOperationParameters + > ): Promise { const { account: account_ = client.account } = args if (!account_) throw new AccountOrClientNotFoundError() diff --git a/packages/permissionless/actions/smartAccount/signMessage.ts b/packages/permissionless/actions/smartAccount/signMessage.ts index 30d7ebf0..8c0deebc 100644 --- a/packages/permissionless/actions/smartAccount/signMessage.ts +++ b/packages/permissionless/actions/smartAccount/signMessage.ts @@ -57,8 +57,13 @@ import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" */ export async function signMessage< entryPoint extends EntryPoint, - TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, { diff --git a/packages/permissionless/actions/smartAccount/signTypedData.ts b/packages/permissionless/actions/smartAccount/signTypedData.ts index 5b833f6e..438f3b39 100644 --- a/packages/permissionless/actions/smartAccount/signTypedData.ts +++ b/packages/permissionless/actions/smartAccount/signTypedData.ts @@ -116,8 +116,13 @@ export async function signTypedData< entryPoint extends EntryPoint, const TTypedData extends TypedData | { [key: string]: unknown }, TPrimaryType extends string, - TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined + TTransport extends Transport = Transport, + TChain extends Chain | undefined = Chain | undefined, + TAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( client: Client, { diff --git a/packages/permissionless/actions/smartAccount/writeContract.ts b/packages/permissionless/actions/smartAccount/writeContract.ts index bb86bc25..67a231aa 100644 --- a/packages/permissionless/actions/smartAccount/writeContract.ts +++ b/packages/permissionless/actions/smartAccount/writeContract.ts @@ -72,9 +72,12 @@ import { */ export type WriteContractWithPaymasterParameters< entryPoint extends EntryPoint, + TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined, TAbi extends Abi | readonly unknown[] = Abi | readonly unknown[], TFunctionName extends ContractFunctionName< @@ -99,8 +102,11 @@ export type WriteContractWithPaymasterParameters< export async function writeContract< entryPoint extends EntryPoint, + TTransport extends Transport, TChain extends Chain | undefined, - TAccount extends SmartAccount | undefined, + TAccount extends + | SmartAccount + | undefined, const TAbi extends Abi | readonly unknown[], TFunctionName extends ContractFunctionName< TAbi, @@ -123,6 +129,7 @@ export async function writeContract< ...request }: WriteContractWithPaymasterParameters< entryPoint, + TTransport, TChain, TAccount, TAbi, @@ -138,7 +145,13 @@ export async function writeContract< } as EncodeFunctionDataParameters) const hash = await getAction( client, - sendTransaction, + sendTransaction< + TTransport, + TChain, + TAccount, + entryPoint, + TChainOverride + >, "sendTransaction" )({ data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`, @@ -146,6 +159,7 @@ export async function writeContract< ...request } as unknown as SendTransactionWithPaymasterParameters< entryPoint, + TTransport, TChain, TAccount, TChainOverride diff --git a/packages/permissionless/clients/createSmartAccountClient.ts b/packages/permissionless/clients/createSmartAccountClient.ts index f773eebf..5a413cc6 100644 --- a/packages/permissionless/clients/createSmartAccountClient.ts +++ b/packages/permissionless/clients/createSmartAccountClient.ts @@ -25,8 +25,10 @@ export type SmartAccountClient< entryPoint extends EntryPoint, transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, - account extends SmartAccount | undefined = - | SmartAccount + account extends + | SmartAccount + | undefined = + | SmartAccount | undefined > = Prettify< Client< @@ -34,7 +36,7 @@ export type SmartAccountClient< chain, account, BundlerRpcSchema, - SmartAccountActions + SmartAccountActions > > @@ -42,8 +44,11 @@ export type SmartAccountClientConfig< entryPoint extends EntryPoint, transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, - account extends SmartAccount | undefined = - | SmartAccount + account extends + | SmartAccount + | undefined = + | SmartAccount + | undefined | undefined > = Prettify< Pick< @@ -79,12 +84,14 @@ export type SmartAccountClientConfig< */ export function createSmartAccountClient< - TSmartAccount extends SmartAccount | undefined, TTransport extends Transport = Transport, TChain extends Chain | undefined = undefined, - TEntryPoint extends EntryPoint = TSmartAccount extends SmartAccount - ? U - : never + TEntryPoint extends EntryPoint = EntryPoint, + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount + | undefined >( parameters: SmartAccountClientConfig< TEntryPoint, diff --git a/packages/permissionless/clients/decorators/smartAccount.ts b/packages/permissionless/clients/decorators/smartAccount.ts index 933b4cdd..39c472c2 100644 --- a/packages/permissionless/clients/decorators/smartAccount.ts +++ b/packages/permissionless/clients/decorators/smartAccount.ts @@ -45,9 +45,12 @@ import type { EntryPoint } from "../../types/entrypoint" export type SmartAccountActions< entryPoint extends EntryPoint, + TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined > = { /** @@ -141,9 +144,11 @@ export type SmartAccountActions< */ signMessage: ( args: Parameters< - typeof signMessage + typeof signMessage >[1] - ) => ReturnType> + ) => ReturnType< + typeof signMessage + > /** * Signs typed data and calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`. * @@ -249,6 +254,7 @@ export type SmartAccountActions< entryPoint, TTypedData, TPrimaryType, + TTransport, TChain, TSmartAccount > @@ -258,6 +264,7 @@ export type SmartAccountActions< entryPoint, TTypedData, TPrimaryType, + TTransport, TChain, TSmartAccount > @@ -373,6 +380,7 @@ export type SmartAccountActions< ) => ReturnType< typeof writeContract< entryPoint, + TTransport, TChain, TSmartAccount, TAbi, @@ -457,9 +465,16 @@ export type SmartAccountActions< */ sendTransactions: ( args: Prettify< - SendTransactionsWithPaymasterParameters + SendTransactionsWithPaymasterParameters< + entryPoint, + TTransport, + TChain, + TSmartAccount + > > - ) => ReturnType> + ) => ReturnType< + typeof sendTransactions + > } export function smartAccountActions({ @@ -468,12 +483,14 @@ export function smartAccountActions({ return < TTransport extends Transport, TChain extends Chain | undefined = Chain | undefined, - TSmartAccount extends SmartAccount | undefined = - | SmartAccount + TSmartAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined >( client: Client - ): SmartAccountActions => ({ + ): SmartAccountActions => ({ prepareUserOperationRequest: (args, stateOverrides) => prepareUserOperationRequest( client, @@ -489,29 +506,44 @@ export function smartAccountActions({ middleware } as DeployContractParametersWithPaymaster), sendTransaction: (args) => - sendTransaction(client, { - ...args, - middleware - } as SendTransactionWithPaymasterParameters< - entryPoint, - TChain, - TSmartAccount - >), + sendTransaction( + client, + { + ...args, + middleware + } as SendTransactionWithPaymasterParameters< + entryPoint, + TTransport, + TChain, + TSmartAccount + > + ), sendTransactions: (args) => - sendTransactions(client, { - ...args, - middleware - }), + sendTransactions( + client, + { + ...args, + middleware + } + ), sendUserOperation: (args) => sendUserOperation( client, { ...args, middleware - } as SendUserOperationParameters + } as SendUserOperationParameters< + entryPoint, + TTransport, + TChain, + TSmartAccount + > ), signMessage: (args) => - signMessage(client, args), + signMessage( + client, + args + ), signTypedData: < const TTypedData extends TypedData | { [key: string]: unknown }, TPrimaryType extends string @@ -521,6 +553,7 @@ export function smartAccountActions({ entryPoint, TTypedData, TPrimaryType, + TTransport, TChain, TSmartAccount > @@ -530,6 +563,7 @@ export function smartAccountActions({ entryPoint, TTypedData, TPrimaryType, + TTransport, TChain, TSmartAccount >(client, args), @@ -564,6 +598,7 @@ export function smartAccountActions({ middleware } as WriteContractWithPaymasterParameters< entryPoint, + TTransport, TChain, TSmartAccount, TAbi diff --git a/packages/permissionless/types/index.ts b/packages/permissionless/types/index.ts index 486a26c1..9119b31e 100644 --- a/packages/permissionless/types/index.ts +++ b/packages/permissionless/types/index.ts @@ -25,7 +25,11 @@ export type GetAccountParameterWithClient< export type GetAccountParameter< entryPoint extends EntryPoint, - TAccount extends SmartAccount | undefined + TTransport extends Transport, + TChain extends Chain | undefined, + TAccount extends + | SmartAccount + | undefined > = IsUndefined extends true ? { account: SmartAccount } : { account?: SmartAccount } From d8235496ee24c813b4060a581c06ef75e348fb3a Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 18:02:08 +0100 Subject: [PATCH 3/6] change createSmartAccountClient default types --- packages/permissionless/clients/createSmartAccountClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/permissionless/clients/createSmartAccountClient.ts b/packages/permissionless/clients/createSmartAccountClient.ts index 5a413cc6..2913be3f 100644 --- a/packages/permissionless/clients/createSmartAccountClient.ts +++ b/packages/permissionless/clients/createSmartAccountClient.ts @@ -84,9 +84,9 @@ export type SmartAccountClientConfig< */ export function createSmartAccountClient< - TTransport extends Transport = Transport, - TChain extends Chain | undefined = undefined, - TEntryPoint extends EntryPoint = EntryPoint, + TTransport extends Transport, + TChain extends Chain | undefined, + TEntryPoint extends EntryPoint, TSmartAccount extends | SmartAccount | undefined = From 3c518aba6d9c68028d2fd8a29563705e103eadcd Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 19:11:31 +0100 Subject: [PATCH 4/6] change account type everywhere --- packages/permissionless/accounts/types.ts | 6 ++--- .../actions/erc7579/accountId.ts | 10 +++++-- .../actions/erc7579/installModule.ts | 21 ++++++++++++--- .../actions/erc7579/installModules.ts | 21 ++++++++++++--- .../actions/erc7579/isModuleInstalled.ts | 10 +++++-- .../actions/erc7579/supportsExecutionMode.ts | 10 +++++-- .../actions/erc7579/supportsModule.ts | 10 +++++-- .../actions/erc7579/uninstallModule.ts | 21 ++++++++++++--- .../actions/erc7579/uninstallModules.ts | 21 ++++++++++++--- .../actions/smartAccount/deployContract.ts | 23 +++++++++++----- .../prepareUserOperationRequest.ts | 25 ++++++++++++----- .../actions/smartAccount/sendTransaction.ts | 16 ++++++++--- .../actions/smartAccount/sendTransactions.ts | 14 ++++++++-- .../actions/smartAccount/sendUserOperation.ts | 27 +++++++++++++------ .../clients/createSmartAccountClient.ts | 2 +- packages/permissionless/types/index.ts | 4 +-- 16 files changed, 185 insertions(+), 56 deletions(-) diff --git a/packages/permissionless/accounts/types.ts b/packages/permissionless/accounts/types.ts index 8be7d632..a11d787f 100644 --- a/packages/permissionless/accounts/types.ts +++ b/packages/permissionless/accounts/types.ts @@ -34,9 +34,9 @@ export class SignTransactionNotSupportedBySmartAccount extends BaseError { export type SmartAccount< entryPoint extends EntryPoint, - TSource extends string = string, - transport extends Transport = Transport, - chain extends Chain | undefined = Chain | undefined, + TSource extends string, + transport extends Transport, + chain extends Chain | undefined, TAbi extends Abi | readonly unknown[] = Abi > = LocalAccount & { client: Client< diff --git a/packages/permissionless/actions/erc7579/accountId.ts b/packages/permissionless/actions/erc7579/accountId.ts index 7c2ba4a3..3e3318a9 100644 --- a/packages/permissionless/actions/erc7579/accountId.ts +++ b/packages/permissionless/actions/erc7579/accountId.ts @@ -1,4 +1,5 @@ import { + type CallParameters, type Chain, type Client, ContractFunctionExecutionError, @@ -37,7 +38,12 @@ export async function accountId< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const publicClient = account.client @@ -75,7 +81,7 @@ export async function accountId< abi, functionName: "accountId" }) - }) + } as unknown as CallParameters) if (!result || !result.data) { throw new Error("accountId result is empty") diff --git a/packages/permissionless/actions/erc7579/installModule.ts b/packages/permissionless/actions/erc7579/installModule.ts index 5cb590ed..2e5a1341 100644 --- a/packages/permissionless/actions/erc7579/installModule.ts +++ b/packages/permissionless/actions/erc7579/installModule.ts @@ -14,7 +14,10 @@ import type { EntryPoint } from "../../types/entrypoint" import { parseAccount } from "../../utils/" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import type { Middleware } from "../smartAccount/prepareUserOperationRequest" -import { sendUserOperation } from "../smartAccount/sendUserOperation" +import { + type SendUserOperationParameters, + sendUserOperation +} from "../smartAccount/sendUserOperation" import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type InstallModuleParameters< @@ -64,7 +67,12 @@ export async function installModule< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const installModuleCallData = await account.encodeCallData({ to: account.address, @@ -103,7 +111,7 @@ export async function installModule< return getAction( client, - sendUserOperation, + sendUserOperation, "sendUserOperation" )({ userOperation: { @@ -115,5 +123,10 @@ export async function installModule< }, account: account, middleware - }) + } as SendUserOperationParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + >) } diff --git a/packages/permissionless/actions/erc7579/installModules.ts b/packages/permissionless/actions/erc7579/installModules.ts index a451bf1f..0f943c4c 100644 --- a/packages/permissionless/actions/erc7579/installModules.ts +++ b/packages/permissionless/actions/erc7579/installModules.ts @@ -14,7 +14,10 @@ import type { EntryPoint } from "../../types/entrypoint" import { parseAccount } from "../../utils/" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import type { Middleware } from "../smartAccount/prepareUserOperationRequest" -import { sendUserOperation } from "../smartAccount/sendUserOperation" +import { + type SendUserOperationParameters, + sendUserOperation +} from "../smartAccount/sendUserOperation" import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type InstallModulesParameters< @@ -67,7 +70,12 @@ export async function installModules< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const installModulesCallData = await account.encodeCallData( await Promise.all( @@ -110,7 +118,7 @@ export async function installModules< return getAction( client, - sendUserOperation, + sendUserOperation, "sendUserOperation" )({ userOperation: { @@ -122,5 +130,10 @@ export async function installModules< }, account: account, middleware - }) + } as SendUserOperationParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + >) } diff --git a/packages/permissionless/actions/erc7579/isModuleInstalled.ts b/packages/permissionless/actions/erc7579/isModuleInstalled.ts index 9f632d1b..6ab614b1 100644 --- a/packages/permissionless/actions/erc7579/isModuleInstalled.ts +++ b/packages/permissionless/actions/erc7579/isModuleInstalled.ts @@ -1,5 +1,6 @@ import { type Address, + type CallParameters, type Chain, type Client, ContractFunctionExecutionError, @@ -57,7 +58,12 @@ export async function isModuleInstalled< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const publicClient = account.client @@ -117,7 +123,7 @@ export async function isModuleInstalled< context ] }) - }) + } as unknown as CallParameters) if (!result || !result.data) { throw new Error("accountId result is empty") diff --git a/packages/permissionless/actions/erc7579/supportsExecutionMode.ts b/packages/permissionless/actions/erc7579/supportsExecutionMode.ts index dc58a30f..da0d27a3 100644 --- a/packages/permissionless/actions/erc7579/supportsExecutionMode.ts +++ b/packages/permissionless/actions/erc7579/supportsExecutionMode.ts @@ -1,4 +1,5 @@ import { + type CallParameters, type Chain, type Client, ContractFunctionExecutionError, @@ -101,7 +102,12 @@ export async function supportsExecutionMode< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const publicClient = account.client @@ -152,7 +158,7 @@ export async function supportsExecutionMode< functionName: "supportsExecutionMode", args: [encodedMode] }) - }) + } as unknown as CallParameters) if (!result || !result.data) { throw new Error("accountId result is empty") diff --git a/packages/permissionless/actions/erc7579/supportsModule.ts b/packages/permissionless/actions/erc7579/supportsModule.ts index 9e62f012..3396d5f5 100644 --- a/packages/permissionless/actions/erc7579/supportsModule.ts +++ b/packages/permissionless/actions/erc7579/supportsModule.ts @@ -1,4 +1,5 @@ import { + type CallParameters, type Chain, type Client, ContractFunctionExecutionError, @@ -65,7 +66,12 @@ export async function supportsModule< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const publicClient = account.client @@ -109,7 +115,7 @@ export async function supportsModule< functionName: "supportsModule", args: [parseModuleTypeId(args.type)] }) - }) + } as unknown as CallParameters) if (!result || !result.data) { throw new Error("accountId result is empty") diff --git a/packages/permissionless/actions/erc7579/uninstallModule.ts b/packages/permissionless/actions/erc7579/uninstallModule.ts index 586f215c..617eb7dd 100644 --- a/packages/permissionless/actions/erc7579/uninstallModule.ts +++ b/packages/permissionless/actions/erc7579/uninstallModule.ts @@ -14,7 +14,10 @@ import type { EntryPoint } from "../../types/entrypoint" import { parseAccount } from "../../utils/" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import type { Middleware } from "../smartAccount/prepareUserOperationRequest" -import { sendUserOperation } from "../smartAccount/sendUserOperation" +import { + type SendUserOperationParameters, + sendUserOperation +} from "../smartAccount/sendUserOperation" import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type UninstallModuleParameters< @@ -71,7 +74,12 @@ export async function uninstallModule< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const uninstallModuleCallData = await account.encodeCallData({ to: account.address, @@ -110,7 +118,7 @@ export async function uninstallModule< return getAction( client, - sendUserOperation, + sendUserOperation, "sendUserOperation" )({ userOperation: { @@ -122,5 +130,10 @@ export async function uninstallModule< }, account: account, middleware - }) + } as SendUserOperationParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + >) } diff --git a/packages/permissionless/actions/erc7579/uninstallModules.ts b/packages/permissionless/actions/erc7579/uninstallModules.ts index 599a32ae..e9a12853 100644 --- a/packages/permissionless/actions/erc7579/uninstallModules.ts +++ b/packages/permissionless/actions/erc7579/uninstallModules.ts @@ -14,7 +14,10 @@ import type { EntryPoint } from "../../types/entrypoint" import { parseAccount } from "../../utils/" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import type { Middleware } from "../smartAccount/prepareUserOperationRequest" -import { sendUserOperation } from "../smartAccount/sendUserOperation" +import { + type SendUserOperationParameters, + sendUserOperation +} from "../smartAccount/sendUserOperation" import { type ModuleType, parseModuleTypeId } from "./supportsModule" export type UninstallModulesParameters< @@ -74,7 +77,12 @@ export async function uninstallModules< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + TEntryPoint, + string, + TTransport, + TChain + > const uninstallModulesCallData = await account.encodeCallData( await Promise.all( @@ -117,7 +125,7 @@ export async function uninstallModules< return getAction( client, - sendUserOperation, + sendUserOperation, "sendUserOperation" )({ userOperation: { @@ -129,5 +137,10 @@ export async function uninstallModules< }, account: account, middleware - }) + } as SendUserOperationParameters< + TEntryPoint, + TTransport, + TChain, + TSmartAccount + >) } diff --git a/packages/permissionless/actions/smartAccount/deployContract.ts b/packages/permissionless/actions/smartAccount/deployContract.ts index 8acca74b..bbb1ee2a 100644 --- a/packages/permissionless/actions/smartAccount/deployContract.ts +++ b/packages/permissionless/actions/smartAccount/deployContract.ts @@ -15,14 +15,20 @@ import { parseAccount } from "../../utils/" import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashWithECDSA" import { waitForUserOperationReceipt } from "../bundler/waitForUserOperationReceipt" import type { Middleware } from "./prepareUserOperationRequest" -import { sendUserOperation } from "./sendUserOperation" +import { + type SendUserOperationParameters, + sendUserOperation +} from "./sendUserOperation" export type DeployContractParametersWithPaymaster< entryPoint extends EntryPoint, TAbi extends Abi | readonly unknown[] = Abi | readonly unknown[], + TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, - TAccount extends SmartAccount | undefined = - | SmartAccount + TAccount extends + | SmartAccount + | undefined = + | SmartAccount | undefined, TChainOverride extends Chain | undefined = Chain | undefined > = DeployContractParameters & @@ -85,11 +91,16 @@ export async function deployContract< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + entryPoint, + string, + TTransport, + TChain + > const userOpHash = await getAction( client, - sendUserOperation, + sendUserOperation, "sendUserOperation" )({ userOperation: { @@ -104,7 +115,7 @@ export async function deployContract< }, account: account, middleware - }) + } as SendUserOperationParameters) const userOperationReceipt = await getAction( client, diff --git a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts index b6e4214f..444a4150 100644 --- a/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts +++ b/packages/permissionless/actions/smartAccount/prepareUserOperationRequest.ts @@ -146,9 +146,12 @@ async function prepareUserOperationRequestForEntryPointV06< } = args if (!account_) throw new AccountOrClientNotFoundError() - const account = parseAccount( - account_ - ) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + ENTRYPOINT_ADDRESS_V06_TYPE, + string, + Transport, + TChain + > const [sender, nonce, initCode, callData] = await Promise.all([ partialUserOperation.sender || account.address, @@ -292,9 +295,12 @@ async function prepareUserOperationRequestEntryPointV07< } = args if (!account_) throw new AccountOrClientNotFoundError() - const account = parseAccount( - account_ - ) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + ENTRYPOINT_ADDRESS_V07_TYPE, + string, + Transport, + TChain + > const [sender, nonce, factory, factoryData, callData] = await Promise.all([ partialUserOperation.sender || account.address, @@ -441,7 +447,12 @@ export async function prepareUserOperationRequest< const { account: account_ = client.account } = args if (!account_) throw new AccountOrClientNotFoundError() - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + entryPoint, + string, + TTransport, + TChain + > const entryPointVersion = getEntryPointVersion(account.entryPoint) diff --git a/packages/permissionless/actions/smartAccount/sendTransaction.ts b/packages/permissionless/actions/smartAccount/sendTransaction.ts index b120c47b..3f64cb4c 100644 --- a/packages/permissionless/actions/smartAccount/sendTransaction.ts +++ b/packages/permissionless/actions/smartAccount/sendTransaction.ts @@ -110,7 +110,12 @@ export async function sendTransaction< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + entryPoint, + string, + TTransport, + TChain + > if (!to) throw new Error("Missing to address") @@ -126,7 +131,12 @@ export async function sendTransaction< const userOpHash = await getAction( client, - sendUserOperation, + sendUserOperation< + entryPoint, + TTransport, + TChain, + SmartAccount + >, "sendUserOperation" )({ userOperation: { @@ -136,7 +146,7 @@ export async function sendTransaction< callData: callData, nonce: nonce ? BigInt(nonce) : undefined }, - account: account, + account, middleware }) diff --git a/packages/permissionless/actions/smartAccount/sendTransactions.ts b/packages/permissionless/actions/smartAccount/sendTransactions.ts index 357a1d4e..ef03a44d 100644 --- a/packages/permissionless/actions/smartAccount/sendTransactions.ts +++ b/packages/permissionless/actions/smartAccount/sendTransactions.ts @@ -114,7 +114,12 @@ export async function sendTransactions< }) } - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + entryPoint, + string, + TTransport, + TChain + > if (account.type !== "local") { throw new Error("RPC account type not supported") @@ -133,7 +138,12 @@ export async function sendTransactions< const userOpHash = await getAction( client, - sendUserOperation, + sendUserOperation< + entryPoint, + TTransport, + TChain, + SmartAccount + >, "sendUserOperation" )({ userOperation: { diff --git a/packages/permissionless/actions/smartAccount/sendUserOperation.ts b/packages/permissionless/actions/smartAccount/sendUserOperation.ts index d5e4a447..b78d19ac 100644 --- a/packages/permissionless/actions/smartAccount/sendUserOperation.ts +++ b/packages/permissionless/actions/smartAccount/sendUserOperation.ts @@ -1,21 +1,22 @@ import type { Chain, Client, Hash, Transport } from "viem" import { getAction } from "viem/utils" import type { SmartAccount } from "../../accounts/types" -import type { - GetAccountParameter, - PartialBy, - Prettify, - UserOperation -} from "../../types/" import type { ENTRYPOINT_ADDRESS_V06_TYPE, EntryPoint, GetEntryPointVersion } from "../../types/entrypoint" +import type { + GetAccountParameter, + PartialBy, + Prettify, + UserOperation +} from "../../types/index" import { AccountOrClientNotFoundError, parseAccount } from "../../utils/" import { sendUserOperation as sendUserOperationBundler } from "../bundler/sendUserOperation" import { type Middleware, + type PrepareUserOperationRequestParameters, prepareUserOperationRequest } from "./prepareUserOperationRequest" @@ -81,13 +82,23 @@ export async function sendUserOperation< const { account: account_ = client.account } = args if (!account_) throw new AccountOrClientNotFoundError() - const account = parseAccount(account_) as SmartAccount + const account = parseAccount(account_) as SmartAccount< + entryPoint, + string, + TTransport, + TChain + > const userOperation = await getAction( client, prepareUserOperationRequest, "prepareUserOperationRequest" - )(args) + )({ ...args, account } as PrepareUserOperationRequestParameters< + entryPoint, + TTransport, + TChain, + TAccount + >) userOperation.signature = await account.signUserOperation( userOperation as UserOperation> diff --git a/packages/permissionless/clients/createSmartAccountClient.ts b/packages/permissionless/clients/createSmartAccountClient.ts index 2913be3f..433c2135 100644 --- a/packages/permissionless/clients/createSmartAccountClient.ts +++ b/packages/permissionless/clients/createSmartAccountClient.ts @@ -52,7 +52,7 @@ export type SmartAccountClientConfig< | undefined > = Prettify< Pick< - ClientConfig, + ClientConfig, "cacheTime" | "chain" | "key" | "name" | "pollingInterval" > & Middleware & { diff --git a/packages/permissionless/types/index.ts b/packages/permissionless/types/index.ts index 9119b31e..05462f29 100644 --- a/packages/permissionless/types/index.ts +++ b/packages/permissionless/types/index.ts @@ -31,8 +31,8 @@ export type GetAccountParameter< | SmartAccount | undefined > = IsUndefined extends true - ? { account: SmartAccount } - : { account?: SmartAccount } + ? { account: SmartAccount } + : { account?: SmartAccount } export type Prettify = { [K in keyof T]: T[K] From a6a297ec44ed297d6ac240332677ec7ab6a61ed4 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 19:15:14 +0100 Subject: [PATCH 5/6] No need for chain in smart account --- packages/permissionless/clients/createSmartAccountClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/permissionless/clients/createSmartAccountClient.ts b/packages/permissionless/clients/createSmartAccountClient.ts index 433c2135..88018107 100644 --- a/packages/permissionless/clients/createSmartAccountClient.ts +++ b/packages/permissionless/clients/createSmartAccountClient.ts @@ -52,8 +52,8 @@ export type SmartAccountClientConfig< | undefined > = Prettify< Pick< - ClientConfig, - "cacheTime" | "chain" | "key" | "name" | "pollingInterval" + ClientConfig, + "cacheTime" | "key" | "name" | "pollingInterval" > & Middleware & { account: account From cc5e8a9592c8cb39076c89c1c1474bccdc6cc496 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Tue, 6 Aug 2024 19:23:36 +0100 Subject: [PATCH 6/6] Chain is needed --- packages/permissionless/clients/createSmartAccountClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/permissionless/clients/createSmartAccountClient.ts b/packages/permissionless/clients/createSmartAccountClient.ts index 88018107..433c2135 100644 --- a/packages/permissionless/clients/createSmartAccountClient.ts +++ b/packages/permissionless/clients/createSmartAccountClient.ts @@ -52,8 +52,8 @@ export type SmartAccountClientConfig< | undefined > = Prettify< Pick< - ClientConfig, - "cacheTime" | "key" | "name" | "pollingInterval" + ClientConfig, + "cacheTime" | "chain" | "key" | "name" | "pollingInterval" > & Middleware & { account: account