Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow test #3

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9127bf4
chore: forge init
gretzke Oct 23, 2023
31acb27
forge install: forge-std
gretzke Oct 23, 2023
c7d88c5
Update foundry.toml
gretzke Oct 23, 2023
db65789
forge install: openzeppelin-contracts
gretzke Oct 24, 2023
af3db4f
forge install: openzeppelin-contracts-upgradeable
gretzke Oct 24, 2023
fa788fd
Add remappings
gretzke Oct 24, 2023
b2445eb
Create CODEOWNERS
gretzke Oct 24, 2023
1141ec9
Update .gitignore
gretzke Oct 24, 2023
c936b83
Create .nvmrc
gretzke Oct 24, 2023
8d9e347
Create .prettierrc
gretzke Oct 24, 2023
b3fb07b
Create .prettierignore
gretzke Oct 24, 2023
b4d6c1c
Create .env.example
gretzke Oct 24, 2023
7d9fd43
Create SECURITY.md
gretzke Oct 24, 2023
80c8e79
Create slither.config.json
gretzke Oct 24, 2023
4a32396
Add MIT License
gretzke Oct 24, 2023
9aa8163
Implement best practices
gretzke Oct 24, 2023
8733bac
Add deployment scripts
gretzke Oct 24, 2023
97cb875
add pre commit hooks for documentation and formatting
gretzke Nov 3, 2023
b77f93b
Run tests on PRs, only trigger docs when content changed
gretzke Nov 3, 2023
cdf98d8
rename directory for autogenerated docs
gretzke Nov 3, 2023
0cb7b9a
readme draft
simonDos Nov 3, 2023
f7d1865
create PR template
simonDos Nov 3, 2023
9427497
chore: update foundry.toml
ZeroEkkusu Nov 3, 2023
feee8bf
feat: change Counter
ZeroEkkusu Nov 3, 2023
60aa7f7
script: add deployer generator
ZeroEkkusu Nov 3, 2023
2679d55
script: add Deploy script
ZeroEkkusu Nov 3, 2023
a9f2dec
test: add basic tests
ZeroEkkusu Nov 3, 2023
06cb743
Run pre-commit
gretzke Nov 3, 2023
04498da
script: add ScriptHelpers
ZeroEkkusu Nov 3, 2023
6309130
chore: remove Counter script
ZeroEkkusu Nov 3, 2023
204ad2b
test: add complete tests
ZeroEkkusu Nov 3, 2023
1982945
feat: use solc 0.8.22
ZeroEkkusu Nov 3, 2023
68d1a29
Add formatter options, run pre-compile
gretzke Nov 4, 2023
cb433f2
small fixes
gretzke Nov 4, 2023
284d7cf
Update Readme & Contributing
gretzke Nov 4, 2023
281cb55
chore: fix misc
ZeroEkkusu Nov 5, 2023
a6e4ff8
Update README.md
gretzke Nov 6, 2023
6f92d1c
Update README.md
gretzke Nov 6, 2023
8ebe47a
docs: update `README`
ZeroEkkusu Nov 6, 2023
9805774
small fixes
gretzke Nov 6, 2023
35e8151
feat: storage checker V1
ZeroEkkusu Nov 7, 2023
d98b6a1
fix: correct path
ZeroEkkusu Nov 7, 2023
d51791f
check whether PR into main is from staging
gretzke Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PRIVATE_KEY=
INFURA_KEY=
ETHERSCAN_API_KEY=
POLYGONSCAN_API_KEY=
POLYGONSCAN_ZKEVM_API_KEY=
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This group is setup to ensure a security review is always required for PRs
/src/ @0xPolygon/internal-security
/script/**/*.sol @0xPolygon/internal-security
/deployments/ @0xPolygon/internal-security
48 changes: 48 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Pull Request

## Description

Please include a summary of the change and which feature was implemented or which issue was fixed. Also, include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

### How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

# Checklist:

Before deployment

- [ ] 100% test and branch coverage
- [ ] check slither for severe issues
- [ ] fuzz and invariant tests (when applicable)
- [ ] formal verification (when applicable)
- [ ] deployment or upgrade scripts ready
- [ ] version management agreed upon and implemented
- [ ] internal team review
- [ ] **Security Team review**

