aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/CHANGELOG.md7
-rw-r--r--packages/0x.js/README.md11
-rw-r--r--packages/0x.js/package.json37
-rw-r--r--packages/0x.js/scripts/postpublish.js9
-rw-r--r--packages/0x.js/scripts/stagedocs.js33
-rw-r--r--packages/0x.js/src/index.ts3
-rw-r--r--packages/abi-gen/CHANGELOG.md2
-rw-r--r--packages/abi-gen/README.md8
-rw-r--r--packages/abi-gen/package.json14
-rw-r--r--packages/assert/CHANGELOG.md2
-rw-r--r--packages/assert/README.md8
-rw-r--r--packages/assert/package.json16
-rw-r--r--packages/base-contract/.npmignore5
-rw-r--r--packages/base-contract/CHANGELOG.md5
-rw-r--r--packages/base-contract/README.md62
-rw-r--r--packages/base-contract/package.json39
-rw-r--r--packages/base-contract/src/index.ts (renamed from packages/web3-wrapper/src/base_contract.ts)3
-rw-r--r--packages/base-contract/tsconfig.json11
-rw-r--r--packages/base-contract/tslint.json3
-rw-r--r--packages/chai-as-promised-typescript-typings/package.json10
-rw-r--r--packages/chai-typescript-typings/package.json8
-rw-r--r--packages/connect/CHANGELOG.md2
-rw-r--r--packages/connect/README.md12
-rw-r--r--packages/connect/package.json24
-rw-r--r--packages/connect/scripts/postpublish.js8
-rw-r--r--packages/connect/scripts/stagedocs.js32
-rw-r--r--packages/contract_templates/contract.handlebars5
-rw-r--r--packages/contracts/README.md12
-rw-r--r--packages/contracts/globals.d.ts1
-rw-r--r--packages/contracts/package.json36
-rw-r--r--packages/contracts/src/contracts/current/tutorials/Arbitrage/Arbitrage.sol114
-rw-r--r--packages/contracts/src/contracts/current/tutorials/EtherDelta/AccountLevels.sol11
-rw-r--r--packages/contracts/src/contracts/current/tutorials/EtherDelta/EtherDelta.sol168
-rw-r--r--packages/contracts/test/tutorials/arbitrage.ts226
-rw-r--r--packages/contracts/util/crypto.ts8
-rw-r--r--packages/contracts/util/types.ts3
-rw-r--r--packages/deployer/CHANGELOG.md2
-rw-r--r--packages/deployer/README.md4
-rw-r--r--packages/deployer/package.json22
-rw-r--r--packages/dev-utils/CHANGELOG.md2
-rw-r--r--packages/dev-utils/README.md8
-rw-r--r--packages/dev-utils/package.json20
-rw-r--r--packages/ethers-typescript-typings/CHANGELOG.md2
-rw-r--r--packages/ethers-typescript-typings/package.json8
-rw-r--r--packages/json-schemas/CHANGELOG.md4
-rw-r--r--packages/json-schemas/package.json14
-rw-r--r--packages/monorepo-scripts/package.json10
-rw-r--r--packages/subproviders/CHANGELOG.md9
-rw-r--r--packages/subproviders/README.md42
-rw-r--r--packages/subproviders/package.json26
-rw-r--r--packages/subproviders/src/globals.d.ts54
-rw-r--r--packages/subproviders/src/index.ts21
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts14
-rw-r--r--packages/subproviders/src/types.ts10
-rw-r--r--packages/subproviders/test/integration/ledger_subprovider_test.ts33
-rw-r--r--packages/subproviders/test/unit/ledger_subprovider_test.ts18
-rw-r--r--packages/testnet-faucets/package.json12
-rw-r--r--packages/testnet-faucets/src/ts/dispense_asset_tasks.ts21
-rw-r--r--packages/tslint-config/package.json8
-rw-r--r--packages/types/CHANGELOG.md3
-rw-r--r--packages/types/README.md8
-rw-r--r--packages/types/package.json16
-rw-r--r--packages/utils/CHANGELOG.md3
-rw-r--r--packages/utils/README.md8
-rw-r--r--packages/utils/package.json20
-rw-r--r--packages/web3-typescript-typings/CHANGELOG.md2
-rw-r--r--packages/web3-typescript-typings/package.json8
-rw-r--r--packages/web3-wrapper/CHANGELOG.md2
-rw-r--r--packages/web3-wrapper/README.md8
-rw-r--r--packages/web3-wrapper/package.json22
-rw-r--r--packages/web3-wrapper/src/index.ts181
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts179
-rw-r--r--packages/website/README.md10
-rw-r--r--packages/website/md/docs/0xjs/installation.md2
-rw-r--r--packages/website/md/docs/0xjs/introduction.md2
-rw-r--r--packages/website/md/docs/connect/installation.md2
-rw-r--r--packages/website/md/docs/connect/introduction.md2
-rw-r--r--packages/website/md/docs/smart_contracts/introduction.md8
-rw-r--r--packages/website/package.json15
-rw-r--r--packages/website/public/images/doc_icons/connect.pngbin361 -> 289 bytes
-rw-r--r--packages/website/public/images/doc_icons/contracts.pngbin1104 -> 930 bytes
-rw-r--r--packages/website/public/images/doc_icons/zeroExJs.pngbin1318 -> 1209 bytes
-rw-r--r--packages/website/ts/blockchain.ts10
-rw-r--r--packages/website/ts/components/top_bar/top_bar.tsx1
-rw-r--r--packages/website/ts/containers/about.ts (renamed from packages/website/ts/containers/about.tsx)0
-rw-r--r--packages/website/ts/containers/connect_documentation.ts (renamed from packages/website/ts/containers/connect_documentation.tsx)23
-rw-r--r--packages/website/ts/containers/faq.ts (renamed from packages/website/ts/containers/faq.tsx)0
-rw-r--r--packages/website/ts/containers/generate_order_form.ts (renamed from packages/website/ts/containers/generate_order_form.tsx)0
-rw-r--r--packages/website/ts/containers/landing.ts (renamed from packages/website/ts/containers/landing.tsx)0
-rw-r--r--packages/website/ts/containers/not_found.ts (renamed from packages/website/ts/containers/not_found.tsx)0
-rw-r--r--packages/website/ts/containers/portal.ts (renamed from packages/website/ts/containers/portal.tsx)0
-rw-r--r--packages/website/ts/containers/smart_contracts_documentation.ts98
-rw-r--r--packages/website/ts/containers/smart_contracts_documentation.tsx65
-rw-r--r--packages/website/ts/containers/wiki.ts (renamed from packages/website/ts/containers/wiki.tsx)0
-rw-r--r--packages/website/ts/containers/zero_ex_js_documentation.ts (renamed from packages/website/ts/containers/zero_ex_js_documentation.tsx)58
-rw-r--r--packages/website/ts/pages/documentation/comment.tsx2
-rw-r--r--packages/website/ts/pages/documentation/doc_page.tsx143
-rw-r--r--packages/website/ts/pages/documentation/docs_info.ts22
-rw-r--r--packages/website/ts/pages/documentation/documentation.tsx168
-rw-r--r--packages/website/ts/pages/documentation/event_definition.tsx5
-rw-r--r--packages/website/ts/pages/documentation/method_block.tsx4
-rw-r--r--packages/website/ts/pages/documentation/source_link.tsx13
-rw-r--r--packages/website/ts/pages/documentation/type_definition.tsx4
-rw-r--r--packages/website/ts/pages/shared/markdown_code_block.tsx6
-rw-r--r--packages/website/ts/pages/shared/markdown_link_block.tsx46
-rw-r--r--packages/website/ts/pages/shared/markdown_section.tsx10
-rw-r--r--packages/website/ts/pages/shared/nested_sidebar_menu.tsx16
-rw-r--r--packages/website/ts/pages/shared/section_header.tsx15
-rw-r--r--packages/website/ts/pages/shared/version_drop_down.tsx14
-rw-r--r--packages/website/ts/pages/wiki/wiki.tsx23
-rw-r--r--packages/website/ts/types.ts27
-rw-r--r--packages/website/ts/utils/configs.ts39
-rw-r--r--packages/website/ts/utils/constants.ts1
-rw-r--r--packages/website/ts/utils/typedoc_utils.ts128
-rw-r--r--packages/website/ts/utils/utils.ts27
-rw-r--r--packages/website/tsconfig.json6
116 files changed, 1908 insertions, 889 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 96ba28b75..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,29 +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/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/.npmignore b/packages/base-contract/.npmignore
new file mode 100644
index 000000000..ad5ffcd56
--- /dev/null
+++ b/packages/base-contract/.npmignore
@@ -0,0 +1,5 @@
+.*
+yarn-error.log
+/scripts/
+/src/
+tsconfig.json
diff --git a/packages/base-contract/CHANGELOG.md b/packages/base-contract/CHANGELOG.md
new file mode 100644
index 000000000..1942b3b3e
--- /dev/null
+++ b/packages/base-contract/CHANGELOG.md
@@ -0,0 +1,5 @@
+# CHANGELOG
+
+## v0.0.2 - _March 4, 2018_
+
+ * Initial release
diff --git a/packages/base-contract/README.md b/packages/base-contract/README.md
new file mode 100644
index 000000000..fa2f3da10
--- /dev/null
+++ b/packages/base-contract/README.md
@@ -0,0 +1,62 @@
+## @0xproject/base-contract
+
+BaseContract to derive all auto-generated wrappers from
+
+## Installation
+
+```bash
+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
+import { BaseContract } from '@0xproject/base-contract';
+```
+
+## Contributing
+
+We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.
+
+Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
+
+### Install Dependencies
+
+If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
+
+```bash
+yarn config set workspaces-experimental true
+```
+
+Then install dependencies
+
+```bash
+yarn install
+```
+
+### Build
+
+```bash
+yarn build
+```
+
+or
+
+```bash
+yarn build:watch
+```
+
+### Lint
+
+```bash
+yarn lint
+```
diff --git a/packages/base-contract/package.json b/packages/base-contract/package.json
new file mode 100644
index 000000000..8b31b8e12
--- /dev/null
+++ b/packages/base-contract/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "@0xproject/base-contract",
+ "version": "0.0.2",
+ "description": "0x Base TS contract",
+ "main": "lib/index.js",
+ "types": "lib/index.d.ts",
+ "scripts": {
+ "build:watch": "tsc -w",
+ "build": "tsc",
+ "clean": "shx rm -rf lib",
+ "lint": "tslint --project . 'src/**/*.ts'"
+ },
+ "license": "Apache-2.0",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/0xProject/0x-monorepo.git"
+ },
+ "bugs": {
+ "url": "https://github.com/0xProject/0x-monorepo/issues"
+ },
+ "homepage": "https://github.com/0xProject/0x-monorepo/packages/base-contract/README.md",
+ "devDependencies": {
+ "@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"
+ },
+ "dependencies": {
+ "@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-typescript-typings": "^0.10.0"
+ }
+}
diff --git a/packages/web3-wrapper/src/base_contract.ts b/packages/base-contract/src/index.ts
index 997ce97d3..cc1e16a13 100644
--- a/packages/web3-wrapper/src/base_contract.ts
+++ b/packages/base-contract/src/index.ts
@@ -1,10 +1,9 @@
import { TxData, TxDataPayable } from '@0xproject/types';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import { Web3Wrapper } from './web3_wrapper';
-
export class BaseContract {
protected _ethersInterface: ethersContracts.Interface;
protected _web3Wrapper: Web3Wrapper;
diff --git a/packages/base-contract/tsconfig.json b/packages/base-contract/tsconfig.json
new file mode 100644
index 000000000..8114d99cd
--- /dev/null
+++ b/packages/base-contract/tsconfig.json
@@ -0,0 +1,11 @@
+{
+ "extends": "../../tsconfig",
+ "compilerOptions": {
+ "outDir": "lib"
+ },
+ "include": [
+ "./src/**/*",
+ "../../node_modules/web3-typescript-typings/index.d.ts",
+ "../../node_modules/ethers-typescript-typings/index.d.ts"
+ ]
+}
diff --git a/packages/base-contract/tslint.json b/packages/base-contract/tslint.json
new file mode 100644
index 000000000..ffaefe83a
--- /dev/null
+++ b/packages/base-contract/tslint.json
@@ -0,0 +1,3 @@
+{
+ "extends": ["@0xproject/tslint-config"]
+}
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 63faf5271..393ea70a0 100644
--- a/packages/connect/README.md
+++ b/packages/connect/README.md
@@ -8,10 +8,18 @@ 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)
-* [Tutorials](https://0xproject.com/wiki#connect)
+* [Docs](https://0xproject.com/docs/connect)
+* [Tutorials](https://0xproject.com/wiki#connect)
## Contributing
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 b5c2dd9f2..132cd60cc 100644
--- a/packages/contract_templates/contract.handlebars
+++ b/packages/contract_templates/contract.handlebars
@@ -1,12 +1,13 @@
/**
* 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
+import { BaseContract } from '@0xproject/base-contract';
import { TxData, TxDataPayable } from '@0xproject/types';
import { BigNumber, classUtils, promisify } from '@0xproject/utils';
-import { BaseContract, Web3Wrapper } from '@0xproject/web3-wrapper';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
import * as Web3 from 'web3';
diff --git a/packages/contracts/README.md b/packages/contracts/README.md
index 11b9e5056..7628b057b 100644
--- a/packages/contracts/README.md
+++ b/packages/contracts/README.md
@@ -4,11 +4,11 @@ Smart contracts that implement the 0x protocol.
## Usage
-* [Docs](https://0xproject.com/docs/contracts)
-* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture)
-* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions)
-* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses)
-* [0x protocol message format](https://0xproject.com/wiki#Message-Format)
+* [Docs](https://0xproject.com/docs/contracts)
+* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture)
+* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions)
+* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses)
+* [0x protocol message format](https://0xproject.com/wiki#Message-Format)
## Contributing
@@ -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 8159ba244..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,17 +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/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 a1929ba25..ccfdd6a3b 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)
* Improve an error message for when deployer is supplied with an incorrect number of constructor arguments (#419)
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 9a9fc12de..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..8e7321d4a 100644
--- a/packages/subproviders/CHANGELOG.md
+++ b/packages/subproviders/CHANGELOG.md
@@ -1,5 +1,14 @@
# CHANGELOG
+## v0.7.0 - _TBD_
+
+ * Updated legerco packages. Removed node-hid package as a dependency and make it an optional dependency. It is still used in integration tests but is causing problems for users on Linux distros. (#437)
+
+## 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 954729713..4614342b2 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:
@@ -34,6 +42,28 @@ const accounts = await ledgerSubprovider.getAccountsAsync();
A subprovider that enables your dApp to send signing requests to a user's Ledger Nano S hardware wallet. These can be requests to sign transactions or messages.
+Ledger Nano (and this library) by default uses a derivation path of `44'/60'/0'`. This is different to TestRPC which by default uses `m/44'/60'/0'/0`. This is a configuration option in the Ledger Subprovider package.
+
+##### Ledger Nano S + Node-hid (usb)
+
+By default, node-hid transport support is an optional dependency. This is due to the requirement of native usb developer packages on the host system. If these aren't installed the entire `npm install` fails. We also no longer export node-hid transport client factories. To re-create this see our integration tests or follow the example below:
+
+```typescript
+import Eth from '@ledgerhq/hw-app-eth';
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
+async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
+ const ledgerConnection = await TransportNodeHid.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
+ return ledgerEthClient;
+}
+
+// Create a LedgerSubprovider with the node-hid transport
+ledgerSubprovider = new LedgerSubprovider({
+ networkId,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+});
+```
+
#### Redundant RPC subprovider
A subprovider which attempts to send an RPC call to a list of RPC endpoints sequentially, until one of them returns a successful response.
@@ -96,10 +126,12 @@ yarn run test:unit
In order to run the integration tests, make sure you have a Ledger Nano S available.
-* Plug it into your computer
-* Unlock the device
-* Open the on-device Ethereum app
-* Make sure "browser support" is disabled
+* Setup your Ledger with the development mnemonic seed: `concert load couple harbor equip island argue ramp clarify fence smart topic`
+* Plug it into your computer
+* Unlock the device
+* Open the on-device Ethereum app
+* Make sure "browser support" and "contract data" are disabled
+* Start [TestRPC](https://github.com/trufflesuite/ganache-cli) locally at port `8545`
Then run:
@@ -107,6 +139,8 @@ Then run:
yarn test:integration
```
+**Note:** We assume a derivation path of `m/44'/60'/0'/0` which is already configured in the tests. With this setup and derivation path, your first account should be `0x5409ed021d9299bf6814279a6a1411a7e866a631`, exactly like TestRPC.
+
#### All tests
```bash
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index 5e9c2ed89..a3e865d24 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,31 +18,33 @@
"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",
+ "@ledgerhq/hw-app-eth": "^4.3.0",
+ "@ledgerhq/hw-transport-u2f": "^4.3.0",
"bn.js": "^4.11.8",
"es6-promisify": "^5.0.0",
"ethereumjs-tx": "^1.3.3",
"ethereumjs-util": "^5.1.1",
"hdkey": "^0.7.1",
- "ledgerco": "0xProject/ledger-node-js-api",
"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 +53,9 @@
"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"
+ },
+ "optionalDependencies": {
+ "@ledgerhq/hw-transport-node-hid": "^4.3.0"
}
}
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 6f344dcd3..d59ee9e67 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -32,32 +32,38 @@ interface ECSignature {
r: string;
s: string;
}
-declare module 'ledgerco' {
- interface comm {
- close_async(): Promise<void>;
- }
- export class comm_node implements comm {
- public static create_async(timeoutMilliseconds?: number): Promise<comm_node>;
- public close_async(): Promise<void>;
- }
- export class comm_u2f implements comm {
- public static create_async(): Promise<comm_u2f>;
- public close_async(): Promise<void>;
- }
- export class eth {
- public comm: comm;
- constructor(comm: comm);
- public getAddress_async(
+
+interface LedgerTransport {
+ close(): Promise<void>;
+}
+
+declare module '@ledgerhq/hw-app-eth' {
+ class Eth {
+ public transport: LedgerTransport;
+ constructor(transport: LedgerTransport);
+ public getAddress(
path: string,
- display?: boolean,
- chaincode?: boolean,
+ boolDisplay?: boolean,
+ boolChaincode?: boolean,
): Promise<{ publicKey: string; address: string; chainCode: string }>;
- public signTransaction_async(path: string, rawTxHex: string): Promise<ECSignatureString>;
- public getAppConfiguration_async(): Promise<{
- arbitraryDataEnabled: number;
- version: string;
- }>;
- public signPersonalMessage_async(path: string, messageHex: string): Promise<ECSignature>;
+ public signTransaction(path: string, rawTxHex: string): Promise<ECSignatureString>;
+ public getAppConfiguration(): Promise<{ arbitraryDataEnabled: number; version: string }>;
+ public signPersonalMessage(path: string, messageHex: string): Promise<ECSignature>;
+ }
+ export default Eth;
+}
+
+declare module '@ledgerhq/hw-transport-u2f' {
+ export default class TransportU2F implements LedgerTransport {
+ public static create(): Promise<LedgerTransport>;
+ public close(): Promise<void>;
+ }
+}
+
+declare module '@ledgerhq/hw-transport-node-hid' {
+ export default class TransportNodeHid implements LedgerTransport {
+ public static create(): Promise<LedgerTransport>;
+ public close(): Promise<void>;
}
}
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 4da405ec0..e22b6f5f3 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -1,8 +1,5 @@
-import {
- comm_node as LedgerNodeCommunication,
- comm_u2f as LedgerBrowserCommunication,
- eth as LedgerEthereumClientFn,
-} from 'ledgerco';
+import Eth from '@ledgerhq/hw-app-eth';
+import TransportU2F from '@ledgerhq/hw-transport-u2f';
import { LedgerEthereumClient } from './types';
@@ -19,17 +16,7 @@ export { ECSignature, LedgerWalletSubprovider, LedgerCommunicationClient, NonceS
* @return LedgerEthereumClient A browser client
*/
export async function ledgerEthereumBrowserClientFactoryAsync(): Promise<LedgerEthereumClient> {
- const ledgerConnection = await LedgerBrowserCommunication.create_async();
- const ledgerEthClient = new LedgerEthereumClientFn(ledgerConnection);
- return ledgerEthClient;
-}
-
-/**
- * A factory for creating a LedgerEthereumClient usable in a Node.js context.
- * @return LedgerEthereumClient A Node.js client
- */
-export async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
- const ledgerConnection = await LedgerNodeCommunication.create_async();
- const ledgerEthClient = new LedgerEthereumClientFn(ledgerConnection);
+ const ledgerConnection = await TransportU2F.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
return ledgerEthClient;
}
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 5966a88bb..0a84caae3 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,12 +129,12 @@ 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;
try {
- ledgerResponse = await this._ledgerClientIfExists.getAddress_async(
+ ledgerResponse = await this._ledgerClientIfExists.getAddress(
this._derivationPath,
this._shouldAlwaysAskForConfirmation,
SHOULD_GET_CHAIN_CODE,
@@ -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;
@@ -173,7 +173,7 @@ export class LedgerSubprovider extends Subprovider {
const txHex = tx.serialize().toString('hex');
try {
const derivationPath = this._getDerivationPath();
- const result = await this._ledgerClientIfExists.signTransaction_async(derivationPath, txHex);
+ const result = await this._ledgerClientIfExists.signTransaction(derivationPath, txHex);
// Store signature in transaction
tx.r = Buffer.from(result.r, 'hex');
tx.s = Buffer.from(result.s, 'hex');
@@ -199,7 +199,7 @@ export class LedgerSubprovider extends Subprovider {
this._ledgerClientIfExists = await this._createLedgerClientAsync();
try {
const derivationPath = this._getDerivationPath();
- const result = await this._ledgerClientIfExists.signPersonalMessage_async(
+ const result = await this._ledgerClientIfExists.signPersonalMessage(
derivationPath,
ethUtil.stripHexPrefix(data),
);
@@ -236,7 +236,7 @@ export class LedgerSubprovider extends Subprovider {
this._connectionLock.signal();
return;
}
- await this._ledgerClientIfExists.comm.close_async();
+ await this._ledgerClientIfExists.transport.close();
this._ledgerClientIfExists = undefined;
this._connectionLock.signal();
}
diff --git a/packages/subproviders/src/types.ts b/packages/subproviders/src/types.ts
index 65b7f6c8f..f49ac6107 100644
--- a/packages/subproviders/src/types.ts
+++ b/packages/subproviders/src/types.ts
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
export interface LedgerCommunicationClient {
- close_async: () => Promise<void>;
+ close: () => Promise<void>;
}
/*
@@ -12,14 +12,14 @@ export interface LedgerCommunicationClient {
export interface LedgerEthereumClient {
// shouldGetChainCode is defined as `true` instead of `boolean` because other types rely on the assumption
// that we get back the chain code and we don't have dependent types to express it properly
- getAddress_async: (
+ getAddress: (
derivationPath: string,
askForDeviceConfirmation: boolean,
shouldGetChainCode: true,
) => Promise<LedgerGetAddressResult>;
- signPersonalMessage_async: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
- signTransaction_async: (derivationPath: string, txHex: string) => Promise<ECSignatureString>;
- comm: LedgerCommunicationClient;
+ signTransaction: (derivationPath: string, rawTxHex: string) => Promise<ECSignatureString>;
+ signPersonalMessage: (derivationPath: string, messageHex: string) => Promise<ECSignature>;
+ transport: LedgerCommunicationClient;
}
export interface ECSignatureString {
diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts
index 628b532d7..a94cfbe3a 100644
--- a/packages/subproviders/test/integration/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts
@@ -1,3 +1,7 @@
+import Eth from '@ledgerhq/hw-app-eth';
+// HACK: This depdency is optional and tslint skips optional depdencies
+// tslint:disable-next-line:no-implicit-dependencies
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
import * as chai from 'chai';
import promisify = require('es6-promisify');
import * as ethUtils from 'ethereumjs-util';
@@ -6,14 +10,21 @@ import Web3 = require('web3');
import Web3ProviderEngine = require('web3-provider-engine');
import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
-import { ledgerEthereumNodeJsClientFactoryAsync, LedgerSubprovider } from '../../src';
-import { DoneCallback } from '../../src/types';
+import { LedgerSubprovider } from '../../src';
+import { DoneCallback, LedgerEthereumClient } from '../../src/types';
import { chaiSetup } from '../chai_setup';
import { reportCallbackErrors } from '../utils/report_callback_errors';
chaiSetup.configure();
const expect = chai.expect;
+async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
+ const ledgerConnection = await TransportNodeHid.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
+ return ledgerEthClient;
+}
+
+const TESTRPC_DERIVATION_PATH = `m/44'/60'/0'/0`;
const TEST_RPC_ACCOUNT_0 = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
describe('LedgerSubprovider', () => {
@@ -23,14 +34,25 @@ describe('LedgerSubprovider', () => {
ledgerSubprovider = new LedgerSubprovider({
networkId,
ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ derivationPath: TESTRPC_DERIVATION_PATH,
});
});
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 the expected first account from a ledger set up with the test mnemonic', async () => {
+ const accounts = await ledgerSubprovider.getAccountsAsync();
+ expect(accounts[0]).to.be.equal(TEST_RPC_ACCOUNT_0);
+ });
+ 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);
@@ -44,10 +66,11 @@ describe('LedgerSubprovider', () => {
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
chainId: 3,
+ from: TEST_RPC_ACCOUNT_0,
};
const txHex = await ledgerSubprovider.signTransactionAsync(tx);
expect(txHex).to.be.equal(
- '0xf85f8080822710940000000000000000000000000000000000000000808077a088a95ef1378487bc82be558e82c8478baf840c545d5b887536bb1da63673a98ba0019f4a4b9a107d1e6752bf7f701e275f28c13791d6e76af895b07373462cefaa',
+ '0xf85f8080822710940000000000000000000000000000000000000000808078a0712854c73c69445cc1b22a7c3d7312ff9a97fe4ffba35fd636e8236b211b6e7ca0647cee031615e52d916c7c707025bc64ad525d8f1b9876c3435a863b42743178',
);
});
});
@@ -172,7 +195,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..4c0803a29 100644
--- a/packages/subproviders/test/unit/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts
@@ -21,7 +21,7 @@ describe('LedgerSubprovider', () => {
const ledgerEthereumClientFactoryAsync = async () => {
// tslint:disable:no-object-literal-type-assertion
const ledgerEthClient = {
- getAddress_async: async () => {
+ getAddress: async () => {
const publicKey =
'04f428290f4c5ed6a198f71b8205f488141dbb3f0840c923bbfa798ecbee6370986c03b5575d94d506772fb48a6a44e345e4ebd4f028a6f609c44b655d6d3e71a1';
const chainCode = 'ac055a5537c0c7e9e02d14a197cad6b857836da2a12043b46912a37d959b5ae8';
@@ -32,7 +32,7 @@ describe('LedgerSubprovider', () => {
chainCode,
};
},
- signPersonalMessage_async: async () => {
+ signPersonalMessage: async () => {
const ecSignature = {
v: 28,
r: 'a6cc284bff14b42bdf5e9286730c152be91719d478605ec46b3bebcd0ae49148',
@@ -40,7 +40,7 @@ describe('LedgerSubprovider', () => {
};
return ecSignature;
},
- signTransaction_async: async (derivationPath: string, txHex: string) => {
+ signTransaction: async (derivationPath: string, txHex: string) => {
const ecSignature = {
v: '77',
r: '88a95ef1378487bc82be558e82c8478baf840c545d5b887536bb1da63673a98b',
@@ -48,8 +48,8 @@ describe('LedgerSubprovider', () => {
};
return ecSignature;
},
- comm: {
- close_async: _.noop,
+ transport: {
+ close: _.noop,
} as LedgerCommunicationClient,
};
// tslint:enable:no-object-literal-type-assertion
@@ -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/testnet-faucets/src/ts/dispense_asset_tasks.ts b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
index 9aa47463c..56b0a9e45 100644
--- a/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
+++ b/packages/testnet-faucets/src/ts/dispense_asset_tasks.ts
@@ -9,11 +9,21 @@ import { utils } from './utils';
const DISPENSE_AMOUNT_ETHER = 0.1;
const DISPENSE_AMOUNT_TOKEN = 0.1;
+const DISPENSE_MAX_AMOUNT_TOKEN = 2;
+const DISPENSE_MAX_AMOUNT_ETHER = 2;
export const dispenseAssetTasks = {
dispenseEtherTask(recipientAddress: string, web3: Web3) {
return async () => {
utils.consoleLog(`Processing ETH ${recipientAddress}`);
+ const userBalance = await promisify<BigNumber>(web3.eth.getBalance)(recipientAddress);
+ const maxAmountInWei = new BigNumber(web3.toWei(DISPENSE_MAX_AMOUNT_ETHER, 'ether'));
+ if (userBalance.greaterThanOrEqualTo(maxAmountInWei)) {
+ utils.consoleLog(
+ `User exceeded ETH balance maximum (${maxAmountInWei}) ${recipientAddress} ${userBalance} `,
+ );
+ return;
+ }
const sendTransactionAsync = promisify(web3.eth.sendTransaction);
const txHash = await sendTransactionAsync({
from: configs.DISPENSER_ADDRESS,
@@ -32,6 +42,17 @@ export const dispenseAssetTasks = {
throw new Error(`Unsupported asset type: ${tokenSymbol}`);
}
const baseUnitAmount = ZeroEx.toBaseUnitAmount(amountToDispense, token.decimals);
+ const userBalanceBaseUnits = await zeroEx.token.getBalanceAsync(token.address, recipientAddress);
+ const maxAmountBaseUnits = ZeroEx.toBaseUnitAmount(
+ new BigNumber(DISPENSE_MAX_AMOUNT_TOKEN),
+ token.decimals,
+ );
+ if (userBalanceBaseUnits.greaterThanOrEqualTo(maxAmountBaseUnits)) {
+ utils.consoleLog(
+ `User exceeded token balance maximum (${maxAmountBaseUnits}) ${recipientAddress} ${userBalanceBaseUnits} `,
+ );
+ return;
+ }
const txHash = await zeroEx.token.transferAsync(
token.address,
configs.DISPENSER_ADDRESS,
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 e827842b0..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",
- "ethers-typescript-typings": "^0.0.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.2",
"lodash": "^4.17.4",
- "web3": "^0.20.0"
+ "web3": "^0.20.0",
+ "web3-typescript-typings": "^0.10.0"
}
}
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index 56dfa227c..a07805344 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -1,2 +1,179 @@
-export { Web3Wrapper } from './web3_wrapper';
-export { BaseContract } from './base_contract';
+import { TransactionReceipt, TxData } from '@0xproject/types';
+import { BigNumber, promisify } from '@0xproject/utils';
+import * as _ from 'lodash';
+import * as Web3 from 'web3';
+
+interface RawLogEntry {
+ logIndex: string | null;
+ transactionIndex: string | null;
+ transactionHash: string;
+ blockHash: string | null;
+ blockNumber: string | null;
+ address: string;
+ data: string;
+ topics: string[];
+}
+
+export class Web3Wrapper {
+ private _web3: Web3;
+ private _defaults: Partial<TxData>;
+ private _jsonRpcRequestId: number;
+ constructor(provider: Web3.Provider, defaults?: Partial<TxData>) {
+ if (_.isUndefined((provider as any).sendAsync)) {
+ // Web3@1.0 provider doesn't support synchronous http requests,
+ // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
+ // We re-assign the send method so that Web3@1.0 providers work with 0x.js
+ (provider as any).sendAsync = (provider as any).send;
+ }
+ this._web3 = new Web3();
+ this._web3.setProvider(provider);
+ this._defaults = defaults || {};
+ this._jsonRpcRequestId = 0;
+ }
+ public getContractDefaults(): Partial<TxData> {
+ return this._defaults;
+ }
+ public setProvider(provider: Web3.Provider) {
+ this._web3.setProvider(provider);
+ }
+ public isAddress(address: string): boolean {
+ return this._web3.isAddress(address);
+ }
+ public async isSenderAddressAvailableAsync(senderAddress: string): Promise<boolean> {
+ const addresses = await this.getAvailableAddressesAsync();
+ const normalizedAddress = senderAddress.toLowerCase();
+ return _.includes(addresses, normalizedAddress);
+ }
+ public async getNodeVersionAsync(): Promise<string> {
+ const nodeVersion = await promisify<string>(this._web3.version.getNode)();
+ return nodeVersion;
+ }
+ public async getNetworkIdAsync(): Promise<number> {
+ const networkIdStr = await promisify<string>(this._web3.version.getNetwork)();
+ const networkId = _.parseInt(networkIdStr);
+ return networkId;
+ }
+ public async getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt> {
+ const transactionReceipt = await promisify<TransactionReceipt>(this._web3.eth.getTransactionReceipt)(txHash);
+ if (!_.isNull(transactionReceipt)) {
+ transactionReceipt.status = this._normalizeTxReceiptStatus(transactionReceipt.status);
+ }
+ return transactionReceipt;
+ }
+ public getCurrentProvider(): Web3.Provider {
+ return this._web3.currentProvider;
+ }
+ public toWei(ethAmount: BigNumber): BigNumber {
+ const balanceWei = this._web3.toWei(ethAmount, 'ether');
+ return balanceWei;
+ }
+ public async getBalanceInWeiAsync(owner: string): Promise<BigNumber> {
+ let balanceInWei = await promisify<BigNumber>(this._web3.eth.getBalance)(owner);
+ // Rewrap in a new BigNumber
+ balanceInWei = new BigNumber(balanceInWei);
+ return balanceInWei;
+ }
+ public async doesContractExistAtAddressAsync(address: string): Promise<boolean> {
+ const code = await promisify<string>(this._web3.eth.getCode)(address);
+ // Regex matches 0x0, 0x00, 0x in order to accommodate poorly implemented clients
+ const codeIsEmpty = /^0x0{0,40}$/i.test(code);
+ return !codeIsEmpty;
+ }
+ public async signTransactionAsync(address: string, message: string): Promise<string> {
+ const signData = await promisify<string>(this._web3.eth.sign)(address, message);
+ return signData;
+ }
+ public async getBlockNumberAsync(): Promise<number> {
+ const blockNumber = await promisify<number>(this._web3.eth.getBlockNumber)();
+ return blockNumber;
+ }
+ public async getBlockAsync(blockParam: string | Web3.BlockParam): Promise<Web3.BlockWithoutTransactionData> {
+ const block = await promisify<Web3.BlockWithoutTransactionData>(this._web3.eth.getBlock)(blockParam);
+ return block;
+ }
+ public async getBlockTimestampAsync(blockParam: string | Web3.BlockParam): Promise<number> {
+ const { timestamp } = await this.getBlockAsync(blockParam);
+ return timestamp;
+ }
+ public async getAvailableAddressesAsync(): Promise<string[]> {
+ const addresses = await promisify<string[]>(this._web3.eth.getAccounts)();
+ const normalizedAddresses = _.map(addresses, address => address.toLowerCase());
+ return normalizedAddresses;
+ }
+ public async getLogsAsync(filter: Web3.FilterObject): Promise<Web3.LogEntry[]> {
+ let fromBlock = filter.fromBlock;
+ if (_.isNumber(fromBlock)) {
+ fromBlock = this._web3.toHex(fromBlock);
+ }
+ let toBlock = filter.toBlock;
+ if (_.isNumber(toBlock)) {
+ toBlock = this._web3.toHex(toBlock);
+ }
+ const serializedFilter = {
+ ...filter,
+ fromBlock,
+ toBlock,
+ };
+ const payload = {
+ jsonrpc: '2.0',
+ id: this._jsonRpcRequestId++,
+ method: 'eth_getLogs',
+ params: [serializedFilter],
+ };
+ const rawLogs = await this._sendRawPayloadAsync<RawLogEntry[]>(payload);
+ const formattedLogs = _.map(rawLogs, this._formatLog.bind(this));
+ return formattedLogs;
+ }
+ public getContractFromAbi(abi: Web3.ContractAbi): Web3.Contract<any> {
+ const web3Contract = this._web3.eth.contract(abi);
+ return web3Contract;
+ }
+ public async estimateGasAsync(txData: Partial<Web3.TxData>): Promise<number> {
+ const gas = await promisify<number>(this._web3.eth.estimateGas)(txData);
+ return gas;
+ }
+ public async callAsync(callData: Web3.CallData, defaultBlock?: Web3.BlockParam): Promise<string> {
+ const rawCalllResult = await promisify<string>(this._web3.eth.call)(callData, defaultBlock);
+ return rawCalllResult;
+ }
+ public async sendTransactionAsync(txData: Web3.TxData): Promise<string> {
+ const txHash = await promisify<string>(this._web3.eth.sendTransaction)(txData);
+ return txHash;
+ }
+ private async _sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> {
+ const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider);
+ const response = await promisify<Web3.JSONRPCResponsePayload>(sendAsync)(payload);
+ const result = response.result;
+ return result;
+ }
+ private _normalizeTxReceiptStatus(status: undefined | null | string | 0 | 1): null | 0 | 1 {
+ // Transaction status might have four values
+ // undefined - Testrpc and other old clients
+ // null - New clients on old transactions
+ // number - Parity
+ // hex - Geth
+ if (_.isString(status)) {
+ return this._web3.toDecimal(status) as 0 | 1;
+ } else if (_.isUndefined(status)) {
+ return null;
+ } else {
+ return status;
+ }
+ }
+ private _formatLog(rawLog: RawLogEntry): Web3.LogEntry {
+ const formattedLog = {
+ ...rawLog,
+ logIndex: this._hexToDecimal(rawLog.logIndex),
+ blockNumber: this._hexToDecimal(rawLog.blockNumber),
+ transactionIndex: this._hexToDecimal(rawLog.transactionIndex),
+ };
+ return formattedLog;
+ }
+ private _hexToDecimal(hex: string | null): number | null {
+ if (_.isNull(hex)) {
+ return null;
+ }
+ const decimal = this._web3.toDecimal(hex);
+ return decimal;
+ }
+}
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts
deleted file mode 100644
index a07805344..000000000
--- a/packages/web3-wrapper/src/web3_wrapper.ts
+++ /dev/null
@@ -1,179 +0,0 @@
-import { TransactionReceipt, TxData } from '@0xproject/types';
-import { BigNumber, promisify } from '@0xproject/utils';
-import * as _ from 'lodash';
-import * as Web3 from 'web3';
-
-interface RawLogEntry {
- logIndex: string | null;
- transactionIndex: string | null;
- transactionHash: string;
- blockHash: string | null;
- blockNumber: string | null;
- address: string;
- data: string;
- topics: string[];
-}
-
-export class Web3Wrapper {
- private _web3: Web3;
- private _defaults: Partial<TxData>;
- private _jsonRpcRequestId: number;
- constructor(provider: Web3.Provider, defaults?: Partial<TxData>) {
- if (_.isUndefined((provider as any).sendAsync)) {
- // Web3@1.0 provider doesn't support synchronous http requests,
- // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
- // We re-assign the send method so that Web3@1.0 providers work with 0x.js
- (provider as any).sendAsync = (provider as any).send;
- }
- this._web3 = new Web3();
- this._web3.setProvider(provider);
- this._defaults = defaults || {};
- this._jsonRpcRequestId = 0;
- }
- public getContractDefaults(): Partial<TxData> {
- return this._defaults;
- }
- public setProvider(provider: Web3.Provider) {
- this._web3.setProvider(provider);
- }
- public isAddress(address: string): boolean {
- return this._web3.isAddress(address);
- }
- public async isSenderAddressAvailableAsync(senderAddress: string): Promise<boolean> {
- const addresses = await this.getAvailableAddressesAsync();
- const normalizedAddress = senderAddress.toLowerCase();
- return _.includes(addresses, normalizedAddress);
- }
- public async getNodeVersionAsync(): Promise<string> {
- const nodeVersion = await promisify<string>(this._web3.version.getNode)();
- return nodeVersion;
- }
- public async getNetworkIdAsync(): Promise<number> {
- const networkIdStr = await promisify<string>(this._web3.version.getNetwork)();
- const networkId = _.parseInt(networkIdStr);
- return networkId;
- }
- public async getTransactionReceiptAsync(txHash: string): Promise<TransactionReceipt> {
- const transactionReceipt = await promisify<TransactionReceipt>(this._web3.eth.getTransactionReceipt)(txHash);
- if (!_.isNull(transactionReceipt)) {
- transactionReceipt.status = this._normalizeTxReceiptStatus(transactionReceipt.status);
- }
- return transactionReceipt;
- }
- public getCurrentProvider(): Web3.Provider {
- return this._web3.currentProvider;
- }
- public toWei(ethAmount: BigNumber): BigNumber {
- const balanceWei = this._web3.toWei(ethAmount, 'ether');
- return balanceWei;
- }
- public async getBalanceInWeiAsync(owner: string): Promise<BigNumber> {
- let balanceInWei = await promisify<BigNumber>(this._web3.eth.getBalance)(owner);
- // Rewrap in a new BigNumber
- balanceInWei = new BigNumber(balanceInWei);
- return balanceInWei;
- }
- public async doesContractExistAtAddressAsync(address: string): Promise<boolean> {
- const code = await promisify<string>(this._web3.eth.getCode)(address);
- // Regex matches 0x0, 0x00, 0x in order to accommodate poorly implemented clients
- const codeIsEmpty = /^0x0{0,40}$/i.test(code);
- return !codeIsEmpty;
- }
- public async signTransactionAsync(address: string, message: string): Promise<string> {
- const signData = await promisify<string>(this._web3.eth.sign)(address, message);
- return signData;
- }
- public async getBlockNumberAsync(): Promise<number> {
- const blockNumber = await promisify<number>(this._web3.eth.getBlockNumber)();
- return blockNumber;
- }
- public async getBlockAsync(blockParam: string | Web3.BlockParam): Promise<Web3.BlockWithoutTransactionData> {
- const block = await promisify<Web3.BlockWithoutTransactionData>(this._web3.eth.getBlock)(blockParam);
- return block;
- }
- public async getBlockTimestampAsync(blockParam: string | Web3.BlockParam): Promise<number> {
- const { timestamp } = await this.getBlockAsync(blockParam);
- return timestamp;
- }
- public async getAvailableAddressesAsync(): Promise<string[]> {
- const addresses = await promisify<string[]>(this._web3.eth.getAccounts)();
- const normalizedAddresses = _.map(addresses, address => address.toLowerCase());
- return normalizedAddresses;
- }
- public async getLogsAsync(filter: Web3.FilterObject): Promise<Web3.LogEntry[]> {
- let fromBlock = filter.fromBlock;
- if (_.isNumber(fromBlock)) {
- fromBlock = this._web3.toHex(fromBlock);
- }
- let toBlock = filter.toBlock;
- if (_.isNumber(toBlock)) {
- toBlock = this._web3.toHex(toBlock);
- }
- const serializedFilter = {
- ...filter,
- fromBlock,
- toBlock,
- };
- const payload = {
- jsonrpc: '2.0',
- id: this._jsonRpcRequestId++,
- method: 'eth_getLogs',
- params: [serializedFilter],
- };
- const rawLogs = await this._sendRawPayloadAsync<RawLogEntry[]>(payload);
- const formattedLogs = _.map(rawLogs, this._formatLog.bind(this));
- return formattedLogs;
- }
- public getContractFromAbi(abi: Web3.ContractAbi): Web3.Contract<any> {
- const web3Contract = this._web3.eth.contract(abi);
- return web3Contract;
- }
- public async estimateGasAsync(txData: Partial<Web3.TxData>): Promise<number> {
- const gas = await promisify<number>(this._web3.eth.estimateGas)(txData);
- return gas;
- }
- public async callAsync(callData: Web3.CallData, defaultBlock?: Web3.BlockParam): Promise<string> {
- const rawCalllResult = await promisify<string>(this._web3.eth.call)(callData, defaultBlock);
- return rawCalllResult;
- }
- public async sendTransactionAsync(txData: Web3.TxData): Promise<string> {
- const txHash = await promisify<string>(this._web3.eth.sendTransaction)(txData);
- return txHash;
- }
- private async _sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> {
- const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider);
- const response = await promisify<Web3.JSONRPCResponsePayload>(sendAsync)(payload);
- const result = response.result;
- return result;
- }
- private _normalizeTxReceiptStatus(status: undefined | null | string | 0 | 1): null | 0 | 1 {
- // Transaction status might have four values
- // undefined - Testrpc and other old clients
- // null - New clients on old transactions
- // number - Parity
- // hex - Geth
- if (_.isString(status)) {
- return this._web3.toDecimal(status) as 0 | 1;
- } else if (_.isUndefined(status)) {
- return null;
- } else {
- return status;
- }
- }
- private _formatLog(rawLog: RawLogEntry): Web3.LogEntry {
- const formattedLog = {
- ...rawLog,
- logIndex: this._hexToDecimal(rawLog.logIndex),
- blockNumber: this._hexToDecimal(rawLog.blockNumber),
- transactionIndex: this._hexToDecimal(rawLog.transactionIndex),
- };
- return formattedLog;
- }
- private _hexToDecimal(hex: string | null): number | null {
- if (_.isNull(hex)) {
- return null;
- }
- const decimal = this._web3.toDecimal(hex);
- return decimal;
- }
-}
diff --git a/packages/website/README.md b/packages/website/README.md
index 7d3187781..042df52de 100644
--- a/packages/website/README.md
+++ b/packages/website/README.md
@@ -58,11 +58,11 @@ yarn lint
##### Toolkit
-* [Material Design Icon Font](http://zavoloklom.github.io/material-design-iconic-font/icons.html#directional)
-* [BassCSS toolkit](http://basscss.com/)
-* [Material-UI component library](http://www.material-ui.com/#/)
+* [Material Design Icon Font](http://zavoloklom.github.io/material-design-iconic-font/icons.html#directional)
+* [BassCSS toolkit](http://basscss.com/)
+* [Material-UI component library](http://www.material-ui.com/#/)
##### Recommended Atom packages:
-* [atom-typescript](https://atom.io/packages/atom-typescript)
-* [linter-tslint](https://atom.io/packages/linter-tslint)
+* [atom-typescript](https://atom.io/packages/atom-typescript)
+* [linter-tslint](https://atom.io/packages/linter-tslint)
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/md/docs/smart_contracts/introduction.md b/packages/website/md/docs/smart_contracts/introduction.md
index 20396289b..566a573b6 100644
--- a/packages/website/md/docs/smart_contracts/introduction.md
+++ b/packages/website/md/docs/smart_contracts/introduction.md
@@ -2,7 +2,7 @@ Welcome to the [0x smart contracts](https://github.com/0xProject/contracts) docu
### Helpful wiki articles:
-* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture)
-* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions)
-* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses)
-* [0x protocol message format](https://0xproject.com/wiki#Message-Format)
+* [Overview of 0x protocol architecture](https://0xproject.com/wiki#Architecture)
+* [0x smart contract interactions](https://0xproject.com/wiki#Contract-Interactions)
+* [Deployed smart contract addresses](https://0xproject.com/wiki#Deployed-Addresses)
+* [0x protocol message format](https://0xproject.com/wiki#Message-Format)
diff --git a/packages/website/package.json b/packages/website/package.json
index 1d313390a..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,6 +87,7 @@
"copy-webpack-plugin": "^4.0.1",
"copyfiles": "^1.2.0",
"css-loader": "0.23.x",
+ "ethers-typescript-typings": "^0.0.2",
"exports-loader": "0.6.x",
"imports-loader": "0.6.x",
"json-loader": "^0.5.4",
@@ -98,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
index ba9bb8a3a..244f504b3 100644
--- a/packages/website/public/images/doc_icons/connect.png
+++ b/packages/website/public/images/doc_icons/connect.png
Binary files differ
diff --git a/packages/website/public/images/doc_icons/contracts.png b/packages/website/public/images/doc_icons/contracts.png
index f5c6545ca..03956f162 100644
--- a/packages/website/public/images/doc_icons/contracts.png
+++ b/packages/website/public/images/doc_icons/contracts.png
Binary files differ
diff --git a/packages/website/public/images/doc_icons/zeroExJs.png b/packages/website/public/images/doc_icons/zeroExJs.png
index 029777ffe..fe0c49a0f 100644
--- a/packages/website/public/images/doc_icons/zeroExJs.png
+++ b/packages/website/public/images/doc_icons/zeroExJs.png
Binary files differ
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/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx
index 2723c2218..b2b2d2ebd 100644
--- a/packages/website/ts/components/top_bar/top_bar.tsx
+++ b/packages/website/ts/components/top_bar/top_bar.tsx
@@ -319,7 +319,6 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
shouldDisplaySectionHeaders={false}
onMenuItemClick={this._onMenuButtonClick.bind(this)}
selectedVersion={this.props.docsVersion}
- docPath={this.props.docsInfo.websitePath}
versions={this.props.availableDocVersions}
/>
</div>
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 5c5d26b44..6a5ba1f99 100644
--- a/packages/website/ts/containers/connect_documentation.tsx
+++ b/packages/website/ts/containers/connect_documentation.ts
@@ -2,15 +2,14 @@ import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
+import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page';
import { DocsInfo } from 'ts/pages/documentation/docs_info';
-import { Documentation as DocumentationComponent, DocumentationAllProps } from 'ts/pages/documentation/documentation';
import { Dispatcher } from 'ts/redux/dispatcher';
import { State } from 'ts/redux/reducer';
-import { DocsInfoConfig, Environments, WebsitePaths } from 'ts/types';
+import { DocPackages, DocsInfoConfig, Environments, SupportedDocJson, WebsitePaths } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
import { Translate } from 'ts/utils/translate';
-import { typeDocUtils } from 'ts/utils/typedoc_utils';
/* tslint:disable:no-var-requires */
const IntroMarkdown = require('md/docs/connect/introduction');
@@ -25,16 +24,11 @@ const connectDocSections = {
types: constants.TYPES_SECTION_NAME,
};
-const s3BucketName =
- configs.ENVIRONMENT === Environments.DEVELOPMENT ? 'staging-connect-docs-jsons' : 'connect-docs-jsons';
-const docsJsonRoot = `https://s3.amazonaws.com/${s3BucketName}`;
-
const docsInfoConfig: DocsInfoConfig = {
+ id: DocPackages.Connect,
+ type: SupportedDocJson.TypeDoc,
displayName: '0x Connect',
- subPackageName: 'connect',
- packageUrl: 'https://github.com/0xProject/0x.js',
- websitePath: WebsitePaths.Connect,
- docsJsonRoot,
+ packageUrl: 'https://github.com/0xProject/0x-monorepo',
menu: {
introduction: [connectDocSections.introduction],
install: [connectDocSections.installation],
@@ -77,7 +71,6 @@ const docsInfoConfig: DocsInfoConfig = {
menuSubsectionToVersionWhenIntroduced: {},
sections: connectDocSections,
visibleConstructors: [connectDocSections.httpClient, connectDocSections.webSocketOrderbookChannel],
- convertToDocAgnosticFormatFn: typeDocUtils.convertToDocAgnosticFormat.bind(typeDocUtils),
};
const docsInfo = new DocsInfo(docsInfoConfig);
@@ -92,7 +85,7 @@ interface ConnectedDispatch {
dispatcher: Dispatcher;
}
-const mapStateToProps = (state: State, ownProps: DocumentationAllProps): ConnectedState => ({
+const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({
docsVersion: state.docsVersion,
availableDocVersions: state.availableDocVersions,
translate: state.translate,
@@ -103,6 +96,6 @@ const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
dispatcher: new Dispatcher(dispatch),
});
-export const Documentation: React.ComponentClass<DocumentationAllProps> = connect(mapStateToProps, mapDispatchToProps)(
- DocumentationComponent,
+export const Documentation: React.ComponentClass<DocPageProps> = connect(mapStateToProps, mapDispatchToProps)(
+ DocPageComponent,
);
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.ts b/packages/website/ts/containers/smart_contracts_documentation.ts
new file mode 100644
index 000000000..a839529aa
--- /dev/null
+++ b/packages/website/ts/containers/smart_contracts_documentation.ts
@@ -0,0 +1,98 @@
+import * as _ from 'lodash';
+import * as React from 'react';
+import { connect } from 'react-redux';
+import { Dispatch } from 'redux';
+import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { Dispatcher } from 'ts/redux/dispatcher';
+import { State } from 'ts/redux/reducer';
+import {
+ DocPackages,
+ DocsInfoConfig,
+ Networks,
+ SmartContractDocSections as Sections,
+ SupportedDocJson,
+ WebsitePaths,
+} from 'ts/types';
+import { Translate } from 'ts/utils/translate';
+
+/* tslint:disable:no-var-requires */
+const IntroMarkdown = require('md/docs/smart_contracts/introduction');
+/* tslint:enable:no-var-requires */
+
+const docsInfoConfig: DocsInfoConfig = {
+ id: DocPackages.SmartContracts,
+ type: SupportedDocJson.Doxity,
+ displayName: '0x Smart Contracts',
+ packageUrl: 'https://github.com/0xProject/contracts',
+ menu: {
+ introduction: [Sections.Introduction],
+ contracts: [Sections.Exchange, Sections.TokenRegistry, Sections.ZRXToken, Sections.TokenTransferProxy],
+ },
+ sectionNameToMarkdown: {
+ [Sections.Introduction]: IntroMarkdown,
+ },
+ sections: {
+ Introduction: Sections.Introduction,
+ Exchange: Sections.Exchange,
+ TokenTransferProxy: Sections.TokenTransferProxy,
+ TokenRegistry: Sections.TokenRegistry,
+ ZRXToken: Sections.ZRXToken,
+ },
+ visibleConstructors: [Sections.Exchange, Sections.TokenRegistry, Sections.ZRXToken, Sections.TokenTransferProxy],
+ contractsByVersionByNetworkId: {
+ '1.0.0': {
+ [Networks.Mainnet]: {
+ [Sections.Exchange]: '0x12459c951127e0c374ff9105dda097662a027093',
+ [Sections.TokenTransferProxy]: '0x8da0d80f5007ef1e431dd2127178d224e32c2ef4',
+ [Sections.ZRXToken]: '0xe41d2489571d322189246dafa5ebde1f4699f498',
+ [Sections.TokenRegistry]: '0x926a74c5c36adf004c87399e65f75628b0f98d2c',
+ },
+ [Networks.Ropsten]: {
+ [Sections.Exchange]: '0x479cc461fecd078f766ecc58533d6f69580cf3ac',
+ [Sections.TokenTransferProxy]: '0x4e9aad8184de8833365fea970cd9149372fdf1e6',
+ [Sections.ZRXToken]: '0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d',
+ [Sections.TokenRegistry]: '0x6b1a50f0bb5a7995444bd3877b22dc89c62843ed',
+ },
+ [Networks.Kovan]: {
+ [Sections.Exchange]: '0x90fe2af704b34e0224bf2299c838e04d4dcf1364',
+ [Sections.TokenTransferProxy]: '0x087Eed4Bc1ee3DE49BeFbd66C662B434B15d49d4',
+ [Sections.ZRXToken]: '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570',
+ [Sections.TokenRegistry]: '0xf18e504561f4347bea557f3d4558f559dddbae7f',
+ },
+ [Networks.Rinkeby]: {
+ [Sections.Exchange]: '0x1d16ef40fac01cec8adac2ac49427b9384192c05',
+ [Sections.TokenTransferProxy]: '0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d',
+ [Sections.ZRXToken]: '0x00f58d6d585f84b2d7267940cede30ce2fe6eae8',
+ [Sections.TokenRegistry]: '0x4e9aad8184de8833365fea970cd9149372fdf1e6',
+ },
+ },
+ },
+};
+const docsInfo = new DocsInfo(docsInfoConfig);
+
+interface ConnectedState {
+ docsVersion: string;
+ availableDocVersions: string[];
+ translate: Translate;
+}
+
+interface ConnectedDispatch {
+ dispatcher: Dispatcher;
+ docsInfo: DocsInfo;
+}
+
+const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({
+ docsVersion: state.docsVersion,
+ availableDocVersions: state.availableDocVersions,
+ translate: state.translate,
+});
+
+const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
+ dispatcher: new Dispatcher(dispatch),
+ docsInfo,
+});
+
+export const Documentation: React.ComponentClass<DocPageProps> = connect(mapStateToProps, mapDispatchToProps)(
+ DocPageComponent,
+);
diff --git a/packages/website/ts/containers/smart_contracts_documentation.tsx b/packages/website/ts/containers/smart_contracts_documentation.tsx
deleted file mode 100644
index c4731f929..000000000
--- a/packages/website/ts/containers/smart_contracts_documentation.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import * as _ from 'lodash';
-import * as React from 'react';
-import { connect } from 'react-redux';
-import { Dispatch } from 'redux';
-import { DocsInfo } from 'ts/pages/documentation/docs_info';
-import { Documentation as DocumentationComponent, DocumentationAllProps } from 'ts/pages/documentation/documentation';
-import { Dispatcher } from 'ts/redux/dispatcher';
-import { State } from 'ts/redux/reducer';
-import { DocsInfoConfig, SmartContractDocSections as Sections, WebsitePaths } from 'ts/types';
-import { doxityUtils } from 'ts/utils/doxity_utils';
-import { Translate } from 'ts/utils/translate';
-
-/* tslint:disable:no-var-requires */
-const IntroMarkdown = require('md/docs/smart_contracts/introduction');
-/* tslint:enable:no-var-requires */
-
-const docsInfoConfig: DocsInfoConfig = {
- displayName: '0x Smart Contracts',
- packageUrl: 'https://github.com/0xProject/contracts',
- websitePath: WebsitePaths.SmartContracts,
- docsJsonRoot: 'https://s3.amazonaws.com/smart-contracts-docs-json',
- menu: {
- introduction: [Sections.Introduction],
- contracts: [Sections.Exchange, Sections.TokenRegistry, Sections.ZRXToken, Sections.TokenTransferProxy],
- },
- sectionNameToMarkdown: {
- [Sections.Introduction]: IntroMarkdown,
- },
- sections: {
- Introduction: Sections.Introduction,
- Exchange: Sections.Exchange,
- TokenTransferProxy: Sections.TokenTransferProxy,
- TokenRegistry: Sections.TokenRegistry,
- ZRXToken: Sections.ZRXToken,
- },
- visibleConstructors: [Sections.Exchange, Sections.TokenRegistry, Sections.ZRXToken, Sections.TokenTransferProxy],
- convertToDocAgnosticFormatFn: doxityUtils.convertToDocAgnosticFormat.bind(doxityUtils),
-};
-const docsInfo = new DocsInfo(docsInfoConfig);
-
-interface ConnectedState {
- docsVersion: string;
- availableDocVersions: string[];
- translate: Translate;
-}
-
-interface ConnectedDispatch {
- dispatcher: Dispatcher;
- docsInfo: DocsInfo;
-}
-
-const mapStateToProps = (state: State, ownProps: DocumentationAllProps): ConnectedState => ({
- docsVersion: state.docsVersion,
- availableDocVersions: state.availableDocVersions,
- translate: state.translate,
-});
-
-const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
- dispatcher: new Dispatcher(dispatch),
- docsInfo,
-});
-
-export const Documentation: React.ComponentClass<DocumentationAllProps> = connect(mapStateToProps, mapDispatchToProps)(
- DocumentationComponent,
-);
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 a32a87f7f..d0d697e70 100644
--- a/packages/website/ts/containers/zero_ex_js_documentation.tsx
+++ b/packages/website/ts/containers/zero_ex_js_documentation.ts
@@ -2,15 +2,14 @@ import * as _ from 'lodash';
import * as React from 'react';
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
+import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page';
import { DocsInfo } from 'ts/pages/documentation/docs_info';
-import { Documentation as DocumentationComponent, DocumentationAllProps } from 'ts/pages/documentation/documentation';
import { Dispatcher } from 'ts/redux/dispatcher';
import { State } from 'ts/redux/reducer';
-import { DocsInfoConfig, Environments, WebsitePaths } from 'ts/types';
+import { DocPackages, DocsInfoConfig, Environments, SupportedDocJson, WebsitePaths } from 'ts/types';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
import { Translate } from 'ts/utils/translate';
-import { typeDocUtils } from 'ts/utils/typedoc_utils';
/* tslint:disable:no-var-requires */
const IntroMarkdown = require('md/docs/0xjs/introduction');
@@ -37,15 +36,11 @@ const zeroExJsDocSections = {
types: constants.TYPES_SECTION_NAME,
};
-const s3BucketName = configs.ENVIRONMENT === Environments.DEVELOPMENT ? 'staging-0xjs-docs-jsons' : '0xjs-docs-jsons';
-const docsJsonRoot = `https://s3.amazonaws.com/${s3BucketName}`;
-
const docsInfoConfig: DocsInfoConfig = {
+ id: DocPackages.ZeroExJs,
+ type: SupportedDocJson.TypeDoc,
displayName: '0x.js',
- packageUrl: 'https://github.com/0xProject/0x.js',
- subPackageName: '0x.js',
- websitePath: WebsitePaths.ZeroExJs,
- docsJsonRoot,
+ packageUrl: 'https://github.com/0xProject/0x-monorepo',
menu: {
introduction: [zeroExJsDocSections.introduction],
install: [zeroExJsDocSections.installation],
@@ -69,7 +64,8 @@ const docsInfoConfig: DocsInfoConfig = {
[zeroExJsDocSections.versioning]: versioningMarkdown,
},
// Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is
- // currently no way to extract the re-exported types from index.ts via TypeDoc :(
+ // currently no way to extract the re-exported types from index.ts via TypeDoc :( Make sure to only
+ // ADD types here, DO NOT REMOVE types since they might still be needed for older supported versions
publicTypes: [
'Order',
'SignedOrder',
@@ -106,6 +102,7 @@ const docsInfoConfig: DocsInfoConfig = {
'ApprovalContractEventArgs',
'TokenContractEventArgs',
'ZeroExConfig',
+ 'TransactionReceipt',
'TransactionReceiptWithDecodedLogs',
'LogWithDecodedArgs',
'EtherTokenEvents',
@@ -128,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',
@@ -147,7 +160,6 @@ const docsInfoConfig: DocsInfoConfig = {
},
sections: zeroExJsDocSections,
visibleConstructors: [zeroExJsDocSections.zeroEx],
- convertToDocAgnosticFormatFn: typeDocUtils.convertToDocAgnosticFormat.bind(typeDocUtils),
};
const docsInfo = new DocsInfo(docsInfoConfig);
@@ -162,7 +174,7 @@ interface ConnectedDispatch {
dispatcher: Dispatcher;
}
-const mapStateToProps = (state: State, ownProps: DocumentationAllProps): ConnectedState => ({
+const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({
docsVersion: state.docsVersion,
availableDocVersions: state.availableDocVersions,
docsInfo,
@@ -173,6 +185,6 @@ const mapDispatchToProps = (dispatch: Dispatch<State>): ConnectedDispatch => ({
dispatcher: new Dispatcher(dispatch),
});
-export const Documentation: React.ComponentClass<DocumentationAllProps> = connect(mapStateToProps, mapDispatchToProps)(
- DocumentationComponent,
+export const Documentation: React.ComponentClass<DocPageProps> = connect(mapStateToProps, mapDispatchToProps)(
+ DocPageComponent,
);
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/doc_page.tsx b/packages/website/ts/pages/documentation/doc_page.tsx
new file mode 100644
index 000000000..098df5bfd
--- /dev/null
+++ b/packages/website/ts/pages/documentation/doc_page.tsx
@@ -0,0 +1,143 @@
+import findVersions = require('find-versions');
+import * as _ from 'lodash';
+import * as React from 'react';
+import DocumentTitle = require('react-document-title');
+import semverSort = require('semver-sort');
+import { TopBar } from 'ts/components/top_bar/top_bar';
+import { DocsInfo } from 'ts/pages/documentation/docs_info';
+import { Documentation } from 'ts/pages/documentation/documentation';
+import { Dispatcher } from 'ts/redux/dispatcher';
+import { DocAgnosticFormat, DocPackages, DoxityDocObj, Environments, MenuSubsectionsBySection } from 'ts/types';
+import { configs } from 'ts/utils/configs';
+import { constants } from 'ts/utils/constants';
+import { docUtils } from 'ts/utils/doc_utils';
+import { Translate } from 'ts/utils/translate';
+
+const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
+
+const isDevelopment = configs.ENVIRONMENT === Environments.DEVELOPMENT;
+const docIdToS3BucketName: { [id: string]: string } = {
+ [DocPackages.ZeroExJs]: isDevelopment ? 'staging-0xjs-docs-jsons' : '0xjs-docs-jsons',
+ [DocPackages.SmartContracts]: 'smart-contracts-docs-json',
+ [DocPackages.Connect]: isDevelopment ? 'staging-connect-docs-jsons' : 'connect-docs-jsons',
+};
+
+const docIdToSubpackageName: { [id: string]: string } = {
+ [DocPackages.ZeroExJs]: '0x.js',
+ [DocPackages.Connect]: 'connect',
+ [DocPackages.SmartContracts]: 'contracts',
+};
+
+export interface DocPageProps {
+ location: Location;
+ dispatcher: Dispatcher;
+ docsVersion: string;
+ availableDocVersions: string[];
+ docsInfo: DocsInfo;
+ translate: Translate;
+}
+
+interface DocPageState {
+ docAgnosticFormat?: DocAgnosticFormat;
+}
+
+export class DocPage extends React.Component<DocPageProps, DocPageState> {
+ private _isUnmounted: boolean;
+ constructor(props: DocPageProps) {
+ super(props);
+ this._isUnmounted = false;
+ this.state = {
+ docAgnosticFormat: undefined,
+ };
+ }
+ public componentWillMount() {
+ const pathName = this.props.location.pathname;
+ const lastSegment = pathName.substr(pathName.lastIndexOf('/') + 1);
+ const versions = findVersions(lastSegment);
+ const preferredVersionIfExists = versions.length > 0 ? versions[0] : undefined;
+ // tslint:disable-next-line:no-floating-promises
+ this._fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists);
+ }
+ public componentWillUnmount() {
+ this._isUnmounted = true;
+ }
+
+ public render() {
+ const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat)
+ ? {}
+ : this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
+ const sourceUrl = this._getSourceUrl();
+ return (
+ <div>
+ <DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} />
+ <TopBar
+ blockchainIsLoaded={false}
+ location={this.props.location}
+ docsVersion={this.props.docsVersion}
+ availableDocVersions={this.props.availableDocVersions}
+ menu={this.props.docsInfo.getMenu(this.props.docsVersion)}
+ menuSubsectionsBySection={menuSubsectionsBySection}
+ docsInfo={this.props.docsInfo}
+ translate={this.props.translate}
+ />
+ <Documentation
+ location={this.props.location}
+ docsVersion={this.props.docsVersion}
+ availableDocVersions={this.props.availableDocVersions}
+ docsInfo={this.props.docsInfo}
+ docAgnosticFormat={this.state.docAgnosticFormat}
+ menuSubsectionsBySection={menuSubsectionsBySection}
+ sourceUrl={sourceUrl}
+ />
+ </div>
+ );
+ }
+ private async _fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
+ const s3BucketName = docIdToS3BucketName[this.props.docsInfo.id];
+ const docsJsonRoot = `${constants.S3_BUCKET_ROOT}/${s3BucketName}`;
+ const versionToFileName = await docUtils.getVersionToFileNameAsync(docsJsonRoot);
+ const versions = _.keys(versionToFileName);
+ this.props.dispatcher.updateAvailableDocVersions(versions);
+ const sortedVersions = semverSort.desc(versions);
+ const latestVersion = sortedVersions[0];
+
+ let versionToFetch = latestVersion;
+ if (!_.isUndefined(preferredVersionIfExists)) {
+ const preferredVersionFileNameIfExists = versionToFileName[preferredVersionIfExists];
+ if (!_.isUndefined(preferredVersionFileNameIfExists)) {
+ versionToFetch = preferredVersionIfExists;
+ }
+ }
+ this.props.dispatcher.updateCurrentDocsVersion(versionToFetch);
+
+ const versionFileNameToFetch = versionToFileName[versionToFetch];
+ const versionDocObj = await docUtils.getJSONDocFileAsync(versionFileNameToFetch, docsJsonRoot);
+ const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj as DoxityDocObj);
+
+ if (!this._isUnmounted) {
+ this.setState({
+ docAgnosticFormat,
+ });
+ }
+ }
+ private _getSourceUrl() {
+ const url = this.props.docsInfo.packageUrl;
+ let pkg = docIdToSubpackageName[this.props.docsInfo.id];
+ let tagPrefix = pkg;
+ const packagesWithNamespace = ['connect'];
+ if (_.includes(packagesWithNamespace, pkg)) {
+ tagPrefix = `@0xproject/${pkg}`;
+ }
+ // HACK: The following three lines exist for backward compatibility reasons
+ // Before exporting types from other packages as part of the 0x.js interface,
+ // all TypeDoc generated paths omitted the topLevel `0x.js` segment. Now it
+ // adds it, and for that reason, we need to make sure we don't add it twice in
+ // the source links we generate.
+ const semvers = semverSort.desc([this.props.docsVersion, ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH]);
+ const isVersionAfterTopLevelPathChange = semvers[0] !== ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH;
+ pkg = this.props.docsInfo.id === DocPackages.ZeroExJs && isVersionAfterTopLevelPathChange ? '' : `/${pkg}`;
+
+ const sourceUrl = `${url}/blob/${tagPrefix}%40${this.props.docsVersion}/packages${pkg}`;
+ return sourceUrl;
+ }
+}
diff --git a/packages/website/ts/pages/documentation/docs_info.ts b/packages/website/ts/pages/documentation/docs_info.ts
index 4b1ec122a..31e151fe8 100644
--- a/packages/website/ts/pages/documentation/docs_info.ts
+++ b/packages/website/ts/pages/documentation/docs_info.ts
@@ -1,33 +1,37 @@
import compareVersions = require('compare-versions');
import * as _ from 'lodash';
import {
+ ContractsByVersionByNetworkId,
DocAgnosticFormat,
DocsInfoConfig,
DocsMenu,
DoxityDocObj,
MenuSubsectionsBySection,
SectionsMap,
+ SupportedDocJson,
TypeDocNode,
} from 'ts/types';
+import { doxityUtils } from 'ts/utils/doxity_utils';
+import { typeDocUtils } from 'ts/utils/typedoc_utils';
export class DocsInfo {
+ public id: string;
+ public type: SupportedDocJson;
public displayName: string;
public packageUrl: string;
- public subPackageName?: string;
- public websitePath: string;
- public docsJsonRoot: string;
public menu: DocsMenu;
public sections: SectionsMap;
public sectionNameToMarkdown: { [sectionName: string]: string };
+ public contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
private _docsInfo: DocsInfoConfig;
constructor(config: DocsInfoConfig) {
+ this.id = config.id;
+ this.type = config.type;
this.displayName = config.displayName;
this.packageUrl = config.packageUrl;
- this.subPackageName = config.subPackageName;
- this.websitePath = config.websitePath;
- this.docsJsonRoot = config.docsJsonRoot;
this.sections = config.sections;
this.sectionNameToMarkdown = config.sectionNameToMarkdown;
+ this.contractsByVersionByNetworkId = config.contractsByVersionByNetworkId;
this._docsInfo = config;
}
public isPublicType(typeName: string): boolean {
@@ -106,6 +110,10 @@ export class DocsInfo {
return _.includes(this._docsInfo.visibleConstructors, sectionName);
}
public convertToDocAgnosticFormat(docObj: DoxityDocObj | TypeDocNode): DocAgnosticFormat {
- return this._docsInfo.convertToDocAgnosticFormatFn(docObj, this);
+ if (this.type === SupportedDocJson.Doxity) {
+ return doxityUtils.convertToDocAgnosticFormat(docObj as DoxityDocObj);
+ } else {
+ return typeDocUtils.convertToDocAgnosticFormat(docObj as TypeDocNode, this);
+ }
}
}
diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx
index 285471166..699bef7a8 100644
--- a/packages/website/ts/pages/documentation/documentation.tsx
+++ b/packages/website/ts/pages/documentation/documentation.tsx
@@ -1,11 +1,7 @@
-import findVersions = require('find-versions');
import * as _ from 'lodash';
import CircularProgress from 'material-ui/CircularProgress';
import * as React from 'react';
-import DocumentTitle = require('react-document-title');
import { scroller } from 'react-scroll';
-import semverSort = require('semver-sort');
-import { TopBar } from 'ts/components/top_bar/top_bar';
import { Badge } from 'ts/components/ui/badge';
import { Comment } from 'ts/pages/documentation/comment';
import { DocsInfo } from 'ts/pages/documentation/docs_info';
@@ -17,29 +13,27 @@ import { TypeDefinition } from 'ts/pages/documentation/type_definition';
import { MarkdownSection } from 'ts/pages/shared/markdown_section';
import { NestedSidebarMenu } from 'ts/pages/shared/nested_sidebar_menu';
import { SectionHeader } from 'ts/pages/shared/section_header';
-import { Dispatcher } from 'ts/redux/dispatcher';
import {
AddressByContractName,
DocAgnosticFormat,
DoxityDocObj,
EtherscanLinkSuffixes,
Event,
+ MenuSubsectionsBySection,
Networks,
Property,
SolidityMethod,
Styles,
+ SupportedDocJson,
TypeDefinitionByName,
TypescriptMethod,
} from 'ts/types';
import { colors } from 'ts/utils/colors';
import { configs } from 'ts/utils/configs';
import { constants } from 'ts/utils/constants';
-import { docUtils } from 'ts/utils/doc_utils';
-import { Translate } from 'ts/utils/translate';
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,
@@ -48,20 +42,18 @@ const networkNameToColor: { [network: string]: string } = {
[Networks.Rinkeby]: colors.darkYellow,
};
-export interface DocumentationAllProps {
- source: string;
+export interface DocumentationProps {
location: Location;
- dispatcher: Dispatcher;
docsVersion: string;
availableDocVersions: string[];
docsInfo: DocsInfo;
- translate: Translate;
-}
-
-interface DocumentationState {
docAgnosticFormat?: DocAgnosticFormat;
+ menuSubsectionsBySection: MenuSubsectionsBySection;
+ sourceUrl: string;
}
+interface DocumentationState {}
+
const styles: Styles = {
mainContainers: {
position: 'absolute',
@@ -81,57 +73,18 @@ const styles: Styles = {
},
};
-export class Documentation extends React.Component<DocumentationAllProps, DocumentationState> {
- private _isUnmounted: boolean;
- constructor(props: DocumentationAllProps) {
- super(props);
- this._isUnmounted = false;
- this.state = {
- docAgnosticFormat: undefined,
- };
- }
- public componentWillMount() {
- const pathName = this.props.location.pathname;
- const lastSegment = pathName.substr(pathName.lastIndexOf('/') + 1);
- const versions = findVersions(lastSegment);
- const preferredVersionIfExists = versions.length > 0 ? versions[0] : undefined;
- // tslint:disable-next-line:no-floating-promises
- this._fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists);
- }
- public componentWillUnmount() {
- this._isUnmounted = true;
+export class Documentation extends React.Component<DocumentationProps, DocumentationState> {
+ public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) {
+ if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) {
+ const hash = this.props.location.hash.slice(1);
+ utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID);
+ }
}
public render() {
- const menuSubsectionsBySection = _.isUndefined(this.state.docAgnosticFormat)
- ? {}
- : this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
return (
<div>
- <DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} />
- <TopBar
- blockchainIsLoaded={false}
- location={this.props.location}
- docsVersion={this.props.docsVersion}
- availableDocVersions={this.props.availableDocVersions}
- menu={this.props.docsInfo.getMenu(this.props.docsVersion)}
- menuSubsectionsBySection={menuSubsectionsBySection}
- docsInfo={this.props.docsInfo}
- translate={this.props.translate}
- />
- {_.isUndefined(this.state.docAgnosticFormat) ? (
- <div className="col col-12" style={styles.mainContainers}>
- <div
- className="relative sm-px2 sm-pt2 sm-m1"
- style={{ height: 122, top: '50%', transform: 'translateY(-50%)' }}
- >
- <div className="center pb2">
- <CircularProgress size={40} thickness={5} />
- </div>
- <div className="center pt2" style={{ paddingBottom: 11 }}>
- Loading documentation...
- </div>
- </div>
- </div>
+ {_.isUndefined(this.props.docAgnosticFormat) ? (
+ this._renderLoading()
) : (
<div style={{ width: '100%', height: '100%', backgroundColor: colors.gray40 }}>
<div
@@ -155,8 +108,7 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
versions={this.props.availableDocVersions}
title={this.props.docsInfo.displayName}
topLevelMenu={this.props.docsInfo.getMenu(this.props.docsVersion)}
- menuSubsectionsBySection={menuSubsectionsBySection}
- docPath={this.props.docsInfo.websitePath}
+ menuSubsectionsBySection={this.props.menuSubsectionsBySection}
/>
</div>
</div>
@@ -164,8 +116,12 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
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>
@@ -175,11 +131,28 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
</div>
);
}
+ private _renderLoading() {
+ return (
+ <div className="col col-12" style={styles.mainContainers}>
+ <div
+ className="relative sm-px2 sm-pt2 sm-m1"
+ style={{ height: 122, top: '50%', transform: 'translateY(-50%)' }}
+ >
+ <div className="center pb2">
+ <CircularProgress size={40} thickness={5} />
+ </div>
+ <div className="center pt2" style={{ paddingBottom: 11 }}>
+ Loading documentation...
+ </div>
+ </div>
+ </div>
+ );
+ }
private _renderDocumentation(): React.ReactNode {
const subMenus = _.values(this.props.docsInfo.getMenu());
const orderedSectionNames = _.flatten(subMenus);
- const typeDefinitionByName = this.props.docsInfo.getTypeDefinitionsByName(this.state.docAgnosticFormat);
+ const typeDefinitionByName = this.props.docsInfo.getTypeDefinitionsByName(this.props.docAgnosticFormat);
const renderedSections = _.map(orderedSectionNames, this._renderSection.bind(this, typeDefinitionByName));
return renderedSections;
@@ -196,7 +169,7 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
);
}
- const docSection = this.state.docAgnosticFormat[sectionName];
+ const docSection = this.props.docAgnosticFormat[sectionName];
if (_.isUndefined(docSection)) {
return null;
}
@@ -278,7 +251,13 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
);
}
private _renderNetworkBadgesIfExists(sectionName: string) {
- const networkToAddressByContractName = configs.CONTRACT_ADDRESS[this.props.docsVersion];
+ if (this.props.docsInfo.type !== SupportedDocJson.Doxity) {
+ return null;
+ }
+
+ const networkToAddressByContractName = this.props.docsInfo.contractsByVersionByNetworkId[
+ this.props.docsVersion
+ ];
const badges = _.map(
networkToAddressByContractName,
(addressByContractName: AddressByContractName, networkName: string) => {
@@ -326,8 +305,7 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
<SourceLink
version={this.props.docsVersion}
source={property.source}
- baseUrl={this.props.docsInfo.packageUrl}
- subPackageName={this.props.docsInfo.subPackageName}
+ sourceUrl={this.props.sourceUrl}
/>
)}
{property.comment && <Comment comment={property.comment} className="py2" />}
@@ -348,54 +326,8 @@ export class Documentation extends React.Component<DocumentationAllProps, Docume
typeDefinitionByName={typeDefinitionByName}
libraryVersion={this.props.docsVersion}
docsInfo={this.props.docsInfo}
+ sourceUrl={this.props.sourceUrl}
/>
);
}
- 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',
- });
- }
- private async _fetchJSONDocsFireAndForgetAsync(preferredVersionIfExists?: string): Promise<void> {
- const versionToFileName = await docUtils.getVersionToFileNameAsync(this.props.docsInfo.docsJsonRoot);
- const versions = _.keys(versionToFileName);
- this.props.dispatcher.updateAvailableDocVersions(versions);
- const sortedVersions = semverSort.desc(versions);
- const latestVersion = sortedVersions[0];
-
- let versionToFetch = latestVersion;
- if (!_.isUndefined(preferredVersionIfExists)) {
- const preferredVersionFileNameIfExists = versionToFileName[preferredVersionIfExists];
- if (!_.isUndefined(preferredVersionFileNameIfExists)) {
- versionToFetch = preferredVersionIfExists;
- }
- }
- this.props.dispatcher.updateCurrentDocsVersion(versionToFetch);
-
- const versionFileNameToFetch = versionToFileName[versionToFetch];
- const versionDocObj = await docUtils.getJSONDocFileAsync(
- versionFileNameToFetch,
- this.props.docsInfo.docsJsonRoot,
- );
- const docAgnosticFormat = this.props.docsInfo.convertToDocAgnosticFormat(versionDocObj as DoxityDocObj);
-
- if (!this._isUnmounted) {
- this.setState(
- {
- docAgnosticFormat,
- },
- () => {
- this._scrollToHash();
- },
- );
- }
- }
}
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/method_block.tsx b/packages/website/ts/pages/documentation/method_block.tsx
index 1bc6aa4f4..d2c96bf8c 100644
--- a/packages/website/ts/pages/documentation/method_block.tsx
+++ b/packages/website/ts/pages/documentation/method_block.tsx
@@ -15,6 +15,7 @@ interface MethodBlockProps {
libraryVersion: string;
typeDefinitionByName: TypeDefinitionByName;
docsInfo: DocsInfo;
+ sourceUrl: string;
}
interface MethodBlockState {
@@ -80,8 +81,7 @@ export class MethodBlock extends React.Component<MethodBlockProps, MethodBlockSt
<SourceLink
version={this.props.libraryVersion}
source={(method as TypescriptMethod).source}
- baseUrl={this.props.docsInfo.packageUrl}
- subPackageName={this.props.docsInfo.subPackageName}
+ sourceUrl={this.props.sourceUrl}
/>
)}
{method.comment && <Comment comment={method.comment} className="py2" />}
diff --git a/packages/website/ts/pages/documentation/source_link.tsx b/packages/website/ts/pages/documentation/source_link.tsx
index 6588ee39e..31f80aba3 100644
--- a/packages/website/ts/pages/documentation/source_link.tsx
+++ b/packages/website/ts/pages/documentation/source_link.tsx
@@ -5,22 +5,13 @@ import { colors } from 'ts/utils/colors';
interface SourceLinkProps {
source: Source;
- baseUrl: string;
+ sourceUrl: string;
version: string;
- subPackageName: string;
}
-const packagesWithNamespace = ['connect'];
-
export function SourceLink(props: SourceLinkProps) {
const src = props.source;
- const url = props.baseUrl;
- const pkg = props.subPackageName;
- let tagPrefix = pkg;
- if (_.includes(packagesWithNamespace, pkg)) {
- tagPrefix = `@0xproject/${pkg}`;
- }
- const sourceCodeUrl = `${url}/blob/${tagPrefix}%40${props.version}/packages/${pkg}/${src.fileName}#L${src.line}`;
+ const sourceCodeUrl = `${props.sourceUrl}/${src.fileName}#L${src.line}`;
return (
<div className="pt2" style={{ fontSize: 14 }}>
<a href={sourceCodeUrl} target="_blank" className="underline" style={{ color: colors.grey }}>
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 ba794ee9f..82a40eb7e 100644
--- a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx
+++ b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx
@@ -16,7 +16,6 @@ interface NestedSidebarMenuProps {
onMenuItemClick?: () => void;
selectedVersion?: string;
versions?: string[];
- docPath?: string;
}
interface NestedSidebarMenuState {}
@@ -69,13 +68,8 @@ export class NestedSidebarMenu extends React.Component<NestedSidebarMenuProps, N
<div>
{this._renderEmblem()}
{!_.isUndefined(this.props.versions) &&
- !_.isUndefined(this.props.selectedVersion) &&
- !_.isUndefined(this.props.docPath) && (
- <VersionDropDown
- selectedVersion={this.props.selectedVersion}
- versions={this.props.versions}
- docPath={this.props.docPath}
- />
+ !_.isUndefined(this.props.selectedVersion) && (
+ <VersionDropDown selectedVersion={this.props.selectedVersion} versions={this.props.versions} />
)}
<div className="pl1">{navigation}</div>
</div>
@@ -92,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 b922e1048..1b4dbb375 100644
--- a/packages/website/ts/pages/shared/version_drop_down.tsx
+++ b/packages/website/ts/pages/shared/version_drop_down.tsx
@@ -2,11 +2,11 @@ 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;
versions: string[];
- docPath: string;
}
interface VersionDropDownState {}
@@ -31,7 +31,15 @@ export class VersionDropDown extends React.Component<VersionDropDownProps, Versi
});
return items;
}
- private _updateSelectedVersion(e: any, index: number, value: string) {
- window.location.href = `${this.props.docPath}/${value}${window.location.hash}`;
+ private _updateSelectedVersion(e: any, index: number, semver: string) {
+ let path = window.location.pathname;
+ const lastChar = path[path.length - 1];
+ if (_.isFinite(_.parseInt(lastChar))) {
+ const pathSections = path.split('/');
+ pathSections.pop();
+ path = pathSections.join('/');
+ }
+ 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 f6413eec5..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[];
@@ -627,20 +627,39 @@ export interface SectionsMap {
[sectionName: string]: string;
}
+export enum DocPackages {
+ Connect = 'CONNECT',
+ ZeroExJs = 'ZERO_EX_JS',
+ SmartContracts = 'SMART_CONTRACTS',
+}
+
+export enum SupportedDocJson {
+ Doxity = 'DOXITY',
+ TypeDoc = 'TYPEDOC',
+}
+
+export interface ContractsByVersionByNetworkId {
+ [version: string]: {
+ [networkName: string]: {
+ [contractName: string]: string;
+ };
+ };
+}
+
export interface DocsInfoConfig {
+ id: string;
+ type: SupportedDocJson;
displayName: string;
packageUrl: string;
- websitePath: string;
- docsJsonRoot: string;
menu: DocsMenu;
sections: SectionsMap;
sectionNameToMarkdown: { [sectionName: string]: string };
visibleConstructors: string[];
- convertToDocAgnosticFormatFn: (docObj: DoxityDocObj | TypeDocNode, docsInfo?: any) => DocAgnosticFormat;
subPackageName?: string;
publicTypes?: string[];
sectionNameToModulePath?: { [sectionName: string]: string[] };
menuSubsectionToVersionWhenIntroduced?: { [sectionName: string]: string };
+ contractsByVersionByNetworkId?: ContractsByVersionByNetworkId;
}
export interface TimestampMsRange {
diff --git a/packages/website/ts/utils/configs.ts b/packages/website/ts/utils/configs.ts
index 8e359f8bd..388fc8530 100644
--- a/packages/website/ts/utils/configs.ts
+++ b/packages/website/ts/utils/configs.ts
@@ -1,12 +1,5 @@
import * as _ from 'lodash';
-import {
- ContractAddresses,
- Environments,
- Networks,
- OutdatedWrappedEtherByNetworkId,
- PublicNodeUrlsByNetworkId,
- SmartContractDocSections,
-} from 'ts/types';
+import { ContractAddresses, Environments, OutdatedWrappedEtherByNetworkId, PublicNodeUrlsByNetworkId } from 'ts/types';
const BASE_URL = window.location.origin;
const isDevelopment = _.includes(
@@ -19,34 +12,6 @@ export const configs = {
BACKEND_BASE_URL: 'https://website-api.0xproject.com',
BASE_URL,
BITLY_ACCESS_TOKEN: 'ffc4c1a31e5143848fb7c523b39f91b9b213d208',
- CONTRACT_ADDRESS: {
- '1.0.0': {
- [Networks.Mainnet]: {
- [SmartContractDocSections.Exchange]: '0x12459c951127e0c374ff9105dda097662a027093',
- [SmartContractDocSections.TokenTransferProxy]: '0x8da0d80f5007ef1e431dd2127178d224e32c2ef4',
- [SmartContractDocSections.ZRXToken]: '0xe41d2489571d322189246dafa5ebde1f4699f498',
- [SmartContractDocSections.TokenRegistry]: '0x926a74c5c36adf004c87399e65f75628b0f98d2c',
- },
- [Networks.Ropsten]: {
- [SmartContractDocSections.Exchange]: '0x479cc461fecd078f766ecc58533d6f69580cf3ac',
- [SmartContractDocSections.TokenTransferProxy]: '0x4e9aad8184de8833365fea970cd9149372fdf1e6',
- [SmartContractDocSections.ZRXToken]: '0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d',
- [SmartContractDocSections.TokenRegistry]: '0x6b1a50f0bb5a7995444bd3877b22dc89c62843ed',
- },
- [Networks.Kovan]: {
- [SmartContractDocSections.Exchange]: '0x90fe2af704b34e0224bf2299c838e04d4dcf1364',
- [SmartContractDocSections.TokenTransferProxy]: '0x087Eed4Bc1ee3DE49BeFbd66C662B434B15d49d4',
- [SmartContractDocSections.ZRXToken]: '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570',
- [SmartContractDocSections.TokenRegistry]: '0xf18e504561f4347bea557f3d4558f559dddbae7f',
- },
- [Networks.Rinkeby]: {
- [SmartContractDocSections.Exchange]: '0x1d16ef40fac01cec8adac2ac49427b9384192c05',
- [SmartContractDocSections.TokenTransferProxy]: '0xa8e9fa8f91e5ae138c74648c9c304f1c75003a8d',
- [SmartContractDocSections.ZRXToken]: '0x00f58d6d585f84b2d7267940cede30ce2fe6eae8',
- [SmartContractDocSections.TokenRegistry]: '0x4e9aad8184de8833365fea970cd9149372fdf1e6',
- },
- },
- } as ContractAddresses,
DEFAULT_DERIVATION_PATH: `44'/60'/0'`,
// WARNING: ZRX & WETH MUST always be default trackedTokens
DEFAULT_TRACKED_TOKEN_SYMBOLS: ['WETH', 'ZRX'],
@@ -129,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/constants.ts b/packages/website/ts/utils/constants.ts
index 6af821dbe..3476b7375 100644
--- a/packages/website/ts/utils/constants.ts
+++ b/packages/website/ts/utils/constants.ts
@@ -42,6 +42,7 @@ export const constants = {
PROVIDER_NAME_GENERIC: 'Injected Web3',
PROVIDER_NAME_PUBLIC: '0x Public',
ROLLBAR_ACCESS_TOKEN: 'a6619002b51c4464928201e6ea94de65',
+ S3_BUCKET_ROOT: 'https://s3.amazonaws.com',
SUCCESS_STATUS: 200,
UNAVAILABLE_STATUS: 503,
TAKER_FEE: new BigNumber(0),
diff --git a/packages/website/ts/utils/typedoc_utils.ts b/packages/website/ts/utils/typedoc_utils.ts
index 11ec8da58..ce7df4dbb 100644
--- a/packages/website/ts/utils/typedoc_utils.ts
+++ b/packages/website/ts/utils/typedoc_utils.ts
@@ -4,6 +4,7 @@ import {
CustomType,
CustomTypeChild,
DocAgnosticFormat,
+ DocPackages,
DocSection,
IndexSignature,
KindString,
@@ -40,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());
@@ -62,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
@@ -76,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;
}
@@ -108,7 +119,7 @@ export const typeDocUtils = {
isConstructor,
docsInfo.sections,
sectionName,
- docsInfo.subPackageName,
+ docsInfo.id,
);
docSection.constructors.push(constructor);
break;
@@ -121,7 +132,7 @@ export const typeDocUtils = {
isConstructor,
docsInfo.sections,
sectionName,
- docsInfo.subPackageName,
+ docsInfo.id,
);
docSection.methods.push(method);
}
@@ -133,7 +144,7 @@ export const typeDocUtils = {
entity,
docsInfo.sections,
sectionName,
- docsInfo.subPackageName,
+ docsInfo.id,
);
docSection.properties.push(property);
}
@@ -149,7 +160,7 @@ export const typeDocUtils = {
entity,
docsInfo.sections,
sectionName,
- docsInfo.subPackageName,
+ docsInfo.id,
);
docSection.types.push(customType);
}
@@ -161,21 +172,24 @@ export const typeDocUtils = {
});
return docSection;
},
- _convertCustomType(
- entity: TypeDocNode,
- sections: SectionsMap,
- sectionName: string,
- subPackageName: string,
- ): CustomType {
+ _convertCustomType(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): CustomType {
const typeIfExists = !_.isUndefined(entity.type)
- ? typeDocUtils._convertType(entity.type, sections, sectionName, subPackageName)
+ ? typeDocUtils._convertType(entity.type, sections, sectionName, docId)
: undefined;
const isConstructor = false;
const methodIfExists = !_.isUndefined(entity.declaration)
- ? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, subPackageName)
+ ? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId)
: undefined;
- const indexSignatureIfExists = !_.isUndefined(entity.indexSignature)
- ? typeDocUtils._convertIndexSignature(entity.indexSignature[0], sections, sectionName, subPackageName)
+ 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)
@@ -185,7 +199,7 @@ export const typeDocUtils = {
const childrenIfExist = !_.isUndefined(entity.children)
? _.map(entity.children, (child: TypeDocNode) => {
const childTypeIfExists = !_.isUndefined(child.type)
- ? typeDocUtils._convertType(child.type, sections, sectionName, subPackageName)
+ ? typeDocUtils._convertType(child.type, sections, sectionName, docId)
: undefined;
const c: CustomTypeChild = {
name: child.name,
@@ -212,27 +226,22 @@ export const typeDocUtils = {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
- subPackageName: string,
+ docId: string,
): IndexSignature {
const key = entity.parameters[0];
const indexSignature = {
keyName: key.name,
- keyType: typeDocUtils._convertType(key.type, sections, sectionName, subPackageName),
+ keyType: typeDocUtils._convertType(key.type, sections, sectionName, docId),
valueName: entity.type.name,
};
return indexSignature;
},
- _convertProperty(
- entity: TypeDocNode,
- sections: SectionsMap,
- sectionName: string,
- subPackageName: string,
- ): Property {
+ _convertProperty(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): Property {
const source = entity.sources[0];
const commentIfExists = !_.isUndefined(entity.comment) ? entity.comment.shortText : undefined;
const property = {
name: entity.name,
- type: typeDocUtils._convertType(entity.type, sections, sectionName, subPackageName),
+ type: typeDocUtils._convertType(entity.type, sections, sectionName, docId),
source: {
fileName: source.fileName,
line: source.line,
@@ -246,7 +255,7 @@ export const typeDocUtils = {
isConstructor: boolean,
sections: SectionsMap,
sectionName: string,
- subPackageName: string,
+ docId: string,
): TypescriptMethod {
const signature = entity.signatures[0];
const source = entity.sources[0];
@@ -258,7 +267,7 @@ export const typeDocUtils = {
let callPath;
if (isConstructor || entity.name === '__type') {
callPath = '';
- } else if (subPackageName === '0x.js') {
+ } else if (docId === DocPackages.ZeroExJs) {
const topLevelInterface = isStatic ? 'ZeroEx.' : 'zeroEx.';
callPath =
!_.isUndefined(sections.zeroEx) && sectionName !== sections.zeroEx
@@ -269,12 +278,12 @@ export const typeDocUtils = {
}
const parameters = _.map(signature.parameters, param => {
- return typeDocUtils._convertParameter(param, sections, sectionName, subPackageName);
+ return typeDocUtils._convertParameter(param, sections, sectionName, docId);
});
- const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, subPackageName);
+ const returnType = typeDocUtils._convertType(signature.type, sections, sectionName, docId);
const typeParameter = _.isUndefined(signature.typeParameter)
? undefined
- : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, subPackageName);
+ : typeDocUtils._convertTypeParameter(signature.typeParameter[0], sections, sectionName, docId);
const method = {
isConstructor,
@@ -297,21 +306,16 @@ export const typeDocUtils = {
entity: TypeDocNode,
sections: SectionsMap,
sectionName: string,
- subPackageName: string,
+ docId: string,
): TypeParameter {
- const type = typeDocUtils._convertType(entity.type, sections, sectionName, subPackageName);
+ const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId);
const parameter = {
name: entity.name,
type,
};
return parameter;
},
- _convertParameter(
- entity: TypeDocNode,
- sections: SectionsMap,
- sectionName: string,
- subPackageName: string,
- ): Parameter {
+ _convertParameter(entity: TypeDocNode, sections: SectionsMap, sectionName: string, docId: string): Parameter {
let comment = '<No comment>';
if (entity.comment && entity.comment.shortText) {
comment = entity.comment.shortText;
@@ -321,7 +325,7 @@ export const typeDocUtils = {
const isOptional = !_.isUndefined(entity.flags.isOptional) ? entity.flags.isOptional : false;
- const type = typeDocUtils._convertType(entity.type, sections, sectionName, subPackageName);
+ const type = typeDocUtils._convertType(entity.type, sections, sectionName, docId);
const parameter = {
name: entity.name,
@@ -331,17 +335,17 @@ export const typeDocUtils = {
};
return parameter;
},
- _convertType(entity: TypeDocType, sections: SectionsMap, sectionName: string, subPackageName: string): Type {
+ _convertType(entity: TypeDocType, sections: SectionsMap, sectionName: string, docId: string): Type {
const typeArguments = _.map(entity.typeArguments, typeArgument => {
- return typeDocUtils._convertType(typeArgument, sections, sectionName, subPackageName);
+ return typeDocUtils._convertType(typeArgument, sections, sectionName, docId);
});
const types = _.map(entity.types, t => {
- return typeDocUtils._convertType(t, sections, sectionName, subPackageName);
+ return typeDocUtils._convertType(t, sections, sectionName, docId);
});
const isConstructor = false;
const methodIfExists = !_.isUndefined(entity.declaration)
- ? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, subPackageName)
+ ? typeDocUtils._convertMethod(entity.declaration, isConstructor, sections, sectionName, docId)
: undefined;
const elementTypeIfExists = !_.isUndefined(entity.elementType)
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();
+ });
+ },
};
diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json
index 38b177d0b..99f465bc2 100644
--- a/packages/website/tsconfig.json
+++ b/packages/website/tsconfig.json
@@ -13,5 +13,9 @@
"*": ["node_modules/@types/*", "*"]
}
},
- "include": ["./ts/**/*", "../../node_modules/web3-typescript-typings/index.d.ts"]
+ "include": [
+ "./ts/**/*",
+ "../../node_modules/web3-typescript-typings/index.d.ts",
+ "../../node_modules/ethers-typescript-typings/index.d.ts"
+ ]
}