diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-04-26 09:46:09 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-27 02:09:53 +0800 |
commit | 31411dd11be29d5dcca646737e6ca08840e2d510 (patch) | |
tree | 220f32f3bca145244ad20d06b511cbc9549a2aa8 /packages/contracts/src | |
parent | b7781108ae4c77112b1522fa8b5e45bc04ce507f (diff) | |
download | dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar.gz dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar.bz2 dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar.lz dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar.xz dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.tar.zst dexon-sol-tools-31411dd11be29d5dcca646737e6ca08840e2d510.zip |
Add LibFillResults
Diffstat (limited to 'packages/contracts/src')
11 files changed, 107 insertions, 78 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol index caf48bfca..47f9e7a4d 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/Exchange.sol @@ -27,17 +27,16 @@ import "./MixinAssetProxyDispatcher.sol"; import "./MixinTransactions.sol"; contract Exchange is + MixinWrapperFunctions, MixinExchangeCore, MixinSignatureValidator, MixinSettlement, - MixinWrapperFunctions, - MixinAssetProxyDispatcher, - MixinTransactions + MixinTransactions, + MixinAssetProxyDispatcher { string constant public VERSION = "2.0.1-alpha"; - function Exchange( - bytes memory _zrxProxyData) + function Exchange(bytes memory _zrxProxyData) public MixinExchangeCore() MixinSignatureValidator() diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/LibFillResults.sol b/packages/contracts/src/contracts/current/protocol/Exchange/LibFillResults.sol new file mode 100644 index 000000000..41096f448 --- /dev/null +++ b/packages/contracts/src/contracts/current/protocol/Exchange/LibFillResults.sol @@ -0,0 +1,46 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.21; +pragma experimental ABIEncoderV2; + +import "../../utils/SafeMath/SafeMath.sol"; + +contract LibFillResults is SafeMath { + + struct FillResults { + uint256 makerAssetFilledAmount; + uint256 takerAssetFilledAmount; + uint256 makerFeePaid; + uint256 takerFeePaid; + } + + /// @dev Adds properties of both FillResults instances. + /// Modifies the first FillResults instance specified. + /// @param totalFillResults Fill results instance that will be added onto. + /// @param singleFillResults Fill results instance that will be added to totalFillResults. + function addFillResults(FillResults memory totalFillResults, FillResults memory singleFillResults) + internal + pure + { + totalFillResults.makerAssetFilledAmount = safeAdd(totalFillResults.makerAssetFilledAmount, singleFillResults.makerAssetFilledAmount); + totalFillResults.takerAssetFilledAmount = safeAdd(totalFillResults.takerAssetFilledAmount, singleFillResults.takerAssetFilledAmount); + totalFillResults.makerFeePaid = safeAdd(totalFillResults.makerFeePaid, singleFillResults.makerFeePaid); + totalFillResults.takerFeePaid = safeAdd(totalFillResults.takerFeePaid, singleFillResults.takerFeePaid); + } +}
\ No newline at end of file diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol index eab8e04a1..b60a1cb08 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinAssetProxyDispatcher.sol @@ -18,9 +18,9 @@ pragma solidity ^0.4.21; -import "./mixins/MAssetProxyDispatcher.sol"; -import "../AssetProxy/IAssetProxy.sol"; import "../../utils/Ownable/Ownable.sol"; +import "../AssetProxy/IAssetProxy.sol"; +import "./mixins/MAssetProxyDispatcher.sol"; contract MixinAssetProxyDispatcher is Ownable, diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol index 80120bc74..af114930b 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinExchangeCore.sol @@ -19,27 +19,29 @@ pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; +import "../../utils/SafeMath/SafeMath.sol"; +import "./LibFillResults.sol"; +import "./LibOrder.sol"; +import "./LibErrors.sol"; +import "./LibPartialAmount.sol"; import "./mixins/MExchangeCore.sol"; import "./mixins/MSettlement.sol"; import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; -import "./LibOrder.sol"; -import "./LibErrors.sol"; -import "./LibPartialAmount.sol"; -import "../../utils/SafeMath/SafeMath.sol"; /// @dev Provides MExchangeCore /// @dev Consumes MSettlement /// @dev Consumes MSignatureValidator contract MixinExchangeCore is + SafeMath, LibOrder, + LibFillResults, + LibErrors, + LibPartialAmount, MExchangeCore, MSettlement, MSignatureValidator, - MTransactions, - SafeMath, - LibErrors, - LibPartialAmount + MTransactions { // Mapping of orderHash => amount of takerAsset already bought by maker mapping (bytes32 => uint256) public filled; diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol index ae41c7a86..df86a9dfa 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSettlement.sol @@ -21,14 +21,15 @@ pragma experimental ABIEncoderV2; import "./mixins/MSettlement.sol"; import "./mixins/MAssetProxyDispatcher.sol"; +import "./LibOrder.sol"; import "./LibPartialAmount.sol"; import "../AssetProxy/IAssetProxy.sol"; /// @dev Provides MixinSettlement contract MixinSettlement is + LibPartialAmount, MSettlement, - MAssetProxyDispatcher, - LibPartialAmount + MAssetProxyDispatcher { bytes ZRX_PROXY_DATA; @@ -46,7 +47,7 @@ contract MixinSettlement is } function settleOrder( - Order memory order, + LibOrder.Order memory order, address takerAddress, uint256 takerAssetFilledAmount) internal diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol index 48e7be424..46bf01e78 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol @@ -23,9 +23,7 @@ import "./mixins/MSignatureValidator.sol"; import "./ISigner.sol"; /// @dev Provides MSignatureValidator -contract MixinSignatureValidator is - MSignatureValidator -{ +contract MixinSignatureValidator is MSignatureValidator { enum SignatureType { Illegal, // Default value Invalid, diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol index 4d6ba17dd..fe58e3d18 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinWrapperFunctions.sol @@ -19,17 +19,21 @@ pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; -import "./mixins/MExchangeCore.sol"; -import "./LibPartialAmount.sol"; import "../../utils/SafeMath/SafeMath.sol"; import "../../utils/LibBytes/LibBytes.sol"; +import "./mixins/MExchangeCore.sol"; +import "./LibPartialAmount.sol"; +import "./LibOrder.sol"; +import "./LibFillResults.sol"; /// @dev Consumes MExchangeCore contract MixinWrapperFunctions is - MExchangeCore, SafeMath, + LibOrder, + LibFillResults, + LibPartialAmount, LibBytes, - LibPartialAmount + MExchangeCore { /// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled. /// @param order Order struct containing order specifications. @@ -489,19 +493,4 @@ contract MixinWrapperFunctions is cancelOrder(orders[i]); } } - - /// @dev Adds properties of both FillResults instances. - /// Modifies the first FillResults instance specified. - /// @param totalFillResults Fill results instance that will be added onto. - /// @param singleFillResults Fill results instance that will be added to totalFillResults. - function addFillResults(FillResults memory totalFillResults, FillResults memory singleFillResults) - internal - pure - { - totalFillResults.makerAssetFilledAmount = safeAdd(totalFillResults.makerAssetFilledAmount, singleFillResults.makerAssetFilledAmount); - totalFillResults.takerAssetFilledAmount = safeAdd(totalFillResults.takerAssetFilledAmount, singleFillResults.takerAssetFilledAmount); - totalFillResults.makerFeePaid = safeAdd(totalFillResults.makerFeePaid, singleFillResults.makerFeePaid); - totalFillResults.takerFeePaid = safeAdd(totalFillResults.takerFeePaid, singleFillResults.takerFeePaid); - } - } diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol index 9a7f80109..656df079e 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MExchangeCore.sol @@ -20,24 +20,18 @@ pragma solidity ^0.4.21; pragma experimental ABIEncoderV2; import "../LibOrder.sol"; +import "../LibFillResults.sol"; -contract MExchangeCore is LibOrder { - - struct FillResults { - uint256 makerAssetFilledAmount; - uint256 takerAssetFilledAmount; - uint256 makerFeePaid; - uint256 takerFeePaid; - } +contract MExchangeCore { function fillOrder( - Order memory order, + LibOrder.Order memory order, uint256 takerAssetFillAmount, bytes memory signature) public - returns (FillResults memory fillResults); + returns (LibFillResults.FillResults memory fillResults); - function cancelOrder(Order memory order) + function cancelOrder(LibOrder.Order memory order) public returns (bool); diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol index 172138f2d..0d7e59a9a 100644 --- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol +++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSettlement.sol @@ -21,10 +21,10 @@ pragma experimental ABIEncoderV2; import "../LibOrder.sol"; -contract MSettlement is LibOrder { +contract MSettlement { function settleOrder( - Order memory order, + LibOrder.Order memory order, address takerAddress, uint256 takerAssetFilledAmount) internal diff --git a/packages/contracts/src/contracts/current/tokens/ERC721Token/ERC721Token.sol b/packages/contracts/src/contracts/current/tokens/ERC721Token/ERC721Token.sol index af4c91509..3bf064c3f 100644 --- a/packages/contracts/src/contracts/current/tokens/ERC721Token/ERC721Token.sol +++ b/packages/contracts/src/contracts/current/tokens/ERC721Token/ERC721Token.sol @@ -402,5 +402,5 @@ contract ERC721Token is // contracts then. assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly return size > 0; - } + } }
\ No newline at end of file diff --git a/packages/contracts/src/contracts/current/tokens/ERC721Token/IERC721Receiver.sol b/packages/contracts/src/contracts/current/tokens/ERC721Token/IERC721Receiver.sol index cef1340f4..26871cc89 100644 --- a/packages/contracts/src/contracts/current/tokens/ERC721Token/IERC721Receiver.sol +++ b/packages/contracts/src/contracts/current/tokens/ERC721Token/IERC721Receiver.sol @@ -32,29 +32,29 @@ pragma solidity ^0.4.21; * Modified from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC721/ERC721Receiver.sol */ contract IERC721Receiver { - /** - * @dev Magic value to be returned upon successful reception of an NFT - * Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`, - * which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` - */ - bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; + /** + * @dev Magic value to be returned upon successful reception of an NFT + * Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`, + * which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` + */ + bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; - /** - * @notice Handle the receipt of an NFT - * @dev The ERC721 smart contract calls this function on the recipient - * after a `safetransfer`. This function MAY throw to revert and reject the - * transfer. This function MUST use 50,000 gas or less. Return of other - * than the magic value MUST result in the transaction being reverted. - * Note: the contract address is always the message sender. - * @param _from The sending address - * @param _tokenId The NFT identifier which is being transfered - * @param _data Additional data with no specified format - * @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` - */ - function onERC721Received( - address _from, - uint256 _tokenId, - bytes _data) - public - returns (bytes4); + /** + * @notice Handle the receipt of an NFT + * @dev The ERC721 smart contract calls this function on the recipient + * after a `safetransfer`. This function MAY throw to revert and reject the + * transfer. This function MUST use 50,000 gas or less. Return of other + * than the magic value MUST result in the transaction being reverted. + * Note: the contract address is always the message sender. + * @param _from The sending address + * @param _tokenId The NFT identifier which is being transfered + * @param _data Additional data with no specified format + * @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` + */ + function onERC721Received( + address _from, + uint256 _tokenId, + bytes _data) + public + returns (bytes4); }
\ No newline at end of file |