aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/2.0.0/forwarder/mixins
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/src/2.0.0/forwarder/mixins')
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MAssets.sol54
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol35
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MExchangeWrapper.sol87
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol42
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol63
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol68
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol42
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol46
-rw-r--r--packages/contracts/src/2.0.0/forwarder/mixins/MWeth.sol41
9 files changed, 191 insertions, 287 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MAssets.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MAssets.sol
new file mode 100644
index 000000000..340ee0bcb
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MAssets.sol
@@ -0,0 +1,54 @@
+/*
+
+ 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 "../interfaces/IAssets.sol";
+
+
+contract MAssets is
+ IAssets
+{
+
+ /// @dev Transfers given amount of asset to sender.
+ /// @param assetData Byte array encoded for the respective asset proxy.
+ /// @param amount Amount of asset to transfer to sender.
+ function transferPurchasedAssetToSender(
+ bytes memory assetData,
+ uint256 amount
+ )
+ internal;
+
+ /// @dev Decodes ERC20 assetData and transfers given amount to sender.
+ /// @param assetData Byte array encoded for the respective asset proxy.
+ /// @param amount Amount of asset to transfer to sender.
+ function transferERC20Token(
+ bytes memory assetData,
+ uint256 amount
+ )
+ internal;
+
+ /// @dev Decodes ERC721 assetData and transfers given amount to sender.
+ /// @param assetData Byte array encoded for the respective asset proxy.
+ /// @param amount Amount of asset to transfer to sender.
+ function transferERC721Token(
+ bytes memory assetData,
+ uint256 amount
+ )
+ internal;
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
deleted file mode 100644
index 348bf169e..000000000
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-
- 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/interfaces/IExchange.sol";
-import "../../tokens/EtherToken/IEtherToken.sol";
-import "../../tokens/ERC20Token/IERC20Token.sol";
-
-
-contract MConstants {
-
- // solhint-disable var-name-mixedcase
- IExchange internal EXCHANGE;
- IEtherToken internal ETHER_TOKEN;
- IERC20Token internal ZRX_TOKEN;
- bytes internal ZRX_ASSET_DATA;
- bytes internal WETH_ASSET_DATA;
- // solhint-enable var-name-mixedcase
-}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MExchangeWrapper.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MExchangeWrapper.sol
new file mode 100644
index 000000000..5a2def7e5
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MExchangeWrapper.sol
@@ -0,0 +1,87 @@
+/*
+
+ 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 MExchangeWrapper {
+
+ /// @dev Fills the input order.
+ /// Returns false if the transaction would otherwise revert.
+ /// @param order Order struct containing order specifications.
+ /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
+ /// @param signature Proof that order has been created by maker.
+ /// @return Amounts filled and fees paid by maker and taker.
+ function fillOrderNoThrow(
+ LibOrder.Order memory order,
+ uint256 takerAssetFillAmount,
+ bytes memory signature
+ )
+ internal
+ returns (LibFillResults.FillResults memory fillResults);
+
+ /// @dev Synchronously executes multiple calls of fillOrder until total amount of WETH has been sold by taker.
+ /// Returns false if the transaction would otherwise revert.
+ /// @param orders Array of order specifications.
+ /// @param wethSellAmount Desired amount of WETH to sell.
+ /// @param signatures Proofs that orders have been signed by makers.
+ /// @return Amounts filled and fees paid by makers and taker.
+ function marketSellWeth(
+ LibOrder.Order[] memory orders,
+ uint256 wethSellAmount,
+ bytes[] memory signatures
+ )
+ internal
+ returns (LibFillResults.FillResults memory totalFillResults);
+
+ /// @dev Synchronously executes multiple fill orders in a single transaction until total amount is bought by taker.
+ /// Returns false if the transaction would otherwise revert.
+ /// The asset being sold by taker must always be WETH.
+ /// @param orders Array of order specifications.
+ /// @param makerAssetFillAmount Desired amount of makerAsset to buy.
+ /// @param signatures Proofs that orders have been signed by makers.
+ /// @return Amounts filled and fees paid by makers and taker.
+ function marketBuyWithWeth(
+ LibOrder.Order[] memory orders,
+ uint256 makerAssetFillAmount,
+ bytes[] memory signatures
+ )
+ internal
+ returns (LibFillResults.FillResults memory totalFillResults);
+
+ /// @dev Buys zrxBuyAmount of ZRX fee tokens, taking into account ZRX fees for each order. This will guarantee
+ /// that at least zrxBuyAmount of ZRX is purchased (sometimes slightly over due to rounding issues).
+ /// It is possible that a request to buy 200 ZRX will require purchasing 202 ZRX
+ /// as 2 ZRX is required to purchase the 200 ZRX fee tokens. This guarantees at least 200 ZRX for future purchases.
+ /// The asset being sold by taker must always be WETH.
+ /// @param orders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset.
+ /// @param zrxBuyAmount Desired amount of ZRX to buy.
+ /// @param signatures Proofs that orders have been created by makers.
+ /// @return totalFillResults Amounts filled and fees paid by maker and taker.
+ function marketBuyZrxWithWeth(
+ LibOrder.Order[] memory orders,
+ uint256 zrxBuyAmount,
+ bytes[] memory signatures
+ )
+ internal
+ returns (LibFillResults.FillResults memory totalFillResults);
+}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
deleted file mode 100644
index cf03bb32e..000000000
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-
- 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";
-import "../interfaces/IExpectedResults.sol";
-
-
-contract MExpectedResults is
- IExpectedResults
-{
-
- /// @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 (LibFillResults.FillResults memory fillResults);
-}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
deleted file mode 100644
index f332637ea..000000000
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-
- 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;
-
-
-contract MFees {
-
- /// @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);
-
- /// @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;
-
- /// @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);
-}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
index 4a54e76b1..0f5cd9c66 100644
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
@@ -28,65 +28,15 @@ contract MForwarderCore is
IForwarderCore
{
- /// @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
+ /// @dev Ensures that all ZRX fees have been repurchased and no extra WETH owned by this contract has been sold.
+ /// @param orderFillResults Amounts filled and fees paid for primary orders.
+ /// @param feeOrderFillResults Amounts filled and fees paid for fee orders.
+ /// @param zrxBuyAmount The amount of ZRX that needed to be repurchased after filling primary orders.
+ function assertValidFillResults(
+ LibFillResults.FillResults memory orderFillResults,
+ LibFillResults.FillResults memory feeOrderFillResults,
+ uint256 zrxBuyAmount
)
internal
- returns (LibFillResults.FillResults memory 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 (LibFillResults.FillResults memory 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
- )
- internal
- returns (LibFillResults.FillResults memory 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
- )
- internal
- returns (LibFillResults.FillResults memory totalFillResults);
+ view;
}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
deleted file mode 100644
index 3501ef001..000000000
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-
- 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/libs/LibFillResults.sol";
-import "../../protocol/Exchange/libs/LibOrder.sol";
-
-
-contract MMarketBuyZrx {
-
- /// @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 (LibFillResults.FillResults memory totalFillResults);
-}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
deleted file mode 100644
index 418a6288b..000000000
--- a/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-
- 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;
-
-
-contract MTransfer {
-
- function onERC721Received(address, uint256, bytes memory)
- public
- pure
- returns(bytes4);
-
- function onERC721Received(address, address, uint256, bytes memory)
- public
- pure
- returns(bytes4);
-
- function transferERC20Token(
- address token,
- address to,
- uint256 amount
- )
- internal;
-
- function transferERC721Token(
- bytes memory assetData,
- address to
- )
- internal;
-}
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MWeth.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MWeth.sol
new file mode 100644
index 000000000..88e77be4e
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MWeth.sol
@@ -0,0 +1,41 @@
+/*
+
+ 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;
+
+
+contract MWeth {
+
+ /// @dev Converts message call's ETH value into WETH.
+ function convertEthToWeth()
+ internal;
+
+ /// @dev Transfers feePercentage of WETH spent on primary orders to feeRecipient.
+ /// Refunds any excess ETH to msg.sender.
+ /// @param wethSoldExcludingFeeOrders Amount of WETH sold when filling primary orders.
+ /// @param wethSoldForZrx Amount of WETH sold when purchasing ZRX required for primary order fees.
+ /// @param feePercentage Percentage of WETH sold that will payed as fee to forwarding contract feeRecipient.
+ /// @param feeRecipient Address that will receive ETH when orders are filled.
+ function transferEthFeeAndRefund(
+ uint256 wethSoldExcludingFeeOrders,
+ uint256 wethSoldForZrx,
+ uint256 feePercentage,
+ address feeRecipient
+ )
+ internal;
+}