Compare commits
46 Commits
protocol@2
...
@0xproject
Author | SHA1 | Date | |
---|---|---|---|
|
8fb5c29b4b | ||
|
40a061a5ca | ||
|
2ef82592a3 | ||
|
14b5448d70 | ||
|
e7d45e47bf | ||
|
28268d4355 | ||
|
50fa02c1d1 | ||
|
b36ff9103d | ||
|
f032c2466c | ||
|
b63ddc9be4 | ||
|
171430b617 | ||
|
d561043774 | ||
|
b1871e9ddd | ||
|
b4a5e7258c | ||
|
3c75debdf9 | ||
|
84d1053f73 | ||
|
f9df42f5d9 | ||
|
4414ef0a0f | ||
|
b7729ada38 | ||
|
3da67feeb2 | ||
|
8a0d563a32 | ||
|
612fc4a949 | ||
|
bf915ce403 | ||
|
0f9ea9773e | ||
|
447a3a6c26 | ||
|
f1cc16c44d | ||
|
aae16b6343 | ||
|
834e1538d1 | ||
|
afc489bc2c | ||
|
3e061e7364 | ||
|
6395c2a8b2 | ||
|
c8225288cd | ||
|
4a108aa67d | ||
|
fd9b3e0dcf | ||
|
f94b647e61 | ||
|
2eccc3efaf | ||
|
972341725e | ||
|
40b10fd29d | ||
|
b31fcffc76 | ||
|
ec222ea0cd | ||
|
5533220da0 | ||
|
6ee7024457 | ||
|
f839ac9c58 | ||
|
1a8b1460a6 | ||
|
feac0779a4 | ||
|
d9eeb0421c |
@@ -1,209 +1,219 @@
|
||||
version: 2.1
|
||||
version: 2
|
||||
|
||||
jobs:
|
||||
build:
|
||||
resource_class: xlarge
|
||||
docker:
|
||||
- image: node:16
|
||||
environment:
|
||||
NODE_OPTIONS: '--max-old-space-size=16384'
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- checkout
|
||||
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
|
||||
- run:
|
||||
name: install-yarn
|
||||
command: npm install --force --global yarn@1.22.0
|
||||
- run:
|
||||
name: yarn
|
||||
command: yarn --frozen-lockfile --ignore-engines install || yarn --frozen-lockfile --ignore-engines install
|
||||
- setup_remote_docker
|
||||
- run: yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci
|
||||
- save_cache:
|
||||
key: repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo
|
||||
- store_artifacts:
|
||||
path: ~/repo/packages/abi-gen/test-cli/output
|
||||
- store_artifacts:
|
||||
path: ~/repo/packages/contract-wrappers/generated_docs
|
||||
test-exchange-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-exchange -m --serial -c test:circleci
|
||||
test-integrations-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-integrations -m --serial -c test:circleci
|
||||
test-contracts-staking-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-staking -m --serial -c test:circleci
|
||||
test-contracts-extra-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-exchange-forwarder -p @0x/contracts-coordinator -m --serial -c test:circleci
|
||||
test-contracts-rest-ganache:
|
||||
resource_class: medium+
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-multisig -p @0x/contracts-utils -p @0x/contracts-exchange-libs -p @0x/contracts-erc20 -p @0x/contracts-erc721 -p @0x/contracts-erc1155 -p @0x/contracts-asset-proxy -p @0x/contracts-broker -p @0x/contracts-zero-ex -m --serial -c test:circleci
|
||||
test-publish:
|
||||
resource_class: large
|
||||
environment:
|
||||
NODE_OPTIONS: '--max-old-space-size=6442'
|
||||
docker:
|
||||
- image: node:16
|
||||
- image: 0xorg/verdaccio
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
command: yarn test:publish:circleci
|
||||
no_output_timeout: 1800
|
||||
- store_artifacts:
|
||||
path: ~/.npm/_logs
|
||||
test-doc-generation:
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
command: yarn test:generate_docs:circleci
|
||||
no_output_timeout: 1200
|
||||
test-rest:
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
environment:
|
||||
RUST_ROUTER: 'true'
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn wsrun -p @0x/contracts-test-utils -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/contract-artifacts -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/contract-wrappers-test -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/order-utils -m --serial -c test:circleci
|
||||
- run: yarn wsrun -p @0x/asset-swapper -m --serial -c test:circleci
|
||||
- save_cache:
|
||||
key: coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/contract-wrappers-test/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/order-utils/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-web3-wrapper-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/web3-wrapper/coverage/lcov.info
|
||||
static-tests:
|
||||
resource_class: large
|
||||
working_directory: ~/repo
|
||||
docker:
|
||||
- image: node:16
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn lerna run lint
|
||||
- run: yarn prettier:ci
|
||||
- run: yarn deps_versions:ci
|
||||
- run: yarn diff_md_docs:ci
|
||||
submit-coverage:
|
||||
docker:
|
||||
- image: node:16
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn report_coverage
|
||||
build:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
environment:
|
||||
CONTRACTS_COMMIT_HASH: '9ed05f5'
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- checkout
|
||||
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
|
||||
- restore_cache:
|
||||
key: dependency-cache-{{ checksum "package.json" }}
|
||||
- run:
|
||||
name: yarn
|
||||
command: yarn --frozen-lockfile
|
||||
- save_cache:
|
||||
key: dependency-cache-{{ checksum "package.json" }}
|
||||
paths:
|
||||
- ./node_modules
|
||||
- run: wget https://s3.amazonaws.com/testrpc-shapshots/${CONTRACTS_COMMIT_HASH}.zip
|
||||
- run: unzip ${CONTRACTS_COMMIT_HASH}.zip -d testrpc_snapshot
|
||||
- run: node ./node_modules/lerna/bin/lerna.js bootstrap
|
||||
- run: yarn build
|
||||
- save_cache:
|
||||
key: repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo
|
||||
test-installation:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn test:installation
|
||||
test-0xjs:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
name: testrpc
|
||||
command: npm run testrpc -- --db testrpc_snapshot
|
||||
background: true
|
||||
- run: yarn wsrun test:circleci 0x.js
|
||||
- save_cache:
|
||||
key: coverage-0xjs-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/0x.js/coverage/lcov.info
|
||||
test-contracts:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
name: testrpc
|
||||
command: npm run testrpc -- --db testrpc_snapshot
|
||||
background: true
|
||||
- run: yarn wsrun test:circleci contracts
|
||||
- save_cache:
|
||||
key: coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/contracts/coverage/lcov.info
|
||||
test-sol-compiler:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
name: testrpc
|
||||
command: npm run testrpc -- --db testrpc_snapshot
|
||||
background: true
|
||||
- run: yarn wsrun test:circleci @0xproject/sol-compiler
|
||||
- save_cache:
|
||||
key: coverage-sol-compiler-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/sol-compiler/coverage/lcov.info
|
||||
test-rest:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run:
|
||||
name: testrpc
|
||||
command: npm run testrpc -- --db testrpc_snapshot
|
||||
background: true
|
||||
- run: yarn wsrun test:circleci --exclude contracts --exclude 0x.js --exclude @0xproject/sol-compiler --stages --exclude-missing
|
||||
- save_cache:
|
||||
key: coverage-assert-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/assert/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-connect-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/connect/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/dev-utils/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/json-schemas/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-subproviders-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/subproviders/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/sol-cov/coverage/lcov.info
|
||||
- save_cache:
|
||||
key: coverage-metacoin-{{ .Environment.CIRCLE_SHA1 }}
|
||||
paths:
|
||||
- ~/repo/packages/metacoin/coverage/lcov.info
|
||||
lint:
|
||||
working_directory: ~/repo
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn lerna:run lint
|
||||
prettier:
|
||||
working_directory: ~/repo
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn prettier:ci
|
||||
submit-coverage:
|
||||
docker:
|
||||
- image: circleci/node:6.12
|
||||
working_directory: ~/repo
|
||||
steps:
|
||||
- restore_cache:
|
||||
keys:
|
||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-assert-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-connect-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-dev-utils-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-subproviders-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-sol-compiler-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-0xjs-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- restore_cache:
|
||||
keys:
|
||||
- coverage-metacoin-{{ .Environment.CIRCLE_SHA1 }}
|
||||
- run: yarn report_coverage
|
||||
workflows:
|
||||
version: 2
|
||||
main:
|
||||
jobs:
|
||||
version: 2
|
||||
main:
|
||||
jobs:
|
||||
- build
|
||||
- test-installation:
|
||||
requires:
|
||||
- build
|
||||
# Disabled until we begin actively developing on these packages again.
|
||||
# - test-exchange-ganache:
|
||||
# requires:
|
||||
# - build
|
||||
# - test-integrations-ganache:
|
||||
# requires:
|
||||
# - build
|
||||
# - test-contracts-staking-ganache:
|
||||
# requires:
|
||||
# - build
|
||||
# - test-contracts-extra-ganache:
|
||||
# requires:
|
||||
# - build
|
||||
- test-contracts-rest-ganache:
|
||||
requires:
|
||||
- build
|
||||
- test-rest:
|
||||
requires:
|
||||
- build
|
||||
- static-tests:
|
||||
requires:
|
||||
- build
|
||||
- test-publish:
|
||||
requires:
|
||||
- build
|
||||
- test-doc-generation:
|
||||
requires:
|
||||
- build
|
||||
# Disabled until this repo has a coveralls API key
|
||||
# - submit-coverage:
|
||||
# requires:
|
||||
# # Disabled until we begin actively developing on these packages again.
|
||||
# # - test-exchange-ganache
|
||||
# # - test-integrations-ganache
|
||||
# # - test-contracts-staking-ganache
|
||||
# # - test-contracts-extra-ganache
|
||||
# - test-contracts-rest-ganache
|
||||
# - test-rest
|
||||
# - static-tests
|
||||
- test-0xjs:
|
||||
requires:
|
||||
- build
|
||||
- test-contracts:
|
||||
requires:
|
||||
- build
|
||||
- test-sol-compiler:
|
||||
requires:
|
||||
- build
|
||||
- test-rest:
|
||||
requires:
|
||||
- build
|
||||
- prettier:
|
||||
requires:
|
||||
- build
|
||||
- lint:
|
||||
requires:
|
||||
- build
|
||||
- submit-coverage:
|
||||
requires:
|
||||
- test-0xjs
|
||||
- test-sol-compiler
|
||||
- test-rest
|
||||
- test-contracts
|
||||
|
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,4 +1 @@
|
||||
*.sol linguist-language=Solidity
|
||||
|
||||
# Automatically collapse generated files in GitHub.
|
||||
*.svg linguist-generated=true
|
||||
|
6
.github/autolabeler.yml
vendored
6
.github/autolabeler.yml
vendored
@@ -1,6 +0,0 @@
|
||||
python: ['python-packages']
|
||||
contracts: ['contracts']
|
||||
@0x/contract-addresses: ['packages/contract-addresses']
|
||||
@0x/order-utils: ['packages/order-utils']
|
||||
@0x/contract-artifacts: ['packages/contract-artifacts']
|
||||
@0x/contract-wrappers: ['packages/contract-wrappers']
|
19
.github/stale.yml
vendored
19
.github/stale.yml
vendored
@@ -1,19 +0,0 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 30
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 30
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: stale
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: >
|
||||
This issue has been automatically closed because no activity occured in 7 days after being marked as stale. If it's still relevant - feel free to reopen. Thank you
|
||||
for your contributions.
|
53
.github/workflows/publish.yml
vendored
53
.github/workflows/publish.yml
vendored
@@ -1,53 +0,0 @@
|
||||
name: publish
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ci_status:
|
||||
description: 'required CI status'
|
||||
default: 'success'
|
||||
required: true
|
||||
prerelease:
|
||||
description: 'prerelease name'
|
||||
required: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 'check successful status'
|
||||
run: |
|
||||
REF_STATUS=$(curl -s \
|
||||
'https://api.github.com/repos/${{ github.repository }}/commits/${{ github.ref }}/status' \
|
||||
| jq .state)
|
||||
[[ "${REF_STATUS}" == '"${{ github.event.inputs.ci_status }}"' ]] || \
|
||||
(echo "::error ::${{ github.ref }} does not have a successful CI status" && false)
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 16
|
||||
- uses: actions/setup-python@v2
|
||||
- name: 'configure git'
|
||||
run: |
|
||||
git config --global user.email "github-actions@github.com"
|
||||
git config --global user.name "Github Actions"
|
||||
- name: 'install dependencies'
|
||||
run: |
|
||||
yarn -D
|
||||
- name: 'build and publish'
|
||||
run: |
|
||||
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
|
||||
npm run run:publish:gha
|
||||
env:
|
||||
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
PUBLISH_PRERELEASE: ${{ github.event.inputs.prerelease }}
|
||||
- name: 'merge into main branch'
|
||||
if: github.event.inputs.prerelease == '' # unless it's a prerelease
|
||||
run: |
|
||||
git checkout main && \
|
||||
git merge ${{ github.ref }} && \
|
||||
git push
|
129
.gitignore
vendored
129
.gitignore
vendored
@@ -11,10 +11,6 @@ pids
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# SQLite database files
|
||||
*.db
|
||||
*.sqlite
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
@@ -40,15 +36,11 @@ build/Release
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# NVM config
|
||||
.nvmrc
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
.npmrc
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
@@ -75,108 +67,31 @@ generated_docs/
|
||||
|
||||
TODO.md
|
||||
|
||||
# IDE file
|
||||
.vscode
|
||||
.idea
|
||||
packages/website/public/bundle*
|
||||
packages/react-docs/example/public/bundle*
|
||||
|
||||
# server cli
|
||||
packages/testnet-faucets/server/
|
||||
|
||||
# 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/
|
||||
contracts/integrations/test/generated-artifacts/
|
||||
contracts/staking/generated-artifacts/
|
||||
contracts/staking/test/generated-artifacts/
|
||||
contracts/coordinator/generated-artifacts/
|
||||
contracts/coordinator/test/generated-artifacts/
|
||||
contracts/exchange/generated-artifacts/
|
||||
contracts/exchange/test/generated-artifacts/
|
||||
contracts/asset-proxy/generated-artifacts/
|
||||
contracts/asset-proxy/test/generated-artifacts/
|
||||
contracts/multisig/generated-artifacts/
|
||||
contracts/multisig/test/generated-artifacts/
|
||||
contracts/utils/generated-artifacts/
|
||||
contracts/utils/test/generated-artifacts/
|
||||
contracts/exchange-libs/generated-artifacts/
|
||||
contracts/exchange-libs/test/generated-artifacts/
|
||||
contracts/erc20/generated-artifacts/
|
||||
contracts/erc20/test/generated-artifacts/
|
||||
contracts/erc721/generated-artifacts/
|
||||
contracts/erc721/test/generated-artifacts/
|
||||
contracts/erc1155/generated-artifacts/
|
||||
contracts/erc1155/test/generated-artifacts/
|
||||
contracts/extensions/generated-artifacts/
|
||||
contracts/extensions/test/generated-artifacts/
|
||||
contracts/exchange-forwarder/generated-artifacts/
|
||||
contracts/exchange-forwarder/test/generated-artifacts/
|
||||
contracts/dev-utils/generated-artifacts/
|
||||
contracts/dev-utils/test/generated-artifacts/
|
||||
contracts/zero-ex/generated-artifacts/
|
||||
contracts/zero-ex/test/generated-artifacts/
|
||||
contracts/treasury/generated-artifacts/
|
||||
contracts/treasury/test/generated-artifacts/
|
||||
|
||||
# generated truffle contract artifacts/
|
||||
contracts/broker/build/
|
||||
contracts/erc20-bridge-sampler/build/
|
||||
contracts/staking/build/
|
||||
contracts/coordinator/build/
|
||||
contracts/exchange/build/
|
||||
contracts/asset-proxy/build/
|
||||
contracts/multisig/build/
|
||||
contracts/utils/build/
|
||||
contracts/exchange-libs/build/
|
||||
contracts/erc20/build/
|
||||
contracts/erc721/build/
|
||||
contracts/erc1155/build/
|
||||
contracts/extensions/build/
|
||||
contracts/exchange-forwarder/build/
|
||||
contracts/dev-utils/build/
|
||||
packages/sol-cov/test/fixtures/artifacts/
|
||||
packages/metacoin/artifacts/
|
||||
packages/order-watcher/test/artifacts/
|
||||
packages/contract-wrappers/test/artifacts/
|
||||
|
||||
# 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/
|
||||
contracts/integrations/generated-wrappers/
|
||||
contracts/integrations/test/generated-wrappers/
|
||||
contracts/staking/generated-wrappers/
|
||||
contracts/staking/test/generated-wrappers/
|
||||
contracts/coordinator/generated-wrappers/
|
||||
contracts/coordinator/test/generated-wrappers/
|
||||
contracts/exchange/generated-wrappers/
|
||||
contracts/exchange/test/generated-wrappers/
|
||||
contracts/asset-proxy/generated-wrappers/
|
||||
contracts/asset-proxy/test/generated-wrappers/
|
||||
contracts/multisig/generated-wrappers/
|
||||
contracts/multisig/test/generated-wrappers/
|
||||
contracts/utils/generated-wrappers/
|
||||
contracts/utils/test/generated-wrappers/
|
||||
contracts/exchange-libs/generated-wrappers/
|
||||
contracts/exchange-libs/test/generated-wrappers/
|
||||
contracts/erc20/generated-wrappers/
|
||||
contracts/erc20/test/generated-wrappers/
|
||||
contracts/erc721/generated-wrappers/
|
||||
contracts/erc721/test/generated-wrappers/
|
||||
contracts/erc1155/generated-wrappers/
|
||||
contracts/erc1155/test/generated-wrappers/
|
||||
contracts/extensions/generated-wrappers/
|
||||
contracts/extensions/test/generated-wrappers/
|
||||
contracts/exchange-forwarder/generated-wrappers/
|
||||
contracts/exchange-forwarder/test/generated-wrappers/
|
||||
contracts/dev-utils/generated-wrappers/
|
||||
contracts/dev-utils/test/generated-wrappers/
|
||||
contracts/zero-ex/generated-wrappers/
|
||||
contracts/zero-ex/test/generated-wrappers/
|
||||
contracts/treasury/generated-wrappers/
|
||||
contracts/treasury/test/generated-wrappers/
|
||||
packages/0x.js/src/contract_wrappers/generated/
|
||||
packages/contracts/src/contract_wrappers/generated/
|
||||
packages/contract-wrappers/src/contract_wrappers/generated/
|
||||
packages/metacoin/src/contract_wrappers
|
||||
packages/fill-scenarios/src/generated_contract_wrappers/
|
||||
packages/order-watcher/src/generated_contract_wrappers/
|
||||
packages/migrations/src/contract_wrappers
|
||||
|
||||
# Doc README copy
|
||||
packages/*/docs/README.md
|
||||
# solc-bin in sol-compiler
|
||||
packages/sol-compiler/solc_bin/
|
||||
|
||||
.DS_Store
|
||||
# Monorepo scripts
|
||||
packages/*/scripts/
|
||||
|
||||
# the snapshot that gets built for migrations sure does have a ton of files
|
||||
packages/migrations/0x_ganache_snapshot*
|
||||
ganache.log
|
||||
|
@@ -1,90 +1,10 @@
|
||||
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
|
||||
/contracts/integrations/test/generated-artifacts
|
||||
/contracts/staking/generated-wrappers
|
||||
/contracts/staking/test/generated-wrappers
|
||||
/contracts/staking/generated-artifacts
|
||||
/contracts/staking/test/generated-artifacts
|
||||
/contracts/coordinator/generated-wrappers
|
||||
/contracts/coordinator/test/generated-wrappers
|
||||
/contracts/coordinator/generated-artifacts
|
||||
/contracts/coordinator/test/generated-artifacts
|
||||
/contracts/exchange/generated-wrappers
|
||||
/contracts/exchange/test/generated-wrappers
|
||||
/contracts/exchange/generated-artifacts
|
||||
/contracts/exchange/test/generated-artifacts
|
||||
/contracts/asset-proxy/generated-wrappers
|
||||
/contracts/asset-proxy/test/generated-wrappers
|
||||
/contracts/asset-proxy/generated-artifacts
|
||||
/contracts/asset-proxy/test/generated-artifacts
|
||||
/contracts/multisig/generated-wrappers
|
||||
/contracts/multisig/test/generated-wrappers
|
||||
/contracts/multisig/generated-artifacts
|
||||
/contracts/multisig/test/generated-artifacts
|
||||
/contracts/utils/generated-wrappers
|
||||
/contracts/utils/test/generated-wrappers
|
||||
/contracts/utils/generated-artifacts
|
||||
/contracts/utils/test/generated-artifacts
|
||||
/contracts/exchange-libs/generated-wrappers
|
||||
/contracts/exchange-libs/test/generated-wrappers
|
||||
/contracts/exchange-libs/generated-artifacts
|
||||
/contracts/exchange-libs/test/generated-artifacts
|
||||
/contracts/erc20/generated-wrappers
|
||||
/contracts/erc20/test/generated-wrappers
|
||||
/contracts/erc20/generated-artifacts
|
||||
/contracts/erc20/test/generated-artifacts
|
||||
/contracts/erc721/generated-wrappers
|
||||
/contracts/erc721/test/generated-wrappers
|
||||
/contracts/erc721/generated-artifacts
|
||||
/contracts/erc721/test/generated-artifacts
|
||||
/contracts/erc1155/generated-wrappers
|
||||
/contracts/erc1155/test/generated-wrappers
|
||||
/contracts/erc1155/generated-artifacts
|
||||
/contracts/erc1155/test/generated-artifacts
|
||||
/contracts/extensions/generated-wrappers
|
||||
/contracts/extensions/test/generated-wrappers
|
||||
/contracts/extensions/generated-artifacts
|
||||
/contracts/extensions/test/generated-artifacts
|
||||
/contracts/exchange-forwarder/generated-wrappers
|
||||
/contracts/exchange-forwarder/test/generated-wrappers
|
||||
/contracts/exchange-forwarder/generated-artifacts
|
||||
/contracts/exchange-forwarder/test/generated-artifacts
|
||||
/contracts/dev-utils/generated-wrappers
|
||||
/contracts/dev-utils/test/generated-wrappers
|
||||
/contracts/dev-utils/generated-artifacts
|
||||
/contracts/dev-utils/test/generated-artifacts
|
||||
/contracts/zero-ex/generated-wrappers
|
||||
/contracts/zero-ex/test/generated-wrappers
|
||||
/contracts/zero-ex/generated-artifacts
|
||||
/contracts/zero-ex/test/generated-artifacts
|
||||
/contracts/treasury/generated-wrappers
|
||||
/contracts/treasury/test/generated-wrappers
|
||||
/contracts/treasury/generated-artifacts
|
||||
/contracts/treasury/test/generated-artifacts
|
||||
/contracts/staking/build/
|
||||
/contracts/coordinator/build/
|
||||
/contracts/exchange/build/
|
||||
/contracts/asset-proxy/build/
|
||||
/contracts/multisig/build/
|
||||
/contracts/utils/build/
|
||||
/contracts/exchange-libs/build/
|
||||
/contracts/erc20/build/
|
||||
/contracts/erc721/build/
|
||||
/contracts/erc1155/build/
|
||||
/contracts/extensions/build/
|
||||
/contracts/exchange-forwarder/build/
|
||||
/packages/asset-swapper/generated-artifacts
|
||||
/packages/asset-swapper/generated-wrappers
|
||||
/packages/asset-swapper/test/generated-artifacts
|
||||
/packages/asset-swapper/test/generated-wrappers
|
||||
/packages/0x.js/test/artifacts
|
||||
/packages/contracts/src/artifacts
|
||||
/packages/metacoin/artifacts
|
||||
/packages/contract-wrappers/test/artifacts
|
||||
/packages/order-watcher/test/artifacts
|
||||
/packages/migrations/artifacts/1.0.0
|
||||
package.json
|
||||
packages/*/docs
|
||||
docs/
|
||||
*.sol
|
||||
scripts/postpublish_utils.js
|
||||
|
@@ -1,8 +1,6 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid"
|
||||
"printWidth": 120,
|
||||
"trailingComma": all,
|
||||
"singleQuote": true
|
||||
}
|
||||
|
@@ -1,23 +0,0 @@
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Build documentation in the docs/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
# Build documentation with MkDocs
|
||||
#mkdocs:
|
||||
# configuration: mkdocs.yml
|
||||
|
||||
# Optionally build your docs in additional formats such as PDF
|
||||
#formats:
|
||||
# - pdf
|
||||
|
||||
# Optionally set the version of Python and requirements required to build your docs
|
||||
python:
|
||||
version: 3.7
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
20
CODEOWNERS
20
CODEOWNERS
@@ -1,20 +0,0 @@
|
||||
# See https://help.github.com/articles/about-codeowners/
|
||||
|
||||
# for more info about CODEOWNERS file
|
||||
|
||||
# It uses the same pattern rule for gitignore file
|
||||
|
||||
# https://git-scm.com/docs/gitignore#_pattern_format
|
||||
|
||||
packages/asset-swapper/ @dekz @dextracker @kyu-c
|
||||
|
||||
# Dev tools & setup
|
||||
|
||||
.circleci/ @dekz
|
||||
packages/contract-addresses/ @dekz @dextracker @kyu-c
|
||||
packages/contract-artifacts/ @dekz
|
||||
packages/protocol-utils/ @dekz
|
||||
|
||||
# Protocol/smart contracts
|
||||
|
||||
contracts/ @dekz @dextracker
|
@@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
- Using welcoming and inclusive language
|
||||
- Being respectful of differing viewpoints and experiences
|
||||
- Gracefully accepting constructive criticism
|
||||
- Focusing on what is best for the community
|
||||
- Showing empathy towards other community members
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
- The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
|
108
CONTRIBUTING.md
108
CONTRIBUTING.md
@@ -1,105 +1,49 @@
|
||||
## 0x Contribution Guide
|
||||
|
||||
We welcome contributions from anyone on the internet and are grateful for even the smallest contributions. This document will help get you setup to start contributing back to 0x.
|
||||
Thank you for your interest in contributing to 0x protocol! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!
|
||||
|
||||
### Getting started
|
||||
### How to contribute
|
||||
|
||||
1. Fork `0xproject/0x-tools`
|
||||
2. Clone your fork
|
||||
3. Follow the [installation & build steps](https://github.com/0xProject/0x-tools#install-dependencies) in the repo's top-level README.
|
||||
4. Setup the recommended [Development Tooling](#development-tooling).
|
||||
5. Open a PR with the `[WIP]` flag against the `development` branch and describe the change you are intending to undertake in the PR description. (see [our branch naming conventions](#branch-structure))
|
||||
If you'd like to contribute to 0x protocol, please fork the repo, fix, commit and send a pull request against the `development` branch for the maintainers to review and merge into the main code base. If you wish to submit more complex changes though, please check with a core dev first on [our RocketChat #dev channel](http://chat.0xproject.com) to ensure those changes are in-line with the general philosophy of the project and/or to get some early feedback which can make both your efforts easier as well as our review and merge procedures quick and simple.
|
||||
|
||||
Before removing the `[WIP]` tag and submitting the PR for review, make sure:
|
||||
We encourage a “PR early” approach so create the PR as early as possible even without the fix/feature ready, so that devs and other contributors know you have picked up the issue. These early PRs should indicate an 'in progress' status by adding the '[WIP]' prefix to the PR title. Please make sure your contributions adhere to our coding guidelines:
|
||||
|
||||
- It passes our linter checks (`yarn lint`)
|
||||
- It is properly formatted with Prettier (`yarn prettier`)
|
||||
- It passes our continuous integration tests (See: [Enabling code coverage checks on your fork](#enabling-code-coverage-checks-on-your-fork) for instructions on getting the `submit-coverage` test to pass on forks)
|
||||
- You've created/updated the corresponding [CHANGELOG](#CHANGELOGs) entries.
|
||||
- Your changes have sufficient test coverage (e.g regression tests have been added for bug fixes)
|
||||
* Pull requests adding features or refactoring should be opened against the `development` branch
|
||||
* Pull requests fixing bugs in the latest release version should be opened again the `master` branch
|
||||
* Write [good commit messages](https://chris.beams.io/posts/git-commit/)
|
||||
|
||||
### Branch structure
|
||||
### Code quality
|
||||
|
||||
We have two main branches:
|
||||
Because 0x.js is used by multiple relayers in production and their businesses depend on it, we strive for exceptional code quality. Please follow the existing code standards and conventions. `tslint` and `prettier` (described below) will help you.
|
||||
|
||||
- `master` represents the most recently released (published on npm) version of the codebase.
|
||||
- `development` represents the current development state of the codebase.
|
||||
If you're adding functionality, please also add tests and make sure they pass. We have an automatic coverage reporting tool, so we'll see it if they are missing ;)
|
||||
If you're adding a new public function/member, make sure you document it with Java doc-style comments. We use typedoc to generate [awesome documentation](https://0xproject.com/docs/0xjs) from the comments within our source code.
|
||||
|
||||
ALL PRs should be opened against `development`.
|
||||
If the sub-package you are modifying has a `CHANGELOG.md` file, make sure to add an entry in it for the change made to the package. For published packages, only changes that modify the public interface or behavior of the package need a CHANGELOG entry.
|
||||
|
||||
Branch names should be prefixed with `fix`, `feature` or `refactor`.
|
||||
### Styleguide
|
||||
|
||||
- e.g `fix/missing-import`
|
||||
- If the PR only edits a single package, add it's name too
|
||||
- e.g `fix/subproviders/missing-import`
|
||||
We use [TSLint](https://palantir.github.io/tslint/) with [custom configs](https://github.com/0xProject/0x-monorepo/tree/development/packages/tslint-config) to keep our code style consistent.
|
||||
|
||||
### CHANGELOGs
|
||||
To lint your code just run: `yarn lint`
|
||||
|
||||
At 0x we use [Semantic Versioning](http://semver.org/) for all our published packages. If a change you make corresponds to a semver bump, you must modify the package's `CHANGELOG.json` file accordingly.
|
||||
|
||||
Each CHANGELOG entry that corresponds to a published package will have a `timestamp`. If no entry exists without a `timestamp`, you must first create a new one:
|
||||
|
||||
```
|
||||
{
|
||||
"version": "1.0.1", <- The updated package version
|
||||
"changes": [
|
||||
{
|
||||
"note": "", <- Describe your change
|
||||
"PR": 100 <- Your PR number
|
||||
}
|
||||
]
|
||||
},
|
||||
```
|
||||
|
||||
If an entry without a `timestamp` already exists, this means other changes have been introduced by other collaborators since the last publish. Add your changes to the list of notes and adjust the version if your PR introduces a greater semver change (i.e current changes required a patch bump, but your changes require a major version bump).
|
||||
|
||||
### Development Tooling
|
||||
|
||||
We strongly recommend you use the [VSCode](https://code.visualstudio.com/) text editor since most of our code is written in TypeScript and it offers amazing support for the language.
|
||||
|
||||
#### Linter
|
||||
|
||||
We use [TSLint](https://palantir.github.io/tslint/) with [custom configs](https://github.com/0xProject/0x-tools/tree/development/packages/tslint-config) to keep our code-style consistent.
|
||||
|
||||
Use `yarn:lint` to lint the entire monorepo, and `PKG={PACKAGE_NAME} yarn lint` to lint a specific package.
|
||||
|
||||
If you want to change a rule, or add a custom rule, please make these changes to our [tslint-config](https://github.com/0xProject/0x-tools/tree/development/packages/tslint-config) package. All other packages have it as a dependency.
|
||||
|
||||
Integrate it into your text editor:
|
||||
|
||||
- VSCode: [vscode-tslint](https://marketplace.visualstudio.com/items?itemName=eg2.tslint)
|
||||
- Atom: [linter-tslint](https://atom.io/packages/linter-tslint)
|
||||
|
||||
#### Auto-formatter
|
||||
|
||||
We use [Prettier](https://prettier.io/) to auto-format our code. Be sure to either add a [text editor integration](https://prettier.io/docs/en/editors.html) or a [pre-commit hook](https://prettier.io/docs/en/precommit.html) to properly format your code changes.
|
||||
We also use [Prettier](https://prettier.io/) to auto-format our code. Be sure to either add a [text editor integration](https://prettier.io/docs/en/editors.html) or a [pre-commit hook](https://prettier.io/docs/en/precommit.html) to properly format your code changes.
|
||||
|
||||
If using the Atom text editor, we recommend you install the following packages:
|
||||
|
||||
- VSCode: [prettier-vscode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
|
||||
- Atom: [prettier-atom](https://atom.io/packages/prettier-atom)
|
||||
* [atom-typescript](https://atom.io/packages/atom-typescript)
|
||||
* [linter-tslint](https://atom.io/packages/linter-tslint)
|
||||
* [prettier-atom](https://atom.io/packages/prettier-atom)
|
||||
* [language-ethereum](https://atom.io/packages/language-ethereum)
|
||||
|
||||
## Unenforced coding conventions
|
||||
Our CI will also run TSLint and Prettier as a part of the test run when you submit your PR. Make sure that the CI tests pass for your contribution.
|
||||
|
||||
A few of our coding conventions are not yet enforced by the linter/auto-formatter. Be careful to follow these conventions in your PR's.
|
||||
### Branch structure & versioning
|
||||
|
||||
1. Unused anonymous function parameters should be named with an underscore + number (e.g \_1, \_2, etc...)
|
||||
1. There should be a new-line between methods in a class and between test cases.
|
||||
1. If a string literal has the same value in two or more places, it should be a single constant referenced in both places.
|
||||
1. Do not import from a project's `index.ts` (e.g import { Token } from '../src';). Always import from the source file itself.
|
||||
1. Generic error variables should be named `err` instead of `e` or `error`.
|
||||
1. If you _must_ cast a variable to any - try to type it back as fast as possible. (e.g., `const cw = ((zeroEx as any)._contractWrappers as ContractWrappers);`). This ensures subsequent code is type-safe.
|
||||
1. Our enum conventions coincide with the recommended TypeScript conventions, using capitalized keys, and all-caps snake-case values. Eg `GetStats = 'GET_STATS'`
|
||||
1. All public, exported methods/functions/classes must have associated Javadoc-style comments.
|
||||
We use [semantic versioning](http://semver.org/), but before a package reaches v1.0.0 all breaking changes as well as new features will be minor version bumps.
|
||||
|
||||
### Fix `submit-coverage` CI failure
|
||||
We have two main branches: `master` and `development`.
|
||||
|
||||
If you simply fork the repo and then create a PR from it, your PR will fail the `submit-coverage` check on CI. This is because the 0x CircleCI configuration sets the `COVERALLS_REPO_TOKEN` environment variable to the token for `0xProject/0x-tools`, but when running the check against your fork the token needs to match your repo's name `your-username/0x-tools`.
|
||||
`master` represents the most recent released (published on npm) version.
|
||||
|
||||
To facilitate this check, after creating your fork, but before creating the branch for your PR, do the following:
|
||||
|
||||
1. Log in to [coveralls.io](https://coveralls.io/), go to `Add Repos`, and enable your fork. Then go to the settings for that repo, and copy the `Repo Token` identifier.
|
||||
2. Log in to [CircleCI](https://circleci.com/login), go to `Add Projects`, click the `Set Up Project` button corresponding to your fork, and then click `Start Building`. (Aside from step 3 below, no actual set up is needed, since it will use the `.circleci/config.yml` file in 0x-tools, so you can ignore all of the instruction/explanation given on the page with the `Start Building` button.)
|
||||
3. In CircleCI, configure your project to add an environment variable, with name `COVERALLS_REPO_TOKEN`, and for the value paste in the `Repo Token` you copied in step 1.
|
||||
|
||||
Now, when you push to your branch, CircleCI will automatically run all of the checks in your own instance, and the coverage check will work since it has the proper `Repo Token`, and the PR will magically refer to your own checks rather than running them in the 0x CircleCI instance.
|
||||
`development` represents the development state and is a default branch to which you will submit a PR. We use this structure so that we can push hotfixes to the currently released version without needing to publish all the changes made towards the next release. If a hotfix is implemented on `master`, it is back-ported to `development`.
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<!--- Before submitting please check to see if this issue was already reported -->
|
||||
|
||||
<!--- Prefix your issue title with the package name it relates to (e.g., `0x.js: ` or `general:`) -->
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Expected Behavior
|
||||
|
||||
@@ -46,13 +46,10 @@
|
||||
|
||||
<!--- Include as many relevant details about the environment you experienced the bug in -->
|
||||
|
||||
| Package | Version |
|
||||
| ------: | :------ |
|
||||
|
||||
<!-- For example:
|
||||
| `0x.js` | 2.0.4 |
|
||||
| `Exchange Contract` | v2 |
|
||||
-->
|
||||
| Package | Version |
|
||||
| ------------------: | :------ |
|
||||
| `0x.js` | 0.25.0 |
|
||||
| `Exchange Contract` | v1 |
|
||||
|
||||
| Network |
|
||||
| ------- |
|
||||
|
4
LICENSE
4
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright 2020 ZeroEx Labs
|
||||
Copyright 2017 ZeroEx Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -10,4 +10,4 @@ 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.
|
||||
limitations under the License.
|
@@ -1,26 +1,41 @@
|
||||
<!--- Thank you for taking the time to submit a Pull Request -->
|
||||
|
||||
<!--- Provide a general summary of the issue in the Title above -->
|
||||
|
||||
## Description
|
||||
|
||||
<!--- Describe your changes in detail -->
|
||||
|
||||
## Testing instructions
|
||||
## Motivation and Context
|
||||
|
||||
<!--- Please describe how reviewers can test your changes -->
|
||||
<!--- Why is this change required? What problem does it solve? -->
|
||||
|
||||
<!--- If it fixes an open issue, please link to the issue here. -->
|
||||
|
||||
## How Has This Been Tested?
|
||||
|
||||
<!--- Please describe in detail how you tested your changes. -->
|
||||
|
||||
<!--- Include details of your testing environment, and the tests you ran to -->
|
||||
|
||||
<!--- see how your change affects other areas of the code, etc. -->
|
||||
|
||||
## Types of changes
|
||||
|
||||
<!--- What types of changes does your code introduce? Uncomment all the bullets that apply: -->
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
|
||||
<!-- * Bug fix (non-breaking change which fixes an issue) -->
|
||||
|
||||
<!-- * New feature (non-breaking change which adds functionality) -->
|
||||
|
||||
<!-- * Breaking change (fix or feature that would cause existing functionality to change) -->
|
||||
* [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
* [ ] New feature (non-breaking change which adds functionality)
|
||||
* [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
|
||||
<!--- The following points should be used to indicate the progress of your PR. Put an `x` in all the boxes that apply right now, and come back over time and check them off as you make progress. If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
|
||||
|
||||
- [ ] Prefix PR title with `[WIP]` if necessary.
|
||||
- [ ] Add tests to cover changes as needed.
|
||||
- [ ] Update documentation as needed.
|
||||
- [ ] Add new entries to the relevant CHANGELOG.jsons.
|
||||
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
|
||||
|
||||
* [ ] Change requires a change to the documentation.
|
||||
* [ ] Added tests to cover my changes.
|
||||
* [ ] Added new entries to the relevant CHANGELOG.jsons.
|
||||
* [ ] Labeled this PR with the 'WIP' label if it is a work in progress.
|
||||
* [ ] Labeled this PR with the labels corresponding to the changed package.
|
||||
|
110
README.md
110
README.md
@@ -1,54 +1,74 @@
|
||||
<img src="https://github.com/0xProject/branding/blob/master/0x%20Logo/PNG/0x-Logo-Black.png" width="150px" >
|
||||
<img src="https://github.com/0xProject/branding/blob/master/0x_Black_CMYK.png" width="200px" >
|
||||
|
||||
---
|
||||
|
||||
[0x][website-url] is an open protocol that facilitates trustless, low friction exchange of Ethereum-based assets. For more information on how it works, check out the [0x protocol specification](https://protocol.0x.org/).
|
||||
[0x][website-url] is an open protocol that facilitates trustless, low friction exchange of Ethereum-based assets. A full description of the protocol may be found in our [whitepaper][whitepaper-url].
|
||||
|
||||
This repository is a monorepo including the 0x protocol smart contracts and numerous developer tools. Each public sub-package is independently published to NPM.
|
||||
|
||||
[website-url]: https://0x.org
|
||||
[website-url]: https://0xproject.com/
|
||||
[whitepaper-url]: https://0xproject.com/pdfs/0x_white_paper.pdf
|
||||
|
||||
[](https://circleci.com/gh/0xProject/protocool)
|
||||
[](https://circleci.com/gh/0xProject/0x-monorepo)
|
||||
[](https://coveralls.io/github/0xProject/0x-monorepo?branch=development)
|
||||
[](https://discordapp.com/invite/d3FTX3M)
|
||||
[](https://chat.0xproject.com)
|
||||
[](https://gitter.im/0xProject/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://opensource.org/licenses/Apache-2.0)
|
||||
|
||||
## Packages
|
||||
### Published Packages
|
||||
|
||||
Visit our [developer portal](https://0x.org/docs/) for a comprehensive list of core & community maintained packages. All packages maintained with this monorepo are listed below.
|
||||
| Package | Version | Description |
|
||||
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [`0x.js`](/packages/0x.js) | [](https://www.npmjs.com/package/0x.js) | A Javascript library for interacting with the 0x protocol |
|
||||
| [`@0xproject/abi-gen`](/packages/abi-gen) | [](https://www.npmjs.com/package/@0xproject/abi-gen) | Tool to generate TS wrappers from smart contract ABIs |
|
||||
| [`@0xproject/assert`](/packages/assert) | [](https://www.npmjs.com/package/@0xproject/assert) | Type and schema assertions used by our packages |
|
||||
| [`@0xproject/base-contract`](/packages/base-contract) | [](https://www.npmjs.com/package/@0xproject/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts |
|
||||
| [`@0xproject/connect`](/packages/connect) | [](https://www.npmjs.com/package/@0xproject/connect) | A Javascript library for interacting with the Standard Relayer API |
|
||||
| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [](https://www.npmjs.com/package/@0xproject/sol-compiler) | A thin wrapper around Solc.js that outputs artifacts, resolves imports, only re-compiles when needed, and other niceties. |
|
||||
| [`@0xproject/dev-utils`](/packages/dev-utils) | [](https://www.npmjs.com/package/@0xproject/dev-utils) | Dev utils to be shared across 0x projects and packages |
|
||||
| [`@0xproject/json-schemas`](/packages/json-schemas) | [](https://www.npmjs.com/package/@0xproject/json-schemas) | 0x-related json schemas |
|
||||
| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts |
|
||||
| [`@0xproject/react-docs`](/packages/react-docs) | [](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON |
|
||||
| [`@0xproject/react-shared`](/packages/react-shared) | [](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components |
|
||||
| [`@0xproject/sra-report`](/packages/sra-report) | [](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance |
|
||||
| [`@0xproject/sol-cov`](/packages/sol-cov) | [](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool |
|
||||
| [`@0xproject/subproviders`](/packages/subproviders) | [](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) |
|
||||
| [`@0xproject/tslint-config`](/packages/tslint-config) | [](https://www.npmjs.com/package/@0xproject/tslint-config) | Custom 0x development TSLint rules |
|
||||
| [`@0xproject/types`](/packages/types) | [](https://www.npmjs.com/package/@0xproject/types) | Shared type declarations |
|
||||
| [`@0xproject/typescript-typings`](/packages/typescript-typings) | [](https://www.npmjs.com/package/@0xproject/typescript-typings) | Repository of types for external packages |
|
||||
| [`@0xproject/utils`](/packages/utils) | [](https://www.npmjs.com/package/@0xproject/utils) | Shared utilities |
|
||||
| [`@0xproject/web3-wrapper`](/packages/web3-wrapper) | [](https://www.npmjs.com/package/@0xproject/web3-wrapper) | Web3 wrapper |
|
||||
|
||||
### Solidity Packages
|
||||
### Private Packages
|
||||
|
||||
These packages are all under development. See [/contracts/README.md](/contracts/README.md) for a list of deployed packages.
|
||||
|
||||
| Package | Version | Description |
|
||||
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
||||
| [`@0x/contracts-zero-ex`](/contracts/zero-ex) | [](https://www.npmjs.com/package/@0x/contracts-zero-ex) | The contracts used for settling trades within the protocol |
|
||||
| [`@0x/contracts-erc20`](/contracts/erc20) | [](https://www.npmjs.com/package/@0x/contracts-erc20) | Implementations of various ERC20 tokens |
|
||||
| [`@0x/contracts-test-utils`](/contracts/test-utils) | [](https://www.npmjs.com/package/@0x/contracts-test-utils) | TypeScript/Javascript shared utilities used for testing contracts |
|
||||
| [`@0x/contracts-utils`](/contracts/utils) | [](https://www.npmjs.com/package/@0x/contracts-utils) | Generic libraries and utilities used throughout all of the contracts |
|
||||
|
||||
### TypeScript/Javascript Packages
|
||||
|
||||
#### 0x-specific packages
|
||||
|
||||
| Package | Version | Description |
|
||||
| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
||||
| [`@0x/asset-swapper`](/packages/asset-swapper) | [](https://www.npmjs.com/package/@0x/asset-swapper) | Package used to find and create aggregated swaps |
|
||||
| [`@0x/protocol-utils`](/packages/protocol-utils) | [](https://www.npmjs.com/package/@0x/protocol-utils) | A set of utilities for generating, parsing, signing and validating 0x orders |
|
||||
| [`@0x/contract-addresses`](/packages/contract-addresses) | [](https://www.npmjs.com/package/@0x/contract-addresses) | A tiny utility library for getting known deployed contract addresses for a particular network. |
|
||||
| [`@0x/contract-wrappers`](/packages/contract-wrappers) | [](https://www.npmjs.com/package/@0x/contract-wrappers) | JS/TS wrappers for interacting with the 0x smart contracts |
|
||||
| [`@0x/contract-artifacts`](/packages/contract-artifacts) | [](https://www.npmjs.com/package/@0x/contract-artifacts) | 0x smart contract compilation artifacts | |
|
||||
| Package | Description |
|
||||
| --------------------------------------------------------------- | ---------------------------------------------------------------- |
|
||||
| [`@0xproject/contracts`](/packages/contracts) | 0x solidity smart contracts & tests |
|
||||
| [`@0xproject/react-docs-example`](/packages/react-docs-example) | Example documentation site created with `@0xproject/react-docs` |
|
||||
| [`@0xproject/testnet-faucets`](/packages/testnet-faucets) | A faucet micro-service that dispenses test ERC20 tokens or Ether |
|
||||
| [`@0xproject/website`](/packages/website) | 0x website & Portal DApp |
|
||||
|
||||
## Usage
|
||||
|
||||
Node version 6.x or 8.x is required.
|
||||
Dedicated documentation pages:
|
||||
|
||||
* [0x.js Library](https://0xproject.com/docs/0xjs)
|
||||
* [0x Connect](https://0xproject.com/docs/connect)
|
||||
* [Smart contracts](https://0xproject.com/docs/contracts)
|
||||
* [Subproviders](https://0xproject.com/docs/subproviders)
|
||||
* [Sol Compiler](https://0xproject.com/docs/sol-compiler)
|
||||
* [Web3-wrapper](https://0xproject.com/docs/web3-wrapper)
|
||||
* [JSON-schemas](https://0xproject.com/docs/json-schemas)
|
||||
* [Sol-cov](https://0xproject.com/docs/sol-cov)
|
||||
* [Standard Relayer API](https://github.com/0xProject/standard-relayer-api/blob/master/README.md)
|
||||
|
||||
Node version >= 6.12 is required.
|
||||
|
||||
Most of the packages require additional typings for external dependencies.
|
||||
You can include those by prepending the `@0x/typescript-typings` package to your [`typeRoots`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) config.
|
||||
You can include those by prepending @0xproject/typescript-typings package to your [`typeRoots`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) config.
|
||||
|
||||
```json
|
||||
"typeRoots": ["node_modules/@0x/typescript-typings/types", "node_modules/@types"],
|
||||
"typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"],
|
||||
```
|
||||
|
||||
## Contributing
|
||||
@@ -59,10 +79,10 @@ We strongly recommend that the community help us make improvements and determine
|
||||
|
||||
### Install dependencies
|
||||
|
||||
Make sure you are using Yarn v1.9.4. To install using brew:
|
||||
If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them:
|
||||
|
||||
```bash
|
||||
brew install yarn@1.9.4
|
||||
yarn config set workspaces-experimental true
|
||||
```
|
||||
|
||||
Then install dependencies
|
||||
@@ -82,13 +102,7 @@ yarn build
|
||||
To build a specific package:
|
||||
|
||||
```bash
|
||||
PKG=@0x/asset-swapper yarn build
|
||||
```
|
||||
|
||||
To build all contracts packages:
|
||||
|
||||
```bash
|
||||
yarn build:contracts
|
||||
PKG=@0xproject/web3-wrapper yarn build
|
||||
```
|
||||
|
||||
### Watch
|
||||
@@ -105,7 +119,7 @@ To watch a specific package and all it's dependent packages:
|
||||
PKG=[NPM_PACKAGE_NAME] yarn watch
|
||||
|
||||
e.g
|
||||
PKG=@0x/asset-swapper yarn watch
|
||||
PKG=@0xproject/web3-wrapper yarn watch
|
||||
```
|
||||
|
||||
### Clean
|
||||
@@ -119,7 +133,7 @@ yarn clean
|
||||
Clean a specific package
|
||||
|
||||
```bash
|
||||
PKG=@0x/asset-swapper yarn clean
|
||||
PKG=0x.js yarn clean
|
||||
```
|
||||
|
||||
### Rebuild
|
||||
@@ -133,7 +147,7 @@ yarn rebuild
|
||||
To re-build (clean & build) a specific package & it's deps:
|
||||
|
||||
```bash
|
||||
PKG=@0x/asset-swapper yarn rebuild
|
||||
PKG=0x.js yarn rebuild
|
||||
```
|
||||
|
||||
### Lint
|
||||
@@ -147,7 +161,7 @@ yarn lint
|
||||
Lint a specific package:
|
||||
|
||||
```bash
|
||||
PKG=@0x/asset-swapper yarn lint
|
||||
PKG=0x.js yarn lint
|
||||
```
|
||||
|
||||
### Run Tests
|
||||
@@ -161,11 +175,5 @@ yarn test
|
||||
Run a specific package's test:
|
||||
|
||||
```bash
|
||||
PKG=@0x/asset-swapper yarn test
|
||||
```
|
||||
|
||||
Run all contracts packages tests:
|
||||
|
||||
```bash
|
||||
yarn test:contracts
|
||||
PKG=@0xproject/web3-wrapper yarn test
|
||||
```
|
||||
|
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"extends": "default",
|
||||
"rules": {
|
||||
"avoid-low-level-calls": false,
|
||||
"avoid-tx-origin": "warn",
|
||||
"bracket-align": false,
|
||||
"code-complexity": false,
|
||||
"compiler-fixed": false,
|
||||
"const-name-snakecase": "error",
|
||||
"expression-indent": "error",
|
||||
"function-max-lines": false,
|
||||
"func-order": "error",
|
||||
"indent": ["error", 4],
|
||||
"max-line-length": ["warn", 160],
|
||||
"no-inline-assembly": false,
|
||||
"quotes": ["error", "double"],
|
||||
"separate-by-one-line-in-contract": "error",
|
||||
"space-after-comma": "error",
|
||||
"statement-indent": "error",
|
||||
"no-empty-blocks": false
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
#### Development
|
||||
|
||||
Building solidity files will update the contract artifact in `{package-name}/generated-artifacts/{contract}.json`, but does not automatically update the `contract-artifacts` or `contract-wrappers` packages, which are generated from the artifact JSON. See `contract-artifacts/README.md` for instructions on updating these packages.
|
@@ -1,10 +0,0 @@
|
||||
# Blacklist all files
|
||||
.*
|
||||
*
|
||||
# Whitelist lib
|
||||
!lib/**/*
|
||||
# Whitelist Solidity contracts
|
||||
!contracts/src/**/*
|
||||
# Blacklist tests in lib
|
||||
/lib/test/*
|
||||
# Package specific ignore
|
@@ -1 +0,0 @@
|
||||
contracts/src/ZRXToken.sol
|
@@ -1,886 +0,0 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "3.3.33",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "3.3.32",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "3.3.31",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "3.3.30",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "3.3.29",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "3.3.28",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "3.3.27",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "3.3.26",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "3.3.25",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "3.3.24",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "3.3.23",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "3.3.22",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "3.3.21",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631710679,
|
||||
"version": "3.3.20",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1631120757,
|
||||
"version": "3.3.19",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "3.3.18",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "3.3.17",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629079369,
|
||||
"version": "3.3.16",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "3.3.15",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add ethers as a dependency",
|
||||
"pr": 305
|
||||
}
|
||||
],
|
||||
"timestamp": 1628665757
|
||||
},
|
||||
{
|
||||
"timestamp": 1628225642,
|
||||
"version": "3.3.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1624356181,
|
||||
"version": "3.3.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1623382456,
|
||||
"version": "3.3.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1622609597,
|
||||
"version": "3.3.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1621944788,
|
||||
"version": "3.3.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1621600614,
|
||||
"version": "3.3.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1620214333,
|
||||
"version": "3.3.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1619596077,
|
||||
"version": "3.3.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1617311315,
|
||||
"version": "3.3.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1616005394,
|
||||
"version": "3.3.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1614141718,
|
||||
"version": "3.3.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1612950500,
|
||||
"version": "3.3.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1611648096,
|
||||
"version": "3.3.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1610510890,
|
||||
"version": "3.3.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "3.3.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add SPDX license identifiers to solidity files",
|
||||
"pr": 105
|
||||
},
|
||||
{
|
||||
"note": "Allow for excess return data in `LibERC20TokenV06` compat* functions",
|
||||
"pr": 97
|
||||
}
|
||||
],
|
||||
"timestamp": 1609802516
|
||||
},
|
||||
{
|
||||
"timestamp": 1608692071,
|
||||
"version": "3.2.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1608245516,
|
||||
"version": "3.2.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1607485227,
|
||||
"version": "3.2.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1607381756,
|
||||
"version": "3.2.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1606961263,
|
||||
"version": "3.2.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1605763885,
|
||||
"version": "3.2.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1605302002,
|
||||
"version": "3.2.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1604385937,
|
||||
"version": "3.2.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1604376968,
|
||||
"version": "3.2.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1604355662,
|
||||
"version": "3.2.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1603851023,
|
||||
"version": "3.2.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1603833198,
|
||||
"version": "3.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1603265572,
|
||||
"version": "3.2.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1594788383,
|
||||
"version": "3.2.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "3.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `LibERC20Token.approveIfBelow()`",
|
||||
"pr": 2512
|
||||
},
|
||||
{
|
||||
"note": "Add solidity 0.6 contracts",
|
||||
"pr": 2545
|
||||
},
|
||||
{
|
||||
"note": "Update `LibERC20TokenV06` comments.",
|
||||
"pr": 2597
|
||||
}
|
||||
],
|
||||
"timestamp": 1592969527
|
||||
},
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.1.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "3.1.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `allowance()` and `balanceOf()` to `LibERC20Token`",
|
||||
"pr": 2464
|
||||
},
|
||||
{
|
||||
"note": "Fix broken tests",
|
||||
"pr": 2456
|
||||
}
|
||||
],
|
||||
"timestamp": 1581204851
|
||||
},
|
||||
{
|
||||
"timestamp": 1580988106,
|
||||
"version": "3.0.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1580811564,
|
||||
"version": "3.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1579682890,
|
||||
"version": "3.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1578272714,
|
||||
"version": "3.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1576540892,
|
||||
"version": "3.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1575931811,
|
||||
"version": "3.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "3.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
||||
"pr": 2330
|
||||
},
|
||||
{
|
||||
"note": "Add `decimals()` to `LibERC20Token`.",
|
||||
"pr": 2344
|
||||
},
|
||||
{
|
||||
"note": "Create `LibERC20Token`",
|
||||
"pr": 2309
|
||||
},
|
||||
{
|
||||
"note": "Replaced `SafeMath` with `LibSafeMath`",
|
||||
"pr": 2254
|
||||
}
|
||||
],
|
||||
"timestamp": 1575296764
|
||||
},
|
||||
{
|
||||
"version": "2.3.0-beta.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1575290197
|
||||
},
|
||||
{
|
||||
"version": "2.3.0-beta.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1574238768
|
||||
},
|
||||
{
|
||||
"version": "2.3.0-beta.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils",
|
||||
"pr": 2330
|
||||
},
|
||||
{
|
||||
"note": "Add `decimals()` to `LibERC20Token`.",
|
||||
"pr": 2344
|
||||
}
|
||||
],
|
||||
"timestamp": 1574030254
|
||||
},
|
||||
{
|
||||
"version": "2.3.0-beta.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Create `LibERC20Token`",
|
||||
"pr": 2309
|
||||
}
|
||||
],
|
||||
"timestamp": 1573159180
|
||||
},
|
||||
{
|
||||
"version": "2.3.0-beta.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
},
|
||||
{
|
||||
"note": "Replaced `SafeMath` with `LibSafeMath`",
|
||||
"pr": 2254
|
||||
}
|
||||
],
|
||||
"timestamp": 1570135330
|
||||
},
|
||||
{
|
||||
"timestamp": 1568744790,
|
||||
"version": "2.2.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1567521715,
|
||||
"version": "2.2.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1566446343,
|
||||
"version": "2.2.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1565296576,
|
||||
"version": "2.2.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.2.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Updated calls to <contract wrapper>.deployFrom0xArtifactAsync to include artifact dependencies.",
|
||||
"pr": 1995
|
||||
}
|
||||
],
|
||||
"timestamp": 1564604963
|
||||
},
|
||||
{
|
||||
"timestamp": 1563957393,
|
||||
"version": "2.2.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1563193019,
|
||||
"version": "2.2.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1563047529,
|
||||
"version": "2.2.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1563006338,
|
||||
"version": "2.2.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1558712885,
|
||||
"version": "2.2.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1557961111,
|
||||
"version": "2.2.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1557799313
|
||||
},
|
||||
{
|
||||
"timestamp": 1557507213,
|
||||
"version": "2.2.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Added UntransferrableDummyERC20Token",
|
||||
"pr": 1714
|
||||
}
|
||||
],
|
||||
"timestamp": 1554997931
|
||||
},
|
||||
{
|
||||
"version": "2.1.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Run Web3ProviderEngine without excess block polling",
|
||||
"pr": 1695
|
||||
}
|
||||
],
|
||||
"timestamp": 1553183790
|
||||
},
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Upgrade contracts to Solidity 0.5.5",
|
||||
"pr": 1682
|
||||
}
|
||||
],
|
||||
"timestamp": 1553091633
|
||||
},
|
||||
{
|
||||
"timestamp": 1551479279,
|
||||
"version": "1.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1551299797,
|
||||
"version": "1.0.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1551220833,
|
||||
"version": "1.0.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1551130135,
|
||||
"version": "1.0.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1549733923,
|
||||
"version": "1.0.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
],
|
||||
"timestamp": 1549547375
|
||||
},
|
||||
{
|
||||
"version": "1.0.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Fake publish to enable pinning"
|
||||
}
|
||||
],
|
||||
"timestamp": 1549504360
|
||||
},
|
||||
{
|
||||
"timestamp": 1549452781,
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1549373905,
|
||||
"version": "1.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Move all ERC20 contracts out of contracts-tokens to new package",
|
||||
"pr": 1539
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@@ -1,387 +0,0 @@
|
||||
<!--
|
||||
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
|
||||
Edit the package's CHANGELOG.json file only.
|
||||
-->
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.3.33 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.32 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.31 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.30 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.29 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.28 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.27 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.26 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.25 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.24 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.23 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.22 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.21 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.20 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.19 - _September 8, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.18 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.17 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.16 - _August 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.15 - _August 11, 2021_
|
||||
|
||||
* Add ethers as a dependency (#305)
|
||||
|
||||
## v3.3.14 - _August 6, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.13 - _June 22, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.12 - _June 11, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.11 - _June 2, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.10 - _May 25, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.9 - _May 21, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.8 - _May 5, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.7 - _April 28, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.6 - _April 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.5 - _March 17, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.4 - _February 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.3 - _February 10, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.2 - _January 26, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.1 - _January 13, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.3.0 - _January 4, 2021_
|
||||
|
||||
* Add SPDX license identifiers to solidity files (#105)
|
||||
* Allow for excess return data in `LibERC20TokenV06` compat* functions (#97)
|
||||
|
||||
## v3.2.14 - _December 23, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.13 - _December 17, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.12 - _December 9, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.11 - _December 7, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.10 - _December 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.9 - _November 19, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.8 - _November 13, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.7 - _November 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.6 - _November 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.5 - _November 2, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.4 - _October 28, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.3 - _October 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.2 - _October 21, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.1 - _July 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.0 - _June 24, 2020_
|
||||
|
||||
* Add `LibERC20Token.approveIfBelow()` (#2512)
|
||||
* Add solidity 0.6 contracts (#2545)
|
||||
* Update `LibERC20TokenV06` comments. (#2597)
|
||||
|
||||
## v3.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.0 - _February 8, 2020_
|
||||
|
||||
* Add `allowance()` and `balanceOf()` to `LibERC20Token` (#2464)
|
||||
* Fix broken tests (#2456)
|
||||
|
||||
## v3.0.6 - _February 6, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.5 - _February 4, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.4 - _January 22, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.3 - _January 6, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.2 - _December 17, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.1 - _December 9, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.0 - _December 2, 2019_
|
||||
|
||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
||||
* Add `decimals()` to `LibERC20Token`. (#2344)
|
||||
* Create `LibERC20Token` (#2309)
|
||||
* Replaced `SafeMath` with `LibSafeMath` (#2254)
|
||||
|
||||
## v2.3.0-beta.4 - _December 2, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.3.0-beta.3 - _November 20, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.3.0-beta.2 - _November 17, 2019_
|
||||
|
||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
||||
* Add `decimals()` to `LibERC20Token`. (#2344)
|
||||
|
||||
## v2.3.0-beta.1 - _November 7, 2019_
|
||||
|
||||
* Create `LibERC20Token` (#2309)
|
||||
|
||||
## v2.3.0-beta.0 - _October 3, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
* Replaced `SafeMath` with `LibSafeMath` (#2254)
|
||||
|
||||
## v2.2.14 - _September 17, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.13 - _September 3, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.12 - _August 22, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.11 - _August 8, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.10 - _July 31, 2019_
|
||||
|
||||
* Updated calls to <contract wrapper>.deployFrom0xArtifactAsync to include artifact dependencies. (#1995)
|
||||
|
||||
## v2.2.9 - _July 24, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.8 - _July 15, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.7 - _July 13, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.6 - _July 13, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.5 - _May 24, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.4 - _May 15, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.3 - _May 14, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.1 - _May 10, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.2.0 - _April 11, 2019_
|
||||
|
||||
* Added UntransferrableDummyERC20Token (#1714)
|
||||
|
||||
## v2.1.0 - _March 21, 2019_
|
||||
|
||||
* Run Web3ProviderEngine without excess block polling (#1695)
|
||||
|
||||
## v2.0.0 - _March 20, 2019_
|
||||
|
||||
* Upgrade contracts to Solidity 0.5.5 (#1682)
|
||||
|
||||
## v1.0.9 - _March 1, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.8 - _February 27, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.7 - _February 26, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.6 - _February 25, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.5 - _February 9, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.4 - _February 7, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.3 - _February 7, 2019_
|
||||
|
||||
* Fake publish to enable pinning
|
||||
|
||||
## v1.0.2 - _February 6, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1 - _February 5, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _Invalid date_
|
||||
|
||||
* Move all ERC20 contracts out of contracts-tokens to new package (#1539)
|
@@ -1,17 +0,0 @@
|
||||
[
|
||||
{
|
||||
"name": "ZRXToken",
|
||||
"version": "1.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "protocol v1 deploy",
|
||||
"networks": {
|
||||
"1": "0xe41d2489571d322189246dafa5ebde1f4699f498",
|
||||
"3": "0xff67881f8d12f372d91baae9752eb3631ff0ed00",
|
||||
"4": "0x2727e688b8fd40b198cd5fe6e408e00494a06f07",
|
||||
"42": "0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@@ -1,73 +0,0 @@
|
||||
## ERC20 Tokens
|
||||
|
||||
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 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-erc20 --save
|
||||
```
|
||||
|
||||
## Bug bounty
|
||||
|
||||
A bug bounty for the 2.0.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-erc20 yarn build
|
||||
```
|
||||
|
||||
Or continuously rebuild on change:
|
||||
|
||||
```bash
|
||||
PKG=@0x/contracts-erc20 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).
|
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"artifactsDir": "./test/generated-artifacts",
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"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",
|
||||
"devdoc"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,148 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
import "./interfaces/IERC20Token.sol";
|
||||
|
||||
|
||||
contract ERC20Token is
|
||||
IERC20Token
|
||||
{
|
||||
mapping (address => uint256) internal balances;
|
||||
mapping (address => mapping (address => uint256)) internal allowed;
|
||||
|
||||
uint256 internal _totalSupply;
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transfer(address _to, uint256 _value)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
require(
|
||||
balances[msg.sender] >= _value,
|
||||
"ERC20_INSUFFICIENT_BALANCE"
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
|
||||
balances[msg.sender] -= _value;
|
||||
balances[_to] += _value;
|
||||
|
||||
emit Transfer(
|
||||
msg.sender,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
require(
|
||||
balances[_from] >= _value,
|
||||
"ERC20_INSUFFICIENT_BALANCE"
|
||||
);
|
||||
require(
|
||||
allowed[_from][msg.sender] >= _value,
|
||||
"ERC20_INSUFFICIENT_ALLOWANCE"
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
allowed[_from][msg.sender] -= _value;
|
||||
|
||||
emit Transfer(
|
||||
_from,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @dev `msg.sender` approves `_spender` 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 Always true if the call has enough gas to complete execution
|
||||
function approve(address _spender, uint256 _value)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
emit Approval(
|
||||
msg.sender,
|
||||
_spender,
|
||||
_value
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @dev Query total supply of token
|
||||
/// @return Total supply of token
|
||||
function totalSupply()
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return _totalSupply;
|
||||
}
|
||||
|
||||
/// @dev Query the balance of owner
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return Balance of owner
|
||||
function balanceOf(address _owner)
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
/// @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)
|
||||
external
|
||||
view
|
||||
returns (uint256)
|
||||
{
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
}
|
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "../src/interfaces/IERC20Token.sol";
|
||||
|
||||
|
||||
library LibERC20Token {
|
||||
bytes constant private DECIMALS_CALL_DATA = hex"313ce567";
|
||||
|
||||
/// @dev Calls `IERC20Token(token).approve()`.
|
||||
/// Reverts if `false` is returned or if the return
|
||||
/// data length is nonzero and not 32 bytes.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param spender The address that receives an allowance.
|
||||
/// @param allowance The allowance to set.
|
||||
function approve(
|
||||
address token,
|
||||
address spender,
|
||||
uint256 allowance
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
IERC20Token(0).approve.selector,
|
||||
spender,
|
||||
allowance
|
||||
);
|
||||
_callWithOptionalBooleanResult(token, callData);
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
|
||||
/// maximum if the current approval is not already >= an amount.
|
||||
/// Reverts if `false` is returned or if the return
|
||||
/// data length is nonzero and not 32 bytes.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param spender The address that receives an allowance.
|
||||
/// @param amount The minimum allowance needed.
|
||||
function approveIfBelow(
|
||||
address token,
|
||||
address spender,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
if (IERC20Token(token).allowance(address(this), spender) < amount) {
|
||||
approve(token, spender, uint256(-1));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20Token(token).transfer()`.
|
||||
/// Reverts if `false` is returned or if the return
|
||||
/// data length is nonzero and not 32 bytes.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param to The address that receives the tokens
|
||||
/// @param amount Number of tokens to transfer.
|
||||
function transfer(
|
||||
address token,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
IERC20Token(0).transfer.selector,
|
||||
to,
|
||||
amount
|
||||
);
|
||||
_callWithOptionalBooleanResult(token, callData);
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20Token(token).transferFrom()`.
|
||||
/// Reverts if `false` is returned or if the return
|
||||
/// data length is nonzero and not 32 bytes.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param from The owner of the tokens.
|
||||
/// @param to The address that receives the tokens
|
||||
/// @param amount Number of tokens to transfer.
|
||||
function transferFrom(
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
IERC20Token(0).transferFrom.selector,
|
||||
from,
|
||||
to,
|
||||
amount
|
||||
);
|
||||
_callWithOptionalBooleanResult(token, callData);
|
||||
}
|
||||
|
||||
/// @dev Retrieves the number of decimals for a token.
|
||||
/// Returns `18` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @return tokenDecimals The number of decimals places for the token.
|
||||
function decimals(address token)
|
||||
internal
|
||||
view
|
||||
returns (uint8 tokenDecimals)
|
||||
{
|
||||
tokenDecimals = 18;
|
||||
(bool didSucceed, bytes memory resultData) = token.staticcall(DECIMALS_CALL_DATA);
|
||||
if (didSucceed && resultData.length == 32) {
|
||||
tokenDecimals = uint8(LibBytes.readUint256(resultData, 0));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Retrieves the allowance for a token, owner, and spender.
|
||||
/// Returns `0` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param owner The owner of the tokens.
|
||||
/// @param spender The address the spender.
|
||||
/// @return allowance The allowance for a token, owner, and spender.
|
||||
function allowance(address token, address owner, address spender)
|
||||
internal
|
||||
view
|
||||
returns (uint256 allowance_)
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = token.staticcall(
|
||||
abi.encodeWithSelector(
|
||||
IERC20Token(0).allowance.selector,
|
||||
owner,
|
||||
spender
|
||||
)
|
||||
);
|
||||
if (didSucceed && resultData.length == 32) {
|
||||
allowance_ = LibBytes.readUint256(resultData, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Retrieves the balance for a token owner.
|
||||
/// Returns `0` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param owner The owner of the tokens.
|
||||
/// @return balance The token balance of an owner.
|
||||
function balanceOf(address token, address owner)
|
||||
internal
|
||||
view
|
||||
returns (uint256 balance)
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = token.staticcall(
|
||||
abi.encodeWithSelector(
|
||||
IERC20Token(0).balanceOf.selector,
|
||||
owner
|
||||
)
|
||||
);
|
||||
if (didSucceed && resultData.length == 32) {
|
||||
balance = LibBytes.readUint256(resultData, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Executes a call on address `target` with calldata `callData`
|
||||
/// and asserts that either nothing was returned or a single boolean
|
||||
/// was returned equal to `true`.
|
||||
/// @param target The call target.
|
||||
/// @param callData The abi-encoded call data.
|
||||
function _callWithOptionalBooleanResult(
|
||||
address target,
|
||||
bytes memory callData
|
||||
)
|
||||
private
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = target.call(callData);
|
||||
if (didSucceed) {
|
||||
if (resultData.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (resultData.length == 32) {
|
||||
uint256 result = LibBytes.readUint256(resultData, 0);
|
||||
if (result == 1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
LibRichErrors.rrevert(resultData);
|
||||
}
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
||||
import "./UnlimitedAllowanceERC20Token.sol";
|
||||
|
||||
|
||||
contract MintableERC20Token is
|
||||
UnlimitedAllowanceERC20Token
|
||||
{
|
||||
using LibSafeMath for uint256;
|
||||
|
||||
/// @dev Mints new tokens
|
||||
/// @param _to Address of the beneficiary that will own the minted token
|
||||
/// @param _value Amount of tokens to mint
|
||||
function _mint(address _to, uint256 _value)
|
||||
internal
|
||||
{
|
||||
balances[_to] = _value.safeAdd(balances[_to]);
|
||||
_totalSupply = _totalSupply.safeAdd(_value);
|
||||
|
||||
emit Transfer(
|
||||
address(0),
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Mints new tokens
|
||||
/// @param _owner Owner of tokens that will be burned
|
||||
/// @param _value Amount of tokens to burn
|
||||
function _burn(address _owner, uint256 _value)
|
||||
internal
|
||||
{
|
||||
balances[_owner] = balances[_owner].safeSub(_value);
|
||||
_totalSupply = _totalSupply.safeSub(_value);
|
||||
|
||||
emit Transfer(
|
||||
_owner,
|
||||
address(0),
|
||||
_value
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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;
|
||||
}
|
||||
}
|
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
|
||||
contract IERC20Token {
|
||||
|
||||
// solhint-disable no-simple-event-func-name
|
||||
event Transfer(
|
||||
address indexed _from,
|
||||
address indexed _to,
|
||||
uint256 _value
|
||||
);
|
||||
|
||||
event Approval(
|
||||
address indexed _owner,
|
||||
address indexed _spender,
|
||||
uint256 _value
|
||||
);
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transfer(address _to, uint256 _value)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev `msg.sender` approves `_spender` 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 Always true if the call has enough gas to complete execution
|
||||
function approve(address _spender, uint256 _value)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev Query total supply of token
|
||||
/// @return Total supply of token
|
||||
function totalSupply()
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return Balance of owner
|
||||
function balanceOf(address _owner)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @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)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
import "./IERC20Token.sol";
|
||||
|
||||
|
||||
contract IEtherToken is
|
||||
IERC20Token
|
||||
{
|
||||
function deposit()
|
||||
public
|
||||
payable;
|
||||
|
||||
function withdraw(uint256 amount)
|
||||
public;
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 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.6.5;
|
||||
|
||||
|
||||
interface IERC20TokenV06 {
|
||||
|
||||
// solhint-disable no-simple-event-func-name
|
||||
event Transfer(
|
||||
address indexed from,
|
||||
address indexed to,
|
||||
uint256 value
|
||||
);
|
||||
|
||||
event Approval(
|
||||
address indexed owner,
|
||||
address indexed spender,
|
||||
uint256 value
|
||||
);
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transfer(address to, uint256 value)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev 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 True if transfer was successful
|
||||
function transferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 value
|
||||
)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev `msg.sender` approves `spender` 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 Always true if the call has enough gas to complete execution
|
||||
function approve(address spender, uint256 value)
|
||||
external
|
||||
returns (bool);
|
||||
|
||||
/// @dev Query total supply of token
|
||||
/// @return Total supply of token
|
||||
function totalSupply()
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @dev Get the balance of `owner`.
|
||||
/// @param owner The address from which the balance will be retrieved
|
||||
/// @return Balance of owner
|
||||
function balanceOf(address owner)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @dev Get the allowance for `spender` to spend from `owner`.
|
||||
/// @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)
|
||||
external
|
||||
view
|
||||
returns (uint256);
|
||||
|
||||
/// @dev Get the number of decimals this token has.
|
||||
function decimals()
|
||||
external
|
||||
view
|
||||
returns (uint8);
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 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.6.5;
|
||||
|
||||
import "./IERC20TokenV06.sol";
|
||||
|
||||
|
||||
interface IEtherTokenV06 is
|
||||
IERC20TokenV06
|
||||
{
|
||||
/// @dev Wrap ether.
|
||||
function deposit() external payable;
|
||||
|
||||
/// @dev Unwrap ether.
|
||||
function withdraw(uint256 amount) external;
|
||||
}
|
@@ -1,210 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2020 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.6.5;
|
||||
|
||||
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
|
||||
import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol";
|
||||
import "./IERC20TokenV06.sol";
|
||||
|
||||
|
||||
library LibERC20TokenV06 {
|
||||
bytes constant private DECIMALS_CALL_DATA = hex"313ce567";
|
||||
|
||||
/// @dev Calls `IERC20TokenV06(token).approve()`.
|
||||
/// Reverts if the return data is invalid or the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param spender The address that receives an allowance.
|
||||
/// @param allowance The allowance to set.
|
||||
function compatApprove(
|
||||
IERC20TokenV06 token,
|
||||
address spender,
|
||||
uint256 allowance
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
token.approve.selector,
|
||||
spender,
|
||||
allowance
|
||||
);
|
||||
_callWithOptionalBooleanResult(address(token), callData);
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20TokenV06(token).approve()` and sets the allowance to the
|
||||
/// maximum if the current approval is not already >= an amount.
|
||||
/// Reverts if the return data is invalid or the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param spender The address that receives an allowance.
|
||||
/// @param amount The minimum allowance needed.
|
||||
function approveIfBelow(
|
||||
IERC20TokenV06 token,
|
||||
address spender,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
if (token.allowance(address(this), spender) < amount) {
|
||||
compatApprove(token, spender, uint256(-1));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20TokenV06(token).transfer()`.
|
||||
/// Reverts if the return data is invalid or the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param to The address that receives the tokens
|
||||
/// @param amount Number of tokens to transfer.
|
||||
function compatTransfer(
|
||||
IERC20TokenV06 token,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
token.transfer.selector,
|
||||
to,
|
||||
amount
|
||||
);
|
||||
_callWithOptionalBooleanResult(address(token), callData);
|
||||
}
|
||||
|
||||
/// @dev Calls `IERC20TokenV06(token).transferFrom()`.
|
||||
/// Reverts if the return data is invalid or the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param from The owner of the tokens.
|
||||
/// @param to The address that receives the tokens
|
||||
/// @param amount Number of tokens to transfer.
|
||||
function compatTransferFrom(
|
||||
IERC20TokenV06 token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
token.transferFrom.selector,
|
||||
from,
|
||||
to,
|
||||
amount
|
||||
);
|
||||
_callWithOptionalBooleanResult(address(token), callData);
|
||||
}
|
||||
|
||||
/// @dev Retrieves the number of decimals for a token.
|
||||
/// Returns `18` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @return tokenDecimals The number of decimals places for the token.
|
||||
function compatDecimals(IERC20TokenV06 token)
|
||||
internal
|
||||
view
|
||||
returns (uint8 tokenDecimals)
|
||||
{
|
||||
tokenDecimals = 18;
|
||||
(bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA);
|
||||
if (didSucceed && resultData.length >= 32) {
|
||||
tokenDecimals = uint8(LibBytesV06.readUint256(resultData, 0));
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Retrieves the allowance for a token, owner, and spender.
|
||||
/// Returns `0` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param owner The owner of the tokens.
|
||||
/// @param spender The address the spender.
|
||||
/// @return allowance_ The allowance for a token, owner, and spender.
|
||||
function compatAllowance(IERC20TokenV06 token, address owner, address spender)
|
||||
internal
|
||||
view
|
||||
returns (uint256 allowance_)
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
|
||||
abi.encodeWithSelector(
|
||||
token.allowance.selector,
|
||||
owner,
|
||||
spender
|
||||
)
|
||||
);
|
||||
if (didSucceed && resultData.length >= 32) {
|
||||
allowance_ = LibBytesV06.readUint256(resultData, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Retrieves the balance for a token owner.
|
||||
/// Returns `0` if the call reverts.
|
||||
/// @param token The address of the token contract.
|
||||
/// @param owner The owner of the tokens.
|
||||
/// @return balance The token balance of an owner.
|
||||
function compatBalanceOf(IERC20TokenV06 token, address owner)
|
||||
internal
|
||||
view
|
||||
returns (uint256 balance)
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
|
||||
abi.encodeWithSelector(
|
||||
token.balanceOf.selector,
|
||||
owner
|
||||
)
|
||||
);
|
||||
if (didSucceed && resultData.length >= 32) {
|
||||
balance = LibBytesV06.readUint256(resultData, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Executes a call on address `target` with calldata `callData`
|
||||
/// and asserts that either nothing was returned or a single boolean
|
||||
/// was returned equal to `true`.
|
||||
/// @param target The call target.
|
||||
/// @param callData The abi-encoded call data.
|
||||
function _callWithOptionalBooleanResult(
|
||||
address target,
|
||||
bytes memory callData
|
||||
)
|
||||
private
|
||||
{
|
||||
(bool didSucceed, bytes memory resultData) = target.call(callData);
|
||||
// Revert if the call reverted.
|
||||
if (!didSucceed) {
|
||||
LibRichErrorsV06.rrevert(resultData);
|
||||
}
|
||||
// If we get back 0 returndata, this may be a non-standard ERC-20 that
|
||||
// does not return a boolean. Check that it at least contains code.
|
||||
if (resultData.length == 0) {
|
||||
uint256 size;
|
||||
assembly { size := extcodesize(target) }
|
||||
require(size > 0, "invalid token address, contains no code");
|
||||
return;
|
||||
}
|
||||
// If we get back at least 32 bytes, we know the target address
|
||||
// contains code, and we assume it is a token that returned a boolean
|
||||
// success value, which must be true.
|
||||
if (resultData.length >= 32) {
|
||||
uint256 result = LibBytesV06.readUint256(resultData, 0);
|
||||
if (result == 1) {
|
||||
return;
|
||||
} else {
|
||||
LibRichErrorsV06.rrevert(resultData);
|
||||
}
|
||||
}
|
||||
// If 0 < returndatasize < 32, the target is a contract, but not a
|
||||
// valid token.
|
||||
LibRichErrorsV06.rrevert(resultData);
|
||||
}
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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 "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
||||
import "@0x/contracts-utils/contracts/src/Ownable.sol";
|
||||
import "../src/MintableERC20Token.sol";
|
||||
|
||||
|
||||
contract DummyERC20Token is
|
||||
Ownable,
|
||||
MintableERC20Token
|
||||
{
|
||||
using LibSafeMath for uint256;
|
||||
|
||||
string public name;
|
||||
string public symbol;
|
||||
uint256 public decimals;
|
||||
uint256 public constant MAX_MINT_AMOUNT = 10000000000000000000000;
|
||||
|
||||
constructor (
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint256 _decimals,
|
||||
uint256 _totalSupply
|
||||
)
|
||||
public
|
||||
{
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
decimals = _decimals;
|
||||
_totalSupply = _totalSupply;
|
||||
balances[msg.sender] = _totalSupply;
|
||||
}
|
||||
|
||||
/// @dev Sets the balance of target address
|
||||
/// @param _target Address or which balance will be updated
|
||||
/// @param _value New balance of target address
|
||||
function setBalance(address _target, uint256 _value)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
uint256 currBalance = balances[_target];
|
||||
if (_value < currBalance) {
|
||||
_totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value));
|
||||
} else {
|
||||
_totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance));
|
||||
}
|
||||
balances[_target] = _value;
|
||||
}
|
||||
|
||||
/// @dev Mints new tokens for sender
|
||||
/// @param _value Amount of tokens to mint
|
||||
function mint(uint256 _value)
|
||||
external
|
||||
{
|
||||
require(
|
||||
_value <= MAX_MINT_AMOUNT,
|
||||
"VALUE_TOO_LARGE"
|
||||
);
|
||||
|
||||
_mint(msg.sender, _value);
|
||||
}
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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 "./DummyERC20Token.sol";
|
||||
|
||||
|
||||
// solhint-disable no-empty-blocks
|
||||
contract DummyMultipleReturnERC20Token is
|
||||
DummyERC20Token
|
||||
{
|
||||
constructor (
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint256 _decimals,
|
||||
uint256 _totalSupply
|
||||
)
|
||||
public
|
||||
DummyERC20Token(
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_totalSupply
|
||||
)
|
||||
{}
|
||||
|
||||
/// @dev 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
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
emit Transfer(
|
||||
_from,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
|
||||
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return 64 bytes (equiavalent to true, true)
|
||||
assembly {
|
||||
mstore(0, 1)
|
||||
mstore(32, 1)
|
||||
return(0, 64)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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 "./DummyERC20Token.sol";
|
||||
|
||||
|
||||
// solhint-disable no-empty-blocks
|
||||
contract DummyNoReturnERC20Token is
|
||||
DummyERC20Token
|
||||
{
|
||||
constructor (
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint256 _decimals,
|
||||
uint256 _totalSupply
|
||||
)
|
||||
public
|
||||
DummyERC20Token(
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_totalSupply
|
||||
)
|
||||
{}
|
||||
|
||||
/// @dev send `value` token to `to` from `msg.sender`
|
||||
/// @param _to The address of the recipient
|
||||
/// @param _value The amount of token to be transferred
|
||||
function transfer(address _to, uint256 _value)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
require(
|
||||
balances[msg.sender] >= _value,
|
||||
"ERC20_INSUFFICIENT_BALANCE"
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
|
||||
balances[msg.sender] -= _value;
|
||||
balances[_to] += _value;
|
||||
|
||||
emit Transfer(
|
||||
msg.sender,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
|
||||
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev 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
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
require(
|
||||
balances[_from] >= _value,
|
||||
"ERC20_INSUFFICIENT_BALANCE"
|
||||
);
|
||||
require(
|
||||
allowed[_from][msg.sender] >= _value,
|
||||
"ERC20_INSUFFICIENT_ALLOWANCE"
|
||||
);
|
||||
require(
|
||||
balances[_to] + _value >= balances[_to],
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
|
||||
balances[_to] += _value;
|
||||
balances[_from] -= _value;
|
||||
allowed[_from][msg.sender] -= _value;
|
||||
|
||||
emit Transfer(
|
||||
_from,
|
||||
_to,
|
||||
_value
|
||||
);
|
||||
|
||||
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
|
||||
assembly {
|
||||
return(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
import "../src/LibERC20Token.sol";
|
||||
import "./TestLibERC20TokenTarget.sol";
|
||||
|
||||
|
||||
contract TestLibERC20Token {
|
||||
|
||||
TestLibERC20TokenTarget public target;
|
||||
|
||||
constructor() public {
|
||||
target = new TestLibERC20TokenTarget();
|
||||
}
|
||||
|
||||
function testApprove(
|
||||
bool shouldRevert,
|
||||
bytes calldata revertData,
|
||||
bytes calldata returnData,
|
||||
address spender,
|
||||
uint256 allowance
|
||||
)
|
||||
external
|
||||
{
|
||||
target.setBehavior(shouldRevert, revertData, returnData);
|
||||
LibERC20Token.approve(address(target), spender, allowance);
|
||||
}
|
||||
|
||||
function testTransfer(
|
||||
bool shouldRevert,
|
||||
bytes calldata revertData,
|
||||
bytes calldata returnData,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
external
|
||||
{
|
||||
target.setBehavior(shouldRevert, revertData, returnData);
|
||||
LibERC20Token.transfer(address(target), to, amount);
|
||||
}
|
||||
|
||||
function testTransferFrom(
|
||||
bool shouldRevert,
|
||||
bytes calldata revertData,
|
||||
bytes calldata returnData,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
external
|
||||
{
|
||||
target.setBehavior(shouldRevert, revertData, returnData);
|
||||
LibERC20Token.transferFrom(address(target), from, to, amount);
|
||||
}
|
||||
|
||||
function testDecimals(
|
||||
bool shouldRevert,
|
||||
bytes calldata revertData,
|
||||
bytes calldata returnData
|
||||
)
|
||||
external
|
||||
returns (uint8)
|
||||
{
|
||||
target.setBehavior(shouldRevert, revertData, returnData);
|
||||
return LibERC20Token.decimals(address(target));
|
||||
}
|
||||
}
|
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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.9;
|
||||
|
||||
|
||||
contract TestLibERC20TokenTarget {
|
||||
|
||||
event ApproveCalled(
|
||||
address spender,
|
||||
uint256 allowance
|
||||
);
|
||||
|
||||
event TransferCalled(
|
||||
address to,
|
||||
uint256 amount
|
||||
);
|
||||
|
||||
event TransferFromCalled(
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
);
|
||||
|
||||
bool private _shouldRevert;
|
||||
bytes private _revertData;
|
||||
bytes private _returnData;
|
||||
|
||||
function setBehavior(
|
||||
bool shouldRevert,
|
||||
bytes calldata revertData,
|
||||
bytes calldata returnData
|
||||
)
|
||||
external
|
||||
{
|
||||
_shouldRevert = shouldRevert;
|
||||
_revertData = revertData;
|
||||
_returnData = returnData;
|
||||
}
|
||||
|
||||
function approve(
|
||||
address spender,
|
||||
uint256 allowance
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
emit ApproveCalled(spender, allowance);
|
||||
_execute();
|
||||
}
|
||||
|
||||
function transfer(
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
emit TransferCalled(to, amount);
|
||||
_execute();
|
||||
}
|
||||
|
||||
function transferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
emit TransferFromCalled(from, to, amount);
|
||||
_execute();
|
||||
}
|
||||
|
||||
function decimals()
|
||||
external
|
||||
view
|
||||
returns (uint8)
|
||||
{
|
||||
_execute();
|
||||
}
|
||||
|
||||
function _execute() private view {
|
||||
if (_shouldRevert) {
|
||||
bytes memory revertData = _revertData;
|
||||
assembly { revert(add(revertData, 0x20), mload(revertData)) }
|
||||
}
|
||||
bytes memory returnData = _returnData;
|
||||
assembly { return(add(returnData, 0x20), mload(returnData)) }
|
||||
}
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 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 "./DummyERC20Token.sol";
|
||||
|
||||
|
||||
// solhint-disable no-empty-blocks
|
||||
// solhint-disable no-unused-vars
|
||||
contract UntransferrableDummyERC20Token is
|
||||
DummyERC20Token
|
||||
{
|
||||
constructor (
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint256 _decimals,
|
||||
uint256 _totalSupply
|
||||
)
|
||||
public
|
||||
DummyERC20Token(
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
_totalSupply
|
||||
)
|
||||
{}
|
||||
|
||||
/// @dev 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
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _value
|
||||
)
|
||||
external
|
||||
returns (bool)
|
||||
{
|
||||
require(
|
||||
false,
|
||||
"TRANSFER_DISABLED"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,92 +0,0 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc20",
|
||||
"version": "3.3.33",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
"description": "Token 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 contracts:gen generate_contract_wrappers contracts:copy",
|
||||
"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",
|
||||
"fix": "tslint --fix --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",
|
||||
"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": {
|
||||
"publicInterfaceContracts": "DummyERC20Token,ERC20Token,WETH9,ZRXToken,DummyNoReturnERC20Token,DummyMultipleReturnERC20Token",
|
||||
"abis": "./test/generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ERC20Token|IERC20Token|IERC20TokenV06|IEtherToken|IEtherTokenV06|LibERC20Token|LibERC20TokenV06|MintableERC20Token|TestLibERC20Token|TestLibERC20TokenTarget|UnlimitedAllowanceERC20Token|UntransferrableDummyERC20Token|WETH9|ZRXToken).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/protocol.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/protocol/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/tokens",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.8.0",
|
||||
"@0x/contracts-gen": "^2.0.46",
|
||||
"@0x/contracts-test-utils": "^5.4.24",
|
||||
"@0x/contracts-utils": "^4.8.14",
|
||||
"@0x/dev-utils": "^4.2.14",
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/ts-doc-gen": "^0.0.28",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "12.12.54",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-bignumber": "^3.0.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"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",
|
||||
"tslint": "5.11.0",
|
||||
"typedoc": "~0.16.11",
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"ethers": "~4.0.4"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "4f91bfd907996b2f4dd383778b50c479c2602b56"
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------
|
||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as DummyERC20Token from '../generated-artifacts/DummyERC20Token.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 WETH9 from '../generated-artifacts/WETH9.json';
|
||||
import * as ZRXToken from '../generated-artifacts/ZRXToken.json';
|
||||
export const artifacts = {
|
||||
DummyERC20Token: DummyERC20Token as ContractArtifact,
|
||||
ERC20Token: ERC20Token as ContractArtifact,
|
||||
WETH9: WETH9 as ContractArtifact,
|
||||
ZRXToken: (ZRXToken as any) as ContractArtifact,
|
||||
DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact,
|
||||
DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact,
|
||||
};
|
@@ -1,47 +0,0 @@
|
||||
export {
|
||||
DummyERC20TokenContract,
|
||||
DummyMultipleReturnERC20TokenContract,
|
||||
DummyNoReturnERC20TokenContract,
|
||||
WETH9Contract,
|
||||
WETH9Events,
|
||||
WETH9DepositEventArgs,
|
||||
WETH9TransferEventArgs,
|
||||
WETH9WithdrawalEventArgs,
|
||||
ZRXTokenContract,
|
||||
DummyERC20TokenTransferEventArgs,
|
||||
ERC20TokenEventArgs,
|
||||
ERC20TokenEvents,
|
||||
ERC20TokenTransferEventArgs,
|
||||
ERC20TokenApprovalEventArgs,
|
||||
ERC20TokenContract,
|
||||
} from './wrappers';
|
||||
export { artifacts } from './artifacts';
|
||||
export {
|
||||
ContractArtifact,
|
||||
ContractChains,
|
||||
CompilerOpts,
|
||||
StandardContractOutput,
|
||||
CompilerSettings,
|
||||
ContractChainData,
|
||||
ContractAbi,
|
||||
DevdocOutput,
|
||||
EvmOutput,
|
||||
CompilerSettingsMetadata,
|
||||
OptimizerSettings,
|
||||
OutputField,
|
||||
ParamDescription,
|
||||
EvmBytecodeOutput,
|
||||
EvmBytecodeOutputLinkReferences,
|
||||
AbiDefinition,
|
||||
FunctionAbi,
|
||||
EventAbi,
|
||||
RevertErrorAbi,
|
||||
EventParameter,
|
||||
DataItem,
|
||||
MethodAbi,
|
||||
ConstructorAbi,
|
||||
FallbackAbi,
|
||||
ConstructorStateMutability,
|
||||
TupleDataItem,
|
||||
StateMutability,
|
||||
} from 'ethereum-types';
|
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------
|
||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
export * from '../generated-wrappers/dummy_erc20_token';
|
||||
export * from '../generated-wrappers/dummy_multiple_return_erc20_token';
|
||||
export * from '../generated-wrappers/dummy_no_return_erc20_token';
|
||||
export * from '../generated-wrappers/erc20_token';
|
||||
export * from '../generated-wrappers/weth9';
|
||||
export * from '../generated-wrappers/zrx_token';
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------
|
||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as DummyERC20Token from '../test/generated-artifacts/DummyERC20Token.json';
|
||||
import * as DummyMultipleReturnERC20Token from '../test/generated-artifacts/DummyMultipleReturnERC20Token.json';
|
||||
import * as DummyNoReturnERC20Token from '../test/generated-artifacts/DummyNoReturnERC20Token.json';
|
||||
import * as ERC20Token from '../test/generated-artifacts/ERC20Token.json';
|
||||
import * as IERC20Token from '../test/generated-artifacts/IERC20Token.json';
|
||||
import * as IERC20TokenV06 from '../test/generated-artifacts/IERC20TokenV06.json';
|
||||
import * as IEtherToken from '../test/generated-artifacts/IEtherToken.json';
|
||||
import * as IEtherTokenV06 from '../test/generated-artifacts/IEtherTokenV06.json';
|
||||
import * as LibERC20Token from '../test/generated-artifacts/LibERC20Token.json';
|
||||
import * as LibERC20TokenV06 from '../test/generated-artifacts/LibERC20TokenV06.json';
|
||||
import * as MintableERC20Token from '../test/generated-artifacts/MintableERC20Token.json';
|
||||
import * as TestLibERC20Token from '../test/generated-artifacts/TestLibERC20Token.json';
|
||||
import * as TestLibERC20TokenTarget from '../test/generated-artifacts/TestLibERC20TokenTarget.json';
|
||||
import * as UnlimitedAllowanceERC20Token from '../test/generated-artifacts/UnlimitedAllowanceERC20Token.json';
|
||||
import * as UntransferrableDummyERC20Token from '../test/generated-artifacts/UntransferrableDummyERC20Token.json';
|
||||
import * as WETH9 from '../test/generated-artifacts/WETH9.json';
|
||||
import * as ZRXToken from '../test/generated-artifacts/ZRXToken.json';
|
||||
export const artifacts = {
|
||||
ERC20Token: ERC20Token as ContractArtifact,
|
||||
LibERC20Token: LibERC20Token as ContractArtifact,
|
||||
MintableERC20Token: MintableERC20Token as ContractArtifact,
|
||||
UnlimitedAllowanceERC20Token: UnlimitedAllowanceERC20Token as ContractArtifact,
|
||||
WETH9: WETH9 as ContractArtifact,
|
||||
ZRXToken: (ZRXToken as any) as ContractArtifact,
|
||||
IERC20Token: IERC20Token as ContractArtifact,
|
||||
IEtherToken: IEtherToken as ContractArtifact,
|
||||
IERC20TokenV06: IERC20TokenV06 as ContractArtifact,
|
||||
IEtherTokenV06: IEtherTokenV06 as ContractArtifact,
|
||||
LibERC20TokenV06: LibERC20TokenV06 as ContractArtifact,
|
||||
DummyERC20Token: DummyERC20Token as ContractArtifact,
|
||||
DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact,
|
||||
DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact,
|
||||
TestLibERC20Token: TestLibERC20Token as ContractArtifact,
|
||||
TestLibERC20TokenTarget: TestLibERC20TokenTarget as ContractArtifact,
|
||||
UntransferrableDummyERC20Token: UntransferrableDummyERC20Token as ContractArtifact,
|
||||
};
|
@@ -1,19 +0,0 @@
|
||||
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();
|
||||
});
|
@@ -1,335 +0,0 @@
|
||||
import {
|
||||
blockchainTests,
|
||||
constants,
|
||||
expect,
|
||||
getRandomInteger,
|
||||
randomAddress,
|
||||
verifyEventsFromLogs,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { hexUtils, RawRevertError, StringRevertError } from '@0x/utils';
|
||||
|
||||
import { TestLibERC20TokenContract, TestLibERC20TokenTargetEvents } from './wrappers';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
|
||||
blockchainTests('LibERC20Token', env => {
|
||||
let testContract: TestLibERC20TokenContract;
|
||||
const REVERT_STRING = 'WHOOPSIE';
|
||||
const ENCODED_REVERT = new StringRevertError(REVERT_STRING).encode();
|
||||
const ENCODED_TRUE = hexUtils.leftPad(1);
|
||||
const ENCODED_FALSE = hexUtils.leftPad(0);
|
||||
const ENCODED_TWO = hexUtils.leftPad(2);
|
||||
const ENCODED_SHORT_TRUE = hexUtils.leftPad(2, 31);
|
||||
const ENCODED_LONG_TRUE = hexUtils.leftPad(2, 33);
|
||||
|
||||
before(async () => {
|
||||
testContract = await TestLibERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestLibERC20Token,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
});
|
||||
|
||||
describe('approve()', () => {
|
||||
it('calls the target with the correct arguments', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const { logs } = await testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(logs).to.be.length(1);
|
||||
verifyEventsFromLogs(logs, [{ spender, allowance }], TestLibERC20TokenTargetEvents.ApproveCalled);
|
||||
});
|
||||
|
||||
it('succeeds if the target returns true', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('succeeds if the target returns nothing', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testApprove(false, ENCODED_REVERT, constants.NULL_BYTES, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('fails if the target returns false', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_FALSE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_FALSE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns nonzero and not true', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_TWO, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_TWO);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns less than 32 bytes', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns greater than 32 bytes', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(false, ENCODED_REVERT, ENCODED_LONG_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target reverts', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(true, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(REVERT_STRING);
|
||||
});
|
||||
|
||||
it('fails if the target reverts with no data', async () => {
|
||||
const spender = randomAddress();
|
||||
const allowance = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testApprove(true, constants.NULL_BYTES, ENCODED_TRUE, spender, allowance)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.be.rejectedWith('revert');
|
||||
});
|
||||
});
|
||||
|
||||
describe('transfer()', () => {
|
||||
it('calls the target with the correct arguments', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const { logs } = await testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(logs).to.be.length(1);
|
||||
verifyEventsFromLogs(logs, [{ to, amount }], TestLibERC20TokenTargetEvents.TransferCalled);
|
||||
});
|
||||
|
||||
it('succeeds if the target returns true', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('succeeds if the target returns nothing', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testTransfer(false, ENCODED_REVERT, constants.NULL_BYTES, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('fails if the target returns false', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_FALSE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_FALSE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns nonzero and not true', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_TWO, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_TWO);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns less than 32 bytes', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns greater than 32 bytes', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(false, ENCODED_REVERT, ENCODED_LONG_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target reverts', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(true, ENCODED_REVERT, ENCODED_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(REVERT_STRING);
|
||||
});
|
||||
|
||||
it('fails if the target reverts with no data', async () => {
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransfer(true, constants.NULL_BYTES, ENCODED_TRUE, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.be.rejectedWith('revert');
|
||||
});
|
||||
});
|
||||
|
||||
describe('transferFrom()', () => {
|
||||
it('calls the target with the correct arguments', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const { logs } = await testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
expect(logs).to.be.length(1);
|
||||
verifyEventsFromLogs(logs, [{ from: owner, to, amount }], TestLibERC20TokenTargetEvents.TransferFromCalled);
|
||||
});
|
||||
|
||||
it('succeeds if the target returns true', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('succeeds if the target returns nothing', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
await testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, constants.NULL_BYTES, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('fails if the target returns false', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_FALSE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_FALSE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns nonzero and not true', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TWO, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_TWO);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns less than 32 bytes', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target returns greater than 32 bytes', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(false, ENCODED_REVERT, ENCODED_LONG_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('fails if the target reverts', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(true, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(REVERT_STRING);
|
||||
});
|
||||
|
||||
it('fails if the target reverts with no data', async () => {
|
||||
const owner = randomAddress();
|
||||
const to = randomAddress();
|
||||
const amount = getRandomInteger(0, 100e18);
|
||||
const tx = testContract
|
||||
.testTransferFrom(true, constants.NULL_BYTES, ENCODED_TRUE, owner, to, amount)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.be.rejectedWith('revert');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decimals()', () => {
|
||||
const DEFAULT_DECIMALS = 18;
|
||||
const ENCODED_ZERO = hexUtils.leftPad(0);
|
||||
const ENCODED_SHORT_ZERO = hexUtils.leftPad(0, 31);
|
||||
const ENCODED_LONG_ZERO = hexUtils.leftPad(0, 33);
|
||||
const randomDecimals = () => Math.floor(Math.random() * 256) + 1;
|
||||
|
||||
it('returns the number of decimals defined by the token', async () => {
|
||||
const decimals = randomDecimals();
|
||||
const encodedDecimals = hexUtils.leftPad(decimals);
|
||||
const result = await testContract.testDecimals(false, ENCODED_REVERT, encodedDecimals).callAsync();
|
||||
return expect(result).to.bignumber.eq(decimals);
|
||||
});
|
||||
|
||||
it('returns 0 if the token returns 0', async () => {
|
||||
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_ZERO).callAsync();
|
||||
return expect(result).to.bignumber.eq(0);
|
||||
});
|
||||
|
||||
it('returns 18 if the token returns less than 32 bytes', async () => {
|
||||
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_SHORT_ZERO).callAsync();
|
||||
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
|
||||
});
|
||||
|
||||
it('returns 18 if the token returns greater than 32 bytes', async () => {
|
||||
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_LONG_ZERO).callAsync();
|
||||
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
|
||||
});
|
||||
|
||||
it('returns 18 if the token reverts', async () => {
|
||||
const result = await testContract.testDecimals(true, ENCODED_REVERT, ENCODED_ZERO).callAsync();
|
||||
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,187 +0,0 @@
|
||||
import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
|
||||
import { DummyERC20TokenContract } from './wrappers';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('UnlimitedAllowanceToken', () => {
|
||||
let owner: string;
|
||||
let spender: string;
|
||||
const MAX_MINT_VALUE = new BigNumber(10000000000000000000000);
|
||||
let token: DummyERC20TokenContract;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
spender = accounts[1];
|
||||
token = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.DummyERC20Token,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
constants.DUMMY_TOKEN_NAME,
|
||||
constants.DUMMY_TOKEN_SYMBOL,
|
||||
constants.DUMMY_TOKEN_DECIMALS,
|
||||
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.mint(MAX_MINT_VALUE).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
describe('transfer', () => {
|
||||
it('should revert if owner has insufficient balance', async () => {
|
||||
const ownerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = ownerBalance.plus(1);
|
||||
return expect(token.transfer(spender, amountToTransfer).callAsync({ from: owner })).to.revertWith(
|
||||
RevertReason.Erc20InsufficientBalance,
|
||||
);
|
||||
});
|
||||
|
||||
it('should transfer balance from sender to receiver', async () => {
|
||||
const receiver = spender;
|
||||
const initOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = new BigNumber(1);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.transfer(receiver, amountToTransfer).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
const finalOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const finalReceiverBalance = await token.balanceOf(receiver).callAsync();
|
||||
|
||||
const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
|
||||
const expectedFinalReceiverBalance = amountToTransfer;
|
||||
expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance);
|
||||
expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance);
|
||||
});
|
||||
|
||||
it('should return true on a 0 value transfer', async () => {
|
||||
const didReturnTrue = await token.transfer(spender, new BigNumber(0)).callAsync({
|
||||
from: owner,
|
||||
});
|
||||
expect(didReturnTrue).to.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('transferFrom', () => {
|
||||
it('should revert if owner has insufficient balance', async () => {
|
||||
const ownerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = ownerBalance.plus(1);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.approve(spender, amountToTransfer).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
return expect(
|
||||
token.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
}),
|
||||
).to.revertWith(RevertReason.Erc20InsufficientBalance);
|
||||
});
|
||||
|
||||
it('should revert if spender has insufficient allowance', async () => {
|
||||
const ownerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = ownerBalance;
|
||||
|
||||
const spenderAllowance = await token.allowance(owner, spender).callAsync();
|
||||
const isSpenderAllowanceInsufficient = spenderAllowance.comparedTo(amountToTransfer) < 0;
|
||||
expect(isSpenderAllowanceInsufficient).to.be.true();
|
||||
|
||||
return expect(
|
||||
token.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
}),
|
||||
).to.revertWith(RevertReason.Erc20InsufficientAllowance);
|
||||
});
|
||||
|
||||
it('should return true on a 0 value transfer', async () => {
|
||||
const amountToTransfer = new BigNumber(0);
|
||||
const didReturnTrue = await token.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
});
|
||||
expect(didReturnTrue).to.be.true();
|
||||
});
|
||||
|
||||
it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
|
||||
const initOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
const initSpenderAllowance = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newSpenderAllowance = await token.allowance(owner, spender).callAsync();
|
||||
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
|
||||
});
|
||||
|
||||
it('should transfer the correct balances if spender has sufficient allowance', async () => {
|
||||
const initOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
const initSpenderAllowance = initOwnerBalance;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const newSpenderBalance = await token.balanceOf(spender).callAsync();
|
||||
|
||||
expect(newOwnerBalance).to.be.bignumber.equal(0);
|
||||
expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance);
|
||||
});
|
||||
|
||||
it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
|
||||
const initOwnerBalance = await token.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
const initSpenderAllowance = initOwnerBalance;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newSpenderAllowance = await token.allowance(owner, spender).callAsync();
|
||||
expect(newSpenderAllowance).to.be.bignumber.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,149 +0,0 @@
|
||||
import {
|
||||
chaiSetup,
|
||||
constants,
|
||||
expectInsufficientFundsAsync,
|
||||
expectTransactionFailedWithoutReasonAsync,
|
||||
provider,
|
||||
txDefaults,
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
|
||||
import { WETH9Contract } from './wrappers';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('EtherToken', () => {
|
||||
let account: string;
|
||||
const gasPrice = new BigNumber(constants.DEFAULT_GAS_PRICE);
|
||||
let etherToken: WETH9Contract;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
account = accounts[0];
|
||||
|
||||
etherToken = await WETH9Contract.deployFrom0xArtifactAsync(
|
||||
artifacts.WETH9,
|
||||
provider,
|
||||
{
|
||||
...txDefaults,
|
||||
gasPrice,
|
||||
},
|
||||
artifacts,
|
||||
);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
describe('deposit', () => {
|
||||
it('should revert if caller attempts to deposit more Ether than caller balance', async () => {
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const ethToDeposit = initEthBalance.plus(1);
|
||||
|
||||
return expectInsufficientFundsAsync(etherToken.deposit().sendTransactionAsync({ value: ethToDeposit }));
|
||||
});
|
||||
|
||||
it('should convert deposited Ether to wrapped Ether tokens', async () => {
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
|
||||
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
|
||||
|
||||
const txHash = await etherToken.deposit().sendTransactionAsync({ value: ethToDeposit });
|
||||
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
txHash,
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
|
||||
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
|
||||
});
|
||||
});
|
||||
|
||||
describe('withdraw', () => {
|
||||
it('should revert if caller attempts to withdraw greater than caller balance', async () => {
|
||||
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
|
||||
|
||||
return expectTransactionFailedWithoutReasonAsync(
|
||||
etherToken.withdraw(ethTokensToWithdraw).sendTransactionAsync(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should convert ether tokens to ether with sufficient balance', async () => {
|
||||
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await etherToken.deposit().sendTransactionAsync({ value: ethToDeposit }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const ethTokensToWithdraw = initEthTokenBalance;
|
||||
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
|
||||
const txHash = await etherToken.withdraw(ethTokensToWithdraw).sendTransactionAsync({
|
||||
gas: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
|
||||
});
|
||||
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
txHash,
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(
|
||||
initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
|
||||
);
|
||||
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
|
||||
});
|
||||
});
|
||||
|
||||
describe('fallback', () => {
|
||||
it('should convert sent ether to ether tokens', async () => {
|
||||
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
|
||||
const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18);
|
||||
|
||||
const txHash = await web3Wrapper.sendTransactionAsync({
|
||||
from: account,
|
||||
to: etherToken.address,
|
||||
value: ethToDeposit,
|
||||
gasPrice,
|
||||
});
|
||||
|
||||
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
txHash,
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
|
||||
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
|
||||
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
|
||||
|
||||
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
|
||||
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* -----------------------------------------------------------------------------
|
||||
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
export * from '../test/generated-wrappers/dummy_erc20_token';
|
||||
export * from '../test/generated-wrappers/dummy_multiple_return_erc20_token';
|
||||
export * from '../test/generated-wrappers/dummy_no_return_erc20_token';
|
||||
export * from '../test/generated-wrappers/erc20_token';
|
||||
export * from '../test/generated-wrappers/i_erc20_token';
|
||||
export * from '../test/generated-wrappers/i_erc20_token_v06';
|
||||
export * from '../test/generated-wrappers/i_ether_token';
|
||||
export * from '../test/generated-wrappers/i_ether_token_v06';
|
||||
export * from '../test/generated-wrappers/lib_erc20_token';
|
||||
export * from '../test/generated-wrappers/lib_erc20_token_v06';
|
||||
export * from '../test/generated-wrappers/mintable_erc20_token';
|
||||
export * from '../test/generated-wrappers/test_lib_erc20_token';
|
||||
export * from '../test/generated-wrappers/test_lib_erc20_token_target';
|
||||
export * from '../test/generated-wrappers/unlimited_allowance_erc20_token';
|
||||
export * from '../test/generated-wrappers/untransferrable_dummy_erc20_token';
|
||||
export * from '../test/generated-wrappers/weth9';
|
||||
export * from '../test/generated-wrappers/zrx_token';
|
@@ -1,210 +0,0 @@
|
||||
import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
|
||||
import { ZRXTokenContract } from './wrappers';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
|
||||
describe('ZRXToken', () => {
|
||||
let owner: string;
|
||||
let spender: string;
|
||||
let MAX_UINT: BigNumber;
|
||||
let zrxToken: ZRXTokenContract;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
after(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
before(async () => {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
spender = accounts[1];
|
||||
zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ZRXToken,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
MAX_UINT = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
afterEach(async () => {
|
||||
await blockchainLifecycle.revertAsync();
|
||||
});
|
||||
describe('constants', () => {
|
||||
it('should have 18 decimals', async () => {
|
||||
const decimals = new BigNumber(await zrxToken.decimals().callAsync());
|
||||
const expectedDecimals = 18;
|
||||
expect(decimals).to.be.bignumber.equal(expectedDecimals);
|
||||
});
|
||||
|
||||
it('should have a total supply of 1 billion tokens', async () => {
|
||||
const totalSupply = new BigNumber(await zrxToken.totalSupply().callAsync());
|
||||
const expectedTotalSupply = 1000000000;
|
||||
expect(Web3Wrapper.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply);
|
||||
});
|
||||
|
||||
it('should be named 0x Protocol Token', async () => {
|
||||
const name = await zrxToken.name().callAsync();
|
||||
const expectedName = '0x Protocol Token';
|
||||
expect(name).to.be.equal(expectedName);
|
||||
});
|
||||
|
||||
it('should have the symbol ZRX', async () => {
|
||||
const symbol = await zrxToken.symbol().callAsync();
|
||||
const expectedSymbol = 'ZRX';
|
||||
expect(symbol).to.be.equal(expectedSymbol);
|
||||
});
|
||||
});
|
||||
|
||||
describe('constructor', () => {
|
||||
it('should initialize owner balance to totalSupply', async () => {
|
||||
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const totalSupply = new BigNumber(await zrxToken.totalSupply().callAsync());
|
||||
expect(totalSupply).to.be.bignumber.equal(ownerBalance);
|
||||
});
|
||||
});
|
||||
|
||||
describe('transfer', () => {
|
||||
it('should transfer balance from sender to receiver', async () => {
|
||||
const receiver = spender;
|
||||
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = new BigNumber(1);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.transfer(receiver, amountToTransfer).sendTransactionAsync({ from: owner }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
const finalOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const finalReceiverBalance = await zrxToken.balanceOf(receiver).callAsync();
|
||||
|
||||
const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
|
||||
const expectedFinalReceiverBalance = amountToTransfer;
|
||||
expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance);
|
||||
expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance);
|
||||
});
|
||||
|
||||
it('should return true on a 0 value transfer', async () => {
|
||||
const didReturnTrue = await zrxToken.transfer(spender, new BigNumber(0)).callAsync({
|
||||
from: owner,
|
||||
});
|
||||
expect(didReturnTrue).to.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('transferFrom', () => {
|
||||
it('should return false if owner has insufficient balance', async () => {
|
||||
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = ownerBalance.plus(1);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.approve(spender, amountToTransfer).sendTransactionAsync({
|
||||
from: owner,
|
||||
gas: constants.MAX_TOKEN_APPROVE_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
});
|
||||
expect(didReturnTrue).to.be.false();
|
||||
});
|
||||
|
||||
it('should return false if spender has insufficient allowance', async () => {
|
||||
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = ownerBalance;
|
||||
|
||||
const spenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
|
||||
const isSpenderAllowanceInsufficient = spenderAllowance.comparedTo(amountToTransfer) < 0;
|
||||
expect(isSpenderAllowanceInsufficient).to.be.true();
|
||||
|
||||
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
});
|
||||
expect(didReturnTrue).to.be.false();
|
||||
});
|
||||
|
||||
it('should return true on a 0 value transfer', async () => {
|
||||
const amountToTransfer = new BigNumber(0);
|
||||
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
|
||||
from: spender,
|
||||
});
|
||||
expect(didReturnTrue).to.be.true();
|
||||
});
|
||||
|
||||
it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
|
||||
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
const initSpenderAllowance = MAX_UINT;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.approve(spender, initSpenderAllowance).sendTransactionAsync({
|
||||
from: owner,
|
||||
gas: constants.MAX_TOKEN_APPROVE_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newSpenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
|
||||
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
|
||||
});
|
||||
|
||||
it('should transfer the correct balances if spender has sufficient allowance', async () => {
|
||||
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const initSpenderBalance = await zrxToken.balanceOf(spender).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
const initSpenderAllowance = initOwnerBalance;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.approve(spender, initSpenderAllowance).sendTransactionAsync(),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const newSpenderBalance = await zrxToken.balanceOf(spender).callAsync();
|
||||
|
||||
expect(newOwnerBalance).to.be.bignumber.equal(0);
|
||||
expect(newSpenderBalance).to.be.bignumber.equal(initSpenderBalance.plus(initOwnerBalance));
|
||||
});
|
||||
|
||||
it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
|
||||
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
|
||||
const amountToTransfer = initOwnerBalance;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.approve(spender, amountToTransfer).sendTransactionAsync(),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
|
||||
from: spender,
|
||||
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const newSpenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
|
||||
expect(newSpenderAllowance).to.be.bignumber.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* 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 <network-name>
|
||||
*/
|
||||
|
||||
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: <address>, // 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: 'constantinople',
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
runs: 1000000,
|
||||
details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig",
|
||||
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
|
||||
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
|
||||
"files": [
|
||||
"generated-artifacts/DummyERC20Token.json",
|
||||
"generated-artifacts/DummyMultipleReturnERC20Token.json",
|
||||
"generated-artifacts/DummyNoReturnERC20Token.json",
|
||||
"generated-artifacts/ERC20Token.json",
|
||||
"generated-artifacts/WETH9.json",
|
||||
"generated-artifacts/ZRXToken.json",
|
||||
"test/generated-artifacts/DummyERC20Token.json",
|
||||
"test/generated-artifacts/DummyMultipleReturnERC20Token.json",
|
||||
"test/generated-artifacts/DummyNoReturnERC20Token.json",
|
||||
"test/generated-artifacts/ERC20Token.json",
|
||||
"test/generated-artifacts/IERC20Token.json",
|
||||
"test/generated-artifacts/IERC20TokenV06.json",
|
||||
"test/generated-artifacts/IEtherToken.json",
|
||||
"test/generated-artifacts/IEtherTokenV06.json",
|
||||
"test/generated-artifacts/LibERC20Token.json",
|
||||
"test/generated-artifacts/LibERC20TokenV06.json",
|
||||
"test/generated-artifacts/MintableERC20Token.json",
|
||||
"test/generated-artifacts/TestLibERC20Token.json",
|
||||
"test/generated-artifacts/TestLibERC20TokenTarget.json",
|
||||
"test/generated-artifacts/UnlimitedAllowanceERC20Token.json",
|
||||
"test/generated-artifacts/UntransferrableDummyERC20Token.json",
|
||||
"test/generated-artifacts/WETH9.json",
|
||||
"test/generated-artifacts/ZRXToken.json"
|
||||
],
|
||||
"exclude": ["./deploy/solc/solc_bin"]
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Blacklist all files
|
||||
.*
|
||||
*
|
||||
# Whitelist lib
|
||||
!lib/**/*
|
||||
# Whitelist Solidity contracts
|
||||
!contracts/src/**/*
|
||||
# Blacklist tests in lib
|
||||
/lib/test/*
|
||||
# Package specific ignore
|
File diff suppressed because it is too large
Load Diff
@@ -1,448 +0,0 @@
|
||||
<!--
|
||||
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
|
||||
Edit the package's CHANGELOG.json file only.
|
||||
-->
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v5.4.24 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.23 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.22 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.21 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.20 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.19 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.18 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.17 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.16 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.15 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.14 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.13 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.12 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.11 - _September 15, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.10 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.9 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.8 - _August 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.7 - _August 11, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.6 - _August 6, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.5 - _June 22, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.4 - _June 11, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.3 - _June 2, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.2 - _May 25, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.1 - _May 21, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.4.0 - _May 5, 2021_
|
||||
|
||||
* Set default ganache gas limit to 100e6 (#197)
|
||||
|
||||
## v5.3.25 - _April 28, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.24 - _April 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.23 - _March 17, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.22 - _February 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.21 - _February 10, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.20 - _January 26, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.19 - _January 13, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.18 - _January 4, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.17 - _December 23, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.16 - _December 17, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.15 - _December 9, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.14 - _December 7, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.13 - _December 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.12 - _November 19, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.11 - _November 13, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.10 - _November 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.9 - _November 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.8 - _November 2, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.7 - _October 28, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.6 - _October 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.5 - _October 21, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.4 - _July 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.3 - _June 24, 2020_
|
||||
|
||||
* Add `msg` param to `assertIntegerRoughlyEquals` (#2576)
|
||||
|
||||
## v5.3.2 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.1 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.3.0 - _February 25, 2020_
|
||||
|
||||
* Add `blockchainTests.config` (#2466)
|
||||
|
||||
## v5.1.5 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.1.4 - _February 8, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.1.3 - _February 6, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.1.2 - _February 4, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.1.1 - _January 22, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.1.0 - _January 6, 2020_
|
||||
|
||||
* Added ERC20BridgeProxy to list of unlocked accounts on mainnet fork (#2401)
|
||||
* Add `blockchainTests.live()` for live network tests. (#2407)
|
||||
* Add modifiers to `blockchainTests.fork()`. (#2407)
|
||||
|
||||
## v5.0.1 - _December 17, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v5.0.0 - _December 9, 2019_
|
||||
|
||||
* Removed `hex_utils.ts`. Moved to @0x/utils (#2373)
|
||||
|
||||
## v4.0.0 - _December 2, 2019_
|
||||
|
||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
||||
* Add new exports orderHashUtils and transactionHashUtils (#2321)
|
||||
* Remove TransactionHelper and MutatorContractFunction (#2325)
|
||||
* OrderFactory default order expiration time increased from ten minutes to fifteen minutes (#2304)
|
||||
* Add `chainId` to `TransactionFactory` constructor (#1742)
|
||||
* Use new `Order` structure with `domain` field (#1742)
|
||||
* Inherit `chaiSetup` from `@0x/dev-utils` (#1761)
|
||||
* Add `generatePseudoRandomOrderHash()` to `orderUtils` (#1761)
|
||||
* Inherit `OrderStatus` from `@0x/types` (#1761)
|
||||
* Update types for arbitrary fee tokens (#1819)
|
||||
* Remove formatters (#1834)
|
||||
* Add `hexConcat()` in `hex_utils.ts` (#1885)
|
||||
* Introduce Mocha blockchain extensions (#2007)
|
||||
* Move `*FillResults`, `OrderInfo` types to `@0x/types` (#2031)
|
||||
* Add `log_utils.ts` (#2031)
|
||||
* Add `hexRandom()` to `hex_utils.ts` (#2031)
|
||||
* Add the constants: `MAX_UINT256`, `ADDRESS_LENGTH`, `MAX_UINT256_ROOT`, `ONE_ETHER` (#2031)
|
||||
* Make `testCombinatoriallyWithReferenceFuncAsync` non-async (#2031)
|
||||
* Update `testWithReferenceFuncAsync` to work with `RevertErrors` (#2031)
|
||||
* `web3Wrapper` is created with `shouldAllowUnlimitedContractSize` if `UNLIMITED_CONTRACT_SIZE` environment variable is set. (#2075)
|
||||
* Add `toHex()`, `hexLeftPad()`, `hexRightPad()`, and 'hexInvert()' hex utils (#2109)
|
||||
* Add `PPM_DENOMINATOR` and `PPM_100_PERCENT` constants. (#2109)
|
||||
* Increase the number of ganache accounts to 20 (#2109)
|
||||
* Add `Numberish` type. (#2131)
|
||||
* Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()` (#2155)
|
||||
* Add `hexHash()` to `hex_utils` (#2155)
|
||||
* Add `shortZip()` to `lang_utils.ts` (#2155)
|
||||
* Add `number_utils.ts` and `hexSize()` (#2220)
|
||||
* Add `verifyEventsFromLogs()` (#2287)
|
||||
|
||||
## v3.2.0-beta.4 - _December 2, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.0-beta.3 - _November 20, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.0-beta.2 - _November 17, 2019_
|
||||
|
||||
* Drastically reduced bundle size by adding .npmignore, only exporting specific artifacts/wrappers/utils (#2330)
|
||||
* Add new exports orderHashUtils and transactionHashUtils (#2321)
|
||||
* Remove TransactionHelper and MutatorContractFunction (#2325)
|
||||
|
||||
## v3.2.0-beta.1 - _November 7, 2019_
|
||||
|
||||
* OrderFactory default order expiration time increased from ten minutes to fifteen minutes (#2304)
|
||||
|
||||
## v3.2.0-beta.0 - _October 3, 2019_
|
||||
|
||||
* Add `chainId` to `TransactionFactory` constructor (#1742)
|
||||
* Use new `Order` structure with `domain` field (#1742)
|
||||
* Inherit `chaiSetup` from `@0x/dev-utils` (#1761)
|
||||
* Add `generatePseudoRandomOrderHash()` to `orderUtils` (#1761)
|
||||
* Inherit `OrderStatus` from `@0x/types` (#1761)
|
||||
* Update types for arbitrary fee tokens (#1819)
|
||||
* Remove formatters (#1834)
|
||||
* Add `hexConcat()` in `hex_utils.ts` (#1885)
|
||||
* Introduce Mocha blockchain extensions (#2007)
|
||||
* Move `*FillResults`, `OrderInfo` types to `@0x/types` (#2031)
|
||||
* Add `log_utils.ts` (#2031)
|
||||
* Add `haxRandom()` to `hex_utils.ts` (#2031)
|
||||
* Add the constants: `MAX_UINT256`, `ADDRESS_LENGTH`, `MAX_UINT256_ROOT`, `ONE_ETHER` (#2031)
|
||||
* Make `testCombinatoriallyWithReferenceFuncAsync` non-async (#2031)
|
||||
* Update `testWithReferenceFuncAsync` to work with `RevertErrors` (#2031)
|
||||
* `web3Wrapper` is created with `shouldAllowUnlimitedContractSize` if `UNLIMITED_CONTRACT_SIZE` environment variable is set. (#2075)
|
||||
* Add `toHex()`, `hexLeftPad()`, `hexRightPad()`, and 'hexInvert()' hex utils (#2109)
|
||||
* Add `PPM_DENOMINATOR` and `PPM_100_PERCENT` constants. (#2109)
|
||||
* Increase the number of ganache accounts to 20 (#2109)
|
||||
* Add `Numberish` type. (#2131)
|
||||
* Tweaks/Upgrades to `hex_utils`, most notably `hexSlice()` (#2155)
|
||||
* Add `hexHash()` to `hex_utils` (#2155)
|
||||
* Add `shortZip()` to `lang_utils.ts` (#2155)
|
||||
* Add `number_utils.ts` and `hexSize()` (#2220)
|
||||
* Add `verifyEventsFromLogs()` (#2287)
|
||||
|
||||
## v3.1.16 - _September 17, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.15 - _September 3, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.14 - _August 22, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.13 - _August 8, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.12 - _July 31, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.11 - _July 24, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.10 - _July 15, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.9 - _July 13, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.8 - _July 13, 2019_
|
||||
|
||||
* Fixed false positives in `expectTransactionFailedAsync` and `expectContractCallFailedAsync` (#1852)
|
||||
|
||||
## v3.1.7 - _May 24, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.6 - _May 15, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.5 - _May 14, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.3 - _May 10, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.2 - _April 11, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.1 - _March 21, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.0 - _March 20, 2019_
|
||||
|
||||
* Added ERC1155Proxy test constants and interfaces (#1661)
|
||||
|
||||
## v3.0.9 - _Invalid date_
|
||||
|
||||
* Set evmVersion to byzantium (#1678)
|
||||
* Remove Coordinator EIP712 constants. They're now in the `order-utils` package. (#1705)
|
||||
|
||||
## v3.0.8 - _March 1, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.7 - _February 27, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.6 - _February 26, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.5 - _February 25, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.4 - _February 9, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.3 - _February 7, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.2 - _February 7, 2019_
|
||||
|
||||
* Fake publish to enable pinning
|
||||
|
||||
## v3.0.1 - _February 6, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.0.0 - _February 5, 2019_
|
||||
|
||||
* Upgrade the bignumber.js to v8.0.2 (#1517)
|
||||
* Import `ZeroExTransaction` type instead of using type defined in this package (#1576)
|
||||
|
||||
## v2.0.1 - _January 17, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.0.0 - _January 15, 2019_
|
||||
|
||||
* Renamed OrderStatus enum members to PascalCase to conform with tslint enum-naming rule (#1474)
|
||||
|
||||
## v1.0.4 - _January 11, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.3 - _January 9, 2019_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.2 - _December 13, 2018_
|
||||
|
||||
* Dependencies updated
|
@@ -1,82 +0,0 @@
|
||||
{
|
||||
"name": "@0x/contracts-test-utils",
|
||||
"version": "5.4.24",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
"description": "Test utils for 0x contracts",
|
||||
"main": "lib/src/index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -b",
|
||||
"build:ci": "yarn build",
|
||||
"test": "yarn run_mocha",
|
||||
"test:coverage": "run-s build run_mocha coverage:report:text coverage:report:lcov",
|
||||
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
|
||||
"clean": "shx rm -rf lib",
|
||||
"lint": "tslint --format stylish --project tsconfig.lint.json",
|
||||
"fix": "tslint --fix --format stylish --project tsconfig.lint.json",
|
||||
"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"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/0xProject/protocol.git"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/0xProject/protocol/issues"
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/test-utils",
|
||||
"devDependencies": {
|
||||
"@0x/sol-compiler": "^4.8.1",
|
||||
"@0x/tslint-config": "^4.1.4",
|
||||
"npm-run-all": "^4.1.2",
|
||||
"shx": "^0.2.2",
|
||||
"tslint": "5.11.0",
|
||||
"typescript": "4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/assert": "^3.0.34",
|
||||
"@0x/base-contract": "^6.5.0",
|
||||
"@0x/contract-addresses": "^6.17.0",
|
||||
"@0x/dev-utils": "^4.2.14",
|
||||
"@0x/json-schemas": "^6.4.4",
|
||||
"@0x/order-utils": "^10.4.28",
|
||||
"@0x/sol-coverage": "^4.0.45",
|
||||
"@0x/sol-profiler": "^4.1.35",
|
||||
"@0x/sol-trace": "^3.0.45",
|
||||
"@0x/subproviders": "^6.6.5",
|
||||
"@0x/types": "^3.3.6",
|
||||
"@0x/typescript-typings": "^5.3.1",
|
||||
"@0x/utils": "^6.5.3",
|
||||
"@0x/web3-wrapper": "^7.6.5",
|
||||
"@types/bn.js": "^4.11.0",
|
||||
"@types/js-combinatorics": "^0.5.29",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "12.12.54",
|
||||
"bn.js": "^4.11.8",
|
||||
"chai": "^4.0.1",
|
||||
"chai-as-promised": "^7.1.0",
|
||||
"chai-bignumber": "^3.0.0",
|
||||
"decimal.js": "^10.2.0",
|
||||
"dirty-chai": "^2.0.1",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"ethereumjs-util": "^7.0.10",
|
||||
"ethers": "~4.0.4",
|
||||
"js-combinatorics": "^0.5.3",
|
||||
"lodash": "^4.17.11",
|
||||
"make-promises-safe": "^1.1.0",
|
||||
"mocha": "^6.2.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "4f91bfd907996b2f4dd383778b50c479c2602b56"
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
export abstract class AbstractAssetWrapper {
|
||||
public abstract getProxyId(): string;
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
import { hexUtils } from '@0x/utils';
|
||||
|
||||
import { constants } from './constants';
|
||||
|
||||
/**
|
||||
* Generates a random address.
|
||||
*/
|
||||
export function randomAddress(): string {
|
||||
return hexUtils.random(constants.ADDRESS_LENGTH);
|
||||
}
|
@@ -1,201 +0,0 @@
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { logUtils } from '@0x/utils';
|
||||
import { NodeType } from '@0x/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
import { TransactionReceipt, TransactionReceiptStatus, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { web3Wrapper } from './web3_wrapper';
|
||||
|
||||
const expect = chai.expect;
|
||||
|
||||
let nodeType: NodeType | undefined;
|
||||
|
||||
// Represents the return value of a `sendTransaction` call. The Promise should
|
||||
// resolve with either a transaction receipt or a transaction hash.
|
||||
export type sendTransactionResult = Promise<TransactionReceipt | TransactionReceiptWithDecodedLogs | string>;
|
||||
|
||||
/**
|
||||
* Returns ganacheError if the backing Ethereum node is Ganache and gethError
|
||||
* if it is Geth.
|
||||
* @param ganacheError the error to be returned if the backing node is Ganache.
|
||||
* @param gethError the error to be returned if the backing node is Geth.
|
||||
* @returns either the given ganacheError or gethError depending on the backing
|
||||
* node.
|
||||
*/
|
||||
async function _getGanacheOrGethErrorAsync(ganacheError: string, gethError: string): Promise<string> {
|
||||
if (nodeType === undefined) {
|
||||
nodeType = await web3Wrapper.getNodeTypeAsync();
|
||||
}
|
||||
switch (nodeType) {
|
||||
case NodeType.Ganache:
|
||||
return ganacheError;
|
||||
case NodeType.Geth:
|
||||
return gethError;
|
||||
default:
|
||||
throw new Error(`Unknown node type: ${nodeType}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function _getInsufficientFundsErrorMessageAsync(): Promise<string> {
|
||||
return _getGanacheOrGethErrorAsync("sender doesn't have enough funds", 'insufficient funds');
|
||||
}
|
||||
|
||||
async function _getTransactionFailedErrorMessageAsync(): Promise<string> {
|
||||
return _getGanacheOrGethErrorAsync('revert', 'always failing transaction');
|
||||
}
|
||||
|
||||
async function _getContractCallFailedErrorMessageAsync(): Promise<string> {
|
||||
return _getGanacheOrGethErrorAsync('revert', 'Contract call failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected error message for an 'invalid opcode' resulting from a
|
||||
* contract call. The exact error message depends on the backing Ethereum node.
|
||||
*/
|
||||
export async function getInvalidOpcodeErrorMessageForCallAsync(): Promise<string> {
|
||||
return _getGanacheOrGethErrorAsync('invalid opcode', 'Contract call failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected error message for the given revert reason resulting from
|
||||
* a sendTransaction call. The exact error message depends on the backing
|
||||
* Ethereum node and whether it supports revert reasons.
|
||||
* @param reason a specific revert reason.
|
||||
* @returns the expected error message.
|
||||
*/
|
||||
export async function getRevertReasonOrErrorMessageForSendTransactionAsync(reason: RevertReason): Promise<string> {
|
||||
return _getGanacheOrGethErrorAsync(reason, 'always failing transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects if the given Promise does not reject with an error indicating
|
||||
* insufficient funds.
|
||||
* @param p a promise resulting from a contract call or sendTransaction call.
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectInsufficientFundsAsync<T>(p: Promise<T>): Promise<void> {
|
||||
const errMessage = await _getInsufficientFundsErrorMessageAsync();
|
||||
return expect(p).to.be.rejectedWith(errMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the the sendTransaction call fails with the given revert reason.
|
||||
* However, since Geth does not support revert reasons for sendTransaction, this
|
||||
* falls back to expectTransactionFailedWithoutReasonAsync if the backing
|
||||
* Ethereum node is Geth.
|
||||
* @param p a Promise resulting from a sendTransaction call
|
||||
* @param reason a specific revert reason
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectTransactionFailedAsync(p: sendTransactionResult, reason: RevertReason): Promise<void> {
|
||||
// HACK(albrow): This dummy `catch` should not be necessary, but if you
|
||||
// remove it, there is an uncaught exception and the Node process will
|
||||
// forcibly exit. It's possible this is a false positive in
|
||||
// make-promises-safe.
|
||||
p.catch(e => {
|
||||
_.noop(e);
|
||||
});
|
||||
|
||||
if (nodeType === undefined) {
|
||||
nodeType = await web3Wrapper.getNodeTypeAsync();
|
||||
}
|
||||
switch (nodeType) {
|
||||
case NodeType.Ganache:
|
||||
const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`);
|
||||
return expect(p).to.be.rejectedWith(rejectionMessageRegex);
|
||||
case NodeType.Geth:
|
||||
logUtils.warn(
|
||||
'WARNING: Geth does not support revert reasons for sendTransaction. This test will pass if the transaction fails for any reason.',
|
||||
);
|
||||
return expectTransactionFailedWithoutReasonAsync(p);
|
||||
default:
|
||||
throw new Error(`Unknown node type: ${nodeType}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the transaction fails without a revert reason, or if the
|
||||
* corresponding transactionReceipt has a status of 0 or '0', indicating
|
||||
* failure.
|
||||
* @param p a Promise resulting from a sendTransaction call
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectTransactionFailedWithoutReasonAsync(p: sendTransactionResult): Promise<void> {
|
||||
return p
|
||||
.then(async result => {
|
||||
let txReceiptStatus: TransactionReceiptStatus;
|
||||
if (_.isString(result)) {
|
||||
// Result is a txHash. We need to make a web3 call to get the
|
||||
// receipt, then get the status from the receipt.
|
||||
const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(result);
|
||||
txReceiptStatus = txReceipt.status;
|
||||
} else if ('status' in result) {
|
||||
// Result is a transaction receipt, so we can get the status
|
||||
// directly.
|
||||
txReceiptStatus = result.status;
|
||||
} else {
|
||||
throw new Error(`Unexpected result type: ${typeof result}`);
|
||||
}
|
||||
expect(_.toString(txReceiptStatus)).to.equal(
|
||||
'0',
|
||||
'Expected transaction to fail but receipt had a non-zero status, indicating success',
|
||||
);
|
||||
})
|
||||
.catch(async err => {
|
||||
// If the promise rejects, we expect a specific error message,
|
||||
// depending on the backing Ethereum node type.
|
||||
const errMessage = await _getTransactionFailedErrorMessageAsync();
|
||||
expect(err.message).to.include(errMessage);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the the contract call fails with the given revert reason.
|
||||
* @param p a Promise resulting from a contract call
|
||||
* @param reason a specific revert reason
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectContractCallFailedAsync<T>(p: Promise<T>, reason: RevertReason): Promise<void> {
|
||||
const rejectionMessageRegex = new RegExp(`^VM Exception while processing transaction: revert ${reason}$`);
|
||||
return expect(p).to.be.rejectedWith(rejectionMessageRegex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the contract call fails without a revert reason.
|
||||
* @param p a Promise resulting from a contract call
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectContractCallFailedWithoutReasonAsync<T>(p: Promise<T>): Promise<void> {
|
||||
const errMessage = await _getContractCallFailedErrorMessageAsync();
|
||||
return expect(p).to.be.rejectedWith(errMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the contract creation/deployment fails without a revert reason.
|
||||
* @param p a Promise resulting from a contract creation/deployment
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectContractCreationFailedAsync<T>(
|
||||
p: sendTransactionResult,
|
||||
reason: RevertReason,
|
||||
): Promise<void> {
|
||||
return expectTransactionFailedAsync(p, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves if the contract creation/deployment fails without a revert reason.
|
||||
* @param p a Promise resulting from a contract creation/deployment
|
||||
* @returns a new Promise which will reject if the conditions are not met and
|
||||
* otherwise resolve with no value.
|
||||
*/
|
||||
export async function expectContractCreationFailedWithoutReasonAsync<T>(p: Promise<T>): Promise<void> {
|
||||
const errMessage = await _getTransactionFailedErrorMessageAsync();
|
||||
return expect(p).to.be.rejectedWith(errMessage);
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
import { constants } from './constants';
|
||||
import { web3Wrapper } from './web3_wrapper';
|
||||
|
||||
let firstAccount: string | undefined;
|
||||
|
||||
/**
|
||||
* Increases time by the given number of seconds and then mines a block so that
|
||||
* the current block timestamp has the offset applied.
|
||||
* @param seconds the number of seconds by which to incrase the time offset.
|
||||
* @returns a new Promise which will resolve with the new total time offset or
|
||||
* reject if the time could not be increased.
|
||||
*/
|
||||
export async function increaseTimeAndMineBlockAsync(seconds: number): Promise<number> {
|
||||
if (firstAccount === undefined) {
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
firstAccount = accounts[0];
|
||||
}
|
||||
|
||||
const offset = await web3Wrapper.increaseTimeAsync(seconds);
|
||||
// Note: we need to send a transaction after increasing time so
|
||||
// that a block is actually mined. The contract looks at the
|
||||
// last mined block for the timestamp.
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({ from: firstAccount, to: firstAccount, value: 0 }),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the latest block in seconds since the Unix epoch.
|
||||
* @returns a new Promise which will resolve with the timestamp in seconds.
|
||||
*/
|
||||
export async function getLatestBlockTimestampAsync(): Promise<number> {
|
||||
const currentBlockIfExists = await web3Wrapper.getBlockIfExistsAsync('latest');
|
||||
if (currentBlockIfExists === undefined) {
|
||||
throw new Error(`Unable to fetch latest block.`);
|
||||
}
|
||||
return currentBlockIfExists.timestamp;
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
import { chaiSetup } from '@0x/dev-utils';
|
||||
export { chaiSetup } from '@0x/dev-utils';
|
||||
import * as chai from 'chai';
|
||||
|
||||
// Set up chai.
|
||||
chaiSetup.configure();
|
||||
export const expect = chai.expect;
|
@@ -1,8 +0,0 @@
|
||||
import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
/**
|
||||
* Get the codesize of a provided artifact.
|
||||
*/
|
||||
export function getCodesizeFromArtifact(artifact: ContractArtifact): number {
|
||||
return (artifact.compilerOutput.evm.bytecode.object.length - 2) / 2;
|
||||
}
|
@@ -1,113 +0,0 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as combinatorics from 'js-combinatorics';
|
||||
|
||||
import { testWithReferenceFuncAsync } from './test_with_reference';
|
||||
|
||||
// A set of values corresponding to the uint256 type in Solidity. This set
|
||||
// contains some notable edge cases, including some values which will overflow
|
||||
// the uint256 type when used in different mathematical operations.
|
||||
export const uint256Values = [
|
||||
new BigNumber(0),
|
||||
new BigNumber(1),
|
||||
new BigNumber(2),
|
||||
// Non-trivial big number.
|
||||
new BigNumber(2).pow(64),
|
||||
// Max that does not overflow when squared.
|
||||
new BigNumber(2).pow(128).minus(1),
|
||||
// Min that does overflow when squared.
|
||||
new BigNumber(2).pow(128),
|
||||
// Max that does not overflow when doubled.
|
||||
new BigNumber(2).pow(255).minus(1),
|
||||
// Min that does overflow when doubled.
|
||||
new BigNumber(2).pow(255),
|
||||
// Max that does not overflow.
|
||||
new BigNumber(2).pow(256).minus(1),
|
||||
];
|
||||
|
||||
// A set of values corresponding to the bytes32 type in Solidity.
|
||||
export const bytes32Values = [
|
||||
// Min
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
||||
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
||||
// Non-trivial big number.
|
||||
'0x000000000000f000000000000000000000000000000000000000000000000000',
|
||||
// Max
|
||||
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
||||
];
|
||||
|
||||
export function testCombinatoriallyWithReferenceFunc<P0, P1, R>(
|
||||
name: string,
|
||||
referenceFunc: (p0: P0, p1: P1) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1) => Promise<R>,
|
||||
allValues: [P0[], P1[]],
|
||||
): void;
|
||||
export function testCombinatoriallyWithReferenceFunc<P0, P1, P2, R>(
|
||||
name: string,
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
|
||||
allValues: [P0[], P1[], P2[]],
|
||||
): void;
|
||||
export function testCombinatoriallyWithReferenceFunc<P0, P1, P2, P3, R>(
|
||||
name: string,
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
|
||||
allValues: [P0[], P1[], P2[], P3[]],
|
||||
): void;
|
||||
export function testCombinatoriallyWithReferenceFunc<P0, P1, P2, P3, P4, R>(
|
||||
name: string,
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
|
||||
allValues: [P0[], P1[], P2[], P3[], P4[]],
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Uses combinatorics to test the behavior of a test function by comparing it to
|
||||
* the expected behavior (defined by a reference function) for a large number of
|
||||
* possible input values.
|
||||
*
|
||||
* First generates test cases by taking the cartesian product of the given
|
||||
* values. Each test case is a set of N values corresponding to the N arguments
|
||||
* for the test func and the reference func. For each test case, first the
|
||||
* reference function will be called to obtain an "expected result", or if the
|
||||
* reference function throws/rejects, an "expected error". Next, the test
|
||||
* function will be called to obtain an "actual result", or if the test function
|
||||
* throws/rejects, an "actual error". Each test case passes if at least one of
|
||||
* the following conditions is met:
|
||||
*
|
||||
* 1) Neither the reference function or the test function throw and the
|
||||
* "expected result" equals the "actual result".
|
||||
*
|
||||
* 2) Both the reference function and the test function throw and the "actual
|
||||
* error" message *contains* the "expected error" message.
|
||||
*
|
||||
* The first test case which does not meet one of these conditions will cause
|
||||
* the entire test to fail and this function will throw/reject.
|
||||
*
|
||||
* @param referenceFuncAsync a reference function implemented in pure
|
||||
* JavaScript/TypeScript which accepts N arguments and returns the "expected
|
||||
* result" or "expected error" for a given test case.
|
||||
* @param testFuncAsync a test function which, e.g., makes a call or sends a
|
||||
* transaction to a contract. It accepts the same N arguments returns the
|
||||
* "actual result" or "actual error" for a given test case.
|
||||
* @param values an array of N arrays. Each inner array is a set of possible
|
||||
* values which are passed into both the reference function and the test
|
||||
* function.
|
||||
* @return A Promise that resolves if the test passes and rejects if the test
|
||||
* fails, according to the rules described above.
|
||||
*/
|
||||
export function testCombinatoriallyWithReferenceFunc(
|
||||
name: string,
|
||||
referenceFuncAsync: (...args: any[]) => Promise<any>,
|
||||
testFuncAsync: (...args: any[]) => Promise<any>,
|
||||
allValues: any[],
|
||||
): void {
|
||||
const testCases = combinatorics.cartesianProduct(...allValues);
|
||||
let counter = 0;
|
||||
testCases.forEach(async testCase => {
|
||||
counter += 1;
|
||||
it(`${name} ${counter}/${testCases.length}`, async () => {
|
||||
await testWithReferenceFuncAsync(referenceFuncAsync, testFuncAsync, testCase as any);
|
||||
});
|
||||
});
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { ExchangeFunctionName } from './types';
|
||||
|
||||
const TESTRPC_PRIVATE_KEYS_STRINGS = [
|
||||
'0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d',
|
||||
'0x5d862464fe9303452126c8bc94274b8c5f9874cbd219789b3eb2128075a76f72',
|
||||
'0xdf02719c4df8b9b8ac7f551fcb5d9ef48fa27eef7a66453879f4d8fdc6e78fb1',
|
||||
'0xff12e391b79415e941a94de3bf3a9aee577aed0731e297d5cfa0b8a1e02fa1d0',
|
||||
'0x752dd9cf65e68cfaba7d60225cbdbc1f4729dd5e5507def72815ed0d8abc6249',
|
||||
'0xefb595a0178eb79a8df953f87c5148402a224cdf725e88c0146727c6aceadccd',
|
||||
'0x83c6d2cc5ddcf9711a6d59b417dc20eb48afd58d45290099e5987e3d768f328f',
|
||||
'0xbb2d3f7c9583780a7d3904a2f55d792707c345f21de1bacb2d389934d82796b2',
|
||||
'0xb2fd4d29c1390b71b8795ae81196bfd60293adf99f9d32a0aff06288fcdac55f',
|
||||
'0x23cb7121166b9a2f93ae0b7c05bde02eae50d64449b2cbb42bc84e9d38d6cc89',
|
||||
'0x5ad34d7f8704ed33ab9e8dc30a76a8c48060649204c1f7b21b973235bba8092f',
|
||||
'0xf18b03c1ae8e3876d76f20c7a5127a169dd6108c55fe9ce78bc7a91aca67dee3',
|
||||
'0x4ccc4e7d7843e0701295e8fd671332a0e2f1e92d0dab16e8792e91cb0b719c9d',
|
||||
'0xd7638ae813450e710e6f1b09921cc1593181073ce2099fb418fc03a933c7f41f',
|
||||
'0xbc7bbca8ca15eb567be60df82e4452b13072dcb60db89747e3c85df63d8270ca',
|
||||
'0x55131517839bf782e6e573bc3ac8f262efd2b6cb0ac86e8f147db26fcbdb15a5',
|
||||
'0x6c2b5a16e327e0c4e7fafca5ae35616141de81f77da66ee0857bc3101d446e68',
|
||||
'0xfd79b71625eec963e6ec42e9b5b10602c938dfec29cbbc7d17a492dd4f403859',
|
||||
'0x3003eace3d4997c52ba69c2ca97a6b5d0d1216d894035a97071590ee284c1023',
|
||||
'0x84a8bb71450a1b82be2b1cdd25d079cbf23dc8054e94c47ad14510aa967f45de',
|
||||
];
|
||||
|
||||
const MAX_UINT256 = new BigNumber(2).pow(256).minus(1);
|
||||
|
||||
export const constants = {
|
||||
BASE_16: 16,
|
||||
INVALID_OPCODE: 'invalid opcode',
|
||||
TESTRPC_CHAIN_ID: 1337,
|
||||
// Note(albrow): In practice V8 and most other engines limit the minimum
|
||||
// interval for setInterval to 10ms. We still set it to 0 here in order to
|
||||
// ensure we always use the minimum interval.
|
||||
AWAIT_TRANSACTION_MINED_MS: 0,
|
||||
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
|
||||
MAX_EXECUTE_TRANSACTION_GAS: 1000000,
|
||||
MAX_TOKEN_TRANSFERFROM_GAS: 80000,
|
||||
MAX_TOKEN_APPROVE_GAS: 60000,
|
||||
MAX_TRANSFER_FROM_GAS: 150000,
|
||||
MAX_MATCH_ORDERS_GAS: 400000,
|
||||
DUMMY_TOKEN_NAME: '',
|
||||
DUMMY_TOKEN_SYMBOL: '',
|
||||
DUMMY_TOKEN_DECIMALS: new BigNumber(18),
|
||||
DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0),
|
||||
NULL_BYTES: '0x',
|
||||
NUM_DUMMY_ERC20_TO_DEPLOY: 4,
|
||||
NUM_DUMMY_ERC721_TO_DEPLOY: 2,
|
||||
NUM_ERC721_TOKENS_TO_MINT: 4,
|
||||
NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY: 2,
|
||||
NUM_ERC1155_FUNGIBLE_TOKENS_MINT: 4,
|
||||
NUM_ERC1155_NONFUNGIBLE_TOKENS_MINT: 4,
|
||||
NULL_BYTES4: '0x00000000',
|
||||
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
|
||||
NULL_BYTES32: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
||||
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
MAX_UINT32: new BigNumber(2).pow(32).minus(1),
|
||||
TESTRPC_PRIVATE_KEYS: _.map(TESTRPC_PRIVATE_KEYS_STRINGS, privateKeyString => ethUtil.toBuffer(privateKeyString)),
|
||||
INITIAL_ERC20_BALANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC20_ALLOWANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC1155_FUNGIBLE_BALANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
INITIAL_ERC1155_FUNGIBLE_ALLOWANCE: Web3Wrapper.toBaseUnitAmount(new BigNumber(10000), 18),
|
||||
STATIC_ORDER_PARAMS: {
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18),
|
||||
},
|
||||
WORD_LENGTH: 32,
|
||||
ADDRESS_LENGTH: 20,
|
||||
ZERO_AMOUNT: new BigNumber(0),
|
||||
PERCENTAGE_DENOMINATOR: new BigNumber(10).pow(18),
|
||||
TIME_BUFFER: new BigNumber(1000),
|
||||
KECCAK256_NULL: ethUtil.bufferToHex(ethUtil.keccak256(Buffer.alloc(0))),
|
||||
MAX_UINT256_ROOT: new BigNumber('340282366920938463463374607431768211456'),
|
||||
ONE_ETHER: new BigNumber(1e18),
|
||||
EIP712_DOMAIN_NAME: '0x Protocol',
|
||||
EIP712_DOMAIN_VERSION: '3.0.0',
|
||||
DEFAULT_GAS_PRICE: 1,
|
||||
NUM_TEST_ACCOUNTS: 20,
|
||||
PPM_DENOMINATOR: 1e6,
|
||||
PPM_100_PERCENT: 1e6,
|
||||
MAX_CODE_SIZE: 24576,
|
||||
SINGLE_FILL_FN_NAMES: [ExchangeFunctionName.FillOrder, ExchangeFunctionName.FillOrKillOrder],
|
||||
BATCH_FILL_FN_NAMES: [
|
||||
ExchangeFunctionName.BatchFillOrders,
|
||||
ExchangeFunctionName.BatchFillOrKillOrders,
|
||||
ExchangeFunctionName.BatchFillOrdersNoThrow,
|
||||
],
|
||||
MARKET_FILL_FN_NAMES: [
|
||||
ExchangeFunctionName.MarketBuyOrdersFillOrKill,
|
||||
ExchangeFunctionName.MarketSellOrdersFillOrKill,
|
||||
ExchangeFunctionName.MarketBuyOrdersNoThrow,
|
||||
ExchangeFunctionName.MarketSellOrdersNoThrow,
|
||||
],
|
||||
MATCH_ORDER_FN_NAMES: [ExchangeFunctionName.MatchOrders, ExchangeFunctionName.MatchOrdersWithMaximalFill],
|
||||
BATCH_MATCH_ORDER_FN_NAMES: [
|
||||
ExchangeFunctionName.BatchMatchOrders,
|
||||
ExchangeFunctionName.BatchMatchOrdersWithMaximalFill,
|
||||
],
|
||||
CANCEL_ORDER_FN_NAMES: [
|
||||
ExchangeFunctionName.CancelOrder,
|
||||
ExchangeFunctionName.BatchCancelOrders,
|
||||
ExchangeFunctionName.CancelOrdersUpTo,
|
||||
],
|
||||
};
|
@@ -1,26 +0,0 @@
|
||||
import { devConstants } from '@0x/dev-utils';
|
||||
import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-coverage';
|
||||
let coverageSubprovider: CoverageSubprovider;
|
||||
|
||||
export const coverage = {
|
||||
getCoverageSubproviderSingleton(): CoverageSubprovider {
|
||||
if (coverageSubprovider === undefined) {
|
||||
coverageSubprovider = coverage._getCoverageSubprovider();
|
||||
}
|
||||
return coverageSubprovider;
|
||||
},
|
||||
_getCoverageSubprovider(): CoverageSubprovider {
|
||||
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
|
||||
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
|
||||
const coverageSubproviderConfig = {
|
||||
isVerbose: true,
|
||||
ignoreFilesGlobs: ['**/node_modules/**', '**/interfaces/**', '**/test/**'],
|
||||
};
|
||||
const subprovider = new CoverageSubprovider(
|
||||
solCompilerArtifactAdapter,
|
||||
defaultFromAddress,
|
||||
coverageSubproviderConfig,
|
||||
);
|
||||
return subprovider;
|
||||
},
|
||||
};
|
@@ -1,15 +0,0 @@
|
||||
import { env, EnvVars } from '@0x/dev-utils';
|
||||
|
||||
import { coverage } from './coverage';
|
||||
import { profiler } from './profiler';
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
@@ -1,63 +0,0 @@
|
||||
export { AbstractAssetWrapper } from './abstract_asset_wrapper';
|
||||
export { constants } from './constants';
|
||||
export {
|
||||
expectContractCallFailedAsync,
|
||||
expectContractCallFailedWithoutReasonAsync,
|
||||
expectContractCreationFailedAsync,
|
||||
expectContractCreationFailedWithoutReasonAsync,
|
||||
expectInsufficientFundsAsync,
|
||||
expectTransactionFailedAsync,
|
||||
sendTransactionResult,
|
||||
expectTransactionFailedWithoutReasonAsync,
|
||||
getInvalidOpcodeErrorMessageForCallAsync,
|
||||
getRevertReasonOrErrorMessageForSendTransactionAsync,
|
||||
} from './assertions';
|
||||
export { getLatestBlockTimestampAsync, increaseTimeAndMineBlockAsync } from './block_timestamp';
|
||||
export { provider, txDefaults, web3Wrapper } from './web3_wrapper';
|
||||
export { LogDecoder } from './log_decoder';
|
||||
export { filterLogs, filterLogsToArguments, verifyEvents, verifyEventsFromLogs } from './log_utils';
|
||||
export { signingUtils } from './signing_utils';
|
||||
export { orderUtils } from './order_utils';
|
||||
export { typeEncodingUtils } from './type_encoding_utils';
|
||||
export { profiler } from './profiler';
|
||||
export { coverage } from './coverage';
|
||||
export { Web3ProviderEngine } from '@0x/subproviders';
|
||||
export { randomAddress } from './address_utils';
|
||||
export { OrderFactory } from './order_factory';
|
||||
export { bytes32Values, testCombinatoriallyWithReferenceFunc, uint256Values } from './combinatorial_utils';
|
||||
export { TransactionFactory } from './transaction_factory';
|
||||
export { testWithReferenceFuncAsync } from './test_with_reference';
|
||||
export {
|
||||
BatchMatchOrder,
|
||||
ContractName,
|
||||
ERC20BalancesByOwner,
|
||||
EthBalancesByOwner,
|
||||
FillEventArgs,
|
||||
MarketBuyOrders,
|
||||
MarketSellOrders,
|
||||
Numberish,
|
||||
OrderStatus,
|
||||
Token,
|
||||
TokenBalances,
|
||||
TransactionDataParams,
|
||||
ExchangeFunctionName,
|
||||
} from './types';
|
||||
export { blockchainTests, BlockchainTestsEnvironment, describe } from './mocha_blockchain';
|
||||
export { chaiSetup, expect } from './chai_setup';
|
||||
export { getCodesizeFromArtifact } from './codesize';
|
||||
export { replaceKeysDeep, shortZip } from './lang_utils';
|
||||
export {
|
||||
assertIntegerRoughlyEquals,
|
||||
assertRoughlyEquals,
|
||||
fromFixed,
|
||||
getRandomFloat,
|
||||
getRandomInteger,
|
||||
getRandomPortion,
|
||||
getNumericalDivergence,
|
||||
getPercentageOfValue,
|
||||
toBaseUnitAmount,
|
||||
toDecimal,
|
||||
toFixed,
|
||||
} from './number_utils';
|
||||
export { orderHashUtils } from './order_hash';
|
||||
export { transactionHashUtils } from './transaction_hash';
|
@@ -1,19 +0,0 @@
|
||||
import * as _ from 'lodash';
|
||||
|
||||
/**
|
||||
* _.zip() that clips to the shortest array.
|
||||
*/
|
||||
export function shortZip<T1, T2>(a: T1[], b: T2[]): Array<[T1, T2]> {
|
||||
const minLength = Math.min(a.length, b.length);
|
||||
return _.zip(a.slice(0, minLength), b.slice(0, minLength)) as Array<[T1, T2]>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the keys in a deeply nested object. Adapted from https://stackoverflow.com/a/39126851
|
||||
*/
|
||||
export function replaceKeysDeep(obj: {}, mapKeys: (key: string) => string | void): _.Dictionary<{}> {
|
||||
return _.transform(obj, (result, value, key) => {
|
||||
const currentKey = mapKeys(key) || key;
|
||||
result[currentKey] = _.isObject(value) ? replaceKeysDeep(value as {}, mapKeys) : (value as {});
|
||||
});
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
import { AbiDecoder, BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import {
|
||||
AbiDefinition,
|
||||
ContractArtifact,
|
||||
DecodedLogArgs,
|
||||
LogEntry,
|
||||
LogWithDecodedArgs,
|
||||
RawLog,
|
||||
TransactionReceipt,
|
||||
TransactionReceiptWithDecodedLogs,
|
||||
} from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export class LogDecoder {
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
private readonly _abiDecoder: AbiDecoder;
|
||||
public static wrapLogBigNumbers(log: any): any {
|
||||
const argNames = _.keys(log.args);
|
||||
for (const argName of argNames) {
|
||||
const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber(');
|
||||
if (isWeb3BigNumber) {
|
||||
log.args[argName] = new BigNumber(log.args[argName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
constructor(web3Wrapper: Web3Wrapper, artifacts: { [contractName: string]: ContractArtifact }) {
|
||||
this._web3Wrapper = web3Wrapper;
|
||||
const abiArrays: AbiDefinition[][] = [];
|
||||
_.forEach(artifacts, (artifact: ContractArtifact) => {
|
||||
const compilerOutput = artifact.compilerOutput;
|
||||
abiArrays.push(compilerOutput.abi);
|
||||
});
|
||||
this._abiDecoder = new AbiDecoder(abiArrays);
|
||||
}
|
||||
public decodeLogOrThrow<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
|
||||
const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
if ((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args === undefined) {
|
||||
throw new Error(`Unable to decode log: ${JSON.stringify(log)}`);
|
||||
}
|
||||
LogDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog);
|
||||
return logWithDecodedArgsOrLog;
|
||||
}
|
||||
public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const receipt = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
return this.decodeReceiptLogs(receipt);
|
||||
}
|
||||
public decodeReceiptLogs(receipt: TransactionReceipt): TransactionReceiptWithDecodedLogs {
|
||||
const decodedLogs = (receipt.logs as LogEntry[]).map(log => this.decodeLogOrThrow(log));
|
||||
return _.merge({}, receipt, { logs: decodedLogs });
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
import { LogEntry, LogWithDecodedArgs, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
|
||||
import { expect } from './chai_setup';
|
||||
|
||||
// tslint:disable no-unnecessary-type-assertion
|
||||
|
||||
/**
|
||||
* Filter logs by event name/type.
|
||||
*/
|
||||
export function filterLogs<TEventArgs>(logs: LogEntry[], event: string): Array<LogWithDecodedArgs<TEventArgs>> {
|
||||
return (logs as Array<LogWithDecodedArgs<any>>).filter(log => log.event === event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter logs by event name/type and convert to arguments.
|
||||
*/
|
||||
export function filterLogsToArguments<TEventArgs>(logs: LogEntry[], event: string): TEventArgs[] {
|
||||
return filterLogs<TEventArgs>(logs, event).map(log => log.args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a transaction emitted the expected events of a particular type.
|
||||
*/
|
||||
export function verifyEvents<TEventArgs>(
|
||||
txReceipt: TransactionReceiptWithDecodedLogs,
|
||||
expectedEvents: TEventArgs[],
|
||||
eventName: string,
|
||||
): void {
|
||||
return verifyEventsFromLogs(txReceipt.logs, expectedEvents, eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a collection of logs, verifies that matching events are identical.
|
||||
*/
|
||||
export function verifyEventsFromLogs<TEventArgs>(
|
||||
logs: LogEntry[],
|
||||
expectedEvents: TEventArgs[],
|
||||
eventName: string,
|
||||
): void {
|
||||
const _logs = filterLogsToArguments<TEventArgs>(logs, eventName);
|
||||
expect(_logs.length, `Number of ${eventName} events emitted`).to.eq(expectedEvents.length);
|
||||
_logs.forEach((log, index) => {
|
||||
expect(log, `${eventName} event ${index}`).to.deep.equal({ ...log, ...expectedEvents[index] });
|
||||
});
|
||||
}
|
@@ -1,430 +0,0 @@
|
||||
import { BlockchainLifecycle, web3Factory } from '@0x/dev-utils';
|
||||
import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
|
||||
import { providerUtils } from '@0x/utils';
|
||||
import { TxData, Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import * as mocha from 'mocha';
|
||||
import * as process from 'process';
|
||||
|
||||
import { provider, providerConfigs, txDefaults, web3Wrapper } from './web3_wrapper';
|
||||
|
||||
// tslint:disable: no-namespace only-arrow-functions no-unbound-method max-classes-per-file
|
||||
|
||||
export type ISuite = mocha.ISuite;
|
||||
export type ISuiteCallbackContext = mocha.ISuiteCallbackContext;
|
||||
export type SuiteCallback = (this: ISuiteCallbackContext) => void;
|
||||
export type ContextDefinitionCallback<T> = (description: string, callback: SuiteCallback) => T;
|
||||
export type BlockchainSuiteCallback = (this: ISuiteCallbackContext, env: BlockchainTestsEnvironment) => void;
|
||||
export type BlockchainContextDefinitionCallback<T> = (description: string, callback: BlockchainSuiteCallback) => T;
|
||||
export interface ContextDefinition extends mocha.IContextDefinition {
|
||||
optional: ContextDefinitionCallback<ISuite | void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* `blockchainTests()` config options.
|
||||
*/
|
||||
export interface BlockchainContextConfig {
|
||||
fork: Partial<{
|
||||
// Accounts to unlock on ganache.
|
||||
unlockedAccounts: string[];
|
||||
}>;
|
||||
}
|
||||
|
||||
let TEST_ENV_CONFIG: Partial<BlockchainContextConfig> = {};
|
||||
|
||||
/**
|
||||
* Interface for `blockchainTests()`.
|
||||
*/
|
||||
export interface BlockchainContextDefinition {
|
||||
(description: string, callback: BlockchainSuiteCallback): ISuite;
|
||||
configure: (config?: Partial<BlockchainContextConfig>) => void;
|
||||
only: BlockchainContextDefinitionCallback<ISuite>;
|
||||
skip: BlockchainContextDefinitionCallback<void>;
|
||||
optional: BlockchainContextDefinitionCallback<ISuite | void>;
|
||||
resets: BlockchainContextDefinitionCallback<ISuite | void> & {
|
||||
only: BlockchainContextDefinitionCallback<ISuite>;
|
||||
skip: BlockchainContextDefinitionCallback<void>;
|
||||
optional: BlockchainContextDefinitionCallback<ISuite | void>;
|
||||
};
|
||||
fork: BlockchainContextDefinitionCallback<ISuite | void> & {
|
||||
only: BlockchainContextDefinitionCallback<ISuite>;
|
||||
skip: BlockchainContextDefinitionCallback<void>;
|
||||
optional: BlockchainContextDefinitionCallback<ISuite | void>;
|
||||
resets: BlockchainContextDefinitionCallback<ISuite | void>;
|
||||
};
|
||||
live: BlockchainContextDefinitionCallback<ISuite | void> & {
|
||||
only: BlockchainContextDefinitionCallback<ISuite>;
|
||||
skip: BlockchainContextDefinitionCallback<void>;
|
||||
optional: BlockchainContextDefinitionCallback<ISuite | void>;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the environment object passed into the `blockchainTests()` callback.
|
||||
*/
|
||||
export interface BlockchainTestsEnvironment {
|
||||
blockchainLifecycle: BlockchainLifecycle;
|
||||
provider: Web3ProviderEngine;
|
||||
txDefaults: Partial<TxData>;
|
||||
web3Wrapper: Web3Wrapper;
|
||||
getChainIdAsync(): Promise<number>;
|
||||
getAccountAddressesAsync(): Promise<string[]>;
|
||||
}
|
||||
|
||||
class BlockchainTestsEnvironmentBase {
|
||||
public blockchainLifecycle!: BlockchainLifecycle;
|
||||
public provider!: Web3ProviderEngine;
|
||||
public txDefaults!: Partial<TxData>;
|
||||
public web3Wrapper!: Web3Wrapper;
|
||||
|
||||
public async getChainIdAsync(): Promise<number> {
|
||||
return providerUtils.getChainIdAsync(this.provider);
|
||||
}
|
||||
|
||||
public async getAccountAddressesAsync(): Promise<string[]> {
|
||||
return this.web3Wrapper.getAvailableAddressesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
interface BlockchainEnvironmentFactory {
|
||||
create(): BlockchainTestsEnvironment;
|
||||
}
|
||||
|
||||
/**
|
||||
* `BlockchainTestsEnvironment` that uses the default ganache provider.
|
||||
*/
|
||||
export class StandardBlockchainTestsEnvironmentSingleton extends BlockchainTestsEnvironmentBase {
|
||||
private static _instance: StandardBlockchainTestsEnvironmentSingleton | undefined;
|
||||
|
||||
// Create or retrieve the singleton instance of this class.
|
||||
public static create(): StandardBlockchainTestsEnvironmentSingleton {
|
||||
if (StandardBlockchainTestsEnvironmentSingleton._instance === undefined) {
|
||||
StandardBlockchainTestsEnvironmentSingleton._instance = new StandardBlockchainTestsEnvironmentSingleton();
|
||||
}
|
||||
return StandardBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
// Reset the singleton.
|
||||
public static reset(): void {
|
||||
StandardBlockchainTestsEnvironmentSingleton._instance = undefined;
|
||||
}
|
||||
|
||||
// Get the singleton instance of this class.
|
||||
public static getInstance(): StandardBlockchainTestsEnvironmentSingleton | undefined {
|
||||
return StandardBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
protected constructor() {
|
||||
super();
|
||||
this.blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
this.provider = provider;
|
||||
this.txDefaults = txDefaults;
|
||||
this.web3Wrapper = web3Wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `BlockchainTestsEnvironment` that uses a forked ganache provider.
|
||||
*/
|
||||
export class ForkedBlockchainTestsEnvironmentSingleton extends BlockchainTestsEnvironmentBase {
|
||||
private static _instance: ForkedBlockchainTestsEnvironmentSingleton | undefined;
|
||||
|
||||
// Create or retrieve the singleton instance of this class.
|
||||
public static create(): ForkedBlockchainTestsEnvironmentSingleton {
|
||||
if (ForkedBlockchainTestsEnvironmentSingleton._instance === undefined) {
|
||||
ForkedBlockchainTestsEnvironmentSingleton._instance = new ForkedBlockchainTestsEnvironmentSingleton();
|
||||
}
|
||||
return ForkedBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
// Reset the singleton.
|
||||
public static reset(): void {
|
||||
ForkedBlockchainTestsEnvironmentSingleton._instance = undefined;
|
||||
}
|
||||
|
||||
protected static _createWeb3Provider(forkHost: string): Web3ProviderEngine {
|
||||
const forkConfig = TEST_ENV_CONFIG.fork || {};
|
||||
const unlockedAccounts = forkConfig.unlockedAccounts;
|
||||
return web3Factory.getRpcProvider({
|
||||
...providerConfigs,
|
||||
fork: forkHost,
|
||||
blockTime: 0,
|
||||
...(unlockedAccounts ? { unlocked_accounts: unlockedAccounts } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
// Get the singleton instance of this class.
|
||||
public static getInstance(): ForkedBlockchainTestsEnvironmentSingleton | undefined {
|
||||
return ForkedBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
protected constructor() {
|
||||
super();
|
||||
this.txDefaults = txDefaults;
|
||||
this.provider = process.env.FORK_RPC_URL
|
||||
? ForkedBlockchainTestsEnvironmentSingleton._createWeb3Provider(process.env.FORK_RPC_URL)
|
||||
: // Create a dummy provider if no RPC backend supplied.
|
||||
createDummyProvider();
|
||||
this.web3Wrapper = new Web3Wrapper(this.provider);
|
||||
this.blockchainLifecycle = new BlockchainLifecycle(this.web3Wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `BlockchainTestsEnvironment` that uses a live web3 provider.
|
||||
*/
|
||||
export class LiveBlockchainTestsEnvironmentSingleton extends BlockchainTestsEnvironmentBase {
|
||||
private static _instance: LiveBlockchainTestsEnvironmentSingleton | undefined;
|
||||
|
||||
// Create or retrieve the singleton instance of this class.
|
||||
public static create(): LiveBlockchainTestsEnvironmentSingleton {
|
||||
if (LiveBlockchainTestsEnvironmentSingleton._instance === undefined) {
|
||||
LiveBlockchainTestsEnvironmentSingleton._instance = new LiveBlockchainTestsEnvironmentSingleton();
|
||||
}
|
||||
return LiveBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
// Reset the singleton.
|
||||
public static reset(): void {
|
||||
LiveBlockchainTestsEnvironmentSingleton._instance = undefined;
|
||||
}
|
||||
|
||||
protected static _createWeb3Provider(rpcHost: string): Web3ProviderEngine {
|
||||
const providerEngine = new Web3ProviderEngine();
|
||||
providerEngine.addProvider(new RPCSubprovider(rpcHost));
|
||||
providerUtils.startProviderEngine(providerEngine);
|
||||
return providerEngine;
|
||||
}
|
||||
|
||||
// Get the singleton instance of this class.
|
||||
public static getInstance(): LiveBlockchainTestsEnvironmentSingleton | undefined {
|
||||
return LiveBlockchainTestsEnvironmentSingleton._instance;
|
||||
}
|
||||
|
||||
protected constructor() {
|
||||
super();
|
||||
this.txDefaults = txDefaults;
|
||||
this.provider = process.env.LIVE_RPC_URL
|
||||
? LiveBlockchainTestsEnvironmentSingleton._createWeb3Provider(process.env.LIVE_RPC_URL)
|
||||
: // Create a dummy provider if no RPC backend supplied.
|
||||
createDummyProvider();
|
||||
this.web3Wrapper = new Web3Wrapper(this.provider);
|
||||
const snapshotHandlerAsync = async (): Promise<void> => {
|
||||
throw new Error('Snapshots are not supported with a live provider.');
|
||||
};
|
||||
this.blockchainLifecycle = {
|
||||
startAsync: snapshotHandlerAsync,
|
||||
revertAsync: snapshotHandlerAsync,
|
||||
} as any;
|
||||
}
|
||||
}
|
||||
|
||||
// The original `describe()` global provided by mocha.
|
||||
const mochaDescribe = (global as any).describe as mocha.IContextDefinition;
|
||||
|
||||
/**
|
||||
* An augmented version of mocha's `describe()`.
|
||||
*/
|
||||
export const describe = _.assign(mochaDescribe, {
|
||||
optional(description: string, callback: SuiteCallback): ISuite | void {
|
||||
const describeCall = process.env.TEST_ALL ? mochaDescribe : mochaDescribe.skip;
|
||||
return describeCall(description, callback);
|
||||
},
|
||||
}) as ContextDefinition;
|
||||
|
||||
/**
|
||||
* Like mocha's `describe()`, but sets up a blockchain environment for you.
|
||||
*/
|
||||
export const blockchainTests: BlockchainContextDefinition = _.assign(
|
||||
function(description: string, callback: BlockchainSuiteCallback): ISuite {
|
||||
return defineBlockchainSuite(StandardBlockchainTestsEnvironmentSingleton, description, callback, describe);
|
||||
},
|
||||
{
|
||||
configure(config?: Partial<BlockchainContextConfig>): void {
|
||||
// Update the global config and reset all environment singletons.
|
||||
TEST_ENV_CONFIG = {
|
||||
...TEST_ENV_CONFIG,
|
||||
...config,
|
||||
};
|
||||
ForkedBlockchainTestsEnvironmentSingleton.reset();
|
||||
StandardBlockchainTestsEnvironmentSingleton.reset();
|
||||
LiveBlockchainTestsEnvironmentSingleton.reset();
|
||||
},
|
||||
only(description: string, callback: BlockchainSuiteCallback): ISuite {
|
||||
return defineBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.only,
|
||||
);
|
||||
},
|
||||
skip(description: string, callback: BlockchainSuiteCallback): void {
|
||||
return defineBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.skip,
|
||||
);
|
||||
},
|
||||
optional(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.TEST_ALL ? describe : describe.skip,
|
||||
);
|
||||
},
|
||||
fork: _.assign(
|
||||
function(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
ForkedBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.FORK_RPC_URL ? describe : describe.skip,
|
||||
);
|
||||
},
|
||||
{
|
||||
only(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
ForkedBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.FORK_RPC_URL ? describe.only : describe.skip,
|
||||
);
|
||||
},
|
||||
skip(description: string, callback: BlockchainSuiteCallback): void {
|
||||
return defineBlockchainSuite(
|
||||
ForkedBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.skip,
|
||||
);
|
||||
},
|
||||
optional(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
ForkedBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.FORK_RPC_URL ? describe.optional : describe.skip,
|
||||
);
|
||||
},
|
||||
resets(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineResetsBlockchainSuite(
|
||||
ForkedBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.FORK_RPC_URL ? describe : describe.skip,
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
live: _.assign(
|
||||
function(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
LiveBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.LIVE_RPC_URL ? describe : describe.skip,
|
||||
);
|
||||
},
|
||||
{
|
||||
only(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
LiveBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.LIVE_RPC_URL ? describe.only : describe.skip,
|
||||
);
|
||||
},
|
||||
skip(description: string, callback: BlockchainSuiteCallback): void {
|
||||
return defineBlockchainSuite(
|
||||
LiveBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.skip,
|
||||
);
|
||||
},
|
||||
optional(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineBlockchainSuite(
|
||||
LiveBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
process.env.LIVE_RPC_URL ? describe.optional : describe.skip,
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
resets: _.assign(
|
||||
function(description: string, callback: BlockchainSuiteCallback): ISuite {
|
||||
return defineResetsBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe,
|
||||
);
|
||||
},
|
||||
{
|
||||
only(description: string, callback: BlockchainSuiteCallback): ISuite {
|
||||
return defineResetsBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.only,
|
||||
);
|
||||
},
|
||||
skip(description: string, callback: BlockchainSuiteCallback): void {
|
||||
return defineResetsBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.skip,
|
||||
);
|
||||
},
|
||||
optional(description: string, callback: BlockchainSuiteCallback): ISuite | void {
|
||||
return defineResetsBlockchainSuite(
|
||||
StandardBlockchainTestsEnvironmentSingleton,
|
||||
description,
|
||||
callback,
|
||||
describe.optional,
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
) as BlockchainContextDefinition;
|
||||
|
||||
function defineBlockchainSuite<T>(
|
||||
envFactory: BlockchainEnvironmentFactory,
|
||||
description: string,
|
||||
callback: BlockchainSuiteCallback,
|
||||
describeCall: ContextDefinitionCallback<T>,
|
||||
): T {
|
||||
return describeCall(description, function(this: ISuiteCallbackContext): void {
|
||||
callback.call(this, envFactory.create());
|
||||
});
|
||||
}
|
||||
|
||||
function defineResetsBlockchainSuite<T>(
|
||||
envFactory: BlockchainEnvironmentFactory,
|
||||
description: string,
|
||||
callback: BlockchainSuiteCallback,
|
||||
describeCall: ContextDefinitionCallback<T>,
|
||||
): T {
|
||||
return describeCall(description, function(this: ISuiteCallbackContext): void {
|
||||
const env = envFactory.create();
|
||||
beforeEach(async () => env.blockchainLifecycle.startAsync());
|
||||
afterEach(async () => env.blockchainLifecycle.revertAsync());
|
||||
callback.call(this, env);
|
||||
});
|
||||
}
|
||||
|
||||
function createDummyProvider(): Web3ProviderEngine {
|
||||
return {
|
||||
addProvider: _.noop,
|
||||
on: _.noop,
|
||||
send: _.noop,
|
||||
sendAsync: _.noop,
|
||||
start: _.noop,
|
||||
stop: _.noop,
|
||||
};
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as crypto from 'crypto';
|
||||
import { Decimal } from 'decimal.js';
|
||||
|
||||
import { expect } from './chai_setup';
|
||||
import { constants } from './constants';
|
||||
import { Numberish } from './types';
|
||||
|
||||
Decimal.set({ precision: 80 });
|
||||
|
||||
/**
|
||||
* Convert `x` to a `Decimal` type.
|
||||
*/
|
||||
export function toDecimal(x: Numberish): Decimal {
|
||||
if (BigNumber.isBigNumber(x)) {
|
||||
return new Decimal(x.toString(10));
|
||||
}
|
||||
return new Decimal(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random integer between `min` and `max`, inclusive.
|
||||
*/
|
||||
export function getRandomInteger(min: Numberish, max: Numberish): BigNumber {
|
||||
const range = new BigNumber(max).minus(min);
|
||||
return getRandomPortion(range).plus(min);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random integer between `0` and `total`, inclusive.
|
||||
*/
|
||||
export function getRandomPortion(total: Numberish): BigNumber {
|
||||
return new BigNumber(total).times(getRandomFloat(0, 1)).integerValue(BigNumber.ROUND_HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random, high-precision decimal between `min` and `max`, inclusive.
|
||||
*/
|
||||
export function getRandomFloat(min: Numberish, max: Numberish): BigNumber {
|
||||
// Generate a really high precision number between [0, 1]
|
||||
const r = new BigNumber(crypto.randomBytes(32).toString('hex'), 16).dividedBy(new BigNumber(2).pow(256).minus(1));
|
||||
return new BigNumber(max)
|
||||
.minus(min)
|
||||
.times(r)
|
||||
.plus(min);
|
||||
}
|
||||
|
||||
export const FIXED_POINT_BASE = new BigNumber(2).pow(127);
|
||||
|
||||
/**
|
||||
* Convert `n` to fixed-point integer represenatation.
|
||||
*/
|
||||
export function toFixed(n: Numberish): BigNumber {
|
||||
return new BigNumber(n).times(FIXED_POINT_BASE).integerValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `n` from fixed-point integer represenatation.
|
||||
*/
|
||||
export function fromFixed(n: Numberish): BigNumber {
|
||||
return new BigNumber(n).dividedBy(FIXED_POINT_BASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts two decimal numbers to integers with `precision` digits, then returns
|
||||
* the absolute difference.
|
||||
*/
|
||||
export function getNumericalDivergence(a: Numberish, b: Numberish, precision: number = 18): number {
|
||||
const _a = new BigNumber(a);
|
||||
const _b = new BigNumber(b);
|
||||
const maxIntegerDigits = Math.max(
|
||||
_a.integerValue(BigNumber.ROUND_DOWN).sd(true),
|
||||
_b.integerValue(BigNumber.ROUND_DOWN).sd(true),
|
||||
);
|
||||
const _toInteger = (n: BigNumber) => {
|
||||
const base = 10 ** (precision - maxIntegerDigits);
|
||||
return n.times(base).integerValue(BigNumber.ROUND_DOWN);
|
||||
};
|
||||
return _toInteger(_a)
|
||||
.minus(_toInteger(_b))
|
||||
.abs()
|
||||
.toNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two numbers are equal up to `precision` digits.
|
||||
*/
|
||||
export function assertRoughlyEquals(actual: Numberish, expected: Numberish, precision: number = 18): void {
|
||||
if (getNumericalDivergence(actual, expected, precision) <= 1) {
|
||||
return;
|
||||
}
|
||||
expect(actual).to.bignumber.eq(expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two numbers are equal with up to `maxError` difference between them.
|
||||
*/
|
||||
export function assertIntegerRoughlyEquals(
|
||||
actual: Numberish,
|
||||
expected: Numberish,
|
||||
maxError: number = 1,
|
||||
msg?: string,
|
||||
): void {
|
||||
const diff = new BigNumber(actual)
|
||||
.minus(expected)
|
||||
.abs()
|
||||
.toNumber();
|
||||
if (diff <= maxError) {
|
||||
return;
|
||||
}
|
||||
expect(actual, msg).to.bignumber.eq(expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `amount` into a base unit amount with 18 digits.
|
||||
*/
|
||||
export function toBaseUnitAmount(amount: Numberish, decimals?: number): BigNumber {
|
||||
const baseDecimals = decimals !== undefined ? decimals : 18;
|
||||
const amountAsBigNumber = new BigNumber(amount);
|
||||
const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountAsBigNumber, baseDecimals);
|
||||
return baseUnitAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a percentage of `value`, first converting `percentage` to be expressed in 18 digits.
|
||||
*/
|
||||
export function getPercentageOfValue(value: Numberish, percentage: Numberish): BigNumber {
|
||||
const numerator = constants.PERCENTAGE_DENOMINATOR.times(percentage).dividedToIntegerBy(100);
|
||||
const newValue = numerator.times(value).dividedToIntegerBy(constants.PERCENTAGE_DENOMINATOR);
|
||||
return newValue;
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { Order, SignatureType, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { getLatestBlockTimestampAsync } from './block_timestamp';
|
||||
import { constants } from './constants';
|
||||
import { orderHashUtils } from './order_hash';
|
||||
import { signingUtils } from './signing_utils';
|
||||
|
||||
export class OrderFactory {
|
||||
private readonly _defaultOrderParams: Partial<Order>;
|
||||
private readonly _privateKey: Buffer;
|
||||
|
||||
constructor(privateKey: Buffer, defaultOrderParams: Partial<Order>) {
|
||||
this._defaultOrderParams = defaultOrderParams;
|
||||
this._privateKey = privateKey;
|
||||
}
|
||||
|
||||
public async newSignedOrderAsync(
|
||||
customOrderParams: Partial<Order> = {},
|
||||
signatureType: SignatureType = SignatureType.EthSign,
|
||||
): Promise<SignedOrder> {
|
||||
const fifteenMinutesInSeconds = 15 * 60;
|
||||
const currentBlockTimestamp = await getLatestBlockTimestampAsync();
|
||||
const order = {
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
expirationTimeSeconds: new BigNumber(currentBlockTimestamp).plus(fifteenMinutesInSeconds),
|
||||
salt: generatePseudoRandomSalt(),
|
||||
...this._defaultOrderParams,
|
||||
...customOrderParams,
|
||||
} as Order; // tslint:disable-line:no-object-literal-type-assertion
|
||||
const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
|
||||
const signature = signingUtils.signMessage(orderHashBuff, this._privateKey, signatureType);
|
||||
const signedOrder = {
|
||||
...order,
|
||||
signature: `0x${signature.toString('hex')}`,
|
||||
};
|
||||
return signedOrder;
|
||||
}
|
||||
}
|
@@ -1,52 +0,0 @@
|
||||
import { assert } from '@0x/assert';
|
||||
import { schemas } from '@0x/json-schemas';
|
||||
import { eip712Utils } from '@0x/order-utils';
|
||||
import { Order, SignedOrder } from '@0x/types';
|
||||
import { signTypedDataUtils } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string';
|
||||
|
||||
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
export const orderHashUtils = {
|
||||
/**
|
||||
* Computes the orderHash for a supplied order.
|
||||
* @param order An object that conforms to the Order or SignedOrder interface definitions.
|
||||
* @return Hex encoded string orderHash from hashing the supplied order.
|
||||
*/
|
||||
getOrderHashHex(order: SignedOrder | Order): string {
|
||||
try {
|
||||
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
|
||||
} catch (error) {
|
||||
if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
|
||||
const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${NULL_ADDRESS}`;
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const orderHashBuff = orderHashUtils.getOrderHashBuffer(order);
|
||||
const orderHashHex = `0x${orderHashBuff.toString('hex')}`;
|
||||
return orderHashHex;
|
||||
},
|
||||
/**
|
||||
* Computes the orderHash for a supplied order
|
||||
* @param order An object that conforms to the Order or SignedOrder interface definitions.
|
||||
* @return A Buffer containing the resulting orderHash from hashing the supplied order
|
||||
*/
|
||||
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
|
||||
try {
|
||||
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
|
||||
} catch (error) {
|
||||
if (_.includes(error.message, INVALID_TAKER_FORMAT)) {
|
||||
const errMsg = `Order taker must be of type string. If you want anyone to be able to fill an order - pass ${NULL_ADDRESS}`;
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
const typedData = eip712Utils.createOrderTypedData(order);
|
||||
const orderHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
|
||||
return orderHashBuff;
|
||||
},
|
||||
};
|
@@ -1,65 +0,0 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { Order, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, hexUtils } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { BatchMatchOrder, CancelOrder, MatchOrder } from './types';
|
||||
|
||||
export const orderUtils = {
|
||||
getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
|
||||
const partialAmount = numerator
|
||||
.multipliedBy(target)
|
||||
.div(denominator)
|
||||
.integerValue(BigNumber.ROUND_FLOOR);
|
||||
return partialAmount;
|
||||
},
|
||||
createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
|
||||
const fill = {
|
||||
order: signedOrder,
|
||||
takerAssetFillAmount: takerAssetFillAmount || signedOrder.takerAssetAmount,
|
||||
signature: signedOrder.signature,
|
||||
};
|
||||
return fill;
|
||||
},
|
||||
createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber): CancelOrder {
|
||||
const cancel = {
|
||||
order: signedOrder,
|
||||
takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount,
|
||||
};
|
||||
return cancel;
|
||||
},
|
||||
createOrderWithoutSignature(signedOrder: SignedOrder): Order {
|
||||
const { signature, ...order } = signedOrder;
|
||||
return order;
|
||||
},
|
||||
createBatchMatchOrders(signedOrdersLeft: SignedOrder[], signedOrdersRight: SignedOrder[]): BatchMatchOrder {
|
||||
return {
|
||||
leftOrders: signedOrdersLeft.map(order => orderUtils.createOrderWithoutSignature(order)),
|
||||
rightOrders: signedOrdersRight.map(order => {
|
||||
const right = orderUtils.createOrderWithoutSignature(order);
|
||||
right.makerAssetData = constants.NULL_BYTES;
|
||||
right.takerAssetData = constants.NULL_BYTES;
|
||||
return right;
|
||||
}),
|
||||
leftSignatures: signedOrdersLeft.map(order => order.signature),
|
||||
rightSignatures: signedOrdersRight.map(order => order.signature),
|
||||
};
|
||||
},
|
||||
createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder): MatchOrder {
|
||||
const fill = {
|
||||
left: orderUtils.createOrderWithoutSignature(signedOrderLeft),
|
||||
right: orderUtils.createOrderWithoutSignature(signedOrderRight),
|
||||
leftSignature: signedOrderLeft.signature,
|
||||
rightSignature: signedOrderRight.signature,
|
||||
};
|
||||
fill.right.makerAssetData = constants.NULL_BYTES;
|
||||
fill.right.takerAssetData = constants.NULL_BYTES;
|
||||
return fill;
|
||||
},
|
||||
generatePseudoRandomOrderHash(): string {
|
||||
const randomBigNum = generatePseudoRandomSalt();
|
||||
const randomHash = hexUtils.hash(randomBigNum);
|
||||
return randomHash;
|
||||
},
|
||||
};
|
@@ -1,26 +0,0 @@
|
||||
import { devConstants } from '@0x/dev-utils';
|
||||
import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-profiler';
|
||||
|
||||
let profilerSubprovider: ProfilerSubprovider;
|
||||
|
||||
export const profiler = {
|
||||
start(): void {
|
||||
profiler.getProfilerSubproviderSingleton().start();
|
||||
},
|
||||
stop(): void {
|
||||
profiler.getProfilerSubproviderSingleton().stop();
|
||||
},
|
||||
getProfilerSubproviderSingleton(): ProfilerSubprovider {
|
||||
if (profilerSubprovider === undefined) {
|
||||
profilerSubprovider = profiler._getProfilerSubprovider();
|
||||
}
|
||||
return profilerSubprovider;
|
||||
},
|
||||
_getProfilerSubprovider(): ProfilerSubprovider {
|
||||
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
|
||||
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
|
||||
const isVerbose = true;
|
||||
const subprovider = new ProfilerSubprovider(solCompilerArtifactAdapter, defaultFromAddress, isVerbose);
|
||||
return subprovider;
|
||||
},
|
||||
};
|
@@ -1,20 +0,0 @@
|
||||
import { devConstants } from '@0x/dev-utils';
|
||||
import { RevertTraceSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-trace';
|
||||
|
||||
let revertTraceSubprovider: RevertTraceSubprovider;
|
||||
|
||||
export const revertTrace = {
|
||||
getRevertTraceSubproviderSingleton(): RevertTraceSubprovider {
|
||||
if (revertTraceSubprovider === undefined) {
|
||||
revertTraceSubprovider = revertTrace._getRevertTraceSubprovider();
|
||||
}
|
||||
return revertTraceSubprovider;
|
||||
},
|
||||
_getRevertTraceSubprovider(): RevertTraceSubprovider {
|
||||
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
|
||||
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
|
||||
const isVerbose = true;
|
||||
const subprovider = new RevertTraceSubprovider(solCompilerArtifactAdapter, defaultFromAddress, isVerbose);
|
||||
return subprovider;
|
||||
},
|
||||
};
|
@@ -1,29 +0,0 @@
|
||||
import { SignatureType } from '@0x/types';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
export const signingUtils = {
|
||||
signMessage(message: Buffer, privateKey: Buffer, signatureType: SignatureType): Buffer {
|
||||
if (signatureType === SignatureType.EthSign) {
|
||||
const prefixedMessage = ethUtil.hashPersonalMessage(message);
|
||||
const ecSignature = ethUtil.ecsign(prefixedMessage, privateKey);
|
||||
const signature = Buffer.concat([
|
||||
ethUtil.toBuffer(ecSignature.v),
|
||||
ecSignature.r,
|
||||
ecSignature.s,
|
||||
ethUtil.toBuffer(signatureType),
|
||||
]);
|
||||
return signature;
|
||||
} else if (signatureType === SignatureType.EIP712) {
|
||||
const ecSignature = ethUtil.ecsign(message, privateKey);
|
||||
const signature = Buffer.concat([
|
||||
ethUtil.toBuffer(ecSignature.v),
|
||||
ecSignature.r,
|
||||
ecSignature.s,
|
||||
ethUtil.toBuffer(signatureType),
|
||||
]);
|
||||
return signature;
|
||||
} else {
|
||||
throw new Error(`${signatureType} is not a valid signature type`);
|
||||
}
|
||||
},
|
||||
};
|
@@ -1,150 +0,0 @@
|
||||
import { BigNumber, RevertError } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { expect } from './chai_setup';
|
||||
|
||||
export async function testWithReferenceFuncAsync<P0, R>(
|
||||
referenceFunc: (p0: P0) => Promise<R>,
|
||||
testFunc: (p0: P0) => Promise<R>,
|
||||
values: [P0],
|
||||
): Promise<void>;
|
||||
export async function testWithReferenceFuncAsync<P0, P1, R>(
|
||||
referenceFunc: (p0: P0, p1: P1) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1) => Promise<R>,
|
||||
values: [P0, P1],
|
||||
): Promise<void>;
|
||||
export async function testWithReferenceFuncAsync<P0, P1, P2, R>(
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2) => Promise<R>,
|
||||
values: [P0, P1, P2],
|
||||
): Promise<void>;
|
||||
export async function testWithReferenceFuncAsync<P0, P1, P2, P3, R>(
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2, p3: P3) => Promise<R>,
|
||||
values: [P0, P1, P2, P3],
|
||||
): Promise<void>;
|
||||
export async function testWithReferenceFuncAsync<P0, P1, P2, P3, P4, R>(
|
||||
referenceFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
|
||||
testFunc: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) => Promise<R>,
|
||||
values: [P0, P1, P2, P3, P4],
|
||||
): Promise<void>;
|
||||
|
||||
/**
|
||||
* Tests the behavior of a test function by comparing it to the expected
|
||||
* behavior (defined by a reference function).
|
||||
*
|
||||
* First the reference function will be called to obtain an "expected result",
|
||||
* or if the reference function throws/rejects, an "expected error". Next, the
|
||||
* test function will be called to obtain an "actual result", or if the test
|
||||
* function throws/rejects, an "actual error". The test passes if at least one
|
||||
* of the following conditions is met:
|
||||
*
|
||||
* 1) Neither the reference function or the test function throw and the
|
||||
* "expected result" equals the "actual result".
|
||||
*
|
||||
* 2) Both the reference function and the test function throw and the "actual
|
||||
* error" message *contains* the "expected error" message.
|
||||
*
|
||||
* @param referenceFuncAsync a reference function implemented in pure
|
||||
* JavaScript/TypeScript which accepts N arguments and returns the "expected
|
||||
* result" or throws/rejects with the "expected error".
|
||||
* @param testFuncAsync a test function which, e.g., makes a call or sends a
|
||||
* transaction to a contract. It accepts the same N arguments returns the
|
||||
* "actual result" or throws/rejects with the "actual error".
|
||||
* @param values an array of N values, where each value corresponds in-order to
|
||||
* an argument to both the test function and the reference function.
|
||||
* @return A Promise that resolves if the test passes and rejects if the test
|
||||
* fails, according to the rules described above.
|
||||
*/
|
||||
export async function testWithReferenceFuncAsync(
|
||||
referenceFuncAsync: (...args: any[]) => Promise<any>,
|
||||
testFuncAsync: (...args: any[]) => Promise<any>,
|
||||
values: any[],
|
||||
): Promise<void> {
|
||||
// Measure correct behavior
|
||||
let expected: any;
|
||||
let expectedError: Error | undefined;
|
||||
try {
|
||||
expected = await referenceFuncAsync(...values);
|
||||
} catch (err) {
|
||||
expectedError = err;
|
||||
}
|
||||
// Measure actual behavior
|
||||
let actual: any;
|
||||
let actualError: Error | undefined;
|
||||
try {
|
||||
actual = await testFuncAsync(...values);
|
||||
} catch (err) {
|
||||
actualError = err;
|
||||
}
|
||||
|
||||
const testCaseString = _getTestCaseString(referenceFuncAsync, values);
|
||||
// Compare behavior
|
||||
if (expectedError !== undefined) {
|
||||
// Expecting an error.
|
||||
if (actualError === undefined) {
|
||||
return expect.fail(actualError, expectedError, `${testCaseString}: expected failure but instead succeeded`);
|
||||
} else {
|
||||
if (expectedError instanceof RevertError) {
|
||||
// Expecting a RevertError.
|
||||
if (actualError instanceof RevertError) {
|
||||
if (!actualError.equals(expectedError)) {
|
||||
return expect.fail(
|
||||
actualError,
|
||||
expectedError,
|
||||
`${testCaseString}: expected error ${actualError.toString()} to equal ${expectedError.toString()}`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return expect.fail(
|
||||
actualError,
|
||||
expectedError,
|
||||
`${testCaseString}: expected a RevertError but received an Error`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Expecing any Error type.
|
||||
if (actualError.message !== expectedError.message) {
|
||||
return expect.fail(
|
||||
actualError,
|
||||
expectedError,
|
||||
`${testCaseString}: expected error message '${actualError.message}' to equal '${expectedError.message}'`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Not expecting an error.
|
||||
if (actualError !== undefined) {
|
||||
return expect.fail(actualError, expectedError, `${testCaseString}: expected success but instead failed`);
|
||||
}
|
||||
if (expected instanceof BigNumber) {
|
||||
// Technically we can do this with `deep.eq`, but this prints prettier
|
||||
// error messages for BigNumbers.
|
||||
expect(actual).to.bignumber.eq(expected, testCaseString);
|
||||
} else {
|
||||
expect(actual).to.deep.eq(expected, testCaseString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _getTestCaseString(referenceFuncAsync: (...args: any[]) => Promise<any>, values: any[]): string {
|
||||
const paramNames = _getParameterNames(referenceFuncAsync);
|
||||
while (paramNames.length < values.length) {
|
||||
paramNames.push(`${paramNames.length}`);
|
||||
}
|
||||
return JSON.stringify(_.zipObject(paramNames, values));
|
||||
}
|
||||
|
||||
// Source: https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically
|
||||
function _getParameterNames(func: (...args: any[]) => any): string[] {
|
||||
return _.toString(func)
|
||||
.replace(/[/][/].*$/gm, '') // strip single-line comments
|
||||
.replace(/\s+/g, '') // strip white space
|
||||
.replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
|
||||
.split(/\){|\)=>/, 1)[0]
|
||||
.replace(/^[^(]*[(]/, '') // extract the parameters
|
||||
.replace(/=[^,]+/g, '') // strip any ES6 defaults
|
||||
.split(',')
|
||||
.filter(Boolean); // split & filter [""]
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { SignatureType, SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
|
||||
import { transactionHashUtils } from '../src';
|
||||
|
||||
import { getLatestBlockTimestampAsync } from './block_timestamp';
|
||||
import { constants } from './constants';
|
||||
import { signingUtils } from './signing_utils';
|
||||
|
||||
export class TransactionFactory {
|
||||
private readonly _signerBuff: Buffer;
|
||||
private readonly _exchangeAddress: string;
|
||||
private readonly _privateKey: Buffer;
|
||||
private readonly _chainId: number;
|
||||
|
||||
constructor(privateKey: Buffer, exchangeAddress: string, chainId: number) {
|
||||
this._privateKey = privateKey;
|
||||
this._exchangeAddress = exchangeAddress;
|
||||
this._chainId = chainId;
|
||||
this._signerBuff = ethUtil.privateToAddress(this._privateKey);
|
||||
}
|
||||
public async newSignedTransactionAsync(
|
||||
customTransactionParams: Partial<ZeroExTransaction>,
|
||||
signatureType: SignatureType = SignatureType.EthSign,
|
||||
): Promise<SignedZeroExTransaction> {
|
||||
if (customTransactionParams.data === undefined) {
|
||||
throw new Error('Error: ZeroExTransaction data field must be supplied');
|
||||
}
|
||||
const tenMinutesInSeconds = 10 * 60;
|
||||
const currentBlockTimestamp = await getLatestBlockTimestampAsync();
|
||||
const salt = generatePseudoRandomSalt();
|
||||
const signerAddress = `0x${this._signerBuff.toString('hex')}`;
|
||||
const transaction = {
|
||||
salt,
|
||||
signerAddress,
|
||||
data: customTransactionParams.data,
|
||||
expirationTimeSeconds: new BigNumber(currentBlockTimestamp).plus(tenMinutesInSeconds),
|
||||
gasPrice: new BigNumber(constants.DEFAULT_GAS_PRICE),
|
||||
domain: {
|
||||
verifyingContract: this._exchangeAddress,
|
||||
chainId: this._chainId,
|
||||
},
|
||||
...customTransactionParams,
|
||||
};
|
||||
|
||||
const transactionHashBuffer = transactionHashUtils.getTransactionHashBuffer(transaction);
|
||||
const signature = signingUtils.signMessage(transactionHashBuffer, this._privateKey, signatureType);
|
||||
const signedTransaction = {
|
||||
...transaction,
|
||||
signature: `0x${signature.toString('hex')}`,
|
||||
};
|
||||
return signedTransaction;
|
||||
}
|
||||
}
|
@@ -1,30 +0,0 @@
|
||||
import { assert } from '@0x/assert';
|
||||
import { schemas } from '@0x/json-schemas';
|
||||
import { eip712Utils } from '@0x/order-utils';
|
||||
import { SignedZeroExTransaction, ZeroExTransaction } from '@0x/types';
|
||||
import { signTypedDataUtils } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export const transactionHashUtils = {
|
||||
/**
|
||||
* Computes the transactionHash for a supplied 0x transaction.
|
||||
* @param transaction An object that conforms to the ZeroExTransaction or SignedZeroExTransaction interface definitions.
|
||||
* @return Hex encoded string transactionHash from hashing the supplied order.
|
||||
*/
|
||||
getTransactionHashHex(transaction: ZeroExTransaction | SignedZeroExTransaction): string {
|
||||
assert.doesConformToSchema('transaction', transaction, schemas.zeroExTransactionSchema, [schemas.hexSchema]);
|
||||
const transactionHashBuff = transactionHashUtils.getTransactionHashBuffer(transaction);
|
||||
const transactionHashHex = `0x${transactionHashBuff.toString('hex')}`;
|
||||
return transactionHashHex;
|
||||
},
|
||||
/**
|
||||
* Computes the transactionHash for a supplied 0x transaction.
|
||||
* @param transaction An object that conforms to the ZeroExTransaction or SignedZeroExTransaction interface definitions.
|
||||
* @return A Buffer containing the resulting transactionHash from hashing the supplied 0x transaction.
|
||||
*/
|
||||
getTransactionHashBuffer(transaction: ZeroExTransaction | SignedZeroExTransaction): Buffer {
|
||||
const typedData = eip712Utils.createZeroExTransactionTypedData(transaction);
|
||||
const transactionHashBuff = signTypedDataUtils.generateTypedDataHash(typedData);
|
||||
return transactionHashBuff;
|
||||
},
|
||||
};
|
@@ -1,21 +0,0 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import BN = require('bn.js');
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
|
||||
import { constants } from './constants';
|
||||
|
||||
export const typeEncodingUtils = {
|
||||
encodeUint256(value: BigNumber): Buffer {
|
||||
const base = 10;
|
||||
const formattedValue = new BN(value.toString(base));
|
||||
const encodedValue = ethUtil.toBuffer(formattedValue);
|
||||
// tslint:disable-next-line:custom-no-magic-numbers
|
||||
const paddedValue = ethUtil.setLengthLeft(encodedValue, constants.WORD_LENGTH);
|
||||
return paddedValue;
|
||||
},
|
||||
decodeUint256(encodedValue: Buffer): BigNumber {
|
||||
const formattedValue = ethUtil.bufferToHex(encodedValue);
|
||||
const value = new BigNumber(formattedValue, constants.BASE_16);
|
||||
return value;
|
||||
},
|
||||
};
|
@@ -1,163 +0,0 @@
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { AbiDefinition } from 'ethereum-types';
|
||||
|
||||
export { OrderStatus } from '@0x/types';
|
||||
|
||||
export interface ERC20BalancesByOwner {
|
||||
[ownerAddress: string]: {
|
||||
[tokenAddress: string]: BigNumber;
|
||||
};
|
||||
}
|
||||
|
||||
export interface EthBalancesByOwner {
|
||||
[owner: string]: BigNumber;
|
||||
}
|
||||
|
||||
export interface SubmissionContractEventArgs {
|
||||
transactionId: BigNumber;
|
||||
}
|
||||
|
||||
export interface BatchFillOrders {
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
takerAssetFillAmounts: BigNumber[];
|
||||
}
|
||||
|
||||
export interface MarketSellOrders {
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
takerAssetFillAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface MarketBuyOrders {
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
makerAssetFillAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface BatchCancelOrders {
|
||||
orders: Order[];
|
||||
}
|
||||
|
||||
export interface CancelOrdersBefore {
|
||||
salt: BigNumber;
|
||||
}
|
||||
|
||||
export interface TransactionDataParams {
|
||||
name: string;
|
||||
abi: AbiDefinition[];
|
||||
args: any[];
|
||||
}
|
||||
|
||||
export interface MultiSigConfig {
|
||||
owners: string[];
|
||||
confirmationsRequired: number;
|
||||
secondsRequired: number;
|
||||
}
|
||||
|
||||
export interface MultiSigConfigByNetwork {
|
||||
[networkName: string]: MultiSigConfig;
|
||||
}
|
||||
|
||||
export interface Token {
|
||||
address?: string;
|
||||
name: string;
|
||||
symbol: string;
|
||||
decimals: number;
|
||||
ipfsHash: string;
|
||||
swarmHash: string;
|
||||
}
|
||||
|
||||
export enum ContractName {
|
||||
TokenRegistry = 'TokenRegistry',
|
||||
MultiSigWalletWithTimeLock = 'MultiSigWalletWithTimeLock',
|
||||
Exchange = 'Exchange',
|
||||
DummyERC20Token = 'DummyERC20Token',
|
||||
EtherToken = 'WETH9',
|
||||
DutchAuction = 'DutchAuction',
|
||||
ZeroExGovernor = 'ZeroExGovernor',
|
||||
AccountLevels = 'AccountLevels',
|
||||
EtherDelta = 'EtherDelta',
|
||||
Arbitrage = 'Arbitrage',
|
||||
TestAssetDataDecoders = 'TestAssetDataDecoders',
|
||||
TestAssetProxyDispatcher = 'TestAssetProxyDispatcher',
|
||||
TestLibs = 'TestLibs',
|
||||
TestSignatureValidator = 'TestSignatureValidator',
|
||||
ERC20Proxy = 'ERC20Proxy',
|
||||
ERC721Proxy = 'ERC721Proxy',
|
||||
DummyERC721Receiver = 'DummyERC721Receiver',
|
||||
DummyERC721Token = 'DummyERC721Token',
|
||||
TestLibBytes = 'TestLibBytes',
|
||||
TestWallet = 'TestWallet',
|
||||
Authorizable = 'Authorizable',
|
||||
Whitelist = 'Whitelist',
|
||||
Forwarder = 'Forwarder',
|
||||
BalanceThresholdFilter = 'BalanceThresholdFilter',
|
||||
}
|
||||
|
||||
export interface CancelOrder {
|
||||
order: Order;
|
||||
takerAssetCancelAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface BatchMatchOrder {
|
||||
leftOrders: Order[];
|
||||
rightOrders: Order[];
|
||||
leftSignatures: string[];
|
||||
rightSignatures: string[];
|
||||
}
|
||||
|
||||
export interface MatchOrder {
|
||||
left: Order;
|
||||
right: Order;
|
||||
leftSignature: string;
|
||||
rightSignature: string;
|
||||
}
|
||||
|
||||
export interface TokenBalances {
|
||||
erc20: ERC20BalancesByOwner;
|
||||
eth: EthBalancesByOwner;
|
||||
}
|
||||
|
||||
export interface FillEventArgs {
|
||||
orderHash: string;
|
||||
makerAddress: string;
|
||||
takerAddress: string;
|
||||
makerAssetFilledAmount: BigNumber;
|
||||
takerAssetFilledAmount: BigNumber;
|
||||
makerFeePaid: BigNumber;
|
||||
takerFeePaid: BigNumber;
|
||||
}
|
||||
|
||||
export type Numberish = BigNumber | string | number;
|
||||
|
||||
export enum ExchangeFunctionName {
|
||||
BatchCancelOrders = 'batchCancelOrders',
|
||||
BatchExecuteTransactions = 'batchExecuteTransactions',
|
||||
BatchFillOrKillOrders = 'batchFillOrKillOrders',
|
||||
BatchFillOrders = 'batchFillOrders',
|
||||
BatchFillOrdersNoThrow = 'batchFillOrdersNoThrow',
|
||||
BatchMatchOrders = 'batchMatchOrders',
|
||||
BatchMatchOrdersWithMaximalFill = 'batchMatchOrdersWithMaximalFill',
|
||||
CancelOrder = 'cancelOrder',
|
||||
CancelOrdersUpTo = 'cancelOrdersUpTo',
|
||||
ExecuteTransaction = 'executeTransaction',
|
||||
FillOrKillOrder = 'fillOrKillOrder',
|
||||
FillOrder = 'fillOrder',
|
||||
FillOrderNoThrow = 'fillOrderNoThrow',
|
||||
MarketBuyOrdersNoThrow = 'marketBuyOrdersNoThrow',
|
||||
MarketSellOrdersNoThrow = 'marketSellOrdersNoThrow',
|
||||
MarketBuyOrdersFillOrKill = 'marketBuyOrdersFillOrKill',
|
||||
MarketSellOrdersFillOrKill = 'marketSellOrdersFillOrKill',
|
||||
MatchOrders = 'matchOrders',
|
||||
MatchOrdersWithMaximalFill = 'matchOrdersWithMaximalFill',
|
||||
PreSign = 'preSign',
|
||||
RegisterAssetProxy = 'registerAssetProxy',
|
||||
SetSignatureValidatorApproval = 'setSignatureValidatorApproval',
|
||||
SimulateDispatchTransferFromCalls = 'simulateDispatchTransferFromCalls',
|
||||
TransferOwnership = 'transferOwnership',
|
||||
SetProtocolFeeMultiplier = 'setProtocolFeeMultiplier',
|
||||
SetProtocolFeeCollectorAddress = 'setProtocolFeeCollectorAddress',
|
||||
DetachProtocolFeeCollector = 'detachProtocolFeeCollector',
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
import { devConstants, env, EnvVars, Web3Config, web3Factory } from '@0x/dev-utils';
|
||||
import { prependSubprovider, Web3ProviderEngine } from '@0x/subproviders';
|
||||
import { logUtils } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { coverage } from './coverage';
|
||||
import { profiler } from './profiler';
|
||||
import { revertTrace } from './revert_trace';
|
||||
|
||||
export const txDefaults = {
|
||||
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||
gas: devConstants.GAS_LIMIT,
|
||||
gasPrice: constants.DEFAULT_GAS_PRICE,
|
||||
};
|
||||
|
||||
export let providerConfigs: Web3Config = {
|
||||
total_accounts: constants.NUM_TEST_ACCOUNTS,
|
||||
shouldUseInProcessGanache: true,
|
||||
shouldAllowUnlimitedContractSize: true,
|
||||
hardfork: 'istanbul',
|
||||
gasLimit: 100e6,
|
||||
unlocked_accounts: [
|
||||
'0x6cc5f688a315f3dc28a7781717a9a798a59fda7b',
|
||||
'0x55dc8f21d20d4c6ed3c82916a438a413ca68e335',
|
||||
'0x8ed95d1746bf1e4dab58d8ed4724f1ef95b20db0', // ERC20BridgeProxy
|
||||
'0xf977814e90da44bfa03b6295a0616a897441acec', // Binance: USDC, TUSD
|
||||
],
|
||||
};
|
||||
|
||||
export const provider: Web3ProviderEngine = web3Factory.getRpcProvider(providerConfigs);
|
||||
provider.stop();
|
||||
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
|
||||
const isProfilerEnabled = env.parseBoolean(EnvVars.SolidityProfiler);
|
||||
const isRevertTraceEnabled = env.parseBoolean(EnvVars.SolidityRevertTrace);
|
||||
const enabledSubproviderCount = _.filter(
|
||||
[isCoverageEnabled, isProfilerEnabled, isRevertTraceEnabled],
|
||||
_.identity.bind(_),
|
||||
).length;
|
||||
if (enabledSubproviderCount > 1) {
|
||||
throw new Error(`Only one of coverage, profiler, or revert trace subproviders can be enabled at a time`);
|
||||
}
|
||||
if (isCoverageEnabled) {
|
||||
const coverageSubprovider = coverage.getCoverageSubproviderSingleton();
|
||||
prependSubprovider(provider, coverageSubprovider);
|
||||
}
|
||||
if (isProfilerEnabled) {
|
||||
const profilerSubprovider = profiler.getProfilerSubproviderSingleton();
|
||||
logUtils.log(
|
||||
"By default profilerSubprovider is stopped so that you don't get noise from setup code. Don't forget to start it before the code you want to profile and stop it afterwards",
|
||||
);
|
||||
profilerSubprovider.stop();
|
||||
prependSubprovider(provider, profilerSubprovider);
|
||||
}
|
||||
if (isRevertTraceEnabled) {
|
||||
const revertTraceSubprovider = revertTrace.getRevertTraceSubproviderSingleton();
|
||||
prependSubprovider(provider, revertTraceSubprovider);
|
||||
}
|
||||
|
||||
export const web3Wrapper = new Web3Wrapper(provider);
|
@@ -1,105 +0,0 @@
|
||||
import * as _ from 'lodash';
|
||||
import * as process from 'process';
|
||||
|
||||
import { expect } from '../src/chai_setup';
|
||||
import { constants } from '../src/constants';
|
||||
import { blockchainTests, describe } from '../src/mocha_blockchain';
|
||||
|
||||
blockchainTests('mocha blockchain extensions', env => {
|
||||
describe('blockchainTests()', () => {
|
||||
it('passes a valid environment object', () => {
|
||||
expect(env.blockchainLifecycle).to.exist('');
|
||||
expect(env.provider).to.exist('');
|
||||
expect(env.txDefaults).to.exist('');
|
||||
expect(env.web3Wrapper).to.exist('');
|
||||
// HACK(dorothy-zbornak): tslint seems to get confused by these assertions.
|
||||
// tslint:disable: no-unbound-method
|
||||
expect(typeof env.getChainIdAsync).to.eq('function');
|
||||
expect(typeof env.getAccountAddressesAsync).to.eq('function');
|
||||
// tslint:enable: no-unbound-method
|
||||
});
|
||||
|
||||
it('initializes the test environment', async () => {
|
||||
expect(await env.getChainIdAsync()).to.eq(constants.TESTRPC_CHAIN_ID);
|
||||
expect(await env.getAccountAddressesAsync()).to.be.not.empty('');
|
||||
});
|
||||
|
||||
describe('modifiers', () => {
|
||||
blockchainTests.skip('skip', () => {
|
||||
it('does not execute this test', () => {
|
||||
expect.fail();
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests('only', () => {
|
||||
it.skip("can't test `only` :-(", () => {
|
||||
// no-op.
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.optional('optional', () => {
|
||||
it('only runs this with `TEST_ALL` environment flag set', () => {
|
||||
expect(process.env.TEST_ALL).to.be.ok('');
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('resets', () => {
|
||||
const originalBlockhainLifecycle = env.blockchainLifecycle;
|
||||
const blockchainLifecycleCalls = [] as string[];
|
||||
|
||||
before(() => {
|
||||
// Replace `blockchainLifecycle` with a hooked version.
|
||||
env.blockchainLifecycle = createHookedObject(
|
||||
originalBlockhainLifecycle,
|
||||
methodName => blockchainLifecycleCalls.push(methodName),
|
||||
['startAsync', 'revertAsync'],
|
||||
);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
// Undo the hook.
|
||||
env.blockchainLifecycle = originalBlockhainLifecycle;
|
||||
});
|
||||
|
||||
it('calls `blockchainLifecycle.startAsync()` before this test', () => {
|
||||
expect(blockchainLifecycleCalls).to.eql(['startAsync']);
|
||||
});
|
||||
|
||||
it('calls `blockchainLifecycle.revertAsync()` after the last test', () => {
|
||||
expect(blockchainLifecycleCalls).to.eql(['startAsync', 'revertAsync', 'startAsync']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests('nested tests', nestedEnv => {
|
||||
it('shares the same environment object', () => {
|
||||
expect(nestedEnv).to.eq(env);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtests', () => {
|
||||
require('./subtests/mocha_blockchain_1').append(env);
|
||||
});
|
||||
});
|
||||
|
||||
describe('describe extensions', () => {
|
||||
describe('modifiers', () => {
|
||||
describe.optional('optional', () => {
|
||||
it('only runs this with `TEST_ALL` environment flag set', () => {
|
||||
expect(process.env.TEST_ALL).to.be.ok('');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createHookedObject(obj: any, handler: (name: string) => void, methods: string[]): any {
|
||||
const hookedMethods = _.map(methods, methodName => {
|
||||
// tslint:disable: only-arrow-functions
|
||||
return function(this: any, ...args: any[]): any {
|
||||
handler(methodName);
|
||||
return obj[methodName].call(this, ...args);
|
||||
};
|
||||
});
|
||||
return _.assign(_.clone(obj), _.zipObject(methods, hookedMethods));
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
import { chaiSetup } from '@0x/dev-utils';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { orderHashUtils } from '../src';
|
||||
|
||||
import { constants } from '../src/constants';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('Order hashing', () => {
|
||||
describe('#getOrderHashHex', () => {
|
||||
const expectedOrderHash = '0x331cb7e07a757bae130702da6646c26531798c92bcfaf671817268fd2c188531';
|
||||
const fakeExchangeContractAddress = '0x1dc4c1cefef38a777b15aa20260a54e584b16c48';
|
||||
const fakeChainID = 50;
|
||||
const order: Order = {
|
||||
makerAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
makerAssetData: constants.NULL_ADDRESS,
|
||||
takerAssetData: constants.NULL_ADDRESS,
|
||||
makerFeeAssetData: constants.NULL_ADDRESS,
|
||||
takerFeeAssetData: constants.NULL_ADDRESS,
|
||||
salt: new BigNumber(0),
|
||||
makerFee: new BigNumber(0),
|
||||
takerFee: new BigNumber(0),
|
||||
makerAssetAmount: new BigNumber(0),
|
||||
takerAssetAmount: new BigNumber(0),
|
||||
expirationTimeSeconds: new BigNumber(0),
|
||||
exchangeAddress: fakeExchangeContractAddress,
|
||||
chainId: fakeChainID,
|
||||
};
|
||||
it('calculates the order hash', async () => {
|
||||
const orderHash = orderHashUtils.getOrderHashHex(order);
|
||||
expect(orderHash).to.be.equal(expectedOrderHash);
|
||||
});
|
||||
it('calculates the order hash if amounts are strings', async () => {
|
||||
// It's common for developers using javascript to provide the amounts
|
||||
// as strings. Since we eventually toString() the BigNumber
|
||||
// before encoding we should result in the same orderHash in this scenario
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const orderHash = orderHashUtils.getOrderHashHex({
|
||||
...order,
|
||||
makerAssetAmount: '0',
|
||||
takerAssetAmount: '0',
|
||||
makerFee: '0',
|
||||
takerFee: '0',
|
||||
} as any);
|
||||
expect(orderHash).to.be.equal(expectedOrderHash);
|
||||
});
|
||||
it('throws a readable error message if taker format is invalid', async () => {
|
||||
const orderWithInvalidtakerFormat = {
|
||||
...order,
|
||||
takerAddress: (null as any) as string,
|
||||
};
|
||||
const expectedErrorMessage = `Expected order to conform to schema`;
|
||||
expect(() => orderHashUtils.getOrderHashHex(orderWithInvalidtakerFormat)).to.throw(expectedErrorMessage);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,11 +0,0 @@
|
||||
import { expect } from '../../src/chai_setup';
|
||||
import { blockchainTests, BlockchainTestsEnvironment } from '../../src/mocha_blockchain';
|
||||
|
||||
// tslint:disable: no-default-export completed-docs
|
||||
export function append(env: BlockchainTestsEnvironment): void {
|
||||
blockchainTests('imported subtests', subtestsEnv => {
|
||||
it('shares the same environment object', () => {
|
||||
expect(subtestsEnv).to.eq(env);
|
||||
});
|
||||
});
|
||||
}
|
@@ -1,89 +0,0 @@
|
||||
import { AnyRevertError, StringRevertError } from '@0x/utils';
|
||||
|
||||
import { expect } from '../src/chai_setup';
|
||||
|
||||
import { testWithReferenceFuncAsync } from '../src/test_with_reference';
|
||||
|
||||
async function divAsync(x: number, y: number): Promise<number> {
|
||||
if (y === 0) {
|
||||
throw new Error('MathError: divide by zero');
|
||||
}
|
||||
return x / y;
|
||||
}
|
||||
|
||||
// returns an async function that always returns the given value.
|
||||
function alwaysValueFunc(value: number): (x: number, y: number) => Promise<number> {
|
||||
return async (x: number, y: number) => value;
|
||||
}
|
||||
|
||||
// returns an async function which always throws/rejects with the given error.
|
||||
function alwaysFailFunc(error: Error): (x: number, y: number) => Promise<number> {
|
||||
return async (x: number, y: number) => {
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
|
||||
describe('testWithReferenceFuncAsync', () => {
|
||||
it('passes when both succeed and actual == expected', async () => {
|
||||
return testWithReferenceFuncAsync(alwaysValueFunc(0.5), divAsync, [1, 2]);
|
||||
});
|
||||
|
||||
it('fails when both succeed and actual != expected', async () => {
|
||||
return expect(testWithReferenceFuncAsync(alwaysValueFunc(3), divAsync, [1, 2])).to.be.rejectedWith(
|
||||
'{"x":1,"y":2}: expected 0.5 to deeply equal 3',
|
||||
);
|
||||
});
|
||||
|
||||
it('passes when both fail and error messages are the same', async () => {
|
||||
const err = new Error('whoopsie');
|
||||
return testWithReferenceFuncAsync(alwaysFailFunc(err), alwaysFailFunc(err), [1, 1]);
|
||||
});
|
||||
|
||||
it('fails when both fail and error messages are not identical', async () => {
|
||||
const errorMessage = 'whoopsie';
|
||||
const notErrorMessage = 'not whoopsie';
|
||||
const error = new Error(errorMessage);
|
||||
const notError = new Error(notErrorMessage);
|
||||
return expect(
|
||||
testWithReferenceFuncAsync(alwaysFailFunc(notError), alwaysFailFunc(error), [1, 2]),
|
||||
).to.be.rejectedWith(`{"x":1,"y":2}: expected error message '${errorMessage}' to equal '${notErrorMessage}'`);
|
||||
});
|
||||
|
||||
it('passes when both fail with compatible RevertErrors', async () => {
|
||||
const error1 = new StringRevertError('whoopsie');
|
||||
const error2 = new AnyRevertError();
|
||||
return testWithReferenceFuncAsync(alwaysFailFunc(error1), alwaysFailFunc(error2), [1, 1]);
|
||||
});
|
||||
|
||||
it('fails when both fail with incompatible RevertErrors', async () => {
|
||||
const error1 = new StringRevertError('whoopsie');
|
||||
const error2 = new StringRevertError('not whoopsie');
|
||||
return expect(
|
||||
testWithReferenceFuncAsync(alwaysFailFunc(error1), alwaysFailFunc(error2), [1, 1]),
|
||||
).to.be.rejectedWith(
|
||||
`{"x":1,"y":1}: expected error StringRevertError({ message: 'not whoopsie' }) to equal StringRevertError({ message: 'whoopsie' })`,
|
||||
);
|
||||
});
|
||||
|
||||
it('fails when reference function fails with a RevertError but test function fails with a regular Error', async () => {
|
||||
const error1 = new StringRevertError('whoopsie');
|
||||
const error2 = new Error('whoopsie');
|
||||
return expect(
|
||||
testWithReferenceFuncAsync(alwaysFailFunc(error1), alwaysFailFunc(error2), [1, 1]),
|
||||
).to.be.rejectedWith(`{"x":1,"y":1}: expected a RevertError but received an Error`);
|
||||
});
|
||||
|
||||
it('fails when referenceFunc succeeds and testFunc fails', async () => {
|
||||
const error = new Error('whoopsie');
|
||||
return expect(testWithReferenceFuncAsync(alwaysValueFunc(0), alwaysFailFunc(error), [1, 2])).to.be.rejectedWith(
|
||||
`{"x":1,"y":2}: expected success but instead failed`,
|
||||
);
|
||||
});
|
||||
|
||||
it('fails when referenceFunc fails and testFunc succeeds', async () => {
|
||||
const error = new Error('whoopsie');
|
||||
return expect(testWithReferenceFuncAsync(alwaysFailFunc(error), divAsync, [1, 2])).to.be.rejectedWith(
|
||||
'{"x":1,"y":2}: expected failure but instead succeeded',
|
||||
);
|
||||
});
|
||||
});
|
@@ -1,48 +0,0 @@
|
||||
import { chaiSetup } from '@0x/dev-utils';
|
||||
import { ZeroExTransaction } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { transactionHashUtils } from '../src';
|
||||
|
||||
import { constants } from '../src/constants';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
describe('0x transaction hashing', () => {
|
||||
describe('#getTransactionHashHex', () => {
|
||||
const expectedTransactionHash = '0x7845d260300acfbebaff52f0462f984016473290b9eb865fb6ffac0503cab364';
|
||||
const fakeVerifyingContractAddress = '0x5e72914535f202659083db3a02c984188fa26e9f';
|
||||
const fakeChainId = 1337;
|
||||
const transaction: ZeroExTransaction = {
|
||||
signerAddress: constants.NULL_ADDRESS,
|
||||
salt: new BigNumber(0),
|
||||
expirationTimeSeconds: new BigNumber(0),
|
||||
gasPrice: new BigNumber(0),
|
||||
data: constants.NULL_BYTES,
|
||||
domain: {
|
||||
verifyingContract: fakeVerifyingContractAddress,
|
||||
chainId: fakeChainId,
|
||||
},
|
||||
};
|
||||
it('calculates the transaction hash', async () => {
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
expect(transactionHash).to.be.equal(expectedTransactionHash);
|
||||
});
|
||||
it('calculates the transaction hash if amounts are strings', async () => {
|
||||
// It's common for developers using javascript to provide the amounts
|
||||
// as strings. Since we eventually toString() the BigNumber
|
||||
// before encoding we should result in the same orderHash in this scenario
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex({
|
||||
...transaction,
|
||||
salt: '0',
|
||||
expirationTimeSeconds: '0',
|
||||
gasPrice: '0',
|
||||
} as any);
|
||||
expect(transactionHash).to.be.equal(expectedTransactionHash);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,7 +0,0 @@
|
||||
{
|
||||
// This file is a workaround that issue: https://github.com/palantir/tslint/issues/4148#issuecomment-419872702
|
||||
"extends": "./tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": false
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"extends": ["@0x/tslint-config"],
|
||||
"rules": {
|
||||
"custom-no-magic-numbers": false
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
# Blacklist all files
|
||||
.*
|
||||
*
|
||||
# Whitelist lib
|
||||
!lib/**/*
|
||||
# Whitelist Solidity contracts
|
||||
!contracts/src/**/*
|
||||
# Blacklist tests in lib
|
||||
/lib/test/*
|
||||
# Package specific ignore
|
@@ -1,358 +0,0 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1658950329,
|
||||
"version": "1.4.16",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1655244958,
|
||||
"version": "1.4.15",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1654284040,
|
||||
"version": "1.4.14",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1652919697,
|
||||
"version": "1.4.13",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1650611093,
|
||||
"version": "1.4.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1648739346,
|
||||
"version": "1.4.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1646225739,
|
||||
"version": "1.4.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1645569128,
|
||||
"version": "1.4.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1640364306,
|
||||
"version": "1.4.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1638390144,
|
||||
"version": "1.4.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1637102971,
|
||||
"version": "1.4.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1635903615,
|
||||
"version": "1.4.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634668033,
|
||||
"version": "1.4.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1634147078,
|
||||
"version": "1.4.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1633374058,
|
||||
"version": "1.4.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1632957537,
|
||||
"version": "1.4.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.4.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Support cast vote by signature in Treasury"
|
||||
}
|
||||
],
|
||||
"timestamp": 1631710679
|
||||
},
|
||||
{
|
||||
"timestamp": 1631120757,
|
||||
"version": "1.3.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1630459879,
|
||||
"version": "1.3.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629353596,
|
||||
"version": "1.3.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1629079369,
|
||||
"version": "1.3.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1628665757,
|
||||
"version": "1.3.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.3.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Added proposal 1 params and test",
|
||||
"pr": 298
|
||||
}
|
||||
],
|
||||
"timestamp": 1628225642
|
||||
},
|
||||
{
|
||||
"timestamp": 1624356181,
|
||||
"version": "1.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1623382456,
|
||||
"version": "1.2.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1622609597,
|
||||
"version": "1.2.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Added proposal 0 params and test",
|
||||
"pr": 252
|
||||
}
|
||||
],
|
||||
"timestamp": 1622154125
|
||||
},
|
||||
{
|
||||
"timestamp": 1621944788,
|
||||
"version": "1.1.8",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1621600614,
|
||||
"version": "1.1.7",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1620214333,
|
||||
"version": "1.1.6",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Patched votingPower logic",
|
||||
"pr": 214
|
||||
}
|
||||
],
|
||||
"timestamp": 1619825976
|
||||
},
|
||||
{
|
||||
"timestamp": 1619596077,
|
||||
"version": "1.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1619481586,
|
||||
"version": "1.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1618259868,
|
||||
"version": "1.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1617311315,
|
||||
"version": "1.1.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.1.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Make the proposal/quorum thresholds updatable",
|
||||
"pr": 165
|
||||
}
|
||||
],
|
||||
"timestamp": 1616005394
|
||||
},
|
||||
{
|
||||
"timestamp": 1614141718,
|
||||
"version": "1.0.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1612950500,
|
||||
"version": "1.0.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Create this package",
|
||||
"pr": 120
|
||||
}
|
||||
],
|
||||
"timestamp": 1611869778
|
||||
}
|
||||
]
|
@@ -1,162 +0,0 @@
|
||||
<!--
|
||||
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
|
||||
Edit the package's CHANGELOG.json file only.
|
||||
-->
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.4.16 - _July 27, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.15 - _June 14, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.14 - _June 3, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.13 - _May 19, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.12 - _April 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.11 - _March 31, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.10 - _March 2, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.9 - _February 22, 2022_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.8 - _December 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.7 - _December 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.6 - _November 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.5 - _November 3, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.4 - _October 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.3 - _October 13, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.2 - _October 4, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.1 - _September 29, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.0 - _September 15, 2021_
|
||||
|
||||
* Support cast vote by signature in Treasury
|
||||
|
||||
## v1.3.5 - _September 8, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.4 - _September 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.3 - _August 19, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.2 - _August 16, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.1 - _August 11, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.0 - _August 6, 2021_
|
||||
|
||||
* Added proposal 1 params and test (#298)
|
||||
|
||||
## v1.2.3 - _June 22, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.2.2 - _June 11, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.2.1 - _June 2, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.2.0 - _May 27, 2021_
|
||||
|
||||
* Added proposal 0 params and test (#252)
|
||||
|
||||
## v1.1.8 - _May 25, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.7 - _May 21, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.6 - _May 5, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.5 - _April 30, 2021_
|
||||
|
||||
* Patched votingPower logic (#214)
|
||||
|
||||
## v1.1.4 - _April 28, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.3 - _April 26, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.2 - _April 12, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.1 - _April 1, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.0 - _March 17, 2021_
|
||||
|
||||
* Make the proposal/quorum thresholds updatable (#165)
|
||||
|
||||
## v1.0.2 - _February 24, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.1 - _February 10, 2021_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.0.0 - _January 28, 2021_
|
||||
|
||||
* Create this package (#120)
|
@@ -1 +0,0 @@
|
||||
[]
|
@@ -1,29 +0,0 @@
|
||||
{
|
||||
"artifactsDir": "./test/generated-artifacts",
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"shouldCompileIndependently": true,
|
||||
"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",
|
||||
"evm.methodIdentifiers"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
pragma solidity ^0.6.12;
|
||||
|
||||
/**
|
||||
* @title ISablier
|
||||
* @author Sablier
|
||||
*/
|
||||
interface ISablier {
|
||||
/**
|
||||
* @notice Emits when a stream is successfully created.
|
||||
*/
|
||||
event CreateStream(
|
||||
uint256 indexed streamId,
|
||||
address indexed sender,
|
||||
address indexed recipient,
|
||||
uint256 deposit,
|
||||
address tokenAddress,
|
||||
uint256 startTime,
|
||||
uint256 stopTime
|
||||
);
|
||||
|
||||
/**
|
||||
* @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream.
|
||||
*/
|
||||
event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount);
|
||||
|
||||
/**
|
||||
* @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis.
|
||||
*/
|
||||
event CancelStream(
|
||||
uint256 indexed streamId,
|
||||
address indexed sender,
|
||||
address indexed recipient,
|
||||
uint256 senderBalance,
|
||||
uint256 recipientBalance
|
||||
);
|
||||
|
||||
function balanceOf(uint256 streamId, address who) external view returns (uint256 balance);
|
||||
|
||||
function getStream(uint256 streamId)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
address sender,
|
||||
address recipient,
|
||||
uint256 deposit,
|
||||
address token,
|
||||
uint256 startTime,
|
||||
uint256 stopTime,
|
||||
uint256 remainingBalance,
|
||||
uint256 ratePerSecond
|
||||
);
|
||||
|
||||
function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
|
||||
external
|
||||
returns (uint256 streamId);
|
||||
|
||||
function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool);
|
||||
|
||||
function cancelStream(uint256 streamId) external returns (bool);
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 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.6.12;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
||||
import "./IStaking.sol";
|
||||
|
||||
|
||||
contract DefaultPoolOperator {
|
||||
// Immutables
|
||||
IStaking public immutable stakingProxy;
|
||||
IERC20TokenV06 public immutable weth;
|
||||
bytes32 public immutable poolId;
|
||||
|
||||
/// @dev Initializes this contract and creates a staking pool.
|
||||
/// @param stakingProxy_ The 0x staking proxy contract.
|
||||
/// @param weth_ The WETH token contract.
|
||||
constructor(
|
||||
IStaking stakingProxy_,
|
||||
IERC20TokenV06 weth_
|
||||
)
|
||||
public
|
||||
{
|
||||
stakingProxy = stakingProxy_;
|
||||
weth = weth_;
|
||||
// operator share = 100%
|
||||
poolId = stakingProxy_.createStakingPool(10 ** 6, false);
|
||||
}
|
||||
|
||||
/// @dev Sends this contract's entire WETH balance to the
|
||||
/// staking proxy contract. This function exists in case
|
||||
/// someone joins the default staking pool and starts
|
||||
/// market making for some reason, thus earning this contract
|
||||
/// some staking rewards. Note that anyone can call this
|
||||
/// function at any time.
|
||||
function returnStakingRewards()
|
||||
external
|
||||
{
|
||||
uint256 wethBalance = weth.balanceOf(address(this));
|
||||
weth.transfer(address(stakingProxy), wethBalance);
|
||||
}
|
||||
}
|
@@ -1,127 +0,0 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/*
|
||||
|
||||
Copyright 2021 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.6.12;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
||||
interface IStaking {
|
||||
/// @dev Statuses that stake can exist in.
|
||||
/// Any stake can be (re)delegated effective at the next epoch
|
||||
/// Undelegated stake can be withdrawn if it is available in both the current and next epoch
|
||||
enum StakeStatus {
|
||||
UNDELEGATED,
|
||||
DELEGATED
|
||||
}
|
||||
|
||||
/// @dev Encapsulates a balance for the current and next epochs.
|
||||
/// Note that these balances may be stale if the current epoch
|
||||
/// is greater than `currentEpoch`.
|
||||
/// @param currentEpoch The current epoch
|
||||
/// @param currentEpochBalance Balance in the current epoch.
|
||||
/// @param nextEpochBalance Balance in `currentEpoch+1`.
|
||||
struct StoredBalance {
|
||||
uint64 currentEpoch;
|
||||
uint96 currentEpochBalance;
|
||||
uint96 nextEpochBalance;
|
||||
}
|
||||
|
||||
/// @dev Holds the metadata for a staking pool.
|
||||
/// @param operator Operator of the pool.
|
||||
/// @param operatorShare Fraction of the total balance owned by the operator, in ppm.
|
||||
struct Pool {
|
||||
address operator;
|
||||
uint32 operatorShare;
|
||||
}
|
||||
|
||||
/// @dev Create a new staking pool. The sender will be the operator of this pool.
|
||||
/// Note that an operator must be payable.
|
||||
/// @param operatorShare Portion of rewards owned by the operator, in ppm.
|
||||
/// @param addOperatorAsMaker Adds operator to the created pool as a maker for convenience iff true.
|
||||
/// @return poolId The unique pool id generated for this pool.
|
||||
function createStakingPool(uint32 operatorShare, bool addOperatorAsMaker)
|
||||
external
|
||||
returns (bytes32 poolId);
|
||||
|
||||
/// @dev Returns the current staking epoch number.
|
||||
/// @return epoch The current epoch.
|
||||
function currentEpoch()
|
||||
external
|
||||
view
|
||||
returns (uint256 epoch);
|
||||
|
||||
/// @dev Returns the time (in seconds) at which the current staking epoch started.
|
||||
/// @return startTime The start time of the current epoch, in seconds.
|
||||
function currentEpochStartTimeInSeconds()
|
||||
external
|
||||
view
|
||||
returns (uint256 startTime);
|
||||
|
||||
/// @dev Returns the duration of an epoch in seconds. This value can be updated.
|
||||
/// @return duration The duration of an epoch, in seconds.
|
||||
function epochDurationInSeconds()
|
||||
external
|
||||
view
|
||||
returns (uint256 duration);
|
||||
|
||||
/// @dev Returns a staking pool
|
||||
/// @param poolId Unique id of pool.
|
||||
function getStakingPool(bytes32 poolId)
|
||||
external
|
||||
view
|
||||
returns (Pool memory);
|
||||
|
||||
/// @dev Gets global stake for a given status.
|
||||
/// @param stakeStatus UNDELEGATED or DELEGATED
|
||||
/// @return balance Global stake for given status.
|
||||
function getGlobalStakeByStatus(StakeStatus stakeStatus)
|
||||
external
|
||||
view
|
||||
returns (StoredBalance memory balance);
|
||||
|
||||
/// @dev Gets an owner's stake balances by status.
|
||||
/// @param staker Owner of stake.
|
||||
/// @param stakeStatus UNDELEGATED or DELEGATED
|
||||
/// @return balance Owner's stake balances for given status.
|
||||
function getOwnerStakeByStatus(
|
||||
address staker,
|
||||
StakeStatus stakeStatus
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (StoredBalance memory balance);
|
||||
|
||||
/// @dev Returns the total stake delegated to a specific staking pool,
|
||||
/// across all members.
|
||||
/// @param poolId Unique Id of pool.
|
||||
/// @return balance Total stake delegated to pool.
|
||||
function getTotalStakeDelegatedToPool(bytes32 poolId)
|
||||
external
|
||||
view
|
||||
returns (StoredBalance memory balance);
|
||||
|
||||
/// @dev Returns the stake delegated to a specific staking pool, by a given staker.
|
||||
/// @param staker of stake.
|
||||
/// @param poolId Unique Id of pool.
|
||||
/// @return balance Stake delegated to pool by staker.
|
||||
function getStakeDelegatedToPoolByOwner(address staker, bytes32 poolId)
|
||||
external
|
||||
view
|
||||
returns (StoredBalance memory balance);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user