After deployment

- [ ] transfer ownership after deployments (when applicable)
- [ ] complete upgrade (when applicable)
- [ ] generate deployment/upgrade log files
- [ ] update [static](https://github.com/maticnetwork/static/tree/master/network) with new contract address and/or version

---

### Considerations

- I have followed the [contributing guidelines](../CONTRIBUTING.md).
- My code follows the style guidelines of this project and I have run `forge fmt` and prettier to ensure the code style is valid
- I have performed a self-review of my own code
- I have commented my code, particularly in hard-to-understand areas
- I have made corresponding changes to the documentation
- My changes generate no new warnings
- I have added tests that prove my fix is effective or that my feature works
- New and existing unit tests pass locally with my changes

### Additional context

Add any other context about the pull request here.
20 changes: 20 additions & 0 deletions .github/workflows/pr-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Source branch check
on:
pull_request:
branches: [main]
types:
- opened
- reopened
- synchronize
- edited
jobs:
check-main:
if: github.base_ref == 'main'
runs-on: ubuntu-latest
steps:
- name: Check branches
run: |
if [ ${{ github.head_ref }} != "staging" ]; then
echo "Merge requests to main branch are only allowed from staging branch."
exit 1
fi
21 changes: 21 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# checks that pre-commit hooks pass before allowing to merge a PR

name: pre-commit
on:
pull_request:
branches: [main, master, staging, dev, feat/**, fix/**]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
36 changes: 36 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: test

on:
pull_request:
branches: [main, master, staging, dev, feat/**, fix/**]

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/target
/out
/cache
/coverage
lcov.info
.DS_Store
.env
.vscode

broadcast/*/31337
deployments/**/31337.*

script/util/storage_check_cache
script/util/storage_check_report
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/openzeppelin/openzeppelin-contracts-upgradeable
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.16.0
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: mixed-line-ending
args: ["--fix=lf"]
description: Forces to replace line ending by the UNIX 'lf' character.
exclude: "^docs/autogen"
- repo: local
hooks:
- id: format
name: Format solidity code
description: Format solidity code with `forge fmt`
language: system
entry: forge fmt
exclude: "^lib/"
pass_filenames: true
- id: doc
name: Generate documentation
description: Generate docs with `forge doc`
language: system
# generates docs and unstages files if only the commit hash changed within the file, this way only when the documentation is updated, the documentation needs to be regenerated and only the changed files are pushed
entry: "script/util/doc_gen.sh"
pass_filenames: false
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: prettier
name: Format non solidity files with prettier
exclude: "^docs/autogen"
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
foundry.toml
out
lib/
cache/
docs/autogenerated
*.sol
25 changes: 25 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": true,
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "*.json",
"options": {
"tabWidth": 4
}
}
]
}
158 changes: 158 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Contributing

- [Install](#install)
- [Pre-commit Hooks](#pre-commit-hooks)
- [Branching](#branching)
- [Main](#main)
- [Staging](#staging)
- [Dev](#dev)
- [Feature](#feature)
- [Fix](#fix)
- [Code Practices](#code-practices)
- [Interfaces](#interfaces)
- [NatSpec \& Comments](#natspec--comments)
- [Versioning](#versioning)
- [Testing](#testing)
- [Deployer Template](#deployer-template)
- [Deployment](#deployment)
- [Deployer Template](#deployer-template-1)
- [Deployment](#deployment-1)
- [Deployment Info Generation](#deployment-info-generation)
- [Deployer Template Script](#deployer-template-script)
- [Releases](#releases)

## Install

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/) for smart contracts. 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

### Deployer Template

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

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

### Deployer Template

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

### 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 for the Etherscan api key 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.

## Deployer Template Script

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

A deployer is an `abstract` contract, meant to be inherited in scripts and tests. The deployer consists of two functions: `deploy<Contract>` and `deploy<Contract>_NoInit`. It handels the creation, proxification, and initialization of the contract.

To generate a new deployer:

```
node script/util/generateDeployer.js <contractFile> [params] <outputDir>
```

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

- 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
Loading
Loading