Skip to content

Commit

Permalink
feat: add alchemy transport update for the mav2 account client
Browse files Browse the repository at this point in the history
  • Loading branch information
Blu-J committed Jan 11, 2025
1 parent 18a9228 commit 0048417
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
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> {
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

0 comments on commit 0048417

Please sign in to comment.