From 9ef55023f2edd73e82152a0abf1120275006db77 Mon Sep 17 00:00:00 2001 From: James Towle Date: Wed, 5 Jun 2019 15:57:15 -0700 Subject: [PATCH] Removed all mixins/ directories from the repository --- .../src/MixinAssetProxyDispatcher.sol | 10 +- .../contracts/src/MixinAuthorizable.sol | 16 +- .../src/mixins/MAssetProxyDispatcher.sol | 45 ---- .../contracts/src/mixins/MAuthorizable.sol | 41 ---- .../src/MixinCoordinatorApprovalVerifier.sol | 8 +- .../contracts/src/MixinCoordinatorCore.sol | 4 +- .../contracts/src/MixinSignatureValidator.sol | 18 +- .../mixins/MCoordinatorApprovalVerifier.sol | 46 ----- .../src/mixins/MSignatureValidator.sol | 35 ---- contracts/erc1155/compiler.json | 1 - .../contracts/src/MixinNonFungibleToken.sol | 6 +- .../src/mixins/MNonFungibleToken.sol | 44 ---- contracts/erc1155/package.json | 2 +- contracts/erc1155/src/artifacts.ts | 6 +- contracts/erc1155/src/wrappers.ts | 1 - contracts/erc1155/tsconfig.json | 1 - contracts/erc20/package.json | 2 +- contracts/erc20/src/artifacts.ts | 2 + contracts/erc20/src/wrappers.ts | 1 + contracts/erc20/tsconfig.json | 1 + .../contracts/src/MixinAssets.sol | 6 +- .../contracts/src/MixinExchangeWrapper.sol | 4 +- .../contracts/src/MixinForwarderCore.sol | 8 +- .../contracts/src/MixinWeth.sol | 2 - .../contracts/src/mixins/MAssets.sol | 53 ----- .../contracts/src/mixins/MExchangeWrapper.sol | 87 -------- .../contracts/src/mixins/MWeth.sol | 41 ---- contracts/exchange/contracts/src/Exchange.sol | 9 +- .../src/MixinAssetProxyDispatcher.sol | 15 +- .../contracts/src/MixinExchangeCore.sol | 88 ++++++-- .../contracts/src/MixinExchangeRichErrors.sol | 106 +++++++++- .../contracts/src/MixinMatchOrders.sol | 63 +++++- .../contracts/src/MixinSignatureValidator.sol | 38 +++- .../contracts/src/MixinTransactions.sol | 14 +- .../contracts/src/MixinWrapperFunctions.sol | 26 ++- .../src/libs/LibExchangeRichErrorDecoder.sol | 102 +++++++-- .../src/mixins/MAssetProxyDispatcher.sol | 47 ----- .../contracts/src/mixins/MExchangeCore.sol | 159 -------------- .../src/mixins/MExchangeRichErrorTypes.sol | 130 ------------ .../src/mixins/MExchangeRichErrors.sol | 194 ------------------ .../contracts/src/mixins/MMatchOrders.sol | 59 ------ .../src/mixins/MSignatureValidator.sol | 65 ------ .../contracts/src/mixins/MTransactions.sol | 52 ----- .../src/mixins/MWrapperFunctions.sol | 41 ---- .../test/TestAssetProxyDispatcher.sol | 4 +- .../contracts/test/TestSignatureValidator.sol | 4 +- .../MixinBalanceThresholdFilterCore.sol | 4 +- .../MixinExchangeCalldata.sol | 5 +- .../mixins/MBalanceThresholdFilterCore.sol | 55 ----- .../mixins/MExchangeCalldata.sol | 57 ----- .../src/OrderMatcher/MixinAssets.sol | 4 +- .../src/OrderMatcher/mixins/MAssets.sol | 71 ------- contracts/utils/contracts/src/RichErrors.sol | 8 +- .../contracts/src/mixins/MRichErrorTypes.sol | 27 --- .../contracts/src/mixins/MRichErrors.sol | 46 ----- 55 files changed, 465 insertions(+), 1519 deletions(-) delete mode 100644 contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol delete mode 100644 contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol delete mode 100644 contracts/coordinator/contracts/src/mixins/MCoordinatorApprovalVerifier.sol delete mode 100644 contracts/coordinator/contracts/src/mixins/MSignatureValidator.sol delete mode 100644 contracts/erc1155/contracts/src/mixins/MNonFungibleToken.sol delete mode 100644 contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol delete mode 100644 contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol delete mode 100644 contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MExchangeCore.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MExchangeRichErrorTypes.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MExchangeRichErrors.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MMatchOrders.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MSignatureValidator.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MTransactions.sol delete mode 100644 contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol delete mode 100644 contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol delete mode 100644 contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol delete mode 100644 contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol delete mode 100644 contracts/utils/contracts/src/mixins/MRichErrorTypes.sol delete mode 100644 contracts/utils/contracts/src/mixins/MRichErrors.sol diff --git a/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol b/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol index ab1afd186f..1396542c27 100644 --- a/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol +++ b/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol @@ -19,14 +19,20 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/Ownable.sol"; -import "./mixins/MAssetProxyDispatcher.sol"; import "./interfaces/IAssetProxy.sol"; +import "./interfaces/IAssetProxyDispatcher.sol"; contract MixinAssetProxyDispatcher is Ownable, - MAssetProxyDispatcher + IAssetProxyDispatcher { + // Logs registration of new asset proxy + event AssetProxyRegistered( + bytes4 id, // Id of new registered AssetProxy. + address assetProxy // Address of new registered AssetProxy. + ); + // Mapping from Asset Proxy Id's to their respective Asset Proxy mapping (bytes4 => address) public assetProxies; diff --git a/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol b/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol index 62b00fc226..6038c18a70 100644 --- a/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol +++ b/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol @@ -19,13 +19,25 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/Ownable.sol"; -import "./mixins/MAuthorizable.sol"; +import "./interfaces/IAuthorizable.sol"; contract MixinAuthorizable is Ownable, - MAuthorizable + IAuthorizable { + // Event logged when a new address is authorized. + event AuthorizedAddressAdded( + address indexed target, + address indexed caller + ); + + // Event logged when a currently authorized address is unauthorized. + event AuthorizedAddressRemoved( + address indexed target, + address indexed caller + ); + /// @dev Only authorized addresses can invoke functions with this modifier. modifier onlyAuthorized { require( diff --git a/contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol b/contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol deleted file mode 100644 index 1e6e8dfbaa..0000000000 --- a/contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol +++ /dev/null @@ -1,45 +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.5.9; - -import "../interfaces/IAssetProxyDispatcher.sol"; - - -contract MAssetProxyDispatcher is - IAssetProxyDispatcher -{ - // Logs registration of new asset proxy - event AssetProxyRegistered( - bytes4 id, // Id of new registered AssetProxy. - address assetProxy // Address of new registered AssetProxy. - ); - - /// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws. - /// @param assetData Byte array encoded for the asset. - /// @param from Address to transfer token from. - /// @param to Address to transfer token to. - /// @param amount Amount of token to transfer. - function _dispatchTransferFrom( - bytes memory assetData, - address from, - address to, - uint256 amount - ) - internal; -} diff --git a/contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol b/contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol deleted file mode 100644 index cf0854af68..0000000000 --- a/contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol +++ /dev/null @@ -1,41 +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.5.9; - -import "../interfaces/IAuthorizable.sol"; - - -contract MAuthorizable is - IAuthorizable -{ - // Event logged when a new address is authorized. - event AuthorizedAddressAdded( - address indexed target, - address indexed caller - ); - - // Event logged when a currently authorized address is unauthorized. - event AuthorizedAddressRemoved( - address indexed target, - address indexed caller - ); - - /// @dev Only authorized addresses can invoke functions with this modifier. - modifier onlyAuthorized { revert(); _; } -} diff --git a/contracts/coordinator/contracts/src/MixinCoordinatorApprovalVerifier.sol b/contracts/coordinator/contracts/src/MixinCoordinatorApprovalVerifier.sol index fb2d4e572e..72664f63a1 100644 --- a/contracts/coordinator/contracts/src/MixinCoordinatorApprovalVerifier.sol +++ b/contracts/coordinator/contracts/src/MixinCoordinatorApprovalVerifier.sol @@ -25,8 +25,8 @@ import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/LibAddressArray.sol"; import "./libs/LibCoordinatorApproval.sol"; -import "./mixins/MSignatureValidator.sol"; -import "./mixins/MCoordinatorApprovalVerifier.sol"; +import "./interfaces/ISignatureValidator.sol"; +import "./interfaces/ICoordinatorApprovalVerifier.sol"; // solhint-disable avoid-tx-origin @@ -34,8 +34,8 @@ contract MixinCoordinatorApprovalVerifier is LibExchangeSelectors, LibCoordinatorApproval, LibZeroExTransaction, - MSignatureValidator, - MCoordinatorApprovalVerifier + ISignatureValidator, + ICoordinatorApprovalVerifier { using LibBytes for bytes; using LibAddressArray for address[]; diff --git a/contracts/coordinator/contracts/src/MixinCoordinatorCore.sol b/contracts/coordinator/contracts/src/MixinCoordinatorCore.sol index b0ae6541ad..76855a3696 100644 --- a/contracts/coordinator/contracts/src/MixinCoordinatorCore.sol +++ b/contracts/coordinator/contracts/src/MixinCoordinatorCore.sol @@ -21,13 +21,13 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; import "./libs/LibConstants.sol"; -import "./mixins/MCoordinatorApprovalVerifier.sol"; import "./interfaces/ICoordinatorCore.sol"; +import "./interfaces/ICoordinatorApprovalVerifier.sol"; contract MixinCoordinatorCore is LibConstants, - MCoordinatorApprovalVerifier, + ICoordinatorApprovalVerifier, ICoordinatorCore { /// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata. diff --git a/contracts/coordinator/contracts/src/MixinSignatureValidator.sol b/contracts/coordinator/contracts/src/MixinSignatureValidator.sol index 5c2ae2ef11..25d2dbef94 100644 --- a/contracts/coordinator/contracts/src/MixinSignatureValidator.sol +++ b/contracts/coordinator/contracts/src/MixinSignatureValidator.sol @@ -19,14 +19,28 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "./mixins/MSignatureValidator.sol"; +import "./interfaces/ISignatureValidator.sol"; contract MixinSignatureValidator is - MSignatureValidator + ISignatureValidator { using LibBytes for bytes; + // Allowed signature types. + enum SignatureType { + Illegal, // 0x00, default value + Invalid, // 0x01 + EIP712, // 0x02 + EthSign, // 0x03 + Wallet, // 0x04 + Validator, // 0x05 + PreSigned, // 0x06 + OrderValidator, // 0x07 + WalletOrderValidator, // 0x08 + NSignatureTypes // 0x09, number of signature types. Always leave at end. + } + /// @dev Recovers the address of a signer given a hash and signature. /// @param hash Any 32 byte hash. /// @param signature Proof that the hash has been signed by signer. diff --git a/contracts/coordinator/contracts/src/mixins/MCoordinatorApprovalVerifier.sol b/contracts/coordinator/contracts/src/mixins/MCoordinatorApprovalVerifier.sol deleted file mode 100644 index 6636e021f9..0000000000 --- a/contracts/coordinator/contracts/src/mixins/MCoordinatorApprovalVerifier.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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "../interfaces/ICoordinatorApprovalVerifier.sol"; - - -contract MCoordinatorApprovalVerifier is - ICoordinatorApprovalVerifier -{ - /// @dev Validates that the feeRecipients of a batch of order have approved a 0x transaction. - /// @param transaction 0x transaction containing salt, signerAddress, and data. - /// @param orders Array of order structs containing order specifications. - /// @param txOrigin Required signer of Ethereum transaction calling this function. - /// @param transactionSignature Proof that the transaction has been signed by the signer. - /// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires. - /// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order. - function _assertValidTransactionOrdersApproval( - LibZeroExTransaction.ZeroExTransaction memory transaction, - LibOrder.Order[] memory orders, - address txOrigin, - bytes memory transactionSignature, - uint256[] memory approvalExpirationTimeSeconds, - bytes[] memory approvalSignatures - ) - internal - view; -} diff --git a/contracts/coordinator/contracts/src/mixins/MSignatureValidator.sol b/contracts/coordinator/contracts/src/mixins/MSignatureValidator.sol deleted file mode 100644 index 8d288f0576..0000000000 --- a/contracts/coordinator/contracts/src/mixins/MSignatureValidator.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.5.9; - -import "../interfaces/ISignatureValidator.sol"; - - -contract MSignatureValidator is - ISignatureValidator -{ - // Allowed signature types. - enum SignatureType { - Illegal, // 0x00, default value - Invalid, // 0x01 - EIP712, // 0x02 - EthSign, // 0x03 - NSignatureTypes // 0x04, number of signature types. Always leave at end. - } -} diff --git a/contracts/erc1155/compiler.json b/contracts/erc1155/compiler.json index ce8ca896b0..1fce0b95f6 100644 --- a/contracts/erc1155/compiler.json +++ b/contracts/erc1155/compiler.json @@ -30,7 +30,6 @@ "src/interfaces/IERC1155.sol", "src/interfaces/IERC1155Mintable.sol", "src/interfaces/IERC1155Receiver.sol", - "src/mixins/MNonFungibleToken.sol", "test/DummyERC1155Receiver.sol" ] } diff --git a/contracts/erc1155/contracts/src/MixinNonFungibleToken.sol b/contracts/erc1155/contracts/src/MixinNonFungibleToken.sol index 216ccdf8c6..b835a17606 100644 --- a/contracts/erc1155/contracts/src/MixinNonFungibleToken.sol +++ b/contracts/erc1155/contracts/src/MixinNonFungibleToken.sol @@ -18,12 +18,8 @@ pragma solidity ^0.5.9; -import "./mixins/MNonFungibleToken.sol"; - -contract MixinNonFungibleToken is - MNonFungibleToken -{ +contract MixinNonFungibleToken { /// Use a split bit implementation. /// Store the type in the upper 128 bits.. uint256 constant internal TYPE_MASK = uint256(uint128(~0)) << 128; diff --git a/contracts/erc1155/contracts/src/mixins/MNonFungibleToken.sol b/contracts/erc1155/contracts/src/mixins/MNonFungibleToken.sol deleted file mode 100644 index edc5f7dc05..0000000000 --- a/contracts/erc1155/contracts/src/mixins/MNonFungibleToken.sol +++ /dev/null @@ -1,44 +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.5.9; - - -contract MNonFungibleToken { - - /// @dev Returns true if token is non-fungible - function isNonFungible(uint256 id) public pure returns(bool); - - /// @dev Returns true if token is fungible - function isFungible(uint256 _d) public pure returns(bool); - - /// @dev Returns index of non-fungible token - function getNonFungibleIndex(uint256 id) public pure returns(uint256); - - /// @dev Returns base type of non-fungible token - function getNonFungibleBaseType(uint256 id) public pure returns(uint256); - - /// @dev Returns true if input is base-type of a non-fungible token - function isNonFungibleBaseType(uint256 id) public pure returns(bool); - - /// @dev Returns true if input is a non-fungible token - function isNonFungibleItem(uint256 id) public pure returns(bool); - - /// @dev returns owner of a non-fungible token - function ownerOf(uint256 id) public view returns (address); -} diff --git a/contracts/erc1155/package.json b/contracts/erc1155/package.json index b3467891b8..5e9d1c9d9d 100644 --- a/contracts/erc1155/package.json +++ b/contracts/erc1155/package.json @@ -34,7 +34,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(DummyERC1155Receiver|ERC1155|ERC1155Mintable|IERC1155|IERC1155Mintable|IERC1155Receiver|MNonFungibleToken|MixinNonFungibleToken).json", + "abis": "./generated-artifacts/@(DummyERC1155Receiver|ERC1155|ERC1155Mintable|IERC1155|IERC1155Mintable|IERC1155Receiver|MixinNonFungibleToken).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/erc1155/src/artifacts.ts b/contracts/erc1155/src/artifacts.ts index 3958d5d9ca..196fb37ef5 100644 --- a/contracts/erc1155/src/artifacts.ts +++ b/contracts/erc1155/src/artifacts.ts @@ -12,14 +12,12 @@ import * as IERC1155 from '../generated-artifacts/IERC1155.json'; import * as IERC1155Mintable from '../generated-artifacts/IERC1155Mintable.json'; import * as IERC1155Receiver from '../generated-artifacts/IERC1155Receiver.json'; import * as MixinNonFungibleToken from '../generated-artifacts/MixinNonFungibleToken.json'; -import * as MNonFungibleToken from '../generated-artifacts/MNonFungibleToken.json'; export const artifacts = { - DummyERC1155Receiver: DummyERC1155Receiver as ContractArtifact, ERC1155: ERC1155 as ContractArtifact, - MNonFungibleToken: MNonFungibleToken as ContractArtifact, ERC1155Mintable: ERC1155Mintable as ContractArtifact, MixinNonFungibleToken: MixinNonFungibleToken as ContractArtifact, + IERC1155: IERC1155 as ContractArtifact, IERC1155Mintable: IERC1155Mintable as ContractArtifact, IERC1155Receiver: IERC1155Receiver as ContractArtifact, - IERC1155: IERC1155 as ContractArtifact, + DummyERC1155Receiver: DummyERC1155Receiver as ContractArtifact, }; diff --git a/contracts/erc1155/src/wrappers.ts b/contracts/erc1155/src/wrappers.ts index fad5514a49..b7819dfce1 100644 --- a/contracts/erc1155/src/wrappers.ts +++ b/contracts/erc1155/src/wrappers.ts @@ -9,5 +9,4 @@ export * from '../generated-wrappers/erc1155_mintable'; export * from '../generated-wrappers/i_erc1155_mintable'; export * from '../generated-wrappers/i_erc1155_receiver'; export * from '../generated-wrappers/ierc1155'; -export * from '../generated-wrappers/m_non_fungible_token'; export * from '../generated-wrappers/mixin_non_fungible_token'; diff --git a/contracts/erc1155/tsconfig.json b/contracts/erc1155/tsconfig.json index 04206336be..bfa8deee96 100644 --- a/contracts/erc1155/tsconfig.json +++ b/contracts/erc1155/tsconfig.json @@ -9,7 +9,6 @@ "generated-artifacts/IERC1155.json", "generated-artifacts/IERC1155Mintable.json", "generated-artifacts/IERC1155Receiver.json", - "generated-artifacts/MNonFungibleToken.json", "generated-artifacts/MixinNonFungibleToken.json" ], "exclude": ["./deploy/solc/solc_bin"] diff --git a/contracts/erc20/package.json b/contracts/erc20/package.json index 17b1999cf5..7137b8f95b 100644 --- a/contracts/erc20/package.json +++ b/contracts/erc20/package.json @@ -34,7 +34,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "./generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ERC20Token|IERC20Token|IEtherToken|MintableERC20Token|UnlimitedAllowanceERC20Token|WETH9|ZRXToken).json", + "abis": "./generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ERC20Token|IERC20Token|IEtherToken|MintableERC20Token|UnlimitedAllowanceERC20Token|UntransferrableDummyERC20Token|WETH9|ZRXToken).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/erc20/src/artifacts.ts b/contracts/erc20/src/artifacts.ts index c63fc8e0dc..6d0e08c3a7 100644 --- a/contracts/erc20/src/artifacts.ts +++ b/contracts/erc20/src/artifacts.ts @@ -13,6 +13,7 @@ import * as IERC20Token from '../generated-artifacts/IERC20Token.json'; import * as IEtherToken from '../generated-artifacts/IEtherToken.json'; import * as MintableERC20Token from '../generated-artifacts/MintableERC20Token.json'; import * as UnlimitedAllowanceERC20Token from '../generated-artifacts/UnlimitedAllowanceERC20Token.json'; +import * as UntransferrableDummyERC20Token from '../generated-artifacts/UntransferrableDummyERC20Token.json'; import * as WETH9 from '../generated-artifacts/WETH9.json'; import * as ZRXToken from '../generated-artifacts/ZRXToken.json'; export const artifacts = { @@ -26,4 +27,5 @@ export const artifacts = { DummyERC20Token: DummyERC20Token as ContractArtifact, DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact, DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact, + UntransferrableDummyERC20Token: UntransferrableDummyERC20Token as ContractArtifact, }; diff --git a/contracts/erc20/src/wrappers.ts b/contracts/erc20/src/wrappers.ts index 3a85ee3d2b..9a921ccfbd 100644 --- a/contracts/erc20/src/wrappers.ts +++ b/contracts/erc20/src/wrappers.ts @@ -11,5 +11,6 @@ export * from '../generated-wrappers/i_erc20_token'; export * from '../generated-wrappers/i_ether_token'; export * from '../generated-wrappers/mintable_erc20_token'; export * from '../generated-wrappers/unlimited_allowance_erc20_token'; +export * from '../generated-wrappers/untransferrable_dummy_erc20_token'; export * from '../generated-wrappers/weth9'; export * from '../generated-wrappers/zrx_token'; diff --git a/contracts/erc20/tsconfig.json b/contracts/erc20/tsconfig.json index 51e9e504dc..26a14799e4 100644 --- a/contracts/erc20/tsconfig.json +++ b/contracts/erc20/tsconfig.json @@ -11,6 +11,7 @@ "generated-artifacts/IEtherToken.json", "generated-artifacts/MintableERC20Token.json", "generated-artifacts/UnlimitedAllowanceERC20Token.json", + "generated-artifacts/UntransferrableDummyERC20Token.json", "generated-artifacts/WETH9.json", "generated-artifacts/ZRXToken.json" ], diff --git a/contracts/exchange-forwarder/contracts/src/MixinAssets.sol b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol index 0839d05a5a..616ca10367 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinAssets.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol @@ -23,13 +23,13 @@ import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; import "@0x/contracts-erc721/contracts/src/interfaces/IERC721Token.sol"; import "./libs/LibConstants.sol"; -import "./mixins/MAssets.sol"; +import "./interfaces/IAssets.sol"; contract MixinAssets is Ownable, - LibConstants, - MAssets + LibConstants + IAssets, { using LibBytes for bytes; diff --git a/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol index 58204fe917..92e62fec09 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol @@ -20,7 +20,6 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; import "./libs/LibConstants.sol"; -import "./mixins/MExchangeWrapper.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; @@ -31,8 +30,7 @@ contract MixinExchangeWrapper is LibFillResults, LibMath, LibConstants, - LibExchangeSelectors, - MExchangeWrapper + LibExchangeSelectors { /// @dev Fills the input order. /// Returns false if the transaction would otherwise revert. diff --git a/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol index 296242029e..19d47b6f34 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol @@ -20,9 +20,7 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; import "./libs/LibConstants.sol"; -import "./mixins/MWeth.sol"; -import "./mixins/MAssets.sol"; -import "./mixins/MExchangeWrapper.sol"; +import "./interfaces/IAsserts.sol"; import "./interfaces/IForwarderCore.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; @@ -34,9 +32,7 @@ contract MixinForwarderCore is LibFillResults, LibMath, LibConstants, - MWeth, - MAssets, - MExchangeWrapper, + IAsserts, IForwarderCore { using LibBytes for bytes; diff --git a/contracts/exchange-forwarder/contracts/src/MixinWeth.sol b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol index c8ea98e2b3..0b4d9b218f 100644 --- a/contracts/exchange-forwarder/contracts/src/MixinWeth.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol @@ -20,13 +20,11 @@ pragma solidity ^0.5.9; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "./libs/LibConstants.sol"; -import "./mixins/MWeth.sol"; contract MixinWeth is LibMath, LibConstants, - MWeth { /// @dev Default payabale function, this allows us to withdraw WETH function () diff --git a/contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol b/contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol deleted file mode 100644 index e8087a015f..0000000000 --- a/contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol +++ /dev/null @@ -1,53 +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.5.9; - -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 _transferAssetToSender( - 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/contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol b/contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol deleted file mode 100644 index 3c6683ac83..0000000000 --- a/contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol +++ /dev/null @@ -1,87 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "@0x/contracts-exchange-libs/contracts/src/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 _marketBuyExactAmountWithWeth( - 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 _marketBuyExactZrxWithWeth( - LibOrder.Order[] memory orders, - uint256 zrxBuyAmount, - bytes[] memory signatures - ) - internal - returns (LibFillResults.FillResults memory totalFillResults); -} diff --git a/contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol b/contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol deleted file mode 100644 index b62eacb479..0000000000 --- a/contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol +++ /dev/null @@ -1,41 +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.5.9; - - -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 payable feeRecipient - ) - internal; -} diff --git a/contracts/exchange/contracts/src/Exchange.sol b/contracts/exchange/contracts/src/Exchange.sol index 07f53be62c..1f59474372 100644 --- a/contracts/exchange/contracts/src/Exchange.sol +++ b/contracts/exchange/contracts/src/Exchange.sol @@ -30,13 +30,12 @@ import "./MixinExchangeRichErrors.sol"; // solhint-disable no-empty-blocks contract Exchange is - MixinExchangeCore, MixinMatchOrders, - MixinSignatureValidator, - MixinTransactions, - MixinAssetProxyDispatcher, MixinWrapperFunctions, - MixinExchangeRichErrors + MixinExchangeCore, + MixinSignatureValidator, + MixinAssetProxyDispatcher, + MixinTransactions { string constant public VERSION = "3.0.0"; diff --git a/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol b/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol index 2c70c1bafe..06e690565e 100644 --- a/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol +++ b/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol @@ -19,16 +19,23 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/Ownable.sol"; -import "./mixins/MAssetProxyDispatcher.sol"; -import "./mixins/MExchangeRichErrors.sol"; +import "@0x/contracts-utils/contracts/src/RichErrors.sol"; import "./interfaces/IAssetProxy.sol"; +import "./interfaces/IAssetProxyDispatcher.sol"; +import "./MixinExchangeRichErrors.sol"; contract MixinAssetProxyDispatcher is + MixinExchangeRichErrors, Ownable, - MAssetProxyDispatcher, - MExchangeRichErrors + IAssetProxyDispatcher { + // Logs registration of new asset proxy + event AssetProxyRegistered( + bytes4 id, // Id of new registered AssetProxy. + address assetProxy // Address of new registered AssetProxy. + ); + // Mapping from Asset Proxy Id's to their respective Asset Proxy mapping (bytes4 => address) public assetProxies; diff --git a/contracts/exchange/contracts/src/MixinExchangeCore.sol b/contracts/exchange/contracts/src/MixinExchangeCore.sol index 8bbc2e87da..72bf8ae6a2 100644 --- a/contracts/exchange/contracts/src/MixinExchangeCore.sol +++ b/contracts/exchange/contracts/src/MixinExchangeCore.sol @@ -25,27 +25,63 @@ import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; -import "./mixins/MExchangeCore.sol"; -import "./mixins/MSignatureValidator.sol"; -import "./mixins/MTransactions.sol"; -import "./mixins/MAssetProxyDispatcher.sol"; -import "./mixins/MExchangeRichErrors.sol"; +import "./interfaces/IAssetProxyDispatcher.sol"; +import "./interfaces/IExchangeCore.sol"; +import "./interfaces/ISignatureValidator.sol"; +import "./interfaces/ITransactions.sol"; +import "./MixinAssetProxyDispatcher.sol"; +import "./MixinExchangeRichErrors.sol"; +import "./MixinSignatureValidator.sol"; contract MixinExchangeCore is + MixinExchangeRichErrors, ReentrancyGuard, LibExchangeSelectors, LibMath, LibOrder, LibFillResults, - MAssetProxyDispatcher, - MExchangeCore, - MSignatureValidator, - MTransactions, - MExchangeRichErrors + IAssetProxyDispatcher, + IExchangeCore, + ISignatureValidator, + ITransactions { using LibBytes for bytes; + // Fill event is emitted whenever an order is filled. + event Fill( + address indexed makerAddress, // Address that created the order. + address indexed feeRecipientAddress, // Address that received fees. + bytes makerAssetData, // Encoded data specific to makerAsset. + bytes takerAssetData, // Encoded data specific to takerAsset. + bytes makerFeeAssetData, // Encoded data specific to makerFeeAsset. + bytes takerFeeAssetData, // Encoded data specific to takerFeeAsset. + uint256 makerAssetFilledAmount, // Amount of makerAsset sold by maker and bought by taker. + uint256 takerAssetFilledAmount, // Amount of takerAsset sold by taker and bought by maker. + uint256 makerFeePaid, // Amount of makerFeeAssetData paid to feeRecipient by maker. + uint256 takerFeePaid, // Amount of takerFeeAssetData paid to feeRecipient by taker. + address takerAddress, // Address that filled the order. + address senderAddress, // Address that called the Exchange contract (msg.sender). + bytes32 indexed orderHash // EIP712 hash of order (see LibOrder.getOrderHash). + ); + + // Cancel event is emitted whenever an individual order is cancelled. + event Cancel( + address indexed makerAddress, // Address that created the order. + address indexed feeRecipientAddress, // Address that would have recieved fees if order was filled. + address senderAddress, // Address that called the Exchange contract (msg.sender). + bytes32 indexed orderHash, // EIP712 hash of order (see LibOrder.getOrderHash). + bytes makerAssetData, // Encoded data specific to makerAsset. + bytes takerAssetData // Encoded data specific to takerAsset. + ); + + // CancelUpTo event is emitted whenever `cancelOrdersUpTo` is executed succesfully. + event CancelUpTo( + address indexed makerAddress, // Orders cancelled must have been created by this address. + address indexed orderSenderAddress, // Orders cancelled must have a `senderAddress` equal to this address. + uint256 orderEpoch // Orders with specified makerAddress and senderAddress with a salt less than this value are considered cancelled. + ); + // Mapping of orderHash => amount of takerAsset already bought by maker mapping (bytes32 => uint256) public filled; @@ -393,14 +429,14 @@ contract MixinExchangeCore is // Revert if fill amount is invalid // TODO: reconsider necessity for v2.1 if (takerAssetFillAmount == 0) { - _rrevert(FillError(FillErrorCodes.INVALID_TAKER_AMOUNT, orderInfo.orderHash)); + _rrevert(FillError(MixinExchangeRichErrors.FillErrorCodes.INVALID_TAKER_AMOUNT, orderInfo.orderHash)); } // Make sure taker does not pay more than desired amount // NOTE: This assertion should never fail, it is here // as an extra defence against potential bugs. if (takerAssetFilledAmount > takerAssetFillAmount) { - _rrevert(FillError(FillErrorCodes.TAKER_OVERPAY, orderInfo.orderHash)); + _rrevert(FillError(MixinExchangeRichErrors.FillErrorCodes.TAKER_OVERPAY, orderInfo.orderHash)); } // Make sure order is not overfilled @@ -408,7 +444,7 @@ contract MixinExchangeCore is // as an extra defence against potential bugs. if (_safeAdd(orderInfo.orderTakerAssetFilledAmount, takerAssetFilledAmount) > order.takerAssetAmount) { - _rrevert(FillError(FillErrorCodes.OVERFILL, orderInfo.orderHash)); + _rrevert(FillError(MixinExchangeRichErrors.FillErrorCodes.OVERFILL, orderInfo.orderHash)); } // Make sure order is filled at acceptable price. @@ -430,7 +466,7 @@ contract MixinExchangeCore is // as an extra defence against potential bugs. if (_safeMul(makerAssetFilledAmount, order.takerAssetAmount) > _safeMul(order.makerAssetAmount, takerAssetFilledAmount)) { - _rrevert(FillError(FillErrorCodes.INVALID_FILL_PRICE, orderInfo.orderHash)); + _rrevert(FillError(MixinExchangeRichErrors.FillErrorCodes.INVALID_FILL_PRICE, orderInfo.orderHash)); } } @@ -500,6 +536,30 @@ contract MixinExchangeCore is return fillResults; } + function _isValidOrderWithHashSignature( + Order memory order, + bytes32 orderHash, + address signerAddress, + bytes memory signature + ) + internal + view + returns (bool isValid); + + function _getCurrentContextAddress() + internal + view + returns (address); + + function _dispatchTransferFrom( + bytes32 orderHash, + bytes memory assetData, + address from, + address to, + uint256 amount + ) + internal; + /// @dev Settles an order by transferring assets between counterparties. /// @param orderHash The order hash. /// @param order Order struct containing order specifications. diff --git a/contracts/exchange/contracts/src/MixinExchangeRichErrors.sol b/contracts/exchange/contracts/src/MixinExchangeRichErrors.sol index 7c8f6db69d..811ce7f330 100644 --- a/contracts/exchange/contracts/src/MixinExchangeRichErrors.sol +++ b/contracts/exchange/contracts/src/MixinExchangeRichErrors.sol @@ -20,13 +20,113 @@ pragma solidity ^0.5.9; import "@0x/contracts-utils/contracts/src/RichErrors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "./mixins/MExchangeRichErrors.sol"; contract MixinExchangeRichErrors is - RichErrors, - MExchangeRichErrors + RichErrors { + enum AssetProxyDispatchErrorCodes { + INVALID_ASSET_DATA_LENGTH, + UNKNOWN_ASSET_PROXY + } + + enum FillErrorCodes { + INVALID_TAKER_AMOUNT, + TAKER_OVERPAY, + OVERFILL, + INVALID_FILL_PRICE + } + + enum SignatureErrorCodes { + BAD_SIGNATURE, + INVALID_LENGTH, + UNSUPPORTED, + ILLEGAL, + INAPPROPRIATE_SIGNATURE_TYPE + } + + enum TransactionErrorCodes { + NO_REENTRANCY, + ALREADY_EXECUTED, + EXPIRED + } + + // bytes4(keccak256("SignatureError(uint8,bytes32,address,bytes)")) + bytes4 internal constant SIGNATURE_ERROR_SELECTOR = + 0x7e5a2318; + + // bytes4(keccak256("SignatureValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_VALIDATOR_ERROR_SELECTOR = + 0x169fad8c; + + // bytes4(keccak256("SignatureWalletError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_WALLET_ERROR_SELECTOR = + 0x1b8388f7; + + // bytes4(keccak256("SignatureOrderValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_ORDER_VALIDATOR_ERROR_SELECTOR = + 0xfabf4577; + + // bytes4(keccak256("SignatureWalletOrderValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_WALLET_ORDER_VALIDATOR_ERROR_SELECTOR = + 0xa85f3360; + + // bytes4(keccak256("OrderStatusError(bytes32,uint8)")) + bytes4 internal constant ORDER_STATUS_ERROR_SELECTOR = + 0xfdb6ca8d; + + // bytes4(keccak256("InvalidSenderError(bytes32,address)")) + bytes4 internal constant INVALID_SENDER_ERROR_SELECTOR = + 0x95b59997; + + // bytes4(keccak256("InvalidMakerError(bytes32,address)")) + bytes4 internal constant INVALID_MAKER_ERROR_SELECTOR = + 0x26bf55d9; + + // bytes4(keccak256("FillError(uint8,bytes32)")) + bytes4 internal constant FILL_ERROR_SELECTOR = + 0xe94a7ed0; + + // bytes4(keccak256("InvalidTakerError(bytes32,address)")) + bytes4 internal constant INVALID_TAKER_ERROR_SELECTOR = + 0xfdb328be; + + // bytes4(keccak256("OrderEpochError(address,address,uint256)")) + bytes4 internal constant ORDER_EPOCH_ERROR_SELECTOR = + 0x4ad31275; + + // bytes4(keccak256("AssetProxyExistsError(address)")) + bytes4 internal constant ASSET_PROXY_EXISTS_ERROR_SELECTOR = + 0xcc8b3b53; + + // bytes4(keccak256("AssetProxyDispatchError(uint8,bytes32,bytes)")) + bytes4 internal constant ASSET_PROXY_DISPATCH_ERROR_SELECTOR = + 0x488219a6; + + // bytes4(keccak256("AssetProxyTransferError(bytes32,bytes,bytes)")) + bytes4 internal constant ASSET_PROXY_TRANSFER_ERROR_SELECTOR = + 0x4678472b; + + // bytes4(keccak256("NegativeSpreadError(bytes32,bytes32)")) + bytes4 internal constant NEGATIVE_SPREAD_ERROR_SELECTOR = + 0xb6555d6f; + + // bytes4(keccak256("TransactionError(uint8,bytes32)")) + bytes4 internal constant TRANSACTION_ERROR_SELECTOR = + 0xf5985184; + + // bytes4(keccak256("TransactionSignatureError(bytes32,address,bytes)")) + bytes4 internal constant TRANSACTION_SIGNATURE_ERROR_SELECTOR = + 0xbfd56ef6; + + // bytes4(keccak256("TransactionExecutionError(bytes32,bytes)")) + bytes4 internal constant TRANSACTION_EXECUTION_ERROR_SELECTOR = + 0x20d11f61; + + // bytes4(keccak256("IncompleteFillError(bytes32)")) + bytes4 internal constant INCOMPLETE_FILL_ERROR_SELECTOR = + 0x152aa60e; + // solhint-disable func-name-mixedcase function SignatureError( SignatureErrorCodes errorCode, diff --git a/contracts/exchange/contracts/src/MixinMatchOrders.sol b/contracts/exchange/contracts/src/MixinMatchOrders.sol index 6dd2b97fa6..07c379e204 100644 --- a/contracts/exchange/contracts/src/MixinMatchOrders.sol +++ b/contracts/exchange/contracts/src/MixinMatchOrders.sol @@ -15,26 +15,27 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/src/RichErrors.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; -import "./mixins/MExchangeCore.sol"; -import "./mixins/MMatchOrders.sol"; -import "./mixins/MTransactions.sol"; -import "./mixins/MAssetProxyDispatcher.sol"; -import "./mixins/MExchangeRichErrors.sol"; +import "./interfaces/IAssetProxyDispatcher.sol"; +import "./interfaces/IExchangeCore.sol"; +import "./interfaces/IMatchOrders.sol"; +import "./interfaces/ITransactions.sol"; +import "./MixinExchangeRichErrors.sol"; contract MixinMatchOrders is + MixinExchangeRichErrors, ReentrancyGuard, LibMath, LibOrder, - MAssetProxyDispatcher, - MExchangeCore, - MMatchOrders, - MTransactions, - MExchangeRichErrors + IAssetProxyDispatcher, + IExchangeCore, + IMatchOrders, + ITransactions { using LibBytes for bytes; @@ -267,6 +268,48 @@ contract MixinMatchOrders is return matchedFillResults; } + function _dispatchTransferFrom( + bytes32 orderHash, + bytes memory assetData, + address from, + address to, + uint256 amount + ) + internal; + + function _getCurrentContextAddress() + internal + view + returns (address); + + function _assertFillableOrder( + Order memory order, + OrderInfo memory orderInfo, + address takerAddress, + bytes memory signature + ) + internal + view; + + function _updateFilledState( + Order memory order, + address takerAddress, + bytes32 orderHash, + uint256 orderTakerAssetFilledAmount, + LibFillResults.FillResults memory fillResults + ) + internal; + + function _assertValidFill( + Order memory order, + OrderInfo memory orderInfo, + uint256 takerAssetFillAmount, // TODO: use FillResults + uint256 takerAssetFilledAmount, + uint256 makerAssetFilledAmount + ) + internal + view; + /// @dev Settles matched order by transferring appropriate funds between order makers, taker, and fee recipient. /// @param leftOrderHash First matched order hash. /// @param rightOrderHash Second matched order hash. diff --git a/contracts/exchange/contracts/src/MixinSignatureValidator.sol b/contracts/exchange/contracts/src/MixinSignatureValidator.sol index 43c3430090..85193beb48 100644 --- a/contracts/exchange/contracts/src/MixinSignatureValidator.sol +++ b/contracts/exchange/contracts/src/MixinSignatureValidator.sol @@ -21,24 +21,45 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/src/RichErrors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "./mixins/MSignatureValidator.sol"; -import "./mixins/MTransactions.sol"; -import "./mixins/MExchangeRichErrors.sol"; import "./interfaces/IWallet.sol"; import "./interfaces/IValidator.sol"; import "./interfaces/IOrderValidator.sol"; +import "./interfaces/ISignatureValidator.sol"; +import "./interfaces/ITransactions.sol"; +import "./MixinExchangeRichErrors.sol"; contract MixinSignatureValidator is + MixinExchangeRichErrors, ReentrancyGuard, LibOrder, - MSignatureValidator, - MTransactions, - MExchangeRichErrors + ISignatureValidator, + ITransactions { using LibBytes for bytes; + // Allowed signature types. + enum SignatureType { + Illegal, // 0x00, default value + Invalid, // 0x01 + EIP712, // 0x02 + EthSign, // 0x03 + Wallet, // 0x04 + Validator, // 0x05 + PreSigned, // 0x06 + OrderValidator, // 0x07 + WalletOrderValidator, // 0x08 + NSignatureTypes // 0x09, number of signature types. Always leave at end. + } + + event SignatureValidatorApproval( + address indexed signerAddress, // Address that approves or disapproves a contract to verify signatures. + address indexed validatorAddress, // Address of signature validator contract. + bool approved // Approval or disapproval of validator contract. + ); + // Mapping of hash => signer => signed mapping (bytes32 => mapping (address => bool)) public preSigned; @@ -210,6 +231,11 @@ contract MixinSignatureValidator is ); } + function _getCurrentContextAddress() + internal + view + returns (address); + /// Reads the `SignatureType` from the end of a signature and validates it. function _readValidSignatureType( bytes32 hash, diff --git a/contracts/exchange/contracts/src/MixinTransactions.sol b/contracts/exchange/contracts/src/MixinTransactions.sol index fdb8000e00..dee053b3bd 100644 --- a/contracts/exchange/contracts/src/MixinTransactions.sol +++ b/contracts/exchange/contracts/src/MixinTransactions.sol @@ -20,17 +20,19 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; -import "./mixins/MSignatureValidator.sol"; -import "./mixins/MTransactions.sol"; -import "./mixins/MExchangeRichErrors.sol"; +import "./interfaces/ISignatureValidator.sol"; +import "./interfaces/ITransactions.sol"; +import "./MixinExchangeRichErrors.sol"; contract MixinTransactions is + MixinExchangeRichErrors, LibZeroExTransaction, - MSignatureValidator, - MTransactions, - MExchangeRichErrors + ISignatureValidator, + ITransactions { + // TransactionExecution event is emitted when a ZeroExTransaction is executed. + event TransactionExecution(bytes32 indexed transactionHash); // Mapping of transaction hash => executed // This prevents transactions from being executed more than once. diff --git a/contracts/exchange/contracts/src/MixinWrapperFunctions.sol b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol index 9a2367d754..4b4d104e2a 100644 --- a/contracts/exchange/contracts/src/MixinWrapperFunctions.sol +++ b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol @@ -20,23 +20,24 @@ pragma solidity ^0.5.9; pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/src/RichErrors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; -import "./mixins/MExchangeCore.sol"; -import "./mixins/MWrapperFunctions.sol"; -import "./mixins/MExchangeRichErrors.sol"; +import "./interfaces/IExchangeCore.sol"; +import "./interfaces/IWrapperFunctions.sol"; +import "./MixinExchangeRichErrors.sol"; contract MixinWrapperFunctions is + MixinExchangeRichErrors, ReentrancyGuard, LibExchangeSelectors, LibMath, LibFillResults, - MExchangeCore, - MWrapperFunctions, - MExchangeRichErrors + IExchangeCore, + IWrapperFunctions { /// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled. /// @param order Order struct containing order specifications. @@ -451,4 +452,17 @@ contract MixinWrapperFunctions is } return fillResults; } + + function _fillOrder( + LibOrder.Order memory order, + uint256 takerAssetFillAmount, + bytes memory signature + ) + internal + returns (FillResults memory fillResults); + + /// @dev After calling, the order can not be filled anymore. + /// @param order Order struct containing order specifications. + function _cancelOrder(LibOrder.Order memory order) + internal; } diff --git a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol index 8ab9863c5b..08643515ab 100644 --- a/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol +++ b/contracts/exchange/contracts/src/libs/LibExchangeRichErrorDecoder.sol @@ -18,13 +18,91 @@ pragma solidity ^0.5.9; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; -import "../mixins/MExchangeRichErrorTypes.sol"; +import "../MixinAssetProxyDispatcher.sol"; +import "../MixinExchangeRichErrors.sol"; +import "../MixinSignatureValidator.sol"; +import "../MixinTransactions.sol"; -contract LibExchangeRichErrorDecoder is - MExchangeRichErrorTypes -{ +contract LibExchangeRichErrorDecoder { + // bytes4(keccak256("SignatureError(uint8,bytes32,address,bytes)")) + bytes4 internal constant SIGNATURE_ERROR_SELECTOR = + 0x7e5a2318; + + // bytes4(keccak256("SignatureValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_VALIDATOR_ERROR_SELECTOR = + 0x169fad8c; + + // bytes4(keccak256("SignatureWalletError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_WALLET_ERROR_SELECTOR = + 0x1b8388f7; + + // bytes4(keccak256("SignatureOrderValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_ORDER_VALIDATOR_ERROR_SELECTOR = + 0xfabf4577; + + // bytes4(keccak256("SignatureWalletOrderValidatorError(bytes32,address,bytes,bytes)")) + bytes4 internal constant SIGNATURE_WALLET_ORDER_VALIDATOR_ERROR_SELECTOR = + 0xa85f3360; + + // bytes4(keccak256("OrderStatusError(bytes32,uint8)")) + bytes4 internal constant ORDER_STATUS_ERROR_SELECTOR = + 0xfdb6ca8d; + + // bytes4(keccak256("InvalidSenderError(bytes32,address)")) + bytes4 internal constant INVALID_SENDER_ERROR_SELECTOR = + 0x95b59997; + + // bytes4(keccak256("InvalidMakerError(bytes32,address)")) + bytes4 internal constant INVALID_MAKER_ERROR_SELECTOR = + 0x26bf55d9; + + // bytes4(keccak256("FillError(uint8,bytes32)")) + bytes4 internal constant FILL_ERROR_SELECTOR = + 0xe94a7ed0; + + // bytes4(keccak256("InvalidTakerError(bytes32,address)")) + bytes4 internal constant INVALID_TAKER_ERROR_SELECTOR = + 0xfdb328be; + + // bytes4(keccak256("OrderEpochError(address,address,uint256)")) + bytes4 internal constant ORDER_EPOCH_ERROR_SELECTOR = + 0x4ad31275; + + // bytes4(keccak256("AssetProxyExistsError(address)")) + bytes4 internal constant ASSET_PROXY_EXISTS_ERROR_SELECTOR = + 0xcc8b3b53; + + // bytes4(keccak256("AssetProxyDispatchError(uint8,bytes32,bytes)")) + bytes4 internal constant ASSET_PROXY_DISPATCH_ERROR_SELECTOR = + 0x488219a6; + + // bytes4(keccak256("AssetProxyTransferError(bytes32,bytes,bytes)")) + bytes4 internal constant ASSET_PROXY_TRANSFER_ERROR_SELECTOR = + 0x4678472b; + + // bytes4(keccak256("NegativeSpreadError(bytes32,bytes32)")) + bytes4 internal constant NEGATIVE_SPREAD_ERROR_SELECTOR = + 0xb6555d6f; + + // bytes4(keccak256("TransactionError(uint8,bytes32)")) + bytes4 internal constant TRANSACTION_ERROR_SELECTOR = + 0xf5985184; + + // bytes4(keccak256("TransactionSignatureError(bytes32,address,bytes)")) + bytes4 internal constant TRANSACTION_SIGNATURE_ERROR_SELECTOR = + 0xbfd56ef6; + + // bytes4(keccak256("TransactionExecutionError(bytes32,bytes)")) + bytes4 internal constant TRANSACTION_EXECUTION_ERROR_SELECTOR = + 0x20d11f61; + + // bytes4(keccak256("IncompleteFillError(bytes32)")) + bytes4 internal constant INCOMPLETE_FILL_ERROR_SELECTOR = + 0x152aa60e; + /// @dev Decompose an ABI-encoded SignatureError. /// @param encoded ABI-encoded revert error. /// @return errorCode The error code. @@ -34,14 +112,14 @@ contract LibExchangeRichErrorDecoder is public pure returns ( - SignatureErrorCodes errorCode, + MixinExchangeRichErrors.SignatureErrorCodes errorCode, bytes32 hash, address signerAddress, bytes memory signature ) { _assertSelectorBytes(encoded, SIGNATURE_ERROR_SELECTOR); - errorCode = SignatureErrorCodes(_readErrorParameterAsUint256(encoded, 0)); + errorCode = MixinExchangeRichErrors.SignatureErrorCodes(_readErrorParameterAsUint256(encoded, 0)); hash = _readErrorParameterAsBytes32(encoded, 1); signerAddress = _readErrorParameterAsAddress(encoded, 2); signature = _readErrorParameterAsBytes(encoded, 3); @@ -214,12 +292,12 @@ contract LibExchangeRichErrorDecoder is public pure returns ( - FillErrorCodes errorCode, + MixinExchangeRichErrors.FillErrorCodes errorCode, bytes32 orderHash ) { _assertSelectorBytes(encoded, FILL_ERROR_SELECTOR); - errorCode = FillErrorCodes(_readErrorParameterAsUint256(encoded, 0)); + errorCode = MixinExchangeRichErrors.FillErrorCodes(_readErrorParameterAsUint256(encoded, 0)); orderHash = _readErrorParameterAsBytes32(encoded, 1); } @@ -264,13 +342,13 @@ contract LibExchangeRichErrorDecoder is public pure returns ( - AssetProxyDispatchErrorCodes errorCode, + MixinExchangeRichErrors.AssetProxyDispatchErrorCodes errorCode, bytes32 orderHash, bytes memory assetData ) { _assertSelectorBytes(encoded, ASSET_PROXY_DISPATCH_ERROR_SELECTOR); - errorCode = AssetProxyDispatchErrorCodes(_readErrorParameterAsUint256(encoded, 0)); + errorCode = MixinExchangeRichErrors.AssetProxyDispatchErrorCodes(_readErrorParameterAsUint256(encoded, 0)); orderHash = _readErrorParameterAsBytes32(encoded, 1); assetData = _readErrorParameterAsBytes(encoded, 2); } @@ -320,12 +398,12 @@ contract LibExchangeRichErrorDecoder is public pure returns ( - TransactionErrorCodes errorCode, + MixinExchangeRichErrors.TransactionErrorCodes errorCode, bytes32 transactionHash ) { _assertSelectorBytes(encoded, TRANSACTION_ERROR_SELECTOR); - errorCode = TransactionErrorCodes(_readErrorParameterAsUint256(encoded, 0)); + errorCode = MixinExchangeRichErrors.TransactionErrorCodes(_readErrorParameterAsUint256(encoded, 0)); transactionHash = _readErrorParameterAsBytes32(encoded, 1); } diff --git a/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol b/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol deleted file mode 100644 index a3cd93b869..0000000000 --- a/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol +++ /dev/null @@ -1,47 +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.5.9; - -import "../interfaces/IAssetProxyDispatcher.sol"; - - -contract MAssetProxyDispatcher is - IAssetProxyDispatcher -{ - // Logs registration of new asset proxy - event AssetProxyRegistered( - bytes4 id, // Id of new registered AssetProxy. - address assetProxy // Address of new registered AssetProxy. - ); - - /// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws. - /// @param orderHash Hash of the order associated with this transfer. - /// @param assetData Byte array encoded for the asset. - /// @param from Address to transfer token from. - /// @param to Address to transfer token to. - /// @param amount Amount of token to transfer. - function _dispatchTransferFrom( - bytes32 orderHash, - bytes memory assetData, - address from, - address to, - uint256 amount - ) - internal; -} diff --git a/contracts/exchange/contracts/src/mixins/MExchangeCore.sol b/contracts/exchange/contracts/src/mixins/MExchangeCore.sol deleted file mode 100644 index 0d4d698c95..0000000000 --- a/contracts/exchange/contracts/src/mixins/MExchangeCore.sol +++ /dev/null @@ -1,159 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; -import "../interfaces/IExchangeCore.sol"; - - -contract MExchangeCore is - IExchangeCore -{ - // Fill event is emitted whenever an order is filled. - event Fill( - address indexed makerAddress, // Address that created the order. - address indexed feeRecipientAddress, // Address that received fees. - bytes makerAssetData, // Encoded data specific to makerAsset. - bytes takerAssetData, // Encoded data specific to takerAsset. - bytes makerFeeAssetData, // Encoded data specific to makerFeeAsset. - bytes takerFeeAssetData, // Encoded data specific to takerFeeAsset. - uint256 makerAssetFilledAmount, // Amount of makerAsset sold by maker and bought by taker. - uint256 takerAssetFilledAmount, // Amount of takerAsset sold by taker and bought by maker. - uint256 makerFeePaid, // Amount of makerFeeAssetData paid to feeRecipient by maker. - uint256 takerFeePaid, // Amount of takerFeeAssetData paid to feeRecipient by taker. - address takerAddress, // Address that filled the order. - address senderAddress, // Address that called the Exchange contract (msg.sender). - bytes32 indexed orderHash // EIP712 hash of order (see LibOrder.getOrderHash). - ); - - // Cancel event is emitted whenever an individual order is cancelled. - event Cancel( - address indexed makerAddress, // Address that created the order. - address indexed feeRecipientAddress, // Address that would have recieved fees if order was filled. - address senderAddress, // Address that called the Exchange contract (msg.sender). - bytes32 indexed orderHash, // EIP712 hash of order (see LibOrder.getOrderHash). - bytes makerAssetData, // Encoded data specific to makerAsset. - bytes takerAssetData // Encoded data specific to takerAsset. - ); - - // CancelUpTo event is emitted whenever `cancelOrdersUpTo` is executed succesfully. - event CancelUpTo( - address indexed makerAddress, // Orders cancelled must have been created by this address. - address indexed orderSenderAddress, // Orders cancelled must have a `senderAddress` equal to this address. - uint256 orderEpoch // Orders with specified makerAddress and senderAddress with a salt less than this value are considered cancelled. - ); - - /// @dev Fills the input order. - /// @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 _fillOrder( - LibOrder.Order memory order, - uint256 takerAssetFillAmount, - bytes memory signature - ) - internal - returns (LibFillResults.FillResults memory fillResults); - - /// @dev After calling, the order can not be filled anymore. - /// @param order Order struct containing order specifications. - function _cancelOrder(LibOrder.Order memory order) - internal; - - /// @dev Updates state with results of a fill order. - /// @param order that was filled. - /// @param takerAddress Address of taker who filled the order. - /// @param orderTakerAssetFilledAmount Amount of order already filled. - /// @return fillResults Amounts filled and fees paid by maker and taker. - function _updateFilledState( - LibOrder.Order memory order, - address takerAddress, - bytes32 orderHash, - uint256 orderTakerAssetFilledAmount, - LibFillResults.FillResults memory fillResults - ) - internal; - - /// @dev Updates state with results of cancelling an order. - /// State is only updated if the order is currently fillable. - /// Otherwise, updating state would have no effect. - /// @param order that was cancelled. - /// @param orderHash Hash of order that was cancelled. - function _updateCancelledState( - LibOrder.Order memory order, - bytes32 orderHash - ) - internal; - - /// @dev Validates context for fillOrder. Succeeds or throws. - /// @param order to be filled. - /// @param orderInfo OrderStatus, orderHash, and amount already filled of order. - /// @param takerAddress Address of order taker. - /// @param signature Proof that the orders was created by its maker. - function _assertFillableOrder( - LibOrder.Order memory order, - LibOrder.OrderInfo memory orderInfo, - address takerAddress, - bytes memory signature - ) - internal - view; - - /// @dev Validates context for fillOrder. Succeeds or throws. - /// @param order to be filled. - /// @param orderInfo Status, orderHash, and amount already filled of order. - /// @param takerAssetFillAmount Desired amount of order to fill by taker. - /// @param takerAssetFilledAmount Amount of takerAsset that will be filled. - /// @param makerAssetFilledAmount Amount of makerAsset that will be transfered. - function _assertValidFill( - LibOrder.Order memory order, - LibOrder.OrderInfo memory orderInfo, - uint256 takerAssetFillAmount, - uint256 takerAssetFilledAmount, - uint256 makerAssetFilledAmount - ) - internal - view; - - /// @dev Validates context for cancelOrder. Succeeds or throws. - /// @param order to be cancelled. - /// @param orderInfo OrderStatus, orderHash, and amount already filled of order. - function _assertValidCancel( - LibOrder.Order memory order, - LibOrder.OrderInfo memory orderInfo - ) - internal - view; - - /// @dev Calculates amounts filled and fees paid by maker and taker. - /// @param order to be filled. - /// @param takerAssetFilledAmount Amount of takerAsset that will be filled. - /// @return fillResults Amounts filled and fees paid by maker and taker. - function _calculateFillResults( - LibOrder.Order memory order, - uint256 takerAssetFilledAmount - ) - internal - pure - returns (LibFillResults.FillResults memory fillResults); - -} diff --git a/contracts/exchange/contracts/src/mixins/MExchangeRichErrorTypes.sol b/contracts/exchange/contracts/src/mixins/MExchangeRichErrorTypes.sol deleted file mode 100644 index 8cd54826e1..0000000000 --- a/contracts/exchange/contracts/src/mixins/MExchangeRichErrorTypes.sol +++ /dev/null @@ -1,130 +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.5.9; - -import "@0x/contracts-utils/contracts/src/mixins/MRichErrorTypes.sol"; -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; - - -contract MExchangeRichErrorTypes is - MRichErrorTypes -{ - enum FillErrorCodes { - INVALID_TAKER_AMOUNT, - TAKER_OVERPAY, - OVERFILL, - INVALID_FILL_PRICE - } - - enum SignatureErrorCodes { - BAD_SIGNATURE, - INVALID_LENGTH, - UNSUPPORTED, - ILLEGAL, - INAPPROPRIATE_SIGNATURE_TYPE - } - - enum AssetProxyDispatchErrorCodes { - INVALID_ASSET_DATA_LENGTH, - UNKNOWN_ASSET_PROXY - } - - enum TransactionErrorCodes { - NO_REENTRANCY, - ALREADY_EXECUTED, - EXPIRED - } - - // bytes4(keccak256("SignatureError(uint8,bytes32,address,bytes)")) - bytes4 internal constant SIGNATURE_ERROR_SELECTOR = - 0x7e5a2318; - - // bytes4(keccak256("SignatureValidatorError(bytes32,address,bytes,bytes)")) - bytes4 internal constant SIGNATURE_VALIDATOR_ERROR_SELECTOR = - 0x169fad8c; - - // bytes4(keccak256("SignatureWalletError(bytes32,address,bytes,bytes)")) - bytes4 internal constant SIGNATURE_WALLET_ERROR_SELECTOR = - 0x1b8388f7; - - // bytes4(keccak256("SignatureOrderValidatorError(bytes32,address,bytes,bytes)")) - bytes4 internal constant SIGNATURE_ORDER_VALIDATOR_ERROR_SELECTOR = - 0xfabf4577; - - // bytes4(keccak256("SignatureWalletOrderValidatorError(bytes32,address,bytes,bytes)")) - bytes4 internal constant SIGNATURE_WALLET_ORDER_VALIDATOR_ERROR_SELECTOR = - 0xa85f3360; - - // bytes4(keccak256("OrderStatusError(bytes32,uint8)")) - bytes4 internal constant ORDER_STATUS_ERROR_SELECTOR = - 0xfdb6ca8d; - - // bytes4(keccak256("InvalidSenderError(bytes32,address)")) - bytes4 internal constant INVALID_SENDER_ERROR_SELECTOR = - 0x95b59997; - - // bytes4(keccak256("InvalidMakerError(bytes32,address)")) - bytes4 internal constant INVALID_MAKER_ERROR_SELECTOR = - 0x26bf55d9; - - // bytes4(keccak256("FillError(uint8,bytes32)")) - bytes4 internal constant FILL_ERROR_SELECTOR = - 0xe94a7ed0; - - // bytes4(keccak256("InvalidTakerError(bytes32,address)")) - bytes4 internal constant INVALID_TAKER_ERROR_SELECTOR = - 0xfdb328be; - - // bytes4(keccak256("OrderEpochError(address,address,uint256)")) - bytes4 internal constant ORDER_EPOCH_ERROR_SELECTOR = - 0x4ad31275; - - // bytes4(keccak256("AssetProxyExistsError(address)")) - bytes4 internal constant ASSET_PROXY_EXISTS_ERROR_SELECTOR = - 0xcc8b3b53; - - // bytes4(keccak256("AssetProxyDispatchError(uint8,bytes32,bytes)")) - bytes4 internal constant ASSET_PROXY_DISPATCH_ERROR_SELECTOR = - 0x488219a6; - - // bytes4(keccak256("AssetProxyTransferError(bytes32,bytes,bytes)")) - bytes4 internal constant ASSET_PROXY_TRANSFER_ERROR_SELECTOR = - 0x4678472b; - - // bytes4(keccak256("NegativeSpreadError(bytes32,bytes32)")) - bytes4 internal constant NEGATIVE_SPREAD_ERROR_SELECTOR = - 0xb6555d6f; - - // bytes4(keccak256("TransactionError(uint8,bytes32)")) - bytes4 internal constant TRANSACTION_ERROR_SELECTOR = - 0xf5985184; - - // bytes4(keccak256("TransactionSignatureError(bytes32,address,bytes)")) - bytes4 internal constant TRANSACTION_SIGNATURE_ERROR_SELECTOR = - 0xbfd56ef6; - - // bytes4(keccak256("TransactionExecutionError(bytes32,bytes)")) - bytes4 internal constant TRANSACTION_EXECUTION_ERROR_SELECTOR = - 0x20d11f61; - - // bytes4(keccak256("IncompleteFillError(bytes32)")) - bytes4 internal constant INCOMPLETE_FILL_ERROR_SELECTOR = - 0x152aa60e; - -} diff --git a/contracts/exchange/contracts/src/mixins/MExchangeRichErrors.sol b/contracts/exchange/contracts/src/mixins/MExchangeRichErrors.sol deleted file mode 100644 index cc6a70bd1a..0000000000 --- a/contracts/exchange/contracts/src/mixins/MExchangeRichErrors.sol +++ /dev/null @@ -1,194 +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.5.9; - -import "@0x/contracts-utils/contracts/src/mixins/MRichErrors.sol"; -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "./MExchangeRichErrorTypes.sol"; - - -contract MExchangeRichErrors is - MExchangeRichErrorTypes, - MRichErrors -{ - // solhint-disable func-name-mixedcase - function SignatureError( - SignatureErrorCodes errorCode, - bytes32 hash, - address signerAddress, - bytes memory signature - ) - internal - pure - returns (bytes memory); - - function SignatureValidatorError( - bytes32 hash, - address signerAddress, - bytes memory signature, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function SignatureWalletError( - bytes32 hash, - address signerAddress, - bytes memory signature, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function SignatureOrderValidatorError( - bytes32 orderHash, - address signerAddress, - bytes memory signature, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function SignatureWalletOrderValidatorError( - bytes32 orderHash, - address wallet, - bytes memory signature, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function OrderStatusError( - bytes32 orderHash, - LibOrder.OrderStatus orderStatus - ) - internal - pure - returns (bytes memory); - - function InvalidSenderError( - bytes32 orderHash, - address senderAddress - ) - internal - pure - returns (bytes memory); - - function InvalidMakerError( - bytes32 orderHash, - address makerAddress - ) - internal - pure - returns (bytes memory); - - function FillError( - FillErrorCodes errorCode, - bytes32 orderHash - ) - internal - pure - returns (bytes memory); - - function InvalidTakerError( - bytes32 orderHash, - address takerAddress - ) - internal - pure - returns (bytes memory); - - function OrderEpochError( - address makerAddress, - address senderAddress, - uint256 currentEpoch - ) - internal - pure - returns (bytes memory); - - function AssetProxyExistsError( - address proxyAddress - ) - internal - pure - returns (bytes memory); - - function AssetProxyDispatchError( - AssetProxyDispatchErrorCodes errorCode, - bytes32 orderHash, - bytes memory assetData - ) - internal - pure - returns (bytes memory); - - function AssetProxyTransferError( - bytes32 orderHash, - bytes memory assetData, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function NegativeSpreadError( - bytes32 leftOrderHash, - bytes32 rightOrderHash - ) - internal - pure - returns (bytes memory); - - function TransactionError( - TransactionErrorCodes errorCode, - bytes32 transactionHash - ) - internal - pure - returns (bytes memory); - - function TransactionSignatureError( - bytes32 transactionHash, - address signerAddress, - bytes memory signature - ) - internal - pure - returns (bytes memory); - - function TransactionExecutionError( - bytes32 transactionHash, - bytes memory errorData - ) - internal - pure - returns (bytes memory); - - function IncompleteFillError( - bytes32 orderHash - ) - internal - pure - returns (bytes memory); -} diff --git a/contracts/exchange/contracts/src/mixins/MMatchOrders.sol b/contracts/exchange/contracts/src/mixins/MMatchOrders.sol deleted file mode 100644 index 5d241bb6b1..0000000000 --- a/contracts/exchange/contracts/src/mixins/MMatchOrders.sol +++ /dev/null @@ -1,59 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; -import "../interfaces/IMatchOrders.sol"; - - -contract MMatchOrders is - IMatchOrders -{ - /// @dev Validates context for matchOrders. Succeeds or throws. - /// @param leftOrder First order to match. - /// @param rightOrder Second order to match. - function _assertValidMatch( - LibOrder.Order memory leftOrder, - LibOrder.Order memory rightOrder - ) - internal - view; - - /// @dev Calculates fill amounts for the matched orders. - /// Each order is filled at their respective price point. However, the calculations are - /// carried out as though the orders are both being filled at the right order's price point. - /// The profit made by the leftOrder order goes to the taker (who matched the two orders). - /// @param leftOrder First order to match. - /// @param rightOrder Second order to match. - /// @param leftOrderTakerAssetFilledAmount Amount of left order already filled. - /// @param rightOrderTakerAssetFilledAmount Amount of right order already filled. - /// @param matchedFillResults Amounts to fill and fees to pay by maker and taker of matched orders. - function _calculateMatchedFillResults( - LibOrder.Order memory leftOrder, - LibOrder.Order memory rightOrder, - uint256 leftOrderTakerAssetFilledAmount, - uint256 rightOrderTakerAssetFilledAmount - ) - internal - pure - returns (LibFillResults.MatchedFillResults memory matchedFillResults); - -} diff --git a/contracts/exchange/contracts/src/mixins/MSignatureValidator.sol b/contracts/exchange/contracts/src/mixins/MSignatureValidator.sol deleted file mode 100644 index 87eea1e12a..0000000000 --- a/contracts/exchange/contracts/src/mixins/MSignatureValidator.sol +++ /dev/null @@ -1,65 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "../interfaces/ISignatureValidator.sol"; - - -contract MSignatureValidator is - ISignatureValidator -{ - event SignatureValidatorApproval( - address indexed signerAddress, // Address that approves or disapproves a contract to verify signatures. - address indexed validatorAddress, // Address of signature validator contract. - bool approved // Approval or disapproval of validator contract. - ); - - // Allowed signature types. - enum SignatureType { - Illegal, // 0x00, default value - Invalid, // 0x01 - EIP712, // 0x02 - EthSign, // 0x03 - Wallet, // 0x04 - Validator, // 0x05 - PreSigned, // 0x06 - OrderValidator, // 0x07 - WalletOrderValidator, // 0x08 - NSignatureTypes // 0x09, number of signature types. Always leave at end. - } - - /// @dev Verifies that an order, with provided order hash, has been signed - /// by the given signer. - /// @param order The order. - /// @param orderHash The hash of the order. - /// @param signerAddress Address that should have signed the.Signat given hash. - /// @param signature Proof that the hash has been signed by signer. - /// @return True if the signature is valid for the given hash and signer. - function _isValidOrderWithHashSignature( - LibOrder.Order memory order, - bytes32 orderHash, - address signerAddress, - bytes memory signature - ) - internal - view - returns (bool isValid); -} diff --git a/contracts/exchange/contracts/src/mixins/MTransactions.sol b/contracts/exchange/contracts/src/mixins/MTransactions.sol deleted file mode 100644 index b3e17e3df3..0000000000 --- a/contracts/exchange/contracts/src/mixins/MTransactions.sol +++ /dev/null @@ -1,52 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; -import "../interfaces/ITransactions.sol"; - - -contract MTransactions is - ITransactions -{ - // TransactionExecution event is emitted when a ZeroExTransaction is executed. - event TransactionExecution(bytes32 indexed transactionHash); - - /// @dev Executes an Exchange method call in the context of signer. - /// @param transaction 0x transaction containing salt, signerAddress, and data. - /// @param signature Proof that transaction has been signed by signer. - /// @return ABI encoded return data of the underlying Exchange function call. - function _executeTransaction( - LibZeroExTransaction.ZeroExTransaction memory transaction, - bytes memory signature - ) - internal - returns (bytes memory); - - /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`). - /// If calling a fill function, this address will represent the taker. - /// If calling a cancel function, this address will represent the maker. - /// @return Signer of 0x transaction if entry point is `executeTransaction`. - /// `msg.sender` if entry point is any other function. - function _getCurrentContextAddress() - internal - view - returns (address); -} diff --git a/contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol b/contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol deleted file mode 100644 index 2875a82900..0000000000 --- a/contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol +++ /dev/null @@ -1,41 +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.5.9; -pragma experimental ABIEncoderV2; - -import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; -import "../interfaces/IWrapperFunctions.sol"; - - -contract MWrapperFunctions is - IWrapperFunctions -{ - /// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled. - /// @param order LibOrder.Order struct containing order specifications. - /// @param takerAssetFillAmount Desired amount of takerAsset to sell. - /// @param signature Proof that order has been created by maker. - function _fillOrKillOrder( - LibOrder.Order memory order, - uint256 takerAssetFillAmount, - bytes memory signature - ) - internal - returns (LibFillResults.FillResults memory fillResults); -} diff --git a/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol b/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol index b61a03b759..989e41a722 100644 --- a/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol +++ b/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol @@ -19,12 +19,10 @@ pragma solidity ^0.5.5; import "../src/MixinAssetProxyDispatcher.sol"; -import "../src/MixinExchangeRichErrors.sol"; contract TestAssetProxyDispatcher is - MixinAssetProxyDispatcher, - MixinExchangeRichErrors + MixinAssetProxyDispatcher { function dispatchTransferFrom( bytes32 orderHash, diff --git a/contracts/exchange/contracts/test/TestSignatureValidator.sol b/contracts/exchange/contracts/test/TestSignatureValidator.sol index 5959708924..0ab6b7169c 100644 --- a/contracts/exchange/contracts/test/TestSignatureValidator.sol +++ b/contracts/exchange/contracts/test/TestSignatureValidator.sol @@ -22,14 +22,12 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol"; import "../src/MixinSignatureValidator.sol"; import "../src/MixinTransactions.sol"; -import "../src/MixinExchangeRichErrors.sol"; contract TestSignatureValidator is LibEIP712ExchangeDomain, MixinSignatureValidator, - MixinTransactions, - MixinExchangeRichErrors + MixinTransactions { // solhint-disable no-empty-blocks diff --git a/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol index e4d577a6dc..7c7712307f 100644 --- a/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol @@ -21,12 +21,12 @@ pragma experimental ABIEncoderV2; import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol"; -import "./mixins/MBalanceThresholdFilterCore.sol"; import "./MixinExchangeCalldata.sol"; +import "./interfaces/IBalanceThresholdFilterCore.sol"; contract MixinBalanceThresholdFilterCore is - MBalanceThresholdFilterCore, + IBalanceThresholdFilterCore, MixinExchangeCalldata, LibExchangeSelectors { diff --git a/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol index 78bc1de305..175fc66f17 100644 --- a/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol @@ -19,13 +19,10 @@ pragma solidity ^0.5.9; -import "./mixins/MExchangeCalldata.sol"; import "@0x/contracts-utils/contracts/src/LibAddressArray.sol"; -contract MixinExchangeCalldata is - MExchangeCalldata -{ +contract MixinExchangeCalldata { using LibAddressArray for address[]; diff --git a/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol deleted file mode 100644 index 08c1f07cde..0000000000 --- a/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol +++ /dev/null @@ -1,55 +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.5.9; - -import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; -import "../interfaces/IThresholdAsset.sol"; -import "../interfaces/IBalanceThresholdFilterCore.sol"; - - -contract MBalanceThresholdFilterCore is - IBalanceThresholdFilterCore -{ - - // Points to 0x exchange contract - // solhint-disable var-name-mixedcase - IExchange internal EXCHANGE; - - // The asset that must be held by makers/takers - IThresholdAsset internal THRESHOLD_ASSET; - - // The minimum balance of `THRESHOLD_ASSET` that must be held by makers/takers - uint256 internal BALANCE_THRESHOLD; - // solhint-enable var-name-mixedcase - - // Addresses that hold at least `BALANCE_THRESHOLD` of `THRESHOLD_ASSET` - event ValidatedAddresses ( - address[] addresses - ); - - /// @dev Constructs an array of addresses to be validated. - /// Addresses depend on which Exchange function is to be called - /// (defined by `signedExchangeTransaction` above). - /// @param signerAddress Address of transaction signer. - /// @return addressesToValidate Array of addresses to validate. - function _getAddressesToValidate(address signerAddress) - internal - pure - returns (address[] memory addressesToValidate); -} diff --git a/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol deleted file mode 100644 index 273d2ffe80..0000000000 --- a/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol +++ /dev/null @@ -1,57 +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/LICENSE2.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.5.9; - - -contract MExchangeCalldata { - - /// @dev Emulates the `calldataload` opcode on the embedded Exchange calldata, - /// which is accessed through `signedExchangeTransaction`. - /// @param offset Offset into the Exchange calldata. - /// @return value Corresponding 32 byte value stored at `offset`. - function _exchangeCalldataload(uint256 offset) - internal pure - returns (bytes32 value); - - /// @dev Convenience function that skips the 4 byte selector when loading - /// from the embedded Exchange calldata. - /// @param offset Offset into the Exchange calldata (minus the 4 byte selector) - /// @return value Corresponding 32 byte value stored at `offset` + 4. - function _loadExchangeData(uint256 offset) - internal pure - returns (bytes32 value); - - /// @dev Extracts the maker address from an order stored in the Exchange calldata - /// (which is embedded in `signedExchangeTransaction`). - /// @param orderParamIndex Index of the order in the Exchange function's signature. - /// @return makerAddress The extracted maker address. - function _loadMakerAddressFromOrder(uint256 orderParamIndex) - internal pure - returns (address makerAddress); - - /// @dev Extracts the maker addresses from an array of orders stored in the Exchange calldata - /// (which is embedded in `signedExchangeTransaction`). - /// @param orderArrayParamIndex Index of the order array in the Exchange function's signature - /// @return makerAddresses The extracted maker addresses. - function _loadMakerAddressesFromOrderArray(uint256 orderArrayParamIndex) - internal - pure - returns (address[] memory makerAddresses); -} diff --git a/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol b/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol index c296c87c89..c4f154a45e 100644 --- a/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol @@ -22,12 +22,12 @@ import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; import "@0x/contracts-erc721/contracts/src/interfaces/IERC721Token.sol"; -import "./mixins/MAssets.sol"; import "./libs/LibConstants.sol"; +import "./interfaces/IAssets.sol"; contract MixinAssets is - MAssets, + IAssets, Ownable, LibConstants { diff --git a/contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol b/contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol deleted file mode 100644 index 51820fca62..0000000000 --- a/contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol +++ /dev/null @@ -1,71 +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.5.9; - -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 _transferAssetToSender( - 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; - - /// @dev Sets approval for ERC20 AssetProxy. - /// @param assetData Byte array encoded for the respective asset proxy. - /// @param amount Amount of asset to approve for respective proxy. - function _approveERC20Token( - bytes memory assetData, - uint256 amount - ) - internal; - - /// @dev Sets approval for ERC721 AssetProxy. - /// @param assetData Byte array encoded for the respective asset proxy. - /// @param amount Amount of asset to approve for respective proxy. - function _approveERC721Token( - bytes memory assetData, - uint256 amount - ) - internal; -} diff --git a/contracts/utils/contracts/src/RichErrors.sol b/contracts/utils/contracts/src/RichErrors.sol index a02c8b78c0..5dcb4439a1 100644 --- a/contracts/utils/contracts/src/RichErrors.sol +++ b/contracts/utils/contracts/src/RichErrors.sol @@ -18,12 +18,12 @@ pragma solidity ^0.5.9; -import "./mixins/MRichErrors.sol"; +contract RichErrors { + // bytes4(keccak256("Error(string)")) + bytes4 internal constant STANDARD_ERROR_SELECTOR = + 0x08c379a0; -contract RichErrors is - MRichErrors -{ // solhint-disable func-name-mixedcase /// @dev ABI encode a standard, string revert error payload. /// This is the same payload that would be included by a `revert(string)` diff --git a/contracts/utils/contracts/src/mixins/MRichErrorTypes.sol b/contracts/utils/contracts/src/mixins/MRichErrorTypes.sol deleted file mode 100644 index 7db945b91d..0000000000 --- a/contracts/utils/contracts/src/mixins/MRichErrorTypes.sol +++ /dev/null @@ -1,27 +0,0 @@ -/* - - Copyright 2019 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.5.9; - - -contract MRichErrorTypes { - // bytes4(keccak256("Error(string)")) - bytes4 internal constant STANDARD_ERROR_SELECTOR = - 0x08c379a0; - -} diff --git a/contracts/utils/contracts/src/mixins/MRichErrors.sol b/contracts/utils/contracts/src/mixins/MRichErrors.sol deleted file mode 100644 index 6eb42bb6be..0000000000 --- a/contracts/utils/contracts/src/mixins/MRichErrors.sol +++ /dev/null @@ -1,46 +0,0 @@ -/* - - Copyright 2019 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.5.9; - -import "./MRichErrorTypes.sol"; - - -contract MRichErrors is - MRichErrorTypes -{ - // solhint-disable func-name-mixedcase - - /// @dev ABI encode a standard, string revert error payload. - /// This is the same payload that would be included by a `revert(string)` - /// solidity statement. It has the function signature `Error(string)`. - /// @param message The error string. - /// @return The ABI encoded error. - function StandardError( - string memory message - ) - internal - pure - returns (bytes memory); - - /// @dev Reverts an encoded rich revert reason `errorData`. - /// @param errorData ABI encoded error data. - function _rrevert(bytes memory errorData) - internal - pure; -}