Skip to content

Commit

Permalink
feat: add aa-accounts subpackage (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 authored Jun 13, 2023
1 parent c4c8f31 commit a7fd5da
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
40 changes: 40 additions & 0 deletions packages/accounts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# `@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!

## 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.

via `yarn`

```bash
yarn add @alchemy/aa-accounts
```

via `npm`

```bash
npm i -s @alchemy/aa-accounts
```

## Contributing

If you are looking to add a new account type, please follow the following structure.

1. Create a new folder in `src` with the name of your account type in `kebab-case` (we're following kebab casing for files throughout the project).
2. Create a new file in the folder you just created called `account.ts` and add your implementation for `BaseSmartContractAccount`
3. If needed, create a sub-folder in your account folder called `abis` and add your abis as `.ts` files. eg:

```ts
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`.

- 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

5. Add some tests for your account and provider (if created) by creating a subfolder in your `account/my-account` called `__tests__` and make sure your files end with the `.test.ts` suffix
6. export the classes and types you've defined in `src/index.ts`
7. Open a PR and we'll review it as soon as possible!
64 changes: 64 additions & 0 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "@alchemy/aa-accounts",
"version": "0.1.0-alpha.2",
"description": "A collection of ERC-4337 compliant smart contract account interfaces",
"author": "Alchemy",
"license": "MIT",
"private": false,
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"sideEffects": false,
"files": [
"dist",
"src/**/*.ts",
"!dist/**/*.tsbuildinfo",
"!vitest.config.ts",
"!.env",
"!src/**/*.test.ts",
"!src/__tests__/**/*"
],
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"default": "./dist/cjs/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"clean": "rm -rf ./dist",
"test": "vitest",
"test:run": "vitest run"
},
"devDependencies": {
"@alchemy/aa-core": "^0.1.0-alpha.2",
"typescript": "^5.0.4",
"typescript-template": "*",
"viem": "^0.3.50",
"vitest": "^0.31.0"
},
"peerDependencies": {
"@alchemy/aa-core": "^0.1.0-alpha.1",
"viem": "^0.3.50"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/alchemyplatform/aa-sdk.git"
},
"bugs": {
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
},
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
"gitHead": "b7e4cd3253f6d93032419a9a559ea16d2a4f71d8"
}
2 changes: 2 additions & 0 deletions packages/accounts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Add you exports here, make sure to export types separately from impls and use the `type` keyword when exporting them
// Don't use wildcard exports, instead use named exports
8 changes: 8 additions & 0 deletions packages/accounts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "typescript-template/build.json",
"exclude": ["node_modules", "**/*/__tests__", "vitest.config.ts"],
"include": ["src"],
"compilerOptions": {
"sourceMap": true
}
}
3 changes: 3 additions & 0 deletions packages/accounts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "typescript-template/base.json"
}
9 changes: 9 additions & 0 deletions packages/accounts/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineProject } from "vitest/config";

export default defineProject({
test: {
globals: true,
setupFiles: ["../../.vitest/setupTests.ts"],
name: "accounts",
},
});
2 changes: 1 addition & 1 deletion packages/alchemy/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default defineProject({
test: {
globals: true,
setupFiles: ["../../.vitest/setupTests.ts"],
name: "core",
name: "aa-alchemy",
},
});

0 comments on commit a7fd5da

Please sign in to comment.