Skip to content
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

chore: move optional mode into account params #1339

Merged
merged 2 commits into from
Feb 10, 2025
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
12 changes: 2 additions & 10 deletions account-kit/core/src/actions/createAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type OptionalFields } from "@aa-sdk/core";
import type { AlchemyWebSigner } from "@account-kit/signer";
import {
createLightAccount,
Expand Down Expand Up @@ -48,10 +47,7 @@ export type AccountConfig<TAccount extends SupportedAccountTypes> =
>
: TAccount extends "ModularAccountV2"
? OmitSignerTransportChain<
OptionalFields<
CreateModularAccountV2Params<Transport, AlchemyWebSigner>,
"mode"
>
CreateModularAccountV2Params<Transport, AlchemyWebSigner>
>
: never;

Expand Down Expand Up @@ -160,12 +156,8 @@ export async function createAccount<TAccount extends SupportedAccountTypes>(
return account;
});
case "ModularAccountV2":
const maV2Params = {
mode: "default",
...params,
};
return createModularAccountV2({
...(maV2Params as AccountConfig<"ModularAccountV2">),
...(params as AccountConfig<"ModularAccountV2">),
...(cachedConfig as OmitSignerTransportChain<CreateModularAccountV2Params>),
signer,
transport: (opts) => transport({ ...opts, retryCount: 0 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type CreateModularAccountV2Params<
}) &
(
| {
mode: "default";
mode?: "default";
salt?: bigint;
factoryAddress?: Address;
initCode?: Hex;
Expand Down Expand Up @@ -136,7 +136,8 @@ export async function createModularAccountV2(
getImplementationAddress,
};
}
case "default": {
case "default":
case undefined: {
const {
salt = 0n,
factoryAddress = getDefaultMAV2FactoryAddress(chain),
Expand Down
16 changes: 5 additions & 11 deletions account-kit/smart-contracts/src/ma-v2/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
type SmartAccountSigner,
type SmartAccountClientConfig,
type NotType,
type OptionalFields,
createSmartAccountClient,
default7702GasEstimator,
default7702UserOpSigner,
Expand Down Expand Up @@ -36,7 +35,7 @@ export type CreateModularAccountV2ClientParams<
TTransport extends Transport = Transport,
TChain extends Chain = Chain,
TSigner extends SmartAccountSigner = SmartAccountSigner
> = OptionalFields<CreateModularAccountV2Params<TTransport, TSigner>, "mode"> &
> = CreateModularAccountV2Params<TTransport, TSigner> &
Omit<
SmartAccountClientConfig<TTransport, TChain>,
"transport" | "account" | "chain"
Expand Down Expand Up @@ -111,14 +110,9 @@ export async function createModularAccountV2Client(
| CreateModularAccountV2ClientParams
| CreateModularAccountV2AlchemyClientParams
): Promise<SmartAccountClient | AlchemySmartAccountClient> {
const config_ = {
...config,
mode: config.mode ?? "default",
};

const { transport, chain } = config_;
const { transport, chain } = config;

const account = await createModularAccountV2(config_);
const account = await createModularAccountV2(config);

const middlewareToAppend =
config.mode === "7702"
Expand All @@ -130,7 +124,7 @@ export async function createModularAccountV2Client(

if (isAlchemyTransport(transport, chain)) {
return createAlchemySmartAccountClient({
...config_,
...config,
transport,
chain,
account,
Expand All @@ -139,7 +133,7 @@ export async function createModularAccountV2Client(
}

return createSmartAccountClient({
...config_,
...config,
account,
...middlewareToAppend,
});
Expand Down