Skip to content

Commit

Permalink
Compound v2.8: COMP Distribution System
Browse files Browse the repository at this point in the history
* Pre-release branch for Flywheel (#40)

This patch adds a COMP distribution mechanism to the Comptroller nicknamed the 'flywheel'. Whenever a user interacts with the protocol, the *Allowed hooks now trigger tracking of a COMP supply and borrow index, and a distribution of COMP to user's whose supply or borrow balances may have changed, proportional to the fraction of total protocol interest they have accumulated.

Tracking interest between markets is accomplished via COMP 'speeds', which are a fraction of a total COMP rate being distributed, proportional to that market's share of total borrow interest (per block, at the time of recalculation). Anyone may trigger a recalculation of speeds at any time.

Tracking interest for a user is accomplished via per-market indices which track the amount of COMP that should have been distributed to the market, given the COMP speeds, the total COMP rate, and the number of blocks that have elapsed since the last update.

This patch also adds a Dripper, which distributes Comp (or any token) to a target (Comptroller) at some fixed rate. The goal of Dripper is to be simple and immutable. Anyone can poke the Dripper at any time to move Comp to the Comptroller as per the scheduled rate. If there is not enough Comp in the Dripper, we drip as much as we can and will try to drip the complete expected sum next time.

Co-authored-by: Max Wolff <[email protected]>
Co-authored-by: Geoffrey Hayes <[email protected]>

* All markets bugfix; add scens (#60)

This patch tracks all markets instead of just COMP markets, since we need to be able to iterate over the superset of markets in most cases, to ensure that toggling COMP-enabled on markets always clears out speeds and re-initializes state correctly. The initial upgrade should take all the existing markets as a parameter, and new markets are initialized via the call to `_supportMarket`.

* Post-audit fixes, more scenarios, and auxiliary improvements fixes (#63)

* Compare boolean values numerically to 1, not string 0x01

* Remove the short-circuits for market NEVER initialized (#64)

These were intended to be short-circuits if not a COMP market, but in fact only take effect if *never* a COMP market. Removing the short-circuit avoids this confusion, and enables us to poke all borrowers once, instead of after every time a market becomes a COMP market for the first time.

* add checkIsComped, add isComped to markets storageAt getter (#65)

* Ensure updating COMP indices only takes 1 SSTORE (#66)

* Set claim threshold; scen code for forks (#69)

* Add events for changing comp rate and adding/dropping comped markets (#70)

* Rename dripper -> reservoir; add fauceteer (#72)

* Rename dripper -> reservoir

* Add Fauceteer and Add Timelock Harness Features (#71)

This patch adds the Fauceteer, which is a simple contract that can hold Erc20 tokens and will give away a small percentage every time you poke it. The idea is that it replaces the need for "FaucetToken" as we now just make Fauceteer own some amount of tokens and you can poke _it_ if you need test tokens. This gives us the ability to use real Dai, etc, on testnets *and* have a faucet available to users. As the Fauceteer only gives away 0.01% of what it has, it will effectively never run out, but instead just give away less and less each time you poke it. The raw number of tokens isn't that important for test-nets, so this is acceptable.

We also add some functions to the TimelockTest harness. We allow it to change admin without going through timelocking, and we add the ability for it to call `_acceptAdmin` without timelocking. This significantly makes the flow of setting up a test-net easier.

Co-authored-by: Max Wolff <[email protected]>
Co-authored-by: Geoff Hayes <[email protected]>

* Release revisions and network configurations (#73)

* Allow Fauceteer to handle non-standard EIP-20 Tokens

* Add the new eureka Kovan config with flywheel

* Add (old) new DSR rate model to mainnet config

* Final polish [COMP-1037] (#74)

This patch adds some improvements based on discoveries from the testnet phase of the release.

The `claimComp` function has been enhanced in several ways to make it far more gas-efficient and versatile. In particular, it no longer refreshes speeds and allows specifying multiple accounts to claim, the markets in which to claim, and whether to claim the supply side and/or the borrow side independently.

The `NewCompRate` event parameter names were changed to reflect that the arguments are not actually mantissas (even though COMP per block units have 18 decimals).

When we `transferComp` and check if the COMP accrued is above the threshold, we now also check if the accrued amount is exactly 0, in order to short-circuit unnecessary transfers.

Finally, this patch extends the COMP Balance Metadata Lens to include COMP Allocated (that is, what is owed to you but not yet received). This is useful for showing users on an interface how much COMP they have earned, since it can be 'called' to return the differential value. A future version may implement this as a pure-view function, though it is more complex and requires detailed understanding about the way COMP is accrued, so the simpler approach is favored initially.

Co-authored-by: Max Wolff <[email protected]>
Co-authored-by: Geoff Hayes <[email protected]>

* Final deployments (#83)

This patch adds the final deployments for the COMP distribution system (aka flywheel) to mainnet, kovan, and ropsten. It includes testnet harnesses, as well as the scripts that will be used to initialize all the pre-existing borrower COMP indices.

Co-authored-by: Max Wolff <[email protected]>
Co-authored-by: Geoff Hayes <[email protected]>

Co-authored-by: Max Wolff <[email protected]>
Co-authored-by: Geoffrey Hayes <[email protected]>
  • Loading branch information
3 people committed Jun 16, 2020
1 parent a79cda9 commit 9e2685e
Show file tree
Hide file tree
Showing 59 changed files with 73,129 additions and 65,613 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:
- run:
shell: /bin/bash -eox pipefail -O globstar
name: yarn test
no_output_timeout: 30m
command: JEST_JUNIT_OUTPUT_DIR=~/junit JEST_JUNIT_OUTPUT_NAME=test-results.xml script/coverage $(circleci tests glob 'tests/**/**Test.js' | circleci tests split --split-by=timings) -- --maxWorkers=4
- save_cache:
paths:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ scenario/build/webpack.js
.solcache
.solcachecov
scenario/.tscache
script/certora
tests/scenarios/
junit.xml
.build
Expand Down
4 changes: 3 additions & 1 deletion .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
],
"security/no-block-members": "off",
"security/no-inline-assembly": "off",
"security/no-low-level-calls": "off"
"security/no-low-level-calls": "off",
"security/no-tx-origin": "off",
"imports-on-top": "off"
}
}
12 changes: 9 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
The software and documentation available in this repository (the "Software") is protected by copyright law and accessible pursuant to the license set forth below. Copyright © 2019 Compound Labs, Inc. All rights reserved.
Copyright 2020 Compound Labs, Inc.

Permission is hereby granted, free of charge, to any person or organization obtaining the Software (the “Licensee”) to privately study, review, and analyze the Software. Licensee shall not use the Software for any other purpose. Licensee shall not modify, transfer, assign, share, or sub-license the Software or any derivative works of the Software.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE.
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 9e2685e

Please sign in to comment.