Skip to content

jinhanloh2021/dao-smub

Repository files navigation


SMUB DAO

SMU Blockchain DAO

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Code Rundown
  5. Roadmap
  6. Contributing
  7. Contact
  8. Acknowledgments

About The Project

SMUB DAO Deployment and Testing

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

Built With

  • Hardhat
  • OpenZeppelin
  • Typescript

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

  • yarn

Installation

  1. Clone the repo
    git clone https://github.com/jinhanloh2021/dao-smub.git
  2. Install NPM packages
    yarn
  3. 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.

(back to top)

Usage

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

(back to top)

Code Rundown

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.

(back to top)

Roadmap

  • 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).

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

Project Link: https://github.com/jinhanloh2021/dao-smub

(back to top)

Acknowledgments

(back to top)