2020-10-23 13:18:01 +00:00
|
|
|
// SPDX-License-Identifier: agpl-3.0
|
|
|
|
pragma solidity ^0.6.8;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
import {LendingPool} from '../lendingpool/LendingPool.sol';
|
|
|
|
import {LendingPoolAddressesProvider} from '../configuration/LendingPoolAddressesProvider.sol';
|
|
|
|
import {LendingPoolConfigurator} from '../lendingpool/LendingPoolConfigurator.sol';
|
|
|
|
import {AToken} from '../tokenization/AToken.sol';
|
2020-11-10 13:18:48 +00:00
|
|
|
import {DelegationAwareAToken} from '../tokenization/DelegationAwareAToken.sol';
|
2020-10-23 13:18:01 +00:00
|
|
|
import {
|
|
|
|
DefaultReserveInterestRateStrategy
|
|
|
|
} from '../lendingpool/DefaultReserveInterestRateStrategy.sol';
|
2020-10-27 09:58:51 +00:00
|
|
|
import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol';
|
2020-10-28 17:39:19 +00:00
|
|
|
import {StringLib} from '../libraries/helpers/StringLib.sol';
|
2020-10-23 13:18:01 +00:00
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
contract ATokensAndRatesHelper is Ownable {
|
2020-10-23 13:18:01 +00:00
|
|
|
address payable private pool;
|
|
|
|
address private addressesProvider;
|
|
|
|
address private poolConfigurator;
|
|
|
|
event deployedContracts(address aToken, address strategy);
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
address payable _pool,
|
|
|
|
address _addressesProvider,
|
|
|
|
address _poolConfigurator
|
|
|
|
) public {
|
|
|
|
pool = _pool;
|
|
|
|
addressesProvider = _addressesProvider;
|
|
|
|
poolConfigurator = _poolConfigurator;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initDeployment(
|
|
|
|
address[] calldata tokens,
|
|
|
|
string[] calldata symbols,
|
|
|
|
uint256[5][] calldata rates,
|
|
|
|
address incentivesController
|
2020-10-27 09:58:51 +00:00
|
|
|
) external onlyOwner {
|
2020-10-23 13:18:01 +00:00
|
|
|
require(tokens.length == symbols.length, 't Arrays not same length');
|
|
|
|
require(rates.length == symbols.length, 'r Arrays not same length');
|
|
|
|
for (uint256 i = 0; i < tokens.length; i++) {
|
2020-11-10 13:18:48 +00:00
|
|
|
address aToken;
|
|
|
|
if (keccak256(bytes(symbols[i])) == keccak256(bytes('UNI'))) {
|
|
|
|
aToken = address(
|
|
|
|
new DelegationAwareAToken(
|
|
|
|
LendingPool(pool),
|
|
|
|
tokens[i],
|
|
|
|
address(0),
|
|
|
|
StringLib.concat('Aave interest bearing ', symbols[i]),
|
|
|
|
StringLib.concat('a', symbols[i]),
|
|
|
|
incentivesController
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
aToken = address(
|
2020-10-23 13:18:01 +00:00
|
|
|
new AToken(
|
|
|
|
LendingPool(pool),
|
|
|
|
tokens[i],
|
|
|
|
address(0),
|
2020-10-28 17:39:19 +00:00
|
|
|
StringLib.concat('Aave interest bearing ', symbols[i]),
|
|
|
|
StringLib.concat('a', symbols[i]),
|
2020-10-23 13:18:01 +00:00
|
|
|
incentivesController
|
|
|
|
)
|
2020-11-10 13:18:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
emit deployedContracts(
|
|
|
|
aToken,
|
2020-10-23 13:18:01 +00:00
|
|
|
address(
|
|
|
|
new DefaultReserveInterestRateStrategy(
|
|
|
|
LendingPoolAddressesProvider(addressesProvider),
|
|
|
|
rates[i][0],
|
|
|
|
rates[i][1],
|
|
|
|
rates[i][2],
|
|
|
|
rates[i][3],
|
|
|
|
rates[i][4]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initReserve(
|
|
|
|
address[] calldata stables,
|
|
|
|
address[] calldata variables,
|
|
|
|
address[] calldata aTokens,
|
|
|
|
address[] calldata strategies,
|
|
|
|
uint8[] calldata reserveDecimals
|
2020-10-27 09:58:51 +00:00
|
|
|
) external onlyOwner {
|
2020-10-26 09:41:24 +00:00
|
|
|
require(variables.length == stables.length);
|
|
|
|
require(aTokens.length == stables.length);
|
|
|
|
require(strategies.length == stables.length);
|
|
|
|
require(reserveDecimals.length == stables.length);
|
2020-10-23 13:18:01 +00:00
|
|
|
|
2020-10-26 09:41:24 +00:00
|
|
|
for (uint256 i = 0; i < stables.length; i++) {
|
2020-10-23 13:18:01 +00:00
|
|
|
LendingPoolConfigurator(poolConfigurator).initReserve(
|
|
|
|
aTokens[i],
|
|
|
|
stables[i],
|
|
|
|
variables[i],
|
|
|
|
reserveDecimals[i],
|
|
|
|
strategies[i]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 16:43:10 +00:00
|
|
|
|
|
|
|
function enableReservesAsCollateral(
|
|
|
|
address[] calldata tokens,
|
|
|
|
uint256[] calldata baseLTVs,
|
|
|
|
uint256[] calldata liquidationThresholds,
|
|
|
|
uint256[] calldata liquidationBonuses
|
2020-10-27 09:58:51 +00:00
|
|
|
) external onlyOwner {
|
2020-10-26 16:43:10 +00:00
|
|
|
require(baseLTVs.length == tokens.length);
|
|
|
|
require(liquidationThresholds.length == tokens.length);
|
|
|
|
require(liquidationBonuses.length == tokens.length);
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < tokens.length; i++) {
|
2020-10-30 14:12:11 +00:00
|
|
|
LendingPoolConfigurator(poolConfigurator).configureReserveAsCollateral(
|
2020-10-26 16:43:10 +00:00
|
|
|
tokens[i],
|
|
|
|
baseLTVs[i],
|
|
|
|
liquidationThresholds[i],
|
|
|
|
liquidationBonuses[i]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableBorrowingOnReserves(address[] calldata tokens, bool[] calldata stableBorrows)
|
|
|
|
external
|
2020-10-27 09:58:51 +00:00
|
|
|
onlyOwner
|
2020-10-26 16:43:10 +00:00
|
|
|
{
|
|
|
|
require(stableBorrows.length == tokens.length);
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < tokens.length; i++) {
|
|
|
|
LendingPoolConfigurator(poolConfigurator).enableBorrowingOnReserve(
|
|
|
|
tokens[i],
|
|
|
|
stableBorrows[i]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-10-23 13:18:01 +00:00
|
|
|
}
|