Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Comp Speeds Branch on Mainnet (#161)
* Add Arr00's changes for split COMP distributions - Adds compBorrowSpeeds and compSupplySpeeds to ComptrollerV6Storage - Change _setCompSpeed to _setCompSpeeds - one function call to update distribution speeds for multiple markets - Change signature of setCompSpeedInternal - compSpeed split up into two parts: compSupplySpeed and compBorrowSpeed * Update setCompSpeedInternal to update COMP speeds and accruals using compSupplySpeeds and compBorrowSpeeds * Fix compilation errors in Comptroller * Update tests to use new split COMP distribution changes * Update tests and frameworks to support the new COMP distributions * Add tests for setting varying supply and borrow rates * Fix bugs in Comptroller#updateCompSupplyIndex and Comptroller#updateCompBorrowIndex - compSupplySpeeds and compBorrowSpeeds were flipped * Add tests for one-sided COMP distribution rates - These tests have been manually verified to fail when they are expected to fail => they work well * Add upgrade hooks for split COMP reward distributions * Add TODO * Update gas costs * Add market initialization and update market state info - Supply state and borrow state now initialized when a market is added, ensuring market state indices are always set * Modify upgrade hook to ensure all market state indices are set * Simplify setCompSpeedInternal logic - Now that market state indices are non lazily set, we can simply update market states when updating COMP speeds * Adjust comments in Comptroller * Add COMP accrual optimizations - Adds changes from PR #173 - Second mint with comp accrued: reduced by 695 - Claim comp: reduced by 1268 * Add comments to accrual functions in Comptroller * Update FlywheelTest to account for initialization of borrow/supply state indices * Update Flywheel scenario test to use the latest Comptroller - Old scen test used ComptrollerG3 - Removed test for removed function which never actually worked * Update mainnet network config and abi to current (taken from compound-config) * Fix split COMP rewards upgrade hook - We need to call the upgrade function using the delegator address to use the storage at that contract address * Add Comptroller upgrade simulation - Asserts that the upgrade proposal passes - Asserts that old comp speeds are deleted - Asserts that new comp speeds are the same as they were previously - Asserts that market state indices are the same post upgrade, with 0 values initialized to 1e36 - Asserts that the 2 comp speed bugs were fixed - Asserts that the new _setCompSpeeds function works - Asserts that comp rewards accrual works * Refactor updateCompSupplyIndex and updateCompBorrowIndex slightly - Stores blockNumber as uint32 for safety * Update gas costs * Make style adjustment and fix typo * Update uninitialized rewards market block numbers in _upgradeSplitCompRewards * new branch * add new scen * add cases to new flywheel scen * Fix bug in distributeBorrowerComp identified by Coburn - Note: This change significantly increases gas usage (claim gas usage increased by 12K iirc) * Improve distributeBorrowerComp efficiency - Don't distribute borrower COMP (or update the user's borrow state) if the user is not in the borrower market. - Decreases gas usage of claim by 35K * Simplify distributeBorrowerComp - Removed the (borrowerIndex > 0) check - Since market state indices are always set now, this condition will always evaluate to true * Improve logic in borrowAllowed - It's possible that a borrower can be added to a market even if borrowAllowed returns an error. This can lead to inefficiences and possibly other problems. - This commit prevents this from happening * Add number fetcher to scenario runner * Move test from CompSpeed to Flywheel * Add new CompSpeed scenario tests * Remove old Flywheel scenario tests * Rename new Flywheel scen test to the old name * Add tests to Flywheel scenario tests - Ensures supply and borrow states properly initialized - Ensures COMP is accrued correctly when COMP rewards are added (after market activation), removed, then added again - This test covers the COMP speed bug identified on August 09, 2021 * Revert market membership changes - The logic didn't flow properly * Fix subtraction underflow problem - Underflow occurs when calling distributeBorrowerComp on markets whose borrowState.index didn't start at 1e36. - The COMP rewards on those markets work fine, so we just need to make a fix for people borrowing cMKR, cAAVE, and the other new markets whose indices haven't been set yet, which this commit does. * Increase gas limit in claimComp test - The change to distributeBorrowerComp to account for borrowers with uninitialized state indices increased the gas costs unfortunately * Add Coburn's scenario test for the flywheel - Ensures new COMP speeds apply to both prior borrowers+suppliers and later borrowers+suppliers correctly * Add another test to Flywheel scen tests - Ensures new COMP speeds apply to both prior borrowers+suppliers and later borrowers+suppliers correctly w/ uninitialized prior borrower/supplier state indices * Upgrade Grants simulation tests * Make distributeSupplierComp logic match distributeBorrowerComp logic * Update gas costs - Oof, the necessary change to distributeSupplierComp increased the gas cost of claim - Lastly, gm Co-authored-by: TRiLeZ <[email protected]> Co-authored-by: Aryeh Greenberg <[email protected]>
- Loading branch information