aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/2.0.0')
-rw-r--r--packages/contracts/src/2.0.0/forwarder/Forwarder.sol82
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinConstants.sol52
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinERC20.sol68
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinERC721.sol66
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol35
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol159
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol259
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol82
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol197
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol115
-rw-r--r--packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol2
-rw-r--r--packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/ERC20Proxy.sol6
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol6
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol6
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetProxy.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol17
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol8
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol75
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol10
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol10
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol4
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol4
-rw-r--r--packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol64
-rw-r--r--packages/contracts/src/2.0.0/test/Mintable/Mintable.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol9
-rw-r--r--packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol3
-rw-r--r--packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol8
-rw-r--r--packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol10
-rw-r--r--packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol61
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol24
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol4
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol7
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol5
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol21
-rw-r--r--packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol11
-rw-r--r--packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol2
-rw-r--r--packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol10
-rw-r--r--packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol26
-rw-r--r--packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol2
-rw-r--r--packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol3
-rw-r--r--packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol3
73 files changed, 1437 insertions, 207 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/Forwarder.sol b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol
new file mode 100644
index 000000000..38128d93e
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol
@@ -0,0 +1,82 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "./MixinWethFees.sol";
+import "./MixinMarketSellTokens.sol";
+import "./MixinMarketBuyTokens.sol";
+import "./MixinConstants.sol";
+import "../utils/Ownable/Ownable.sol";
+
+
+contract Forwarder is
+ Ownable,
+ MixinConstants,
+ MixinWethFees,
+ MixinMarketBuyZrx,
+ MixinMarketBuyTokens,
+ MixinMarketSellTokens
+{
+ uint256 constant internal MAX_UINT = 2**256 - 1;
+
+ constructor (
+ address _exchange,
+ address _etherToken,
+ address _zrxToken,
+ bytes4 _erc20AssetProxyId,
+ bytes memory _zrxAssetData,
+ bytes memory _wethAssetData
+ )
+ public
+ Ownable()
+ MixinConstants(
+ _exchange,
+ _etherToken,
+ _zrxToken,
+ _zrxAssetData,
+ _wethAssetData
+ )
+ {
+ 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);
+ }
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol
new file mode 100644
index 000000000..ea82e9d64
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol
@@ -0,0 +1,52 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+
+import "../protocol/Exchange/Exchange.sol";
+import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
+import "../tokens/ERC20Token/IERC20Token.sol";
+
+
+contract MixinConstants {
+
+ // solhint-disable var-name-mixedcase
+ Exchange internal EXCHANGE;
+ EtherToken internal ETHER_TOKEN;
+ IERC20Token internal ZRX_TOKEN;
+ bytes internal ZRX_ASSET_DATA;
+ bytes internal WETH_ASSET_DATA;
+ // solhint-enable var-name-mixedcase
+
+ constructor (
+ address _exchange,
+ address _etherToken,
+ address _zrxToken,
+ bytes memory _zrxAssetData,
+ bytes memory _wethAssetData
+ )
+ public
+ {
+ EXCHANGE = Exchange(_exchange);
+ ETHER_TOKEN = EtherToken(_etherToken);
+ ZRX_TOKEN = IERC20Token(_zrxToken);
+ ZRX_ASSET_DATA = _zrxAssetData;
+ WETH_ASSET_DATA = _wethAssetData;
+ }
+
+} \ No newline at end of file
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol b/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol
new file mode 100644
index 000000000..387c3de6b
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol
@@ -0,0 +1,68 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+
+contract MixinERC20 {
+
+ bytes4 constant internal ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));
+
+ function transferToken(
+ address token,
+ address to,
+ uint256 amount
+ )
+ internal
+ {
+ // Transfer tokens.
+ // We do a raw call so we can check the success separate
+ // from the return data.
+ bool success = token.call(abi.encodeWithSelector(
+ ERC20_TRANSFER_SELECTOR,
+ to,
+ amount
+ ));
+ require(
+ success,
+ "TRANSFER_FAILED"
+ );
+
+ // Check return data.
+ // If there is no return data, we assume the token incorrectly
+ // does not return a bool. In this case we expect it to revert
+ // on failure, which was handled above.
+ // If the token does return data, we require that it is a single
+ // value that evaluates to true.
+ assembly {
+ if returndatasize {
+ success := 0
+ if eq(returndatasize, 32) {
+ // First 64 bytes of memory are reserved scratch space
+ returndatacopy(0, 0, 32)
+ success := mload(0)
+ }
+ }
+ }
+ require(
+ success,
+ "TRANSFER_FAILED"
+ );
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol b/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol
new file mode 100644
index 000000000..b5be223b6
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol
@@ -0,0 +1,66 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "../utils/LibBytes/LibBytes.sol";
+import "../tokens/ERC721Token/IERC721Token.sol";
+
+
+contract MixinERC721 {
+
+ using LibBytes for bytes;
+
+ bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,uint256,bytes)"));
+ bytes4 constant internal ERC721_RECEIVED_OPERATOR = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
+
+ function onERC721Received(address, uint256, bytes memory)
+ public
+ pure
+ returns(bytes4)
+ {
+ return ERC721_RECEIVED;
+ }
+
+ function onERC721Received(address, address, uint256, bytes memory)
+ public
+ pure
+ returns(bytes4)
+ {
+ return ERC721_RECEIVED_OPERATOR;
+ }
+
+ function transferERC721Token(
+ bytes memory assetData,
+ address to
+ )
+ internal
+ {
+ // Decode asset data.
+ address token = assetData.readAddress(16);
+ uint256 tokenId = assetData.readUint256(36);
+ bytes memory receiverData = assetData.readBytesWithLength(100);
+ IERC721Token(token).safeTransferFrom(
+ address(this),
+ to,
+ tokenId,
+ receiverData
+ );
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol b/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol
new file mode 100644
index 000000000..1b3e3f488
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol
@@ -0,0 +1,35 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+// solhint-disable
+pragma solidity 0.4.24;
+
+
+/// This contract is intended to serve as a reference, but is not actually used for efficiency reasons.
+contract MixinErrorMessages {
+ string constant VALUE_GREATER_THAN_ZERO = "VALUE_GREATER_THAN_ZERO";
+ string constant FEE_PROPORTION_TOO_LARGE = "FEE_PROPORTION_TOO_LARGE";
+ string constant TAKER_ASSET_ZRX_REQUIRED = "TAKER_ASSET_ZRX_REQUIRED";
+ string constant TAKER_ASSET_WETH_REQUIRED = "TAKER_ASSET_WETH_REQUIRED";
+ string constant SAME_ASSET_TYPE_REQUIRED = "SAME_ASSET_TYPE_REQUIRED";
+ string constant UNACCEPTABLE_THRESHOLD = "UNACCEPTABLE_THRESHOLD";
+ string constant UNSUPPORTED_TOKEN_PROXY = "UNSUPPORTED_TOKEN_PROXY";
+ string constant ASSET_AMOUNT_MATCH_ORDER_SIZE = "ASSET_AMOUNT_MUST_MATCH_ORDER_SIZE";
+ string constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY = "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY";
+ string constant INVALID_MSG_VALUE = "INVALID_MSG_VALUE";
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol
new file mode 100644
index 000000000..6406d1d37
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol
@@ -0,0 +1,159 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "../utils/LibBytes/LibBytes.sol";
+import "../protocol/Exchange/libs/LibFillResults.sol";
+import "../protocol/Exchange/libs/LibMath.sol";
+import "../protocol/Exchange/libs/LibOrder.sol";
+import "./MixinConstants.sol";
+
+
+contract MixinExpectedResults is
+ LibMath,
+ LibFillResults,
+ MixinConstants
+{
+
+ /// @dev Calculates a total FillResults for buying makerAssetFillAmount over all orders.
+ /// Including the fees required to be paid.
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param makerAssetFillAmount A number representing the amount of this order to fill.
+ /// @return totalFillResults Amounts filled and fees paid by maker and taker.
+ function calculateMarketBuyResults(
+ LibOrder.Order[] memory orders,
+ uint256 makerAssetFillAmount
+ )
+ public
+ view
+ returns (FillResults memory totalFillResults)
+ {
+ for (uint256 i = 0; i < orders.length; i++) {
+ uint256 remainingMakerAssetFillAmount = safeSub(makerAssetFillAmount, totalFillResults.makerAssetFilledAmount);
+ uint256 remainingTakerAssetFillAmount = getPartialAmount(
+ orders[i].takerAssetAmount,
+ orders[i].makerAssetAmount,
+ remainingMakerAssetFillAmount
+ );
+ FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount);
+ addFillResults(totalFillResults, singleFillResult);
+ if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) {
+ break;
+ }
+ }
+ return totalFillResults;
+ }
+
+ /// @dev Calculates fill results for buyFeeTokens. This handles fees on buying ZRX
+ /// so the end result is the expected amount of ZRX (not less after fees).
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param zrxFillAmount A number representing the amount zrx to buy
+ /// @return totalFillResults Expected fill result amounts from buying fees
+ function calculateMarketBuyZrxResults(
+ LibOrder.Order[] memory orders,
+ uint256 zrxFillAmount
+ )
+ public
+ view
+ returns (FillResults memory totalFillResults)
+ {
+ for (uint256 i = 0; i < orders.length; i++) {
+ uint256 remainingZrxFillAmount = safeSub(zrxFillAmount, totalFillResults.makerAssetFilledAmount);
+ // Convert the remaining amount of makerToken to buy into remaining amount
+ // of takerToken to sell, assuming entire amount can be sold in the current order
+ uint256 remainingWethSellAmount = getPartialAmount(
+ orders[i].takerAssetAmount,
+ safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees
+ remainingZrxFillAmount
+ );
+ FillResults memory singleFillResult = calculateFillResults(orders[i], safeAdd(remainingWethSellAmount, 1));
+
+ singleFillResult.makerAssetFilledAmount = safeSub(singleFillResult.makerAssetFilledAmount, singleFillResult.takerFeePaid);
+ addFillResults(totalFillResults, singleFillResult);
+ // As we compensate for the rounding issue above have slightly more ZRX than the requested zrxFillAmount
+ if (totalFillResults.makerAssetFilledAmount >= zrxFillAmount) {
+ break;
+ }
+ }
+ return totalFillResults;
+ }
+
+ /// @dev Simulates the 0x Exchange fillOrder validation and calculations, without performing any state changes.
+ /// @param order An Order struct containing order specifications.
+ /// @param takerAssetFillAmount A number representing the amount of this order to fill.
+ /// @return fillResults Amounts filled and fees paid by maker and taker.
+ function calculateFillResults(
+ LibOrder.Order memory order,
+ uint256 takerAssetFillAmount
+ )
+ internal
+ view
+ returns (FillResults memory fillResults)
+ {
+ LibOrder.OrderInfo memory orderInfo = EXCHANGE.getOrderInfo(order);
+ if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
+ return fillResults;
+ }
+ uint256 remainingTakerAssetAmount = safeSub(order.takerAssetAmount, orderInfo.orderTakerAssetFilledAmount);
+ uint256 takerAssetFilledAmount = min256(takerAssetFillAmount, remainingTakerAssetAmount);
+
+ fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
+ fillResults.makerAssetFilledAmount = getPartialAmount(
+ takerAssetFilledAmount,
+ order.takerAssetAmount,
+ order.makerAssetAmount
+ );
+ fillResults.makerFeePaid = getPartialAmount(
+ takerAssetFilledAmount,
+ order.takerAssetAmount,
+ order.makerFee
+ );
+ fillResults.takerFeePaid = getPartialAmount(
+ takerAssetFilledAmount,
+ order.takerAssetAmount,
+ order.takerFee
+ );
+ return fillResults;
+ }
+
+ /// @dev Calculates a FillResults total for selling takerAssetFillAmount over all orders.
+ /// Including the fees required to be paid.
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param takerAssetFillAmount A number representing the amount of this order to fill.
+ /// @return totalFillResults Amounts filled and fees paid by maker and taker.
+ function calculateMarketSellResults(
+ LibOrder.Order[] memory orders,
+ uint256 takerAssetFillAmount
+ )
+ internal
+ view
+ returns (FillResults memory totalFillResults)
+ {
+ for (uint256 i = 0; i < orders.length; i++) {
+ uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
+ FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount);
+ addFillResults(totalFillResults, singleFillResult);
+ if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) {
+ break;
+ }
+ }
+ return totalFillResults;
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol
new file mode 100644
index 000000000..165fec61f
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol
@@ -0,0 +1,259 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "../utils/LibBytes/LibBytes.sol";
+import "./MixinWethFees.sol";
+import "./MixinMarketBuyZrx.sol";
+import "./MixinExpectedResults.sol";
+import "./MixinERC20.sol";
+import "./MixinERC721.sol";
+import "./MixinConstants.sol";
+import "../protocol/Exchange/libs/LibOrder.sol";
+
+
+contract MixinMarketBuyTokens is
+ MixinConstants,
+ MixinWethFees,
+ MixinMarketBuyZrx,
+ MixinExpectedResults,
+ MixinERC20,
+ MixinERC721
+{
+ bytes4 public constant ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
+ bytes4 public constant ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
+
+ /// @dev Buys the exact amount of assets (ERC20 and ERC721), performing fee abstraction if required.
+ /// All order assets must be of the same type. Deducts a proportional fee to fee recipient.
+ /// This function is payable and will convert all incoming ETH into WETH and perform the trade on behalf of the caller.
+ /// The caller is sent all assets from the fill of orders. This function will revert unless the requested amount of assets are purchased.
+ /// Any excess ETH sent will be returned to the caller
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param signatures An array of Proof that order has been created by maker.
+ /// @param feeOrders An array of Order struct containing order specifications for fees.
+ /// @param makerTokenFillAmount The amount of maker asset to buy.
+ /// @param feeSignatures An array of Proof that order has been created by maker for the fee orders.
+ /// @param feeProportion A proportion deducted off the ETH spent and sent to feeRecipient. The maximum value for this
+ /// is 1000, aka 10%. Supports up to 2 decimal places. I.e 0.59% is 59.
+ /// @param feeRecipient An address of the fee recipient whom receives feeProportion of ETH.
+ /// @return FillResults amounts filled and fees paid by maker and taker.
+ function marketBuyTokensWithEth(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ LibOrder.Order[] memory feeOrders,
+ bytes[] memory feeSignatures,
+ uint256 makerTokenFillAmount,
+ uint16 feeProportion,
+ address feeRecipient
+ )
+ public
+ payable
+ returns (FillResults memory totalFillResults)
+ {
+ uint256 takerEthAmount = msg.value;
+ require(
+ takerEthAmount > 0,
+ "VALUE_GREATER_THAN_ZERO"
+ );
+ require(
+ makerTokenFillAmount > 0,
+ "VALUE_GREATER_THAN_ZERO"
+ );
+ bytes4 assetDataId = LibBytes.readBytes4(orders[0].makerAssetData, 0);
+ require(
+ assetDataId == ERC20_DATA_ID || assetDataId == ERC721_DATA_ID,
+ "UNSUPPORTED_TOKEN_PROXY"
+ );
+
+ ETHER_TOKEN.deposit.value(takerEthAmount)();
+ if (assetDataId == ERC20_DATA_ID) {
+ totalFillResults = marketBuyERC20TokensInternal(
+ orders,
+ signatures,
+ feeOrders,
+ feeSignatures,
+ makerTokenFillAmount
+ );
+ } else if (assetDataId == ERC721_DATA_ID) {
+ totalFillResults = batchBuyERC721TokensInternal(
+ orders,
+ signatures,
+ feeOrders,
+ feeSignatures
+ );
+ }
+ // Prevent accidental WETH owned by this contract and it being spent
+ require(
+ takerEthAmount >= totalFillResults.takerAssetFilledAmount,
+ "INVALID_MSG_VALUE"
+ );
+ withdrawPayAndDeductEthFee(
+ safeSub(takerEthAmount, totalFillResults.takerAssetFilledAmount),
+ totalFillResults.takerAssetFilledAmount,
+ feeProportion,
+ feeRecipient
+ );
+ return totalFillResults;
+ }
+
+ /// @dev Buys an exact amount of an ERC20 token using WETH.
+ /// @param orders Orders to fill. The maker asset is the ERC20 token to buy. The taker asset is WETH.
+ /// @param signatures Proof that the orders were created by their respective makers.
+ /// @param feeOrders to fill. The maker asset is ZRX and the taker asset is WETH.
+ /// @param feeSignatures Proof that the feeOrders were created by their respective makers.
+ /// @param makerTokenFillAmount Amount of the ERC20 token to buy.
+ /// @return totalFillResults Aggregated fill results of buying the ERC20 and ZRX tokens.
+ function marketBuyERC20TokensInternal(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ LibOrder.Order[] memory feeOrders,
+ bytes[] memory feeSignatures,
+ uint256 makerTokenFillAmount
+ )
+ private
+ returns (FillResults memory totalFillResults)
+ {
+ // We read the maker token address to check if it is ZRX and later use it for transfer
+ address makerTokenAddress = LibBytes.readAddress(orders[0].makerAssetData, 16);
+ // We assume that asset being bought by taker is the same for each order.
+ // Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders.
+ orders[0].takerAssetData = WETH_ASSET_DATA;
+ // We can short cut here for effeciency and use buyFeeTokensInternal if maker asset token is ZRX
+ // this buys us exactly that amount taking into account the fees. This saves gas and calculates the rate correctly
+ FillResults memory marketBuyResults;
+ if (makerTokenAddress == address(ZRX_TOKEN)) {
+ marketBuyResults = marketBuyZrxInternal(
+ orders,
+ signatures,
+ makerTokenFillAmount
+ );
+ // When buying ZRX we round up which can result in a small margin excess
+ require(
+ marketBuyResults.makerAssetFilledAmount >= makerTokenFillAmount,
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ addFillResults(totalFillResults, marketBuyResults);
+ require(
+ isAcceptableThreshold(
+ safeAdd(totalFillResults.makerAssetFilledAmount, totalFillResults.takerFeePaid), // Total ZRX
+ totalFillResults.makerAssetFilledAmount // amount going to msg.sender
+ ),
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ } else {
+ FillResults memory calculatedMarketBuyResults = calculateMarketBuyResults(orders, makerTokenFillAmount);
+ if (calculatedMarketBuyResults.takerFeePaid > 0) {
+ // Fees are required for these orders. Buy enough ZRX to cover the future market buy
+ FillResults memory zrxMarketBuyResults = marketBuyZrxInternal(
+ feeOrders,
+ feeSignatures,
+ calculatedMarketBuyResults.takerFeePaid
+ );
+ totalFillResults.takerAssetFilledAmount = zrxMarketBuyResults.takerAssetFilledAmount;
+ totalFillResults.takerFeePaid = zrxMarketBuyResults.takerFeePaid;
+ }
+ // Make our market buy of the requested tokens with the remaining balance
+ marketBuyResults = EXCHANGE.marketBuyOrders(
+ orders,
+ makerTokenFillAmount,
+ signatures
+ );
+ require(
+ marketBuyResults.makerAssetFilledAmount == makerTokenFillAmount,
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ addFillResults(totalFillResults, marketBuyResults);
+ require(
+ isAcceptableThreshold(
+ totalFillResults.takerAssetFilledAmount,
+ marketBuyResults.takerAssetFilledAmount
+ ),
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ }
+ // Transfer all purchased tokens to msg.sender
+ transferToken(
+ makerTokenAddress,
+ msg.sender,
+ marketBuyResults.makerAssetFilledAmount
+ );
+ return totalFillResults;
+ }
+
+ /// @dev Buys an all of the ERC721 tokens in the orders.
+ /// @param orders Orders to fill. The maker asset is the ERC721 token to buy. The taker asset is WETH.
+ /// @param signatures Proof that the orders were created by their respective makers.
+ /// @param feeOrders to fill. The maker asset is ZRX and the taker asset is WETH.
+ /// @param feeSignatures Proof that the feeOrders were created by their respective makers.
+ /// @return totalFillResults Aggregated fill results of buying the ERC721 tokens and ZRX tokens.
+ function batchBuyERC721TokensInternal(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ LibOrder.Order[] memory feeOrders,
+ bytes[] memory feeSignatures
+ )
+ private
+ returns (FillResults memory totalFillResults)
+ {
+ uint256 totalZrxFeeAmount;
+ uint256 ordersLength = orders.length;
+ uint256[] memory takerAssetFillAmounts = new uint256[](ordersLength);
+ for (uint256 i = 0; i < ordersLength; i++) {
+ // Total up the fees
+ totalZrxFeeAmount = safeAdd(totalZrxFeeAmount, orders[i].takerFee);
+ // We assume that asset being bought by taker is the same for each order.
+ // Rather than passing this in as calldata, we set the takerAssetData as WETH asset data
+ orders[i].takerAssetData = WETH_ASSET_DATA;
+ // Populate takerAssetFillAmounts for later batchFill
+ takerAssetFillAmounts[i] = orders[i].takerAssetAmount;
+ }
+ if (totalZrxFeeAmount > 0) {
+ // Fees are required for these orders. Buy enough ZRX to cover the future fill
+ FillResults memory zrxMarketBuyResults = marketBuyZrxInternal(
+ feeOrders,
+ feeSignatures,
+ totalZrxFeeAmount
+ );
+ totalFillResults.takerFeePaid = zrxMarketBuyResults.takerFeePaid;
+ totalFillResults.takerAssetFilledAmount = zrxMarketBuyResults.takerAssetFilledAmount;
+ }
+ FillResults memory batchFillResults = EXCHANGE.batchFillOrKillOrders(
+ orders,
+ takerAssetFillAmounts,
+ signatures
+ );
+ addFillResults(totalFillResults, batchFillResults);
+ require(
+ isAcceptableThreshold(
+ totalFillResults.takerAssetFilledAmount,
+ batchFillResults.takerAssetFilledAmount
+ ),
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ // Transfer all of the tokens filled from the batchFill
+ for (i = 0; i < ordersLength; i++) {
+ transferERC721Token(
+ orders[i].makerAssetData,
+ msg.sender
+ );
+ }
+ return totalFillResults;
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol
new file mode 100644
index 000000000..cc98cb63d
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol
@@ -0,0 +1,82 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "../protocol/Exchange/Exchange.sol";
+import "../protocol/Exchange/libs/LibFillResults.sol";
+import "../protocol/Exchange/libs/LibOrder.sol";
+import "../protocol/Exchange/libs/LibMath.sol";
+import "./MixinConstants.sol";
+
+
+contract MixinMarketBuyZrx is
+ LibMath,
+ LibFillResults,
+ MixinConstants
+{
+
+ /// @dev Buys zrxBuyAmount of ZRX fee tokens, taking into account the fees on buying fee tokens. This will guarantee
+ /// At least zrxBuyAmount of ZRX fee tokens are purchased (sometimes slightly over due to rounding issues).
+ /// It is possible that a request to buy 200 ZRX fee tokens will require purchasing 202 ZRX tokens
+ /// As 2 ZRX is required to purchase the 200 ZRX fee tokens. This guarantees at least 200 ZRX for future purchases.
+ /// @param orders An array of Order struct containing order specifications for fees.
+ /// @param signatures An array of Proof that order has been created by maker for the fee orders.
+ /// @param zrxBuyAmount The number of requested ZRX fee tokens.
+ /// @return totalFillResults Amounts filled and fees paid by maker and taker. makerTokenAmount is the zrx amount deducted of fees
+ function marketBuyZrxInternal(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ uint256 zrxBuyAmount
+ )
+ internal
+ returns (FillResults memory totalFillResults)
+ {
+ for (uint256 i = 0; i < orders.length; i++) {
+ // All of these are ZRX/WETH, we can drop the respective assetData from callData
+ orders[i].makerAssetData = ZRX_ASSET_DATA;
+ orders[i].takerAssetData = WETH_ASSET_DATA;
+ // Calculate the remaining amount of makerToken to buy
+ uint256 remainingZrxBuyAmount = safeSub(zrxBuyAmount, totalFillResults.makerAssetFilledAmount);
+ // Convert the remaining amount of makerToken to buy into remaining amount
+ // of takerToken to sell, assuming entire amount can be sold in the current order
+ uint256 remainingWethSellAmount = getPartialAmount(
+ orders[i].takerAssetAmount,
+ safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees
+ remainingZrxBuyAmount
+ );
+ // Attempt to sell the remaining amount of takerToken
+ // Round up the amount to ensure we don't under buy by a fractional amount
+ FillResults memory singleFillResult = EXCHANGE.fillOrder(
+ orders[i],
+ safeAdd(remainingWethSellAmount, 1),
+ signatures[i]
+ );
+ // We didn't buy the full amount when buying ZRX as some were taken for fees
+ singleFillResult.makerAssetFilledAmount = safeSub(singleFillResult.makerAssetFilledAmount, singleFillResult.takerFeePaid);
+ // Update amounts filled and fees paid by maker and taker
+ addFillResults(totalFillResults, singleFillResult);
+ // Stop execution if the entire amount of makerToken has been bought
+ if (totalFillResults.makerAssetFilledAmount >= zrxBuyAmount) {
+ break;
+ }
+ }
+ return totalFillResults;
+ }
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol
new file mode 100644
index 000000000..f4f509846
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol
@@ -0,0 +1,197 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import "../protocol/Exchange/libs/LibOrder.sol";
+import "../utils/LibBytes/LibBytes.sol";
+import "./MixinWethFees.sol";
+import "./MixinExpectedResults.sol";
+import "./MixinERC20.sol";
+import "./MixinConstants.sol";
+import "./MixinMarketBuyZrx.sol";
+
+
+contract MixinMarketSellTokens is
+ MixinConstants,
+ MixinWethFees,
+ MixinMarketBuyZrx,
+ MixinExpectedResults,
+ MixinERC20
+{
+ /// @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.
+ /// This function allows for a deduction of a proportion of incoming ETH sent to the feeRecipient.
+ /// The caller is sent all tokens from the operation.
+ /// If the purchased token amount does not meet an acceptable threshold then this function reverts.
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param signatures An array of Proof that order has been created by maker.
+ /// @param feeOrders An array of Order struct containing order specifications for fees.
+ /// @param feeSignatures An array of Proof that order has been created by maker for the fee orders.
+ /// @param feeProportion A proportion deducted off the incoming ETH and sent to feeRecipient. The maximum value for this
+ /// is 1000, aka 10%. Supports up to 2 decimal places. I.e 0.59% is 59.
+ /// @param feeRecipient An address of the fee recipient whom receives feeProportion of ETH.
+ /// @return FillResults amounts filled and fees paid by maker and taker.
+ function marketSellEthForERC20(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ LibOrder.Order[] memory feeOrders,
+ bytes[] memory feeSignatures,
+ uint16 feeProportion,
+ address feeRecipient
+ )
+ public
+ payable
+ returns (FillResults memory totalFillResults)
+ {
+ uint256 takerEthAmount = msg.value;
+ require(
+ takerEthAmount > 0,
+ "VALUE_GREATER_THAN_ZERO"
+ );
+ // Deduct the fee from the total amount of ETH sent in
+ uint256 ethFeeAmount = payEthFee(
+ takerEthAmount,
+ feeProportion,
+ feeRecipient
+ );
+ uint256 wethSellAmount = safeSub(takerEthAmount, ethFeeAmount);
+
+ // Deposit the remaining to be used for trading
+ ETHER_TOKEN.deposit.value(wethSellAmount)();
+ // Populate the known assetData, as it is always WETH the caller can provide null bytes to save gas
+ // marketSellOrders fills the remaining
+ address makerTokenAddress = LibBytes.readAddress(orders[0].makerAssetData, 16);
+ orders[0].takerAssetData = WETH_ASSET_DATA;
+ if (makerTokenAddress == address(ZRX_TOKEN)) {
+ // If this is ZRX then we market sell from the orders, rather than a 2 step of buying ZRX fees from feeOrders
+ // then buying ZRX from orders
+ totalFillResults = marketSellEthForZRXInternal(
+ orders,
+ signatures,
+ wethSellAmount
+ );
+ } else {
+ totalFillResults = marketSellEthForERC20Internal(
+ orders,
+ signatures,
+ feeOrders,
+ feeSignatures,
+ wethSellAmount
+ );
+ }
+ // Prevent accidental WETH owned by this contract and it being spent
+ require(
+ takerEthAmount >= totalFillResults.takerAssetFilledAmount,
+ "INVALID_MSG_VALUE"
+ );
+ // Ensure no WETH is left in this contract
+ require(
+ wethSellAmount == totalFillResults.takerAssetFilledAmount,
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ // Transfer all tokens to msg.sender
+ transferToken(
+ makerTokenAddress,
+ msg.sender,
+ totalFillResults.makerAssetFilledAmount
+ );
+ return totalFillResults;
+ }
+
+ /// @dev Market sells WETH for ERC20 tokens.
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param signatures An array of Proof that order has been created by maker.
+ /// @param feeOrders An array of Order struct containing order specifications for fees.
+ /// @param feeSignatures An array of Proof that order has been created by maker for the fee orders.
+ /// @param wethSellAmount The amount of WETH to sell.
+ /// @return FillResults amounts filled and fees paid by maker and taker.
+ function marketSellEthForERC20Internal(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ LibOrder.Order[] memory feeOrders,
+ bytes[] memory feeSignatures,
+ uint256 wethSellAmount
+ )
+ internal
+ returns (FillResults memory totalFillResults)
+ {
+ uint256 remainingWethSellAmount = wethSellAmount;
+ FillResults memory calculatedMarketSellResults = calculateMarketSellResults(orders, wethSellAmount);
+ if (calculatedMarketSellResults.takerFeePaid > 0) {
+ // Fees are required for these orders. Buy enough ZRX to cover the future market buy
+ FillResults memory feeTokensResults = marketBuyZrxInternal(
+ feeOrders,
+ feeSignatures,
+ calculatedMarketSellResults.takerFeePaid
+ );
+ // Ensure the token abstraction was fair if fees were proportionally too high, we fail
+ require(
+ isAcceptableThreshold(
+ wethSellAmount,
+ safeSub(wethSellAmount, feeTokensResults.takerAssetFilledAmount)
+ ),
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ remainingWethSellAmount = safeSub(remainingWethSellAmount, feeTokensResults.takerAssetFilledAmount);
+ totalFillResults.takerFeePaid = feeTokensResults.takerFeePaid;
+ totalFillResults.takerAssetFilledAmount = feeTokensResults.takerAssetFilledAmount;
+ }
+ // Make our market sell to buy the requested tokens with the remaining balance
+ FillResults memory requestedTokensResults = EXCHANGE.marketSellOrders(
+ orders,
+ remainingWethSellAmount,
+ signatures
+ );
+ // Update our return FillResult with the market sell
+ addFillResults(totalFillResults, requestedTokensResults);
+ return totalFillResults;
+ }
+
+ /// @dev Market sells WETH for ZRX tokens.
+ /// @param orders An array of Order struct containing order specifications.
+ /// @param signatures An array of Proof that order has been created by maker.
+ /// @param wethSellAmount The amount of WETH to sell.
+ /// @return FillResults amounts filled and fees paid by maker and taker.
+ function marketSellEthForZRXInternal(
+ LibOrder.Order[] memory orders,
+ bytes[] memory signatures,
+ uint256 wethSellAmount
+ )
+ internal
+ returns (FillResults memory totalFillResults)
+ {
+ // Make our market sell to buy the requested tokens with the remaining balance
+ totalFillResults = EXCHANGE.marketSellOrders(
+ orders,
+ wethSellAmount,
+ signatures
+ );
+ // Exchange does not special case ZRX in the makerAssetFilledAmount, if fees were deducted then using this amount
+ // for future transfers is invalid.
+ uint256 zrxAmountBought = safeSub(totalFillResults.makerAssetFilledAmount, totalFillResults.takerFeePaid);
+ require(
+ isAcceptableThreshold(totalFillResults.makerAssetFilledAmount, zrxAmountBought),
+ "UNACCEPTABLE_THRESHOLD"
+ );
+ totalFillResults.makerAssetFilledAmount = zrxAmountBought;
+ return totalFillResults;
+ }
+
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol b/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol
new file mode 100644
index 000000000..92e2cebe8
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol
@@ -0,0 +1,115 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+*/
+
+pragma solidity 0.4.24;
+pragma experimental ABIEncoderV2;
+
+import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
+import "../protocol/Exchange/libs/LibMath.sol";
+import "./MixinConstants.sol";
+
+
+contract MixinWethFees is
+ LibMath,
+ MixinConstants
+{
+
+ uint16 constant public PERCENTAGE_DENOMINATOR = 10000; // 9800 == 98%, 10000 == 100%
+ uint16 constant public MAX_FEE = 1000; // 10%
+ uint16 constant public ALLOWABLE_EXCHANGE_PERCENTAGE = 9500; // 95%
+
+ /// @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 feeProportion The proportion of fees
+ /// @param feeRecipient The recipient of the fees
+ /// @return ethFeeAmount Amount of ETH paid to feeRecipient as fee.
+ function payEthFee(
+ uint256 takerEthAmount,
+ uint16 feeProportion,
+ address feeRecipient
+ )
+ internal
+ returns (uint256 ethFeeAmount)
+ {
+ if (feeProportion > 0 && feeRecipient != address(0)) {
+ require(
+ feeProportion <= MAX_FEE,
+ "FEE_PROPORTION_TOO_LARGE"
+ );
+ // 1.5% is 150, allowing for 2 decimal precision, i.e 0.05% is 5
+ ethFeeAmount = getPartialAmount(
+ feeProportion,
+ PERCENTAGE_DENOMINATOR,
+ takerEthAmount
+ );
+ feeRecipient.transfer(ethFeeAmount);
+ }
+ return ethFeeAmount;
+ }
+
+ /// @dev Withdraws the remaining WETH, deduct and pay fees from this amount based on the takerTokenAmount to the feeRecipient.
+ /// If a user overpaid ETH initially, the fees are calculated from the amount traded and deducted from withdrawAmount.
+ /// Any remaining ETH is sent back to the user.
+ /// @param ethWithdrawAmount The amount to withdraw from the WETH contract.
+ /// @param wethAmountSold The total amount that was transacted in WETH, fees are calculated from this value.
+ /// @param feeProportion The proportion of fees
+ /// @param feeRecipient The recipient of the fees
+ function withdrawPayAndDeductEthFee(
+ uint256 ethWithdrawAmount,
+ uint256 wethAmountSold,
+ uint16 feeProportion,
+ address feeRecipient
+ )
+ internal
+ {
+ // Return all of the excess WETH if any after deducting fees on the amount
+ if (ethWithdrawAmount > 0) {
+ ETHER_TOKEN.withdraw(ethWithdrawAmount);
+ // Fees proportional to the amount traded
+ uint256 ethFeeAmount = payEthFee(
+ wethAmountSold,
+ feeProportion,
+ feeRecipient
+ );
+ uint256 unspentEthAmount = safeSub(ethWithdrawAmount, ethFeeAmount);
+ if (unspentEthAmount > 0) {
+ msg.sender.transfer(unspentEthAmount);
+ }
+ }
+ }
+
+ /// @dev Checks whether the amount of tokens sold against the amount of tokens requested
+ /// is within a certain threshold. This ensures the caller gets a fair deal when
+ /// performing any token fee abstraction. Threshold is 95%. If fee abstraction costs more than
+ /// 5% of the total transaction, we return false.
+ /// @param requestedSellAmount The amount the user requested, or sent in to a payable function
+ /// @param tokenAmountSold The amount of the token that was sold after fee abstraction
+ /// @return bool of whether this is within an acceptable threshold
+ function isAcceptableThreshold(uint256 requestedSellAmount, uint256 tokenAmountSold)
+ internal
+ pure
+ returns (bool)
+ {
+ uint256 acceptableSellAmount = getPartialAmount(
+ ALLOWABLE_EXCHANGE_PERCENTAGE,
+ PERCENTAGE_DENOMINATOR,
+ requestedSellAmount
+ );
+ return tokenAmountSold >= acceptableSellAmount;
+ }
+}
diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
index 79fd92029..eb54fe047 100644
--- a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
+++ b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
@@ -1,5 +1,7 @@
+// solhint-disable
pragma solidity ^0.4.10;
+
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <stefan.george@consensys.net>
contract MultiSigWallet {
diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
index 9766c2158..8c5e6e1e6 100644
--- a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
+++ b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
@@ -16,10 +16,12 @@
*/
+// solhint-disable
pragma solidity ^0.4.10;
import "./MultiSigWallet.sol";
+
/// @title Multisignature wallet with time lock- Allows multiple parties to execute a transaction after a time lock has passed.
/// @author Amir Bandeali - <amir@0xProject.com>
contract MultiSigWalletWithTimeLock is MultiSigWallet {
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC20Proxy.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC20Proxy.sol
index aed62f54f..295974f97 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC20Proxy.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC20Proxy.sol
@@ -16,18 +16,20 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol";
+
contract ERC20Proxy is
MixinAuthorizable
{
// Id of this proxy.
- bytes4 constant PROXY_ID = bytes4(keccak256("ERC20Token(address)"));
+ bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC20Token(address)"));
+ // solhint-disable-next-line payable-fallback
function ()
external
{
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol
index b73dc36cc..43777d374 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol
@@ -16,18 +16,20 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol";
+
contract ERC721Proxy is
MixinAuthorizable
{
// Id of this proxy.
- bytes4 constant PROXY_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
+ bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
+ // solhint-disable-next-line payable-fallback
function ()
external
{
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol
index 3b9584a44..d21eac618 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/Ownable/Ownable.sol";
import "./mixins/MAuthorizable.sol";
+
contract MixinAuthorizable is
Ownable,
MAuthorizable
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol
index 7ebd6acf0..3e76e38dd 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol
@@ -16,13 +16,15 @@
*/
-pragma solidity ^0.4.23;
+// solhint-disable
+pragma solidity 0.4.24;
+
// @dev Interface of the asset proxy's assetData.
// The asset proxies take an ABI encoded `bytes assetData` as argument.
// This argument is ABI encoded as one of the methods of this interface.
interface IAssetData {
-
+
function ERC20Token(address tokenContract)
external
pure;
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetProxy.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetProxy.sol
index eacd5a412..71491f7bb 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetProxy.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetProxy.sol
@@ -16,11 +16,12 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./IAuthorizable.sol";
+
contract IAssetProxy is
IAuthorizable
{
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol
index cedd1744c..dd4c5fc65 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol
@@ -16,22 +16,16 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../../utils/Ownable/IOwnable.sol";
+
contract IAuthorizable is
IOwnable
{
- /// @dev Gets all authorized addresses.
- /// @return Array of authorized addresses.
- function getAuthorizedAddresses()
- external
- view
- returns (address[]);
-
/// @dev Authorizes an address.
/// @param target Address to authorize.
function addAuthorizedAddress(address target)
@@ -50,4 +44,11 @@ contract IAuthorizable is
uint256 index
)
external;
+
+ /// @dev Gets all authorized addresses.
+ /// @return Array of authorized addresses.
+ function getAuthorizedAddresses()
+ external
+ view
+ returns (address[] memory);
}
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol
index 338cb12e2..1d9a70cc1 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol
@@ -16,7 +16,9 @@
*/
-pragma solidity ^0.4.24;
+// solhint-disable
+pragma solidity 0.4.24;
+
/// @dev This contract documents the revert reasons used in the AssetProxy contracts.
/// This contract is intended to serve as a reference, but is not actually used for efficiency reasons.
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol
index 6f35bd7ec..312e1bde9 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol
@@ -16,11 +16,12 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../interfaces/IAuthorizable.sol";
+
contract MAuthorizable is
IAuthorizable
{
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
index eb58b3374..e7cf4ab5c 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
@@ -21,6 +21,7 @@ pragma solidity ^0.4.10;
import "../../multisig/MultiSigWalletWithTimeLock.sol";
import "../../utils/LibBytes/LibBytes.sol";
+
contract AssetProxyOwner is
MultiSigWalletWithTimeLock
{
@@ -32,7 +33,7 @@ contract AssetProxyOwner is
// if this contract is allowed to call the AssetProxy's `removeAuthorizedAddressAtIndex` method without a time lock.
mapping (address => bool) public isAssetProxyRegistered;
- bytes4 constant REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR = bytes4(keccak256("removeAuthorizedAddressAtIndex(address,uint256)"));
+ bytes4 constant internal REMOVE_AUTHORIZED_ADDRESS_AT_INDEX_SELECTOR = bytes4(keccak256("removeAuthorizedAddressAtIndex(address,uint256)"));
/// @dev Function will revert if the transaction does not call `removeAuthorizedAddressAtIndex`
/// on an approved AssetProxy contract.
@@ -88,6 +89,7 @@ contract AssetProxyOwner is
{
Transaction storage tx = transactions[transactionId];
tx.executed = true;
+ // solhint-disable-next-line avoid-call-value
if (tx.destination.call.value(tx.value)(tx.data))
Execution(transactionId);
else {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol b/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol
index d36e9633e..7507d3da1 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol";
@@ -27,6 +27,8 @@ import "./MixinAssetProxyDispatcher.sol";
import "./MixinTransactions.sol";
import "./MixinMatchOrders.sol";
+
+// solhint-disable no-empty-blocks
contract Exchange is
MixinExchangeCore,
MixinMatchOrders,
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol
index 9e9d88ce7..e9f882194 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol
@@ -16,13 +16,14 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../utils/Ownable/Ownable.sol";
import "../../utils/LibBytes/LibBytes.sol";
import "./mixins/MAssetProxyDispatcher.sol";
import "../AssetProxy/interfaces/IAssetProxy.sol";
+
contract MixinAssetProxyDispatcher is
Ownable,
MAssetProxyDispatcher
@@ -150,6 +151,7 @@ contract MixinAssetProxyDispatcher is
/////// Setup Data Area ///////
// This area holds `assetData`.
let dataArea := add(cdStart, 132)
+ // solhint-disable-next-line no-empty-blocks
for {} lt(dataArea, cdEnd) {} {
mstore(dataArea, mload(assetData))
dataArea := add(dataArea, 32)
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
index c0ed023ac..cf53c3176 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol";
@@ -28,6 +28,7 @@ import "./mixins/MSignatureValidator.sol";
import "./mixins/MTransactions.sol";
import "./mixins/MAssetProxyDispatcher.sol";
+
contract MixinExchangeCore is
LibConstants,
LibMath,
@@ -48,8 +49,6 @@ contract MixinExchangeCore is
// Orders with specified senderAddress and with a salt less than their epoch to are considered cancelled
mapping (address => mapping (address => uint256)) public orderEpoch;
- ////// Core exchange functions //////
-
/// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
/// and senderAddress equal to msg.sender (or null address if msg.sender == makerAddress).
/// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
@@ -174,6 +173,7 @@ contract MixinExchangeCore is
}
// Validate order expiration
+ // solhint-disable-next-line not-rely-on-time
if (block.timestamp >= order.expirationTimeSeconds) {
orderInfo.orderStatus = uint8(OrderStatus.EXPIRED);
return orderInfo;
@@ -396,7 +396,7 @@ contract MixinExchangeCore is
return fillResults;
}
- /// @dev Settles an order by transferring assets between counterparties.
+ /// @dev Settles an order by transferring assets between counterparties.
/// @param order Order struct containing order specifications.
/// @param takerAddress Address selling takerAsset and buying makerAsset.
/// @param fillResults Amounts to be filled and fees paid by maker and taker.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol
index 1a43eec79..ba687543a 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol
@@ -11,7 +11,7 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol";
@@ -23,6 +23,7 @@ import "./mixins/MMatchOrders.sol";
import "./mixins/MTransactions.sol";
import "./mixins/MAssetProxyDispatcher.sol";
+
contract MixinMatchOrders is
LibConstants,
LibMath,
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol
index 29172057a..822701459 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
import "./mixins/MSignatureValidator.sol";
@@ -24,6 +24,7 @@ import "./mixins/MTransactions.sol";
import "./interfaces/IWallet.sol";
import "./interfaces/IValidator.sol";
+
contract MixinSignatureValidator is
MSignatureValidator,
MTransactions
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
index 31f7f2847..823e14316 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
@@ -15,13 +15,14 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "./libs/LibExchangeErrors.sol";
import "./mixins/MSignatureValidator.sol";
import "./mixins/MTransactions.sol";
import "./libs/LibEIP712.sol";
+
contract MixinTransactions is
LibEIP712,
MSignatureValidator,
@@ -36,7 +37,7 @@ contract MixinTransactions is
address public currentContextAddress;
// Hash for the EIP712 ZeroEx Transaction Schema
- bytes32 constant EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = keccak256(abi.encodePacked(
+ bytes32 constant internal EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = keccak256(abi.encodePacked(
"ZeroExTransaction(",
"uint256 salt,",
"address signerAddress,",
@@ -44,41 +45,6 @@ contract MixinTransactions is
")"
));
- /// @dev Calculates EIP712 hash of the Transaction.
- /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
- /// @param signerAddress Address of transaction signer.
- /// @param data AbiV2 encoded calldata.
- /// @return EIP712 hash of the Transaction.
- function hashZeroExTransaction(
- uint256 salt,
- address signerAddress,
- bytes memory data
- )
- internal
- pure
- returns (bytes32 result)
- {
- bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
- bytes32 dataHash = keccak256(data);
- // Assembly for more efficiently computing:
- // keccak256(abi.encode(
- // EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH,
- // salt,
- // signerAddress,
- // keccak256(data)
- // ));
- assembly {
- let memPtr := mload(64)
- mstore(memPtr, schemaHash)
- mstore(add(memPtr, 32), salt)
- mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff))
- mstore(add(memPtr, 96), dataHash)
- result := keccak256(memPtr, 128)
- }
-
- return result;
- }
-
/// @dev Executes an exchange method call in the context of signer.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash.
/// @param signerAddress Address of transaction signer.
@@ -138,6 +104,41 @@ contract MixinTransactions is
currentContextAddress = address(0);
}
+ /// @dev Calculates EIP712 hash of the Transaction.
+ /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
+ /// @param signerAddress Address of transaction signer.
+ /// @param data AbiV2 encoded calldata.
+ /// @return EIP712 hash of the Transaction.
+ function hashZeroExTransaction(
+ uint256 salt,
+ address signerAddress,
+ bytes memory data
+ )
+ internal
+ pure
+ returns (bytes32 result)
+ {
+ bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
+ bytes32 dataHash = keccak256(data);
+ // Assembly for more efficiently computing:
+ // keccak256(abi.encode(
+ // EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH,
+ // salt,
+ // signerAddress,
+ // keccak256(data)
+ // ));
+ assembly {
+ let memPtr := mload(64)
+ mstore(memPtr, schemaHash)
+ mstore(add(memPtr, 32), salt)
+ mstore(add(memPtr, 64), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff))
+ mstore(add(memPtr, 96), dataHash)
+ result := keccak256(memPtr, 128)
+ }
+
+ return result;
+ }
+
/// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
/// If calling a fill function, this address will represent the taker.
/// If calling a cancel function, this address will represent the maker.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
index 00668ca43..a16d2f897 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./libs/LibMath.sol";
@@ -24,6 +24,7 @@ import "./libs/LibOrder.sol";
import "./libs/LibFillResults.sol";
import "./mixins/MExchangeCore.sol";
+
contract MixinWrapperFunctions is
LibMath,
LibFillResults,
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
index 66f3b5796..8db8d6f6c 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
@@ -16,7 +16,8 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract IAssetProxyDispatcher {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol
index 9f21c18d7..b92abba04 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./IExchangeCore.sol";
@@ -26,6 +26,8 @@ import "./ITransactions.sol";
import "./IAssetProxyDispatcher.sol";
import "./IWrapperFunctions.sol";
+
+// solhint-disable no-empty-blocks
contract IExchange is
IExchangeCore,
IMatchOrders,
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol
index 98222f33f..9995e0385 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
+
contract IExchangeCore {
/// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol
index df009d063..cea5adbbb 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol
@@ -15,12 +15,13 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
+
contract IMatchOrders {
/// @dev Match two complementary orders that have a profitable spread.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol
index 511463309..1fd0eccf0 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol
@@ -16,7 +16,8 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract ISignatureValidator {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol
index a7cab8f55..4446c55ce 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol
@@ -15,7 +15,8 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract ITransactions {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol
index 0b1796a66..2dd69100c 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol
@@ -16,7 +16,8 @@
*/
-pragma solidity ^0.4.23;
+pragma solidity 0.4.24;
+
contract IValidator {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol
index c86a2c057..c97161ca6 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol
@@ -16,7 +16,8 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract IWallet {
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol
index 84bb683bc..7c8b12724 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
+
contract IWrapperFunctions {
/// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
/// @param order LibOrder.Order struct containing order specifications.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol
index 488ca956c..6918d755e 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol
@@ -16,13 +16,15 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract LibConstants {
// Asset data for ZRX token. Used for fee transfers.
// @TODO: Hardcode constant when we deploy. Currently
// not constant to make testing easier.
+ // solhint-disable-next-line var-name-mixedcase
bytes public ZRX_ASSET_DATA;
// @TODO: Remove when we deploy.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
index b983347a4..1fc41dafd 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol
@@ -16,17 +16,18 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
contract LibEIP712 {
// EIP191 header for EIP712 prefix
- string constant EIP191_HEADER = "\x19\x01";
+ string constant internal EIP191_HEADER = "\x19\x01";
// EIP712 Domain Name value
- string constant EIP712_DOMAIN_NAME = "0x Protocol";
+ string constant internal EIP712_DOMAIN_NAME = "0x Protocol";
// EIP712 Domain Version value
- string constant EIP712_DOMAIN_VERSION = "2";
+ string constant internal EIP712_DOMAIN_VERSION = "2";
// Hash of the EIP712 Domain Separator Schema
bytes32 public constant EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked(
@@ -38,6 +39,7 @@ contract LibEIP712 {
));
// Hash of the EIP712 Domain Separator data
+ // solhint-disable-next-line var-name-mixedcase
bytes32 public EIP712_DOMAIN_HASH;
constructor ()
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol
index 01aa78a1d..a0f75bc06 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol
@@ -16,7 +16,9 @@
*/
-pragma solidity ^0.4.24;
+// solhint-disable
+pragma solidity 0.4.24;
+
/// @dev This contract documents the revert reasons used in the Exchange contract.
/// This contract is intended to serve as a reference, but is not actually used for efficiency reasons.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol
index 63f1b8c87..1b4181d94 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol
@@ -16,10 +16,11 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol";
+
contract LibFillResults is
SafeMath
{
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol
index bfe2fd33f..46c13d390 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol
@@ -16,10 +16,11 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol";
+
contract LibMath is
SafeMath
{
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol
index 954f94f76..2ea864a5a 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol
@@ -16,16 +16,17 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "./LibEIP712.sol";
+
contract LibOrder is
LibEIP712
{
// Hash for the EIP712 Order Schema
- bytes32 constant EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(
+ bytes32 constant internal EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(
"Order(",
"address makerAddress,",
"address takerAddress,",
@@ -54,6 +55,7 @@ contract LibOrder is
CANCELLED // Order has been cancelled
}
+ // solhint-disable max-line-length
struct Order {
address makerAddress; // Address that created the order.
address takerAddress; // Address that is allowed to fill the order. If set to 0, any address is allowed to fill the order.
@@ -68,6 +70,7 @@ contract LibOrder is
bytes makerAssetData; // Encoded data that can be decoded by a specified proxy contract when transferring makerAsset. The last byte references the id of this proxy.
bytes takerAssetData; // Encoded data that can be decoded by a specified proxy contract when transferring takerAsset. The last byte references the id of this proxy.
}
+ // solhint-enable max-line-length
struct OrderInfo {
uint8 orderStatus; // Status that describes order's validity and fillability.
@@ -115,17 +118,20 @@ contract LibOrder is
// ));
assembly {
// Backup
+ // solhint-disable-next-line space-after-comma
let temp1 := mload(sub(order, 32))
let temp2 := mload(add(order, 320))
let temp3 := mload(add(order, 352))
// Hash in place
+ // solhint-disable-next-line space-after-comma
mstore(sub(order, 32), schemaHash)
mstore(add(order, 320), makerAssetDataHash)
mstore(add(order, 352), takerAssetDataHash)
result := keccak256(sub(order, 32), 416)
// Restore
+ // solhint-disable-next-line space-after-comma
mstore(sub(order, 32), temp1)
mstore(add(order, 320), temp2)
mstore(add(order, 352), temp3)
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol
index 5bf59c6ce..9207dfdc2 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol
@@ -16,11 +16,12 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../interfaces/IAssetProxyDispatcher.sol";
+
contract MAssetProxyDispatcher is
IAssetProxyDispatcher
{
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol
index 6e406e1c4..9e3b5a2e2 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol
@@ -16,13 +16,14 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
import "../interfaces/IExchangeCore.sol";
+
contract MExchangeCore is
IExchangeCore
{
@@ -101,7 +102,6 @@ contract MExchangeCore is
internal
view;
-
/// @dev Validates context for cancelOrder. Succeeds or throws.
/// @param order to be cancelled.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order.
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol
index abe7c3596..a31ec1585 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol
@@ -15,13 +15,14 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
import "../libs/LibFillResults.sol";
import "../interfaces/IMatchOrders.sol";
+
contract MMatchOrders is
IMatchOrders
{
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol
index 6cc1d7a10..f14f2ba00 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol
@@ -16,10 +16,11 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../interfaces/ISignatureValidator.sol";
+
contract MSignatureValidator is
ISignatureValidator
{
diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol
index e2f89de01..f2b5e4b16 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol
@@ -15,10 +15,11 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../interfaces/ITransactions.sol";
+
contract MTransactions is
ITransactions
{
diff --git a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
index b2fe2df06..44b0777b8 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../Mintable/Mintable.sol";
import "../../utils/Ownable/Ownable.sol";
+
contract DummyERC20Token is Mintable, Ownable {
string public name;
string public symbol;
diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
index c584d0b54..5dce74a14 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol
@@ -23,10 +23,11 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../tokens/ERC721Token/IERC721Receiver.sol";
+
contract DummyERC721Receiver is
IERC721Receiver
{
diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
index 78ea96447..ba647fea4 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
@@ -16,12 +16,14 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../tokens/ERC721Token/ERC721Token.sol";
import "../../utils/Ownable/Ownable.sol";
+
+// solhint-disable no-empty-blocks
contract DummyERC721Token is
Ownable,
ERC721Token
diff --git a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol
index 5baaf6e5a..2fa0e3c5e 100644
--- a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol
+++ b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol
@@ -16,16 +16,18 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol";
import "../../protocol/Exchange/libs/LibOrder.sol";
+
contract ExchangeWrapper {
// Exchange contract.
- IExchange EXCHANGE;
+ // solhint-disable-next-line var-name-mixedcase
+ IExchange internal EXCHANGE;
constructor (address _exchange)
public
@@ -33,6 +35,35 @@ contract ExchangeWrapper {
EXCHANGE = IExchange(_exchange);
}
+ /// @dev Cancels all orders created by sender with a salt less than or equal to the targetOrderEpoch
+ /// and senderAddress equal to this contract.
+ /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
+ /// @param salt Arbitrary value to gaurantee uniqueness of 0x transaction hash.
+ /// @param makerSignature Proof that maker wishes to call this function with given params.
+ function cancelOrdersUpTo(
+ uint256 targetOrderEpoch,
+ uint256 salt,
+ bytes makerSignature
+ )
+ external
+ {
+ address makerAddress = msg.sender;
+
+ // Encode arguments into byte array.
+ bytes memory data = abi.encodeWithSelector(
+ EXCHANGE.cancelOrdersUpTo.selector,
+ targetOrderEpoch
+ );
+
+ // Call `cancelOrdersUpTo` via `executeTransaction`.
+ EXCHANGE.executeTransaction(
+ salt,
+ makerAddress,
+ data,
+ makerSignature
+ );
+ }
+
/// @dev Fills an order using `msg.sender` as the taker.
/// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
@@ -66,33 +97,4 @@ contract ExchangeWrapper {
takerSignature
);
}
-
- /// @dev Cancels all orders created by sender with a salt less than or equal to the targetOrderEpoch
- /// and senderAddress equal to this contract.
- /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
- /// @param salt Arbitrary value to gaurantee uniqueness of 0x transaction hash.
- /// @param makerSignature Proof that maker wishes to call this function with given params.
- function cancelOrdersUpTo(
- uint256 targetOrderEpoch,
- uint256 salt,
- bytes makerSignature
- )
- external
- {
- address makerAddress = msg.sender;
-
- // Encode arguments into byte array.
- bytes memory data = abi.encodeWithSelector(
- EXCHANGE.cancelOrdersUpTo.selector,
- targetOrderEpoch
- );
-
- // Call `cancelOrdersUpTo` via `executeTransaction`.
- EXCHANGE.executeTransaction(
- salt,
- makerAddress,
- data,
- makerSignature
- );
- }
}
diff --git a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
index a91bfee9e..747ac7a86 100644
--- a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
+++ b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol";
import "../../utils/SafeMath/SafeMath.sol";
+
/*
* Mintable
* Base contract that creates a mintable UnlimitedAllowanceToken
diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol
index 2ae69e0ef..76f1c6290 100644
--- a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol
+++ b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol
@@ -16,11 +16,12 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol";
+
contract TestAssetProxyDispatcher is MixinAssetProxyDispatcher {
function publicDispatchTransferFrom(
bytes memory assetData,
diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol
index 2abcd17a0..d6b6b29f2 100644
--- a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol
+++ b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol
@@ -16,13 +16,16 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol";
+
+// solhint-disable no-empty-blocks
contract TestAssetProxyOwner is
AssetProxyOwner
{
+
constructor(
address[] memory _owners,
address[] memory _assetProxyContracts,
@@ -31,11 +34,11 @@ contract TestAssetProxyOwner is
)
public
AssetProxyOwner(_owners, _assetProxyContracts, _required, _secondsTimeLocked)
- {
- }
+ {}
function testValidRemoveAuthorizedAddressAtIndexTx(uint256 id)
public
+ view
validRemoveAuthorizedAddressAtIndexTx(id)
returns (bool)
{
diff --git a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol
index f45faaf36..8b9c00590 100644
--- a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol
+++ b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol
@@ -16,11 +16,12 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
+
contract TestLibBytes {
using LibBytes for bytes;
diff --git a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol
index 010080703..40e2c84dc 100644
--- a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol
+++ b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol
@@ -16,13 +16,14 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/libs/LibMath.sol";
import "../../protocol/Exchange/libs/LibOrder.sol";
import "../../protocol/Exchange/libs/LibFillResults.sol";
+
contract TestLibs is
LibMath,
LibOrder,
diff --git a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol
index 0f84678cf..235c77d17 100644
--- a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol
+++ b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol
@@ -16,12 +16,13 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/MixinSignatureValidator.sol";
import "../../protocol/Exchange/MixinTransactions.sol";
+
contract TestSignatureValidator is
MixinSignatureValidator,
MixinTransactions
diff --git a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol
index f9271bf7a..6278aede0 100644
--- a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol
+++ b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol
@@ -16,16 +16,18 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IValidator.sol";
+
contract TestValidator is
IValidator
{
// The single valid signer for this wallet.
- address VALID_SIGNER;
+ // solhint-disable-next-line var-name-mixedcase
+ address internal VALID_SIGNER;
/// @dev constructs a new `TestValidator` with a single valid signer.
/// @param validSigner The sole, valid signer.
@@ -38,6 +40,7 @@ contract TestValidator is
/// @param signerAddress Address that should have signed the given hash.
/// @param signature Proof of signing.
/// @return Validity of signature.
+ // solhint-disable no-unused-vars
function isValidSignature(
bytes32 hash,
address signerAddress,
@@ -49,4 +52,5 @@ contract TestValidator is
{
return (signerAddress == VALID_SIGNER);
}
+ // solhint-enable no-unused-vars
}
diff --git a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol
index 17dee9e9c..0415823e3 100644
--- a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol
+++ b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol
@@ -16,20 +16,20 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IWallet.sol";
import "../../utils/LibBytes/LibBytes.sol";
+
contract TestWallet is
IWallet
{
using LibBytes for bytes;
- string constant LENGTH_65_REQUIRED = "LENGTH_65_REQUIRED";
-
// The owner of this wallet.
- address WALLET_OWNER;
+ // solhint-disable-next-line var-name-mixedcase
+ address internal WALLET_OWNER;
/// @dev constructs a new `TestWallet` with a single owner.
/// @param walletOwner The owner of this wallet.
@@ -52,7 +52,7 @@ contract TestWallet is
{
require(
eip712Signature.length == 65,
- LENGTH_65_REQUIRED
+ "LENGTH_65_REQUIRED"
);
uint8 v = uint8(eip712Signature[0]);
diff --git a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol
index 8b52858b1..60cac26ea 100644
--- a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol
+++ b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol
@@ -16,29 +16,28 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol";
import "../../protocol/Exchange/libs/LibOrder.sol";
import "../../utils/Ownable/Ownable.sol";
+
contract Whitelist is
Ownable
{
- // Revert reasons
- string constant MAKER_NOT_WHITELISTED = "MAKER_NOT_WHITELISTED"; // Maker address not whitelisted.
- string constant TAKER_NOT_WHITELISTED = "TAKER_NOT_WHITELISTED"; // Taker address not whitelisted.
- string constant INVALID_SENDER = "INVALID_SENDER"; // Sender must equal transaction origin.
// Mapping of address => whitelist status.
mapping (address => bool) public isWhitelisted;
// Exchange contract.
- IExchange EXCHANGE;
+ // solhint-disable var-name-mixedcase
+ IExchange internal EXCHANGE;
+ bytes internal TX_ORIGIN_SIGNATURE;
+ // solhint-enable var-name-mixedcase
- byte constant VALIDATOR_SIGNATURE_BYTE = "\x06";
- bytes TX_ORIGIN_SIGNATURE;
+ byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x06";
constructor (address _exchange)
public
@@ -60,6 +59,27 @@ contract Whitelist is
isWhitelisted[target] = isApproved;
}
+ /// @dev Verifies signer is same as signer of current Ethereum transaction.
+ /// NOTE: This function can currently be used to validate signatures coming from outside of this contract.
+ /// Extra safety checks can be added for a production contract.
+ /// @param signerAddress Address that should have signed the given hash.
+ /// @param signature Proof of signing.
+ /// @return Validity of order signature.
+ // solhint-disable no-unused-vars
+ function isValidSignature(
+ bytes32 hash,
+ address signerAddress,
+ bytes signature
+ )
+ external
+ view
+ returns (bool isValid)
+ {
+ // solhint-disable-next-line avoid-tx-origin
+ return signerAddress == tx.origin;
+ }
+ // solhint-enable no-unused-vars
+
/// @dev Fills an order using `msg.sender` as the taker.
/// The transaction will revert if both the maker and taker are not whitelisted.
/// Orders should specify this contract as the `senderAddress` in order to gaurantee
@@ -80,20 +100,21 @@ contract Whitelist is
// This contract must be the entry point for the transaction.
require(
+ // solhint-disable-next-line avoid-tx-origin
takerAddress == tx.origin,
- INVALID_SENDER
+ "INVALID_SENDER"
);
// Check if maker is on the whitelist.
require(
isWhitelisted[order.makerAddress],
- MAKER_NOT_WHITELISTED
+ "MAKER_NOT_WHITELISTED"
);
// Check if taker is on the whitelist.
require(
isWhitelisted[takerAddress],
- TAKER_NOT_WHITELISTED
+ "TAKER_NOT_WHITELISTED"
);
// Encode arguments into byte array.
@@ -112,22 +133,4 @@ contract Whitelist is
TX_ORIGIN_SIGNATURE
);
}
-
- /// @dev Verifies signer is same as signer of current Ethereum transaction.
- /// NOTE: This function can currently be used to validate signatures coming from outside of this contract.
- /// Extra safety checks can be added for a production contract.
- /// @param signerAddress Address that should have signed the given hash.
- /// @param signature Proof of signing.
- /// @return Validity of order signature.
- function isValidSignature(
- bytes32 hash,
- address signerAddress,
- bytes signature
- )
- external
- view
- returns (bool isValid)
- {
- return signerAddress == tx.origin;
- }
}
diff --git a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
index b6961a6ec..58ffdfcb6 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
@@ -16,19 +16,16 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "./IERC20Token.sol";
-contract ERC20Token is IERC20Token {
- string constant INSUFFICIENT_BALANCE = "ERC20_INSUFFICIENT_BALANCE";
- string constant INSUFFICIENT_ALLOWANCE = "ERC20_INSUFFICIENT_ALLOWANCE";
- string constant OVERFLOW = "Transfer would result in an overflow.";
+contract ERC20Token is IERC20Token {
- mapping (address => uint256) balances;
- mapping (address => mapping (address => uint256)) allowed;
+ mapping (address => uint256) internal balances;
+ mapping (address => mapping (address => uint256)) internal allowed;
uint256 public totalSupply;
@@ -38,11 +35,11 @@ contract ERC20Token is IERC20Token {
{
require(
balances[msg.sender] >= _value,
- INSUFFICIENT_BALANCE
+ "ERC20_INSUFFICIENT_BALANCE"
);
require(
balances[_to] + _value >= balances[_to],
- OVERFLOW
+ "OVERFLOW"
);
balances[msg.sender] -= _value;
balances[_to] += _value;
@@ -56,15 +53,15 @@ contract ERC20Token is IERC20Token {
{
require(
balances[_from] >= _value,
- INSUFFICIENT_BALANCE
+ "ERC20_INSUFFICIENT_BALANCE"
);
require(
allowed[_from][msg.sender] >= _value,
- INSUFFICIENT_ALLOWANCE
+ "ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
- OVERFLOW
+ "OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
@@ -83,7 +80,8 @@ contract ERC20Token is IERC20Token {
}
function balanceOf(address _owner)
- public view
+ public
+ view
returns (uint256)
{
return balances[_owner];
diff --git a/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol b/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol
index eb879b6a8..e3e193666 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol
@@ -16,9 +16,10 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
+
contract IERC20Token {
/// @notice send `value` token to `to` from `msg.sender`
@@ -59,6 +60,7 @@ contract IERC20Token {
public view
returns (uint256);
+ // solhint-disable-next-line no-simple-event-func-name
event Transfer(
address indexed _from,
address indexed _to,
diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol
index 41ba149e3..60603aa19 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol
@@ -23,12 +23,13 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "./IERC721Token.sol";
import "./IERC721Receiver.sol";
import "../../utils/SafeMath/SafeMath.sol";
+
/**
* @title ERC721 Non-Fungible Token Standard basic implementation
* @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
@@ -40,7 +41,7 @@ contract ERC721Token is
{
// Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`
// which can be also obtained as `ERC721Receiver(0).onERC721Received.selector`
- bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba;
+ bytes4 constant internal ERC721_RECEIVED = 0xf0b9e5ba;
// Mapping from token ID to owner
mapping (uint256 => address) internal tokenOwner;
@@ -72,7 +73,7 @@ contract ERC721Token is
_;
}
- function ERC721Token(
+ constructor (
string _name,
string _symbol)
public
diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol
index b0fff3c90..f2e8f3c88 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol
@@ -23,7 +23,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
/**
* @title ERC721 token receiver interface
@@ -37,7 +38,7 @@ contract IERC721Receiver {
* Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`,
* which can be also obtained as `ERC721Receiver(0).onERC721Received.selector`
*/
- bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba;
+ bytes4 constant internal ERC721_RECEIVED = 0xf0b9e5ba;
/**
* @notice Handle the receipt of an NFT
diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol
index 345712d67..4d57ece38 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol
@@ -23,7 +23,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
/**
* @title ERC721 Non-Fungible Token Standard basic interface
@@ -39,11 +40,13 @@ contract IERC721Token {
address indexed _to,
uint256 _tokenId
);
+
event Approval(
address indexed _owner,
address indexed _approved,
uint256 _tokenId
);
+
event ApprovalForAll(
address indexed _owner,
address indexed _operator,
@@ -54,6 +57,7 @@ contract IERC721Token {
public
view
returns (string);
+
function symbol()
public
view
@@ -63,10 +67,12 @@ contract IERC721Token {
public
view
returns (uint256 _balance);
+
function ownerOf(uint256 _tokenId)
public
view
returns (address _owner);
+
function exists(uint256 _tokenId)
public
view
@@ -74,6 +80,7 @@ contract IERC721Token {
function approve(address _to, uint256 _tokenId)
public;
+
function getApproved(uint256 _tokenId)
public
view
@@ -81,6 +88,7 @@ contract IERC721Token {
function setApprovalForAll(address _operator, bool _approved)
public;
+
function isApprovedForAll(address _owner, address _operator)
public
view
@@ -89,17 +97,22 @@ contract IERC721Token {
function transferFrom(
address _from,
address _to,
- uint256 _tokenId)
+ uint256 _tokenId
+ )
public;
+
function safeTransferFrom(
address _from,
address _to,
- uint256 _tokenId)
+ uint256 _tokenId
+ )
public;
+
function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
- bytes _data)
+ bytes _data
+ )
public;
}
diff --git a/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol b/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
index f62602ab3..a974503ca 100644
--- a/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
+++ b/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
@@ -16,14 +16,15 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../ERC20Token/ERC20Token.sol";
+
contract UnlimitedAllowanceToken is ERC20Token {
- uint256 constant MAX_UINT = 2**256 - 1;
+ uint256 constant internal MAX_UINT = 2**256 - 1;
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance. See https://github.com/ethereum/EIPs/issues/717
/// @param _from Address to transfer from.
@@ -37,15 +38,15 @@ contract UnlimitedAllowanceToken is ERC20Token {
uint256 allowance = allowed[_from][msg.sender];
require(
balances[_from] >= _value,
- INSUFFICIENT_BALANCE
+ "ERC20_INSUFFICIENT_BALANCE"
);
require(
allowance >= _value,
- INSUFFICIENT_ALLOWANCE
+ "ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
- OVERFLOW
+ "OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
diff --git a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol b/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol
index 733ca414b..1fdb04de5 100644
--- a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol
+++ b/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol
@@ -13,8 +13,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+// solhint-disable
pragma solidity ^0.4.18;
+
contract WETH9 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
diff --git a/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol b/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol
index 2e5b61e0b..28c0b2fb3 100644
--- a/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol
+++ b/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol
@@ -16,18 +16,24 @@
*/
-pragma solidity ^0.4.11;
+pragma solidity 0.4.11;
+// solhint-disable-next-line max-line-length
import { UnlimitedAllowanceToken_v1 as UnlimitedAllowanceToken } from "../../../1.0.0/UnlimitedAllowanceToken/UnlimitedAllowanceToken_v1.sol";
+
contract ZRXToken is UnlimitedAllowanceToken {
+ // solhint-disable const-name-snakecase
uint8 constant public decimals = 18;
uint public totalSupply = 10**27; // 1 billion tokens, 18 decimal places
string constant public name = "0x Protocol Token";
string constant public symbol = "ZRX";
+ // solhint-enableconst-name-snakecase
- function ZRXToken() {
+ function ZRXToken()
+ public
+ {
balances[msg.sender] = totalSupply;
}
}
diff --git a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
index 78b1ddf7c..01d34fa8f 100644
--- a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
@@ -16,7 +16,8 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
+
library LibBytes {
@@ -114,6 +115,7 @@ library LibBytes {
// Copy whole words front to back
// Note: the first check is always true,
// this could have been a do-while loop.
+ // solhint-disable-next-line no-empty-blocks
for {} lt(source, sEnd) {} {
mstore(dest, mload(source))
source := add(source, 32)
@@ -144,6 +146,7 @@ library LibBytes {
// 2**255, so they can be safely re-interpreted as signed.
// Note: the first check is always true,
// this could have been a do-while loop.
+ // solhint-disable-next-line no-empty-blocks
for {} slt(dest, dEnd) {} {
mstore(dEnd, mload(sEnd))
sEnd := sub(sEnd, 32)
@@ -156,13 +159,17 @@ library LibBytes {
}
}
}
-
+
/// @dev Returns a slices from a byte array.
/// @param b The byte array to take a slice from.
/// @param from The starting index for the slice (inclusive).
/// @param to The final index for the slice (exclusive).
/// @return result The slice containing bytes at indices [from, to)
- function slice(bytes memory b, uint256 from, uint256 to)
+ function slice(
+ bytes memory b,
+ uint256 from,
+ uint256 to
+ )
internal
pure
returns (bytes memory result)
@@ -191,7 +198,11 @@ library LibBytes {
/// @param to The final index for the slice (exclusive).
/// @return result The slice containing bytes at indices [from, to)
/// @dev When `from == 0`, the original array will match the slice. In other cases its state will be corrupted.
- function sliceDestructive(bytes memory b, uint256 from, uint256 to)
+ function sliceDestructive(
+ bytes memory b,
+ uint256 from,
+ uint256 to
+ )
internal
pure
returns (bytes memory result)
@@ -343,7 +354,10 @@ library LibBytes {
// 1. Add index to address of bytes array
// 2. Load 32-byte word from memory
// 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address
- let neighbors := and(mload(add(b, index)), 0xffffffffffffffffffffffff0000000000000000000000000000000000000000)
+ let neighbors := and(
+ mload(add(b, index)),
+ 0xffffffffffffffffffffffff0000000000000000000000000000000000000000
+ )
// Make sure input address is clean.
// (Solidity does not guarantee this)
@@ -508,7 +522,7 @@ library LibBytes {
// Assert length of <b> is valid, given
// length of input
require(
- b.length >= index + 32 /* 32 bytes to store length */ + input.length,
+ b.length >= index + 32 + input.length, // 32 bytes to store length
"GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED"
);
diff --git a/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol b/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol
index e77680903..36563d837 100644
--- a/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol
+++ b/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol
@@ -1,4 +1,4 @@
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
/*
diff --git a/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol b/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol
index 6f5761cc7..81a14a447 100644
--- a/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol
+++ b/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol
@@ -1,4 +1,4 @@
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
/*
@@ -10,6 +10,7 @@ pragma experimental ABIEncoderV2;
import "./IOwnable.sol";
+
contract Ownable is IOwnable {
address public owner;
diff --git a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol
index e137f6ca5..8cbb8e526 100644
--- a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol
+++ b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol
@@ -1,6 +1,7 @@
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
+
contract SafeMath {
function safeMul(uint a, uint b)
internal