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

chore: add readme and deploy scripts #10

Merged
merged 24 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d6c1343
feat: add wonderGovernor and wonderVotes contract examples
0xRaccoon Dec 20, 2023
b4410f1
fix: return memory proposal instead of storage
0xRaccoon Dec 20, 2023
120a7f7
Merge branch 'dev' of github-defi:defi-wonderland/wonderland-governoo…
0xRaccoon Dec 21, 2023
d7300bc
test: add Governor unit tests
0xRaccoon Dec 21, 2023
d07cb6c
test: add governor unit tests
0xRaccoon Dec 21, 2023
3a3a65d
test: add governor castVote tests
0xRaccoon Dec 21, 2023
6414e1a
test: add governor unit tests
0xRaccoon Dec 21, 2023
681175b
test: add wonder votes unit tests
0xRaccoon Dec 22, 2023
71d2242
test: add wonder votes unit tests
0xRaccoon Dec 22, 2023
3856d2d
test: add wonder votes unit tests
0xRaccoon Dec 22, 2023
fbeccaf
test: add integration tests
0xRaccoon Dec 26, 2023
ef0afb9
fix: add optimism rpc
0xRaccoon Dec 26, 2023
d8440ad
fix: add optimism rpc
0xRaccoon Dec 26, 2023
66a61f2
test: add integration tests
0xRaccoon Dec 27, 2023
8f0f9b0
fix: add missing file headers
0xRaccoon Dec 27, 2023
991e7e8
Merge branch 'test/add-governor-unit-tests' of github-defi:defi-wonde…
0xRaccoon Dec 27, 2023
278f18a
fix: add missing headers
0xRaccoon Dec 27, 2023
0320deb
Merge branch 'test/add-wonder-votes-unit-tests' of github-defi:defi-w…
0xRaccoon Dec 27, 2023
5a3bbf8
feat: add non delegable flag feature
0xRaccoon Dec 28, 2023
6490b89
feat: add non-delegable flag feature
0xRaccoon Dec 28, 2023
7e41901
Merge branch 'dev' of github-defi:defi-wonderland/wonderland-governoo…
0xRaccoon Dec 28, 2023
21250cb
test: add delegation suspension integration tests
0xRaccoon Dec 28, 2023
04fe0a3
chore: add readme and deploy scripts
0xRaccoon Jan 2, 2024
f063faa
Merge branch 'dev' of github-defi:defi-wonderland/wonderland-governoo…
0xRaccoon Jan 2, 2024
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
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ MAINNET_DEPLOYER_PK=
GOERLI_RPC=
GOERLI_DEPLOYER_PK=

ETHERSCAN_API_KEY=
OPTIMISM_RPC=
OPTIMISM_DEPLOYER_PK=

LOCAL_RPC=
LOCAL_DEPLOYER_PK=

OPTIMISM_RPC=
ETHERSCAN_API_KEY=
160 changes: 38 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,146 +1,62 @@
<img src="https://raw.githubusercontent.com/defi-wonderland/brand/v1.0.0/external/solidity-foundry-boilerplate-banner.png" alt="wonderland banner" align="center" />
<br />
# Wonderland Governor

<div align="center"><strong>Start your next Solidity project with Foundry in seconds</strong></div>
<div align="center">A highly scalable foundation focused on DX and best practices</div>
⚠️ The code has not been audited yet, tread with caution.

<br />
## Overview

## Features
Wonderland Governor is a DAO governance solution designed to address the current limitations in delegation within governance protocols. Unlike old systems where users give all their voting power to one delegate, it offers a flexible solution, introducing innovative features to empower users and enhance governance processes in decentralized organizations.

<dl>
<dt>Sample contracts</dt>
<dd>Basic Greeter contract with an external interface.</dd>
Key Features:

<dt>Foundry setup</dt>
<dd>Foundry configuration with multiple custom profiles and remappings.</dd>
Proposal Types:

<dt>Deployment scripts</dt>
<dd>Sample scripts to deploy contracts on both mainnet and testnet.</dd>
Wonderland Governor lets organizations set different types of proposals for specific needs like legal or technical matters.
Every proposal now has a required type, making it clear which category it falls into.

<dt>Sample e2e & unit tests</dt>
<dd>Example tests showcasing mocking, assertions and configuration for mainnet forking. As well it includes everything needed in order to check code coverage.</dd>
Better Delegation:

<dt>Linter</dt>
<dd>Simple and fast solidity linting thanks to forge fmt</a>.</dd>
Users can now spread their voting power across different categories.
Users can choose multiple delegates for each proposal type, assigning a percentage of their voting power to each.
Users can still delegate 100% of their voting power to one person if they prefer.

<dt>Github workflows CI</dt>
<dd>Run all tests and see the coverage as you push your changes.</dd>
<dd>Export your Solidity interfaces and contracts as packages, and publish them to NPM.</dd>
</dl>
Wonderland Governor is founded on the OpenZeppelin contracts and enhances their functionalities to achieve the described features.

