Merge branch 'v2-prototype' into refactor/move-spawn-switch-to-utils

* v2-prototype:
  Fix tslint issues
  Fix tslint failure
  Pass in fee and assetAmount rather then the whole signedOrder
  Fix missing paths
  Revert to returning orderState on invalid order
  - Refactor remainingFillableCalculator so it can be used for the maker and taker side - Moved the tests over from order-watcher - Did some token -> asset renaming
  Update naming in orderStateUtils to use asset over token, also removed cancelledAmount since in V2 it's binary.
  Fixed path
  Use source-map-support package to include correct line numbers in mocha
  move generated contract wrappers from `contract_wrappers/generated/` to `generated_contract_wrappers` in package with no non-generated contract wrappers
This commit is contained in:
Fabio Berger
2018-06-07 21:13:30 +02:00
49 changed files with 301 additions and 290 deletions

4
.gitignore vendored
View File

@@ -80,8 +80,8 @@ packages/order-watcher/test/artifacts/
packages/contract-wrappers/test/artifacts/
# generated contract wrappers
packages/0x.js/src/contract_wrappers/generated/
packages/contracts/src/contract_wrappers/generated/
packages/0x.js/src/generated_contract_wrappers/
packages/contracts/src/generated_contract_wrappers/
packages/contract-wrappers/src/contract_wrappers/generated/
packages/metacoin/src/contract_wrappers
packages/fill-scenarios/src/generated_contract_wrappers/

View File

@@ -1,9 +1,9 @@
lib
.nyc_output
/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/0x.js/src/generated_contract_wrappers/
/packages/contracts/src/generated_contract_wrappers/
/packages/fill-scenarios/src/generated_contract_wrappers/
/packages/order-watcher/src/generated_contract_wrappers/
/packages/order-utils/src/generated_contract_wrappers/

View File

@@ -43,7 +43,8 @@
"lerna": "^2.5.1",
"npm-run-all": "^4.1.2",
"prettier": "^1.11.1",
"wsrun": "^2.2.0"
"wsrun": "^2.2.0",
"source-map-support": "^0.5.6"
},
"resolutions": {
"ethereumjs-tx": "0xProject/ethereumjs-tx#fake-tx-include-signature-by-default",

View File

@@ -20,17 +20,17 @@
"build:all": "run-p build:umd:prod build:commonjs; exit 0;",
"pre_build": "run-s generate_contract_wrappers copy_artifacts",
"copy_artifacts": "copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts",
"generate_contract_wrappers": "abi-gen --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers",
"lint": "tslint --project . --exclude **/src/contract_wrappers/generated/**/*",
"generate_contract_wrappers": "abi-gen --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"lint": "tslint --project . --exclude **/src/generated_contract_wrapper/**/*",
"test:circleci": "run-s test:coverage",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf _bundles lib test_temp scripts src/contract_wrappers/generated",
"clean": "shx rm -rf _bundles lib test_temp scripts src/generated_contract_wrappers",
"build:umd:prod": "NODE_ENV=production webpack",
"build:commonjs": "tsc && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js",
"docs:stage": "node scripts/stage_docs.js",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES",
@@ -54,9 +54,9 @@
"../contract-wrappers/src/contract_wrappers/token_transfer_proxy_wrapper.ts",
"../contract-wrappers/src/contract_wrappers/token_wrapper.ts",
"../order-watcher/src/order_watcher/order_watcher.ts",
"./src/contract_wrappers/generated/ether_token.ts",
"./src/contract_wrappers/generated/token.ts",
"./src/contract_wrappers/generated/exchange.ts"
"./src/generated_contract_wrappers/ether_token.ts",
"./src/generated_contract_wrappers/token.ts",
"./src/generated_contract_wrappers/exchange.ts"
],
"s3BucketPath": "s3://doc-jsons/0x.js/",
"s3StagingBucketPath": "s3://staging-doc-jsons/0x.js/"

View File

@@ -12,7 +12,7 @@
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib test_temp scripts",
"lint": "tslint --project .",
"run_mocha": "mocha lib/test/**/*_test.js --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --exit",
"prepublishOnly": "run-p build",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s clean build test",

View File

@@ -14,7 +14,7 @@
"test": "yarn run_mocha",
"rebuild_and_test": "run-s clean build test",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"lint": "tslint --project . --exclude **/src/contract_wrappers/**/*",

View File

@@ -20,7 +20,7 @@
"clean": "shx rm -rf lib test_temp scripts",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"lint": "tslint --project .",
"run_mocha": "mocha lib/test/**/*_test.js --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --exit",
"test": "run-s copy_test_fixtures run_mocha",
"rebuild_and_test": "run-s clean build test",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",

View File

@@ -24,7 +24,7 @@
"update_compact_artifacts": "copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts",
"update_test_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/1.0.0/$i.json test/artifacts; done;",
"clean": "shx rm -rf _bundles lib test_temp scripts test/artifacts src/contract_wrappers/generated",
"run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"config": {

View File

