Skip to content

Commit

Permalink
Add Comp Token and Governor Alpha [2.5]
Browse files Browse the repository at this point in the history
This patch adds the Comp Token and Governor Alpha contracts. The Comp token represents the administrative rights of the protocol, divided into 10,000,000 fungible tokens. These tokens have governance rights in the Governor contract, which in turn will become the admin of the Compound Timelock that administers the Compound Comptroller and cToken contracts.

The Comp Token is a basic Erc-20 with an ability to delegate to third parties. The goal of delegation is that an account could delegate his/her voting rights in the Governor to a hot-wallet or trusted third-party which is paying closer attention to governance proposals.

The Governor Alpha system is a simple vote-based governor which allows Comp Token holders to propose and ratify specific Ethereum actions. For instance, a user with sufficient tokens could propose supporting a new market in the Compound Comptroller. All Comp Token delegees will then have the ability over some period to vote on that proposal, and if its ratified, it can be automatically executed (through the Compound Timelock).

Delegation is unique in the fact it's tracked by block, forever, for each account. This allows us to say "how many delegated votes existed for X account at block Y." We then say that your votes for a given proposal are the amount of votes you had delegated at the time the proposal was created. In this way, we prevent sybil attacks without forcing users to lock tokens before voting.
  • Loading branch information
hayesgm committed Jan 16, 2020
1 parent ecceff0 commit 6858417
Show file tree
Hide file tree
Showing 87 changed files with 24,750 additions and 9,540 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- run:
|
sudo wget https://github.com/ethereum/solidity/releases/download/v0.5.12/solc-static-linux -O /usr/local/bin/solc
sudo wget https://github.com/ethereum/solidity/releases/download/v0.5.13/solc-static-linux -O /usr/local/bin/solc
sudo chmod +x /usr/local/bin/solc
- checkout
- restore_cache:
Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
- store_artifacts:
path: ~/junit
parallelism: 3
resource_class: large
resource_class: xlarge

verify:
docker:
Expand All @@ -81,7 +81,7 @@ jobs:
steps:
- run:
|
sudo wget https://github.com/ethereum/solidity/releases/download/v0.5.12/solc-static-linux -O /usr/local/bin/solc
sudo wget https://github.com/ethereum/solidity/releases/download/v0.5.13/solc-static-linux -O /usr/local/bin/solc
sudo chmod +x /usr/local/bin/solc
- checkout
- restore_cache:
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
- codecov/upload:
file: ~/repo/coverage/coverage-final.json
parallelism: 10
resource_class: large
resource_class: xlarge

lint:
docker:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ scenario/build/webpack.js
scenario/.tscache
tests/scenarios/
junit.xml
.build
.build
.last_confs
1 change: 1 addition & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"error",
200
],
"security/no-block-members": "off",
"security/no-inline-assembly": "off",
"security/no-low-level-calls": "off"
}
Expand Down
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ spec/certora/Math/%.cvl:
--verify \
MathCertora:$@

spec/certora/Comp/%.cvl:
$(CERTORA_RUN) \
spec/certora/contracts/CompCertora.sol \
--settings -b=4,-graphDrawLimit=0 \
--verify \
CompCertora:$@

spec/certora/Governor/%.cvl:
$(CERTORA_RUN) \
spec/certora/contracts/GovernorAlphaCertora.sol \
--verify \
GovernorAlphaCertora:$@

spec/certora/Comptroller/%.cvl:
$(CERTORA_RUN) \
spec/certora/contracts/ComptrollerCertora.sol \
Expand All @@ -41,7 +54,7 @@ spec/certora/cDAI/%.cvl:
spec/certora/contracts/mcd/pot.sol:Pot \
spec/certora/contracts/mcd/vat.sol:Vat \
spec/certora/contracts/mcd/join.sol:DaiJoin \
contracts/test/BoolComptroller.sol \
tests/Contracts/BoolComptroller.sol \
--link \
CDaiDelegateCertora:comptroller=BoolComptroller \
CDaiDelegateCertora:underlying=Dai \
Expand Down
46 changes: 12 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ We detail a few of the core contracts in the Compound protocol.
<dd>The risk model contract, which validates permissible user actions and disallows actions if they do not fit certain risk parameters. For instance, the Comptroller enforces that each borrowing user must maintain a sufficient collateral balance across all cTokens.</dd>
</dl>

<dl>
<dt>Comp</dt>
<dd>The Compound Governance Token (COMP). Holders of this token have the ability to govern the protocol via the governor contract.</dd>
</dl>

<dl>
<dt>Governor Alpha</dt>
<dd>The administrator of the Compound timelock contract. Holders of Comp token may create and vote on proposals which will be queued into the Compound timelock and then have effects on Compound cToken and Copmtroller contracts. This contract may be replaced in the future with a beta version.</dd>
</dl>

<dl>
<dt>InterestRateModel</dt>
<dd>Contracts which define interest rate models. These models algorithmically determine interest rates based on the current utilization of a given market (that is, how much of the supplied assets are liquid versus borrowed).</dd>
Expand Down Expand Up @@ -73,28 +83,12 @@ You can then compile and deploy the contracts with:

Note: this project does not use truffle migrations. The command above is the best way to deploy contracts. To view the addresses of contracts, please inspect the `networks/development.json` file that is produced as an artifact of that command.

Console
-------

After you deploy, as above, you can run a truffle console with the following command:

yarn run console

This command will create a truffle-like build directory and start a truffle console, thus you can then run:

truffle(rinkeby)> cDAI.deployed().then((cdai) => cdai.borrowRatePerBlock.call())
<BN: 7699bf9dd>

You can also specify a network (rinkeby, ropsten, kovan, goerli or mainnet):

yarn run console rinkeby

REPL
----

The Compound Protocol has a simple scenario evaluation tool to test and evaluate scenarios which could occur on the blockchain. This is primarily used for constructing high-level integration tests. The tool also has a REPL to interact with local the Compound Protocol (similar to `truffle console`).

yarn run repl
yarn repl

> Read CToken cBAT Address
Command: Read CToken cBAT Address
Expand All @@ -113,12 +107,6 @@ Mocha contract tests are defined under the [test directory](https://github.com/c

yarn run test

or with inspection (visit chrome://inspect) and look for a remote target after running:

node --inspect node_modules/truffle-core/cli.js test

Assertions used in our tests are provided by [ChaiJS](http://chaijs.com).

Integration Specs
-----------------

Expand All @@ -133,7 +121,6 @@ Code Coverage
-------------
To run code coverage, run:

scripts/ganache-coverage # run ganache in coverage mode
yarn run coverage

Linting
Expand All @@ -153,18 +140,9 @@ To run in docker:
# Run a shell to the built image
docker run -it compound-protocol /bin/sh

From within a docker shell, you can interact locally with the protocol via ganache and truffle:

> ganache-cli &
> yarn run deploy
> yarn run console
truffle(development)> cDAI.deployed().then((contract) => cdai = contract);
truffle(development)> cdai.borrowRatePerBlock.call().then((rate) => rate.toNumber())
20

Discussion
----------

For any concerns with the protocol, visit us on [Discord](https://compound.finance/discord) to discuss.

_© Copyright 2019, Compound Labs, Inc._
_© Copyright 2020, Compound Labs, Inc._
3 changes: 3 additions & 0 deletions contracts/EIP20Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pragma solidity ^0.5.12;
* https://eips.ethereum.org/EIPS/eip-20
*/
interface EIP20Interface {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);

/**
* @notice Get the total number of tokens in circulation
Expand Down
Loading

0 comments on commit 6858417

Please sign in to comment.