diff options
Diffstat (limited to 'packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol')
-rw-r--r-- | packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol index 6406d1d37..a575c9675 100644 --- a/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol +++ b/packages/contracts/src/2.0.0/forwarder/MixinExpectedResults.sol @@ -23,13 +23,15 @@ 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"; +import "./mixins/MConstants.sol"; +import "./mixins/MExpectedResults.sol"; contract MixinExpectedResults is LibMath, LibFillResults, - MixinConstants + MConstants, + MExpectedResults { /// @dev Calculates a total FillResults for buying makerAssetFillAmount over all orders. @@ -61,6 +63,30 @@ contract MixinExpectedResults is return totalFillResults; } + /// @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 + ) + public + 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 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. @@ -132,28 +158,4 @@ contract MixinExpectedResults is ); 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; - } } |