Add interfaces and mixins
This commit is contained in:
@@ -22,14 +22,19 @@ pragma experimental ABIEncoderV2;
|
||||
import "./MixinFees.sol";
|
||||
import "./MixinForwarderCore.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "./MixinMarketBuyZrx.sol";
|
||||
import "./MixinExpectedResults.sol";
|
||||
import "./MixinTransfer.sol";
|
||||
import "../utils/Ownable/Ownable.sol";
|
||||
|
||||
|
||||
contract Forwarder is
|
||||
Ownable,
|
||||
MixinConstants,
|
||||
MixinExpectedResults,
|
||||
MixinFees,
|
||||
MixinMarketBuyZrx,
|
||||
MixinTransfer,
|
||||
MixinForwarderCore
|
||||
{
|
||||
uint256 constant internal MAX_UINT = 2**256 - 1;
|
||||
|
@@ -18,20 +18,12 @@
|
||||
|
||||
pragma solidity 0.4.24;
|
||||
|
||||
import "../protocol/Exchange/interfaces/IExchange.sol";
|
||||
import "../tokens/EtherToken/IEtherToken.sol";
|
||||
import "../tokens/ERC20Token/IERC20Token.sol";
|
||||
import "./mixins/MConstants.sol";
|
||||
|
||||
|
||||
contract MixinConstants {
|
||||
|
||||
// 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
|
||||
contract MixinConstants is
|
||||
MConstants
|
||||
{
|
||||
|
||||
constructor (
|
||||
address _exchange,
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -19,12 +19,14 @@
|
||||
pragma solidity 0.4.24;
|
||||
|
||||
import "../protocol/Exchange/libs/LibMath.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "./mixins/MConstants.sol";
|
||||
import "./mixins/MFees.sol";
|
||||
|
||||
|
||||
contract MixinFees is
|
||||
LibMath,
|
||||
MixinConstants
|
||||
MConstants,
|
||||
MFees
|
||||
{
|
||||
|
||||
uint16 constant public PERCENTAGE_DENOMINATOR = 10000; // 9800 == 98%, 10000 == 100%
|
||||
|
@@ -20,20 +20,24 @@ pragma solidity 0.4.24;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../utils/LibBytes/LibBytes.sol";
|
||||
import "./MixinFees.sol";
|
||||
import "./MixinMarketBuyZrx.sol";
|
||||
import "./MixinExpectedResults.sol";
|
||||
import "./MixinTransfer.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "./mixins/MFees.sol";
|
||||
import "./mixins/MMarketBuyZrx.sol";
|
||||
import "./mixins/MExpectedResults.sol";
|
||||
import "./mixins/MTransfer.sol";
|
||||
import "./mixins/MConstants.sol";
|
||||
import "./mixins/MForwarderCore.sol";
|
||||
import "../protocol/Exchange/libs/LibOrder.sol";
|
||||
import "../protocol/Exchange/libs/LibFillResults.sol";
|
||||
|
||||
|
||||
contract MixinForwarderCore is
|
||||
MixinConstants,
|
||||
MixinExpectedResults,
|
||||
MixinFees,
|
||||
MixinMarketBuyZrx,
|
||||
MixinTransfer
|
||||
LibFillResults,
|
||||
MConstants,
|
||||
MExpectedResults,
|
||||
MFees,
|
||||
MMarketBuyZrx,
|
||||
MTransfer,
|
||||
MForwarderCore
|
||||
{
|
||||
bytes4 public constant ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
|
||||
bytes4 public constant ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256,bytes)"));
|
||||
@@ -284,8 +288,8 @@ contract MixinForwarderCore is
|
||||
bytes[] memory feeSignatures,
|
||||
uint256 makerTokenFillAmount
|
||||
)
|
||||
private
|
||||
returns (FillResults memory totalFillResults)
|
||||
internal
|
||||
returns (LibFillResults.FillResults memory totalFillResults)
|
||||
{
|
||||
// We read the maker token address to check if it is ZRX and later use it for transfer
|
||||
address makerTokenAddress = LibBytes.readAddress(orders[0].makerAssetData, 16);
|
||||
@@ -366,8 +370,8 @@ contract MixinForwarderCore is
|
||||
LibOrder.Order[] memory feeOrders,
|
||||
bytes[] memory feeSignatures
|
||||
)
|
||||
private
|
||||
returns (FillResults memory totalFillResults)
|
||||
internal
|
||||
returns (LibFillResults.FillResults memory totalFillResults)
|
||||
{
|
||||
uint256 totalZrxFeeAmount;
|
||||
uint256 ordersLength = orders.length;
|
||||
|
@@ -19,17 +19,18 @@
|
||||
pragma solidity 0.4.24;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../protocol/Exchange/Exchange.sol";
|
||||
import "../protocol/Exchange/libs/LibFillResults.sol";
|
||||
import "../protocol/Exchange/libs/LibOrder.sol";
|
||||
import "../protocol/Exchange/libs/LibMath.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "./mixins/MConstants.sol";
|
||||
import "./mixins/MMarketBuyZrx.sol";
|
||||
|
||||
|
||||
contract MixinMarketBuyZrx is
|
||||
LibMath,
|
||||
LibFillResults,
|
||||
MixinConstants
|
||||
MConstants,
|
||||
MMarketBuyZrx
|
||||
{
|
||||
|
||||
/// @dev Buys zrxBuyAmount of ZRX fee tokens, taking into account the fees on buying fee tokens. This will guarantee
|
||||
|
@@ -17,13 +17,15 @@
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.24;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../utils/LibBytes/LibBytes.sol";
|
||||
import "../tokens/ERC721Token/IERC721Token.sol";
|
||||
import "./mixins/MTransfer.sol";
|
||||
|
||||
|
||||
contract MixinTransfer {
|
||||
contract MixinTransfer is
|
||||
MTransfer
|
||||
{
|
||||
|
||||
using LibBytes for bytes;
|
||||
|
||||
@@ -31,7 +33,11 @@ contract MixinTransfer {
|
||||
bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,uint256,bytes)"));
|
||||
bytes4 constant internal ERC721_RECEIVED_OPERATOR = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
|
||||
|
||||
function onERC721Received(address, uint256, bytes memory)
|
||||
function onERC721Received(
|
||||
address,
|
||||
uint256,
|
||||
bytes memory
|
||||
)
|
||||
public
|
||||
pure
|
||||
returns(bytes4)
|
||||
@@ -39,7 +45,12 @@ contract MixinTransfer {
|
||||
return ERC721_RECEIVED;
|
||||
}
|
||||
|
||||
function onERC721Received(address, address, uint256, bytes memory)
|
||||
function onERC721Received(
|
||||
address,
|
||||
address,
|
||||
uint256,
|
||||
bytes memory
|
||||
)
|
||||
public
|
||||
pure
|
||||
returns(bytes4)
|
||||
|
66
packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol
vendored
Normal file
66
packages/contracts/src/2.0.0/forwarder/interfaces/IExpectedResults.sol
vendored
Normal file
@@ -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);
|
||||
}
|
30
packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol
vendored
Normal file
30
packages/contracts/src/2.0.0/forwarder/interfaces/IForwarder.sol
vendored
Normal file
@@ -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
|
||||
{}
|
79
packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol
vendored
Normal file
79
packages/contracts/src/2.0.0/forwarder/interfaces/IForwarderCore.sol
vendored
Normal file
@@ -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);
|
||||
}
|
35
packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
vendored
Normal file
35
packages/contracts/src/2.0.0/forwarder/mixins/MConstants.sol
vendored
Normal file
@@ -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
|
||||
}
|
42
packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
vendored
Normal file
42
packages/contracts/src/2.0.0/forwarder/mixins/MExpectedResults.sol
vendored
Normal file
@@ -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);
|
||||
}
|
63
packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
vendored
Normal file
63
packages/contracts/src/2.0.0/forwarder/mixins/MFees.sol
vendored
Normal file
@@ -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);
|
||||
}
|
92
packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
vendored
Normal file
92
packages/contracts/src/2.0.0/forwarder/mixins/MForwarderCore.sol
vendored
Normal file
@@ -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);
|
||||
}
|
42
packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
vendored
Normal file
42
packages/contracts/src/2.0.0/forwarder/mixins/MMarketBuyZrx.sol
vendored
Normal file
@@ -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);
|
||||
}
|
46
packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
vendored
Normal file
46
packages/contracts/src/2.0.0/forwarder/mixins/MTransfer.sol
vendored
Normal 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.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;
|
||||
}
|
Reference in New Issue
Block a user