Refactor EIP712 libraries
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
||||
import "./libs/LibConstants.sol";
|
||||
import "./libs/LibEIP712CoordinatorDomain.sol";
|
||||
import "./MixinSignatureValidator.sol";
|
||||
import "./MixinCoordinatorApprovalVerifier.sol";
|
||||
import "./MixinCoordinatorCore.sol";
|
||||
@@ -37,6 +39,7 @@ contract Coordinator is
|
||||
constructor (address exchange, uint256 chainId)
|
||||
public
|
||||
LibConstants(exchange)
|
||||
LibEIP712Domain(chainId)
|
||||
LibEIP712CoordinatorDomain(chainId, address(0))
|
||||
LibEIP712ExchangeDomain(chainId, exchange)
|
||||
{}
|
||||
}
|
||||
|
@@ -21,10 +21,10 @@ pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
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 "./libs/LibZeroExTransaction.sol";
|
||||
import "./mixins/MSignatureValidator.sol";
|
||||
import "./mixins/MCoordinatorApprovalVerifier.sol";
|
||||
|
||||
|
@@ -19,7 +19,7 @@
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "./libs/LibZeroExTransaction.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
||||
import "./libs/LibConstants.sol";
|
||||
import "./mixins/MCoordinatorApprovalVerifier.sol";
|
||||
import "./interfaces/ICoordinatorCore.sol";
|
||||
|
@@ -20,7 +20,7 @@ pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
import "../libs/LibZeroExTransaction.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
||||
|
||||
|
||||
contract ICoordinatorApprovalVerifier {
|
||||
|
@@ -19,7 +19,7 @@
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "../libs/LibZeroExTransaction.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
||||
|
||||
|
||||
contract ICoordinatorCore {
|
||||
|
@@ -19,11 +19,11 @@
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "./LibEIP712Domain.sol";
|
||||
import "./LibEIP712CoordinatorDomain.sol";
|
||||
|
||||
|
||||
contract LibCoordinatorApproval is
|
||||
LibEIP712Domain
|
||||
LibEIP712CoordinatorDomain
|
||||
{
|
||||
// Hash for the EIP712 Coordinator approval message
|
||||
// keccak256(abi.encodePacked(
|
||||
|
@@ -18,16 +18,14 @@
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomainConstants.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
||||
import "./LibConstants.sol";
|
||||
|
||||
|
||||
// solhint-disable var-name-mixedcase
|
||||
contract LibEIP712Domain is
|
||||
contract LibEIP712CoordinatorDomain is
|
||||
LibConstants,
|
||||
LibEIP712,
|
||||
LibEIP712ExchangeDomainConstants
|
||||
LibEIP712ExchangeDomain
|
||||
{
|
||||
|
||||
// EIP712 Domain Name value for the Coordinator
|
||||
@@ -43,20 +41,15 @@ contract LibEIP712Domain is
|
||||
bytes32 public EIP712_EXCHANGE_DOMAIN_HASH;
|
||||
|
||||
/// @param chainId Chain ID of the network this contract is deployed on.
|
||||
constructor (uint256 chainId)
|
||||
/// @param verifyingContractAddress Address of the verifying contract (null if the address of this contract)
|
||||
constructor (uint256 chainId, address verifyingContractAddress)
|
||||
public
|
||||
{
|
||||
EIP712_COORDINATOR_DOMAIN_HASH = hashEIP712Domain(
|
||||
EIP712_COORDINATOR_DOMAIN_NAME,
|
||||
EIP712_COORDINATOR_DOMAIN_VERSION,
|
||||
chainId,
|
||||
address(this)
|
||||
);
|
||||
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
|
||||
EIP712_EXCHANGE_DOMAIN_NAME,
|
||||
EIP712_EXCHANGE_DOMAIN_VERSION,
|
||||
chainId,
|
||||
address(EXCHANGE)
|
||||
verifyingContractAddress == address(0) ? address(this) : verifyingContractAddress
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,16 +64,4 @@ contract LibEIP712Domain is
|
||||
{
|
||||
return hashEIP712Message(EIP712_COORDINATOR_DOMAIN_HASH, hashStruct);
|
||||
}
|
||||
|
||||
/// @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);
|
||||
}
|
||||
}
|
@@ -27,10 +27,11 @@
|
||||
"src/LibAbiEncoder.sol",
|
||||
"src/LibAssetProxyErrors.sol",
|
||||
"src/LibConstants.sol",
|
||||
"src/LibEIP712.sol",
|
||||
"src/LibEIP712ExchangeDomain.sol",
|
||||
"src/LibFillResults.sol",
|
||||
"src/LibMath.sol",
|
||||
"src/LibOrder.sol",
|
||||
"src/LibZeroExTransaction.sol",
|
||||
"test/TestLibs.sol"
|
||||
]
|
||||
}
|
||||
|
@@ -18,27 +18,32 @@
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
import "./LibEIP712.sol";
|
||||
import "./LibEIP712ExchangeDomainConstants.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP712.sol";
|
||||
|
||||
|
||||
contract LibEIP712ExchangeDomain is
|
||||
LibEIP712,
|
||||
LibEIP712ExchangeDomainConstants
|
||||
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 internal EIP712_EXCHANGE_DOMAIN_HASH;
|
||||
|
||||
/// @param chainId Chain ID of the network this contract is deployed on.
|
||||
constructor (uint256 chainId)
|
||||
/// @param verifyingContractAddress Address of the verifying contract (null if the address of this contract)
|
||||
constructor (uint256 chainId, address verifyingContractAddress)
|
||||
public
|
||||
{
|
||||
EIP712_EXCHANGE_DOMAIN_HASH = hashEIP712Domain(
|
||||
EIP712_EXCHANGE_DOMAIN_NAME,
|
||||
EIP712_EXCHANGE_DOMAIN_VERSION,
|
||||
chainId,
|
||||
address(this)
|
||||
verifyingContractAddress == address(0) ? address(this) : verifyingContractAddress
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -1,29 +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.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";
|
||||
}
|
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "./LibEIP712ExchangeDomain.sol";
|
||||
|
||||
@@ -81,7 +82,7 @@ contract LibOrder is
|
||||
/// @param order The order structure.
|
||||
/// @return Keccak-256 EIP712 hash of the order.
|
||||
function getOrderHash(Order memory order)
|
||||
internal
|
||||
public
|
||||
view
|
||||
returns (bytes32 orderHash)
|
||||
{
|
||||
|
@@ -19,11 +19,11 @@
|
||||
pragma solidity ^0.5.5;
|
||||
pragma experimental "ABIEncoderV2";
|
||||
|
||||
import "./LibEIP712Domain.sol";
|
||||
import "./LibEIP712ExchangeDomain.sol";
|
||||
|
||||
|
||||
contract LibZeroExTransaction is
|
||||
LibEIP712Domain
|
||||
LibEIP712ExchangeDomain
|
||||
{
|
||||
// Hash for the EIP712 0x transaction schema
|
||||
// keccak256(abi.encodePacked(
|
@@ -36,7 +36,7 @@ contract TestLibs is
|
||||
{
|
||||
constructor (uint256 chainId)
|
||||
public
|
||||
LibEIP712ExchangeDomain(chainId)
|
||||
LibEIP712ExchangeDomain(chainId, address(0))
|
||||
{}
|
||||
|
||||
function publicAbiEncodeFillOrder(
|
||||
|
@@ -34,7 +34,7 @@
|
||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||
},
|
||||
"config": {
|
||||
"abis": "./generated-artifacts/@(LibAbiEncoder|LibAssetProxyErrors|LibConstants|LibEIP712|LibEIP712ExchangeDomainConstants|LibEIP712ExchangeDomain|LibFillResults|LibMath|LibOrder|TestLibs).json",
|
||||
"abis": "./generated-artifacts/@(LibAbiEncoder|LibAssetProxyErrors|LibConstants|LibEIP712ExchangeDomain|LibFillResults|LibMath|LibOrder|LibZeroExTransaction|TestLibs).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
|
@@ -8,18 +8,20 @@ import { ContractArtifact } from 'ethereum-types';
|
||||
import * as LibAbiEncoder from '../generated-artifacts/LibAbiEncoder.json';
|
||||
import * as LibAssetProxyErrors from '../generated-artifacts/LibAssetProxyErrors.json';
|
||||
import * as LibConstants from '../generated-artifacts/LibConstants.json';
|
||||
import * as LibEIP712 from '../generated-artifacts/LibEIP712.json';
|
||||
import * as LibEIP712ExchangeDomain from '../generated-artifacts/LibEIP712ExchangeDomain.json';
|
||||
import * as LibFillResults from '../generated-artifacts/LibFillResults.json';
|
||||
import * as LibMath from '../generated-artifacts/LibMath.json';
|
||||
import * as LibOrder from '../generated-artifacts/LibOrder.json';
|
||||
import * as LibZeroExTransaction from '../generated-artifacts/LibZeroExTransaction.json';
|
||||
import * as TestLibs from '../generated-artifacts/TestLibs.json';
|
||||
export const artifacts = {
|
||||
LibAbiEncoder: LibAbiEncoder as ContractArtifact,
|
||||
LibAssetProxyErrors: LibAssetProxyErrors as ContractArtifact,
|
||||
LibConstants: LibConstants as ContractArtifact,
|
||||
LibEIP712: LibEIP712 as ContractArtifact,
|
||||
LibFillResults: LibFillResults as ContractArtifact,
|
||||
LibMath: LibMath as ContractArtifact,
|
||||
LibOrder: LibOrder as ContractArtifact,
|
||||
LibZeroExTransaction: LibZeroExTransaction as ContractArtifact,
|
||||
LibEIP712ExchangeDomain: LibEIP712ExchangeDomain as ContractArtifact,
|
||||
TestLibs: TestLibs as ContractArtifact,
|
||||
};
|
||||
|
@@ -6,8 +6,9 @@
|
||||
export * from '../generated-wrappers/lib_abi_encoder';
|
||||
export * from '../generated-wrappers/lib_asset_proxy_errors';
|
||||
export * from '../generated-wrappers/lib_constants';
|
||||
export * from '../generated-wrappers/lib_e_i_p712';
|
||||
export * from '../generated-wrappers/lib_e_i_p712_exchange_domain';
|
||||
export * from '../generated-wrappers/lib_fill_results';
|
||||
export * from '../generated-wrappers/lib_math';
|
||||
export * from '../generated-wrappers/lib_order';
|
||||
export * from '../generated-wrappers/lib_zero_ex_transaction';
|
||||
export * from '../generated-wrappers/test_libs';
|
||||
|
@@ -6,10 +6,11 @@
|
||||
"generated-artifacts/LibAbiEncoder.json",
|
||||
"generated-artifacts/LibAssetProxyErrors.json",
|
||||
"generated-artifacts/LibConstants.json",
|
||||
"generated-artifacts/LibEIP712.json",
|
||||
"generated-artifacts/LibEIP712ExchangeDomain.json",
|
||||
"generated-artifacts/LibFillResults.json",
|
||||
"generated-artifacts/LibMath.json",
|
||||
"generated-artifacts/LibOrder.json",
|
||||
"generated-artifacts/LibZeroExTransaction.json",
|
||||
"generated-artifacts/TestLibs.json"
|
||||
],
|
||||
"exclude": ["./deploy/solc/solc_bin"]
|
||||
|
@@ -45,7 +45,7 @@ contract Exchange is
|
||||
constructor (bytes memory zrxAssetData, uint256 chainId)
|
||||
public
|
||||
LibConstants(zrxAssetData) // @TODO: Remove zrxAssetData when we deploy.
|
||||
LibEIP712ExchangeDomain(chainId)
|
||||
LibEIP712ExchangeDomain(chainId, address(0))
|
||||
MixinExchangeCore()
|
||||
MixinMatchOrders()
|
||||
MixinSignatureValidator()
|
||||
|
@@ -18,13 +18,13 @@
|
||||
|
||||
pragma solidity ^0.5.5;
|
||||
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
||||
import "../src/MixinSignatureValidator.sol";
|
||||
import "../src/MixinTransactions.sol";
|
||||
|
||||
|
||||
contract TestSignatureValidator is
|
||||
LibEIP712,
|
||||
LibEIP712ExchangeDomain,
|
||||
MixinSignatureValidator,
|
||||
MixinTransactions
|
||||
{
|
||||
@@ -32,7 +32,7 @@ contract TestSignatureValidator is
|
||||
// solhint-disable no-empty-blocks
|
||||
constructor (uint256 chainId)
|
||||
public
|
||||
LibEIP712ExchangeDomain(chainId)
|
||||
LibEIP712ExchangeDomain(chainId, address(0))
|
||||
{}
|
||||
|
||||
function publicIsValidSignature(
|
||||
|
@@ -26,6 +26,7 @@
|
||||
"contracts": [
|
||||
"src/Address.sol",
|
||||
"src/LibBytes.sol",
|
||||
"src/LibEIP712.sol",
|
||||
"src/Ownable.sol",
|
||||
"src/ReentrancyGuard.sol",
|
||||
"src/SafeMath.sol",
|
||||
|
@@ -43,7 +43,7 @@ contract LibEIP712 {
|
||||
address verifyingContractAddress
|
||||
)
|
||||
internal
|
||||
view
|
||||
pure
|
||||
returns (bytes32 result)
|
||||
{
|
||||
return keccak256(abi.encodePacked(
|
@@ -34,7 +34,7 @@
|
||||
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
|
||||
},
|
||||
"config": {
|
||||
"abis": "./generated-artifacts/@(Address|IOwnable|LibBytes|Ownable|ReentrancyGuard|SafeMath|TestConstants|TestLibAddressArray|TestLibBytes).json",
|
||||
"abis": "./generated-artifacts/@(Address|IOwnable|LibBytes|LibEIP712|Ownable|ReentrancyGuard|SafeMath|TestConstants|TestLibAddressArray|TestLibBytes).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
|
@@ -8,6 +8,7 @@ import { ContractArtifact } from 'ethereum-types';
|
||||
import * as Address from '../generated-artifacts/Address.json';
|
||||
import * as IOwnable from '../generated-artifacts/IOwnable.json';
|
||||
import * as LibBytes from '../generated-artifacts/LibBytes.json';
|
||||
import * as LibEIP712 from '../generated-artifacts/LibEIP712.json';
|
||||
import * as Ownable from '../generated-artifacts/Ownable.json';
|
||||
import * as ReentrancyGuard from '../generated-artifacts/ReentrancyGuard.json';
|
||||
import * as SafeMath from '../generated-artifacts/SafeMath.json';
|
||||
@@ -20,8 +21,9 @@ export const artifacts = {
|
||||
Ownable: Ownable as ContractArtifact,
|
||||
ReentrancyGuard: ReentrancyGuard as ContractArtifact,
|
||||
SafeMath: SafeMath as ContractArtifact,
|
||||
LibEIP712: LibEIP712 as ContractArtifact,
|
||||
IOwnable: IOwnable as ContractArtifact,
|
||||
TestConstants: TestConstants as ContractArtifact,
|
||||
TestLibBytes: TestLibBytes as ContractArtifact,
|
||||
TestLibAddressArray: TestLibAddressArray as ContractArtifact,
|
||||
TestLibBytes: TestLibBytes as ContractArtifact,
|
||||
};
|
||||
|
@@ -6,6 +6,7 @@
|
||||
export * from '../generated-wrappers/address';
|
||||
export * from '../generated-wrappers/i_ownable';
|
||||
export * from '../generated-wrappers/lib_bytes';
|
||||
export * from '../generated-wrappers/lib_e_i_p712';
|
||||
export * from '../generated-wrappers/ownable';
|
||||
export * from '../generated-wrappers/reentrancy_guard';
|
||||
export * from '../generated-wrappers/safe_math';
|
||||
|
@@ -6,6 +6,7 @@
|
||||
"generated-artifacts/Address.json",
|
||||
"generated-artifacts/IOwnable.json",
|
||||
"generated-artifacts/LibBytes.json",
|
||||
"generated-artifacts/LibEIP712.json",
|
||||
"generated-artifacts/Ownable.json",
|
||||
"generated-artifacts/ReentrancyGuard.json",
|
||||
"generated-artifacts/SafeMath.json",
|
||||
|
Reference in New Issue
Block a user