From ffe7363776077e2363afc23a8e4c5e2ea420aefe Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 14 Mar 2018 15:02:58 -0700 Subject: Add SignedOrder, Order, and ECSignature types to the types package --- packages/0x.js/src/0x.ts | 4 +-- .../src/contract_wrappers/exchange_wrapper.ts | 12 ++++--- packages/0x.js/src/index.ts | 6 ++-- .../0x.js/src/order_watcher/order_state_watcher.ts | 3 +- .../order_watcher/remaining_fillable_calculator.ts | 3 +- packages/0x.js/src/types.ts | 37 +++++----------------- packages/0x.js/src/utils/assert.ts | 2 +- packages/0x.js/src/utils/order_state_utils.ts | 10 ++---- packages/0x.js/src/utils/order_validation_utils.ts | 3 +- packages/0x.js/src/utils/signature_utils.ts | 3 +- packages/0x.js/src/utils/utils.ts | 4 +-- .../test/remaining_fillable_calculator_test.ts | 2 +- packages/connect/package.json | 3 +- packages/connect/src/http_client.ts | 2 +- packages/connect/src/index.ts | 5 ++- packages/connect/src/types.ts | 30 +----------------- .../src/utils/relayer_response_json_parsers.ts | 3 +- packages/types/src/index.ts | 28 ++++++++++++++++ 18 files changed, 67 insertions(+), 93 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 22a5fee10..09da4b046 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -1,5 +1,5 @@ import { schemas, SchemaValidator } from '@0xproject/json-schemas'; -import { TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { ECSignature, Order, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; import { AbiDecoder, BigNumber, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethUtil from 'ethereumjs-util'; @@ -15,7 +15,7 @@ import { OrderStateWatcher } from './order_watcher/order_state_watcher'; import { zeroExConfigSchema } from './schemas/zero_ex_config_schema'; import { zeroExPrivateNetworkConfigSchema } from './schemas/zero_ex_private_network_config_schema'; import { zeroExPublicNetworkConfigSchema } from './schemas/zero_ex_public_network_config_schema'; -import { ECSignature, Order, SignedOrder, Web3Provider, ZeroExConfig, ZeroExError } from './types'; +import { Web3Provider, ZeroExConfig, ZeroExError } from './types'; import { assert } from './utils/assert'; import { constants } from './utils/constants'; import { decorators } from './utils/decorators'; diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 20b46c6bc..6414985e6 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -1,5 +1,12 @@ import { schemas } from '@0xproject/json-schemas'; -import { BlockParamLiteral, DecodedLogArgs, LogWithDecodedArgs } from '@0xproject/types'; +import { + BlockParamLiteral, + DecodedLogArgs, + ECSignature, + LogWithDecodedArgs, + Order, + SignedOrder, +} from '@0xproject/types'; import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -8,19 +15,16 @@ import * as Web3 from 'web3'; import { artifacts } from '../artifacts'; import { BlockRange, - ECSignature, EventCallback, ExchangeContractErrCodes, ExchangeContractErrs, IndexedFilterValues, MethodOpts, - Order, OrderAddresses, OrderCancellationRequest, OrderFillRequest, OrderTransactionOpts, OrderValues, - SignedOrder, ValidateOrderFillableOpts, } from '../types'; import { assert } from '../utils/assert'; diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 9879bbb56..7885fb82a 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -1,9 +1,6 @@ export { ZeroEx } from './0x'; export { - Order, - SignedOrder, - ECSignature, ZeroExError, EventCallback, ExchangeContractErrs, @@ -34,6 +31,9 @@ export { BlockParam, ContractEventArg, LogWithDecodedArgs, + Order, + SignedOrder, + ECSignature, TransactionReceipt, TransactionReceiptWithDecodedLogs, } from '@0xproject/types'; diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index e489dd5cc..f7515e59e 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -1,5 +1,5 @@ import { schemas } from '@0xproject/json-schemas'; -import { BlockParamLiteral, LogWithDecodedArgs } from '@0xproject/types'; +import { BlockParamLiteral, LogWithDecodedArgs, SignedOrder } from '@0xproject/types'; import { AbiDecoder, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -31,7 +31,6 @@ import { OnOrderStateChangeCallback, OrderState, OrderStateWatcherConfig, - SignedOrder, ZeroExError, } from '../types'; import { assert } from '../utils/assert'; diff --git a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts index 20b09d606..184c13aa4 100644 --- a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts +++ b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts @@ -1,7 +1,6 @@ +import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -import { SignedOrder } from '../types'; - export class RemainingFillableCalculator { private _signedOrder: SignedOrder; private _isMakerTokenZRX: boolean; diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 2f17e30c2..65342b694 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -1,6 +1,13 @@ import { BigNumber } from '@0xproject/utils'; -import { BlockParam, BlockParamLiteral, ContractEventArg, LogWithDecodedArgs } from '@0xproject/types'; +import { + BlockParam, + BlockParamLiteral, + ContractEventArg, + LogWithDecodedArgs, + Order, + SignedOrder, +} from '@0xproject/types'; import * as Web3 from 'web3'; @@ -37,15 +44,6 @@ export enum InternalZeroExError { WethNotInTokenRegistry = 'WETH_NOT_IN_TOKEN_REGISTRY', } -/** - * Elliptic Curve signature - */ -export interface ECSignature { - v: number; - r: string; - s: string; -} - export type OrderAddresses = [string, string, string, string, string]; export type OrderValues = [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber]; @@ -107,25 +105,6 @@ export interface ContractEvent { export type ContractEventArgs = ExchangeContractEventArgs | TokenContractEventArgs | EtherTokenContractEventArgs; -export interface Order { - maker: string; - taker: string; - makerFee: BigNumber; - takerFee: BigNumber; - makerTokenAmount: BigNumber; - takerTokenAmount: BigNumber; - makerTokenAddress: string; - takerTokenAddress: string; - salt: BigNumber; - exchangeContractAddress: string; - feeRecipient: string; - expirationUnixTimestampSec: BigNumber; -} - -export interface SignedOrder extends Order { - ecSignature: ECSignature; -} - // [address, name, symbol, decimals, ipfsHash, swarmHash] export type TokenMetadata = [string, string, string, number, string, string]; diff --git a/packages/0x.js/src/utils/assert.ts b/packages/0x.js/src/utils/assert.ts index c21f2dbca..5e8004cd0 100644 --- a/packages/0x.js/src/utils/assert.ts +++ b/packages/0x.js/src/utils/assert.ts @@ -3,11 +3,11 @@ import { assert as sharedAssert } from '@0xproject/assert'; // tslint:disable-next-line:no-unused-variable import { Schema } from '@0xproject/json-schemas'; // tslint:disable-next-line:no-unused-variable +import { ECSignature } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import { ECSignature } from '../types'; import { signatureUtils } from '../utils/signature_utils'; export const assert = { diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index b7a55ff42..38189443b 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -1,3 +1,4 @@ +import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; @@ -6,14 +7,7 @@ import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; import { RemainingFillableCalculator } from '../order_watcher/remaining_fillable_calculator'; import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store'; import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store'; -import { - ExchangeContractErrs, - OrderRelevantState, - OrderState, - OrderStateInvalid, - OrderStateValid, - SignedOrder, -} from '../types'; +import { ExchangeContractErrs, OrderRelevantState, OrderState, OrderStateInvalid, OrderStateValid } from '../types'; const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001; diff --git a/packages/0x.js/src/utils/order_validation_utils.ts b/packages/0x.js/src/utils/order_validation_utils.ts index 917d414c8..f32bf43d0 100644 --- a/packages/0x.js/src/utils/order_validation_utils.ts +++ b/packages/0x.js/src/utils/order_validation_utils.ts @@ -1,9 +1,10 @@ +import { Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import { ZeroEx } from '../0x'; import { ExchangeWrapper } from '../contract_wrappers/exchange_wrapper'; -import { ExchangeContractErrs, Order, SignedOrder, TradeSide, TransferType, ZeroExError } from '../types'; +import { ExchangeContractErrs, TradeSide, TransferType, ZeroExError } from '../types'; import { constants } from '../utils/constants'; import { utils } from '../utils/utils'; diff --git a/packages/0x.js/src/utils/signature_utils.ts b/packages/0x.js/src/utils/signature_utils.ts index b0f1d61ef..46f167339 100644 --- a/packages/0x.js/src/utils/signature_utils.ts +++ b/packages/0x.js/src/utils/signature_utils.ts @@ -1,7 +1,6 @@ +import { ECSignature } from '@0xproject/types'; import * as ethUtil from 'ethereumjs-util'; -import { ECSignature } from '../types'; - export const signatureUtils = { isValidSignature(data: string, signature: ECSignature, signerAddress: string): boolean { const dataBuff = ethUtil.toBuffer(data); diff --git a/packages/0x.js/src/utils/utils.ts b/packages/0x.js/src/utils/utils.ts index 3e98de84f..c8bcd907e 100644 --- a/packages/0x.js/src/utils/utils.ts +++ b/packages/0x.js/src/utils/utils.ts @@ -1,12 +1,10 @@ -import { SolidityTypes } from '@0xproject/types'; +import { Order, SignedOrder, SolidityTypes } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import BN = require('bn.js'); import * as ethABI from 'ethereumjs-abi'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; -import { Order, SignedOrder } from '../types'; - export const utils = { /** * Converts BigNumber instance to BN diff --git a/packages/0x.js/test/remaining_fillable_calculator_test.ts b/packages/0x.js/test/remaining_fillable_calculator_test.ts index 4c6b8f3ac..d97402ef6 100644 --- a/packages/0x.js/test/remaining_fillable_calculator_test.ts +++ b/packages/0x.js/test/remaining_fillable_calculator_test.ts @@ -1,10 +1,10 @@ +import { ECSignature, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; import 'mocha'; import { ZeroEx } from '../src/0x'; import { RemainingFillableCalculator } from '../src/order_watcher/remaining_fillable_calculator'; -import { ECSignature, SignedOrder } from '../src/types'; import { chaiSetup } from './utils/chai_setup'; diff --git a/packages/connect/package.json b/packages/connect/package.json index e0478b42a..61b92dc3e 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -50,6 +50,7 @@ "dependencies": { "@0xproject/assert": "^0.2.0", "@0xproject/json-schemas": "^0.7.14", + "@0xproject/types": "^0.3.1", "@0xproject/utils": "^0.4.1", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", @@ -82,6 +83,6 @@ "web3-typescript-typings": "^0.10.0" }, "publishConfig": { - "access": "public" + "access": "public" } } diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index a221b54e8..5806f1d43 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -1,5 +1,6 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; +import { SignedOrder } from '@0xproject/types'; import 'isomorphic-fetch'; import * as _ from 'lodash'; import * as queryString from 'query-string'; @@ -15,7 +16,6 @@ import { OrderbookResponse, OrdersRequestOpts, PagedRequestOpts, - SignedOrder, TokenPairsItem, TokenPairsRequestOpts, } from './types'; diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index bb42384f9..135b5b5f6 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -2,10 +2,8 @@ export { HttpClient } from './http_client'; export { WebSocketOrderbookChannel } from './ws_orderbook_channel'; export { Client, - ECSignature, FeesRequest, FeesResponse, - Order, OrderbookChannel, OrderbookChannelHandler, OrderbookChannelSubscriptionOpts, @@ -13,9 +11,10 @@ export { OrderbookResponse, OrdersRequestOpts, PagedRequestOpts, - SignedOrder, TokenPairsItem, TokenPairsRequestOpts, TokenTradeInfo, WebSocketOrderbookChannelConfig, } from './types'; + +export { ECSignature, Order, SignedOrder } from '@0xproject/types'; diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 5f837b0b3..5c344e328 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -1,34 +1,6 @@ +import { ECSignature, Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; -// TODO: Consolidate Order, SignedOrder and ECSignature into a shared package instead of duplicating them from 0x.js -export interface Order { - maker: string; - taker: string; - makerFee: BigNumber; - takerFee: BigNumber; - makerTokenAmount: BigNumber; - takerTokenAmount: BigNumber; - makerTokenAddress: string; - takerTokenAddress: string; - salt: BigNumber; - exchangeContractAddress: string; - feeRecipient: string; - expirationUnixTimestampSec: BigNumber; -} - -export interface SignedOrder extends Order { - ecSignature: ECSignature; -} - -/** - * Elliptic Curve signature - */ -export interface ECSignature { - v: number; - r: string; - s: string; -} - export interface Client { getTokenPairsAsync: (requestOpts?: TokenPairsRequestOpts & PagedRequestOpts) => Promise; getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise; diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index 668461bf4..cf1c07bd9 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -1,8 +1,9 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; +import { SignedOrder } from '@0xproject/types'; import * as _ from 'lodash'; -import { FeesResponse, OrderbookResponse, SignedOrder, TokenPairsItem } from '../types'; +import { FeesResponse, OrderbookResponse, TokenPairsItem } from '../types'; import { typeConverters } from './type_converters'; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 149aaca8a..2147a3edb 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -73,3 +73,31 @@ export interface RawLogEntry { data: string; topics: string[]; } + +export interface Order { + maker: string; + taker: string; + makerFee: BigNumber; + takerFee: BigNumber; + makerTokenAmount: BigNumber; + takerTokenAmount: BigNumber; + makerTokenAddress: string; + takerTokenAddress: string; + salt: BigNumber; + exchangeContractAddress: string; + feeRecipient: string; + expirationUnixTimestampSec: BigNumber; +} + +export interface SignedOrder extends Order { + ecSignature: ECSignature; +} + +/** + * Elliptic Curve signature + */ +export interface ECSignature { + v: number; + r: string; + s: string; +} -- cgit v1.2.3