Remove redundant getters from bridges

This commit is contained in:
Amir Bandeali
2019-12-01 15:55:27 -08:00
parent 7fb0818923
commit b8439598bc
6 changed files with 24 additions and 73 deletions

View File

@@ -55,7 +55,7 @@ contract Eth2DaiBridge is
// Decode the bridge data to get the `fromTokenAddress`. // Decode the bridge data to get the `fromTokenAddress`.
(address fromTokenAddress) = abi.decode(bridgeData, (address)); (address fromTokenAddress) = abi.decode(bridgeData, (address));
IEth2Dai exchange = _getEth2DaiContract(); IEth2Dai exchange = IEth2Dai(_getEth2DaiAddress());
// Grant an allowance to the exchange to spend `fromTokenAddress` token. // Grant an allowance to the exchange to spend `fromTokenAddress` token.
LibERC20Token.approve(fromTokenAddress, address(exchange), uint256(-1)); LibERC20Token.approve(fromTokenAddress, address(exchange), uint256(-1));
@@ -84,14 +84,4 @@ contract Eth2DaiBridge is
{ {
return LEGACY_WALLET_MAGIC_VALUE; return LEGACY_WALLET_MAGIC_VALUE;
} }
/// @dev Overridable way to get the eth2dai contract.
/// @return exchange The Eth2Dai exchange contract.
function _getEth2DaiContract()
internal
view
returns (IEth2Dai exchange)
{
return IEth2Dai(_getEth2DaiAddress());
}
} }

View File

@@ -77,8 +77,8 @@ contract KyberBridge is
returns (bytes4 success) returns (bytes4 success)
{ {
TradeState memory state; TradeState memory state;
state.kyber = _getKyberContract(); state.kyber = IKyberNetworkProxy(_getKyberNetworkProxyAddress());
state.weth = _getWETHContract(); state.weth = IEtherToken(_getWethAddress());
// Decode the bridge data to get the `fromTokenAddress`. // Decode the bridge data to get the `fromTokenAddress`.
(state.fromTokenAddress) = abi.decode(bridgeData, (address)); (state.fromTokenAddress) = abi.decode(bridgeData, (address));
state.fromTokenBalance = IERC20Token(state.fromTokenAddress).balanceOf(address(this)); state.fromTokenBalance = IERC20Token(state.fromTokenAddress).balanceOf(address(this));
@@ -143,24 +143,4 @@ contract KyberBridge is
{ {
return LEGACY_WALLET_MAGIC_VALUE; return LEGACY_WALLET_MAGIC_VALUE;
} }
/// @dev Overridable way to get the `KyberNetworkProxy` contract.
/// @return kyber The `IKyberNetworkProxy` contract.
function _getKyberContract()
internal
view
returns (IKyberNetworkProxy kyber)
{
return IKyberNetworkProxy(_getKyberNetworkProxyAddress());
}
/// @dev Overridable way to get the WETH contract.
/// @return weth The WETH contract.
function _getWETHContract()
internal
view
returns (IEtherToken weth)
{
return IEtherToken(_getWETHAddress());
}
} }

View File

@@ -88,7 +88,7 @@ contract UniswapBridge is
// Get our balance of `fromTokenAddress` token. // Get our balance of `fromTokenAddress` token.
state.fromTokenBalance = IERC20Token(fromTokenAddress).balanceOf(address(this)); state.fromTokenBalance = IERC20Token(fromTokenAddress).balanceOf(address(this));
// Get the weth contract. // Get the weth contract.
state.weth = getWethContract(); state.weth = IEtherToken(_getWethAddress());
// Convert from WETH to a token. // Convert from WETH to a token.
if (fromTokenAddress == address(state.weth)) { if (fromTokenAddress == address(state.weth)) {
@@ -161,26 +161,6 @@ contract UniswapBridge is
return LEGACY_WALLET_MAGIC_VALUE; return LEGACY_WALLET_MAGIC_VALUE;
} }
/// @dev Overridable way to get the weth contract.
/// @return token The WETH contract.
function getWethContract()
public
view
returns (IEtherToken token)
{
return IEtherToken(_getWETHAddress());
}
/// @dev Overridable way to get the uniswap exchange factory contract.
/// @return factory The exchange factory contract.
function getUniswapExchangeFactoryContract()
public
view
returns (IUniswapExchangeFactory factory)
{
return IUniswapExchangeFactory(_getUniswapExchangeFactoryAddress());
}
/// @dev Grants an unlimited allowance to the exchange for its token /// @dev Grants an unlimited allowance to the exchange for its token
/// on behalf of this contract. /// on behalf of this contract.
/// @param exchange The Uniswap token exchange. /// @param exchange The Uniswap token exchange.
@@ -207,11 +187,12 @@ contract UniswapBridge is
{ {
address exchangeTokenAddress = fromTokenAddress; address exchangeTokenAddress = fromTokenAddress;
// Whichever isn't WETH is the exchange token. // Whichever isn't WETH is the exchange token.
if (fromTokenAddress == address(getWethContract())) { if (fromTokenAddress == _getWethAddress()) {
exchangeTokenAddress = toTokenAddress; exchangeTokenAddress = toTokenAddress;
} }
exchange = IUniswapExchange( exchange = IUniswapExchange(
getUniswapExchangeFactoryContract().getExchange(exchangeTokenAddress) IUniswapExchangeFactory(_getUniswapExchangeFactoryAddress())
.getExchange(exchangeTokenAddress)
); );
require(address(exchange) != address(0), "NO_UNISWAP_EXCHANGE_FOR_TOKEN"); require(address(exchange) != address(0), "NO_UNISWAP_EXCHANGE_FOR_TOKEN");
return exchange; return exchange;

View File

@@ -192,11 +192,11 @@ contract TestEth2DaiBridge is
} }
// @dev This contract will double as the Eth2Dai contract. // @dev This contract will double as the Eth2Dai contract.
function _getEth2DaiContract() function _getEth2DaiAddress()
internal internal
view view
returns (IEth2Dai) returns (address)
{ {
return IEth2Dai(address(this)); return address(this);
} }
} }

View File

@@ -303,20 +303,20 @@ contract TestKyberBridge is
} }
// @dev overridden to point to this contract. // @dev overridden to point to this contract.
function _getKyberContract() function _getKyberNetworkProxyAddress()
internal internal
view view
returns (IKyberNetworkProxy kyber) returns (address)
{ {
return IKyberNetworkProxy(address(this)); return address(this);
} }
// @dev overridden to point to test WETH. // @dev overridden to point to test WETH.
function _getWETHContract() function _getWethAddress()
internal internal
view view
returns (IEtherToken weth_) returns (address)
{ {
return weth; return address(weth);
} }
} }

View File

@@ -413,20 +413,20 @@ contract TestUniswapBridge is
} }
// @dev Use `wethToken`. // @dev Use `wethToken`.
function getWethContract() function _getWethAddress()
public internal
view view
returns (IEtherToken) returns (address)
{ {
return IEtherToken(address(wethToken)); return address(wethToken);
} }
// @dev This contract will double as the Uniswap contract. // @dev This contract will double as the Uniswap contract.
function getUniswapExchangeFactoryContract() function _getUniswapExchangeFactoryAddress()
public internal
view view
returns (IUniswapExchangeFactory) returns (address)
{ {
return IUniswapExchangeFactory(address(this)); return address(this);
} }
} }