Skip to content

Commit

Permalink
[WIP] Refactor and Start implementing methods (bcnmy#17)
Browse files Browse the repository at this point in the history
* 🙈 Add cache_forge to .gitignore

* Add .husky to .gitignore

* 🎨 Update tab width to 4 spaces in .prettierrc

* 🚧 Disable no-inline-assembly rule in .solhint.json

* ⚡️ Add account-abstraction dependency and update husky hooks

* 🔥 Remove Git hooks for branch name validation

* 🔧 Update tsconfig.json to disable strict mode

* 🎨 Update Solidity version and remappings, delete unused contracts and tests

* 🙈 Add .vscode/settings.json to .gitignore

* 🔥 Delete unused contracts and tests

* ✨ Add utility functions for conversion and formatting

* ✨ Add buildUserOp function to utils.ts

* ✨ Add git hook to check branch names

* ✨ Add SmartAccount contract

* ✨ Add AccountConfig contract implementation

* ✨ Add Execution contract for account execution

* ✨ Add ModuleConfig contract for managing modules

* ✨ Add Storage contract for isolated storage access

* ✨ Add Validator contract for user operation validation

* ⚡️ Add ERC-7579 interfaces for smart account configuration, execution, module, and module configuration

* ✨ Add IStorage interface for ERC20 account storage

* 🚀 Add deployment of SmartAccount contract

* 🚧 Update import statement and variable name in Deploy script

* ⚡️ Add Entrypoint 0.7.0

* ⚡️ Add Imports.sol for consolidated imports

* ✅ Add SmartAccount test file

* 👷 Remove unnecessary branch from PR Automation Workflow

* ✏️ Update storage location for SmartAccount in contracts

* Feat/slither (bcnmy#14)

* 👷 Add Slither analysis workflow

* ♻️ Update Slither workflow to include Foundry installation***

* Add permissions and update Slither configuration

* Update Slither workflow to ensure tool availability

* Update Slither workflow

* Add Slither workflow to run static analysis

* 💚 add yarn.lock

* ✨ Update Slither workflow to include Node.js setup and SARIF report generation

* Remove SARIF file upload step in slither.yml

* Update Slither configuration in workflow

* 🚧 Update Slither workflow to include Foundry installation and contract building

* Remove target directory for analysis in slither.yml workflow

* 🚑 Update Slither workflow to include SARIF file upload

* Add token to SARIF file upload

* Add comment.js and update slither.yml workflow

* Update node version in slither.yml

* Update Slither workflow to fail on medium severity issues

* Add target directory for Slither analysis

* Update slither.yml with filter paths for mock contracts

* Update slither-args in slither.yml

* Fix slither-args path in GitHub workflow

* Update slither configuration to exclude node_modules directory

* Update slither-args in slither.yml workflow

* Update Slither version to 0.10.0

* Update slither.yml to fail on no severity issues

* Add check for pull request event in comment.js

* Update GitHub Actions workflow to trigger on pull requests (bcnmy#15)

* Update GitHub Actions workflow to trigger on pull requests

* Update Slither workflow permissions and arguments

* Refactor CI workflow and remove redundant coverage and slither workflows

* Update Node.js and Foundry versions

* Add Foundry to PATH

* Update CI workflow to install lcov and make other improvements

* Add cache for Foundry Toolchain

* Update CI workflow configuration

* Refactor GitHub Actions workflow***

* Update CI workflow to cache node_modules and Foundry toolchain

* Update CI workflow and add linting, unit tests, coverage, and static analysis

* Update cache keys and add Foundry toolchain

* Add Foundry cache key generation and ensure Foundry directory exists

* Update CI workflow and cache actions***

* Update CI workflow and dependencies

* Update CI workflow to install Foundry and generate coverage report

* Add lcov installation step and update Codecov upload for Foundry and Hardhat coverage reports

* Refactor CI workflow and add Slither analysis

* Update CI Workflow to include linting, unit tests, coverage, and slither analysis

* lint comment.js module

* prettier on branch name check and add comments

* Refactor CI workflow and update Slither analysis

* Refactor comment.js and ci.yml to improve Slither analysis report generation

* Add Module contract implementation

* Fix returnData initialization bug in Execution.sol and import IModule in Module.sol

* Refactor getEmoji function to use text instead of impact level

* Update TYPE_ID constant to uint256

* Refactor comment.js to add URL shortening and emoji processing

* Update constant declaration in Module.sol

* Refactor comment.js to improve readability and add emojis

* Refactor comment.js to improve URL shortening and emoji handling

* refactor, change acc id

* 🎨 further refactor. add module types

* ⚙️ validateUserOp implementation

* ✅ add execute via EP test

* Add remappings and solady module

* 📦 Add new dependencies and update existing ones

* 🔨 Update package.json with new check-branch-name script

* Add 'deployments' to .gitignore

* Add hardhat-deploy package

* Refactor comment.js

* Refactor buildUserOp function and add new utility functions

* Add UserOperation and PackedUserOperation interfaces

* 📦 Update dependencies in yarn.lock

* Update husky hooks in package.json

* 🔥 Remove unused contract files

* 🐛 revert remappings in remappings.txt due to issue with hh

* Remove duplicated account-abstraction dep

* Update import paths for PackedUserOperation

* Remove unused contracts and imports

* ♻️ Update AccountConfig implementation ID

* 🙈 Add .solcover.js configuration file

* 🙈 add solcover

* 🔥 remove utils

* 🔥 remove account.test.ts

* 🎨 improve code with interface

* ✨ add encoding utils function

* ✨ add helpers for operation

* 🔥 remove unused module

* 🚀 utils for deployment

* ✨ add Counter test contract

* ✅ add mockvalidator for test purpose

* 🎨 simplify Execution funcs for quick test

* ✨ add onInstall hook on moduleManager

* 🔥 remove empty useless contract

* 🚀 add basic AccountFactory

* 🎨 add interface for AccountFactory

* ✅ add deployment tests

* ✅ add configuration tests

* ✅ add module management tests

* ✅ add acc execution tests

* 🚨 lint fix

* chore: forge init

* forge install: forge-std

v1.7.6

* chore: forge init

* Delete CounterTest contract and related tests

* Remove submodule lib/forge-std

* 🔧 Update remappings in remappings.txt

* 📦 Add ds-test dependency

* 📦 Add ds-test dependency

* ✨ Add computeAccountAddress function to AccountFactory

* Add test function to ignore coverage of ModuleTypeLib.sol

* Add test function to MockValidator to ignore coverage

* Remove forge-std subproject

* Update import path for Script.sol

* ✨ Add Structs.sol with ModuleType enum

* 🚚 Update import statement in Storage.sol

* 🚚 Update module interface in AccountFactory

* Remove deprecated interfaces

* Add IStorage interface definition

* Update imports in Imports.sol

* ✨ Add Helpers.sol with utility functions

* Refactor code to improve performance and readability

* Refactor BicoTestBase and import Helpers and console2.sol

* Add Forge-std Test import and refactor newWallet function

* 🚨 Lint fix

* Delete unnecessary files

* 🔥 Remove unused function isInitialized()

* ⚡️ Refactor comment posting logic to delete existing Slither comments

* lint fix (Remove empty line in IModule.sol)

* 🐛 fix missing var on comment.js

* Add uniqueSlitherHeader to markdownComment

* Remove test workflow

* refactor

* proposed naming convention changes

* rename to supportsExecutionMode

* lint refactor

* refactor as per discussion / PR

* fix linter with unused import

* 🎨 lint

---------

Co-authored-by: aboudjem <[email protected]>
Co-authored-by: Filipp Makarov <[email protected]>
Co-authored-by: livingrockrises <[email protected]>
  • Loading branch information
4 people authored Feb 29, 2024
1 parent fa0dcf8 commit 3787306
Show file tree
Hide file tree
Showing 56 changed files with 2,228 additions and 723 deletions.
96 changes: 75 additions & 21 deletions .github/scripts/comment.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,82 @@
module.exports = async ({ github, context, header, body }) => {
const comment = [header, body].join("\n");

// Check if the workflow is triggered by a pull request event
if (!context.payload.pull_request) {
console.log('This workflow is not triggered by a pull request. Skipping comment creation/update.');
return;
}

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
const uniqueSlitherHeader = "# Slither report";

// Function to select emoji based on the impact level found in the text
const getEmoji = (text) => {
if (text.includes("High")) return ":red_circle:";
if (text.includes("Medium")) return ":yellow_circle:";
if (text.includes("Low")) return ":large_blue_circle:";
if (text.includes("Informational")) return ":information_source:";
return "";
};

// Function to shorten GitHub URLs to Markdown link format
const shortenUrls = (text) => {
const urlRegex =
/https:\/\/github\.com\/([\w-]+\/[\w-]+)\/blob\/([a-z0-9]+)\/(.+?)(#L\d+(-L\d+)?)/g;
return text.replace(urlRegex, (_, repo, commit, path, hash) => {
const shortPath = path.replace(/^contracts\/contracts\//, "");
return `[${shortPath}${hash}](https://github.com/${repo}/blob/${commit}/${path}${hash})`;
});

const botComment = comments.find(
comment => comment.user.type === 'Bot' && comment.body.startsWith(header)
};

// Process the body to add emojis and shorten URLs
const processedBody = body
.split("\n")
.map((line) => {
let processedLine = shortenUrls(line); // Apply URL shortening
const emoji = getEmoji(processedLine);
return emoji ? `${emoji} ${processedLine}` : processedLine;
})
.join("\n");

const markdownComment = `
## :robot: Slither Analysis Report :mag_right:
${uniqueSlitherHeader}
${header}
${processedBody}
_This comment was automatically generated by the GitHub Actions workflow._
`;

// Check if the workflow is triggered by a pull request event
if (!context.payload.pull_request) {
console.log(
"This workflow is not triggered by a pull request. Skipping comment creation/update.",
);

const commentFn = botComment ? 'updateComment' : 'createComment';

await github.rest.issues[commentFn]({
return;
}

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});

// Delete all Slither comments before posting a new one
for (const comment of comments.filter(comment => comment.user.type === "Bot" && comment.body.includes(uniqueSlitherHeader))) {
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
body: comment,
...(botComment ? { comment_id: botComment.id } : { issue_number: context.payload.pull_request.number }),
comment_id: comment.id,
});
}


// After deleting, post a new comment
const response = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: markdownComment,
});

console.log(
response.status === 200
? "Slither analysis comment created or updated successfully."
: "Failed to create or update the comment.",
);
};
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
slither-version: "0.10.0"
node-version: "18"
fail-on: "none"
slither-args: '--filter-paths "contracts/mock|node_modules" --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/contracts/'
slither-args: '--exclude assembly --exclude solc-version --filter-paths "contracts/mock|node_modules" --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/contracts/'

- name: Create/update checklist as PR comment
uses: actions/github-script@v7
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ out
docs
storageLayout
.husky
deployments

# files
*.env
Expand Down
3 changes: 3 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ["test", "lib/ModuleTypeLib"],
};
200 changes: 36 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,194 +1,66 @@
[![Biconomy](https://img.shields.io/badge/Made_with_%F0%9F%8D%8A_by-Biconomy-ff4e17?style=flat)](https://biconomy.io) [![License MIT](https://img.shields.io/badge/License-MIT-blue?&style=flat)](./LICENSE) [![Hardhat](https://img.shields.io/badge/Built%20with-Hardhat-FFDB1C.svg)](https://hardhat.org/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-FFBD10.svg)](https://getfoundry.sh/)
## Foundry

![Codecov Hardhat Coverage](https://img.shields.io/codecov/c/github/bcnmy/erc7579-modular-smart-account?token=oyX38XKbO9&flag=hardhat&label=Hardhat%20Coverage&logo=codecov) ![Codecov Foundry Coverage](https://img.shields.io/codecov/c/github/bcnmy/erc7579-modular-smart-account?token=oyX38XKbO9&flag=foundry&label=Foundry%20Coverage&logo=codecov)
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

# ERC-7579 Modular Smart Account Base 🚀
Foundry consists of:

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/bcnmy/erc7579-modular-smart-account)
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

This repository serves as a comprehensive foundation for smart contract projects, streamlining the development process with a focus on best practices, security, and efficiency.
## Documentation

## 📚 Table of Contents
https://book.getfoundry.sh/

- [ERC-7579 Modular Smart Account Base 🚀](#erc-7579-modular-smart-account-base-)
- [📚 Table of Contents](#-table-of-contents)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [🛠️ Essential Scripts](#️-essential-scripts)
- [🏗️ Build Contracts](#️-build-contracts)
- [🧪 Run Tests](#-run-tests)
- [⛽ Gas Report](#-gas-report)
- [📊 Coverage Report](#-coverage-report)
- [📄 Documentation](#-documentation)
- [🚀 Deploy Contracts](#-deploy-contracts)
- [🎨 Lint Code](#-lint-code)
- [🖌️ Auto-fix Linting Issues](#️-auto-fix-linting-issues)
- [🚀 Generating Storage Layout](#-generating-storage-layout)
- [🔒 Security Audits](#-security-audits)
- [🏆 Biconomy Champions League 🏆](#-biconomy-champions-league-)
- [Champions Roster](#champions-roster)
- [Entering the League](#entering-the-league)
- [Documentation and Resources](#documentation-and-resources)
- [License](#license)
- [Connect with Biconomy 🍊](#connect-with-biconomy-)
## Usage

## Getting Started
### Build

To kickstart, follow these steps:

### Prerequisites

- Node.js (v18.x or later)
- Yarn (or npm)
- Foundry (Refer to [Foundry installation instructions](https://getfoundry.sh/docs/installation))

### Installation

1. **Clone the repository:**

```bash
git clone https://github.com/bcnmy/erc7579-modular-smart-account.git
cd erc7579-modular-smart-account
```

2. **Install dependencies:**

```bash
yarn install
```

3. **Setup environment variables:**

Copy `.env.example` to `.env` and fill in your details.

## 🛠️ Essential Scripts

Execute key operations for Foundry and Hardhat with these scripts. Append `:forge` or `:hardhat` to run them in the respective environment.

### 🏗️ Build Contracts

```bash
yarn build
```shell
$ forge build
```

Compiles contracts for both Foundry and Hardhat.
### Test

### 🧪 Run Tests

```bash
yarn test
```shell
$ forge test
```

Carries out tests to verify contract functionality.

### ⛽ Gas Report
### Format

```bash
yarn test:gas
```shell
$ forge fmt
```

Creates detailed reports for test coverage.

### 📊 Coverage Report
### Gas Snapshots

```bash
yarn coverage
```shell
$ forge snapshot
```

Creates detailed reports for test coverage.
### Anvil

### 📄 Documentation

```bash
yarn docs
```shell
$ anvil
```

Generate documentation from NatSpec comments.

### 🚀 Deploy Contracts
### Deploy

```bash
yarn deploy
```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

Deploys contracts onto the blockchain network.

### 🎨 Lint Code
### Cast

```bash
yarn lint
```shell
$ cast <subcommand>
```

Checks code for style and potential errors.
### Help

### 🖌️ Auto-fix Linting Issues

```bash
yarn lint:fix
```shell
$ forge --help
$ anvil --help
$ cast --help
```

Automatically fixes linting problems found.

### 🚀 Generating Storage Layout

```bash
yarn check
```

To generate reports of the storage layout for potential upgrades safety using `hardhat-storage-layout`.

🔄 Add `:forge` or `:hardhat` to any script above to target only Foundry or Hardhat environment, respectively.

## 🔒 Security Audits

| Auditor | Date | Final Report Link |
| --------- | ---------- | ----------------------- |
| Firm Name | DD-MM-YYYY | [View Report](./audits) |
| Firm Name | DD-MM-YYYY | [View Report](./audits) |
| Firm Name | DD-MM-YYYY | [View Report](./audits) |

## 🏆 Biconomy Champions League 🏆

Welcome to the Champions League, a place where your contributions to Biconomy are celebrated and immortalized in our Hall of Fame. This elite group showcases individuals who have significantly advanced our mission, from enhancing code efficiency to strengthening security, and enriching our documentation.

### Champions Roster

| 🍊 Contributor | 🛡️ Domain |
| -------------- | ----------------- |
| @user1 | Code Optimization |
| @user2 | Security |
| @user3 | Documentation |
| ... | ... |

### Entering the League

Your journey to becoming a champion can start in any domain:

- **Code Wizards**: Dive into our [Gas Optimization](./GAS_OPTIMIZATION.md) efforts.
- **Security Guardians**: Enhance our safety following the [Security Guidelines](./SECURITY.md).
- **Documentation Scribes**: Elevate our knowledge base with your contributions.

The **Champions League** is not just a recognition, it's a testament to the impactful work done by our community. Whether you're optimizing gas usage or securing our contracts, your contributions help shape the future of Biconomy.

> **To Join**: Leave a lasting impact in your chosen area. Our Hall of Fame is regularly updated to honor our most dedicated contributors.
Let's build a legacy together, championing innovation and excellence in the blockchain space.

## Documentation and Resources

For a comprehensive understanding of our project and to contribute effectively, please refer to the following resources:

- [**Contributing Guidelines**](./CONTRIBUTING.md): Learn how to contribute to our project, from code contributions to documentation improvements.
- [**Code of Conduct**](./CODE_OF_CONDUCT.md): Our commitment to fostering an open and welcoming environment.
- [**Security Policy**](./SECURITY.md): Guidelines for reporting security vulnerabilities.
- [**Gas Optimization Program**](./GAS_OPTIMIZATION.md): Contribute towards optimizing gas efficiency of our smart contracts.
- [**Changelog**](./CHANGELOG.md): Stay updated with the changes and versions.

## License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

## Connect with Biconomy 🍊

[![Website](https://img.shields.io/badge/🍊-Website-ff4e17?style=for-the-badge&logoColor=white)](https://biconomy.io) [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/biconomy) [![Twitter](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)](https://twitter.com/biconomy) [![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/company/biconomy) [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/biconomy) [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white)](https://www.youtube.com/channel/UC0CtA-Dw9yg-ENgav_VYjRw) [![GitHub](https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/bcnmy/)
34 changes: 0 additions & 34 deletions contracts/Account/AccountConfig.sol

This file was deleted.

Loading

0 comments on commit 3787306

Please sign in to comment.