Add LibFillResults

This commit is contained in:
Amir Bandeali
2018-04-25 18:46:09 -07:00
parent b7781108ae
commit 31411dd11b
11 changed files with 107 additions and 78 deletions

View File

@@ -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()

View File

@@ -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);
}
}

View File

@@ -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,

View File

@@ -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;

View File

@@ -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

View File

@@ -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,

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -402,5 +402,5 @@ contract ERC721Token is
// contracts then.
assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly
return size > 0;
}
}
}

View File

@@ -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);
}