Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aave/aave-v3-periphery
Browse files Browse the repository at this point in the history
  • Loading branch information
kartojal committed Dec 27, 2021
2 parents 0916252 + 6c3b1fd commit d24f24c
Show file tree
Hide file tree
Showing 48 changed files with 1,438 additions and 4,237 deletions.
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'./misc/UiIncentiveDataProvider.sol',
'./misc/UiPoolDataProvider.sol',
'./misc/WalletBalanceProvider.sol',
'./incentives-v2/interfaces/',
'./rewards/interfaces/',
'./misc/interfaces/',
],
onCompileComplete: function () {
Expand Down
28 changes: 17 additions & 11 deletions contracts/misc/UiIncentiveDataProviderV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.10;

import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol';
import {IAaveIncentivesControllerV2} from '../incentives-v2/interfaces/IAaveIncentivesControllerV2.sol';
import {IRewardsController} from '../rewards/interfaces/IRewardsController.sol';
import {IUiIncentiveDataProviderV3} from './interfaces/IUiIncentiveDataProviderV3.sol';
import {IPool} from '@aave/core-v3/contracts/interfaces/IPool.sol';
import {IncentivizedERC20} from '@aave/core-v3/contracts/protocol/tokenization/IncentivizedERC20.sol';
Expand Down Expand Up @@ -52,7 +52,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {

// Get aTokens rewards information
// TODO: check that this is deployed correctly on contract and remove casting
IAaveIncentivesControllerV2 aTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController aTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.aTokenAddress).getIncentivesController())
);
RewardInfo[] memory aRewardsInformation;
Expand All @@ -76,7 +76,9 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
rewardInformation.rewardTokenAddress
);

rewardInformation.precision = aTokenIncentiveController.getAssetDecimals(baseData.aTokenAddress);
rewardInformation.precision = aTokenIncentiveController.getAssetDecimals(
baseData.aTokenAddress
);
rewardInformation.rewardTokenDecimals = IERC20Detailed(
rewardInformation.rewardTokenAddress
).decimals();
Expand Down Expand Up @@ -105,7 +107,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
);

// Get vTokens rewards information
IAaveIncentivesControllerV2 vTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController vTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.variableDebtTokenAddress).getIncentivesController())
);
address[] memory vTokenRewardAddresses = vTokenIncentiveController.getRewardsByAsset(
Expand All @@ -129,7 +131,9 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
rewardInformation.rewardTokenAddress
);

rewardInformation.precision = vTokenIncentiveController.getAssetDecimals(baseData.variableDebtTokenAddress);
rewardInformation.precision = vTokenIncentiveController.getAssetDecimals(
baseData.variableDebtTokenAddress
);
rewardInformation.rewardTokenDecimals = IERC20Detailed(
rewardInformation.rewardTokenAddress
).decimals();
Expand Down Expand Up @@ -158,7 +162,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
);

// Get sTokens rewards information
IAaveIncentivesControllerV2 sTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController sTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.stableDebtTokenAddress).getIncentivesController())
);
address[] memory sTokenRewardAddresses = sTokenIncentiveController.getRewardsByAsset(
Expand All @@ -182,7 +186,9 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
rewardInformation.rewardTokenAddress
);

rewardInformation.precision = sTokenIncentiveController.getAssetDecimals(baseData.stableDebtTokenAddress);
rewardInformation.precision = sTokenIncentiveController.getAssetDecimals(
baseData.stableDebtTokenAddress
);
rewardInformation.rewardTokenDecimals = IERC20Detailed(
rewardInformation.rewardTokenAddress
).decimals();
Expand Down Expand Up @@ -241,7 +247,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
// user reserve data
userReservesIncentivesData[i].underlyingAsset = reserves[i];

IAaveIncentivesControllerV2 aTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController aTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.aTokenAddress).getIncentivesController())
);
if (address(aTokenIncentiveController) != address(0)) {
Expand Down Expand Up @@ -294,7 +300,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
}

