Unpin @0x/contracts-exchange dependency in /contracts/coordinator.

Split up EIP712 constants and functionality in `/contracts/exchange-libs` across 3, modular contracts.
Make coordinator inherit from the modular EIP712 contracts in `@0x\contracts-exchange`.
This commit is contained in:
Lawrence Forman 2019-03-22 15:43:17 -04:00 committed by Amir Bandeali
parent 7aaef5d807
commit 74a9a13564
6 changed files with 102 additions and 44 deletions

View File

@ -19,24 +19,29 @@
pragma solidity ^0.5.5; pragma solidity ^0.5.5;
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomainConstants.sol";
import "./LibConstants.sol"; import "./LibConstants.sol";
// solhint-disable var-name-mixedcase // solhint-disable var-name-mixedcase
contract LibEIP712Domain is contract LibEIP712Domain is
LibConstants, LibConstants,
LibEIP712 LibEIP712,
LibEIP712ExchangeDomainConstants
{ {
// EIP712 Domain Name value for the Coordinator // EIP712 Domain Name value for the Coordinator
string constant internal EIP712_COORDINATOR_DOMAIN_NAME = "0x Protocol Coordinator"; string constant internal EIP712_COORDINATOR_DOMAIN_NAME = "0x Protocol Coordinator";
// EIP712 Domain Version value for the Coordinator // EIP712 Domain Version value for the Coordinator
string constant internal EIP712_COORDINATOR_DOMAIN_VERSION = "1.0.0"; string constant internal EIP712_COORDINATOR_DOMAIN_VERSION = "2.0.0";
// Hash of the EIP712 Domain Separator data for the Coordinator // Hash of the EIP712 Domain Separator data for the Coordinator
bytes32 public EIP712_COORDINATOR_DOMAIN_HASH; bytes32 public EIP712_COORDINATOR_DOMAIN_HASH;
// Hash of the EIP712 Domain Separator data for the Exchange
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
constructor () constructor ()
public public
{ {
@ -45,6 +50,11 @@ contract LibEIP712Domain is
EIP712_COORDINATOR_DOMAIN_VERSION, EIP712_COORDINATOR_DOMAIN_VERSION,
address(this) address(this)
); );
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
EIP712_EXCHANGE_DOMAIN_NAME,
EIP712_EXCHANGE_DOMAIN_VERSION,
address(this)
);
} }
/// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain /// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain

View File

@ -31,17 +31,6 @@ contract LibEIP712 {
")" ")"
)); ));
// EIP712 Exchange Domain Name value
string constant internal EIP712_EXCHANGE_DOMAIN_NAME = "0x Protocol";
// EIP712 Exchange Domain Version value
string constant internal EIP712_EXCHANGE_DOMAIN_VERSION = "3.0.0";
// Hash of the EIP712 Domain Separator data
// solhint-disable-next-line var-name-mixedcase
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
// Chain ID of the network this contract is deployed on. // Chain ID of the network this contract is deployed on.
// solhint-disable-next-line var-name-mixedcase // solhint-disable-next-line var-name-mixedcase
uint256 internal CHAIN_ID; uint256 internal CHAIN_ID;
@ -51,11 +40,6 @@ contract LibEIP712 {
public public
{ {
CHAIN_ID = chainId; CHAIN_ID = chainId;
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
EIP712_EXCHANGE_DOMAIN_NAME,
EIP712_EXCHANGE_DOMAIN_VERSION,
address(this)
);
} }
/// @dev Calculates a EIP712 domain separator. /// @dev Calculates a EIP712 domain separator.

View File

