diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-03-06 07:08:56 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-03-06 07:08:56 +0800 |
commit | d171ce4fba97847a617fc4c8fd7e3b759586c933 (patch) | |
tree | c800ae90713a098cd00a418bffe516776b579baf /packages | |
parent | 92b9dbd706768fd0edfc8f72a90f197abd8b3d66 (diff) | |
parent | 994935b5da0b15796958a32c5bab0a25b9430b5a (diff) | |
download | dexon-0x-contracts-d171ce4fba97847a617fc4c8fd7e3b759586c933.tar.gz dexon-0x-contracts-d171ce4fba97847a617fc4c8fd7e3b759586c933.tar.zst dexon-0x-contracts-d171ce4fba97847a617fc4c8fd7e3b759586c933.zip |
Merge branch 'development' into feature/sra-reporter
* development: (79 commits)
remove from devDeps
Remove date for now
Add ethers typescript typings to 0x.js deps. The library works without this atm since another dep of 0x.js has it as a dep. But it's more robust to have it here.
Add missing instructions to add external types to tsconfig.json after installing the package
Fix bugs in postpublish_utils.js
Update @0xproject/utils in top-level package.json
Changelog tweaks
Publish
Updated CHANGELOGS
Fix typo
Add PR number to changelog entry
Add changelog update to subproviders package
Add `numberOfAccounts` param to `LedgerSubprovider` method `getAccountsAsync` and add tests
Remove unnecessary type assertion
Fix comments
Add comments
Don't need any external packages for 0x connect docs yet
Instead of adding `@0xproject/types` to tsconfig.json, let's only add it when calling TypeDoc
Fix styling
Make prettier ignore postpublish_utils
...
Diffstat (limited to 'packages')
96 files changed, 1097 insertions, 340 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md index b882a1b31..976ae35b2 100644 --- a/packages/0x.js/CHANGELOG.md +++ b/packages/0x.js/CHANGELOG.md @@ -1,11 +1,16 @@ # CHANGELOG -## v0.33.0 - _TBD, 2018_ +## v0.33.1 - _TBD, 2018_ + + * Add missing EthersJs typescript typings as dependency + +## v0.33.0 - _March 4, 2018_ * Validate and lowercase all addresses in public methods (#373) * Improve validation to force passing contract addresses on private networks (#385) * Change `LogErrorContractEventArgs.errorId` type from `BigNumber` to `number` (#413) * Rename all public `_unsubscribeAll` methods to `unsubscribeAll` (#415) + * Move web3 typings from devDep to dep since cannot use this package without it (#429) ## v0.32.2 - _February 9, 2018_ diff --git a/packages/0x.js/README.md b/packages/0x.js/README.md index bac4fa5d8..2d0394726 100644 --- a/packages/0x.js/README.md +++ b/packages/0x.js/README.md @@ -18,11 +18,20 @@ npm install 0x.js --save import { ZeroEx } from '0x.js'; ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", + "./node_modules/ethers-typescript-typings/index.d.ts" +] +``` + #### UMD: **Install** -Download the UMD module from our [releases page](https://github.com/0xProject/0x.js/releases) and add it to your project. +Download the UMD module from our [releases page](https://github.com/0xProject/0x-monorepo/releases) and add it to your project. **Import** diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 20af430d6..2196fa777 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -1,6 +1,6 @@ { "name": "0x.js", - "version": "0.32.4", + "version": "0.33.0", "description": "A javascript library for interacting with the 0x protocol", "keywords": [ "0x.js", @@ -15,7 +15,7 @@ "build:watch": "tsc -w", "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", - "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", @@ -35,16 +35,16 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js" + "url": "https://github.com/0xProject/0x-monorepo" }, "license": "Apache-2.0", "engines": { "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/abi-gen": "^0.2.3", - "@0xproject/dev-utils": "^0.1.0", - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/abi-gen": "^0.2.4", + "@0xproject/dev-utils": "^0.2.0", + "@0xproject/tslint-config": "^0.4.10", "@types/bintrees": "^1.0.2", "@types/jsonschema": "^1.1.1", "@types/lodash": "^4.14.86", @@ -55,9 +55,9 @@ "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.9", + "chai-as-promised-typescript-typings": "^0.0.10", "chai-bignumber": "^2.0.1", - "chai-typescript-typings": "^0.0.3", + "chai-typescript-typings": "^0.0.4", "copyfiles": "^1.2.0", "coveralls": "^3.0.0", "dirty-chai": "^2.0.1", @@ -73,30 +73,30 @@ "source-map-support": "^0.5.0", "truffle-hdwallet-provider": "^0.0.3", "tslint": "5.8.0", - "typedoc": "~0.8.0", + "typedoc": "0xProject/typedoc", "types-bn": "^0.0.1", "typescript": "2.7.1", "web3-provider-engine": "^13.0.1", - "ethers-typescript-typings": "^0.0.1", - "web3-typescript-typings": "^0.9.11", "webpack": "^3.1.0" }, "dependencies": { - "@0xproject/assert": "^0.0.20", - "@0xproject/base-contract": "^0.0.1", - "@0xproject/json-schemas": "^0.7.12", - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", - "@0xproject/web3-wrapper": "^0.1.14", + "@0xproject/assert": "^0.1.0", + "@0xproject/base-contract": "^0.0.2", + "@0xproject/json-schemas": "^0.7.13", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", + "@0xproject/web3-wrapper": "^0.2.0", "bintrees": "^1.0.2", "bn.js": "^4.11.8", - "ethers-contracts": "^2.2.1", "ethereumjs-abi": "^0.6.4", "ethereumjs-blockstream": "^2.0.6", "ethereumjs-util": "^5.1.1", + "ethers-contracts": "^2.2.1", + "ethers-typescript-typings": "^0.0.2", "js-sha3": "^0.7.0", "lodash": "^4.17.4", "uuid": "^3.1.0", - "web3": "^0.20.0" + "web3": "^0.20.0", + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/0x.js/scripts/postpublish.js b/packages/0x.js/scripts/postpublish.js index 7cbabd8f6..1a9ab73ea 100644 --- a/packages/0x.js/scripts/postpublish.js +++ b/packages/0x.js/scripts/postpublish.js @@ -1,9 +1,16 @@ const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); const packageJSON = require('../package.json'); +const tsConfig = require('../tsconfig.json'); const cwd = __dirname + '/..'; const subPackageName = packageJSON.name; +// Include any external packages that are part of the 0x.js public interface +// to this array so that TypeDoc picks it up and adds it to the Docs JSON +// So far, we only have @0xproject/types as part of 0x.js's public interface. +const fileIncludes = [...tsConfig.include, '../types/src/index.ts']; +const fileIncludesAdjusted = postpublish_utils.adjustFileIncludePaths(fileIncludes, __dirname); +const projectFiles = fileIncludesAdjusted.join(' '); const S3BucketPath = 's3://0xjs-docs-jsons/'; let tag; @@ -20,7 +27,7 @@ postpublish_utils .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json'; - return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { + return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_FILES="' + projectFiles + '" yarn docs:json', { cwd, }); }) diff --git a/packages/0x.js/scripts/stagedocs.js b/packages/0x.js/scripts/stagedocs.js index b48c23851..f0ba55205 100644 --- a/packages/0x.js/scripts/stagedocs.js +++ b/packages/0x.js/scripts/stagedocs.js @@ -1,24 +1,31 @@ const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); +const tsConfig = require('../tsconfig.json'); const cwd = __dirname + '/..'; const S3BucketPath = 's3://staging-0xjs-docs-jsons/'; +// Include any external packages that are part of the 0x.js public interface +// to this array so that TypeDoc picks it up and adds it to the Docs JSON +// So far, we only have @0xproject/types as part of 0x.js's public interface. +const fileIncludes = [...tsConfig.include, '../types/src/index.ts']; +const fileIncludesAdjusted = postpublish_utils.adjustFileIncludePaths(fileIncludes, __dirname); +const projectFiles = fileIncludesAdjusted.join(' '); const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json'; const version = process.env.DOCS_VERSION; -execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { +execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_FILES="' + projectFiles + '" yarn docs:json', { cwd, }) -.then(function(result) { - if (result.stderr !== '') { - throw new Error(result.stderr); - } - const fileName = 'v' + version + '.json'; - const s3Url = S3BucketPath + fileName; - return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { - cwd, + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const fileName = 'v' + version + '.json'; + const s3Url = S3BucketPath + fileName; + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { + cwd, + }); + }) + .catch(function(err) { + console.log(err); }); -}) -.catch(function(err) { - console.log(err); -}); diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 161945443..9879bbb56 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -34,6 +34,7 @@ export { BlockParam, ContractEventArg, LogWithDecodedArgs, + TransactionReceipt, TransactionReceiptWithDecodedLogs, } from '@0xproject/types'; @@ -58,5 +59,3 @@ export { ExchangeContractEventArgs, ExchangeEvents, } from './contract_wrappers/generated/exchange'; - -export { TransactionReceipt } from '@0xproject/types'; diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md index d9198d3ed..90e82c632 100644 --- a/packages/abi-gen/CHANGELOG.md +++ b/packages/abi-gen/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.2.3 - _TBD, 2018_ +## v0.2.4 - _March 4, 2018_ * Add a `backend` parameter that allows you to specify the Ethereum library you use in your templates (`web3` or `ethers`). Ethers auto-converts small ints to numbers whereas Web3 doesn't. Defaults to `web3` (#413) * Add support for [tuple types](https://solidity.readthedocs.io/en/develop/abi-spec.html#handling-tuple-types) (#413) diff --git a/packages/abi-gen/README.md b/packages/abi-gen/README.md index 1188bd437..5232e59ce 100644 --- a/packages/abi-gen/README.md +++ b/packages/abi-gen/README.md @@ -4,8 +4,8 @@ This package allows you to generate TypeScript contract wrappers from ABI files. It's heavily inspired by [Geth abigen](https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts) but takes a different approach. You can write your custom handlebars templates which will allow you to seamlessly integrate the generated code into your existing codebase with existing conventions. -For an example of the generated [wrapper files](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/src/contract_wrappers/generated) check out 0x.js. -[Here](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/contract_templates) are the templates used to generate those files. +For an example of the generated [wrapper files](https://github.com/0xProject/0x-monorepo/tree/development/packages/0x.js/src/contract_wrappers/generated) check out 0x.js. +[Here](https://github.com/0xProject/0x-monorepo/tree/development/packages/0x.js/contract_templates) are the templates used to generate those files. ## Installation @@ -36,14 +36,14 @@ The abi file should be either a [Truffle](http://truffleframework.com/) contract ## How to write custom templates? -The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x.js/tree/development/packages/0x.js/contract_templates) and start adjusting them for your needs. +The best way to get started is to copy [0x.js templates](https://github.com/0xProject/0x-monorepo/tree/development/packages/0x.js/contract_templates) and start adjusting them for your needs. We use [handlebars](http://handlebarsjs.com/) template engine under the hood. You need to have a master template called `contract.mustache`. it will be used to generate each contract wrapper. Although - you don't need and probably shouldn't write all your logic in a single template file. You can write [partial templates](http://handlebarsjs.com/partials.html) and as long as they are within a partials folder - they will be registered and available. ## Which data/context do I get in my templates? For now you don't get much on top of methods abi, some useful helpers and a contract name because it was enough for our use-case, but if you need something else - create a PR. -See the [type definition](https://github.com/0xProject/0x.js/tree/development/packages/abi-gen/src/types.ts) of what we pass to the render method. +See the [type definition](https://github.com/0xProject/0x-monorepo/tree/development/packages/abi-gen/src/types.ts) of what we pass to the render method. ## Output files diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index 2506335a4..741cf3940 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/abi-gen", - "version": "0.2.3", + "version": "0.2.4", "description": "Generate contract wrappers from ABI and handlebars templates", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -15,15 +15,15 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/abi-gen/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/abi-gen/README.md", "dependencies": { - "@0xproject/utils": "^0.3.4", + "@0xproject/utils": "^0.4.0", "chalk": "^2.3.0", "glob": "^7.1.2", "handlebars": "^4.0.11", @@ -34,7 +34,7 @@ "yargs": "^10.0.3" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/glob": "^5.0.33", "@types/handlebars": "^4.0.36", "@types/mkdirp": "^0.5.1", @@ -44,6 +44,6 @@ "shx": "^0.2.2", "tslint": "5.8.0", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11" + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/assert/CHANGELOG.md b/packages/assert/CHANGELOG.md index 6721c4cb6..b37a810e3 100644 --- a/packages/assert/CHANGELOG.md +++ b/packages/assert/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.1.0 - _TBD, 2018_ +## v0.1.0 - _March 4, 2018_ * Remove isETHAddressHex checksum address check and assume address will be lowercased (#373) * Add an optional parameter `subSchemas` to `doesConformToSchema` method (#385) diff --git a/packages/assert/README.md b/packages/assert/README.md index 59ab63e91..1ea6acfb5 100644 --- a/packages/assert/README.md +++ b/packages/assert/README.md @@ -8,6 +8,14 @@ Standard type and schema assertions to be used across all 0x projects and packag yarn add @0xproject/assert ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage ```typescript diff --git a/packages/assert/package.json b/packages/assert/package.json index 0a1659dd8..cfe019444 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/assert", - "version": "0.0.20", + "version": "0.1.0", "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", @@ -17,19 +17,19 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/assert/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/assert/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", "@types/valid-url": "^1.0.2", "chai": "^4.0.1", - "chai-typescript-typings": "^0.0.3", + "chai-typescript-typings": "^0.0.4", "dirty-chai": "^2.0.1", "mocha": "^4.0.1", "npm-run-all": "^4.1.2", @@ -38,8 +38,8 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/json-schemas": "^0.7.12", - "@0xproject/utils": "^0.3.4", + "@0xproject/json-schemas": "^0.7.13", + "@0xproject/utils": "^0.4.0", "lodash": "^4.17.4", "valid-url": "^1.0.9" } diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md index 74e983f1c..1942b3b3e 100644 --- a/packages/base-contract/CHANGELOG.md +++ b/packages/base-contract/CHANGELOG.md @@ -1,5 +1,5 @@ # CHANGELOG -## v0.0.1 - _TBD, 2018_ +## v0.0.2 - _March 4, 2018_ - * Initial release (#TBD) + * Initial release diff --git a/packages/base-contract/README.md b/packages/base-contract/README.md index ff0d4d303..fa2f3da10 100644 --- a/packages/base-contract/README.md +++ b/packages/base-contract/README.md @@ -8,6 +8,15 @@ BaseContract to derive all auto-generated wrappers from yarn add @0xproject/base-contract ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", + "./node_modules/ethers-typescript-typings/index.d.ts" +] +``` + ## Usage ```javascript diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json index 6edbed161..8b31b8e12 100644 --- a/packages/base-contract/package.json +++ b/packages/base-contract/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/base-contract", - "version": "0.0.1", + "version": "0.0.2", "description": "0x Base TS contract", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -13,27 +13,27 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/base-contract/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", - "typescript": "2.7.1", - "ethers-typescript-typings": "^0.0.1", - "web3-typescript-typings": "^0.9.11" + "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.2.3", - "@0xproject/web3-wrapper": "^0.1.14", + "@0xproject/types": "^0.3.0", + "@0xproject/web3-wrapper": "^0.2.0", "ethers-contracts": "^2.2.1", + "ethers-typescript-typings": "^0.0.2", "lodash": "^4.17.4", - "web3": "^0.20.0" + "web3": "^0.20.0", + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/chai-as-promised-typescript-typings/package.json b/packages/chai-as-promised-typescript-typings/package.json index e1cbdd44f..18fdf438c 100644 --- a/packages/chai-as-promised-typescript-typings/package.json +++ b/packages/chai-as-promised-typescript-typings/package.json @@ -1,12 +1,12 @@ { "name": "chai-as-promised-typescript-typings", - "version": "0.0.9", + "version": "0.0.10", "description": "Typescript type definitions for chai-as-promised", "main": "index.d.ts", "types": "index.d.ts", "repository": { "type": "git", - "url": "git+https://github.com/0xProject/0x.js.git" + "url": "git+https://github.com/0xProject/0x-monorepo.git" }, "author": "Fabio Berger", "contributors": [ @@ -14,10 +14,10 @@ ], "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/chai-as-promised-typescript-typings#readme", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/chai-as-promised-typescript-typings#readme", "dependencies": { - "chai-typescript-typings": "^0.0.3" + "chai-typescript-typings": "^0.0.4" } } diff --git a/packages/chai-typescript-typings/package.json b/packages/chai-typescript-typings/package.json index 65103f76d..afd40df76 100644 --- a/packages/chai-typescript-typings/package.json +++ b/packages/chai-typescript-typings/package.json @@ -1,16 +1,16 @@ { "name": "chai-typescript-typings", - "version": "0.0.3", + "version": "0.0.4", "description": "Typescript type definitions for chai", "main": "index.d.ts", "types": "index.d.ts", "repository": { "type": "git", - "url": "git+https://github.com/0xProject/0x.js.git" + "url": "git+https://github.com/0xProject/0x-monorepo.git" }, "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/chai-typescript-typings#readme" + "homepage": "https://github.com/0xProject/0x-monorepo/packages/chai-typescript-typings#readme" } diff --git a/packages/connect/CHANGELOG.md b/packages/connect/CHANGELOG.md index 75ffb5274..e1fb7c795 100644 --- a/packages/connect/CHANGELOG.md +++ b/packages/connect/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.6.1 - _February 16, 2018_ +## v0.6.2 - _February 16, 2018_ * Fix JSON parse empty response (#407) diff --git a/packages/connect/README.md b/packages/connect/README.md index 7302322e6..393ea70a0 100644 --- a/packages/connect/README.md +++ b/packages/connect/README.md @@ -8,6 +8,14 @@ This repository contains a Javascript library that makes it easy to interact wit yarn add @0xproject/connect ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage * [Docs](https://0xproject.com/docs/connect) diff --git a/packages/connect/package.json b/packages/connect/package.json index c5c8f4ea0..f2eec9f00 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/connect", - "version": "0.6.1", + "version": "0.6.2", "description": "A javascript library for interacting with the standard relayer api", "keywords": [ "connect", @@ -15,7 +15,7 @@ "build:watch": "tsc -w", "build": "tsc", "clean": "shx rm -rf _bundles lib test_temp", - "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_DIR", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json", "copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures", "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", @@ -25,7 +25,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "author": "Brandon Millman", "license": "Apache-2.0", @@ -33,20 +33,20 @@ "node": ">=6.0.0" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/connect/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md", "dependencies": { - "@0xproject/assert": "^0.0.20", - "@0xproject/json-schemas": "^0.7.12", - "@0xproject/utils": "^0.3.4", + "@0xproject/assert": "^0.1.0", + "@0xproject/json-schemas": "^0.7.13", + "@0xproject/utils": "^0.4.0", "isomorphic-fetch": "^2.2.1", "lodash": "^4.17.4", "query-string": "^5.0.1", "websocket": "^1.0.25" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/fetch-mock": "^5.12.1", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", @@ -54,8 +54,8 @@ "@types/websocket": "^0.0.34", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.9", - "chai-typescript-typings": "^0.0.3", + "chai-as-promised-typescript-typings": "^0.0.10", + "chai-typescript-typings": "^0.0.4", "copyfiles": "^1.2.0", "dirty-chai": "^2.0.1", "fetch-mock": "^5.13.1", @@ -65,6 +65,6 @@ "tslint": "5.8.0", "typedoc": "~0.8.0", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11" + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/connect/scripts/postpublish.js b/packages/connect/scripts/postpublish.js index 869bad099..e447615f9 100644 --- a/packages/connect/scripts/postpublish.js +++ b/packages/connect/scripts/postpublish.js @@ -1,10 +1,16 @@ const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); const packageJSON = require('../package.json'); +const tsConfig = require('../tsconfig.json'); const cwd = __dirname + '/..'; const subPackageName = packageJSON.name; const S3BucketPath = 's3://connect-docs-jsons/'; +// Include any external packages that are part of the @0xproject/connect public interface +// to this array so that TypeDoc picks it up and adds it to the Docs JSON +const fileIncludes = [...tsConfig.include]; +const fileIncludesAdjusted = postpublish_utils.adjustFileIncludePaths(fileIncludes, __dirname); +const projectFiles = fileIncludesAdjusted.join(' '); let tag; let version; @@ -19,7 +25,7 @@ postpublish_utils .then(function(release) { console.log('POSTPUBLISH: Release successful, generating docs...'); const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json'; - return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { + return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_FILES="' + projectFiles + '" yarn docs:json', { cwd, }); }) diff --git a/packages/connect/scripts/stagedocs.js b/packages/connect/scripts/stagedocs.js index 868112a37..58272ab86 100644 --- a/packages/connect/scripts/stagedocs.js +++ b/packages/connect/scripts/stagedocs.js @@ -1,24 +1,30 @@ const execAsync = require('async-child-process').execAsync; const postpublish_utils = require('../../../scripts/postpublish_utils'); +const tsConfig = require('../tsconfig.json'); const cwd = __dirname + '/..'; const S3BucketPath = 's3://staging-connect-docs-jsons/'; const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json'; const version = process.env.DOCS_VERSION; +// Include any external packages that are part of the @0xproject/connect public interface +// to this array so that TypeDoc picks it up and adds it to the Docs JSON +const fileIncludes = [...tsConfig.include]; +const fileIncludesAdjusted = postpublish_utils.adjustFileIncludePaths(fileIncludes, __dirname); +const projectFiles = fileIncludesAdjusted.join(' '); -execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', { +execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_FILES="' + projectFiles + '" yarn docs:json', { cwd, }) -.then(function(result) { - if (result.stderr !== '') { - throw new Error(result.stderr); - } - const fileName = 'v' + version + '.json'; - const s3Url = S3BucketPath + fileName; - return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { - cwd, + .then(function(result) { + if (result.stderr !== '') { + throw new Error(result.stderr); + } + const fileName = 'v' + version + '.json'; + const s3Url = S3BucketPath + fileName; + return execAsync('S3_URL=' + s3Url + ' yarn upload_docs_json', { + cwd, + }); + }) + .catch(function(err) { + console.log(err); }); -}) -.catch(function(err) { - console.log(err); -}); diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 2e8ac3f06..132cd60cc 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -1,6 +1,6 @@ /** * This file is auto-generated using abi-gen. Don't edit directly. - * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/contract_templates. + * Templates can be found at https://github.com/0xProject/0x-monorepo/tree/development/packages/contract_templates. */ // tslint:disable:no-consecutive-blank-lines // tslint:disable-next-line:no-unused-variable diff --git a/packages/contracts/README.md b/packages/contracts/README.md index c209edf02..7628b057b 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -60,7 +60,7 @@ yarn lint Before running the tests, you will need to spin up a [TestRPC](https://www.npmjs.com/package/ethereumjs-testrpc) instance. -In a separate terminal, start TestRPC (a convenience command is provided as part of the [0x.js monorepo](https://github.com/0xProject/0x.js)) +In a separate terminal, start TestRPC (a convenience command is provided as part of the [0x.js monorepo](https://github.com/0xProject/0x-monorepo)) ```bash cd ../.. diff --git a/packages/contracts/globals.d.ts b/packages/contracts/globals.d.ts index 0e6586a4b..c6597054a 100644 --- a/packages/contracts/globals.d.ts +++ b/packages/contracts/globals.d.ts @@ -30,5 +30,6 @@ declare module 'web3-eth-abi' { declare module 'ethereumjs-abi' { const soliditySHA3: (argTypes: string[], args: any[]) => Buffer; + const soliditySHA256: (argTypes: string[], args: any[]) => Buffer; const methodID: (name: string, types: string[]) => Buffer; } diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 7cac30069..0d084a542 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "contracts", - "version": "2.1.13", + "version": "2.1.14", "description": "Smart contract components of 0x protocol", "main": "index.js", "directories": { @@ -17,27 +17,27 @@ "compile:comment": "Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846", "compile": "node ../deployer/lib/src/cli.js compile --contracts ${npm_package_config_contracts} --contracts-dir src/contracts --artifacts-dir src/artifacts", "clean": "shx rm -rf ./lib", - "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/artifacts/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "migrate": "node ../deployer/lib/src/cli.js migrate", "lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'", "test:circleci": "yarn test" }, "config": { - "contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry" + "contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry,Arbitrage,EtherDelta,AccountLevels" }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "author": "Amir Bandeali", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/contracts/README.md", "devDependencies": { - "@0xproject/dev-utils": "^0.1.0", - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/dev-utils": "^0.2.0", + "@0xproject/tslint-config": "^0.4.10", "@types/bluebird": "^3.5.3", "@types/lodash": "^4.14.86", "@types/node": "^8.0.53", @@ -45,11 +45,12 @@ "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.9", + "chai-as-promised-typescript-typings": "^0.0.10", "chai-bignumber": "^2.0.1", - "chai-typescript-typings": "^0.0.3", + "chai-typescript-typings": "^0.0.4", "copyfiles": "^1.2.0", "dirty-chai": "^2.0.1", + "ethers-typescript-typings": "^0.0.2", "mocha": "^4.0.1", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -58,18 +59,16 @@ "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", - "ethers-typescript-typings": "^0.0.1", - "web3-typescript-typings": "^0.9.11", + "web3-typescript-typings": "^0.10.0", "yargs": "^10.0.3" }, "dependencies": { - "0x.js": "^0.32.4", - "@0xproject/web3-wrapper": "^0.1.14", - "@0xproject/deployer": "^0.1.0", - "@0xproject/json-schemas": "^0.7.12", - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", - "@0xproject/web3-wrapper": "^0.1.14", + "0x.js": "^0.33.0", + "@0xproject/deployer": "^0.2.0", + "@0xproject/json-schemas": "^0.7.13", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", + "@0xproject/web3-wrapper": "^0.2.0", "bluebird": "^3.5.0", "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", diff --git a/packages/contracts/src/contracts/current/tutorials/Arbitrage/Arbitrage.sol b/packages/contracts/src/contracts/current/tutorials/Arbitrage/Arbitrage.sol new file mode 100644 index 000000000..a9f3c22e6 --- /dev/null +++ b/packages/contracts/src/contracts/current/tutorials/Arbitrage/Arbitrage.sol @@ -0,0 +1,114 @@ +pragma solidity ^0.4.19; + +import { Exchange } from "../../protocol/Exchange/Exchange.sol"; +import { EtherDelta } from "../EtherDelta/EtherDelta.sol"; +import { Ownable } from "../../utils/Ownable/Ownable.sol"; +import { Token } from "../../tokens/Token/Token.sol"; + +/// @title Arbitrage - Facilitates atomic arbitrage of ERC20 tokens between EtherDelta and 0x Exchange contract. +/// @author Leonid Logvinov - <leo@0xProject.com> +contract Arbitrage is Ownable { + + Exchange exchange; + EtherDelta etherDelta; + address proxyAddress; + + uint256 constant MAX_UINT = 2**256 - 1; + + function Arbitrage(address _exchangeAddress, address _etherDeltaAddress, address _proxyAddress) { + exchange = Exchange(_exchangeAddress); + etherDelta = EtherDelta(_etherDeltaAddress); + proxyAddress = _proxyAddress; + } + + /* + * Makes token tradeable by setting an allowance for etherDelta and 0x proxy contract. + * Also sets an allowance for the owner of the contracts therefore allowing to withdraw tokens. + */ + function setAllowances(address tokenAddress) external onlyOwner { + Token token = Token(tokenAddress); + token.approve(address(etherDelta), MAX_UINT); + token.approve(proxyAddress, MAX_UINT); + token.approve(owner, MAX_UINT); + } + + /* + * Because of the limits on the number of local variables in Solidity we need to compress parameters while loosing + * readability. Scheme of the parameter layout: + * + * addresses + * 0..4 orderAddresses + * 5 user + * + * values + * 0..5 orderValues + * 6 fillTakerTokenAmount + * 7 amountGet + * 8 amountGive + * 9 expires + * 10 nonce + * 11 amount + + * signature + * exchange then etherDelta + */ + function makeAtomicTrade( + address[6] addresses, uint[12] values, + uint8[2] v, bytes32[2] r, bytes32[2] s + ) external onlyOwner { + makeExchangeTrade(addresses, values, v, r, s); + makeEtherDeltaTrade(addresses, values, v, r, s); + } + + function makeEtherDeltaTrade( + address[6] addresses, uint[12] values, + uint8[2] v, bytes32[2] r, bytes32[2] s + ) internal { + uint amount = values[11]; + etherDelta.depositToken( + addresses[2], // tokenGet === makerToken + values[7] // amountGet + ); + etherDelta.trade( + addresses[2], // tokenGet === makerToken + values[7], // amountGet + addresses[3], // tokenGive === takerToken + values[8], // amountGive + values[9], // expires + values[10], // nonce + addresses[5], // user + v[1], + r[1], + s[1], + amount + ); + etherDelta.withdrawToken( + addresses[3], // tokenGive === tokenToken + values[8] // amountGive + ); + } + + function makeExchangeTrade( + address[6] addresses, uint[12] values, + uint8[2] v, bytes32[2] r, bytes32[2] s + ) internal { + address[5] memory orderAddresses = [ + addresses[0], // maker + addresses[1], // taker + addresses[2], // makerToken + addresses[3], // takerToken + addresses[4] // feeRecepient + ]; + uint[6] memory orderValues = [ + values[0], // makerTokenAmount + values[1], // takerTokenAmount + values[2], // makerFee + values[3], // takerFee + values[4], // expirationTimestampInSec + values[5] // salt + ]; + uint fillTakerTokenAmount = values[6]; // fillTakerTokenAmount + // Execute Exchange trade. It either succeeds in full or fails and reverts all the changes. + exchange.fillOrKillOrder(orderAddresses, orderValues, fillTakerTokenAmount, v[0], r[0], s[0]); + } +} diff --git a/packages/contracts/src/contracts/current/tutorials/EtherDelta/AccountLevels.sol b/packages/contracts/src/contracts/current/tutorials/EtherDelta/AccountLevels.sol new file mode 100644 index 000000000..8d7a930d3 --- /dev/null +++ b/packages/contracts/src/contracts/current/tutorials/EtherDelta/AccountLevels.sol @@ -0,0 +1,11 @@ +pragma solidity ^0.4.19; + +contract AccountLevels { + //given a user, returns an account level + //0 = regular user (pays take fee and make fee) + //1 = market maker silver (pays take fee, no make fee, gets rebate) + //2 = market maker gold (pays take fee, no make fee, gets entire counterparty's take fee as rebate) + function accountLevel(address user) constant returns(uint) { + return 0; + } +} diff --git a/packages/contracts/src/contracts/current/tutorials/EtherDelta/EtherDelta.sol b/packages/contracts/src/contracts/current/tutorials/EtherDelta/EtherDelta.sol new file mode 100644 index 000000000..49847ab48 --- /dev/null +++ b/packages/contracts/src/contracts/current/tutorials/EtherDelta/EtherDelta.sol @@ -0,0 +1,168 @@ +pragma solidity ^0.4.19; + +import { SafeMath } from "../../utils/SafeMath/SafeMath.sol"; +import { AccountLevels } from "./AccountLevels.sol"; +import { Token } from "../../tokens/Token/Token.sol"; + +contract EtherDelta is SafeMath { + address public admin; //the admin address + address public feeAccount; //the account that will receive fees + address public accountLevelsAddr; //the address of the AccountLevels contract + uint public feeMake; //percentage times (1 ether) + uint public feeTake; //percentage times (1 ether) + uint public feeRebate; //percentage times (1 ether) + mapping (address => mapping (address => uint)) public tokens; //mapping of token addresses to mapping of account balances (token=0 means Ether) + mapping (address => mapping (bytes32 => bool)) public orders; //mapping of user accounts to mapping of order hashes to booleans (true = submitted by user, equivalent to offchain signature) + mapping (address => mapping (bytes32 => uint)) public orderFills; //mapping of user accounts to mapping of order hashes to uints (amount of order that has been filled) + + event Order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user); + event Cancel(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s); + event Trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address get, address give); + event Deposit(address token, address user, uint amount, uint balance); + event Withdraw(address token, address user, uint amount, uint balance); + + function EtherDelta(address admin_, address feeAccount_, address accountLevelsAddr_, uint feeMake_, uint feeTake_, uint feeRebate_) { + admin = admin_; + feeAccount = feeAccount_; + accountLevelsAddr = accountLevelsAddr_; + feeMake = feeMake_; + feeTake = feeTake_; + feeRebate = feeRebate_; + } + + function() { + throw; + } + + function changeAdmin(address admin_) { + if (msg.sender != admin) throw; + admin = admin_; + } + + function changeAccountLevelsAddr(address accountLevelsAddr_) { + if (msg.sender != admin) throw; + accountLevelsAddr = accountLevelsAddr_; + } + + function changeFeeAccount(address feeAccount_) { + if (msg.sender != admin) throw; + feeAccount = feeAccount_; + } + + function changeFeeMake(uint feeMake_) { + if (msg.sender != admin) throw; + if (feeMake_ > feeMake) throw; + feeMake = feeMake_; + } + + function changeFeeTake(uint feeTake_) { + if (msg.sender != admin) throw; + if (feeTake_ > feeTake || feeTake_ < feeRebate) throw; + feeTake = feeTake_; + } + + function changeFeeRebate(uint feeRebate_) { + if (msg.sender != admin) throw; + if (feeRebate_ < feeRebate || feeRebate_ > feeTake) throw; + feeRebate = feeRebate_; + } + + function deposit() payable { + tokens[0][msg.sender] = safeAdd(tokens[0][msg.sender], msg.value); + Deposit(0, msg.sender, msg.value, tokens[0][msg.sender]); + } + + function withdraw(uint amount) { + if (tokens[0][msg.sender] < amount) throw; + tokens[0][msg.sender] = safeSub(tokens[0][msg.sender], amount); + if (!msg.sender.call.value(amount)()) throw; + Withdraw(0, msg.sender, amount, tokens[0][msg.sender]); + } + + function depositToken(address token, uint amount) { + //remember to call Token(address).approve(this, amount) or this contract will not be able to do the transfer on your behalf. + if (token==0) throw; + if (!Token(token).transferFrom(msg.sender, this, amount)) throw; + tokens[token][msg.sender] = safeAdd(tokens[token][msg.sender], amount); + Deposit(token, msg.sender, amount, tokens[token][msg.sender]); + } + + function withdrawToken(address token, uint amount) { + if (token==0) throw; + if (tokens[token][msg.sender] < amount) throw; + tokens[token][msg.sender] = safeSub(tokens[token][msg.sender], amount); + if (!Token(token).transfer(msg.sender, amount)) throw; + Withdraw(token, msg.sender, amount, tokens[token][msg.sender]); + } + + function balanceOf(address token, address user) constant returns (uint) { + return tokens[token][user]; + } + + function order(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce) { + bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); + orders[msg.sender][hash] = true; + Order(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender); + } + + function trade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount) { + //amount is in amountGet terms + bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); + if (!( + (orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && + block.number <= expires && + safeAdd(orderFills[user][hash], amount) <= amountGet + )) throw; + tradeBalances(tokenGet, amountGet, tokenGive, amountGive, user, amount); + orderFills[user][hash] = safeAdd(orderFills[user][hash], amount); + Trade(tokenGet, amount, tokenGive, amountGive * amount / amountGet, user, msg.sender); + } + + function tradeBalances(address tokenGet, uint amountGet, address tokenGive, uint amountGive, address user, uint amount) private { + uint feeMakeXfer = safeMul(amount, feeMake) / (1 ether); + uint feeTakeXfer = safeMul(amount, feeTake) / (1 ether); + uint feeRebateXfer = 0; + if (accountLevelsAddr != 0x0) { + uint accountLevel = AccountLevels(accountLevelsAddr).accountLevel(user); + if (accountLevel==1) feeRebateXfer = safeMul(amount, feeRebate) / (1 ether); + if (accountLevel==2) feeRebateXfer = feeTakeXfer; + } + tokens[tokenGet][msg.sender] = safeSub(tokens[tokenGet][msg.sender], safeAdd(amount, feeTakeXfer)); + tokens[tokenGet][user] = safeAdd(tokens[tokenGet][user], safeSub(safeAdd(amount, feeRebateXfer), feeMakeXfer)); + tokens[tokenGet][feeAccount] = safeAdd(tokens[tokenGet][feeAccount], safeSub(safeAdd(feeMakeXfer, feeTakeXfer), feeRebateXfer)); + tokens[tokenGive][user] = safeSub(tokens[tokenGive][user], safeMul(amountGive, amount) / amountGet); + tokens[tokenGive][msg.sender] = safeAdd(tokens[tokenGive][msg.sender], safeMul(amountGive, amount) / amountGet); + } + + function testTrade(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s, uint amount, address sender) constant returns(bool) { + if (!( + tokens[tokenGet][sender] >= amount && + availableVolume(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, user, v, r, s) >= amount + )) return false; + return true; + } + + function availableVolume(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) constant returns(uint) { + bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); + if (!( + (orders[user][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == user) && + block.number <= expires + )) return 0; + uint available1 = safeSub(amountGet, orderFills[user][hash]); + uint available2 = safeMul(tokens[tokenGive][user], amountGet) / amountGive; + if (available1<available2) return available1; + return available2; + } + + function amountFilled(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, address user, uint8 v, bytes32 r, bytes32 s) constant returns(uint) { + bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); + return orderFills[user][hash]; + } + + function cancelOrder(address tokenGet, uint amountGet, address tokenGive, uint amountGive, uint expires, uint nonce, uint8 v, bytes32 r, bytes32 s) { + bytes32 hash = sha256(this, tokenGet, amountGet, tokenGive, amountGive, expires, nonce); + if (!(orders[msg.sender][hash] || ecrecover(sha3("\x19Ethereum Signed Message:\n32", hash),v,r,s) == msg.sender)) throw; + orderFills[msg.sender][hash] = amountGet; + Cancel(tokenGet, amountGet, tokenGive, amountGive, expires, nonce, msg.sender, v, r, s); + } +} diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts new file mode 100644 index 000000000..2bafbff0b --- /dev/null +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -0,0 +1,226 @@ +import { ECSignature, SignedOrder, ZeroEx } from '0x.js'; +import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as chai from 'chai'; +import ethUtil = require('ethereumjs-util'); +import * as Web3 from 'web3'; + +import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage'; +import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta'; +import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; +import { Balances } from '../../util/balances'; +import { constants } from '../../util/constants'; +import { crypto } from '../../util/crypto'; +import { ExchangeWrapper } from '../../util/exchange_wrapper'; +import { OrderFactory } from '../../util/order_factory'; +import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; +import { chaiSetup } from '../utils/chai_setup'; +import { deployer } from '../utils/deployer'; + +chaiSetup.configure(); +const expect = chai.expect; +const web3 = web3Factory.create(); +const web3Wrapper = new Web3Wrapper(web3.currentProvider); +const blockchainLifecycle = new BlockchainLifecycle(); + +describe('Arbitrage', () => { + let coinbase: string; + let maker: string; + let edMaker: string; + let edFrontRunner: string; + let amountGet: BigNumber; + let amountGive: BigNumber; + let makerTokenAmount: BigNumber; + let takerTokenAmount: BigNumber; + const feeRecipient = ZeroEx.NULL_ADDRESS; + const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); + const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); + + let weth: Web3.ContractInstance; + let zrx: Web3.ContractInstance; + let arbitrage: ArbitrageContract; + let etherDelta: EtherDeltaContract; + + let signedOrder: SignedOrder; + let exWrapper: ExchangeWrapper; + let orderFactory: OrderFactory; + + let zeroEx: ZeroEx; + + // From a bird's eye view - we create two orders. + // 0x order of 1 ZRX (maker) for 1 WETH (taker) + // ED order of 2 WETH (tokenGive) for 1 ZRX (tokenGet) + // And then we do an atomic arbitrage between them which gives us 1 WETH. + before(async () => { + const accounts = await web3Wrapper.getAvailableAddressesAsync(); + [coinbase, maker, edMaker, edFrontRunner] = accounts; + weth = await deployer.deployAsync(ContractName.DummyToken); + zrx = await deployer.deployAsync(ContractName.DummyToken); + const accountLevels = await deployer.deployAsync(ContractName.AccountLevels); + const edAdminAddress = accounts[0]; + const edMakerFee = 0; + const edTakerFee = 0; + const edFeeRebate = 0; + const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [ + edAdminAddress, + feeRecipient, + accountLevels.address, + edMakerFee, + edTakerFee, + edFeeRebate, + ]); + etherDelta = new EtherDeltaContract(web3Wrapper, etherDeltaInstance.abi, etherDeltaInstance.address); + const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); + const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + zrx.address, + tokenTransferProxy.address, + ]); + await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] }); + zeroEx = new ZeroEx(web3.currentProvider, { + exchangeContractAddress: exchangeInstance.address, + networkId: constants.TESTRPC_NETWORK_ID, + }); + const exchange = new ExchangeContract(web3Wrapper, exchangeInstance.abi, exchangeInstance.address); + exWrapper = new ExchangeWrapper(exchange, zeroEx); + + makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); + takerTokenAmount = makerTokenAmount; + const defaultOrderParams = { + exchangeContractAddress: exchange.address, + maker, + feeRecipient, + makerTokenAddress: zrx.address, + takerTokenAddress: weth.address, + makerTokenAmount, + takerTokenAmount, + makerFee: new BigNumber(0), + takerFee: new BigNumber(0), + }; + orderFactory = new OrderFactory(zeroEx, defaultOrderParams); + const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [ + exchange.address, + etherDelta.address, + tokenTransferProxy.address, + ]); + arbitrage = new ArbitrageContract(web3Wrapper, arbitrageInstance.abi, arbitrageInstance.address); + // Enable arbitrage and withdrawals of tokens + await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase }); + await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase }); + + // Give some tokens to arbitrage contract + await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase }); + + // Fund the maker on exchange side + await zrx.setBalance(maker, makerTokenAmount, { from: coinbase }); + // Set the allowance for the maker on Exchange side + await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker }); + + amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); + // Fund the maker on EtherDelta side + await weth.setBalance(edMaker, amountGive, { from: coinbase }); + // Set the allowance for the maker on EtherDelta side + await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker }); + // Deposit maker funds into EtherDelta + await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker }); + + amountGet = makerTokenAmount; + // Fund the front runner on EtherDelta side + await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase }); + // Set the allowance for the front-runner on EtherDelta side + await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner }); + // Deposit front runner funds into EtherDelta + await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner }); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('makeAtomicTrade', () => { + let addresses: string[]; + let values: BigNumber[]; + let v: number[]; + let r: string[]; + let s: string[]; + let tokenGet: string; + let tokenGive: string; + let expires: BigNumber; + let nonce: BigNumber; + let edSignature: ECSignature; + before(async () => { + signedOrder = await orderFactory.newSignedOrderAsync(); + tokenGet = zrx.address; + tokenGive = weth.address; + const blockNumber = await web3Wrapper.getBlockNumberAsync(); + const ED_ORDER_EXPIRATION_IN_BLOCKS = 10; + expires = new BigNumber(blockNumber + ED_ORDER_EXPIRATION_IN_BLOCKS); + nonce = new BigNumber(42); + const edOrderHash = `0x${crypto + .solSHA256([etherDelta.address, tokenGet, amountGet, tokenGive, amountGive, expires, nonce]) + .toString('hex')}`; + const shouldAddPersonalMessagePrefix = false; + edSignature = await zeroEx.signOrderHashAsync(edOrderHash, edMaker, shouldAddPersonalMessagePrefix); + addresses = [ + signedOrder.maker, + signedOrder.taker, + signedOrder.makerTokenAddress, + signedOrder.takerTokenAddress, + signedOrder.feeRecipient, + edMaker, + ]; + const fillTakerTokenAmount = takerTokenAmount; + const edFillAmount = makerTokenAmount; + values = [ + signedOrder.makerTokenAmount, + signedOrder.takerTokenAmount, + signedOrder.makerFee, + signedOrder.takerFee, + signedOrder.expirationUnixTimestampSec, + signedOrder.salt, + fillTakerTokenAmount, + amountGet, + amountGive, + expires, + nonce, + edFillAmount, + ]; + v = [signedOrder.ecSignature.v, edSignature.v]; + r = [signedOrder.ecSignature.r, edSignature.r]; + s = [signedOrder.ecSignature.s, edSignature.s]; + }); + it('should successfully execute the arbitrage if not front-runned', async () => { + const txHash = await arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { + from: coinbase, + }); + const res = await zeroEx.awaitTransactionMinedAsync(txHash); + const postBalance = await weth.balanceOf(arbitrage.address); + expect(postBalance).to.be.bignumber.equal(amountGive); + }); + it('should fail and revert if front-runned', async () => { + const preBalance = await weth.balanceOf(arbitrage.address); + // Front-running transaction + await etherDelta.trade.sendTransactionAsync( + tokenGet, + amountGet, + tokenGive, + amountGive, + expires, + nonce, + edMaker, + edSignature.v, + edSignature.r, + edSignature.s, + amountGet, + { from: edFrontRunner }, + ); + // tslint:disable-next-line:await-promise + await expect( + arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }), + ).to.be.rejectedWith(constants.REVERT); + const postBalance = await weth.balanceOf(arbitrage.address); + expect(preBalance).to.be.bignumber.equal(postBalance); + }); + }); +}); diff --git a/packages/contracts/util/crypto.ts b/packages/contracts/util/crypto.ts index 9173df643..97b8f5643 100644 --- a/packages/contracts/util/crypto.ts +++ b/packages/contracts/util/crypto.ts @@ -13,6 +13,12 @@ export const crypto = { * valid Ethereum address -> address */ solSHA3(args: any[]): Buffer { + return crypto._solHash(args, ABI.soliditySHA3); + }, + solSHA256(args: any[]): Buffer { + return crypto._solHash(args, ABI.soliditySHA256); + }, + _solHash(args: any[], hashFunction: (types: string[], values: any[]) => Buffer) { const argTypes: string[] = []; _.each(args, (arg, i) => { const isNumber = _.isFinite(arg); @@ -31,7 +37,7 @@ export const crypto = { throw new Error(`Unable to guess arg type: ${arg}`); } }); - const hash = ABI.soliditySHA3(argTypes, args); + const hash = hashFunction(argTypes, args); return hash; }, }; diff --git a/packages/contracts/util/types.ts b/packages/contracts/util/types.ts index d6e4c587d..61a19acb4 100644 --- a/packages/contracts/util/types.ts +++ b/packages/contracts/util/types.ts @@ -96,6 +96,9 @@ export enum ContractName { EtherToken = 'WETH9', MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', MaliciousToken = 'MaliciousToken', + AccountLevels = 'AccountLevels', + EtherDelta = 'EtherDelta', + Arbitrage = 'Arbitrage', } export interface Artifact { diff --git a/packages/deployer/CHANGELOG.md b/packages/deployer/CHANGELOG.md index a63d9cf3b..05383bed5 100644 --- a/packages/deployer/CHANGELOG.md +++ b/packages/deployer/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.2.0 - _TBD, 2018_ +## v0.2.0 - _March 4, 2018_ * Check dependencies when determining if contracts should be recompiled (#408). diff --git a/packages/deployer/README.md b/packages/deployer/README.md index f4e688fd7..4c4d234dd 100644 --- a/packages/deployer/README.md +++ b/packages/deployer/README.md @@ -22,11 +22,11 @@ Commands: Options: --version Show version number [boolean] --contracts-dir path of contracts directory to compile - [string] [default: "/Users/leonidlogvinov/Dev/0x/0x.js/contracts"] + [string] [default: "/Users/leonidlogvinov/Dev/0x/contracts"] --network-id mainnet=1, kovan=42, testrpc=50 [number] [default: 50] --should-optimize enable optimizer [boolean] [default: false] --artifacts-dir path to write contracts artifacts to - [string] [default: "/Users/leonidlogvinov/Dev/0x/0x.js/build/artifacts/"] + [string] [default: "/Users/leonidlogvinov/Dev/0x/build/artifacts/"] --jsonrpc-port port connected to JSON RPC [number] [default: 8545] --gas-price gasPrice to be used for transactions [string] [default: "2000000000"] diff --git a/packages/deployer/package.json b/packages/deployer/package.json index 2a6668fa6..32f67f071 100644 --- a/packages/deployer/package.json +++ b/packages/deployer/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/deployer", - "version": "0.1.0", + "version": "0.2.0", "description": "Smart contract deployer of 0x protocol", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -19,31 +19,31 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "author": "Amir Bandeali", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/deployer/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/deployer/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "chai": "^4.0.1", "copyfiles": "^1.2.0", + "ethers-typescript-typings": "^0.0.2", "mocha": "^4.0.1", "shx": "^0.2.2", "tslint": "5.8.0", "types-bn": "^0.0.1", "typescript": "2.7.1", - "ethers-typescript-typings": "^0.0.1", - "web3-typescript-typings": "^0.9.11" + "web3-typescript-typings": "^0.10.0" }, "dependencies": { - "@0xproject/json-schemas": "^0.7.12", - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", - "@0xproject/web3-wrapper": "^0.1.14", + "@0xproject/json-schemas": "^0.7.13", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", + "@0xproject/web3-wrapper": "^0.2.0", "ethereumjs-util": "^5.1.1", "lodash": "^4.17.4", "solc": "^0.4.18", diff --git a/packages/dev-utils/CHANGELOG.md b/packages/dev-utils/CHANGELOG.md index 41f59d3af..ecc5546ae 100644 --- a/packages/dev-utils/CHANGELOG.md +++ b/packages/dev-utils/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.1.0 - _February 16, 2018_ +## v0.2.0 - _February 16, 2018_ * Remove subproviders (#392) diff --git a/packages/dev-utils/README.md b/packages/dev-utils/README.md index 5a8e71f2f..f7e30df1e 100644 --- a/packages/dev-utils/README.md +++ b/packages/dev-utils/README.md @@ -7,3 +7,11 @@ Dev utils to be shared across 0x projects and packages ```bash yarn add @0xproject/dev-utils ``` + +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index dc6410211..4ad613dbe 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/dev-utils", - "version": "0.1.0", + "version": "0.2.0", "description": "0x dev TS utils", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -16,19 +16,19 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/dev-utils/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/dev-utils/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", - "@0xproject/web3-wrapper": "^0.1.14", + "@0xproject/tslint-config": "^0.4.10", + "@0xproject/web3-wrapper": "^0.2.0", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", "chai": "^4.0.1", - "chai-typescript-typings": "^0.0.3", + "chai-typescript-typings": "^0.0.4", "mocha": "^4.0.1", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -38,9 +38,9 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/subproviders": "^0.5.0", - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", + "@0xproject/subproviders": "^0.6.0", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", "ethereumjs-util": "^5.1.2", "lodash": "^4.17.4", "request-promise-native": "^1.0.5", diff --git a/packages/ethers-typescript-typings/CHANGELOG.md b/packages/ethers-typescript-typings/CHANGELOG.md index d67d5c73d..00bf165a4 100644 --- a/packages/ethers-typescript-typings/CHANGELOG.md +++ b/packages/ethers-typescript-typings/CHANGELOG.md @@ -1,5 +1,5 @@ # CHANGELOG -## v0.0.1 - _TBD, 2018_ +## v0.0.2 - _March 4, 2018_ * Initial types (#413) diff --git a/packages/ethers-typescript-typings/package.json b/packages/ethers-typescript-typings/package.json index 0e6f517c8..588ff52b5 100644 --- a/packages/ethers-typescript-typings/package.json +++ b/packages/ethers-typescript-typings/package.json @@ -1,6 +1,6 @@ { "name": "ethers-typescript-typings", - "version": "0.0.1", + "version": "0.0.2", "description": "Typescript type definitions for ethers.js", "main": "index.d.ts", "types": "index.d.ts", @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/0xProject/0x.js.git" + "url": "git+https://github.com/0xProject/0x-monorepo.git" }, "author": "Fabio Berger", "contributors": [ @@ -17,9 +17,9 @@ ], "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/ethers-typescript-typings#readme", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/ethers-typescript-typings#readme", "devDependencies": { "tslint": "5.8.0", "tslint-config-0xproject": "^0.0.2", diff --git a/packages/json-schemas/CHANGELOG.md b/packages/json-schemas/CHANGELOG.md index 7fdae6cf3..ab98227af 100644 --- a/packages/json-schemas/CHANGELOG.md +++ b/packages/json-schemas/CHANGELOG.md @@ -1,8 +1,8 @@ # CHANGELOG -## v0.7.10 - _February 9, 2018_ +## v0.7.13 - _February 9, 2018_ -* Fix publishing issue where .npmignore was not properly excluding undesired content (#389) + * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) ## v0.7.0 - _December 20, 2017_ diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index 6952c9bdd..230732cec 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/json-schemas", - "version": "0.7.12", + "version": "0.7.13", "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", @@ -15,26 +15,26 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "author": "", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/json-schemas/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/json-schemas/README.md", "dependencies": { "jsonschema": "^1.2.0", "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", - "@0xproject/utils": "^0.3.4", + "@0xproject/tslint-config": "^0.4.10", + "@0xproject/utils": "^0.4.0", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", "chai": "^4.0.1", - "chai-typescript-typings": "^0.0.3", + "chai-typescript-typings": "^0.0.4", "dirty-chai": "^2.0.1", "lodash.foreach": "^4.5.0", "mocha": "^4.0.1", diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index 8edfef605..c9bbe0c6a 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/monorepo-scripts", - "version": "0.1.11", + "version": "0.1.12", "private": true, "description": "Helper scripts for the monorepo", "scripts": { @@ -12,15 +12,15 @@ }, "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/monorepo-scripts/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/monorepo-scripts/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/glob": "^5.0.33", "@types/node": "^8.0.53", "shx": "^0.2.2", diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md index c2d590a35..7e1e006e3 100644 --- a/packages/subproviders/CHANGELOG.md +++ b/packages/subproviders/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## v0.6.0 - _March 4, 2018_ + + * Move web3 types from being a devDep to a dep since one cannot use this package without it (#429) + * Add `numberOfAccounts` param to `LedgerSubprovider` method `getAccountsAsync` (#432) + ## v0.5.0 - _February 16, 2018_ * Add EmptyWalletSubprovider and FakeGasEstimateSubprovider (#392) diff --git a/packages/subproviders/README.md b/packages/subproviders/README.md index 39e4a46e7..67a6a92d2 100644 --- a/packages/subproviders/README.md +++ b/packages/subproviders/README.md @@ -10,6 +10,14 @@ We have written up a [Wiki](https://0xproject.com/wiki#Web3-Provider-Examples) a yarn add @0xproject/subproviders ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage Simply import the subprovider you are interested in using: diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 5e9c2ed89..ec0642bce 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/subproviders", - "version": "0.5.0", + "version": "0.6.0", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "license": "Apache-2.0", @@ -18,9 +18,9 @@ "test:integration": "run-s clean build run_mocha_integration" }, "dependencies": { - "@0xproject/assert": "^0.0.20", - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", + "@0xproject/assert": "^0.1.0", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", "bn.js": "^4.11.8", "es6-promisify": "^5.0.0", "ethereumjs-tx": "^1.3.3", @@ -30,19 +30,20 @@ "lodash": "^4.17.4", "semaphore-async-await": "^1.5.1", "web3": "^0.20.0", - "web3-provider-engine": "^13.0.1" + "web3-provider-engine": "^13.0.1", + "web3-typescript-typings": "^0.10.0" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", - "@0xproject/utils": "^0.3.4", + "@0xproject/tslint-config": "^0.4.10", + "@0xproject/utils": "^0.4.0", "@types/lodash": "^4.14.86", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", "awesome-typescript-loader": "^3.1.3", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", - "chai-as-promised-typescript-typings": "^0.0.9", - "chai-typescript-typings": "^0.0.3", + "chai-as-promised-typescript-typings": "^0.0.10", + "chai-typescript-typings": "^0.0.4", "dirty-chai": "^2.0.1", "mocha": "^4.0.1", "npm-run-all": "^4.1.2", @@ -51,7 +52,6 @@ "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11", "webpack": "^3.1.0" } } diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts index 5966a88bb..85cdf0efc 100644 --- a/packages/subproviders/src/subproviders/ledger.ts +++ b/packages/subproviders/src/subproviders/ledger.ts @@ -19,7 +19,7 @@ import { import { Subprovider } from './subprovider'; const DEFAULT_DERIVATION_PATH = `44'/60'/0'`; -const NUM_ADDRESSES_TO_FETCH = 10; +const DEFAULT_NUM_ADDRESSES_TO_FETCH = 10; const ASK_FOR_ON_DEVICE_CONFIRMATION = false; const SHOULD_GET_CHAIN_CODE = true; @@ -129,7 +129,7 @@ export class LedgerSubprovider extends Subprovider { return; } } - public async getAccountsAsync(): Promise<string[]> { + public async getAccountsAsync(numberOfAccounts: number = DEFAULT_NUM_ADDRESSES_TO_FETCH): Promise<string[]> { this._ledgerClientIfExists = await this._createLedgerClientAsync(); let ledgerResponse; @@ -148,7 +148,7 @@ export class LedgerSubprovider extends Subprovider { hdKey.chainCode = new Buffer(ledgerResponse.chainCode, 'hex'); const accounts = []; - for (let i = 0; i < NUM_ADDRESSES_TO_FETCH; i++) { + for (let i = 0; i < numberOfAccounts; i++) { const derivedHDNode = hdKey.derive(`m/${i + this._derivationPathIndex}`); const derivedPublicKey = derivedHDNode.publicKey; const shouldSanitizePublicKey = true; diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts index 628b532d7..b052a76d2 100644 --- a/packages/subproviders/test/integration/ledger_subprovider_test.ts +++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts @@ -26,11 +26,17 @@ describe('LedgerSubprovider', () => { }); }); describe('direct method calls', () => { - it('returns a list of accounts', async () => { + it('returns default number of accounts', async () => { const accounts = await ledgerSubprovider.getAccountsAsync(); expect(accounts[0]).to.not.be.an('undefined'); expect(accounts.length).to.be.equal(10); }); + it('returns requested number of accounts', async () => { + const numberOfAccounts = 20; + const accounts = await ledgerSubprovider.getAccountsAsync(numberOfAccounts); + expect(accounts[0]).to.not.be.an('undefined'); + expect(accounts.length).to.be.equal(numberOfAccounts); + }); it('signs a personal message', async () => { const data = ethUtils.bufferToHex(ethUtils.toBuffer('hello world')); const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data); @@ -172,7 +178,7 @@ describe('LedgerSubprovider', () => { }; const callback = reportCallbackErrors(done)((err: Error, response: Web3.JSONRPCResponsePayload) => { expect(err).to.be.a('null'); - const result = response.result.result; + const result = response.result; expect(result.length).to.be.equal(66); expect(result.substr(0, 2)).to.be.equal('0x'); done(); diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts index 1c70dd3a6..0d301bce9 100644 --- a/packages/subproviders/test/unit/ledger_subprovider_test.ts +++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts @@ -62,11 +62,17 @@ describe('LedgerSubprovider', () => { }); describe('direct method calls', () => { describe('success cases', () => { - it('returns a list of accounts', async () => { + it('returns default number of accounts', async () => { const accounts = await ledgerSubprovider.getAccountsAsync(); expect(accounts[0]).to.be.equal(FAKE_ADDRESS); expect(accounts.length).to.be.equal(10); }); + it('returns requested number of accounts', async () => { + const numberOfAccounts = 20; + const accounts = await ledgerSubprovider.getAccountsAsync(numberOfAccounts); + expect(accounts[0]).to.be.equal(FAKE_ADDRESS); + expect(accounts.length).to.be.equal(numberOfAccounts); + }); it('signs a personal message', async () => { const data = ethUtils.bufferToHex(ethUtils.toBuffer('hello world')); const ecSignatureHex = await ledgerSubprovider.signPersonalMessageAsync(data); diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 64f4427e1..ccb303909 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.14", + "version": "1.0.15", "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.4", - "@0xproject/subproviders": "^0.5.0", - "@0xproject/utils": "^0.3.4", + "0x.js": "^0.33.0", + "@0xproject/subproviders": "^0.6.0", + "@0xproject/utils": "^0.4.0", "body-parser": "^1.17.1", "ethereumjs-tx": "^1.3.3", "ethereumjs-util": "^5.1.1", @@ -28,7 +28,7 @@ "web3-provider-engine": "^13.0.1" }, "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/body-parser": "^1.16.1", "@types/express": "^4.0.35", "@types/lodash": "^4.14.86", @@ -41,7 +41,7 @@ "types-bn": "^0.0.1", "types-ethereumjs-util": "0xProject/types-ethereumjs-util", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11", + "web3-typescript-typings": "^0.10.0", "webpack": "^3.1.0", "webpack-node-externals": "^1.6.0" } diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index 3f431f1b4..4830a448e 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/tslint-config", - "version": "0.4.9", + "version": "0.4.10", "description": "Lint rules related to 0xProject for TSLint", "main": "tslint.json", "scripts": { @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/0xProject/0x.js.git" + "url": "git://github.com/0xProject/0x-monorepo.git" }, "keywords": [ "tslint", @@ -26,9 +26,9 @@ }, "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/tslint-config/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/tslint-config/README.md", "devDependencies": { "@types/lodash": "^4.14.86", "shx": "^0.2.2", diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index a4f293d60..e1117b170 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,9 +1,10 @@ # CHANGELOG -## v0.2.4 - _TBD, 2018_ +## v0.3.0 - _March 4, 2018_ * Add `data` to `TxData` (#413) * Add `number` as an option to `ContractEventArg` (#413) + * Move web3 types from devDep to dep since required when using this package (#429) ## v0.2.1 - _February 9, 2018_ diff --git a/packages/types/README.md b/packages/types/README.md index d2fa33c8f..5101ee544 100644 --- a/packages/types/README.md +++ b/packages/types/README.md @@ -8,6 +8,14 @@ Typescript types shared across 0x projects and packages yarn add -D @0xproject/types ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage ```javascript diff --git a/packages/types/package.json b/packages/types/package.json index afaa1aa48..31e853113 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/types", - "version": "0.2.3", + "version": "0.3.0", "description": "0x types", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -13,21 +13,21 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/types/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/types/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "shx": "^0.2.2", "tslint": "5.8.0", - "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11" + "typescript": "2.7.1" }, "dependencies": { "bignumber.js": "~4.1.0", - "web3": "^0.20.0" + "web3": "^0.20.0", + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index 81792bee8..bf9cf53b4 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -1,8 +1,9 @@ # CHANGELOG -## v0.4.0 - _TBD, 2018_ +## v0.4.0 - _March 4, 2018_ * Use `ethers-contracts` as a backend to decode event args (#413) + * Move web3 types from devDep to dep since required when using this package (#429) ## v0.3.2 - _February 9, 2018_ diff --git a/packages/utils/README.md b/packages/utils/README.md index ffb0d0190..22de85f4a 100644 --- a/packages/utils/README.md +++ b/packages/utils/README.md @@ -8,6 +8,14 @@ Utils to be shared across 0x projects and packages yarn add @0xproject/utils ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage ```javascript diff --git a/packages/utils/package.json b/packages/utils/package.json index 4f63aa4ce..424a73dd2 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/utils", - "version": "0.3.4", + "version": "0.4.0", "description": "0x TS utils", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -13,28 +13,28 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/utils/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/utils/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", - "typescript": "2.7.1", - "ethers-typescript-typings": "^0.0.1", - "web3-typescript-typings": "^0.9.11" + "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.2.3", + "@0xproject/types": "^0.3.0", "bignumber.js": "~4.1.0", "ethers-contracts": "^2.2.1", + "ethers-typescript-typings": "^0.0.2", "js-sha3": "^0.7.0", "lodash": "^4.17.4", - "web3": "^0.20.0" + "web3": "^0.20.0", + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/web3-typescript-typings/CHANGELOG.md b/packages/web3-typescript-typings/CHANGELOG.md index 74dc8748f..1bf6d7459 100644 --- a/packages/web3-typescript-typings/CHANGELOG.md +++ b/packages/web3-typescript-typings/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.10.0 - _TBD, 2018_ +## v0.10.0 - _March 4, 2018_ * Support ABIv2 (#401) diff --git a/packages/web3-typescript-typings/package.json b/packages/web3-typescript-typings/package.json index 2b9430323..7db818759 100644 --- a/packages/web3-typescript-typings/package.json +++ b/packages/web3-typescript-typings/package.json @@ -1,6 +1,6 @@ { "name": "web3-typescript-typings", - "version": "0.9.11", + "version": "0.10.0", "description": "Typescript type definitions for web3", "main": "index.d.ts", "types": "index.d.ts", @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/0xProject/0x.js.git" + "url": "git+https://github.com/0xProject/0x-monorepo.git" }, "author": "Fabio Berger", "contributors": [ @@ -17,9 +17,9 @@ ], "license": "Apache-2.0", "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/web3-typescript-typings#readme", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/web3-typescript-typings#readme", "devDependencies": { "@types/bignumber.js": "^4.0.2", "tslint": "5.8.0", diff --git a/packages/web3-wrapper/CHANGELOG.md b/packages/web3-wrapper/CHANGELOG.md index eef665d24..ac0f5ff0b 100644 --- a/packages/web3-wrapper/CHANGELOG.md +++ b/packages/web3-wrapper/CHANGELOG.md @@ -1,6 +1,6 @@ # CHANGELOG -## v0.2.0 _TBD, 2018_ +## v0.2.0 _March 4, 2018_ * Ensure all returned user addresses are lowercase (#373) * Add `web3Wrapper.callAsync` (#413) diff --git a/packages/web3-wrapper/README.md b/packages/web3-wrapper/README.md index 7ed66ca41..0d5defb1e 100644 --- a/packages/web3-wrapper/README.md +++ b/packages/web3-wrapper/README.md @@ -8,6 +8,14 @@ Wrapped version of web3 with a nicer interface that is used across 0x projects a yarn add @0xproject/web3-wrapper ``` +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +``` +"include": [ + "./node_modules/web3-typescript-typings/index.d.ts", +] +``` + ## Usage ```typescript diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index 55f1ffff0..b754e791c 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/web3-wrapper", - "version": "0.1.14", + "version": "0.2.0", "description": "Wraps around web3 and gives a nicer interface", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -13,27 +13,27 @@ "license": "Apache-2.0", "repository": { "type": "git", - "url": "https://github.com/0xProject/0x.js.git" + "url": "https://github.com/0xProject/0x-monorepo.git" }, "bugs": { - "url": "https://github.com/0xProject/0x.js/issues" + "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x.js/packages/web3-wrapper/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/packages/web3-wrapper/README.md", "devDependencies": { - "@0xproject/tslint-config": "^0.4.9", + "@0xproject/tslint-config": "^0.4.10", "@types/lodash": "^4.14.86", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", - "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11" + "typescript": "2.7.1" }, "dependencies": { - "@0xproject/types": "^0.2.3", - "@0xproject/utils": "^0.3.4", + "@0xproject/types": "^0.3.0", + "@0xproject/utils": "^0.4.0", "ethers-contracts": "^2.2.1", - "ethers-typescript-typings": "^0.0.1", + "ethers-typescript-typings": "^0.0.2", "lodash": "^4.17.4", - "web3": "^0.20.0" + "web3": "^0.20.0", + "web3-typescript-typings": "^0.10.0" } } diff --git a/packages/website/md/docs/0xjs/installation.md b/packages/website/md/docs/0xjs/installation.md index 5f5c9137e..ac0a47699 100644 --- a/packages/website/md/docs/0xjs/installation.md +++ b/packages/website/md/docs/0xjs/installation.md @@ -18,7 +18,7 @@ import { ZeroEx } from '0x.js'; **Install** -Download the UMD module from our [releases page](https://github.com/0xProject/0x.js/releases) and add it to your project. +Download the UMD module from our [releases page](https://github.com/0xProject/0x-monorepo/releases) and add it to your project. **Import** diff --git a/packages/website/md/docs/0xjs/introduction.md b/packages/website/md/docs/0xjs/introduction.md index 7bad3eaa9..008376d33 100644 --- a/packages/website/md/docs/0xjs/introduction.md +++ b/packages/website/md/docs/0xjs/introduction.md @@ -1 +1 @@ -Welcome to the [0x.js](https://github.com/0xProject/0x.js) documentation! 0x.js is a Javascript library for interacting with the 0x protocol. With it, you can easily make calls to the 0x smart contracts as well as any ERC20 token. Functionality includes generating, signing, filling and cancelling orders, verifying an orders signature, setting or checking a users ERC20 token balance/allowance and much more. +Welcome to the [0x.js](https://github.com/0xProject/0x-monorepo) documentation! 0x.js is a Javascript library for interacting with the 0x protocol. With it, you can easily make calls to the 0x smart contracts as well as any ERC20 token. Functionality includes generating, signing, filling and cancelling orders, verifying an orders signature, setting or checking a users ERC20 token balance/allowance and much more. diff --git a/packages/website/md/docs/connect/installation.md b/packages/website/md/docs/connect/installation.md index 184fa6e0d..950bf92ca 100644 --- a/packages/website/md/docs/connect/installation.md +++ b/packages/website/md/docs/connect/installation.md @@ -12,4 +12,4 @@ import { HttpClient } from '@0xproject/connect'; ### Wiki -Check out our [0x Connect introduction tutorial](https://0xproject.com/wiki#Intro-Tutorial:-Connect) for information on how to integrate relayers into your application. +Check out our [0x Connect introduction tutorial](https://0xproject.com/wiki#Intro-Tutorial) for information on how to integrate relayers into your application. diff --git a/packages/website/md/docs/connect/introduction.md b/packages/website/md/docs/connect/introduction.md index 533e1481a..4e3039442 100644 --- a/packages/website/md/docs/connect/introduction.md +++ b/packages/website/md/docs/connect/introduction.md @@ -1 +1 @@ -Welcome to the [0x Connect](https://github.com/0xProject/0x.js/tree/development/packages/connect) documentation! 0x Connect is a Javascript library that makes it easy to interact with relayers that conform to the [Standard Relayer API](https://github.com/0xProject/standard-relayer-api). Functionality includes getting supported token pairs from a relayer, getting orders filtered by different attributes, getting individual orders specified by order hash, getting orderbooks for specific token pairs, getting fee information, and submitting orders. +Welcome to the [0x Connect](https://github.com/0xProject/0x-monorepo/tree/development/packages/connect) documentation! 0x Connect is a Javascript library that makes it easy to interact with relayers that conform to the [Standard Relayer API](https://github.com/0xProject/standard-relayer-api). Functionality includes getting supported token pairs from a relayer, getting orders filtered by different attributes, getting individual orders specified by order hash, getting orderbooks for specific token pairs, getting fee information, and submitting orders. diff --git a/packages/website/package.json b/packages/website/package.json index ceb3853f9..ca1b596f3 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -1,6 +1,6 @@ { "name": "@0xproject/website", - "version": "0.0.16", + "version": "0.0.17", "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.4", - "@0xproject/subproviders": "^0.5.0", - "@0xproject/utils": "^0.3.4", + "0x.js": "^0.33.0", + "@0xproject/subproviders": "^0.6.0", + "@0xproject/utils": "^0.4.0", "accounting": "^0.4.1", "basscss": "^8.0.3", "blockies": "^0.0.2", @@ -43,10 +43,10 @@ "react-document-title": "^2.0.3", "react-dom": "15.6.1", "react-ga": "^2.4.1", - "react-highlight": "^0.10.0", + "react-highlight": "0xproject/react-highlight", "react-html5video": "^2.1.0", "react-inlinesvg": "^0.5.5", - "react-markdown": "^2.5.0", + "react-markdown": "^3.2.2", "react-recaptcha": "^2.3.2", "react-redux": "^5.0.3", "react-router-dom": "^4.1.1", @@ -87,7 +87,7 @@ "copy-webpack-plugin": "^4.0.1", "copyfiles": "^1.2.0", "css-loader": "0.23.x", - "ethers-typescript-typings": "^0.0.1", + "ethers-typescript-typings": "^0.0.2", "exports-loader": "0.6.x", "imports-loader": "0.6.x", "json-loader": "^0.5.4", @@ -99,7 +99,7 @@ "tslint": "5.8.0", "tslint-config-0xproject": "^0.0.2", "typescript": "2.7.1", - "web3-typescript-typings": "^0.9.11", + "web3-typescript-typings": "^0.10.0", "webpack": "^3.1.0", "webpack-dev-middleware": "^1.10.0", "webpack-dev-server": "^2.5.0" diff --git a/packages/website/public/images/doc_icons/connect.png b/packages/website/public/images/doc_icons/connect.png Binary files differindex ba9bb8a3a..244f504b3 100644 --- a/packages/website/public/images/doc_icons/connect.png +++ b/packages/website/public/images/doc_icons/connect.png diff --git a/packages/website/public/images/doc_icons/contracts.png b/packages/website/public/images/doc_icons/contracts.png Binary files differindex f5c6545ca..03956f162 100644 --- a/packages/website/public/images/doc_icons/contracts.png +++ b/packages/website/public/images/doc_icons/contracts.png diff --git a/packages/website/public/images/doc_icons/zeroExJs.png b/packages/website/public/images/doc_icons/zeroExJs.png Binary files differindex 029777ffe..fe0c49a0f 100644 --- a/packages/website/public/images/doc_icons/zeroExJs.png +++ b/packages/website/public/images/doc_icons/zeroExJs.png diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 85b4e892f..156dc44e8 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -69,14 +69,6 @@ export class Blockchain { private _cachedProviderNetworkId: number; private _ledgerSubprovider: LedgerWalletSubprovider; private _defaultGasPrice: BigNumber; - private static async _onPageLoadAsync(): Promise<void> { - if (document.readyState === 'complete') { - return; // Already loaded - } - return new Promise<void>((resolve, reject) => { - window.onload = () => resolve(); - }); - } private static _getNameGivenProvider(provider: Web3.Provider): string { if (!_.isUndefined((provider as any).isMetaMask)) { return constants.PROVIDER_NAME_METAMASK; @@ -710,7 +702,7 @@ export class Blockchain { return tokenByAddress; } private async _onPageLoadInitFireAndForgetAsync() { - await Blockchain._onPageLoadAsync(); // wait for page to load + await utils.onPageLoadAsync(); // wait for page to load // Hack: We need to know the networkId the injectedWeb3 is connected to (if it is defined) in // order to properly instantiate the web3Wrapper. Since we must use the async call, we cannot diff --git a/packages/website/ts/containers/about.tsx b/packages/website/ts/containers/about.ts index ce8fd3afb..ce8fd3afb 100644 --- a/packages/website/ts/containers/about.tsx +++ b/packages/website/ts/containers/about.ts diff --git a/packages/website/ts/containers/connect_documentation.tsx b/packages/website/ts/containers/connect_documentation.ts index 464bdcd74..6a5ba1f99 100644 --- a/packages/website/ts/containers/connect_documentation.tsx +++ b/packages/website/ts/containers/connect_documentation.ts @@ -28,7 +28,7 @@ const docsInfoConfig: DocsInfoConfig = { id: DocPackages.Connect, type: SupportedDocJson.TypeDoc, displayName: '0x Connect', - packageUrl: 'https://github.com/0xProject/0x.js', + packageUrl: 'https://github.com/0xProject/0x-monorepo', menu: { introduction: [connectDocSections.introduction], install: [connectDocSections.installation], diff --git a/packages/website/ts/containers/faq.tsx b/packages/website/ts/containers/faq.ts index b539e33c9..b539e33c9 100644 --- a/packages/website/ts/containers/faq.tsx +++ b/packages/website/ts/containers/faq.ts diff --git a/packages/website/ts/containers/generate_order_form.tsx b/packages/website/ts/containers/generate_order_form.ts index 8c5deb690..8c5deb690 100644 --- a/packages/website/ts/containers/generate_order_form.tsx +++ b/packages/website/ts/containers/generate_order_form.ts diff --git a/packages/website/ts/containers/landing.tsx b/packages/website/ts/containers/landing.ts index a620bb12e..a620bb12e 100644 --- a/packages/website/ts/containers/landing.tsx +++ b/packages/website/ts/containers/landing.ts diff --git a/packages/website/ts/containers/not_found.tsx b/packages/website/ts/containers/not_found.ts index dd151e2c8..dd151e2c8 100644 --- a/packages/website/ts/containers/not_found.tsx +++ b/packages/website/ts/containers/not_found.ts diff --git a/packages/website/ts/containers/portal.tsx b/packages/website/ts/containers/portal.ts index befa16bdb..befa16bdb 100644 --- a/packages/website/ts/containers/portal.tsx +++ b/packages/website/ts/containers/portal.ts diff --git a/packages/website/ts/containers/smart_contracts_documentation.tsx b/packages/website/ts/containers/smart_contracts_documentation.ts index a839529aa..a839529aa 100644 --- a/packages/website/ts/containers/smart_contracts_documentation.tsx +++ b/packages/website/ts/containers/smart_contracts_documentation.ts diff --git a/packages/website/ts/containers/wiki.tsx b/packages/website/ts/containers/wiki.ts index 2cb87d0a1..2cb87d0a1 100644 --- a/packages/website/ts/containers/wiki.tsx +++ b/packages/website/ts/containers/wiki.ts diff --git a/packages/website/ts/containers/zero_ex_js_documentation.tsx b/packages/website/ts/containers/zero_ex_js_documentation.ts index 500bf8d96..d0d697e70 100644 --- a/packages/website/ts/containers/zero_ex_js_documentation.tsx +++ b/packages/website/ts/containers/zero_ex_js_documentation.ts @@ -40,7 +40,7 @@ const docsInfoConfig: DocsInfoConfig = { id: DocPackages.ZeroExJs, type: SupportedDocJson.TypeDoc, displayName: '0x.js', - packageUrl: 'https://github.com/0xProject/0x.js', + packageUrl: 'https://github.com/0xProject/0x-monorepo', menu: { introduction: [zeroExJsDocSections.introduction], install: [zeroExJsDocSections.installation], @@ -102,6 +102,7 @@ const docsInfoConfig: DocsInfoConfig = { 'ApprovalContractEventArgs', 'TokenContractEventArgs', 'ZeroExConfig', + 'TransactionReceipt', 'TransactionReceiptWithDecodedLogs', 'LogWithDecodedArgs', 'EtherTokenEvents', @@ -124,17 +125,33 @@ const docsInfoConfig: DocsInfoConfig = { 'FilterObject', ], sectionNameToModulePath: { - [zeroExJsDocSections.zeroEx]: ['"src/0x"'], - [zeroExJsDocSections.exchange]: ['"src/contract_wrappers/exchange_wrapper"'], - [zeroExJsDocSections.tokenRegistry]: ['"src/contract_wrappers/token_registry_wrapper"'], - [zeroExJsDocSections.token]: ['"src/contract_wrappers/token_wrapper"'], - [zeroExJsDocSections.etherToken]: ['"src/contract_wrappers/ether_token_wrapper"'], + [zeroExJsDocSections.zeroEx]: ['"0x.js/src/0x"', '"src/0x"'], + [zeroExJsDocSections.exchange]: [ + '"0x.js/src/contract_wrappers/exchange_wrapper"', + '"src/contract_wrappers/exchange_wrapper"', + ], + [zeroExJsDocSections.tokenRegistry]: [ + '"0x.js/src/contract_wrappers/token_registry_wrapper"', + '"src/contract_wrappers/token_registry_wrapper"', + ], + [zeroExJsDocSections.token]: [ + '"0x.js/src/contract_wrappers/token_wrapper"', + '"src/contract_wrappers/token_wrapper"', + ], + [zeroExJsDocSections.etherToken]: [ + '"0x.js/src/contract_wrappers/ether_token_wrapper"', + '"src/contract_wrappers/ether_token_wrapper"', + ], [zeroExJsDocSections.proxy]: [ - '"src/contract_wrappers/proxy_wrapper"', + '"0x.js/src/contract_wrappers/proxy_wrapper"', + '"0x.js/src/contract_wrappers/token_transfer_proxy_wrapper"', '"src/contract_wrappers/token_transfer_proxy_wrapper"', ], - [zeroExJsDocSections.orderWatcher]: ['"src/order_watcher/order_state_watcher"'], - [zeroExJsDocSections.types]: ['"src/types"'], + [zeroExJsDocSections.orderWatcher]: [ + '"0x.js/src/order_watcher/order_state_watcher"', + '"src/order_watcher/order_state_watcher"', + ], + [zeroExJsDocSections.types]: ['"0x.js/src/types"', '"src/types"', '"types/src/index"'], }, menuSubsectionToVersionWhenIntroduced: { [zeroExJsDocSections.etherToken]: '0.7.1', diff --git a/packages/website/ts/pages/documentation/comment.tsx b/packages/website/ts/pages/documentation/comment.tsx index 23cfd96bd..5f177e97e 100644 --- a/packages/website/ts/pages/documentation/comment.tsx +++ b/packages/website/ts/pages/documentation/comment.tsx @@ -15,7 +15,7 @@ const defaultProps = { export const Comment: React.SFC<CommentProps> = (props: CommentProps) => { return ( <div className={`${props.className} comment`}> - <ReactMarkdown source={props.comment} renderers={{ CodeBlock: MarkdownCodeBlock }} /> + <ReactMarkdown source={props.comment} renderers={{ code: MarkdownCodeBlock }} /> </div> ); }; diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx index 7eed78fc3..699bef7a8 100644 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ b/packages/website/ts/pages/documentation/documentation.tsx @@ -29,11 +29,11 @@ import { TypescriptMethod, } from 'ts/types'; import { colors } from 'ts/utils/colors'; +import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import { utils } from 'ts/utils/utils'; const TOP_BAR_HEIGHT = 60; -const SCROLL_TOP_ID = 'docsScrollTop'; const networkNameToColor: { [network: string]: string } = { [Networks.Kovan]: colors.purple, @@ -76,7 +76,8 @@ const styles: Styles = { export class Documentation extends React.Component<DocumentationProps, DocumentationState> { public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) { if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) { - this._scrollToHash(); + const hash = this.props.location.hash.slice(1); + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); } } public render() { @@ -115,8 +116,12 @@ export class Documentation extends React.Component<DocumentationProps, Documenta className="relative col lg-col-9 md-col-9 sm-col-12 col-12" style={{ backgroundColor: colors.white }} > - <div id="documentation" style={styles.mainContainers} className="absolute px1"> - <div id={SCROLL_TOP_ID} /> + <div + id={configs.SCROLL_CONTAINER_ID} + style={styles.mainContainers} + className="absolute px1" + > + <div id={configs.SCROLL_TOP_ID} /> {this._renderDocumentation()} </div> </div> @@ -325,17 +330,4 @@ export class Documentation extends React.Component<DocumentationProps, Documenta /> ); } - private _scrollToHash(): void { - const hashWithPrefix = this.props.location.hash; - let hash = hashWithPrefix.slice(1); - if (_.isEmpty(hash)) { - hash = SCROLL_TOP_ID; // scroll to the top - } - - scroller.scrollTo(hash, { - duration: 0, - offset: 0, - containerId: 'documentation', - }); - } } diff --git a/packages/website/ts/pages/documentation/event_definition.tsx b/packages/website/ts/pages/documentation/event_definition.tsx index 0e53e38e7..e62c9ecbd 100644 --- a/packages/website/ts/pages/documentation/event_definition.tsx +++ b/packages/website/ts/pages/documentation/event_definition.tsx @@ -25,9 +25,10 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event } public render() { const event = this.props.event; + const id = `${this.props.sectionName}-${event.name}`; return ( <div - id={`${this.props.sectionName}-${event.name}`} + id={id} className="pb2" style={{ overflow: 'hidden', width: '100%' }} onMouseOver={this._setAnchorVisibility.bind(this, true)} @@ -36,7 +37,7 @@ export class EventDefinition extends React.Component<EventDefinitionProps, Event <AnchorTitle headerSize={HeaderSizes.H3} title={`Event ${event.name}`} - id={event.name} + id={id} shouldShowAnchor={this.state.shouldShowAnchor} /> <div style={{ fontSize: 16 }}> diff --git a/packages/website/ts/pages/documentation/type_definition.tsx b/packages/website/ts/pages/documentation/type_definition.tsx index d46eec76c..02bf63258 100644 --- a/packages/website/ts/pages/documentation/type_definition.tsx +++ b/packages/website/ts/pages/documentation/type_definition.tsx @@ -113,7 +113,9 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef <code className="hljs">{codeSnippet}</code> </pre> </div> - {customType.comment && <Comment comment={customType.comment} className="py2" />} + <div style={{ maxWidth: 620 }}> + {customType.comment && <Comment comment={customType.comment} className="py2" />} + </div> </div> ); } diff --git a/packages/website/ts/pages/shared/markdown_code_block.tsx b/packages/website/ts/pages/shared/markdown_code_block.tsx index 98ca3aee6..6dfb74554 100644 --- a/packages/website/ts/pages/shared/markdown_code_block.tsx +++ b/packages/website/ts/pages/shared/markdown_code_block.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import * as HighLight from 'react-highlight'; interface MarkdownCodeBlockProps { - literal: string; + value: string; language: string; } @@ -13,12 +13,12 @@ export class MarkdownCodeBlock extends React.Component<MarkdownCodeBlockProps, M // Re-rendering a codeblock causes any use selection to become de-selected. This is annoying when trying // to copy-paste code examples. We therefore noop re-renders on this component if it's props haven't changed. public shouldComponentUpdate(nextProps: MarkdownCodeBlockProps, nextState: MarkdownCodeBlockState) { - return nextProps.literal !== this.props.literal || nextProps.language !== this.props.language; + return nextProps.value !== this.props.value || nextProps.language !== this.props.language; } public render() { return ( <span style={{ fontSize: 14 }}> - <HighLight className={this.props.language || 'javascript'}>{this.props.literal}</HighLight> + <HighLight className={this.props.language || 'javascript'}>{this.props.value}</HighLight> </span> ); } diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx new file mode 100644 index 000000000..e4553c87f --- /dev/null +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -0,0 +1,46 @@ +import * as _ from 'lodash'; +import * as React from 'react'; +import { configs } from 'ts/utils/configs'; +import { utils } from 'ts/utils/utils'; + +interface MarkdownLinkBlockProps { + href: string; +} + +interface MarkdownLinkBlockState {} + +export class MarkdownLinkBlock extends React.Component<MarkdownLinkBlockProps, MarkdownLinkBlockState> { + // Re-rendering a linkBlock causes it to remain unclickable. + // We therefore noop re-renders on this component if it's props haven't changed. + public shouldComponentUpdate(nextProps: MarkdownLinkBlockProps, nextState: MarkdownLinkBlockState) { + return nextProps.href !== this.props.href; + } + public render() { + const href = this.props.href; + const isLinkToSection = _.startsWith(href, '#'); + // If protocol is http or https, we can open in a new tab, otherwise don't for security reasons + if (_.startsWith(href, 'http') || _.startsWith(href, 'https')) { + return ( + <a href={href} target="_blank" rel="nofollow noreferrer noopener"> + {this.props.children} + </a> + ); + } else if (isLinkToSection) { + return ( + <a + style={{ cursor: 'pointer', textDecoration: 'underline' }} + onClick={this._onHashUrlClick.bind(this, href)} + > + {this.props.children} + </a> + ); + } else { + return <a href={href}>{this.props.children}</a>; + } + } + private _onHashUrlClick(href: string) { + const hash = href.split('#')[1]; + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); + utils.setUrlHash(hash); + } +} diff --git a/packages/website/ts/pages/shared/markdown_section.tsx b/packages/website/ts/pages/shared/markdown_section.tsx index 4d7d8b4ca..7253072d9 100644 --- a/packages/website/ts/pages/shared/markdown_section.tsx +++ b/packages/website/ts/pages/shared/markdown_section.tsx @@ -5,6 +5,7 @@ import * as ReactMarkdown from 'react-markdown'; import { Element as ScrollElement } from 'react-scroll'; import { AnchorTitle } from 'ts/pages/shared/anchor_title'; import { MarkdownCodeBlock } from 'ts/pages/shared/markdown_code_block'; +import { MarkdownLinkBlock } from 'ts/pages/shared/markdown_link_block'; import { HeaderSizes } from 'ts/types'; import { colors } from 'ts/utils/colors'; import { utils } from 'ts/utils/utils'; @@ -64,7 +65,14 @@ export class MarkdownSection extends React.Component<MarkdownSectionProps, Markd </div> </div> <hr style={{ border: `1px solid ${colors.lightestGrey}` }} /> - <ReactMarkdown source={this.props.markdownContent} renderers={{ CodeBlock: MarkdownCodeBlock }} /> + <ReactMarkdown + source={this.props.markdownContent} + escapeHtml={false} + renderers={{ + code: MarkdownCodeBlock, + link: MarkdownLinkBlock, + }} + /> </ScrollElement> </div> ); diff --git a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx index 1a08ca9f9..82a40eb7e 100644 --- a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx +++ b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx @@ -86,14 +86,14 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N docs </div> </div> - <div className="pl1" style={{ color: colors.grey350, paddingBottom: 9, paddingLeft: 14, height: 17 }}> + <div className="pl1" style={{ color: colors.grey350, paddingBottom: 9, paddingLeft: 10, height: 17 }}> | </div> <div className="flex"> <div> - <img src={`/images/doc_icons/${titleToIcon[this.props.title]}`} width="24" /> + <img src={`/images/doc_icons/${titleToIcon[this.props.title]}`} width="22" /> </div> - <div className="pl1" style={{ fontWeight: 600, fontSize: 20, lineHeight: 1 }}> + <div className="pl1" style={{ fontWeight: 600, fontSize: 20, lineHeight: 1.2 }}> {this.props.title} </div> </div> diff --git a/packages/website/ts/pages/shared/section_header.tsx b/packages/website/ts/pages/shared/section_header.tsx index a5f5f52cf..52a1f30d9 100644 --- a/packages/website/ts/pages/shared/section_header.tsx +++ b/packages/website/ts/pages/shared/section_header.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { Element as ScrollElement } from 'react-scroll'; import { AnchorTitle } from 'ts/pages/shared/anchor_title'; import { HeaderSizes } from 'ts/types'; +import { colors } from 'ts/utils/colors'; import { utils } from 'ts/utils/utils'; interface SectionHeaderProps { @@ -34,7 +35,19 @@ export class SectionHeader extends React.Component<SectionHeaderProps, SectionHe <ScrollElement name={id}> <AnchorTitle headerSize={this.props.headerSize} - title={<span style={{ textTransform: 'capitalize' }}>{sectionName}</span>} + title={ + <span + style={{ + textTransform: 'uppercase', + color: colors.grey, + fontFamily: 'Roboto Mono', + fontWeight: 300, + fontSize: 27, + }} + > + {sectionName} + </span> + } id={id} shouldShowAnchor={this.state.shouldShowAnchor} /> diff --git a/packages/website/ts/pages/shared/version_drop_down.tsx b/packages/website/ts/pages/shared/version_drop_down.tsx index 3b331af9b..1b4dbb375 100644 --- a/packages/website/ts/pages/shared/version_drop_down.tsx +++ b/packages/website/ts/pages/shared/version_drop_down.tsx @@ -2,6 +2,7 @@ import * as _ from 'lodash'; import DropDownMenu from 'material-ui/DropDownMenu'; import MenuItem from 'material-ui/MenuItem'; import * as React from 'react'; +import { utils } from 'ts/utils/utils'; interface VersionDropDownProps { selectedVersion: string; @@ -31,8 +32,6 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi return items; } private _updateSelectedVersion(e: any, index: number, semver: string) { - const port = window.location.port; - const hasPort = !_.isUndefined(port); let path = window.location.pathname; const lastChar = path[path.length - 1]; if (_.isFinite(_.parseInt(lastChar))) { @@ -40,7 +39,7 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi pathSections.pop(); path = pathSections.join('/'); } - const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}${path}`; - window.location.href = `${baseUrl}/${semver}${window.location.hash}`; + const baseUrl = utils.getCurrentBaseUrl(); + window.location.href = `${baseUrl}${path}/${semver}${window.location.hash}`; } } diff --git a/packages/website/ts/pages/wiki/wiki.tsx b/packages/website/ts/pages/wiki/wiki.tsx index 56c3be0fe..4bb6052a2 100644 --- a/packages/website/ts/pages/wiki/wiki.tsx +++ b/packages/website/ts/pages/wiki/wiki.tsx @@ -135,11 +135,11 @@ export class Wiki extends React.Component<WikiProps, WikiState> { }} > <div - id="documentation" + id={configs.SCROLL_CONTAINER_ID} style={{ ...mainContainersStyle, overflow: 'auto' }} className="absolute" > - <div id="0xProtocolWiki" /> + <div id={configs.SCROLL_TOP_ID} /> <div id="wiki" style={{ paddingRight: 2 }}> {this._renderWikiArticles()} </div> @@ -188,19 +188,6 @@ export class Wiki extends React.Component<WikiProps, WikiState> { </div> ); } - private _scrollToHash(): void { - const hashWithPrefix = this.props.location.hash; - let hash = hashWithPrefix.slice(1); - if (_.isEmpty(hash)) { - hash = '0xProtocolWiki'; // scroll to the top - } - - scroller.scrollTo(hash, { - duration: 0, - offset: 0, - containerId: 'documentation', - }); - } private async _fetchArticlesBySectionAsync(): Promise<void> { const endpoint = `${configs.BACKEND_BASE_URL}${WebsitePaths.Wiki}`; const response = await fetch(endpoint); @@ -224,8 +211,10 @@ export class Wiki extends React.Component<WikiProps, WikiState> { { articlesBySection, }, - () => { - this._scrollToHash(); + async () => { + await utils.onPageLoadAsync(); + const hash = this.props.location.hash.slice(1); + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); }, ); } diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index f0db537e6..28663270e 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -308,7 +308,7 @@ export interface TypeDocNode { returns?: string; declaration: TypeDocNode; flags?: TypeDocFlags; - indexSignature?: TypeDocNode[]; + indexSignature?: TypeDocNode | TypeDocNode[]; // TypeDocNode in TypeDoc <V0.9.0, TypeDocNode[] in >V0.9.0 signatures?: TypeDocNode[]; parameters?: TypeDocNode[]; typeParameter?: TypeDocNode[]; diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts index 7e9ba69de..388fc8530 100644 --- a/packages/website/ts/utils/configs.ts +++ b/packages/website/ts/utils/configs.ts @@ -94,6 +94,8 @@ export const configs = { [3]: [`https://ropsten.infura.io/${INFURA_API_KEY}`], [4]: [`https://rinkeby.infura.io/${INFURA_API_KEY}`], } as PublicNodeUrlsByNetworkId, + SCROLL_CONTAINER_ID: 'documentation', + SCROLL_TOP_ID: 'pageScrollTop', SHOULD_DEPRECATE_OLD_WETH_TOKEN: true, SYMBOLS_OF_MINTABLE_KOVAN_TOKENS: ['MKR', 'MLN', 'GNT', 'DGD', 'REP'], SYMBOLS_OF_MINTABLE_RINKEBY_ROPSTEN_TOKENS: [ diff --git a/packages/website/ts/utils/typedoc_utils.ts b/packages/website/ts/utils/typedoc_utils.ts index 992475911..ce7df4dbb 100644 --- a/packages/website/ts/utils/typedoc_utils.ts +++ b/packages/website/ts/utils/typedoc_utils.ts @@ -41,18 +41,17 @@ export const typeDocUtils = { isPrivateOrProtectedProperty(propertyName: string): boolean { return _.startsWith(propertyName, '_'); }, - getModuleDefinitionBySectionNameIfExists( - versionDocObj: TypeDocNode, - modulePaths: string[], - ): TypeDocNode | undefined { - const modules = versionDocObj.children; - for (const mod of modules) { - if (_.includes(modulePaths, mod.name)) { - const moduleWithName = mod; - return moduleWithName; - } - } - return undefined; + getModuleDefinitionsBySectionName(versionDocObj: TypeDocNode, configModulePaths: string[]): TypeDocNode[] { + const moduleDefinitions: TypeDocNode[] = []; + const jsonModules = versionDocObj.children; + _.each(jsonModules, jsonMod => { + _.each(configModulePaths, configModulePath => { + if (_.includes(configModulePath, jsonMod.name)) { + moduleDefinitions.push(jsonMod); + } + }); + }); + return moduleDefinitions; }, convertToDocAgnosticFormat(typeDocJson: TypeDocNode, docsInfo: DocsInfo): DocAgnosticFormat { const subMenus = _.values(docsInfo.getMenu()); @@ -63,12 +62,23 @@ export const typeDocUtils = { if (_.isUndefined(modulePathsIfExists)) { return; // no-op } - const packageDefinitionIfExists = typeDocUtils.getModuleDefinitionBySectionNameIfExists( - typeDocJson, - modulePathsIfExists, - ); - if (_.isUndefined(packageDefinitionIfExists)) { + const packageDefinitions = typeDocUtils.getModuleDefinitionsBySectionName(typeDocJson, modulePathsIfExists); + let packageDefinitionWithMergedChildren; + if (_.isEmpty(packageDefinitions)) { return; // no-op + } else if (packageDefinitions.length === 1) { + packageDefinitionWithMergedChildren = packageDefinitions[0]; + } else { + // HACK: For now, if there are two modules to display in a single section, + // we simply concat the children. This works for our limited use-case where + // we want to display types stored in two files under a single section + packageDefinitionWithMergedChildren = packageDefinitions[0]; + for (let i = 1; i < packageDefinitions.length; i++) { + packageDefinitionWithMergedChildren.children = [ + ...packageDefinitionWithMergedChildren.children, + ...packageDefinitions[i].children, + ]; + } } // Since the `types.ts` file is the only file that does not export a module/class but @@ -77,10 +87,10 @@ export const typeDocUtils = { let entities; let packageComment = ''; if (sectionName === docsInfo.sections.types) { - entities = packageDefinitionIfExists.children; + entities = packageDefinitionWithMergedChildren.children; } else { - entities = packageDefinitionIfExists.children[0].children; - const commentObj = packageDefinitionIfExists.children[0].comment; + entities = packageDefinitionWithMergedChildren.children[0].children; + const commentObj = packageDefinitionWithMergedChildren.children[0].comment; packageComment = !_.isUndefined(commentObj) ? commentObj.shortText : packageComment; } @@ -170,8 +180,16 @@ export const typeDocUtils = { const methodIfExists = !_.isUndefined(entity.declaration) ? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId) : undefined; - const indexSignatureIfExists = !_.isUndefined(entity.indexSignature) - ? typeDocUtils._convertIndexSignature(entity.indexSignature[0], sections, sectionName, docId) + const doesIndexSignatureExist = !_.isUndefined(entity.indexSignature); + const isIndexSignatureArray = _.isArray(entity.indexSignature); + // HACK: TypeDoc Versions <0.9.0 indexSignature is of type TypeDocNode[] + // Versions >0.9.0 have it as type TypeDocNode + const indexSignature = + doesIndexSignatureExist && isIndexSignatureArray + ? (entity.indexSignature as TypeDocNode[])[0] + : (entity.indexSignature as TypeDocNode); + const indexSignatureIfExists = doesIndexSignatureExist + ? typeDocUtils._convertIndexSignature(indexSignature, sections, sectionName, docId) : undefined; const commentIfExists = !_.isUndefined(entity.comment) && !_.isUndefined(entity.comment.shortText) diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index c38f84c92..a1e045af7 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -4,6 +4,7 @@ import deepEqual = require('deep-equal'); import isMobile = require('is-mobile'); import * as _ from 'lodash'; import * as moment from 'moment'; +import { scroller } from 'react-scroll'; import { EtherscanLinkSuffixes, Networks, @@ -290,4 +291,30 @@ export const utils = { ); return isTestNetwork; }, + getCurrentBaseUrl() { + const port = window.location.port; + const hasPort = !_.isUndefined(port); + const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`; + return baseUrl; + }, + scrollToHash(hash: string, containerId: string): void { + let finalHash = hash; + if (_.isEmpty(hash)) { + finalHash = configs.SCROLL_TOP_ID; // scroll to the top + } + + scroller.scrollTo(finalHash, { + duration: 0, + offset: 0, + containerId, + }); + }, + async onPageLoadAsync(): Promise<void> { + if (document.readyState === 'complete') { + return; // Already loaded + } + return new Promise<void>((resolve, reject) => { + window.onload = () => resolve(); + }); + }, }; |