diff options
Diffstat (limited to 'packages/contracts/src/2.0.0')
70 files changed, 1180 insertions, 2 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/Forwarder.sol b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol new file mode 100644 index 000000000..71a4aff13 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/Forwarder.sol @@ -0,0 +1,81 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +import "./MixinWethFees.sol"; +import "./MixinMarketSellTokens.sol"; +import "./MixinMarketBuyTokens.sol"; +import "./MixinConstants.sol"; +import "../utils/Ownable/Ownable.sol"; + +contract Forwarder is + Ownable, + MixinConstants, + MixinWethFees, + MixinMarketBuyZrx, + MixinMarketBuyTokens, + MixinMarketSellTokens +{ + uint256 MAX_UINT = 2**256 - 1; + + constructor ( + address _exchange, + address _etherToken, + address _zrxToken, + bytes4 _erc20AssetProxyId, + bytes memory _zrxAssetData, + bytes memory _wethAssetData + ) + public + Ownable() + MixinConstants( + _exchange, + _etherToken, + _zrxToken, + _zrxAssetData, + _wethAssetData + ) + { + setERC20ProxyApproval(_erc20AssetProxyId); + } + + /// @dev Default payabale function, this allows us to withdraw WETH + function () + public + payable + { + require( + msg.sender == address(ETHER_TOKEN), + "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY" + ); + } + + /// @dev Sets the allowances to the proxy for this contract + function setERC20ProxyApproval(bytes4 erc20AssetProxyId) + public + onlyOwner + { + address proxyAddress = EXCHANGE.getAssetProxy(erc20AssetProxyId); + if (proxyAddress != address(0)) { + ETHER_TOKEN.approve(proxyAddress, MAX_UINT); + ZRX_TOKEN.approve(proxyAddress, MAX_UINT); + } + } +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol new file mode 100644 index 000000000..18f2ba3bc --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinConstants.sol @@ -0,0 +1,49 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; + +import "../protocol/Exchange/Exchange.sol"; +import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol"; +import "../tokens/ERC20Token/IERC20Token.sol"; + +contract MixinConstants { + + Exchange EXCHANGE; + EtherToken ETHER_TOKEN; + IERC20Token ZRX_TOKEN; + bytes ZRX_ASSET_DATA; + bytes WETH_ASSET_DATA; + + constructor ( + address _exchange, + address _etherToken, + address _zrxToken, + bytes memory _zrxAssetData, + bytes memory _wethAssetData + ) + public + { + EXCHANGE = Exchange(_exchange); + ETHER_TOKEN = EtherToken(_etherToken); + ZRX_TOKEN = IERC20Token(_zrxToken); + ZRX_ASSET_DATA = _zrxAssetData; + WETH_ASSET_DATA = _wethAssetData; + } + +}
\ No newline at end of file diff --git a/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol b/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol new file mode 100644 index 000000000..53d4116d7 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinERC20.sol @@ -0,0 +1,68 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +contract MixinERC20 { + + string constant ERROR_TRANSFER_FAILED = "TRANSFER_FAILED"; + bytes4 constant ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)")); + + function transferToken( + address token, + address to, + uint256 amount + ) + internal + { + // Transfer tokens. + // We do a raw call so we can check the success separate + // from the return data. + bool success = token.call(abi.encodeWithSelector( + ERC20_TRANSFER_SELECTOR, + to, + amount + )); + require( + success, + "TRANSFER_FAILED" + ); + + // Check return data. + // If there is no return data, we assume the token incorrectly + // does not return a bool. In this case we expect it to revert + // on failure, which was handled above. + // If the token does return data, we require that it is a single + // value that evaluates to true. + assembly { + if returndatasize { + success := 0 + if eq(returndatasize, 32) { + // First 64 bytes of memory are reserved scratch space + returndatacopy(0, 0, 32) + success := mload(0) + } + } + } + require( + success, + "TRANSFER_FAILED" + ); + } +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol b/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol new file mode 100644 index 000000000..b2e8803a9 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinERC721.sol @@ -0,0 +1,64 @@ +/* + + 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 new file mode 100644 index 000000000..c2a6ea0a4 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinErrorMessages.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; + +/// This contract is intended to serve as a reference, but is not actually used for efficiency reasons. +contract MixinErrorMessages { + string constant VALUE_GREATER_THAN_ZERO = "VALUE_GREATER_THAN_ZERO"; + string constant FEE_PROPORTION_TOO_LARGE = "FEE_PROPORTION_TOO_LARGE"; + string constant TAKER_ASSET_ZRX_REQUIRED = "TAKER_ASSET_ZRX_REQUIRED"; + string constant TAKER_ASSET_WETH_REQUIRED = "TAKER_ASSET_WETH_REQUIRED"; + string constant SAME_ASSET_TYPE_REQUIRED = "SAME_ASSET_TYPE_REQUIRED"; + string constant UNACCEPTABLE_THRESHOLD = "UNACCEPTABLE_THRESHOLD"; + string constant UNSUPPORTED_TOKEN_PROXY = "UNSUPPORTED_TOKEN_PROXY"; + string constant ASSET_AMOUNT_MATCH_ORDER_SIZE = "ASSET_AMOUNT_MUST_MATCH_ORDER_SIZE"; + string constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY = "DEFAULT_FUNCTION_WETH_CONTRACT_ONLY"; + string constant INVALID_MSG_VALUE = "INVALID_MSG_VALUE"; +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol new file mode 100644 index 000000000..0bca7dc80 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol @@ -0,0 +1,158 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +import "../utils/LibBytes/LibBytes.sol"; +import "../protocol/Exchange/libs/LibFillResults.sol"; +import "../protocol/Exchange/libs/LibMath.sol"; +import "../protocol/Exchange/libs/LibOrder.sol"; +import "./MixinConstants.sol"; + +contract MixinExpectedResults is + LibMath, + LibFillResults, + MixinConstants +{ + + /// @dev 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. + /// Including the fees required to be paid. + /// @param orders An array of Order struct containing order specifications. + /// @param makerAssetFillAmount A number representing the amount of this order to fill. + /// @return totalFillResults Amounts filled and fees paid by maker and taker. + function calculateMarketBuyResults( + LibOrder.Order[] memory orders, + uint256 makerAssetFillAmount + ) + public + view + returns (FillResults memory totalFillResults) + { + for (uint256 i = 0; i < orders.length; i++) { + uint256 remainingMakerAssetFillAmount = safeSub(makerAssetFillAmount, totalFillResults.makerAssetFilledAmount); + uint256 remainingTakerAssetFillAmount = getPartialAmount( + orders[i].takerAssetAmount, + orders[i].makerAssetAmount, + remainingMakerAssetFillAmount + ); + FillResults memory singleFillResult = calculateFillResults(orders[i], remainingTakerAssetFillAmount); + addFillResults(totalFillResults, singleFillResult); + if (totalFillResults.makerAssetFilledAmount == makerAssetFillAmount) { + break; + } + } + return totalFillResults; + } + + /// @dev Calculates fill results for buyFeeTokens. This handles fees on buying ZRX + /// so the end result is the expected amount of ZRX (not less after fees). + /// @param orders An array of Order struct containing order specifications. + /// @param zrxFillAmount A number representing the amount zrx to buy + /// @return totalFillResults Expected fill result amounts from buying fees + function calculateMarketBuyZrxResults( + LibOrder.Order[] memory orders, + uint256 zrxFillAmount + ) + public + view + returns (FillResults memory totalFillResults) + { + for (uint256 i = 0; i < orders.length; i++) { + uint256 remainingZrxFillAmount = safeSub(zrxFillAmount, totalFillResults.makerAssetFilledAmount); + // Convert the remaining amount of makerToken to buy into remaining amount + // of takerToken to sell, assuming entire amount can be sold in the current order + uint256 remainingWethSellAmount = getPartialAmount( + orders[i].takerAssetAmount, + safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees + remainingZrxFillAmount + ); + FillResults memory singleFillResult = calculateFillResults(orders[i], safeAdd(remainingWethSellAmount, 1)); + + singleFillResult.makerAssetFilledAmount = safeSub(singleFillResult.makerAssetFilledAmount, singleFillResult.takerFeePaid); + addFillResults(totalFillResults, singleFillResult); + // As we compensate for the rounding issue above have slightly more ZRX than the requested zrxFillAmount + if (totalFillResults.makerAssetFilledAmount >= zrxFillAmount) { + break; + } + } + return totalFillResults; + } +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol new file mode 100644 index 000000000..ef06fe519 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyTokens.sol @@ -0,0 +1,258 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +import "../utils/LibBytes/LibBytes.sol"; +import "./MixinWethFees.sol"; +import "./MixinMarketBuyZrx.sol"; +import "./MixinExpectedResults.sol"; +import "./MixinERC20.sol"; +import "./MixinERC721.sol"; +import "./MixinConstants.sol"; +import "../protocol/Exchange/libs/LibOrder.sol"; + +contract MixinMarketBuyTokens is + MixinConstants, + MixinWethFees, + MixinMarketBuyZrx, + MixinExpectedResults, + MixinERC20, + MixinERC721 +{ + bytes4 public constant ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)")); + bytes4 public constant ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)")); + + /// @dev Buys the exact amount of assets (ERC20 and ERC721), performing fee abstraction if required. + /// All order assets must be of the same type. Deducts a proportional fee to fee recipient. + /// This function is payable and will convert all incoming ETH into WETH and perform the trade on behalf of the caller. + /// The caller is sent all assets from the fill of orders. This function will revert unless the requested amount of assets are purchased. + /// Any excess ETH sent will be returned to the caller + /// @param orders An array of Order struct containing order specifications. + /// @param signatures An array of Proof that order has been created by maker. + /// @param feeOrders An array of Order struct containing order specifications for fees. + /// @param makerTokenFillAmount The amount of maker asset to buy. + /// @param feeSignatures An array of Proof that order has been created by maker for the fee orders. + /// @param feeProportion A proportion deducted off the ETH spent and sent to feeRecipient. The maximum value for this + /// is 1000, aka 10%. Supports up to 2 decimal places. I.e 0.59% is 59. + /// @param feeRecipient An address of the fee recipient whom receives feeProportion of ETH. + /// @return FillResults amounts filled and fees paid by maker and taker. + function marketBuyTokensWithEth( + LibOrder.Order[] memory orders, + bytes[] memory signatures, + LibOrder.Order[] memory feeOrders, + bytes[] memory feeSignatures, + uint256 makerTokenFillAmount, + uint16 feeProportion, + address feeRecipient + ) + payable + public + returns (FillResults memory totalFillResults) + { + uint256 takerEthAmount = msg.value; + require( + takerEthAmount > 0, + "VALUE_GREATER_THAN_ZERO" + ); + require( + makerTokenFillAmount > 0, + "VALUE_GREATER_THAN_ZERO" + ); + bytes4 assetDataId = LibBytes.readBytes4(orders[0].makerAssetData, 0); + require( + assetDataId == ERC20_DATA_ID || assetDataId == ERC721_DATA_ID, + "UNSUPPORTED_TOKEN_PROXY" + ); + + ETHER_TOKEN.deposit.value(takerEthAmount)(); + if (assetDataId == ERC20_DATA_ID) { + totalFillResults = marketBuyERC20TokensInternal( + orders, + signatures, + feeOrders, + feeSignatures, + makerTokenFillAmount + ); + } else if (assetDataId == ERC721_DATA_ID) { + totalFillResults = batchBuyERC721TokensInternal( + orders, + signatures, + feeOrders, + feeSignatures + ); + } + // Prevent accidental WETH owned by this contract and it being spent + require( + takerEthAmount >= totalFillResults.takerAssetFilledAmount, + "INVALID_MSG_VALUE" + ); + withdrawPayAndDeductEthFee( + safeSub(takerEthAmount, totalFillResults.takerAssetFilledAmount), + totalFillResults.takerAssetFilledAmount, + feeProportion, + feeRecipient + ); + return totalFillResults; + } + + /// @dev Buys an exact amount of an ERC20 token using WETH. + /// @param orders Orders to fill. The maker asset is the ERC20 token to buy. The taker asset is WETH. + /// @param signatures Proof that the orders were created by their respective makers. + /// @param feeOrders to fill. The maker asset is ZRX and the taker asset is WETH. + /// @param feeSignatures Proof that the feeOrders were created by their respective makers. + /// @param makerTokenFillAmount Amount of the ERC20 token to buy. + /// @return totalFillResults Aggregated fill results of buying the ERC20 and ZRX tokens. + function marketBuyERC20TokensInternal( + LibOrder.Order[] memory orders, + bytes[] memory signatures, + LibOrder.Order[] memory feeOrders, + bytes[] memory feeSignatures, + uint256 makerTokenFillAmount + ) + private + returns (FillResults memory totalFillResults) + { + // We read the maker token address to check if it is ZRX and later use it for transfer + address makerTokenAddress = LibBytes.readAddress(orders[0].makerAssetData, 16); + // We assume that asset being bought by taker is the same for each order. + // Rather than passing this in as calldata, we copy the makerAssetData from the first order onto all later orders. + orders[0].takerAssetData = WETH_ASSET_DATA; + // We can short cut here for effeciency and use buyFeeTokensInternal if maker asset token is ZRX + // this buys us exactly that amount taking into account the fees. This saves gas and calculates the rate correctly + FillResults memory marketBuyResults; + if (makerTokenAddress == address(ZRX_TOKEN)) { + marketBuyResults = marketBuyZrxInternal( + orders, + signatures, + makerTokenFillAmount + ); + // When buying ZRX we round up which can result in a small margin excess + require( + marketBuyResults.makerAssetFilledAmount >= makerTokenFillAmount, + "UNACCEPTABLE_THRESHOLD" + ); + addFillResults(totalFillResults, marketBuyResults); + require( + isAcceptableThreshold( + safeAdd(totalFillResults.makerAssetFilledAmount, totalFillResults.takerFeePaid), // Total ZRX + totalFillResults.makerAssetFilledAmount // amount going to msg.sender + ), + "UNACCEPTABLE_THRESHOLD" + ); + } else { + FillResults memory calculatedMarketBuyResults = calculateMarketBuyResults(orders, makerTokenFillAmount); + if (calculatedMarketBuyResults.takerFeePaid > 0) { + // Fees are required for these orders. Buy enough ZRX to cover the future market buy + FillResults memory zrxMarketBuyResults = marketBuyZrxInternal( + feeOrders, + feeSignatures, + calculatedMarketBuyResults.takerFeePaid + ); + totalFillResults.takerAssetFilledAmount = zrxMarketBuyResults.takerAssetFilledAmount; + totalFillResults.takerFeePaid = zrxMarketBuyResults.takerFeePaid; + } + // Make our market buy of the requested tokens with the remaining balance + marketBuyResults = EXCHANGE.marketBuyOrders( + orders, + makerTokenFillAmount, + signatures + ); + require( + marketBuyResults.makerAssetFilledAmount == makerTokenFillAmount, + "UNACCEPTABLE_THRESHOLD" + ); + addFillResults(totalFillResults, marketBuyResults); + require( + isAcceptableThreshold( + totalFillResults.takerAssetFilledAmount, + marketBuyResults.takerAssetFilledAmount + ), + "UNACCEPTABLE_THRESHOLD" + ); + } + // Transfer all purchased tokens to msg.sender + transferToken( + makerTokenAddress, + msg.sender, + marketBuyResults.makerAssetFilledAmount + ); + return totalFillResults; + } + + /// @dev Buys an all of the ERC721 tokens in the orders. + /// @param orders Orders to fill. The maker asset is the ERC721 token to buy. The taker asset is WETH. + /// @param signatures Proof that the orders were created by their respective makers. + /// @param feeOrders to fill. The maker asset is ZRX and the taker asset is WETH. + /// @param feeSignatures Proof that the feeOrders were created by their respective makers. + /// @return totalFillResults Aggregated fill results of buying the ERC721 tokens and ZRX tokens. + function batchBuyERC721TokensInternal( + LibOrder.Order[] memory orders, + bytes[] memory signatures, + LibOrder.Order[] memory feeOrders, + bytes[] memory feeSignatures + ) + private + returns (FillResults memory totalFillResults) + { + uint256 totalZrxFeeAmount; + uint256 ordersLength = orders.length; + uint256[] memory takerAssetFillAmounts = new uint256[](ordersLength); + for (uint256 i = 0; i < ordersLength; i++) { + // Total up the fees + totalZrxFeeAmount = safeAdd(totalZrxFeeAmount, orders[i].takerFee); + // We assume that asset being bought by taker is the same for each order. + // Rather than passing this in as calldata, we set the takerAssetData as WETH asset data + orders[i].takerAssetData = WETH_ASSET_DATA; + // Populate takerAssetFillAmounts for later batchFill + takerAssetFillAmounts[i] = orders[i].takerAssetAmount; + } + if (totalZrxFeeAmount > 0) { + // Fees are required for these orders. Buy enough ZRX to cover the future fill + FillResults memory zrxMarketBuyResults = marketBuyZrxInternal( + feeOrders, + feeSignatures, + totalZrxFeeAmount + ); + totalFillResults.takerFeePaid = zrxMarketBuyResults.takerFeePaid; + totalFillResults.takerAssetFilledAmount = zrxMarketBuyResults.takerAssetFilledAmount; + } + FillResults memory batchFillResults = EXCHANGE.batchFillOrKillOrders( + orders, + takerAssetFillAmounts, + signatures + ); + addFillResults(totalFillResults, batchFillResults); + require( + isAcceptableThreshold( + totalFillResults.takerAssetFilledAmount, + batchFillResults.takerAssetFilledAmount + ), + "UNACCEPTABLE_THRESHOLD" + ); + // Transfer all of the tokens filled from the batchFill + for (i = 0; i < ordersLength; i++) { + transferERC721Token( + orders[i].makerAssetData, + msg.sender + ); + } + return totalFillResults; + } +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol new file mode 100644 index 000000000..4dbb34de3 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketBuyZrx.sol @@ -0,0 +1,80 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +import "../protocol/Exchange/Exchange.sol"; +import "../protocol/Exchange/libs/LibFillResults.sol"; +import "../protocol/Exchange/libs/LibOrder.sol"; +import "../protocol/Exchange/libs/LibMath.sol"; +import "./MixinConstants.sol"; + +contract MixinMarketBuyZrx is + LibMath, + LibFillResults, + MixinConstants +{ + /// @dev Buys zrxBuyAmount of ZRX fee tokens, taking into account the fees on buying fee tokens. This will guarantee + /// At least zrxBuyAmount of ZRX fee tokens are purchased (sometimes slightly over due to rounding issues). + /// It is possible that a request to buy 200 ZRX fee tokens will require purchasing 202 ZRX tokens + /// As 2 ZRX is required to purchase the 200 ZRX fee tokens. This guarantees at least 200 ZRX for future purchases. + /// @param orders An array of Order struct containing order specifications for fees. + /// @param signatures An array of Proof that order has been created by maker for the fee orders. + /// @param zrxBuyAmount The number of requested ZRX fee tokens. + /// @return totalFillResults Amounts filled and fees paid by maker and taker. makerTokenAmount is the zrx amount deducted of fees + function marketBuyZrxInternal( + LibOrder.Order[] memory orders, + bytes[] memory signatures, + uint256 zrxBuyAmount + ) + internal + returns (FillResults memory totalFillResults) + { + for (uint256 i = 0; i < orders.length; i++) { + // All of these are ZRX/WETH, we can drop the respective assetData from callData + orders[i].makerAssetData = ZRX_ASSET_DATA; + orders[i].takerAssetData = WETH_ASSET_DATA; + // Calculate the remaining amount of makerToken to buy + uint256 remainingZrxBuyAmount = safeSub(zrxBuyAmount, totalFillResults.makerAssetFilledAmount); + // Convert the remaining amount of makerToken to buy into remaining amount + // of takerToken to sell, assuming entire amount can be sold in the current order + uint256 remainingWethSellAmount = getPartialAmount( + orders[i].takerAssetAmount, + safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees + remainingZrxBuyAmount + ); + // Attempt to sell the remaining amount of takerToken + // Round up the amount to ensure we don't under buy by a fractional amount + FillResults memory singleFillResult = EXCHANGE.fillOrder( + orders[i], + safeAdd(remainingWethSellAmount, 1), + signatures[i] + ); + // We didn't buy the full amount when buying ZRX as some were taken for fees + singleFillResult.makerAssetFilledAmount = safeSub(singleFillResult.makerAssetFilledAmount, singleFillResult.takerFeePaid); + // Update amounts filled and fees paid by maker and taker + addFillResults(totalFillResults, singleFillResult); + // Stop execution if the entire amount of makerToken has been bought + if (totalFillResults.makerAssetFilledAmount >= zrxBuyAmount) { + break; + } + } + return totalFillResults; + } +} diff --git a/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol b/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol new file mode 100644 index 000000000..8c9cdb8d5 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinMarketSellTokens.sol @@ -0,0 +1,196 @@ +/* + + 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/MixinWethFees.sol b/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol new file mode 100644 index 000000000..9206c5fe0 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/MixinWethFees.sol @@ -0,0 +1,114 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; +pragma experimental ABIEncoderV2; + +import { WETH9 as EtherToken } from "../tokens/WETH9/WETH9.sol"; +import "../protocol/Exchange/libs/LibMath.sol"; +import "./MixinConstants.sol"; + +contract MixinWethFees is + LibMath, + MixinConstants +{ + + uint16 constant public PERCENTAGE_DENOMINATOR = 10000; // 9800 == 98%, 10000 == 100% + uint16 constant public MAX_FEE = 1000; // 10% + uint16 constant public ALLOWABLE_EXCHANGE_PERCENTAGE = 9500; // 95% + + /// @dev Pays the feeRecipient feeProportion of the total takerEthAmount, denominated in ETH + /// @param takerEthAmount The total amount that was transacted in WETH, fees are calculated from this value. + /// @param feeProportion The proportion of fees + /// @param feeRecipient The recipient of the fees + /// @return ethFeeAmount Amount of ETH paid to feeRecipient as fee. + function payEthFee( + uint256 takerEthAmount, + uint16 feeProportion, + address feeRecipient + ) + internal + returns (uint256 ethFeeAmount) + { + if (feeProportion > 0 && feeRecipient != address(0)) { + require( + feeProportion <= MAX_FEE, + "FEE_PROPORTION_TOO_LARGE" + ); + // 1.5% is 150, allowing for 2 decimal precision, i.e 0.05% is 5 + ethFeeAmount = getPartialAmount( + feeProportion, + PERCENTAGE_DENOMINATOR, + takerEthAmount + ); + feeRecipient.transfer(ethFeeAmount); + } + return ethFeeAmount; + } + + /// @dev Withdraws the remaining WETH, deduct and pay fees from this amount based on the takerTokenAmount to the feeRecipient. + /// If a user overpaid ETH initially, the fees are calculated from the amount traded and deducted from withdrawAmount. + /// Any remaining ETH is sent back to the user. + /// @param ethWithdrawAmount The amount to withdraw from the WETH contract. + /// @param wethAmountSold The total amount that was transacted in WETH, fees are calculated from this value. + /// @param feeProportion The proportion of fees + /// @param feeRecipient The recipient of the fees + function withdrawPayAndDeductEthFee( + uint256 ethWithdrawAmount, + uint256 wethAmountSold, + uint16 feeProportion, + address feeRecipient + ) + internal + { + // Return all of the excess WETH if any after deducting fees on the amount + if (ethWithdrawAmount > 0) { + ETHER_TOKEN.withdraw(ethWithdrawAmount); + // Fees proportional to the amount traded + uint256 ethFeeAmount = payEthFee( + wethAmountSold, + feeProportion, + feeRecipient + ); + uint256 unspentEthAmount = safeSub(ethWithdrawAmount, ethFeeAmount); + if (unspentEthAmount > 0) { + msg.sender.transfer(unspentEthAmount); + } + } + } + + /// @dev Checks whether the amount of tokens sold against the amount of tokens requested + /// is within a certain threshold. This ensures the caller gets a fair deal when + /// performing any token fee abstraction. Threshold is 95%. If fee abstraction costs more than + /// 5% of the total transaction, we return false. + /// @param requestedSellAmount The amount the user requested, or sent in to a payable function + /// @param tokenAmountSold The amount of the token that was sold after fee abstraction + /// @return bool of whether this is within an acceptable threshold + function isAcceptableThreshold(uint256 requestedSellAmount, uint256 tokenAmountSold) + internal + pure + returns (bool) + { + uint256 acceptableSellAmount = getPartialAmount( + ALLOWABLE_EXCHANGE_PERCENTAGE, + PERCENTAGE_DENOMINATOR, + requestedSellAmount + ); + return tokenAmountSold >= acceptableSellAmount; + } +} diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol index 79fd92029..1ceecd907 100644 --- a/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol +++ b/packages/contracts/src/2.0.0/multisig/MultiSigWallet.sol @@ -1,5 +1,7 @@ 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> contract MultiSigWallet { diff --git a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol index 9766c2158..d714b661d 100644 --- a/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol +++ b/packages/contracts/src/2.0.0/multisig/MultiSigWalletWithTimeLock.sol @@ -20,6 +20,8 @@ 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> contract MultiSigWalletWithTimeLock is MultiSigWallet { diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol index 3b9584a44..5bc5f3a47 100644 --- a/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol +++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/MixinAuthorizable.sol @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../../utils/Ownable/Ownable.sol"; import "./mixins/MAuthorizable.sol"; + contract MixinAuthorizable is Ownable, MAuthorizable diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAssetData.sol index 7ebd6acf0..b4ff2d900 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 @@ -18,15 +18,18 @@ pragma solidity ^0.4.23; + // @dev Interface of the asset proxy's assetData. // The asset proxies take an ABI encoded `bytes assetData` as argument. // This argument is ABI encoded as one of the methods of this interface. interface IAssetData { - + + // 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 eacd5a412..0ef1ed2e0 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 @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "./IAuthorizable.sol"; + contract IAssetProxy is IAuthorizable { diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/interfaces/IAuthorizable.sol index cedd1744c..286db74aa 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 @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../../../utils/Ownable/IOwnable.sol"; + contract IAuthorizable is IOwnable { diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/libs/LibAssetProxyErrors.sol index 338cb12e2..4b460ea9a 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + /// @dev This contract documents the revert reasons used in the AssetProxy contracts. /// This contract is intended to serve as a reference, but is not actually used for efficiency reasons. contract LibAssetProxyErrors { diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/mixins/MAuthorizable.sol index 6f35bd7ec..66c259a23 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 @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../interfaces/IAuthorizable.sol"; + contract MAuthorizable is IAuthorizable { diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol index eb58b3374..232155a6b 100644 --- a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol +++ b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol @@ -21,6 +21,7 @@ pragma solidity ^0.4.10; import "../../multisig/MultiSigWalletWithTimeLock.sol"; import "../../utils/LibBytes/LibBytes.sol"; + contract AssetProxyOwner is MultiSigWalletWithTimeLock { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol b/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol index d36e9633e..effff82e0 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/Exchange.sol @@ -27,6 +27,7 @@ import "./MixinAssetProxyDispatcher.sol"; import "./MixinTransactions.sol"; import "./MixinMatchOrders.sol"; + contract Exchange is MixinExchangeCore, MixinMatchOrders, diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol index 9e9d88ce7..dcfe9e1de 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinAssetProxyDispatcher.sol @@ -23,6 +23,7 @@ import "../../utils/LibBytes/LibBytes.sol"; import "./mixins/MAssetProxyDispatcher.sol"; import "../AssetProxy/interfaces/IAssetProxy.sol"; + contract MixinAssetProxyDispatcher is Ownable, MAssetProxyDispatcher diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol index c0ed023ac..9e63dc1c0 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinExchangeCore.sol @@ -28,6 +28,7 @@ import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; import "./mixins/MAssetProxyDispatcher.sol"; + contract MixinExchangeCore is LibConstants, LibMath, @@ -396,7 +397,7 @@ contract MixinExchangeCore is return fillResults; } - /// @dev Settles an order by transferring assets between counterparties. + /// @dev Settles an order by transferring assets between counterparties. /// @param order Order struct containing order specifications. /// @param takerAddress Address selling takerAsset and buying makerAsset. /// @param fillResults Amounts to be filled and fees paid by maker and taker. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol index 1a43eec79..bfe838837 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinMatchOrders.sol @@ -23,6 +23,7 @@ import "./mixins/MMatchOrders.sol"; import "./mixins/MTransactions.sol"; import "./mixins/MAssetProxyDispatcher.sol"; + contract MixinMatchOrders is LibConstants, LibMath, diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol index 29172057a..78f13286f 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinSignatureValidator.sol @@ -24,6 +24,7 @@ import "./mixins/MTransactions.sol"; import "./interfaces/IWallet.sol"; import "./interfaces/IValidator.sol"; + contract MixinSignatureValidator is MSignatureValidator, MTransactions diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol index 31f7f2847..3b18ac733 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinTransactions.sol @@ -22,6 +22,7 @@ import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; import "./libs/LibEIP712.sol"; + contract MixinTransactions is LibEIP712, MSignatureValidator, diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol index 00668ca43..678d0252a 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/MixinWrapperFunctions.sol @@ -24,6 +24,7 @@ import "./libs/LibOrder.sol"; import "./libs/LibFillResults.sol"; import "./mixins/MExchangeCore.sol"; + contract MixinWrapperFunctions is LibMath, LibFillResults, diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IAssetProxyDispatcher.sol index 66f3b5796..b73881c07 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + contract IAssetProxyDispatcher { /// @dev Registers an asset proxy to its asset proxy id. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchange.sol index 9f21c18d7..05e5dedf4 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 @@ -26,6 +26,7 @@ import "./ITransactions.sol"; import "./IAssetProxyDispatcher.sol"; import "./IWrapperFunctions.sol"; + contract IExchange is IExchangeCore, IMatchOrders, diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IExchangeCore.sol index 98222f33f..2b573eb1a 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 @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../libs/LibOrder.sol"; import "../libs/LibFillResults.sol"; + contract IExchangeCore { /// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IMatchOrders.sol index df009d063..d44116474 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 @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../libs/LibOrder.sol"; import "../libs/LibFillResults.sol"; + contract IMatchOrders { /// @dev Match two complementary orders that have a profitable spread. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ISignatureValidator.sol index 511463309..c5a4a57e1 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + contract ISignatureValidator { /// @dev Approves a hash on-chain using any valid signature type. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/ITransactions.sol index a7cab8f55..aaaee389f 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 @@ -17,6 +17,7 @@ */ pragma solidity ^0.4.24; + contract ITransactions { /// @dev Executes an exchange method call in the context of signer. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IValidator.sol index 0b1796a66..2c0a5dbe2 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.23; + contract IValidator { /// @dev Verifies that a signature is valid. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWallet.sol index c86a2c057..c2db4a5b1 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + contract IWallet { /// @dev Verifies that a signature is valid. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/interfaces/IWrapperFunctions.sol index 84bb683bc..04257b883 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 @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../libs/LibOrder.sol"; import "../libs/LibFillResults.sol"; + contract IWrapperFunctions { /// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled. /// @param order LibOrder.Order struct containing order specifications. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol index 488ca956c..76200ec44 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 @@ -18,11 +18,13 @@ pragma solidity ^0.4.24; + contract LibConstants { // Asset data for ZRX token. Used for fee transfers. // @TODO: Hardcode constant when we deploy. Currently // not constant to make testing easier. + // solhint-disable-next-line var-name-mixedcase bytes public ZRX_ASSET_DATA; // @TODO: Remove when we deploy. diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibEIP712.sol index b983347a4..2bd7b60d4 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + contract LibEIP712 { // EIP191 header for EIP712 prefix string constant EIP191_HEADER = "\x19\x01"; @@ -38,6 +39,7 @@ contract LibEIP712 { )); // Hash of the EIP712 Domain Separator data + // solhint-disable-next-line var-name-mixedcase bytes32 public EIP712_DOMAIN_HASH; constructor () diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibExchangeErrors.sol index 01aa78a1d..99f683e1a 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 @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + /// @dev This contract documents the revert reasons used in the Exchange contract. /// This contract is intended to serve as a reference, but is not actually used for efficiency reasons. contract LibExchangeErrors { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibFillResults.sol index 63f1b8c87..35fa9ac0f 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 @@ -20,6 +20,7 @@ pragma solidity ^0.4.24; import "../../../utils/SafeMath/SafeMath.sol"; + contract LibFillResults is SafeMath { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibMath.sol index bfe2fd33f..9da784854 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 @@ -20,6 +20,7 @@ pragma solidity ^0.4.24; import "../../../utils/SafeMath/SafeMath.sol"; + contract LibMath is SafeMath { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibOrder.sol index 954f94f76..dda581d9f 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 @@ -20,6 +20,7 @@ pragma solidity ^0.4.24; import "./LibEIP712.sol"; + contract LibOrder is LibEIP712 { @@ -115,17 +116,20 @@ contract LibOrder is // )); assembly { // Backup + // solhint-disable-next-line space-after-comma let temp1 := mload(sub(order, 32)) let temp2 := mload(add(order, 320)) let temp3 := mload(add(order, 352)) // Hash in place + // solhint-disable-next-line space-after-comma mstore(sub(order, 32), schemaHash) mstore(add(order, 320), makerAssetDataHash) mstore(add(order, 352), takerAssetDataHash) result := keccak256(sub(order, 32), 416) // Restore + // solhint-disable-next-line space-after-comma mstore(sub(order, 32), temp1) mstore(add(order, 320), temp2) mstore(add(order, 352), temp3) diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MAssetProxyDispatcher.sol index 5bf59c6ce..367b37e80 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 @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../interfaces/IAssetProxyDispatcher.sol"; + contract MAssetProxyDispatcher is IAssetProxyDispatcher { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MExchangeCore.sol index 6e406e1c4..e28d9d25b 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 @@ -23,6 +23,7 @@ import "../libs/LibOrder.sol"; import "../libs/LibFillResults.sol"; import "../interfaces/IExchangeCore.sol"; + contract MExchangeCore is IExchangeCore { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MMatchOrders.sol index abe7c3596..289514b24 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 @@ -22,6 +22,7 @@ import "../libs/LibOrder.sol"; import "../libs/LibFillResults.sol"; import "../interfaces/IMatchOrders.sol"; + contract MMatchOrders is IMatchOrders { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MSignatureValidator.sol index 6cc1d7a10..83650b4aa 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 @@ -20,6 +20,7 @@ pragma solidity ^0.4.24; import "../interfaces/ISignatureValidator.sol"; + contract MSignatureValidator is ISignatureValidator { diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol b/packages/contracts/src/2.0.0/protocol/Exchange/mixins/MTransactions.sol index e2f89de01..a9fa6d4e2 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 @@ -19,6 +19,7 @@ pragma solidity ^0.4.24; import "../interfaces/ITransactions.sol"; + contract MTransactions is ITransactions { diff --git a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol index b2fe2df06..7a2702449 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../Mintable/Mintable.sol"; import "../../utils/Ownable/Ownable.sol"; + contract DummyERC20Token is Mintable, Ownable { string public name; string public symbol; diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol index c584d0b54..b027ac960 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol @@ -27,6 +27,7 @@ pragma solidity ^0.4.24; import "../../tokens/ERC721Token/IERC721Receiver.sol"; + contract DummyERC721Receiver is IERC721Receiver { diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol index 78ea96447..de76f10c5 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../../tokens/ERC721Token/ERC721Token.sol"; import "../../utils/Ownable/Ownable.sol"; + contract DummyERC721Token is Ownable, ERC721Token diff --git a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol index 5baaf6e5a..f20e2a944 100644 --- a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol +++ b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol @@ -22,9 +22,11 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; + contract ExchangeWrapper { // Exchange contract. + // solhint-disable-next-line var-name-mixedcase IExchange EXCHANGE; constructor (address _exchange) diff --git a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol index a91bfee9e..bccb74ce8 100644 --- a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol +++ b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol"; import "../../utils/SafeMath/SafeMath.sol"; + /* * Mintable * Base contract that creates a mintable UnlimitedAllowanceToken diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol index 2ae69e0ef..be7fea7d3 100644 --- a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol +++ b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol"; + contract TestAssetProxyDispatcher is MixinAssetProxyDispatcher { function publicDispatchTransferFrom( bytes memory assetData, diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol index 2abcd17a0..ddcc62f35 100644 --- a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol +++ b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol @@ -20,6 +20,7 @@ pragma solidity ^0.4.24; import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol"; + contract TestAssetProxyOwner is AssetProxyOwner { diff --git a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol index f45faaf36..f52f635e1 100644 --- a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol +++ b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../../utils/LibBytes/LibBytes.sol"; + contract TestLibBytes { using LibBytes for bytes; diff --git a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol index 010080703..df8eb55ce 100644 --- a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol +++ b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol @@ -23,6 +23,7 @@ import "../../protocol/Exchange/libs/LibMath.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../protocol/Exchange/libs/LibFillResults.sol"; + contract TestLibs is LibMath, LibOrder, diff --git a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol index 0f84678cf..591ae3378 100644 --- a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol +++ b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol @@ -22,6 +22,7 @@ pragma experimental ABIEncoderV2; import "../../protocol/Exchange/MixinSignatureValidator.sol"; import "../../protocol/Exchange/MixinTransactions.sol"; + contract TestSignatureValidator is MixinSignatureValidator, MixinTransactions diff --git a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol index f9271bf7a..5076dedc9 100644 --- a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol +++ b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol @@ -20,11 +20,13 @@ pragma solidity ^0.4.24; import "../../protocol/Exchange/interfaces/IValidator.sol"; + contract TestValidator is IValidator { // The single valid signer for this wallet. + // solhint-disable-next-line var-name-mixedcase address VALID_SIGNER; /// @dev constructs a new `TestValidator` with a single valid signer. diff --git a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol index 17dee9e9c..07dfac588 100644 --- a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol +++ b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol @@ -21,6 +21,7 @@ pragma solidity ^0.4.24; import "../../protocol/Exchange/interfaces/IWallet.sol"; import "../../utils/LibBytes/LibBytes.sol"; + contract TestWallet is IWallet { @@ -29,6 +30,7 @@ contract TestWallet is string constant LENGTH_65_REQUIRED = "LENGTH_65_REQUIRED"; // The owner of this wallet. + // solhint-disable-next-line var-name-mixedcase address WALLET_OWNER; /// @dev constructs a new `TestWallet` with a single owner. diff --git a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol index 8b52858b1..07bd7d531 100644 --- a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol +++ b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol @@ -23,6 +23,7 @@ import "../../protocol/Exchange/interfaces/IExchange.sol"; import "../../protocol/Exchange/libs/LibOrder.sol"; import "../../utils/Ownable/Ownable.sol"; + contract Whitelist is Ownable { @@ -35,15 +36,19 @@ contract Whitelist is mapping (address => bool) public isWhitelisted; // Exchange contract. + // solhint-disable-next-line var-name-mixedcase IExchange EXCHANGE; byte constant VALIDATOR_SIGNATURE_BYTE = "\x06"; + // solhint-disable-next-line var-name-mixedcase bytes TX_ORIGIN_SIGNATURE; 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); } diff --git a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol index b6961a6ec..59dc7d7bf 100644 --- a/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol +++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/ERC20Token.sol @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "./IERC20Token.sol"; + contract ERC20Token is IERC20Token { string constant INSUFFICIENT_BALANCE = "ERC20_INSUFFICIENT_BALANCE"; diff --git a/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol b/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol index eb879b6a8..de4ed2af9 100644 --- a/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol +++ b/packages/contracts/src/2.0.0/tokens/ERC20Token/IERC20Token.sol @@ -19,6 +19,7 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; + contract IERC20Token { /// @notice send `value` token to `to` from `msg.sender` diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol index 41ba149e3..defb506a8 100644 --- a/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol +++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/ERC721Token.sol @@ -29,6 +29,7 @@ import "./IERC721Token.sol"; import "./IERC721Receiver.sol"; import "../../utils/SafeMath/SafeMath.sol"; + /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol index b0fff3c90..f72c75638 100644 --- a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol +++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Receiver.sol @@ -25,6 +25,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pragma solidity ^0.4.24; + /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers diff --git a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol index 345712d67..0d64ee861 100644 --- a/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol +++ b/packages/contracts/src/2.0.0/tokens/ERC721Token/IERC721Token.sol @@ -25,6 +25,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pragma solidity ^0.4.24; + /** * @title ERC721 Non-Fungible Token Standard basic interface * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md diff --git a/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol b/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol index f62602ab3..845324e4e 100644 --- a/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol +++ b/packages/contracts/src/2.0.0/tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol @@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2; import "../ERC20Token/ERC20Token.sol"; + contract UnlimitedAllowanceToken is ERC20Token { uint256 constant MAX_UINT = 2**256 - 1; diff --git a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol b/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol index 733ca414b..378a507b9 100644 --- a/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol +++ b/packages/contracts/src/2.0.0/tokens/WETH9/WETH9.sol @@ -15,6 +15,7 @@ pragma solidity ^0.4.18; + contract WETH9 { string public name = "Wrapped Ether"; string public symbol = "WETH"; diff --git a/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol b/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol index 2e5b61e0b..ed0670072 100644 --- a/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol +++ b/packages/contracts/src/2.0.0/tokens/ZRXToken/ZRXToken.sol @@ -20,6 +20,8 @@ pragma solidity ^0.4.11; import { UnlimitedAllowanceToken_v1 as UnlimitedAllowanceToken } from "../../../1.0.0/UnlimitedAllowanceToken/UnlimitedAllowanceToken_v1.sol"; + + contract ZRXToken is UnlimitedAllowanceToken { uint8 constant public decimals = 18; diff --git a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol index 78b1ddf7c..c2fff5efb 100644 --- a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol +++ b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol @@ -18,6 +18,7 @@ pragma solidity ^0.4.24; + library LibBytes { using LibBytes for bytes; diff --git a/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol b/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol index 6f5761cc7..489793a95 100644 --- a/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol +++ b/packages/contracts/src/2.0.0/utils/Ownable/Ownable.sol @@ -10,6 +10,7 @@ pragma experimental ABIEncoderV2; import "./IOwnable.sol"; + contract Ownable is IOwnable { address public owner; diff --git a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol index e137f6ca5..ec0a3fe76 100644 --- a/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol +++ b/packages/contracts/src/2.0.0/utils/SafeMath/SafeMath.sol @@ -1,6 +1,7 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; + contract SafeMath { function safeMul(uint a, uint b) internal |