Initial commit

This commit is contained in:
emilio 2020-08-07 18:23:52 +02:00
parent d8dd838d85
commit a0bf692373
3 changed files with 42 additions and 26 deletions

View File

@ -4,11 +4,12 @@ pragma experimental ABIEncoderV2;
import '@openzeppelin/contracts/math/SafeMath.sol';
import '../interfaces/IERC20Detailed.sol';
import '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import '../libraries/ReserveConfiguration.sol';
import '../configuration/LendingPoolAddressesProvider.sol';
import '../tokenization/AToken.sol';
import '../libraries/openzeppelin-upgradeability/InitializableAdminUpgradeabilityProxy.sol';
import {LendingPool} from './LendingPool.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
/**
* @title LendingPoolConfigurator contract
@ -171,19 +172,14 @@ contract LendingPoolConfigurator is VersionedInitializable {
function initReserve(
address _reserve,
uint8 _underlyingAssetDecimals,
address _aTokenInstance,
address _interestRateStrategyAddress,
address _stableDebtTokenAddress,
address _variableDebtTokenAddress
) external onlyLendingPoolManager {
string memory aTokenName = string(
abi.encodePacked('Aave Interest bearing ', IERC20Detailed(_reserve).name())
);
string memory aTokenSymbol = string(abi.encodePacked('a', IERC20Detailed(_reserve).symbol()));
initReserveWithData(
_reserve,
aTokenName,
aTokenSymbol,
_aTokenInstance,
_stableDebtTokenAddress,
_variableDebtTokenAddress,
_underlyingAssetDecimals,
@ -194,31 +190,35 @@ contract LendingPoolConfigurator is VersionedInitializable {
/**
* @dev initializes a reserve using aTokenData provided externally (useful if the underlying ERC20 contract doesn't expose name or decimals)
* @param _reserve the address of the reserve to be initialized
* @param _aTokenName the name of the aToken contract
* @param _aTokenSymbol the symbol of the aToken contract
* @param _aTokenInstance the name of the aToken contract
* @param _underlyingAssetDecimals the decimals of the reserve underlying asset
* @param _interestRateStrategyAddress the address of the interest rate strategy contract for this reserve
**/
function initReserveWithData(
address _reserve,
string memory _aTokenName,
string memory _aTokenSymbol,
address _aTokenInstance,
address _stableDebtTokenAddress,
address _variableDebtTokenAddress,
uint8 _underlyingAssetDecimals,
address _interestRateStrategyAddress
) public onlyLendingPoolManager {
AToken aTokenInstance = new AToken(
poolAddressesProvider,
InitializableAdminUpgradeabilityProxy aTokenProxy = new InitializableAdminUpgradeabilityProxy();
bytes memory params = abi.encodeWithSignature(
'initialize(address,address,uint8,string,string)',
address(poolAddressesProvider),
_reserve,
_underlyingAssetDecimals,
_aTokenName,
_aTokenSymbol
IERC20Detailed(_aTokenInstance).name(),
IERC20Detailed(_aTokenInstance).symbol()
);
aTokenProxy.initialize(_aTokenInstance, address(this), params);
pool.initReserve(
_reserve,
address(aTokenInstance),
address(aTokenProxy),
_stableDebtTokenAddress,
_variableDebtTokenAddress,
_interestRateStrategyAddress
@ -233,7 +233,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
pool.setConfiguration(_reserve, currentConfig.data);
emit ReserveInitialized(_reserve, address(aTokenInstance), _interestRateStrategyAddress);
emit ReserveInitialized(_reserve, address(aTokenProxy), _interestRateStrategyAddress);
}
/**

View File

@ -6,6 +6,8 @@ import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddresse
import {LendingPool} from '../lendingpool/LendingPool.sol';
import {WadRayMath} from '../libraries/WadRayMath.sol';
import {UniversalERC20} from '../libraries/UniversalERC20.sol';
import {VersionedInitializable} from '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import '@nomiclabs/buidler/console.sol';
/**
@ -14,7 +16,7 @@ import '@nomiclabs/buidler/console.sol';
* @dev Implementation of the interest bearing token for the DLP protocol.
* @author Aave
*/
contract AToken is ERC20 {
contract AToken is VersionedInitializable, ERC20 {
using WadRayMath for uint256;
using UniversalERC20 for ERC20;
@ -127,6 +129,8 @@ contract AToken is ERC20 {
LendingPoolAddressesProvider private addressesProvider;
LendingPool private pool;
uint256 public constant ATOKEN_REVISION = 0x1;
modifier onlyLendingPool {
require(msg.sender == address(pool), 'The caller of this function must be a lending pool');
_;
@ -137,19 +141,31 @@ contract AToken is ERC20 {
_;
}
constructor(
constructor() public ERC20(_name, _symbol) {
}
function getRevision() internal override pure returns (uint256) {
return ATOKEN_REVISION;
}
function initialize(
LendingPoolAddressesProvider _addressesProvider,
address _underlyingAsset,
uint8 _underlyingAssetDecimals,
string memory _name,
string memory _symbol
) public ERC20(_name, _symbol) {
string calldata _tokenName,
string calldata _tokenSymbol
) external initializer {
_name = _tokenName;
_symbol = _tokenSymbol;
_setupDecimals(_underlyingAssetDecimals);
addressesProvider = _addressesProvider;
pool = LendingPool(payable(addressesProvider.getLendingPool()));
underlyingAssetAddress = _underlyingAsset;
}
/**
* @notice ERC20 implementation internal function backing transfer() and transferFrom()
* @dev validates the transfer before allowing it. NOTE: This is not standard ERC20 behavior

View File

@ -39,8 +39,8 @@ contract ERC20 is Context, IERC20 {
uint256 private _totalSupply;
string private _name;
string private _symbol;
string internal _name;
string internal _symbol;
uint8 private _decimals;
/**