@@ -18,11 +18,11 @@
"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",
"run_mocha": "mocha 'lib/test/**/*.js' --timeout 100000 --bail --exit",
"run_mocha": "mocha --require source-map-support/register 'lib/test/**/*.js' --timeout 100000 --bail --exit",
"compile": "sol-compiler",
"clean": "shx rm -rf lib src/contract_wrappers/generated",
"clean": "shx rm -rf lib src/generated_contract_wrappers",
"generate_contract_wrappers":
"abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers",
"abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"lint": "tslint --project . --exclude **/src/contract_wrappers/**/* --exclude **/lib/**/*",
"coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html",

View File

@@ -3,8 +3,8 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../contract_wrappers/generated/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../contract_wrappers/generated/e_r_c20_proxy';
import { DummyERC20TokenContract } from '../generated_contract_wrappers/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../generated_contract_wrappers/e_r_c20_proxy';
import { artifacts } from './artifacts';
import { constants } from './constants';

View File

@@ -4,8 +4,8 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
import * as _ from 'lodash';
import { DummyERC721TokenContract } from '../contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC721ProxyContract } from '../contract_wrappers/generated/e_r_c721_proxy';
import { DummyERC721TokenContract } from '../generated_contract_wrappers/dummy_e_r_c721_token';
import { ERC721ProxyContract } from '../generated_contract_wrappers/e_r_c721_proxy';
import { artifacts } from './artifacts';
import { constants } from './constants';

View File

@@ -4,7 +4,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
import { ExchangeContract } from '../contract_wrappers/generated/exchange';
import { ExchangeContract } from '../generated_contract_wrappers/exchange';
import { constants } from './constants';
import { formatters } from './formatters';

View File

@@ -3,8 +3,8 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
import { AssetProxyOwnerContract } from '../contract_wrappers/generated/asset_proxy_owner';
import { MultiSigWalletContract } from '../contract_wrappers/generated/multi_sig_wallet';
import { AssetProxyOwnerContract } from '../generated_contract_wrappers/asset_proxy_owner';
import { MultiSigWalletContract } from '../generated_contract_wrappers/multi_sig_wallet';
import { LogDecoder } from './log_decoder';
@@ -44,6 +44,7 @@ export class MultiSigWrapper {
txId: BigNumber,
from: string,
): Promise<TransactionReceiptWithDecodedLogs> {
// tslint:disable-next-line:no-unnecessary-type-assertion
const txHash = await (this
._multiSig as AssetProxyOwnerContract).executeRemoveAuthorizedAddress.sendTransactionAsync(txId, { from });
const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash);

View File

@@ -1,7 +1,7 @@
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
import { TokenRegistryContract } from '../contract_wrappers/generated/token_registry';
import { TokenRegistryContract } from '../generated_contract_wrappers/token_registry';
import { Token } from './types';

View File

@@ -2,7 +2,7 @@ import { BlockchainLifecycle } from '@0xproject/dev-utils';
import * as chai from 'chai';
import 'make-promises-safe';
import { MixinAuthorizableContract } from '../../src/contract_wrappers/generated/mixin_authorizable';
import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,10 +4,10 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';

View File

