From 7c864b81e0d958560e098ebd8bd241385e4aadff Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 1 Aug 2018 15:08:17 -0700 Subject: Add createOrder with no signing to orderFactory --- packages/order-utils/CHANGELOG.json | 8 ++++++ packages/order-utils/src/constants.ts | 1 + packages/order-utils/src/order_factory.ts | 42 ++++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 6 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index a399f5ea1..7d9ca0a53 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "1.1.0-rc.2", + "changes": [ + { + "note": "Added a synchronous `createOrder` method in `orderFactory`" + } + ] + }, { "version": "1.0.1-rc.2", "changes": [ diff --git a/packages/order-utils/src/constants.ts b/packages/order-utils/src/constants.ts index bb7482184..92eb89d70 100644 --- a/packages/order-utils/src/constants.ts +++ b/packages/order-utils/src/constants.ts @@ -10,4 +10,5 @@ export const constants = { ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH: 53, SELECTOR_LENGTH: 4, BASE_16: 16, + INFINITE_TIMESTAMP_SEC: new BigNumber(2524604400), // Close to infinite }; diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index 803cb82b1..4be7a1913 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -1,17 +1,17 @@ -import { ECSignature, SignedOrder } from '@0xproject/types'; +import { ECSignature, Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Provider } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; +import { constants } from './constants'; import { orderHashUtils } from './order_hash'; import { generatePseudoRandomSalt } from './salt'; import { ecSignOrderHashAsync } from './signature_utils'; import { MessagePrefixType } from './types'; export const orderFactory = { - async createSignedOrderAsync( - provider: Provider, + createOrder( makerAddress: string, takerAddress: string, senderAddress: string, @@ -24,10 +24,9 @@ export const orderFactory = { exchangeAddress: string, feeRecipientAddress: string, expirationTimeSecondsIfExists?: BigNumber, - ): Promise { - const defaultExpirationUnixTimestampSec = new BigNumber(2524604400); // Close to infinite + ): Order { const expirationTimeSeconds = _.isUndefined(expirationTimeSecondsIfExists) - ? defaultExpirationUnixTimestampSec + ? constants.INFINITE_TIMESTAMP_SEC : expirationTimeSecondsIfExists; const order = { makerAddress, @@ -44,6 +43,37 @@ export const orderFactory = { feeRecipientAddress, expirationTimeSeconds, }; + return order; + }, + async createSignedOrderAsync( + provider: Provider, + makerAddress: string, + takerAddress: string, + senderAddress: string, + makerFee: BigNumber, + takerFee: BigNumber, + makerAssetAmount: BigNumber, + makerAssetData: string, + takerAssetAmount: BigNumber, + takerAssetData: string, + exchangeAddress: string, + feeRecipientAddress: string, + expirationTimeSecondsIfExists?: BigNumber, + ): Promise { + const order = orderFactory.createOrder( + makerAddress, + takerAddress, + senderAddress, + makerFee, + takerFee, + makerAssetAmount, + makerAssetData, + takerAssetAmount, + takerAssetData, + exchangeAddress, + feeRecipientAddress, + expirationTimeSecondsIfExists, + ); const orderHash = orderHashUtils.getOrderHashHex(order); const messagePrefixOpts = { prefixType: MessagePrefixType.EthSign, -- cgit v1.2.3 From c3e6be7956adf4fabcc8dfffe081515562a1dde0 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Thu, 2 Aug 2018 15:53:02 -0700 Subject: Add missing PR numbers --- packages/order-utils/CHANGELOG.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index 7d9ca0a53..ddfa690fe 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -3,7 +3,8 @@ "version": "1.1.0-rc.2", "changes": [ { - "note": "Added a synchronous `createOrder` method in `orderFactory`" + "note": "Added a synchronous `createOrder` method in `orderFactory`", + "pr": 935 } ] }, -- cgit v1.2.3 From 4f381ca1d9b6f8ecc232d0481d86f8ba695f7601 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 3 Aug 2018 15:47:19 -0400 Subject: Update orderFactory interface --- packages/order-utils/src/constants.ts | 1 + packages/order-utils/src/order_factory.ts | 42 +++++++++++++++---------------- 2 files changed, 22 insertions(+), 21 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/src/constants.ts b/packages/order-utils/src/constants.ts index 92eb89d70..ea3f8b932 100644 --- a/packages/order-utils/src/constants.ts +++ b/packages/order-utils/src/constants.ts @@ -11,4 +11,5 @@ export const constants = { SELECTOR_LENGTH: 4, BASE_16: 16, INFINITE_TIMESTAMP_SEC: new BigNumber(2524604400), // Close to infinite + ZERO_AMOUNT: new BigNumber(0), }; diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index 4be7a1913..444e5a0b2 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -13,21 +13,19 @@ import { MessagePrefixType } from './types'; export const orderFactory = { createOrder( makerAddress: string, - takerAddress: string, - senderAddress: string, - makerFee: BigNumber, - takerFee: BigNumber, makerAssetAmount: BigNumber, makerAssetData: string, takerAssetAmount: BigNumber, takerAssetData: string, exchangeAddress: string, - feeRecipientAddress: string, - expirationTimeSecondsIfExists?: BigNumber, + takerAddress: string = constants.NULL_ADDRESS, + senderAddress: string = constants.NULL_ADDRESS, + makerFee: BigNumber = constants.ZERO_AMOUNT, + takerFee: BigNumber = constants.ZERO_AMOUNT, + feeRecipientAddress: string = constants.NULL_ADDRESS, + salt: BigNumber = generatePseudoRandomSalt(), + expirationTimeSeconds: BigNumber = constants.INFINITE_TIMESTAMP_SEC, ): Order { - const expirationTimeSeconds = _.isUndefined(expirationTimeSecondsIfExists) - ? constants.INFINITE_TIMESTAMP_SEC - : expirationTimeSecondsIfExists; const order = { makerAddress, takerAddress, @@ -38,7 +36,7 @@ export const orderFactory = { takerAssetAmount, makerAssetData, takerAssetData, - salt: generatePseudoRandomSalt(), + salt, exchangeAddress, feeRecipientAddress, expirationTimeSeconds, @@ -48,31 +46,33 @@ export const orderFactory = { async createSignedOrderAsync( provider: Provider, makerAddress: string, - takerAddress: string, - senderAddress: string, - makerFee: BigNumber, - takerFee: BigNumber, makerAssetAmount: BigNumber, makerAssetData: string, takerAssetAmount: BigNumber, takerAssetData: string, exchangeAddress: string, - feeRecipientAddress: string, - expirationTimeSecondsIfExists?: BigNumber, + takerAddress?: string, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + salt?: BigNumber, + expirationTimeSeconds?: BigNumber, ): Promise { const order = orderFactory.createOrder( makerAddress, - takerAddress, - senderAddress, - makerFee, - takerFee, makerAssetAmount, makerAssetData, takerAssetAmount, takerAssetData, exchangeAddress, + takerAddress, + senderAddress, + makerFee, + takerFee, feeRecipientAddress, - expirationTimeSecondsIfExists, + salt, + expirationTimeSeconds, ); const orderHash = orderHashUtils.getOrderHashHex(order); const messagePrefixOpts = { -- cgit v1.2.3 From d00ee5df0d861e15e258e6747bec4af3284205b2 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 3 Aug 2018 15:58:17 -0400 Subject: Fix CHANGELOGs --- packages/order-utils/CHANGELOG.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index ddfa690fe..cac29bf6b 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -1,10 +1,10 @@ [ { - "version": "1.1.0-rc.2", + "version": "1.0.1-rc.3", "changes": [ { "note": "Added a synchronous `createOrder` method in `orderFactory`", - "pr": 935 + "pr": 936 } ] }, -- cgit v1.2.3 From 47673ba4bb2932051cb810bd0012c208665eb277 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Sun, 5 Aug 2018 16:51:53 -0400 Subject: Update createFactory to accept one createOrderOpts param to encompass all optional params --- packages/order-utils/CHANGELOG.json | 3 +- packages/order-utils/src/order_factory.ts | 70 ++++++++++++++++++------------- 2 files changed, 44 insertions(+), 29 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/CHANGELOG.json b/packages/order-utils/CHANGELOG.json index cac29bf6b..70a75854a 100644 --- a/packages/order-utils/CHANGELOG.json +++ b/packages/order-utils/CHANGELOG.json @@ -3,7 +3,8 @@ "version": "1.0.1-rc.3", "changes": [ { - "note": "Added a synchronous `createOrder` method in `orderFactory`", + "note": + "Added a synchronous `createOrder` method in `orderFactory`, updated public interfaces to support some optional parameters", "pr": 936 } ] diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index 444e5a0b2..5901d38c3 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -10,6 +10,16 @@ import { generatePseudoRandomSalt } from './salt'; import { ecSignOrderHashAsync } from './signature_utils'; import { MessagePrefixType } from './types'; +export interface CreateOrderOpts { + takerAddress?: string; + senderAddress?: string; + makerFee?: BigNumber; + takerFee?: BigNumber; + feeRecipientAddress?: string; + salt?: BigNumber; + expirationTimeSeconds?: BigNumber; +} + export const orderFactory = { createOrder( makerAddress: string, @@ -18,28 +28,24 @@ export const orderFactory = { takerAssetAmount: BigNumber, takerAssetData: string, exchangeAddress: string, - takerAddress: string = constants.NULL_ADDRESS, - senderAddress: string = constants.NULL_ADDRESS, - makerFee: BigNumber = constants.ZERO_AMOUNT, - takerFee: BigNumber = constants.ZERO_AMOUNT, - feeRecipientAddress: string = constants.NULL_ADDRESS, - salt: BigNumber = generatePseudoRandomSalt(), - expirationTimeSeconds: BigNumber = constants.INFINITE_TIMESTAMP_SEC, + createOrderOpts: CreateOrderOpts = generateDefaultCreateOrderOpts(), ): Order { + const defaultCreateOrderOpts = generateDefaultCreateOrderOpts(); const order = { makerAddress, - takerAddress, - senderAddress, - makerFee, - takerFee, makerAssetAmount, takerAssetAmount, makerAssetData, takerAssetData, - salt, exchangeAddress, - feeRecipientAddress, - expirationTimeSeconds, + takerAddress: createOrderOpts.takerAddress || defaultCreateOrderOpts.takerAddress, + senderAddress: createOrderOpts.senderAddress || defaultCreateOrderOpts.senderAddress, + makerFee: createOrderOpts.makerFee || defaultCreateOrderOpts.makerFee, + takerFee: createOrderOpts.takerFee || defaultCreateOrderOpts.takerFee, + feeRecipientAddress: createOrderOpts.feeRecipientAddress || defaultCreateOrderOpts.feeRecipientAddress, + salt: createOrderOpts.salt || defaultCreateOrderOpts.salt, + expirationTimeSeconds: + createOrderOpts.expirationTimeSeconds || defaultCreateOrderOpts.expirationTimeSeconds, }; return order; }, @@ -51,13 +57,7 @@ export const orderFactory = { takerAssetAmount: BigNumber, takerAssetData: string, exchangeAddress: string, - takerAddress?: string, - senderAddress?: string, - makerFee?: BigNumber, - takerFee?: BigNumber, - feeRecipientAddress?: string, - salt?: BigNumber, - expirationTimeSeconds?: BigNumber, + createOrderOpts?: CreateOrderOpts, ): Promise { const order = orderFactory.createOrder( makerAddress, @@ -66,13 +66,7 @@ export const orderFactory = { takerAssetAmount, takerAssetData, exchangeAddress, - takerAddress, - senderAddress, - makerFee, - takerFee, - feeRecipientAddress, - salt, - expirationTimeSeconds, + createOrderOpts, ); const orderHash = orderHashUtils.getOrderHashHex(order); const messagePrefixOpts = { @@ -86,6 +80,26 @@ export const orderFactory = { }, }; +function generateDefaultCreateOrderOpts(): { + takerAddress: string; + senderAddress: string; + makerFee: BigNumber; + takerFee: BigNumber; + feeRecipientAddress: string; + salt: BigNumber; + expirationTimeSeconds: BigNumber; +} { + return { + takerAddress: constants.NULL_ADDRESS, + senderAddress: constants.NULL_ADDRESS, + makerFee: constants.ZERO_AMOUNT, + takerFee: constants.ZERO_AMOUNT, + feeRecipientAddress: constants.NULL_ADDRESS, + salt: generatePseudoRandomSalt(), + expirationTimeSeconds: constants.INFINITE_TIMESTAMP_SEC, + }; +} + function getVRSHexString(ecSignature: ECSignature): string { const ETH_SIGN_SIGNATURE_TYPE = '03'; const vrs = `${intToHex(ecSignature.v)}${ethUtil.stripHexPrefix(ecSignature.r)}${ethUtil.stripHexPrefix( -- cgit v1.2.3 From 3cb955c136bf47b5f40cdbc44bcc4d19ec6d6453 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Sun, 5 Aug 2018 17:15:58 -0400 Subject: Move CreateOrderOpts into shared types --- packages/order-utils/src/index.ts | 10 +++++++++- packages/order-utils/src/order_factory.ts | 12 +----------- packages/order-utils/src/types.ts | 12 ++++++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'packages/order-utils') diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 76be63bb8..129eb0a3d 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -13,7 +13,15 @@ export { orderFactory } from './order_factory'; export { constants } from './constants'; export { crypto } from './crypto'; export { generatePseudoRandomSalt } from './salt'; -export { OrderError, MessagePrefixType, MessagePrefixOpts, EIP712Parameter, EIP712Schema, EIP712Types } from './types'; +export { + CreateOrderOpts, + OrderError, + MessagePrefixType, + MessagePrefixOpts, + EIP712Parameter, + EIP712Schema, + EIP712Types, +} from './types'; export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher'; export { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_filled_cancelled_fetcher'; export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store'; diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts index 5901d38c3..14727fd97 100644 --- a/packages/order-utils/src/order_factory.ts +++ b/packages/order-utils/src/order_factory.ts @@ -8,17 +8,7 @@ import { constants } from './constants'; import { orderHashUtils } from './order_hash'; import { generatePseudoRandomSalt } from './salt'; import { ecSignOrderHashAsync } from './signature_utils'; -import { MessagePrefixType } from './types'; - -export interface CreateOrderOpts { - takerAddress?: string; - senderAddress?: string; - makerFee?: BigNumber; - takerFee?: BigNumber; - feeRecipientAddress?: string; - salt?: BigNumber; - expirationTimeSeconds?: BigNumber; -} +import { CreateOrderOpts, MessagePrefixType } from './types'; export const orderFactory = { createOrder( diff --git a/packages/order-utils/src/types.ts b/packages/order-utils/src/types.ts index b08e74e71..f44e94349 100644 --- a/packages/order-utils/src/types.ts +++ b/packages/order-utils/src/types.ts @@ -1,3 +1,5 @@ +import { BigNumber } from '@0xproject/utils'; + export enum OrderError { InvalidSignature = 'INVALID_SIGNATURE', } @@ -51,3 +53,13 @@ export enum EIP712Types { String = 'string', Uint256 = 'uint256', } + +export interface CreateOrderOpts { + takerAddress?: string; + senderAddress?: string; + makerFee?: BigNumber; + takerFee?: BigNumber; + feeRecipientAddress?: string; + salt?: BigNumber; + expirationTimeSeconds?: BigNumber; +} -- cgit v1.2.3