@ -0,0 +1,55 @@
/*
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.5;
import "./LibEIP712.sol";
import "./LibEIP712ExchangeDomainConstants.sol";
contract LibEIP712ExchangeDomain is
LibEIP712,
LibEIP712ExchangeDomainConstants
{
// Hash of the EIP712 Domain Separator data
// solhint-disable-next-line var-name-mixedcase
bytes32 internal EIP712_EXCHANGE_DOMAIN_HASH;
constructor ()
public
{
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
EIP712_EXCHANGE_DOMAIN_NAME,
EIP712_EXCHANGE_DOMAIN_VERSION,
address(this)
);
}
/// @dev Calculates EIP712 encoding for a hash struct in the EIP712 domain
/// of the Exchange contract.
/// @param hashStruct The EIP712 hash struct.
/// @return EIP712 hash applied to the Exchange EIP712 Domain.
function hashEIP712ExchangeMessage(bytes32 hashStruct)
internal
view
returns (bytes32 result)
{
return hashEIP712Message(EIP712_EXCHANGE_DOMAIN_HASH, hashStruct);
}
}

View File

@ -0,0 +1,29 @@
/*
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.5;
contract LibEIP712ExchangeDomainConstants {
// EIP712 Exchange Domain Name value
string constant internal EIP712_EXCHANGE_DOMAIN_NAME = "0x Protocol";
// EIP712 Exchange Domain Version value
string constant internal EIP712_EXCHANGE_DOMAIN_VERSION = "3.0.0";
}

View File

@ -18,11 +18,11 @@
pragma solidity ^0.5.5; pragma solidity ^0.5.5;
import "./LibEIP712.sol"; import "./LibEIP712ExchangeDomain.sol";
contract LibOrder is contract LibOrder is
LibEIP712 LibEIP712ExchangeDomain
{ {
// Hash for the EIP712 Order Schema // Hash for the EIP712 Order Schema
bytes32 constant internal EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked( bytes32 constant internal EIP712_ORDER_SCHEMA_HASH = keccak256(abi.encodePacked(
@ -85,7 +85,7 @@ contract LibOrder is
view view
returns (bytes32 orderHash) returns (bytes32 orderHash)
{ {
orderHash = hashEIP712Message(EIP712_EXCHANGE_DOMAIN_HASH, hashOrder(order)); orderHash = hashEIP712ExchangeMessage(hashOrder(order));
return orderHash; return orderHash;
} }

View File

@ -18,28 +18,18 @@
pragma solidity ^0.5.5; pragma solidity ^0.5.5;
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibExchangeErrors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibExchangeErrors.sol";
import "./mixins/MSignatureValidator.sol"; import "./mixins/MSignatureValidator.sol";
import "./mixins/MTransactions.sol"; import "./mixins/MTransactions.sol";
contract MixinTransactions is contract MixinTransactions is
LibEIP712, LibEIP712ExchangeDomain,
MSignatureValidator, MSignatureValidator,
MTransactions MTransactions
{ {
// EIP712 Domain Name value
string constant internal EIP712_DOMAIN_NAME = "0x Protocol";
// EIP712 Domain Version value
string constant internal EIP712_DOMAIN_VERSION = "3.0.0";
// Hash of the EIP712 Domain Separator data
// solhint-disable-next-line var-name-mixedcase
bytes32 public EIP712_DOMAIN_HASH;
// Mapping of transaction hash => executed // Mapping of transaction hash => executed
// This prevents transactions from being executed more than once. // This prevents transactions from being executed more than once.
mapping (bytes32 => bool) public transactions; mapping (bytes32 => bool) public transactions;
@ -47,16 +37,6 @@ contract MixinTransactions is
// Address of current transaction signer // Address of current transaction signer
address public currentContextAddress; address public currentContextAddress;
constructor ()
public
{
EIP712_DOMAIN_HASH = hashEIP712Domain(
EIP712_DOMAIN_NAME,
EIP712_DOMAIN_VERSION,
address(this)
);
}
/// @dev Executes an exchange method call in the context of signer. /// @dev Executes an exchange method call in the context of signer.
/// @param salt Arbitrary number to ensure uniqueness of transaction hash. /// @param salt Arbitrary number to ensure uniqueness of transaction hash.
/// @param signerAddress Address of transaction signer. /// @param signerAddress Address of transaction signer.
@ -77,7 +57,7 @@ contract MixinTransactions is
); );
bytes32 transactionHash = hashEIP712Message( bytes32 transactionHash = hashEIP712Message(
EIP712_DOMAIN_HASH, EIP712_EXCHANGE_DOMAIN_HASH,
hashZeroExTransaction( hashZeroExTransaction(
salt, salt,
signerAddress, signerAddress,