## Setup

1. Install Foundry by following the instructions from [their repository](https://github.com/foundry-rs/foundry#installation).
2. Copy the `.env.example` file to `.env` and fill in the variables.
3. Install the dependencies by running: `yarn install`. In case there is an error with the commands, run `foundryup` and try them again.
This project uses [Foundry](https://book.getfoundry.sh/). To build it locally, run:

## Build

The default way to build the code is suboptimal but fast, you can run it via:

```bash
```sh
git clone [email protected]:defi-wonderland/wonderland-governooor-poc.git
cd wonderland-governooor-poc
yarn install
yarn build
```

In order to build a more optimized code ([via IR](https://docs.soliditylang.org/en/v0.8.15/ir-breaking-changes.html#solidity-ir-based-codegen-changes)), run:

```bash
yarn build:optimized
```

## Running tests

Unit tests should be isolated from any externalities, while E2E usually run in a fork of the blockchain. In this boilerplate you will find example of both.

In order to run both unit and E2E tests, run:

```bash
yarn test
```

In order to just run unit tests, run:

```bash
yarn test:unit
```

In order to run unit tests and run way more fuzzing than usual (5x), run:

```bash
yarn test:unit:deep
```

In order to just run e2e tests, run:

```bash
yarn test:e2e
```

In order to check your current code coverage, run:
### Available Commands

```bash
yarn coverage
```

<br>

## Deploy & verify

### Setup

Configure the `.env` variables.
Make sure to set `OPTIMISM_RPC` environment variable before running end-to-end tests.

### Goerli

```bash
yarn deploy:goerli
```

### Mainnet

```bash
yarn deploy:mainnet
```
| Yarn Command | Description |
| ----------------------- | ---------------------------------------------------------- |
| `yarn build` | Compile all contracts. |
| `yarn coverage` | See `forge coverage` report. |
| `yarn deploy:local` | Deploy the contracts to a local fork. |
| `yarn deploy:goerli` | Deploy the contracts to Goerli testnet. |
| `yarn deploy:optimism` | Deploy the contracts to Optimism mainnet. |
| `yarn deploy:mainnet` | Deploy the contracts to Ethereum mainnet. |
| `yarn test` | Run all unit and integration tests. |
| `yarn test:unit` | Run unit tests. |
| `yarn test:integration` | Run integration tests. |
| `yarn test:gas` | Run all unit and integration tests, and make a gas report. |

The deployments are stored in ./broadcast
## Licensing

See the [Foundry Book for available options](https://book.getfoundry.sh/reference/forge/forge-create.html).
The primary license for Wonderland Governor contracts is MIT, see [`LICENSE`](./LICENSE).

## Export And Publish
## Contributors

Export TypeScript interfaces from Solidity contracts and interfaces providing compatibility with TypeChain. Publish the exported packages to NPM.
Wonderland Governor was built with ❤️ by [Wonderland](https://defi.sucks).

To enable this feature, make sure you've set the `NPM_TOKEN` on your org's secrets. Then set the job's conditional to `true`:

```yaml
solidity-exporter.yml

jobs:
export:
name: Generate Interfaces And Contracts
# Remove the following line if you wish to export your Solidity contracts and interfaces and publish them to NPM
if: true
...
```

Also, remember to update the `package_name` param to your package name:

```yaml
solidity-exporter.yml

- name: Export Solidity - ${{ matrix.export_type }}
uses: defi-wonderland/solidity-exporter-action@1dbf5371c260add4a354e7a8d3467e5d3b9580b8
with:
# Update package_name with your package name
package_name: "my-cool-project"
...


- name: Publish to NPM - ${{ matrix.export_type }}
# Update `my-cool-project` with your package name
run: cd export/my-cool-project-${{ matrix.export_type }} && npm publish --access public
...
```
Wonderland is a team of top Web3 researchers, developers, and operators who believe that the future needs to be open-source, permissionless, and decentralized.

You can take a look at our [solidity-exporter-action](https://github.com/defi-wonderland/solidity-exporter-action) repository more information and usage examples.
[DeFi sucks](https://defi.sucks), but Wonderland is here to make it better.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
"build": "forge build",
"build:optimized": "FOUNDRY_PROFILE=optimized forge build",
"coverage": "forge coverage --match-contract Unit",
"deploy:goerli": "bash -c 'source .env && forge script DeployGoerli --rpc-url $GOERLI_RPC --broadcast --private-key $GOERLI_DEPLOYER_PK --verify --etherscan-api-key $ETHERSCAN_API_KEY'",
"deploy:mainnet": "bash -c 'source .env && forge script DeployMainnet --rpc-url $MAINNET_RPC --broadcast --private-key $MAINNET_DEPLOYER_PK --verify --etherscan-api-key $ETHERSCAN_API_KEY'",
"deploy:goerli": "dotenv -- bash -c 'forge script DeployGoerli -vv --slow --broadcast --rpc-url $GOERLI_RPC'",
"deploy:local": "dotenv -- bash -c 'forge script DeployLocal -vv --slow --broadcast --rpc-url $LOCAL_RPC'",
"deploy:mainnet": "dotenv -- bash -c 'forge script DeployMainnet -vv --slow --broadcast --rpc-url $MAINNET_RPC'",
"deploy:optimism": "dotenv -- bash -c 'forge script DeployOptimism -vv --slow --broadcast --rpc-url $OPTIMISM_RPC'",
"lint:check": "yarn lint:sol-tests && yarn lint:sol-logic && forge fmt --check",
"lint:fix": "sort-package-json && forge fmt && yarn lint:sol-tests --fix && yarn lint:sol-logic --fix",
"lint:sol-logic": "solhint -c .solhint.json 'solidity/contracts/**/*.sol' 'solidity/interfaces/**/*.sol'",
"lint:sol-tests": "solhint 'solidity/test/**/*.sol'",
"prepare": "husky install",
"test": "forge test -vvv",
"test:e2e": "forge test --match-contract E2E -vvv",
"test:gas": "forge test --match-contract Integration -vvv --gas-report",
"test:integration": "forge test --match-contract Integration -vvv",
"test:unit": "forge test --match-contract Unit -vvv",
"test:unit:deep": "FOUNDRY_FUZZ_RUNS=5000 yarn test:unit"
},
Expand All @@ -39,6 +43,7 @@
"devDependencies": {
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"dotenv-cli": "7.2.1",
"ds-test": "github:dapphub/ds-test#e282159",
"forge-std": "github:foundry-rs/forge-std#v1.7.3",
"husky": ">=8",
Expand Down
44 changes: 38 additions & 6 deletions solidity/scripts/Deploy.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Script} from 'forge-std/Script.sol';
import {IWonderGovernor} from 'interfaces/governance/IWonderGovernor.sol';
import {IWonderVotes} from 'interfaces/governance/utils/IWonderVotes.sol';
import {AliceGovernor} from 'examples/AliceGovernor.sol';
import {RabbitToken} from 'examples/RabbitToken.sol';

import {Script, console} from 'forge-std/Script.sol';

abstract contract Deploy is Script {
function _deploy() internal {
vm.startBroadcast();
// Deploy the contract
function _deploy(address _deployer) internal {
vm.startBroadcast(_deployer);

// Deploy the contracts
address tokenAddress = vm.computeCreateAddress(_deployer, vm.getNonce(_deployer) + 1);
AliceGovernor governor = new AliceGovernor(tokenAddress);
console.log('WonderGovernor:', address(governor));
RabbitToken rabbitToken = new RabbitToken(AliceGovernor(payable(address(governor))));
console.log('WonderVotes:', address(rabbitToken));

vm.stopBroadcast();
}
}

contract DeployMainnet is Deploy {
function run() external {
_deploy();
address _deployer = vm.rememberKey(vm.envUint('MAINNET_DEPLOYER_PK'));

_deploy(_deployer);
}
}

contract DeployGoerli is Deploy {
function run() external {
_deploy();
address _deployer = vm.rememberKey(vm.envUint('GOERLI_DEPLOYER_PK'));

_deploy(_deployer);
}
}

contract DeployLocal is Deploy {
function run() external {
address _deployer = vm.rememberKey(vm.envUint('LOCAL_DEPLOYER_PK'));

_deploy(_deployer);
}
}

contract DeployOptimism is Deploy {
function run() external {
address _deployer = vm.rememberKey(vm.envUint('OPTIMISM_DEPLOYER_PK'));

_deploy(_deployer);
}
}
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,26 @@ dot-prop@^5.1.0:
dependencies:
is-obj "^2.0.0"

[email protected]:
version "7.2.1"
resolved "https://registry.yarnpkg.com/dotenv-cli/-/dotenv-cli-7.2.1.tgz#e595afd9ebfb721df9da809a435b9aa966c92062"
integrity sha512-ODHbGTskqRtXAzZapDPvgNuDVQApu4oKX8lZW7Y0+9hKA6le1ZJlyRS687oU9FXjOVEDU/VFV6zI125HzhM1UQ==
dependencies:
cross-spawn "^7.0.3"
dotenv "^16.0.0"
dotenv-expand "^10.0.0"
minimist "^1.2.6"

dotenv-expand@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==

dotenv@^16.0.0:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==

"ds-test@github:dapphub/ds-test#e282159":
version "1.0.0"
resolved "https://codeload.github.com/dapphub/ds-test/tar.gz/e282159d5170298eb2455a6c05280ab5a73a4ef0"
Expand Down
Loading