Skip to content

Commit

Permalink
Merge pull request #2053 from Web3Auth/feat/pass-smart-account-config
Browse files Browse the repository at this point in the history
Feat/pass smart account config
  • Loading branch information
chaitanyapotti authored Jan 15, 2025
2 parents 25b7451 + 443b812 commit 76d3837
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 43 deletions.
4 changes: 2 additions & 2 deletions packages/plugins/wallet-services-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"dist"
],
"devDependencies": {
"@toruslabs/ethereum-controllers": "^7.0.1"
"@toruslabs/ethereum-controllers": "^7.1.3"
},
"dependencies": {
"@web3auth/account-abstraction-provider": "^9.5.2",
"@web3auth/auth": "^9.6.2",
"@web3auth/base": "^9.5.2",
"@web3auth/no-modal": "^9.5.2",
"@web3auth/ws-embed": "^3.4.0",
"@web3auth/ws-embed": "^3.4.4",
"loglevel": "^1.9.2"
},
"peerDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions packages/plugins/wallet-services-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type BaseEmbedControllerState } from "@toruslabs/base-controllers";
import type { EthereumProviderConfig } from "@toruslabs/ethereum-controllers";
import type { AccountAbstractionConfig, EthereumProviderConfig } from "@toruslabs/ethereum-controllers";
import { AccountAbstractionProvider } from "@web3auth/account-abstraction-provider";
import { SafeEventEmitter, type WhiteLabelData } from "@web3auth/auth";
import {
Expand All @@ -21,7 +21,7 @@ import {
WALLET_ADAPTERS,
WalletServicesPluginError,
} from "@web3auth/base";
import WsEmbed, { AccountAbstractionConfig, CtorArgs, WsEmbedParams } from "@web3auth/ws-embed";
import WsEmbed, { CtorArgs, WsEmbedParams } from "@web3auth/ws-embed";

type WsPluginEmbedParams = Omit<WsEmbedParams, "buildEnv" | "enableLogging" | "chainConfig" | "confirmationStrategy"> & {
/**
Expand Down Expand Up @@ -111,13 +111,15 @@ export class WalletServicesPlugin extends SafeEventEmitter implements IPlugin {
const smartAccountType = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.name;
const paymasterConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config?.paymasterConfig;
const bundlerConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config?.bundlerConfig;
const smartAccountConfig = (web3auth.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.options;

// TODO: fix this type casting when we start using accountAbstractionController
accountAbstractionConfig = {
smartAccountAddress: smartAccountAddress || undefined,
smartAccountType: smartAccountType || undefined,
paymasterConfig: paymasterConfig || undefined,
bundlerConfig: bundlerConfig || undefined,
smartAccountConfig: smartAccountConfig || undefined,
} as AccountAbstractionConfig;
} else if (this.walletInitOptions?.accountAbstractionConfig && Object.keys(this.walletInitOptions.accountAbstractionConfig).length > 0) {
// if wallet services plugin is initialized with accountAbstractionConfig we enable wallet service AA without AA provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint06Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type BiconomySmartAccountConfig = Pick<ToBiconomySmartAccountParameters, "entryPoint" | "ecdsaModuleAddress" | "factoryAddress">;
import { BiconomySmartAccountConfig, ISmartAccount } from "./types";

export class BiconomySmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.BICONOMY;

private options: BiconomySmartAccountConfig;
public options: BiconomySmartAccountConfig;

constructor(options?: BiconomySmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type KernelSmartAccountParameters = Parameters<typeof toEcdsaKernelSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type KernelSmartAccountConfig = Omit<KernelSmartAccountParameters, "owners" | "client" | "address" | "nonceKey" | "index">;
import { ISmartAccount, KernelSmartAccountConfig, KernelSmartAccountParameters } from "./types";

export class KernelSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.KERNEL;

private options: KernelSmartAccountConfig;
public options: KernelSmartAccountConfig;

constructor(options?: KernelSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type LightSmartAccountConfig = Omit<ToLightSmartAccountParameters, "owner" | "client" | "index" | "address" | "nonceKey">;
import { ISmartAccount, LightSmartAccountConfig } from "./types";

export class LightSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.LIGHT;

private options: LightSmartAccountConfig;
public options: LightSmartAccountConfig;

constructor(options?: LightSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type NexusSmartAccountConfig = Omit<ToNexusSmartAccountParameters, "owners" | "client" | "index" | "address">;
import { ISmartAccount, NexusSmartAccountConfig } from "./types";

export class NexusSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.NEXUS;

private options: NexusSmartAccountConfig;
public options: NexusSmartAccountConfig;

constructor(options?: NexusSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type SafeSmartAccountParameters = Parameters<typeof toSafeSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type SafeSmartAccountConfig = Omit<
SafeSmartAccountParameters,
"owners" | "client" | "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter"
>;
import { ISmartAccount, SafeSmartAccountConfig, SafeSmartAccountParameters } from "./types";

export class SafeSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.SAFE;

private options: SafeSmartAccountConfig;
public options: SafeSmartAccountConfig;

constructor(options?: SafeSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type SimpleSmartAccountParameters = Parameters<typeof toSimpleSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type SimpleSmartAccountConfig = Omit<SimpleSmartAccountParameters, "owner" | "client">;
import { ISmartAccount, SimpleSmartAccountConfig } from "./types";

export class SimpleSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.SIMPLE;

private options: SimpleSmartAccountConfig;
public options: SimpleSmartAccountConfig;

constructor(options?: SimpleSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import { Client, EIP1193Provider } from "viem";
import { entryPoint06Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type TrustSmartAccountParameters = Parameters<typeof toTrustSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type TrustSmartAccountConfig = Omit<TrustSmartAccountParameters, "owner" | "client" | "address" | "nonceKey" | "index">;
import { ISmartAccount, TrustSmartAccountConfig, TrustSmartAccountParameters } from "./types";

export class TrustSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.TRUST;

private options: TrustSmartAccountConfig;
public options: TrustSmartAccountConfig;

constructor(options?: TrustSmartAccountConfig) {
this.options = options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
import { IBaseSmartAccount, IProvider } from "@web3auth/base";
import {
ToBiconomySmartAccountParameters,
toEcdsaKernelSmartAccount,
ToLightSmartAccountParameters,
ToNexusSmartAccountParameters,
toSafeSmartAccount,
toSimpleSmartAccount,
toTrustSmartAccount,
} from "permissionless/accounts";
import { Client } from "viem";
import { SmartAccount } from "viem/account-abstraction";

export type BiconomySmartAccountConfig = Pick<ToBiconomySmartAccountParameters, "entryPoint" | "ecdsaModuleAddress" | "factoryAddress">;

export type KernelSmartAccountParameters = Parameters<typeof toEcdsaKernelSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

export type KernelSmartAccountConfig = Omit<KernelSmartAccountParameters, "owners" | "client" | "address" | "nonceKey" | "index">;

export type LightSmartAccountConfig = Omit<ToLightSmartAccountParameters, "owner" | "client" | "index" | "address" | "nonceKey">;

export type NexusSmartAccountConfig = Omit<ToNexusSmartAccountParameters, "owners" | "client" | "index" | "address">;

export type SafeSmartAccountParameters = Parameters<typeof toSafeSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

export type SafeSmartAccountConfig = Omit<
SafeSmartAccountParameters,
"owners" | "client" | "address" | "nonceKey" | "saltNonce" | "validUntil" | "validAfter"
>;

export type SimpleSmartAccountParameters = Parameters<typeof toSimpleSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

export type SimpleSmartAccountConfig = Omit<SimpleSmartAccountParameters, "owner" | "client">;

export type TrustSmartAccountParameters = Parameters<typeof toTrustSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

export type TrustSmartAccountConfig = Omit<TrustSmartAccountParameters, "owner" | "client" | "address" | "nonceKey" | "index">;

export interface ISmartAccount extends IBaseSmartAccount {
options:
| BiconomySmartAccountConfig
| KernelSmartAccountConfig
| NexusSmartAccountConfig
| SafeSmartAccountConfig
| TrustSmartAccountConfig
| LightSmartAccountConfig
| SimpleSmartAccountConfig;
getSmartAccount(params: { owner: IProvider; client: Client }): Promise<SmartAccount>;
}

0 comments on commit 76d3837

Please sign in to comment.