aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-09 04:06:17 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-09 04:10:09 +0800
commit5198c56db94a43148789d3d0561220bd7cf546c0 (patch)
tree6d4c6b8e99fab87190c7de41bdfa8bf6e2213687 /packages/contracts
parent7e7364fc83167677594f246b418fe939b1b02f2a (diff)
downloaddexon-sol-tools-5198c56db94a43148789d3d0561220bd7cf546c0.tar.gz
dexon-sol-tools-5198c56db94a43148789d3d0561220bd7cf546c0.tar.zst
dexon-sol-tools-5198c56db94a43148789d3d0561220bd7cf546c0.zip
Add revert variables, change lib => libs to get around gitignore
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol4
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol18
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol12
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol2
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol2
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol8
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol2
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol6
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ISignatureValidator.sol2
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ITransactions.sol2
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IWrapperFunctions.sol4
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol58
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibFillResults.sol47
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibMath.sol72
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol84
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol4
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol2
-rw-r--r--packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol6
-rw-r--r--packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol24
-rw-r--r--packages/contracts/src/contracts/current/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol6
-rw-r--r--packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol12
21 files changed, 325 insertions, 52 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol
index 14d5eb7ca..308dace32 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol
@@ -20,7 +20,7 @@ pragma solidity ^0.4.23;
import "../../utils/Ownable/Ownable.sol";
import "../AssetProxy/interfaces/IAssetProxy.sol";
-import "./lib/LibExchangeErrors.sol";
+import "./libs/LibExchangeErrors.sol";
import "./mixins/MAssetProxyDispatcher.sol";
contract MixinAssetProxyDispatcher is
@@ -94,7 +94,7 @@ contract MixinAssetProxyDispatcher is
// Lookup asset proxy
require(
assetMetadata.length >= 1,
- GREATER_THAN_ZERO_LENGTH_REQUIRED
+ GT_ZERO_LENGTH_REQUIRED
);
uint8 assetProxyId = uint8(assetMetadata[0]);
IAssetProxy assetProxy = assetProxies[assetProxyId];
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
index c22acf966..82c7a2ddc 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol
@@ -19,10 +19,10 @@
pragma solidity ^0.4.23;
pragma experimental ABIEncoderV2;
-import "./lib/LibFillResults.sol";
-import "./lib/LibOrder.sol";
-import "./lib/LibMath.sol";
-import "./lib/LibExchangeErrors.sol";
+import "./libs/LibFillResults.sol";
+import "./libs/LibOrder.sol";
+import "./libs/LibMath.sol";
+import "./libs/LibExchangeErrors.sol";
import "./mixins/MExchangeCore.sol";
import "./mixins/MSettlement.sol";
import "./mixins/MSignatureValidator.sol";
@@ -94,11 +94,11 @@ contract MixinExchangeCore is
if (filled[orderHash] == 0) {
require(
order.makerAssetAmount > 0,
- GREATER_THAN_ZERO_AMOUNT_REQUIRED
+ GT_ZERO_AMOUNT_REQUIRED
);
require(
order.takerAssetAmount > 0,
- GREATER_THAN_ZERO_AMOUNT_REQUIRED
+ GT_ZERO_AMOUNT_REQUIRED
);
require(
isValidSignature(orderHash, order.makerAddress, signature),
@@ -124,7 +124,7 @@ contract MixinExchangeCore is
}
require(
takerAssetFillAmount > 0,
- GREATER_THAN_ZERO_AMOUNT_REQUIRED
+ GT_ZERO_AMOUNT_REQUIRED
);
// Validate order expiration
@@ -174,11 +174,11 @@ contract MixinExchangeCore is
// Validate the order
require(
order.makerAssetAmount > 0,
- GREATER_THAN_ZERO_AMOUNT_REQUIRED
+ GT_ZERO_AMOUNT_REQUIRED
);
require(
order.takerAssetAmount > 0,
- GREATER_THAN_ZERO_AMOUNT_REQUIRED
+ GT_ZERO_AMOUNT_REQUIRED
);
// Validate sender is allowed to cancel this order
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol
index ae1dd9bee..30f1bb49b 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol
@@ -20,15 +20,17 @@ pragma solidity ^0.4.23;
import "./mixins/MSettlement.sol";
import "./mixins/MAssetProxyDispatcher.sol";
-import "./lib/LibOrder.sol";
-import "./lib/LibMath.sol";
+import "./libs/LibOrder.sol";
+import "./libs/LibMath.sol";
contract MixinSettlement is
LibMath,
MSettlement,
MAssetProxyDispatcher
{
- /// ZRX metadata used for fee transfers.
+ // ZRX metadata used for fee transfers.
+ // This will be constant throughout the life of the Exchange contract,
+ // since ZRX will always be transferred via the ERC20 AssetProxy.
bytes internal ZRX_PROXY_DATA;
/// @dev Gets the ZRX metadata used for fee transfers.
@@ -49,10 +51,10 @@ contract MixinSettlement is
ZRX_PROXY_DATA = _zrxProxyData;
}
- /// @dev Settles an order by transfering assets between counterparties.
+ /// @dev Settles an order by transferring assets between counterparties.
/// @param order Order struct containing order specifications.
/// @param takerAddress Address selling takerAsset and buying makerAsset.
- /// @param takerAssetFilledAmount The amount of takerAsset that will be transfered to the order's maker.
+ /// @param takerAssetFilledAmount The amount of takerAsset that will be transferred to the order's maker.
/// @return Amount filled by maker and fees paid by maker/taker.
function settleOrder(
LibOrder.Order memory order,
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index 43d138669..2322625d9 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -20,7 +20,7 @@ pragma solidity ^0.4.23;
import "./mixins/MSignatureValidator.sol";
import "./interfaces/ISigner.sol";
-import "./lib/LibExchangeErrors.sol";
+import "./libs/LibExchangeErrors.sol";
import "../../utils/LibBytes/LibBytes.sol";
contract MixinSignatureValidator is
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
index a8b60e8a4..7f12834a3 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
@@ -19,7 +19,7 @@ pragma solidity ^0.4.21;
import "./mixins/MSignatureValidator.sol";
import "./mixins/MTransactions.sol";
-import "./lib/LibExchangeErrors.sol";
+import "./libs/LibExchangeErrors.sol";
contract MixinTransactions is
LibExchangeErrors,
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol
index 33a125083..42517221e 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol
@@ -21,10 +21,10 @@ pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
import "./mixins/MExchangeCore.sol";
-import "./lib/LibMath.sol";
-import "./lib/LibOrder.sol";
-import "./lib/LibFillResults.sol";
-import "./lib/LibExchangeErrors.sol";
+import "./libs/LibMath.sol";
+import "./libs/LibOrder.sol";
+import "./libs/LibFillResults.sol";
+import "./libs/LibExchangeErrors.sol";
contract MixinWrapperFunctions is
LibOrder,
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
index d60b8ca48..4e4ed6be8 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol
@@ -38,4 +38,4 @@ contract IAssetProxyDispatcher {
external
view
returns (address);
-} \ No newline at end of file
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
index 18f794ee8..0f19525ca 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IExchangeCore.sol
@@ -19,8 +19,8 @@
pragma solidity ^0.4.23;
pragma experimental ABIEncoderV2;
-import "../lib/LibOrder.sol";
-import "../lib/LibFillResults.sol";
+import "../libs/LibOrder.sol";
+import "../libs/LibFillResults.sol";
contract IExchangeCore {
@@ -48,4 +48,4 @@ contract IExchangeCore {
function cancelOrder(LibOrder.Order memory order)
public
returns (bool);
-} \ No newline at end of file
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ISignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ISignatureValidator.sol
index 806d7c56f..b4a238472 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ISignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ISignatureValidator.sol
@@ -29,4 +29,4 @@ contract ISignatureValidator {
address signer,
bytes signature)
external;
-} \ No newline at end of file
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ITransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ITransactions.sol
index 078b07816..76e4cf2fe 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ITransactions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/ITransactions.sol
@@ -30,4 +30,4 @@ contract ITransactions {
bytes data,
bytes signature)
external;
-} \ No newline at end of file
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IWrapperFunctions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IWrapperFunctions.sol
index 0ebae309d..d23170b1c 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IWrapperFunctions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IWrapperFunctions.sol
@@ -19,8 +19,8 @@
pragma solidity ^0.4.23;
pragma experimental ABIEncoderV2;
-import "./lib/LibOrder.sol";
-import "./lib/LibFillResults.sol";
+import "./libs/LibOrder.sol";
+import "./libs/LibFillResults.sol";
contract IWrapperFunctions is
LibOrder,
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol
new file mode 100644
index 000000000..6ffbdfdca
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibExchangeErrors.sol
@@ -0,0 +1,58 @@
+/*
+
+ 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.23;
+
+contract LibExchangeErrors {
+
+ // Error Codes
+ enum Errors {
+ ORDER_EXPIRED, // Order has already expired
+ ORDER_FULLY_FILLED, // Order has already been fully filled
+ ORDER_CANCELLED, // Order has already been cancelled
+ ROUNDING_ERROR_TOO_LARGE, // Rounding error too large
+ INSUFFICIENT_BALANCE_OR_ALLOWANCE // Insufficient balance or allowance for token transfer
+ }
+
+ event ExchangeError(uint8 indexed errorId, bytes32 indexed orderHash);
+
+ // Core revert reasons
+ string constant GT_ZERO_AMOUNT_REQUIRED = "Amount must be greater than 0.";
+ string constant SIGNATURE_VALIDATION_FAILED = "Signature validation failed.";
+ string constant INVALID_SENDER = "Invalid `msg.sender`.";
+ string constant INVALID_CONTEXT = "Function called in an invalid context.";
+ string constant INVALID_NEW_MAKER_EPOCH = "Specified salt must be greater than or equal to existing makerEpoch.";
+
+ // Transaction revert reasons
+ string constant DUPLICATE_TRANSACTION_HASH = "Transaction has already been executed.";
+ string constant TRANSACTION_EXECUTION_FAILED = "Transaction execution failed.";
+
+ // Wrapper revert reasons
+ string constant COMPLETE_FILL_FAILED = "Desired fill amount could not be completely filled.";
+ string constant ASSET_DATA_MISMATCH = "Asset data must be the same for each order.";
+
+ // Asset proxy dispatcher revert reasons
+ string constant GT_ZERO_LENGTH_REQUIRED = "Length must be greater than 0.";
+ string constant OLD_ASSET_PROXY_MISMATCH = "Old asset proxy does not match asset proxy at given id.";
+ string constant NEW_ASSET_PROXY_MISMATCH = "New asset proxy id does not match given id.";
+
+ // Signature validator revert reasons
+ string constant INVALID_SIGNATURE_LENGTH = "Invalid signature length.";
+ string constant ILLEGAL_SIGNATURE_TYPE = "Illegal signature type.";
+ string constant UNSUPPORTED_SIGNATURE_TYPE = "Unsupported signature type.";
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibFillResults.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibFillResults.sol
new file mode 100644
index 000000000..3b8f2acf9
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibFillResults.sol
@@ -0,0 +1,47 @@
+/*
+
+ 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.23;
+
+import "../../../utils/SafeMath/SafeMath.sol";
+
+contract LibFillResults is
+ SafeMath
+{
+
+ struct FillResults {
+ uint256 makerAssetFilledAmount;
+ uint256 takerAssetFilledAmount;
+ uint256 makerFeePaid;
+ uint256 takerFeePaid;
+ }
+
+ /// @dev Adds properties of both FillResults instances.
+ /// Modifies the first FillResults instance specified.
+ /// @param totalFillResults Fill results instance that will be added onto.
+ /// @param singleFillResults Fill results instance that will be added to totalFillResults.
+ function addFillResults(FillResults memory totalFillResults, FillResults memory singleFillResults)
+ internal
+ pure
+ {
+ totalFillResults.makerAssetFilledAmount = safeAdd(totalFillResults.makerAssetFilledAmount, singleFillResults.makerAssetFilledAmount);
+ totalFillResults.takerAssetFilledAmount = safeAdd(totalFillResults.takerAssetFilledAmount, singleFillResults.takerAssetFilledAmount);
+ totalFillResults.makerFeePaid = safeAdd(totalFillResults.makerFeePaid, singleFillResults.makerFeePaid);
+ totalFillResults.takerFeePaid = safeAdd(totalFillResults.takerFeePaid, singleFillResults.takerFeePaid);
+ }
+} \ No newline at end of file
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibMath.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibMath.sol
new file mode 100644
index 000000000..b48602d19
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibMath.sol
@@ -0,0 +1,72 @@
+/*
+
+ 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.23;
+
+import "../../../utils/SafeMath/SafeMath.sol";
+
+contract LibMath is
+ SafeMath
+{
+
+ /// @dev Calculates partial value given a numerator and denominator.
+ /// @param numerator Numerator.
+ /// @param denominator Denominator.
+ /// @param target Value to calculate partial of.
+ /// @return Partial value of target.
+ function getPartialAmount(
+ uint256 numerator,
+ uint256 denominator,
+ uint256 target)
+ internal
+ pure
+ returns (uint256 partialAmount)
+ {
+ partialAmount = safeDiv(
+ safeMul(numerator, target),
+ denominator
+ );
+ return partialAmount;
+ }
+
+ /// @dev Checks if rounding error > 0.1%.
+ /// @param numerator Numerator.
+ /// @param denominator Denominator.
+ /// @param target Value to multiply with numerator/denominator.
+ /// @return Rounding error is present.
+ function isRoundingError(
+ uint256 numerator,
+ uint256 denominator,
+ uint256 target)
+ internal
+ pure
+ returns (bool isError)
+ {
+ uint256 remainder = mulmod(target, numerator, denominator);
+ if (remainder == 0) {
+ return false; // No rounding error.
+ }
+
+ uint256 errPercentageTimes1000000 = safeDiv(
+ safeMul(remainder, 1000000),
+ safeMul(numerator, target)
+ );
+ isError = errPercentageTimes1000000 > 1000;
+ return isError;
+ }
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol
new file mode 100644
index 000000000..0fe8c8c96
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/libs/LibOrder.sol
@@ -0,0 +1,84 @@
+/*
+
+ 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.23;
+
+contract LibOrder {
+
+ bytes32 constant ORDER_SCHEMA_HASH = keccak256(
+ "address exchangeAddress",
+ "address makerAddress",
+ "address takerAddress",
+ "address feeRecipientAddress",
+ "address senderAddress",
+ "uint256 makerAssetAmount",
+ "uint256 takerAssetAmount",
+ "uint256 makerFee",
+ "uint256 takerFee",
+ "uint256 expirationTimeSeconds",
+ "uint256 salt",
+ "bytes makerAssetData",
+ "bytes takerAssetData"
+ );
+
+ struct Order {
+ address makerAddress;
+ address takerAddress;
+ address feeRecipientAddress;
+ address senderAddress;
+ uint256 makerAssetAmount;
+ uint256 takerAssetAmount;
+ uint256 makerFee;
+ uint256 takerFee;
+ uint256 expirationTimeSeconds;
+ uint256 salt;
+ bytes makerAssetData;
+ bytes takerAssetData;
+ }
+
+ /// @dev Calculates Keccak-256 hash of the order.
+ /// @param order The order structure.
+ /// @return Keccak-256 EIP712 hash of the order.
+ function getOrderHash(Order memory order)
+ internal
+ view
+ returns (bytes32 orderHash)
+ {
+ // TODO: EIP712 is not finalized yet
+ // Source: https://github.com/ethereum/EIPs/pull/712
+ orderHash = keccak256(
+ ORDER_SCHEMA_HASH,
+ keccak256(
+ address(this),
+ order.makerAddress,
+ order.takerAddress,
+ order.feeRecipientAddress,
+ order.senderAddress,
+ order.makerAssetAmount,
+ order.takerAssetAmount,
+ order.makerFee,
+ order.takerFee,
+ order.expirationTimeSeconds,
+ order.salt,
+ order.makerAssetData,
+ order.takerAssetData
+ )
+ );
+ return orderHash;
+ }
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol
index b80af9dc1..5b78e70da 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol
@@ -18,8 +18,8 @@
pragma solidity ^0.4.23;
-import "../lib/LibOrder.sol";
-import "../lib/LibFillResults.sol";
+import "../libs/LibOrder.sol";
+import "../libs/LibFillResults.sol";
import "../interfaces/IExchangeCore.sol";
contract MExchangeCore is
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol
index 3075aae15..5e2edbf99 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol
@@ -18,7 +18,7 @@
pragma solidity ^0.4.23;
-import "../lib/LibOrder.sol";
+import "../libs/LibOrder.sol";
contract MSettlement {
diff --git a/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol b/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol
index 3d199681b..0dc7785b2 100644
--- a/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol
+++ b/packages/contracts/src/contracts/current/test/TestLibs/TestLibs.sol
@@ -19,9 +19,9 @@
pragma solidity ^0.4.23;
pragma experimental ABIEncoderV2;
-import "../../protocol/Exchange/lib/LibMath.sol";
-import "../../protocol/Exchange/lib/LibOrder.sol";
-import "../../protocol/Exchange/lib/LibFillResults.sol";
+import "../../protocol/Exchange/libs/LibMath.sol";
+import "../../protocol/Exchange/libs/LibOrder.sol";
+import "../../protocol/Exchange/libs/LibFillResults.sol";
contract TestLibs is
LibMath,
diff --git a/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol b/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol
index 27e7fa355..6497d3c7a 100644
--- a/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol
+++ b/packages/contracts/src/contracts/current/tokens/ERC20Token/ERC20Token.sol
@@ -23,17 +23,26 @@ import "./IERC20Token.sol";
contract ERC20Token is IERC20Token {
+ string constant INSUFFICIENT_BALANCE = "Insufficient balance to complete transfer.";
+ string constant INSUFFICIENT_ALLOWANCE = "Insufficient allowance to complete transfer.";
+ string constant OVERFLOW = "Transfer would result in an overflow.";
+
+ mapping (address => uint256) balances;
+ mapping (address => mapping (address => uint256)) allowed;
+
+ uint256 public totalSupply;
+
function transfer(address _to, uint256 _value)
public
returns (bool)
{
require(
balances[msg.sender] >= _value,
- "Insufficient balance to complete transfer."
+ INSUFFICIENT_BALANCE
);
require(
balances[_to] + _value >= balances[_to],
- "Transfer would result in an overflow."
+ OVERFLOW
);
balances[msg.sender] -= _value;
balances[_to] += _value;
@@ -47,15 +56,15 @@ contract ERC20Token is IERC20Token {
{
require(
balances[_from] >= _value,
- "Insufficient balance to complete transfer."
+ INSUFFICIENT_BALANCE
);
require(
allowed[_from][msg.sender] >= _value,
- "Insufficient allowance to complete transfer."
+ INSUFFICIENT_ALLOWANCE
);
require(
balances[_to] + _value >= balances[_to],
- "Transfer would result in an overflow."
+ OVERFLOW
);
balances[_to] += _value;
balances[_from] -= _value;
@@ -87,8 +96,5 @@ contract ERC20Token is IERC20Token {
{
return allowed[_owner][_spender];
}
-
- mapping (address => uint256) balances;
- mapping (address => mapping (address => uint256)) allowed;
- uint256 public totalSupply;
}
+
diff --git a/packages/contracts/src/contracts/current/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol b/packages/contracts/src/contracts/current/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
index 4aedced49..395e5d356 100644
--- a/packages/contracts/src/contracts/current/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
+++ b/packages/contracts/src/contracts/current/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol
@@ -37,15 +37,15 @@ contract UnlimitedAllowanceToken is ERC20Token {
uint256 allowance = allowed[_from][msg.sender];
require(
balances[_from] >= _value,
- "Insufficient balance to complete transfer."
+ INSUFFICIENT_BALANCE
);
require(
allowance >= _value,
- "Insufficient allowance to complete transfer."
+ INSUFFICIENT_ALLOWANCE
);
require(
balances[_to] + _value >= balances[_to],
- "Transfer would result in an overflow."
+ OVERFLOW
);
balances[_to] += _value;
balances[_from] -= _value;
diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
index 3eba0708f..3c5531e35 100644
--- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
@@ -20,6 +20,10 @@ pragma solidity ^0.4.23;
contract LibBytes {
+ // Revert reasons
+ string constant GTE_20_LENGTH_REQUIRED = "Length must be greater than or equal to 20.";
+ string constant GTE_32_LENGTH_REQUIRED = "Length must be greater than or equal to 32.";
+
/// @dev Tests equality of two byte arrays.
/// @param lhs First byte array to compare.
/// @param rhs Second byte array to compare.
@@ -65,7 +69,7 @@ contract LibBytes {
{
require(
b.length >= index + 20, // 20 is length of address
- "Cannot read address from byte array shorter than 20 bytes."
+ GTE_20_LENGTH_REQUIRED
);
// Add offset to index:
@@ -96,7 +100,7 @@ contract LibBytes {
{
require(
b.length >= index + 20, // 20 is length of address
- "Cannot write address to byte array shorter than 20 bytes."
+ GTE_20_LENGTH_REQUIRED
);
// Add offset to index:
@@ -134,7 +138,7 @@ contract LibBytes {
{
require(
b.length >= index + 32,
- "Cannot read 32 bytes from byte array shorter than 32 bytes."
+ GTE_32_LENGTH_REQUIRED
);
// Arrays are prefixed by a 256 bit length parameter
@@ -160,7 +164,7 @@ contract LibBytes {
{
require(
b.length >= index + 32,
- "Cannot write 32 bytes to byte array shorter than 32 bytes."
+ GTE_32_LENGTH_REQUIRED
);
// Arrays are prefixed by a 256 bit length parameter