-
Notifications
You must be signed in to change notification settings - Fork 587
/
Copy pathMintableIncentivizedERC20.sol
66 lines (57 loc) · 2.25 KB
/
MintableIncentivizedERC20.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.10;
import {IAaveIncentivesController} from '../../../interfaces/IAaveIncentivesController.sol';
import {IPool} from '../../../interfaces/IPool.sol';
import {IncentivizedERC20} from './IncentivizedERC20.sol';
/**
* @title MintableIncentivizedERC20
* @author Aave
* @notice Implements mint and burn functions for IncentivizedERC20
**/
abstract contract MintableIncentivizedERC20 is IncentivizedERC20 {
/**
* @dev Constructor.
* @param pool The reference to the main Pool contract
* @param name The name of the token
* @param symbol The symbol of the token
* @param decimals The number of decimals of the token
*/
constructor(
IPool pool,
string memory name,
string memory symbol,
uint8 decimals
) IncentivizedERC20(pool, name, symbol, decimals) {
// Intentionally left blank
}
/**
* @notice Mints tokens to an account and apply incentives if defined
* @param account The address receiving tokens
* @param amount The amount of tokens to mint
*/
function _mint(address account, uint128 amount) internal virtual {
uint256 oldTotalSupply = _totalSupply;
_totalSupply = oldTotalSupply + amount;
uint128 oldAccountBalance = _userState[account].balance;
_userState[account].balance = oldAccountBalance + amount;
IAaveIncentivesController incentivesControllerLocal = _incentivesController;
if (address(incentivesControllerLocal) != address(0)) {
incentivesControllerLocal.handleAction(account, oldTotalSupply, oldAccountBalance);
}
}
/**
* @notice Burns tokens from an account and apply incentives if defined
* @param account The account whose tokens are burnt
* @param amount The amount of tokens to burn
*/
function _burn(address account, uint128 amount) internal virtual {
uint256 oldTotalSupply = _totalSupply;
_totalSupply = oldTotalSupply - amount;
uint128 oldAccountBalance = _userState[account].balance;
_userState[account].balance = oldAccountBalance - amount;
IAaveIncentivesController incentivesControllerLocal = _incentivesController;
if (address(incentivesControllerLocal) != address(0)) {
incentivesControllerLocal.handleAction(account, oldTotalSupply, oldAccountBalance);
}
}
}