|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +pragma solidity =0.8.24; |
| 4 | + |
| 5 | +import { BaseTest } from "../utils/BaseTest.sol"; |
| 6 | +import { AaveView } from "../../contracts/views/AaveView.sol"; |
| 7 | +import { |
| 8 | + IAaveProtocolDataProviderV2 |
| 9 | +} from "../../contracts/interfaces/protocols/aaveV2/IAaveProtocolDataProviderV2.sol"; |
| 10 | +import { |
| 11 | + ILendingPoolAddressesProviderV2 |
| 12 | +} from "../../contracts/interfaces/protocols/aaveV2/ILendingPoolAddressesProviderV2.sol"; |
| 13 | + |
| 14 | +contract TestAaveView is BaseTest { |
| 15 | + AaveView cut; |
| 16 | + |
| 17 | + /// @dev Aave V2 LendingPoolAddressesProvider on mainnet |
| 18 | + address internal constant AAVE_V2_MARKET = 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5; |
| 19 | + address internal constant USER = 0xECf1839269f9240F9b897e38C092b1740A4c316D; |
| 20 | + |
| 21 | + address internal constant STETH = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84; |
| 22 | + address internal constant REN = 0x408e41876cCCDC0F92210600ef50372656052a38; |
| 23 | + |
| 24 | + bytes32 internal constant DATA_PROVIDER_ID = |
| 25 | + 0x0100000000000000000000000000000000000000000000000000000000000000; |
| 26 | + |
| 27 | + function setUp() public override { |
| 28 | + forkMainnetLatest(); |
| 29 | + cut = new AaveView(); |
| 30 | + } |
| 31 | + |
| 32 | + function test_getLoanData_does_not_revert() public view { |
| 33 | + AaveView.LoanData memory data = cut.getLoanData(AAVE_V2_MARKET, USER); |
| 34 | + assertEq(data.user, USER); |
| 35 | + } |
| 36 | + |
| 37 | + function test_getTokensInfo_stETH_and_REN() public view { |
| 38 | + address[] memory tokens = new address[](2); |
| 39 | + tokens[0] = STETH; |
| 40 | + tokens[1] = REN; |
| 41 | + |
| 42 | + AaveView.TokenInfo[] memory infos = cut.getTokensInfo(AAVE_V2_MARKET, tokens); |
| 43 | + |
| 44 | + assertEq(infos.length, 2); |
| 45 | + assertEq(infos[0].underlyingTokenAddress, STETH); |
| 46 | + assertEq(infos[1].underlyingTokenAddress, REN); |
| 47 | + assertTrue(infos[0].price > 0); |
| 48 | + assertTrue(infos[1].price == 0); |
| 49 | + } |
| 50 | + |
| 51 | + function test_getTokenInfoFull_stETH() public view { |
| 52 | + address dataProviderAddr = |
| 53 | + ILendingPoolAddressesProviderV2(AAVE_V2_MARKET).getAddress(DATA_PROVIDER_ID); |
| 54 | + address priceOracle = ILendingPoolAddressesProviderV2(AAVE_V2_MARKET).getPriceOracle(); |
| 55 | + IAaveProtocolDataProviderV2 dataProvider = IAaveProtocolDataProviderV2(dataProviderAddr); |
| 56 | + |
| 57 | + AaveView.TokenInfoFull memory info = cut.getTokenInfoFull(dataProvider, priceOracle, STETH); |
| 58 | + |
| 59 | + assertEq(info.underlyingTokenAddress, STETH); |
| 60 | + assertTrue(info.price > 0); |
| 61 | + assertTrue(info.totalSupply > 0); |
| 62 | + } |
| 63 | + |
| 64 | + function test_getTokenInfoFull_REN() public view { |
| 65 | + address dataProviderAddr = |
| 66 | + ILendingPoolAddressesProviderV2(AAVE_V2_MARKET).getAddress(DATA_PROVIDER_ID); |
| 67 | + address priceOracle = ILendingPoolAddressesProviderV2(AAVE_V2_MARKET).getPriceOracle(); |
| 68 | + IAaveProtocolDataProviderV2 dataProvider = IAaveProtocolDataProviderV2(dataProviderAddr); |
| 69 | + |
| 70 | + AaveView.TokenInfoFull memory info = cut.getTokenInfoFull(dataProvider, priceOracle, REN); |
| 71 | + |
| 72 | + assertEq(info.underlyingTokenAddress, REN); |
| 73 | + assertTrue(info.price == 0); |
| 74 | + } |
| 75 | +} |
0 commit comments