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

feat: RBSv1.4 + Clearinghouse + OCG (Governor Bravo + Proposal Simulator) #10

Merged
merged 9 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 30 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,51 @@ on:
- master
pull_request:

env:
ETH_MAINNET_RPC_URL: ${{ secrets.ETH_MAINNET_RPC_URL }}
POLYGON_MAINNET_RPC_URL: ${{ secrets.POLYGON_MAINNET_RPC_URL }}

jobs:
run-ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-node@v2

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Install Node dependencies
run: npm install
run: pnpm install

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

- name: Install Foundry dependencies
run: forge install

- name: Run lint check
run: npm run lint:check
run: pnpm run lint:check

- name: Run unit tests
run: pnpm run test:unit

- name: Run proposal simulation tests
run: pnpm run test:proposal
env:
FORK_TEST_RPC_URL: ${{ secrets.FORK_TEST_RPC_URL }}

- name: Run fork tests
run: pnpm run test:fork
env:
FORK_TEST_RPC_URL: ${{ secrets.FORK_TEST_RPC_URL }}

- name: Run tests
run: forge test
- name: Run cross-chain fork tests
run: pnpm run test:crosschainfork
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ remappings.txt
broadcast/
src/test/sim/in/*.json
src/test/sim/out/*.json
src/test/sim/sims/*.t.sol
src/test/sim/sims/*.t.sol
# deployments/* idea is that deployments should be saved for each chain, you can manually delete them from sims
.env_deploy*
docs/
coverage/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict = true
4 changes: 3 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"func-visibility": [ "warn", { "ignoreConstructors":true }],
"no-inline-assembly": "off",
"reason-string": "off",
"no-empty-blocks": "off"
"no-empty-blocks": "off",
"no-console": "off",
"no-global-import": "off"
}
}
8 changes: 2 additions & 6 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
src/test/lib/larping.sol
src/test/mocks/MockModuleWriter.sol
src/test/lib/quabi/Quabi.sol
src/test/sim/RangeSim.sol
src/scripts/Deploy.sol
src/scripts/DeployV2.sol
src/test/**/*.sol
src/scripts/**/*.sol
27 changes: 22 additions & 5 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@
ffi = true
remappings = [
'ds-test/=lib/ds-test/src/',
'solmate/=lib/solmate/src/',
'forge-std/=lib/forge-std/src/',
'balancer-v2/=lib/balancer-v2/',

'interfaces/=src/interfaces',
'modules/=src/modules',
'policies/=src/policies',
'libraries/=src/libraries',
'solmate/=lib/solmate/src/',
'balancer-v2/=lib/balancer-v2/',
'layer-zero/=lib/solidity-examples/contracts/',
'@openzeppelin/=lib/openzeppelin-contracts/',
'bonds/=lib/bonds/src/',
'test/=src/test/',
'clones/=lib/clones-with-immutable-args/src/',
'proposal-sim=lib/forge-proposal-simulator/',
'proposal-sim/proposals/=lib/forge-proposal-simulator/proposals/',
'proposals/=src/proposals/',
'openzeppelin/=lib/openzeppelin-contracts/contracts',
'@addresses/=lib/forge-proposal-simulator/addresses/',
'@proposals/=lib/forge-proposal-simulator/proposals/',
'@utils/=lib/forge-proposal-simulator/utils/'
]
fs_permissions = [
{access = "write", path = "./src/test/sim/out/"},
{access = "write", path = "./deployments/"},
{access = "read", path = "./src/scripts/"},
{access = "read", path = "./src/proposals/addresses.json"},
]
fs_permissions = [{access = "write", path = "./src/test/sim/out/"}, {access = "write", path = "./deployments/"}]
solc_version = "0.8.15"
optimizer = true
optimizer_runs = 10
chain_id = 1

[fuzz]
runs = 4096
runs = 256
1 change: 1 addition & 0 deletions lib/clones-with-immutable-args/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
22 changes: 22 additions & 0 deletions lib/clones-with-immutable-args/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
push:
branches:
- master
pull_request:

jobs:
run-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

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

- name: Run tests
run: make test
8 changes: 8 additions & 0 deletions lib/clones-with-immutable-args/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Node
node_modules

# Forge
out/
cache/

.env
3 changes: 3 additions & 0 deletions lib/clones-with-immutable-args/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
20 changes: 20 additions & 0 deletions lib/clones-with-immutable-args/.solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.5.8"],
"const-name-snakecase": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"max-line-length": ["error", 10000],
"not-rely-on-time": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"reason-string": ["warn", { "maxLength": 64 }]
}
}
7 changes: 7 additions & 0 deletions lib/clones-with-immutable-args/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib",
"files.associations": {
".dapprc": "shellscript"
}
}
29 changes: 29 additions & 0 deletions lib/clones-with-immutable-args/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2022, wighawag & zefram.eth
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 14 additions & 0 deletions lib/clones-with-immutable-args/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# include .env file and export its env vars
# (-include to ignore error if it does not exist)
-include .env

# deps
update:; forge update

# Build & test
build :; forge clean && forge build --optimize --optimize-runs 1000000
test :; forge clean && forge test --optimize --optimize-runs 1000000 -v # --ffi # enable if you need the `ffi` cheat code on HEVM
trace :; forge clean && forge test --optimize --optimize-runs 1000000 -vvv # --ffi # enable if you need the `ffi` cheat code on HEVM
clean :; forge clean
snapshot :; forge clean && forge snapshot --optimize --optimize-runs 1000000
lint :; yarn lint
57 changes: 57 additions & 0 deletions lib/clones-with-immutable-args/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# ClonesWithImmutableArgs

Enables creating clone contracts with immutable arguments.

The immutable arguments are stored in the code region of the created proxy contract, and whenever the proxy is called, it reads the arguments into memory, and then appends them to the calldata of the delegate call to the implementation contract. The implementation contract can thus read the arguments straight from calldata.

By doing so, the gas cost of creating clones is reduced, since there's no need to store the immutable arguments in storage. The cost of using the clones is also reduced, since storage loads are replaced with calldata reading, which is far cheaper.

## Usage

Clone factory contracts should use the [`ClonesWithImmutableArgs`](src/ClonesWithImmutableArgs.sol) library. `ClonesWithImmutableArgs.clone()` is the main function for creating clones.

Contracts intended to be cloned should inherit from [`Clone`](src/Clone.sol) to get access to the helper functions for reading immutable args.

To see an example usage of the library, check out [`ExampleClone`](src/ExampleClone.sol) and [`ExampleCloneFactory`](src/ExampleCloneFactory.sol).

## Installation

To install with [DappTools](https://github.com/dapphub/dapptools):

```
dapp install wighawag/clones-with-immutable-args
```

To install with [Foundry](https://github.com/gakonst/foundry):

```
forge install wighawag/clones-with-immutable-args
```

To install with [Hardhat](https://hardhat.org):

```
npm i -D clones-with-immutable-args
```

## Local development

This project uses [Foundry](https://github.com/gakonst/foundry) as the development framework.

### Dependencies

```
make update
```

### Compilation

```
make build
```

### Testing

```
make test
```
3 changes: 3 additions & 0 deletions lib/clones-with-immutable-args/lib/ds-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.dapple
/build
/out
Loading
Loading