Skip to content

Commit

Permalink
chore: upgrade to viem v2.x.x (alchemyplatform#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored Jan 30, 2024
1 parent c567a32 commit e8a99bd
Show file tree
Hide file tree
Showing 101 changed files with 539 additions and 361 deletions.
2 changes: 1 addition & 1 deletion packages/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@
"gitHead": "ee46e8bb857de3b631044fa70714ea706d9e317d",
"dependencies": {
"@alchemy/aa-core": "^3.0.0-alpha.0",
"viem": "^1.21.4"
"viem": "^2.5.0"
}
}
2 changes: 1 addition & 1 deletion packages/accounts/plugindefs/multi-owner/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sepolia } from "@alchemy/aa-core";
import { parseAbiParameters } from "viem";
import { sepolia } from "viem/chains";
import type { PluginGenConfig } from "../types";
import { MultiOwnerPluginAbi } from "./abi.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/plugindefs/session-key/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sepolia } from "@alchemy/aa-core";
import { parseAbiParameters } from "viem";
import { sepolia } from "viem/chains";
import { MultiOwnerPluginGenConfig } from "../multi-owner/config.js";
import type { PluginGenConfig } from "../types";
import { SessionKeyPluginAbi } from "./abi.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/plugindefs/token-receiver/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sepolia } from "viem/chains";
import { sepolia } from "@alchemy/aa-core";
import type { PluginGenConfig } from "../types";
import { TokenReceiverPluginAbi } from "./abi.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/plugingen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function plugingen({
const plugin = getContract({
address: address[chain.id],
abi: IPluginAbi,
publicClient: client,
client,
});

