Skip to content

Fix public actions type #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@
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>(

Check warning on line 154 in packages/permissionless/actions/erc7579.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/actions/erc7579.ts#L154

Added line #L154 was not covered by tests
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

Check warning on line 168 in packages/permissionless/actions/erc7579.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/actions/erc7579.ts#L167-L168

Added lines #L167 - L168 were not covered by tests
>(client, args),
supportsModule: (args) =>
supportsModule<TEntryPoint, TSmartAccount, TTransport, TChain>(
supportsModule<TEntryPoint, TTransport, TChain, TSmartAccount>(

Check warning on line 171 in packages/permissionless/actions/erc7579.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/actions/erc7579.ts#L171

Added line #L171 was not covered by tests
client,
args
),
uninstallModule: (args) =>
uninstallModule<TEntryPoint, TSmartAccount, TTransport, TChain>(
uninstallModule<TEntryPoint, TTransport, TChain, TSmartAccount>(

Check warning on line 176 in packages/permissionless/actions/erc7579.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/actions/erc7579.ts#L176

Added line #L176 was not covered by tests
client,
args
),
uninstallModules: (args) =>
uninstallModules<TEntryPoint, TSmartAccount, TTransport, TChain>(
uninstallModules<TEntryPoint, TTransport, TChain, TSmartAccount>(

Check warning on line 181 in packages/permissionless/actions/erc7579.ts

View check run for this annotation

Codecov / codecov/patch

packages/permissionless/actions/erc7579.ts#L181

Added line #L181 was not covered by tests
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
Loading