Skip to content

Commit

Permalink
review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Jun 29, 2023
1 parent 7cf125b commit 502d8a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions contracts/plugins/assets/erc20/RewardableERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@ abstract contract RewardableERC20 is IRewardable, ERC20 {
mapping(address => uint256) public accumulatedRewards; // {qRewards}
mapping(address => uint256) public claimedRewards; // {qRewards}

// Keep an internal balance of reward token.
// By tracking it internally we can correctly distribute it in case
// where the token is transferred to this contract directly to the contract.
// This would allow the RewardsVault to handle two cases:
// 1. The main use case would be if a protocol does a direct airdrop.
// It is actually somewhat common for low-fee protocol to just send you a reward directly.
// 2. The protocol supports allows anyone to claim rewards on behalf of someone else. As
// is the case with Morpho.
// Used to keep track of how many reward the Vault has accumulated
// Whenever _claimAndSyncRewards() is called we will calculate the difference
// between the current balance and `previousBalance` to figure out how much to distribute
uint256 internal previousBalance = 0;

/// @dev Extending class must ensure ERC20 constructor is called
Expand Down Expand Up @@ -94,9 +89,13 @@ abstract contract RewardableERC20 is IRewardable, ERC20 {
if (claimableRewards == 0) {
return;
}

emit RewardsClaimed(IERC20(address(rewardToken)), claimableRewards);
claimedRewards[account] = accumulatedRewards[account];
rewardToken.safeTransfer(account, claimableRewards);

// If totalSupply() == 0 and someone with claimable rewards calls claim rewards
// we could possibly end up having unaccounted reward tokens in the contract.
previousBalance = rewardToken.balanceOf(address(this));
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/plugins/assets/morpho-aave/IMorpho.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BlueOak-1.0.0
pragma solidity 0.8.19;

import { IERC20Metadata, RewardableERC4626Vault } from "../erc20/RewardableERC4626Vault.sol";
import { IERC20Metadata } from "../erc20/RewardableERC4626Vault.sol";
import { IERC4626 } from "../../../vendor/oz/IERC4626.sol";

interface IMorpho {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const collateralSpecificStatusTests = () => {}
const beforeEachRewardsTest = async () => {}

export const defaultCollateralOpts: MAFiatCollateralOpts = {
targetName: ethers.utils.formatBytes32String('WBTC'),
targetName: ethers.utils.formatBytes32String('BTC'),
underlyingToken: networkConfig[1].tokens.WBTC!,
poolToken: networkConfig[1].tokens.aWBTC!,
priceTimeout: PRICE_TIMEOUT,
Expand Down

0 comments on commit 502d8a7

Please sign in to comment.