Move functions out of Forwarder.sol

This commit is contained in:
Amir Bandeali 2018-07-07 23:23:22 -07:00
parent 8314bbbbac
commit f1613d36ac
12 changed files with 35 additions and 42 deletions

View File

@ -25,11 +25,9 @@ import "./MixinConstants.sol";
import "./MixinMarketBuyZrx.sol"; import "./MixinMarketBuyZrx.sol";
import "./MixinExpectedResults.sol"; import "./MixinExpectedResults.sol";
import "./MixinTransfer.sol"; import "./MixinTransfer.sol";
import "../utils/Ownable/Ownable.sol";
contract Forwarder is contract Forwarder is
Ownable,
MixinConstants, MixinConstants,
MixinExpectedResults, MixinExpectedResults,
MixinFees, MixinFees,
@ -37,7 +35,6 @@ contract Forwarder is
MixinTransfer, MixinTransfer,
MixinForwarderCore MixinForwarderCore
{ {
uint256 constant internal MAX_UINT = 2**256 - 1;
constructor ( constructor (
address _exchange, address _exchange,
@ -48,7 +45,6 @@ contract Forwarder is
bytes memory _wethAssetData bytes memory _wethAssetData
) )
public public
Ownable()
MixinConstants( MixinConstants(
_exchange, _exchange,
_etherToken, _etherToken,
@ -56,30 +52,6 @@ contract Forwarder is
_zrxAssetData, _zrxAssetData,
_wethAssetData _wethAssetData
) )
{ MixinForwarderCore()
setERC20ProxyApproval(_erc20AssetProxyId); {}
}
/// @dev Default payabale function, this allows us to withdraw WETH
function ()
public
payable
{
require(
msg.sender == address(ETHER_TOKEN),
"DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"
);
}
/// @dev Sets the allowances to the proxy for this contract
function setERC20ProxyApproval(bytes4 erc20AssetProxyId)
public
onlyOwner
{
address proxyAddress = EXCHANGE.getAssetProxy(erc20AssetProxyId);
if (proxyAddress != address(0)) {
ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
ZRX_TOKEN.approve(proxyAddress, MAX_UINT);
}
}
} }

View File

@ -40,5 +40,4 @@ contract MixinConstants is
ZRX_ASSET_DATA = _zrxAssetData; ZRX_ASSET_DATA = _zrxAssetData;
WETH_ASSET_DATA = _wethAssetData; WETH_ASSET_DATA = _wethAssetData;
} }
}
}

View File

@ -33,6 +33,17 @@ contract MixinFees is
uint16 constant public MAX_FEE = 1000; // 10% uint16 constant public MAX_FEE = 1000; // 10%
uint16 constant public ALLOWABLE_EXCHANGE_PERCENTAGE = 9500; // 95% uint16 constant public ALLOWABLE_EXCHANGE_PERCENTAGE = 9500; // 95%
/// @dev Default payabale function, this allows us to withdraw WETH
function ()
public
payable
{
require(
msg.sender == address(ETHER_TOKEN),
"DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"
);
}
/// @dev Pays the feeRecipient feeProportion of the total takerEthAmount, denominated in ETH /// @dev Pays the feeRecipient feeProportion of the total takerEthAmount, denominated in ETH
/// @param takerEthAmount The total amount that was transacted in WETH, fees are calculated from this value. /// @param takerEthAmount The total amount that was transacted in WETH, fees are calculated from this value.
/// @param feeProportion The proportion of fees /// @param feeProportion The proportion of fees

View File

@ -39,8 +39,19 @@ contract MixinForwarderCore is
MTransfer, MTransfer,
MForwarderCore MForwarderCore
{ {
bytes4 public constant ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)")); bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
bytes4 public constant ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)")); bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
uint256 constant internal MAX_UINT = 2**256 - 1;
constructor ()
public
{
address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
if (proxyAddress != address(0)) {
ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
ZRX_TOKEN.approve(proxyAddress, MAX_UINT);
}
}
/// @dev Market sells ETH for ERC20 tokens, performing fee abstraction if required. This does not support ERC721 tokens. This function is payable /// @dev Market sells ETH for ERC20 tokens, performing fee abstraction if required. This does not support ERC721 tokens. This function is payable
/// and will convert all incoming ETH into WETH and perform the trade on behalf of the caller. /// and will convert all incoming ETH into WETH and perform the trade on behalf of the caller.

View File

@ -63,4 +63,4 @@ contract IExpectedResults {
public public
view view
returns (LibFillResults.FillResults memory totalFillResults); returns (LibFillResults.FillResults memory totalFillResults);
} }

View File

@ -27,4 +27,4 @@ import "./IExpectedResults.sol";
contract IForwarder is contract IForwarder is
IForwarderCore, IForwarderCore,
IExpectedResults IExpectedResults
{} {}

View File

@ -76,4 +76,4 @@ contract IForwarderCore {
public public
payable payable
returns (LibFillResults.FillResults memory totalFillResults); returns (LibFillResults.FillResults memory totalFillResults);
} }

View File

@ -39,4 +39,4 @@ contract MExpectedResults is
internal internal
view view
returns (LibFillResults.FillResults memory fillResults); returns (LibFillResults.FillResults memory fillResults);
} }

View File

@ -60,4 +60,4 @@ contract MFees {
internal internal
pure pure
returns (bool); returns (bool);
} }

View File

@ -89,4 +89,4 @@ contract MForwarderCore is
) )
internal internal
returns (LibFillResults.FillResults memory totalFillResults); returns (LibFillResults.FillResults memory totalFillResults);
} }

View File

@ -39,4 +39,4 @@ contract MMarketBuyZrx {
) )
internal internal
returns (LibFillResults.FillResults memory totalFillResults); returns (LibFillResults.FillResults memory totalFillResults);
} }

View File

@ -43,4 +43,4 @@ contract MTransfer {
address to address to
) )
internal; internal;
} }