aave-protocol-v2/contracts/misc/AaveProtocolTestHelpers.sol
2020-10-06 15:51:48 +02:00

50 lines
1.7 KiB
Solidity

// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2;
import {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';
import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol';
import {ILendingPool} from '../interfaces/ILendingPool.sol';
contract AaveProtocolTestHelpers {
struct TokenData {
string symbol;
address tokenAddress;
}
ILendingPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
constructor(ILendingPoolAddressesProvider addressesProvider) public {
ADDRESSES_PROVIDER = addressesProvider;
}
function getAllReservesTokens() external view returns (TokenData[] memory) {
ILendingPool pool = ILendingPool(ADDRESSES_PROVIDER.getLendingPool());
address[] memory reserves = pool.getReservesList();
TokenData[] memory reservesTokens = new TokenData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
reservesTokens[i] = TokenData({
symbol: (reserves[i] == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
? 'ETH'
: IERC20Detailed(reserves[i]).symbol(),
tokenAddress: reserves[i]
});
}
return reservesTokens;
}
function getAllATokens() external view returns (TokenData[] memory) {
ILendingPool pool = ILendingPool(ADDRESSES_PROVIDER.getLendingPool());
address[] memory reserves = pool.getReservesList();
TokenData[] memory aTokens = new TokenData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
(address aTokenAddress, , ) = pool.getReserveTokensAddresses(reserves[i]);
aTokens[i] = TokenData({
symbol: IERC20Detailed(aTokenAddress).symbol(),
tokenAddress: aTokenAddress
});
}
return aTokens;
}
}