Skip to content

Commit

Permalink
Merge branch 'alchemyplatform:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored Feb 1, 2024
2 parents 86c511b + b34a470 commit 6a87de9
Show file tree
Hide file tree
Showing 35 changed files with 265 additions and 379 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ There are currently 5 SDKs that are part of the `aa-sdk` suite:

The core SDK also implements an EIP-1193 provider interface to easily plug into any popular dapp or wallet connect libraries such as RainbowKit, Wagmi, and Web3Modal. It also includes [`ethers.js`](https://docs.ethers.org/v5/) adapters to provide full support for `ethers.js`` apps.

The `aa-sdk` is modular at every layer of the stack and can be easily extended to fit your custom needs. You can plug in any [smart account](https://accountkit.alchemy.com/smart-accounts/accounts/using-your-own) implementation, [Signer](https://accountkit.alchemy.com/smart-accounts/signers/overview), [Gas Manager API](https://accountkit.alchemy.com/overview/introduction.html#gas-manager-api) and RPC Provider.
The `aa-sdk` is modular at every layer of the stack and can be easily extended to fit your custom needs. You can plug in any [smart account](https://accountkit.alchemy.com/smart-accounts/accounts/using-your-own) implementation, [Signer](https://accountkit.alchemy.com/signers/overview), [Gas Manager API](https://accountkit.alchemy.com/overview/introduction.html#gas-manager-api) and RPC Provider.

## Getting Started

Expand Down
1 change: 0 additions & 1 deletion packages/alchemy/src/client/smartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type AlchemySmartAccountClientConfig<
> = {
account?: account;
useSimulation?: boolean;
// TODO: this is missing the current gas manager fallback stuff
gasManagerConfig?: AlchemyGasManagerConfig;
} & AlchemyProviderConfig &
Pick<
Expand Down
60 changes: 30 additions & 30 deletions packages/alchemy/src/middleware/gasManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { ClientMiddleware, ClientMiddlewareFn } from "@alchemy/aa-core";
import type {
ClientMiddlewareConfig,
ClientMiddlewareFn,
} from "@alchemy/aa-core";
import {
deepHexlify,
defaultGasEstimator,
Expand Down Expand Up @@ -34,12 +37,26 @@ export interface AlchemyGasEstimationOptions {
fallbackFeeDataGetter?: ClientMiddlewareFn;
}

const dummyPaymasterAndData =
<C extends ClientWithAlchemyMethods>(client: C) =>
() => {
switch (client.chain.id) {
case 1:
case 10:
case 137:
case 42161:
return "0x4Fd9098af9ddcB41DA48A1d78F91F1398965addcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
default:
return "0xc03aac639bb21233e0139381970328db8bceeb67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
}
};

export const alchemyGasManagerMiddleware = <C extends ClientWithAlchemyMethods>(
client: C,
config: AlchemyGasManagerConfig
): Pick<
ClientMiddleware,
"dummyPaymasterAndData" | "paymasterAndData" | "feeEstimator" | "gasEstimator"
ClientMiddlewareConfig,
"paymasterAndData" | "feeEstimator" | "gasEstimator"
> => {
const gasEstimationOptions = config.gasEstimationOptions;
const disableGasEstimation =
Expand Down Expand Up @@ -103,25 +120,6 @@ export const alchemyGasManagerMiddleware = <C extends ClientWithAlchemyMethods>(
maxPriorityFeePerGas,
};
},
dummyPaymasterAndData: async (struct) => {
switch (client.chain.id) {
case 1:
case 10:
case 137:
case 42161:
return {
...struct,
paymasterAndData:
"0x4Fd9098af9ddcB41DA48A1d78F91F1398965addcfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
};
default:
return {
...struct,
paymasterAndData:
"0xc03aac639bb21233e0139381970328db8bceeb67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
};
}
},
paymasterAndData: disableGasEstimation
? requestPaymasterAndData(client, config)
: requestGasAndPaymasterData(client, config),
Expand All @@ -131,9 +129,9 @@ export const alchemyGasManagerMiddleware = <C extends ClientWithAlchemyMethods>(
const requestGasAndPaymasterData: <C extends ClientWithAlchemyMethods>(
client: C,
config: AlchemyGasManagerConfig
) => ClientMiddlewareFn =
(client, config) =>
async (struct, { overrides, feeOptions, account }) => {
) => ClientMiddlewareConfig["paymasterAndData"] = (client, config) => ({
dummyPaymasterAndData: dummyPaymasterAndData(client),
paymasterAndData: async (struct, { overrides, feeOptions, account }) => {
const userOperation: UserOperationRequest = deepHexlify(
await resolveProperties(struct)
);
Expand Down Expand Up @@ -196,14 +194,15 @@ const requestGasAndPaymasterData: <C extends ClientWithAlchemyMethods>(
...struct,
...result,
};
};
},
});

const requestPaymasterAndData: <C extends ClientWithAlchemyMethods>(
client: C,
config: AlchemyGasManagerConfig
) => ClientMiddlewareFn =
(client, config) =>
async (struct, { account }) => {
) => ClientMiddlewareConfig["paymasterAndData"] = (client, config) => ({
dummyPaymasterAndData: dummyPaymasterAndData(client),
paymasterAndData: async (struct, { account }) => {
const { paymasterAndData } = await client.request({
method: "alchemy_requestPaymasterAndData",
params: [
Expand All @@ -219,4 +218,5 @@ const requestPaymasterAndData: <C extends ClientWithAlchemyMethods>(
...struct,
paymasterAndData,
};
};
},
});
3 changes: 2 additions & 1 deletion packages/core/src/client/smartAccountClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
type BaseSmartAccountClientActions,
} from "./decorators/smartAccountClient.js";
import { SmartAccountClientOptsSchema } from "./schema.js";
import type { ClientMiddlewareConfig } from "./types.js";

type SmartAccountClientOpts = z.output<typeof SmartAccountClientOptsSchema>;

Expand All @@ -40,7 +41,7 @@ export type SmartAccountClientConfig<
> & {
account?: account;
opts?: z.input<typeof SmartAccountClientOptsSchema>;
} & Partial<ClientMiddleware>
} & ClientMiddlewareConfig
>;

export type SmartAccountClientRpcSchema = [
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { Address } from "abitype";
import type { Hash, Hex } from "viem";
import type { z } from "zod";
import type {
ClientMiddleware,
ClientMiddlewareFn,
} from "../middleware/types.js";
import type { UserOperationRequest } from "../types.js";
import type { ConnectionConfigSchema } from "./schema.js";

Expand All @@ -19,3 +23,13 @@ export type UpgradeToData = {
implAddress: Address;
initializationData: Hex;
};

export type ClientMiddlewareConfig = Omit<
Partial<ClientMiddleware>,
"dummyPaymasterAndData" | "paymasterAndData"
> & {
paymasterAndData?: {
dummyPaymasterAndData: () => Hex;
paymasterAndData: ClientMiddlewareFn;
};
};
15 changes: 11 additions & 4 deletions packages/core/src/middleware/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
BundlerActions,
BundlerRpcSchema,
} from "../client/decorators/bundlerClient.js";
import type { ClientMiddlewareConfig } from "../client/types.js";
import { defaultFeeEstimator } from "./defaults/feeEstimator.js";
import { defaultGasEstimator } from "./defaults/gasEstimator.js";
import { defaultPaymasterAndData } from "./defaults/paymasterAndData.js";
Expand All @@ -31,7 +32,7 @@ export type MiddlewareClient<
>;

export const middlewareActions =
(overrides: Partial<ClientMiddleware>) =>
(overrides: ClientMiddlewareConfig) =>
<
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined,
Expand All @@ -43,11 +44,17 @@ export const middlewareActions =
): { middleware: ClientMiddleware } => ({
middleware: {
customMiddleware: overrides.customMiddleware ?? noopMiddleware,
dummyPaymasterAndData:
overrides.dummyPaymasterAndData ?? defaultPaymasterAndData,
dummyPaymasterAndData: overrides.paymasterAndData?.dummyPaymasterAndData
? async (struct) => ({
...struct,
paymasterAndData:
overrides.paymasterAndData!.dummyPaymasterAndData(),
})
: defaultPaymasterAndData,
feeEstimator: overrides.feeEstimator ?? defaultFeeEstimator(client),
gasEstimator: overrides.gasEstimator ?? defaultGasEstimator(client),
paymasterAndData: overrides.paymasterAndData ?? defaultPaymasterAndData,
paymasterAndData:
overrides.paymasterAndData?.paymasterAndData ?? defaultPaymasterAndData,
userOperationSimulator:
overrides.userOperationSimulator ?? noopMiddleware,
},
Expand Down
9 changes: 5 additions & 4 deletions site/.vitepress/sidebar/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export const newSidebar: DefaultTheme.Sidebar = [
},
{
text: "Choosing a Signer",
base: "/smart-accounts/signers",
base: "/signers",
items: [
{ text: "Introduction", link: "/choosing-a-signer" },
{
text: "Signer Guides",
base: "/smart-accounts/signers/guides",
base: "/signers/guides",
collapsed: true,
items: [
{ text: "Magic", link: "/magic" },
Expand Down Expand Up @@ -146,9 +146,10 @@ export const newSidebar: DefaultTheme.Sidebar = [
},
{
text: "Third Party Integrations",
base: "/third-party",
items: [
{ text: "Bundlers", link: "/" },
{ text: "Paymasters", link: "/" },
{ text: "Bundlers", link: "/bundlers" },
{ text: "Paymasters", link: "/paymasters" },
],
},
packagesSidebar,
Expand Down
143 changes: 0 additions & 143 deletions site/.vitepress/sidebar/old.ts

This file was deleted.

2 changes: 1 addition & 1 deletion site/getting-started/deploy-an-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The `LightAccount` implementation is not [ERC-6900](/smart-accounts/modular-acco

## 3. Choosing a Signer

A Signer is the entity that signs transactions (User Operations) on behalf of the smart account. It can be an EOA, a custodial service, or a multi-party computation (MPC) service. We explain the different types of signers in detail in the [overview](/smart-accounts/signers/choosing-a-signer) section on choosing a Signer and offer integration guides in these docs, many of which use our `aa-signers` SDK.
A Signer is the entity that signs transactions (User Operations) on behalf of the smart account. It can be an EOA, a custodial service, or a multi-party computation (MPC) service. We explain the different types of signers in detail in the [overview](/signers/choosing-a-signer) section on choosing a Signer and offer integration guides in these docs, many of which use our `aa-signers` SDK.

At this point you should be able to integrate smart accounts in your application. However, there are a few advanced features that can help you improve the user experience and save on gas costs. Information about these can be found in the `Guides` section.

Expand Down
2 changes: 1 addition & 1 deletion site/getting-started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ In this guide, we initialized an `AlchemyProvider` with the `aa-alchemy` package

2. To learn about the end-to-end process of integrating smart accounts in your applications, check out the section on [Smart Accounts](/smart-accounts/).

3. To learn about the `owner` field on your smart account, check out the section on [Choosing a Signer](/smart-accounts/signers/choosing-a-signer) to own the smart account.
3. To learn about the `owner` field on your smart account, check out the section on [Choosing a Signer](/signers/choosing-a-signer) to own the smart account.

4. To learn more about different User Operations you can send with different `target` and `data` fields in the `sendUserOperation` function above, look at our [How to Send a User Operation](/using-smart-accounts/send-user-operations) guide for an example using NFT mints.

Expand Down
2 changes: 1 addition & 1 deletion site/glossary/terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ head:

## Account Kit

Account Kit is a framework designed to embed smart accounts in web3 applications. It includes a set of tools such as [Signer integrations](https://accountkit.alchemy.com/smart-accounts/signers/choosing-a-signer.html), [Gas Manager](https://docs.alchemy.com/docs/gas-manager-services) and [Bundler](https://docs.alchemy.com/docs/bundler-services) utilities that unlock features such as [gas sponsorship](https://accountkit.alchemy.com/using-smart-accounts/sponsoring-gas/gas-manager.html), [batched transactions](https://accountkit.alchemy.com/using-smart-accounts/batch-user-operations.html) and email/social login. With its user-friendly suite of SDKs, known as [aa-sdk](https://github.com/alchemyplatform/aa-sdk), Account Kit makes it easy to deploy smart accounts, manage `UserOperation`s, and handle gas sponsorship, streamlining the entire process with minimal coding effort.
Account Kit is a framework designed to embed smart accounts in web3 applications. It includes a set of tools such as [Signer integrations](https://accountkit.alchemy.com/signers/choosing-a-signer.html), [Gas Manager](https://docs.alchemy.com/docs/gas-manager-services) and [Bundler](https://docs.alchemy.com/docs/bundler-services) utilities that unlock features such as [gas sponsorship](https://accountkit.alchemy.com/using-smart-accounts/sponsoring-gas/gas-manager.html), [batched transactions](https://accountkit.alchemy.com/using-smart-accounts/batch-user-operations.html) and email/social login. With its user-friendly suite of SDKs, known as [aa-sdk](https://github.com/alchemyplatform/aa-sdk), Account Kit makes it easy to deploy smart accounts, manage `UserOperation`s, and handle gas sponsorship, streamlining the entire process with minimal coding effort.

## Bundler

Expand Down
Loading

0 comments on commit 6a87de9

Please sign in to comment.