aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-07-10 02:08:28 +0800
committerGitHub <noreply@github.com>2018-07-10 02:08:28 +0800
commit4b60a3cbab3a97125499cb89d9c253deebfb7d2d (patch)
tree3cd745f49d55406e95453bf3efac6383fba5f038 /packages/contracts
parent9f08916cf18ad3e2686811933116122eea0890b9 (diff)
parent17956efe351e3ec0b1e9cdeee8292ebb0b4e563c (diff)
downloaddexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.gz
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.bz2
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.lz
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.xz
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.zst
dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.zip
Merge branch 'v2-prototype' into abi-gen-ignore-unchanged
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/.solhint.json23
-rw-r--r--packages/contracts/package.json26
-rw-r--r--packages/contracts/src/2.0.0/forwarder/Forwarder.sol50
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinConstants.sol22
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinERC721.sol64
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol4
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol121
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinFees.sol (renamed from packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol)30
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol (renamed from packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol)217
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol11
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol196
-rw-r--r--packages/contracts/src/2.0.0/forwarder/MixinTransfer.sol (renamed from packages/contracts/src/2.0.0/forwarder/MixinERC20.sol)64
-rw-r--r--packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol66
-rw-r--r--packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol30
-rw-r--r--packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol79
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol35
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol42
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol63
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol92
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol42
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol46
-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.sol7
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol7
-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.sol5
-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.sol3
-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.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol13
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol5
-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.sol83
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol2
-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.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol2
-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.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol8
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol36
-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.sol3
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol2
-rw-r--r--packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol2
-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.sol2
-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.sol62
-rw-r--r--packages/contracts/src/2.0.0/test/Mintable/Mintable.sol8
-rw-r--r--packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol6
-rw-r--r--packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol8
-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.sol8
-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.sol6
-rw-r--r--packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol8
-rw-r--r--packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol64
-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.sol6
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol4
-rw-r--r--packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol20
-rw-r--r--packages/contracts/src/2.0.0/tokens/EtherToken/IEtherToken.sol33
-rw-r--r--packages/contracts/src/2.0.0/tokens/EtherToken/WETH9.sol (renamed from packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol)1
-rw-r--r--packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol11
-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.sol25
-rw-r--r--packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol3
-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.sol17
85 files changed, 1216 insertions, 706 deletions
diff --git a/packages/contracts/.solhint.json b/packages/contracts/.solhint.json
index 7e3b4dca2..076afe9f3 100644
--- a/packages/contracts/.solhint.json
+++ b/packages/contracts/.solhint.json
@@ -1,17 +1,20 @@
{
"extends": "default",
"rules": {
- "bracket-align": "warn",
- "code-complexity": "warn",
- "const-name-snakecase": "warn",
- "expression-indent": "warn",
- "function-max-lines": "warn",
- "statement-indent": "warn",
- "indent": ["warn", 4],
+ "avoid-low-level-calls": false,
+ "avoid-tx-origin": "warn",
+ "bracket-align": false,
+ "code-complexity": false,
+ "const-name-snakecase": "error",
+ "expression-indent": "error",
+ "function-max-lines": false,
+ "func-order": "error",
+ "indent": ["error", 4],
+ "max-line-length": ["warn", 160],
+ "no-inline-assembly": false,
"quotes": ["error", "double"],
- "max-line-length": ["warn", 120],
- "separate-by-one-line-in-contract": "warn",
+ "separate-by-one-line-in-contract": "error",
"space-after-comma": "error",
- "func-order": "warn"
+ "statement-indent": "error"
}
}
diff --git a/packages/contracts/package.json b/packages/contracts/package.json
index a8bbdbe16..98b133e63 100644
--- a/packages/contracts/package.json
+++ b/packages/contracts/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "contracts",
- "version": "2.1.33",
+ "version": "2.1.34",
"engines": {
"node": ">=6.12"
},
@@ -24,13 +24,13 @@
"compile": "sol-compiler --contracts-dir src",
"clean": "shx rm -rf lib generated_contract_wrappers",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output generated_contract_wrappers --backend ethers",
- "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/* --exclude **/lib/**/*",
+ "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/* --exclude **/lib/**/* && yarn lint-contracts",
"coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html",
"profiler:report:html": "istanbul report html && open coverage/index.html",
"coverage:report:lcov": "istanbul report lcov",
"test:circleci": "yarn test",
- "lint-contracts": "solhint src/2.0.0/**/*.sol"
+ "lint-contracts": "solhint src/2.0.0/**/**/**/**/*.sol"
},
"config": {
"abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestAssetProxyDispatcher|TestLibBytes|TestLibs|TestSignatureValidator|TestValidator|TestWallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json"
@@ -46,11 +46,11 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/contracts/README.md",
"devDependencies": {
- "@0xproject/abi-gen": "^0.3.2",
- "@0xproject/dev-utils": "^0.4.4",
- "@0xproject/tslint-config": "^0.4.20",
- "@0xproject/subproviders": "^0.10.1",
- "@0xproject/sol-cov": "^0.1.1",
+ "@0xproject/abi-gen": "^0.3.3",
+ "@0xproject/dev-utils": "^0.4.5",
+ "@0xproject/tslint-config": "^0.4.21",
+ "@0xproject/subproviders": "^0.10.5",
+ "@0xproject/sol-cov": "^0.1.2",
"@types/lodash": "4.14.104",
"@types/bn.js": "^4.11.0",
"@types/node": "^8.0.53",
@@ -72,13 +72,13 @@
"yargs": "^10.0.3"
},
"dependencies": {
- "@0xproject/base-contract": "^0.3.4",
+ "@0xproject/base-contract": "^0.3.5",
"@0xproject/order-utils": "^1.0.0",
- "@0xproject/sol-compiler": "^0.5.2",
+ "@0xproject/sol-compiler": "^0.5.3",
"@0xproject/types": "^1.0.0",
- "@0xproject/typescript-typings": "^0.4.1",
- "@0xproject/utils": "^0.7.1",
- "@0xproject/web3-wrapper": "^0.7.1",
+ "@0xproject/typescript-typings": "^0.4.2",
+ "@0xproject/utils": "^0.7.2",
+ "@0xproject/web3-wrapper": "^0.7.2",
"ethereum-types": "^0.0.2",
"bn.js": "^4.11.8",
"ethereumjs-abi": "^0.6.4",
diff --git a/packages/contracts/src/2.0.0/forwarder/Forwarder.sol b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol
index 71a4aff13..fc17a4c72 100644
--- a/packages/contracts/src/2.0.0/forwarder/Forwarder.sol
+++ b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol
@@ -16,24 +16,25 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
-import "./MixinWethFees.sol";
-import "./MixinMarketSellTokens.sol";
-import "./MixinMarketBuyTokens.sol";
+import "./MixinFees.sol";
+import "./MixinForwarderCore.sol";
import "./MixinConstants.sol";
-import "../utils/Ownable/Ownable.sol";
+import "./MixinMarketBuyZrx.sol";
+import "./MixinExpectedResults.sol";
+import "./MixinTransfer.sol";
+
contract Forwarder is
- Ownable,
MixinConstants,
- MixinWethFees,
+ MixinExpectedResults,
+ MixinFees,
MixinMarketBuyZrx,
- MixinMarketBuyTokens,
- MixinMarketSellTokens
+ MixinTransfer,
+ MixinForwarderCore
{
- uint256 MAX_UINT = 2**256 - 1;
constructor (
address _exchange,
@@ -44,7 +45,6 @@ contract Forwarder is
bytes memory _wethAssetData
)
public
- Ownable()
MixinConstants(
_exchange,
_etherToken,
@@ -52,30 +52,6 @@ contract Forwarder is
_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);
- }
- }
+ MixinForwarderCore()
+ {}
}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol
index 18f2ba3bc..2b064d579 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol
@@ -16,19 +16,14 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
-import "../protocol/Exchange/Exchange.sol";
-import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
-import "../tokens/ERC20Token/IERC20Token.sol";
+import "./mixins/MConstants.sol";
-contract MixinConstants {
- Exchange EXCHANGE;
- EtherToken ETHER_TOKEN;
- IERC20Token ZRX_TOKEN;
- bytes ZRX_ASSET_DATA;
- bytes WETH_ASSET_DATA;
+contract MixinConstants is
+ MConstants
+{
constructor (
address _exchange,
@@ -39,11 +34,10 @@ contract MixinConstants {
)
public
{
- EXCHANGE = Exchange(_exchange);
- ETHER_TOKEN = EtherToken(_etherToken);
+ EXCHANGE = IExchange(_exchange);
+ ETHER_TOKEN = IEtherToken(_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/MixinERC721.sol b/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol
deleted file mode 100644
index b2e8803a9..000000000
--- a/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-
- 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 ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,uint256,bytes)"));
- bytes4 constant 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
index c2a6ea0a4..1b3e3f488 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.sol
@@ -16,7 +16,9 @@
*/
-pragma solidity ^0.4.24;
+// 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 {
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol
index 0bca7dc80..a575c9675 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol
@@ -16,106 +16,71 @@
*/
-pragma solidity ^0.4.24;
+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";
+import "./mixins/MConstants.sol";
+import "./mixins/MExpectedResults.sol";
+
contract MixinExpectedResults is
LibMath,
LibFillResults,
- MixinConstants
+ MConstants,
+ MExpectedResults
{
- /// @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.
+ /// @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 takerAssetFillAmount A number representing the amount of this order to fill.
+ /// @param makerAssetFillAmount A number representing the amount of this order to fill.
/// @return totalFillResults Amounts filled and fees paid by maker and taker.
- function calculateMarketSellResults(
+ function calculateMarketBuyResults(
LibOrder.Order[] memory orders,
- uint256 takerAssetFillAmount
+ uint256 makerAssetFillAmount
)
- internal
+ public
view
returns (FillResults memory totalFillResults)
{
for (uint256 i = 0; i < orders.length; i++) {
- uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
+ 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.takerAssetFilledAmount == takerAssetFillAmount) {
+ if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) {
break;
}
}
return totalFillResults;
}
- /// @dev Calculates a total FillResults for buying makerAssetFillAmount over all orders.
+ /// @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 makerAssetFillAmount A number representing the amount of this order to fill.
+ /// @param takerAssetFillAmount A number representing the amount of this order to fill.
/// @return totalFillResults Amounts filled and fees paid by maker and taker.
- function calculateMarketBuyResults(
+ function calculateMarketSellResults(
LibOrder.Order[] memory orders,
- uint256 makerAssetFillAmount
+ uint256 takerAssetFillAmount
)
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
- );
+ uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount);
addFillResults(totalFillResults, singleFillResult);
- if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) {
+ if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) {
break;
}
}
@@ -155,4 +120,42 @@ contract MixinExpectedResults is
}
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;
+ }
}
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol b/packages/contracts/src/2.0.0/forwarder/MixinFees.sol
index 9206c5fe0..8ea00a1d5 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinFees.sol
@@ -16,21 +16,33 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
-import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
import "../protocol/Exchange/libs/LibMath.sol";
-import "./MixinConstants.sol";
+import "./mixins/MConstants.sol";
+import "./mixins/MFees.sol";
-contract MixinWethFees is
+
+contract MixinFees is
LibMath,
- MixinConstants
+ MConstants,
+ MFees
{
- 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%
+ 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 Default payabale function, this allows us to withdraw WETH
+ function ()
+ public
+ payable
+ {
+ require(
+ msg.sender == address(ETHER_TOKEN),
+ "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"
+ );
+ }
/// @dev Pays the feeRecipient feeProportion of the total takerEthAmount, denominated in ETH
/// @param takerEthAmount The total amount that was transacted in WETH, fees are calculated from this value.
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol
index ef06fe519..eadeaf5ba 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinForwarderCore.sol
@@ -16,28 +16,122 @@
*/
-pragma solidity ^0.4.24;
+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 "./mixins/MFees.sol";
+import "./mixins/MMarketBuyZrx.sol";
+import "./mixins/MExpectedResults.sol";
+import "./mixins/MTransfer.sol";
+import "./mixins/MConstants.sol";
+import "./mixins/MForwarderCore.sol";
import "../protocol/Exchange/libs/LibOrder.sol";
+import "../protocol/Exchange/libs/LibFillResults.sol";
-contract MixinMarketBuyTokens is
- MixinConstants,
- MixinWethFees,
- MixinMarketBuyZrx,
- MixinExpectedResults,
- MixinERC20,
- MixinERC721
+
+contract MixinForwarderCore is
+ LibFillResults,
+ MConstants,
+ MExpectedResults,
+ MFees,
+ MMarketBuyZrx,
+ MTransfer,
+ MForwarderCore
{
- bytes4 public constant ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
- bytes4 public constant ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
+ bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
+ bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
+ uint256 constant internal MAX_UINT = 2**256 - 1;
+
+ constructor ()
+ public
+ {
+ address proxyAddress = EXCHANGE.getAssetProxy(ERC20_DATA_ID);
+ if (proxyAddress != address(0)) {
+ ETHER_TOKEN.approve(proxyAddress, MAX_UINT);
+ ZRX_TOKEN.approve(proxyAddress, MAX_UINT);
+ }
+ }
+
+ /// @dev Market sells ETH for ERC20 tokens, performing fee abstraction if required. This does not support ERC721 tokens. This function is payable
+ /// 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
+ transferERC20Token(
+ makerTokenAddress,
+ msg.sender,
+ totalFillResults.makerAssetFilledAmount
+ );
+ return totalFillResults;
+ }
/// @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.
@@ -62,8 +156,8 @@ contract MixinMarketBuyTokens is
uint16 feeProportion,
address feeRecipient
)
- payable
public
+ payable
returns (FillResults memory totalFillResults)
{
uint256 takerEthAmount = msg.value;
@@ -112,6 +206,85 @@ contract MixinMarketBuyTokens is
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;
+ }
+
/// @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.
@@ -126,8 +299,8 @@ contract MixinMarketBuyTokens is
bytes[] memory feeSignatures,
uint256 makerTokenFillAmount
)
- private
- returns (FillResults memory totalFillResults)
+ internal
+ returns (LibFillResults.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);
@@ -188,7 +361,7 @@ contract MixinMarketBuyTokens is
);
}
// Transfer all purchased tokens to msg.sender
- transferToken(
+ transferERC20Token(
makerTokenAddress,
msg.sender,
marketBuyResults.makerAssetFilledAmount
@@ -208,8 +381,8 @@ contract MixinMarketBuyTokens is
LibOrder.Order[] memory feeOrders,
bytes[] memory feeSignatures
)
- private
- returns (FillResults memory totalFillResults)
+ internal
+ returns (LibFillResults.FillResults memory totalFillResults)
{
uint256 totalZrxFeeAmount;
uint256 ordersLength = orders.length;
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol
index 4dbb34de3..e272f8aad 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol
@@ -16,20 +16,23 @@
*/
-pragma solidity ^0.4.24;
+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";
+import "./mixins/MConstants.sol";
+import "./mixins/MMarketBuyZrx.sol";
+
contract MixinMarketBuyZrx is
LibMath,
LibFillResults,
- MixinConstants
+ MConstants,
+ MMarketBuyZrx
{
+
/// @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
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol
deleted file mode 100644
index 8c9cdb8d5..000000000
--- a/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
-
- 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
- )
- payable
- public
- 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/MixinERC20.sol b/packages/contracts/src/2.0.0/forwarder/MixinTransfer.sol
index 53d4116d7..6c49330f2 100644
--- a/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol
+++ b/packages/contracts/src/2.0.0/forwarder/MixinTransfer.sol
@@ -16,15 +16,49 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
-contract MixinERC20 {
+import "../utils/LibBytes/LibBytes.sol";
+import "../tokens/ERC721Token/IERC721Token.sol";
+import "./mixins/MTransfer.sol";
- string constant ERROR_TRANSFER_FAILED = "TRANSFER_FAILED";
- bytes4 constant ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));
- function transferToken(
+contract MixinTransfer is
+ MTransfer
+{
+
+ using LibBytes for bytes;
+
+ bytes4 constant internal ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));
+ 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 transferERC20Token(
address token,
address to,
uint256 amount
@@ -65,4 +99,22 @@ contract MixinERC20 {
"TRANSFER_FAILED"
);
}
+
+ 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/interfaces/IExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol
new file mode 100644
index 000000000..89187b750
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.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 "../../protocol/Exchange/libs/LibFillResults.sol";
+import "../../protocol/Exchange/libs/LibOrder.sol";
+
+
+contract IExpectedResults {
+
+ /// @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 (LibFillResults.FillResults memory totalFillResults);
+
+ /// @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
+ )
+ public
+ view
+ returns (LibFillResults.FillResults memory 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 (LibFillResults.FillResults memory totalFillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol
new file mode 100644
index 000000000..745dd29a9
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol
@@ -0,0 +1,30 @@
+/*
+
+ 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 "./IForwarderCore.sol";
+import "./IExpectedResults.sol";
+
+
+// solhint-disable no-empty-blocks
+contract IForwarder is
+ IForwarderCore,
+ IExpectedResults
+{}
diff --git a/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol
new file mode 100644
index 000000000..7ac2a8af3
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol
@@ -0,0 +1,79 @@
+/*
+
+ 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 "../../protocol/Exchange/libs/LibFillResults.sol";
+
+
+contract IForwarderCore {
+
+ /// @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 (LibFillResults.FillResults memory totalFillResults);
+
+ /// @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 (LibFillResults.FillResults memory totalFillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
new file mode 100644
index 000000000..348bf169e
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.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.
+
+*/
+
+pragma solidity 0.4.24;
+
+import "../../protocol/Exchange/interfaces/IExchange.sol";
+import "../../tokens/EtherToken/IEtherToken.sol";
+import "../../tokens/ERC20Token/IERC20Token.sol";
+
+
+contract MConstants {
+
+ // solhint-disable var-name-mixedcase
+ IExchange internal EXCHANGE;
+ IEtherToken internal ETHER_TOKEN;
+ IERC20Token internal ZRX_TOKEN;
+ bytes internal ZRX_ASSET_DATA;
+ bytes internal WETH_ASSET_DATA;
+ // solhint-enable var-name-mixedcase
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
new file mode 100644
index 000000000..cf03bb32e
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
@@ -0,0 +1,42 @@
+/*
+
+ 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/LibFillResults.sol";
+import "../../protocol/Exchange/libs/LibOrder.sol";
+import "../interfaces/IExpectedResults.sol";
+
+
+contract MExpectedResults is
+ IExpectedResults
+{
+
+ /// @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 (LibFillResults.FillResults memory fillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
new file mode 100644
index 000000000..f332637ea
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
@@ -0,0 +1,63 @@
+/*
+
+ 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;
+
+
+contract MFees {
+
+ /// @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);
+
+ /// @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;
+
+ /// @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);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
new file mode 100644
index 000000000..4a54e76b1
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
@@ -0,0 +1,92 @@
+/*
+
+ 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 "../../protocol/Exchange/libs/LibFillResults.sol";
+import "../interfaces/IForwarderCore.sol";
+
+
+contract MForwarderCore is
+ IForwarderCore
+{
+
+ /// @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 (LibFillResults.FillResults memory 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 (LibFillResults.FillResults memory 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
+ )
+ internal
+ returns (LibFillResults.FillResults memory 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
+ )
+ internal
+ returns (LibFillResults.FillResults memory totalFillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
new file mode 100644
index 000000000..3501ef001
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
@@ -0,0 +1,42 @@
+/*
+
+ 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/libs/LibFillResults.sol";
+import "../../protocol/Exchange/libs/LibOrder.sol";
+
+
+contract MMarketBuyZrx {
+
+ /// @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 (LibFillResults.FillResults memory totalFillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
new file mode 100644
index 000000000..418a6288b
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
@@ -0,0 +1,46 @@
+/*
+
+ 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;
+
+
+contract MTransfer {
+
+ function onERC721Received(address, uint256, bytes memory)
+ public
+ pure
+ returns(bytes4);
+
+ function onERC721Received(address, address, uint256, bytes memory)
+ public
+ pure
+ returns(bytes4);
+
+ function transferERC20Token(
+ address token,
+ address to,
+ uint256 amount
+ )
+ internal;
+
+ function transferERC721Token(
+ bytes memory assetData,
+ address to
+ )
+ internal;
+}
diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
index 1ceecd907..eb54fe047 100644
--- a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
+++ b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol
@@ -1,6 +1,6 @@
+// solhint-disable
pragma solidity ^0.4.10;
-// solhint-disable
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <stefan.george@consensys.net>
diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
index d714b661d..8c5e6e1e6 100644
--- a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
+++ b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol
@@ -16,11 +16,11 @@
*/
+// solhint-disable
pragma solidity ^0.4.10;
import "./MultiSigWallet.sol";
-// solhint-disable
/// @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>
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..b5cec6b64 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,19 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
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..1f9958b43 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,19 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
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 5bc5f3a47..ff4660a31 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../utils/Ownable/Ownable.sol";
import "./mixins/MAuthorizable.sol";
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 b4ff2d900..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,7 +16,8 @@
*/
-pragma solidity ^0.4.23;
+// solhint-disable
+pragma solidity 0.4.24;
// @dev Interface of the asset proxy's assetData.
@@ -24,12 +25,10 @@ pragma solidity ^0.4.23;
// This argument is ABI encoded as one of the methods of this interface.
interface IAssetData {
- // solhint-disable-next-line func-name-mixedcase
function ERC20Token(address tokenContract)
external
pure;
- // solhint-disable-next-line func-name-mixedcase
function ERC721Token(
address tokenContract,
uint256 tokenId,
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 0ef1ed2e0..3651dd694 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,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "./IAuthorizable.sol";
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 286db74aa..8fac43a47 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,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../../utils/Ownable/IOwnable.sol";
@@ -26,13 +25,6 @@ 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)
@@ -51,4 +43,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 4b460ea9a..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,8 @@
*/
-pragma solidity ^0.4.24;
+// solhint-disable
+pragma solidity 0.4.24;
/// @dev This contract documents the revert reasons used in the AssetProxy contracts.
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 66c259a23..8afc8c8d8 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,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../interfaces/IAuthorizable.sol";
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 232155a6b..e7cf4ab5c 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
@@ -33,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.
@@ -89,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 effff82e0..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";
@@ -28,6 +28,7 @@ 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 dcfe9e1de..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../utils/Ownable/Ownable.sol";
import "../../utils/LibBytes/LibBytes.sol";
@@ -151,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 9e63dc1c0..ec84b1e19 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";
@@ -49,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.
@@ -175,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;
@@ -375,21 +374,19 @@ contract MixinExchangeCore is
returns (FillResults memory fillResults)
{
// Compute proportional transfer amounts
- // TODO: All three are multiplied by the same fraction. This can
- // potentially be optimized.
fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
fillResults.makerAssetFilledAmount = getPartialAmount(
- fillResults.takerAssetFilledAmount,
+ takerAssetFilledAmount,
order.takerAssetAmount,
order.makerAssetAmount
);
fillResults.makerFeePaid = getPartialAmount(
- fillResults.takerAssetFilledAmount,
+ takerAssetFilledAmount,
order.takerAssetAmount,
order.makerFee
);
fillResults.takerFeePaid = getPartialAmount(
- fillResults.takerAssetFilledAmount,
+ takerAssetFilledAmount,
order.takerAssetAmount,
order.takerFee
);
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 bfe838837..56b309a1b 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";
@@ -41,7 +41,6 @@ contract MixinMatchOrders is
/// @param leftSignature Proof that order was created by the left maker.
/// @param rightSignature Proof that order was created by the right maker.
/// @return matchedFillResults Amounts filled and fees paid by maker and taker of matched orders.
- /// TODO: Make this function external once supported by Solidity (See Solidity Issues #3199, #1603)
function matchOrders(
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder,
@@ -184,7 +183,6 @@ contract MixinMatchOrders is
leftTakerAssetFilledAmount = leftTakerAssetAmountRemaining;
// The right order receives an amount proportional to how much was spent.
- // TODO: Can we ensure rounding error is in the correct direction?
rightTakerAssetFilledAmount = getPartialAmount(
rightOrder.takerAssetAmount,
rightOrder.makerAssetAmount,
@@ -195,7 +193,6 @@ contract MixinMatchOrders is
rightTakerAssetFilledAmount = rightTakerAssetAmountRemaining;
// The left order receives an amount proportional to how much was spent.
- // TODO: Can we ensure rounding error is in the correct direction?
leftTakerAssetFilledAmount = getPartialAmount(
rightOrder.makerAssetAmount,
rightOrder.takerAssetAmount,
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 78f13286f..ac7382715 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";
@@ -91,7 +91,6 @@ contract MixinSignatureValidator is
view
returns (bool isValid)
{
- // TODO: Domain separation: make hash depend on role. (Taker sig should not be valid as maker sig, etc.)
require(
signature.length > 0,
"LENGTH_GREATER_THAN_0_REQUIRED"
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 3b18ac733..88d2da7d7 100644
--- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol
@@ -15,7 +15,7 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "./libs/LibExchangeErrors.sol";
import "./mixins/MSignatureValidator.sol";
@@ -37,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,",
@@ -45,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.
@@ -134,9 +99,47 @@ contract MixinTransactions is
"FAILED_EXECUTION"
);
- // Reset current transaction signer
- // TODO: Check if gas is paid when currentContextAddress is already 0.
- currentContextAddress = address(0);
+ // Reset current transaction signer if it was previously updated
+ if (signerAddress != msg.sender) {
+ 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`).
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 678d0252a..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";
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 b73881c07..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,7 @@
*/
-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 05e5dedf4..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";
@@ -27,6 +27,7 @@ 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 2b573eb1a..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
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 d44116474..73447f3ae 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,7 +15,7 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
@@ -33,7 +33,6 @@ contract IMatchOrders {
/// @param leftSignature Proof that order was created by the left maker.
/// @param rightSignature Proof that order was created by the right maker.
/// @return matchedFillResults Amounts filled and fees paid by maker and taker of matched orders.
- /// TODO: Make this function external once supported by Solidity (See Solidity Issues #3199, #1603)
function matchOrders(
LibOrder.Order memory leftOrder,
LibOrder.Order memory rightOrder,
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 c5a4a57e1..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,7 @@
*/
-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 aaaee389f..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,7 @@
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 2c0a5dbe2..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,7 @@
*/
-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 c2db4a5b1..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,7 @@
*/
-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 04257b883..ad7a56a06 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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
@@ -24,6 +24,7 @@ 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.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell.
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 76200ec44..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
contract LibConstants {
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 2bd7b60d4..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,18 +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(
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 99f683e1a..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,8 @@
*/
-pragma solidity ^0.4.24;
+// solhint-disable
+pragma solidity 0.4.24;
/// @dev This contract documents the revert reasons used in the Exchange contract.
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 35fa9ac0f..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol";
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 9da784854..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol";
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 dda581d9f..68f2c8aed 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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "./LibEIP712.sol";
@@ -26,7 +26,7 @@ contract LibOrder is
{
// 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,",
@@ -55,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.
@@ -69,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.
@@ -99,21 +101,23 @@ contract LibOrder is
bytes32 schemaHash = EIP712_ORDER_SCHEMA_HASH;
bytes32 makerAssetDataHash = keccak256(order.makerAssetData);
bytes32 takerAssetDataHash = keccak256(order.takerAssetData);
+
// Assembly for more efficiently computing:
- // keccak256(abi.encode(
- // order.makerAddress,
- // order.takerAddress,
- // order.feeRecipientAddress,
- // order.senderAddress,
- // order.makerAssetAmount,
- // order.takerAssetAmount,
- // order.makerFee,
- // order.takerFee,
- // order.expirationTimeSeconds,
- // order.salt,
- // keccak256(order.makerAssetData),
- // keccak256(order.takerAssetData)
- // ));
+ // keccak256(abi.encode(
+ // order.makerAddress,
+ // order.takerAddress,
+ // order.feeRecipientAddress,
+ // order.senderAddress,
+ // order.makerAssetAmount,
+ // order.takerAssetAmount,
+ // order.makerFee,
+ // order.takerFee,
+ // order.expirationTimeSeconds,
+ // order.salt,
+ // keccak256(order.makerAssetData),
+ // keccak256(order.takerAssetData)
+ // ));
+
assembly {
// Backup
// solhint-disable-next-line space-after-comma
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 367b37e80..c6904300a 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,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../interfaces/IAssetProxyDispatcher.sol";
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 e28d9d25b..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
@@ -102,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 289514b24..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,7 +15,7 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol";
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 83650b4aa..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../interfaces/ISignatureValidator.sol";
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 a9fa6d4e2..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,7 +15,7 @@
limitations under the License.
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../interfaces/ITransactions.sol";
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 7a2702449..97801166a 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../Mintable/Mintable.sol";
import "../../utils/Ownable/Ownable.sol";
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 b027ac960..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,7 +23,7 @@ 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";
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 de76f10c5..627746a52 100644
--- a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
+++ b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol
@@ -16,13 +16,13 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
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 f20e2a944..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol";
@@ -27,7 +27,7 @@ contract ExchangeWrapper {
// Exchange contract.
// solhint-disable-next-line var-name-mixedcase
- IExchange EXCHANGE;
+ IExchange internal EXCHANGE;
constructor (address _exchange)
public
@@ -35,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.
@@ -68,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 bccb74ce8..767cc8d25 100644
--- a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
+++ b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol";
import "../../utils/SafeMath/SafeMath.sol";
@@ -27,7 +26,10 @@ import "../../utils/SafeMath/SafeMath.sol";
* Mintable
* Base contract that creates a mintable UnlimitedAllowanceToken
*/
-contract Mintable is UnlimitedAllowanceToken, SafeMath {
+contract Mintable is
+ UnlimitedAllowanceToken,
+ SafeMath
+{
function mint(uint256 _value)
public
{
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 be7fea7d3..07986f4bb 100644
--- a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol
+++ b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol";
@@ -27,7 +26,8 @@ contract TestAssetProxyDispatcher is MixinAssetProxyDispatcher {
bytes memory assetData,
address from,
address to,
- uint256 amount)
+ uint256 amount
+ )
public
{
dispatchTransferFrom(assetData, from, to, amount);
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 ddcc62f35..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,14 +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,
@@ -32,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 f52f635e1..00d861e61 100644
--- a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol
+++ b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol";
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 df8eb55ce..5a349527b 100644
--- a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol
+++ b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol
@@ -16,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/libs/LibMath.sol";
@@ -32,7 +32,8 @@ contract TestLibs is
function publicGetPartialAmount(
uint256 numerator,
uint256 denominator,
- uint256 target)
+ uint256 target
+ )
public
pure
returns (uint256 partialAmount)
@@ -48,7 +49,8 @@ contract TestLibs is
function publicIsRoundingError(
uint256 numerator,
uint256 denominator,
- uint256 target)
+ uint256 target
+ )
public
pure
returns (bool isError)
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 591ae3378..e1a610469 100644
--- a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol
+++ b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/MixinSignatureValidator.sol";
import "../../protocol/Exchange/MixinTransactions.sol";
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 5076dedc9..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IValidator.sol";
@@ -27,7 +27,7 @@ contract TestValidator is
// The single valid signer for this wallet.
// solhint-disable-next-line var-name-mixedcase
- address VALID_SIGNER;
+ address internal VALID_SIGNER;
/// @dev constructs a new `TestValidator` with a single valid signer.
/// @param validSigner The sole, valid signer.
@@ -40,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,
@@ -51,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 07dfac588..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IWallet.sol";
import "../../utils/LibBytes/LibBytes.sol";
@@ -27,11 +27,9 @@ contract TestWallet is
{
using LibBytes for bytes;
- string constant LENGTH_65_REQUIRED = "LENGTH_65_REQUIRED";
-
// The owner of this wallet.
// solhint-disable-next-line var-name-mixedcase
- address WALLET_OWNER;
+ address internal WALLET_OWNER;
/// @dev constructs a new `TestWallet` with a single owner.
/// @param walletOwner The owner of this wallet.
@@ -54,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 07bd7d531..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,7 +16,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol";
@@ -27,28 +27,22 @@ 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.
- // solhint-disable-next-line var-name-mixedcase
- 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";
- // solhint-disable-next-line var-name-mixedcase
- bytes TX_ORIGIN_SIGNATURE;
+ byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x06";
constructor (address _exchange)
public
{
- // solhint-disable-next-line var-name-mixedcase
EXCHANGE = IExchange(_exchange);
- // solhint-disable-next-line var-name-mixedcase
TX_ORIGIN_SIGNATURE = abi.encodePacked(address(this), VALIDATOR_SIGNATURE_BYTE);
}
@@ -65,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
@@ -85,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.
@@ -117,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 59dc7d7bf..d9950145d 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol
@@ -16,20 +16,15 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
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.";
-
- 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;
@@ -39,11 +34,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;
@@ -57,15 +52,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;
@@ -84,7 +79,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 de4ed2af9..5ee5e1011 100644
--- a/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol
+++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol
@@ -16,8 +16,7 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
contract IERC20Token {
@@ -60,6 +59,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 defb506a8..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,7 +23,7 @@ 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";
@@ -41,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;
@@ -73,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 f72c75638..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,7 @@ 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;
/**
@@ -38,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 0d64ee861..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,7 @@ 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;
/**
@@ -40,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,
@@ -55,6 +57,7 @@ contract IERC721Token {
public
view
returns (string);
+
function symbol()
public
view
@@ -64,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
@@ -75,6 +80,7 @@ contract IERC721Token {
function approve(address _to, uint256 _tokenId)
public;
+
function getApproved(uint256 _tokenId)
public
view
@@ -82,6 +88,7 @@ contract IERC721Token {
function setApprovalForAll(address _operator, bool _approved)
public;
+
function isApprovedForAll(address _owner, address _operator)
public
view
@@ -90,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/EtherToken/IEtherToken.sol b/packages/contracts/src/2.0.0/tokens/EtherToken/IEtherToken.sol
new file mode 100644
index 000000000..9e2e68766
--- /dev/null
+++ b/packages/contracts/src/2.0.0/tokens/EtherToken/IEtherToken.sol
@@ -0,0 +1,33 @@
+/*
+
+ 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 "../ERC20Token/IERC20Token.sol";
+
+
+contract IEtherToken is
+ IERC20Token
+{
+ function deposit()
+ public
+ payable;
+
+ function withdraw(uint256 amount)
+ public;
+}
diff --git a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol b/packages/contracts/src/2.0.0/tokens/EtherToken/WETH9.sol
index 378a507b9..1fdb04de5 100644
--- a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol
+++ b/packages/contracts/src/2.0.0/tokens/EtherToken/WETH9.sol
@@ -13,6 +13,7 @@
// 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;
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 845324e4e..9feb5c914 100644
--- a/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
+++ b/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
@@ -16,15 +16,14 @@
*/
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
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.
@@ -38,15 +37,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/ZRXToken/ZRXToken.sol b/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol
index ed0670072..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,20 +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 c2fff5efb..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,7 @@
*/
-pragma solidity ^0.4.24;
+pragma solidity 0.4.24;
library LibBytes {
@@ -115,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)
@@ -145,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)
@@ -157,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)
@@ -192,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)
@@ -344,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)
@@ -509,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..116b8dc89 100644
--- a/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol
+++ b/packages/contracts/src/2.0.0/utils/Ownable/IOwnable.sol
@@ -1,5 +1,4 @@
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
/*
* Ownable
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 489793a95..aca65aad2 100644
--- a/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol
+++ b/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol
@@ -1,5 +1,4 @@
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
/*
* Ownable
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 ec0a3fe76..4413244db 100644
--- a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol
+++ b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol
@@ -1,28 +1,27 @@
-pragma solidity ^0.4.24;
-pragma experimental ABIEncoderV2;
+pragma solidity 0.4.24;
contract SafeMath {
- function safeMul(uint a, uint b)
+ function safeMul(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
- uint c = a * b;
+ uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
- function safeDiv(uint a, uint b)
+ function safeDiv(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
- uint c = a / b;
+ uint256 c = a / b;
return c;
}
- function safeSub(uint a, uint b)
+ function safeSub(uint256 a, uint256 b)
internal
pure
returns (uint256)
@@ -31,12 +30,12 @@ contract SafeMath {
return a - b;
}
- function safeAdd(uint a, uint b)
+ function safeAdd(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
- uint c = a + b;
+ uint256 c = a + b;
assert(c >= a);
return c;
}