Skip to content

Commit

Permalink
Merge pull request #261 from pimlicolabs/fix-public-actions
Browse files Browse the repository at this point in the history
Fix public actions type
  • Loading branch information
plusminushalf authored Aug 6, 2024
2 parents 623f380 + cc5e8a9 commit b6c6c6c
Show file tree
Hide file tree
Showing 33 changed files with 615 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function privateKeyToBiconomySmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
privateKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export async function signerToBiconomySmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export async function signerToEcdsaKernelSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function privateKeyToLightSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{ privateKey, ...rest }: PrivateKeyToLightSmartAccountParameters<entryPoint>
): Promise<LightSmartAccount<entryPoint, TTransport, TChain>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export async function signerToLightSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function privateKeyToSafeSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{ privateKey, ...rest }: PrivateKeyToSafeSmartAccountParameters<entryPoint>
): Promise<SafeSmartAccount<entryPoint, TTransport, TChain>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ export async function signerToSafeSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
args: SignerToSafeSmartAccountParameters<
entryPoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function privateKeyToSimpleSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
privateKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export async function signerToSimpleSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
signer,
Expand Down
8 changes: 7 additions & 1 deletion packages/permissionless/accounts/toSmartAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export function toSmartAccount<
signTypedData
}: TAccountSource & {
source: TSource
client: Client<transport, chain, undefined, PublicRpcSchema, PublicActions>
client: Client<
transport,
chain,
undefined,
PublicRpcSchema,
PublicActions<transport, chain>
>
entryPoint: TEntryPoint
getNonce: (key?: bigint) => Promise<bigint>
getInitCode: () => Promise<Hex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function privateKeyToTrustSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{ privateKey, ...rest }: PrivateKeyToTrustSmartAccountParameters<entryPoint>
): Promise<TrustSmartAccount<entryPoint, TTransport, TChain>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export async function signerToTrustSmartAccount<
TChain,
undefined,
PublicRpcSchema,
PublicActions
PublicActions<TTransport, TChain>
>,
{
signer,
Expand Down
14 changes: 10 additions & 4 deletions packages/permissionless/accounts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ 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<TSource> & {
client: Client<transport, chain, undefined, PublicRpcSchema, PublicActions>
client: Client<
transport,
chain,
undefined,
PublicRpcSchema,
PublicActions<transport, chain>
>
entryPoint: entryPoint
getNonce: (key?: bigint) => Promise<bigint>
getInitCode: () => Promise<Hex>
Expand Down
86 changes: 66 additions & 20 deletions packages/permissionless/actions/erc7579.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,77 @@ import {

export type Erc7579Actions<
TEntryPoint extends EntryPoint,
TSmartAccount extends SmartAccount<TEntryPoint> | undefined
TTransport extends Transport,
TChain extends Chain | undefined,
TSmartAccount extends
| SmartAccount<TEntryPoint, string, TTransport, TChain>
| undefined
> = {
accountId: (
args?: TSmartAccount extends undefined
? GetAccountParameter<TEntryPoint, TSmartAccount>
? GetAccountParameter<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
: undefined
) => Promise<string>
installModule: (
args: InstallModuleParameters<TEntryPoint, TSmartAccount>
args: InstallModuleParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<Hash>
installModules: (
args: InstallModulesParameters<TEntryPoint, TSmartAccount>
args: InstallModulesParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<Hash>
isModuleInstalled: (
args: IsModuleInstalledParameters<TEntryPoint, TSmartAccount>
args: IsModuleInstalledParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<boolean>
supportsExecutionMode: (
args: SupportsExecutionModeParameters<TEntryPoint, TSmartAccount>
args: SupportsExecutionModeParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<boolean>
supportsModule: (
args: SupportsModuleParameters<TEntryPoint, TSmartAccount>
args: SupportsModuleParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<boolean>
uninstallModule: (
args: UninstallModuleParameters<TEntryPoint, TSmartAccount>
args: UninstallModuleParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<Hash>
uninstallModules: (
args: UninstallModulesParameters<TEntryPoint, TSmartAccount>
args: UninstallModulesParameters<
TEntryPoint,
TTransport,
TChain,
TSmartAccount
>
) => Promise<Hash>
}

Expand Down Expand Up @@ -92,47 +136,49 @@ export function erc7579Actions<TEntryPoint extends EntryPoint>(_args: {
entryPoint: TEntryPoint
}) {
return <
TSmartAccount extends SmartAccount<TEntryPoint> | undefined,
TTransport extends Transport,
TChain extends Chain | undefined
TChain extends Chain | undefined,
TSmartAccount extends
| SmartAccount<TEntryPoint, string, TTransport, TChain>
| undefined
>(
client: Client<TTransport, TChain, TSmartAccount>
): Erc7579Actions<TEntryPoint, TSmartAccount> => ({
): Erc7579Actions<TEntryPoint, TTransport, TChain, TSmartAccount> => ({
accountId: (args) => accountId(client, args),
installModule: (args) =>
installModule<TEntryPoint, TSmartAccount, TTransport, TChain>(
installModule<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
),
installModules: (args) =>
installModules<TEntryPoint, TSmartAccount, TTransport, TChain>(
installModules<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
),
isModuleInstalled: (args) =>
isModuleInstalled<TEntryPoint, TSmartAccount, TTransport, TChain>(
isModuleInstalled<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
),
supportsExecutionMode: (args) =>
supportsExecutionMode<
TEntryPoint,
TSmartAccount,
TTransport,
TChain
TChain,
TSmartAccount
>(client, args),
supportsModule: (args) =>
supportsModule<TEntryPoint, TSmartAccount, TTransport, TChain>(
supportsModule<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
),
uninstallModule: (args) =>
uninstallModule<TEntryPoint, TSmartAccount, TTransport, TChain>(
uninstallModule<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
),
uninstallModules: (args) =>
uninstallModules<TEntryPoint, TSmartAccount, TTransport, TChain>(
uninstallModules<TEntryPoint, TTransport, TChain, TSmartAccount>(
client,
args
)
Expand Down
20 changes: 14 additions & 6 deletions packages/permissionless/actions/erc7579/accountId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CallParameters,
type Chain,
type Client,
ContractFunctionExecutionError,
Expand All @@ -14,13 +15,15 @@ import { AccountOrClientNotFoundError } from "../../utils/signUserOperationHashW

export async function accountId<
TEntryPoint extends EntryPoint,
TSmartAccount extends SmartAccount<TEntryPoint> | undefined,
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
TTransport extends Transport,
TChain extends Chain | undefined,
TSmartAccount extends
| SmartAccount<TEntryPoint, string, TTransport, TChain>
| undefined
>(
client: Client<TTransport, TChain, TSmartAccount>,
args?: TSmartAccount extends undefined
? GetAccountParameter<TEntryPoint, TSmartAccount>
? GetAccountParameter<TEntryPoint, TTransport, TChain, TSmartAccount>
: undefined
): Promise<string> {
let account_ = client.account
Expand All @@ -35,7 +38,12 @@ export async function accountId<
})
}

const account = parseAccount(account_) as SmartAccount<TEntryPoint>
const account = parseAccount(account_) as SmartAccount<
TEntryPoint,
string,
TTransport,
TChain
>

const publicClient = account.client

Expand Down Expand Up @@ -73,7 +81,7 @@ export async function accountId<
abi,
functionName: "accountId"
})
})
} as unknown as CallParameters<TChain>)

if (!result || !result.data) {
throw new Error("accountId result is empty")
Expand Down
Loading

0 comments on commit b6c6c6c

Please sign in to comment.