aave-protocol-v2/contracts/tokenization/base/DebtTokenBase.sol

145 lines
4.0 KiB
Solidity
Raw Normal View History

2020-06-30 12:09:28 +00:00
pragma solidity ^0.6.0;
import {Context} from '@openzeppelin/contracts/GSN/Context.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
2020-06-30 12:09:28 +00:00
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
import {LendingPool} from '../../lendingpool/LendingPool.sol';
2020-08-18 09:39:34 +00:00
import {
VersionedInitializable
} from '../../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
2020-06-30 12:09:28 +00:00
2020-07-13 08:54:08 +00:00
/**
* @title contract DebtTokenBase
* @author Aave
* @notice base contract for StableDebtToken and VariableDebtToken
*/
2020-08-17 19:28:50 +00:00
abstract contract DebtTokenBase is IERC20, VersionedInitializable {
2020-06-30 12:09:28 +00:00
using SafeMath for uint256;
using Address for address;
uint256 public override totalSupply;
string public name;
string public symbol;
uint8 public decimals;
2020-08-11 07:36:46 +00:00
address public immutable underlyingAssetAddress;
2020-06-30 12:09:28 +00:00
2020-08-11 07:36:46 +00:00
LendingPool internal immutable pool;
2020-06-30 12:09:28 +00:00
mapping(address => uint256) internal balances;
/**
2020-07-13 08:54:08 +00:00
* @dev only lending pool can call functions marked by this modifier
**/
modifier onlyLendingPool {
require(msg.sender == address(pool), 'The caller of this function must be a lending pool');
_;
}
2020-06-30 12:09:28 +00:00
2020-08-18 09:39:34 +00:00
constructor(
address _pool,
address _underlyingAssetAddress,
string memory _name,
string memory _symbol
) public {
2020-08-11 07:36:46 +00:00
pool = LendingPool(payable(_pool));
2020-08-18 09:39:34 +00:00
underlyingAssetAddress = _underlyingAssetAddress;
name = _name;
symbol = _symbol;
2020-08-11 07:36:46 +00:00
}
2020-08-18 09:39:34 +00:00
2020-06-30 12:09:28 +00:00
/**
* @dev initializes the debt token.
* @param _name the name of the token
* @param _symbol the symbol of the token
* @param _decimals the decimals of the token
2020-06-30 12:09:28 +00:00
*/
2020-08-17 19:28:50 +00:00
function initialize(
uint8 _decimals,
2020-06-30 12:09:28 +00:00
string memory _name,
2020-08-17 19:28:50 +00:00
string memory _symbol
) public initializer {
2020-06-30 12:09:28 +00:00
name = _name;
symbol = _symbol;
decimals = _decimals;
}
/**
* @dev calculates the accumulated debt balance of the user
* @return the debt balance of the user
**/
function balanceOf(address _user) public virtual override view returns (uint256);
2020-06-30 12:09:28 +00:00
/**
2020-07-13 08:54:08 +00:00
* @dev returns the principal debt balance of the user from
* @return the debt balance of the user since the last burn/mint action
**/
function principalBalanceOf(address _user) public view returns (uint256) {
return balances[_user];
}
2020-06-30 12:09:28 +00:00
/**
2020-07-13 08:54:08 +00:00
* @dev basic accounting for the mint action
* @dev _user the target user of the minting action
* @dev _amount the amount to mint
**/
function _mint(address _user, uint256 _amount) internal {
totalSupply = totalSupply.add(_amount);
balances[_user] = balances[_user].add(_amount);
}
2020-06-30 12:09:28 +00:00
/**
2020-07-13 08:54:08 +00:00
* @dev basic accounting for the burn action
* @dev _user the target user of the burning action
* @dev _amount the amount to burn
**/
function _burn(address _user, uint256 _amount) internal {
totalSupply = totalSupply.sub(_amount);
balances[_user] = balances[_user].sub(_amount);
2020-06-30 12:09:28 +00:00
}
/**
2020-07-13 08:54:08 +00:00
* @dev being non transferrable, the debt token does not implement any of the
* standard ERC20 functions for transfer and allowance.
**/
function transfer(address recipient, uint256 _amount) public virtual override returns (bool) {
2020-06-30 12:09:28 +00:00
revert('TRANSFER_NOT_SUPPORTED');
}
function allowance(address owner, address spender)
public
virtual
override
view
returns (uint256)
{
revert('ALLOWANCE_NOT_SUPPORTED');
}
function approve(address spender, uint256 _amount) public virtual override returns (bool) {
2020-06-30 12:09:28 +00:00
revert('APPROVAL_NOT_SUPPORTED');
}
function transferFrom(
address sender,
address recipient,
uint256 _amount
2020-06-30 12:09:28 +00:00
) public virtual override returns (bool) {
revert('TRANSFER_NOT_SUPPORTED');
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
revert('ALLOWANCE_NOT_SUPPORTED');
}
function decreaseAllowance(address spender, uint256 subtractedValue)
public
virtual
returns (bool)
{
revert('ALLOWANCE_NOT_SUPPORTED');
}
}