From 44162811bd57afb89e5d052a2d9db25007cc1463 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 26 Jan 2018 09:40:42 -0800 Subject: Add order signing and dispensing ability to faucet --- packages/testnet-faucets/package.json | 3 + packages/testnet-faucets/src/ts/global.d.ts | 8 ++ packages/testnet-faucets/src/ts/handler.ts | 116 +++++++++++++++------ packages/testnet-faucets/src/ts/id_management.ts | 16 ++- .../testnet-faucets/src/ts/parameter_extractor.ts | 34 ++++++ packages/testnet-faucets/src/ts/server.ts | 7 +- .../testnet-faucets/src/ts/zrx_request_queue.ts | 7 +- packages/testnet-faucets/tsconfig.json | 7 +- yarn.lock | 8 ++ 9 files changed, 167 insertions(+), 39 deletions(-) create mode 100644 packages/testnet-faucets/src/ts/parameter_extractor.ts diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 3b42ebb3e..9f1c1e88d 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -18,6 +18,7 @@ "@0xproject/utils": "^0.2.3", "body-parser": "^1.17.1", "ethereumjs-tx": "^1.3.3", + "ethereumjs-util": "^5.1.1", "express": "^4.15.2", "lodash": "^4.17.4", "rollbar": "^0.6.5", @@ -35,6 +36,8 @@ "shx": "^0.2.2", "source-map-loader": "^0.1.6", "tslint": "5.8.0", + "types-bn": "^0.0.1", + "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "~2.6.1", "web3-typescript-typings": "^0.9.7", "webpack": "^3.1.0", diff --git a/packages/testnet-faucets/src/ts/global.d.ts b/packages/testnet-faucets/src/ts/global.d.ts index 97cd35680..af9534377 100644 --- a/packages/testnet-faucets/src/ts/global.d.ts +++ b/packages/testnet-faucets/src/ts/global.d.ts @@ -24,3 +24,11 @@ declare module 'ethereumjs-tx' { } export = EthereumTx; } + +// Define extra params on Request for parameter extraction in middleware +declare namespace Express { + export interface Request { + recipientAddress: string; + networkId: string; + } +} diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index bf5b3e81e..7883cefd8 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -1,11 +1,20 @@ -import { addressUtils } from '@0xproject/utils'; +import { Order, SignedOrder, ZeroEx } from '0x.js'; +import { BigNumber } from '@0xproject/utils'; import * as express from 'express'; import * as _ from 'lodash'; + +// HACK: web3 injects XMLHttpRequest into the global scope and ProviderEngine checks XMLHttpRequest +// to know whether it is running in a browser or node environment. We need it to be undefined since +// we are not running in a browser env. +// Filed issue: https://github.com/ethereum/web3.js/issues/844 +(global as any).XMLHttpRequest = undefined; + import ProviderEngine = require('web3-provider-engine'); import HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet'); import NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); +import { configs } from './configs'; import { EtherRequestQueue } from './ether_request_queue'; import { idManagement } from './id_management'; import { RequestQueue } from './request_queue'; @@ -19,32 +28,38 @@ import { ZRXRequestQueue } from './zrx_request_queue'; // tslint:disable-next-line:ordered-imports import * as Web3 from 'web3'; -interface RequestQueueByNetworkId { - [networkId: string]: RequestQueue; +interface ItemByNetworkId { + [networkId: string]: T; } -enum QueueType { +enum RequestedAssetType { ETH = 'ETH', + WETH = 'WETH', ZRX = 'ZRX', } -const DEFAULT_NETWORK_ID = 42; // kovan +const TWO_DAYS_IN_MS = 1.728e8; // TODO: make this configurable export class Handler { - private _etherRequestQueueByNetworkId: RequestQueueByNetworkId = {}; - private _zrxRequestQueueByNetworkId: RequestQueueByNetworkId = {}; + private _zeroExByNetworkId: ItemByNetworkId = {}; + private _etherRequestQueueByNetworkId: ItemByNetworkId = {}; + private _zrxRequestQueueByNetworkId: ItemByNetworkId = {}; constructor() { _.forIn(rpcUrls, (rpcUrl: string, networkId: string) => { const providerObj = this._createProviderEngine(rpcUrl); const web3 = new Web3(providerObj); + const zeroExConfig = { + 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, +networkId); + this._zrxRequestQueueByNetworkId[networkId] = new ZRXRequestQueue(web3, zeroEx); }); } public getQueueInfo(req: express.Request, res: express.Response) { res.setHeader('Content-Type', 'application/json'); const queueInfo = _.mapValues(rpcUrls, (rpcUrl: string, networkId: string) => { - utils.consoleLog(networkId); const etherRequestQueue = this._etherRequestQueueByNetworkId[networkId]; const zrxRequestQueue = this._zrxRequestQueueByNetworkId[networkId]; return { @@ -62,37 +77,83 @@ export class Handler { res.status(200).send(payload); } public dispenseEther(req: express.Request, res: express.Response) { - this._dispense(req, res, this._etherRequestQueueByNetworkId, QueueType.ETH); + this._dispenseAsset(req, res, this._etherRequestQueueByNetworkId, RequestedAssetType.ETH); } public dispenseZRX(req: express.Request, res: express.Response) { - this._dispense(req, res, this._zrxRequestQueueByNetworkId, QueueType.ZRX); + this._dispenseAsset(req, res, this._zrxRequestQueueByNetworkId, RequestedAssetType.ZRX); + } + public async dispenseWETHOrder(req: express.Request, res: express.Response) { + await this._dispenseOrder(req, res, RequestedAssetType.WETH); } - private _dispense( + public async dispenseZRXOrder(req: express.Request, res: express.Response, next: express.NextFunction) { + await this._dispenseOrder(req, res, RequestedAssetType.ZRX); + } + // tslint:disable-next-line:prefer-function-over-method + private _dispenseAsset( req: express.Request, res: express.Response, - requestQueueByNetworkId: RequestQueueByNetworkId, - queueType: QueueType, + requestQueueByNetworkId: ItemByNetworkId, + requestedAssetType: RequestedAssetType, ) { - const recipientAddress = req.params.recipient; - if (_.isUndefined(recipientAddress) || !this._isValidEthereumAddress(recipientAddress)) { - res.status(400).send('INVALID_RECIPIENT_ADDRESS'); - return; - } - const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); - const requestQueue = _.get(requestQueueByNetworkId, networkId); + const requestQueue = _.get(requestQueueByNetworkId, req.networkId); if (_.isUndefined(requestQueue)) { - res.status(400).send('INVALID_NETWORK_ID'); + res.status(400).send('UNSUPPORTED_NETWORK_ID'); return; } - const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); - const didAddToQueue = requestQueue.add(lowerCaseRecipientAddress); + const didAddToQueue = requestQueue.add(req.recipientAddress); if (!didAddToQueue) { res.status(503).send('QUEUE_IS_FULL'); return; } - utils.consoleLog(`Added ${lowerCaseRecipientAddress} to queue: ${queueType} networkId: ${networkId}`); + utils.consoleLog(`Added ${req.recipientAddress} to queue: ${requestedAssetType} networkId: ${req.networkId}`); res.status(200).end(); } + private async _dispenseOrder(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { + const zeroEx = _.get(this._zeroExByNetworkId, req.networkId); + if (_.isUndefined(zeroEx)) { + res.status(400).send('UNSUPPORTED_NETWORK_ID'); + return; + } + res.setHeader('Content-Type', 'application/json'); + const makerTokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(requestedAssetType); + if (_.isUndefined(makerTokenAddress)) { + res.status(400).send('INVALID_TOKEN'); + return; + } + const takerTokenSymbol = + requestedAssetType === RequestedAssetType.WETH ? RequestedAssetType.ZRX : RequestedAssetType.WETH; + const takerTokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(takerTokenSymbol); + if (_.isUndefined(takerTokenAddress)) { + res.status(400).send('INVALID_TOKEN'); + return; + } + const makerTokenAmount = new BigNumber(0.1); + const takerTokenAmount = new BigNumber(0.1); + const order: Order = { + maker: configs.DISPENSER_ADDRESS, + taker: req.recipientAddress, + makerFee: new BigNumber(0), + takerFee: new BigNumber(0), + makerTokenAmount, + takerTokenAmount, + makerTokenAddress, + takerTokenAddress, + salt: ZeroEx.generatePseudoRandomSalt(), + exchangeContractAddress: zeroEx.exchange.getContractAddress(), + feeRecipient: ZeroEx.NULL_ADDRESS, + expirationUnixTimestampSec: new BigNumber(Date.now() + TWO_DAYS_IN_MS), + }; + const orderHash = ZeroEx.getOrderHashHex(order); + const signature = await zeroEx.signOrderHashAsync(orderHash, configs.DISPENSER_ADDRESS, false); + const signedOrder = { + ...order, + signature, + }; + const signedOrderHash = ZeroEx.getOrderHashHex(signedOrder); + const payload = JSON.stringify(signedOrder); + utils.consoleLog(`Dispensed signed order: ${payload}`); + res.status(200).send(payload); + } // tslint:disable-next-line:prefer-function-over-method private _createProviderEngine(rpcUrl: string) { const engine = new ProviderEngine(); @@ -106,9 +167,4 @@ export class Handler { engine.start(); return engine; } - // tslint:disable-next-line:prefer-function-over-method - private _isValidEthereumAddress(address: string): boolean { - const lowercaseAddress = address.toLowerCase(); - return addressUtils.isAddress(lowercaseAddress); - } } diff --git a/packages/testnet-faucets/src/ts/id_management.ts b/packages/testnet-faucets/src/ts/id_management.ts index db9b610a3..b088e6cf8 100644 --- a/packages/testnet-faucets/src/ts/id_management.ts +++ b/packages/testnet-faucets/src/ts/id_management.ts @@ -1,8 +1,10 @@ import EthereumTx = require('ethereumjs-tx'); +import * as ethUtil from 'ethereumjs-util'; +import * as _ from 'lodash'; import { configs } from './configs'; -type Callback = (err: Error | null, accounts: any) => void; +type Callback = (err: Error | null, result: any) => void; export const idManagement = { getAccounts(callback: Callback) { @@ -18,4 +20,16 @@ export const idManagement = { const rawTx = `0x${tx.serialize().toString('hex')}`; callback(null, rawTx); }, + signMessage(message: object, callback: Callback) { + const data = _.get(message, 'data'); + if (_.isUndefined(data)) { + callback(new Error('No data to sign'), null); + } + const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex'); + const dataBuff = ethUtil.toBuffer(data); + const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); + const sig = ethUtil.ecsign(msgHashBuff, privateKeyBuffer); + const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s); + callback(null, rpcSig); + }, }; diff --git a/packages/testnet-faucets/src/ts/parameter_extractor.ts b/packages/testnet-faucets/src/ts/parameter_extractor.ts new file mode 100644 index 000000000..f3a26ae01 --- /dev/null +++ b/packages/testnet-faucets/src/ts/parameter_extractor.ts @@ -0,0 +1,34 @@ +import { addressUtils } from '@0xproject/utils'; +import { NextFunction, Request, Response } from 'express'; +import * as _ from 'lodash'; + +import { configs } from './configs'; +import { rpcUrls } from './rpc_urls'; +import { utils } from './utils'; + +const DEFAULT_NETWORK_ID = 42; // kovan + +export const parameterExtractor = { + extract(req: Request, res: Response, next: NextFunction) { + const recipientAddress = req.params.recipient; + if (_.isUndefined(recipientAddress) || !_isValidEthereumAddress(recipientAddress)) { + res.status(400).send('INVALID_RECIPIENT_ADDRESS'); + return; + } + const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); + req.recipientAddress = lowerCaseRecipientAddress; + const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); + const rpcUrl = _.get(rpcUrls, networkId); + if (_.isUndefined(rpcUrl)) { + res.status(400).send('UNSUPPORTED_NETWORK_ID'); + return; + } + req.networkId = networkId; + next(); + }, +}; + +function _isValidEthereumAddress(address: string): boolean { + const lowercaseAddress = address.toLowerCase(); + return addressUtils.isAddress(lowercaseAddress); +} diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index 26edfff5a..38c2f1428 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -3,6 +3,7 @@ import * as express from 'express'; import { errorReporter } from './error_reporter'; import { Handler } from './handler'; +import { parameterExtractor } from './parameter_extractor'; // Setup the errorReporter to catch uncaught exceptions and unhandled rejections errorReporter.setup(); @@ -20,8 +21,10 @@ app.get('/ping', (req: express.Request, res: express.Response) => { res.status(200).send('pong'); }); app.get('/info', handler.getQueueInfo.bind(handler)); -app.get('/ether/:recipient', handler.dispenseEther.bind(handler)); -app.get('/zrx/:recipient', handler.dispenseZRX.bind(handler)); +app.get('/ether/:recipient', parameterExtractor.extract, handler.dispenseEther.bind(handler)); +app.get('/zrx/:recipient', parameterExtractor.extract, handler.dispenseZRX.bind(handler)); +app.get('/order/weth/:recipient', parameterExtractor.extract, handler.dispenseWETHOrder.bind(handler)); +app.get('/order/zrx/:recipient', parameterExtractor.extract, handler.dispenseZRXOrder.bind(handler)); // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); diff --git a/packages/testnet-faucets/src/ts/zrx_request_queue.ts b/packages/testnet-faucets/src/ts/zrx_request_queue.ts index 3d73f9dd2..1a8bfe1d8 100644 --- a/packages/testnet-faucets/src/ts/zrx_request_queue.ts +++ b/packages/testnet-faucets/src/ts/zrx_request_queue.ts @@ -18,13 +18,10 @@ const QUEUE_INTERVAL_MS = 5000; export class ZRXRequestQueue extends RequestQueue { private _zeroEx: ZeroEx; - constructor(web3: Web3, networkId: number) { + constructor(web3: Web3, zeroEx: ZeroEx) { super(web3); this.queueIntervalMs = QUEUE_INTERVAL_MS; - const zeroExConfig = { - networkId, - }; - this._zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig); + this._zeroEx = zeroEx; } protected async processNextRequestFireAndForgetAsync(recipientAddress: string) { utils.consoleLog(`Processing ZRX ${recipientAddress}`); diff --git a/packages/testnet-faucets/tsconfig.json b/packages/testnet-faucets/tsconfig.json index 7f0c084ff..79f9e2413 100644 --- a/packages/testnet-faucets/tsconfig.json +++ b/packages/testnet-faucets/tsconfig.json @@ -3,5 +3,10 @@ "compilerOptions": { "outDir": "lib" }, - "include": ["./src/ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"] + "include": [ + "./src/ts/**/*", + "../../node_modules/types-bn/index.d.ts", + "../../node_modules/types-ethereumjs-util/index.d.ts", + "../../node_modules/web3-typescript-typings/index.d.ts" + ] } diff --git a/yarn.lock b/yarn.lock index 4c66bf2cb..38bca8d81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9097,6 +9097,14 @@ types-bn@^0.0.1: dependencies: bn.js "4.11.7" +types-ethereumjs-util@0xProject/types-ethereumjs-util: + version "0.0.6" + resolved "https://codeload.github.com/0xProject/types-ethereumjs-util/tar.gz/0c5058e4f9d6585f7c7c1f88939546acb14323b8" + dependencies: + bn.js "^4.11.7" + buffer "^5.0.6" + rlp "^2.0.0" + types-ethereumjs-util@0xproject/types-ethereumjs-util: version "0.0.6" resolved "https://codeload.github.com/0xproject/types-ethereumjs-util/tar.gz/0c5058e4f9d6585f7c7c1f88939546acb14323b8" -- cgit From 3a1ca32ff172f735e4b69f125fea4237c83643f0 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 30 Jan 2018 12:10:06 -0800 Subject: Fix lint errors --- packages/testnet-faucets/src/ts/global.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/testnet-faucets/src/ts/global.d.ts b/packages/testnet-faucets/src/ts/global.d.ts index af9534377..50cd205a1 100644 --- a/packages/testnet-faucets/src/ts/global.d.ts +++ b/packages/testnet-faucets/src/ts/global.d.ts @@ -26,9 +26,11 @@ declare module 'ethereumjs-tx' { } // Define extra params on Request for parameter extraction in middleware +/* tslint:disable */ declare namespace Express { export interface Request { recipientAddress: string; networkId: string; } } +/* tslint:enable */ -- cgit From c7db837214056be5b3661cd5d082e9dc94e4e136 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 31 Jan 2018 15:40:13 -0800 Subject: Update testnet-faucets README --- packages/testnet-faucets/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index a52d16a00..72532bbb2 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -88,15 +88,23 @@ Returns a JSON payload describing the state of the queues for each network. For `GET /ether/:recipient` -Where recipient is a hex encoded Ethereum address prefixed with `0x`. +Schedules a transaction that sends 0.1 ETH to the `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. `GET /zrx/:recipient` -Where recipient is a hex encoded Ethereum address prefixed with `0x`. +Schedules a transaction that sends 0.1 ZRX to the `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. + +`GET /order/weth/:recipient` + +Returns a JSON payload describing an order for 0.1 WETH in exchange for 0.1 ZRX signed by the dispenser address. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. + +`GET /order/zrx/:recipient` + +Returns a JSON payload describing an order for 0.1 ZRX in exchange for 0.1 WETH signed by the dispenser address. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. #### Parameters -The endpoints `/ether` and `/zrx` take a query parameter named `networkId` to specify the desired network where you would like to receive the ETH or ZRX. For example: +The endpoints `/ether`, `/zrx`, `/order/weth/`, and `/order/zrx/` take a query parameter named `networkId` to specify the desired ethereum network ```bash curl -i http://localhost:3000/ether/0x14e2F1F157E7DD4057D02817436D628A37120FD1\?networkId=3 -- cgit From 6577d607332e2fb1a442d663e260ecb969457c36 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 31 Jan 2018 15:52:05 -0800 Subject: Prettier --- packages/testnet-faucets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index 72532bbb2..d0b9858a1 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -104,7 +104,7 @@ Returns a JSON payload describing an order for 0.1 ZRX in exchange for 0.1 WETH #### Parameters -The endpoints `/ether`, `/zrx`, `/order/weth/`, and `/order/zrx/` take a query parameter named `networkId` to specify the desired ethereum network +The endpoints `/ether`, `/zrx`, `/order/weth/`, and `/order/zrx/` take a query parameter named `networkId` to specify the desired ethereum network ```bash curl -i http://localhost:3000/ether/0x14e2F1F157E7DD4057D02817436D628A37120FD1\?networkId=3 -- cgit From 83d0bad3a1e6635dedb46fbd99ee1bec5246d4bf Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 5 Feb 2018 16:28:03 -0800 Subject: Addressed comments and update 0xProject/types-ethereumjs-util deps --- packages/contracts/package.json | 2 +- packages/dev-utils/package.json | 2 +- packages/subproviders/package.json | 2 +- packages/testnet-faucets/README.md | 21 +++-- packages/testnet-faucets/package.json | 1 - packages/testnet-faucets/src/ts/global.d.ts | 10 --- packages/testnet-faucets/src/ts/handler.ts | 92 ++++++++++------------ packages/testnet-faucets/src/ts/id_management.ts | 8 +- .../testnet-faucets/src/ts/parameter_extractor.ts | 34 -------- .../src/ts/parameter_transformer.ts | 29 +++++++ packages/testnet-faucets/src/ts/request_queue.ts | 8 +- packages/testnet-faucets/src/ts/rpc_urls.ts | 8 +- packages/testnet-faucets/src/ts/server.ts | 10 +-- yarn.lock | 17 ++-- 14 files changed, 107 insertions(+), 137 deletions(-) delete mode 100644 packages/testnet-faucets/src/ts/parameter_extractor.ts create mode 100644 packages/testnet-faucets/src/ts/parameter_transformer.ts diff --git a/packages/contracts/package.json b/packages/contracts/package.json index d5e352c5d..b3b08fe29 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -52,7 +52,7 @@ "solc": "^0.4.18", "tslint": "5.8.0", "types-bn": "^0.0.1", - "types-ethereumjs-util": "0xproject/types-ethereumjs-util", + "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", "web3-typescript-typings": "^0.9.8", "yargs": "^10.0.3" diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index 0c292c01f..fca082583 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -27,7 +27,7 @@ "shx": "^0.2.2", "tslint": "5.8.0", "types-bn": "^0.0.1", - "types-ethereumjs-util": "0xproject/types-ethereumjs-util", + "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1" }, "dependencies": { diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 18ba247ea..ee283dff3 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -48,7 +48,7 @@ "shx": "^0.2.2", "tslint": "5.8.0", "types-bn": "^0.0.1", - "types-ethereumjs-util": "0xproject/types-ethereumjs-util", + "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", "web3-typescript-typings": "^0.9.8", "webpack": "^3.1.0" diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index d0b9858a1..6cd842ea6 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -86,25 +86,24 @@ Returns a JSON payload describing the state of the queues for each network. For } ``` -`GET /ether/:recipient` +`GET /ether/:recipient?networkId=:networkId` -Schedules a transaction that sends 0.1 ETH to the `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. +Schedules a transaction that sends 0.1 ETH to the `recipient` on the network specified by `networkId` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). -`GET /zrx/:recipient` -Schedules a transaction that sends 0.1 ZRX to the `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. +`GET /zrx/:recipient?networkId=:networkId` -`GET /order/weth/:recipient` +Schedules a transaction that sends 0.1 ZRX to the `recipient` on the network specified by `networkId` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). -Returns a JSON payload describing an order for 0.1 WETH in exchange for 0.1 ZRX signed by the dispenser address. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. +`GET /order/weth/:recipient?networkId=:networkId` -`GET /order/zrx/:recipient` +Returns a JSON payload describing an order for 0.1 WETH in exchange for 0.1 ZRX signed by the dispenser address on the network specified by `networkId`. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). -Returns a JSON payload describing an order for 0.1 ZRX in exchange for 0.1 WETH signed by the dispenser address. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. +`GET /order/zrx/:recipient?networkId=:networkId` -#### Parameters +Returns a JSON payload describing an order for 0.1 ZRX in exchange for 0.1 WETH signed by the dispenser address on the network specified by `networkId`. The taker is specified by `recipient` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). -The endpoints `/ether`, `/zrx`, `/order/weth/`, and `/order/zrx/` take a query parameter named `networkId` to specify the desired ethereum network +#### Example request ```bash curl -i http://localhost:3000/ether/0x14e2F1F157E7DD4057D02817436D628A37120FD1\?networkId=3 @@ -112,8 +111,6 @@ curl -i http://localhost:3000/ether/0x14e2F1F157E7DD4057D02817436D628A37120FD1\? This command will request the local server to initiate a transfer of 0.1 ETH from the dispensing address to `0x14e2F1F157E7DD4057D02817436D628A37120FD1` on the Ropsten testnet. -If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan) - ### Docker configs ``` diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index f73857f82..b7a55aeb0 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -37,7 +37,6 @@ "shx": "^0.2.2", "source-map-loader": "^0.1.6", "tslint": "5.8.0", - "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", "web3-typescript-typings": "^0.9.8", diff --git a/packages/testnet-faucets/src/ts/global.d.ts b/packages/testnet-faucets/src/ts/global.d.ts index 50cd205a1..97cd35680 100644 --- a/packages/testnet-faucets/src/ts/global.d.ts +++ b/packages/testnet-faucets/src/ts/global.d.ts @@ -24,13 +24,3 @@ declare module 'ethereumjs-tx' { } export = EthereumTx; } - -// Define extra params on Request for parameter extraction in middleware -/* tslint:disable */ -declare namespace Express { - export interface Request { - recipientAddress: string; - networkId: string; - } -} -/* tslint:enable */ diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index 7883cefd8..1dae8a47f 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -2,13 +2,13 @@ import { Order, SignedOrder, ZeroEx } from '0x.js'; import { BigNumber } from '@0xproject/utils'; import * as express from 'express'; import * as _ from 'lodash'; +import * as Web3 from 'web3'; // HACK: web3 injects XMLHttpRequest into the global scope and ProviderEngine checks XMLHttpRequest // to know whether it is running in a browser or node environment. We need it to be undefined since // we are not running in a browser env. // Filed issue: https://github.com/ethereum/web3.js/issues/844 (global as any).XMLHttpRequest = undefined; - import ProviderEngine = require('web3-provider-engine'); import HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet'); import NonceSubprovider = require('web3-provider-engine/subproviders/nonce-tracker'); @@ -22,12 +22,6 @@ import { rpcUrls } from './rpc_urls'; import { utils } from './utils'; import { ZRXRequestQueue } from './zrx_request_queue'; -// 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'; - interface ItemByNetworkId { [networkId: string]: T; } @@ -38,15 +32,46 @@ enum RequestedAssetType { ZRX = 'ZRX', } -const TWO_DAYS_IN_MS = 1.728e8; // TODO: make this configurable +const FIVE_DAYS_IN_MS = 4.32e8; // TODO: make this configurable export class Handler { private _zeroExByNetworkId: ItemByNetworkId = {}; private _etherRequestQueueByNetworkId: ItemByNetworkId = {}; private _zrxRequestQueueByNetworkId: ItemByNetworkId = {}; + private static _dispenseAsset( + req: express.Request, + res: express.Response, + requestQueueByNetworkId: ItemByNetworkId, + 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 static _createProviderEngine(rpcUrl: string) { + const engine = new ProviderEngine(); + engine.addProvider(new NonceSubprovider()); + engine.addProvider(new HookedWalletSubprovider(idManagement)); + engine.addProvider( + new RpcSubprovider({ + rpcUrl, + }), + ); + engine.start(); + return engine; + } constructor() { _.forIn(rpcUrls, (rpcUrl: string, networkId: string) => { - const providerObj = this._createProviderEngine(rpcUrl); + const providerObj = Handler._createProviderEngine(rpcUrl); const web3 = new Web3(providerObj); const zeroExConfig = { networkId: +networkId, @@ -77,10 +102,10 @@ export class Handler { res.status(200).send(payload); } public dispenseEther(req: express.Request, res: express.Response) { - this._dispenseAsset(req, res, this._etherRequestQueueByNetworkId, RequestedAssetType.ETH); + Handler._dispenseAsset(req, res, this._etherRequestQueueByNetworkId, RequestedAssetType.ETH); } public dispenseZRX(req: express.Request, res: express.Response) { - this._dispenseAsset(req, res, this._zrxRequestQueueByNetworkId, RequestedAssetType.ZRX); + Handler._dispenseAsset(req, res, this._zrxRequestQueueByNetworkId, RequestedAssetType.ZRX); } public async dispenseWETHOrder(req: express.Request, res: express.Response) { await this._dispenseOrder(req, res, RequestedAssetType.WETH); @@ -88,28 +113,8 @@ export class Handler { public async dispenseZRXOrder(req: express.Request, res: express.Response, next: express.NextFunction) { await this._dispenseOrder(req, res, RequestedAssetType.ZRX); } - // tslint:disable-next-line:prefer-function-over-method - private _dispenseAsset( - req: express.Request, - res: express.Response, - requestQueueByNetworkId: ItemByNetworkId, - requestedAssetType: RequestedAssetType, - ) { - const requestQueue = _.get(requestQueueByNetworkId, req.networkId); - if (_.isUndefined(requestQueue)) { - res.status(400).send('UNSUPPORTED_NETWORK_ID'); - return; - } - const didAddToQueue = requestQueue.add(req.recipientAddress); - if (!didAddToQueue) { - res.status(503).send('QUEUE_IS_FULL'); - return; - } - utils.consoleLog(`Added ${req.recipientAddress} to queue: ${requestedAssetType} networkId: ${req.networkId}`); - res.status(200).end(); - } private async _dispenseOrder(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { - const zeroEx = _.get(this._zeroExByNetworkId, req.networkId); + const zeroEx = _.get(this._zeroExByNetworkId, req.params.networkId); if (_.isUndefined(zeroEx)) { res.status(400).send('UNSUPPORTED_NETWORK_ID'); return; @@ -117,21 +122,19 @@ export class Handler { res.setHeader('Content-Type', 'application/json'); const makerTokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(requestedAssetType); if (_.isUndefined(makerTokenAddress)) { - res.status(400).send('INVALID_TOKEN'); - return; + throw new Error(`Unsupported asset type: ${requestedAssetType}`); } const takerTokenSymbol = requestedAssetType === RequestedAssetType.WETH ? RequestedAssetType.ZRX : RequestedAssetType.WETH; const takerTokenAddress = await zeroEx.tokenRegistry.getTokenAddressBySymbolIfExistsAsync(takerTokenSymbol); if (_.isUndefined(takerTokenAddress)) { - res.status(400).send('INVALID_TOKEN'); - return; + throw new Error(`Unsupported asset type: ${requestedAssetType}`); } const makerTokenAmount = new BigNumber(0.1); const takerTokenAmount = new BigNumber(0.1); const order: Order = { maker: configs.DISPENSER_ADDRESS, - taker: req.recipientAddress, + taker: req.params.recipient, makerFee: new BigNumber(0), takerFee: new BigNumber(0), makerTokenAmount, @@ -141,7 +144,7 @@ export class Handler { salt: ZeroEx.generatePseudoRandomSalt(), exchangeContractAddress: zeroEx.exchange.getContractAddress(), feeRecipient: ZeroEx.NULL_ADDRESS, - expirationUnixTimestampSec: new BigNumber(Date.now() + TWO_DAYS_IN_MS), + expirationUnixTimestampSec: new BigNumber(Date.now() + FIVE_DAYS_IN_MS), }; const orderHash = ZeroEx.getOrderHashHex(order); const signature = await zeroEx.signOrderHashAsync(orderHash, configs.DISPENSER_ADDRESS, false); @@ -154,17 +157,4 @@ export class Handler { utils.consoleLog(`Dispensed signed order: ${payload}`); res.status(200).send(payload); } - // tslint:disable-next-line:prefer-function-over-method - private _createProviderEngine(rpcUrl: string) { - const engine = new ProviderEngine(); - engine.addProvider(new NonceSubprovider()); - engine.addProvider(new HookedWalletSubprovider(idManagement)); - engine.addProvider( - new RpcSubprovider({ - rpcUrl, - }), - ); - engine.start(); - return engine; - } } diff --git a/packages/testnet-faucets/src/ts/id_management.ts b/packages/testnet-faucets/src/ts/id_management.ts index b088e6cf8..7c598f91c 100644 --- a/packages/testnet-faucets/src/ts/id_management.ts +++ b/packages/testnet-faucets/src/ts/id_management.ts @@ -21,12 +21,12 @@ export const idManagement = { callback(null, rawTx); }, signMessage(message: object, callback: Callback) { - const data = _.get(message, 'data'); - if (_.isUndefined(data)) { - callback(new Error('No data to sign'), null); + const dataIfExists = _.get(message, 'data'); + if (_.isUndefined(dataIfExists)) { + callback(new Error('NO_DATA_TO_SIGN'), null); } const privateKeyBuffer = new Buffer(configs.DISPENSER_PRIVATE_KEY as string, 'hex'); - const dataBuff = ethUtil.toBuffer(data); + const dataBuff = ethUtil.toBuffer(dataIfExists); const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff); const sig = ethUtil.ecsign(msgHashBuff, privateKeyBuffer); const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s); diff --git a/packages/testnet-faucets/src/ts/parameter_extractor.ts b/packages/testnet-faucets/src/ts/parameter_extractor.ts deleted file mode 100644 index f3a26ae01..000000000 --- a/packages/testnet-faucets/src/ts/parameter_extractor.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { addressUtils } from '@0xproject/utils'; -import { NextFunction, Request, Response } from 'express'; -import * as _ from 'lodash'; - -import { configs } from './configs'; -import { rpcUrls } from './rpc_urls'; -import { utils } from './utils'; - -const DEFAULT_NETWORK_ID = 42; // kovan - -export const parameterExtractor = { - extract(req: Request, res: Response, next: NextFunction) { - const recipientAddress = req.params.recipient; - if (_.isUndefined(recipientAddress) || !_isValidEthereumAddress(recipientAddress)) { - res.status(400).send('INVALID_RECIPIENT_ADDRESS'); - return; - } - const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); - req.recipientAddress = lowerCaseRecipientAddress; - const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); - const rpcUrl = _.get(rpcUrls, networkId); - if (_.isUndefined(rpcUrl)) { - res.status(400).send('UNSUPPORTED_NETWORK_ID'); - return; - } - req.networkId = networkId; - next(); - }, -}; - -function _isValidEthereumAddress(address: string): boolean { - const lowercaseAddress = address.toLowerCase(); - return addressUtils.isAddress(lowercaseAddress); -} diff --git a/packages/testnet-faucets/src/ts/parameter_transformer.ts b/packages/testnet-faucets/src/ts/parameter_transformer.ts new file mode 100644 index 000000000..c5711d462 --- /dev/null +++ b/packages/testnet-faucets/src/ts/parameter_transformer.ts @@ -0,0 +1,29 @@ +import { addressUtils } from '@0xproject/utils'; +import { NextFunction, Request, Response } from 'express'; +import * as _ from 'lodash'; + +import { configs } from './configs'; +import { rpcUrls } from './rpc_urls'; +import { utils } from './utils'; + +const DEFAULT_NETWORK_ID = 42; // kovan + +export const parameterTransformer = { + transform(req: Request, res: Response, next: NextFunction) { + const recipientAddress = req.params.recipient; + if (_.isUndefined(recipientAddress) || !addressUtils.isAddress(recipientAddress)) { + res.status(400).send('INVALID_RECIPIENT_ADDRESS'); + return; + } + const lowerCaseRecipientAddress = recipientAddress.toLowerCase(); + req.params.recipient = lowerCaseRecipientAddress; + const networkId = _.get(req.query, 'networkId', DEFAULT_NETWORK_ID); + const rpcUrlIfExists = _.get(rpcUrls, networkId); + if (_.isUndefined(rpcUrlIfExists)) { + res.status(400).send('UNSUPPORTED_NETWORK_ID'); + return; + } + req.params.networkId = networkId; + next(); + }, +}; diff --git a/packages/testnet-faucets/src/ts/request_queue.ts b/packages/testnet-faucets/src/ts/request_queue.ts index 7d685522a..718f8be0c 100644 --- a/packages/testnet-faucets/src/ts/request_queue.ts +++ b/packages/testnet-faucets/src/ts/request_queue.ts @@ -13,14 +13,12 @@ const DEFAULT_QUEUE_INTERVAL_MS = 1000; export class RequestQueue { protected _queueIntervalMs: number; protected _queue: string[]; - protected _queueIntervalId: NodeJS.Timer; + 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 { @@ -47,7 +45,9 @@ export class RequestQueue { }, this._queueIntervalMs); } protected _stop() { - clearInterval(this._queueIntervalId); + if (!_.isUndefined(this._queueIntervalId)) { + clearInterval(this._queueIntervalId); + } } // tslint:disable-next-line:prefer-function-over-method protected async _processNextRequestFireAndForgetAsync(recipientAddress: string) { diff --git a/packages/testnet-faucets/src/ts/rpc_urls.ts b/packages/testnet-faucets/src/ts/rpc_urls.ts index 25a3b938f..c57e85eac 100644 --- a/packages/testnet-faucets/src/ts/rpc_urls.ts +++ b/packages/testnet-faucets/src/ts/rpc_urls.ts @@ -1,13 +1,13 @@ import { configs } from './configs'; const productionRpcUrls = { - '2': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, - '3': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, - '42': `https://kovan.infura.io/${configs.INFURA_API_KEY}`, + 2: `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, + 3: `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, + 42: `https://kovan.infura.io/${configs.INFURA_API_KEY}`, }; const developmentRpcUrls = { - '50': 'http://127.0.0.1:8545', + 50: 'http://127.0.0.1:8545', }; export const rpcUrls = configs.ENVIRONMENT === 'development' ? developmentRpcUrls : productionRpcUrls; diff --git a/packages/testnet-faucets/src/ts/server.ts b/packages/testnet-faucets/src/ts/server.ts index 38c2f1428..be1077756 100644 --- a/packages/testnet-faucets/src/ts/server.ts +++ b/packages/testnet-faucets/src/ts/server.ts @@ -3,7 +3,7 @@ import * as express from 'express'; import { errorReporter } from './error_reporter'; import { Handler } from './handler'; -import { parameterExtractor } from './parameter_extractor'; +import { parameterTransformer } from './parameter_transformer'; // Setup the errorReporter to catch uncaught exceptions and unhandled rejections errorReporter.setup(); @@ -21,10 +21,10 @@ app.get('/ping', (req: express.Request, res: express.Response) => { res.status(200).send('pong'); }); app.get('/info', handler.getQueueInfo.bind(handler)); -app.get('/ether/:recipient', parameterExtractor.extract, handler.dispenseEther.bind(handler)); -app.get('/zrx/:recipient', parameterExtractor.extract, handler.dispenseZRX.bind(handler)); -app.get('/order/weth/:recipient', parameterExtractor.extract, handler.dispenseWETHOrder.bind(handler)); -app.get('/order/zrx/:recipient', parameterExtractor.extract, handler.dispenseZRXOrder.bind(handler)); +app.get('/ether/:recipient', parameterTransformer.transform, handler.dispenseEther.bind(handler)); +app.get('/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRX.bind(handler)); +app.get('/order/weth/:recipient', parameterTransformer.transform, handler.dispenseWETHOrder.bind(handler)); +app.get('/order/zrx/:recipient', parameterTransformer.transform, handler.dispenseZRXOrder.bind(handler)); // Log to rollbar any errors unhandled by handlers app.use(errorReporter.errorHandler()); diff --git a/yarn.lock b/yarn.lock index 668fa4944..832856c62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9097,21 +9097,20 @@ types-bn@^0.0.1: dependencies: bn.js "4.11.7" -types-ethereumjs-util@0xProject/types-ethereumjs-util: - version "0.0.6" - resolved "https://codeload.github.com/0xProject/types-ethereumjs-util/tar.gz/0c5058e4f9d6585f7c7c1f88939546acb14323b8" +"types-bn@https://github.com/machinomy/types-bn.git": + version "0.0.1" + resolved "https://github.com/machinomy/types-bn.git#08ede69e138640d332b0dae0dc2e2fffee5f7160" dependencies: - bn.js "^4.11.7" - buffer "^5.0.6" - rlp "^2.0.0" + bn.js "4.11.7" -types-ethereumjs-util@0xproject/types-ethereumjs-util: - version "0.0.6" - resolved "https://codeload.github.com/0xproject/types-ethereumjs-util/tar.gz/0c5058e4f9d6585f7c7c1f88939546acb14323b8" +types-ethereumjs-util@0xProject/types-ethereumjs-util: + version "0.0.7" + resolved "https://codeload.github.com/0xProject/types-ethereumjs-util/tar.gz/72722fc605bfa7f87ec4a959956b387320479ffc" dependencies: bn.js "^4.11.7" buffer "^5.0.6" rlp "^2.0.0" + types-bn "https://github.com/machinomy/types-bn.git" typescript@2.4.1: version "2.4.1" -- cgit From 6bdabe72b955b0a5cc613fea61b7eacee606d5a9 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Feb 2018 11:48:56 -0800 Subject: Prettier --- packages/testnet-faucets/README.md | 1 - packages/testnet-faucets/src/ts/handler.ts | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/testnet-faucets/README.md b/packages/testnet-faucets/README.md index 6cd842ea6..2f6ae347f 100644 --- a/packages/testnet-faucets/README.md +++ b/packages/testnet-faucets/README.md @@ -90,7 +90,6 @@ Returns a JSON payload describing the state of the queues for each network. For Schedules a transaction that sends 0.1 ETH to the `recipient` on the network specified by `networkId` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). - `GET /zrx/:recipient?networkId=:networkId` Schedules a transaction that sends 0.1 ZRX to the `recipient` on the network specified by `networkId` where `recipient` is a hex encoded Ethereum address prefixed with `0x`. If no `networkId` is provided via query parameters the faucet will default to network 42 (Kovan). diff --git a/packages/testnet-faucets/src/ts/handler.ts b/packages/testnet-faucets/src/ts/handler.ts index 1dae8a47f..e9ced3437 100644 --- a/packages/testnet-faucets/src/ts/handler.ts +++ b/packages/testnet-faucets/src/ts/handler.ts @@ -54,7 +54,9 @@ export class Handler { res.status(503).send('QUEUE_IS_FULL'); return; } - utils.consoleLog(`Added ${req.params.recipient} to queue: ${requestedAssetType} networkId: ${req.params.networkId}`); + utils.consoleLog( + `Added ${req.params.recipient} to queue: ${requestedAssetType} networkId: ${req.params.networkId}`, + ); res.status(200).end(); } private static _createProviderEngine(rpcUrl: string) { -- cgit From 2bf1aa975afc242e49bcd19c0b57a3730e27639e Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Feb 2018 15:24:11 -0800 Subject: Add types-bn package to 0x.js and testnet-faucets --- packages/0x.js/package.json | 1 + packages/testnet-faucets/package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 013b4ae6e..de18a1b2e 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -74,6 +74,7 @@ "truffle-hdwallet-provider": "^0.0.3", "tslint": "5.8.0", "typedoc": "~0.8.0", + "types-bn": "^0.0.1", "typescript": "2.7.1", "web3-provider-engine": "^13.0.1", "web3-typescript-typings": "^0.9.9", diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index e38f4b6cd..9efacae0a 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -37,6 +37,7 @@ "shx": "^0.2.2", "source-map-loader": "^0.1.6", "tslint": "5.8.0", + "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", "web3-typescript-typings": "^0.9.9", -- cgit From f818d06b43ae9279c4ee022685e3bcb9f27ba2fd Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Feb 2018 15:31:12 -0800 Subject: Change rpcUrls keys back into string literals --- packages/testnet-faucets/src/ts/rpc_urls.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/testnet-faucets/src/ts/rpc_urls.ts b/packages/testnet-faucets/src/ts/rpc_urls.ts index c57e85eac..25a3b938f 100644 --- a/packages/testnet-faucets/src/ts/rpc_urls.ts +++ b/packages/testnet-faucets/src/ts/rpc_urls.ts @@ -1,13 +1,13 @@ import { configs } from './configs'; const productionRpcUrls = { - 2: `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, - 3: `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, - 42: `https://kovan.infura.io/${configs.INFURA_API_KEY}`, + '2': `https://ropsten.infura.io/${configs.INFURA_API_KEY}`, + '3': `https://rinkeby.infura.io/${configs.INFURA_API_KEY}`, + '42': `https://kovan.infura.io/${configs.INFURA_API_KEY}`, }; const developmentRpcUrls = { - 50: 'http://127.0.0.1:8545', + '50': 'http://127.0.0.1:8545', }; export const rpcUrls = configs.ENVIRONMENT === 'development' ? developmentRpcUrls : productionRpcUrls; -- cgit From 7357a0a3243a08c9e9fe866f43de9ff38f79ddfd Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Feb 2018 15:38:23 -0800 Subject: Update yarn.lock --- yarn.lock | 9 --------- 1 file changed, 9 deletions(-) diff --git a/yarn.lock b/yarn.lock index 9dc647c77..832856c62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,15 +2,6 @@ # yarn lockfile v1 -"@0xproject/utils@^0.2.0": - version "0.2.4" - resolved "https://registry.yarnpkg.com/@0xproject/utils/-/utils-0.2.4.tgz#d84d0737f47730e5724a76797d30e716b587a0cf" - dependencies: - bignumber.js "~4.1.0" - js-sha3 "^0.7.0" - lodash "^4.17.4" - web3 "^0.20.0" - "@types/accounting@^0.4.1": version "0.4.1" resolved "https://registry.yarnpkg.com/@types/accounting/-/accounting-0.4.1.tgz#865d9f5694fd7c438fba34eb4bc82eec6f34cdd5" -- cgit From f44bfa9682544a8fc50ef9221991982fd665f9f5 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Feb 2018 15:56:40 -0800 Subject: Bump subproviders version --- packages/testnet-faucets/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 53c2f75e9..3f052d91f 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -17,7 +17,7 @@ "dependencies": { "0x.js": "^0.32.0", "@0xproject/utils": "^0.3.0", - "@0xproject/subproviders": "^0.3.5", + "@0xproject/subproviders": "^0.3.6", "body-parser": "^1.17.1", "ethereumjs-tx": "^1.3.3", "ethereumjs-util": "^5.1.1", -- cgit