// variable debt token
IAaveIncentivesControllerV2 vTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController vTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.variableDebtTokenAddress).getIncentivesController())
);
if (address(vTokenIncentiveController) != address(0)) {
Expand Down Expand Up @@ -347,7 +353,7 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {
}

// stable debt toekn
IAaveIncentivesControllerV2 sTokenIncentiveController = IAaveIncentivesControllerV2(
IRewardsController sTokenIncentiveController = IRewardsController(
address(IncentivizedERC20(baseData.stableDebtTokenAddress).getIncentivesController())
);
if (address(sTokenIncentiveController) != address(0)) {
Expand Down Expand Up @@ -402,4 +408,4 @@ contract UiIncentiveDataProviderV3 is IUiIncentiveDataProviderV3 {

return (userReservesIncentivesData);
}
}
}
6 changes: 3 additions & 3 deletions contracts/mocks/ATokenMock.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.10;

import {IAaveIncentivesControllerV2} from '../incentives-v2/interfaces/IAaveIncentivesControllerV2.sol';
import {IRewardsController} from '../rewards/interfaces/IRewardsController.sol';

contract ATokenMock {
IAaveIncentivesControllerV2 public _aic;
IRewardsController public _aic;
uint256 internal _userBalance;
uint256 internal _totalSupply;
uint256 internal immutable _decimals;
Expand All @@ -17,7 +17,7 @@ contract ATokenMock {
event AssetIndexUpdated(address indexed asset, uint256 index);
event UserIndexUpdated(address indexed user, address indexed asset, uint256 index);

constructor(IAaveIncentivesControllerV2 aic, uint256 decimals) {
constructor(IRewardsController aic, uint256 decimals) {
_aic = aic;
_decimals = decimals;
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/MockBadTransferStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity 0.8.10;

import {ITransferStrategyBase} from '../incentives-v2/interfaces/ITransferStrategyBase.sol';
import {TransferStrategyBase} from '../incentives-v2/transfer-strategies/TransferStrategyBase.sol';
import {ITransferStrategyBase} from '../rewards/interfaces/ITransferStrategyBase.sol';
import {TransferStrategyBase} from '../rewards/transfer-strategies/TransferStrategyBase.sol';
import {GPv2SafeERC20} from '@aave/core-v3/contracts/dependencies/gnosis/contracts/GPv2SafeERC20.sol';
import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ pragma solidity 0.8.10;

import {VersionedInitializable} from '@aave/core-v3/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol';
import {IScaledBalanceToken} from '@aave/core-v3/contracts/interfaces/IScaledBalanceToken.sol';
import {DistributionManagerV2} from './DistributionManagerV2.sol';
import {IAaveIncentivesControllerV2} from './interfaces/IAaveIncentivesControllerV2.sol';
import {RewardsDistributor} from './RewardsDistributor.sol';
import {IRewardsController} from './interfaces/IRewardsController.sol';
import {ITransferStrategyBase} from './interfaces/ITransferStrategyBase.sol';
import {DistributionTypesV2} from './libraries/DistributionTypesV2.sol';
import {RewardsDistributorTypes} from './libraries/RewardsDistributorTypes.sol';
import {IEACAggregatorProxy} from '../misc/interfaces/IEACAggregatorProxy.sol';

/**
* @title IncentivesControllerV2
* @title RewardsController
* @notice Abstract contract template to build Distributors contracts for ERC20 rewards to protocol participants
* @author Aave
**/
contract IncentivesControllerV2 is
DistributionManagerV2,
VersionedInitializable,
IAaveIncentivesControllerV2
{
contract RewardsController is RewardsDistributor, VersionedInitializable, IRewardsController {
uint256 public constant REVISION = 1;

// This mapping allows whitelisted addresses to claim on behalf of others
Expand All @@ -41,14 +37,14 @@ contract IncentivesControllerV2 is
_;
}

constructor(address emissionManager) DistributionManagerV2(emissionManager) {}
constructor(address emissionManager) RewardsDistributor(emissionManager) {}

/**
* @dev Empty initialize for IncentivesControllerV2
* @dev Empty initialize for RewardsController
**/
function initialize() external initializer {}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function getClaimer(address user) external view override returns (address) {
return _authorizedClaimers[user];
}
Expand All @@ -61,18 +57,18 @@ contract IncentivesControllerV2 is
return REVISION;
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function getRewardOracle(address reward) external view override returns (address) {
return address(_rewardOracle[reward]);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function getTransferStrategy(address reward) external view override returns (address) {
return address(_transferStrategy[reward]);
}

/// @inheritdoc IAaveIncentivesControllerV2
function configureAssets(DistributionTypesV2.RewardsConfigInput[] memory config)
/// @inheritdoc IRewardsController
function configureAssets(RewardsDistributorTypes.RewardsConfigInput[] memory config)
external
override
onlyEmissionManager
Expand All @@ -90,23 +86,23 @@ contract IncentivesControllerV2 is
_configureAssets(config);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function setTransferStrategy(address reward, ITransferStrategyBase transferStrategy)
external
onlyEmissionManager
{
_installTransferStrategy(reward, transferStrategy);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function setRewardOracle(address reward, IEACAggregatorProxy rewardOracle)
external
onlyEmissionManager
{
_setRewardOracle(reward, rewardOracle);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function handleAction(
address user,
uint256 totalSupply,
Expand All @@ -115,7 +111,7 @@ contract IncentivesControllerV2 is
_updateUserRewardsPerAssetInternal(msg.sender, user, userBalance, totalSupply);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimRewards(
address[] calldata assets,
uint256 amount,
Expand All @@ -126,7 +122,7 @@ contract IncentivesControllerV2 is
return _claimRewards(assets, amount, msg.sender, msg.sender, to, reward);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
Expand All @@ -139,7 +135,7 @@ contract IncentivesControllerV2 is
return _claimRewards(assets, amount, msg.sender, user, to, reward);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimRewardsToSelf(
address[] calldata assets,
uint256 amount,
Expand All @@ -148,7 +144,7 @@ contract IncentivesControllerV2 is
return _claimRewards(assets, amount, msg.sender, msg.sender, msg.sender, reward);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimAllRewards(address[] calldata assets, address to)
external
override
Expand All @@ -158,7 +154,7 @@ contract IncentivesControllerV2 is
return _claimAllRewards(assets, msg.sender, msg.sender, to);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimAllRewardsOnBehalf(
address[] calldata assets,
address user,
Expand All @@ -174,7 +170,7 @@ contract IncentivesControllerV2 is
return _claimAllRewards(assets, msg.sender, user, to);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function claimAllRewardsToSelf(address[] calldata assets)
external
override
Expand All @@ -183,7 +179,7 @@ contract IncentivesControllerV2 is
return _claimAllRewards(assets, msg.sender, msg.sender, msg.sender);
}

/// @inheritdoc IAaveIncentivesControllerV2
/// @inheritdoc IRewardsController
function setClaimer(address user, address caller) external override onlyEmissionManager {
_authorizedClaimers[user] = caller;
emit ClaimerSet(user, caller);
Expand All @@ -199,9 +195,9 @@ contract IncentivesControllerV2 is
internal
view
override
returns (DistributionTypesV2.UserAssetStatsInput[] memory userState)
returns (RewardsDistributorTypes.UserAssetStatsInput[] memory userState)
{
userState = new DistributionTypesV2.UserAssetStatsInput[](assets.length);
userState = new RewardsDistributorTypes.UserAssetStatsInput[](assets.length);
for (uint256 i = 0; i < assets.length; i++) {
userState[i].underlyingAsset = assets[i];
(userState[i].userBalance, userState[i].totalSupply) = IScaledBalanceToken(assets[i])
Expand Down
Loading

0 comments on commit d24f24c

Please sign in to comment.