Skip to content

Commit

Permalink
docs: refactor the actions section of aa-core docs
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Jan 31, 2024
1 parent 806d207 commit 408b5a4
Show file tree
Hide file tree
Showing 68 changed files with 275 additions and 263 deletions.
1 change: 1 addition & 0 deletions packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export type * from "./light-account/account.js";
export { createLightAccount } from "./light-account/account.js";
export { transferOwnership as transferLightAccountOwnership } from "./light-account/actions/transferOwnership.js";
export { createLightAccountClient } from "./light-account/createLightAccountClient.js";
export { getLightAccountVersion } from "./light-account/getLightAccountVersion.js";
export type * from "./light-account/lightAccountClientDecorator.js";
export { lightAccountClientActions } from "./light-account/lightAccountClientDecorator.js";
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/client/bundlerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ export const createBundlerClientFromExisting: <
* @returns
*/
export function createBundlerClient<TTransport extends Transport>(
args: PublicClientConfig<TTransport, Chain>
args: PublicClientConfig<TTransport, Chain> & { type?: string }
): BundlerClient<TTransport>;

export function createBundlerClient(args: PublicClientConfig): BundlerClient {
export function createBundlerClient(
args: PublicClientConfig & { type?: string }
): BundlerClient {
if (!args.chain) {
throw new Error("Chain must be provided");
}
const { key = "bundler-public", name = "Public Bundler Client" } = args;
const {
key = "bundler-public",
name = "Public Bundler Client",
type = "bundlerClient",
} = args;

const { transport, ...opts } = args;
const resolvedTransport = transport({
Expand All @@ -61,7 +67,7 @@ export function createBundlerClient(args: PublicClientConfig): BundlerClient {
...args,
key,
name,
type: "bundlerClient",
type,
};

const client = (() => {
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/client/smartAccountClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
createClient,
custom,
publicActions,
type Chain,
type Client,
type ClientConfig,
Expand All @@ -16,9 +14,8 @@ import type { SmartContractAccount } from "../account/smartContractAccount.js";
import { middlewareActions } from "../middleware/actions.js";
import type { ClientMiddleware } from "../middleware/types.js";
import type { Prettify } from "../utils/index.js";
import type { BundlerClient } from "./bundlerClient.js";
import { createBundlerClient, type BundlerClient } from "./bundlerClient.js";
import {
bundlerActions,
type BundlerActions,
type BundlerRpcSchema,
} from "./decorators/bundlerClient.js";
Expand Down Expand Up @@ -111,7 +108,7 @@ export function createSmartAccountClient(
...params
} = config;

const client = createClient({
const client = createBundlerClient({
...params,
key,
name,
Expand All @@ -125,8 +122,6 @@ export function createSmartAccountClient(
.extend(() => ({
...SmartAccountClientOptsSchema.parse(config.opts ?? {}),
}))
.extend(publicActions)
.extend(bundlerActions)
.extend(middlewareActions(config))
.extend(smartAccountClientActions);
}
Expand Down
10 changes: 5 additions & 5 deletions site/overview/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ If the `UserOperation` (meta-transaction for 4337 accounts) is correctly priced
::: details Answer
This can happen when `UserOperation`s (UOs) become underpriced, frequently due to fee market movement between when gas and fees are estimations and when the UO is actually submitted.

You may experience this when calling the [`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/waitForUserOperationTransaction.html#waitForUserOperationTransaction) method. It may throw an error if it does not find the UO in a mined Transaction within its retry limits.
You may experience this when calling the [`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/actions/waitForUserOperationTransaction.html#waitForUserOperationTransaction) method. It may throw an error if it does not find the UO in a mined Transaction within its retry limits.

You can mitigate this by defining a more flexible retry period when constructing a [`Provider`](/packages/aa-core/smart-account-client/createSmartAccountClient.html#constructor) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). If your UO continues to be delayed beyond a limit you are willing to wait, you can resubmit it using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/dropAndReplaceUserOperation.html#dropandreplaceuseroperation).
You can mitigate this by defining a more flexible retry period when constructing a [`Client`](/packages/aa-core/smart-account-client/index.html#usage) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`). If your UO continues to be delayed beyond a limit you are willing to wait, you can resubmit it using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/actions/dropAndReplaceUserOperation.html#dropandreplaceuseroperation).
:::

### Are `UserOperation`s protected from MEV bots?
Expand Down Expand Up @@ -156,9 +156,9 @@ Currently our Bundler allows max 10M gas in aggregate between `preVerificationGa
### `waitForUserOperationTransaction` timeout

::: details Answer
[`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/waitForUserOperationTransaction) may throw this error if it does not find the mined User Operation within its retry limits.
[`waitForUserOperationTransaction`](/packages/aa-core/smart-account-client/actions/waitForUserOperationTransaction) may throw this error if it does not find the mined User Operation within its retry limits.

You can mitigate this by defining a more flexible retry period when constructing a [`Client`](/packages/aa-core/smart-account-client/createSmartAccountClient.html#usage) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`).
You can mitigate this by defining a more flexible retry period when constructing a [`Client`](/packages/aa-core/smart-account-client/index.html#usage) (i.e. `txMaxRetries`, `txRetryIntervalMs`, `txRetryMultiplier` in `opts`).

If your `UserOperation` continues to be delayed beyond a limit you are willing to wait, you can resubmit the user operation using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/dropAndReplaceUserOperation.html#dropandreplaceuseroperation).
If your `UserOperation` continues to be delayed beyond a limit you are willing to wait, you can resubmit the user operation using [`dropAndReplaceUserOperation`](/packages/aa-core/smart-account-client/actions/dropAndReplaceUserOperation.html#usage).
:::
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const encodedTransferOwnershipData =
LightSmartContractAccount.encodeTransferOwnership(newOwner);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-accounts/light-account/getOwnerAddress.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { provider } from "./provider";
const owner = await provider.account.getOwnerAddress();
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-accounts/light-account/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const result = await LightSmartContractAccount.transferOwnership(
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Developer Links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { provider } from "./provider";
const signedMessageWith6492 = provider.signMessageWith6492("test");
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-accounts/light-account/signTypedData.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const signedTypedData = provider.signTypedData({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const signedTypedDataWith6492 = provider.signTypedDataWith6492({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const result = await LightSmartContractAccount.transferOwnership(
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-alchemy/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ pnpm i @alchemy/aa-alchemy
Then, you can create a provider like so:
::: code-group

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::
2 changes: 1 addition & 1 deletion site/packages/aa-alchemy/middleware/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ const providerWithGasManager = withAlchemyGasManager(
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const providerWithGasFeeEstimator = withAlchemyGasFeeEstimator(
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const providerWithGasManager = withAlchemyGasManager(
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { withAlchemyUserOpSimulation } from "@alchemy/aa-alchemy";
const providerWithUserOpSimulation = withAlchemyUserOpSimulation(provider);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
4 changes: 2 additions & 2 deletions site/packages/aa-alchemy/provider/gasEstimator.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const uoStruct = await provider.buildUserOperation({
const uoHash = await provider.sendUserOperation(uoStruct);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand All @@ -45,4 +45,4 @@ the resulting user operation struct after gas estimation, run as part of a middl

### `struct: Deferrable<UserOperationStruct>` -- the struct containing UserOperation fields, where each field may be asychronously returned from the middleware used to generate its final value.

Note: You typically will call this method as part of a middleware chain when building and sending UserOperations, so the parameters of `UserOperationStruct` should be generated for you, as long as you pass in the initial parameters needed for [sendUserOperation](/packages/aa-core/smart-account-client/sendUserOperation).
Note: You typically will call this method as part of a middleware chain when building and sending UserOperations, so the parameters of `UserOperationStruct` should be generated for you, as long as you pass in the initial parameters needed for [sendUserOperation](/packages/aa-core/smart-account-client/actions/sendUserOperation).
5 changes: 2 additions & 3 deletions site/packages/aa-alchemy/provider/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ head:

# AlchemyProvider

`AlchemyProvider` is an extension of the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/introduction) implementation. It's a simpler interface you can use to leverage the Alchemy stack - JSON-RPC requests via API Key or JSON Web Token (JWT), Rundler (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Bundler), and Gas Manager (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Paymaster).
`AlchemyProvider` is an extension of the [`SmartAccountProvider`](/packages/aa-core/smart-account-client/index) implementation. It's a simpler interface you can use to leverage the Alchemy stack - JSON-RPC requests via API Key or JSON Web Token (JWT), Rundler (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Bundler), and Gas Manager (an [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) Paymaster).

Notable differences between `AlchemyProvider` and `SmartAccountProvider` are implementations for:

1. [`gasEstimator`](/packages/aa-core/smart-account-client/withGasEstimator.md) -- overrides the base `SmartAccountProvider` gas estimator.
2. [`withAlchemyGasManager`](/packages/aa-alchemy/provider/withAlchemyGasManager.md) -- adds the Alchemy Gas Manager middleware to the provider.

## Usage
Expand All @@ -42,5 +41,5 @@ const providerWithGasManager = provider.withAlchemyGasManager({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (uoSimResult.error) {
const uo = await provider.sendUserOperation(uoStruct);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const alchemy = new Alchemy();
const providerWithEnhancedApis = provider.withAlchemyEnhancedApis(alchemy);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-alchemy/provider/withAlchemyGasManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const providerWithGasManager = provider.withAlchemyGasManager({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { provider } from "./provider";
const providerWithGasManager = provider.withAlchemyUserOpSimulation();
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts
:::

## Returns
Expand Down
2 changes: 1 addition & 1 deletion site/packages/aa-core/accounts/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ prev:

## BaseSmartContractAccount

The `BaseSmartContractAccount` is an abstract class that provides the base implementation the `ISmartContractAccount` interface to provide the ease of creating your own Smart Contract Account. Any class that extends and implements `BaseSmartContractAccount` may also expose additional methods that support its connecting [SmartAccountProvider](/packages/aa-core/smart-account-client/introduction).
The `BaseSmartContractAccount` is an abstract class that provides the base implementation the `ISmartContractAccount` interface to provide the ease of creating your own Smart Contract Account. Any class that extends and implements `BaseSmartContractAccount` may also expose additional methods that support its connecting [SmartAccountProvider](/packages/aa-core/smart-account-client/index).

`BaseSmartContractAccount` contains abstract methods that requires implementation from any class that extends the class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ This method wraps the result of `signMessage` as per [EIP-6492](https://eips.eth
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
const signedMsgWrappedWith6492 = await provider.signMessageWith6492("msg");
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
4 changes: 2 additions & 2 deletions site/packages/aa-core/accounts/optional/signTypedData.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If your contract supports signing and verifying typed data, you should implement
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
// sign typed data
const signedTypedData = provider.signTypedData({
Expand Down Expand Up @@ -57,7 +57,7 @@ const signedTypedData = provider.signTypedData({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Similar to the signMessageWith6492 method above, this method wraps the result of
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
const signedTypedDataWrappedWith6492 = provider.signTypedDataWith6492({
domain: {
Expand Down Expand Up @@ -58,7 +58,7 @@ const signedTypedDataWrappedWith6492 = provider.signTypedDataWith6492({
});
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ If your account handles [ERC-1271 signatures](https://eips.ethereum.org/EIPS/eip
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
const signature = await provider.account.signUserOperationHash(
`<SOME_UO_HASH>`
);
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
4 changes: 2 additions & 2 deletions site/packages/aa-core/accounts/other/getAddress.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Returns the address of the account.
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
const address = await provider.account.getAddress();
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
4 changes: 2 additions & 2 deletions site/packages/aa-core/accounts/other/getDeploymentState.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Returns the current deployment state as an enum `DeploymentState` (`UNDEFINED`,
::: code-group

```ts [example.ts]
import { provider } from "./provider";
import { smartAccountClient } from "./smartAccountClient";
// [!code focus:99]
const deploymentState = await provider.account.getDeploymentState();
```

<<< @/snippets/provider.ts
<<< @/snippets/smartAccountClient.ts

:::

Expand Down
Loading

0 comments on commit 408b5a4

Please sign in to comment.