From 54fb3da5cb0ce655a32da0f631faa72edf0a2a99 Mon Sep 17 00:00:00 2001 From: linna Date: Thu, 12 Dec 2024 19:45:53 -0500 Subject: [PATCH] feat: adds MAv2 client --- .../src/ma-v2/client/client.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) 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 e69de29bb2..f3d693e55f 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.ts @@ -0,0 +1,73 @@ +import { + createSmartAccountClient, + type SmartAccountClient, + type SmartAccountSigner, +} from "@aa-sdk/core"; +import { type Chain, type CustomTransport, type Transport } from "viem"; + +import type { SmartAccountClientConfig } from "@aa-sdk/core"; + +import { + createSMAV2Account, + type CreateSMAV2AccountParams, + type SMAV2Account, +} from "../account/account.js"; + +export type CreateSMAV2AccountClientParams< + TTransport extends Transport = Transport, + TChain extends Chain = Chain, + TSigner extends SmartAccountSigner = SmartAccountSigner +> = CreateSMAV2AccountParams & + Omit< + SmartAccountClientConfig, + "transport" | "account" | "chain" + >; + +export function createSMAV2SignerAccountClient< + TChain extends Chain = Chain, + TSigner extends SmartAccountSigner = SmartAccountSigner +>( + args: CreateSMAV2AccountClientParams +): Promise>>; + +/** + * Creates a MAv2 account client using the provided configuration parameters. + * + * @example + * ```ts + * import { http } from "viem"; + * import { createSMAV2SignerAccountClient } from "@account-kit/smart-contracts"; + * import { LocalAccountSigner } from "@aa-sdk/core"; + * import { sepolia } from "@account-kit/infra"; + * + * const MNEMONIC = "..."; + * const RPC_URL = "..."; + * + * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); + * + * const chain = sepolia; + * + * const transport = http(RPC_URL); + * + * const SMAV2SignerAccountClient = await createSMAV2SignerAccountClient({di + * chain, + * signer, + * transport, + * }); + * ``` + * + * @param {CreateSMAV2AccountClientParams} config The configuration parameters required to create the MAv2 account client + * @returns {Promise} A promise that resolves to a `SmartAccountClient` instance + */ +export async function createSMAV2SignerAccountClient({ + ...config +}: CreateSMAV2AccountClientParams): Promise { + const maV2SignerAccount = await createSMAV2Account({ + ...config, + }); + + return createSmartAccountClient({ + ...config, + account: maV2SignerAccount, + }); +}