diff --git a/.circleci/config.yml b/.circleci/config.yml index f049fbdd17..6623f60bf3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,7 +81,7 @@ jobs: - restore_cache: keys: - repo-{{ .Environment.CIRCLE_SHA1 }} - - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils + - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking test-contracts-geth: docker: - image: circleci/node:9-browsers @@ -93,7 +93,7 @@ jobs: - repo-{{ .Environment.CIRCLE_SHA1 }} # HACK(albrow): we need to sleep 10 seconds to ensure the devnet is # initialized - - run: sleep 10 && TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils + - run: sleep 10 && TEST_PROVIDER=geth yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking test-publish: resource_class: medium+ docker: diff --git a/.gitignore b/.gitignore index 9fde6b4c0f..2f2bba325d 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ packages/react-docs/example/public/bundle* packages/testnet-faucets/server/ # generated contract artifacts/ +contracts/staking/generated-artifacts/ contracts/coordinator/generated-artifacts/ contracts/exchange/generated-artifacts/ contracts/asset-proxy/generated-artifacts/ @@ -101,6 +102,7 @@ python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/ # generated contract wrappers packages/abi-gen-wrappers/src/generated-wrappers/ packages/python-contract-wrappers/generated/ +contracts/staking/generated-wrappers/ contracts/coordinator/generated-wrappers/ contracts/exchange/generated-wrappers/ contracts/asset-proxy/generated-wrappers/ diff --git a/.prettierignore b/.prettierignore index f4d158c3ae..fbd71e154c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,7 @@ lib .nyc_output +/contracts/staking/generated-wrappers +/contracts/staking/generated-artifacts /contracts/coordinator/generated-wrappers /contracts/coordinator/generated-artifacts /contracts/exchange/generated-wrappers diff --git a/README.md b/README.md index 00099e4c27..334c45da34 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ These packages are all under development. See [/contracts/README.md](/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 | | [`@0x/contracts-coordinator`](/contracts/coordinator) | [![npm](https://img.shields.io/npm/v/@0x/contracts-coordinator.svg)](https://www.npmjs.com/package/@0x/contracts-coordinator) | A contract that allows users to execute 0x transactions with permission from a Coordinator | | [`@0x/contracts-dev-utils`](/contracts/dev-utils) | [![npm](https://img.shields.io/npm/v/@0x/contracts-dev-utils.svg)](https://www.npmjs.com/package/@0x/contracts-dev-utils) | A contract contains utility functions for developers (such as validating many orders using a single eth_call) | +| [`@0x/contracts-staking`](/contracts/staking) | [![npm](https://img.shields.io/npm/v/@0x/contracts-staking.svg)](https://www.npmjs.com/package/@0x/contracts-staking) | Implements the stake-based liquidity incentives defined by [`ZEIP-31`](https://github.com/0xProject/ZEIPs/issues/31) | ### Typescript/Javascript Packages diff --git a/contracts/staking/CHANGELOG.json b/contracts/staking/CHANGELOG.json new file mode 100644 index 0000000000..aa3faa9e87 --- /dev/null +++ b/contracts/staking/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "1.0.0", + "changes": [ + { + "note": "Created package", + "pr": 1821 + } + ] + } +] diff --git a/contracts/staking/CHANGELOG.md b/contracts/staking/CHANGELOG.md new file mode 100644 index 0000000000..1004e94271 --- /dev/null +++ b/contracts/staking/CHANGELOG.md @@ -0,0 +1,6 @@ + + +CHANGELOG diff --git a/contracts/staking/DEPLOYS.json b/contracts/staking/DEPLOYS.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/contracts/staking/DEPLOYS.json @@ -0,0 +1 @@ +[] diff --git a/contracts/staking/README.md b/contracts/staking/README.md new file mode 100644 index 0000000000..5d0c5153a7 --- /dev/null +++ b/contracts/staking/README.md @@ -0,0 +1,69 @@ +## ERC1155 Tokens + +This package implements the stake-based liquidity incentives defined by [ZEIP-31](https://github.com/0xProject/ZEIPs/issues/31). 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-staking --save +``` + +## 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-staking yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-staking 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/staking/compiler.json b/contracts/staking/compiler.json new file mode 100644 index 0000000000..93997e09f0 --- /dev/null +++ b/contracts/staking/compiler.json @@ -0,0 +1,21 @@ +{ + "artifactsDir": "generated-artifacts", + "contractsDir": "contracts", + "useDockerisedSolc": false, + "compilerSettings": { + "evmVersion": "constantinople", + "optimizer": { "enabled": true, "runs": 1000000 }, + "outputSelection": { + "*": { + "*": [ + "abi", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + }, + "contracts": ["src/IStaking.sol", "src/Staking.sol"] +} diff --git a/contracts/staking/contracts/src/IStaking.sol b/contracts/staking/contracts/src/IStaking.sol new file mode 100644 index 0000000000..1ca6e303df --- /dev/null +++ b/contracts/staking/contracts/src/IStaking.sol @@ -0,0 +1,24 @@ +/* + + 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.5.5; + + +interface IStaking { + +} diff --git a/contracts/staking/contracts/src/Staking.sol b/contracts/staking/contracts/src/Staking.sol new file mode 100644 index 0000000000..355dbfacc7 --- /dev/null +++ b/contracts/staking/contracts/src/Staking.sol @@ -0,0 +1,26 @@ +/* + + 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.5.5; + +import "./IStaking.sol"; + + +contract Staking is IStaking { + +} diff --git a/contracts/staking/package.json b/contracts/staking/package.json new file mode 100644 index 0000000000..4d4b8243c5 --- /dev/null +++ b/contracts/staking/package.json @@ -0,0 +1,83 @@ +{ + "name": "@0x/contracts-staking", + "version": "1.0.0", + "engines": { + "node": ">=6.12" + }, + "description": "Staking contracts used by 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", + "fix": "tslint --fix --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", + "contracts:gen": "contracts-gen", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" + }, + "config": { + "abis": "generated-artifacts/@(IStaking|Staking).json", + "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." + }, + "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/tokens/README.md", + "devDependencies": { + "@0x/abi-gen": "^2.0.10", + "@0x/contracts-gen": "^1.0.9", + "@0x/dev-utils": "^2.2.2", + "@0x/sol-compiler": "^3.1.7", + "@0x/tslint-config": "^3.0.1", + "@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": "^5.1.0", + "@0x/contracts-test-utils": "^3.1.6", + "@0x/contracts-utils": "^3.1.5", + "@0x/types": "^2.2.2", + "@0x/typescript-typings": "^4.2.2", + "@0x/utils": "^4.3.3", + "@0x/web3-wrapper": "^6.0.6", + "ethereum-types": "^2.1.2", + "lodash": "^4.17.11" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/contracts/staking/src/artifacts.ts b/contracts/staking/src/artifacts.ts new file mode 100644 index 0000000000..980e292291 --- /dev/null +++ b/contracts/staking/src/artifacts.ts @@ -0,0 +1,10 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +import * as IStaking from '../generated-artifacts/IStaking.json'; +import * as Staking from '../generated-artifacts/Staking.json'; +export const artifacts = { Staking: Staking as ContractArtifact, IStaking: IStaking as ContractArtifact }; diff --git a/contracts/staking/src/index.ts b/contracts/staking/src/index.ts new file mode 100644 index 0000000000..91dd7e0e3e --- /dev/null +++ b/contracts/staking/src/index.ts @@ -0,0 +1,2 @@ +export * from './wrappers'; +export * from './artifacts'; diff --git a/contracts/staking/src/wrappers.ts b/contracts/staking/src/wrappers.ts new file mode 100644 index 0000000000..8828ed1226 --- /dev/null +++ b/contracts/staking/src/wrappers.ts @@ -0,0 +1,7 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +export * from '../generated-wrappers/i_staking'; +export * from '../generated-wrappers/staking'; diff --git a/contracts/staking/test/global_hooks.ts b/contracts/staking/test/global_hooks.ts new file mode 100644 index 0000000000..2ca47d433b --- /dev/null +++ b/contracts/staking/test/global_hooks.ts @@ -0,0 +1,19 @@ +import { env, EnvVars } from '@0x/dev-utils'; + +import { coverage, profiler, provider } from '@0x/contracts-test-utils'; +import { providerUtils } from '@0x/utils'; + +before('start web3 provider', () => { + providerUtils.startProviderEngine(provider); +}); +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/staking/tsconfig.json b/contracts/staking/tsconfig.json new file mode 100644 index 0000000000..1d41c52f40 --- /dev/null +++ b/contracts/staking/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "files": ["generated-artifacts/IStaking.json", "generated-artifacts/Staking.json"], + "exclude": ["./deploy/solc/solc_bin"] +} diff --git a/contracts/staking/tslint.json b/contracts/staking/tslint.json new file mode 100644 index 0000000000..1bb3ac2a22 --- /dev/null +++ b/contracts/staking/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": ["@0x/tslint-config"], + "rules": { + "custom-no-magic-numbers": false + } +} diff --git a/package.json b/package.json index 70e732e5f4..4f1c7305f7 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "lint": "wsrun lint $PKG --fast-exit --parallel --exclude-missing" }, "config": { - "contractsPackages": "@0x/contracts-asset-proxy @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-multisig @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-dev-utils", + "contractsPackages": "@0x/contracts-asset-proxy @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-multisig @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking", "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", "ignoreDependencyVersions": "@types/styled-components @types/node",