diff --git a/.gitignore b/.gitignore index e68ecfe096..3e550c43cb 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,8 @@ TODO.md .vscode # generated contract artifacts/ +contracts/broker/generated-artifacts/ +contracts/broker/test/generated-artifacts/ contracts/erc20-bridge-sampler/generated-artifacts/ contracts/erc20-bridge-sampler/test/generated-artifacts/ contracts/integrations/generated-artifacts/ @@ -113,6 +115,7 @@ packages/sol-tracing-utils/test/fixtures/artifacts/ python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/ # generated truffle contract artifacts/ +contracts/broker/build/ contracts/erc20-bridge-sampler/build/ contracts/staking/build/ contracts/coordinator/build/ @@ -129,6 +132,8 @@ contracts/exchange-forwarder/build/ contracts/dev-utils/build/ # generated contract wrappers +contracts/broker/generated-wrappers/ +contracts/broker/test/generated-wrappers/ packages/python-contract-wrappers/generated/ contracts/erc20-bridge-sampler/generated-wrappers/ contracts/erc20-bridge-sampler/test/generated-wrappers/ diff --git a/.prettierignore b/.prettierignore index f1ca1c7f39..d358c5534d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,9 @@ lib .nyc_output +/contracts/broker/generated-wrappers +/contracts/broker/test/generated-wrappers +/contracts/broker/generated-artifacts +/contracts/broker/test/generated-artifacts /contracts/integrations/generated-wrappers /contracts/integrations/test/generated-wrappers /contracts/integrations/generated-artifacts diff --git a/contracts/broker/.npmignore b/contracts/broker/.npmignore new file mode 100644 index 0000000000..bdf2b8acbe --- /dev/null +++ b/contracts/broker/.npmignore @@ -0,0 +1,10 @@ +# Blacklist all files +.* +* +# Whitelist lib +!lib/**/* +# Whitelist Solidity contracts +!contracts/src/**/* +# Blacklist tests in lib +/lib/test/* +# Package specific ignore diff --git a/contracts/broker/CHANGELOG.json b/contracts/broker/CHANGELOG.json new file mode 100644 index 0000000000..651647a956 --- /dev/null +++ b/contracts/broker/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Created package", + "pr": "2455" + } + ] + } +] diff --git a/contracts/broker/DEPLOYS.json b/contracts/broker/DEPLOYS.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/contracts/broker/DEPLOYS.json @@ -0,0 +1 @@ +[] diff --git a/contracts/broker/README.md b/contracts/broker/README.md new file mode 100644 index 0000000000..83ceefcf00 --- /dev/null +++ b/contracts/broker/README.md @@ -0,0 +1,73 @@ +## Broker + +This package contains the implementation of the `Broker` contract. This contract serves as an entry-point to the 0x Exchange for the filling of property-based orders. Addresses of the deployed contracts can be found in this 0x [guide](https://0x.org/docs/guides/0x-cheat-sheet) or the [DEPLOYS](./DEPLOYS.json) file within this package. + +## Installation + +**Install** + +```bash +npm install @0x/contracts-broker --save +``` + +## Bug bounty + +A bug bounty for the 3.0 contracts is ongoing! Instructions can be found [here](https://0x.org/docs/guides/bug-bounty-program). + +## 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-broker yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-broker 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/broker/compiler.json b/contracts/broker/compiler.json new file mode 100644 index 0000000000..2984f7fd9f --- /dev/null +++ b/contracts/broker/compiler.json @@ -0,0 +1,26 @@ +{ + "artifactsDir": "./test/generated-artifacts", + "contractsDir": "./contracts", + "useDockerisedSolc": false, + "isOfflineMode": false, + "compilerSettings": { + "evmVersion": "istanbul", + "optimizer": { + "enabled": true, + "runs": 1000000, + "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "devdoc", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + } +} diff --git a/contracts/broker/contracts/src/Broker.sol b/contracts/broker/contracts/src/Broker.sol new file mode 100644 index 0000000000..86a782be85 --- /dev/null +++ b/contracts/broker/contracts/src/Broker.sol @@ -0,0 +1,5 @@ +pragma solidity ^0.5.9; + + +// TODO(mzhu25): Implement, you know, the whole thing +contract Broker { } // solhint-disable-line no-empty-blocks diff --git a/contracts/broker/package.json b/contracts/broker/package.json new file mode 100644 index 0000000000..357fcc651d --- /dev/null +++ b/contracts/broker/package.json @@ -0,0 +1,95 @@ +{ + "name": "@0x/contracts-broker", + "version": "1.0.0", + "engines": { + "node": ">=6.12" + }, + "description": "Extension of 0x protocol for property-based orders", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "yarn build:contracts && yarn build:ts", + "build:contracts": "run-s compile contracts:gen generate_contract_wrappers contracts:copy", + "build:ts": "tsc -b", + "build:ci": "yarn build", + "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 test/generated-artifacts test/generated-wrappers generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output test/generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/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", + "contracts:gen": "contracts-gen generate", + "contracts:copy": "contracts-gen copy", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol", + "compile:truffle": "truffle compile", + "docs:md": "ts-doc-gen --sourceDir='$PROJECT_FILES' --output=$MD_FILE_DIR --fileExtension=mdx --tsconfig=./typedoc-tsconfig.json", + "docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES" + }, + "config": { + "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", + "abis": "./test/generated-artifacts/@(Broker).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": "^5.1.0", + "@0x/contracts-asset-proxy": "^3.1.1", + "@0x/contracts-erc1155": "^2.0.4", + "@0x/contracts-erc721": "^3.0.4", + "@0x/contracts-exchange": "^3.1.0", + "@0x/contracts-exchange-libs": "^4.1.0", + "@0x/contracts-gen": "^2.0.4", + "@0x/contracts-test-utils": "^5.1.1", + "@0x/contracts-utils": "^4.1.0", + "@0x/sol-compiler": "^4.0.4", + "@0x/ts-doc-gen": "^0.0.22", + "@0x/tslint-config": "^4.0.0", + "@0x/types": "^3.1.1", + "@0x/utils": "^5.2.0", + "@0x/web3-wrapper": "^7.0.4", + "@types/lodash": "4.14.104", + "@types/mocha": "^5.2.7", + "@types/node": "*", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^3.0.0", + "dirty-chai": "^2.0.1", + "lodash": "^4.17.11", + "make-promises-safe": "^1.1.0", + "mocha": "^6.2.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solhint": "^1.4.1", + "truffle": "^5.0.32", + "tslint": "5.11.0", + "typedoc": "^0.15.0", + "typescript": "3.0.1" + }, + "dependencies": { + "@0x/base-contract": "^6.1.0", + "@0x/typescript-typings": "^5.0.1", + "ethereum-types": "^3.0.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/contracts/broker/src/artifacts.ts b/contracts/broker/src/artifacts.ts new file mode 100644 index 0000000000..5a7c1d00fe --- /dev/null +++ b/contracts/broker/src/artifacts.ts @@ -0,0 +1,9 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +import * as Broker from '../generated-artifacts/Broker.json'; +export const artifacts = { Broker: Broker as ContractArtifact }; diff --git a/contracts/broker/src/index.ts b/contracts/broker/src/index.ts new file mode 100644 index 0000000000..25a249b40a --- /dev/null +++ b/contracts/broker/src/index.ts @@ -0,0 +1,2 @@ +export { artifacts } from './artifacts'; +export { BrokerContract } from './wrappers'; diff --git a/contracts/broker/src/wrappers.ts b/contracts/broker/src/wrappers.ts new file mode 100644 index 0000000000..dab8ce6cfe --- /dev/null +++ b/contracts/broker/src/wrappers.ts @@ -0,0 +1,6 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +export * from '../generated-wrappers/broker'; diff --git a/contracts/broker/test/artifacts.ts b/contracts/broker/test/artifacts.ts new file mode 100644 index 0000000000..0b7646a376 --- /dev/null +++ b/contracts/broker/test/artifacts.ts @@ -0,0 +1,9 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +import * as Broker from '../test/generated-artifacts/Broker.json'; +export const artifacts = { Broker: Broker as ContractArtifact }; diff --git a/contracts/broker/test/wrappers.ts b/contracts/broker/test/wrappers.ts new file mode 100644 index 0000000000..3f0ebb4864 --- /dev/null +++ b/contracts/broker/test/wrappers.ts @@ -0,0 +1,6 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +export * from '../test/generated-wrappers/broker'; diff --git a/contracts/broker/truffle-config.js b/contracts/broker/truffle-config.js new file mode 100644 index 0000000000..8c95491cdc --- /dev/null +++ b/contracts/broker/truffle-config.js @@ -0,0 +1,96 @@ +/** + * Use this file to configure your truffle project. It's seeded with some + * common settings for different networks and features like migrations, + * compilation and testing. Uncomment the ones you need or modify + * them to suit your project as necessary. + * + * More information about configuration can be found at: + * + * truffleframework.com/docs/advanced/configuration + * + * To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider) + * to sign your transactions before they're sent to a remote public node. Infura accounts + * are available for free at: infura.io/register. + * + * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate + * public/private key pairs. If you're publishing your code to GitHub make sure you load this + * phrase from a file you've .gitignored so it doesn't accidentally become public. + * + */ + +// const HDWalletProvider = require('truffle-hdwallet-provider'); +// const infuraKey = "fj4jll3k....."; +// +// const fs = require('fs'); +// const mnemonic = fs.readFileSync(".secret").toString().trim(); + +module.exports = { + /** + * Networks define how you connect to your ethereum client and let you set the + * defaults web3 uses to send transactions. If you don't specify one truffle + * will spin up a development blockchain for you on port 9545 when you + * run `develop` or `test`. You can ask a truffle command to use a specific + * network from the command line, e.g + * + * $ truffle test --network + */ + + networks: { + // Useful for testing. The `development` name is special - truffle uses it by default + // if it's defined here and no other network is specified at the command line. + // You should run a client (like ganache-cli, geth or parity) in a separate terminal + // tab if you use this network and you must also set the `host`, `port` and `network_id` + // options below to some value. + // + // development: { + // host: "127.0.0.1", // Localhost (default: none) + // port: 8545, // Standard Ethereum port (default: none) + // network_id: "*", // Any network (default: none) + // }, + // Another network with more advanced options... + // advanced: { + // port: 8777, // Custom port + // network_id: 1342, // Custom network + // gas: 8500000, // Gas sent with each transaction (default: ~6700000) + // gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei) + // from:
, // Account to send txs from (default: accounts[0]) + // websockets: true // Enable EventEmitter interface for web3 (default: false) + // }, + // Useful for deploying to a public network. + // NB: It's important to wrap the provider as a function. + // ropsten: { + // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`), + // network_id: 3, // Ropsten's id + // gas: 5500000, // Ropsten has a lower block limit than mainnet + // confirmations: 2, // # of confs to wait between deployments. (default: 0) + // timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) + // skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) + // }, + // Useful for private networks + // private: { + // provider: () => new HDWalletProvider(mnemonic, `https://network.io`), + // network_id: 2111, // This network is yours, in the cloud. + // production: true // Treats this network as if it was a public net. (default: false) + // } + }, + + // Set default mocha options here, use special reporters etc. + mocha: { + // timeout: 100000 + }, + + // Configure your compilers + compilers: { + solc: { + version: '0.5.9', + settings: { + evmVersion: 'istanbul', + optimizer: { + enabled: true, + runs: 1000000, + details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true }, + }, + }, + }, + }, +}; diff --git a/contracts/broker/tsconfig.json b/contracts/broker/tsconfig.json new file mode 100644 index 0000000000..d882eb3367 --- /dev/null +++ b/contracts/broker/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "files": ["generated-artifacts/Broker.json", "test/generated-artifacts/Broker.json"], + "exclude": ["./deploy/solc/solc_bin"] +} diff --git a/contracts/broker/tslint.json b/contracts/broker/tslint.json new file mode 100644 index 0000000000..1bb3ac2a22 --- /dev/null +++ b/contracts/broker/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": ["@0x/tslint-config"], + "rules": { + "custom-no-magic-numbers": false + } +} diff --git a/contracts/broker/typedoc-tsconfig.json b/contracts/broker/typedoc-tsconfig.json new file mode 100644 index 0000000000..c9b0af1ae6 --- /dev/null +++ b/contracts/broker/typedoc-tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../typedoc-tsconfig", + "compilerOptions": { + "outDir": "lib" + }, + "include": ["./src/**/*", "./test/**/*"] +} diff --git a/package.json b/package.json index df0a5c57fa..c837e75ce5 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "lint:contracts": "wsrun lint -p ${npm_package_config_contractsPackages} -c --fast-exit --stages --exclude-missing" }, "config": { - "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc20-bridge-sampler @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-erc20-bridge-sampler", + "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc20-bridge-sampler @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-erc20-bridge-sampler @0x/contracts-broker", "mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic", "packagesWithDocPages": "0x.js @0x/contract-wrappers @0x/connect @0x/json-schemas @0x/subproviders @0x/web3-wrapper @0x/order-utils @0x/sol-compiler @0x/sol-coverage @0x/sol-profiler @0x/sol-trace @0x/dev-utils @0x/asset-swapper @0x/migrations @0x/orderbook @0x/contracts-asset-proxy @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-extensions @0x/contracts-staking", "ignoreDependencyVersions": "@types/styled-components @types/node",