diff options
35 files changed, 309 insertions, 264 deletions
diff --git a/CODEOWNERS b/CODEOWNERS index cecdc9327..b0a5366ed 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @abandeali1 @BMillman19 @dekz @fabioberger @LogvinovLeon @Remco +* @abandeali1 @BMillman19 @dekz @fabioberger @LogvinovLeon @Recmo diff --git a/package.json b/package.json index 4bc8dc0f8..5720d7a60 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic" }, "devDependencies": { - "@0xproject/utils": "^0.3.0", + "@0xproject/utils": "^0.3.1", "async-child-process": "^1.1.1", "ethereumjs-testrpc": "^6.0.3", "lerna": "^2.5.1", diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index 54c06444a..fa5bd6d4d 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## v0.32.1 - _February 7, 2018_ + + * Reorganized `BlockParamLiteral` export into `@0xproject/types` package (#355) + * Now using `abi-gen` package to generate ContractEventArgs types (#371) + ## v0.32.0 - _February 5, 2018_ * Add `zeroEx.etherToken.getContractAddressIfExists` (#350) diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index de18a1b2e..a42d3b9dd 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.32.0", + "version": "0.32.1", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -42,8 +42,8 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^0.1.7", - "@0xproject/dev-utils": "^0.0.10", + "@0xproject/abi-gen": "^0.2.0", + "@0xproject/dev-utils": "^0.0.11", "@0xproject/tslint-config": "^0.4.7", "@types/bintrees": "^1.0.2", "@types/jsonschema": "^1.1.1", @@ -81,11 +81,11 @@ "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.16", - "@0xproject/json-schemas": "^0.7.8", - "@0xproject/types": "^0.1.9", - "@0xproject/utils": "^0.3.0", - "@0xproject/web3-wrapper": "^0.1.10", + "@0xproject/assert": "^0.0.17", + "@0xproject/json-schemas": "^0.7.9", + "@0xproject/types": "^0.2.0", + "@0xproject/utils": "^0.3.1", + "@0xproject/web3-wrapper": "^0.1.11", "bintrees": "^1.0.2", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md index 570c76bdd..ac6d58e9c 100644 --- a/packages/abi-gen/CHANGELOG.md +++ b/packages/abi-gen/CHANGELOG.md @@ -1,9 +1,9 @@ # CHANGELOG -## v0.2.0 - _???_ +## v0.2.0 - _February 7, 2018_ * Added CLI options for explicit specifying location of partials and main template (#346) -* Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts +* Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts (#388) ## v0.1.0 - _January 11, 2018_ diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index 10bd7e712..17810a7f1 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/abi-gen", - "version": "0.1.7", + "version": "0.2.0", "description": "Generate contract wrappers from ABI and handlebars templates", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/abi-gen/README.md", "dependencies": { - "@0xproject/utils": "^0.3.0", + "@0xproject/utils": "^0.3.1", "chalk": "^2.3.0", "glob": "^7.1.2", "handlebars": "^4.0.11", diff --git a/packages/assert/package.json b/packages/assert/package.json index b8da740d6..7de27121f 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.16", + "version": "0.0.17", "description": "Provides a standard way of performing type and schema validation across 0x projects", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -38,8 +38,8 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/json-schemas": "^0.7.8", - "@0xproject/utils": "^0.3.0", + "@0xproject/json-schemas": "^0.7.9", + "@0xproject/utils": "^0.3.1", "lodash": "^4.17.4", "valid-url": "^1.0.9" } diff --git a/packages/connect/package.json b/packages/connect/package.json index d892e2d04..26ec44ae0 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.5.5", + "version": "0.5.6", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "connect", @@ -37,9 +37,9 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", "dependencies": { - "@0xproject/assert": "^0.0.16", - "@0xproject/json-schemas": "^0.7.8", - "@0xproject/utils": "^0.3.0", + "@0xproject/assert": "^0.0.17", + "@0xproject/json-schemas": "^0.7.9", + "@0xproject/utils": "^0.3.1", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", "query-string": "^5.0.1", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index af7441d85..0bc5080c7 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "contracts", - "version": "2.1.9", + "version": "2.1.10", "description": "Smart contract components of 0x protocol", "main": "index.js", "directories": { @@ -33,9 +33,9 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md", "devDependencies": { - "@0xproject/dev-utils": "^0.0.10", + "@0xproject/dev-utils": "^0.0.11", "@0xproject/tslint-config": "^0.4.7", - "@0xproject/types": "^0.1.9", + "@0xproject/types": "^0.2.0", "@types/bluebird": "^3.5.3", "@types/lodash": "^4.14.86", "@types/node": "^8.0.53", @@ -59,11 +59,11 @@ "yargs": "^10.0.3" }, "dependencies": { - "0x.js": "^0.32.0", - "@0xproject/deployer": "^0.0.6", - "@0xproject/json-schemas": "^0.7.8", - "@0xproject/utils": "^0.3.0", - "@0xproject/web3-wrapper": "^0.1.10", + "0x.js": "^0.32.1", + "@0xproject/deployer": "^0.0.7", + "@0xproject/json-schemas": "^0.7.9", + "@0xproject/utils": "^0.3.1", + "@0xproject/web3-wrapper": "^0.1.11", "bluebird": "^3.5.0", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", diff --git a/packages/deployer/package.json b/packages/deployer/package.json index 49e0ec26a..6564d89eb 100644 --- a/packages/deployer/package.json +++ b/packages/deployer/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/deployer", - "version": "0.0.6", + "version": "0.0.7", "description": "Smart contract deployer of 0x protocol", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -34,8 +34,8 @@ "web3-typescript-typings": "^0.9.9" }, "dependencies": { - "@0xproject/utils": "^0.3.0", - "@0xproject/web3-wrapper": "^0.1.10", + "@0xproject/utils": "^0.3.1", + "@0xproject/web3-wrapper": "^0.1.11", "lodash": "^4.17.4", "solc": "^0.4.18", "web3": "^0.20.0", diff --git a/packages/dev-utils/CHANGELOG.md b/packages/dev-utils/CHANGELOG.md new file mode 100644 index 000000000..00c022e8b --- /dev/null +++ b/packages/dev-utils/CHANGELOG.md @@ -0,0 +1,5 @@ +# CHANGELOG + +## v0.0.11 - _February 7, 2018_ + + * Updated `types-ethereumjs-util` dev dependency (#352) diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index 2a1fe26f2..4ebb9c7c8 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/dev-utils", - "version": "0.0.10", + "version": "0.0.11", "description": "0x dev TS utils", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -21,7 +21,7 @@ "homepage": "https://github.com/0xProject/0x.js/packages/dev-utils/README.md", "devDependencies": { "@0xproject/tslint-config": "^0.4.7", - "@0xproject/types": "^0.1.9", + "@0xproject/types": "^0.2.0", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -31,7 +31,7 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/utils": "^0.3.0", + "@0xproject/utils": "^0.3.1", "ethereumjs-util": "^5.1.2", "lodash": "^4.17.4", "request-promise-native": "^1.0.5", diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 02a8c1994..270b4d4e0 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.7.8", + "version": "0.7.9", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -29,7 +29,7 @@ }, "devDependencies": { "@0xproject/tslint-config": "^0.4.7", - "@0xproject/utils": "^0.3.0", + "@0xproject/utils": "^0.3.1", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md index 908272406..7876b2a4f 100644 --- a/packages/subproviders/CHANGELOG.md +++ b/packages/subproviders/CHANGELOG.md @@ -1,11 +1,11 @@ # CHANGELOG -## v0.4.1 - _Febuary 2, 2018_ +## v0.4.0 - _February 7, 2018_ * Added NonceTrackerSubprovider (#355) * InjectedWeb3Subprovider accepts a Provider in the constructor, previously it was a Web3 object (#363) -## v0.3.5 - _January 28, 2018_ +## v0.3.6 - _January 28, 2018_ * Return a transaction hash from `_sendTransactionAsync` (#303) diff --git a/packages/subproviders/README.md b/packages/subproviders/README.md index 0d8f85910..954729713 100644 --- a/packages/subproviders/README.md +++ b/packages/subproviders/README.md @@ -20,10 +20,10 @@ import { LedgerSubprovider, } from '@0xproject/subproviders'; -const ledgerSubprovider = new LedgerSubprovider( +const ledgerSubprovider = new LedgerSubprovider({ networkId, ledgerEthereumClientFactoryAsync, -); +}); const accounts = await ledgerSubprovider.getAccountsAsync(); ``` diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 76f7ab089..7cb721cdd 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/subproviders", - "version": "0.3.6", + "version": "0.4.0", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "license": "Apache-2.0", @@ -18,8 +18,8 @@ "test:integration": "run-s clean build run_mocha_integration" }, "dependencies": { - "@0xproject/assert": "^0.0.16", - "@0xproject/utils": "^0.3.0", + "@0xproject/assert": "^0.0.17", + "@0xproject/utils": "^0.3.1", "bn.js": "^4.11.8", "es6-promisify": "^5.0.0", "ethereumjs-tx": "^1.3.3", @@ -33,8 +33,8 @@ }, "devDependencies": { "@0xproject/tslint-config": "^0.4.7", - "@0xproject/types": "^0.1.9", - "@0xproject/utils": "^0.3.0", + "@0xproject/types": "^0.2.0", + "@0xproject/utils": "^0.3.1", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 3f052d91f..75b780d93 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@0xproject/testnet-faucets", - "version": "1.0.10", + "version": "1.0.11", "description": "A faucet micro-service that dispenses test ERC20 tokens or Ether", "main": "server.js", "scripts": { @@ -15,9 +15,9 @@ "author": "Fabio Berger", "license": "Apache-2.0", "dependencies": { - "0x.js": "^0.32.0", - "@0xproject/utils": "^0.3.0", - "@0xproject/subproviders": "^0.3.6", + "0x.js": "^0.32.1", + "@0xproject/subproviders": "^0.4.0", + "@0xproject/utils": "^0.3.1", "body-parser": "^1.17.1", "ethereumjs-tx": "^1.3.3", "ethereumjs-util": "^5.1.1", diff --git a/packages/testnet-faucets/src/ts/dispatch_queue.ts b/packages/testnet-faucets/src/ts/dispatch_queue.ts new file mode 100644 index 000000000..672511619 --- /dev/null +++ b/packages/testnet-faucets/src/ts/dispatch_queue.ts @@ -0,0 +1,54 @@ +import { intervalUtils } from '@0xproject/utils'; +import * as _ from 'lodash'; + +import { errorReporter } from './error_reporter'; +import { utils } from './utils'; + +const MAX_QUEUE_SIZE = 500; +const DEFAULT_QUEUE_INTERVAL_MS = 1000; + +export class DispatchQueue { + private _queueIntervalMs: number; + private _queue: Array<() => Promise<void>>; + private _queueIntervalIdIfExists?: NodeJS.Timer; + constructor() { + this._queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS; + this._queue = []; + this._start(); + } + public add(taskAsync: () => Promise<void>): boolean { + if (this.isFull()) { + return false; + } + this._queue.push(taskAsync); + return true; + } + public size(): number { + return this._queue.length; + } + public isFull(): boolean { + return this.size() >= MAX_QUEUE_SIZE; + } + public stop() { + if (!_.isUndefined(this._queueIntervalIdIfExists)) { + intervalUtils.clearAsyncExcludingInterval(this._queueIntervalIdIfExists); + } + } + private _start() { + this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( + async () => { + const taskAsync = this._queue.shift(); + if (_.isUndefined(taskAsync)) { + return Promise.resolve(); + } + await taskAsync(); + }, + this._queueIntervalMs, + (err: Error) => { + utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); + // tslint:disable-next-line:no-floating-promises + errorReporter.reportAsync(err); + }, + ); + } +} diff --git a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts new file mode 100644 index 000000000..9aa47463c --- /dev/null +++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts @@ -0,0 +1,44 @@ +import { ZeroEx } from '0x.js'; +import { BigNumber, promisify } from '@0xproject/utils'; +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import { configs } from './configs'; +import { errorReporter } from './error_reporter'; +import { utils } from './utils'; + +const DISPENSE_AMOUNT_ETHER = 0.1; +const DISPENSE_AMOUNT_TOKEN = 0.1; + +export const dispenseAssetTasks = { + dispenseEtherTask(recipientAddress: string, web3: Web3) { + return async () => { + utils.consoleLog(`Processing ETH ${recipientAddress}`); + const sendTransactionAsync = promisify(web3.eth.sendTransaction); + const txHash = await sendTransactionAsync({ + from: configs.DISPENSER_ADDRESS, + to: recipientAddress, + value: web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'), + }); + utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); + }; + }, + dispenseTokenTask(recipientAddress: string, tokenSymbol: string, zeroEx: ZeroEx) { + return async () => { + utils.consoleLog(`Processing ${tokenSymbol} ${recipientAddress}`); + const amountToDispense = new BigNumber(DISPENSE_AMOUNT_TOKEN); + const token = await zeroEx.tokenRegistry.getTokenBySymbolIfExistsAsync(tokenSymbol); + if (_.isUndefined(token)) { + throw new Error(`Unsupported asset type: ${tokenSymbol}`); + } + const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals); + const txHash = await zeroEx.token.transferAsync( + token.address, + configs.DISPENSER_ADDRESS, + recipientAddress, + baseUnitAmount, + ); + utils.consoleLog(`Sent ${amountToDispense} ZRX to ${recipientAddress} tx: ${txHash}`); + }; + }, +}; diff --git a/packages/testnet-faucets/src/ts/error_reporter.ts b/packages/testnet-faucets/src/ts/error_reporter.ts index 6865d3893..7fd76bde5 100644 --- a/packages/testnet-faucets/src/ts/error_reporter.ts +++ b/packages/testnet-faucets/src/ts/error_reporter.ts @@ -9,9 +9,7 @@ export const errorReporter = { rollbar.init(configs.ROLLBAR_ACCESS_KEY, { environment: configs.ENVIRONMENT, }); - rollbar.handleUncaughtExceptions(configs.ROLLBAR_ACCESS_KEY); - process.on('unhandledRejection', async (err: Error) => { utils.consoleLog(`Uncaught exception ${err}. Stack: ${err.stack}`); await this.reportAsync(err); @@ -22,7 +20,6 @@ export const errorReporter = { if (configs.ENVIRONMENT === 'development') { return; // Do not log development environment errors } - return new Promise((resolve, reject) => { rollbar.handleError(err, req, (rollbarErr: Error) => { if (rollbarErr) { diff --git a/packages/testnet-faucets/src/ts/ether_request_queue.ts b/packages/testnet-faucets/src/ts/ether_request_queue.ts deleted file mode 100644 index 710d49f39..000000000 --- a/packages/testnet-faucets/src/ts/ether_request_queue.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { promisify } from '@0xproject/utils'; -import * as _ from 'lodash'; - -import { configs } from './configs'; -import { errorReporter } from './error_reporter'; -import { RequestQueue } from './request_queue'; -import { utils } from './utils'; - -const DISPENSE_AMOUNT_ETHER = 0.1; - -export class EtherRequestQueue extends RequestQueue { - protected async _processNextRequestFireAndForgetAsync(recipientAddress: string) { - utils.consoleLog(`Processing ETH ${recipientAddress}`); - const sendTransactionAsync = promisify(this._web3.eth.sendTransaction); - try { - const txHash = await sendTransactionAsync({ - from: configs.DISPENSER_ADDRESS, - to: recipientAddress, - value: this._web3.toWei(DISPENSE_AMOUNT_ETHER, 'ether'), - }); - utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ETHER} ETH to ${recipientAddress} tx: ${txHash}`); - } catch (err) { - utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); - await errorReporter.reportAsync(err); - } - } -} diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index d96b90802..5ed9ce628 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -1,5 +1,4 @@ import { Order, SignedOrder, ZeroEx } from '0x.js'; -import { NonceTrackerSubprovider } from '@0xproject/subproviders'; import { BigNumber } from '@0xproject/utils'; import * as express from 'express'; import * as _ from 'lodash'; @@ -10,17 +9,23 @@ import * as Web3 from 'web3'; // we are not running in a browser env. // Filed issue: https://github.com/ethereum/web3.js/issues/844 (global as any).XMLHttpRequest = undefined; +import { NonceTrackerSubprovider } from '@0xproject/subproviders'; import ProviderEngine = require('web3-provider-engine'); import HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { configs } from './configs'; -import { EtherRequestQueue } from './ether_request_queue'; +import { DispatchQueue } from './dispatch_queue'; +import { dispenseAssetTasks } from './dispense_asset_tasks'; import { idManagement } from './id_management'; -import { RequestQueue } from './request_queue'; import { rpcUrls } from './rpc_urls'; import { utils } from './utils'; -import { ZRXRequestQueue } from './zrx_request_queue'; + +interface NetworkConfig { + dispatchQueue: DispatchQueue; + web3: Web3; + zeroEx: ZeroEx; +} interface ItemByNetworkId<T> { [networkId: string]: T; @@ -35,30 +40,7 @@ enum RequestedAssetType { const FIVE_DAYS_IN_MS = 4.32e8; // TODO: make this configurable export class Handler { - private _zeroExByNetworkId: ItemByNetworkId<ZeroEx> = {}; - private _etherRequestQueueByNetworkId: ItemByNetworkId<RequestQueue> = {}; - private _zrxRequestQueueByNetworkId: ItemByNetworkId<RequestQueue> = {}; - private static _dispenseAsset( - req: express.Request, - res: express.Response, - requestQueueByNetworkId: ItemByNetworkId<RequestQueue>, - requestedAssetType: RequestedAssetType, - ) { - const requestQueue = _.get(requestQueueByNetworkId, req.params.networkId); - if (_.isUndefined(requestQueue)) { - res.status(400).send('UNSUPPORTED_NETWORK_ID'); - return; - } - const didAddToQueue = requestQueue.add(req.params.recipient); - if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); - return; - } - utils.consoleLog( - `Added ${req.params.recipient} to queue: ${requestedAssetType} networkId: ${req.params.networkId}`, - ); - res.status(200).end(); - } + private _networkConfigByNetworkId: ItemByNetworkId<NetworkConfig> = {}; private static _createProviderEngine(rpcUrl: string) { const engine = new ProviderEngine(); engine.addProvider(new NonceTrackerSubprovider()); @@ -79,35 +61,31 @@ export class Handler { networkId: +networkId, }; const zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); - this._zeroExByNetworkId[networkId] = zeroEx; - this._etherRequestQueueByNetworkId[networkId] = new EtherRequestQueue(web3); - this._zrxRequestQueueByNetworkId[networkId] = new ZRXRequestQueue(web3, zeroEx); + const dispatchQueue = new DispatchQueue(); + this._networkConfigByNetworkId[networkId] = { + dispatchQueue, + web3, + zeroEx, + }; }); } public getQueueInfo(req: express.Request, res: express.Response) { res.setHeader('Content-Type', 'application/json'); const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { - const etherRequestQueue = this._etherRequestQueueByNetworkId[networkId]; - const zrxRequestQueue = this._zrxRequestQueueByNetworkId[networkId]; + const dispatchQueue = this._networkConfigByNetworkId[networkId].dispatchQueue; return { - ether: { - full: etherRequestQueue.isFull(), - size: etherRequestQueue.size(), - }, - zrx: { - full: zrxRequestQueue.isFull(), - size: zrxRequestQueue.size(), - }, + full: dispatchQueue.isFull(), + size: dispatchQueue.size(), }; }); const payload = JSON.stringify(queueInfo); res.status(200).send(payload); } public dispenseEther(req: express.Request, res: express.Response) { - Handler._dispenseAsset(req, res, this._etherRequestQueueByNetworkId, RequestedAssetType.ETH); + this._dispenseAsset(req, res, RequestedAssetType.ETH); } public dispenseZRX(req: express.Request, res: express.Response) { - Handler._dispenseAsset(req, res, this._zrxRequestQueueByNetworkId, RequestedAssetType.ZRX); + this._dispenseAsset(req, res, RequestedAssetType.ZRX); } public async dispenseWETHOrder(req: express.Request, res: express.Response) { await this._dispenseOrder(req, res, RequestedAssetType.WETH); @@ -115,12 +93,41 @@ export class Handler { public async dispenseZRXOrder(req: express.Request, res: express.Response, next: express.NextFunction) { await this._dispenseOrder(req, res, RequestedAssetType.ZRX); } + private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + const networkId = req.params.networkId; + const recipient = req.params.recipient; + const networkConfig = this._networkConfigByNetworkId[networkId]; + let dispenserTask; + switch (requestedAssetType) { + case RequestedAssetType.ETH: + dispenserTask = dispenseAssetTasks.dispenseEtherTask(recipient, networkConfig.web3); + break; + case RequestedAssetType.WETH: + case RequestedAssetType.ZRX: + dispenserTask = dispenseAssetTasks.dispenseTokenTask( + recipient, + requestedAssetType, + networkConfig.zeroEx, + ); + break; + default: + throw new Error(`Unsupported asset type: ${requestedAssetType}`); + } + const didAddToQueue = networkConfig.dispatchQueue.add(dispenserTask); + if (!didAddToQueue) { + res.status(503).send('QUEUE_IS_FULL'); + return; + } + utils.consoleLog(`Added ${recipient} to queue: ${requestedAssetType} networkId: ${networkId}`); + res.status(200).end(); + } private async _dispenseOrder(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { - const zeroEx = _.get(this._zeroExByNetworkId, req.params.networkId); - if (_.isUndefined(zeroEx)) { + const networkConfig = _.get(this._networkConfigByNetworkId, req.params.networkId); + if (_.isUndefined(networkConfig)) { res.status(400).send('UNSUPPORTED_NETWORK_ID'); return; } + const zeroEx = networkConfig.zeroEx; res.setHeader('Content-Type', 'application/json'); const makerTokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(requestedAssetType); if (_.isUndefined(makerTokenAddress)) { diff --git a/packages/testnet-faucets/src/ts/request_queue.ts b/packages/testnet-faucets/src/ts/request_queue.ts deleted file mode 100644 index f128528a5..000000000 --- a/packages/testnet-faucets/src/ts/request_queue.ts +++ /dev/null @@ -1,51 +0,0 @@ -import * as _ from 'lodash'; -import * as timers from 'timers'; - -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Filed issue: https://github.com/ethereum/web3.js/issues/844 -// tslint:disable-next-line:ordered-imports -import * as Web3 from 'web3'; - -const MAX_QUEUE_SIZE = 500; -const DEFAULT_QUEUE_INTERVAL_MS = 1000; - -export class RequestQueue { - protected _queueIntervalMs: number; - protected _queue: string[]; - protected _queueIntervalId?: NodeJS.Timer; - protected _web3: Web3; - constructor(web3: any) { - this._queueIntervalMs = DEFAULT_QUEUE_INTERVAL_MS; - this._queue = []; - this._web3 = web3; - this._start(); - } - public add(recipientAddress: string): boolean { - if (this.isFull()) { - return false; - } - this._queue.push(recipientAddress); - return true; - } - public size(): number { - return this._queue.length; - } - public isFull(): boolean { - return this.size() >= MAX_QUEUE_SIZE; - } - protected _start() { - this._queueIntervalId = timers.setInterval(() => { - const recipientAddress = this._queue.shift(); - if (_.isUndefined(recipientAddress)) { - return; - } - // tslint:disable-next-line:no-floating-promises - this._processNextRequestFireAndForgetAsync(recipientAddress); - }, this._queueIntervalMs); - } - // tslint:disable-next-line:prefer-function-over-method - protected async _processNextRequestFireAndForgetAsync(recipientAddress: string) { - throw new Error('Expected processNextRequestFireAndForgetAsync to be implemented by a subclass'); - } -} diff --git a/packages/testnet-faucets/src/ts/rpc_urls.ts b/packages/testnet-faucets/src/ts/rpc_urls.ts index 25a3b938f..f8a57e171 100644 --- a/packages/testnet-faucets/src/ts/rpc_urls.ts +++ b/packages/testnet-faucets/src/ts/rpc_urls.ts @@ -1,8 +1,8 @@ import { configs } from './configs'; const productionRpcUrls = { - '2': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, - '3': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, + '3': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, + '4': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, '42': `https://kovan.infura.io/${configs.INFURA_API_KEY}`, }; diff --git a/packages/testnet-faucets/src/ts/zrx_request_queue.ts b/packages/testnet-faucets/src/ts/zrx_request_queue.ts deleted file mode 100644 index 3659f4856..000000000 --- a/packages/testnet-faucets/src/ts/zrx_request_queue.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ZeroEx } from '0x.js'; -import { BigNumber } from '@0xproject/utils'; -import * as _ from 'lodash'; - -import { configs } from './configs'; -import { errorReporter } from './error_reporter'; -import { RequestQueue } from './request_queue'; -import { utils } from './utils'; - -// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang -// because they are using the wrong XHR package. -// Filed issue: https://github.com/ethereum/web3.js/issues/844 -// tslint:disable-next-line:ordered-imports -import * as Web3 from 'web3'; - -const DISPENSE_AMOUNT_ZRX = new BigNumber(0.1); -const QUEUE_INTERVAL_MS = 5000; - -export class ZRXRequestQueue extends RequestQueue { - private _zeroEx: ZeroEx; - constructor(web3: Web3, zeroEx: ZeroEx) { - super(web3); - this._queueIntervalMs = QUEUE_INTERVAL_MS; - this._zeroEx = zeroEx; - } - protected async _processNextRequestFireAndForgetAsync(recipientAddress: string) { - utils.consoleLog(`Processing ZRX ${recipientAddress}`); - const baseUnitAmount = ZeroEx.toBaseUnitAmount(DISPENSE_AMOUNT_ZRX, 18); - try { - const zrxTokenAddress = this._zeroEx.exchange.getZRXTokenAddress(); - const txHash = await this._zeroEx.token.transferAsync( - zrxTokenAddress, - configs.DISPENSER_ADDRESS, - recipientAddress, - baseUnitAmount, - ); - utils.consoleLog(`Sent ${DISPENSE_AMOUNT_ZRX} ZRX to ${recipientAddress} tx: ${txHash}`); - } catch (err) { - utils.consoleLog(`Unexpected err: ${err} - ${JSON.stringify(err)}`); - await errorReporter.reportAsync(err); - } - } -} diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index e75d0ddcb..316d92713 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,5 +1,5 @@ # CHANGELOG -## vx.x.x +## v0.2.0 - _February 7, 2018_ * Added BlockLiteralParam and BlockParam, refactored out of 0x.js types. (#355) diff --git a/packages/types/package.json b/packages/types/package.json index 6d8e93cfd..6b5d7f82e 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/types", - "version": "0.1.9", + "version": "0.2.0", "description": "0x types", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/utils/package.json b/packages/utils/package.json index 2a434d79a..f25295754 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/utils", - "version": "0.3.0", + "version": "0.3.1", "description": "0x TS utils", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -21,7 +21,7 @@ "homepage": "https://github.com/0xProject/0x.js/packages/utils/README.md", "devDependencies": { "@0xproject/tslint-config": "^0.4.7", - "@0xproject/types": "^0.1.9", + "@0xproject/types": "^0.2.0", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index 33d2fde20..49342ed92 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/web3-wrapper", - "version": "0.1.10", + "version": "0.1.11", "description": "Wraps around web3 and gives a nicer interface", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -21,7 +21,7 @@ "homepage": "https://github.com/0xProject/0x.js/packages/web3-wrapper/README.md", "devDependencies": { "@0xproject/tslint-config": "^0.4.7", - "@0xproject/types": "^0.1.9", + "@0xproject/types": "^0.2.0", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -30,7 +30,7 @@ "web3-typescript-typings": "^0.9.9" }, "dependencies": { - "@0xproject/utils": "^0.3.0", + "@0xproject/utils": "^0.3.1", "lodash": "^4.17.4", "web3": "^0.20.0" } diff --git a/packages/website/less/all.less b/packages/website/less/all.less index 5212df959..7f2a8fc67 100644 --- a/packages/website/less/all.less +++ b/packages/website/less/all.less @@ -21,14 +21,19 @@ a { } #landing { - .h1, .h2, .h3, .h4 { + .h1, + .h2, + .h3, + .h4 { font-family: 'Roboto Mono'; } } - #portal { - h1, h2, h3, h4 { + h1, + h2, + h3, + h4 { font-weight: 100; } } @@ -55,13 +60,13 @@ a { * Source: https://davidwalsh.name/osx-overflow */ ::-webkit-scrollbar { - -webkit-appearance: none; - width: 7px; + -webkit-appearance: none; + width: 7px; } ::-webkit-scrollbar-thumb { - border-radius: 4px; - background-color: rgba(0, 0, 0, .5); - -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, .5); + border-radius: 4px; + background-color: rgba(0, 0, 0, 0.5); + -webkit-box-shadow: 0 0 1px rgba(255, 255, 255, 0.5); } // Hack: For some reason the animation applied to the material-ui textfield causes the overflow @@ -87,18 +92,24 @@ code { &.hljs { background-color: #dde4e9 !important; // blue gray - border-left: 5px solid #0091EA !important; // colors.lightBlueA700 + border-left: 5px solid #0091ea !important; // colors.lightBlueA700 padding: 30px; } } #wiki { - p, blockquote, ul, ol, dl, li, table, pre { + p, + blockquote, + ol, + dl, + li, + table, + pre { margin: 15px 0; } - ol, ul { - padding-bottom: 20px; + li { + margin: 5px 0; } table { @@ -127,10 +138,12 @@ code { margin: 0; padding: 6px 13px; } - table tr th :first-child, table tr td :first-child { + table tr th :first-child, + table tr td :first-child { margin-top: 0; } - table tr th :last-child, table tr td :last-child { + table tr th :last-child, + table tr td :last-child { margin-bottom: 0; } } diff --git a/packages/website/package.json b/packages/website/package.json index f7d0ab978..c8fc78474 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/website", - "version": "0.0.12", + "version": "0.0.13", "private": true, "description": "Website and 0x portal dapp", "scripts": { @@ -18,9 +18,9 @@ "author": "Fabio Berger", "license": "Apache-2.0", "dependencies": { - "0x.js": "^0.32.0", - "@0xproject/subproviders": "^0.3.6", - "@0xproject/utils": "^0.3.0", + "0x.js": "^0.32.1", + "@0xproject/subproviders": "^0.4.0", + "@0xproject/utils": "^0.3.1", "accounting": "^0.4.1", "basscss": "^8.0.3", "blockies": "^0.0.2", diff --git a/packages/website/ts/components/token_balances.tsx b/packages/website/ts/components/token_balances.tsx index dfb62bbb3..894edf0a8 100644 --- a/packages/website/ts/components/token_balances.tsx +++ b/packages/website/ts/components/token_balances.tsx @@ -118,7 +118,8 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala if (nextProps.userEtherBalance !== this.props.userEtherBalance) { if (this.state.isBalanceSpinnerVisible) { const receivedAmount = nextProps.userEtherBalance.minus(this.props.userEtherBalance); - this.props.dispatcher.showFlashMessage(`Received ${receivedAmount.toString(10)} Kovan Ether`); + const networkName = constants.NETWORK_NAME_BY_ID[this.props.networkId]; + this.props.dispatcher.showFlashMessage(`Received ${receivedAmount.toString(10)} ${networkName} Ether`); } this.setState({ isBalanceSpinnerVisible: false, @@ -176,13 +177,14 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala onTouchTap={this._onDharmaDialogToggle.bind(this, false)} />, ]; + const isTestNetwork = utils.isTestNetwork(this.props.networkId); const isKovanTestNetwork = this.props.networkId === constants.NETWORK_ID_KOVAN; const dharmaButtonColumnStyle = { paddingLeft: 3, display: isKovanTestNetwork ? 'table-cell' : 'none', }; const stubColumnStyle = { - display: isKovanTestNetwork ? 'none' : 'table-cell', + display: isTestNetwork ? 'none' : 'table-cell', }; const allTokenRowHeight = _.size(this.props.tokenByAddress) * TOKEN_TABLE_ROW_HEIGHT; const tokenTableHeight = @@ -201,10 +203,10 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala smart contract so you can start trading that token.'; return ( <div className="lg-px4 md-px4 sm-px1 pb2"> - <h3>{isKovanTestNetwork ? 'Test ether' : 'Ether'}</h3> + <h3>{isTestNetwork ? 'Test ether' : 'Ether'}</h3> <Divider /> <div className="pt2 pb2"> - {isKovanTestNetwork + {isTestNetwork ? 'In order to try out the 0x Portal Dapp, request some test ether to pay for \ gas costs. It might take a bit of time for the test ether to show up.' : 'Ether must be converted to Ether Tokens in order to be tradable via 0x. \ @@ -216,7 +218,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala <TableHeaderColumn>Currency</TableHeaderColumn> <TableHeaderColumn>Balance</TableHeaderColumn> <TableRowColumn className="sm-hide xs-hide" style={stubColumnStyle} /> - {isKovanTestNetwork && ( + {isTestNetwork && ( <TableHeaderColumn style={{ paddingLeft: 3 }}> {isSmallScreen ? 'Faucet' : 'Request from faucet'} </TableHeaderColumn> @@ -243,7 +245,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala )} </TableRowColumn> <TableRowColumn className="sm-hide xs-hide" style={stubColumnStyle} /> - {isKovanTestNetwork && ( + {isTestNetwork && ( <TableRowColumn style={{ paddingLeft: 3 }}> <LifeCycleRaisedButton labelReady="Request" @@ -267,7 +269,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala </Table> <div className="clearfix" style={{ paddingBottom: 1 }}> <div className="col col-10"> - <h3 className="pt2">{isKovanTestNetwork ? 'Test tokens' : 'Tokens'}</h3> + <h3 className="pt2">{isTestNetwork ? 'Test tokens' : 'Tokens'}</h3> </div> <div className="col col-1 pt3 align-right"> <FloatingActionButton mini={true} zDepth={0} onClick={this._onAddTokenClicked.bind(this)}> @@ -282,7 +284,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala </div> <Divider /> <div className="pt2 pb2"> - {isKovanTestNetwork + {isTestNetwork ? "Mint some test tokens you'd like to use to generate or fill an order using 0x." : "Set trading permissions for a token you'd like to start trading."} </div> @@ -362,8 +364,13 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala EtherscanLinkSuffixes.Address, ); const isMintable = - _.includes(configs.SYMBOLS_OF_MINTABLE_TOKENS, token.symbol) && - this.props.networkId !== constants.NETWORK_ID_MAINNET; + (_.includes(configs.SYMBOLS_OF_MINTABLE_KOVAN_TOKENS, token.symbol) && + this.props.networkId === constants.NETWORK_ID_BY_NAME[Networks.Kovan]) || + (_.includes(configs.SYMBOLS_OF_MINTABLE_RINKEBY_ROPSTEN_TOKENS, token.symbol) && + _.includes( + [constants.NETWORK_ID_BY_NAME[Networks.Rinkeby], constants.NETWORK_ID_BY_NAME[Networks.Ropsten]], + this.props.networkId, + )); return ( <TableRow key={token.address} style={{ height: TOKEN_TABLE_ROW_HEIGHT }}> <TableRowColumn colSpan={tokenColSpan}> @@ -413,7 +420,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala /> )} {token.symbol === ZRX_TOKEN_SYMBOL && - this.props.networkId === constants.NETWORK_ID_KOVAN && ( + utils.isTestNetwork(this.props.networkId) && ( <LifeCycleRaisedButton labelReady="Request" labelLoading="Sending..." @@ -498,9 +505,8 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala case BalanceErrs.incorrectNetworkForFaucet: return ( <div> - Our faucet can only send test Ether to addresses on the {Networks.Kovan} testnet (networkId{' '} - {constants.NETWORK_ID_KOVAN}). Please make sure you are connected to the {Networks.Kovan}{' '} - testnet and try requesting ether again. + Our faucet can only send test Ether to addresses on testnets. Please make sure you are connected + to a testnet and try requesting again. </div> ); @@ -589,7 +595,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala // If on another network other then the testnet our faucet serves test ether // from, we must show user an error message - if (this.props.blockchain.networkId !== constants.NETWORK_ID_KOVAN) { + if (!utils.isTestNetwork(this.props.blockchain.networkId)) { this.setState({ errorType: BalanceErrs.incorrectNetworkForFaucet, }); @@ -599,7 +605,9 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala await utils.sleepAsync(ARTIFICIAL_FAUCET_REQUEST_DELAY); const segment = isEtherRequest ? 'ether' : 'zrx'; - const response = await fetch(`${constants.URL_ETHER_FAUCET}/${segment}/${this.props.userAddress}`); + const response = await fetch( + `${constants.URL_TESTNET_FAUCET}/${segment}/${this.props.userAddress}?networkId=${this.props.networkId}`, + ); const responseBody = await response.text(); if (response.status !== constants.SUCCESS_STATUS) { utils.consoleLog(`Unexpected status code: ${response.status} -> ${responseBody}`); diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts index 874ad04c2..69773eae7 100644 --- a/packages/website/ts/utils/configs.ts +++ b/packages/website/ts/utils/configs.ts @@ -124,5 +124,27 @@ export const configs = { [4]: [`https://rinkeby.infura.io/${INFURA_API_KEY}`], } as PublicNodeUrlsByNetworkId, SHOULD_DEPRECATE_OLD_WETH_TOKEN: true, - SYMBOLS_OF_MINTABLE_TOKENS: ['MKR', 'MLN', 'GNT', 'DGD', 'REP'], + SYMBOLS_OF_MINTABLE_KOVAN_TOKENS: ['MKR', 'MLN', 'GNT', 'DGD', 'REP'], + SYMBOLS_OF_MINTABLE_RINKEBY_ROPSTEN_TOKENS: [ + 'TKN0', + 'TKN1', + 'TKN2', + 'TKN3', + 'TKN4', + 'TKN5', + 'TKN6', + 'TKN7', + 'TKN8', + 'TKN9', + 'TKN10', + 'TKN11', + 'TKN12', + 'TKN13', + 'TKN14', + 'TKN15', + 'TKN16', + 'TKN17', + 'TKN18', + 'TKN19', + ], }; diff --git a/packages/website/ts/utils/constants.ts b/packages/website/ts/utils/constants.ts index 26a793f38..3df4c9370 100644 --- a/packages/website/ts/utils/constants.ts +++ b/packages/website/ts/utils/constants.ts @@ -69,7 +69,7 @@ export const constants = { URL_BLOG: 'https://blog.0xproject.com/latest', URL_DISCOURSE_FORUM: 'https://forum.0xproject.com', URL_FIREFOX_U2F_ADDON: 'https://addons.mozilla.org/en-US/firefox/addon/u2f-support-add-on/', - URL_ETHER_FAUCET: 'https://faucet.0xproject.com', + URL_TESTNET_FAUCET: 'https://faucet.0xproject.com', URL_GITHUB_ORG: 'https://github.com/0xProject', URL_GITHUB_WIKI: 'https://github.com/0xProject/wiki', URL_METAMASK_CHROME_STORE: 'https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn', diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 7e69b1c5f..a7865d41b 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -282,4 +282,15 @@ export const utils = { isTestRpc(nodeVersion: string): boolean { return _.includes(nodeVersion, 'TestRPC'); }, + isTestNetwork(networkId: number): boolean { + const isTestNetwork = _.includes( + [ + constants.NETWORK_ID_BY_NAME[Networks.Kovan], + constants.NETWORK_ID_BY_NAME[Networks.Rinkeby], + constants.NETWORK_ID_BY_NAME[Networks.Ropsten], + ], + networkId, + ); + return isTestNetwork; + }, }; |