forked from aave/aave-v3-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VariableDebtToken.sol
155 lines (132 loc) · 4.93 KB
/
VariableDebtToken.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {SafeCast} from '../../dependencies/openzeppelin/contracts/SafeCast.sol';
import {VersionedInitializable} from '../libraries/aave-upgradeability/VersionedInitializable.sol';
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {Errors} from '../libraries/helpers/Errors.sol';
import {IPool} from '../../interfaces/IPool.sol';
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
import {IInitializableDebtToken} from '../../interfaces/IInitializableDebtToken.sol';
import {IVariableDebtToken} from '../../interfaces/IVariableDebtToken.sol';
import {EIP712Base} from './base/EIP712Base.sol';
import {DebtTokenBase} from './base/DebtTokenBase.sol';
import {ScaledBalanceTokenBase} from './base/ScaledBalanceTokenBase.sol';
/**
* @title VariableDebtToken
* @author Aave
* @notice Implements a variable debt token to track the borrowing positions of users
* at variable rate mode
* @dev Transfer and approve functionalities are disabled since its a non-transferable token
*/
contract VariableDebtToken is DebtTokenBase, ScaledBalanceTokenBase, IVariableDebtToken {
using WadRayMath for uint256;
using SafeCast for uint256;
uint256 public constant DEBT_TOKEN_REVISION = 0x1;
/**
* @dev Constructor.
* @param pool The address of the Pool contract
*/
constructor(
IPool pool
)
DebtTokenBase()
ScaledBalanceTokenBase(pool, 'VARIABLE_DEBT_TOKEN_IMPL', 'VARIABLE_DEBT_TOKEN_IMPL', 0)
{
// Intentionally left blank
}
/// @inheritdoc IInitializableDebtToken
function initialize(
IPool initializingPool,
address underlyingAsset,
IAaveIncentivesController incentivesController,
uint8 debtTokenDecimals,
string memory debtTokenName,
string memory debtTokenSymbol,
bytes calldata params
) external override initializer {
require(initializingPool == POOL, Errors.POOL_ADDRESSES_DO_NOT_MATCH);
_setName(debtTokenName);
_setSymbol(debtTokenSymbol);
_setDecimals(debtTokenDecimals);
_underlyingAsset = underlyingAsset;
_incentivesController = incentivesController;
_domainSeparator = _calculateDomainSeparator();
emit Initialized(
underlyingAsset,
address(POOL),
address(incentivesController),
debtTokenDecimals,
debtTokenName,
debtTokenSymbol,
params
);
}
/// @inheritdoc VersionedInitializable
function getRevision() internal pure virtual override returns (uint256) {
return DEBT_TOKEN_REVISION;
}
/// @inheritdoc IERC20
function balanceOf(address user) public view virtual override returns (uint256) {
uint256 scaledBalance = super.balanceOf(user);
if (scaledBalance == 0) {
return 0;
}
return scaledBalance.rayMul(POOL.getReserveNormalizedVariableDebt(_underlyingAsset));
}
/// @inheritdoc IVariableDebtToken
function mint(
address user,
address onBehalfOf,
uint256 amount,
uint256 index
) external virtual override onlyPool returns (bool, uint256) {
if (user != onBehalfOf) {
_decreaseBorrowAllowance(onBehalfOf, user, amount);
}
return (_mintScaled(user, onBehalfOf, amount, index), scaledTotalSupply());
}
/// @inheritdoc IVariableDebtToken
function burn(
address from,
uint256 amount,
uint256 index
) external virtual override onlyPool returns (uint256) {
_burnScaled(from, address(0), amount, index);
return scaledTotalSupply();
}
/// @inheritdoc IERC20
function totalSupply() public view virtual override returns (uint256) {
return super.totalSupply().rayMul(POOL.getReserveNormalizedVariableDebt(_underlyingAsset));
}
/// @inheritdoc EIP712Base
function _EIP712BaseId() internal view override returns (string memory) {
return name();
}
/**
* @dev Being non transferrable, the debt token does not implement any of the
* standard ERC20 functions for transfer and allowance.
*/
function transfer(address, uint256) external virtual override returns (bool) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
function allowance(address, address) external view virtual override returns (uint256) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
function approve(address, uint256) external virtual override returns (bool) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
function transferFrom(address, address, uint256) external virtual override returns (bool) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
function increaseAllowance(address, uint256) external virtual override returns (bool) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
function decreaseAllowance(address, uint256) external virtual override returns (bool) {
revert(Errors.OPERATION_NOT_SUPPORTED);
}
/// @inheritdoc IVariableDebtToken
function UNDERLYING_ASSET_ADDRESS() external view override returns (address) {
return _underlyingAsset;
}
}