From b826ba09a1d748719be0aa8102e26f426c3af2df Mon Sep 17 00:00:00 2001 From: Jade Hamilton Date: Fri, 10 Jan 2025 13:22:19 -0700 Subject: [PATCH] feat: add alchemy transport update for the mav2 account client --- .../clients/alchemyClient.test.ts | 1 - .../clients/multiOwnerAlchemyClient.test.ts | 1 - .../src/ma-v2/client/client.test.ts | 2 +- .../src/ma-v2/client/client.ts | 52 +++++++++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts index b28be01efa..e4ee1b1768 100644 --- a/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts +++ b/account-kit/smart-contracts/src/light-account/clients/alchemyClient.test.ts @@ -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", () => { diff --git a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts index 93ca19dda4..5c7185a55c 100644 --- a/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts +++ b/account-kit/smart-contracts/src/light-account/clients/multiOwnerAlchemyClient.test.ts @@ -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", () => { diff --git a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts index d98a23e652..614565ad45 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts @@ -214,7 +214,7 @@ describe("MA v2 Tests", async () => { }, contents: "Hello, Bob!", }, - }; + } as const; const hashedMessageTypedData = hashTypedData(typedData); let signature = await provider.signTypedData({ typedData }); diff --git a/account-kit/smart-contracts/src/ma-v2/client/client.ts b/account-kit/smart-contracts/src/ma-v2/client/client.ts index 58bf4f3dc6..806104d786 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.ts @@ -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>; + TSigner extends SmartAccountSigner = SmartAccountSigner, + TChain extends Chain = Chain, + TTransport extends Transport | AlchemyTransport = Transport +> = SmartAccountClient>; export type CreateSMAV2AccountClientParams< TTransport extends Transport = Transport, @@ -25,13 +35,32 @@ export type CreateSMAV2AccountClientParams< SmartAccountClientConfig, "transport" | "account" | "chain" >; +export type CreateSMAV2AlchemyAccountClientParams< + TTransport extends AlchemyTransport = AlchemyTransport, + TChain extends Chain = Chain, + TSigner extends SmartAccountSigner = SmartAccountSigner +> = Omit< + CreateSMAV2AccountClientParams, + "transport" +> & + Omit< + AlchemySmartAccountClientConfig>, + "account" + >; + +export function createSMAV2AccountClient< + TChain extends Chain = Chain, + TSigner extends SmartAccountSigner = SmartAccountSigner +>( + args: CreateSMAV2AlchemyAccountClientParams +): Promise>; export function createSMAV2AccountClient< TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner >( args: CreateSMAV2AccountClientParams -): Promise>; +): Promise>; /** * Creates a SMAv2 account client using the provided configuration parameters. @@ -64,8 +93,21 @@ export function createSMAV2AccountClient< */ export async function createSMAV2AccountClient( config: CreateSMAV2AccountClientParams -): Promise { - const smaV2Account = await createSMAV2Account(config); +): Promise { + 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,