diff --git a/.env.example b/.env.template similarity index 100% rename from .env.example rename to .env.template diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a71f48..0a1ed3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,24 +88,21 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 + - name: Install scopelint + uses: engineerd/configurator@v0.0.8 + with: + name: scopelint + repo: ScopeLift/scopelint + fromGitHubReleases: true + version: latest + pathInArchive: scopelint-x86_64-linux/scopelint + urlTemplate: https://github.com/ScopeLift/scopelint/releases/download/{{version}}/scopelint-x86_64-linux.tar.xz + token: ${{ secrets.GITHUB_TOKEN }} + - name: Check formatting - run: forge fmt --check - - #- name: Install scopelint - # uses: engineerd/configurator@v0.0.8 - # with: - # name: scopelint - # repo: ScopeLift/scopelint - # fromGitHubReleases: true - # version: latest - # pathInArchive: scopelint-x86_64-linux/scopelint - # urlTemplate: https://github.com/ScopeLift/scopelint/releases/download/{{version}}/scopelint-x86_64-linux.tar.xz - # token: ${{ secrets.GITHUB_TOKEN }} - - #- name: Check formatting - # run: | - # scopelint --version - # scopelint check + run: | + scopelint --version + scopelint check slither-analyze: runs-on: ubuntu-latest diff --git a/README.md b/README.md index ed5d5da..4f9e2bf 100644 --- a/README.md +++ b/README.md @@ -1,159 +1,47 @@ -# ScopeLift Foundry Template +# Flexible Voting Clients -An opinionated template for [Foundry](https://github.com/foundry-rs/foundry) projects. +[Flexible Voting](https://github.com/ScopeLift/flexible-voting) is an extension to the widely used [OpenZeppelin Governor](https://docs.openzeppelin.com/contracts/4.x/api/governance#Governor) that enables novel voting patterns for delegates. Clients are contracts that leverage Flexible Voting to allow they these novel voting patterns, such as: -_**Please read the full README before using this template.**_ -- [Usage](#usage) -- [Overview](#overview) - - [`foundry.toml`](#foundrytoml) - - [CI](#ci) - - [Test Structure](#test-structure) -- [Configuration](#configuration) - - [Coverage](#coverage) - - [Slither](#slither) - - [GitHub Code Scanning](#github-code-scanning) + - Voting with tokens while earning yield in DeFi + - Voting with tokens bridged to L2 + - Shielded voting (i.e. secret/private voting) + - Cheaper subsidized signature based voting -## Usage +The Flexible Voting Clients repo contains existing clients and the necessary tools to build new clients. -To use this template, use one of the below approaches: +#### Getting started -1. Run `forge init --template ScopeLift/foundry-template` in an empty directory. -2. Click [here](https://github.com/ScopeLift/foundry-template/generate) to generate a new repository from this template. -3. Click the "Use this template" button from this repo's [home page](https://github.com/ScopeLift/foundry-template). +Clone the repo -It's also recommend to install [scopelint](https://github.com/ScopeLift/scopelint), which is used in CI. -You can run this locally with `scopelint fmt` and `scopelint check`. -Note that these are supersets of `forge fmt` and `forge fmt --check`, so you do not need to run those forge commands when using scopelint. - -## Overview - -This template is designed to be a simple but powerful configuration for Foundry projects, that aims to help you follow Solidity and Foundry [best practices](https://book.getfoundry.sh/tutorials/best-practices) -Writing secure contracts is hard, so it ships with strict defaults that you can loosen as needed. - -### `foundry.toml` - -The `foundry.toml` config file comes with: - -- A `fmt` configuration. -- `default`, `lite`, and `ci` profiles. - -Both of these can of course be modified. -The `default` and `ci` profiles use the same solc build settings, which are intended to be the production settings, but the `ci` profile is configured to run deeper fuzz and invariant tests. -The `lite` profile turns the optimizer off, which is useful for speeding up compilation times during development. - -It's recommended to keep the solidity configuration of the `default` and `ci` profiles in sync, to avoid accidentally deploying contracts with suboptimal configuration settings when running `forge script`. -This means you can change the solc settings in the `default` profile and the `lite` profile, but never for the `ci` profile. - -Note that the `foundry.toml` file is formatted using [Taplo](https://taplo.tamasfe.dev/) via `scopelint fmt`. - -### CI - -Robust CI is also included, with a GitHub Actions workflow that does the following: - -- Runs tests with the `ci` profile. -- Verifies contracts are within the [size limit](https://eips.ethereum.org/EIPS/eip-170) of 24576 bytes. -- Runs `forge coverage` and verifies a minimum coverage threshold is met. -- Runs `slither`, integrated with GitHub's [code scanning](https://docs.github.com/en/code-security/code-scanning). See the [Configuration](#configuration) section to learn more. - -The CI also runs [scopelint](https://github.com/ScopeLift/scopelint) to verify formatting and best practices: - -- Checks that Solidity and TOML files have been formatted. - - Solidity checks use the `foundry.toml` config. - - Currently the TOML formatting cannot be customized. -- Validates test names follow a convention of `test(Fork)?(Fuzz)?_(Revert(If_|When_){1})?\w{1,}`. [^naming-convention] -- Validates constants and immutables are in `ALL_CAPS`. -- Validates internal functions in `src/` start with a leading underscore. -- Validates function names and visibility in forge scripts to 1 public `run` method per script. [^script-abi] - -Note that the foundry-toolchain GitHub Action will cache RPC responses in CI by default, and it will also update the cache when you update your fork tests. - -### Test Structure - -The test structure is configured to follow recommended [best practices](https://book.getfoundry.sh/tutorials/best-practices). -It's strongly recommended to read that document, as it covers a range of aspects. -Consequently, the test structure is as follows: - -- The core protocol deploy script is `script/Deploy.sol`. - This deploys the contracts and saves their addresses to storage variables. -- The tests inherit from this deploy script and execute `Deploy.run()` in their `setUp` method. - This has the effect of running all tests against your deploy script, giving confidence that your deploy script is correct. -- Each test contract serves as `describe` block to unit test a function, e.g. `contract Increment` to test the `increment` function. - -## Configuration - -After creating a new repository from this template, make sure to set any desired [branch protections](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches) on your repo. - -### Coverage - -The [`ci.yml`](.github/workflows/ci.yml) has `coverage` configured by default, and contains comments explaining how to modify the configuration. -It uses: -The [lcov] CLI tool to filter out the `test/` and `script/` folders from the coverage report. - -- The [romeovs/lcov-reporter-action](https://github.com/romeovs/lcov-reporter-action) action to post a detailed coverage report to the PR. Subsequent commits on the same branch will automatically delete stale coverage comments and post new ones. -- The [zgosalvez/github-actions-report-lcov](https://github.com/zgosalvez/github-actions-report-lcov) action to fail coverage if a minimum coverage threshold is not met. - -Be aware of foundry's current coverage limitations: - -- You cannot filter files/folders from `forge` directly, so `lcov` is used to do this. -- `forge coverage` always runs with the optimizer off and without via-ir, so if you need either of these to compile you will not be able to run coverage. - -Remember not to optimize for coverage, but to optimize for [well thought-out tests](https://book.getfoundry.sh/tutorials/best-practices?highlight=coverage#best-practices-1). - -### Slither - -In [`ci.yml`](.github/workflows/ci.yml), you'll notice Slither is configured as follows: - -```yml -slither-args: --filter-paths "./lib|./test" --exclude naming-convention,solc-version +```bash +git clone git@github.com:ScopeLift/flexible-voting-clients.git +cd flexible-voting-clients ``` -This means Slither is not run on the `lib` or `test` folders, and the [`naming-convention`](https://github.com/crytic/slither/wiki/Detector-Documentation#conformance-to-solidity-naming-conventions) and [solc-version](https://github.com/crytic/slither/wiki/Detector-Documentation#incorrect-versions-of-solidity) checks are disabled. - -This `slither-args` field is where you can change the Slither configuration for your project, and the defaults above can of course be changed. +Copy the `.env.template` file and populate it with values -Notice that Slither will run against `script/` by default. -Carefully written and tested scripts are key to ensuring complex deployment and scripting pipelines execute as planned, but you are free to disable Slither checks on the scripts folder if it feels like overkill for your use case. - -For more information on configuration Slither, see [the documentation](https://github.com/crytic/slither/wiki/Usage). For more information on configuring the slither action, see the [slither-action](https://github.com/crytic/slither-action) repo. - -### GitHub Code Scanning - -As mentioned, the Slither CI step is integrated with GitHub's [code scanning](https://docs.github.com/en/code-security/code-scanning) feature. -This means when your jobs execute, you'll see two related checks: - -1. `CI / slither-analyze` -2. `Code scanning results / Slither` - -The first check is the actual Slither analysis. -You'll notice in the [`ci.yml`](.github/workflows/ci.yml) file that this check has a configuration of `fail-on: none`. -This means this step will _never_ fail CI, no matter how many findings there are or what their severity is. -Instead, this check outputs the findings to a SARIF file[^sarif] to be used in the next check. - -The second check is the GitHub code scanning check. -The `slither-analyze` job uploads the SARIF report to GitHub, which is then analyzed by GitHub's code scanning feature in this step. -This is the check that will fail CI if there are Slither findings. - -By default when you create a repository, only alerts with the severity level of `Error` will cause a pull request check failure, and checks will succeed with alerts of lower severities. -However, you can [configure](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#defining-the-severities-causing-pull-request-check-failure) which level of slither results cause PR check failures. +```bash +cp .env.template .env +# Open the .env file and add your values +``` -It's recommended to conservatively set the failure level to `Any` to start, and to reduce the failure level if you are unable to sufficiently tune Slither or find it to be too noisy. +```bash +forge install +forge build +forge test +``` -Findings are shown directly on the PR, as well as in your repo's "Security" tab, under the "Code scanning" section. -Alerts that are dismissed are remembered by GitHub, and will not be shown again on future PRs. +#### Repo Contents -Note that code scanning integration [only works](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/setting-up-code-scanning-for-a-repository) for public repos, or private repos with GitHub Enterprise Cloud and a license for GitHub Advanced Security. -If you have a private repo and don't want to purchase a license, the best option is probably to: +| Name | Description | Contract | +|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------| +| Aave AToken Client | An extension of Aave V3's AToken contract which makes it possible for AToken holders to still vote on governance proposals | [ATokenFlexVoting](./src/ATokenFlexVoting.sol) | +| Comet Client | This is an extension of Compound V3's Comet contract which makes it possible for Comet token holders to still vote on governance proposals. | [CometFlexVotingClient](./src/CometFlexVoting.sol) | +| Flex Voting Client |This is an abstract contract to make it easy to build clients for governance systems that are "flexible voting" governors. The above clients inherit from this contract. | [FlexVotingClient](./src/FlexVotingClient.sol) | -- Remove the `Upload SARIF file` step from CI. -- Change the `Run Slither` step to `fail-on` whichever level you like, and remove the `sarif` output. -- Use [triage mode](https://github.com/crytic/slither/wiki/Usage#triage-mode) locally and commit the resulting `slither.db.json` file, and make sure CI has access to that file. +## License -[^naming-convention]: - A rigorous test naming convention is important for ensuring that tests are easy to understand and maintain, while also making filtering much easier. - For example, one benefit is filtering out all reverting tests when generating gas reports. +Fractional Voting is available under the [MIT](LICENSE.txt) license. -[^script-abi]: Limiting scripts to a single public method makes it easier to understand a script's purpose, and facilitates composability of simple, atomic scripts. -[^sarif]: - [SARIF](https://sarifweb.azurewebsites.net/) (Static Analysis Results Interchange Format) is an industry standard for static analysis results. - You can read learn more about SARIF [here](https://github.com/microsoft/sarif-tutorials) and read about GitHub's SARIF support [here](https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning). +Copyright (c) 2023 ScopeLift diff --git a/src/ATokenFlexVoting.sol b/src/ATokenFlexVoting.sol index 16f6e79..9503569 100644 --- a/src/ATokenFlexVoting.sol +++ b/src/ATokenFlexVoting.sol @@ -1,10 +1,11 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.10; -// forgefmt: disable-start import {AToken} from "aave-v3-core/contracts/protocol/tokenization/AToken.sol"; -import {MintableIncentivizedERC20} from "aave-v3-core/contracts/protocol/tokenization/base/MintableIncentivizedERC20.sol"; -import {IAaveIncentivesController} from "aave-v3-core/contracts/interfaces/IAaveIncentivesController.sol"; +import {MintableIncentivizedERC20} from + "aave-v3-core/contracts/protocol/tokenization/base/MintableIncentivizedERC20.sol"; +import {IAaveIncentivesController} from + "aave-v3-core/contracts/interfaces/IAaveIncentivesController.sol"; import {IPool} from "aave-v3-core/contracts/interfaces/IPool.sol"; import {Checkpoints} from "@openzeppelin/contracts/utils/Checkpoints.sol"; import {FlexVotingClient} from "flexible-voting/src/FlexVotingClient.sol"; diff --git a/src/CometFlexVoting.sol b/src/CometFlexVoting.sol index 1e8d41d..c530baa 100644 --- a/src/CometFlexVoting.sol +++ b/src/CometFlexVoting.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; import {Comet} from "comet/Comet.sol"; @@ -62,6 +62,7 @@ contract CometFlexVoting is Comet, FlexVotingClient { //=========================================================================== // // This function is called any time the underlying balance is changed. + // scopelint: disable-next-line function updateBasePrincipal(address _account, UserBasic memory _userBasic, int104 _principalNew) internal override diff --git a/test/CometFlexVotingFork.t.sol b/test/CometFlexVotingFork.t.sol index 4323b1c..4616c0f 100644 --- a/test/CometFlexVotingFork.t.sol +++ b/test/CometFlexVotingFork.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Unlicensed +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; import {Test, console2, Vm} from "forge-std/Test.sol"; diff --git a/test/FractionalGovernor.sol b/test/FractionalGovernor.sol index ad57e73..e091f74 100644 --- a/test/FractionalGovernor.sol +++ b/test/FractionalGovernor.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; import "flexible-voting/src/GovernorCountingFractional.sol"; diff --git a/test/GovToken.sol b/test/GovToken.sol index 65b2072..5cb3f61 100644 --- a/test/GovToken.sol +++ b/test/GovToken.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; import {ERC20Votes} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; diff --git a/test/MockATokenFlexVoting.sol b/test/MockATokenFlexVoting.sol index a5b95ec..b40a93c 100644 --- a/test/MockATokenFlexVoting.sol +++ b/test/MockATokenFlexVoting.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: Unlicensed +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; import {IPool} from "aave-v3-core/contracts/interfaces/IPool.sol"; diff --git a/test/ProposalReceiverMock.sol b/test/ProposalReceiverMock.sol index 2a3df4c..8744284 100644 --- a/test/ProposalReceiverMock.sol +++ b/test/ProposalReceiverMock.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity >=0.8.10; contract ProposalReceiverMock {