Skip to content

Commit

Permalink
feat: merge development into main for new minor release (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
avasisht23 committed Nov 14, 2023
1 parent 23c8663 commit ab098ee
Show file tree
Hide file tree
Showing 28 changed files with 346 additions and 60 deletions.
1 change: 0 additions & 1 deletion packages/accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
- entry point address as optional to SmartAccountProvider ([#180](https://github.com/alchemyplatform/aa-sdk/issues/180)) ([f5c378b](https://github.com/alchemyplatform/aa-sdk/commit/f5c378ba1cb04bdc1e41c3e6dd0eba1cb6ee7f2c))
- remove AA_SDK_TESTS_SIGNER_TYPE constant exported from aa-core ([#232](https://github.com/alchemyplatform/aa-sdk/issues/232)) ([883c489](https://github.com/alchemyplatform/aa-sdk/commit/883c489b077d587b6c5b50c44d92b2a00f10e5ac))
- use alchemy provider, light account for e2e tests ([#209](https://github.com/alchemyplatform/aa-sdk/issues/209)) ([124be68](https://github.com/alchemyplatform/aa-sdk/commit/124be68c5137a3511ec612e814265739e6909e75))

- remove AA_SDK_TESTS_SIGNER_TYPE constant exported from aa-core ([#232](https://github.com/alchemyplatform/aa-sdk/issues/232)) ([5170a6b](https://github.com/alchemyplatform/aa-sdk/commit/5170a6b689c9834a9a2489f054b767e190fa38f7))

# 0.2.0 (2023-11-03)
Expand Down
12 changes: 9 additions & 3 deletions packages/accounts/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# `@alchemy/aa-accounts`

This package contains various implementations of the [`BaseSmartContractAccount`](../core/src/account/base.ts) class defined in `aa-core`. This repo is community maintained and we welcome contributions!
This package contains various implementations of the [`BaseSmartContractAccount`](https://accountkit.alchemy.com/packages/aa-core/accounts/introduction.html#basesmartcontractaccount) class defined in `aa-core`. This repo is community maintained and we welcome contributions!

## Getting started

If you are already using the `@alchemy/aa-core` package, you can simply install this package and start using the accounts. If you are not using `@alchemy/aa-core`, you can install it and follow the instructions in the [README](../../README.md) to get started.
If you are already using the `@alchemy/aa-core` package, you can simply install this package and start using the accounts. If you are not using `@alchemy/aa-core`, you can install it and follow the instructions in the [Getting Started](https://accountkit.alchemy.com/packages/aa-accounts/) docs to get started.

via `yarn`

Expand All @@ -18,6 +18,12 @@ via `npm`
npm i -s @alchemy/aa-accounts
```

via `pnpm`

```bash
pnpm i @alchemy/aa-accounts
```

## Contributing

If you are looking to add a new account type, please follow the following structure.
Expand All @@ -30,7 +36,7 @@ If you are looking to add a new account type, please follow the following struct
export const MyContractAbi = [] as const; // the as const is important so we can get correct typing from viem
```

4. If you need to extend the [`SmartAccountProvider`](../core/src/provider/base.ts) class, add a file called `provider.ts` and add your implementation for `SmartAccountProvider`.
4. If you need to extend the [`SmartAccountProvider`](https://accountkit.alchemy.com/packages/aa-core/provider/introduction.html) class, add a file called `provider.ts` and add your implementation for `SmartAccountProvider`.

- Ideally, your `Account` impl should _just_ work with the base provider provided by `aa-core`.
- If not, consider generalizing the use case and updating SmartAccountProvider
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"@alchemy/aa-alchemy": "^1.0.0",
"@alchemy/aa-core": "^0.2.0",
"@alchemy/aa-core": "^1.0.0",
"typescript": "^5.0.4",
"typescript-template": "*",
"vitest": "^0.31.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/accounts/src/light-account/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
arbitrumSepolia,
base,
baseGoerli,
baseSepolia,
goerli,
mainnet,
optimism,
optimismGoerli,
optimismSepolia,
polygon,
polygonMumbai,
sepolia,
Expand All @@ -30,11 +32,13 @@ export const getDefaultLightAccountFactoryAddress = (chain: Chain): Address => {
case polygonMumbai.id:
case optimism.id:
case optimismGoerli.id:
case optimismSepolia.id:
case arbitrum.id:
case arbitrumGoerli.id:
case arbitrumSepolia.id:
case base.id:
case baseGoerli.id:
case baseSepolia.id:
return "0x00000055C0b4fA41dde26A74435ff03692292FBD";
}
throw new Error(
Expand Down
51 changes: 51 additions & 0 deletions packages/alchemy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# `@alchemy/aa-alchemy`

This package contains `AlchemyProvider`, an implementation of `SmartAccountProvider` class defined in `aa-core`. It also contains middleware for accessing the Alchemy Gas Manager (an [ERC-4337](https://eips.ethereum.org/EIPS/eip-4337) Paymaster) and for doing Fee Estimates according to the expectations of the Alchemy [Rundler](https://github.com/alchemyplatform/rundler/tree/main) (an ERC-4337 Bundler). You may also find the util methods helpful. This repo is community maintained and we welcome contributions!

## Getting started

If you are already using the `@alchemy/aa-core` package, you can simply install this package and start using the `AlchemyProvider`. If you are not using `@alchemy/aa-core`, you can install it and follow the instructions in the ["Getting Started"](https://accountkit.alchemy.com/packages/aa-alchemy/) docs to get started.

```bash [yarn]
yarn add @alchemy/aa-alchemy
```

```bash [npm]
npm i -s @alchemy/aa-alchemy
```

```bash [pnpm]
pnpm i @alchemy/aa-alchemy
```

## Usage

You can create `AlchemyProvider` like so:

```typescript
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core";
import { sepolia } from "viem/chains";

const chain = sepolia;
const PRIVATE_KEY = "0xYourEOAPrivateKey";
const eoaSigner: SmartAccountSigner =
LocalAccountSigner.privateKeyToAccountSigner(`0x${PRIVATE_KEY}`);

export const provider = new AlchemyProvider({
apiKey: "ALCHEMY_API_KEY", // replace with your alchemy api key of the Alchemy app associated with the Gas Manager, get yours at https://dashboard.alchemy.com/
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
chain,
owner: eoaSigner,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
```
46 changes: 44 additions & 2 deletions packages/alchemy/e2e-tests/simple-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
type SmartAccountSigner,
} from "@alchemy/aa-core";
import { Alchemy, Network } from "alchemy-sdk";
import { toHex, type Address, type Chain, type Hash } from "viem";
import {
toHex,
type Address,
type Chain,
type Hash,
type HDAccount,
} from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { sepolia } from "viem/chains";
import { AlchemyProvider } from "../src/provider.js";
Expand All @@ -15,14 +21,15 @@ const network = Network.ETH_SEPOLIA;

describe("Simple Account Tests", () => {
const ownerAccount = mnemonicToAccount(OWNER_MNEMONIC);
const owner: SmartAccountSigner = {
const owner: SmartAccountSigner<HDAccount> = {
signMessage: async (msg) =>
ownerAccount.signMessage({
message: { raw: toHex(msg) },
}),
signTypedData: async () => "0xHash",
getAddress: async () => ownerAccount.address,
signerType: "aa-sdk-tests",
inner: ownerAccount,
};

it("should successfully get counterfactual address", async () => {
Expand Down Expand Up @@ -92,6 +99,34 @@ describe("Simple Account Tests", () => {
).rejects.toThrow();
}, 50000);

it("should support overrides for buildUserOperation", async () => {
const signer = givenConnectedProvider({
owner,
chain,
}).withAlchemyGasManager({
policyId: PAYMASTER_POLICY_ID,
});

const overrides = {
maxFeePerGas: 100000000n,
maxPriorityFeePerGas: 100000000n,
paymasterAndData: "0x",
};
const uoStruct = await signer.buildUserOperation(
{
target: await signer.getAddress(),
data: "0x",
},
overrides
);

expect(uoStruct.maxFeePerGas).toEqual(overrides.maxFeePerGas);
expect(uoStruct.maxPriorityFeePerGas).toEqual(
overrides.maxPriorityFeePerGas
);
expect(uoStruct.paymasterAndData).toEqual(overrides.paymasterAndData);
}, 50000);

it("should successfully use paymaster with fee opts", async () => {
const signer = givenConnectedProvider({
owner,
Expand Down Expand Up @@ -180,6 +215,10 @@ describe("Simple Account Tests", () => {
"contractAddress": "0xdcf5d3e08c5007dececdb34808c49331bd82a247",
"tokenBalance": "0x00000000000000000000000000000000000000000000000000000000000f423f",
},
{
"contractAddress": "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
"tokenBalance": "0x0000000000000000000000000000000000000000000000000000000000000000",
},
]
`);
}, 50000);
Expand Down Expand Up @@ -223,6 +262,9 @@ const givenConnectedProvider = ({
apiKey: API_KEY!,
chain,
feeOpts,
opts: {
txMaxRetries: 10,
},
}).connect(
(provider) =>
new SimpleSmartContractAccount({
Expand Down
2 changes: 1 addition & 1 deletion packages/alchemy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"test:run-e2e": "vitest run --config vitest.config.e2e.ts"
},
"devDependencies": {
"@alchemy/aa-core": "^0.2.0",
"@alchemy/aa-core": "^1.0.0",
"typescript": "^5.0.4",
"typescript-template": "*",
"vitest": "^0.31.0"
Expand Down
6 changes: 5 additions & 1 deletion packages/alchemy/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import type { Chain } from "viem";
import {
arbitrum,
arbitrumGoerli,
arbitrumSepolia,
goerli,
mainnet,
optimism,
optimismGoerli,
optimismSepolia,
polygon,
polygonMumbai,
sepolia,
base,
baseGoerli,
arbitrumSepolia,
baseSepolia,
} from "viem/chains";

export const SupportedChains = new Map<number, Chain>([
Expand All @@ -25,6 +27,8 @@ export const SupportedChains = new Map<number, Chain>([
[arbitrum.id, arbitrum],
[optimism.id, optimism],
[optimismGoerli.id, optimismGoerli],
[optimismSepolia.id, optimismSepolia],
[base.id, base],
[baseGoerli.id, baseGoerli],
[baseSepolia.id, baseSepolia],
]);
57 changes: 57 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# `@alchemy/aa-core`

This package contains the core interfaces and components for interacting with 4337 infrastructure. The primary interfaces that it exports are the `SmartAccountProvider` and `BaseSmartContractAccount`.

The `SmartAccountProvider` is an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compliant Provider that wraps JSON RPC methods and some Wallet Methods (signing, sendTransaction, etc). With this Provider, you can submit User Operations to RPC providers, estimate gas, configure a Paymaster, send standard JSON RPC requests, and more. It is not opinionated about which RPC provider you are using and is configurable to work with any RPC provider. Because it implements EIP-1193, it can be used with any web3 library.

The `BaseSmartContractAccount` interface defines how you would interact with your Smart Contract Account. Any class that extends `BaseSmartContractAccount` may also expose additional methods that allow its connecting `SmartAccountProvider` to provide ergonic utilities for building and submitting `User Operation`s.

## Getting Started

To get started, first install the package:

```bash [yarn]
yarn add @alchemy/aa-core
```

```bash [npm]
npm i -s @alchemy/aa-core
```

```bash [pnpm]
pnpm i @alchemy/aa-core
```

## Usage

You can create a provider like so:

```typescript
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import {
LocalAccountSigner,
SmartAccountProvider,
SmartAccountSigner,
} from "@alchemy/aa-core";
import { polygonMumbai } from "viem/chains";

const chain = polygonMumbai;
const owner: SmartAccountSigner =
LocalAccountSigner.mnemonicToAccountSigner(YOUR_OWNER_MNEMONIC);

export const provider = new SmartAccountProvider({
rpcProvider: "https://polygon-mumbai.g.alchemy.com/v2/demo",
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
chain,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
owner,
})
);
```
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export type { BaseSmartAccountParams } from "./account/types.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export type {
SmartAccountSigner,
SmartAccountAuthenticator,
SmartAccountSigner,
} from "./signer/types.js";
export {
verifyEIP6492Signature,
Expand Down

0 comments on commit ab098ee

Please sign in to comment.