From f3597f670fb56902d552b075c7a23a4fe9cbfefd Mon Sep 17 00:00:00 2001 From: andyk Date: Tue, 2 Jun 2020 17:16:22 +0300 Subject: [PATCH] remove EthAddressLib --- contracts/fees/MockKyberProxy.sol | 1 - contracts/fees/MockOneSplit.sol | 3 +-- contracts/fees/OneSplitAdapter.sol | 11 ++++++----- contracts/fees/TokenDistributor.sol | 3 +-- contracts/flashloan/base/FlashLoanReceiverBase.sol | 3 +-- contracts/interfaces/IExchangeAdapter.sol | 3 +-- contracts/lendingpool/LendingPool.sol | 3 +-- contracts/lendingpool/LendingPoolCore.sol | 1 - contracts/libraries/EthAddressLib.sol | 13 ------------- contracts/misc/ChainlinkProxyPriceProvider.sol | 9 ++++++--- contracts/misc/WalletBalanceProvider.sol | 9 +++++---- contracts/mocks/flashloan/MockFlashLoanReceiver.sol | 8 ++++++-- 12 files changed, 28 insertions(+), 39 deletions(-) delete mode 100644 contracts/libraries/EthAddressLib.sol diff --git a/contracts/fees/MockKyberProxy.sol b/contracts/fees/MockKyberProxy.sol index 354b84a3..8f812fe3 100644 --- a/contracts/fees/MockKyberProxy.sol +++ b/contracts/fees/MockKyberProxy.sol @@ -4,7 +4,6 @@ pragma solidity ^0.6.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; -import "../libraries/EthAddressLib.sol"; import "../libraries/UniversalERC20.sol"; import "../mocks/tokens/MintableERC20.sol"; diff --git a/contracts/fees/MockOneSplit.sol b/contracts/fees/MockOneSplit.sol index f6e29d68..60668c4b 100644 --- a/contracts/fees/MockOneSplit.sol +++ b/contracts/fees/MockOneSplit.sol @@ -4,7 +4,6 @@ pragma solidity ^0.6.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; -import "../libraries/EthAddressLib.sol"; import "../mocks/tokens/MintableERC20.sol"; import "../interfaces/IOneSplit.sol"; @@ -62,4 +61,4 @@ contract MockOneSplit is IOneSplit { } tokenToBurn.safeTransfer(msg.sender, 10000 ether); } -} \ No newline at end of file +} diff --git a/contracts/fees/OneSplitAdapter.sol b/contracts/fees/OneSplitAdapter.sol index b4773ac3..a77bf3ef 100644 --- a/contracts/fees/OneSplitAdapter.sol +++ b/contracts/fees/OneSplitAdapter.sol @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../interfaces/IOneSplit.sol"; import "../interfaces/IPriceOracleGetter.sol"; import "../interfaces/IExchangeAdapter.sol"; - +import "../libraries/UniversalERC20.sol"; /// @title OneSplitAdapter /// @author Aave /// @notice Implements the logic to exchange assets through 1Split @@ -26,6 +26,7 @@ import "../interfaces/IExchangeAdapter.sol"; contract OneSplitAdapter is IExchangeAdapter { using SafeMath for uint256; + using UniversalERC20 for IERC20; event OneSplitAdapterSetup(address oneSplit, address priceOracle, uint256 splitParts); @@ -37,20 +38,20 @@ contract OneSplitAdapter is IExchangeAdapter { /// @param _tokens the list of token addresses to approve function approveExchange(IERC20[] calldata _tokens) external override { for (uint256 i = 0; i < _tokens.length; i++) { - if (address(_tokens[i]) != EthAddressLib.ethAddress()) { + if (!_tokens[i].isETH()) { _tokens[i].safeApprove(0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, UintConstants.maxUintMinus1()); } } } /// @notice Exchanges _amount of _from token (or ETH) to _to token (or ETH) - /// - Uses EthAddressLib.ethAddress() as the reference on 1Split of ETH + /// - Uses UniversalERC20.isETH() as the reference on 1Split of ETH /// @param _from The asset to exchange from /// @param _to The asset to exchange to /// @param _amount The amount to exchange /// @param _maxSlippage Max slippage acceptable, taken into account after the goodSwap() function exchange(address _from, address _to, uint256 _amount, uint256 _maxSlippage) external override returns(uint256) { - uint256 _value = (_from == EthAddressLib.ethAddress()) ? _amount : 0; + uint256 _value = IERC20(_from).isETH() ? _amount : 0; uint256 _fromAssetPriceInWei = IPriceOracleGetter(0x76B47460d7F7c5222cFb6b6A75615ab10895DDe4).getAssetPrice(_from); uint256 _toAssetPriceInWei = IPriceOracleGetter(0x76B47460d7F7c5222cFb6b6A75615ab10895DDe4).getAssetPrice(_to); @@ -76,4 +77,4 @@ contract OneSplitAdapter is IExchangeAdapter { emit Exchange(_from, _to, 0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, _amount, _toReceivedAmount); return _toReceivedAmount; } -} \ No newline at end of file +} diff --git a/contracts/fees/TokenDistributor.sol b/contracts/fees/TokenDistributor.sol index 3db76462..a282ed27 100644 --- a/contracts/fees/TokenDistributor.sol +++ b/contracts/fees/TokenDistributor.sol @@ -10,7 +10,6 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "../libraries/openzeppelin-upgradeability/VersionedInitializable.sol"; import "../interfaces/IKyberNetworkProxyInterface.sol"; import "../interfaces/IExchangeAdapter.sol"; -import "../libraries/EthAddressLib.sol"; import "../libraries/UniversalERC20.sol"; @@ -209,4 +208,4 @@ contract TokenDistributor is ReentrancyGuard, VersionedInitializable { return IMPLEMENTATION_REVISION; } -} \ No newline at end of file +} diff --git a/contracts/flashloan/base/FlashLoanReceiverBase.sol b/contracts/flashloan/base/FlashLoanReceiverBase.sol index 19bc847a..25fa03c0 100644 --- a/contracts/flashloan/base/FlashLoanReceiverBase.sol +++ b/contracts/flashloan/base/FlashLoanReceiverBase.sol @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; import "../interfaces/IFlashLoanReceiver.sol"; import "../../interfaces/ILendingPoolAddressesProvider.sol"; -import "../../libraries/EthAddressLib.sol"; import "../../libraries/UniversalERC20.sol"; abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { @@ -37,4 +36,4 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { function getBalanceInternal(address _target, address _reserve) internal view returns(uint256) { return IERC20(_reserve).universalBalanceOf(_target); } -} \ No newline at end of file +} diff --git a/contracts/interfaces/IExchangeAdapter.sol b/contracts/interfaces/IExchangeAdapter.sol index 54343d58..1267f2b9 100644 --- a/contracts/interfaces/IExchangeAdapter.sol +++ b/contracts/interfaces/IExchangeAdapter.sol @@ -4,7 +4,6 @@ pragma solidity ^0.6.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; -import "../libraries/EthAddressLib.sol"; import "../libraries/UintConstants.sol"; interface IExchangeAdapter { @@ -21,4 +20,4 @@ interface IExchangeAdapter { function approveExchange(IERC20[] calldata _tokens) external; function exchange(address _from, address _to, uint256 _amount, uint256 _maxSlippage) external returns(uint256); -} \ No newline at end of file +} diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 1c0b7bb6..e8d0b337 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -17,7 +17,6 @@ import "../flashloan/interfaces/IFlashLoanReceiver.sol"; import "./LendingPoolCore.sol"; import "./LendingPoolDataProvider.sol"; import "./LendingPoolLiquidationManager.sol"; -import "../libraries/EthAddressLib.sol"; import "../libraries/UniversalERC20.sol"; /** @@ -550,7 +549,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable { ) = core.getUserBorrowBalances(_reserve, _onBehalfOf); vars.originationFee = core.getUserOriginationFee(_reserve, _onBehalfOf); - vars.isETH = EthAddressLib.ethAddress() == _reserve; + vars.isETH = IERC20(_reserve).isETH(); require(vars.compoundedBorrowBalance > 0, "The user does not have any borrow pending"); diff --git a/contracts/lendingpool/LendingPoolCore.sol b/contracts/lendingpool/LendingPoolCore.sol index a685b2cb..4606dfdd 100644 --- a/contracts/lendingpool/LendingPoolCore.sol +++ b/contracts/lendingpool/LendingPoolCore.sol @@ -12,7 +12,6 @@ import "../interfaces/ILendingRateOracle.sol"; import "../interfaces/IReserveInterestRateStrategy.sol"; import "../libraries/WadRayMath.sol"; import "../tokenization/AToken.sol"; -import "../libraries/EthAddressLib.sol"; import "../libraries/UniversalERC20.sol"; /** diff --git a/contracts/libraries/EthAddressLib.sol b/contracts/libraries/EthAddressLib.sol deleted file mode 100644 index 07d485f9..00000000 --- a/contracts/libraries/EthAddressLib.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity ^0.6.8; - -library EthAddressLib { - - /** - * @dev returns the address used within the protocol to identify ETH - * @return the address assigned to ETH - */ - function ethAddress() internal pure returns(address) { - return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; - } -} \ No newline at end of file diff --git a/contracts/misc/ChainlinkProxyPriceProvider.sol b/contracts/misc/ChainlinkProxyPriceProvider.sol index e2c6d8fa..3695496c 100644 --- a/contracts/misc/ChainlinkProxyPriceProvider.sol +++ b/contracts/misc/ChainlinkProxyPriceProvider.sol @@ -2,10 +2,12 @@ pragma solidity ^0.6.8; import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + import "../interfaces/IPriceOracleGetter.sol"; import "../interfaces/IChainlinkAggregator.sol"; -import "../libraries/EthAddressLib.sol"; +import "../libraries/UniversalERC20.sol"; /// @title ChainlinkProxyPriceProvider /// @author Aave @@ -15,6 +17,7 @@ import "../libraries/EthAddressLib.sol"; /// - Owned by the Aave governance system, allowed to add sources for assets, replace them /// and change the fallbackOracle contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { + using UniversalERC20 for IERC20; event AssetSourceUpdated(address indexed asset, address indexed source); event FallbackOracleUpdated(address indexed fallbackOracle); @@ -68,7 +71,7 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { /// @param _asset The asset address function getAssetPrice(address _asset) public override view returns(uint256) { IChainlinkAggregator source = assetsSources[_asset]; - if (_asset == EthAddressLib.ethAddress()) { + if (IERC20(_asset).isETH()) { return 1 ether; } else { // If there is no registered source for the asset, call the fallbackOracle @@ -107,4 +110,4 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { function getFallbackOracle() external view returns(address) { return address(fallbackOracle); } -} \ No newline at end of file +} diff --git a/contracts/misc/WalletBalanceProvider.sol b/contracts/misc/WalletBalanceProvider.sol index 36c28bb4..73b8624e 100644 --- a/contracts/misc/WalletBalanceProvider.sol +++ b/contracts/misc/WalletBalanceProvider.sol @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../configuration/LendingPoolAddressesProvider.sol"; import "../lendingpool/LendingPoolCore.sol"; -import "../libraries/EthAddressLib.sol"; +import "../libraries/UniversalERC20.sol"; /** @@ -19,6 +19,7 @@ import "../libraries/EthAddressLib.sol"; contract WalletBalanceProvider { using Address for address; + using UniversalERC20 for IERC20; LendingPoolAddressesProvider provider; @@ -59,7 +60,7 @@ contract WalletBalanceProvider { for (uint256 i = 0; i < _users.length; i++) { for (uint256 j = 0; j < _tokens.length; j++) { uint256 _offset = i * _tokens.length; - if (_tokens[j] == EthAddressLib.ethAddress()) { + if (IERC20(_tokens[j]).isETH()) { balances[_offset + j] = _users[i].balance; // ETH balance } else { if (!_tokens[j].isContract()) { @@ -91,7 +92,7 @@ contract WalletBalanceProvider { balances[j] = 0; continue; } - if (reserves[j] != EthAddressLib.ethAddress()) { + if (!IERC20(reserves[j]).isETH()) { balances[j] = balanceOf(_user, reserves[j]); } else { balances[j] = _user.balance; // ETH balance @@ -100,4 +101,4 @@ contract WalletBalanceProvider { return (reserves, balances); } -} \ No newline at end of file +} diff --git a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol index 688d507f..932e630d 100644 --- a/contracts/mocks/flashloan/MockFlashLoanReceiver.sol +++ b/contracts/mocks/flashloan/MockFlashLoanReceiver.sol @@ -2,13 +2,17 @@ pragma solidity ^0.6.8; import "@openzeppelin/contracts/math/SafeMath.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../../flashloan/base/FlashLoanReceiverBase.sol"; import "../tokens/MintableERC20.sol"; +import "../libraries/UniversalERC20.sol"; contract MockFlashLoanReceiver is FlashLoanReceiverBase { using SafeMath for uint256; + using UniversalERC20 for IERC20; + event ExecutedWithFail(address _reserve, uint256 _amount, uint256 _fee); event ExecutedWithSuccess(address _reserve, uint256 _amount, uint256 _fee); @@ -42,11 +46,11 @@ contract MockFlashLoanReceiver is FlashLoanReceiverBase { //execution does not fail - mint tokens and return them to the _destination //note: if the reserve is eth, the mock contract must receive at least _fee ETH before calling executeOperation - if(_reserve != EthAddressLib.ethAddress()) { + if(!IERC20(_reserve).isETH()) { token.mint(_fee); } //returning amount + fee to the destination transferFundsBackToPoolInternal(_reserve, _amount.add(_fee)); emit ExecutedWithSuccess(_reserve, _amount, _fee); } -} \ No newline at end of file +}