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 10, 2025
1 parent d05051e commit 0bbe272
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
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
55 changes: 51 additions & 4 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,24 @@ 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
> = SmartAccountClient<Transport, TChain, MAV2Account<TSigner>>;

export type SMAV2AlchemyAccountClient<
TSigner extends SmartAccountSigner = SmartAccountSigner,
TChain extends Chain = Chain
> = SmartAccountClient<AlchemyTransport, TChain, MAV2Account<TSigner>>;

export type CreateSMAV2AccountClientParams<
TTransport extends Transport = Transport,
Expand All @@ -25,13 +39,32 @@ export type CreateSMAV2AccountClientParams<
SmartAccountClientConfig<TTransport, TChain>,
"transport" | "account" | "chain"
>;
export type CreateSMAV2AlchemyAccountClientParams<
TTransport extends Transport = 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<SMAV2AlchemyAccountClient<TSigner, TChain>>;

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,7 +97,21 @@ export function createSMAV2AccountClient<
*/
export async function createSMAV2AccountClient(
config: CreateSMAV2AccountClientParams
): Promise<SmartAccountClient> {
): Promise<SmartAccountClient | AlchemySmartAccountClient> {
const { transport, chain } = config;
if (isAlchemyTransport(transport, chain)) {
const smaV2Account = await createSMAV2Account({
...config,
transport,
chain,
});
return createAlchemySmartAccountClient({
...config,
transport,
chain,
account: smaV2Account,
});
}
const smaV2Account = await createSMAV2Account(config);

return createSmartAccountClient({
Expand Down

0 comments on commit 0bbe272

Please sign in to comment.