@@ -10,8 +10,8 @@ import {
ExecutionContractEventArgs,
ExecutionFailureContractEventArgs,
SubmissionContractEventArgs,
} from '../src/contract_wrappers/generated/asset_proxy_owner';
import { MixinAuthorizableContract } from '../src/contract_wrappers/generated/mixin_authorizable';
} from '../src/generated_contract_wrappers/asset_proxy_owner';
import { MixinAuthorizableContract } from '../src/generated_contract_wrappers/mixin_authorizable';
import { artifacts } from '../src/utils/artifacts';
import {
expectRevertOrAlwaysFailingTransactionAsync,

View File

@@ -4,7 +4,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
import { WETH9Contract } from '../src/contract_wrappers/generated/weth9';
import { WETH9Contract } from '../src/generated_contract_wrappers/weth9';
import { artifacts } from '../src/utils/artifacts';
import { expectInsufficientFundsAsync, expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';

View File

@@ -8,15 +8,15 @@ import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
import 'make-promises-safe';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import {
CancelContractEventArgs,
ExchangeContract,
FillContractEventArgs,
} from '../../src/contract_wrappers/generated/exchange';
} from '../../src/generated_contract_wrappers/exchange';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,10 +4,10 @@ import { AssetProxyId } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { TestAssetProxyDispatcherContract } from '../../src/contract_wrappers/generated/test_asset_proxy_dispatcher';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { TestAssetProxyDispatcherContract } from '../../src/generated_contract_wrappers/test_asset_proxy_dispatcher';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,7 +4,7 @@ import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { TestLibsContract } from '../../src/contract_wrappers/generated/test_libs';
import { TestLibsContract } from '../../src/generated_contract_wrappers/test_libs';
import { addressUtils } from '../../src/utils/address_utils';
import { artifacts } from '../../src/utils/artifacts';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -6,11 +6,11 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,7 +4,7 @@ import { SignedOrder } from '@0xproject/types';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import { TestSignatureValidatorContract } from '../../src/contract_wrappers/generated/test_signature_validator';
import { TestSignatureValidatorContract } from '../../src/generated_contract_wrappers/test_signature_validator';
import { addressUtils } from '../../src/utils/address_utils';
import { artifacts } from '../../src/utils/artifacts';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,10 +4,10 @@ import { AssetProxyId, OrderWithoutExchangeAddress, SignedOrder } from '@0xproje
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
import { WhitelistContract } from '../../src/contract_wrappers/generated/whitelist';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -7,11 +7,11 @@ import * as chai from 'chai';
import * as _ from 'lodash';
import 'make-promises-safe';
import { DummyERC20TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/contract_wrappers/generated/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/contract_wrappers/generated/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/contract_wrappers/generated/e_r_c721_proxy';
import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c721_token';
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';

View File

@@ -4,9 +4,9 @@ import BN = require('bn.js');
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import { TestLibBytesContract } from '../../src/contract_wrappers/generated/test_lib_bytes';
import { TestLibBytesContract } from '../../src/generated_contract_wrappers/test_lib_bytes';
import { artifacts } from '../../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync, expectRevertOrOtherErrorAsync } from '../../src/utils/assertions';
import { expectRevertOrOtherErrorAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';

View File

@@ -7,7 +7,7 @@ import 'make-promises-safe';
import {
MultiSigWalletWithTimeLockContract,
SubmissionContractEventArgs,
} from '../src/contract_wrappers/generated/multi_sig_wallet_with_time_lock';
} from '../src/generated_contract_wrappers/multi_sig_wallet_with_time_lock';
import { artifacts } from '../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';

View File

@@ -5,7 +5,7 @@ import ethUtil = require('ethereumjs-util');
import * as _ from 'lodash';
import 'make-promises-safe';
import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry';
import { TokenRegistryContract } from '../src/generated_contract_wrappers/token_registry';
import { artifacts } from '../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';

View File

@@ -8,12 +8,12 @@
// import ethUtil = require('ethereumjs-util');
// import * as Web3 from 'web3';
// import { AccountLevelsContract } from '../../src/contract_wrappers/generated/account_levels';
// import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage';
// import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token';
// import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta';
// import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange';
// import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy';
// import { AccountLevelsContract } from '../../src/generated_contract_wrappers/account_levels';
// import { ArbitrageContract } from '../../src/generated_contract_wrappers/arbitrage';
// import { DummyTokenContract } from '../../src/generated_contract_wrappers/dummy_token';
// import { EtherDeltaContract } from '../../src/generated_contract_wrappers/ether_delta';
// import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange';
// import { TokenTransferProxyContract } from '../../src/generated_contract_wrappers/token_transfer_proxy';
// import { artifacts } from '../../util/artifacts';
// import { Balances } from '../../util/balances';
// import { constants } from '../../util/constants';

View File

@@ -3,9 +3,9 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import 'make-promises-safe';
import { DummyERC20TokenContract } from '../src/contract_wrappers/generated/dummy_e_r_c20_token';
import { DummyERC20TokenContract } from '../src/generated_contract_wrappers/dummy_e_r_c20_token';
import { artifacts } from '../src/utils/artifacts';
import { expectRevertOrAlwaysFailingTransactionAsync, expectRevertOrOtherErrorAsync } from '../src/utils/assertions';
import { expectRevertOrOtherErrorAsync } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';

View File

@@ -4,7 +4,7 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
import { ZRXTokenContract } from '../src/contract_wrappers/generated/zrx_token';
import { ZRXTokenContract } from '../src/generated_contract_wrappers/zrx_token';
import { artifacts } from '../src/utils/artifacts';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';

View File

@@ -13,7 +13,7 @@
"test": "yarn run_mocha",
"rebuild_and_test": "run-s clean build test",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf lib scripts",

View File

@@ -15,7 +15,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --exit",
"clean": "shx rm -rf lib test_temp scripts",
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js",

View File

@@ -17,7 +17,7 @@
"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",
"run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js lib/test/global_hooks.js --bail --exit",
"generate_contract_wrappers": "abi-gen --abis 'artifacts/Metacoin.json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers",
"coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html",

File diff suppressed because one or more lines are too long

View File

@@ -18,7 +18,7 @@
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf lib scripts lib/src/artifacts src/generated_contract_wrappers",

View File

@@ -2,7 +2,6 @@ import { BigNumber } from '@0xproject/utils';
export abstract class AbstractOrderFilledCancelledFetcher {
public abstract async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber>;
public abstract async getCancelledTakerAmountAsync(orderHash: string): Promise<BigNumber>;
public abstract async getUnavailableTakerAmountAsync(orderHash: string): Promise<BigNumber>;
public abstract async isOrderCancelledAsync(orderHash: string): Promise<boolean>;
public abstract getZRXTokenAddress(): string;
}

View File

@@ -20,11 +20,8 @@ export class OrderStateUtils {
private _balanceAndProxyAllowanceFetcher: AbstractBalanceAndProxyAllowanceFetcher;
private _orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher;
private static _validateIfOrderIsValid(signedOrder: SignedOrder, orderRelevantState: OrderRelevantState): void {
const unavailableTakerTokenAmount = orderRelevantState.cancelledTakerTokenAmount.add(
orderRelevantState.filledTakerTokenAmount,
);
const availableTakerTokenAmount = signedOrder.takerAssetAmount.minus(unavailableTakerTokenAmount);
if (availableTakerTokenAmount.eq(0)) {
const availableTakerAssetAmount = signedOrder.takerAssetAmount.minus(orderRelevantState.filledTakerAssetAmount);
if (availableTakerAssetAmount.eq(0)) {
throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
}
@@ -42,12 +39,12 @@ export class OrderStateUtils {
throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance);
}
}
const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerAssetAmount
const minFillableTakerAssetAmountWithinNoRoundingErrorRange = signedOrder.takerAssetAmount
.dividedBy(ACCEPTABLE_RELATIVE_ROUNDING_ERROR)
.dividedBy(signedOrder.makerAssetAmount);
if (
orderRelevantState.remainingFillableTakerTokenAmount.lessThan(
minFillableTakerTokenAmountWithinNoRoundingErrorRange,
orderRelevantState.remainingFillableTakerAssetAmount.lessThan(
minFillableTakerAssetAmountWithinNoRoundingErrorRange,
)
) {
throw new Error(ExchangeContractErrs.OrderFillRoundingError);
@@ -82,13 +79,15 @@ export class OrderStateUtils {
}
public async getOrderRelevantStateAsync(signedOrder: SignedOrder): Promise<OrderRelevantState> {
const zrxTokenAddress = this._orderFilledCancelledFetcher.getZRXTokenAddress();
const makerProxyData = assetProxyUtils.decodeERC20ProxyData(signedOrder.makerAssetData);
const makerAssetAddress = makerProxyData.tokenAddress;
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const makerBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync(
signedOrder.makerAssetData,
makerAssetAddress,
signedOrder.makerAddress,
);
const makerProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync(
signedOrder.makerAssetData,
makerAssetAddress,
signedOrder.makerAddress,
);
const makerFeeBalance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync(
@@ -99,42 +98,41 @@ export class OrderStateUtils {
zrxTokenAddress,
signedOrder.makerAddress,
);
const filledTakerTokenAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
const cancelledTakerTokenAmount = await this._orderFilledCancelledFetcher.getCancelledTakerAmountAsync(
orderHash,
);
const unavailableTakerTokenAmount = await this._orderFilledCancelledFetcher.getUnavailableTakerAmountAsync(
orderHash,
);
const totalMakerTokenAmount = signedOrder.makerAssetAmount;
const totalTakerTokenAmount = signedOrder.takerAssetAmount;
const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount);
const remainingMakerTokenAmount = remainingTakerTokenAmount
.times(totalMakerTokenAmount)
.dividedToIntegerBy(totalTakerTokenAmount);
const transferrableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
const transferrableFeeTokenAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]);
const filledTakerAssetAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
const isOrderCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(orderHash);
const totalMakerAssetAmount = signedOrder.makerAssetAmount;
const totalTakerAssetAmount = signedOrder.takerAssetAmount;
const remainingTakerAssetAmount = isOrderCancelled
? new BigNumber(0)
: totalTakerAssetAmount.minus(filledTakerAssetAmount);
const remainingMakerAssetAmount = remainingTakerAssetAmount
.times(totalMakerAssetAmount)
.dividedToIntegerBy(totalTakerAssetAmount);
const transferrableMakerAssetAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
const transferrableFeeAssetAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]);
const zrxAssetData = assetProxyUtils.encodeERC20ProxyData(zrxTokenAddress);
const isMakerTokenZRX = signedOrder.makerAssetData === zrxAssetData;
const isMakerAssetZRX = signedOrder.makerAssetData === zrxAssetData;
const remainingFillableCalculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
transferrableFeeTokenAmount,
remainingMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakerAssetZRX,
transferrableMakerAssetAmount,
transferrableFeeAssetAmount,
remainingMakerAssetAmount,
);
const remainingFillableMakerTokenAmount = remainingFillableCalculator.computeRemainingMakerFillable();
const remainingFillableTakerTokenAmount = remainingFillableCalculator.computeRemainingTakerFillable();
const remainingFillableMakerAssetAmount = remainingFillableCalculator.computeRemainingFillable();
const remainingFillableTakerAssetAmount = remainingFillableMakerAssetAmount
.times(signedOrder.takerAssetAmount)
.dividedToIntegerBy(signedOrder.makerAssetAmount);
const orderRelevantState = {
makerBalance,
makerProxyAllowance,
makerFeeBalance,
makerFeeProxyAllowance,
filledTakerTokenAmount,
cancelledTakerTokenAmount,
remainingFillableMakerTokenAmount,
remainingFillableTakerTokenAmount,
filledTakerAssetAmount,
remainingFillableMakerAssetAmount,
remainingFillableTakerAssetAmount,
};
return orderRelevantState;
}

