This document describes the tokens of the Emissions Tokens Network and the
DAO. Both types of tokens are in the contracts/ sub-directory.
The emissions tokens network in contracts/NetEmissionsTokenNetwork.sol is an ERC-1155 multi-token standard smart contract
compatible on any EVM-compatible blockchain and produces CLM8 tokens from issuers to consumers. Each CLM8 token is a record of addition or reduction of
greenhouse gas (GHG) emissions. The unit of the CLM8 token is 1 kg, so 1000 CLM8 tokens is a metric ton of emissions.
The DAO in contracts/Governance is customized from the
Compound Defi Protocol DAO to create an ERC-20 dCLM8 token that is used for voting on proposals.
Hardhat is an Ethereum development and testing environment which is great for deploying and testing the contracts locally.
For local development on can simply run those commands from the project root directory:
- To start hardhat locally:
npm run hardhat - After it started to setup the default test accounts and demo transactions:
npm run hardhat-setup
For more advanced commands, tests and deployment, you can also run from the hardhat directory:
- To see all commands, run
npx hardhat - To compile, run
npx hardhat compile - To test, run
npx hardhat test(andnpx hardhat test [filename] to run a specific test) make sure that neitherhardhatnoripfsis already running because some tests will start those manually. - To run a local test network without deploying the contracts, run
npx hardhat node --no-deploy - To run a local test network that automatically deploys all of the contracts locally, run
npx hardhat node - To deploy to a given network (e.g. goerli), run
npx hardhat deploy --network goerli
You can start by deploying the contracts locally:
$ npx hardhat node
After deploying to hardhat locally, and you will see the addresses of the deployed contracts as well as 20 accounts available for testing. You can then run this command to set up roles for some of those accounts:
$ npx hardhat setTestAccountRoles --network localhost --contract <NetEmissionsTokeNetwork address>
To test the DAO, use this command to give the DAO tokens to your test accounts:
$ npx hardhat giveDaoTokens --network localhost --contract <DaoToken address>
To check the balances of the test accounts, use this command:
$ npx hardhat showDaoTokenBalances --network localhost --contract <DaoToken address>
The limited mode is useful in production environments. Once it is enabled:
- Only the admin can register roles
- Only the DAO's Timelock contract can issue carbon offsets and REC tokens.
- Offset and REC tokens can only be issued to the admin.
- Emissions audits tokens can be issued as usual by emissions auditors.
- Only the admin can transfer tokens
- Once transferred from the admin to a recipient, they are immediately retired in the recipient's account.
To turn on limited mode on a given network, run the task:
npx hardhat setLimitedMode --network localhost --contract <NetEmissionsTokenNetwork deployed address> --value trueYou can turn it off with:
npx hardhat setLimitedMode --network localhost --contract <NetEmissionsTokenNetwork deployed address> --value falseBy default, the quorum (minimum number of votes in order for a proposal to succeed) is 632 votes or about sqrt(4% of total supply). The guardian can set this value by running the task:
npx hardhat setQuorum --network localhost --contract <Governor deployed address> --value <votes>To get the current quorum, run the similar task:
npx hardhat getQuorum --network localhost --contract <Governor deployed address> In the original Compound DAO design, the proposal threshold is the minimum amount of DAO tokens required to make a proposal. In our system, this amount of dCLM8 is locked with a proposal by being sent to the Governor contract for safekeeping until the proposal has passed or failed. If the proposal did not pass quorum, the proposer can refund for 3/4 of their staked tokens. The guardian can also set adjust this value if needed:
npx hardhat setProposalThreshold --network localhost --contract <Governor deployed address> --value 1000000000000000000000This value represents a dCLM8 amount with no sqrt calculation, so 18 zeros must be padded to the end of the number. By default, it is set to 100,000 or 1% of the dCLM8 supply.
Similarly, you can easily see the value by running the similar task:
npx hardhat getProposalThreshold --network localhost --contract <Governor deployed address>The DAO token has an initial supply of 10 million. It can be increased with
npx hardhat addToSupply --network localhost --contract <DAO Token deployed address> --amount 10000000000000000000000000Note there must be 18 zeroes after the amount, so this is 10 million more tokens above. The new DAO tokens will go to the same initial holder who can then transfer them to other holders.
To check the total supply, use
npx hardhat getTotalSupply --network localhost --contract <DAO Token deployed address>In the case that new changes are made to the DAO (Governor.sol and/or its Timelock.sol) and we want to deploy a new version of it to a production environment but we also want to keep the same DAOToken.sol contract, we can utilize the hardhat-deploy plugin's tags/dependencies features to easily deploy some contracts individually while reusing others. To upgrade just the DAO:
-
Make sure the current addresses of the contracts you don't need to upgrade are correctly set in the .json files in
deployments/<network>/after runningnpx hardhat deploy --network <network> -
Rename or delete the current references in
deployments/<network>/to the Governor and Timelock, which areGovernor.jsonandTimelock.json -
From
hardhat/, runnpx hardhat deploy --network <network>again
Now instead of running the full deployment for every contract, the deployment script will reuse the current DAOToken and NetEmissionsTokenNetwork addresses on the network you're using and point it to the new DAO contracts.
Slither is a powerful Solidity static analysis framework written in Python. To install and run the Slither static analysis on the Solidity contracts, first ensure Python 3.6+ and Pip 3 are installed. Then from hardhat/ sub-directory, run the script with:
sh runSlither.shThe results of the analysis will be outputted as JSON files to SlitherResults/. Those files can be viewed with Slither printer.