From 78da14c9801aa076e42e190025bb11713eab2b54 Mon Sep 17 00:00:00 2001 From: moldy Date: Tue, 13 Jun 2023 12:06:31 -0400 Subject: [PATCH] feat: add aa-accounts subpackage --- packages/accounts/README.md | 40 +++++++++++++++++ packages/accounts/package.json | 64 +++++++++++++++++++++++++++ packages/accounts/src/index.ts | 2 + packages/accounts/tsconfig.build.json | 8 ++++ packages/accounts/tsconfig.json | 3 ++ packages/accounts/vitest.config.ts | 9 ++++ packages/alchemy/vitest.config.ts | 2 +- 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 packages/accounts/README.md create mode 100644 packages/accounts/package.json create mode 100644 packages/accounts/src/index.ts create mode 100644 packages/accounts/tsconfig.build.json create mode 100644 packages/accounts/tsconfig.json create mode 100644 packages/accounts/vitest.config.ts diff --git a/packages/accounts/README.md b/packages/accounts/README.md new file mode 100644 index 0000000000..daa130effe --- /dev/null +++ b/packages/accounts/README.md @@ -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! diff --git a/packages/accounts/package.json b/packages/accounts/package.json new file mode 100644 index 0000000000..eee821156c --- /dev/null +++ b/packages/accounts/package.json @@ -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" +} diff --git a/packages/accounts/src/index.ts b/packages/accounts/src/index.ts new file mode 100644 index 0000000000..6df77d9150 --- /dev/null +++ b/packages/accounts/src/index.ts @@ -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 diff --git a/packages/accounts/tsconfig.build.json b/packages/accounts/tsconfig.build.json new file mode 100644 index 0000000000..345f8f3fab --- /dev/null +++ b/packages/accounts/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "typescript-template/build.json", + "exclude": ["node_modules", "**/*/__tests__", "vitest.config.ts"], + "include": ["src"], + "compilerOptions": { + "sourceMap": true + } +} diff --git a/packages/accounts/tsconfig.json b/packages/accounts/tsconfig.json new file mode 100644 index 0000000000..748018d6a6 --- /dev/null +++ b/packages/accounts/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "typescript-template/base.json" +} diff --git a/packages/accounts/vitest.config.ts b/packages/accounts/vitest.config.ts new file mode 100644 index 0000000000..23a5d67ee2 --- /dev/null +++ b/packages/accounts/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineProject } from "vitest/config"; + +export default defineProject({ + test: { + globals: true, + setupFiles: ["../../.vitest/setupTests.ts"], + name: "accounts", + }, +}); diff --git a/packages/alchemy/vitest.config.ts b/packages/alchemy/vitest.config.ts index 0d61b56b29..073e809d6e 100644 --- a/packages/alchemy/vitest.config.ts +++ b/packages/alchemy/vitest.config.ts @@ -4,6 +4,6 @@ export default defineProject({ test: { globals: true, setupFiles: ["../../.vitest/setupTests.ts"], - name: "core", + name: "aa-alchemy", }, });