Skip to content

Commit

Permalink
feat: getReserveAToken getter (aave-dao#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Oct 16, 2024
1 parent 2ea3e77 commit 7e582b0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
13 changes: 5 additions & 8 deletions src/contracts/extensions/static-a-token/StataTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,20 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {
for (uint256 i = 0; i < underlyings.length; i++) {
address cachedStataToken = _underlyingToStataToken[underlyings[i]];
if (cachedStataToken == address(0)) {
DataTypes.ReserveDataLegacy memory reserveData = POOL.getReserveData(underlyings[i]);
if (reserveData.aTokenAddress == address(0))
revert NotListedUnderlying(reserveData.aTokenAddress);
address aTokenAddress = POOL.getReserveAToken(underlyings[i]);
if (aTokenAddress == address(0)) revert NotListedUnderlying(aTokenAddress);
bytes memory symbol = abi.encodePacked(
'stat',
IERC20Metadata(reserveData.aTokenAddress).symbol(),
IERC20Metadata(aTokenAddress).symbol(),
'v2'
);
address stataToken = TRANSPARENT_PROXY_FACTORY.createDeterministic(
STATA_TOKEN_IMPL,
PROXY_ADMIN,
abi.encodeWithSelector(
StataTokenV2.initialize.selector,
reserveData.aTokenAddress,
string(
abi.encodePacked('Static ', IERC20Metadata(reserveData.aTokenAddress).name(), ' v2')
),
aTokenAddress,
string(abi.encodePacked('Static ', IERC20Metadata(aTokenAddress).name(), ' v2')),
string(symbol)
),
bytes32(uint256(uint160(underlyings[i])))
Expand Down
12 changes: 5 additions & 7 deletions src/contracts/helpers/AaveProtocolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ contract AaveProtocolDataProvider is IPoolDataProvider {
address[] memory reserves = pool.getReservesList();
TokenData[] memory aTokens = new TokenData[](reserves.length);
for (uint256 i = 0; i < reserves.length; i++) {
DataTypes.ReserveDataLegacy memory reserveData = pool.getReserveData(reserves[i]);
address aTokenAddress = pool.getReserveAToken(reserves[i]);
aTokens[i] = TokenData({
symbol: IERC20Detailed(reserveData.aTokenAddress).symbol(),
tokenAddress: reserveData.aTokenAddress
symbol: IERC20Detailed(aTokenAddress).symbol(),
tokenAddress: aTokenAddress
});
}
return aTokens;
Expand Down Expand Up @@ -188,10 +188,8 @@ contract AaveProtocolDataProvider is IPoolDataProvider {

/// @inheritdoc IPoolDataProvider
function getATokenTotalSupply(address asset) external view override returns (uint256) {
DataTypes.ReserveDataLegacy memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);
return IERC20Detailed(reserve.aTokenAddress).totalSupply();
address aTokenAddress = IPool(ADDRESSES_PROVIDER.getPool()).getReserveAToken(asset);
return IERC20Detailed(aTokenAddress).totalSupply();
}

/// @inheritdoc IPoolDataProvider
Expand Down
4 changes: 2 additions & 2 deletions src/contracts/helpers/WrappedTokenGatewayV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract WrappedTokenGatewayV3 is IWrappedTokenGatewayV3, Ownable {
* @param to address of the user who will receive native ETH
*/
function withdrawETH(address, uint256 amount, address to) external override {
IAToken aWETH = IAToken(POOL.getReserveData(address(WETH)).aTokenAddress);
IAToken aWETH = IAToken(POOL.getReserveAToken(address(WETH)));
uint256 userBalance = aWETH.balanceOf(msg.sender);
uint256 amountToWithdraw = amount;

Expand Down Expand Up @@ -127,7 +127,7 @@ contract WrappedTokenGatewayV3 is IWrappedTokenGatewayV3, Ownable {
bytes32 permitR,
bytes32 permitS
) external override {
IAToken aWETH = IAToken(POOL.getReserveData(address(WETH)).aTokenAddress);
IAToken aWETH = IAToken(POOL.getReserveAToken(address(WETH)));
uint256 userBalance = aWETH.balanceOf(msg.sender);
uint256 amountToWithdraw = amount;

Expand Down
7 changes: 7 additions & 0 deletions src/contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,13 @@ interface IPool {
*/
function getReserveDeficit(address asset) external view returns (uint256);

/**
* @notice Returns the aToken address of a reserve.
* @param asset The address of the underlying asset of the reserve
* @return The address of the aToken
*/
function getReserveAToken(address asset) external view returns (address);

/**
* @notice Gets the address of the external FlashLoanLogic
*/
Expand Down
10 changes: 5 additions & 5 deletions src/contracts/protocol/libraries/logic/ConfiguratorLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ library ConfiguratorLogic {
IPool cachedPool,
ConfiguratorInputTypes.UpdateATokenInput calldata input
) external {
DataTypes.ReserveDataLegacy memory reserveData = cachedPool.getReserveData(input.asset);
address aTokenAddress = cachedPool.getReserveAToken(input.asset);

(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParams();
uint256 decimals = cachedPool.getConfiguration(input.asset).getDecimals();

bytes memory encodedCall = abi.encodeWithSelector(
IInitializableAToken.initialize.selector,
Expand All @@ -140,9 +140,9 @@ library ConfiguratorLogic {
input.params
);

_upgradeTokenImplementation(reserveData.aTokenAddress, input.implementation, encodedCall);
_upgradeTokenImplementation(aTokenAddress, input.implementation, encodedCall);

emit ATokenUpgraded(input.asset, reserveData.aTokenAddress, input.implementation);
emit ATokenUpgraded(input.asset, aTokenAddress, input.implementation);
}

/**
Expand All @@ -157,7 +157,7 @@ library ConfiguratorLogic {
) external {
DataTypes.ReserveDataLegacy memory reserveData = cachedPool.getReserveData(input.asset);

(, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParams();
uint256 decimals = cachedPool.getConfiguration(input.asset).getDecimals();

bytes memory encodedCall = abi.encodeWithSelector(
IInitializableDebtToken.initialize.selector,
Expand Down
5 changes: 5 additions & 0 deletions src/contracts/protocol/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ abstract contract Pool is VersionedInitializable, PoolStorage, IPool {
return _reserves[asset].deficit;
}

/// @inheritdoc IPool
function getReserveAToken(address asset) external view virtual returns (address) {
return _reserves[asset].aTokenAddress;
}

/// @inheritdoc IPool
function getFlashLoanLogic() external pure returns (address) {
return address(FlashLoanLogic);
Expand Down
2 changes: 0 additions & 2 deletions tests/extensions/static-a-token/StataTokenV2Rescuable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ contract StataTokenV2RescuableTest is BaseTest {
_fundAToken(donation, address(stataTokenV2));
_fund4626(stake, address(this));

address treasury = IAToken(aToken).RESERVE_TREASURY_ADDRESS();

vm.expectEmit(true, true, true, true);
emit ERC20Rescued(poolAdmin, aToken, address(this), donation);
vm.startPrank(poolAdmin);
Expand Down
5 changes: 2 additions & 3 deletions tests/protocol/pool/Pool.Deficit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ contract PoolDeficitTests is TestnetProcedures {
}

function test_reverts_eliminateReserveDeficit_reserve_not_in_deficit(
address coverageAdmin,
uint120 supplyAmount
address coverageAdmin
) public {
_filterAddresses(coverageAdmin);

Expand Down Expand Up @@ -167,7 +166,7 @@ contract PoolDeficitTests is TestnetProcedures {
return (tokenList.usdx, currentDeficit);
}

function _filterAddresses(address user) internal {
function _filterAddresses(address user) internal view {
vm.assume(user != address(0));
vm.assume(user != report.proxyAdmin);
vm.assume(user != report.poolAddressesProvider);
Expand Down

0 comments on commit 7e582b0

Please sign in to comment.