2020-08-20 12:32:20 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
2020-06-30 12:09:28 +00:00
|
|
|
|
2020-07-09 09:59:49 +00:00
|
|
|
import {Context} from '@openzeppelin/contracts/GSN/Context.sol';
|
|
|
|
import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol';
|
2020-06-30 12:09:28 +00:00
|
|
|
import {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';
|
2020-08-20 12:32:20 +00:00
|
|
|
import {ILendingPool} from '../../interfaces/ILendingPool.sol';
|
2020-08-18 09:39:34 +00:00
|
|
|
import {
|
|
|
|
VersionedInitializable
|
|
|
|
} from '../../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
|
2020-09-04 14:27:35 +00:00
|
|
|
import {ERC20} from '../ERC20.sol';
|
2020-09-02 15:54:34 +00:00
|
|
|
import {Errors} from '../../libraries/helpers/Errors.sol';
|
2020-06-30 12:09:28 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
/**
|
2020-09-04 14:27:35 +00:00
|
|
|
* @title DebtTokenBase
|
|
|
|
* @notice Base contract for different types of debt tokens, like StableDebtToken or VariableDebtToken
|
2020-07-13 08:54:08 +00:00
|
|
|
* @author Aave
|
|
|
|
*/
|
|
|
|
|
2020-09-04 14:27:35 +00:00
|
|
|
abstract contract DebtTokenBase is ERC20, VersionedInitializable {
|
|
|
|
address internal immutable UNDERLYING_ASSET;
|
|
|
|
ILendingPool internal immutable POOL;
|
2020-09-04 15:10:32 +00:00
|
|
|
mapping(address => uint256) internal _usersData;
|
2020-06-30 12:09:28 +00:00
|
|
|
|
2020-07-09 09:59:49 +00:00
|
|
|
/**
|
2020-09-04 14:27:35 +00:00
|
|
|
* @dev Only lending pool can call functions marked by this modifier
|
2020-07-13 08:54:08 +00:00
|
|
|
**/
|
2020-07-09 09:59:49 +00:00
|
|
|
modifier onlyLendingPool {
|
2020-09-04 14:27:35 +00:00
|
|
|
require(msg.sender == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL);
|
2020-07-09 09:59:49 +00:00
|
|
|
_;
|
|
|
|
}
|
2020-06-30 12:09:28 +00:00
|
|
|
|
2020-09-09 19:26:52 +00:00
|
|
|
/**
|
2020-09-04 14:27:35 +00:00
|
|
|
* @dev The metadata of the token will be set on the proxy, that the reason of
|
|
|
|
* passing "NULL" and 0 as metadata
|
|
|
|
*/
|
2020-08-18 09:39:34 +00:00
|
|
|
constructor(
|
2020-08-21 10:38:08 +00:00
|
|
|
address pool,
|
|
|
|
address underlyingAssetAddress,
|
|
|
|
string memory name,
|
|
|
|
string memory symbol
|
2020-09-04 14:27:35 +00:00
|
|
|
) public ERC20(name, symbol, 18) {
|
|
|
|
POOL = ILendingPool(pool);
|
|
|
|
UNDERLYING_ASSET = underlyingAssetAddress;
|
2020-08-11 07:36:46 +00:00
|
|
|
}
|
2020-08-18 09:39:34 +00:00
|
|
|
|
2020-06-30 12:09:28 +00:00
|
|
|
/**
|
2020-09-04 14:27:35 +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(
|
2020-08-21 10:38:08 +00:00
|
|
|
uint8 decimals,
|
|
|
|
string memory name,
|
|
|
|
string memory symbol
|
2020-08-17 19:28:50 +00:00
|
|
|
) public initializer {
|
2020-09-04 14:27:35 +00:00
|
|
|
_setName(name);
|
|
|
|
_setSymbol(symbol);
|
|
|
|
_setDecimals(decimals);
|
2020-08-21 10:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function underlyingAssetAddress() public view returns (address) {
|
2020-09-04 14:27:35 +00:00
|
|
|
return UNDERLYING_ASSET;
|
2020-06-30 12:09:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 09:59:49 +00:00
|
|
|
/**
|
2020-09-04 14:27:35 +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
|
2020-07-09 09:59:49 +00:00
|
|
|
**/
|
2020-08-21 10:38:08 +00:00
|
|
|
function principalBalanceOf(address user) public view returns (uint256) {
|
2020-09-04 14:27:35 +00:00
|
|
|
return super.balanceOf(user);
|
2020-06-30 12:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-09-04 14:27:35 +00:00
|
|
|
* @dev Being non transferrable, the debt token does not implement any of the
|
2020-07-13 08:54:08 +00:00
|
|
|
* standard ERC20 functions for transfer and allowance.
|
|
|
|
**/
|
2020-09-04 14:27:35 +00:00
|
|
|
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
|
2020-09-09 19:26:52 +00:00
|
|
|
recipient;
|
|
|
|
amount;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('TRANSFER_NOT_SUPPORTED');
|
|
|
|
}
|
|
|
|
|
|
|
|
function allowance(address owner, address spender)
|
2020-09-09 19:26:52 +00:00
|
|
|
public
|
2020-06-30 12:09:28 +00:00
|
|
|
virtual
|
|
|
|
override
|
|
|
|
view
|
|
|
|
returns (uint256)
|
|
|
|
{
|
2020-09-09 19:26:52 +00:00
|
|
|
owner;
|
|
|
|
spender;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('ALLOWANCE_NOT_SUPPORTED');
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:27:35 +00:00
|
|
|
function approve(address spender, uint256 amount) public virtual override returns (bool) {
|
2020-09-09 19:26:52 +00:00
|
|
|
spender;
|
|
|
|
amount;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('APPROVAL_NOT_SUPPORTED');
|
|
|
|
}
|
|
|
|
|
|
|
|
function transferFrom(
|
|
|
|
address sender,
|
|
|
|
address recipient,
|
2020-08-21 10:38:08 +00:00
|
|
|
uint256 amount
|
2020-09-09 19:26:52 +00:00
|
|
|
) public virtual override returns (bool) {
|
|
|
|
sender;
|
|
|
|
recipient;
|
|
|
|
amount;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('TRANSFER_NOT_SUPPORTED');
|
|
|
|
}
|
|
|
|
|
2020-09-09 19:26:52 +00:00
|
|
|
function increaseAllowance(address spender, uint256 addedValue)
|
|
|
|
public
|
|
|
|
virtual
|
|
|
|
override
|
|
|
|
returns (bool)
|
|
|
|
{
|
|
|
|
spender;
|
|
|
|
addedValue;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('ALLOWANCE_NOT_SUPPORTED');
|
|
|
|
}
|
|
|
|
|
|
|
|
function decreaseAllowance(address spender, uint256 subtractedValue)
|
2020-09-09 19:26:52 +00:00
|
|
|
public
|
2020-06-30 12:09:28 +00:00
|
|
|
virtual
|
2020-09-09 19:26:52 +00:00
|
|
|
override
|
2020-06-30 12:09:28 +00:00
|
|
|
returns (bool)
|
|
|
|
{
|
2020-09-09 19:26:52 +00:00
|
|
|
spender;
|
|
|
|
subtractedValue;
|
2020-06-30 12:09:28 +00:00
|
|
|
revert('ALLOWANCE_NOT_SUPPORTED');
|
|
|
|
}
|
2020-08-20 14:26:06 +00:00
|
|
|
|
|
|
|
/**
|
2020-09-04 14:27:35 +00:00
|
|
|
* @dev Calculates the increase in balance since the last user interaction
|
|
|
|
* @param user The address of the user for which the interest is being accumulated
|
|
|
|
* @return The previous principal balance, the new principal balance, the balance increase
|
2020-08-20 14:26:06 +00:00
|
|
|
* and the new user index
|
|
|
|
**/
|
2020-08-21 10:38:08 +00:00
|
|
|
function _calculateBalanceIncrease(address user)
|
2020-08-20 14:26:06 +00:00
|
|
|
internal
|
|
|
|
view
|
|
|
|
returns (
|
|
|
|
uint256,
|
|
|
|
uint256,
|
|
|
|
uint256
|
|
|
|
)
|
|
|
|
{
|
2020-09-04 14:27:35 +00:00
|
|
|
uint256 previousPrincipalBalance = principalBalanceOf(user);
|
2020-08-20 14:26:06 +00:00
|
|
|
|
|
|
|
if (previousPrincipalBalance == 0) {
|
|
|
|
return (0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:27:35 +00:00
|
|
|
// Calculation of the accrued interest since the last accumulation
|
2020-08-21 10:38:08 +00:00
|
|
|
uint256 balanceIncrease = balanceOf(user).sub(previousPrincipalBalance);
|
2020-08-20 14:26:06 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
previousPrincipalBalance,
|
|
|
|
previousPrincipalBalance.add(balanceIncrease),
|
|
|
|
balanceIncrease
|
|
|
|
);
|
|
|
|
}
|
2020-06-30 12:09:28 +00:00
|
|
|
}
|