This is the OUSD decentralized governance stack.
The recommended way to install Brownie is via pipx:
python3 -m pip install --user pipx
python3 -m pipx ensurepath
You may need to restart your terminal after installing pipx
.
pipx install eth-brownie
We require OpenZeppelin contract code that is in master and will be released after 4.5.0. Since the release tag has not been created yet we need to import them by commit hash. Once newer version of 4.5.0 is released we can default to that.
brownie pm install OpenZeppelin/openzeppelin-contracts-upgradeable@4.6.0
brownie pm install OpenZeppelin/openzeppelin-contracts@4.6.0
yarn install
cd contracts
brownie test --network hardhat
If this command reverts with an error it may be an incompatability with python 3.10. Try python 3.9 instead (pyenv is a good solution for managing multiple python versions).
The OGV staking contracts use forge for tests.
forge install
forge test
Copy dev.env
to .env
and fill out the PROVIDER_URL
Node will be run in forked mode
yarn run node
In another terminal:
brownie run deploy main client/networks/governance.localhost.json
Copy dev.env
to .env
and fill out the PROVIDER_URL
Node will be run in forked mode
yarn run node
In another terminal:
brownie console --network hardhat-fork
First, install the dependencies:
cd client
yarn install
Copy client/sample.env
to client/.env
.
Setup postgresql locally and create a database and update the DATABASE_URL
in your client/.env
A typical postgres example looks like postgres://user:secret@localhost:5432/ousdgovernance
.
Push the database and generate a client:
npx prisma db push
(these are already defaults in client/sample.env
)
Set the NETWORK_ID
env var to 31337.
Set the WEB3_PROVIDER
variable in your environment.
The hardhat RPC default is http://127.0.0.1:8545
.
Then, run the development server:
npm run dev
# or
yarn dev
This will start both the NextJS app and a listener script monitoring your local blockchain for changes.
Here are some places you may come unstuck when setting up locally. If you find any yourself, please document them here to help your fellow engineers:
Problem:
You're adding proposals and the transactions are going through on-chain, but confirmed proposals aren't showing in the UI. You might experience listener.ts outputting lots of info: Got confirmed block
messages, but nothing to confirm the script is picking up ProposalCreated
events.
Explanation:
Proposals aren't pushed to the database from the front-end submision handler. Instead, listener.ts monitors your local node, detects when the ProposalCreated
event is fired, then adds the proposal to the database. However, these events can't be picked up when the starting block number is off in your database.
Solution:
Because we start from the last seen block saved in the database, you may experience issues if this number is out of sync. To quickly solve:
- Comment out the database lookup function
- Add
ethereumEvents.start(0)
beneath to ensure a start from the beginning - Run
yarn run dev
- Revert what you changed
- Run
yarn run dev
again
You should now see proposals added to the database when you submit transactions.