From 8314bbbbac0101831bf8167c01e5ccf46663a2f0 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sat, 7 Jul 2018 22:57:09 -0700 Subject: Add interfaces and mixins --- .../forwarder/interfaces/IExpectedResults.sol | 66 ++++++++++++++++++ .../src/2.0.0/forwarder/interfaces/IForwarder.sol | 30 ++++++++ .../2.0.0/forwarder/interfaces/IForwarderCore.sol | 79 ++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol create mode 100644 packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol create mode 100644 packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol (limited to 'packages/contracts/src/2.0.0/forwarder/interfaces') diff --git a/packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol new file mode 100644 index 000000000..1ea335b6c --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol @@ -0,0 +1,66 @@ +/* + + 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/LibFillResults.sol"; +import "../../protocol/Exchange/libs/LibOrder.sol"; + + +contract IExpectedResults { + + /// @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 (LibFillResults.FillResults memory 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 (LibFillResults.FillResults memory 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 (LibFillResults.FillResults memory totalFillResults); +} \ No newline at end of file diff --git a/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol new file mode 100644 index 000000000..fffce92b1 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol @@ -0,0 +1,30 @@ +/* + + 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 "./IForwarderCore.sol"; +import "./IExpectedResults.sol"; + + +// solhint-disable no-empty-blocks +contract IForwarder is + IForwarderCore, + IExpectedResults +{} \ No newline at end of file diff --git a/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol new file mode 100644 index 000000000..75c8e8c98 --- /dev/null +++ b/packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol @@ -0,0 +1,79 @@ +/* + + 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 "../../protocol/Exchange/libs/LibFillResults.sol"; + + +contract IForwarderCore { + + /// @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 + ) + public + payable + returns (LibFillResults.FillResults memory totalFillResults); + + /// @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 + ) + public + payable + returns (LibFillResults.FillResults memory totalFillResults); +} \ No newline at end of file -- cgit v1.2.3