diff --git a/.circleci/config.yml b/.circleci/config.yml index f64017b564..d0115c47b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -43,10 +43,13 @@ jobs: - repo-{{ .Environment.CIRCLE_SHA1 }} - run: yarn wsrun test:circleci @0x/contracts-multisig - run: yarn wsrun test:circleci @0x/contracts-utils - - run: yarn wsrun test:circleci @0x/contracts-libs - - run: yarn wsrun test:circleci @0x/contracts-tokens + - run: yarn wsrun test:circleci @0x/contracts-exchange-libs + - run: yarn wsrun test:circleci @0x/contracts-erc20 + - run: yarn wsrun test:circleci @0x/contracts-erc721 - run: yarn wsrun test:circleci @0x/contracts-extensions - - run: yarn wsrun test:circleci @0x/contracts-protocol + - run: yarn wsrun test:circleci @0x/contracts-asset-proxy + - run: yarn wsrun test:circleci @0x/contracts-exchange + - run: yarn wsrun test:circleci @0x/contracts-exchange-forwarder test-contracts-geth: docker: - image: circleci/node:9-browsers @@ -59,11 +62,14 @@ jobs: # HACK(albrow): we need to sleep 10 seconds to ensure the devnet is # initialized - run: sleep 10 && TEST_PROVIDER=geth yarn wsrun test @0x/contracts-multisig - - run: TEST_PROVIDER=geth yarn wsrun test @0x/contracts-utils - - run: TEST_PROVIDER=geth yarn wsrun test @0x/contracts-libs - - run: TEST_PROVIDER=geth yarn wsrun test @0x/contracts-tokens - - run: TEST_PROVIDER=geth yarn wsrun test @0x/contracts-extensions - - run: TEST_PROVIDER=geth yarn wsrun test @0x/contracts-protocol + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-utils + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-exchange-libs + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-erc20 + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-erc721 + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-extensions + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-asset-proxy + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-exchange + - run: TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-exchange-forwarder test-publish: resource_class: medium+ docker: diff --git a/.gitignore b/.gitignore index 0210edc4f9..f055a93981 100644 --- a/.gitignore +++ b/.gitignore @@ -83,27 +83,29 @@ packages/react-docs/example/public/bundle* packages/testnet-faucets/server/ # generated contract artifacts/ -contracts/protocol/generated-artifacts/ +contracts/exchange/generated-artifacts/ +contracts/asset-proxy/generated-artifacts/ contracts/multisig/generated-artifacts/ contracts/utils/generated-artifacts/ -contracts/libs/generated-artifacts/ -contracts/interfaces/generated-artifacts/ -contracts/tokens/generated-artifacts/ -contracts/examples/generated-artifacts/ +contracts/exchange-libs/generated-artifacts/ +contracts/erc20/generated-artifacts/ +contracts/erc721/generated-artifacts/ contracts/extensions/generated-artifacts/ +contracts/exchange-forwarder/generated-artifacts/ packages/sol-tracing-utils/test/fixtures/artifacts/ packages/metacoin/artifacts/ # generated contract wrappers packages/abi-gen-wrappers/wrappers -contracts/protocol/generated-wrappers/ +contracts/exchange/generated-wrappers/ +contracts/asset-proxy/generated-wrappers/ contracts/multisig/generated-wrappers/ contracts/utils/generated-wrappers/ -contracts/libs/generated-wrappers/ -contracts/interfaces/generated-wrappers/ -contracts/tokens/generated-wrappers/ -contracts/examples/generated-wrappers/ +contracts/exchange-libs/generated-wrappers/ +contracts/erc20/generated-wrappers/ +contracts/erc721/generated-wrappers/ contracts/extensions/generated-wrappers/ +contracts/exchange-forwarder/generated-wrappers/ packages/metacoin/src/contract_wrappers # solc-bin in sol-compiler diff --git a/.prettierignore b/.prettierignore index a490918168..a72b5ed2a6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,21 +1,23 @@ lib .nyc_output -/contracts/protocol/generated-wrappers -/contracts/protocol/generated-artifacts +/contracts/exchange/generated-wrappers +/contracts/exchange/generated-artifacts +/contracts/asset-proxy/generated-wrappers +/contracts/asset-proxy/generated-artifacts /contracts/multisig/generated-wrappers /contracts/multisig/generated-artifacts /contracts/utils/generated-wrappers /contracts/utils/generated-artifacts -/contracts/libs/generated-wrappers -/contracts/libs/generated-artifacts -/contracts/interfaces/generated-wrappers -/contracts/interfaces/generated-artifacts -/contracts/tokens/generated-wrappers -/contracts/tokens/generated-artifacts -/contracts/examples/generated-wrappers -/contracts/examples/generated-artifacts +/contracts/exchange-libs/generated-wrappers +/contracts/exchange-libs/generated-artifacts +/contracts/erc20/generated-wrappers +/contracts/erc20/generated-artifacts +/contracts/erc721/generated-wrappers +/contracts/erc721/generated-artifacts /contracts/extensions/generated-wrappers /contracts/extensions/generated-artifacts +/contracts/exchange-forwarder/generated-wrappers +/contracts/exchange-forwarder/generated-artifacts /packages/abi-gen-wrappers/src/generated-wrappers /packages/contract-artifacts/artifacts /python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts diff --git a/README.md b/README.md index 12f9df7f88..b542124c01 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,21 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr | [`0x-order-utils`](/python-packages/order_utils) | [![PyPI](https://img.shields.io/pypi/v/0x-order-utils.svg)](https://pypi.org/project/0x-order-utils/) | A set of utilities for generating, parsing, signing and validating 0x orders | | [`0x-sra-client`](/python-packages/sra_client) | [![PyPI](https://img.shields.io/pypi/v/0x-sra-client.svg)](https://pypi.org/project/0x-sra-client/) | A Python client for interacting with servers conforming to the Standard Relayer API specification | +### Solidity Packages + +| Package | Version | Description | +| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [`@0x/contracts-asset-proxy`](/contracts/asset-proxy) | [![npm](https://img.shields.io/npm/v/@0x/contracts-asset-proxy.svg)](https://www.npmjs.com/package/@0x/contracts-asset-proxy) | [`AssetProxy`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#assetproxy) contracts used within the protocol | +| [`@0x/contracts-erc20`](/contracts/erc20) | [![npm](https://img.shields.io/npm/v/@0x/contracts-erc20.svg)](https://www.npmjs.com/package/@0x/contracts-erc20) | Implementations of various ERC20 tokens | +| [`@0x/contracts-erc721`](/contracts/erc721) | [![npm](https://img.shields.io/npm/v/@0x/contracts-erc721.svg)](https://www.npmjs.com/package/@0x/contracts-erc721) | Implementations of various ERC721 tokens | +| [`@0x/contracts-exchange`](/contracts/exchange) | [![npm](https://img.shields.io/npm/v/@0x/contracts-exchange.svg)](https://www.npmjs.com/package/@0x/contracts-exchange) | The [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange) contract used for settling trades within the protocol | +| [`@0x/contracts-exchange-forwarder`](/contracts/exchange-forwarder) | [![npm](https://img.shields.io/npm/v/@0x/contracts-exchange-forwarder.svg)](https://www.npmjs.com/package/@0x/contracts-exchange-forwarder) | A [`Forwarder`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/forwarder-specification.md) contract used to simplify UX for interacting with the protocol | +| [`@0x/contracts-exchange-libs`](/contracts/exchange-libs) | [![npm](https://img.shields.io/npm/v/@0x/contracts-exchange-libs.svg)](https://www.npmjs.com/package/@0x/contracts-exchange-libs) | Protocol specific Llbraries used within the [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange) contract | +| [`@0x/contracts-extensions`](/contracts/extensions) | [![npm](https://img.shields.io/npm/v/@0x/contracts-extensions.svg)](https://www.npmjs.com/package/@0x/contracts-extensions) | Contracts that interact with and extend the functionality of the core protocol | +| [`@0x/contracts-multisig`](/contracts/multisig) | [![npm](https://img.shields.io/npm/v/@0x/contracts-multisig.svg)](https://www.npmjs.com/package/@0x/contracts-multisig) | Various implementations of multisignature wallets, including the [`AssetProxyOwner`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#assetproxyowner) contract that has permissions to upgrade the protocol | +| [`@0x/contracts-test-utils`](/contracts/test-utils) | [![npm](https://img.shields.io/npm/v/@0x/contracts-test-utils.svg)](https://www.npmjs.com/package/@0x/contracts-test-utils) | Typescript/Javascript shared utilities used for testing contracts | +| [`@0x/contracts-utils`](/contracts/utils) | [![npm](https://img.shields.io/npm/v/@0x/contracts-utils.svg)](https://www.npmjs.com/package/@0x/contracts-utils) | Generic libraries and utilities used throughout all of the contracts | + ### Typescript/Javascript Packages #### 0x-specific packages @@ -84,7 +99,6 @@ Visit our [developer portal](https://0xproject.com/docs/order-utils) for a compr | Package | Description | | -------------------------------------------------- | -------------------------------------------------------------------------------- | -| [`@0x/contracts`](/contracts/core) | 0x protocol solidity smart contracts & tests | | [`@0x/instant`](/packages/instant) | A free and flexible way to offer simple crypto purchasing in any app or website. | | [`@0x/testnet-faucets`](/packages/testnet-faucets) | A faucet micro-service that dispenses test ERC20 tokens or Ether | | [`@0x/website`](/packages/website) | 0x website | @@ -134,6 +148,12 @@ To build a specific package: PKG=@0x/web3-wrapper yarn build ``` +To build all contracts packages: + +```bash +yarn build:contracts +``` + ### Watch To re-build all packages on change: @@ -206,3 +226,9 @@ Run a specific package's test: ```bash PKG=@0x/web3-wrapper yarn test ``` + +Run all contracts packages tests: + +```bash +yarn test:contracts +``` diff --git a/contracts/asset-proxy/CHANGELOG.json b/contracts/asset-proxy/CHANGELOG.json new file mode 100644 index 0000000000..9307f7da49 --- /dev/null +++ b/contracts/asset-proxy/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Move all AssetProxy contracts out of contracts-protocol to new package", + "pr": 1539 + } + ] + } +] diff --git a/contracts/protocol/CHANGELOG.md b/contracts/asset-proxy/CHANGELOG.md similarity index 100% rename from contracts/protocol/CHANGELOG.md rename to contracts/asset-proxy/CHANGELOG.md diff --git a/contracts/asset-proxy/DEPLOYS.json b/contracts/asset-proxy/DEPLOYS.json new file mode 100644 index 0000000000..0f25da1c3a --- /dev/null +++ b/contracts/asset-proxy/DEPLOYS.json @@ -0,0 +1,47 @@ +[ + { + "name": "MultiAssetProxy", + "version": "1.0.0", + "changes": [ + { + "note": "Add MultiAssetProxy implementation", + "pr": 1224, + "networks": { + "3": "0xab8fbd189c569ccdee3a4d929bb7f557be4028f6", + "4": "0xb34cde0ad3a83d04abebc0b66e75196f22216621", + "42": "0xf6313a772c222f51c28f2304c0703b8cf5428fd8" + } + } + ] + }, + { + "name": "ERC20Proxy", + "version": "1.0.0", + "changes": [ + { + "note": "protocol v2 deploy", + "networks": { + "1": "0x2240dab907db71e64d3e0dba4800c83b5c502d4e", + "3": "0xb1408f4c245a23c31b98d2c626777d4c0d766caa", + "4": "0x3e809c563c15a295e832e37053798ddc8d6c8dab", + "42": "0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e" + } + } + ] + }, + { + "name": "ERC721Proxy", + "version": "1.0.0", + "changes": [ + { + "note": "protocol v2 deploy", + "networks": { + "1": "0x208e41fb445f1bb1b6780d58356e81405f3e6127", + "3": "0xe654aac058bfbf9f83fcaee7793311dd82f6ddb4", + "4": "0x8e1ff02637cb5e39f2fa36c14706aa348b065b09", + "42": "0x2a9127c745688a165106c11cd4d647d2220af821" + } + } + ] + } +] diff --git a/contracts/protocol/README.md b/contracts/asset-proxy/README.md similarity index 59% rename from contracts/protocol/README.md rename to contracts/asset-proxy/README.md index dc1f32c986..48a5b20a53 100644 --- a/contracts/protocol/README.md +++ b/contracts/asset-proxy/README.md @@ -1,15 +1,14 @@ -## Contracts +## AssetProxy -Smart contracts that implement the 0x protocol. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [CHANGELOG](./CHANGELOG.json) of this package. +This package contains the implementations of all of the [`AssetProxy`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#assetproxy) contracts available within the 0x protocol. These contracts are responsible for decoding the `assetData` sent to them and performing the actual transfer of assets. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contracts that make up and interact with version 2.0.0 of the protocol can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [protocol](./contracts/protocol) - - This directory contains the contracts that make up version 2.0.0. A full specification can be found [here](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md). -- [test](./contracts/test) - - This directory contains mocks and other contracts that are used solely for testing contracts within the other directories. +```bash +npm install @0x/contracts-asset-proxy --save +``` ## Bug bounty @@ -42,13 +41,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-protocol yarn build +PKG=@0x/contracts-asset-proxy yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-protocol yarn watch +PKG=@0x/contracts-asset-proxy yarn watch ``` ### Clean diff --git a/contracts/protocol/compiler.json b/contracts/asset-proxy/compiler.json similarity index 72% rename from contracts/protocol/compiler.json rename to contracts/asset-proxy/compiler.json index 10e5bb0a1c..6a077e965f 100644 --- a/contracts/protocol/compiler.json +++ b/contracts/asset-proxy/compiler.json @@ -19,16 +19,12 @@ } }, "contracts": [ - "AssetProxyOwner", + "IAssetData", + "IAssetProxy", + "IAuthorizable", "ERC20Proxy", "ERC721Proxy", - "Exchange", "MixinAuthorizable", - "MultiAssetProxy", - "TestAssetProxyOwner", - "TestAssetProxyDispatcher", - "TestExchangeInternals", - "TestSignatureValidator", - "TestStaticCallReceiver" + "MultiAssetProxy" ] } diff --git a/contracts/protocol/contracts/protocol/AssetProxy/ERC20Proxy.sol b/contracts/asset-proxy/contracts/src/ERC20Proxy.sol similarity index 100% rename from contracts/protocol/contracts/protocol/AssetProxy/ERC20Proxy.sol rename to contracts/asset-proxy/contracts/src/ERC20Proxy.sol diff --git a/contracts/protocol/contracts/protocol/AssetProxy/ERC721Proxy.sol b/contracts/asset-proxy/contracts/src/ERC721Proxy.sol similarity index 100% rename from contracts/protocol/contracts/protocol/AssetProxy/ERC721Proxy.sol rename to contracts/asset-proxy/contracts/src/ERC721Proxy.sol diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol b/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol similarity index 98% rename from contracts/protocol/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol rename to contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol index 2922a8c1a5..36c287ea34 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinAssetProxyDispatcher.sol +++ b/contracts/asset-proxy/contracts/src/MixinAssetProxyDispatcher.sol @@ -18,9 +18,9 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "./mixins/MAssetProxyDispatcher.sol"; -import "@0x/contracts-interfaces/contracts/protocol/AssetProxy/IAssetProxy.sol"; +import "./interfaces/IAssetProxy.sol"; contract MixinAssetProxyDispatcher is diff --git a/contracts/protocol/contracts/protocol/AssetProxy/MixinAuthorizable.sol b/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol similarity index 97% rename from contracts/protocol/contracts/protocol/AssetProxy/MixinAuthorizable.sol rename to contracts/asset-proxy/contracts/src/MixinAuthorizable.sol index b610ef709c..ace820625c 100644 --- a/contracts/protocol/contracts/protocol/AssetProxy/MixinAuthorizable.sol +++ b/contracts/asset-proxy/contracts/src/MixinAuthorizable.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "./mixins/MAuthorizable.sol"; diff --git a/contracts/protocol/contracts/protocol/AssetProxy/MultiAssetProxy.sol b/contracts/asset-proxy/contracts/src/MultiAssetProxy.sol similarity index 99% rename from contracts/protocol/contracts/protocol/AssetProxy/MultiAssetProxy.sol rename to contracts/asset-proxy/contracts/src/MultiAssetProxy.sol index 5f559163ce..0b2cb41348 100644 --- a/contracts/protocol/contracts/protocol/AssetProxy/MultiAssetProxy.sol +++ b/contracts/asset-proxy/contracts/src/MultiAssetProxy.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../Exchange/MixinAssetProxyDispatcher.sol"; +import "./MixinAssetProxyDispatcher.sol"; import "./MixinAuthorizable.sol"; diff --git a/contracts/interfaces/contracts/protocol/AssetProxy/IAssetData.sol b/contracts/asset-proxy/contracts/src/interfaces/IAssetData.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/AssetProxy/IAssetData.sol rename to contracts/asset-proxy/contracts/src/interfaces/IAssetData.sol diff --git a/contracts/interfaces/contracts/protocol/AssetProxy/IAssetProxy.sol b/contracts/asset-proxy/contracts/src/interfaces/IAssetProxy.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/AssetProxy/IAssetProxy.sol rename to contracts/asset-proxy/contracts/src/interfaces/IAssetProxy.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/IAssetProxyDispatcher.sol b/contracts/asset-proxy/contracts/src/interfaces/IAssetProxyDispatcher.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/IAssetProxyDispatcher.sol rename to contracts/asset-proxy/contracts/src/interfaces/IAssetProxyDispatcher.sol diff --git a/contracts/interfaces/contracts/protocol/AssetProxy/IAuthorizable.sol b/contracts/asset-proxy/contracts/src/interfaces/IAuthorizable.sol similarity index 95% rename from contracts/interfaces/contracts/protocol/AssetProxy/IAuthorizable.sol rename to contracts/asset-proxy/contracts/src/interfaces/IAuthorizable.sol index 2021739985..0df6547117 100644 --- a/contracts/interfaces/contracts/protocol/AssetProxy/IAuthorizable.sol +++ b/contracts/asset-proxy/contracts/src/interfaces/IAuthorizable.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/Ownable/IOwnable.sol"; +import "@0x/contracts-utils/contracts/src/interfaces/IOwnable.sol"; contract IAuthorizable is diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MAssetProxyDispatcher.sol b/contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol similarity index 93% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MAssetProxyDispatcher.sol rename to contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol index 05c2c4c0be..0ae555ddad 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MAssetProxyDispatcher.sol +++ b/contracts/asset-proxy/contracts/src/mixins/MAssetProxyDispatcher.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IAssetProxyDispatcher.sol"; +import "../interfaces/IAssetProxyDispatcher.sol"; contract MAssetProxyDispatcher is diff --git a/contracts/protocol/contracts/protocol/AssetProxy/mixins/MAuthorizable.sol b/contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol similarity index 93% rename from contracts/protocol/contracts/protocol/AssetProxy/mixins/MAuthorizable.sol rename to contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol index 6c3f705008..c9c07e788b 100644 --- a/contracts/protocol/contracts/protocol/AssetProxy/mixins/MAuthorizable.sol +++ b/contracts/asset-proxy/contracts/src/mixins/MAuthorizable.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/AssetProxy/IAuthorizable.sol"; +import "../interfaces/IAuthorizable.sol"; contract MAuthorizable is diff --git a/contracts/asset-proxy/package.json b/contracts/asset-proxy/package.json new file mode 100644 index 0000000000..6d4ba8b8bf --- /dev/null +++ b/contracts/asset-proxy/package.json @@ -0,0 +1,82 @@ +{ + "name": "@0x/contracts-asset-proxy", + "version": "1.0.0", + "engines": { + "node": ">=6.12" + }, + "description": "Smart contract components of 0x protocol", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "yarn pre_build && tsc -b", + "build:ci": "yarn build", + "pre_build": "run-s compile generate_contract_wrappers", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s build test", + "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", + "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", + "compile": "sol-compiler", + "watch": "sol-compiler -w", + "clean": "shx rm -rf lib generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "coverage:report:text": "istanbul report text", + "coverage:report:html": "istanbul report html && open coverage/index.html", + "profiler:report:html": "istanbul report html && open coverage/index.html", + "coverage:report:lcov": "istanbul report lcov", + "test:circleci": "yarn test", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" + }, + "config": { + "abis": "generated-artifacts/@(ERC20Proxy|ERC721Proxy|IAssetData|IAssetProxy|IAuthorizable|MixinAuthorizable|MultiAssetProxy).json" + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md", + "devDependencies": { + "@0x/abi-gen": "^1.0.22", + "@0x/dev-utils": "^1.0.24", + "@0x/sol-compiler": "^2.0.2", + "@0x/tslint-config": "^2.0.2", + "@types/lodash": "4.14.104", + "@types/node": "*", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^3.0.0", + "dirty-chai": "^2.0.1", + "make-promises-safe": "^1.1.0", + "mocha": "^4.1.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solhint": "^1.4.1", + "tslint": "5.11.0", + "typescript": "3.0.1" + }, + "dependencies": { + "@0x/base-contract": "^3.0.13", + "@0x/contracts-test-utils": "^2.0.1", + "@0x/contracts-erc20": "^1.0.0", + "@0x/contracts-erc721": "^1.0.0", + "@0x/contracts-utils": "^3.0.0", + "@0x/order-utils": "^3.1.2", + "@0x/types": "^1.5.2", + "@0x/typescript-typings": "^3.0.8", + "@0x/utils": "^3.0.1", + "@0x/web3-wrapper": "^3.2.4", + "ethereum-types": "^1.1.6", + "lodash": "^4.17.5" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/contracts/asset-proxy/src/artifacts/index.ts b/contracts/asset-proxy/src/artifacts/index.ts new file mode 100644 index 0000000000..7f30608158 --- /dev/null +++ b/contracts/asset-proxy/src/artifacts/index.ts @@ -0,0 +1,19 @@ +import { ContractArtifact } from 'ethereum-types'; + +import * as ERC20Proxy from '../../generated-artifacts/ERC20Proxy.json'; +import * as ERC721Proxy from '../../generated-artifacts/ERC721Proxy.json'; +import * as IAssetData from '../../generated-artifacts/IAssetData.json'; +import * as IAssetProxy from '../../generated-artifacts/IAssetProxy.json'; +import * as IAuthorizable from '../../generated-artifacts/IAuthorizable.json'; +import * as MixinAuthorizable from '../../generated-artifacts/MixinAuthorizable.json'; +import * as MultiAssetProxy from '../../generated-artifacts/MultiAssetProxy.json'; + +export const artifacts = { + IAuthorizable: IAuthorizable as ContractArtifact, + IAssetData: IAssetData as ContractArtifact, + IAssetProxy: IAssetProxy as ContractArtifact, + ERC20Proxy: ERC20Proxy as ContractArtifact, + ERC721Proxy: ERC721Proxy as ContractArtifact, + MixinAuthorizable: MixinAuthorizable as ContractArtifact, + MultiAssetProxy: MultiAssetProxy as ContractArtifact, +}; diff --git a/contracts/protocol/src/index.ts b/contracts/asset-proxy/src/index.ts similarity index 100% rename from contracts/protocol/src/index.ts rename to contracts/asset-proxy/src/index.ts diff --git a/contracts/asset-proxy/src/wrappers/index.ts b/contracts/asset-proxy/src/wrappers/index.ts new file mode 100644 index 0000000000..6aecbc086f --- /dev/null +++ b/contracts/asset-proxy/src/wrappers/index.ts @@ -0,0 +1,7 @@ +export * from '../../generated-wrappers/i_asset_data'; +export * from '../../generated-wrappers/i_asset_proxy'; +export * from '../../generated-wrappers/erc20_proxy'; +export * from '../../generated-wrappers/erc721_proxy'; +export * from '../../generated-wrappers/mixin_authorizable'; +export * from '../../generated-wrappers/multi_asset_proxy'; +export * from '../../generated-wrappers/i_authorizable'; diff --git a/contracts/protocol/test/asset_proxy/authorizable.ts b/contracts/asset-proxy/test/authorizable.ts similarity index 98% rename from contracts/protocol/test/asset_proxy/authorizable.ts rename to contracts/asset-proxy/test/authorizable.ts index 853d18be0d..0871212358 100644 --- a/contracts/protocol/test/asset_proxy/authorizable.ts +++ b/contracts/asset-proxy/test/authorizable.ts @@ -12,8 +12,7 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { MixinAuthorizableContract } from '../../generated-wrappers/mixin_authorizable'; -import { artifacts } from '../../src/artifacts'; +import { artifacts, MixinAuthorizableContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/libs/test/global_hooks.ts b/contracts/asset-proxy/test/global_hooks.ts similarity index 100% rename from contracts/libs/test/global_hooks.ts rename to contracts/asset-proxy/test/global_hooks.ts diff --git a/contracts/protocol/test/asset_proxy/proxies.ts b/contracts/asset-proxy/test/proxies.ts similarity index 98% rename from contracts/protocol/test/asset_proxy/proxies.ts rename to contracts/asset-proxy/test/proxies.ts index c34be9c6a2..7977871358 100644 --- a/contracts/protocol/test/asset_proxy/proxies.ts +++ b/contracts/asset-proxy/test/proxies.ts @@ -1,4 +1,15 @@ -import { artifacts as interfacesArtifacts, IAssetDataContract, IAssetProxyContract } from '@0x/contracts-interfaces'; +import { + artifacts as erc20Artifacts, + DummyERC20TokenContract, + DummyERC20TokenTransferEventArgs, + DummyMultipleReturnERC20TokenContract, + DummyNoReturnERC20TokenContract, +} from '@0x/contracts-erc20'; +import { + artifacts as erc721Artifacts, + DummyERC721ReceiverContract, + DummyERC721TokenContract, +} from '@0x/contracts-erc721'; import { chaiSetup, constants, @@ -9,15 +20,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokensArtifacts, - DummyERC20TokenContract, - DummyERC20TokenTransferEventArgs, - DummyERC721ReceiverContract, - DummyERC721TokenContract, - DummyMultipleReturnERC20TokenContract, - DummyNoReturnERC20TokenContract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason } from '@0x/types'; @@ -26,23 +28,27 @@ import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy'; -import { MultiAssetProxyContract } from '../../generated-wrappers/multi_asset_proxy'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ERC721Wrapper } from '../utils/erc721_wrapper'; +import { + artifacts, + ERC20ProxyContract, + ERC20Wrapper, + ERC721ProxyContract, + ERC721Wrapper, + IAssetDataContract, + IAssetProxyContract, + MultiAssetProxyContract, +} from '../src'; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const assetProxyInterface = new IAssetProxyContract( - interfacesArtifacts.IAssetProxy.compilerOutput.abi, + artifacts.IAssetProxy.compilerOutput.abi, constants.NULL_ADDRESS, provider, ); const assetDataInterface = new IAssetDataContract( - interfacesArtifacts.IAssetData.compilerOutput.abi, + artifacts.IAssetData.compilerOutput.abi, constants.NULL_ADDRESS, provider, ); @@ -148,7 +154,7 @@ describe('Asset Transfer Proxies', () => { constants.DUMMY_TOKEN_DECIMALS, ); noReturnErc20Token = await DummyNoReturnERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.DummyNoReturnERC20Token, + erc20Artifacts.DummyNoReturnERC20Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, @@ -157,7 +163,7 @@ describe('Asset Transfer Proxies', () => { constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); multipleReturnErc20Token = await DummyMultipleReturnERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.DummyMultipleReturnERC20Token, + erc20Artifacts.DummyMultipleReturnERC20Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, @@ -198,7 +204,7 @@ describe('Asset Transfer Proxies', () => { // Deploy and configure ERC721 tokens and receiver [erc721TokenA, erc721TokenB] = await erc721Wrapper.deployDummyTokensAsync(); erc721Receiver = await DummyERC721ReceiverContract.deployFrom0xArtifactAsync( - tokensArtifacts.DummyERC721Receiver, + erc721Artifacts.DummyERC721Receiver, provider, txDefaults, ); @@ -562,7 +568,7 @@ describe('Asset Transfer Proxies', () => { erc721Receiver.address, amount, ); - const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...tokensArtifacts }); + const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...erc721Artifacts }); const tx = await logDecoder.getTxWithDecodedLogsAsync( await web3Wrapper.sendTransactionAsync({ to: erc721Proxy.address, @@ -754,7 +760,7 @@ describe('Asset Transfer Proxies', () => { inputAmount, ); const erc20Balances = await erc20Wrapper.getBalancesAsync(); - const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...tokensArtifacts }); + const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...erc20Artifacts }); const tx = await logDecoder.getTxWithDecodedLogsAsync( await web3Wrapper.sendTransactionAsync({ to: multiAssetProxy.address, diff --git a/contracts/protocol/test/utils/erc20_wrapper.ts b/contracts/asset-proxy/test/utils/erc20_wrapper.ts similarity index 99% rename from contracts/protocol/test/utils/erc20_wrapper.ts rename to contracts/asset-proxy/test/utils/erc20_wrapper.ts index e5ab0e36ca..12cd06ecee 100644 --- a/contracts/protocol/test/utils/erc20_wrapper.ts +++ b/contracts/asset-proxy/test/utils/erc20_wrapper.ts @@ -1,5 +1,5 @@ +import { artifacts as tokensArtifacts, DummyERC20TokenContract } from '@0x/contracts-erc20'; import { constants, ERC20BalancesByOwner, txDefaults } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts, DummyERC20TokenContract } from '@0x/contracts-tokens'; import { assetDataUtils } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; diff --git a/contracts/protocol/test/utils/erc721_wrapper.ts b/contracts/asset-proxy/test/utils/erc721_wrapper.ts similarity index 99% rename from contracts/protocol/test/utils/erc721_wrapper.ts rename to contracts/asset-proxy/test/utils/erc721_wrapper.ts index 1f658ce867..fc43d8c525 100644 --- a/contracts/protocol/test/utils/erc721_wrapper.ts +++ b/contracts/asset-proxy/test/utils/erc721_wrapper.ts @@ -1,5 +1,5 @@ +import { artifacts as tokensArtifacts, DummyERC721TokenContract } from '@0x/contracts-erc721'; import { constants, ERC721TokenIdsByOwner, txDefaults } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts, DummyERC721TokenContract } from '@0x/contracts-tokens'; import { generatePseudoRandomSalt } from '@0x/order-utils'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; diff --git a/contracts/protocol/test/utils/index.ts b/contracts/asset-proxy/test/utils/index.ts similarity index 65% rename from contracts/protocol/test/utils/index.ts rename to contracts/asset-proxy/test/utils/index.ts index 75cd88666f..b11f6a45de 100644 --- a/contracts/protocol/test/utils/index.ts +++ b/contracts/asset-proxy/test/utils/index.ts @@ -1,3 +1,2 @@ -export * from './exchange_wrapper'; export * from './erc20_wrapper'; export * from './erc721_wrapper'; diff --git a/contracts/asset-proxy/tsconfig.json b/contracts/asset-proxy/tsconfig.json new file mode 100644 index 0000000000..7baa48cbe2 --- /dev/null +++ b/contracts/asset-proxy/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib", + "rootDir": ".", + "resolveJsonModule": true + }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "files": [ + "./generated-artifacts/IAssetData.json", + "./generated-artifacts/IAssetProxy.json", + "./generated-artifacts/IAuthorizable.json", + "./generated-artifacts/ERC20Proxy.json", + "./generated-artifacts/ERC721Proxy.json", + "./generated-artifacts/MixinAuthorizable.json", + "./generated-artifacts/MultiAssetProxy.json" + ], + "exclude": ["./deploy/solc/solc_bin"] +} diff --git a/contracts/examples/tslint.json b/contracts/asset-proxy/tslint.json similarity index 100% rename from contracts/examples/tslint.json rename to contracts/asset-proxy/tslint.json diff --git a/contracts/erc20/.solhintignore b/contracts/erc20/.solhintignore new file mode 100644 index 0000000000..ededa90be5 --- /dev/null +++ b/contracts/erc20/.solhintignore @@ -0,0 +1 @@ +contracts/src/ZRXToken.sol diff --git a/contracts/erc20/CHANGELOG.json b/contracts/erc20/CHANGELOG.json new file mode 100644 index 0000000000..93f2842340 --- /dev/null +++ b/contracts/erc20/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Move all ERC20 contracts out of contracts-tokens to new package", + "pr": 1539 + } + ] + } +] diff --git a/contracts/examples/CHANGELOG.md b/contracts/erc20/CHANGELOG.md similarity index 100% rename from contracts/examples/CHANGELOG.md rename to contracts/erc20/CHANGELOG.md diff --git a/contracts/tokens/DEPLOYS.json b/contracts/erc20/DEPLOYS.json similarity index 86% rename from contracts/tokens/DEPLOYS.json rename to contracts/erc20/DEPLOYS.json index 5ff58c0353..e165b37b33 100644 --- a/contracts/tokens/DEPLOYS.json +++ b/contracts/erc20/DEPLOYS.json @@ -8,6 +8,7 @@ "networks": { "1": "0xe41d2489571d322189246dafa5ebde1f4699f498", "3": "0xff67881f8d12f372d91baae9752eb3631ff0ed00", + "4": "0x2727e688b8fd40b198cd5fe6e408e00494a06f07", "42": "0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa" } } diff --git a/contracts/interfaces/README.md b/contracts/erc20/README.md similarity index 68% rename from contracts/interfaces/README.md rename to contracts/erc20/README.md index 81dd4c3acc..e1214c00c4 100644 --- a/contracts/interfaces/README.md +++ b/contracts/erc20/README.md @@ -1,13 +1,14 @@ -## Contract interfaces +## ERC20 Tokens -Smart contract interfaces of the 0x protocol. +This package contains implementations of various [ERC20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md) tokens, including WETH (Wrapped Ether) and ZRX. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contracts that make up and interact with version 2.0.0 of the protocol can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [protocol](./contracts/protocol) - - This directory contains the contract interfaces that make up version 2.0.0. A full specification can be found [here](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md). +```bash +npm install @0x/contracts-erc20 --save +``` ## Bug bounty @@ -40,13 +41,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-interfaces yarn build +PKG=@0x/contracts-erc20 yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-interfaces yarn watch +PKG=@0x/contracts-erc20 yarn watch ``` ### Clean diff --git a/contracts/tokens/compiler.json b/contracts/erc20/compiler.json similarity index 75% rename from contracts/tokens/compiler.json rename to contracts/erc20/compiler.json index 498c5d8260..58fc8ea9b9 100644 --- a/contracts/tokens/compiler.json +++ b/contracts/erc20/compiler.json @@ -22,23 +22,13 @@ "DummyERC20Token", "DummyMultipleReturnERC20Token", "DummyNoReturnERC20Token", - "DummyERC721Receiver", - "InvalidERC721Receiver", - "DummyERC721Token", "ReentrantERC20Token", "ERC20Token", "IERC20Token", "MintableERC20Token", "UnlimitedAllowanceERC20Token", - "ERC721Token", - "IERC721Receiver", - "IERC721Token", - "MintableERC721Token", "IEtherToken", "WETH9", - "ERC20Token_v1", - "Token_v1", - "UnlimitedAllowanceToken_v1", "ZRXToken" ] } diff --git a/contracts/tokens/contracts/tokens/ERC20Token/ERC20Token.sol b/contracts/erc20/contracts/src/ERC20Token.sol similarity index 99% rename from contracts/tokens/contracts/tokens/ERC20Token/ERC20Token.sol rename to contracts/erc20/contracts/src/ERC20Token.sol index 190eead766..b6e9d0f9f1 100644 --- a/contracts/tokens/contracts/tokens/ERC20Token/ERC20Token.sol +++ b/contracts/erc20/contracts/src/ERC20Token.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "./IERC20Token.sol"; +import "./interfaces/IERC20Token.sol"; contract ERC20Token is diff --git a/contracts/tokens/contracts/tokens/ERC20Token/MintableERC20Token.sol b/contracts/erc20/contracts/src/MintableERC20Token.sol similarity index 95% rename from contracts/tokens/contracts/tokens/ERC20Token/MintableERC20Token.sol rename to contracts/erc20/contracts/src/MintableERC20Token.sol index a66031f035..1108db53d7 100644 --- a/contracts/tokens/contracts/tokens/ERC20Token/MintableERC20Token.sol +++ b/contracts/erc20/contracts/src/MintableERC20Token.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; import "./UnlimitedAllowanceERC20Token.sol"; diff --git a/contracts/tokens/contracts/tokens/ERC20Token/UnlimitedAllowanceERC20Token.sol b/contracts/erc20/contracts/src/UnlimitedAllowanceERC20Token.sol similarity index 97% rename from contracts/tokens/contracts/tokens/ERC20Token/UnlimitedAllowanceERC20Token.sol rename to contracts/erc20/contracts/src/UnlimitedAllowanceERC20Token.sol index 869d16147a..3a43c250d3 100644 --- a/contracts/tokens/contracts/tokens/ERC20Token/UnlimitedAllowanceERC20Token.sol +++ b/contracts/erc20/contracts/src/UnlimitedAllowanceERC20Token.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "../ERC20Token/ERC20Token.sol"; +import "./ERC20Token.sol"; contract UnlimitedAllowanceERC20Token is diff --git a/contracts/tokens/contracts/tokens/EtherToken/WETH9.sol b/contracts/erc20/contracts/src/WETH9.sol similarity index 100% rename from contracts/tokens/contracts/tokens/EtherToken/WETH9.sol rename to contracts/erc20/contracts/src/WETH9.sol diff --git a/contracts/erc20/contracts/src/ZRXToken.sol b/contracts/erc20/contracts/src/ZRXToken.sol new file mode 100644 index 0000000000..75e4dc0a9b --- /dev/null +++ b/contracts/erc20/contracts/src/ZRXToken.sol @@ -0,0 +1,150 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity 0.4.11; + + +contract Token { + + /// @return total amount of tokens + function totalSupply() constant returns (uint supply) {} + + /// @param _owner The address from which the balance will be retrieved + /// @return The balance + function balanceOf(address _owner) constant returns (uint balance) {} + + /// @notice send `_value` token to `_to` from `msg.sender` + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transfer(address _to, uint _value) returns (bool success) {} + + /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` + /// @param _from The address of the sender + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transferFrom(address _from, address _to, uint _value) returns (bool success) {} + + /// @notice `msg.sender` approves `_addr` to spend `_value` tokens + /// @param _spender The address of the account able to transfer the tokens + /// @param _value The amount of wei to be approved for transfer + /// @return Whether the approval was successful or not + function approve(address _spender, uint _value) returns (bool success) {} + + /// @param _owner The address of the account owning tokens + /// @param _spender The address of the account able to transfer the tokens + /// @return Amount of remaining tokens allowed to spent + function allowance(address _owner, address _spender) constant returns (uint remaining) {} + + event Transfer(address indexed _from, address indexed _to, uint _value); + event Approval(address indexed _owner, address indexed _spender, uint _value); +} + + +contract ERC20Token is Token { + + function transfer(address _to, uint _value) returns (bool) { + //Default assumes totalSupply can't be over max (2^256 - 1). + if (balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) { + balances[msg.sender] -= _value; + balances[_to] += _value; + Transfer(msg.sender, _to, _value); + return true; + } else { return false; } + } + + function transferFrom(address _from, address _to, uint _value) returns (bool) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]) { + balances[_to] += _value; + balances[_from] -= _value; + allowed[_from][msg.sender] -= _value; + Transfer(_from, _to, _value); + return true; + } else { return false; } + } + + function balanceOf(address _owner) constant returns (uint) { + return balances[_owner]; + } + + function approve(address _spender, uint _value) returns (bool) { + allowed[msg.sender][_spender] = _value; + Approval(msg.sender, _spender, _value); + return true; + } + + function allowance(address _owner, address _spender) constant returns (uint) { + return allowed[_owner][_spender]; + } + + mapping (address => uint) balances; + mapping (address => mapping (address => uint)) allowed; + uint public totalSupply; +} + + +contract UnlimitedAllowanceToken is ERC20Token { + + uint constant MAX_UINT = 2**256 - 1; + + /// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance. + /// @param _from Address to transfer from. + /// @param _to Address to transfer to. + /// @param _value Amount to transfer. + /// @return Success of transfer. + function transferFrom(address _from, address _to, uint _value) + public + returns (bool) + { + uint allowance = allowed[_from][msg.sender]; + if (balances[_from] >= _value + && allowance >= _value + && balances[_to] + _value >= balances[_to] + ) { + balances[_to] += _value; + balances[_from] -= _value; + if (allowance < MAX_UINT) { + allowed[_from][msg.sender] -= _value; + } + Transfer(_from, _to, _value); + return true; + } else { + return false; + } + } +} + + +contract ZRXToken is + UnlimitedAllowanceToken +{ + + // solhint-disable const-name-snakecase + uint8 constant public decimals = 18; + uint256 public totalSupply = 10**27; // 1 billion tokens, 18 decimal places + string constant public name = "0x Protocol Token"; + string constant public symbol = "ZRX"; + // solhint-enableconst-name-snakecase + + function ZRXToken() + public + { + balances[msg.sender] = totalSupply; + } +} diff --git a/contracts/tokens/contracts/tokens/ERC20Token/IERC20Token.sol b/contracts/erc20/contracts/src/interfaces/IERC20Token.sol similarity index 100% rename from contracts/tokens/contracts/tokens/ERC20Token/IERC20Token.sol rename to contracts/erc20/contracts/src/interfaces/IERC20Token.sol diff --git a/contracts/tokens/contracts/tokens/EtherToken/IEtherToken.sol b/contracts/erc20/contracts/src/interfaces/IEtherToken.sol similarity index 95% rename from contracts/tokens/contracts/tokens/EtherToken/IEtherToken.sol rename to contracts/erc20/contracts/src/interfaces/IEtherToken.sol index 32baa3eb08..cb07cae6f6 100644 --- a/contracts/tokens/contracts/tokens/EtherToken/IEtherToken.sol +++ b/contracts/erc20/contracts/src/interfaces/IEtherToken.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "../ERC20Token/IERC20Token.sol"; +import "./IERC20Token.sol"; contract IEtherToken is diff --git a/contracts/tokens/contracts/test/DummyERC20Token/DummyERC20Token.sol b/contracts/erc20/contracts/test/DummyERC20Token.sol similarity index 94% rename from contracts/tokens/contracts/test/DummyERC20Token/DummyERC20Token.sol rename to contracts/erc20/contracts/test/DummyERC20Token.sol index 33028db0c1..39e739a916 100644 --- a/contracts/tokens/contracts/test/DummyERC20Token/DummyERC20Token.sol +++ b/contracts/erc20/contracts/test/DummyERC20Token.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; -import "../../tokens/ERC20Token/MintableERC20Token.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; +import "../src/MintableERC20Token.sol"; contract DummyERC20Token is diff --git a/contracts/tokens/contracts/test/DummyERC20Token/DummyMultipleReturnERC20Token.sol b/contracts/erc20/contracts/test/DummyMultipleReturnERC20Token.sol similarity index 100% rename from contracts/tokens/contracts/test/DummyERC20Token/DummyMultipleReturnERC20Token.sol rename to contracts/erc20/contracts/test/DummyMultipleReturnERC20Token.sol diff --git a/contracts/tokens/contracts/test/DummyERC20Token/DummyNoReturnERC20Token.sol b/contracts/erc20/contracts/test/DummyNoReturnERC20Token.sol similarity index 100% rename from contracts/tokens/contracts/test/DummyERC20Token/DummyNoReturnERC20Token.sol rename to contracts/erc20/contracts/test/DummyNoReturnERC20Token.sol diff --git a/contracts/tokens/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol b/contracts/erc20/contracts/test/ReentrantERC20Token.sol similarity index 96% rename from contracts/tokens/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol rename to contracts/erc20/contracts/test/ReentrantERC20Token.sol index d8c65929dc..0629754c08 100644 --- a/contracts/tokens/contracts/test/ReentrantERC20Token/ReentrantERC20Token.sol +++ b/contracts/erc20/contracts/test/ReentrantERC20Token.sol @@ -19,10 +19,10 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "../../tokens/ERC20Token/ERC20Token.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "../src/ERC20Token.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; // solhint-disable no-unused-vars diff --git a/contracts/tokens/package.json b/contracts/erc20/package.json similarity index 77% rename from contracts/tokens/package.json rename to contracts/erc20/package.json index bd03169191..7616b9ccfa 100644 --- a/contracts/tokens/package.json +++ b/contracts/erc20/package.json @@ -1,6 +1,6 @@ { - "name": "@0x/contracts-tokens", - "version": "1.0.6", + "name": "@0x/contracts-erc20", + "version": "1.0.0", "engines": { "node": ">=6.12" }, @@ -32,7 +32,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|DummyERC721Receiver|InvalidERC721Receiver|DummyERC721Token|ReentrantERC20Token|ERC20Token|IERC20Token|MintableERC20Token|UnlimitedAllowanceERC20Token|ERC721Token|IERC721Receiver|IERC721Token|MintableERC721Token|IEtherToken|WETH9|ERC20Token_v1|Token_v1|UnlimitedAllowanceToken_v1|ZRXToken).json" + "abis": "generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ReentrantERC20Token|ERC20Token|IERC20Token|MintableERC20Token|UnlimitedAllowanceERC20Token|IEtherToken|WETH9|ZRXToken).json" }, "repository": { "type": "git", @@ -48,41 +48,30 @@ "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-interfaces": "^1.0.6", - "@0x/contracts-libs": "^1.0.6", - "@0x/contracts-multisig": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", - "@0x/order-utils": "^3.1.2", + "@0x/contracts-exchange-libs": "^1.0.0", + "@0x/contracts-utils": "^3.0.0", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", - "@types/js-combinatorics": "^0.5.29", - "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", - "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" }, "publishConfig": { diff --git a/contracts/tokens/src/artifacts/index.ts b/contracts/erc20/src/artifacts/index.ts similarity index 56% rename from contracts/tokens/src/artifacts/index.ts rename to contracts/erc20/src/artifacts/index.ts index 977d01c3eb..ce1ae06ac4 100644 --- a/contracts/tokens/src/artifacts/index.ts +++ b/contracts/erc20/src/artifacts/index.ts @@ -1,24 +1,14 @@ import { ContractArtifact } from 'ethereum-types'; import * as DummyERC20Token from '../../generated-artifacts/DummyERC20Token.json'; -import * as DummyERC721Receiver from '../../generated-artifacts/DummyERC721Receiver.json'; -import * as DummyERC721Token from '../../generated-artifacts/DummyERC721Token.json'; import * as DummyMultipleReturnERC20Token from '../../generated-artifacts/DummyMultipleReturnERC20Token.json'; import * as DummyNoReturnERC20Token from '../../generated-artifacts/DummyNoReturnERC20Token.json'; import * as ERC20Token from '../../generated-artifacts/ERC20Token.json'; -import * as ERC20Token_v1 from '../../generated-artifacts/ERC20Token_v1.json'; -import * as ERC721Token from '../../generated-artifacts/ERC721Token.json'; import * as IERC20Token from '../../generated-artifacts/IERC20Token.json'; -import * as IERC721Receiver from '../../generated-artifacts/IERC721Receiver.json'; -import * as IERC721Token from '../../generated-artifacts/IERC721Token.json'; import * as IEtherToken from '../../generated-artifacts/IEtherToken.json'; -import * as InvalidERC721Receiver from '../../generated-artifacts/InvalidERC721Receiver.json'; import * as MintableERC20Token from '../../generated-artifacts/MintableERC20Token.json'; -import * as MintableERC721Token from '../../generated-artifacts/MintableERC721Token.json'; import * as ReentrantERC20Token from '../../generated-artifacts/ReentrantERC20Token.json'; -import * as Token_v1 from '../../generated-artifacts/Token_v1.json'; import * as UnlimitedAllowanceERC20Token from '../../generated-artifacts/UnlimitedAllowanceERC20Token.json'; -import * as UnlimitedAllowanceToken_v1 from '../../generated-artifacts/UnlimitedAllowanceToken_v1.json'; import * as WETH9 from '../../generated-artifacts/WETH9.json'; import * as ZRXToken from '../../generated-artifacts/ZRXToken.json'; @@ -27,23 +17,13 @@ export const artifacts = { DummyERC20Token: DummyERC20Token as ContractArtifact, DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact, DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact, - DummyERC721Receiver: DummyERC721Receiver as ContractArtifact, - InvalidERC721Receiver: InvalidERC721Receiver as ContractArtifact, - DummyERC721Token: DummyERC721Token as ContractArtifact, ReentrantERC20Token: ReentrantERC20Token as ContractArtifact, ERC20Token: ERC20Token as ContractArtifact, IERC20Token: IERC20Token as ContractArtifact, MintableERC20Token: MintableERC20Token as ContractArtifact, UnlimitedAllowanceERC20Token: UnlimitedAllowanceERC20Token as ContractArtifact, - ERC721Token: ERC721Token as ContractArtifact, - IERC721Receiver: IERC721Receiver as ContractArtifact, - IERC721Token: IERC721Token as ContractArtifact, - MintableERC721Token: MintableERC721Token as ContractArtifact, IEtherToken: IEtherToken as ContractArtifact, WETH9: WETH9 as ContractArtifact, - ERC20Token_v1: ERC20Token_v1 as ContractArtifact, - Token_v1: Token_v1 as ContractArtifact, - UnlimitedAllowanceToken_v1: UnlimitedAllowanceToken_v1 as ContractArtifact, // Note(albrow): "as any" hack still required here because ZRXToken does not // conform to the v2 artifact type. ZRXToken: (ZRXToken as any) as ContractArtifact, diff --git a/contracts/tokens/src/index.ts b/contracts/erc20/src/index.ts similarity index 100% rename from contracts/tokens/src/index.ts rename to contracts/erc20/src/index.ts diff --git a/contracts/tokens/src/wrappers/index.ts b/contracts/erc20/src/wrappers/index.ts similarity index 52% rename from contracts/tokens/src/wrappers/index.ts rename to contracts/erc20/src/wrappers/index.ts index 98bf266579..b4e4ef9697 100644 --- a/contracts/tokens/src/wrappers/index.ts +++ b/contracts/erc20/src/wrappers/index.ts @@ -1,21 +1,11 @@ export * from '../../generated-wrappers/zrx_token'; export * from '../../generated-wrappers/weth9'; -export * from '../../generated-wrappers/unlimitedallowancetoken_v1'; export * from '../../generated-wrappers/unlimited_allowance_erc20_token'; -export * from '../../generated-wrappers/token_v1'; export * from '../../generated-wrappers/reentrant_erc20_token'; -export * from '../../generated-wrappers/mintable_erc721_token'; export * from '../../generated-wrappers/mintable_erc20_token'; -export * from '../../generated-wrappers/invalid_erc721_receiver'; export * from '../../generated-wrappers/i_ether_token'; -export * from '../../generated-wrappers/i_erc721_token'; -export * from '../../generated-wrappers/i_erc721_receiver'; export * from '../../generated-wrappers/i_erc20_token'; -export * from '../../generated-wrappers/erc721_token'; -export * from '../../generated-wrappers/erc20token_v1'; export * from '../../generated-wrappers/erc20_token'; export * from '../../generated-wrappers/dummy_no_return_erc20_token'; export * from '../../generated-wrappers/dummy_multiple_return_erc20_token'; -export * from '../../generated-wrappers/dummy_erc721_token'; -export * from '../../generated-wrappers/dummy_erc721_receiver'; export * from '../../generated-wrappers/dummy_erc20_token'; diff --git a/contracts/protocol/test/global_hooks.ts b/contracts/erc20/test/global_hooks.ts similarity index 100% rename from contracts/protocol/test/global_hooks.ts rename to contracts/erc20/test/global_hooks.ts diff --git a/contracts/tokens/test/unlimited_allowance_token.ts b/contracts/erc20/test/unlimited_allowance_token.ts similarity index 100% rename from contracts/tokens/test/unlimited_allowance_token.ts rename to contracts/erc20/test/unlimited_allowance_token.ts diff --git a/contracts/tokens/test/weth9.ts b/contracts/erc20/test/weth9.ts similarity index 100% rename from contracts/tokens/test/weth9.ts rename to contracts/erc20/test/weth9.ts diff --git a/contracts/tokens/test/zrx_token.ts b/contracts/erc20/test/zrx_token.ts similarity index 100% rename from contracts/tokens/test/zrx_token.ts rename to contracts/erc20/test/zrx_token.ts diff --git a/contracts/tokens/tsconfig.json b/contracts/erc20/tsconfig.json similarity index 61% rename from contracts/tokens/tsconfig.json rename to contracts/erc20/tsconfig.json index 0d5f98cb81..4df7424be6 100644 --- a/contracts/tokens/tsconfig.json +++ b/contracts/erc20/tsconfig.json @@ -10,23 +10,13 @@ "./generated-artifacts/DummyERC20Token.json", "./generated-artifacts/DummyMultipleReturnERC20Token.json", "./generated-artifacts/DummyNoReturnERC20Token.json", - "./generated-artifacts/DummyERC721Receiver.json", - "./generated-artifacts/InvalidERC721Receiver.json", - "./generated-artifacts/DummyERC721Token.json", "./generated-artifacts/ReentrantERC20Token.json", "./generated-artifacts/ERC20Token.json", "./generated-artifacts/IERC20Token.json", "./generated-artifacts/MintableERC20Token.json", "./generated-artifacts/UnlimitedAllowanceERC20Token.json", - "./generated-artifacts/ERC721Token.json", - "./generated-artifacts/IERC721Receiver.json", - "./generated-artifacts/IERC721Token.json", - "./generated-artifacts/MintableERC721Token.json", "./generated-artifacts/IEtherToken.json", "./generated-artifacts/WETH9.json", - "./generated-artifacts/ERC20Token_v1.json", - "./generated-artifacts/Token_v1.json", - "./generated-artifacts/UnlimitedAllowanceToken_v1.json", "./generated-artifacts/ZRXToken.json" ], "exclude": ["./deploy/solc/solc_bin"] diff --git a/contracts/interfaces/tslint.json b/contracts/erc20/tslint.json similarity index 100% rename from contracts/interfaces/tslint.json rename to contracts/erc20/tslint.json diff --git a/contracts/tokens/.solhintignore b/contracts/erc721/.solhintignore similarity index 100% rename from contracts/tokens/.solhintignore rename to contracts/erc721/.solhintignore diff --git a/contracts/erc721/CHANGELOG.json b/contracts/erc721/CHANGELOG.json new file mode 100644 index 0000000000..caf1e6701d --- /dev/null +++ b/contracts/erc721/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Move all ERC721 contracts out of contracts-tokens to new package", + "pr": 1539 + } + ] + } +] diff --git a/contracts/interfaces/CHANGELOG.md b/contracts/erc721/CHANGELOG.md similarity index 100% rename from contracts/interfaces/CHANGELOG.md rename to contracts/erc721/CHANGELOG.md diff --git a/contracts/erc721/DEPLOYS.json b/contracts/erc721/DEPLOYS.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/contracts/erc721/DEPLOYS.json @@ -0,0 +1 @@ +[] diff --git a/contracts/libs/README.md b/contracts/erc721/README.md similarity index 67% rename from contracts/libs/README.md rename to contracts/erc721/README.md index cfa6316797..c14035b9e2 100644 --- a/contracts/libs/README.md +++ b/contracts/erc721/README.md @@ -1,15 +1,18 @@ -## Contracts libs +## ERC721 Tokens -Smart contracts libs used in the 0x protocol. +This package contains implementations of various [ERC721](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md) tokens. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contracts can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [libs](./contracts/protocol) - - This directory contains the libs. -- [test](./contracts/test) - - This directory contains mocks and other contracts that are used solely for testing contracts within the other directories. +```bash +npm install @0x/contracts-erc721 --save +``` + +## Bug bounty + +A bug bounty for the 2.0.0 contracts is ongoing! Instructions can be found [here](https://0xproject.com/wiki#Bug-Bounty). ## Contributing @@ -38,13 +41,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-libs yarn build +PKG=@0x/contracts-erc721 yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-libs yarn watch +PKG=@0x/contracts-erc721 yarn watch ``` ### Clean diff --git a/contracts/erc721/compiler.json b/contracts/erc721/compiler.json new file mode 100644 index 0000000000..c5f07ddb84 --- /dev/null +++ b/contracts/erc721/compiler.json @@ -0,0 +1,30 @@ +{ + "artifactsDir": "./generated-artifacts", + "contractsDir": "./contracts", + "compilerSettings": { + "optimizer": { + "enabled": true, + "runs": 1000000 + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + }, + "contracts": [ + "DummyERC721Receiver", + "InvalidERC721Receiver", + "DummyERC721Token", + "ERC721Token", + "IERC721Receiver", + "IERC721Token", + "MintableERC721Token" + ] +} diff --git a/contracts/tokens/contracts/tokens/ERC721Token/ERC721Token.sol b/contracts/erc721/contracts/src/ERC721Token.sol similarity index 98% rename from contracts/tokens/contracts/tokens/ERC721Token/ERC721Token.sol rename to contracts/erc721/contracts/src/ERC721Token.sol index c46bd0af4b..32f70ccf8d 100644 --- a/contracts/tokens/contracts/tokens/ERC721Token/ERC721Token.sol +++ b/contracts/erc721/contracts/src/ERC721Token.sol @@ -18,9 +18,9 @@ pragma solidity ^0.4.24; -import "./IERC721Token.sol"; -import "./IERC721Receiver.sol"; -import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; +import "./interfaces/IERC721Token.sol"; +import "./interfaces/IERC721Receiver.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; contract ERC721Token is diff --git a/contracts/tokens/contracts/tokens/ERC721Token/MintableERC721Token.sol b/contracts/erc721/contracts/src/MintableERC721Token.sol similarity index 100% rename from contracts/tokens/contracts/tokens/ERC721Token/MintableERC721Token.sol rename to contracts/erc721/contracts/src/MintableERC721Token.sol diff --git a/contracts/tokens/contracts/tokens/ERC721Token/IERC721Receiver.sol b/contracts/erc721/contracts/src/interfaces/IERC721Receiver.sol similarity index 100% rename from contracts/tokens/contracts/tokens/ERC721Token/IERC721Receiver.sol rename to contracts/erc721/contracts/src/interfaces/IERC721Receiver.sol diff --git a/contracts/tokens/contracts/tokens/ERC721Token/IERC721Token.sol b/contracts/erc721/contracts/src/interfaces/IERC721Token.sol similarity index 100% rename from contracts/tokens/contracts/tokens/ERC721Token/IERC721Token.sol rename to contracts/erc721/contracts/src/interfaces/IERC721Token.sol diff --git a/contracts/tokens/contracts/test/DummyERC721Receiver/DummyERC721Receiver.sol b/contracts/erc721/contracts/test/DummyERC721Receiver.sol similarity index 97% rename from contracts/tokens/contracts/test/DummyERC721Receiver/DummyERC721Receiver.sol rename to contracts/erc721/contracts/test/DummyERC721Receiver.sol index 6c83715591..b5de01aa5e 100644 --- a/contracts/tokens/contracts/test/DummyERC721Receiver/DummyERC721Receiver.sol +++ b/contracts/erc721/contracts/test/DummyERC721Receiver.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../tokens/ERC721Token/IERC721Receiver.sol"; +import "../src/interfaces/IERC721Receiver.sol"; contract DummyERC721Receiver is diff --git a/contracts/tokens/contracts/test/DummyERC721Token/DummyERC721Token.sol b/contracts/erc721/contracts/test/DummyERC721Token.sol similarity index 92% rename from contracts/tokens/contracts/test/DummyERC721Token/DummyERC721Token.sol rename to contracts/erc721/contracts/test/DummyERC721Token.sol index 4c978b2df7..41dc8ea18c 100644 --- a/contracts/tokens/contracts/test/DummyERC721Token/DummyERC721Token.sol +++ b/contracts/erc721/contracts/test/DummyERC721Token.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "../../tokens/ERC721Token/MintableERC721Token.sol"; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "../src/MintableERC721Token.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; // solhint-disable no-empty-blocks diff --git a/contracts/tokens/contracts/test/DummyERC721Receiver/InvalidERC721Receiver.sol b/contracts/erc721/contracts/test/InvalidERC721Receiver.sol similarity index 97% rename from contracts/tokens/contracts/test/DummyERC721Receiver/InvalidERC721Receiver.sol rename to contracts/erc721/contracts/test/InvalidERC721Receiver.sol index 309633bf5e..ea59dedc51 100644 --- a/contracts/tokens/contracts/test/DummyERC721Receiver/InvalidERC721Receiver.sol +++ b/contracts/erc721/contracts/test/InvalidERC721Receiver.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../tokens/ERC721Token/IERC721Receiver.sol"; +import "../src/interfaces/IERC721Receiver.sol"; contract InvalidERC721Receiver is diff --git a/contracts/examples/package.json b/contracts/erc721/package.json similarity index 64% rename from contracts/examples/package.json rename to contracts/erc721/package.json index 845ea06362..8e83ea4e45 100644 --- a/contracts/examples/package.json +++ b/contracts/erc721/package.json @@ -1,10 +1,10 @@ { - "name": "@0x/contracts-examples", - "version": "1.0.6", + "name": "@0x/contracts-erc721", + "version": "1.0.0", "engines": { "node": ">=6.12" }, - "description": "Smart contract examples of 0x protocol", + "description": "Token contracts used by 0x protocol", "main": "lib/src/index.js", "directories": { "test": "test" @@ -13,15 +13,26 @@ "build": "yarn pre_build && tsc -b", "build:ci": "yarn build", "pre_build": "run-s compile generate_contract_wrappers", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s build test", + "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", + "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "coverage:report:text": "istanbul report text", + "coverage:report:html": "istanbul report html && open coverage/index.html", + "profiler:report:html": "istanbul report html && open coverage/index.html", + "coverage:report:lcov": "istanbul report lcov", + "test:circleci": "yarn test", "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(ExchangeWrapper|Validator|Wallet|Whitelist).json" + "abis": "generated-artifacts/@(DummyERC721Receiver|InvalidERC721Receiver|DummyERC721Token|ERC721Token|IERC721Receiver|IERC721Token|MintableERC721Token).json" }, "repository": { "type": "git", @@ -31,48 +42,35 @@ "bugs": { "url": "https://github.com/0xProject/0x-monorepo/issues" }, - "homepage": "https://github.com/0xProject/0x-monorepo/contracts/examples/README.md", + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/tokens/README.md", "devDependencies": { "@0x/abi-gen": "^1.0.22", "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-interfaces": "^1.0.6", - "@0x/contracts-libs": "^1.0.6", - "@0x/contracts-multisig": "^1.0.6", - "@0x/contracts-tokens": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", - "@0x/order-utils": "^3.1.2", + "@0x/contracts-utils": "^3.0.0", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", - "@types/js-combinatorics": "^0.5.29", - "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", - "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" }, "publishConfig": { diff --git a/contracts/erc721/src/artifacts/index.ts b/contracts/erc721/src/artifacts/index.ts new file mode 100644 index 0000000000..8d5ec8a46f --- /dev/null +++ b/contracts/erc721/src/artifacts/index.ts @@ -0,0 +1,20 @@ +import { ContractArtifact } from 'ethereum-types'; + +import * as DummyERC721Receiver from '../../generated-artifacts/DummyERC721Receiver.json'; +import * as DummyERC721Token from '../../generated-artifacts/DummyERC721Token.json'; +import * as ERC721Token from '../../generated-artifacts/ERC721Token.json'; +import * as IERC721Receiver from '../../generated-artifacts/IERC721Receiver.json'; +import * as IERC721Token from '../../generated-artifacts/IERC721Token.json'; +import * as InvalidERC721Receiver from '../../generated-artifacts/InvalidERC721Receiver.json'; +import * as MintableERC721Token from '../../generated-artifacts/MintableERC721Token.json'; + +// tslint:disable:no-unnecessary-type-assertion +export const artifacts = { + DummyERC721Receiver: DummyERC721Receiver as ContractArtifact, + InvalidERC721Receiver: InvalidERC721Receiver as ContractArtifact, + DummyERC721Token: DummyERC721Token as ContractArtifact, + ERC721Token: ERC721Token as ContractArtifact, + IERC721Receiver: IERC721Receiver as ContractArtifact, + IERC721Token: IERC721Token as ContractArtifact, + MintableERC721Token: MintableERC721Token as ContractArtifact, +}; diff --git a/contracts/libs/src/index.ts b/contracts/erc721/src/index.ts similarity index 100% rename from contracts/libs/src/index.ts rename to contracts/erc721/src/index.ts index d55f08ea2d..91dd7e0e3e 100644 --- a/contracts/libs/src/index.ts +++ b/contracts/erc721/src/index.ts @@ -1,2 +1,2 @@ -export * from './artifacts'; export * from './wrappers'; +export * from './artifacts'; diff --git a/contracts/erc721/src/wrappers/index.ts b/contracts/erc721/src/wrappers/index.ts new file mode 100644 index 0000000000..ba6c518854 --- /dev/null +++ b/contracts/erc721/src/wrappers/index.ts @@ -0,0 +1,7 @@ +export * from '../../generated-wrappers/mintable_erc721_token'; +export * from '../../generated-wrappers/invalid_erc721_receiver'; +export * from '../../generated-wrappers/i_erc721_token'; +export * from '../../generated-wrappers/i_erc721_receiver'; +export * from '../../generated-wrappers/erc721_token'; +export * from '../../generated-wrappers/dummy_erc721_token'; +export * from '../../generated-wrappers/dummy_erc721_receiver'; diff --git a/contracts/tokens/test/erc721_token.ts b/contracts/erc721/test/erc721_token.ts similarity index 100% rename from contracts/tokens/test/erc721_token.ts rename to contracts/erc721/test/erc721_token.ts diff --git a/contracts/tokens/test/global_hooks.ts b/contracts/erc721/test/global_hooks.ts similarity index 100% rename from contracts/tokens/test/global_hooks.ts rename to contracts/erc721/test/global_hooks.ts diff --git a/contracts/erc721/tsconfig.json b/contracts/erc721/tsconfig.json new file mode 100644 index 0000000000..098c3a7f3e --- /dev/null +++ b/contracts/erc721/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib", + "rootDir": ".", + "resolveJsonModule": true + }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "files": [ + "./generated-artifacts/DummyERC721Receiver.json", + "./generated-artifacts/InvalidERC721Receiver.json", + "./generated-artifacts/DummyERC721Token.json", + "./generated-artifacts/ERC721Token.json", + "./generated-artifacts/IERC721Receiver.json", + "./generated-artifacts/IERC721Token.json", + "./generated-artifacts/MintableERC721Token.json" + ], + "exclude": ["./deploy/solc/solc_bin"] +} diff --git a/contracts/libs/tslint.json b/contracts/erc721/tslint.json similarity index 100% rename from contracts/libs/tslint.json rename to contracts/erc721/tslint.json diff --git a/contracts/examples/CHANGELOG.json b/contracts/examples/CHANGELOG.json deleted file mode 100644 index 724ab1e4a5..0000000000 --- a/contracts/examples/CHANGELOG.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547747677, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1544741676, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - } -] diff --git a/contracts/examples/src/artifacts/index.ts b/contracts/examples/src/artifacts/index.ts deleted file mode 100644 index c921fbf89a..0000000000 --- a/contracts/examples/src/artifacts/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -import * as ExchangeWrapper from '../../generated-artifacts/ExchangeWrapper.json'; -import * as Validator from '../../generated-artifacts/Validator.json'; -import * as Wallet from '../../generated-artifacts/Wallet.json'; -import * as Whitelist from '../../generated-artifacts/Whitelist.json'; - -export const artifacts = { - ExchangeWrapper: ExchangeWrapper as ContractArtifact, - Validator: Validator as ContractArtifact, - Wallet: Wallet as ContractArtifact, - Whitelist: Whitelist as ContractArtifact, -}; diff --git a/contracts/examples/src/wrappers/index.ts b/contracts/examples/src/wrappers/index.ts deleted file mode 100644 index dc67277d7f..0000000000 --- a/contracts/examples/src/wrappers/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from '../../generated-wrappers/exchange_wrapper'; -export * from '../../generated-wrappers/validator'; -export * from '../../generated-wrappers/wallet'; -export * from '../../generated-wrappers/whitelist'; diff --git a/contracts/exchange-forwarder/CHANGELOG.json b/contracts/exchange-forwarder/CHANGELOG.json new file mode 100644 index 0000000000..a9e5fa8da1 --- /dev/null +++ b/contracts/exchange-forwarder/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Move Forwarder contract out of contracts-extensions into new package", + "pr": 1539 + } + ] + } +] diff --git a/contracts/tokens/CHANGELOG.md b/contracts/exchange-forwarder/CHANGELOG.md similarity index 50% rename from contracts/tokens/CHANGELOG.md rename to contracts/exchange-forwarder/CHANGELOG.md index 59d0804da4..94ffdfb67b 100644 --- a/contracts/tokens/CHANGELOG.md +++ b/contracts/exchange-forwarder/CHANGELOG.md @@ -5,21 +5,27 @@ Edit the package's CHANGELOG.json file only. CHANGELOG -## v1.0.6 - _January 17, 2019_ +## v1.2.3 - _January 17, 2019_ * Dependencies updated -## v1.0.5 - _January 15, 2019_ +## v1.2.2 - _January 15, 2019_ * Dependencies updated -## v1.0.4 - _January 11, 2019_ +## v1.2.1 - _January 11, 2019_ * Dependencies updated -## v1.0.3 - _January 9, 2019_ +## v1.2.0 - _January 9, 2019_ - * Dependencies updated + * Added Dutch Auction Wrapper (#1465) + +## v1.1.0 - _Invalid date_ + + * Added Balance Threshold Filter (#1383) + * Add OrderMatcher (#1117) + * Add OrderValidator (#1464) ## v1.0.2 - _December 13, 2018_ diff --git a/contracts/exchange-forwarder/DEPLOYS.json b/contracts/exchange-forwarder/DEPLOYS.json new file mode 100644 index 0000000000..86bd264c45 --- /dev/null +++ b/contracts/exchange-forwarder/DEPLOYS.json @@ -0,0 +1,32 @@ +[ + { + "name": "Forwarder", + "version": "1.1.0", + "changes": [ + { + "note": "Round up when calculating remaining amounts in marketBuy functions", + "pr": 1162, + "networks": { + "1": "0x5468a1dc173652ee28d249c271fa9933144746b1", + "3": "0x2240dab907db71e64d3e0dba4800c83b5c502d4e", + "4": "0xd2dbf3250a764eaaa94fa0c84ed87c0edc8ed04e", + "42": "0x17992e4ffb22730138e4b62aaa6367fa9d3699a6" + } + } + ] + }, + { + "name": "Forwarder", + "version": "1.0.0", + "changes": [ + { + "note": "protocol v2 deploy", + "networks": { + "1": "0x7afc2d5107af94c462a194d2c21b5bdd238709d6", + "3": "0x3983e204b12b3c02fb0638caf2cd406a62e0ead3", + "42": "0xd85e2fa7e7e252b27b01bf0d65c946959d2f45b8" + } + } + ] + } +] diff --git a/contracts/tokens/README.md b/contracts/exchange-forwarder/README.md similarity index 57% rename from contracts/tokens/README.md rename to contracts/exchange-forwarder/README.md index 2d1db92f01..3fc8c006b3 100644 --- a/contracts/tokens/README.md +++ b/contracts/exchange-forwarder/README.md @@ -1,15 +1,14 @@ -## Token contracts +## Exchange Forwarder -Token smart contracts that are used in the 0x protocol. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [CHANGELOG](./CHANGELOG.json) of this package. +This package contains the implementation of the [`Forwarder`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/forwarder-specification.md) contract. This contract is intended to improve the UX of interacting with the 0x [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange) contract by abstracting user approvals, converting ETH to WETH, and paying fees. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Token contracts that make up and interact with version 2.0.0 of the protocol can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [tokens](./contracts/tokens) - - This directory contains implementations of different tokens and token standards, including [wETH](https://weth.io/), ZRX, [ERC20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md), and [ERC721](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md). -- [test](./contracts/test) - - This directory contains mocks and other contracts that are used solely for testing contracts within the other directories. +```bash +npm install @0x/contracts-exchange-forwarder --save +``` ## Bug bounty @@ -42,13 +41,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-tokens yarn build +PKG=@0x/contracts-exchange-forwarder yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-tokens yarn watch +PKG=@0x/contracts-exchange-forwarder yarn watch ``` ### Clean diff --git a/contracts/examples/compiler.json b/contracts/exchange-forwarder/compiler.json similarity index 88% rename from contracts/examples/compiler.json rename to contracts/exchange-forwarder/compiler.json index 375fa0c553..b0237a519e 100644 --- a/contracts/examples/compiler.json +++ b/contracts/exchange-forwarder/compiler.json @@ -18,5 +18,5 @@ } } }, - "contracts": ["ExchangeWrapper", "Validator", "Wallet", "Whitelist"] + "contracts": ["Forwarder"] } diff --git a/contracts/extensions/contracts/Forwarder/Forwarder.sol b/contracts/exchange-forwarder/contracts/src/Forwarder.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/Forwarder.sol rename to contracts/exchange-forwarder/contracts/src/Forwarder.sol diff --git a/contracts/extensions/contracts/Forwarder/MixinAssets.sol b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol similarity index 93% rename from contracts/extensions/contracts/Forwarder/MixinAssets.sol rename to contracts/exchange-forwarder/contracts/src/MixinAssets.sol index 116cdf2671..330586ed94 100644 --- a/contracts/extensions/contracts/Forwarder/MixinAssets.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinAssets.sol @@ -18,10 +18,10 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC721Token/IERC721Token.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; +import "@0x/contracts-erc721/contracts/src/interfaces/IERC721Token.sol"; import "./libs/LibConstants.sol"; import "./mixins/MAssets.sol"; diff --git a/contracts/extensions/contracts/Forwarder/MixinExchangeWrapper.sol b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol similarity index 97% rename from contracts/extensions/contracts/Forwarder/MixinExchangeWrapper.sol rename to contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol index cab26741de..c970c40cff 100644 --- a/contracts/extensions/contracts/Forwarder/MixinExchangeWrapper.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinExchangeWrapper.sol @@ -21,10 +21,10 @@ pragma experimental ABIEncoderV2; import "./libs/LibConstants.sol"; import "./mixins/MExchangeWrapper.sol"; -import "@0x/contracts-libs/contracts/libs/LibAbiEncoder.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibAbiEncoder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; contract MixinExchangeWrapper is diff --git a/contracts/extensions/contracts/Forwarder/MixinForwarderCore.sol b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol similarity index 97% rename from contracts/extensions/contracts/Forwarder/MixinForwarderCore.sol rename to contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol index 11c0147a56..b65e1f7ce1 100644 --- a/contracts/extensions/contracts/Forwarder/MixinForwarderCore.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinForwarderCore.sol @@ -24,10 +24,10 @@ import "./mixins/MWeth.sol"; import "./mixins/MAssets.sol"; import "./mixins/MExchangeWrapper.sol"; import "./interfaces/IForwarderCore.sol"; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; contract MixinForwarderCore is diff --git a/contracts/extensions/contracts/Forwarder/MixinWeth.sol b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol similarity index 98% rename from contracts/extensions/contracts/Forwarder/MixinWeth.sol rename to contracts/exchange-forwarder/contracts/src/MixinWeth.sol index 25a35f47b0..029924019e 100644 --- a/contracts/extensions/contracts/Forwarder/MixinWeth.sol +++ b/contracts/exchange-forwarder/contracts/src/MixinWeth.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "./libs/LibConstants.sol"; import "./mixins/MWeth.sol"; diff --git a/contracts/extensions/contracts/Forwarder/interfaces/IAssets.sol b/contracts/exchange-forwarder/contracts/src/interfaces/IAssets.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/interfaces/IAssets.sol rename to contracts/exchange-forwarder/contracts/src/interfaces/IAssets.sol diff --git a/contracts/extensions/contracts/Forwarder/interfaces/IForwarder.sol b/contracts/exchange-forwarder/contracts/src/interfaces/IForwarder.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/interfaces/IForwarder.sol rename to contracts/exchange-forwarder/contracts/src/interfaces/IForwarder.sol diff --git a/contracts/extensions/contracts/Forwarder/interfaces/IForwarderCore.sol b/contracts/exchange-forwarder/contracts/src/interfaces/IForwarderCore.sol similarity index 96% rename from contracts/extensions/contracts/Forwarder/interfaces/IForwarderCore.sol rename to contracts/exchange-forwarder/contracts/src/interfaces/IForwarderCore.sol index 7f62722e77..00009d3d5f 100644 --- a/contracts/extensions/contracts/Forwarder/interfaces/IForwarderCore.sol +++ b/contracts/exchange-forwarder/contracts/src/interfaces/IForwarderCore.sol @@ -19,8 +19,8 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; contract IForwarderCore { diff --git a/contracts/extensions/contracts/Forwarder/libs/LibConstants.sol b/contracts/exchange-forwarder/contracts/src/libs/LibConstants.sol similarity index 86% rename from contracts/extensions/contracts/Forwarder/libs/LibConstants.sol rename to contracts/exchange-forwarder/contracts/src/libs/LibConstants.sol index 0d2f6e36d9..3ff2a03e5d 100644 --- a/contracts/extensions/contracts/Forwarder/libs/LibConstants.sol +++ b/contracts/exchange-forwarder/contracts/src/libs/LibConstants.sol @@ -18,10 +18,10 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-tokens/contracts/tokens/EtherToken/IEtherToken.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; contract LibConstants { diff --git a/contracts/extensions/contracts/Forwarder/libs/LibForwarderErrors.sol b/contracts/exchange-forwarder/contracts/src/libs/LibForwarderErrors.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/libs/LibForwarderErrors.sol rename to contracts/exchange-forwarder/contracts/src/libs/LibForwarderErrors.sol diff --git a/contracts/extensions/contracts/Forwarder/mixins/MAssets.sol b/contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/mixins/MAssets.sol rename to contracts/exchange-forwarder/contracts/src/mixins/MAssets.sol diff --git a/contracts/extensions/contracts/Forwarder/mixins/MExchangeWrapper.sol b/contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol similarity index 96% rename from contracts/extensions/contracts/Forwarder/mixins/MExchangeWrapper.sol rename to contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol index 143f888b1c..7439e8259e 100644 --- a/contracts/extensions/contracts/Forwarder/mixins/MExchangeWrapper.sol +++ b/contracts/exchange-forwarder/contracts/src/mixins/MExchangeWrapper.sol @@ -19,8 +19,8 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; contract MExchangeWrapper { diff --git a/contracts/extensions/contracts/Forwarder/mixins/MWeth.sol b/contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol similarity index 100% rename from contracts/extensions/contracts/Forwarder/mixins/MWeth.sol rename to contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol diff --git a/contracts/exchange-forwarder/package.json b/contracts/exchange-forwarder/package.json new file mode 100644 index 0000000000..7ec103746b --- /dev/null +++ b/contracts/exchange-forwarder/package.json @@ -0,0 +1,86 @@ +{ + "name": "@0x/contracts-exchange-forwarder", + "version": "1.0.0", + "engines": { + "node": ">=6.12" + }, + "description": "Smart contract extensions of 0x protocol", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "yarn pre_build && tsc -b", + "build:ci": "yarn build", + "pre_build": "run-s compile generate_contract_wrappers", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s build test", + "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", + "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", + "compile": "sol-compiler", + "watch": "sol-compiler -w", + "clean": "shx rm -rf lib generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "coverage:report:text": "istanbul report text", + "coverage:report:html": "istanbul report html && open coverage/index.html", + "profiler:report:html": "istanbul report html && open coverage/index.html", + "coverage:report:lcov": "istanbul report lcov", + "test:circleci": "yarn test", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" + }, + "config": { + "abis": "generated-artifacts/@(Forwarder).json" + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md", + "devDependencies": { + "@0x/abi-gen": "^1.0.22", + "@0x/contract-wrappers": "^5.0.1", + "@0x/contracts-test-utils": "^2.0.1", + "@0x/dev-utils": "^1.0.24", + "@0x/sol-compiler": "^2.0.2", + "@0x/tslint-config": "^2.0.2", + "@types/lodash": "4.14.104", + "@types/node": "*", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^3.0.0", + "dirty-chai": "^2.0.1", + "make-promises-safe": "^1.1.0", + "mocha": "^4.1.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solhint": "^1.4.1", + "tslint": "5.11.0", + "typescript": "3.0.1" + }, + "dependencies": { + "@0x/base-contract": "^3.0.13", + "@0x/contracts-asset-proxy": "^1.0.0", + "@0x/contracts-exchange-libs": "^1.0.0", + "@0x/contracts-exchange": "^1.0.0", + "@0x/contracts-erc20": "^1.0.0", + "@0x/contracts-erc721": "^1.0.0", + "@0x/contracts-utils": "^3.0.0", + "@0x/order-utils": "^3.1.2", + "@0x/types": "^1.5.2", + "@0x/typescript-typings": "^3.0.8", + "@0x/utils": "^3.0.1", + "@0x/web3-wrapper": "^3.2.4", + "ethereum-types": "^1.1.6", + "lodash": "^4.17.5" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/contracts/exchange-forwarder/src/artifacts/index.ts b/contracts/exchange-forwarder/src/artifacts/index.ts new file mode 100644 index 0000000000..f15dac49a4 --- /dev/null +++ b/contracts/exchange-forwarder/src/artifacts/index.ts @@ -0,0 +1,7 @@ +import { ContractArtifact } from 'ethereum-types'; + +import * as Forwarder from '../../generated-artifacts/Forwarder.json'; + +export const artifacts = { + Forwarder: Forwarder as ContractArtifact, +}; diff --git a/contracts/interfaces/src/index.ts b/contracts/exchange-forwarder/src/index.ts similarity index 64% rename from contracts/interfaces/src/index.ts rename to contracts/exchange-forwarder/src/index.ts index d55f08ea2d..ba813e7caf 100644 --- a/contracts/interfaces/src/index.ts +++ b/contracts/exchange-forwarder/src/index.ts @@ -1,2 +1,3 @@ export * from './artifacts'; export * from './wrappers'; +export * from '../test/utils'; diff --git a/contracts/exchange-forwarder/src/wrappers/index.ts b/contracts/exchange-forwarder/src/wrappers/index.ts new file mode 100644 index 0000000000..89dff9e746 --- /dev/null +++ b/contracts/exchange-forwarder/src/wrappers/index.ts @@ -0,0 +1 @@ +export * from '../../generated-wrappers/forwarder'; diff --git a/contracts/extensions/test/extensions/forwarder.ts b/contracts/exchange-forwarder/test/forwarder.ts similarity index 99% rename from contracts/extensions/test/extensions/forwarder.ts rename to contracts/exchange-forwarder/test/forwarder.ts index 69939ed04d..24c2195633 100644 --- a/contracts/extensions/test/extensions/forwarder.ts +++ b/contracts/exchange-forwarder/test/forwarder.ts @@ -1,10 +1,7 @@ -import { - artifacts as protocolArtifacts, - ERC20Wrapper, - ERC721Wrapper, - ExchangeContract, - ExchangeWrapper, -} from '@0x/contracts-protocol'; +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts, ExchangeContract, ExchangeWrapper } from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -18,12 +15,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokenArtifacts, - DummyERC20TokenContract, - DummyERC721TokenContract, - WETH9Contract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; @@ -32,10 +23,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; -import { ForwarderContract } from '../../generated-wrappers/forwarder'; -import { artifacts } from '../../src/artifacts'; - -import { ForwarderWrapper } from '../utils/forwarder_wrapper'; +import { artifacts, ForwarderContract, ForwarderWrapper } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -100,14 +88,14 @@ describe(ContractName.Forwarder, () => { const erc721Balances = await erc721Wrapper.getBalancesAsync(); erc721MakerAssetIds = erc721Balances[makerAddress][erc721Token.address]; - wethContract = await WETH9Contract.deployFrom0xArtifactAsync(tokenArtifacts.WETH9, provider, txDefaults); + wethContract = await WETH9Contract.deployFrom0xArtifactAsync(erc20Artifacts.WETH9, provider, txDefaults); weth = new DummyERC20TokenContract(wethContract.abi, wethContract.address, provider); erc20Wrapper.addDummyTokenContract(weth); wethAssetData = assetDataUtils.encodeERC20AssetData(wethContract.address); zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, zrxAssetData, @@ -178,7 +166,7 @@ describe(ContractName.Forwarder, () => { describe('constructor', () => { it('should revert if assetProxy is unregistered', async () => { const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, zrxAssetData, diff --git a/contracts/exchange-forwarder/test/global_hooks.ts b/contracts/exchange-forwarder/test/global_hooks.ts new file mode 100644 index 0000000000..f8ace376a5 --- /dev/null +++ b/contracts/exchange-forwarder/test/global_hooks.ts @@ -0,0 +1,17 @@ +import { env, EnvVars } from '@0x/dev-utils'; + +import { coverage, profiler, provider } from '@0x/contracts-test-utils'; +before('start web3 provider', () => { + provider.start(); +}); +after('generate coverage report', async () => { + if (env.parseBoolean(EnvVars.SolidityCoverage)) { + const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); + await coverageSubprovider.writeCoverageAsync(); + } + if (env.parseBoolean(EnvVars.SolidityProfiler)) { + const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); + await profilerSubprovider.writeProfilerOutputAsync(); + } + provider.stop(); +}); diff --git a/contracts/extensions/test/utils/forwarder_wrapper.ts b/contracts/exchange-forwarder/test/utils/forwarder_wrapper.ts similarity index 94% rename from contracts/extensions/test/utils/forwarder_wrapper.ts rename to contracts/exchange-forwarder/test/utils/forwarder_wrapper.ts index 4a43be04aa..2071068526 100644 --- a/contracts/extensions/test/utils/forwarder_wrapper.ts +++ b/contracts/exchange-forwarder/test/utils/forwarder_wrapper.ts @@ -1,6 +1,7 @@ -import { artifacts as protocolArtifacts } from '@0x/contracts-protocol'; +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; +import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange'; import { constants, formatters, LogDecoder, MarketSellOrders } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; @@ -62,8 +63,9 @@ export class ForwarderWrapper { this._web3Wrapper = new Web3Wrapper(provider); this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, - ...tokensArtifacts, - ...protocolArtifacts, + ...erc20Artifacts, + ...erc721Artifacts, + ...exchangeArtifacts, }); } public async marketSellOrdersWithEthAsync( diff --git a/contracts/exchange-forwarder/test/utils/index.ts b/contracts/exchange-forwarder/test/utils/index.ts new file mode 100644 index 0000000000..d290ec75d5 --- /dev/null +++ b/contracts/exchange-forwarder/test/utils/index.ts @@ -0,0 +1 @@ +export * from './forwarder_wrapper'; diff --git a/contracts/examples/tsconfig.json b/contracts/exchange-forwarder/tsconfig.json similarity index 55% rename from contracts/examples/tsconfig.json rename to contracts/exchange-forwarder/tsconfig.json index 63245da1e4..cd80b5a5fc 100644 --- a/contracts/examples/tsconfig.json +++ b/contracts/exchange-forwarder/tsconfig.json @@ -6,11 +6,6 @@ "resolveJsonModule": true }, "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], - "files": [ - "./generated-artifacts/ExchangeWrapper.json", - "./generated-artifacts/Validator.json", - "./generated-artifacts/Wallet.json", - "./generated-artifacts/Whitelist.json" - ], + "files": ["./generated-artifacts/Forwarder.json"], "exclude": ["./deploy/solc/solc_bin"] } diff --git a/contracts/protocol/tslint.json b/contracts/exchange-forwarder/tslint.json similarity index 100% rename from contracts/protocol/tslint.json rename to contracts/exchange-forwarder/tslint.json diff --git a/contracts/exchange-libs/CHANGELOG.json b/contracts/exchange-libs/CHANGELOG.json new file mode 100644 index 0000000000..cdaac93ea2 --- /dev/null +++ b/contracts/exchange-libs/CHANGELOG.json @@ -0,0 +1,15 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Rename contracts-libs to contracts-exchange-libs", + "pr": 1539 + }, + { + "note": "Move LibAddressArray contract to contracts-utils", + "pr": 1539 + } + ] + } +] diff --git a/contracts/libs/CHANGELOG.md b/contracts/exchange-libs/CHANGELOG.md similarity index 100% rename from contracts/libs/CHANGELOG.md rename to contracts/exchange-libs/CHANGELOG.md diff --git a/contracts/examples/README.md b/contracts/exchange-libs/README.md similarity index 54% rename from contracts/examples/README.md rename to contracts/exchange-libs/README.md index ca23d09741..696fb7f11c 100644 --- a/contracts/examples/README.md +++ b/contracts/exchange-libs/README.md @@ -1,11 +1,14 @@ -## Contract examples +## Exchange Libraries -Example smart contracts that interact with 0x protocol. +This package contains the implementations of various libraries and utilities used within the [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange) contract. These libraries may be useful when creating external contracts that interact with the `Exchange` contract. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contracts can be found in the [contracts](./contracts) directory. -This package contains example implementations of contracts that interact with the protocol but are _not_ intended for use in production. Examples include [filter](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#filter-contracts) contracts, a [Wallet](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#wallet) contract, and a [Validator](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#validator) contract, among others. +**Install** + +```bash +npm install @0x/contracts-exchange-libs --save +``` ## Contributing @@ -34,13 +37,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-examples yarn build +PKG=@0x/contracts-exchange-libs yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-examples yarn watch +PKG=@0x/contracts-exchange-libs yarn watch ``` ### Clean @@ -54,3 +57,13 @@ yarn clean ```bash yarn lint ``` + +### Run Tests + +```bash +yarn test +``` + +#### Testing options + +Contracts testing options like coverage, profiling, revert traces or backing node choosing - are described [here](../TESTING.md). diff --git a/contracts/libs/compiler.json b/contracts/exchange-libs/compiler.json similarity index 100% rename from contracts/libs/compiler.json rename to contracts/exchange-libs/compiler.json diff --git a/contracts/libs/contracts/libs/LibAbiEncoder.sol b/contracts/exchange-libs/contracts/src/LibAbiEncoder.sol similarity index 100% rename from contracts/libs/contracts/libs/LibAbiEncoder.sol rename to contracts/exchange-libs/contracts/src/LibAbiEncoder.sol diff --git a/contracts/libs/contracts/libs/LibAssetProxyErrors.sol b/contracts/exchange-libs/contracts/src/LibAssetProxyErrors.sol similarity index 100% rename from contracts/libs/contracts/libs/LibAssetProxyErrors.sol rename to contracts/exchange-libs/contracts/src/LibAssetProxyErrors.sol diff --git a/contracts/libs/contracts/libs/LibConstants.sol b/contracts/exchange-libs/contracts/src/LibConstants.sol similarity index 100% rename from contracts/libs/contracts/libs/LibConstants.sol rename to contracts/exchange-libs/contracts/src/LibConstants.sol diff --git a/contracts/libs/contracts/libs/LibEIP712.sol b/contracts/exchange-libs/contracts/src/LibEIP712.sol similarity index 100% rename from contracts/libs/contracts/libs/LibEIP712.sol rename to contracts/exchange-libs/contracts/src/LibEIP712.sol diff --git a/contracts/libs/contracts/libs/LibExchangeErrors.sol b/contracts/exchange-libs/contracts/src/LibExchangeErrors.sol similarity index 100% rename from contracts/libs/contracts/libs/LibExchangeErrors.sol rename to contracts/exchange-libs/contracts/src/LibExchangeErrors.sol diff --git a/contracts/libs/contracts/libs/LibExchangeSelectors.sol b/contracts/exchange-libs/contracts/src/LibExchangeSelectors.sol similarity index 100% rename from contracts/libs/contracts/libs/LibExchangeSelectors.sol rename to contracts/exchange-libs/contracts/src/LibExchangeSelectors.sol diff --git a/contracts/libs/contracts/libs/LibFillResults.sol b/contracts/exchange-libs/contracts/src/LibFillResults.sol similarity index 97% rename from contracts/libs/contracts/libs/LibFillResults.sol rename to contracts/exchange-libs/contracts/src/LibFillResults.sol index 74b7f79847..08a1649b86 100644 --- a/contracts/libs/contracts/libs/LibFillResults.sol +++ b/contracts/exchange-libs/contracts/src/LibFillResults.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; contract LibFillResults is diff --git a/contracts/libs/contracts/libs/LibMath.sol b/contracts/exchange-libs/contracts/src/LibMath.sol similarity index 99% rename from contracts/libs/contracts/libs/LibMath.sol rename to contracts/exchange-libs/contracts/src/LibMath.sol index f14b1b34de..24ea90c6b9 100644 --- a/contracts/libs/contracts/libs/LibMath.sol +++ b/contracts/exchange-libs/contracts/src/LibMath.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; contract LibMath is diff --git a/contracts/libs/contracts/libs/LibOrder.sol b/contracts/exchange-libs/contracts/src/LibOrder.sol similarity index 100% rename from contracts/libs/contracts/libs/LibOrder.sol rename to contracts/exchange-libs/contracts/src/LibOrder.sol diff --git a/contracts/libs/contracts/test/TestLibs/TestLibs.sol b/contracts/exchange-libs/contracts/test/TestLibs.sol similarity index 95% rename from contracts/libs/contracts/test/TestLibs/TestLibs.sol rename to contracts/exchange-libs/contracts/test/TestLibs.sol index bd5f9f9da8..751a3773ec 100644 --- a/contracts/libs/contracts/test/TestLibs/TestLibs.sol +++ b/contracts/exchange-libs/contracts/test/TestLibs.sol @@ -19,10 +19,10 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../libs/LibMath.sol"; -import "../../libs/LibOrder.sol"; -import "../../libs/LibFillResults.sol"; -import "../../libs/LibAbiEncoder.sol"; +import "../src/LibMath.sol"; +import "../src/LibOrder.sol"; +import "../src/LibFillResults.sol"; +import "../src/LibAbiEncoder.sol"; contract TestLibs is diff --git a/contracts/libs/package.json b/contracts/exchange-libs/package.json similarity index 87% rename from contracts/libs/package.json rename to contracts/exchange-libs/package.json index b28ec37742..9d35106cc0 100644 --- a/contracts/libs/package.json +++ b/contracts/exchange-libs/package.json @@ -1,6 +1,6 @@ { - "name": "@0x/contracts-libs", - "version": "1.0.6", + "name": "@0x/contracts-exchange-libs", + "version": "1.0.0", "engines": { "node": ">=6.12" }, @@ -48,39 +48,30 @@ "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-multisig": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", + "@0x/contracts-utils": "^3.0.0", "@0x/order-utils": "^3.1.2", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", - "@types/js-combinatorics": "^0.5.29", - "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", - "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" }, "publishConfig": { diff --git a/contracts/libs/src/artifacts/index.ts b/contracts/exchange-libs/src/artifacts/index.ts similarity index 100% rename from contracts/libs/src/artifacts/index.ts rename to contracts/exchange-libs/src/artifacts/index.ts diff --git a/contracts/examples/src/index.ts b/contracts/exchange-libs/src/index.ts similarity index 100% rename from contracts/examples/src/index.ts rename to contracts/exchange-libs/src/index.ts diff --git a/contracts/libs/src/wrappers/index.ts b/contracts/exchange-libs/src/wrappers/index.ts similarity index 100% rename from contracts/libs/src/wrappers/index.ts rename to contracts/exchange-libs/src/wrappers/index.ts diff --git a/contracts/libs/test/exchange/libs.ts b/contracts/exchange-libs/test/exchange_libs.ts similarity index 97% rename from contracts/libs/test/exchange/libs.ts rename to contracts/exchange-libs/test/exchange_libs.ts index 44ff6a844b..b613231895 100644 --- a/contracts/libs/test/exchange/libs.ts +++ b/contracts/exchange-libs/test/exchange_libs.ts @@ -13,8 +13,8 @@ import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; -import { TestLibsContract } from '../../generated-wrappers/test_libs'; -import { artifacts } from '../../src/artifacts'; +import { TestLibsContract } from '../generated-wrappers/test_libs'; +import { artifacts } from '../src/artifacts'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/exchange-libs/test/global_hooks.ts b/contracts/exchange-libs/test/global_hooks.ts new file mode 100644 index 0000000000..f8ace376a5 --- /dev/null +++ b/contracts/exchange-libs/test/global_hooks.ts @@ -0,0 +1,17 @@ +import { env, EnvVars } from '@0x/dev-utils'; + +import { coverage, profiler, provider } from '@0x/contracts-test-utils'; +before('start web3 provider', () => { + provider.start(); +}); +after('generate coverage report', async () => { + if (env.parseBoolean(EnvVars.SolidityCoverage)) { + const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); + await coverageSubprovider.writeCoverageAsync(); + } + if (env.parseBoolean(EnvVars.SolidityProfiler)) { + const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); + await profilerSubprovider.writeProfilerOutputAsync(); + } + provider.stop(); +}); diff --git a/contracts/libs/tsconfig.json b/contracts/exchange-libs/tsconfig.json similarity index 100% rename from contracts/libs/tsconfig.json rename to contracts/exchange-libs/tsconfig.json diff --git a/contracts/tokens/tslint.json b/contracts/exchange-libs/tslint.json similarity index 100% rename from contracts/tokens/tslint.json rename to contracts/exchange-libs/tslint.json diff --git a/contracts/exchange/CHANGELOG.json b/contracts/exchange/CHANGELOG.json new file mode 100644 index 0000000000..e4c7aa986b --- /dev/null +++ b/contracts/exchange/CHANGELOG.json @@ -0,0 +1,15 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Move Exchange contract out of contracts-protocol to new package", + "pr": 1539 + }, + { + "note": "Move example contracts out of contracts-examples to new package", + "pr": 1539 + } + ] + } +] diff --git a/contracts/exchange/CHANGELOG.md b/contracts/exchange/CHANGELOG.md new file mode 100644 index 0000000000..779eb68a71 --- /dev/null +++ b/contracts/exchange/CHANGELOG.md @@ -0,0 +1,28 @@ + + +CHANGELOG + +## v2.2.3 - _January 17, 2019_ + + * Dependencies updated + +## v2.2.2 - _January 15, 2019_ + + * Dependencies updated + +## v2.2.1 - _January 11, 2019_ + + * Dependencies updated + +## v2.2.0 - _January 9, 2019_ + + * Added LibAddressArray (#1383) + * Add validation and comments to MultiAssetProxy (#1455) + * Move OrderValidator to extensions (#1464) + +## v2.1.59 - _December 13, 2018_ + + * Dependencies updated diff --git a/contracts/exchange/DEPLOYS.json b/contracts/exchange/DEPLOYS.json new file mode 100644 index 0000000000..1e110d4f78 --- /dev/null +++ b/contracts/exchange/DEPLOYS.json @@ -0,0 +1,17 @@ +[ + { + "name": "Exchange", + "version": "2.0.0", + "changes": [ + { + "note": "protocol v2 deploy", + "networks": { + "1": "0x4f833a24e1f95d70f028921e27040ca56e09ab0b", + "3": "0x4530c0483a1633c7a1c97d2c53721caff2caaaaf", + "4": "0x22ebc052f43a88efa06379426120718170f2204e", + "42": "0x35dd2932454449b14cee11a94d3674a936d5d7b2" + } + } + ] + } +] diff --git a/contracts/exchange/README.md b/contracts/exchange/README.md new file mode 100644 index 0000000000..41997f84d0 --- /dev/null +++ b/contracts/exchange/README.md @@ -0,0 +1,73 @@ +## Exchange + +This package contains the implementation of the [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange). This contract is responsible for settling trades and is typically the entry point for all transactions that interact with the 0x protocol. Lightweight examples of how external contracts can interct with the `Exchange` contract can be found in the [examples](./contracts/examples) directory. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. + +## Installation + +**Install** + +```bash +npm install @0x/contracts-exchange --save +``` + +## Bug bounty + +A bug bounty for the 2.0.0 contracts is ongoing! Instructions can be found [here](https://0xproject.com/wiki#Bug-Bounty). + +## 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. + +For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein. + +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 + +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + +```bash +PKG=@0x/contracts-exchange yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-exchange yarn watch +``` + +### Clean + +```bash +yarn clean +``` + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` + +#### Testing options + +Contracts testing options like coverage, profiling, revert traces or backing node choosing - are described [here](../TESTING.md). diff --git a/contracts/interfaces/compiler.json b/contracts/exchange/compiler.json similarity index 73% rename from contracts/interfaces/compiler.json rename to contracts/exchange/compiler.json index 38a2325410..e53fce0ecd 100644 --- a/contracts/interfaces/compiler.json +++ b/contracts/exchange/compiler.json @@ -19,9 +19,7 @@ } }, "contracts": [ - "IAssetData", - "IAssetProxy", - "IAuthorizable", + "Exchange", "IAssetProxyDispatcher", "IExchange", "IExchangeCore", @@ -30,6 +28,14 @@ "ITransactions", "IValidator", "IWallet", - "IWrapperFunctions" + "IWrapperFunctions", + "TestAssetProxyDispatcher", + "TestExchangeInternals", + "TestSignatureValidator", + "TestStaticCallReceiver", + "ExchangeWrapper", + "Validator", + "Wallet", + "Whitelist" ] } diff --git a/contracts/examples/contracts/ExchangeWrapper/ExchangeWrapper.sol b/contracts/exchange/contracts/examples/ExchangeWrapper.sol similarity index 95% rename from contracts/examples/contracts/ExchangeWrapper/ExchangeWrapper.sol rename to contracts/exchange/contracts/examples/ExchangeWrapper.sol index d981369229..604f614b52 100644 --- a/contracts/examples/contracts/ExchangeWrapper/ExchangeWrapper.sol +++ b/contracts/exchange/contracts/examples/ExchangeWrapper.sol @@ -19,8 +19,8 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; +import "../src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; contract ExchangeWrapper { diff --git a/contracts/examples/contracts/Validator/Validator.sol b/contracts/exchange/contracts/examples/Validator.sol similarity index 95% rename from contracts/examples/contracts/Validator/Validator.sol rename to contracts/exchange/contracts/examples/Validator.sol index e488a9ca76..98a10d37f9 100644 --- a/contracts/examples/contracts/Validator/Validator.sol +++ b/contracts/exchange/contracts/examples/Validator.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IValidator.sol"; +import "../src/interfaces/IValidator.sol"; contract Validator is diff --git a/contracts/examples/contracts/Wallet/Wallet.sol b/contracts/exchange/contracts/examples/Wallet.sol similarity index 92% rename from contracts/examples/contracts/Wallet/Wallet.sol rename to contracts/exchange/contracts/examples/Wallet.sol index 8edc74eb3f..17e3dd5ccb 100644 --- a/contracts/examples/contracts/Wallet/Wallet.sol +++ b/contracts/exchange/contracts/examples/Wallet.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IWallet.sol"; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "../src/interfaces/IWallet.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; contract Wallet is diff --git a/contracts/examples/contracts/Whitelist/Whitelist.sol b/contracts/exchange/contracts/examples/Whitelist.sol similarity index 95% rename from contracts/examples/contracts/Whitelist/Whitelist.sol rename to contracts/exchange/contracts/examples/Whitelist.sol index 2a3d33738b..a9db1bb825 100644 --- a/contracts/examples/contracts/Whitelist/Whitelist.sol +++ b/contracts/exchange/contracts/examples/Whitelist.sol @@ -19,9 +19,9 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "../src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; contract Whitelist is diff --git a/contracts/protocol/contracts/protocol/Exchange/Exchange.sol b/contracts/exchange/contracts/src/Exchange.sol similarity index 95% rename from contracts/protocol/contracts/protocol/Exchange/Exchange.sol rename to contracts/exchange/contracts/src/Exchange.sol index 65ca742eab..541750518d 100644 --- a/contracts/protocol/contracts/protocol/Exchange/Exchange.sol +++ b/contracts/exchange/contracts/src/Exchange.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibConstants.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibConstants.sol"; import "./MixinExchangeCore.sol"; import "./MixinSignatureValidator.sol"; import "./MixinWrapperFunctions.sol"; diff --git a/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol b/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol new file mode 100644 index 0000000000..c55d6aaec3 --- /dev/null +++ b/contracts/exchange/contracts/src/MixinAssetProxyDispatcher.sol @@ -0,0 +1,174 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; + +import "@0x/contracts-utils/contracts/src/Ownable.sol"; +import "./mixins/MAssetProxyDispatcher.sol"; +import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol"; + + +contract MixinAssetProxyDispatcher is + Ownable, + MAssetProxyDispatcher +{ + // Mapping from Asset Proxy Id's to their respective Asset Proxy + mapping (bytes4 => IAssetProxy) public assetProxies; + + /// @dev Registers an asset proxy to its asset proxy id. + /// Once an asset proxy is registered, it cannot be unregistered. + /// @param assetProxy Address of new asset proxy to register. + function registerAssetProxy(address assetProxy) + external + onlyOwner + { + IAssetProxy assetProxyContract = IAssetProxy(assetProxy); + + // Ensure that no asset proxy exists with current id. + bytes4 assetProxyId = assetProxyContract.getProxyId(); + address currentAssetProxy = assetProxies[assetProxyId]; + require( + currentAssetProxy == address(0), + "ASSET_PROXY_ALREADY_EXISTS" + ); + + // Add asset proxy and log registration. + assetProxies[assetProxyId] = assetProxyContract; + emit AssetProxyRegistered( + assetProxyId, + assetProxy + ); + } + + /// @dev Gets an asset proxy. + /// @param assetProxyId Id of the asset proxy. + /// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered. + function getAssetProxy(bytes4 assetProxyId) + external + view + returns (address) + { + return assetProxies[assetProxyId]; + } + + /// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws. + /// @param assetData Byte array encoded for the asset. + /// @param from Address to transfer token from. + /// @param to Address to transfer token to. + /// @param amount Amount of token to transfer. + function dispatchTransferFrom( + bytes memory assetData, + address from, + address to, + uint256 amount + ) + internal + { + // Do nothing if no amount should be transferred. + if (amount > 0 && from != to) { + // Ensure assetData length is valid + require( + assetData.length > 3, + "LENGTH_GREATER_THAN_3_REQUIRED" + ); + + // Lookup assetProxy. We do not use `LibBytes.readBytes4` for gas efficiency reasons. + bytes4 assetProxyId; + assembly { + assetProxyId := and(mload( + add(assetData, 32)), + 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000 + ) + } + address assetProxy = assetProxies[assetProxyId]; + + // Ensure that assetProxy exists + require( + assetProxy != address(0), + "ASSET_PROXY_DOES_NOT_EXIST" + ); + + // We construct calldata for the `assetProxy.transferFrom` ABI. + // The layout of this calldata is in the table below. + // + // | Area | Offset | Length | Contents | + // | -------- |--------|---------|-------------------------------------------- | + // | Header | 0 | 4 | function selector | + // | Params | | 4 * 32 | function parameters: | + // | | 4 | | 1. offset to assetData (*) | + // | | 36 | | 2. from | + // | | 68 | | 3. to | + // | | 100 | | 4. amount | + // | Data | | | assetData: | + // | | 132 | 32 | assetData Length | + // | | 164 | ** | assetData Contents | + + assembly { + /////// Setup State /////// + // `cdStart` is the start of the calldata for `assetProxy.transferFrom` (equal to free memory ptr). + let cdStart := mload(64) + // `dataAreaLength` is the total number of words needed to store `assetData` + // As-per the ABI spec, this value is padded up to the nearest multiple of 32, + // and includes 32-bytes for length. + let dataAreaLength := and(add(mload(assetData), 63), 0xFFFFFFFFFFFE0) + // `cdEnd` is the end of the calldata for `assetProxy.transferFrom`. + let cdEnd := add(cdStart, add(132, dataAreaLength)) + + + /////// Setup Header Area /////// + // This area holds the 4-byte `transferFromSelector`. + // bytes4(keccak256("transferFrom(bytes,address,address,uint256)")) = 0xa85e59e4 + mstore(cdStart, 0xa85e59e400000000000000000000000000000000000000000000000000000000) + + /////// Setup Params Area /////// + // Each parameter is padded to 32-bytes. The entire Params Area is 128 bytes. + // Notes: + // 1. The offset to `assetData` is the length of the Params Area (128 bytes). + // 2. A 20-byte mask is applied to addresses to zero-out the unused bytes. + mstore(add(cdStart, 4), 128) + mstore(add(cdStart, 36), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) + mstore(add(cdStart, 68), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) + mstore(add(cdStart, 100), amount) + + /////// Setup Data Area /////// + // This area holds `assetData`. + let dataArea := add(cdStart, 132) + // solhint-disable-next-line no-empty-blocks + for {} lt(dataArea, cdEnd) {} { + mstore(dataArea, mload(assetData)) + dataArea := add(dataArea, 32) + assetData := add(assetData, 32) + } + + /////// Call `assetProxy.transferFrom` using the constructed calldata /////// + let success := call( + gas, // forward all gas + assetProxy, // call address of asset proxy + 0, // don't send any ETH + cdStart, // pointer to start of input + sub(cdEnd, cdStart), // length of input + cdStart, // write output over input + 512 // reserve 512 bytes for output + ) + if iszero(success) { + revert(cdStart, returndatasize()) + } + } + } + } +} diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinExchangeCore.sol b/contracts/exchange/contracts/src/MixinExchangeCore.sol similarity index 98% rename from contracts/protocol/contracts/protocol/Exchange/MixinExchangeCore.sol rename to contracts/exchange/contracts/src/MixinExchangeCore.sol index 72bcebc626..2e4f717c99 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinExchangeCore.sol +++ b/contracts/exchange/contracts/src/MixinExchangeCore.sol @@ -19,11 +19,11 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; -import "@0x/contracts-libs/contracts/libs/LibConstants.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; +import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibConstants.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "./mixins/MExchangeCore.sol"; import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinMatchOrders.sol b/contracts/exchange/contracts/src/MixinMatchOrders.sol similarity index 97% rename from contracts/protocol/contracts/protocol/Exchange/MixinMatchOrders.sol rename to contracts/exchange/contracts/src/MixinMatchOrders.sol index 2627b82fd1..e848427938 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinMatchOrders.sol +++ b/contracts/exchange/contracts/src/MixinMatchOrders.sol @@ -14,11 +14,11 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; -import "@0x/contracts-libs/contracts/libs/LibConstants.sol"; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibConstants.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; import "./mixins/MExchangeCore.sol"; import "./mixins/MMatchOrders.sol"; import "./mixins/MTransactions.sol"; diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinSignatureValidator.sol b/contracts/exchange/contracts/src/MixinSignatureValidator.sol similarity index 97% rename from contracts/protocol/contracts/protocol/Exchange/MixinSignatureValidator.sol rename to contracts/exchange/contracts/src/MixinSignatureValidator.sol index b40aa14127..421ec666ae 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinSignatureValidator.sol +++ b/contracts/exchange/contracts/src/MixinSignatureValidator.sol @@ -18,12 +18,12 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IWallet.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IValidator.sol"; +import "./interfaces/IWallet.sol"; +import "./interfaces/IValidator.sol"; contract MixinSignatureValidator is diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinTransactions.sol b/contracts/exchange/contracts/src/MixinTransactions.sol similarity index 97% rename from contracts/protocol/contracts/protocol/Exchange/MixinTransactions.sol rename to contracts/exchange/contracts/src/MixinTransactions.sol index 1ac5b1a5ed..6b9b06b0d1 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinTransactions.sol +++ b/contracts/exchange/contracts/src/MixinTransactions.sol @@ -17,10 +17,10 @@ */ pragma solidity ^0.4.24; -import "@0x/contracts-libs/contracts/libs/LibExchangeErrors.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibExchangeErrors.sol"; import "./mixins/MSignatureValidator.sol"; import "./mixins/MTransactions.sol"; -import "@0x/contracts-libs/contracts/libs/LibEIP712.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibEIP712.sol"; contract MixinTransactions is diff --git a/contracts/protocol/contracts/protocol/Exchange/MixinWrapperFunctions.sol b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol similarity index 98% rename from contracts/protocol/contracts/protocol/Exchange/MixinWrapperFunctions.sol rename to contracts/exchange/contracts/src/MixinWrapperFunctions.sol index 6fc6ee999d..911107422e 100644 --- a/contracts/protocol/contracts/protocol/Exchange/MixinWrapperFunctions.sol +++ b/contracts/exchange/contracts/src/MixinWrapperFunctions.sol @@ -19,11 +19,11 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol"; -import "@0x/contracts-libs/contracts/libs/LibMath.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-libs/contracts/libs/LibAbiEncoder.sol"; +import "@0x/contracts-utils/contracts/src/ReentrancyGuard.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibAbiEncoder.sol"; import "./mixins/MExchangeCore.sol"; import "./mixins/MWrapperFunctions.sol"; diff --git a/contracts/exchange/contracts/src/interfaces/IAssetProxyDispatcher.sol b/contracts/exchange/contracts/src/interfaces/IAssetProxyDispatcher.sol new file mode 100644 index 0000000000..b73881c077 --- /dev/null +++ b/contracts/exchange/contracts/src/interfaces/IAssetProxyDispatcher.sol @@ -0,0 +1,37 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; + + +contract IAssetProxyDispatcher { + + /// @dev Registers an asset proxy to its asset proxy id. + /// Once an asset proxy is registered, it cannot be unregistered. + /// @param assetProxy Address of new asset proxy to register. + function registerAssetProxy(address assetProxy) + external; + + /// @dev Gets an asset proxy. + /// @param assetProxyId Id of the asset proxy. + /// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered. + function getAssetProxy(bytes4 assetProxyId) + external + view + returns (address); +} diff --git a/contracts/interfaces/contracts/protocol/Exchange/IExchange.sol b/contracts/exchange/contracts/src/interfaces/IExchange.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/IExchange.sol rename to contracts/exchange/contracts/src/interfaces/IExchange.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/IExchangeCore.sol b/contracts/exchange/contracts/src/interfaces/IExchangeCore.sol similarity index 94% rename from contracts/interfaces/contracts/protocol/Exchange/IExchangeCore.sol rename to contracts/exchange/contracts/src/interfaces/IExchangeCore.sol index ab4a624082..f87abb2ad4 100644 --- a/contracts/interfaces/contracts/protocol/Exchange/IExchangeCore.sol +++ b/contracts/exchange/contracts/src/interfaces/IExchangeCore.sol @@ -19,8 +19,8 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; contract IExchangeCore { diff --git a/contracts/interfaces/contracts/protocol/Exchange/IMatchOrders.sol b/contracts/exchange/contracts/src/interfaces/IMatchOrders.sol similarity index 92% rename from contracts/interfaces/contracts/protocol/Exchange/IMatchOrders.sol rename to contracts/exchange/contracts/src/interfaces/IMatchOrders.sol index 5df46ea802..fba1da6d90 100644 --- a/contracts/interfaces/contracts/protocol/Exchange/IMatchOrders.sol +++ b/contracts/exchange/contracts/src/interfaces/IMatchOrders.sol @@ -18,8 +18,8 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; contract IMatchOrders { diff --git a/contracts/interfaces/contracts/protocol/Exchange/ISignatureValidator.sol b/contracts/exchange/contracts/src/interfaces/ISignatureValidator.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/ISignatureValidator.sol rename to contracts/exchange/contracts/src/interfaces/ISignatureValidator.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/ITransactions.sol b/contracts/exchange/contracts/src/interfaces/ITransactions.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/ITransactions.sol rename to contracts/exchange/contracts/src/interfaces/ITransactions.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/IValidator.sol b/contracts/exchange/contracts/src/interfaces/IValidator.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/IValidator.sol rename to contracts/exchange/contracts/src/interfaces/IValidator.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/IWallet.sol b/contracts/exchange/contracts/src/interfaces/IWallet.sol similarity index 100% rename from contracts/interfaces/contracts/protocol/Exchange/IWallet.sol rename to contracts/exchange/contracts/src/interfaces/IWallet.sol diff --git a/contracts/interfaces/contracts/protocol/Exchange/IWrapperFunctions.sol b/contracts/exchange/contracts/src/interfaces/IWrapperFunctions.sol similarity index 98% rename from contracts/interfaces/contracts/protocol/Exchange/IWrapperFunctions.sol rename to contracts/exchange/contracts/src/interfaces/IWrapperFunctions.sol index 0eeaa874bd..b1afc8895f 100644 --- a/contracts/interfaces/contracts/protocol/Exchange/IWrapperFunctions.sol +++ b/contracts/exchange/contracts/src/interfaces/IWrapperFunctions.sol @@ -19,8 +19,8 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; contract IWrapperFunctions { diff --git a/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol b/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol new file mode 100644 index 0000000000..0ae555ddad --- /dev/null +++ b/contracts/exchange/contracts/src/mixins/MAssetProxyDispatcher.sol @@ -0,0 +1,45 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.24; + +import "../interfaces/IAssetProxyDispatcher.sol"; + + +contract MAssetProxyDispatcher is + IAssetProxyDispatcher +{ + // Logs registration of new asset proxy + event AssetProxyRegistered( + bytes4 id, // Id of new registered AssetProxy. + address assetProxy // Address of new registered AssetProxy. + ); + + /// @dev Forwards arguments to assetProxy and calls `transferFrom`. Either succeeds or throws. + /// @param assetData Byte array encoded for the asset. + /// @param from Address to transfer token from. + /// @param to Address to transfer token to. + /// @param amount Amount of token to transfer. + function dispatchTransferFrom( + bytes memory assetData, + address from, + address to, + uint256 amount + ) + internal; +} diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MExchangeCore.sol b/contracts/exchange/contracts/src/mixins/MExchangeCore.sol similarity index 97% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MExchangeCore.sol rename to contracts/exchange/contracts/src/mixins/MExchangeCore.sol index 09dc491cd1..b5a9c660b5 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MExchangeCore.sol +++ b/contracts/exchange/contracts/src/mixins/MExchangeCore.sol @@ -19,9 +19,9 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchangeCore.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "../interfaces/IExchangeCore.sol"; contract MExchangeCore is diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MMatchOrders.sol b/contracts/exchange/contracts/src/mixins/MMatchOrders.sol similarity index 91% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MMatchOrders.sol rename to contracts/exchange/contracts/src/mixins/MMatchOrders.sol index 56ee895c4b..3dcc9f31b4 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MMatchOrders.sol +++ b/contracts/exchange/contracts/src/mixins/MMatchOrders.sol @@ -18,9 +18,9 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IMatchOrders.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "../interfaces/IMatchOrders.sol"; contract MMatchOrders is diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MSignatureValidator.sol b/contracts/exchange/contracts/src/mixins/MSignatureValidator.sol similarity index 96% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MSignatureValidator.sol rename to contracts/exchange/contracts/src/mixins/MSignatureValidator.sol index 6407760d4d..c39e84e08e 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MSignatureValidator.sol +++ b/contracts/exchange/contracts/src/mixins/MSignatureValidator.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/ISignatureValidator.sol"; +import "../interfaces/ISignatureValidator.sol"; contract MSignatureValidator is diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MTransactions.sol b/contracts/exchange/contracts/src/mixins/MTransactions.sol similarity index 96% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MTransactions.sol rename to contracts/exchange/contracts/src/mixins/MTransactions.sol index 04dd716d70..04a25ccf36 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MTransactions.sol +++ b/contracts/exchange/contracts/src/mixins/MTransactions.sol @@ -17,7 +17,7 @@ */ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/ITransactions.sol"; +import "../interfaces/ITransactions.sol"; contract MTransactions is diff --git a/contracts/protocol/contracts/protocol/Exchange/mixins/MWrapperFunctions.sol b/contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol similarity index 85% rename from contracts/protocol/contracts/protocol/Exchange/mixins/MWrapperFunctions.sol rename to contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol index 2ff3b87909..df50c6a8e8 100644 --- a/contracts/protocol/contracts/protocol/Exchange/mixins/MWrapperFunctions.sol +++ b/contracts/exchange/contracts/src/mixins/MWrapperFunctions.sol @@ -19,9 +19,9 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IWrapperFunctions.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "../interfaces/IWrapperFunctions.sol"; contract MWrapperFunctions is diff --git a/contracts/protocol/contracts/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol b/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol similarity index 93% rename from contracts/protocol/contracts/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol rename to contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol index ad71fc9a1d..88155c6ee2 100644 --- a/contracts/protocol/contracts/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol +++ b/contracts/exchange/contracts/test/TestAssetProxyDispatcher.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol"; +import "../src/MixinAssetProxyDispatcher.sol"; contract TestAssetProxyDispatcher is diff --git a/contracts/protocol/contracts/test/TestExchangeInternals/TestExchangeInternals.sol b/contracts/exchange/contracts/test/TestExchangeInternals.sol similarity index 99% rename from contracts/protocol/contracts/test/TestExchangeInternals/TestExchangeInternals.sol rename to contracts/exchange/contracts/test/TestExchangeInternals.sol index 27187f8f8e..dce8e03c0f 100644 --- a/contracts/protocol/contracts/test/TestExchangeInternals/TestExchangeInternals.sol +++ b/contracts/exchange/contracts/test/TestExchangeInternals.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "../../protocol/Exchange/Exchange.sol"; +import "../src/Exchange.sol"; // solhint-disable no-empty-blocks diff --git a/contracts/protocol/contracts/test/TestSignatureValidator/TestSignatureValidator.sol b/contracts/exchange/contracts/test/TestSignatureValidator.sol similarity index 89% rename from contracts/protocol/contracts/test/TestSignatureValidator/TestSignatureValidator.sol rename to contracts/exchange/contracts/test/TestSignatureValidator.sol index ea3e2de591..2f95236661 100644 --- a/contracts/protocol/contracts/test/TestSignatureValidator/TestSignatureValidator.sol +++ b/contracts/exchange/contracts/test/TestSignatureValidator.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "../../protocol/Exchange/MixinSignatureValidator.sol"; -import "../../protocol/Exchange/MixinTransactions.sol"; +import "../src/MixinSignatureValidator.sol"; +import "../src/MixinTransactions.sol"; contract TestSignatureValidator is diff --git a/contracts/protocol/contracts/test/TestStaticCallReceiver/TestStaticCallReceiver.sol b/contracts/exchange/contracts/test/TestStaticCallReceiver.sol similarity index 96% rename from contracts/protocol/contracts/test/TestStaticCallReceiver/TestStaticCallReceiver.sol rename to contracts/exchange/contracts/test/TestStaticCallReceiver.sol index d08da73037..23e60b387c 100644 --- a/contracts/protocol/contracts/test/TestStaticCallReceiver/TestStaticCallReceiver.sol +++ b/contracts/exchange/contracts/test/TestStaticCallReceiver.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; // solhint-disable no-unused-vars diff --git a/contracts/protocol/package.json b/contracts/exchange/package.json similarity index 79% rename from contracts/protocol/package.json rename to contracts/exchange/package.json index d1ef70a707..9d7db18627 100644 --- a/contracts/protocol/package.json +++ b/contracts/exchange/package.json @@ -1,6 +1,6 @@ { - "name": "@0x/contracts-protocol", - "version": "2.2.3", + "name": "@0x/contracts-exchange", + "version": "1.0.0", "engines": { "node": ">=6.12" }, @@ -32,7 +32,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(AssetProxyOwner|ERC20Proxy|ERC721Proxy|Exchange|MixinAuthorizable|MultiAssetProxy|TestSignatureValidator|TestAssetProxyOwner|TestAssetProxyDispatcher|TestExchangeInternals|TestStaticCallReceiver).json" + "abis": "generated-artifacts/@(ERC20Proxy|ERC721Proxy|Exchange|IAssetProxyDispatcher|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IWrapperFunctions|IValidator|IWallet|MixinAuthorizable|MultiAssetProxy|TestSignatureValidator|TestAssetProxyDispatcher|TestExchangeInternals|TestStaticCallReceiver|ExchangeWrapper|Validator|Wallet|Whitelist).json" }, "repository": { "type": "git", @@ -47,42 +47,34 @@ "@0x/abi-gen": "^1.0.22", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-examples": "^1.0.6", - "@0x/contracts-interfaces": "^1.0.6", - "@0x/contracts-libs": "^1.0.6", - "@0x/contracts-multisig": "^1.0.6", + "@0x/contracts-asset-proxy": "^1.0.0", + "@0x/contracts-exchange-libs": "^1.0.0", "@0x/contracts-test-utils": "^2.0.1", - "@0x/contracts-tokens": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", + "@0x/contracts-erc20": "^1.0.0", + "@0x/contracts-erc721": "^1.0.0", + "@0x/contracts-utils": "^3.0.0", "@0x/order-utils": "^3.1.2", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", - "@types/js-combinatorics": "^0.5.29", - "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" diff --git a/contracts/interfaces/src/artifacts/index.ts b/contracts/exchange/src/artifacts/index.ts similarity index 50% rename from contracts/interfaces/src/artifacts/index.ts rename to contracts/exchange/src/artifacts/index.ts index 5a2a37d8a5..798ff17abb 100644 --- a/contracts/interfaces/src/artifacts/index.ts +++ b/contracts/exchange/src/artifacts/index.ts @@ -1,9 +1,8 @@ import { ContractArtifact } from 'ethereum-types'; -import * as IAssetData from '../../generated-artifacts/IAssetData.json'; -import * as IAssetProxy from '../../generated-artifacts/IAssetProxy.json'; +import * as Exchange from '../../generated-artifacts/Exchange.json'; +import * as ExchangeWrapper from '../../generated-artifacts/ExchangeWrapper.json'; import * as IAssetProxyDispatcher from '../../generated-artifacts/IAssetProxyDispatcher.json'; -import * as IAuthorizable from '../../generated-artifacts/IAuthorizable.json'; import * as IExchange from '../../generated-artifacts/IExchange.json'; import * as IExchangeCore from '../../generated-artifacts/IExchangeCore.json'; import * as IMatchOrders from '../../generated-artifacts/IMatchOrders.json'; @@ -12,18 +11,31 @@ import * as ITransactions from '../../generated-artifacts/ITransactions.json'; import * as IValidator from '../../generated-artifacts/IValidator.json'; import * as IWallet from '../../generated-artifacts/IWallet.json'; import * as IWrapperFunctions from '../../generated-artifacts/IWrapperFunctions.json'; +import * as TestAssetProxyDispatcher from '../../generated-artifacts/TestAssetProxyDispatcher.json'; +import * as TestExchangeInternals from '../../generated-artifacts/TestExchangeInternals.json'; +import * as TestSignatureValidator from '../../generated-artifacts/TestSignatureValidator.json'; +import * as TestStaticCallReceiver from '../../generated-artifacts/TestStaticCallReceiver.json'; +import * as Validator from '../../generated-artifacts/Validator.json'; +import * as Wallet from '../../generated-artifacts/Wallet.json'; +import * as Whitelist from '../../generated-artifacts/Whitelist.json'; export const artifacts = { - IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact, - IAuthorizable: IAuthorizable as ContractArtifact, + Exchange: Exchange as ContractArtifact, + TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact, + TestExchangeInternals: TestExchangeInternals as ContractArtifact, + TestSignatureValidator: TestSignatureValidator as ContractArtifact, + TestStaticCallReceiver: TestStaticCallReceiver as ContractArtifact, IExchange: IExchange as ContractArtifact, IExchangeCore: IExchangeCore as ContractArtifact, IMatchOrders: IMatchOrders as ContractArtifact, ISignatureValidator: ISignatureValidator as ContractArtifact, ITransactions: ITransactions as ContractArtifact, IWrapperFunctions: IWrapperFunctions as ContractArtifact, - IAssetData: IAssetData as ContractArtifact, - IAssetProxy: IAssetProxy as ContractArtifact, + IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact, IValidator: IValidator as ContractArtifact, IWallet: IWallet as ContractArtifact, + ExchangeWrapper: ExchangeWrapper as ContractArtifact, + Validator: Validator as ContractArtifact, + Wallet: Wallet as ContractArtifact, + Whitelist: Whitelist as ContractArtifact, }; diff --git a/contracts/exchange/src/index.ts b/contracts/exchange/src/index.ts new file mode 100644 index 0000000000..ba813e7caf --- /dev/null +++ b/contracts/exchange/src/index.ts @@ -0,0 +1,3 @@ +export * from './artifacts'; +export * from './wrappers'; +export * from '../test/utils'; diff --git a/contracts/exchange/src/wrappers/index.ts b/contracts/exchange/src/wrappers/index.ts new file mode 100644 index 0000000000..86e939b568 --- /dev/null +++ b/contracts/exchange/src/wrappers/index.ts @@ -0,0 +1,18 @@ +export * from '../../generated-wrappers/exchange'; +export * from '../../generated-wrappers/test_asset_proxy_dispatcher'; +export * from '../../generated-wrappers/test_exchange_internals'; +export * from '../../generated-wrappers/test_signature_validator'; +export * from '../../generated-wrappers/test_static_call_receiver'; +export * from '../../generated-wrappers/i_asset_proxy_dispatcher'; +export * from '../../generated-wrappers/i_exchange'; +export * from '../../generated-wrappers/i_exchange_core'; +export * from '../../generated-wrappers/i_match_orders'; +export * from '../../generated-wrappers/i_signature_validator'; +export * from '../../generated-wrappers/i_transactions'; +export * from '../../generated-wrappers/i_wrapper_functions'; +export * from '../../generated-wrappers/i_validator'; +export * from '../../generated-wrappers/i_wallet'; +export * from '../../generated-wrappers/exchange_wrapper'; +export * from '../../generated-wrappers/validator'; +export * from '../../generated-wrappers/wallet'; +export * from '../../generated-wrappers/whitelist'; diff --git a/contracts/protocol/test/exchange/core.ts b/contracts/exchange/test/core.ts similarity index 98% rename from contracts/protocol/test/exchange/core.ts rename to contracts/exchange/test/core.ts index f88be1c94a..74161cc73e 100644 --- a/contracts/protocol/test/exchange/core.ts +++ b/contracts/exchange/test/core.ts @@ -1,3 +1,19 @@ +import { + artifacts as proxyArtifacts, + ERC20ProxyContract, + ERC20Wrapper, + ERC721ProxyContract, + ERC721Wrapper, + MultiAssetProxyContract, +} from '@0x/contracts-asset-proxy'; +import { + artifacts as erc20Artifacts, + DummyERC20TokenContract, + DummyERC20TokenTransferEventArgs, + DummyNoReturnERC20TokenContract, + ReentrantERC20TokenContract, +} from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; import { chaiSetup, constants, @@ -11,14 +27,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokensArtifacts, - DummyERC20TokenContract, - DummyERC20TokenTransferEventArgs, - DummyERC721TokenContract, - DummyNoReturnERC20TokenContract, - ReentrantERC20TokenContract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { RevertReason, SignatureType, SignedOrder } from '@0x/types'; @@ -29,15 +37,13 @@ import { LogWithDecodedArgs } from 'ethereum-types'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy'; -import { ExchangeCancelEventArgs, ExchangeContract } from '../../generated-wrappers/exchange'; -import { MultiAssetProxyContract } from '../../generated-wrappers/multi_asset_proxy'; -import { TestStaticCallReceiverContract } from '../../generated-wrappers/test_static_call_receiver'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ERC721Wrapper } from '../utils/erc721_wrapper'; -import { ExchangeWrapper } from '../utils/exchange_wrapper'; +import { + artifacts, + ExchangeCancelEventArgs, + ExchangeContract, + ExchangeWrapper, + TestStaticCallReceiverContract, +} from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -92,7 +98,7 @@ describe('Exchange core', () => { erc20Proxy = await erc20Wrapper.deployProxyAsync(); erc721Proxy = await erc721Wrapper.deployProxyAsync(); multiAssetProxy = await MultiAssetProxyContract.deployFrom0xArtifactAsync( - artifacts.MultiAssetProxy, + proxyArtifacts.MultiAssetProxy, provider, txDefaults, ); @@ -114,7 +120,7 @@ describe('Exchange core', () => { txDefaults, ); reentrantErc20Token = await ReentrantERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.ReentrantERC20Token, + erc20Artifacts.ReentrantERC20Token, provider, txDefaults, exchange.address, @@ -339,7 +345,7 @@ describe('Exchange core', () => { describe('Testing exchange of ERC20 tokens with no return values', () => { before(async () => { noReturnErc20Token = await DummyNoReturnERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.DummyNoReturnERC20Token, + erc20Artifacts.DummyNoReturnERC20Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, diff --git a/contracts/protocol/test/exchange/dispatcher.ts b/contracts/exchange/test/dispatcher.ts similarity index 96% rename from contracts/protocol/test/exchange/dispatcher.ts rename to contracts/exchange/test/dispatcher.ts index eca1b38f18..a257559365 100644 --- a/contracts/protocol/test/exchange/dispatcher.ts +++ b/contracts/exchange/test/dispatcher.ts @@ -1,3 +1,11 @@ +import { + artifacts as proxyArtifacts, + ERC20ProxyContract, + ERC20Wrapper, + ERC721ProxyContract, + ERC721Wrapper, +} from '@0x/contracts-asset-proxy'; +import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { chaiSetup, constants, @@ -7,7 +15,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { DummyERC20TokenContract } from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { AssetProxyId, RevertReason } from '@0x/types'; @@ -16,15 +23,11 @@ import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy'; import { + artifacts, TestAssetProxyDispatcherAssetProxyRegisteredEventArgs, TestAssetProxyDispatcherContract, -} from '../../generated-wrappers/test_asset_proxy_dispatcher'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ERC721Wrapper } from '../utils/erc721_wrapper'; +} from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -128,7 +131,7 @@ describe('AssetProxyDispatcher', () => { expect(proxyAddress).to.be.equal(erc20Proxy.address); // Deploy a new version of the ERC20 Transfer Proxy contract const newErc20TransferProxy = await ERC20ProxyContract.deployFrom0xArtifactAsync( - artifacts.ERC20Proxy, + proxyArtifacts.ERC20Proxy, provider, txDefaults, ); diff --git a/contracts/protocol/test/exchange/fill_order.ts b/contracts/exchange/test/fill_order.ts similarity index 99% rename from contracts/protocol/test/exchange/fill_order.ts rename to contracts/exchange/test/fill_order.ts index 2bdbe4855d..3f54091d4c 100644 --- a/contracts/protocol/test/exchange/fill_order.ts +++ b/contracts/exchange/test/fill_order.ts @@ -16,10 +16,7 @@ import { import { BlockchainLifecycle } from '@0x/dev-utils'; import * as _ from 'lodash'; -import { - FillOrderCombinatorialUtils, - fillOrderCombinatorialUtilsFactoryAsync, -} from '../utils/fill_order_combinatorial_utils'; +import { FillOrderCombinatorialUtils, fillOrderCombinatorialUtilsFactoryAsync } from '../src'; chaiSetup.configure(); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); diff --git a/contracts/exchange/test/global_hooks.ts b/contracts/exchange/test/global_hooks.ts new file mode 100644 index 0000000000..f8ace376a5 --- /dev/null +++ b/contracts/exchange/test/global_hooks.ts @@ -0,0 +1,17 @@ +import { env, EnvVars } from '@0x/dev-utils'; + +import { coverage, profiler, provider } from '@0x/contracts-test-utils'; +before('start web3 provider', () => { + provider.start(); +}); +after('generate coverage report', async () => { + if (env.parseBoolean(EnvVars.SolidityCoverage)) { + const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); + await coverageSubprovider.writeCoverageAsync(); + } + if (env.parseBoolean(EnvVars.SolidityProfiler)) { + const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); + await profilerSubprovider.writeProfilerOutputAsync(); + } + provider.stop(); +}); diff --git a/contracts/protocol/test/exchange/internal.ts b/contracts/exchange/test/internal.ts similarity index 99% rename from contracts/protocol/test/exchange/internal.ts rename to contracts/exchange/test/internal.ts index 6ff1fdc2f8..7a1e12a7a1 100644 --- a/contracts/protocol/test/exchange/internal.ts +++ b/contracts/exchange/test/internal.ts @@ -16,8 +16,7 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { TestExchangeInternalsContract } from '../../generated-wrappers/test_exchange_internals'; -import { artifacts } from '../../src/artifacts'; +import { artifacts, TestExchangeInternalsContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/protocol/test/exchange/match_orders.ts b/contracts/exchange/test/match_orders.ts similarity index 98% rename from contracts/protocol/test/exchange/match_orders.ts rename to contracts/exchange/test/match_orders.ts index 8e943c237f..d17025dddb 100644 --- a/contracts/protocol/test/exchange/match_orders.ts +++ b/contracts/exchange/test/match_orders.ts @@ -1,3 +1,6 @@ +import { ERC20ProxyContract, ERC20Wrapper, ERC721ProxyContract, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts, DummyERC20TokenContract, ReentrantERC20TokenContract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; import { chaiSetup, constants, @@ -9,12 +12,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokensArtifacts, - DummyERC20TokenContract, - DummyERC721TokenContract, - ReentrantERC20TokenContract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason } from '@0x/types'; @@ -23,15 +20,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy'; -import { ExchangeContract } from '../../generated-wrappers/exchange'; -import { TestExchangeInternalsContract } from '../../generated-wrappers/test_exchange_internals'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ERC721Wrapper } from '../utils/erc721_wrapper'; -import { ExchangeWrapper } from '../utils/exchange_wrapper'; -import { MatchOrderTester } from '../utils/match_order_tester'; +import { artifacts, ExchangeContract, ExchangeWrapper, MatchOrderTester, TestExchangeInternalsContract } from '../src'; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); chaiSetup.configure(); @@ -142,7 +131,7 @@ describe('matchOrders', () => { ); reentrantErc20Token = await ReentrantERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.ReentrantERC20Token, + erc20Artifacts.ReentrantERC20Token, provider, txDefaults, exchange.address, diff --git a/contracts/protocol/test/exchange/signature_validator.ts b/contracts/exchange/test/signature_validator.ts similarity index 98% rename from contracts/protocol/test/exchange/signature_validator.ts rename to contracts/exchange/test/signature_validator.ts index 3f1786b5b9..89eac4ddb3 100644 --- a/contracts/protocol/test/exchange/signature_validator.ts +++ b/contracts/exchange/test/signature_validator.ts @@ -1,4 +1,4 @@ -import { artifacts as examplesArtifacts, ValidatorContract, WalletContract } from '@0x/contracts-examples'; +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; import { addressUtils, chaiSetup, @@ -10,7 +10,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, orderHashUtils, signatureUtils } from '@0x/order-utils'; import { RevertReason, SignatureType, SignedOrder } from '@0x/types'; @@ -23,7 +22,9 @@ import { TestSignatureValidatorContract, TestSignatureValidatorSignatureValidatorApprovalEventArgs, TestStaticCallReceiverContract, -} from '../../src'; + ValidatorContract, + WalletContract, +} from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -61,13 +62,13 @@ describe('MixinSignatureValidator', () => { txDefaults, ); testWallet = await WalletContract.deployFrom0xArtifactAsync( - examplesArtifacts.Wallet, + artifacts.Wallet, provider, txDefaults, signerAddress, ); testValidator = await ValidatorContract.deployFrom0xArtifactAsync( - examplesArtifacts.Validator, + artifacts.Validator, provider, txDefaults, signerAddress, @@ -77,7 +78,7 @@ describe('MixinSignatureValidator', () => { provider, txDefaults, ); - signatureValidatorLogDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...tokensArtifacts }); + signatureValidatorLogDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...erc20Artifacts }); await web3Wrapper.awaitTransactionSuccessAsync( await signatureValidator.setSignatureValidatorApproval.sendTransactionAsync(testValidator.address, true, { from: signerAddress, diff --git a/contracts/protocol/test/exchange/transactions.ts b/contracts/exchange/test/transactions.ts similarity index 97% rename from contracts/protocol/test/exchange/transactions.ts rename to contracts/exchange/test/transactions.ts index e8c775f3e3..6139534939 100644 --- a/contracts/protocol/test/exchange/transactions.ts +++ b/contracts/exchange/test/transactions.ts @@ -1,4 +1,5 @@ -import { artifacts as examplesArtifacts, ExchangeWrapperContract, WhitelistContract } from '@0x/contracts-examples'; +import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy'; +import { DummyERC20TokenContract } from '@0x/contracts-erc20'; import { chaiSetup, constants, @@ -12,7 +13,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { DummyERC20TokenContract } from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils'; import { OrderWithoutExchangeAddress, RevertReason, SignedOrder } from '@0x/types'; @@ -20,11 +20,7 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ExchangeContract } from '../../generated-wrappers/exchange'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ExchangeWrapper } from '../utils/exchange_wrapper'; +import { artifacts, ExchangeContract, ExchangeWrapper, ExchangeWrapperContract, WhitelistContract } from '../src/'; chaiSetup.configure(); const expect = chai.expect; @@ -221,7 +217,7 @@ describe('Exchange transactions', () => { before(async () => { exchangeWrapperContract = await ExchangeWrapperContract.deployFrom0xArtifactAsync( - examplesArtifacts.ExchangeWrapper, + artifacts.ExchangeWrapper, provider, txDefaults, exchange.address, @@ -335,7 +331,7 @@ describe('Exchange transactions', () => { before(async () => { whitelist = await WhitelistContract.deployFrom0xArtifactAsync( - examplesArtifacts.Whitelist, + artifacts.Whitelist, provider, txDefaults, exchange.address, diff --git a/contracts/protocol/test/utils/asset_wrapper.ts b/contracts/exchange/test/utils/asset_wrapper.ts similarity index 93% rename from contracts/protocol/test/utils/asset_wrapper.ts rename to contracts/exchange/test/utils/asset_wrapper.ts index e4090ad741..e5a5205f58 100644 --- a/contracts/protocol/test/utils/asset_wrapper.ts +++ b/contracts/exchange/test/utils/asset_wrapper.ts @@ -4,8 +4,7 @@ import { AssetProxyId } from '@0x/types'; import { BigNumber, errorUtils } from '@0x/utils'; import * as _ from 'lodash'; -import { ERC20Wrapper } from './erc20_wrapper'; -import { ERC721Wrapper } from './erc721_wrapper'; +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; interface ProxyIdToAssetWrappers { [proxyId: string]: AbstractAssetWrapper; @@ -28,11 +27,13 @@ export class AssetWrapper { const proxyId = assetDataUtils.decodeAssetProxyId(assetData); switch (proxyId) { case AssetProxyId.ERC20: { + // tslint:disable-next-line:no-unnecessary-type-assertion const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const balance = await erc20Wrapper.getBalanceAsync(userAddress, assetData); return balance; } case AssetProxyId.ERC721: { + // tslint:disable-next-line:no-unnecessary-type-assertion const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData); const isOwner = await assetWrapper.isOwnerAsync( @@ -51,6 +52,7 @@ export class AssetWrapper { const proxyId = assetDataUtils.decodeAssetProxyId(assetData); switch (proxyId) { case AssetProxyId.ERC20: { + // tslint:disable-next-line:no-unnecessary-type-assertion const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; await erc20Wrapper.setBalanceAsync(userAddress, assetData, desiredBalance); return; @@ -59,6 +61,7 @@ export class AssetWrapper { if (!desiredBalance.eq(0) && !desiredBalance.eq(1)) { throw new Error(`Balance for ERC721 token can only be set to 0 or 1. Got: ${desiredBalance}`); } + // tslint:disable-next-line:no-unnecessary-type-assertion const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData); const doesTokenExist = erc721Wrapper.doesTokenExistAsync( @@ -109,11 +112,13 @@ export class AssetWrapper { const proxyId = assetDataUtils.decodeAssetProxyId(assetData); switch (proxyId) { case AssetProxyId.ERC20: { + // tslint:disable-next-line:no-unnecessary-type-assertion const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; const allowance = await erc20Wrapper.getProxyAllowanceAsync(userAddress, assetData); return allowance; } case AssetProxyId.ERC721: { + // tslint:disable-next-line:no-unnecessary-type-assertion const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const erc721ProxyData = assetDataUtils.decodeERC721AssetData(assetData); const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync( @@ -143,6 +148,7 @@ export class AssetWrapper { const proxyId = assetDataUtils.decodeAssetProxyId(assetData); switch (proxyId) { case AssetProxyId.ERC20: { + // tslint:disable-next-line:no-unnecessary-type-assertion const erc20Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC20Wrapper; await erc20Wrapper.setAllowanceAsync(userAddress, assetData, desiredAllowance); return; @@ -157,6 +163,7 @@ export class AssetWrapper { `Allowance for ERC721 token can only be set to 0, 1 or 2^256-1. Got: ${desiredAllowance}`, ); } + // tslint:disable-next-line:no-unnecessary-type-assertion const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper; const assetProxyData = assetDataUtils.decodeERC721AssetData(assetData); diff --git a/contracts/protocol/test/utils/exchange_wrapper.ts b/contracts/exchange/test/utils/exchange_wrapper.ts similarity index 98% rename from contracts/protocol/test/utils/exchange_wrapper.ts rename to contracts/exchange/test/utils/exchange_wrapper.ts index 437882b417..eca535c656 100644 --- a/contracts/protocol/test/utils/exchange_wrapper.ts +++ b/contracts/exchange/test/utils/exchange_wrapper.ts @@ -1,3 +1,5 @@ +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; +import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; import { FillResults, formatters, @@ -6,15 +8,13 @@ import { orderUtils, SignedTransaction, } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { SignedOrder } from '@0x/types'; import { AbiEncoder, BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { MethodAbi, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; -import { ExchangeContract } from '../../generated-wrappers/exchange'; -import { artifacts } from '../../src/artifacts'; +import { artifacts, ExchangeContract } from '../../src'; import { AbiDecodedFillOrderData } from './types'; @@ -25,7 +25,7 @@ export class ExchangeWrapper { constructor(exchangeContract: ExchangeContract, provider: Provider) { this._exchange = exchangeContract; this._web3Wrapper = new Web3Wrapper(provider); - this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, ...tokensArtifacts }); + this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, ...erc20Artifacts, ...erc721Artifacts }); } public async fillOrderAsync( signedOrder: SignedOrder, diff --git a/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts similarity index 99% rename from contracts/protocol/test/utils/fill_order_combinatorial_utils.ts rename to contracts/exchange/test/utils/fill_order_combinatorial_utils.ts index c2f530e5b2..26b1689093 100644 --- a/contracts/protocol/test/utils/fill_order_combinatorial_utils.ts +++ b/contracts/exchange/test/utils/fill_order_combinatorial_utils.ts @@ -1,4 +1,5 @@ -import { artifacts as libsArtifacts, TestLibsContract } from '@0x/contracts-libs'; +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { artifacts as libsArtifacts, TestLibsContract } from '@0x/contracts-exchange-libs'; import { AllowanceAmountScenario, AssetDataScenario, @@ -32,12 +33,9 @@ import { LogWithDecodedArgs, Provider, TxData } from 'ethereum-types'; import * as _ from 'lodash'; import 'make-promises-safe'; -import { ExchangeContract, ExchangeFillEventArgs } from '../../generated-wrappers/exchange'; -import { artifacts } from '../../src/artifacts'; +import { artifacts, ExchangeContract, ExchangeFillEventArgs } from '../../src'; import { AssetWrapper } from './asset_wrapper'; -import { ERC20Wrapper } from './erc20_wrapper'; -import { ERC721Wrapper } from './erc721_wrapper'; import { ExchangeWrapper } from './exchange_wrapper'; import { OrderFactoryFromScenario } from './order_factory_from_scenario'; import { SimpleAssetBalanceAndProxyAllowanceFetcher } from './simple_asset_balance_and_proxy_allowance_fetcher'; diff --git a/contracts/exchange/test/utils/index.ts b/contracts/exchange/test/utils/index.ts new file mode 100644 index 0000000000..d88a382668 --- /dev/null +++ b/contracts/exchange/test/utils/index.ts @@ -0,0 +1,3 @@ +export * from './exchange_wrapper'; +export * from './fill_order_combinatorial_utils'; +export * from './match_order_tester'; diff --git a/contracts/protocol/test/utils/match_order_tester.ts b/contracts/exchange/test/utils/match_order_tester.ts similarity index 99% rename from contracts/protocol/test/utils/match_order_tester.ts rename to contracts/exchange/test/utils/match_order_tester.ts index 0ba8017c50..680ff13ac2 100644 --- a/contracts/protocol/test/utils/match_order_tester.ts +++ b/contracts/exchange/test/utils/match_order_tester.ts @@ -1,3 +1,4 @@ +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; import { chaiSetup, ERC20BalancesByOwner, @@ -15,8 +16,6 @@ import * as _ from 'lodash'; import { TransactionReceiptWithDecodedLogs } from '../../../../node_modules/ethereum-types'; -import { ERC20Wrapper } from './erc20_wrapper'; -import { ERC721Wrapper } from './erc721_wrapper'; import { ExchangeWrapper } from './exchange_wrapper'; chaiSetup.configure(); diff --git a/contracts/protocol/test/utils/order_factory_from_scenario.ts b/contracts/exchange/test/utils/order_factory_from_scenario.ts similarity index 99% rename from contracts/protocol/test/utils/order_factory_from_scenario.ts rename to contracts/exchange/test/utils/order_factory_from_scenario.ts index ecb4b2e281..6f56459060 100644 --- a/contracts/protocol/test/utils/order_factory_from_scenario.ts +++ b/contracts/exchange/test/utils/order_factory_from_scenario.ts @@ -1,3 +1,4 @@ +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; import { AssetDataScenario, constants, @@ -8,7 +9,6 @@ import { OrderScenario, TakerScenario, } from '@0x/contracts-test-utils'; -import { DummyERC721TokenContract } from '@0x/contracts-tokens'; import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils'; import { Order } from '@0x/types'; import { BigNumber, errorUtils } from '@0x/utils'; diff --git a/contracts/protocol/test/utils/simple_asset_balance_and_proxy_allowance_fetcher.ts b/contracts/exchange/test/utils/simple_asset_balance_and_proxy_allowance_fetcher.ts similarity index 100% rename from contracts/protocol/test/utils/simple_asset_balance_and_proxy_allowance_fetcher.ts rename to contracts/exchange/test/utils/simple_asset_balance_and_proxy_allowance_fetcher.ts diff --git a/contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts b/contracts/exchange/test/utils/simple_order_filled_cancelled_fetcher.ts similarity index 100% rename from contracts/protocol/test/utils/simple_order_filled_cancelled_fetcher.ts rename to contracts/exchange/test/utils/simple_order_filled_cancelled_fetcher.ts diff --git a/contracts/protocol/test/utils/types.ts b/contracts/exchange/test/utils/types.ts similarity index 100% rename from contracts/protocol/test/utils/types.ts rename to contracts/exchange/test/utils/types.ts diff --git a/contracts/protocol/test/exchange/wrapper.ts b/contracts/exchange/test/wrapper.ts similarity index 99% rename from contracts/protocol/test/exchange/wrapper.ts rename to contracts/exchange/test/wrapper.ts index 49ba5a2e57..62a0d426f3 100644 --- a/contracts/protocol/test/exchange/wrapper.ts +++ b/contracts/exchange/test/wrapper.ts @@ -1,3 +1,6 @@ +import { ERC20ProxyContract, ERC20Wrapper, ERC721ProxyContract, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts, DummyERC20TokenContract, ReentrantERC20TokenContract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; import { chaiSetup, constants, @@ -11,12 +14,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokensArtifacts, - DummyERC20TokenContract, - DummyERC721TokenContract, - ReentrantERC20TokenContract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; @@ -25,13 +22,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { ERC20ProxyContract } from '../../generated-wrappers/erc20_proxy'; -import { ERC721ProxyContract } from '../../generated-wrappers/erc721_proxy'; -import { ExchangeContract } from '../../generated-wrappers/exchange'; -import { artifacts } from '../../src/artifacts'; -import { ERC20Wrapper } from '../utils/erc20_wrapper'; -import { ERC721Wrapper } from '../utils/erc721_wrapper'; -import { ExchangeWrapper } from '../utils/exchange_wrapper'; +import { artifacts, ExchangeContract, ExchangeWrapper } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -116,7 +107,7 @@ describe('Exchange wrappers', () => { ); reentrantErc20Token = await ReentrantERC20TokenContract.deployFrom0xArtifactAsync( - tokensArtifacts.ReentrantERC20Token, + erc20Artifacts.ReentrantERC20Token, provider, txDefaults, exchange.address, diff --git a/contracts/interfaces/tsconfig.json b/contracts/exchange/tsconfig.json similarity index 50% rename from contracts/interfaces/tsconfig.json rename to contracts/exchange/tsconfig.json index 90b7d41bbb..b0fcd1771a 100644 --- a/contracts/interfaces/tsconfig.json +++ b/contracts/exchange/tsconfig.json @@ -5,11 +5,8 @@ "rootDir": ".", "resolveJsonModule": true }, - "include": ["./src/**/*", "./generated-wrappers/**/*"], + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ - "./generated-artifacts/IAssetData.json", - "./generated-artifacts/IAssetProxy.json", - "./generated-artifacts/IAuthorizable.json", "./generated-artifacts/IAssetProxyDispatcher.json", "./generated-artifacts/IExchange.json", "./generated-artifacts/IExchangeCore.json", @@ -18,7 +15,16 @@ "./generated-artifacts/ITransactions.json", "./generated-artifacts/IValidator.json", "./generated-artifacts/IWallet.json", - "./generated-artifacts/IWrapperFunctions.json" + "./generated-artifacts/IWrapperFunctions.json", + "./generated-artifacts/Exchange.json", + "./generated-artifacts/TestAssetProxyDispatcher.json", + "./generated-artifacts/TestExchangeInternals.json", + "./generated-artifacts/TestSignatureValidator.json", + "./generated-artifacts/TestStaticCallReceiver.json", + "./generated-artifacts/ExchangeWrapper.json", + "./generated-artifacts/Validator.json", + "./generated-artifacts/Wallet.json", + "./generated-artifacts/Whitelist.json" ], "exclude": ["./deploy/solc/solc_bin"] } diff --git a/contracts/exchange/tslint.json b/contracts/exchange/tslint.json new file mode 100644 index 0000000000..1bb3ac2a22 --- /dev/null +++ b/contracts/exchange/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": ["@0x/tslint-config"], + "rules": { + "custom-no-magic-numbers": false + } +} diff --git a/contracts/extensions/CHANGELOG.json b/contracts/extensions/CHANGELOG.json index 920fef05a0..16ec073aaf 100644 --- a/contracts/extensions/CHANGELOG.json +++ b/contracts/extensions/CHANGELOG.json @@ -1,4 +1,17 @@ [ + { + "version": "3.0.0", + "changes": [ + { + "note": "Move Forwarder contract into new package", + "pr": 1539 + }, + { + "note": "Nest extensions under src directory", + "pr": 1539 + } + ] + }, { "version": "2.0.0", "changes": [ diff --git a/contracts/extensions/DEPLOYS.json b/contracts/extensions/DEPLOYS.json index 1a093bf77b..fe51488c70 100644 --- a/contracts/extensions/DEPLOYS.json +++ b/contracts/extensions/DEPLOYS.json @@ -1,31 +1 @@ -[ - { - "name": "Forwarder", - "version": "1.1.0", - "changes": [ - { - "note": "Round up when calculating remaining amounts in marketBuy functions", - "pr": 1162, - "networks": { - "1": "0x5468a1dc173652ee28d249c271fa9933144746b1", - "3": "0x2240dab907db71e64d3e0dba4800c83b5c502d4e", - "42": "0x17992e4ffb22730138e4b62aaa6367fa9d3699a6" - } - } - ] - }, - { - "name": "Forwarder", - "version": "1.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x7afc2d5107af94c462a194d2c21b5bdd238709d6", - "3": "0x3983e204b12b3c02fb0638caf2cd406a62e0ead3", - "42": "0xd85e2fa7e7e252b27b01bf0d65c946959d2f45b8" - } - } - ] - } -] +[] diff --git a/contracts/extensions/README.md b/contracts/extensions/README.md index 820f6e78ac..f1767869d4 100644 --- a/contracts/extensions/README.md +++ b/contracts/extensions/README.md @@ -1,10 +1,14 @@ -## Contract extensions +## Extensions -Smart contracts that implement extensions for the 0x protocol. +This package implements various extensions to the 0x protocol. Extension contracts can add various rules around how orders are settled while still getting the interoperability and security benefits of using the underlying 0x protocol contracts. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contract extensions of the protocol can be found in the [contracts](./contracts) directory. This directory contains contracts that interact with the 2.0.0 contracts and will be used in production, such as the [Forwarder](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/forwarder-specification.md) contract. +**Install** + +```bash +npm install @0x/contracts-extensions --save +``` ## Bug bounty diff --git a/contracts/extensions/compiler.json b/contracts/extensions/compiler.json index 2bb468724b..1dfaf7a05d 100644 --- a/contracts/extensions/compiler.json +++ b/contracts/extensions/compiler.json @@ -18,5 +18,5 @@ } } }, - "contracts": ["BalanceThresholdFilter", "DutchAuction", "Forwarder", "OrderMatcher", "OrderValidator"] + "contracts": ["BalanceThresholdFilter", "DutchAuction", "OrderMatcher", "OrderValidator"] } diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/BalanceThresholdFilter.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/BalanceThresholdFilter.sol similarity index 94% rename from contracts/extensions/contracts/BalanceThresholdFilter/BalanceThresholdFilter.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/BalanceThresholdFilter.sol index 16cacd461d..b6e14525df 100644 --- a/contracts/extensions/contracts/BalanceThresholdFilter/BalanceThresholdFilter.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/BalanceThresholdFilter.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; import "./interfaces/IThresholdAsset.sol"; import "./MixinBalanceThresholdFilterCore.sol"; diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol similarity index 97% rename from contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol index da050bf72f..68dabafeba 100644 --- a/contracts/extensions/contracts/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinBalanceThresholdFilterCore.sol @@ -18,8 +18,8 @@ pragma solidity ^0.4.24; -import "@0x/contracts-libs/contracts/libs/LibExchangeSelectors.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "./mixins/MBalanceThresholdFilterCore.sol"; import "./MixinExchangeCalldata.sol"; diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol similarity index 98% rename from contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol index a15e95a9d8..f2c0caa579 100644 --- a/contracts/extensions/contracts/BalanceThresholdFilter/MixinExchangeCalldata.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/MixinExchangeCalldata.sol @@ -20,7 +20,7 @@ pragma solidity ^0.4.24; import "./mixins/MExchangeCalldata.sol"; -import "@0x/contracts-libs/contracts/libs/LibAddressArray.sol"; +import "@0x/contracts-utils/contracts/src/LibAddressArray.sol"; contract MixinExchangeCalldata is diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol similarity index 100% rename from contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/interfaces/IBalanceThresholdFilterCore.sol diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IThresholdAsset.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/interfaces/IThresholdAsset.sol similarity index 100% rename from contracts/extensions/contracts/BalanceThresholdFilter/interfaces/IThresholdAsset.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/interfaces/IThresholdAsset.sol diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol similarity index 95% rename from contracts/extensions/contracts/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol index 074686e8d6..1c840136ba 100644 --- a/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol +++ b/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MBalanceThresholdFilterCore.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; import "../interfaces/IThresholdAsset.sol"; import "../interfaces/IBalanceThresholdFilterCore.sol"; diff --git a/contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol b/contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol similarity index 100% rename from contracts/extensions/contracts/BalanceThresholdFilter/mixins/MExchangeCalldata.sol rename to contracts/extensions/contracts/src/BalanceThresholdFilter/mixins/MExchangeCalldata.sol diff --git a/contracts/extensions/contracts/DutchAuction/DutchAuction.sol b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol similarity index 96% rename from contracts/extensions/contracts/DutchAuction/DutchAuction.sol rename to contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol index 9c9f3990ad..7631880c06 100644 --- a/contracts/extensions/contracts/DutchAuction/DutchAuction.sol +++ b/contracts/extensions/contracts/src/DutchAuction/DutchAuction.sol @@ -19,11 +19,11 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-utils/contracts/utils/SafeMath/SafeMath.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-utils/contracts/src/SafeMath.sol"; contract DutchAuction is diff --git a/contracts/extensions/contracts/OrderMatcher/MixinAssets.sol b/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol similarity index 95% rename from contracts/extensions/contracts/OrderMatcher/MixinAssets.sol rename to contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol index f0f91cfc00..65b36ea65e 100644 --- a/contracts/extensions/contracts/OrderMatcher/MixinAssets.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/MixinAssets.sol @@ -18,10 +18,10 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC721Token/IERC721Token.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; +import "@0x/contracts-erc721/contracts/src/interfaces/IERC721Token.sol"; import "./mixins/MAssets.sol"; import "./libs/LibConstants.sol"; diff --git a/contracts/extensions/contracts/OrderMatcher/MixinMatchOrders.sol b/contracts/extensions/contracts/src/OrderMatcher/MixinMatchOrders.sol similarity index 94% rename from contracts/extensions/contracts/OrderMatcher/MixinMatchOrders.sol rename to contracts/extensions/contracts/src/OrderMatcher/MixinMatchOrders.sol index 1787deb595..baf41f6509 100644 --- a/contracts/extensions/contracts/OrderMatcher/MixinMatchOrders.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/MixinMatchOrders.sol @@ -20,9 +20,9 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; import "./libs/LibConstants.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-libs/contracts/libs/LibFillResults.sol"; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibFillResults.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; contract MixinMatchOrders is diff --git a/contracts/extensions/contracts/OrderMatcher/OrderMatcher.sol b/contracts/extensions/contracts/src/OrderMatcher/OrderMatcher.sol similarity index 93% rename from contracts/extensions/contracts/OrderMatcher/OrderMatcher.sol rename to contracts/extensions/contracts/src/OrderMatcher/OrderMatcher.sol index 4879b7bcaf..89a7f3c55f 100644 --- a/contracts/extensions/contracts/OrderMatcher/OrderMatcher.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/OrderMatcher.sol @@ -19,7 +19,7 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-utils/contracts/utils/Ownable/Ownable.sol"; +import "@0x/contracts-utils/contracts/src/Ownable.sol"; import "./libs/LibConstants.sol"; import "./MixinMatchOrders.sol"; import "./MixinAssets.sol"; diff --git a/contracts/extensions/contracts/OrderMatcher/interfaces/IAssets.sol b/contracts/extensions/contracts/src/OrderMatcher/interfaces/IAssets.sol similarity index 100% rename from contracts/extensions/contracts/OrderMatcher/interfaces/IAssets.sol rename to contracts/extensions/contracts/src/OrderMatcher/interfaces/IAssets.sol diff --git a/contracts/extensions/contracts/OrderMatcher/interfaces/IMatchOrders.sol b/contracts/extensions/contracts/src/OrderMatcher/interfaces/IMatchOrders.sol similarity index 96% rename from contracts/extensions/contracts/OrderMatcher/interfaces/IMatchOrders.sol rename to contracts/extensions/contracts/src/OrderMatcher/interfaces/IMatchOrders.sol index 1443c73b9a..7e4a88df84 100644 --- a/contracts/extensions/contracts/OrderMatcher/interfaces/IMatchOrders.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/interfaces/IMatchOrders.sol @@ -19,7 +19,7 @@ pragma solidity ^0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; contract IMatchOrders { diff --git a/contracts/extensions/contracts/OrderMatcher/interfaces/IOrderMatcher.sol b/contracts/extensions/contracts/src/OrderMatcher/interfaces/IOrderMatcher.sol similarity index 91% rename from contracts/extensions/contracts/OrderMatcher/interfaces/IOrderMatcher.sol rename to contracts/extensions/contracts/src/OrderMatcher/interfaces/IOrderMatcher.sol index 75f26dca60..5e5125dea3 100644 --- a/contracts/extensions/contracts/OrderMatcher/interfaces/IOrderMatcher.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/interfaces/IOrderMatcher.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contract-utils/contracts/utils/Ownable/IOwnable.sol"; +import "@0x/contract-utils/contracts/src/interfaces/IOwnable.sol"; import "./IMatchOrders.sol"; import "./IAssets.sol"; diff --git a/contracts/extensions/contracts/OrderMatcher/libs/LibConstants.sol b/contracts/extensions/contracts/src/OrderMatcher/libs/LibConstants.sol similarity index 95% rename from contracts/extensions/contracts/OrderMatcher/libs/LibConstants.sol rename to contracts/extensions/contracts/src/OrderMatcher/libs/LibConstants.sol index c1a86a9c77..77b72398fb 100644 --- a/contracts/extensions/contracts/OrderMatcher/libs/LibConstants.sol +++ b/contracts/extensions/contracts/src/OrderMatcher/libs/LibConstants.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; contract LibConstants { diff --git a/contracts/extensions/contracts/OrderMatcher/mixins/MAssets.sol b/contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol similarity index 100% rename from contracts/extensions/contracts/OrderMatcher/mixins/MAssets.sol rename to contracts/extensions/contracts/src/OrderMatcher/mixins/MAssets.sol diff --git a/contracts/extensions/contracts/OrderValidator/OrderValidator.sol b/contracts/extensions/contracts/src/OrderValidator/OrderValidator.sol similarity index 96% rename from contracts/extensions/contracts/OrderValidator/OrderValidator.sol rename to contracts/extensions/contracts/src/OrderValidator/OrderValidator.sol index 33dd1326c5..3297a980f7 100644 --- a/contracts/extensions/contracts/OrderValidator/OrderValidator.sol +++ b/contracts/extensions/contracts/src/OrderValidator/OrderValidator.sol @@ -19,11 +19,11 @@ pragma solidity 0.4.24; pragma experimental ABIEncoderV2; -import "@0x/contracts-interfaces/contracts/protocol/Exchange/IExchange.sol"; -import "@0x/contracts-libs/contracts/libs/LibOrder.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC20Token/IERC20Token.sol"; -import "@0x/contracts-tokens/contracts/tokens/ERC721Token/IERC721Token.sol"; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol"; +import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; +import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; +import "@0x/contracts-erc721/contracts/src/interfaces/IERC721Token.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; contract OrderValidator { diff --git a/contracts/extensions/package.json b/contracts/extensions/package.json index 14492af8fb..780244f37d 100644 --- a/contracts/extensions/package.json +++ b/contracts/extensions/package.json @@ -32,7 +32,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(BalanceThresholdFilter|DutchAuction|Forwarder|OrderMatcher|OrderValidator).json" + "abis": "generated-artifacts/@(BalanceThresholdFilter|DutchAuction|OrderMatcher|OrderValidator).json" }, "repository": { "type": "git", @@ -49,42 +49,35 @@ "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-interfaces": "^1.0.6", - "@0x/contracts-libs": "^1.0.6", - "@0x/contracts-protocol": "^2.2.3", - "@0x/contracts-tokens": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", + "@0x/contracts-asset-proxy": "^1.0.0", + "@0x/contracts-exchange-libs": "^1.0.0", + "@0x/contracts-exchange": "^1.0.0", + "@0x/contracts-erc20": "^1.0.0", + "@0x/contracts-erc721": "^1.0.0", + "@0x/contracts-utils": "^3.0.0", "@0x/order-utils": "^3.1.2", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", - "@types/js-combinatorics": "^0.5.29", - "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", - "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" }, "publishConfig": { diff --git a/contracts/extensions/src/artifacts/index.ts b/contracts/extensions/src/artifacts/index.ts index 329d0f3f32..f2aee49083 100644 --- a/contracts/extensions/src/artifacts/index.ts +++ b/contracts/extensions/src/artifacts/index.ts @@ -2,14 +2,12 @@ import { ContractArtifact } from 'ethereum-types'; import * as BalanceThresholdFilter from '../../generated-artifacts/BalanceThresholdFilter.json'; import * as DutchAuction from '../../generated-artifacts/DutchAuction.json'; -import * as Forwarder from '../../generated-artifacts/Forwarder.json'; import * as OrderMatcher from '../../generated-artifacts/OrderMatcher.json'; import * as OrderValidator from '../../generated-artifacts/OrderValidator.json'; export const artifacts = { BalanceThresholdFilter: BalanceThresholdFilter as ContractArtifact, DutchAuction: DutchAuction as ContractArtifact, - Forwarder: Forwarder as ContractArtifact, OrderMatcher: OrderMatcher as ContractArtifact, OrderValidator: OrderValidator as ContractArtifact, }; diff --git a/contracts/extensions/src/index.ts b/contracts/extensions/src/index.ts index d55f08ea2d..ba813e7caf 100644 --- a/contracts/extensions/src/index.ts +++ b/contracts/extensions/src/index.ts @@ -1,2 +1,3 @@ export * from './artifacts'; export * from './wrappers'; +export * from '../test/utils'; diff --git a/contracts/extensions/src/wrappers/index.ts b/contracts/extensions/src/wrappers/index.ts index 65aec3ccd5..eed1985244 100644 --- a/contracts/extensions/src/wrappers/index.ts +++ b/contracts/extensions/src/wrappers/index.ts @@ -1,5 +1,4 @@ export * from '../../generated-wrappers/balance_threshold_filter'; export * from '../../generated-wrappers/dutch_auction'; -export * from '../../generated-wrappers/forwarder'; export * from '../../generated-wrappers/order_matcher'; export * from '../../generated-wrappers/order_validator'; diff --git a/contracts/extensions/test/extensions/balance_threshold_filter.ts b/contracts/extensions/test/balance_threshold_filter.ts similarity index 99% rename from contracts/extensions/test/extensions/balance_threshold_filter.ts rename to contracts/extensions/test/balance_threshold_filter.ts index adeb7c422e..c79a72f5a1 100644 --- a/contracts/extensions/test/extensions/balance_threshold_filter.ts +++ b/contracts/extensions/test/balance_threshold_filter.ts @@ -7,13 +7,9 @@ import * as chai from 'chai'; import { TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; -import { - artifacts as protocolArtifacts, - ERC20Wrapper, - ERC721Wrapper, - ExchangeContract, - ExchangeWrapper, -} from '@0x/contracts-protocol'; +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { DummyERC20TokenContract } from '@0x/contracts-erc20'; +import { artifacts as exchangeArtifacts, ExchangeContract, ExchangeWrapper } from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -27,11 +23,8 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { DummyERC20TokenContract } from '@0x/contracts-tokens'; -import { BalanceThresholdFilterContract } from '../../generated-wrappers/balance_threshold_filter'; -import { artifacts } from '../../src/artifacts'; -import { BalanceThresholdWrapper } from '../utils/balance_threshold_wrapper'; +import { artifacts, BalanceThresholdFilterContract, BalanceThresholdWrapper } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -134,7 +127,7 @@ describe(ContractName.BalanceThresholdFilter, () => { await erc20Wrapper.setBalancesAndAllowancesAsync(); // Deploy Exchange contract exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, zrxAssetData, diff --git a/contracts/extensions/test/extensions/dutch_auction.ts b/contracts/extensions/test/dutch_auction.ts similarity index 96% rename from contracts/extensions/test/extensions/dutch_auction.ts rename to contracts/extensions/test/dutch_auction.ts index 22b3caa162..34ff25c3d1 100644 --- a/contracts/extensions/test/extensions/dutch_auction.ts +++ b/contracts/extensions/test/dutch_auction.ts @@ -1,11 +1,8 @@ import { DutchAuctionWrapper } from '@0x/contract-wrappers'; -import { - artifacts as protocolArtifacts, - ERC20Wrapper, - ERC721Wrapper, - ExchangeContract, - ExchangeWrapper, -} from '@0x/contracts-protocol'; +import { ERC20Wrapper, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts, ExchangeContract, ExchangeWrapper } from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -18,12 +15,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { - artifacts as tokensArtifacts, - DummyERC20TokenContract, - DummyERC721TokenContract, - WETH9Contract, -} from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, generatePseudoRandomSalt } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; @@ -32,9 +23,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { DutchAuctionContract } from '../../generated-wrappers/dutch_auction'; -import { artifacts } from '../../src/artifacts'; -import { DutchAuctionTestWrapper } from '../utils/dutch_auction_test_wrapper'; +import { artifacts, DutchAuctionContract, DutchAuctionTestWrapper } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -93,12 +82,12 @@ describe(ContractName.DutchAuction, () => { const erc721Balances = await erc721Wrapper.getBalancesAsync(); erc721MakerAssetIds = erc721Balances[makerAddress][erc721Token.address]; - wethContract = await WETH9Contract.deployFrom0xArtifactAsync(tokensArtifacts.WETH9, provider, txDefaults); + wethContract = await WETH9Contract.deployFrom0xArtifactAsync(erc20Artifacts.WETH9, provider, txDefaults); erc20Wrapper.addDummyTokenContract(wethContract as any); const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, zrxAssetData, diff --git a/contracts/extensions/test/extensions/order_matcher.ts b/contracts/extensions/test/order_matcher.ts similarity index 98% rename from contracts/extensions/test/extensions/order_matcher.ts rename to contracts/extensions/test/order_matcher.ts index acb46ced46..0b2f9ddbb6 100644 --- a/contracts/extensions/test/extensions/order_matcher.ts +++ b/contracts/extensions/test/order_matcher.ts @@ -1,12 +1,17 @@ import { - artifacts as protocolArtifacts, + artifacts as proxyArtifacts, ERC20ProxyContract, ERC20Wrapper, ERC721ProxyContract, +} from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20'; +import { artifacts as erc721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { + artifacts as exchangeArtifacts, ExchangeContract, ExchangeFillEventArgs, ExchangeWrapper, -} from '@0x/contracts-protocol'; +} from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -20,7 +25,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { artifacts as tokenArtifacts, DummyERC20TokenContract, DummyERC721TokenContract } from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason } from '@0x/types'; @@ -30,8 +34,7 @@ import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { OrderMatcherContract } from '../../generated-wrappers/order_matcher'; -import { artifacts } from '../../src/artifacts'; +import { artifacts, OrderMatcherContract } from '../src'; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); chaiSetup.configure(); @@ -102,13 +105,13 @@ describe('OrderMatcher', () => { await erc20Wrapper.setBalancesAndAllowancesAsync(); // Deploy ERC721 proxy erc721Proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync( - protocolArtifacts.ERC721Proxy, + proxyArtifacts.ERC721Proxy, provider, txDefaults, ); // Depoy exchange exchange = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, assetDataUtils.encodeERC20AssetData(zrxToken.address), @@ -197,7 +200,7 @@ describe('OrderMatcher', () => { describe('constructor', () => { it('should revert if assetProxy is unregistered', async () => { const exchangeInstance = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, constants.NULL_BYTES, @@ -451,7 +454,7 @@ describe('OrderMatcher', () => { signedOrderLeft.signature, signedOrderRight.signature, ); - const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...tokenArtifacts, ...protocolArtifacts }); + const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...erc20Artifacts, ...exchangeArtifacts }); const txReceipt = await logDecoder.getTxWithDecodedLogsAsync( await web3Wrapper.sendTransactionAsync({ data, @@ -489,7 +492,7 @@ describe('OrderMatcher', () => { signedOrderLeft.signature, signedOrderRight.signature, ); - const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...tokenArtifacts, ...protocolArtifacts }); + const logDecoder = new LogDecoder(web3Wrapper, { ...artifacts, ...erc20Artifacts, ...exchangeArtifacts }); const txReceipt = await logDecoder.getTxWithDecodedLogsAsync( await web3Wrapper.sendTransactionAsync({ data, @@ -726,7 +729,7 @@ describe('OrderMatcher', () => { }); it('should allow owner to withdraw ERC721 tokens', async () => { const erc721Token = await DummyERC721TokenContract.deployFrom0xArtifactAsync( - tokenArtifacts.DummyERC721Token, + erc721Artifacts.DummyERC721Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, @@ -771,7 +774,7 @@ describe('OrderMatcher', () => { }); it('should be able to approve an ERC721 token by passing in allowance = 1', async () => { const erc721Token = await DummyERC721TokenContract.deployFrom0xArtifactAsync( - tokenArtifacts.DummyERC721Token, + erc721Artifacts.DummyERC721Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, @@ -788,7 +791,7 @@ describe('OrderMatcher', () => { }); it('should be able to approve an ERC721 token by passing in allowance > 1', async () => { const erc721Token = await DummyERC721TokenContract.deployFrom0xArtifactAsync( - tokenArtifacts.DummyERC721Token, + erc721Artifacts.DummyERC721Token, provider, txDefaults, constants.DUMMY_TOKEN_NAME, diff --git a/contracts/extensions/test/extensions/order_validator.ts b/contracts/extensions/test/order_validator.ts similarity index 98% rename from contracts/extensions/test/extensions/order_validator.ts rename to contracts/extensions/test/order_validator.ts index 7d8675f36e..88dae14fb5 100644 --- a/contracts/extensions/test/extensions/order_validator.ts +++ b/contracts/extensions/test/order_validator.ts @@ -1,12 +1,7 @@ -import { - artifacts as protocolArtifacts, - ERC20ProxyContract, - ERC20Wrapper, - ERC721ProxyContract, - ERC721Wrapper, - ExchangeContract, - ExchangeWrapper, -} from '@0x/contracts-protocol'; +import { ERC20ProxyContract, ERC20Wrapper, ERC721ProxyContract, ERC721Wrapper } from '@0x/contracts-asset-proxy'; +import { DummyERC20TokenContract } from '@0x/contracts-erc20'; +import { DummyERC721TokenContract } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts, ExchangeContract, ExchangeWrapper } from '@0x/contracts-exchange'; import { chaiSetup, constants, @@ -16,7 +11,6 @@ import { txDefaults, web3Wrapper, } from '@0x/contracts-test-utils'; -import { DummyERC20TokenContract, DummyERC721TokenContract } from '@0x/contracts-tokens'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils, orderHashUtils } from '@0x/order-utils'; import { SignedOrder } from '@0x/types'; @@ -24,8 +18,7 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import * as _ from 'lodash'; -import { OrderValidatorContract } from '../../generated-wrappers/order_validator'; -import { artifacts } from '../../src/artifacts/index'; +import { artifacts, OrderValidatorContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -81,7 +74,7 @@ describe('OrderValidator', () => { const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); exchange = await ExchangeContract.deployFrom0xArtifactAsync( - protocolArtifacts.Exchange, + exchangeArtifacts.Exchange, provider, txDefaults, zrxAssetData, diff --git a/contracts/extensions/test/utils/balance_threshold_wrapper.ts b/contracts/extensions/test/utils/balance_threshold_wrapper.ts index 28a4ef0118..3178d992ed 100644 --- a/contracts/extensions/test/utils/balance_threshold_wrapper.ts +++ b/contracts/extensions/test/utils/balance_threshold_wrapper.ts @@ -1,4 +1,6 @@ -import { artifacts as protocolArtifacts, ExchangeContract } from '@0x/contracts-protocol'; +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; +import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts, ExchangeContract } from '@0x/contracts-exchange'; import { FillResults, formatters, @@ -7,7 +9,6 @@ import { orderUtils, TransactionFactory, } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; @@ -35,8 +36,9 @@ export class BalanceThresholdWrapper { this._web3Wrapper = new Web3Wrapper(provider); this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, - ...tokensArtifacts, - ...protocolArtifacts, + ...erc20Artifacts, + ...erc721Artifacts, + ...exchangeArtifacts, }); } public async fillOrderAsync( diff --git a/contracts/extensions/test/utils/dutch_auction_test_wrapper.ts b/contracts/extensions/test/utils/dutch_auction_test_wrapper.ts index c1e2f20701..5899ffcacd 100644 --- a/contracts/extensions/test/utils/dutch_auction_test_wrapper.ts +++ b/contracts/extensions/test/utils/dutch_auction_test_wrapper.ts @@ -1,6 +1,7 @@ -import { artifacts as protocolArtifacts } from '@0x/contracts-protocol'; +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; +import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; +import { artifacts as exchangeArtifacts } from '@0x/contracts-exchange'; import { LogDecoder } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -19,8 +20,9 @@ export class DutchAuctionTestWrapper { this._web3Wrapper = new Web3Wrapper(provider); this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, - ...tokensArtifacts, - ...protocolArtifacts, + ...erc20Artifacts, + ...erc721Artifacts, + ...exchangeArtifacts, }); } /** diff --git a/contracts/extensions/test/utils/index.ts b/contracts/extensions/test/utils/index.ts new file mode 100644 index 0000000000..6ba9a23001 --- /dev/null +++ b/contracts/extensions/test/utils/index.ts @@ -0,0 +1,2 @@ +export * from './balance_threshold_wrapper'; +export * from './dutch_auction_test_wrapper'; diff --git a/contracts/extensions/tsconfig.json b/contracts/extensions/tsconfig.json index ed9b4fbe18..0c06c69024 100644 --- a/contracts/extensions/tsconfig.json +++ b/contracts/extensions/tsconfig.json @@ -9,7 +9,6 @@ "files": [ "./generated-artifacts/BalanceThresholdFilter.json", "./generated-artifacts/DutchAuction.json", - "./generated-artifacts/Forwarder.json", "./generated-artifacts/OrderMatcher.json", "./generated-artifacts/OrderValidator.json" ], diff --git a/contracts/interfaces/CHANGELOG.json b/contracts/interfaces/CHANGELOG.json deleted file mode 100644 index 724ab1e4a5..0000000000 --- a/contracts/interfaces/CHANGELOG.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547747677, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1544741676, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - } -] diff --git a/contracts/interfaces/package.json b/contracts/interfaces/package.json deleted file mode 100644 index c67c25df39..0000000000 --- a/contracts/interfaces/package.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "name": "@0x/contracts-interfaces", - "version": "1.0.6", - "engines": { - "node": ">=6.12" - }, - "description": "Smart contract interfaces of 0x protocol", - "main": "lib/src/index.js", - "scripts": { - "build": "yarn pre_build && tsc -b", - "build:ci": "yarn build", - "pre_build": "run-s compile generate_contract_wrappers", - "compile": "sol-compiler", - "watch": "sol-compiler -w", - "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers", - "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", - "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" - }, - "config": { - "abis": "generated-artifacts/@(IAssetData|IAssetProxy|IAuthorizable|IAssetProxyDispatcher|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IValidator|IWallet|IWrapperFunctions).json" - }, - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x-monorepo.git" - }, - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/0xProject/0x-monorepo/issues" - }, - "homepage": "https://github.com/0xProject/0x-monorepo/contracts/interfaces/README.md", - "devDependencies": { - "@0x/abi-gen": "^1.0.22", - "@0x/sol-compiler": "^2.0.2", - "@0x/tslint-config": "^2.0.2", - "npm-run-all": "^4.1.2", - "shx": "^0.2.2", - "solhint": "^1.4.1", - "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" - }, - "dependencies": { - "@0x/base-contract": "^3.0.13", - "@0x/contracts-libs": "^1.0.6", - "@0x/contracts-utils": "^1.0.6", - "@0x/types": "^1.5.2", - "@0x/typescript-typings": "^3.0.8", - "@0x/utils": "^3.0.1", - "@0x/web3-wrapper": "^3.2.4", - "ethereum-types": "^1.1.6", - "lodash": "^4.17.5" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/contracts/interfaces/src/wrappers/index.ts b/contracts/interfaces/src/wrappers/index.ts deleted file mode 100644 index f7f72fadaa..0000000000 --- a/contracts/interfaces/src/wrappers/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -export * from '../../generated-wrappers/i_asset_data'; -export * from '../../generated-wrappers/i_asset_proxy'; -export * from '../../generated-wrappers/i_asset_proxy_dispatcher'; -export * from '../../generated-wrappers/i_exchange'; -export * from '../../generated-wrappers/i_exchange_core'; -export * from '../../generated-wrappers/i_match_orders'; -export * from '../../generated-wrappers/i_signature_validator'; -export * from '../../generated-wrappers/i_transactions'; -export * from '../../generated-wrappers/i_authorizable'; -export * from '../../generated-wrappers/i_wrapper_functions'; -export * from '../../generated-wrappers/i_validator'; -export * from '../../generated-wrappers/i_wallet'; diff --git a/contracts/libs/CHANGELOG.json b/contracts/libs/CHANGELOG.json deleted file mode 100644 index 724ab1e4a5..0000000000 --- a/contracts/libs/CHANGELOG.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547747677, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1544741676, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - } -] diff --git a/contracts/multisig/CHANGELOG.json b/contracts/multisig/CHANGELOG.json index 724ab1e4a5..0fd8833c9c 100644 --- a/contracts/multisig/CHANGELOG.json +++ b/contracts/multisig/CHANGELOG.json @@ -1,4 +1,17 @@ [ + { + "version": "3.0.0", + "changes": [ + { + "note": "Add AssetProxyOwner contract", + "pr": 1539 + }, + { + "note": "Rename multisig directory to src", + "pr": 1539 + } + ] + }, { "version": "2.0.0", "changes": [ diff --git a/contracts/multisig/DEPLOYS.json b/contracts/multisig/DEPLOYS.json new file mode 100644 index 0000000000..ea4e7ff89f --- /dev/null +++ b/contracts/multisig/DEPLOYS.json @@ -0,0 +1,17 @@ +[ + { + "name": "AssetProxyOwner", + "version": "1.0.0", + "changes": [ + { + "note": "protocol v2 deploy", + "networks": { + "1": "0x17992e4ffb22730138e4b62aaa6367fa9d3699a6", + "3": "0xf5fa5b5fed2727a0e44ac67f6772e97977aa358b", + "4": "0x1da52d1d3a3acfa0a1836b737393b4e9931268fc", + "42": "0x2c824d2882baa668e0d5202b1e7f2922278703f8" + } + } + ] + } +] diff --git a/contracts/multisig/README.md b/contracts/multisig/README.md index e29f462510..98cd8a0805 100644 --- a/contracts/multisig/README.md +++ b/contracts/multisig/README.md @@ -1,15 +1,14 @@ -## MultisSig Contracts +## MultiSignature Contracts -MultiSig smart contracts +This package contains various types of multisignature wallet contracts, including the [`AssetProxyOwner`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#assetproxyowner) contract that is responsible for upgrading the 0x protocol smart contracts. Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. -## Usage +## Installation -Contracts can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [multisig](./contracts/multisig) - - This directory contains the [Gnosis MultiSigWallet](https://github.com/gnosis/MultiSigWallet) and a custom extension that adds a timelock to transactions within the MultiSigWallet. -- [test](./contracts/test) - - This directory contains mocks and other contracts that are used solely for testing contracts within the other directories. +```bash +npm install @0x/contracts-multisig --save +``` ## Contributing diff --git a/contracts/multisig/compiler.json b/contracts/multisig/compiler.json index 5a1f689e2a..772665775e 100644 --- a/contracts/multisig/compiler.json +++ b/contracts/multisig/compiler.json @@ -18,5 +18,11 @@ } } }, - "contracts": ["MultiSigWallet", "MultiSigWalletWithTimeLock", "TestRejectEther"] + "contracts": [ + "AssetProxyOwner", + "MultiSigWallet", + "MultiSigWalletWithTimeLock", + "TestAssetProxyOwner", + "TestRejectEther" + ] } diff --git a/contracts/protocol/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol b/contracts/multisig/contracts/src/AssetProxyOwner.sol similarity index 96% rename from contracts/protocol/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol rename to contracts/multisig/contracts/src/AssetProxyOwner.sol index bfc7b5a665..d115a9d82b 100644 --- a/contracts/protocol/contracts/protocol/AssetProxyOwner/AssetProxyOwner.sol +++ b/contracts/multisig/contracts/src/AssetProxyOwner.sol @@ -18,8 +18,8 @@ pragma solidity 0.4.24; -import "@0x/contracts-multisig/contracts/multisig/MultiSigWalletWithTimeLock.sol"; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "./MultiSigWalletWithTimeLock.sol"; +import "@0x/contracts-utils/contracts/src/LibBytes.sol"; contract AssetProxyOwner is diff --git a/contracts/multisig/contracts/multisig/MultiSigWallet.sol b/contracts/multisig/contracts/src/MultiSigWallet.sol similarity index 100% rename from contracts/multisig/contracts/multisig/MultiSigWallet.sol rename to contracts/multisig/contracts/src/MultiSigWallet.sol diff --git a/contracts/multisig/contracts/multisig/MultiSigWalletWithTimeLock.sol b/contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol similarity index 100% rename from contracts/multisig/contracts/multisig/MultiSigWalletWithTimeLock.sol rename to contracts/multisig/contracts/src/MultiSigWalletWithTimeLock.sol diff --git a/contracts/protocol/contracts/test/TestAssetProxyOwner/TestAssetProxyOwner.sol b/contracts/multisig/contracts/test/TestAssetProxyOwner.sol similarity index 96% rename from contracts/protocol/contracts/test/TestAssetProxyOwner/TestAssetProxyOwner.sol rename to contracts/multisig/contracts/test/TestAssetProxyOwner.sol index 52c66cb568..09ae836c75 100644 --- a/contracts/protocol/contracts/test/TestAssetProxyOwner/TestAssetProxyOwner.sol +++ b/contracts/multisig/contracts/test/TestAssetProxyOwner.sol @@ -18,7 +18,7 @@ pragma solidity 0.4.24; -import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol"; +import "../src/AssetProxyOwner.sol"; // solhint-disable no-empty-blocks diff --git a/contracts/multisig/contracts/test/TestRejectEther/TestRejectEther.sol b/contracts/multisig/contracts/test/TestRejectEther.sol similarity index 100% rename from contracts/multisig/contracts/test/TestRejectEther/TestRejectEther.sol rename to contracts/multisig/contracts/test/TestRejectEther.sol diff --git a/contracts/multisig/package.json b/contracts/multisig/package.json index 1c3911cbcc..3282e0ae51 100644 --- a/contracts/multisig/package.json +++ b/contracts/multisig/package.json @@ -32,7 +32,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "generated-artifacts/@(MultiSigWallet|MultiSigWalletWithTimeLock|TestRejectEther).json" + "abis": "generated-artifacts/@(AssetProxyOwner|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestRejectEther).json" }, "repository": { "type": "git", @@ -48,13 +48,9 @@ "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", - "@types/ethereumjs-abi": "^0.6.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", @@ -65,12 +61,12 @@ "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/order-utils": "^3.1.2", + "@0x/contracts-asset-proxy": "^1.0.0", + "@0x/contracts-erc20": "^1.0.0", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", diff --git a/contracts/multisig/src/artifacts/index.ts b/contracts/multisig/src/artifacts/index.ts index 7cf47be01a..326d790003 100644 --- a/contracts/multisig/src/artifacts/index.ts +++ b/contracts/multisig/src/artifacts/index.ts @@ -1,11 +1,15 @@ import { ContractArtifact } from 'ethereum-types'; +import * as AssetProxyOwner from '../../generated-artifacts/AssetProxyOwner.json'; import * as MultiSigWallet from '../../generated-artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../../generated-artifacts/MultiSigWalletWithTimeLock.json'; +import * as TestAssetProxyOwner from '../../generated-artifacts/TestAssetProxyOwner.json'; import * as TestRejectEther from '../../generated-artifacts/TestRejectEther.json'; export const artifacts = { - TestRejectEther: TestRejectEther as ContractArtifact, + AssetProxyOwner: AssetProxyOwner as ContractArtifact, MultiSigWallet: MultiSigWallet as ContractArtifact, MultiSigWalletWithTimeLock: MultiSigWalletWithTimeLock as ContractArtifact, + TestAssetProxyOwner: TestAssetProxyOwner as ContractArtifact, + TestRejectEther: TestRejectEther as ContractArtifact, }; diff --git a/contracts/multisig/src/index.ts b/contracts/multisig/src/index.ts index d55f08ea2d..ba813e7caf 100644 --- a/contracts/multisig/src/index.ts +++ b/contracts/multisig/src/index.ts @@ -1,2 +1,3 @@ export * from './artifacts'; export * from './wrappers'; +export * from '../test/utils'; diff --git a/contracts/multisig/src/wrappers/index.ts b/contracts/multisig/src/wrappers/index.ts index 69abd62f29..43ab257044 100644 --- a/contracts/multisig/src/wrappers/index.ts +++ b/contracts/multisig/src/wrappers/index.ts @@ -1,2 +1,5 @@ +export * from '../../generated-wrappers/asset_proxy_owner'; export * from '../../generated-wrappers/multi_sig_wallet'; export * from '../../generated-wrappers/multi_sig_wallet_with_time_lock'; +export * from '../../generated-wrappers/test_asset_proxy_owner'; +export * from '../../generated-wrappers/test_reject_ether'; diff --git a/contracts/protocol/test/multisig/asset_proxy_owner.ts b/contracts/multisig/test/asset_proxy_owner.ts similarity index 98% rename from contracts/protocol/test/multisig/asset_proxy_owner.ts rename to contracts/multisig/test/asset_proxy_owner.ts index daebfb7fb4..62081554be 100644 --- a/contracts/protocol/test/multisig/asset_proxy_owner.ts +++ b/contracts/multisig/test/asset_proxy_owner.ts @@ -1,3 +1,4 @@ +import { artifacts as proxyArtifacts, MixinAuthorizableContract } from '@0x/contracts-asset-proxy'; import { chaiSetup, constants, @@ -18,16 +19,15 @@ import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; import { + artifacts, AssetProxyOwnerAssetProxyRegistrationEventArgs, AssetProxyOwnerContract, AssetProxyOwnerExecutionEventArgs, AssetProxyOwnerExecutionFailureEventArgs, AssetProxyOwnerSubmissionEventArgs, -} from '../../generated-wrappers/asset_proxy_owner'; -import { MixinAuthorizableContract } from '../../generated-wrappers/mixin_authorizable'; -import { TestAssetProxyOwnerContract } from '../../generated-wrappers/test_asset_proxy_owner'; -import { artifacts } from '../../src/artifacts'; -import { AssetProxyOwnerWrapper } from '../utils/asset_proxy_owner_wrapper'; + AssetProxyOwnerWrapper, + TestAssetProxyOwnerContract, +} from '../src'; chaiSetup.configure(); const expect = chai.expect; @@ -58,12 +58,12 @@ describe('AssetProxyOwner', () => { notOwner = accounts[3]; const initialOwner = accounts[0]; erc20Proxy = await MixinAuthorizableContract.deployFrom0xArtifactAsync( - artifacts.MixinAuthorizable, + proxyArtifacts.MixinAuthorizable, provider, txDefaults, ); erc721Proxy = await MixinAuthorizableContract.deployFrom0xArtifactAsync( - artifacts.MixinAuthorizable, + proxyArtifacts.MixinAuthorizable, provider, txDefaults, ); diff --git a/contracts/multisig/test/multi_sig_with_time_lock.ts b/contracts/multisig/test/multi_sig_with_time_lock.ts index 31c2155052..b9b3732a7e 100644 --- a/contracts/multisig/test/multi_sig_with_time_lock.ts +++ b/contracts/multisig/test/multi_sig_with_time_lock.ts @@ -16,17 +16,16 @@ import { LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; import { + artifacts, MultiSigWalletWithTimeLockConfirmationEventArgs, MultiSigWalletWithTimeLockConfirmationTimeSetEventArgs, MultiSigWalletWithTimeLockContract, MultiSigWalletWithTimeLockExecutionEventArgs, MultiSigWalletWithTimeLockExecutionFailureEventArgs, MultiSigWalletWithTimeLockSubmissionEventArgs, -} from '../generated-wrappers/multi_sig_wallet_with_time_lock'; -import { TestRejectEtherContract } from '../generated-wrappers/test_reject_ether'; -import { artifacts } from '../src/artifacts'; - -import { MultiSigWrapper } from './utils/multi_sig_wrapper'; + MultiSigWrapper, + TestRejectEtherContract, +} from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/protocol/test/utils/asset_proxy_owner_wrapper.ts b/contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts similarity index 94% rename from contracts/protocol/test/utils/asset_proxy_owner_wrapper.ts rename to contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts index df23658d80..b6040d8e38 100644 --- a/contracts/protocol/test/utils/asset_proxy_owner_wrapper.ts +++ b/contracts/multisig/test/utils/asset_proxy_owner_wrapper.ts @@ -1,5 +1,6 @@ +import { artifacts as proxyArtifacts } from '@0x/contracts-asset-proxy'; +import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; import { LogDecoder } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -15,7 +16,7 @@ export class AssetProxyOwnerWrapper { constructor(assetproxyOwnerContract: AssetProxyOwnerContract, provider: Provider) { this._assetProxyOwner = assetproxyOwnerContract; this._web3Wrapper = new Web3Wrapper(provider); - this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, ...tokensArtifacts }); + this._logDecoder = new LogDecoder(this._web3Wrapper, { ...artifacts, ...erc20Artifacts, ...proxyArtifacts }); } public async submitTransactionAsync( destination: string, diff --git a/contracts/multisig/test/utils/index.ts b/contracts/multisig/test/utils/index.ts new file mode 100644 index 0000000000..382fd92e54 --- /dev/null +++ b/contracts/multisig/test/utils/index.ts @@ -0,0 +1,2 @@ +export * from './asset_proxy_owner_wrapper'; +export * from './multi_sig_wrapper'; diff --git a/contracts/multisig/tsconfig.json b/contracts/multisig/tsconfig.json index 6f381620e4..ad1707e43e 100644 --- a/contracts/multisig/tsconfig.json +++ b/contracts/multisig/tsconfig.json @@ -7,8 +7,10 @@ }, "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ + "./generated-artifacts/AssetProxyOwner.json", "./generated-artifacts/MultiSigWallet.json", "./generated-artifacts/MultiSigWalletWithTimeLock.json", + "./generated-artifacts/TestAssetProxyOwner.json", "./generated-artifacts/TestRejectEther.json" ], "exclude": ["./deploy/solc/solc_bin"] diff --git a/contracts/protocol/CHANGELOG.json b/contracts/protocol/CHANGELOG.json deleted file mode 100644 index 0d513cc176..0000000000 --- a/contracts/protocol/CHANGELOG.json +++ /dev/null @@ -1,65 +0,0 @@ -[ - { - "version": "3.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547747677, - "version": "2.2.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547561734, - "version": "2.2.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "2.2.1", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "2.2.0", - "changes": [ - { - "note": "Added LibAddressArray", - "pr": 1383 - }, - { - "note": "Add validation and comments to MultiAssetProxy", - "pr": 1455 - }, - { - "note": "Move OrderValidator to extensions", - "pr": 1464 - } - ], - "timestamp": 1547040760 - }, - { - "timestamp": 1544741676, - "version": "2.1.59", - "changes": [ - { - "note": "Dependencies updated" - } - ] - } -] diff --git a/contracts/protocol/DEPLOYS.json b/contracts/protocol/DEPLOYS.json deleted file mode 100644 index 5c24ae59cd..0000000000 --- a/contracts/protocol/DEPLOYS.json +++ /dev/null @@ -1,92 +0,0 @@ -[ - { - "name": "MultiAssetProxy", - "version": "1.0.0", - "changes": [ - { - "note": "Add MultiAssetProxy implementation", - "pr": 1224 - } - ] - }, - { - "name": "OrderValidator", - "version": "1.0.0", - "changes": [ - { - "note": "remove `getApproved` check from ERC721 approval query", - "pr": 1149 - } - ] - }, - { - "name": "OrderValidator", - "version": "1.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x9463e518dea6810309563c81d5266c1b1d149138", - "3": "0x90431a90516ab49af23a0530e04e8c7836e7122f", - "42": "0xb389da3d204b412df2f75c6afb3d0a7ce0bc283d" - } - } - ] - }, - { - "name": "Exchange", - "version": "2.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x4f833a24e1f95d70f028921e27040ca56e09ab0b", - "3": "0x4530c0483a1633c7a1c97d2c53721caff2caaaaf", - "42": "0x35dd2932454449b14cee11a94d3674a936d5d7b2" - } - } - ] - }, - { - "name": "ERC20Proxy", - "version": "1.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x2240dab907db71e64d3e0dba4800c83b5c502d4e", - "3": "0xb1408f4c245a23c31b98d2c626777d4c0d766caa", - "42": "0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e" - } - } - ] - }, - { - "name": "ERC721Proxy", - "version": "1.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x208e41fb445f1bb1b6780d58356e81405f3e6127", - "3": "0xe654aac058bfbf9f83fcaee7793311dd82f6ddb4", - "42": "0x2a9127c745688a165106c11cd4d647d2220af821" - } - } - ] - }, - { - "name": "AssetProxyOwner", - "version": "1.0.0", - "changes": [ - { - "note": "protocol v2 deploy", - "networks": { - "1": "0x17992e4ffb22730138e4b62aaa6367fa9d3699a6", - "3": "0xf5fa5b5fed2727a0e44ac67f6772e97977aa358b", - "42": "0x2c824d2882baa668e0d5202b1e7f2922278703f8" - } - } - ] - } -] diff --git a/contracts/protocol/src/artifacts/index.ts b/contracts/protocol/src/artifacts/index.ts deleted file mode 100644 index c5d12f10b1..0000000000 --- a/contracts/protocol/src/artifacts/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -import * as AssetProxyOwner from '../../generated-artifacts/AssetProxyOwner.json'; -import * as ERC20Proxy from '../../generated-artifacts/ERC20Proxy.json'; -import * as ERC721Proxy from '../../generated-artifacts/ERC721Proxy.json'; -import * as Exchange from '../../generated-artifacts/Exchange.json'; -import * as MixinAuthorizable from '../../generated-artifacts/MixinAuthorizable.json'; -import * as MultiAssetProxy from '../../generated-artifacts/MultiAssetProxy.json'; -import * as TestAssetProxyDispatcher from '../../generated-artifacts/TestAssetProxyDispatcher.json'; -import * as TestAssetProxyOwner from '../../generated-artifacts/TestAssetProxyOwner.json'; -import * as TestExchangeInternals from '../../generated-artifacts/TestExchangeInternals.json'; -import * as TestSignatureValidator from '../../generated-artifacts/TestSignatureValidator.json'; -import * as TestStaticCallReceiver from '../../generated-artifacts/TestStaticCallReceiver.json'; - -export const artifacts = { - AssetProxyOwner: AssetProxyOwner as ContractArtifact, - ERC20Proxy: ERC20Proxy as ContractArtifact, - ERC721Proxy: ERC721Proxy as ContractArtifact, - Exchange: Exchange as ContractArtifact, - MixinAuthorizable: MixinAuthorizable as ContractArtifact, - MultiAssetProxy: MultiAssetProxy as ContractArtifact, - TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact, - TestAssetProxyOwner: TestAssetProxyOwner as ContractArtifact, - TestExchangeInternals: TestExchangeInternals as ContractArtifact, - TestSignatureValidator: TestSignatureValidator as ContractArtifact, - TestStaticCallReceiver: TestStaticCallReceiver as ContractArtifact, -}; diff --git a/contracts/protocol/src/wrappers/index.ts b/contracts/protocol/src/wrappers/index.ts deleted file mode 100644 index 01b1210540..0000000000 --- a/contracts/protocol/src/wrappers/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from '../../generated-wrappers/asset_proxy_owner'; -export * from '../../generated-wrappers/erc20_proxy'; -export * from '../../generated-wrappers/erc721_proxy'; -export * from '../../generated-wrappers/exchange'; -export * from '../../generated-wrappers/mixin_authorizable'; -export * from '../../generated-wrappers/test_asset_proxy_dispatcher'; -export * from '../../generated-wrappers/test_asset_proxy_owner'; -export * from '../../generated-wrappers/test_exchange_internals'; -export * from '../../generated-wrappers/test_signature_validator'; -export * from '../../generated-wrappers/test_static_call_receiver'; diff --git a/contracts/protocol/tsconfig.json b/contracts/protocol/tsconfig.json deleted file mode 100644 index db872fc324..0000000000 --- a/contracts/protocol/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": ".", - "resolveJsonModule": true - }, - "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], - "files": [ - "./generated-artifacts/AssetProxyOwner.json", - "./generated-artifacts/ERC20Proxy.json", - "./generated-artifacts/ERC721Proxy.json", - "./generated-artifacts/Exchange.json", - "./generated-artifacts/MixinAuthorizable.json", - "./generated-artifacts/MultiAssetProxy.json", - "./generated-artifacts/TestAssetProxyDispatcher.json", - "./generated-artifacts/TestAssetProxyOwner.json", - "./generated-artifacts/TestExchangeInternals.json", - "./generated-artifacts/TestSignatureValidator.json", - "./generated-artifacts/TestStaticCallReceiver.json" - ], - "exclude": ["./deploy/solc/solc_bin"] -} diff --git a/contracts/test-utils/package.json b/contracts/test-utils/package.json index b0f4713afe..262b8c7cda 100644 --- a/contracts/test-utils/package.json +++ b/contracts/test-utils/package.json @@ -54,7 +54,6 @@ "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", "@types/bn.js": "^4.11.0", - "@types/ethereumjs-abi": "^0.6.0", "@types/js-combinatorics": "^0.5.29", "@types/lodash": "4.14.104", "@types/node": "*", @@ -64,7 +63,6 @@ "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", "ethereum-types": "^1.1.6", - "ethereumjs-abi": "0.6.5", "ethereumjs-util": "^5.1.1", "ethers": "~4.0.4", "js-combinatorics": "^0.5.3", diff --git a/contracts/tokens/CHANGELOG.json b/contracts/tokens/CHANGELOG.json deleted file mode 100644 index 724ab1e4a5..0000000000 --- a/contracts/tokens/CHANGELOG.json +++ /dev/null @@ -1,56 +0,0 @@ -[ - { - "version": "2.0.0", - "changes": [ - { - "note": "Upgrade the bignumber.js to v8.0.2", - "pr": 1517 - } - ] - }, - { - "timestamp": 1547747677, - "version": "1.0.6", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547561734, - "version": "1.0.5", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547225310, - "version": "1.0.4", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1547040760, - "version": "1.0.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "timestamp": 1544741676, - "version": "1.0.2", - "changes": [ - { - "note": "Dependencies updated" - } - ] - } -] diff --git a/contracts/tokens/contracts/tokens/ZRXToken/ERC20Token_v1.sol b/contracts/tokens/contracts/tokens/ZRXToken/ERC20Token_v1.sol deleted file mode 100644 index 4920c4aac6..0000000000 --- a/contracts/tokens/contracts/tokens/ZRXToken/ERC20Token_v1.sol +++ /dev/null @@ -1,44 +0,0 @@ -pragma solidity ^0.4.11; - -import { Token_v1 as Token } from "./Token_v1.sol"; - -contract ERC20Token_v1 is Token { - - function transfer(address _to, uint _value) returns (bool) { - //Default assumes totalSupply can't be over max (2^256 - 1). - if (balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) { - balances[msg.sender] -= _value; - balances[_to] += _value; - Transfer(msg.sender, _to, _value); - return true; - } else { return false; } - } - - function transferFrom(address _from, address _to, uint _value) returns (bool) { - if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]) { - balances[_to] += _value; - balances[_from] -= _value; - allowed[_from][msg.sender] -= _value; - Transfer(_from, _to, _value); - return true; - } else { return false; } - } - - function balanceOf(address _owner) constant returns (uint) { - return balances[_owner]; - } - - function approve(address _spender, uint _value) returns (bool) { - allowed[msg.sender][_spender] = _value; - Approval(msg.sender, _spender, _value); - return true; - } - - function allowance(address _owner, address _spender) constant returns (uint) { - return allowed[_owner][_spender]; - } - - mapping (address => uint) balances; - mapping (address => mapping (address => uint)) allowed; - uint public totalSupply; -} diff --git a/contracts/tokens/contracts/tokens/ZRXToken/Token_v1.sol b/contracts/tokens/contracts/tokens/ZRXToken/Token_v1.sol deleted file mode 100644 index de619fb7ef..0000000000 --- a/contracts/tokens/contracts/tokens/ZRXToken/Token_v1.sol +++ /dev/null @@ -1,39 +0,0 @@ -pragma solidity ^0.4.11; - -contract Token_v1 { - - /// @return total amount of tokens - function totalSupply() constant returns (uint supply) {} - - /// @param _owner The address from which the balance will be retrieved - /// @return The balance - function balanceOf(address _owner) constant returns (uint balance) {} - - /// @notice send `_value` token to `_to` from `msg.sender` - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transfer(address _to, uint _value) returns (bool success) {} - - /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` - /// @param _from The address of the sender - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transferFrom(address _from, address _to, uint _value) returns (bool success) {} - - /// @notice `msg.sender` approves `_addr` to spend `_value` tokens - /// @param _spender The address of the account able to transfer the tokens - /// @param _value The amount of wei to be approved for transfer - /// @return Whether the approval was successful or not - function approve(address _spender, uint _value) returns (bool success) {} - - /// @param _owner The address of the account owning tokens - /// @param _spender The address of the account able to transfer the tokens - /// @return Amount of remaining tokens allowed to spent - function allowance(address _owner, address _spender) constant returns (uint remaining) {} - - event Transfer(address indexed _from, address indexed _to, uint _value); - event Approval(address indexed _owner, address indexed _spender, uint _value); -} - diff --git a/contracts/tokens/contracts/tokens/ZRXToken/UnlimitedAllowanceToken_v1.sol b/contracts/tokens/contracts/tokens/ZRXToken/UnlimitedAllowanceToken_v1.sol deleted file mode 100644 index bf1b0335a1..0000000000 --- a/contracts/tokens/contracts/tokens/ZRXToken/UnlimitedAllowanceToken_v1.sol +++ /dev/null @@ -1,52 +0,0 @@ -/* - - Copyright 2018 ZeroEx Intl. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -pragma solidity ^0.4.11; - -import { ERC20Token_v1 as ERC20Token } from "./ERC20Token_v1.sol"; - -contract UnlimitedAllowanceToken_v1 is ERC20Token { - - uint constant MAX_UINT = 2**256 - 1; - - /// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance. - /// @param _from Address to transfer from. - /// @param _to Address to transfer to. - /// @param _value Amount to transfer. - /// @return Success of transfer. - function transferFrom(address _from, address _to, uint _value) - public - returns (bool) - { - uint allowance = allowed[_from][msg.sender]; - if (balances[_from] >= _value - && allowance >= _value - && balances[_to] + _value >= balances[_to] - ) { - balances[_to] += _value; - balances[_from] -= _value; - if (allowance < MAX_UINT) { - allowed[_from][msg.sender] -= _value; - } - Transfer(_from, _to, _value); - return true; - } else { - return false; - } - } -} diff --git a/contracts/tokens/contracts/tokens/ZRXToken/ZRXToken.sol b/contracts/tokens/contracts/tokens/ZRXToken/ZRXToken.sol deleted file mode 100644 index 831e1822cd..0000000000 --- a/contracts/tokens/contracts/tokens/ZRXToken/ZRXToken.sol +++ /dev/null @@ -1,41 +0,0 @@ -/* - - Copyright 2018 ZeroEx Intl. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -pragma solidity 0.4.11; - -// solhint-disable-next-line max-line-length -import { UnlimitedAllowanceToken_v1 as UnlimitedAllowanceToken } from "./UnlimitedAllowanceToken_v1.sol"; - - -contract ZRXToken is - UnlimitedAllowanceToken -{ - - // solhint-disable const-name-snakecase - uint8 constant public decimals = 18; - uint256 public totalSupply = 10**27; // 1 billion tokens, 18 decimal places - string constant public name = "0x Protocol Token"; - string constant public symbol = "ZRX"; - // solhint-enableconst-name-snakecase - - function ZRXToken() - public - { - balances[msg.sender] = totalSupply; - } -} diff --git a/contracts/utils/CHANGELOG.json b/contracts/utils/CHANGELOG.json index d44a81fef5..94434b803a 100644 --- a/contracts/utils/CHANGELOG.json +++ b/contracts/utils/CHANGELOG.json @@ -1,4 +1,21 @@ [ + { + "version": "3.0.0", + "changes": [ + { + "note": "Add LibAddressArray contract", + "pr": 1539 + }, + { + "note": "Do not nest contracts in redundant directories", + "pr": 1539 + }, + { + "note": "Rename utils directory to src", + "pr": 1539 + } + ] + }, { "version": "2.0.1", "changes": [ diff --git a/contracts/utils/README.md b/contracts/utils/README.md index 2f872ddb5e..5c69971b67 100644 --- a/contracts/utils/README.md +++ b/contracts/utils/README.md @@ -1,15 +1,14 @@ ## Contracts utils -Smart contracts utils used in the 0x protocol. +This package contains smart contract utilities and libraries that are used throughout the entire codebase of smart contracts. These contracts are all generic and may helpful to use outside of the context of 0x protocol. -## Usage +## Installation -Contracts can be found in the [contracts](./contracts) directory. The contents of this directory are broken down into the following subdirectories: +**Install** -- [utils](./contracts/utils) - - This directory contains libraries and utils. -- [test](./contracts/test) - - This directory contains mocks and other contracts that are used solely for testing contracts within the other directories. +```bash +npm install @0x/contracts-utils --save +``` ## Contributing diff --git a/contracts/libs/contracts/libs/LibAddressArray.sol b/contracts/utils/contracts/src/LibAddressArray.sol similarity index 97% rename from contracts/libs/contracts/libs/LibAddressArray.sol rename to contracts/utils/contracts/src/LibAddressArray.sol index 997ce85fa1..892c486f14 100644 --- a/contracts/libs/contracts/libs/LibAddressArray.sol +++ b/contracts/utils/contracts/src/LibAddressArray.sol @@ -18,7 +18,7 @@ pragma solidity ^0.4.24; -import "@0x/contracts-utils/contracts/utils/LibBytes/LibBytes.sol"; +import "./LibBytes.sol"; library LibAddressArray { diff --git a/contracts/utils/contracts/utils/LibBytes/LibBytes.sol b/contracts/utils/contracts/src/LibBytes.sol similarity index 100% rename from contracts/utils/contracts/utils/LibBytes/LibBytes.sol rename to contracts/utils/contracts/src/LibBytes.sol diff --git a/contracts/utils/contracts/utils/Ownable/Ownable.sol b/contracts/utils/contracts/src/Ownable.sol similarity index 93% rename from contracts/utils/contracts/utils/Ownable/Ownable.sol rename to contracts/utils/contracts/src/Ownable.sol index aa74a72d20..f67f241a4f 100644 --- a/contracts/utils/contracts/utils/Ownable/Ownable.sol +++ b/contracts/utils/contracts/src/Ownable.sol @@ -1,6 +1,6 @@ pragma solidity ^0.4.24; -import "./IOwnable.sol"; +import "./interfaces/IOwnable.sol"; contract Ownable is diff --git a/contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol b/contracts/utils/contracts/src/ReentrancyGuard.sol similarity index 100% rename from contracts/utils/contracts/utils/ReentrancyGuard/ReentrancyGuard.sol rename to contracts/utils/contracts/src/ReentrancyGuard.sol diff --git a/contracts/utils/contracts/utils/SafeMath/SafeMath.sol b/contracts/utils/contracts/src/SafeMath.sol similarity index 100% rename from contracts/utils/contracts/utils/SafeMath/SafeMath.sol rename to contracts/utils/contracts/src/SafeMath.sol diff --git a/contracts/utils/contracts/utils/Ownable/IOwnable.sol b/contracts/utils/contracts/src/interfaces/IOwnable.sol similarity index 100% rename from contracts/utils/contracts/utils/Ownable/IOwnable.sol rename to contracts/utils/contracts/src/interfaces/IOwnable.sol diff --git a/contracts/utils/contracts/test/TestConstants/TestConstants.sol b/contracts/utils/contracts/test/TestConstants.sol similarity index 95% rename from contracts/utils/contracts/test/TestConstants/TestConstants.sol rename to contracts/utils/contracts/test/TestConstants.sol index 1275d007b8..bf98bafefe 100644 --- a/contracts/utils/contracts/test/TestConstants/TestConstants.sol +++ b/contracts/utils/contracts/test/TestConstants.sol @@ -16,9 +16,9 @@ */ -pragma solidity 0.4.24; +pragma solidity ^0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; +import "../src/LibBytes.sol"; // solhint-disable max-line-length diff --git a/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol b/contracts/utils/contracts/test/TestLibBytes.sol similarity index 99% rename from contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol rename to contracts/utils/contracts/test/TestLibBytes.sol index 00d861e613..cd6b1456de 100644 --- a/contracts/utils/contracts/test/TestLibBytes/TestLibBytes.sol +++ b/contracts/utils/contracts/test/TestLibBytes.sol @@ -16,9 +16,9 @@ */ -pragma solidity 0.4.24; +pragma solidity ^0.4.24; -import "../../utils/LibBytes/LibBytes.sol"; +import "../src/LibBytes.sol"; contract TestLibBytes { diff --git a/contracts/utils/package.json b/contracts/utils/package.json index 4e45169fd3..33d94cc332 100644 --- a/contracts/utils/package.json +++ b/contracts/utils/package.json @@ -1,6 +1,6 @@ { "name": "@0x/contracts-utils", - "version": "1.0.6", + "version": "3.0.0", "engines": { "node": ">=6.12" }, @@ -48,35 +48,30 @@ "@0x/contracts-test-utils": "^2.0.1", "@0x/dev-utils": "^1.0.24", "@0x/sol-compiler": "^2.0.2", - "@0x/subproviders": "^2.1.11", "@0x/tslint-config": "^2.0.2", - "@types/bn.js": "^4.11.0", "@types/lodash": "4.14.104", "@types/node": "*", - "@types/yargs": "^10.0.0", - "bn.js": "^4.11.8", + "@types/bn.js": "^4.11.0", "chai": "^4.0.1", "chai-as-promised": "^7.1.0", "chai-bignumber": "^3.0.0", "dirty-chai": "^2.0.1", - "ethereumjs-abi": "0.6.5", "make-promises-safe": "^1.1.0", "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", "tslint": "5.11.0", - "typescript": "3.0.1", - "yargs": "^10.0.3" + "typescript": "3.0.1" }, "dependencies": { "@0x/base-contract": "^3.0.13", - "@0x/contracts-multisig": "^1.0.6", "@0x/order-utils": "^3.1.2", "@0x/types": "^1.5.2", "@0x/typescript-typings": "^3.0.8", "@0x/utils": "^3.0.1", "@0x/web3-wrapper": "^3.2.4", + "bn.js": "^4.11.8", "ethereum-types": "^1.1.6", "ethereumjs-util": "^5.1.1", "lodash": "^4.17.5" diff --git a/contracts/utils/test/lib_bytes.ts b/contracts/utils/test/lib_bytes.ts index 6fb859c673..daad287299 100644 --- a/contracts/utils/test/lib_bytes.ts +++ b/contracts/utils/test/lib_bytes.ts @@ -16,8 +16,7 @@ import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; -import { TestLibBytesContract } from '../generated-wrappers/test_lib_bytes'; -import { artifacts } from '../src'; +import { artifacts, TestLibBytesContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/utils/test/libs.ts b/contracts/utils/test/libs.ts index 81596b2e4a..77dc6e2ba5 100644 --- a/contracts/utils/test/libs.ts +++ b/contracts/utils/test/libs.ts @@ -2,8 +2,7 @@ import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test import { BlockchainLifecycle } from '@0x/dev-utils'; import * as chai from 'chai'; -import { TestConstantsContract } from '../generated-wrappers/test_constants'; -import { artifacts } from '../src'; +import { artifacts, TestConstantsContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; diff --git a/package.json b/package.json index 27675ddd30..62b4c1c367 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "build": "wsrun build $PKG --fast-exit -r --stages --exclude-missing", "build:no_website": "wsrun build $PKG --fast-exit -r --stages --exclude @0x/website --exclude-missing", "build:ci:no_website": "wsrun build:ci $PKG --fast-exit -r --stages --exclude @0x/website --exclude-missing", + "build:contracts": "wsrun build -p ${npm_package_config_contractsPackages} -c --fast-exit -r --stages --exclude-missing", "build:monorepo_scripts": "PKG=@0x/monorepo-scripts yarn build", "build:ts": "tsc -b", "watch:ts": "tsc -b -w", @@ -34,12 +35,14 @@ "rebuild": "run-s clean build", "rebuild:no_website": "run-s clean build:no_website", "test": "wsrun test $PKG --fast-exit --serial --exclude-missing", + "test:contracts": "wsrun test -p ${npm_package_config_contractsPackages} -c --fast-exit --serial --exclude-missing", "generate_doc": "node ./packages/monorepo-scripts/lib/doc_generate_and_upload.js", "test:generate_docs:circleci": "for i in ${npm_package_config_packagesWithDocPages}; do yarn generate_doc --package $i --shouldUpload false --isStaging true || break -1; done;", "bundlewatch": "bundlewatch", "lint": "wsrun lint $PKG --fast-exit --parallel --exclude-missing" }, "config": { + "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-extensions @0x/contracts-multisig @0x/contracts-test-utils @0x/contracts-utils", "mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic", "packagesWithDocPages": "0x.js connect json-schemas subproviders web3-wrapper contract-wrappers order-utils order-watcher sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer migrations" }, diff --git a/tsconfig.json b/tsconfig.json index a494839722..0a063c85b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,14 +20,15 @@ // any top-level TypeScript code. "include": [], "references": [ - { "path": "./contracts/examples" }, + { "path": "./contracts/asset-proxy" }, + { "path": "./contracts/erc20" }, + { "path": "./contracts/erc721" }, + { "path": "./contracts/exchange" }, + { "path": "./contracts/exchange-forwarder" }, + { "path": "./contracts/exchange-libs" }, { "path": "./contracts/extensions" }, - { "path": "./contracts/interfaces" }, - { "path": "./contracts/libs" }, { "path": "./contracts/multisig" }, - { "path": "./contracts/protocol" }, { "path": "./contracts/test-utils" }, - { "path": "./contracts/tokens" }, { "path": "./contracts/utils" }, { "path": "./packages/0x.js" }, { "path": "./packages/abi-gen-wrappers" }, diff --git a/yarn.lock b/yarn.lock index 9edcc8e501..543ec9d5cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1389,12 +1389,6 @@ dependencies: bignumber.js "7.2.1" -"@types/ethereumjs-abi@^0.6.0": - version "0.6.0" - resolved "https://registry.yarnpkg.com/@types/ethereumjs-abi/-/ethereumjs-abi-0.6.0.tgz#72d21083a36d9288821b62905e04b15e0c12175d" - dependencies: - "@types/node" "*" - "@types/ethereumjs-tx@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/ethereumjs-tx/-/ethereumjs-tx-1.0.0.tgz#ae2ce90a145cc1a6849656db38baf0e793ff7927" @@ -13401,6 +13395,16 @@ react-dom@^16.3.2: object-assign "^4.1.1" prop-types "^15.6.0" +react-dom@^16.4.2: + version "16.7.0" + resolved "https://registry.npmjs.org/react-dom/-/react-dom-16.7.0.tgz#a17b2a7ca89ee7390bc1ed5eb81783c7461748b8" + integrity sha512-D0Ufv1ExCAmF38P2Uh1lwpminZFRXEINJe53zRAbm4KPwSyd6DY/uDoS0Blj9jvPpn1+wivKpZYc8aAAN/nAkg== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + scheduler "^0.12.0" + react-dom@^16.5.2: version "16.5.2" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.5.2.tgz#b69ee47aa20bab5327b2b9d7c1fe2a30f2cfa9d7" @@ -13727,6 +13731,16 @@ react@^16.3.2: object-assign "^4.1.1" prop-types "^15.6.0" +react@^16.4.2: + version "16.7.0" + resolved "https://registry.npmjs.org/react/-/react-16.7.0.tgz#b674ec396b0a5715873b350446f7ea0802ab6381" + integrity sha512-StCz3QY8lxTb5cl2HJxjwLFOXPIFQp+p+hxQfc8WE0QiLfCtIlKj8/+5tjjKm8uSTlAW+fCPaavGFS06V9Ar3A== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + scheduler "^0.12.0" + react@^16.5.2: version "16.5.2" resolved "https://registry.yarnpkg.com/react/-/react-16.5.2.tgz#19f6b444ed139baa45609eee6dc3d318b3895d42" @@ -14615,6 +14629,14 @@ schedule@^0.5.0: dependencies: object-assign "^4.1.1" +scheduler@^0.12.0: + version "0.12.0" + resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.12.0.tgz#8ab17699939c0aedc5a196a657743c496538647b" + integrity sha512-t7MBR28Akcp4Jm+QoR63XgAi9YgCUmgvDHqf5otgAj4QvdoBE4ImCX0ffehefePPG+aitiYHp0g/mW6s4Tp+dw== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + schema-utils@^0.4.4: version "0.4.7" resolved "https://registry.npmjs.org/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187"