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

168 lines
4.5 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: agpl-3.0
2020-11-20 10:45:20 +00:00
pragma solidity 0.6.12;
2020-06-30 12:09:28 +00:00
import {ILendingPool} from '../../../interfaces/ILendingPool.sol';
import {ICreditDelegationToken} from '../../../interfaces/ICreditDelegationToken.sol';
2020-08-18 09:39:34 +00:00
import {
VersionedInitializable
2020-10-15 13:16:05 +00:00
} from '../../libraries/aave-upgradeability/VersionedInitializable.sol';
2020-09-15 15:08:28 +00:00
import {IncentivizedERC20} from '../IncentivizedERC20.sol';
import {Errors} from '../../libraries/helpers/Errors.sol';
2020-06-30 12:09:28 +00:00
2020-07-13 08:54:08 +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
*/
abstract contract DebtTokenBase is
IncentivizedERC20,
VersionedInitializable,
ICreditDelegationToken
{
address public immutable UNDERLYING_ASSET_ADDRESS;
ILendingPool public immutable POOL;
2020-11-03 18:47:57 +00:00
mapping(address => mapping(address => uint256)) internal _borrowAllowances;
2020-06-30 12:09:28 +00:00
/**
* @dev Only lending pool can call functions marked by this modifier
2020-07-13 08:54:08 +00:00
**/
modifier onlyLendingPool {
2020-11-12 12:54:23 +00:00
require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_LENDING_POOL);
_;
}
2020-06-30 12:09:28 +00:00
2020-09-09 19:26:52 +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(
address pool,
address underlyingAssetAddress,
string memory name,
2020-09-15 13:53:20 +00:00
string memory symbol,
address incentivesController
2020-09-15 15:08:28 +00:00
) public IncentivizedERC20(name, symbol, 18, incentivesController) {
POOL = ILendingPool(pool);
UNDERLYING_ASSET_ADDRESS = 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
/**
* @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,
string memory name,
string memory symbol
2020-08-17 19:28:50 +00:00
) public initializer {
_setName(name);
_setSymbol(symbol);
_setDecimals(decimals);
}
2020-11-03 18:47:57 +00:00
/**
* @dev delegates borrowing power to a user on the specific debt token
* @param delegatee the address receiving the delegated borrowing power
* @param amount the maximum amount being delegated. Delegation will still
* respect the liquidation constraints (even if delegated, a delegatee cannot
* force a delegator HF to go below 1)
**/
function approveDelegation(address delegatee, uint256 amount) external override {
2020-11-03 18:47:57 +00:00
_borrowAllowances[_msgSender()][delegatee] = amount;
emit BorrowAllowanceDelegated(_msgSender(), delegatee, UNDERLYING_ASSET_ADDRESS, amount);
}
/**
* @dev returns the borrow allowance of the user
* @param fromUser The user to giving allowance
* @param toUser The user to give allowance to
* @return the current allowance of toUser
**/
function borrowAllowance(address fromUser, address toUser)
external
view
override
returns (uint256)
{
2020-11-03 18:47:57 +00:00
return _borrowAllowances[fromUser][toUser];
}
2020-06-30 12:09:28 +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.
**/
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
view
2020-06-30 12:09:28 +00:00
virtual
override
returns (uint256)
{
2020-09-09 19:26:52 +00:00
owner;
spender;
2020-06-30 12:09:28 +00:00
revert('ALLOWANCE_NOT_SUPPORTED');
}
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,
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-11-03 18:47:57 +00:00
function _decreaseBorrowAllowance(
address delegator,
address delegatee,
uint256 amount
) internal {
uint256 newAllowance =
_borrowAllowances[delegator][delegatee].sub(amount, Errors.BORROW_ALLOWANCE_NOT_ENOUGH);
2020-11-03 18:47:57 +00:00
_borrowAllowances[delegator][delegatee] = newAllowance;
emit BorrowAllowanceDelegated(delegator, delegatee, UNDERLYING_ASSET_ADDRESS, newAllowance);
}
2020-06-30 12:09:28 +00:00
}