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/MConstants.sol35
-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.sol92
-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
6 files changed, 320 insertions, 0 deletions
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
new file mode 100644
index 000000000..348bf169e
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
@@ -0,0 +1,35 @@
+/*
+
+ 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/MExpectedResults.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
new file mode 100644
index 000000000..e4645cb61
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
@@ -0,0 +1,42 @@
+/*
+
+ 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);
+} \ No newline at end of file
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
new file mode 100644
index 000000000..2a178915f
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
@@ -0,0 +1,63 @@
+/*
+
+ 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);
+} \ No newline at end of file
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
new file mode 100644
index 000000000..64c0716a1
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
@@ -0,0 +1,92 @@
+/*
+
+ 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";
+import "../interfaces/IForwarderCore.sol";
+
+
+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
+ )
+ 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);
+} \ No newline at end of file
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
new file mode 100644
index 000000000..16ddf20fd
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
@@ -0,0 +1,42 @@
+/*
+
+ 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);
+} \ No newline at end of file
diff --git a/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol b/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
new file mode 100644
index 000000000..5deefac53
--- /dev/null
+++ b/packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.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.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;
+} \ No newline at end of file