Apply new linter rules

This commit is contained in:
Amir Bandeali 2018-07-06 09:51:23 -07:00
parent e796734659
commit d2e422cd5e
74 changed files with 351 additions and 299 deletions

View File

@ -4,7 +4,7 @@
"avoid-low-level-calls": false, "avoid-low-level-calls": false,
"avoid-tx-origin": "warn", "avoid-tx-origin": "warn",
"bracket-align": false, "bracket-align": false,
"code-complexity": "false", "code-complexity": false,
"const-name-snakecase": "error", "const-name-snakecase": "error",
"expression-indent": "error", "expression-indent": "error",
"function-max-lines": false, "function-max-lines": false,

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./MixinWethFees.sol"; import "./MixinWethFees.sol";
@ -25,6 +25,7 @@ import "./MixinMarketBuyTokens.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
import "../utils/Ownable/Ownable.sol"; import "../utils/Ownable/Ownable.sol";
contract Forwarder is contract Forwarder is
Ownable, Ownable,
MixinConstants, MixinConstants,
@ -33,7 +34,7 @@ contract Forwarder is
MixinMarketBuyTokens, MixinMarketBuyTokens,
MixinMarketSellTokens MixinMarketSellTokens
{ {
uint256 MAX_UINT = 2**256 - 1; uint256 constant internal MAX_UINT = 2**256 - 1;
constructor ( constructor (
address _exchange, address _exchange,

View File

@ -16,19 +16,22 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../protocol/Exchange/Exchange.sol"; import "../protocol/Exchange/Exchange.sol";
import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol"; import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
import "../tokens/ERC20Token/IERC20Token.sol"; import "../tokens/ERC20Token/IERC20Token.sol";
contract MixinConstants { contract MixinConstants {
Exchange EXCHANGE; // solhint-disable var-name-mixedcase
EtherToken ETHER_TOKEN; Exchange internal EXCHANGE;
IERC20Token ZRX_TOKEN; EtherToken internal ETHER_TOKEN;
bytes ZRX_ASSET_DATA; IERC20Token internal ZRX_TOKEN;
bytes WETH_ASSET_DATA; bytes internal ZRX_ASSET_DATA;
bytes internal WETH_ASSET_DATA;
// solhint-enable var-name-mixedcase
constructor ( constructor (
address _exchange, address _exchange,

View File

@ -16,13 +16,13 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
contract MixinERC20 { contract MixinERC20 {
string constant ERROR_TRANSFER_FAILED = "TRANSFER_FAILED"; bytes4 constant internal ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));
bytes4 constant ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));
function transferToken( function transferToken(
address token, address token,

View File

@ -16,17 +16,19 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../utils/LibBytes/LibBytes.sol"; import "../utils/LibBytes/LibBytes.sol";
import "../tokens/ERC721Token/IERC721Token.sol"; import "../tokens/ERC721Token/IERC721Token.sol";
contract MixinERC721 { contract MixinERC721 {
using LibBytes for bytes; 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)")); 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) function onERC721Received(address, uint256, bytes memory)
public public

View File

@ -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. /// This contract is intended to serve as a reference, but is not actually used for efficiency reasons.
contract MixinErrorMessages { contract MixinErrorMessages {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../utils/LibBytes/LibBytes.sol"; import "../utils/LibBytes/LibBytes.sol";
@ -25,74 +25,13 @@ import "../protocol/Exchange/libs/LibMath.sol";
import "../protocol/Exchange/libs/LibOrder.sol"; import "../protocol/Exchange/libs/LibOrder.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
contract MixinExpectedResults is contract MixinExpectedResults is
LibMath, LibMath,
LibFillResults, LibFillResults,
MixinConstants MixinConstants
{ {
/// @dev Simulates the 0x Exchange fillOrder validation and calculations, without performing any state changes.
/// @param order An Order struct containing order specifications.
/// @param takerAssetFillAmount A number representing the amount of this order to fill.
/// @return fillResults Amounts filled and fees paid by maker and taker.
function calculateFillResults(
LibOrder.Order memory order,
uint256 takerAssetFillAmount
)
internal
view
returns (FillResults memory fillResults)
{
LibOrder.OrderInfo memory orderInfo = EXCHANGE.getOrderInfo(order);
if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
return fillResults;
}
uint256 remainingTakerAssetAmount = safeSub(order.takerAssetAmount, orderInfo.orderTakerAssetFilledAmount);
uint256 takerAssetFilledAmount = min256(takerAssetFillAmount, remainingTakerAssetAmount);
fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
fillResults.makerAssetFilledAmount = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerAssetAmount
);
fillResults.makerFeePaid = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerFee
);
fillResults.takerFeePaid = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.takerFee
);
return fillResults;
}
/// @dev Calculates a FillResults total for selling takerAssetFillAmount over all orders.
/// Including the fees required to be paid.
/// @param orders An array of Order struct containing order specifications.
/// @param takerAssetFillAmount A number representing the amount of this order to fill.
/// @return totalFillResults Amounts filled and fees paid by maker and taker.
function calculateMarketSellResults(
LibOrder.Order[] memory orders,
uint256 takerAssetFillAmount
)
internal
view
returns (FillResults memory totalFillResults)
{
for (uint256 i = 0; i < orders.length; i++) {
uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount);
addFillResults(totalFillResults, singleFillResult);
if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) {
break;
}
}
return totalFillResults;
}
/// @dev Calculates a total FillResults for buying makerAssetFillAmount over all orders. /// @dev Calculates a total FillResults for buying makerAssetFillAmount over all orders.
/// Including the fees required to be paid. /// Including the fees required to be paid.
/// @param orders An array of Order struct containing order specifications. /// @param orders An array of Order struct containing order specifications.
@ -155,4 +94,66 @@ contract MixinExpectedResults is
} }
return totalFillResults; return totalFillResults;
} }
/// @dev Simulates the 0x Exchange fillOrder validation and calculations, without performing any state changes.
/// @param order An Order struct containing order specifications.
/// @param takerAssetFillAmount A number representing the amount of this order to fill.
/// @return fillResults Amounts filled and fees paid by maker and taker.
function calculateFillResults(
LibOrder.Order memory order,
uint256 takerAssetFillAmount
)
internal
view
returns (FillResults memory fillResults)
{
LibOrder.OrderInfo memory orderInfo = EXCHANGE.getOrderInfo(order);
if (orderInfo.orderStatus != uint8(LibOrder.OrderStatus.FILLABLE)) {
return fillResults;
}
uint256 remainingTakerAssetAmount = safeSub(order.takerAssetAmount, orderInfo.orderTakerAssetFilledAmount);
uint256 takerAssetFilledAmount = min256(takerAssetFillAmount, remainingTakerAssetAmount);
fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
fillResults.makerAssetFilledAmount = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerAssetAmount
);
fillResults.makerFeePaid = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.makerFee
);
fillResults.takerFeePaid = getPartialAmount(
takerAssetFilledAmount,
order.takerAssetAmount,
order.takerFee
);
return fillResults;
}
/// @dev Calculates a FillResults total for selling takerAssetFillAmount over all orders.
/// Including the fees required to be paid.
/// @param orders An array of Order struct containing order specifications.
/// @param takerAssetFillAmount A number representing the amount of this order to fill.
/// @return totalFillResults Amounts filled and fees paid by maker and taker.
function calculateMarketSellResults(
LibOrder.Order[] memory orders,
uint256 takerAssetFillAmount
)
internal
view
returns (FillResults memory totalFillResults)
{
for (uint256 i = 0; i < orders.length; i++) {
uint256 remainingTakerAssetFillAmount = safeSub(takerAssetFillAmount, totalFillResults.takerAssetFilledAmount);
FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount);
addFillResults(totalFillResults, singleFillResult);
if (totalFillResults.takerAssetFilledAmount == takerAssetFillAmount) {
break;
}
}
return totalFillResults;
}
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../utils/LibBytes/LibBytes.sol"; import "../utils/LibBytes/LibBytes.sol";
@ -28,6 +28,7 @@ import "./MixinERC721.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
import "../protocol/Exchange/libs/LibOrder.sol"; import "../protocol/Exchange/libs/LibOrder.sol";
contract MixinMarketBuyTokens is contract MixinMarketBuyTokens is
MixinConstants, MixinConstants,
MixinWethFees, MixinWethFees,
@ -62,8 +63,8 @@ contract MixinMarketBuyTokens is
uint16 feeProportion, uint16 feeProportion,
address feeRecipient address feeRecipient
) )
payable
public public
payable
returns (FillResults memory totalFillResults) returns (FillResults memory totalFillResults)
{ {
uint256 takerEthAmount = msg.value; uint256 takerEthAmount = msg.value;

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../protocol/Exchange/Exchange.sol"; import "../protocol/Exchange/Exchange.sol";
@ -25,11 +25,13 @@ import "../protocol/Exchange/libs/LibOrder.sol";
import "../protocol/Exchange/libs/LibMath.sol"; import "../protocol/Exchange/libs/LibMath.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
contract MixinMarketBuyZrx is contract MixinMarketBuyZrx is
LibMath, LibMath,
LibFillResults, LibFillResults,
MixinConstants MixinConstants
{ {
/// @dev Buys zrxBuyAmount of ZRX fee tokens, taking into account the fees on buying fee tokens. This will guarantee /// @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). /// 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 /// It is possible that a request to buy 200 ZRX fee tokens will require purchasing 202 ZRX tokens

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../protocol/Exchange/libs/LibOrder.sol"; import "../protocol/Exchange/libs/LibOrder.sol";
@ -27,6 +27,7 @@ import "./MixinERC20.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
import "./MixinMarketBuyZrx.sol"; import "./MixinMarketBuyZrx.sol";
contract MixinMarketSellTokens is contract MixinMarketSellTokens is
MixinConstants, MixinConstants,
MixinWethFees, MixinWethFees,
@ -55,8 +56,8 @@ contract MixinMarketSellTokens is
uint16 feeProportion, uint16 feeProportion,
address feeRecipient address feeRecipient
) )
payable
public public
payable
returns (FillResults memory totalFillResults) returns (FillResults memory totalFillResults)
{ {
uint256 takerEthAmount = msg.value; uint256 takerEthAmount = msg.value;

View File

@ -16,13 +16,14 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol"; import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol";
import "../protocol/Exchange/libs/LibMath.sol"; import "../protocol/Exchange/libs/LibMath.sol";
import "./MixinConstants.sol"; import "./MixinConstants.sol";
contract MixinWethFees is contract MixinWethFees is
LibMath, LibMath,
MixinConstants MixinConstants

View File

@ -1,6 +1,6 @@
// solhint-disable
pragma solidity ^0.4.10; pragma solidity ^0.4.10;
// solhint-disable
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution. /// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
/// @author Stefan George - <stefan.george@consensys.net> /// @author Stefan George - <stefan.george@consensys.net>

View File

@ -16,11 +16,11 @@
*/ */
// solhint-disable
pragma solidity ^0.4.10; pragma solidity ^0.4.10;
import "./MultiSigWallet.sol"; import "./MultiSigWallet.sol";
// solhint-disable
/// @title Multisignature wallet with time lock- Allows multiple parties to execute a transaction after a time lock has passed. /// @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> /// @author Amir Bandeali - <amir@0xProject.com>

View File

@ -16,18 +16,20 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol"; import "./MixinAuthorizable.sol";
contract ERC20Proxy is contract ERC20Proxy is
MixinAuthorizable MixinAuthorizable
{ {
// Id of this proxy. // 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 () function ()
external external
{ {

View File

@ -16,18 +16,20 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "./MixinAuthorizable.sol"; import "./MixinAuthorizable.sol";
contract ERC721Proxy is contract ERC721Proxy is
MixinAuthorizable MixinAuthorizable
{ {
// Id of this proxy. // 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 () function ()
external external
{ {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";

View File

@ -16,7 +16,8 @@
*/ */
pragma solidity ^0.4.23; // solhint-disable
pragma solidity 0.4.24;
// @dev Interface of the asset proxy's assetData. // @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. // This argument is ABI encoded as one of the methods of this interface.
interface IAssetData { interface IAssetData {
// solhint-disable-next-line func-name-mixedcase
function ERC20Token(address tokenContract) function ERC20Token(address tokenContract)
external external
pure; pure;
// solhint-disable-next-line func-name-mixedcase
function ERC721Token( function ERC721Token(
address tokenContract, address tokenContract,
uint256 tokenId, uint256 tokenId,

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./IAuthorizable.sol"; import "./IAuthorizable.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../../utils/Ownable/IOwnable.sol"; import "../../../utils/Ownable/IOwnable.sol";
@ -26,13 +26,6 @@ contract IAuthorizable is
IOwnable IOwnable
{ {
/// @dev Gets all authorized addresses.
/// @return Array of authorized addresses.
function getAuthorizedAddresses()
external
view
returns (address[]);
/// @dev Authorizes an address. /// @dev Authorizes an address.
/// @param target Address to authorize. /// @param target Address to authorize.
function addAuthorizedAddress(address target) function addAuthorizedAddress(address target)
@ -51,4 +44,11 @@ contract IAuthorizable is
uint256 index uint256 index
) )
external; external;
/// @dev Gets all authorized addresses.
/// @return Array of authorized addresses.
function getAuthorizedAddresses()
external
view
returns (address[] memory);
} }

View File

@ -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. /// @dev This contract documents the revert reasons used in the AssetProxy contracts.

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../interfaces/IAuthorizable.sol"; import "../interfaces/IAuthorizable.sol";

View File

@ -33,7 +33,7 @@ contract AssetProxyOwner is
// if this contract is allowed to call the AssetProxy's `removeAuthorizedAddressAtIndex` method without a time lock. // if this contract is allowed to call the AssetProxy's `removeAuthorizedAddressAtIndex` method without a time lock.
mapping (address => bool) public isAssetProxyRegistered; 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` /// @dev Function will revert if the transaction does not call `removeAuthorizedAddressAtIndex`
/// on an approved AssetProxy contract. /// on an approved AssetProxy contract.
@ -89,6 +89,7 @@ contract AssetProxyOwner is
{ {
Transaction storage tx = transactions[transactionId]; Transaction storage tx = transactions[transactionId];
tx.executed = true; tx.executed = true;
// solhint-disable-next-line avoid-call-value
if (tx.destination.call.value(tx.value)(tx.data)) if (tx.destination.call.value(tx.value)(tx.data))
Execution(transactionId); Execution(transactionId);
else { else {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol"; import "./libs/LibConstants.sol";
@ -28,6 +28,7 @@ import "./MixinTransactions.sol";
import "./MixinMatchOrders.sol"; import "./MixinMatchOrders.sol";
// solhint-disable no-empty-blocks
contract Exchange is contract Exchange is
MixinExchangeCore, MixinExchangeCore,
MixinMatchOrders, MixinMatchOrders,

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
@ -151,6 +151,7 @@ contract MixinAssetProxyDispatcher is
/////// Setup Data Area /////// /////// Setup Data Area ///////
// This area holds `assetData`. // This area holds `assetData`.
let dataArea := add(cdStart, 132) let dataArea := add(cdStart, 132)
// solhint-disable-next-line no-empty-blocks
for {} lt(dataArea, cdEnd) {} { for {} lt(dataArea, cdEnd) {} {
mstore(dataArea, mload(assetData)) mstore(dataArea, mload(assetData))
dataArea := add(dataArea, 32) dataArea := add(dataArea, 32)

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol"; 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 // Orders with specified senderAddress and with a salt less than their epoch to are considered cancelled
mapping (address => mapping (address => uint256)) public orderEpoch; 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 /// @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). /// 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. /// @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 // Validate order expiration
// solhint-disable-next-line not-rely-on-time
if (block.timestamp >= order.expirationTimeSeconds) { if (block.timestamp >= order.expirationTimeSeconds) {
orderInfo.orderStatus = uint8(OrderStatus.EXPIRED); orderInfo.orderStatus = uint8(OrderStatus.EXPIRED);
return orderInfo; return orderInfo;

View File

@ -11,7 +11,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./libs/LibConstants.sol"; import "./libs/LibConstants.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
import "./mixins/MSignatureValidator.sol"; import "./mixins/MSignatureValidator.sol";

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "./libs/LibExchangeErrors.sol"; import "./libs/LibExchangeErrors.sol";
import "./mixins/MSignatureValidator.sol"; import "./mixins/MSignatureValidator.sol";
@ -37,7 +37,7 @@ contract MixinTransactions is
address public currentContextAddress; address public currentContextAddress;
// Hash for the EIP712 ZeroEx Transaction Schema // 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(", "ZeroExTransaction(",
"uint256 salt,", "uint256 salt,",
"address signerAddress,", "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. /// @dev Executes an exchange method call in the context of signer.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash. /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
/// @param signerAddress Address of transaction signer. /// @param signerAddress Address of transaction signer.
@ -139,6 +104,41 @@ contract MixinTransactions is
currentContextAddress = address(0); 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`). /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
/// If calling a fill function, this address will represent the taker. /// If calling a fill function, this address will represent the taker.
/// If calling a cancel function, this address will represent the maker. /// If calling a cancel function, this address will represent the maker.

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./libs/LibMath.sol"; import "./libs/LibMath.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract IAssetProxyDispatcher { contract IAssetProxyDispatcher {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./IExchangeCore.sol"; import "./IExchangeCore.sol";
@ -27,6 +27,7 @@ import "./IAssetProxyDispatcher.sol";
import "./IWrapperFunctions.sol"; import "./IWrapperFunctions.sol";
// solhint-disable no-empty-blocks
contract IExchange is contract IExchange is
IExchangeCore, IExchangeCore,
IMatchOrders, IMatchOrders,

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol"; import "../libs/LibOrder.sol";

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol"; import "../libs/LibOrder.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract ISignatureValidator { contract ISignatureValidator {

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract ITransactions { contract ITransactions {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.23; pragma solidity 0.4.24;
contract IValidator { contract IValidator {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract IWallet { contract IWallet {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol"; import "../libs/LibOrder.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract LibConstants { contract LibConstants {

View File

@ -16,18 +16,18 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
contract LibEIP712 { contract LibEIP712 {
// EIP191 header for EIP712 prefix // EIP191 header for EIP712 prefix
string constant EIP191_HEADER = "\x19\x01"; string constant internal EIP191_HEADER = "\x19\x01";
// EIP712 Domain Name value // EIP712 Domain Name value
string constant EIP712_DOMAIN_NAME = "0x Protocol"; string constant internal EIP712_DOMAIN_NAME = "0x Protocol";
// EIP712 Domain Version value // EIP712 Domain Version value
string constant EIP712_DOMAIN_VERSION = "2"; string constant internal EIP712_DOMAIN_VERSION = "2";
// Hash of the EIP712 Domain Separator Schema // Hash of the EIP712 Domain Separator Schema
bytes32 public constant EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked( bytes32 public constant EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = keccak256(abi.encodePacked(

View File

@ -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. /// @dev This contract documents the revert reasons used in the Exchange contract.

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol"; import "../../../utils/SafeMath/SafeMath.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../../utils/SafeMath/SafeMath.sol"; import "../../../utils/SafeMath/SafeMath.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "./LibEIP712.sol"; import "./LibEIP712.sol";
@ -26,7 +26,7 @@ contract LibOrder is
{ {
// Hash for the EIP712 Order Schema // 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(", "Order(",
"address makerAddress,", "address makerAddress,",
"address takerAddress,", "address takerAddress,",
@ -55,6 +55,7 @@ contract LibOrder is
CANCELLED // Order has been cancelled CANCELLED // Order has been cancelled
} }
// solhint-disable max-line-length
struct Order { struct Order {
address makerAddress; // Address that created the 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. 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 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. 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 { struct OrderInfo {
uint8 orderStatus; // Status that describes order's validity and fillability. uint8 orderStatus; // Status that describes order's validity and fillability.

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../interfaces/IAssetProxyDispatcher.sol"; import "../interfaces/IAssetProxyDispatcher.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol"; import "../libs/LibOrder.sol";
@ -102,7 +102,6 @@ contract MExchangeCore is
internal internal
view; view;
/// @dev Validates context for cancelOrder. Succeeds or throws. /// @dev Validates context for cancelOrder. Succeeds or throws.
/// @param order to be cancelled. /// @param order to be cancelled.
/// @param orderInfo OrderStatus, orderHash, and amount already filled of order. /// @param orderInfo OrderStatus, orderHash, and amount already filled of order.

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../libs/LibOrder.sol"; import "../libs/LibOrder.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../interfaces/ISignatureValidator.sol"; import "../interfaces/ISignatureValidator.sol";

View File

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../interfaces/ITransactions.sol"; import "../interfaces/ITransactions.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../Mintable/Mintable.sol"; import "../Mintable/Mintable.sol";

View File

@ -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. 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"; import "../../tokens/ERC721Token/IERC721Receiver.sol";

View File

@ -16,13 +16,14 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../tokens/ERC721Token/ERC721Token.sol"; import "../../tokens/ERC721Token/ERC721Token.sol";
import "../../utils/Ownable/Ownable.sol"; import "../../utils/Ownable/Ownable.sol";
// solhint-disable no-empty-blocks
contract DummyERC721Token is contract DummyERC721Token is
Ownable, Ownable,
ERC721Token ERC721Token

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/interfaces/IExchange.sol";
@ -27,7 +27,7 @@ contract ExchangeWrapper {
// Exchange contract. // Exchange contract.
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
IExchange EXCHANGE; IExchange internal EXCHANGE;
constructor (address _exchange) constructor (address _exchange)
public public
@ -35,6 +35,35 @@ contract ExchangeWrapper {
EXCHANGE = IExchange(_exchange); 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. /// @dev Fills an order using `msg.sender` as the taker.
/// @param order Order struct containing order specifications. /// @param order Order struct containing order specifications.
/// @param takerAssetFillAmount Desired amount of takerAsset to sell. /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
@ -68,33 +97,4 @@ contract ExchangeWrapper {
takerSignature 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
);
}
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol"; import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol"; import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol";

View File

@ -16,14 +16,16 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol"; import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol";
// solhint-disable no-empty-blocks
contract TestAssetProxyOwner is contract TestAssetProxyOwner is
AssetProxyOwner AssetProxyOwner
{ {
constructor( constructor(
address[] memory _owners, address[] memory _owners,
address[] memory _assetProxyContracts, address[] memory _assetProxyContracts,
@ -32,11 +34,11 @@ contract TestAssetProxyOwner is
) )
public public
AssetProxyOwner(_owners, _assetProxyContracts, _required, _secondsTimeLocked) AssetProxyOwner(_owners, _assetProxyContracts, _required, _secondsTimeLocked)
{ {}
}
function testValidRemoveAuthorizedAddressAtIndexTx(uint256 id) function testValidRemoveAuthorizedAddressAtIndexTx(uint256 id)
public public
view
validRemoveAuthorizedAddressAtIndexTx(id) validRemoveAuthorizedAddressAtIndexTx(id)
returns (bool) returns (bool)
{ {

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibMath.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/MixinSignatureValidator.sol"; import "../../protocol/Exchange/MixinSignatureValidator.sol";

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IValidator.sol"; import "../../protocol/Exchange/interfaces/IValidator.sol";
@ -27,7 +27,7 @@ contract TestValidator is
// The single valid signer for this wallet. // The single valid signer for this wallet.
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
address VALID_SIGNER; address internal VALID_SIGNER;
/// @dev constructs a new `TestValidator` with a single valid signer. /// @dev constructs a new `TestValidator` with a single valid signer.
/// @param validSigner The sole, 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 signerAddress Address that should have signed the given hash.
/// @param signature Proof of signing. /// @param signature Proof of signing.
/// @return Validity of signature. /// @return Validity of signature.
// solhint-disable no-unused-vars
function isValidSignature( function isValidSignature(
bytes32 hash, bytes32 hash,
address signerAddress, address signerAddress,
@ -51,4 +52,5 @@ contract TestValidator is
{ {
return (signerAddress == VALID_SIGNER); return (signerAddress == VALID_SIGNER);
} }
// solhint-enable no-unused-vars
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "../../protocol/Exchange/interfaces/IWallet.sol"; import "../../protocol/Exchange/interfaces/IWallet.sol";
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
@ -27,11 +27,9 @@ contract TestWallet is
{ {
using LibBytes for bytes; using LibBytes for bytes;
string constant LENGTH_65_REQUIRED = "LENGTH_65_REQUIRED";
// The owner of this wallet. // The owner of this wallet.
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
address WALLET_OWNER; address internal WALLET_OWNER;
/// @dev constructs a new `TestWallet` with a single owner. /// @dev constructs a new `TestWallet` with a single owner.
/// @param walletOwner The owner of this wallet. /// @param walletOwner The owner of this wallet.
@ -54,7 +52,7 @@ contract TestWallet is
{ {
require( require(
eip712Signature.length == 65, eip712Signature.length == 65,
LENGTH_65_REQUIRED "LENGTH_65_REQUIRED"
); );
uint8 v = uint8(eip712Signature[0]); uint8 v = uint8(eip712Signature[0]);

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/interfaces/IExchange.sol";
@ -27,28 +27,22 @@ import "../../utils/Ownable/Ownable.sol";
contract Whitelist is contract Whitelist is
Ownable 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 of address => whitelist status.
mapping (address => bool) public isWhitelisted; mapping (address => bool) public isWhitelisted;
// Exchange contract. // Exchange contract.
// solhint-disable-next-line var-name-mixedcase // solhint-disable var-name-mixedcase
IExchange EXCHANGE; IExchange internal EXCHANGE;
bytes internal TX_ORIGIN_SIGNATURE;
// solhint-enable var-name-mixedcase
byte constant VALIDATOR_SIGNATURE_BYTE = "\x06"; byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x06";
// solhint-disable-next-line var-name-mixedcase
bytes TX_ORIGIN_SIGNATURE;
constructor (address _exchange) constructor (address _exchange)
public public
{ {
// solhint-disable-next-line var-name-mixedcase
EXCHANGE = IExchange(_exchange); EXCHANGE = IExchange(_exchange);
// solhint-disable-next-line var-name-mixedcase
TX_ORIGIN_SIGNATURE = abi.encodePacked(address(this), VALIDATOR_SIGNATURE_BYTE); TX_ORIGIN_SIGNATURE = abi.encodePacked(address(this), VALIDATOR_SIGNATURE_BYTE);
} }
@ -65,6 +59,27 @@ contract Whitelist is
isWhitelisted[target] = isApproved; 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. /// @dev Fills an order using `msg.sender` as the taker.
/// The transaction will revert if both the maker and taker are not whitelisted. /// 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 /// 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. // This contract must be the entry point for the transaction.
require( require(
// solhint-disable-next-line avoid-tx-origin
takerAddress == tx.origin, takerAddress == tx.origin,
INVALID_SENDER "INVALID_SENDER"
); );
// Check if maker is on the whitelist. // Check if maker is on the whitelist.
require( require(
isWhitelisted[order.makerAddress], isWhitelisted[order.makerAddress],
MAKER_NOT_WHITELISTED "MAKER_NOT_WHITELISTED"
); );
// Check if taker is on the whitelist. // Check if taker is on the whitelist.
require( require(
isWhitelisted[takerAddress], isWhitelisted[takerAddress],
TAKER_NOT_WHITELISTED "TAKER_NOT_WHITELISTED"
); );
// Encode arguments into byte array. // Encode arguments into byte array.
@ -117,22 +133,4 @@ contract Whitelist is
TX_ORIGIN_SIGNATURE 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;
}
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./IERC20Token.sol"; import "./IERC20Token.sol";
@ -24,12 +24,8 @@ import "./IERC20Token.sol";
contract ERC20Token is IERC20Token { contract ERC20Token is IERC20Token {
string constant INSUFFICIENT_BALANCE = "ERC20_INSUFFICIENT_BALANCE"; mapping (address => uint256) internal balances;
string constant INSUFFICIENT_ALLOWANCE = "ERC20_INSUFFICIENT_ALLOWANCE"; mapping (address => mapping (address => uint256)) internal allowed;
string constant OVERFLOW = "Transfer would result in an overflow.";
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply; uint256 public totalSupply;
@ -39,11 +35,11 @@ contract ERC20Token is IERC20Token {
{ {
require( require(
balances[msg.sender] >= _value, balances[msg.sender] >= _value,
INSUFFICIENT_BALANCE "ERC20_INSUFFICIENT_BALANCE"
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
OVERFLOW "OVERFLOW"
); );
balances[msg.sender] -= _value; balances[msg.sender] -= _value;
balances[_to] += _value; balances[_to] += _value;
@ -57,15 +53,15 @@ contract ERC20Token is IERC20Token {
{ {
require( require(
balances[_from] >= _value, balances[_from] >= _value,
INSUFFICIENT_BALANCE "ERC20_INSUFFICIENT_BALANCE"
); );
require( require(
allowed[_from][msg.sender] >= _value, allowed[_from][msg.sender] >= _value,
INSUFFICIENT_ALLOWANCE "ERC20_INSUFFICIENT_ALLOWANCE"
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
OVERFLOW "OVERFLOW"
); );
balances[_to] += _value; balances[_to] += _value;
balances[_from] -= _value; balances[_from] -= _value;
@ -84,7 +80,8 @@ contract ERC20Token is IERC20Token {
} }
function balanceOf(address _owner) function balanceOf(address _owner)
public view public
view
returns (uint256) returns (uint256)
{ {
return balances[_owner]; return balances[_owner];

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
@ -60,6 +60,7 @@ contract IERC20Token {
public view public view
returns (uint256); returns (uint256);
// solhint-disable-next-line no-simple-event-func-name
event Transfer( event Transfer(
address indexed _from, address indexed _from,
address indexed _to, address indexed _to,

View File

@ -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. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
import "./IERC721Token.sol"; import "./IERC721Token.sol";
import "./IERC721Receiver.sol"; import "./IERC721Receiver.sol";
@ -41,7 +41,7 @@ contract ERC721Token is
{ {
// Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` // Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`
// which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` // 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 from token ID to owner
mapping (uint256 => address) internal tokenOwner; mapping (uint256 => address) internal tokenOwner;
@ -73,7 +73,7 @@ contract ERC721Token is
_; _;
} }
function ERC721Token( constructor (
string _name, string _name,
string _symbol) string _symbol)
public public

View File

@ -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. 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)"))`, * Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`,
* which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` * 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 * @notice Handle the receipt of an NFT

View File

@ -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. 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, address indexed _to,
uint256 _tokenId uint256 _tokenId
); );
event Approval( event Approval(
address indexed _owner, address indexed _owner,
address indexed _approved, address indexed _approved,
uint256 _tokenId uint256 _tokenId
); );
event ApprovalForAll( event ApprovalForAll(
address indexed _owner, address indexed _owner,
address indexed _operator, address indexed _operator,
@ -55,6 +57,7 @@ contract IERC721Token {
public public
view view
returns (string); returns (string);
function symbol() function symbol()
public public
view view
@ -64,10 +67,12 @@ contract IERC721Token {
public public
view view
returns (uint256 _balance); returns (uint256 _balance);
function ownerOf(uint256 _tokenId) function ownerOf(uint256 _tokenId)
public public
view view
returns (address _owner); returns (address _owner);
function exists(uint256 _tokenId) function exists(uint256 _tokenId)
public public
view view
@ -75,6 +80,7 @@ contract IERC721Token {
function approve(address _to, uint256 _tokenId) function approve(address _to, uint256 _tokenId)
public; public;
function getApproved(uint256 _tokenId) function getApproved(uint256 _tokenId)
public public
view view
@ -82,6 +88,7 @@ contract IERC721Token {
function setApprovalForAll(address _operator, bool _approved) function setApprovalForAll(address _operator, bool _approved)
public; public;
function isApprovedForAll(address _owner, address _operator) function isApprovedForAll(address _owner, address _operator)
public public
view view
@ -90,17 +97,22 @@ contract IERC721Token {
function transferFrom( function transferFrom(
address _from, address _from,
address _to, address _to,
uint256 _tokenId) uint256 _tokenId
)
public; public;
function safeTransferFrom( function safeTransferFrom(
address _from, address _from,
address _to, address _to,
uint256 _tokenId) uint256 _tokenId
)
public; public;
function safeTransferFrom( function safeTransferFrom(
address _from, address _from,
address _to, address _to,
uint256 _tokenId, uint256 _tokenId,
bytes _data) bytes _data
)
public; public;
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "../ERC20Token/ERC20Token.sol"; import "../ERC20Token/ERC20Token.sol";
@ -24,7 +24,7 @@ import "../ERC20Token/ERC20Token.sol";
contract UnlimitedAllowanceToken is ERC20Token { 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 /// @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. /// @param _from Address to transfer from.
@ -38,15 +38,15 @@ contract UnlimitedAllowanceToken is ERC20Token {
uint256 allowance = allowed[_from][msg.sender]; uint256 allowance = allowed[_from][msg.sender];
require( require(
balances[_from] >= _value, balances[_from] >= _value,
INSUFFICIENT_BALANCE "ERC20_INSUFFICIENT_BALANCE"
); );
require( require(
allowance >= _value, allowance >= _value,
INSUFFICIENT_ALLOWANCE "ERC20_INSUFFICIENT_ALLOWANCE"
); );
require( require(
balances[_to] + _value >= balances[_to], balances[_to] + _value >= balances[_to],
OVERFLOW "OVERFLOW"
); );
balances[_to] += _value; balances[_to] += _value;
balances[_from] -= _value; balances[_from] -= _value;

View File

@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// solhint-disable
pragma solidity ^0.4.18; pragma solidity ^0.4.18;

View File

@ -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"; import { UnlimitedAllowanceToken_v1 as UnlimitedAllowanceToken } from "../../../1.0.0/UnlimitedAllowanceToken/UnlimitedAllowanceToken_v1.sol";
contract ZRXToken is UnlimitedAllowanceToken { contract ZRXToken is UnlimitedAllowanceToken {
// solhint-disable const-name-snakecase
uint8 constant public decimals = 18; uint8 constant public decimals = 18;
uint public totalSupply = 10**27; // 1 billion tokens, 18 decimal places uint public totalSupply = 10**27; // 1 billion tokens, 18 decimal places
string constant public name = "0x Protocol Token"; string constant public name = "0x Protocol Token";
string constant public symbol = "ZRX"; string constant public symbol = "ZRX";
// solhint-enableconst-name-snakecase
function ZRXToken() { function ZRXToken()
public
{
balances[msg.sender] = totalSupply; balances[msg.sender] = totalSupply;
} }
} }

View File

@ -16,7 +16,7 @@
*/ */
pragma solidity ^0.4.24; pragma solidity 0.4.24;
library LibBytes { library LibBytes {
@ -115,6 +115,7 @@ library LibBytes {
// Copy whole words front to back // Copy whole words front to back
// Note: the first check is always true, // Note: the first check is always true,
// this could have been a do-while loop. // this could have been a do-while loop.
// solhint-disable-next-line no-empty-blocks
for {} lt(source, sEnd) {} { for {} lt(source, sEnd) {} {
mstore(dest, mload(source)) mstore(dest, mload(source))
source := add(source, 32) source := add(source, 32)
@ -145,6 +146,7 @@ library LibBytes {
// 2**255, so they can be safely re-interpreted as signed. // 2**255, so they can be safely re-interpreted as signed.
// Note: the first check is always true, // Note: the first check is always true,
// this could have been a do-while loop. // this could have been a do-while loop.
// solhint-disable-next-line no-empty-blocks
for {} slt(dest, dEnd) {} { for {} slt(dest, dEnd) {} {
mstore(dEnd, mload(sEnd)) mstore(dEnd, mload(sEnd))
sEnd := sub(sEnd, 32) sEnd := sub(sEnd, 32)
@ -157,13 +159,17 @@ library LibBytes {
} }
} }
} }
/// @dev Returns a slices from a byte array. /// @dev Returns a slices from a byte array.
/// @param b The byte array to take a slice from. /// @param b The byte array to take a slice from.
/// @param from The starting index for the slice (inclusive). /// @param from The starting index for the slice (inclusive).
/// @param to The final index for the slice (exclusive). /// @param to The final index for the slice (exclusive).
/// @return result The slice containing bytes at indices [from, to) /// @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 internal
pure pure
returns (bytes memory result) returns (bytes memory result)
@ -192,7 +198,11 @@ library LibBytes {
/// @param to The final index for the slice (exclusive). /// @param to The final index for the slice (exclusive).
/// @return result The slice containing bytes at indices [from, to) /// @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. /// @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 internal
pure pure
returns (bytes memory result) returns (bytes memory result)
@ -344,7 +354,10 @@ library LibBytes {
// 1. Add index to address of bytes array // 1. Add index to address of bytes array
// 2. Load 32-byte word from memory // 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 // 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. // Make sure input address is clean.
// (Solidity does not guarantee this) // (Solidity does not guarantee this)
@ -509,7 +522,7 @@ library LibBytes {
// Assert length of <b> is valid, given // Assert length of <b> is valid, given
// length of input // length of input
require( 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" "GREATER_OR_EQUAL_TO_NESTED_BYTES_LENGTH_REQUIRED"
); );

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
/* /*

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
/* /*

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.24; pragma solidity 0.4.24;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;