mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
remove EthAddressLib
This commit is contained in:
parent
2dfcc970da
commit
f3597f670f
|
@ -4,7 +4,6 @@ pragma solidity ^0.6.8;
|
||||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../libraries/UniversalERC20.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
import "../mocks/tokens/MintableERC20.sol";
|
import "../mocks/tokens/MintableERC20.sol";
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ pragma solidity ^0.6.8;
|
||||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../mocks/tokens/MintableERC20.sol";
|
import "../mocks/tokens/MintableERC20.sol";
|
||||||
|
|
||||||
import "../interfaces/IOneSplit.sol";
|
import "../interfaces/IOneSplit.sol";
|
||||||
|
@ -62,4 +61,4 @@ contract MockOneSplit is IOneSplit {
|
||||||
}
|
}
|
||||||
tokenToBurn.safeTransfer(msg.sender, 10000 ether);
|
tokenToBurn.safeTransfer(msg.sender, 10000 ether);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import "../interfaces/IOneSplit.sol";
|
import "../interfaces/IOneSplit.sol";
|
||||||
import "../interfaces/IPriceOracleGetter.sol";
|
import "../interfaces/IPriceOracleGetter.sol";
|
||||||
import "../interfaces/IExchangeAdapter.sol";
|
import "../interfaces/IExchangeAdapter.sol";
|
||||||
|
import "../libraries/UniversalERC20.sol";
|
||||||
/// @title OneSplitAdapter
|
/// @title OneSplitAdapter
|
||||||
/// @author Aave
|
/// @author Aave
|
||||||
/// @notice Implements the logic to exchange assets through 1Split
|
/// @notice Implements the logic to exchange assets through 1Split
|
||||||
|
@ -26,6 +26,7 @@ import "../interfaces/IExchangeAdapter.sol";
|
||||||
|
|
||||||
contract OneSplitAdapter is IExchangeAdapter {
|
contract OneSplitAdapter is IExchangeAdapter {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
using UniversalERC20 for IERC20;
|
||||||
|
|
||||||
event OneSplitAdapterSetup(address oneSplit, address priceOracle, uint256 splitParts);
|
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
|
/// @param _tokens the list of token addresses to approve
|
||||||
function approveExchange(IERC20[] calldata _tokens) external override {
|
function approveExchange(IERC20[] calldata _tokens) external override {
|
||||||
for (uint256 i = 0; i < _tokens.length; i++) {
|
for (uint256 i = 0; i < _tokens.length; i++) {
|
||||||
if (address(_tokens[i]) != EthAddressLib.ethAddress()) {
|
if (!_tokens[i].isETH()) {
|
||||||
_tokens[i].safeApprove(0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, UintConstants.maxUintMinus1());
|
_tokens[i].safeApprove(0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, UintConstants.maxUintMinus1());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Exchanges _amount of _from token (or ETH) to _to token (or ETH)
|
/// @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 _from The asset to exchange from
|
||||||
/// @param _to The asset to exchange to
|
/// @param _to The asset to exchange to
|
||||||
/// @param _amount The amount to exchange
|
/// @param _amount The amount to exchange
|
||||||
/// @param _maxSlippage Max slippage acceptable, taken into account after the goodSwap()
|
/// @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) {
|
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 _fromAssetPriceInWei = IPriceOracleGetter(0x76B47460d7F7c5222cFb6b6A75615ab10895DDe4).getAssetPrice(_from);
|
||||||
uint256 _toAssetPriceInWei = IPriceOracleGetter(0x76B47460d7F7c5222cFb6b6A75615ab10895DDe4).getAssetPrice(_to);
|
uint256 _toAssetPriceInWei = IPriceOracleGetter(0x76B47460d7F7c5222cFb6b6A75615ab10895DDe4).getAssetPrice(_to);
|
||||||
|
@ -76,4 +77,4 @@ contract OneSplitAdapter is IExchangeAdapter {
|
||||||
emit Exchange(_from, _to, 0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, _amount, _toReceivedAmount);
|
emit Exchange(_from, _to, 0x1814222fa8c8c1C1bf380e3BBFBd9De8657Da476, _amount, _toReceivedAmount);
|
||||||
return _toReceivedAmount;
|
return _toReceivedAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||||
import "../libraries/openzeppelin-upgradeability/VersionedInitializable.sol";
|
import "../libraries/openzeppelin-upgradeability/VersionedInitializable.sol";
|
||||||
import "../interfaces/IKyberNetworkProxyInterface.sol";
|
import "../interfaces/IKyberNetworkProxyInterface.sol";
|
||||||
import "../interfaces/IExchangeAdapter.sol";
|
import "../interfaces/IExchangeAdapter.sol";
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../libraries/UniversalERC20.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,4 +208,4 @@ contract TokenDistributor is ReentrancyGuard, VersionedInitializable {
|
||||||
return IMPLEMENTATION_REVISION;
|
return IMPLEMENTATION_REVISION;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
import "../interfaces/IFlashLoanReceiver.sol";
|
import "../interfaces/IFlashLoanReceiver.sol";
|
||||||
import "../../interfaces/ILendingPoolAddressesProvider.sol";
|
import "../../interfaces/ILendingPoolAddressesProvider.sol";
|
||||||
import "../../libraries/EthAddressLib.sol";
|
|
||||||
import "../../libraries/UniversalERC20.sol";
|
import "../../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
|
abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
|
||||||
|
@ -37,4 +36,4 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver {
|
||||||
function getBalanceInternal(address _target, address _reserve) internal view returns(uint256) {
|
function getBalanceInternal(address _target, address _reserve) internal view returns(uint256) {
|
||||||
return IERC20(_reserve).universalBalanceOf(_target);
|
return IERC20(_reserve).universalBalanceOf(_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ pragma solidity ^0.6.8;
|
||||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../libraries/UintConstants.sol";
|
import "../libraries/UintConstants.sol";
|
||||||
|
|
||||||
interface IExchangeAdapter {
|
interface IExchangeAdapter {
|
||||||
|
@ -21,4 +20,4 @@ interface IExchangeAdapter {
|
||||||
function approveExchange(IERC20[] calldata _tokens) external;
|
function approveExchange(IERC20[] calldata _tokens) external;
|
||||||
|
|
||||||
function exchange(address _from, address _to, uint256 _amount, uint256 _maxSlippage) external returns(uint256);
|
function exchange(address _from, address _to, uint256 _amount, uint256 _maxSlippage) external returns(uint256);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import "../flashloan/interfaces/IFlashLoanReceiver.sol";
|
||||||
import "./LendingPoolCore.sol";
|
import "./LendingPoolCore.sol";
|
||||||
import "./LendingPoolDataProvider.sol";
|
import "./LendingPoolDataProvider.sol";
|
||||||
import "./LendingPoolLiquidationManager.sol";
|
import "./LendingPoolLiquidationManager.sol";
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../libraries/UniversalERC20.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -550,7 +549,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable {
|
||||||
) = core.getUserBorrowBalances(_reserve, _onBehalfOf);
|
) = core.getUserBorrowBalances(_reserve, _onBehalfOf);
|
||||||
|
|
||||||
vars.originationFee = core.getUserOriginationFee(_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");
|
require(vars.compoundedBorrowBalance > 0, "The user does not have any borrow pending");
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import "../interfaces/ILendingRateOracle.sol";
|
||||||
import "../interfaces/IReserveInterestRateStrategy.sol";
|
import "../interfaces/IReserveInterestRateStrategy.sol";
|
||||||
import "../libraries/WadRayMath.sol";
|
import "../libraries/WadRayMath.sol";
|
||||||
import "../tokenization/AToken.sol";
|
import "../tokenization/AToken.sol";
|
||||||
import "../libraries/EthAddressLib.sol";
|
|
||||||
import "../libraries/UniversalERC20.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,10 +2,12 @@
|
||||||
pragma solidity ^0.6.8;
|
pragma solidity ^0.6.8;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
|
|
||||||
import "../interfaces/IPriceOracleGetter.sol";
|
import "../interfaces/IPriceOracleGetter.sol";
|
||||||
import "../interfaces/IChainlinkAggregator.sol";
|
import "../interfaces/IChainlinkAggregator.sol";
|
||||||
import "../libraries/EthAddressLib.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
/// @title ChainlinkProxyPriceProvider
|
/// @title ChainlinkProxyPriceProvider
|
||||||
/// @author Aave
|
/// @author Aave
|
||||||
|
@ -15,6 +17,7 @@ import "../libraries/EthAddressLib.sol";
|
||||||
/// - Owned by the Aave governance system, allowed to add sources for assets, replace them
|
/// - Owned by the Aave governance system, allowed to add sources for assets, replace them
|
||||||
/// and change the fallbackOracle
|
/// and change the fallbackOracle
|
||||||
contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable {
|
contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable {
|
||||||
|
using UniversalERC20 for IERC20;
|
||||||
|
|
||||||
event AssetSourceUpdated(address indexed asset, address indexed source);
|
event AssetSourceUpdated(address indexed asset, address indexed source);
|
||||||
event FallbackOracleUpdated(address indexed fallbackOracle);
|
event FallbackOracleUpdated(address indexed fallbackOracle);
|
||||||
|
@ -68,7 +71,7 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable {
|
||||||
/// @param _asset The asset address
|
/// @param _asset The asset address
|
||||||
function getAssetPrice(address _asset) public override view returns(uint256) {
|
function getAssetPrice(address _asset) public override view returns(uint256) {
|
||||||
IChainlinkAggregator source = assetsSources[_asset];
|
IChainlinkAggregator source = assetsSources[_asset];
|
||||||
if (_asset == EthAddressLib.ethAddress()) {
|
if (IERC20(_asset).isETH()) {
|
||||||
return 1 ether;
|
return 1 ether;
|
||||||
} else {
|
} else {
|
||||||
// If there is no registered source for the asset, call the fallbackOracle
|
// 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) {
|
function getFallbackOracle() external view returns(address) {
|
||||||
return address(fallbackOracle);
|
return address(fallbackOracle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
import "../configuration/LendingPoolAddressesProvider.sol";
|
import "../configuration/LendingPoolAddressesProvider.sol";
|
||||||
import "../lendingpool/LendingPoolCore.sol";
|
import "../lendingpool/LendingPoolCore.sol";
|
||||||
import "../libraries/EthAddressLib.sol";
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +19,7 @@ import "../libraries/EthAddressLib.sol";
|
||||||
contract WalletBalanceProvider {
|
contract WalletBalanceProvider {
|
||||||
|
|
||||||
using Address for address;
|
using Address for address;
|
||||||
|
using UniversalERC20 for IERC20;
|
||||||
|
|
||||||
LendingPoolAddressesProvider provider;
|
LendingPoolAddressesProvider provider;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ contract WalletBalanceProvider {
|
||||||
for (uint256 i = 0; i < _users.length; i++) {
|
for (uint256 i = 0; i < _users.length; i++) {
|
||||||
for (uint256 j = 0; j < _tokens.length; j++) {
|
for (uint256 j = 0; j < _tokens.length; j++) {
|
||||||
uint256 _offset = i * _tokens.length;
|
uint256 _offset = i * _tokens.length;
|
||||||
if (_tokens[j] == EthAddressLib.ethAddress()) {
|
if (IERC20(_tokens[j]).isETH()) {
|
||||||
balances[_offset + j] = _users[i].balance; // ETH balance
|
balances[_offset + j] = _users[i].balance; // ETH balance
|
||||||
} else {
|
} else {
|
||||||
if (!_tokens[j].isContract()) {
|
if (!_tokens[j].isContract()) {
|
||||||
|
@ -91,7 +92,7 @@ contract WalletBalanceProvider {
|
||||||
balances[j] = 0;
|
balances[j] = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (reserves[j] != EthAddressLib.ethAddress()) {
|
if (!IERC20(reserves[j]).isETH()) {
|
||||||
balances[j] = balanceOf(_user, reserves[j]);
|
balances[j] = balanceOf(_user, reserves[j]);
|
||||||
} else {
|
} else {
|
||||||
balances[j] = _user.balance; // ETH balance
|
balances[j] = _user.balance; // ETH balance
|
||||||
|
@ -100,4 +101,4 @@ contract WalletBalanceProvider {
|
||||||
|
|
||||||
return (reserves, balances);
|
return (reserves, balances);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
pragma solidity ^0.6.8;
|
pragma solidity ^0.6.8;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/math/SafeMath.sol";
|
import "@openzeppelin/contracts/math/SafeMath.sol";
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
import "../../flashloan/base/FlashLoanReceiverBase.sol";
|
import "../../flashloan/base/FlashLoanReceiverBase.sol";
|
||||||
import "../tokens/MintableERC20.sol";
|
import "../tokens/MintableERC20.sol";
|
||||||
|
import "../libraries/UniversalERC20.sol";
|
||||||
|
|
||||||
contract MockFlashLoanReceiver is FlashLoanReceiverBase {
|
contract MockFlashLoanReceiver is FlashLoanReceiverBase {
|
||||||
|
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
using UniversalERC20 for IERC20;
|
||||||
|
|
||||||
event ExecutedWithFail(address _reserve, uint256 _amount, uint256 _fee);
|
event ExecutedWithFail(address _reserve, uint256 _amount, uint256 _fee);
|
||||||
event ExecutedWithSuccess(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
|
//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
|
//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);
|
token.mint(_fee);
|
||||||
}
|
}
|
||||||
//returning amount + fee to the destination
|
//returning amount + fee to the destination
|
||||||
transferFundsBackToPoolInternal(_reserve, _amount.add(_fee));
|
transferFundsBackToPoolInternal(_reserve, _amount.add(_fee));
|
||||||
emit ExecutedWithSuccess(_reserve, _amount, _fee);
|
emit ExecutedWithSuccess(_reserve, _amount, _fee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user