Convert LibOrder and LibZeroExTransaction to libraries
This commit is contained in:
parent
74a5c8c23c
commit
f45014f75b
@ -19,12 +19,13 @@
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./LibEIP712ExchangeDomain.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP712.sol";
|
||||
|
||||
|
||||
contract LibOrder is
|
||||
LibEIP712ExchangeDomain
|
||||
{
|
||||
library LibOrder {
|
||||
|
||||
using LibOrder for Order;
|
||||
|
||||
// Hash for the EIP712 Order Schema:
|
||||
// keccak256(abi.encodePacked(
|
||||
// "Order(",
|
||||
@ -44,7 +45,7 @@ contract LibOrder is
|
||||
// "bytes takerFeeAssetData",
|
||||
// ")"
|
||||
// ))
|
||||
bytes32 constant public EIP712_ORDER_SCHEMA_HASH =
|
||||
bytes32 constant internal _EIP712_ORDER_SCHEMA_HASH =
|
||||
0xf80322eb8376aafb64eadf8f0d7623f22130fd9491a221e902b713cb984a7534;
|
||||
|
||||
// A valid order remains fillable until it is expired, fully filled, or cancelled.
|
||||
@ -87,24 +88,27 @@ contract LibOrder is
|
||||
/// @dev Calculates Keccak-256 hash of the order.
|
||||
/// @param order The order structure.
|
||||
/// @return Keccak-256 EIP712 hash of the order.
|
||||
function getOrderHash(Order memory order)
|
||||
public
|
||||
view
|
||||
function getOrderHash(Order memory order, bytes32 eip712ExchangeDomainHash)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 orderHash)
|
||||
{
|
||||
orderHash = _hashEIP712ExchangeMessage(_hashOrder(order));
|
||||
orderHash = LibEIP712.hashEIP712Message(
|
||||
eip712ExchangeDomainHash,
|
||||
order.hashOrder()
|
||||
);
|
||||
return orderHash;
|
||||
}
|
||||
|
||||
/// @dev Calculates EIP712 hash of the order.
|
||||
/// @param order The order structure.
|
||||
/// @return EIP712 hash of the order.
|
||||
function _hashOrder(Order memory order)
|
||||
function hashOrder(Order memory order)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 result)
|
||||
{
|
||||
bytes32 schemaHash = EIP712_ORDER_SCHEMA_HASH;
|
||||
bytes32 schemaHash = _EIP712_ORDER_SCHEMA_HASH;
|
||||
bytes memory makerAssetData = order.makerAssetData;
|
||||
bytes memory takerAssetData = order.takerAssetData;
|
||||
bytes memory makerFeeAssetData = order.makerFeeAssetData;
|
||||
|
@ -19,12 +19,13 @@
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./LibEIP712ExchangeDomain.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP712.sol";
|
||||
|
||||
|
||||
contract LibZeroExTransaction is
|
||||
LibEIP712ExchangeDomain
|
||||
{
|
||||
library LibZeroExTransaction {
|
||||
|
||||
using LibZeroExTransaction for ZeroExTransaction;
|
||||
|
||||
// Hash for the EIP712 0x transaction schema
|
||||
// keccak256(abi.encodePacked(
|
||||
// "ZeroExTransaction(",
|
||||
@ -34,7 +35,7 @@ contract LibZeroExTransaction is
|
||||
// "bytes data",
|
||||
// ")"
|
||||
// ));
|
||||
bytes32 constant public EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0x6b4c70d217b44d0ff0d3bf7aeb18eb8604c5cd06f615a4b497aeefa4f01d2775;
|
||||
bytes32 constant internal _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0x6b4c70d217b44d0ff0d3bf7aeb18eb8604c5cd06f615a4b497aeefa4f01d2775;
|
||||
|
||||
struct ZeroExTransaction {
|
||||
uint256 salt; // Arbitrary number to ensure uniqueness of transaction hash.
|
||||
@ -46,25 +47,28 @@ contract LibZeroExTransaction is
|
||||
/// @dev Calculates the EIP712 hash of a 0x transaction using the domain separator of the Exchange contract.
|
||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||
/// @return EIP712 hash of the transaction with the domain separator of this contract.
|
||||
function getTransactionHash(ZeroExTransaction memory transaction)
|
||||
public
|
||||
view
|
||||
function getTransactionHash(ZeroExTransaction memory transaction, bytes32 eip712ExchangeDomainHash)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 transactionHash)
|
||||
{
|
||||
// Hash the transaction with the domain separator of the Exchange contract.
|
||||
transactionHash = _hashEIP712ExchangeMessage(_hashZeroExTransaction(transaction));
|
||||
transactionHash = LibEIP712.hashEIP712Message(
|
||||
eip712ExchangeDomainHash,
|
||||
transaction.hashZeroExTransaction()
|
||||
);
|
||||
return transactionHash;
|
||||
}
|
||||
|
||||
/// @dev Calculates EIP712 hash of the 0x transaction with no domain separator.
|
||||
/// @param transaction 0x transaction containing salt, signerAddress, and data.
|
||||
/// @return EIP712 hash of the transaction with no domain separator.
|
||||
function _hashZeroExTransaction(ZeroExTransaction memory transaction)
|
||||
function hashZeroExTransaction(ZeroExTransaction memory transaction)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32 result)
|
||||
{
|
||||
bytes32 schemaHash = EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
|
||||
bytes32 schemaHash = _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
|
||||
bytes memory data = transaction.data;
|
||||
uint256 salt = transaction.salt;
|
||||
uint256 expirationTimeSeconds = transaction.expirationTimeSeconds;
|
||||
|
Loading…
x
Reference in New Issue
Block a user