Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Test Case #164

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d15d685
Add Arr00's changes for split COMP distributions
TylerEther Jul 28, 2021
26e460a
Update setCompSpeedInternal to update COMP speeds and accruals using …
TylerEther Jul 28, 2021
cf90f78
Fix compilation errors in Comptroller
TylerEther Jul 28, 2021
d664a41
Update tests to use new split COMP distribution changes
TylerEther Jul 28, 2021
a1be01e
Update tests and frameworks to support the new COMP distributions
TylerEther Jul 29, 2021
7fae6e0
Add tests for setting varying supply and borrow rates
TylerEther Jul 29, 2021
f9d129d
Fix bugs in Comptroller#updateCompSupplyIndex and Comptroller#updateC…
TylerEther Jul 29, 2021
8f92ff1
Add tests for one-sided COMP distribution rates
TylerEther Jul 30, 2021
c1dfab5
Add upgrade hooks for split COMP reward distributions
TylerEther Jul 30, 2021
73b5e38
Add TODO
TylerEther Jul 30, 2021
86dfbca
Update gas costs
TylerEther Jul 30, 2021
fb5dd8c
Add market initialization and update market state info
TylerEther Aug 12, 2021
bb51bce
Modify upgrade hook to ensure all market state indices are set
TylerEther Aug 12, 2021
2112335
Simplify setCompSpeedInternal logic
TylerEther Aug 12, 2021
2da08c4
Adjust comments in Comptroller
TylerEther Aug 13, 2021
c5bc5cf
Add COMP accrual optimizations
TylerEther Aug 13, 2021
94476c4
Add comments to accrual functions in Comptroller
TylerEther Aug 13, 2021
df47b0a
Update FlywheelTest to account for initialization of borrow/supply st…
TylerEther Aug 13, 2021
b47a06a
Update Flywheel scenario test to use the latest Comptroller
TylerEther Aug 17, 2021
d53167d
Update mainnet network config and abi to current (taken from compound…
TylerEther Aug 19, 2021
20a218f
Fix split COMP rewards upgrade hook
TylerEther Aug 19, 2021
da2d724
Add Comptroller upgrade simulation
TylerEther Aug 19, 2021
ad27d25
Merge branch 'master' of github.com:compound-finance/compound-protoco…
TylerEther Aug 20, 2021
bb72669
Refactor updateCompSupplyIndex and updateCompBorrowIndex slightly
TylerEther Aug 21, 2021
8de3e74
Update gas costs
TylerEther Aug 21, 2021
1d85a34
Make style adjustment and fix typo
TylerEther Aug 29, 2021
6f4926b
Update uninitialized rewards market block numbers in _upgradeSplitCom…
TylerEther Aug 29, 2021
88fe058
new branch
arr00 Aug 30, 2021
453c671
add new scen
arr00 Sep 5, 2021
af023bd
add cases to new flywheel scen
arr00 Sep 6, 2021
f6d717b
Fix bug in distributeBorrowerComp identified by Coburn
TylerEther Sep 10, 2021
255d017
Improve distributeBorrowerComp efficiency
TylerEther Sep 10, 2021
18fb346
Simplify distributeBorrowerComp
TylerEther Sep 11, 2021
be21aa8
Improve logic in borrowAllowed
TylerEther Sep 11, 2021
31150fd
Merge branch 'dynamic-comp-reward-tyler' of github.com:arr00/compound…
TylerEther Sep 11, 2021
38d8855
Add number fetcher to scenario runner
TylerEther Sep 12, 2021
f6e8ebd
Move test from CompSpeed to Flywheel
TylerEther Sep 12, 2021
f8fd957
Add new CompSpeed scenario tests
TylerEther Sep 12, 2021
ae7702d
Remove old Flywheel scenario tests
TylerEther Sep 12, 2021
8c82a0c
Rename new Flywheel scen test to the old name
TylerEther Sep 12, 2021
4c3b2c2
Add tests to Flywheel scenario tests
TylerEther Sep 12, 2021
102aa41
Revert market membership changes
TylerEther Sep 12, 2021
2c7984f
Fix subtraction underflow problem
TylerEther Sep 13, 2021
053ac7c
Increase gas limit in claimComp test
TylerEther Sep 13, 2021
51ec789
Add Coburn's scenario test for the flywheel
TylerEther Sep 13, 2021
0432441
Add another test to Flywheel scen tests
TylerEther Sep 13, 2021
f055751
Upgrade Grants simulation tests
TylerEther Sep 13, 2021
732887b
Make distributeSupplierComp logic match distributeBorrowerComp logic
TylerEther Sep 17, 2021
f73b293
Update gas costs
TylerEther Sep 18, 2021
64cbbd0
Remove upgrade hook
TylerEther Sep 30, 2021
6c66d60
Temporarily pause COMP rewards
TylerEther Sep 30, 2021
4a0dcbc
Add failing test case for the proposal 62 bug
TylerEther Sep 30, 2021
ddde3ec
Fix the bug introduced in proposal 62
TylerEther Sep 30, 2021
63eb1cc
Add pessimistic authorizaion of transferring COMP rewards
TylerEther Oct 1, 2021
106c5a2
Merge branch 'master' of github.com:compound-finance/compound-protoco…
TylerEther Oct 1, 2021
137f9cf
Remove forgotten merge conflict
TylerEther Oct 1, 2021
086b1c8
Remove upgrade hook
TylerEther Oct 2, 2021
aecd143
Add ClaimCompInMarkets to the scenario runner
TylerEther Oct 4, 2021
0b29727
Add proposal 64 scenario test
TylerEther Oct 4, 2021
65083cf
Add Test Case
Sep 8, 2021
002fd08
Fix to match Tyler's changes
hayesgm Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 14 additions & 35 deletions contracts/Comptroller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1077,39 +1077,6 @@ contract Comptroller is ComptrollerV6Storage, ComptrollerInterface, ComptrollerE
function _become(Unitroller unitroller) public {
require(msg.sender == unitroller.admin(), "only unitroller admin can change brains");
require(unitroller._acceptImplementation() == 0, "change not authorized");

// TODO: Remove this post upgrade
Comptroller(address(unitroller))._upgradeSplitCompRewards();
}

function _upgradeSplitCompRewards() public {
require(msg.sender == comptrollerImplementation, "only brains can become itself");

uint32 blockNumber = safe32(getBlockNumber(), "block number exceeds 32 bits");

// compSpeeds -> compBorrowSpeeds & compSupplySpeeds t
for (uint i = 0; i < allMarkets.length; i ++) {
compBorrowSpeeds[address(allMarkets[i])] = compSupplySpeeds[address(allMarkets[i])] = compSpeeds[address(allMarkets[i])];
delete compSpeeds[address(allMarkets[i])];

/*
* Ensure supply and borrow state indices are all set. If not set, update to default value
*/
CompMarketState storage supplyState = compSupplyState[address(allMarkets[i])];
CompMarketState storage borrowState = compBorrowState[address(allMarkets[i])];

if (supplyState.index == 0) {
// Initialize supply state index with default value
supplyState.index = compInitialIndex;
supplyState.block = blockNumber;
}

if (borrowState.index == 0) {
// Initialize borrow state index with default value
borrowState.index = compInitialIndex;
borrowState.block = blockNumber;
}
}
}

/**
Expand Down Expand Up @@ -1214,7 +1181,7 @@ contract Comptroller is ComptrollerV6Storage, ComptrollerInterface, ComptrollerE
// Update supplier's index to the current index since we are distributing accrued COMP
compSupplierIndex[cToken][supplier] = supplyIndex;

if (supplierIndex == 0 && supplyIndex > compInitialIndex) {
if (supplierIndex == 0 && supplyIndex >= compInitialIndex) {
// Covers the case where users supplied tokens before the market's supply state index was set.
// Rewards the user with COMP accrued from the start of when supplier rewards were first
// set for the market.
Expand Down Expand Up @@ -1253,7 +1220,7 @@ contract Comptroller is ComptrollerV6Storage, ComptrollerInterface, ComptrollerE
// Update borrowers's index to the current index since we are distributing accrued COMP
compBorrowerIndex[cToken][borrower] = borrowIndex;

if (borrowerIndex == 0 && borrowIndex > compInitialIndex) {
if (borrowerIndex == 0 && borrowIndex >= compInitialIndex) {
// Covers the case where users borrowed tokens before the market's borrow state index was set.
// Rewards the user with COMP accrued from the start of when borrower rewards were first
// set for the market.
Expand Down Expand Up @@ -1348,6 +1315,18 @@ contract Comptroller is ComptrollerV6Storage, ComptrollerInterface, ComptrollerE
* @return The amount of COMP which was NOT transferred to the user
*/
function grantCompInternal(address user, uint amount) internal returns (uint) {
for (uint i = 0; i < allMarkets.length; ++i) {
address market = address(allMarkets[i]);

bool noOriginalSpeed = compBorrowSpeeds[market] == 0;
bool invalidSupply = noOriginalSpeed && compSupplierIndex[market][user] > 0;
bool invalidBorrow = noOriginalSpeed && compBorrowerIndex[market][user] > 0;

if (invalidSupply || invalidBorrow) {
return amount;
}
}

Comp comp = Comp(getCompAddress());
uint compRemaining = comp.balanceOf(address(this));
if (amount > 0 && amount <= compRemaining) {
Expand Down
Loading