diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-03-30 01:02:46 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-03-30 01:02:46 +0800 |
commit | 665011174bab7cfc6ec53e0044d60e1463222aee (patch) | |
tree | 44bc55bd390044d6cbfe8e0f7dddb621a8be7249 /packages/0x.js/src | |
parent | d106079d9b69191d9cdc6d9323dbae3e4b45daf2 (diff) | |
parent | c4dd9658e791a9f821ea3b6eb4326bcba53b081a (diff) | |
download | dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar.gz dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar.bz2 dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar.lz dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar.xz dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.tar.zst dexon-sol-tools-665011174bab7cfc6ec53e0044d60e1463222aee.zip |
Merge branch 'development' into feature/website/wallet-wrap
* development: (35 commits)
Fix CHANGELOG
Update Yarn.lock
Standardize changelog dates and format
Fix stubbing of a non-existent property
Remove redundant cast
Move common types out of web3 types
Add monorepo_scripts to npmignore
Add typeRoots
Add clean-state tests
Remove nested .gitignore files since `yarn publish` gets confused by them and ignores their contents on the top-level scope
Remove WETH hack now that updated WETH address is in TokenRegistry
Revert TokenRegistry address on Kovan
Improve rounding error message
Portal fill with mixed decimals
Add error popover if TokenRegistry on network user is browsing on don't include the requisite default tokens for 0x Portal to function
Set timeout for compiler tests
Remove redundant types
Add missing param comments
Fix a comment
Add a comment
...
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/artifacts/TokenRegistry.json | 2 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 18 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 4 | ||||
-rw-r--r-- | packages/0x.js/src/contract_wrappers/generated/.gitignore | 1 | ||||
-rw-r--r-- | packages/0x.js/src/globals.d.ts | 5 | ||||
-rw-r--r-- | packages/0x.js/src/index.ts | 2 | ||||
-rw-r--r-- | packages/0x.js/src/order_watcher/event_watcher.ts | 10 | ||||
-rw-r--r-- | packages/0x.js/src/types.ts | 11 | ||||
-rw-r--r-- | packages/0x.js/src/utils/filter_utils.ts | 24 |
9 files changed, 42 insertions, 35 deletions
diff --git a/packages/0x.js/src/artifacts/TokenRegistry.json b/packages/0x.js/src/artifacts/TokenRegistry.json index 95bee4b1d..0f583628c 100644 --- a/packages/0x.js/src/artifacts/TokenRegistry.json +++ b/packages/0x.js/src/artifacts/TokenRegistry.json @@ -538,7 +538,7 @@ "address": "0x4e9aad8184de8833365fea970cd9149372fdf1e6" }, "42": { - "address": "0xd0a1e359811322d97991e03f863a0c30c2cf029c" + "address": "0xf18e504561f4347bea557f3d4558f559dddbae7f" }, "50": { "address": "0x0b1ba0af832d7c05fd64161e0db78e85978e8082" diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index ad7727de5..6c96428ed 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -1,4 +1,4 @@ -import { BlockParamLiteral, LogWithDecodedArgs, RawLog } from '@0xproject/types'; +import { BlockParamLiteral, ContractAbi, FilterObject, LogEntry, LogWithDecodedArgs, RawLog } from '@0xproject/types'; import { AbiDecoder, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream'; @@ -35,7 +35,7 @@ export class ContractWrapper { private _abiDecoder?: AbiDecoder; private _blockAndLogStreamerIfExists?: BlockAndLogStreamer; private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer; - private _filters: { [filterToken: string]: Web3.FilterObject }; + private _filters: { [filterToken: string]: FilterObject }; private _filterCallbacks: { [filterToken: string]: EventCallback<ContractEventArgs>; }; @@ -75,7 +75,7 @@ export class ContractWrapper { address: string, eventName: ContractEvents, indexFilterValues: IndexedFilterValues, - abi: Web3.ContractAbi, + abi: ContractAbi, callback: EventCallback<ArgsType>, ): string { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi); @@ -92,7 +92,7 @@ export class ContractWrapper { eventName: ContractEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, - abi: Web3.ContractAbi, + abi: ContractAbi, ): Promise<Array<LogWithDecodedArgs<ArgsType>>> { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, blockRange); const logs = await this._web3Wrapper.getLogsAsync(filter); @@ -100,7 +100,7 @@ export class ContractWrapper { return logsWithDecodedArguments; } protected _tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>( - log: Web3.LogEntry, + log: LogEntry, ): LogWithDecodedArgs<ArgsType> | RawLog { if (_.isUndefined(this._abiDecoder)) { throw new Error(InternalZeroExError.NoAbiDecoder); @@ -111,7 +111,7 @@ export class ContractWrapper { protected async _getContractAbiAndAddressFromArtifactsAsync( artifact: Artifact, addressIfExists?: string, - ): Promise<[Web3.ContractAbi, string]> { + ): Promise<[ContractAbi, string]> { let contractAddress: string; if (_.isUndefined(addressIfExists)) { if (_.isUndefined(artifact.networks[this._networkId])) { @@ -125,7 +125,7 @@ export class ContractWrapper { if (!doesContractExist) { throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]); } - const abiAndAddress: [Web3.ContractAbi, string] = [artifact.abi, contractAddress]; + const abiAndAddress: [ContractAbi, string] = [artifact.abi, contractAddress]; return abiAndAddress; } protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { @@ -139,8 +139,8 @@ export class ContractWrapper { return addressIfExists; } } - private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, log: Web3.LogEntry): void { - _.forEach(this._filters, (filter: Web3.FilterObject, filterToken: string) => { + private _onLogStateChanged<ArgsType extends ContractEventArgs>(isRemoved: boolean, log: LogEntry): void { + _.forEach(this._filters, (filter: FilterObject, filterToken: string) => { if (filterUtils.matchesFilter(log, filter)) { const decodedLog = this._tryToDecodeLogOrNoop(log) as LogWithDecodedArgs<ArgsType>; const logEvent = { diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 59bd4db6b..6b5a75a9a 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -3,6 +3,7 @@ import { BlockParamLiteral, DecodedLogArgs, ECSignature, + LogEntry, LogWithDecodedArgs, Order, SignedOrder, @@ -10,7 +11,6 @@ import { import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; import { artifacts } from '../artifacts'; import { @@ -863,7 +863,7 @@ export class ExchangeWrapper extends ContractWrapper { * Checks if logs contain LogError, which is emitted by Exchange contract on transaction failure. * @param logs Transaction logs as returned by `zeroEx.awaitTransactionMinedAsync` */ - public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>): void { + public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs> | LogEntry>): void { const errLog = _.find(logs, { event: ExchangeEvents.LogError, }); diff --git a/packages/0x.js/src/contract_wrappers/generated/.gitignore b/packages/0x.js/src/contract_wrappers/generated/.gitignore deleted file mode 100644 index 72e8ffc0d..000000000 --- a/packages/0x.js/src/contract_wrappers/generated/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* diff --git a/packages/0x.js/src/globals.d.ts b/packages/0x.js/src/globals.d.ts index e2c321f38..3e8ea21bc 100644 --- a/packages/0x.js/src/globals.d.ts +++ b/packages/0x.js/src/globals.d.ts @@ -37,12 +37,13 @@ declare module 'ethereumjs-abi' { // truffle-hdwallet-provider declarations declare module 'truffle-hdwallet-provider' { + import { JSONRPCRequestPayload, JSONRPCResponsePayload } from '@0xproject/types'; import * as Web3 from 'web3'; class HDWalletProvider implements Web3.Provider { constructor(mnemonic: string, rpcUrl: string); public sendAsync( - payload: Web3.JSONRPCRequestPayload, - callback: (err: Error, result: Web3.JSONRPCResponsePayload) => void, + payload: JSONRPCRequestPayload, + callback: (err: Error, result: JSONRPCResponsePayload) => void, ): void; } export = HDWalletProvider; diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 7885fb82a..e353a1d3d 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -16,7 +16,6 @@ export { MethodOpts, OrderTransactionOpts, TransactionOpts, - FilterObject, LogEvent, DecodedLogEvent, EventWatcherCallback, @@ -28,6 +27,7 @@ export { export { BlockParamLiteral, + FilterObject, BlockParam, ContractEventArg, LogWithDecodedArgs, diff --git a/packages/0x.js/src/order_watcher/event_watcher.ts b/packages/0x.js/src/order_watcher/event_watcher.ts index e67b93251..246ab8292 100644 --- a/packages/0x.js/src/order_watcher/event_watcher.ts +++ b/packages/0x.js/src/order_watcher/event_watcher.ts @@ -1,9 +1,7 @@ +import { BlockParamLiteral, LogEntry } from '@0xproject/types'; import { intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import * as Web3 from 'web3'; - -import { BlockParamLiteral } from '@0xproject/types'; import { EventWatcherCallback, ZeroExError } from '../types'; import { assert } from '../utils/assert'; @@ -23,7 +21,7 @@ export class EventWatcher { private _web3Wrapper: Web3Wrapper; private _pollingIntervalMs: number; private _intervalIdIfExists?: NodeJS.Timer; - private _lastEvents: Web3.LogEntry[] = []; + private _lastEvents: LogEntry[] = []; constructor(web3Wrapper: Web3Wrapper, pollingIntervalIfExistsMs: undefined | number) { this._web3Wrapper = web3Wrapper; this._pollingIntervalMs = _.isUndefined(pollingIntervalIfExistsMs) @@ -69,7 +67,7 @@ export class EventWatcher { await this._emitDifferencesAsync(newEvents, LogEventState.Added, callback); this._lastEvents = pendingEvents; } - private async _getEventsAsync(): Promise<Web3.LogEntry[]> { + private async _getEventsAsync(): Promise<LogEntry[]> { const eventFilter = { fromBlock: BlockParamLiteral.Pending, toBlock: BlockParamLiteral.Pending, @@ -78,7 +76,7 @@ export class EventWatcher { return events; } private async _emitDifferencesAsync( - logs: Web3.LogEntry[], + logs: LogEntry[], logEventState: LogEventState, callback: EventWatcherCallback, ): Promise<void> { diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts index 65342b694..38cfb6306 100644 --- a/packages/0x.js/src/types.ts +++ b/packages/0x.js/src/types.ts @@ -3,7 +3,10 @@ import { BigNumber } from '@0xproject/utils'; import { BlockParam, BlockParamLiteral, + ContractAbi, ContractEventArg, + FilterObject, + LogEntryEvent, LogWithDecodedArgs, Order, SignedOrder, @@ -48,7 +51,7 @@ export type OrderAddresses = [string, string, string, string, string]; export type OrderValues = [BigNumber, BigNumber, BigNumber, BigNumber, BigNumber, BigNumber]; -export type LogEvent = Web3.LogEntryEvent; +export type LogEvent = LogEntryEvent; export interface DecodedLogEvent<ArgsType> { isRemoved: boolean; log: LogWithDecodedArgs<ArgsType>; @@ -197,7 +200,7 @@ export type ArtifactContractName = 'ZRX' | 'TokenTransferProxy' | 'TokenRegistry export interface Artifact { contract_name: ArtifactContractName; - abi: Web3.ContractAbi; + abi: ContractAbi; networks: { [networkId: number]: { address: string; @@ -222,7 +225,7 @@ export interface ValidateOrderFillableOpts { * flag when running Parity). */ export interface MethodOpts { - defaultBlock?: Web3.BlockParam; + defaultBlock?: BlockParam; } /* @@ -242,8 +245,6 @@ export interface OrderTransactionOpts extends TransactionOpts { shouldValidate?: boolean; } -export type FilterObject = Web3.FilterObject; - export enum TradeSide { Maker = 'maker', Taker = 'taker', diff --git a/packages/0x.js/src/utils/filter_utils.ts b/packages/0x.js/src/utils/filter_utils.ts index 97205ace3..c5df7321e 100644 --- a/packages/0x.js/src/utils/filter_utils.ts +++ b/packages/0x.js/src/utils/filter_utils.ts @@ -1,8 +1,16 @@ +import { + ConstructorAbi, + ContractAbi, + EventAbi, + FallbackAbi, + FilterObject, + LogEntry, + MethodAbi, +} from '@0xproject/types'; import * as ethUtil from 'ethereumjs-util'; import * as jsSHA3 from 'js-sha3'; import * as _ from 'lodash'; import * as uuid from 'uuid/v4'; -import * as Web3 from 'web3'; import { BlockRange, ContractEvents, IndexedFilterValues } from '../types'; @@ -16,15 +24,15 @@ export const filterUtils = { address: string, eventName: ContractEvents, indexFilterValues: IndexedFilterValues, - abi: Web3.ContractAbi, + abi: ContractAbi, blockRange?: BlockRange, - ): Web3.FilterObject { - const eventAbi = _.find(abi, { name: eventName }) as Web3.EventAbi; + ): FilterObject { + const eventAbi = _.find(abi, { name: eventName }) as EventAbi; const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi, eventName); const topicForEventSignature = ethUtil.addHexPrefix(jsSHA3.keccak256(eventSignature)); const topicsForIndexedArgs = filterUtils.getTopicsForIndexedArgs(eventAbi, indexFilterValues); const topics = [topicForEventSignature, ...topicsForIndexedArgs]; - let filter: Web3.FilterObject = { + let filter: FilterObject = { address, topics, }; @@ -36,12 +44,12 @@ export const filterUtils = { } return filter; }, - getEventSignatureFromAbiByName(eventAbi: Web3.EventAbi, eventName: ContractEvents): string { + getEventSignatureFromAbiByName(eventAbi: EventAbi, eventName: ContractEvents): string { const types = _.map(eventAbi.inputs, 'type'); const signature = `${eventAbi.name}(${types.join(',')})`; return signature; }, - getTopicsForIndexedArgs(abi: Web3.EventAbi, indexFilterValues: IndexedFilterValues): Array<string | null> { + getTopicsForIndexedArgs(abi: EventAbi, indexFilterValues: IndexedFilterValues): Array<string | null> { const topics: Array<string | null> = []; for (const eventInput of abi.inputs) { if (!eventInput.indexed) { @@ -60,7 +68,7 @@ export const filterUtils = { } return topics; }, - matchesFilter(log: Web3.LogEntry, filter: Web3.FilterObject): boolean { + matchesFilter(log: LogEntry, filter: FilterObject): boolean { if (!_.isUndefined(filter.address) && log.address !== filter.address) { return false; } |