@@ -51,7 +51,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
51
51
event MarketComped (CToken cToken , bool isComped );
52
52
53
53
/// @notice Emitted when COMP rate is changed
54
- event NewCompRate (uint oldCompRateMantissa , uint newCompRateMantissa );
54
+ event NewCompRate (uint oldCompRate , uint newCompRate );
55
55
56
56
/// @notice Emitted when a new COMP speed is calculated for a market
57
57
event CompSpeedUpdated (CToken indexed cToken , uint newSpeed );
@@ -247,7 +247,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
247
247
248
248
// Keep the flywheel moving
249
249
updateCompSupplyIndex (cToken);
250
- distributeSupplierComp (cToken, minter);
250
+ distributeSupplierComp (cToken, minter, false );
251
251
252
252
return uint (Error.NO_ERROR);
253
253
}
@@ -287,7 +287,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
287
287
288
288
// Keep the flywheel moving
289
289
updateCompSupplyIndex (cToken);
290
- distributeSupplierComp (cToken, redeemer);
290
+ distributeSupplierComp (cToken, redeemer, false );
291
291
292
292
return uint (Error.NO_ERROR);
293
293
}
@@ -376,7 +376,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
376
376
// Keep the flywheel moving
377
377
Exp memory borrowIndex = Exp ({mantissa: CToken (cToken).borrowIndex ()});
378
378
updateCompBorrowIndex (cToken, borrowIndex);
379
- distributeBorrowerComp (cToken, borrower, borrowIndex);
379
+ distributeBorrowerComp (cToken, borrower, borrowIndex, false );
380
380
381
381
return uint (Error.NO_ERROR);
382
382
}
@@ -424,7 +424,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
424
424
// Keep the flywheel moving
425
425
Exp memory borrowIndex = Exp ({mantissa: CToken (cToken).borrowIndex ()});
426
426
updateCompBorrowIndex (cToken, borrowIndex);
427
- distributeBorrowerComp (cToken, borrower, borrowIndex);
427
+ distributeBorrowerComp (cToken, borrower, borrowIndex, false );
428
428
429
429
return uint (Error.NO_ERROR);
430
430
}
@@ -557,8 +557,8 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
557
557
558
558
// Keep the flywheel moving
559
559
updateCompSupplyIndex (cTokenCollateral);
560
- distributeSupplierComp (cTokenCollateral, borrower);
561
- distributeSupplierComp (cTokenCollateral, liquidator);
560
+ distributeSupplierComp (cTokenCollateral, borrower, false );
561
+ distributeSupplierComp (cTokenCollateral, liquidator, false );
562
562
563
563
return uint (Error.NO_ERROR);
564
564
}
@@ -611,8 +611,8 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
611
611
612
612
// Keep the flywheel moving
613
613
updateCompSupplyIndex (cToken);
614
- distributeSupplierComp (cToken, src);
615
- distributeSupplierComp (cToken, dst);
614
+ distributeSupplierComp (cToken, src, false );
615
+ distributeSupplierComp (cToken, dst, false );
616
616
617
617
return uint (Error.NO_ERROR);
618
618
}
@@ -1110,7 +1110,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1110
1110
return msg .sender == admin || msg .sender == comptrollerImplementation;
1111
1111
}
1112
1112
1113
- /*** Comp Flywheel Distribution ***/
1113
+ /*** Comp Distribution ***/
1114
1114
1115
1115
/**
1116
1116
* @notice Recalculate and update COMP speeds for all COMP markets
@@ -1197,7 +1197,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1197
1197
* @param cToken The market in which the supplier is interacting
1198
1198
* @param supplier The address of the supplier to distribute COMP to
1199
1199
*/
1200
- function distributeSupplierComp (address cToken , address supplier ) internal {
1200
+ function distributeSupplierComp (address cToken , address supplier , bool distributeAll ) internal {
1201
1201
CompMarketState storage supplyState = compSupplyState[cToken];
1202
1202
Double memory supplyIndex = Double ({mantissa: supplyState.index});
1203
1203
Double memory supplierIndex = Double ({mantissa: compSupplierIndex[cToken][supplier]});
@@ -1211,7 +1211,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1211
1211
uint supplierTokens = CToken (cToken).balanceOf (supplier);
1212
1212
uint supplierDelta = mul_ (supplierTokens, deltaIndex);
1213
1213
uint supplierAccrued = add_ (compAccrued[supplier], supplierDelta);
1214
- compAccrued[supplier] = transferComp (supplier, supplierAccrued, compClaimThreshold);
1214
+ compAccrued[supplier] = transferComp (supplier, supplierAccrued, distributeAll ? 0 : compClaimThreshold);
1215
1215
emit DistributedSupplierComp (CToken (cToken), supplier, supplierDelta, supplyIndex.mantissa);
1216
1216
}
1217
1217
@@ -1221,7 +1221,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1221
1221
* @param cToken The market in which the borrower is interacting
1222
1222
* @param borrower The address of the borrower to distribute COMP to
1223
1223
*/
1224
- function distributeBorrowerComp (address cToken , address borrower , Exp memory marketBorrowIndex ) internal {
1224
+ function distributeBorrowerComp (address cToken , address borrower , Exp memory marketBorrowIndex , bool distributeAll ) internal {
1225
1225
CompMarketState storage borrowState = compBorrowState[cToken];
1226
1226
Double memory borrowIndex = Double ({mantissa: borrowState.index});
1227
1227
Double memory borrowerIndex = Double ({mantissa: compBorrowerIndex[cToken][borrower]});
@@ -1232,7 +1232,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1232
1232
uint borrowerAmount = div_ (CToken (cToken).borrowBalanceStored (borrower), marketBorrowIndex);
1233
1233
uint borrowerDelta = mul_ (borrowerAmount, deltaIndex);
1234
1234
uint borrowerAccrued = add_ (compAccrued[borrower], borrowerDelta);
1235
- compAccrued[borrower] = transferComp (borrower, borrowerAccrued, compClaimThreshold);
1235
+ compAccrued[borrower] = transferComp (borrower, borrowerAccrued, distributeAll ? 0 : compClaimThreshold);
1236
1236
emit DistributedBorrowerComp (CToken (cToken), borrower, borrowerDelta, borrowIndex.mantissa);
1237
1237
}
1238
1238
}
@@ -1245,7 +1245,7 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1245
1245
* @return The amount of COMP which was NOT transferred to the user
1246
1246
*/
1247
1247
function transferComp (address user , uint userAccrued , uint threshold ) internal returns (uint ) {
1248
- if (userAccrued >= threshold) {
1248
+ if (userAccrued >= threshold && userAccrued > 0 ) {
1249
1249
Comp comp = Comp (getCompAddress ());
1250
1250
uint compRemaining = comp.balanceOf (address (this ));
1251
1251
if (userAccrued <= compRemaining) {
@@ -1257,24 +1257,52 @@ contract Comptroller is ComptrollerV3Storage, ComptrollerInterface, ComptrollerE
1257
1257
}
1258
1258
1259
1259
/**
1260
- * @notice Claim all the comp accrued by holder
1261
- * @param holder The address to claim comp for
1260
+ * @notice Claim all the comp accrued by holder in all markets
1261
+ * @param holder The address to claim COMP for
1262
1262
*/
1263
1263
function claimComp (address holder ) public {
1264
- refreshCompSpeeds ();
1264
+ return claimComp (holder, allMarkets);
1265
+ }
1265
1266
1266
- CToken[] memory allMarkets_ = allMarkets;
1267
- for (uint i = 0 ; i < allMarkets_.length ; i++ ) {
1268
- CToken cToken = allMarkets_[i];
1269
- Exp memory borrowIndex = Exp ({mantissa: cToken.borrowIndex ()});
1270
- distributeSupplierComp (address (cToken), holder);
1271
- distributeBorrowerComp (address (cToken), holder, borrowIndex);
1272
- }
1267
+ /**
1268
+ * @notice Claim all the comp accrued by holder in the specified markets
1269
+ * @param holder The address to claim COMP for
1270
+ * @param cTokens The list of markets to claim COMP in
1271
+ */
1272
+ function claimComp (address holder , CToken[] memory cTokens ) public {
1273
+ address [] memory holders = new address [](1 );
1274
+ holders[0 ] = holder;
1275
+ claimComp (holders, cTokens, true , true );
1276
+ }
1273
1277
1274
- compAccrued[holder] = transferComp (holder, compAccrued[holder], 0 );
1278
+ /**
1279
+ * @notice Claim all comp accrued by the holders
1280
+ * @param holders The addresses to claim COMP for
1281
+ * @param cTokens The list of markets to claim COMP in
1282
+ * @param borrowers Whether or not to claim COMP earned by borrowing
1283
+ * @param suppliers Whether or not to claim COMP earned by supplying
1284
+ */
1285
+ function claimComp (address [] memory holders , CToken[] memory cTokens , bool borrowers , bool suppliers ) public {
1286
+ for (uint i = 0 ; i < cTokens.length ; i++ ) {
1287
+ CToken cToken = cTokens[i];
1288
+ require (markets[address (cToken)].isListed, "market must be listed " );
1289
+ if (borrowers == true ) {
1290
+ Exp memory borrowIndex = Exp ({mantissa: cToken.borrowIndex ()});
1291
+ updateCompBorrowIndex (address (cToken), borrowIndex);
1292
+ for (uint j = 0 ; j < holders.length ; j++ ) {
1293
+ distributeBorrowerComp (address (cToken), holders[j], borrowIndex, true );
1294
+ }
1295
+ }
1296
+ if (suppliers == true ) {
1297
+ updateCompSupplyIndex (address (cToken));
1298
+ for (uint j = 0 ; j < holders.length ; j++ ) {
1299
+ distributeSupplierComp (address (cToken), holders[j], true );
1300
+ }
1301
+ }
1302
+ }
1275
1303
}
1276
1304
1277
- /*** Comp Flyhwheel Admin ***/
1305
+ /*** Comp Distribution Admin ***/
1278
1306
1279
1307
/**
1280
1308
* @notice Set the amount of COMP distributed per block
0 commit comments