Skip to content

Commit

Permalink
Update Readme & Contributing
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Nov 4, 2023
1 parent cb433f2 commit 0fb41e5
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 51 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
RPC_URL=
PRIVATE_KEY=
ETHERSCAN_API_KEY=
INFURA_KEY=
ETHERSCAN_API_KEY=
POLYGONSCAN_API_KEY=
POLYGONSCAN_ZKEVM_API_KEY=
140 changes: 137 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,142 @@
# Contributing

- [Install](#install)
- [Pre-commit Hooks](#pre-commit-hooks)
- [Branching](#branching)
- [Versioning](#versioning)
- [Code Practices](#code-practices)
- [Testing](#testing)
- [Deployment](#deployment)
- [Deployment Info Generation](#deployment-info-generation)
- [Deployment Template Script](#deployment-template-script)
- [Releases](#releases)

## Install

To ensure consistency in our formatting we use `pre-commit` to check whether code was formatted properly and the documentation is up to date. On pull requests the CI checks whether all pre-commit hooks were run correctly.
Follow these steps to set up your local environment for development:

- [Install foundry](https://book.getfoundry.sh/getting-started/installation)
- Install dependencies: `forge install`
- [Install pre-commit](https://pre-commit.com/#post-commit)
- Install pre commit hooks: `pre-commit install`

## Pre-commit Hooks

Follow the [installation steps](#install) to enable pre-commit hooks. To ensure consistency in our formatting we use `pre-commit` to check whether code was formatted properly and the documentation is up to date. Whenever a commit does not meet the checks implemented by pre-commit, the commit will fail and the pre-commit checks will modify the files to make the commits pass. Include these changes in your commit for the next commit attempt to succeed. On pull requests the CI checks whether all pre-commit hooks were run correctly.
This repo includes the following pre-commit hooks that are defined in the `.pre-commit-config.yaml`:

- `mixed-line-ending`: This hook ensures that all files have the same line endings (LF).
- `format`: This hook uses `forge fmt` to format all Solidity files.
- `doc`: This hook uses `forge doc` to automatically generate documentation for all Solidity files whenever the NatSpec documentation changes. The `script/util/doc_gen.sh` script is used to generate documentation. Forge updates the commit hash in the documentation automatically. To only generate new documentation when the documentation has actually changed, the script checks whether more than just the hash has changed in the documentation and discard all changes if only the hash has changed.
- `prettier`: All remaining files are formatted using prettier.

## Branching

This section outlines the branching strategy of this repo.

### Main

The main branch is supposed to reflect the deployed state on all networks. Any pull requests into this branch MUST come from the staging branch. The main branch is protected and requires a separate code review by the security team. Whenever the main branch is updated, a new release is created with the latest version. For more information on versioning, check [here](#versioning).

### Staging

The staging branch reflects new code complete deployments or upgrades containing fixes and/or features. Any pull requests into this branch MUST come from the dev branch. The staging branch is used for security audits and deployments. Once the deployment is complete and deployment log files are generated, the branch can be merged into main. For more information on the deployment and log file generation check [here](#deployment--versioning).

### Dev

This is the active development branch. All pull requests into this branch MUST come from fix or feature branches. Upon code completion this branch is merged into staging for auditing and deployment.

### Feature

Any new feature should be developed on a separate branch. The naming convention for these branches is `feat/*`. Once the feature is complete, a pull request into the dev branch can be created.

### Fix

Any bug fixes should be developed on a separate branch. The naming convention for these branches is `fix/*`. Once the fix is complete, a pull request into the dev branch can be created.

## Code Practices

### Interfaces

Every contract MUST implement their corresponding interface that includes all externally callable functions, errors and events.

### NatSpec & Comments

Interfaces should be the entrypoint for all contracts. When exploring the a contract within the repository, the interface MUST contain all relevant information to understand the functionality of the contract in the form of NatSpec comments. This includes all externally callable functions, errors and events. The NatSpec documentation MUST be added to the functions, errors and events within the interface. This allows a reader to understand the functionality of a function before moving on to the implementation. The implementing functions MUST point to the NatSpec documentation in the interface using `@inheritdoc`. Internal and private functions shouldn't have NatSpec documentation except for `@dev` comments, whenever more context is needed. Additional comments within a function should only be used to give more context to more complex operations, otherwise the code should be kept readable and self-explanatory.

## Versioning

This repo utilizes [semantic versioning](https://semver.org/). An `IVersioned` interface is included in the [interfaces directory](src/interface/IVersioned.sol) exposing a unified versioning interface for all contracts. This version MUST be included in all contracts, whether they are upgradeable or not, to be able to easily match deployed versions. For example, in the case of a non-upgradeable contract one version could be deployed to a network and later a new version might be deployed to another network. The exposed `version()` function is also used by the [Deployment Info Generator](#deployment-info-generation) to extract information about the version.

Whenever contracts are modified, only the version of the changed contracts should be updated. Unmodified contracts should remain on the version of their last change.

## Testing

### Deployment Template

This repo provides a deployment script template for consistency between scripts and unit tests. For more information on how to use the template, check [here](#deployment-script-template).

## Deployment

This repo utilizes versioned deployments. Any changes to a contract should update the version of this specific contract. To deploy a new version of a contract, create a new deployment script in a directory named after the new version of the modified contracts (e.g., `1.0.0`). A script is provided that extracts deployment information from the `run-latest.json` file within the `broadcast` directory generated while the forge script runs. From this information a JSON and markdown file is generated containing various information about the deployment itself as well as past deployments.

### Deployment Template

This repo provides a deployment script template for consistency between scripts and unit tests. For more information on how to use the template, check [here](#deployment-script-template).

### Deployment

This repo set up the following RPCs in the `foundry.toml` file:

- mainnet: Ethereum Mainnet
- goerli: Ethereum Goerli
- sepolia: Ethereum Sepolia
- polygon_pos: Polygon PoS
- mumbai: Polygon Mumbai
- polygon_zkevm: Polygon zkEVM
- polygon_zkevm_testnet: Polygon zkEVM Testnet

To deploy the contracts, provide the `--broadcast` flag to the forge script command. Should the etherscan verification time out, it can be picked up again by replacing the `--broadcast` flag with `--resume`.
Deploy the contracts to one of the predefined networks by providing the according key with the `--rpc-url` flag. Most of the predefined networks require the `INFURA_KEY` environment variable to be set in the `.env` file.
Including the `--verify` flag will verify deployed contracts on Etherscan. Define the appropriate environment variable in the `.env` file.

```shell
$ forge script script/1.0.0/Deploy.s.sol --broadcast --rpc-url <rpc_url> --verify
```

### Deployment Info Generation

A JSON and Markdown file can be generated in the `deployments` directory containing various information about the deployment itself as well as past deployments using the following command. To find out more about versioning of contracts within this repo, check [here](CONTRIBUTING.md#versioning).

```shell
$ node script/util/extract.js <chainId> <version> <scriptName>
```

As the `chainId`, provide the chainId of the network the contracts were deployed to as a number. The supplied `version` should be the version of the modified contracts and the sub directory the deployment script is located in (e.g., `1.0.0`). The `scriptName` should be the file name of the script used in the deployment (e.g., `Deploy.s.sol`).

When upgrading a contract, most of the times just the new implementation is deployed and the actual upgrade is triggered by a governance process or a multisig. The script will check whether the implementation of the upgraded contract was updated to the deployed version and if not, it will fail and not generate any files.

## Deployment Template Script

This repo provides a deployment script template for consistency between scripts and unit tests.

TODO more documentation

## Releases

Releases should be created whenever the code on the main branch is updated to reflect a deployment or an upgrade on a network. The release should be named after the version of the contracts deployed or upgraded.
The release should include the following:

1. Install [pre-commit](https://pre-commit.com/#post-commit)
2. Run `pre-commit install`
- In case of a MAJOR version
- changelog
- summary of new features
- summary of breaking changes
- In case of a MINOR version
- changelog
- summary of new features
- summary of fixes
- In case of a PATCH version
- changelog
- summary of fixes
- Deployment information
- TODO
48 changes: 25 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
## Template Repo (Foundry)

This is a brief summary of the project.
What are its core features and what is its role in the bigger ecosystem
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI Status](../../actions/workflows/test.yaml/badge.svg)](../../actions)

Want to contribute to this project?
Check [CONTRIBUTING.md](CONTRIBUTING.md)
TODO: summary of the features of the template repo

#### Table of Contents

[Setup](#setup)
[Compilation](#compilation)
[Testing](#testing)
[Deployment](#deployment)
[Architecture](#architecture)
[License](#license)
- [Setup](#setup)
- [Deployment](#deployment)
- [Docs](#docs)
- [Contributing](#contributing)

## Compilation
## Setup

```shell
$ forge build
```
Follow these steps to set up your local environment:

### Testing
- [Install foundry](https://book.getfoundry.sh/getting-started/installation)
- Install dependencies: `forge install`
- Build contracts: `forge build`
- Test contracts: `forge test`

```shell
$ forge test
```
If you intend to develop on this repo, follow the steps outlined in [CONTRIBUTING.md](CONTRIBUTING.md#install).

## Deployment

This repo utilizes versioned deployments. For more information on how to use forge scripts within the repo, check [here](CONTRIBUTING.md#deployment).

Smart contracts are deployed or upgraded using the following command:

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ forge script script/1.0.0/Deploy.s.sol --broadcast --rpc-url <rpc_url> --verify
```

## Architecture
## Docs

Add explanations and graphs to help poeple understand how the contracts of this repo work together.
The documentation and architecture diagrams for the contracts within this repo can be found [here](docs/).
Detailed documentation generated from the NatSpec documentation of the contracts can be found [here](docs/autogen/src/src/).
When exploring the contracts within this repository, it is recommended to start with the interfaces first and then move on to the implementation as outlined [here](CONTRIBUTING.md#natspec--comments)

## License
## Contributing

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
If you want to contribute to this project, please check [CONTRIBUTING.md](CONTRIBUTING.md) first.

---

Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Documentation

TODO
48 changes: 25 additions & 23 deletions docs/autogen/src/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
## Template Repo (Foundry)

This is a brief summary of the project.
What are its core features and what is its role in the bigger ecosystem
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI Status](../../actions/workflows/test.yaml/badge.svg)](../../actions)

Want to contribute to this project?
Check [CONTRIBUTING.md](CONTRIBUTING.md)
TODO: summary of the features of the template repo

#### Table of Contents

[Setup](#setup)
[Compilation](#compilation)
[Testing](#testing)
[Deployment](#deployment)
[Architecture](#architecture)
[License](#license)
- [Setup](#setup)
- [Deployment](#deployment)
- [Docs](#docs)
- [Contributing](#contributing)

## Compilation
## Setup

```shell
$ forge build
```
Follow these steps to set up your local environment:

### Testing
- [Install foundry](https://book.getfoundry.sh/getting-started/installation)
- Install dependencies: `forge install`
- Build contracts: `forge build`
- Test contracts: `forge test`

```shell
$ forge test
```
If you intend to develop on this repo, follow the steps outlined in [CONTRIBUTING.md](CONTRIBUTING.md#install).

## Deployment

This repo utilizes versioned deployments. For more information on how to use forge scripts within the repo, check [here](CONTRIBUTING.md#deployment).

Smart contracts are deployed or upgraded using the following command:

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ forge script script/1.0.0/Deploy.s.sol --broadcast --rpc-url <rpc_url> --verify
```

## Architecture
## Docs

Add explanations and graphs to help poeple understand how the contracts of this repo work together.
The documentation and architecture diagrams for the contracts within this repo can be found [here](docs/).
Detailed documentation generated from the NatSpec documentation of the contracts can be found [here](docs/autogen/src/).
When exploring the contracts within this repository, it is recommended to start with the interfaces first and then move on to the implementation as outlined [here](CONTRIBUTING.md#natspec--comments)

## License
## Contributing

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
If you want to contribute to this project, please check [CONTRIBUTING.md](CONTRIBUTING.md) first.

---

Expand Down
19 changes: 19 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ max_test_rejects = 999999
line_length = 160
number_underscore = "thousands"

[rpc_endpoints]
anvil = "http://127.0.0.1:8545"
mainnet = "https://mainnet.infura.io/v3/${INFURA_KEY}"
goerli = "https://goerli.infura.io/v3/${INFURA_KEY}"
sepolia = "https://sepolia.infura.io/v3/${INFURA_KEY}"
polygon_pos = "https://polygon-mainnet.infura.io/v3/${INFURA_KEY}"
mumbai = "https://polygon-mumbai.infura.io/v3/${INFURA_KEY}"
polygon_zkevm = "https://zkevm-rpc.com"
polygon_zkevm_testnet = "https://rpc.public.zkevm-test.net"

[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY}" }
goerli = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
polygon_pos = { key = "${POLYGONSCAN_API_KEY}" }
mumbai = { key = "${POLYGONSCAN_API_KEY}" }
polygon_zkevm = { key = "${POLYGONSCAN_ZKEVM_API_KEY}" }
polygon_zkevm_testnet = { key = "${POLYGONSCAN_ZKEVM_API_KEY}" }

# See more config options https://github.com/foundry-rs/foundry/tree/master/config

0 comments on commit 0fb41e5

Please sign in to comment.