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 '@openzeppelin/contracts/math/SafeMath.sol';
import '../interfaces/IERC20Detailed.sol';
import '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol'; import '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import '../libraries/ReserveConfiguration.sol'; import '../libraries/ReserveConfiguration.sol';
import '../configuration/LendingPoolAddressesProvider.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 * @title LendingPoolConfigurator contract
@ -171,19 +172,14 @@ contract LendingPoolConfigurator is VersionedInitializable {
function initReserve( function initReserve(
address _reserve, address _reserve,
uint8 _underlyingAssetDecimals, uint8 _underlyingAssetDecimals,
address _aTokenInstance,
address _interestRateStrategyAddress, address _interestRateStrategyAddress,
address _stableDebtTokenAddress, address _stableDebtTokenAddress,
address _variableDebtTokenAddress address _variableDebtTokenAddress
) external onlyLendingPoolManager { ) 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( initReserveWithData(
_reserve, _reserve,
aTokenName, _aTokenInstance,
aTokenSymbol,
_stableDebtTokenAddress, _stableDebtTokenAddress,
_variableDebtTokenAddress, _variableDebtTokenAddress,
_underlyingAssetDecimals, _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) * @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 _reserve the address of the reserve to be initialized
* @param _aTokenName the name of the aToken contract * @param _aTokenInstance the name of the aToken contract
* @param _aTokenSymbol the symbol of the aToken contract
* @param _underlyingAssetDecimals the decimals of the reserve underlying asset * @param _underlyingAssetDecimals the decimals of the reserve underlying asset
* @param _interestRateStrategyAddress the address of the interest rate strategy contract for this reserve * @param _interestRateStrategyAddress the address of the interest rate strategy contract for this reserve
**/ **/
function initReserveWithData( function initReserveWithData(
address _reserve, address _reserve,
string memory _aTokenName, address _aTokenInstance,
string memory _aTokenSymbol,
address _stableDebtTokenAddress, address _stableDebtTokenAddress,
address _variableDebtTokenAddress, address _variableDebtTokenAddress,
uint8 _underlyingAssetDecimals, uint8 _underlyingAssetDecimals,
address _interestRateStrategyAddress address _interestRateStrategyAddress
) public onlyLendingPoolManager { ) 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, _reserve,
_underlyingAssetDecimals, _underlyingAssetDecimals,
_aTokenName, IERC20Detailed(_aTokenInstance).name(),
_aTokenSymbol IERC20Detailed(_aTokenInstance).symbol()
); );
aTokenProxy.initialize(_aTokenInstance, address(this), params);
pool.initReserve( pool.initReserve(
_reserve, _reserve,
address(aTokenInstance), address(aTokenProxy),
_stableDebtTokenAddress, _stableDebtTokenAddress,
_variableDebtTokenAddress, _variableDebtTokenAddress,
_interestRateStrategyAddress _interestRateStrategyAddress
@ -233,7 +233,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
pool.setConfiguration(_reserve, currentConfig.data); 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 {LendingPool} from '../lendingpool/LendingPool.sol';
import {WadRayMath} from '../libraries/WadRayMath.sol'; import {WadRayMath} from '../libraries/WadRayMath.sol';
import {UniversalERC20} from '../libraries/UniversalERC20.sol'; import {UniversalERC20} from '../libraries/UniversalERC20.sol';
import {VersionedInitializable} from '../libraries/openzeppelin-upgradeability/VersionedInitializable.sol';
import '@nomiclabs/buidler/console.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. * @dev Implementation of the interest bearing token for the DLP protocol.
* @author Aave * @author Aave
*/ */
contract AToken is ERC20 { contract AToken is VersionedInitializable, ERC20 {
using WadRayMath for uint256; using WadRayMath for uint256;
using UniversalERC20 for ERC20; using UniversalERC20 for ERC20;
@ -127,6 +129,8 @@ contract AToken is ERC20 {
LendingPoolAddressesProvider private addressesProvider; LendingPoolAddressesProvider private addressesProvider;
LendingPool private pool; LendingPool private pool;
uint256 public constant ATOKEN_REVISION = 0x1;
modifier onlyLendingPool { modifier onlyLendingPool {
require(msg.sender == address(pool), 'The caller of this function must be a lending pool'); 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, LendingPoolAddressesProvider _addressesProvider,
address _underlyingAsset, address _underlyingAsset,
uint8 _underlyingAssetDecimals, uint8 _underlyingAssetDecimals,
string memory _name, string calldata _tokenName,
string memory _symbol string calldata _tokenSymbol
) public ERC20(_name, _symbol) { ) external initializer {
_name = _tokenName;
_symbol = _tokenSymbol;
_setupDecimals(_underlyingAssetDecimals); _setupDecimals(_underlyingAssetDecimals);
addressesProvider = _addressesProvider; addressesProvider = _addressesProvider;
pool = LendingPool(payable(addressesProvider.getLendingPool())); pool = LendingPool(payable(addressesProvider.getLendingPool()));
underlyingAssetAddress = _underlyingAsset; underlyingAssetAddress = _underlyingAsset;
} }
/** /**
* @notice ERC20 implementation internal function backing transfer() and transferFrom() * @notice ERC20 implementation internal function backing transfer() and transferFrom()
* @dev validates the transfer before allowing it. NOTE: This is not standard ERC20 behavior * @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; uint256 private _totalSupply;
string private _name; string internal _name;
string private _symbol; string internal _symbol;
uint8 private _decimals; uint8 private _decimals;
/** /**