aave-protocol-v2/contracts/deployments/ATokensAndRatesHelper.sol

122 lines
3.6 KiB
Solidity
Raw Normal View History

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';
import {
DefaultReserveInterestRateStrategy
} from '../lendingpool/DefaultReserveInterestRateStrategy.sol';
import {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol';
import {StringLib} from '../libraries/helpers/StringLib.sol';
2020-10-23 13:18:01 +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
) 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++) {
emit deployedContracts(
address(
2020-10-23 13:18:01 +00:00
new AToken(
LendingPool(pool),
tokens[i],
address(0),
StringLib.concat('Aave interest bearing ', symbols[i]),
StringLib.concat('a', symbols[i]),
2020-10-23 13:18:01 +00:00
incentivesController
)
),
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
) 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]
);
}
}
function enableReservesAsCollateral(
address[] calldata tokens,
uint256[] calldata baseLTVs,
uint256[] calldata liquidationThresholds,
uint256[] calldata liquidationBonuses
) external onlyOwner {
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(
tokens[i],
baseLTVs[i],
liquidationThresholds[i],
liquidationBonuses[i]
);
}
}
function enableBorrowingOnReserves(address[] calldata tokens, bool[] calldata stableBorrows)
external
onlyOwner
{
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
}