Skip to content

Commit

Permalink
more efficient claiming compoundv2
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Oct 30, 2023
1 parent 6a8fae6 commit 8aa6a50
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion contracts/plugins/assets/compoundv2/CTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ contract CTokenWrapper is RewardableERC20Wrapper {
// === Overrides ===

function _claimAssetRewards() internal virtual override {
address[] memory holders = new address[](1);
address[] memory cTokens = new address[](1);
holders[0] = address(this);
cTokens[0] = address(underlying);
comptroller.claimComp(address(this), cTokens);
comptroller.claimComp(holders, cTokens, false, true);
}

// No overrides of _deposit()/_withdraw() necessary: no staking required
Expand Down
7 changes: 6 additions & 1 deletion contracts/plugins/assets/compoundv2/ICToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ interface ICToken is IERC20Metadata {

interface IComptroller {
/// Claim comp for an account, to an account
function claimComp(address account, address[] memory cTokens) external;
function claimComp(
address[] memory holders,
address[] memory cTokens,
bool borrowers,
bool suppliers
) external;

/// @return The address for COMP token
function getCompAddress() external view returns (address);
Expand Down
4 changes: 3 additions & 1 deletion contracts/plugins/mocks/CTokenWrapperMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ contract CTokenWrapperMock is ERC20Mock, IRewardable {
revert("reverting claim rewards");
}
uint256 oldBal = comp.balanceOf(msg.sender);
address[] memory holders = new address[](1);
address[] memory cTokens = new address[](1);
holders[0] = msg.sender;
cTokens[0] = address(underlying);
comptroller.claimComp(msg.sender, cTokens);
comptroller.claimComp(holders, cTokens, false, true);
emit RewardsClaimed(IERC20(address(comp)), comp.balanceOf(msg.sender) - oldBal);
}

Expand Down
8 changes: 7 additions & 1 deletion contracts/plugins/mocks/ComptrollerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ contract ComptrollerMock is IComptroller {
compBalances[recipient] = amount;
}

function claimComp(address holder, address[] memory) external {
function claimComp(
address[] memory holders,
address[] memory,
bool,
bool
) external {
// Mint amount and update internal balances
address holder = holders[0];
if (address(compToken) != address(0)) {
uint256 amount = compBalances[holder];
compBalances[holder] = 0;
Expand Down

0 comments on commit 8aa6a50

Please sign in to comment.