View File

@@ -1,95 +1,86 @@
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
export class RemainingFillableCalculator {
private _signedOrder: SignedOrder;
private _isMakerTokenZRX: boolean;
private _isTraderAssetZRX: boolean;
// Transferrable Amount is the minimum of Approval and Balance
private _transferrableMakerTokenAmount: BigNumber;
private _transferrableMakerFeeTokenAmount: BigNumber;
private _remainingMakerTokenAmount: BigNumber;
private _remainingMakerFeeAmount: BigNumber;
private _transferrableAssetAmount: BigNumber;
private _transferrableFeeAmount: BigNumber;
private _remainingOrderAssetAmount: BigNumber;
private _remainingOrderFeeAmount: BigNumber;
private _orderFee: BigNumber;
private _orderAssetAmount: BigNumber;
constructor(
signedOrder: SignedOrder,
isMakerTokenZRX: boolean,
transferrableMakerTokenAmount: BigNumber,
transferrableMakerFeeTokenAmount: BigNumber,
remainingMakerTokenAmount: BigNumber,
orderFee: BigNumber,
orderAssetAmount: BigNumber,
isTraderAssetZRX: boolean,
transferrableAssetAmount: BigNumber,
transferrableFeeAmount: BigNumber,
remainingOrderAssetAmount: BigNumber,
) {
this._signedOrder = signedOrder;
this._isMakerTokenZRX = isMakerTokenZRX;
this._transferrableMakerTokenAmount = transferrableMakerTokenAmount;
this._transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
this._remainingMakerTokenAmount = remainingMakerTokenAmount;
this._remainingMakerFeeAmount = remainingMakerTokenAmount
.times(signedOrder.makerFee)
.dividedToIntegerBy(signedOrder.makerAssetAmount);
this._orderFee = orderFee;
this._orderAssetAmount = orderAssetAmount;
this._isTraderAssetZRX = isTraderAssetZRX;
this._transferrableAssetAmount = transferrableAssetAmount;
this._transferrableFeeAmount = transferrableFeeAmount;
this._remainingOrderAssetAmount = remainingOrderAssetAmount;
this._remainingOrderFeeAmount = remainingOrderAssetAmount
.times(this._orderFee)
.dividedToIntegerBy(this._orderAssetAmount);
}
public computeRemainingMakerFillable(): BigNumber {
public computeRemainingFillable(): BigNumber {
if (this._hasSufficientFundsForFeeAndTransferAmount()) {
return this._remainingMakerTokenAmount;
return this._remainingOrderAssetAmount;
}
if (this._signedOrder.makerFee.isZero()) {
return BigNumber.min(this._remainingMakerTokenAmount, this._transferrableMakerTokenAmount);
if (this._orderFee.isZero()) {
return BigNumber.min(this._remainingOrderAssetAmount, this._transferrableAssetAmount);
}
return this._calculatePartiallyFillableMakerTokenAmount();
}
public computeRemainingTakerFillable(): BigNumber {
return this.computeRemainingMakerFillable()
.times(this._signedOrder.takerAssetAmount)
.dividedToIntegerBy(this._signedOrder.makerAssetAmount);
return this._calculatePartiallyFillableAssetAmount();
}
private _hasSufficientFundsForFeeAndTransferAmount(): boolean {
if (this._isMakerTokenZRX) {
const totalZRXTransferAmountRequired = this._remainingMakerTokenAmount.plus(this._remainingMakerFeeAmount);
const hasSufficientFunds = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
if (this._isTraderAssetZRX) {
const totalZRXTransferAmountRequired = this._remainingOrderAssetAmount.plus(this._remainingOrderFeeAmount);
const hasSufficientFunds = this._transferrableAssetAmount.greaterThanOrEqualTo(
totalZRXTransferAmountRequired,
);
return hasSufficientFunds;
} else {
const hasSufficientFundsForTransferAmount = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
this._remainingMakerTokenAmount,
const hasSufficientFundsForTransferAmount = this._transferrableAssetAmount.greaterThanOrEqualTo(
this._remainingOrderAssetAmount,
);
const hasSufficientFundsForFeeAmount = this._transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
this._remainingMakerFeeAmount,
const hasSufficientFundsForFeeAmount = this._transferrableFeeAmount.greaterThanOrEqualTo(
this._remainingOrderFeeAmount,
);
const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount;
return hasSufficientFunds;
}
}
private _calculatePartiallyFillableMakerTokenAmount(): BigNumber {
private _calculatePartiallyFillableAssetAmount(): BigNumber {
// Given an order for 200 wei for 2 ZRXwei fee, find 100 wei for 1 ZRXwei. Order ratio is then 100:1
const orderToFeeRatio = this._signedOrder.makerAssetAmount.dividedBy(this._signedOrder.makerFee);
// The number of times the maker can fill the order, if each fill only required the transfer of a single
const orderToFeeRatio = this._orderAssetAmount.dividedBy(this._orderFee);
// The number of times the trader (maker or taker) can fill the order, if each fill only required the transfer of a single
// baseUnit of fee tokens.
// Given 2 ZRXwei, the maximum amount of times Maker can fill this order, in terms of fees, is 2
const fillableTimesInFeeTokenBaseUnits = BigNumber.min(
this._transferrableMakerFeeTokenAmount,
this._remainingMakerFeeAmount,
);
// The number of times the Maker can fill the order, given the Maker Token Balance
// Assuming a balance of 150 wei, and an orderToFeeRatio of 100:1, maker can fill this order 1 time.
let fillableTimesInMakerTokenUnits = this._transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
if (this._isMakerTokenZRX) {
// If ZRX is the maker token, the Fee and the Maker amount need to be removed from the same pool;
// Given 2 ZRXwei, the maximum amount of times trader can fill this order, in terms of fees, is 2
const fillableTimesInFeeBaseUnits = BigNumber.min(this._transferrableFeeAmount, this._remainingOrderFeeAmount);
// The number of times the trader can fill the order, given the traders asset Balance
// Assuming a balance of 150 wei, and an orderToFeeRatio of 100:1, trader can fill this order 1 time.
let fillableTimesInAssetUnits = this._transferrableAssetAmount.dividedBy(orderToFeeRatio);
if (this._isTraderAssetZRX) {
// If ZRX is the trader asset, the Fee and the trader fill amount need to be removed from the same pool;
// 200 ZRXwei for 2ZRXwei fee can only be filled once (need 202 ZRXwei)
const totalZRXTokenPooled = this._transferrableMakerTokenAmount;
const totalZRXTokenPooled = this._transferrableAssetAmount;
// The purchasing power here is less as the tokens are taken from the same Pool
// For every one number of fills, we have to take an extra ZRX out of the pool
fillableTimesInMakerTokenUnits = totalZRXTokenPooled.dividedBy(orderToFeeRatio.plus(new BigNumber(1)));
fillableTimesInAssetUnits = totalZRXTokenPooled.dividedBy(orderToFeeRatio.plus(new BigNumber(1)));
}
// When Ratio is not fully divisible there can be remainders which cannot be represented, so they are floored.
// This can result in a RoundingError being thrown by the Exchange Contract.
const partiallyFillableMakerTokenAmount = fillableTimesInMakerTokenUnits
.times(this._signedOrder.makerAssetAmount)
.dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableFeeTokenAmount = fillableTimesInFeeTokenBaseUnits
.times(this._signedOrder.makerAssetAmount)
.dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableAmount = BigNumber.min(
partiallyFillableMakerTokenAmount,
partiallyFillableFeeTokenAmount,
);
const partiallyFillableAssetAmount = fillableTimesInAssetUnits
.times(this._orderAssetAmount)
.dividedToIntegerBy(this._orderFee);
const partiallyFillableFeeAmount = fillableTimesInFeeBaseUnits
.times(this._orderAssetAmount)
.dividedToIntegerBy(this._orderFee);
const partiallyFillableAmount = BigNumber.min(partiallyFillableAssetAmount, partiallyFillableFeeAmount);
return partiallyFillableAmount;
}
}

View File

@@ -1,11 +1,11 @@
import { ECSignature, SignedOrder } from '@0xproject/types';
import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'make-promises-safe';
import 'mocha';
import { RemainingFillableCalculator } from '@0xproject/order-utils';
import { RemainingFillableCalculator } from '../src/remaining_fillable_calculator';
import { chaiSetup } from './utils/chai_setup';
@@ -15,101 +15,107 @@ const expect = chai.expect;
describe('RemainingFillableCalculator', () => {
let calculator: RemainingFillableCalculator;
let signedOrder: SignedOrder;
let transferrableMakerTokenAmount: BigNumber;
let transferrableMakeAssetAmount: BigNumber;
let transferrableMakerFeeTokenAmount: BigNumber;
let remainingMakerTokenAmount: BigNumber;
let remainingMakeAssetAmount: BigNumber;
let makerAmount: BigNumber;
let takerAmount: BigNumber;
let makerFeeAmount: BigNumber;
let isMakerTokenZRX: boolean;
const makerToken: string = '0x1';
const takerToken: string = '0x2';
let isMakeAssetZRX: boolean;
const makerAssetData: string = '0x1';
const takerAssetData: string = '0x2';
const decimals: number = 4;
const zero: BigNumber = new BigNumber(0);
const zeroAddress = '0x0';
const signature: ECSignature = { v: 27, r: '', s: '' };
const signature: string =
'0x1B61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace225403';
beforeEach(async () => {
[makerAmount, takerAmount, makerFeeAmount] = [
Web3Wrapper.toBaseUnitAmount(new BigNumber(50), decimals),
Web3Wrapper.toBaseUnitAmount(new BigNumber(5), decimals),
Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals),
];
[transferrableMakerTokenAmount, transferrableMakerFeeTokenAmount] = [
[transferrableMakeAssetAmount, transferrableMakerFeeTokenAmount] = [
Web3Wrapper.toBaseUnitAmount(new BigNumber(50), decimals),
Web3Wrapper.toBaseUnitAmount(new BigNumber(5), decimals),
];
});
function buildSignedOrder(): SignedOrder {
return {
ecSignature: signature,
exchangeContractAddress: zeroAddress,
feeRecipient: zeroAddress,
maker: zeroAddress,
taker: zeroAddress,
signature,
exchangeAddress: zeroAddress,
feeRecipientAddress: zeroAddress,
senderAddress: zeroAddress,
makerAddress: zeroAddress,
takerAddress: zeroAddress,
makerFee: makerFeeAmount,
takerFee: zero,
makerTokenAmount: makerAmount,
takerTokenAmount: takerAmount,
makerTokenAddress: makerToken,
takerTokenAddress: takerToken,
makerAssetAmount: makerAmount,
takerAssetAmount: takerAmount,
makerAssetData,
takerAssetData,
salt: zero,
expirationUnixTimestampSec: zero,
expirationTimeSeconds: zero,
};
}
describe('Maker token is NOT ZRX', () => {
before(async () => {
isMakerTokenZRX = false;
isMakeAssetZRX = false;
});
it('calculates the correct amount when unfilled and funds available', () => {
signedOrder = buildSignedOrder();
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(remainingMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(remainingMakeAssetAmount);
});
it('calculates the correct amount when partially filled and funds available', () => {
signedOrder = buildSignedOrder();
remainingMakerTokenAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals);
remainingMakeAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(remainingMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(remainingMakeAssetAmount);
});
it('calculates the amount to be 0 when all fee funds are transferred', () => {
signedOrder = buildSignedOrder();
transferrableMakerFeeTokenAmount = zero;
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(zero);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(zero);
});
it('calculates the correct amount when balance is less than remaining fillable', () => {
signedOrder = buildSignedOrder();
const partiallyFilledAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), decimals);
remainingMakerTokenAmount = signedOrder.makerTokenAmount.minus(partiallyFilledAmount);
transferrableMakerTokenAmount = remainingMakerTokenAmount.minus(partiallyFilledAmount);
remainingMakeAssetAmount = signedOrder.makerAssetAmount.minus(partiallyFilledAmount);
transferrableMakeAssetAmount = remainingMakeAssetAmount.minus(partiallyFilledAmount);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(transferrableMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(transferrableMakeAssetAmount);
});
describe('Order to Fee Ratio is < 1', () => {
beforeEach(async () => {
@@ -121,17 +127,18 @@ describe('RemainingFillableCalculator', () => {
});
it('calculates the correct amount when funds unavailable', () => {
signedOrder = buildSignedOrder();
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
const transferredAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), decimals);
transferrableMakerTokenAmount = remainingMakerTokenAmount.minus(transferredAmount);
transferrableMakeAssetAmount = remainingMakeAssetAmount.minus(transferredAmount);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(transferrableMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(transferrableMakeAssetAmount);
});
});
describe('Ratio is not evenly divisble', () => {
@@ -144,20 +151,21 @@ describe('RemainingFillableCalculator', () => {
});
it('calculates the correct amount when funds unavailable', () => {
signedOrder = buildSignedOrder();
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
const transferredAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), decimals);
transferrableMakerTokenAmount = remainingMakerTokenAmount.minus(transferredAmount);
transferrableMakeAssetAmount = remainingMakeAssetAmount.minus(transferredAmount);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
const calculatedFillableAmount = calculator.computeRemainingMakerFillable();
expect(calculatedFillableAmount.lessThanOrEqualTo(transferrableMakerTokenAmount)).to.be.true();
const calculatedFillableAmount = calculator.computeRemainingFillable();
expect(calculatedFillableAmount.lessThanOrEqualTo(transferrableMakeAssetAmount)).to.be.true();
expect(calculatedFillableAmount).to.be.bignumber.greaterThan(new BigNumber(0));
const orderToFeeRatio = signedOrder.makerTokenAmount.dividedBy(signedOrder.makerFee);
const orderToFeeRatio = signedOrder.makerAssetAmount.dividedBy(signedOrder.makerFee);
const calculatedFeeAmount = calculatedFillableAmount.dividedBy(orderToFeeRatio);
expect(calculatedFeeAmount).to.be.bignumber.lessThan(transferrableMakerFeeTokenAmount);
});
@@ -165,69 +173,73 @@ describe('RemainingFillableCalculator', () => {
});
describe('Maker Token is ZRX', () => {
before(async () => {
isMakerTokenZRX = true;
isMakeAssetZRX = true;
});
it('calculates the correct amount when unfilled and funds available', () => {
signedOrder = buildSignedOrder();
transferrableMakerTokenAmount = makerAmount.plus(makerFeeAmount);
transferrableMakerFeeTokenAmount = transferrableMakerTokenAmount;
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
transferrableMakeAssetAmount = makerAmount.plus(makerFeeAmount);
transferrableMakerFeeTokenAmount = transferrableMakeAssetAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(remainingMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(remainingMakeAssetAmount);
});
it('calculates the correct amount when partially filled and funds available', () => {
signedOrder = buildSignedOrder();
remainingMakerTokenAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals);
remainingMakeAssetAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), decimals);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(remainingMakerTokenAmount);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(remainingMakeAssetAmount);
});
it('calculates the amount to be 0 when all fee funds are transferred', () => {
signedOrder = buildSignedOrder();
transferrableMakerTokenAmount = zero;
transferrableMakeAssetAmount = zero;
transferrableMakerFeeTokenAmount = zero;
remainingMakerTokenAmount = signedOrder.makerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount;
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
expect(calculator.computeRemainingMakerFillable()).to.be.bignumber.equal(zero);
expect(calculator.computeRemainingFillable()).to.be.bignumber.equal(zero);
});
it('calculates the correct amount when balance is less than remaining fillable', () => {
signedOrder = buildSignedOrder();
const partiallyFilledAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(2), decimals);
remainingMakerTokenAmount = signedOrder.makerTokenAmount.minus(partiallyFilledAmount);
transferrableMakerTokenAmount = remainingMakerTokenAmount.minus(partiallyFilledAmount);
transferrableMakerFeeTokenAmount = transferrableMakerTokenAmount;
remainingMakeAssetAmount = signedOrder.makerAssetAmount.minus(partiallyFilledAmount);
transferrableMakeAssetAmount = remainingMakeAssetAmount.minus(partiallyFilledAmount);
transferrableMakerFeeTokenAmount = transferrableMakeAssetAmount;
const orderToFeeRatio = signedOrder.makerTokenAmount.dividedToIntegerBy(signedOrder.makerFee);
const orderToFeeRatio = signedOrder.makerAssetAmount.dividedToIntegerBy(signedOrder.makerFee);
const expectedFillableAmount = new BigNumber(450980);
calculator = new RemainingFillableCalculator(
signedOrder,
isMakerTokenZRX,
transferrableMakerTokenAmount,
signedOrder.makerFee,
signedOrder.makerAssetAmount,
isMakeAssetZRX,
transferrableMakeAssetAmount,
transferrableMakerFeeTokenAmount,
remainingMakerTokenAmount,
remainingMakeAssetAmount,
);
const calculatedFillableAmount = calculator.computeRemainingMakerFillable();
const calculatedFillableAmount = calculator.computeRemainingFillable();
const numberOfFillsInRatio = calculatedFillableAmount.dividedToIntegerBy(orderToFeeRatio);
const calculatedFillableAmountPlusFees = calculatedFillableAmount.plus(numberOfFillsInRatio);
expect(calculatedFillableAmountPlusFees).to.be.bignumber.lessThan(transferrableMakerTokenAmount);
expect(calculatedFillableAmountPlusFees).to.be.bignumber.lessThan(remainingMakerTokenAmount);
expect(calculatedFillableAmountPlusFees).to.be.bignumber.lessThan(transferrableMakeAssetAmount);
expect(calculatedFillableAmountPlusFees).to.be.bignumber.lessThan(remainingMakeAssetAmount);
expect(calculatedFillableAmount).to.be.bignumber.equal(expectedFillableAmount);
expect(numberOfFillsInRatio.decimalPlaces()).to.be.equal(0);
});

View File

@@ -25,7 +25,7 @@
"update_compact_artifacts": "copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts",
"update_test_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/1.0.0/$i.json test/artifacts; done;",
"clean": "shx rm -rf _bundles lib test_temp scripts test/artifacts src/generated_contract_wrappers",
"run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"config": {

View File

@@ -14,7 +14,7 @@
"update_contract_fixtures": "copyfiles 'test/fixtures/contracts/**/*' ./lib",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"run_mocha": "mocha lib/test/*_test.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf lib scripts",

View File

@@ -17,7 +17,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --exit",
"clean": "shx rm -rf lib scripts test/fixtures/artifacts src/artifacts",
"copy_test_fixtures": "copyfiles 'test/fixtures/**/*' ./lib",
"compile_test": "sol-compiler compile",

View File

@@ -16,7 +16,7 @@
"rebuild_and_test": "run-s clean build test",
"copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures",
"copy_test_environments": "copyfiles -u 2 './test/environments/**/*.json' ./lib/test/environments",
"run_mocha": "mocha lib/test/**/*_test.js --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --exit",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js"
},
"bin": {

View File

@@ -12,8 +12,8 @@
"build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib scripts",
"lint": "tslint --project .",
"run_mocha_unit": "mocha lib/test/unit/**/*_test.js --timeout 10000 --bail --exit",
"run_mocha_integration": "mocha lib/test/integration/**/*_test.js --timeout 10000 --bail --exit",
"run_mocha_unit": "mocha --require source-map-support/register lib/test/unit/**/*_test.js --timeout 10000 --bail --exit",
"run_mocha_integration": "mocha --require source-map-support/register lib/test/integration/**/*_test.js --timeout 10000 --bail --exit",
"test": "npm run test:unit",
"test:unit:coverage": "nyc npm run test:unit --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",

View File

@@ -103,10 +103,9 @@ export interface OrderRelevantState {
makerProxyAllowance: BigNumber;
makerFeeBalance: BigNumber;
makerFeeProxyAllowance: BigNumber;
filledTakerTokenAmount: BigNumber;
cancelledTakerTokenAmount: BigNumber;
remainingFillableMakerTokenAmount: BigNumber;
remainingFillableTakerTokenAmount: BigNumber;
filledTakerAssetAmount: BigNumber;
remainingFillableMakerAssetAmount: BigNumber;
remainingFillableTakerAssetAmount: BigNumber;
}
export interface OrderStateValid {

View File

@@ -15,7 +15,7 @@
"test": "yarn run_mocha",
"rebuild_and_test": "run-s clean build test",
"test:circleci": "yarn test:coverage",
"run_mocha": "mocha lib/test/**/*_test.js --bail --exit",
"run_mocha": "mocha --require source-map-support/register lib/test/**/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"manual:postpublish": "yarn build; node ./scripts/postpublish.js",

View File

@@ -101,6 +101,9 @@ const docsInfoConfig: DocsInfoConfig = {
'"0x.js/src/contract_wrappers/generated/ether_token"',
'"0x.js/src/contract_wrappers/generated/token"',
'"0x.js/src/contract_wrappers/generated/exchange"',
'"0x.js/src/generated_contract_wrappers/ether_token"',
'"0x.js/src/generated_contract_wrappers/token"',
'"0x.js/src/generated_contract_wrappers/exchange"',
],
},
menuSubsectionToVersionWhenIntroduced: {

View File

@@ -10802,6 +10802,13 @@ source-map-support@^0.5.0, source-map-support@^0.5.3:
dependencies:
source-map "^0.6.0"
source-map-support@^0.5.6:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.6.tgz#4435cee46b1aab62b8e8610ce60f788091c51c13"
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"