3
.gitignore
vendored
3
.gitignore
vendored
@@ -67,6 +67,9 @@ generated_docs/
|
||||
|
||||
TODO.md
|
||||
|
||||
# VSCode file
|
||||
.vscode
|
||||
|
||||
packages/website/public/bundle*
|
||||
packages/react-docs/example/public/bundle*
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
"@0xproject/dev-utils": "^0.4.5",
|
||||
"@0xproject/migrations": "^0.0.9",
|
||||
"@0xproject/monorepo-scripts": "^0.2.2",
|
||||
"@0xproject/sol-compiler": "^0.5.3",
|
||||
"@0xproject/subproviders": "^0.10.5",
|
||||
"@0xproject/tslint-config": "^0.4.21",
|
||||
"@types/lodash": "4.14.104",
|
||||
@@ -75,6 +74,7 @@
|
||||
"@0xproject/fill-scenarios": "^0.0.5",
|
||||
"@0xproject/json-schemas": "^0.8.2",
|
||||
"@0xproject/order-utils": "^0.0.8",
|
||||
"@0xproject/sol-compiler": "^0.5.3",
|
||||
"@0xproject/types": "^0.8.2",
|
||||
"@0xproject/typescript-typings": "^0.4.2",
|
||||
"@0xproject/utils": "^0.7.2",
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
LogWithDecodedArgs,
|
||||
RawLog,
|
||||
} from '@0xproject/types';
|
||||
import { AbiDecoder, intervalUtils } from '@0xproject/utils';
|
||||
import { intervalUtils, logUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import { Block, BlockAndLogStreamer, Log } from 'ethereumjs-blockstream';
|
||||
import * as _ from 'lodash';
|
||||
@@ -46,9 +46,12 @@ export class ContractWrapper {
|
||||
};
|
||||
private _onLogAddedSubscriptionToken: string | undefined;
|
||||
private _onLogRemovedSubscriptionToken: string | undefined;
|
||||
private static _onBlockstreamError(err: Error): void {
|
||||
private static _onBlockstreamError(isVerbose: boolean, err: Error): void {
|
||||
// Noop on blockstream errors since they are automatically
|
||||
// recovered from and don't cause Blockstream to exit.
|
||||
if (isVerbose) {
|
||||
logUtils.warn(err.message);
|
||||
}
|
||||
}
|
||||
constructor(web3Wrapper: Web3Wrapper, networkId: number) {
|
||||
this._web3Wrapper = web3Wrapper;
|
||||
@@ -85,10 +88,11 @@ export class ContractWrapper {
|
||||
indexFilterValues: IndexedFilterValues,
|
||||
abi: ContractAbi,
|
||||
callback: EventCallback<ArgsType>,
|
||||
isVerbose: boolean = false,
|
||||
): string {
|
||||
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi);
|
||||
if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
|
||||
this._startBlockAndLogStream();
|
||||
this._startBlockAndLogStream(isVerbose);
|
||||
}
|
||||
const filterToken = filterUtils.generateUUID();
|
||||
this._filters[filterToken] = filter;
|
||||
@@ -159,21 +163,21 @@ export class ContractWrapper {
|
||||
}
|
||||
});
|
||||
}
|
||||
private _startBlockAndLogStream(): void {
|
||||
private _startBlockAndLogStream(isVerbose: boolean): void {
|
||||
if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
|
||||
throw new Error(ContractWrappersError.SubscriptionAlreadyPresent);
|
||||
}
|
||||
this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
|
||||
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
|
||||
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
|
||||
ContractWrapper._onBlockstreamError.bind(this),
|
||||
ContractWrapper._onBlockstreamError.bind(this, isVerbose),
|
||||
);
|
||||
const catchAllLogFilter = {};
|
||||
this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter);
|
||||
this._blockAndLogStreamIntervalIfExists = intervalUtils.setAsyncExcludingInterval(
|
||||
this._reconcileBlockAsync.bind(this),
|
||||
constants.DEFAULT_BLOCK_POLLING_INTERVAL,
|
||||
ContractWrapper._onBlockstreamError.bind(this),
|
||||
ContractWrapper._onBlockstreamError.bind(this, isVerbose),
|
||||
);
|
||||
let isRemoved = false;
|
||||
this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded(
|
||||
|
||||
@@ -133,6 +133,7 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
* @param indexFilterValues An object where the keys are indexed args returned by the event and
|
||||
* the value is the value you are interested in. E.g `{_owner: aUserAddressHex}`
|
||||
* @param callback Callback that gets called when a log is added/removed
|
||||
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
|
||||
* @return Subscription token used later to unsubscribe
|
||||
*/
|
||||
public subscribe<ArgsType extends EtherTokenContractEventArgs>(
|
||||
@@ -140,6 +141,7 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
eventName: EtherTokenEvents,
|
||||
indexFilterValues: IndexedFilterValues,
|
||||
callback: EventCallback<ArgsType>,
|
||||
isVerbose: boolean = false,
|
||||
): string {
|
||||
assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
|
||||
const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase();
|
||||
@@ -152,6 +154,7 @@ export class EtherTokenWrapper extends ContractWrapper {
|
||||
indexFilterValues,
|
||||
artifacts.EtherToken.abi,
|
||||
callback,
|
||||
isVerbose,
|
||||
);
|
||||
return subscriptionToken;
|
||||
}
|
||||
|
||||
@@ -652,12 +652,14 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
* @param indexFilterValues An object where the keys are indexed args returned by the event and
|
||||
* the value is the value you are interested in. E.g `{maker: aUserAddressHex}`
|
||||
* @param callback Callback that gets called when a log is added/removed
|
||||
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
|
||||
* @return Subscription token used later to unsubscribe
|
||||
*/
|
||||
public subscribe<ArgsType extends ExchangeContractEventArgs>(
|
||||
eventName: ExchangeEvents,
|
||||
indexFilterValues: IndexedFilterValues,
|
||||
callback: EventCallback<ArgsType>,
|
||||
isVerbose: boolean = false,
|
||||
): string {
|
||||
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
|
||||
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
|
||||
@@ -669,6 +671,7 @@ export class ExchangeWrapper extends ContractWrapper {
|
||||
indexFilterValues,
|
||||
artifacts.Exchange.abi,
|
||||
callback,
|
||||
isVerbose,
|
||||
);
|
||||
return subscriptionToken;
|
||||
}
|
||||
|
||||
@@ -350,6 +350,7 @@ export class TokenWrapper extends ContractWrapper {
|
||||
* @param indexFilterValues An object where the keys are indexed args returned by the event and
|
||||
* the value is the value you are interested in. E.g `{maker: aUserAddressHex}`
|
||||
* @param callback Callback that gets called when a log is added/removed
|
||||
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
|
||||
* @return Subscription token used later to unsubscribe
|
||||
*/
|
||||
public subscribe<ArgsType extends TokenContractEventArgs>(
|
||||
@@ -357,6 +358,7 @@ export class TokenWrapper extends ContractWrapper {
|
||||
eventName: TokenEvents,
|
||||
indexFilterValues: IndexedFilterValues,
|
||||
callback: EventCallback<ArgsType>,
|
||||
isVerbose: boolean = false,
|
||||
): string {
|
||||
assert.isETHAddressHex('tokenAddress', tokenAddress);
|
||||
const normalizedTokenAddress = tokenAddress.toLowerCase();
|
||||
@@ -369,6 +371,7 @@ export class TokenWrapper extends ContractWrapper {
|
||||
indexFilterValues,
|
||||
artifacts.Token.abi,
|
||||
callback,
|
||||
isVerbose,
|
||||
);
|
||||
return subscriptionToken;
|
||||
}
|
||||
|
||||
@@ -61,13 +61,9 @@ export class EventWatcher {
|
||||
if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
|
||||
throw new Error(OrderWatcherError.SubscriptionAlreadyPresent);
|
||||
}
|
||||
const eventFilter = {
|
||||
fromBlock: this._stateLayer,
|
||||
toBlock: this._stateLayer,
|
||||
};
|
||||
this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
|
||||
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper, this._stateLayer),
|
||||
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper, eventFilter),
|
||||
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
|
||||
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
|
||||
this._onBlockAndLogStreamerError.bind(this),
|
||||
);
|
||||
const catchAllLogFilter = {};
|
||||
|
||||
@@ -61,6 +61,7 @@ interface OrderStateByOrderHash {
|
||||
|
||||
// tslint:disable-next-line:custom-no-magic-numbers
|
||||
const DEFAULT_CLEANUP_JOB_INTERVAL_MS = 1000 * 60 * 60; // 1h
|
||||
const STATE_LAYER = BlockParamLiteral.Latest;
|
||||
|
||||
/**
|
||||
* This class includes all the functionality related to watching a set of orders
|
||||
@@ -91,17 +92,15 @@ export class OrderWatcher {
|
||||
});
|
||||
this._contractWrappers = new ContractWrappers(provider, { networkId });
|
||||
const pollingIntervalIfExistsMs = _.isUndefined(config) ? undefined : config.eventPollingIntervalMs;
|
||||
const stateLayer =
|
||||
_.isUndefined(config) || _.isUndefined(config.stateLayer) ? BlockParamLiteral.Latest : config.stateLayer;
|
||||
const isVerbose = !_.isUndefined(config) && !_.isUndefined(config.isVerbose) ? config.isVerbose : false;
|
||||
this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, stateLayer, isVerbose);
|
||||
this._eventWatcher = new EventWatcher(this._web3Wrapper, pollingIntervalIfExistsMs, STATE_LAYER, isVerbose);
|
||||
this._balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
|
||||
this._contractWrappers.token,
|
||||
stateLayer,
|
||||
STATE_LAYER,
|
||||
);
|
||||
this._orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(
|
||||
this._contractWrappers.exchange,
|
||||
stateLayer,
|
||||
STATE_LAYER,
|
||||
);
|
||||
this._orderStateUtils = new OrderStateUtils(
|
||||
this._balanceAndProxyAllowanceLazyStore,
|
||||
|
||||
@@ -16,7 +16,6 @@ export type EventWatcherCallback = (err: null | Error, log?: LogEntryEvent) => v
|
||||
* stateLayer: Optional blockchain state layer OrderWatcher will monitor for new events. Default=latest.
|
||||
*/
|
||||
export interface OrderWatcherConfig {
|
||||
stateLayer: BlockParamLiteral;
|
||||
orderExpirationCheckingIntervalMs?: number;
|
||||
eventPollingIntervalMs?: number;
|
||||
expirationMarginMs?: number;
|
||||
|
||||
@@ -1 +1 @@
|
||||
Welcome to the [Web3Wrapper](https://github.com/0xProject/0x-monorepo/packages/web3-wrapper) documentation! Web3Wrapper is a convenience wrapper around Web3.js, adding support for promises and other niceties.
|
||||
Welcome to the [Web3Wrapper](https://github.com/0xProject/0x-monorepo/tree/development/packages/web3-wrapper) documentation! Web3-wrapper is a JSON-RPC client for Ethereum nodes. It is a type-safe alternative to [Web3.js](https://github.com/ethereum/web3.js/) written in TypeScript.
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
[
|
||||
{
|
||||
"version": "0.4.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add back ethers-contracts types for Aquaduct which relies on it",
|
||||
"pr": 885
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "0.4.2",
|
||||
"changes": [
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/typescript-typings#readme",
|
||||
"dependencies": {
|
||||
"@0xproject/types": "^0.8.2",
|
||||
"bignumber.js": "~4.1.0"
|
||||
"bignumber.js": "~4.1.0",
|
||||
"ethereum-types": "^0.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@0xproject/monorepo-scripts": "^0.2.2",
|
||||
|
||||
28
packages/typescript-typings/types/ethers-contracts/index.d.ts
vendored
Normal file
28
packages/typescript-typings/types/ethers-contracts/index.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
declare module 'ethers-contracts' {
|
||||
export interface TransactionDescription {
|
||||
name: string;
|
||||
signature: string;
|
||||
sighash: string;
|
||||
data: string;
|
||||
}
|
||||
export interface CallDescription extends TransactionDescription {
|
||||
parse: (...args: any[]) => any;
|
||||
}
|
||||
export interface FunctionDescription {
|
||||
(...params: any[]): TransactionDescription | CallDescription;
|
||||
inputs: { names: string[]; types: string[] };
|
||||
outputs: { names: string[]; types: string[] };
|
||||
}
|
||||
export interface EventDescription {
|
||||
parse: (...args: any[]) => any;
|
||||
inputs: { names: string[]; types: string[] };
|
||||
signature: string;
|
||||
topic: string;
|
||||
}
|
||||
export class Interface {
|
||||
public functions: { [functionName: string]: FunctionDescription };
|
||||
public events: { [eventName: string]: EventDescription };
|
||||
public static decodeParams(types: string[], data: string): any[];
|
||||
constructor(abi: any);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import { Web3WrapperErrors } from './types';
|
||||
const BASE_TEN = 10;
|
||||
|
||||
/**
|
||||
* A wrapper around the Web3.js 0.x library that provides a consistent, clean promise-based interface.
|
||||
* Web3Wrapper is a JSON-RPC client for Ethereum nodes. It provides a consistent, clean promise-based interface.
|
||||
*/
|
||||
export class Web3Wrapper {
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
Welcome to the [sol-compiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-compiler) documentation! Sol-compiler is a tool for compiling Solidity smart contracts and generating artifacts with ease.
|
||||
Welcome to the [sol-compiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-compiler) documentation! Sol-compiler is a wrapper around [solc-js](https://www.npmjs.com/package/solc) that adds:
|
||||
|
||||
It serves a similar purpose as parts of the [Truffle framework](http://truffleframework.com/), but with the UNIX philosophy in mind: Make each program do one thing well. This tool is for intermediate to advanced Solidity developers that require greater configurability and reliability.
|
||||
|
||||
Sol-compiler has the following advantages over Truffle:
|
||||
|
||||
* Compile each smart contract with a specific version of Solidity.
|
||||
* Improved artifact files:
|
||||
* Storage of constructor args, source maps and paths to all requisite source files.
|
||||
* An easy to maintain codebase: TypeScript + Single repo.
|
||||
* Supports Solidity version ranges - contract compiled with latest Solidity version that satisfies the range.
|
||||
|
||||
Sol-compiler can be used as a command-line tool or as an imported module.
|
||||
* Smart re-compilation: Only recompiles when smart contracts have changed
|
||||
* Ability to compile an entire project instead of only individual `.sol` files
|
||||
* Compilation using the Solidity version specified at the top of each individual `.sol` file
|
||||
* Proper parsing of Solidity version ranges
|
||||
* Support for the standard [input description](https://solidity.readthedocs.io/en/develop/using-the-compiler.html#input-description) for what information you'd like added to the resulting `artifacts` file (i.e 100% configurable artifacts content).
|
||||
* Storage of constructor args, source maps and paths to all dependency source files.
|
||||
|
||||
@@ -1 +1 @@
|
||||
Welcome to the [Web3Wrapper](https://github.com/0xProject/0x-monorepo/tree/development/packages/web3-wrapper) documentation! Web3Wrapper is a convenience library that wraps Web3 v0.x, providing promise-based endpoints and a consistent API.
|
||||
Welcome to the [Web3Wrapper](https://github.com/0xProject/0x-monorepo/tree/development/packages/web3-wrapper) documentation! Web3-wrapper is a JSON-RPC client for Ethereum nodes. It is a type-safe alternative to [Web3.js](https://github.com/ethereum/web3.js/) written in TypeScript.
|
||||
|
||||
Reference in New Issue
Block a user