From 92b0efff5abaac8bea468a1b3f897d004ec9c542 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 24 May 2018 10:56:31 -0700 Subject: Migrate migrations to v2 --- packages/contracts/src/utils/exchange_wrapper.ts | 4 +-- packages/contracts/src/utils/formatters.ts | 3 +- packages/contracts/src/utils/match_order_tester.ts | 3 +- packages/contracts/src/utils/order_factory.ts | 3 +- packages/contracts/src/utils/order_utils.ts | 5 +-- packages/contracts/src/utils/types.ts | 39 +++++----------------- 6 files changed, 18 insertions(+), 39 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index c353442f3..f2533a598 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -1,4 +1,4 @@ -import { Provider, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -10,7 +10,7 @@ import { constants } from './constants'; import { formatters } from './formatters'; import { LogDecoder } from './log_decoder'; import { orderUtils } from './order_utils'; -import { AssetProxyId, OrderInfo, SignedOrder, SignedTransaction } from './types'; +import { AssetProxyId, OrderInfo, SignedTransaction } from './types'; export class ExchangeWrapper { private _exchange: ExchangeContract; diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts index bfa48d6f1..d84a16469 100644 --- a/packages/contracts/src/utils/formatters.ts +++ b/packages/contracts/src/utils/formatters.ts @@ -1,8 +1,9 @@ import { BigNumber } from '@0xproject/utils'; +import { SignedOrder } from '@0xproject/types'; import * as _ from 'lodash'; import { orderUtils } from './order_utils'; -import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types'; +import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders } from './types'; export const formatters = { createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []): BatchFillOrders { diff --git a/packages/contracts/src/utils/match_order_tester.ts b/packages/contracts/src/utils/match_order_tester.ts index 30039937f..87399b9f6 100644 --- a/packages/contracts/src/utils/match_order_tester.ts +++ b/packages/contracts/src/utils/match_order_tester.ts @@ -1,5 +1,5 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils'; -import { LogWithDecodedArgs } from '@0xproject/types'; +import { LogWithDecodedArgs, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); @@ -29,7 +29,6 @@ import { ERC20BalancesByOwner, ERC721TokenIdsByOwner, ExchangeStatus, - SignedOrder, TransferAmountsByMatchOrders as TransferAmounts, } from '../utils/types'; import { provider, web3Wrapper } from '../utils/web3_wrapper'; diff --git a/packages/contracts/src/utils/order_factory.ts b/packages/contracts/src/utils/order_factory.ts index 86b3d5ac7..f704c26ec 100644 --- a/packages/contracts/src/utils/order_factory.ts +++ b/packages/contracts/src/utils/order_factory.ts @@ -1,11 +1,12 @@ import { generatePseudoRandomSalt } from '@0xproject/order-utils'; +import { SignedOrder, UnsignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { constants } from './constants'; import { orderUtils } from './order_utils'; import { signingUtils } from './signing_utils'; -import { SignatureType, SignedOrder, UnsignedOrder } from './types'; +import { SignatureType } from './types'; export class OrderFactory { private _defaultOrderParams: Partial; diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 8adc6b735..9542a3858 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -1,10 +1,11 @@ +import { Order, SignedOrder, UnsignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import { crypto } from './crypto'; -import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; +import { CancelOrder, MatchOrder, SignatureType } from './types'; export const orderUtils = { createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => { @@ -22,7 +23,7 @@ export const orderUtils = { }; return cancel; }, - getOrderStruct(signedOrder: SignedOrder): OrderStruct { + getOrderStruct(signedOrder: SignedOrder): Order { const orderStruct = { senderAddress: signedOrder.senderAddress, makerAddress: signedOrder.makerAddress, diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index ef86b4f38..8c53b966f 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -1,4 +1,4 @@ -import { AbiDefinition, ContractAbi } from '@0xproject/types'; +import { AbiDefinition, ContractAbi, Order } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface ERC20BalancesByOwner { @@ -18,25 +18,25 @@ export interface SubmissionContractEventArgs { } export interface BatchFillOrders { - orders: OrderStruct[]; + orders: Order[]; signatures: string[]; takerAssetFillAmounts: BigNumber[]; } export interface MarketSellOrders { - orders: OrderStruct[]; + orders: Order[]; signatures: string[]; takerAssetFillAmount: BigNumber; } export interface MarketBuyOrders { - orders: OrderStruct[]; + orders: Order[]; signatures: string[]; makerAssetFillAmount: BigNumber; } export interface BatchCancelOrders { - orders: OrderStruct[]; + orders: Order[]; } export interface CancelOrdersBefore { @@ -113,29 +113,6 @@ export enum ContractName { Authorizable = 'Authorizable', } -export interface SignedOrder extends UnsignedOrder { - signature: string; -} - -export interface OrderStruct { - senderAddress: string; - makerAddress: string; - takerAddress: string; - feeRecipientAddress: string; - makerAssetAmount: BigNumber; - takerAssetAmount: BigNumber; - makerFee: BigNumber; - takerFee: BigNumber; - expirationTimeSeconds: BigNumber; - salt: BigNumber; - makerAssetData: string; - takerAssetData: string; -} - -export interface UnsignedOrder extends OrderStruct { - exchangeAddress: string; -} - export enum SignatureType { Illegal, Invalid, @@ -199,13 +176,13 @@ export interface ProxyData { } export interface CancelOrder { - order: OrderStruct; + order: Order; takerAssetCancelAmount: BigNumber; } export interface MatchOrder { - left: OrderStruct; - right: OrderStruct; + left: Order; + right: Order; leftSignature: string; rightSignature: string; } -- cgit v1.2.3 From ea3f82ccc25ad411d32d4dd8c2dbcbc95847dc0b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 24 May 2018 14:56:20 -0700 Subject: Fix linter issues --- packages/contracts/src/utils/formatters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts index d84a16469..c46d668bc 100644 --- a/packages/contracts/src/utils/formatters.ts +++ b/packages/contracts/src/utils/formatters.ts @@ -1,5 +1,5 @@ -import { BigNumber } from '@0xproject/utils'; import { SignedOrder } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { orderUtils } from './order_utils'; -- cgit v1.2.3 From 65676c22f92996feb0e3cb98daa3d8ce7b3854e9 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 8 May 2018 15:31:56 +1000 Subject: Update order hash to match latest eip712 --- packages/contracts/src/utils/order_utils.ts | 45 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 8adc6b735..688259b6c 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -1,7 +1,5 @@ import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; import ethUtil = require('ethereumjs-util'); -import * as _ from 'lodash'; import { crypto } from './crypto'; import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; @@ -39,22 +37,31 @@ export const orderUtils = { }; return orderStruct; }, - getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer { + getOrderSchemaHex(): string { const orderSchemaHashBuff = crypto.solSHA3([ - 'address exchangeAddress', - 'address makerAddress', - 'address takerAddress', - 'address feeRecipientAddress', - 'address senderAddress', - 'uint256 makerAssetAmount', - 'uint256 takerAssetAmount', - 'uint256 makerFee', - 'uint256 takerFee', - 'uint256 expirationTimeSeconds', - 'uint256 salt', - 'bytes makerAssetData', - 'bytes takerAssetData', + 'Order(', + 'address exchangeAddress,', + 'address makerAddress,', + 'address takerAddress,', + 'address feeRecipientAddress,', + 'address senderAddress,', + 'uint256 makerAssetAmount,', + 'uint256 takerAssetAmount,', + 'uint256 makerFee,', + 'uint256 takerFee,', + 'uint256 expirationTimeSeconds,', + 'uint256 salt,', + 'bytes makerAssetData,', + 'bytes takerAssetData,', + ')', ]); + const schemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`; + return schemaHashHex; + }, + getOrderHashBuff(order: SignedOrder | UnsignedOrder): Buffer { + const makerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.makerAssetData)]); + const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]); + const orderParamsHashBuff = crypto.solSHA3([ order.exchangeAddress, order.makerAddress, @@ -67,11 +74,11 @@ export const orderUtils = { order.takerFee, order.expirationTimeSeconds, order.salt, - ethUtil.toBuffer(order.makerAssetData), - ethUtil.toBuffer(order.takerAssetData), + makerAssetDataHash, + takerAssetDataHash, ]); - const orderSchemaHashHex = `0x${orderSchemaHashBuff.toString('hex')}`; const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`; + const orderSchemaHashHex = orderUtils.getOrderSchemaHex(); const orderHashBuff = crypto.solSHA3([new BigNumber(orderSchemaHashHex), new BigNumber(orderParamsHashHex)]); return orderHashBuff; }, -- cgit v1.2.3 From 3cc8af819c9f62f42e7cb3d03f896b35cfc10d05 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Wed, 23 May 2018 17:27:49 -0700 Subject: Use domain separator for exchange address --- packages/contracts/src/utils/order_utils.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 688259b6c..969d43dd1 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -2,7 +2,7 @@ import { BigNumber } from '@0xproject/utils'; import ethUtil = require('ethereumjs-util'); import { crypto } from './crypto'; -import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; +import { CancelOrder, MatchOrder, OrderStruct, SignedOrder, UnsignedOrder } from './types'; export const orderUtils = { createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => { @@ -37,10 +37,19 @@ export const orderUtils = { }; return orderStruct; }, + getDomainSeparatorSchemaHex(): string { + const domainSeparatorSchemaHashBuff = crypto.solSHA3(['DomainSeparator(address contract)']); + const schemaHashHex = `0x${domainSeparatorSchemaHashBuff.toString('hex')}`; + return schemaHashHex; + }, + getDomainSeparatorHashHex(exchangeAddress: string): string { + const domainSeparatorHashBuff = crypto.solSHA3([exchangeAddress]); + const domainSeparatorHashHex = `0x${domainSeparatorHashBuff.toString('hex')}`; + return domainSeparatorHashHex; + }, getOrderSchemaHex(): string { const orderSchemaHashBuff = crypto.solSHA3([ 'Order(', - 'address exchangeAddress,', 'address makerAddress,', 'address takerAddress,', 'address feeRecipientAddress,', @@ -63,7 +72,6 @@ export const orderUtils = { const takerAssetDataHash = crypto.solSHA3([ethUtil.toBuffer(order.takerAssetData)]); const orderParamsHashBuff = crypto.solSHA3([ - order.exchangeAddress, order.makerAddress, order.takerAddress, order.feeRecipientAddress, @@ -79,7 +87,14 @@ export const orderUtils = { ]); const orderParamsHashHex = `0x${orderParamsHashBuff.toString('hex')}`; const orderSchemaHashHex = orderUtils.getOrderSchemaHex(); - const orderHashBuff = crypto.solSHA3([new BigNumber(orderSchemaHashHex), new BigNumber(orderParamsHashHex)]); + const domainSeparatorHashHex = this.getDomainSeparatorHashHex(order.exchangeAddress); + const domainSeparatorSchemaHex = this.getDomainSeparatorSchemaHex(); + const orderHashBuff = crypto.solSHA3([ + new BigNumber(domainSeparatorSchemaHex), + new BigNumber(domainSeparatorHashHex), + new BigNumber(orderSchemaHashHex), + new BigNumber(orderParamsHashHex), + ]); return orderHashBuff; }, getOrderHashHex(order: SignedOrder | UnsignedOrder): string { -- cgit v1.2.3