const result = await asyncPipe(...phases)({
Expand Down
6 changes: 3 additions & 3 deletions packages/accounts/plugingen/phases/plugin-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const PluginActionsGenPhase: Phase = async (input) => {
const executionAbiConst = `${contract.name}ExecutionFunctionAbi`;
const executionAbi = extractExecutionAbi(executionFunctions, contract.abi);

addImport("viem", { name: "GetFunctionArgs", isType: true });
addImport("viem", { name: "EncodeFunctionDataParameters", isType: true });
addImport("viem", { name: "Transport", isType: true });
addImport("viem", { name: "Chain", isType: true });
addImport("@alchemy/aa-core", {
Expand Down Expand Up @@ -54,9 +54,9 @@ export const PluginActionsGenPhase: Phase = async (input) => {
providerFunctionDefs.push(dedent`
${camelCase(
n.name
)}: (args: GetFunctionArgs<typeof ${executionAbiConst}, "${
)}: (args: Pick<EncodeFunctionDataParameters<typeof ${executionAbiConst}, "${
n.name
}"> & { overrides?: UserOperationOverrides; } & GetAccountParameter<TAccount>) => Promise<SendUserOperationResult>
}">, "args"> & { overrides?: UserOperationOverrides; } & GetAccountParameter<TAccount>) => Promise<SendUserOperationResult>
`);
return dedent`
${camelCase(n.name)}(${argsParamString}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const AccountReadActionsGenPhase: Phase = async (input) => {
const executionAbiConst = `${contract.name}ExecutionFunctionAbi`;
const executionAbi = extractExecutionAbi(executionFunctions, contract.abi);

addImport("viem", { name: "GetFunctionArgs", isType: true });
addImport("viem", { name: "EncodeFunctionDataParameters", isType: true });
addImport("viem", { name: "encodeFunctionData" });
addImport("viem", { name: "Hex", isType: true });

Expand All @@ -24,9 +24,9 @@ export const AccountReadActionsGenPhase: Phase = async (input) => {
accountFunctionActionDefs.push(
dedent`encode${pascalCase(
n.name
)}: (args: GetFunctionArgs<typeof ${executionAbiConst}, "${
)}: (args: Pick<EncodeFunctionDataParameters<typeof ${executionAbiConst}, "${
n.name
}">) => Hex`
}">, "args">) => Hex`
);
methodContent.push(dedent`
encode${pascalCase(n.name)}(${argsParamString}) {
Expand All @@ -49,9 +49,9 @@ export const AccountReadActionsGenPhase: Phase = async (input) => {
n.inputs.length > 0
? dedent`read${pascalCase(
n.name
)}: (args: GetFunctionArgs<typeof ${executionAbiConst}, "${
)}: (args: Pick<EncodeFunctionDataParameters<typeof ${executionAbiConst}, "${
n.name
}"> & GetAccountParameter<TAccount>) => Promise<ReadContractReturnType<typeof ${executionAbiConst}, "${
}">, "args"> & GetAccountParameter<TAccount>) => Promise<ReadContractReturnType<typeof ${executionAbiConst}, "${
n.name
}">>`
: dedent`read${pascalCase(
Expand Down
109 changes: 0 additions & 109 deletions packages/accounts/plugingen/phases/plugin-generator/client-actions.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const GetContractGenPhase: Phase = async (input) => {
getContract: <C extends Client>(
client: C,
address?: Address
): GetContractReturnType<typeof ${contract.name}Abi, PublicClient, undefined, Address> => {
): GetContractReturnType<typeof ${contract.name}Abi, PublicClient, Address> => {
if (!client.chain) throw new Error("Missing chain on client");
return getContract({
address: address || addresses[client.chain.id],
abi: ${contract.name}Abi,
publicClient: client,
client: client,
});
}`);

Expand Down
6 changes: 1 addition & 5 deletions packages/accounts/plugingen/phases/plugin-generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import { GetContractGenPhase } from "./get-contract-gen.js";
import { MetaGenPhase } from "./meta-gen.js";

export const PluginGeneratorPhase: Phase = async (input) => {
const pluginPhases: Phase[] = [
MetaGenPhase,
GetContractGenPhase,
// ClientDecoratorGenPhase,
];
const pluginPhases: Phase[] = [MetaGenPhase, GetContractGenPhase];
const { contract, addImport } = input;

const result = await asyncPipe(...pluginPhases)({
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/light-account/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
LocalAccountSigner,
createPublicErc4337FromClient,
polygonMumbai,
type BatchUserOperationCallData,
type SmartAccountSigner,
} from "@alchemy/aa-core";
import { createPublicClient, custom } from "viem";
import { polygonMumbai, type Chain } from "viem/chains";
import { createPublicClient, custom, type Chain } from "viem";
import { createLightAccountClient } from "./createLightAccountClient.js";

const chain = polygonMumbai;
Expand Down
8 changes: 6 additions & 2 deletions packages/accounts/src/light-account/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
hashMessage,
hashTypedData,
trim,
type SignTypedDataParameters,
type Transport,
} from "viem";
import { LightAccountAbi } from "./abis/LightAccountAbi.js";
Expand Down Expand Up @@ -203,8 +204,11 @@ export async function createLightAccount({
async signTypedData(params) {
const version = await getLightAccountVersion(account);
switch (version) {
case "v1.0.1":
return owner.signTypedData(params);
case "v1.0.1": {
return owner.signTypedData(
params as unknown as SignTypedDataParameters
);
}
case "v1.0.2":
throw new Error(
`Version ${version} of LightAccount doesn't support 1271`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
Logger,
createPublicErc4337Client,
createSmartAccountClientFromExisting,
sepolia,
type SmartAccountSigner,
type UserOperationFeeOptions,
} from "@alchemy/aa-core";
import { isAddress, type Address, type Chain, type HDAccount } from "viem";
import { generatePrivateKey } from "viem/accounts";
import { sepolia } from "viem/chains";
import {
multiOwnerPluginActions,
type LightAccountVersion,
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts/src/light-account/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Address, Chain } from "viem";
import {
arbitrum,
arbitrumGoerli,
Expand All @@ -14,7 +13,8 @@ import {
polygon,
polygonMumbai,
sepolia,
} from "viem/chains";
} from "@alchemy/aa-core";
import type { Address, Chain } from "viem";

export type LightAccountVersion =
/** @deprecated This version does not support 1271 signature validation */
Expand Down
50 changes: 32 additions & 18 deletions packages/accounts/src/msca/plugins/multi-owner/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type Transport,
type PublicClient,
type Client,
type GetFunctionArgs,
type EncodeFunctionDataParameters,
type Chain,
type Hex,
type ReadContractReturnType,
Expand All @@ -34,9 +34,12 @@ type ExecutionActions<
| undefined
> = {
updateOwners: (
args: GetFunctionArgs<
typeof MultiOwnerPluginExecutionFunctionAbi,
"updateOwners"
args: Pick<
EncodeFunctionDataParameters<
typeof MultiOwnerPluginExecutionFunctionAbi,
"updateOwners"
>,
"args"
> & { overrides?: UserOperationOverrides } & GetAccountParameter<TAccount>
) => Promise<SendUserOperationResult>;
};
Expand Down Expand Up @@ -68,16 +71,22 @@ type ReadAndEncodeActions<
| undefined
> = {
encodeUpdateOwners: (
args: GetFunctionArgs<
typeof MultiOwnerPluginExecutionFunctionAbi,
"updateOwners"
args: Pick<
EncodeFunctionDataParameters<
typeof MultiOwnerPluginExecutionFunctionAbi,
"updateOwners"
>,
"args"
>
) => Hex;

encodeEip712Domain: (
args: GetFunctionArgs<
typeof MultiOwnerPluginExecutionFunctionAbi,
"eip712Domain"
args: Pick<
EncodeFunctionDataParameters<
typeof MultiOwnerPluginExecutionFunctionAbi,
"eip712Domain"
>,
"args"
>
) => Hex;

Expand All @@ -91,16 +100,22 @@ type ReadAndEncodeActions<
>;

encodeIsValidSignature: (
args: GetFunctionArgs<
typeof MultiOwnerPluginExecutionFunctionAbi,
"isValidSignature"
args: Pick<
EncodeFunctionDataParameters<
typeof MultiOwnerPluginExecutionFunctionAbi,
"isValidSignature"
>,
"args"
>
) => Hex;

readIsValidSignature: (
args: GetFunctionArgs<
typeof MultiOwnerPluginExecutionFunctionAbi,
"isValidSignature"
args: Pick<
EncodeFunctionDataParameters<
typeof MultiOwnerPluginExecutionFunctionAbi,
"isValidSignature"
>,
"args"
> &
GetAccountParameter<TAccount>
) => Promise<
Expand Down Expand Up @@ -135,15 +150,14 @@ export const MultiOwnerPlugin: Plugin<typeof MultiOwnerPluginAbi> = {
): GetContractReturnType<
typeof MultiOwnerPluginAbi,
PublicClient,
undefined,
Address
> => {
if (!client.chain) throw new Error("Missing chain on client");

return getContract({
address: address || addresses[client.chain.id],
abi: MultiOwnerPluginAbi,
publicClient: client,
client: client,
});
},
};
Expand Down
Loading

0 comments on commit e8a99bd

Please sign in to comment.