Table of Contents
This Hardhat project is for writing, testing and deploying the SMU Blockchain Club DAO. This implements the Governance, TimeLock and ERC20Votes interfaces from @openzeppelin/contracts. The governed contract stores the SMUB EXCO members names. This allows the DAO to vote on and decide the EXCO members in the club.
Deployment is done on both Hardhat and the Sepolia testnet and testing on Hardhat.
See frontend app here
YouTube walkthrough here
- Hardhat
- OpenZeppelin
- Typescript
To get a local copy up and running follow these simple example steps.
- yarn
- Clone the repo
git clone https://github.com/jinhanloh2021/dao-smub.git
- Install NPM packages
yarn
- See .example.env for the environment variables. You will need a Sepolia RPC URL as a provider, and your Sepolia private key as a signer.
Run tests
yarn hardhat test
Run deployment on Hardhat
yarn hardhat run scripts/DeployHardhatDao.ts
Run deployment on Sepolia
yarn hardhat run scripts/DeploySepoliaDao.ts
Generate a code coverage report for tests
yarn hardhat coverage
See YouTube for full rundown
The governed contract is Smub.sol
which is owned by the DAO. Hence the setExco function can only be called if a proposal passes. This enforces governance on the values that the s_exco mapping, which represents the EXCO members, can be.
The Governance contract and TimeLock contracts were simple because they were copied from OpenZeppelin. However, debugging and reading these interfaces was not easy, as I needed to dig into the code to understand the functions that I am extending. And also to understand how exactly does the Governance work with the TimeLock and the Token.
Deployment has to be done in the correct order to resolve dependencies. eg. Deploy TimeLock before GovernanceContract, as we require the TimeLock address in the GovernanceContract constructor. There are also small nuances such as granting and revoking roles on the TimeLock, so that only the GovernanceContract can propose, and there is no admin. This ensures the TimeLock can only be controlled through the DAO and not an individual account. It is a complex process to deploy 4 contracts that are tightly coupled.
Testing was straightforward apart from the integration tests. Listening for events on Hardhat network was very hard to debug. And having to manually manipulate the chain to increase its block number and time was an added challenge, as I needed to simulate time passing and blocks being mined.
The multi-step process of propose, vote, queue, execute was difficult to test individually as each step relies on the previous. Hence the integrated testing was done in a single test, which is not ideal.
- Hardhat deployment
- Sepolia deployment
- Automated contract verification
- Unit testing
- Staging tests (done manually now on website)
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Project Link: https://github.com/jinhanloh2021/dao-smub