Skip to content

Commit

Permalink
feat: added setIncentivesController
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Oct 12, 2021
1 parent 63f0779 commit 8c027f4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
10 changes: 4 additions & 6 deletions contracts/protocol/tokenization/AToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import {IncentivizedERC20} from './IncentivizedERC20.sol';
* @author Aave
* @notice Implementation of the interest bearing token for the Aave protocol
*/
contract AToken is
VersionedInitializable,
IncentivizedERC20('ATOKEN_IMPL', 'ATOKEN_IMPL', 0),
IAToken
{
contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
using WadRayMath for uint256;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -54,7 +50,9 @@ contract AToken is
return ATOKEN_REVISION;
}

constructor(IPool pool) {
constructor(IPool pool)
IncentivizedERC20(pool.getAddressesProvider(), 'ATOKEN_IMPL', 'ATOKEN_IMPL', 0)
{
_pool = pool;
}

Expand Down
20 changes: 20 additions & 0 deletions contracts/protocol/tokenization/IncentivizedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {IERC20Detailed} from '../../dependencies/openzeppelin/contracts/IERC20De
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
import {Helpers} from '../libraries/helpers/Helpers.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IACLManager} from '../../interfaces/IACLManager.sol';
import {Errors} from '../libraries/helpers/Errors.sol';

/**
* @title IncentivizedERC20
Expand All @@ -16,6 +19,12 @@ import {WadRayMath} from '../libraries/math/WadRayMath.sol';
abstract contract IncentivizedERC20 is Context, IERC20, IERC20Detailed {
using WadRayMath for uint256;

modifier onlyPoolAdmins() {
IACLManager aclManager = IACLManager(_addressesProvider.getACLManager());
require(aclManager.isPoolAdmin(msg.sender), Errors.CALLER_NOT_POOL_ADMIN);
_;
}

/**
* @dev UserState - additionalData is a flexible field.
* ATokens and VariableDebtTokens use this field store the index of the
Expand All @@ -34,12 +43,15 @@ abstract contract IncentivizedERC20 is Context, IERC20, IERC20Detailed {
string private _symbol;
uint8 private _decimals;
IAaveIncentivesController internal _incentivesController;
IPoolAddressesProvider internal _addressesProvider;

constructor(
IPoolAddressesProvider addressesProvider,
string memory name,
string memory symbol,
uint8 decimals
) {
_addressesProvider = addressesProvider;
_name = name;
_symbol = symbol;
_decimals = decimals;
Expand Down Expand Up @@ -78,6 +90,14 @@ abstract contract IncentivizedERC20 is Context, IERC20, IERC20Detailed {
return _incentivesController;
}

/**
* @notice Sets a new incentives controller
* @param controller the new Incentives controller
**/
function setIncentivesController(IAaveIncentivesController controller) external onlyPoolAdmins {
_incentivesController = controller;
}

/// @inheritdoc IERC20
function transfer(address recipient, uint256 amount) external virtual override returns (bool) {
uint128 castAmount = Helpers.castUint128(amount);
Expand Down
5 changes: 4 additions & 1 deletion contracts/protocol/tokenization/StableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IInitializableDebtToken} from '../../interfaces/IInitializableDebtToken.
import {IStableDebtToken} from '../../interfaces/IStableDebtToken.sol';
import {IPool} from '../../interfaces/IPool.sol';
import {DebtTokenBase} from './base/DebtTokenBase.sol';
import {IncentivizedERC20} from './IncentivizedERC20.sol';

/**
* @title StableDebtToken
Expand All @@ -31,7 +32,9 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
IPool internal immutable _pool;
address internal _underlyingAsset;

constructor(IPool pool) {
constructor(IPool pool)
IncentivizedERC20(pool.getAddressesProvider(), 'DEBT_TOKEN_IMPL', 'DEBT_TOKEN_IMPL', 0)
{
_pool = pool;
}

Expand Down
5 changes: 4 additions & 1 deletion contracts/protocol/tokenization/VariableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {IInitializableDebtToken} from '../../interfaces/IInitializableDebtToken.
import {IVariableDebtToken} from '../../interfaces/IVariableDebtToken.sol';
import {IScaledBalanceToken} from '../../interfaces/IScaledBalanceToken.sol';
import {DebtTokenBase} from './base/DebtTokenBase.sol';
import {IncentivizedERC20} from './IncentivizedERC20.sol';

/**
* @title VariableDebtToken
Expand All @@ -27,7 +28,9 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
IPool internal immutable _pool;
address internal _underlyingAsset;

constructor(IPool pool) {
constructor(IPool pool)
IncentivizedERC20(pool.getAddressesProvider(), 'DEBT_TOKEN_IMPL', 'DEBT_TOKEN_IMPL', 0)
{
_pool = pool;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/tokenization/base/DebtTokenBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {IncentivizedERC20} from '../IncentivizedERC20.sol';
* @dev Transfer and approve functionalities are disabled since its a non-transferable token.
*/
abstract contract DebtTokenBase is
IncentivizedERC20('DEBTTOKEN_IMPL', 'DEBTTOKEN_IMPL', 0),
IncentivizedERC20,
VersionedInitializable,
ICreditDelegationToken
{
Expand Down

0 comments on commit 8c027f4

Please sign in to comment.