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

feat: add alchemy transport update for the mav2 account client #1271

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -12,7 +12,6 @@ import {
} from "@account-kit/infra";
import { Alchemy, Network } from "alchemy-sdk";
import { avalanche, type Chain } from "viem/chains";
import { createLightAccountAlchemyClient } from "./alchemyClient.js";
import { createLightAccountClient } from "./client.js";

describe("Light Account Client Tests", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from "@account-kit/infra";
import { Alchemy, Network } from "alchemy-sdk";
import { avalanche, type Chain } from "viem/chains";
import { createMultiOwnerLightAccountAlchemyClient } from "./multiOwnerAlchemyClient.js";
import { createMultiOwnerLightAccountClient } from "./multiOwnerLightAccount.js";

describe("MultiOwnerLightAccount Client Tests", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe("MA v2 Tests", async () => {
},
contents: "Hello, Bob!",
},
};
} as const;

const hashedMessageTypedData = hashTypedData(typedData);
let signature = await provider.signTypedData({ typedData });
Expand Down
52 changes: 47 additions & 5 deletions account-kit/smart-contracts/src/ma-v2/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ import {
type CreateSMAV2AccountParams,
type MAV2Account,
} from "../account/semiModularAccountV2.js";
import {
createAlchemySmartAccountClient,
isAlchemyTransport,
type AlchemySmartAccountClient,
type AlchemySmartAccountClientConfig,
type AlchemyTransport,
} from "@account-kit/infra";
import type { LightAccount } from "../../light-account/accounts/account.js";

export type SMAV2AccountClient<
TSigner extends SmartAccountSigner = SmartAccountSigner
> = SmartAccountClient<Transport, Chain, MAV2Account<TSigner>>;
TSigner extends SmartAccountSigner = SmartAccountSigner,
TChain extends Chain = Chain,
TTransport extends Transport | AlchemyTransport = Transport
> = SmartAccountClient<TTransport, TChain, MAV2Account<TSigner>>;

export type CreateSMAV2AccountClientParams<
TTransport extends Transport = Transport,
Expand All @@ -25,13 +35,32 @@ export type CreateSMAV2AccountClientParams<
SmartAccountClientConfig<TTransport, TChain>,
"transport" | "account" | "chain"
>;
export type CreateSMAV2AlchemyAccountClientParams<
TTransport extends AlchemyTransport = AlchemyTransport,
TChain extends Chain = Chain,
TSigner extends SmartAccountSigner = SmartAccountSigner
> = Omit<
CreateSMAV2AccountClientParams<TTransport, TChain, TSigner>,
"transport"
> &
Omit<
AlchemySmartAccountClientConfig<TChain, LightAccount<TSigner>>,
"account"
>;

export function createSMAV2AccountClient<
TChain extends Chain = Chain,
TSigner extends SmartAccountSigner = SmartAccountSigner
>(
args: CreateSMAV2AlchemyAccountClientParams<AlchemyTransport, TChain, TSigner>
): Promise<SMAV2AccountClient<TSigner, TChain, AlchemyTransport>>;

export function createSMAV2AccountClient<
TChain extends Chain = Chain,
TSigner extends SmartAccountSigner = SmartAccountSigner
>(
args: CreateSMAV2AccountClientParams<Transport, TChain, TSigner>
): Promise<SMAV2AccountClient<TSigner>>;
): Promise<SMAV2AccountClient<TSigner, TChain>>;

/**
* Creates a SMAv2 account client using the provided configuration parameters.
Expand Down Expand Up @@ -64,8 +93,21 @@ export function createSMAV2AccountClient<
*/
export async function createSMAV2AccountClient(
config: CreateSMAV2AccountClientParams
): Promise<SmartAccountClient> {
const smaV2Account = await createSMAV2Account(config);
): Promise<SmartAccountClient | AlchemySmartAccountClient> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my own understanding: does it complain if this is just SmartAccountClient? technically the AlchemySmartAccountClient is a SmartAccountClient

const { transport, chain } = config;
const smaV2Account = await createSMAV2Account({
...config,
transport,
chain,
});
if (isAlchemyTransport(transport, chain)) {
return createAlchemySmartAccountClient({
...config,
transport,
chain,
account: smaV2Account,
});
}

return createSmartAccountClient({
...config,
Expand Down
Loading